diff options
author | Bo Hu <bohu@google.com> | 2024-05-10 11:43:42 -0700 |
---|---|---|
committer | Bo Hu <bohu@google.com> | 2024-05-10 11:43:42 -0700 |
commit | d21b37c7f1371f3031aef6fa697a6afea6e78328 (patch) | |
tree | 3d7416eb10f21e37572f56c4bca6c7f53239e9c9 | |
parent | 10b96003f0b6eaa9382b9d306b1a6c3eea53a7a4 (diff) | |
download | qemu-d21b37c7f1371f3031aef6fa697a6afea6e78328.tar.gz |
resizable: disallow transition overlap
When resizable is in the middle of config change,
disallow new requests; this is to keep state consistent.
Bug: 336702265
Change-Id: Ia66aa67ebfc2e3483bee4f31ca7154eee3f96a47
5 files changed, 40 insertions, 1 deletions
diff --git a/android/android-emu/android/emulation/resizable_display_config.cpp b/android/android-emu/android/emulation/resizable_display_config.cpp index 9ba5e862ed..9d08ce518f 100644 --- a/android/android-emu/android/emulation/resizable_display_config.cpp +++ b/android/android-emu/android/emulation/resizable_display_config.cpp @@ -30,6 +30,7 @@ #include "host-common/opengles.h" #include "studio_stats.pb.h" +#include <atomic> #include <map> using android::metrics::MetricsReporter; @@ -220,11 +221,21 @@ public: mMetricsRegistered = true; } + bool isTransitionInProgress() const { + bool result = mTransitionInProgress.load(std::memory_order_relaxed); + return result; + } + + void setTransitionInProgress(int inProgress) { + mTransitionInProgress.store(inProgress, std::memory_order_relaxed); + } + private: std::map<PresetEmulatorSizeType, PresetEmulatorSizeInfo> mConfigs; PresetEmulatorSizeType mActiveConfigId = PRESET_SIZE_MAX; std::map<PresetEmulatorSizeType, uint32_t> mTypeCount; bool mMetricsRegistered = false; + std::atomic<bool> mTransitionInProgress{false}; }; static android::base::LazyInstance<ResizableConfig> sResizableConfig = @@ -254,6 +265,19 @@ void updateAndroidDisplayConfigPath(enum PresetEmulatorSizeType id) { android::emulation::sResizableConfig->updateAndroidDisplayConfigPath(id); } +bool isResizableTransitionInProgress() { + if (!resizableEnabled()) + return false; + + return android::emulation::sResizableConfig->isTransitionInProgress(); +} + +void setResizableTransitionInProgress(bool inProgress) { + if (!resizableEnabled()) + return; + android::emulation::sResizableConfig->setTransitionInProgress(inProgress); +} + bool resizableEnabled34() { const char* pconfigs = getConsoleAgents()->settings->hw()->hw_resizable_configs; diff --git a/android/android-emu/android/emulation/resizable_display_config.h b/android/android-emu/android/emulation/resizable_display_config.h index 921841b183..caf6162f6e 100644 --- a/android/android-emu/android/emulation/resizable_display_config.h +++ b/android/android-emu/android/emulation/resizable_display_config.h @@ -32,6 +32,8 @@ struct PresetEmulatorSizeInfo { int dpi; }; +bool isResizableTransitionInProgress(); +void setResizableTransitionInProgress(bool inProgress); bool resizableEnabled(); bool resizableEnabled34(); void resizableInit(); diff --git a/android/android-emu/android/hw-sensors.cpp b/android/android-emu/android/hw-sensors.cpp index c6f2808654..13d6853b17 100644 --- a/android/android-emu/android/hw-sensors.cpp +++ b/android/android-emu/android/hw-sensors.cpp @@ -1412,6 +1412,9 @@ int android_foldable_pixel_fold_second_display_id() { // We still need to discuss how to support foldable for secondary displays bool android_foldable_hinge_enabled() { + if (isResizableTransitionInProgress()) { + return false; + } return ((android_foldable_hinge_configured() || android_foldable_folded_area_configured(0) || android_foldable_rollable_configured()) && @@ -1532,7 +1535,7 @@ bool android_foldable_unfold() { } bool android_foldable_set_posture(int posture) { - if (!android_foldable_hinge_configured()) { + if (!android_foldable_hinge_enabled()) { return false; } struct FoldableState state; diff --git a/android/android-emu/android/physics/FoldableModel.cpp b/android/android-emu/android/physics/FoldableModel.cpp index c576b9ab1f..f4764834fb 100644 --- a/android/android-emu/android/physics/FoldableModel.cpp +++ b/android/android-emu/android/physics/FoldableModel.cpp @@ -424,6 +424,9 @@ void FoldableModel::setHingeAngle(uint32_t hingeIndex, PhysicalInterpolation mode, std::recursive_mutex& mutex) { VLOG(foldable) << "setHingeAngle index " << hingeIndex << " degrees " << degrees; + if (!android_foldable_hinge_enabled()) { + return; + } std::unique_lock<std::recursive_mutex> lock(mutex); if (hingeIndex >= ANDROID_FOLDABLE_MAX_HINGES) return; diff --git a/android/android-ui/modules/aemu-ui-qt/src/android/skin/qt/tool-window.cpp b/android/android-ui/modules/aemu-ui-qt/src/android/skin/qt/tool-window.cpp index b76db16dc6..d4f332fa10 100644 --- a/android/android-ui/modules/aemu-ui-qt/src/android/skin/qt/tool-window.cpp +++ b/android/android-ui/modules/aemu-ui-qt/src/android/skin/qt/tool-window.cpp @@ -476,6 +476,9 @@ void ToolWindow::on_sleep_timer_done() { emugl::setShouldSkipDraw(false); android_redrawOpenglesWindow(); } + if (isResizableTransitionInProgress()) { + setResizableTransitionInProgress(false); + } if (mSleepKeySent) { mEmulatorWindow->getAdbInterface()-> enqueueCommand( {"shell", "input", "keyevent", "KEYCODE_WAKEUP"}); @@ -978,6 +981,9 @@ void ToolWindow::presetSizeAdvance(PresetEmulatorSizeType newSize) { if (getResizableActiveConfigId() == newSize) { return; } + if (isResizableTransitionInProgress()) { + return; + } if (android_foldable_is_folded()) { startUnfoldTimer(newSize); return; @@ -998,6 +1004,7 @@ void ToolWindow::presetSizeAdvance(PresetEmulatorSizeType newSize) { on_new_posture_requested(POSTURE_OPENED); } + setResizableTransitionInProgress(true); emugl::setShouldSkipDraw(true); startSleepTimer(); std::string updateMsg = "Updating device size\n"; |