SurfaceFlinger: update orientation via transactions

This change merges the ISurfaceComposer::setOrientation functionality
into ISurfaceComposer::setTransactionState.  It enables the window
manager to atomically update both the display orientation and the
position and size of the windows in a single transaction with
SurfaceFlinger.

Bug: 5439574
Change-Id: I18a8ccc564d7d760ef8afb2d015ccdb7a7963900
diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp
index 00a4bf6..5f3d608 100644
--- a/libs/gui/SurfaceComposerClient.cpp
+++ b/libs/gui/SurfaceComposerClient.cpp
@@ -91,8 +91,10 @@
 
     mutable Mutex               mLock;
     SortedVector<ComposerState> mStates;
+    int                         mOrientation;
 
-    Composer() : Singleton<Composer>() { }
+    Composer() : Singleton<Composer>(),
+        mOrientation(ISurfaceComposer::eOrientationUnchanged) { }
 
     void closeGlobalTransactionImpl();
 
@@ -119,6 +121,7 @@
     status_t setFreezeTint(
             const sp<SurfaceComposerClient>& client, SurfaceID id,
             uint32_t tint);
+    status_t setOrientation(int orientation);
 
     static void closeGlobalTransaction() {
         Composer::getInstance().closeGlobalTransactionImpl();
@@ -133,14 +136,18 @@
     sp<ISurfaceComposer> sm(getComposerService());
 
     Vector<ComposerState> transaction;
+    int orientation;
 
     { // scope for the lock
         Mutex::Autolock _l(mLock);
         transaction = mStates;
         mStates.clear();
+
+        orientation = mOrientation;
+        mOrientation = ISurfaceComposer::eOrientationUnchanged;
     }
 
-   sm->setTransactionState(transaction);
+   sm->setTransactionState(transaction, orientation);
 }
 
 layer_state_t* Composer::getLayerStateLocked(
@@ -260,6 +267,12 @@
     return NO_ERROR;
 }
 
+status_t Composer::setOrientation(int orientation) {
+    Mutex::Autolock _l(mLock);
+    mOrientation = orientation;
+    return NO_ERROR;
+}
+
 // ---------------------------------------------------------------------------
 
 SurfaceComposerClient::SurfaceComposerClient()
@@ -427,6 +440,12 @@
     return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy);
 }
 
+status_t SurfaceComposerClient::setOrientation(DisplayID dpy,
+        int orientation, uint32_t flags)
+{
+    return Composer::getInstance().setOrientation(orientation);
+}
+
 // ----------------------------------------------------------------------------
 
 status_t SurfaceComposerClient::getDisplayInfo(
@@ -491,21 +510,14 @@
 
 status_t SurfaceComposerClient::freezeDisplay(DisplayID dpy, uint32_t flags)
 {
-    sp<ISurfaceComposer> sm(getComposerService());
-    return sm->freezeDisplay(dpy, flags);
+    // This has been made a no-op because it can cause Gralloc buffer deadlocks.
+    return NO_ERROR;
 }
 
 status_t SurfaceComposerClient::unfreezeDisplay(DisplayID dpy, uint32_t flags)
 {
-    sp<ISurfaceComposer> sm(getComposerService());
-    return sm->unfreezeDisplay(dpy, flags);
-}
-
-int SurfaceComposerClient::setOrientation(DisplayID dpy,
-        int orientation, uint32_t flags)
-{
-    sp<ISurfaceComposer> sm(getComposerService());
-    return sm->setOrientation(dpy, orientation, flags);
+    // This has been made a no-op because it can cause Gralloc buffer deadlocks.
+    return NO_ERROR;
 }
 
 // ----------------------------------------------------------------------------
@@ -572,4 +584,3 @@
 
 // ----------------------------------------------------------------------------
 }; // namespace android
-