From 21230c6410bdab13cd2bd274da54b1e4061b6035 Mon Sep 17 00:00:00 2001 From: Jeff Brown Date: Tue, 20 Sep 2011 15:08:29 -0700 Subject: [PATCH] Handle orientation changes more systematically. Bug: 4981385 Simplify the orientation changing code path in the WindowManager. Instead of the policy calling setRotation() when the sensor determined orientation changes, it calls updateRotation(), which figures everything out. For the most part, the rotation actually passed to setRotation() was more or less ignored and just added confusion, particularly when handling deferred orientation changes. Ensure that 180 degree rotations are disallowed even when the application specifies SCREEN_ORIENTATION_SENSOR_*. These rotations are only enabled when docked upside-down for some reason or when the application specifies SCREEN_ORIENTATION_FULL_SENSOR. Ensure that special modes like HDMI connected, lid switch, dock and rotation lock all cause the sensor to be ignored even when the application asks for sensor-based orientation changes. The sensor is not relevant in these modes because some external factor (or the user) is determining the preferred rotation. Currently, applications can still override the preferred rotation even when there are special modes in play that might say otherwise. We could tweak this so that some special modes trump application choices completely (resulting in a letter-boxed application, perhaps). I tested this sort of tweak (not included in the patch) and it seems to work fine, including transitions between applications with varying orientation. Delete dead code related to animFlags. Handle pausing/resuming orientation changes more precisely. Ensure that a deferred orientation change is performed when a drag completes, even if endDragLw() is not called because the drag was aborted before the drop happened. We pause the orientation change in register() and resume in unregister() because those methods appear to always be called as needed. Change-Id: If0a31de3d057251e581fdee64819f2b19e676e9a --- include/surfaceflinger/ISurfaceComposer.h | 8 ++------ services/surfaceflinger/SurfaceFlinger.cpp | 4 ++-- services/surfaceflinger/SurfaceFlinger.h | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/include/surfaceflinger/ISurfaceComposer.h b/include/surfaceflinger/ISurfaceComposer.h index 6b31ca4cb..e0f4cf900 100644 --- a/include/surfaceflinger/ISurfaceComposer.h +++ b/include/surfaceflinger/ISurfaceComposer.h @@ -88,11 +88,6 @@ public: eElectronBeamAnimationOff = 0x10 }; - // flags for setOrientation - enum { - eOrientationAnimationDisable = 0x00000001 - }; - /* create connection with surface flinger, requires * ACCESS_SURFACE_FLINGER permission */ @@ -112,7 +107,8 @@ public: virtual status_t freezeDisplay(DisplayID dpy, uint32_t flags) = 0; virtual status_t unfreezeDisplay(DisplayID dpy, uint32_t flags) = 0; - /* Set display orientation. requires ACCESS_SURFACE_FLINGER permission */ + /* Set display orientation. requires ACCESS_SURFACE_FLINGER permission + * No flags are currently defined. Set flags to 0. */ virtual int setOrientation(DisplayID dpy, int orientation, uint32_t flags) = 0; /* signal that we're done booting. diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 0ef03bb7d..09097eea8 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -566,7 +566,7 @@ void SurfaceFlinger::handleTransactionLocked(uint32_t transactionFlags) const int dpy = 0; const int orientation = mCurrentState.orientation; - const uint32_t type = mCurrentState.orientationType; + // Currently unused: const uint32_t flags = mCurrentState.orientationFlags; GraphicPlane& plane(graphicPlane(dpy)); plane.setOrientation(orientation); @@ -1299,7 +1299,7 @@ int SurfaceFlinger::setOrientation(DisplayID dpy, Mutex::Autolock _l(mStateLock); if (mCurrentState.orientation != orientation) { if (uint32_t(orientation)<=eOrientation270 || orientation==42) { - mCurrentState.orientationType = flags; + mCurrentState.orientationFlags = flags; mCurrentState.orientation = orientation; setTransactionFlags(eTransactionNeeded); mTransactionCV.wait(mStateLock); diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h index d7f005f7c..43191b7e8 100644 --- a/services/surfaceflinger/SurfaceFlinger.h +++ b/services/surfaceflinger/SurfaceFlinger.h @@ -245,7 +245,7 @@ private: } LayerVector layersSortedByZ; uint8_t orientation; - uint8_t orientationType; + uint8_t orientationFlags; uint8_t freezeDisplay; };