make multi-display more real

- displays are represented by a binder on the client side
- c++ clients can now create and modify displays

Change-Id: I203ea5b4beae0819d742ec5171c27568f4e8354b
diff --git a/include/gui/ISurfaceComposer.h b/include/gui/ISurfaceComposer.h
index b2f8889..9ab35b1 100644
--- a/include/gui/ISurfaceComposer.h
+++ b/include/gui/ISurfaceComposer.h
@@ -48,6 +48,11 @@
         eSynchronous = 0x01,
     };
 
+    enum {
+        eDisplayIdMain = 0,
+        eDisplayIdHdmi = 1
+    };
+
     /* create connection with surface flinger, requires
      * ACCESS_SURFACE_FLINGER permission
      */
@@ -57,6 +62,19 @@
      */
     virtual sp<IGraphicBufferAlloc> createGraphicBufferAlloc() = 0;
 
+    /* return an IDisplayEventConnection */
+    virtual sp<IDisplayEventConnection> createDisplayEventConnection() = 0;
+
+    /* create a display with given id.
+     * requires ACCESS_SURFACE_FLINGER permission.
+     */
+    virtual sp<IBinder> createDisplay() = 0;
+
+    /* get the token for the existing default displays. possible values
+     * for id are eDisplayIdMain and eDisplayIdHdmi.
+     */
+    virtual sp<IBinder> getBuiltInDisplay(int32_t id) = 0;
+
     /* open/close transactions. requires ACCESS_SURFACE_FLINGER permission */
     virtual void setTransactionState(const Vector<ComposerState>& state,
             const Vector<DisplayState>& displays, uint32_t flags) = 0;
@@ -66,6 +84,11 @@
      */
     virtual void bootFinished() = 0;
 
+    /* verify that an ISurfaceTexture was created by SurfaceFlinger.
+     */
+    virtual bool authenticateSurfaceTexture(
+            const sp<ISurfaceTexture>& surface) const = 0;
+
     /* Capture the specified screen. requires READ_FRAME_BUFFER permission
      * This function will fail if there is a secure window on screen.
      */
@@ -74,13 +97,6 @@
             uint32_t reqWidth, uint32_t reqHeight, uint32_t minLayerZ,
             uint32_t maxLayerZ) = 0;
 
-    /* verify that an ISurfaceTexture was created by SurfaceFlinger.
-     */
-    virtual bool authenticateSurfaceTexture(
-            const sp<ISurfaceTexture>& surface) const = 0;
-
-    /* return an IDisplayEventConnection */
-    virtual sp<IDisplayEventConnection> createDisplayEventConnection() = 0;
 
     /* triggers screen off and waits for it to complete */
     virtual void blank() = 0;
@@ -106,13 +122,15 @@
         BOOT_FINISHED = IBinder::FIRST_CALL_TRANSACTION,
         CREATE_CONNECTION,
         CREATE_GRAPHIC_BUFFER_ALLOC,
-        GET_DISPLAY_INFO,
-        SET_TRANSACTION_STATE,
-        CAPTURE_SCREEN,
-        AUTHENTICATE_SURFACE,
         CREATE_DISPLAY_EVENT_CONNECTION,
+        CREATE_DISPLAY,
+        GET_BUILT_IN_DISPLAY,
+        SET_TRANSACTION_STATE,
+        AUTHENTICATE_SURFACE,
+        CAPTURE_SCREEN,
         BLANK,
         UNBLANK,
+        GET_DISPLAY_INFO,
         CONNECT_DISPLAY,
     };
 
diff --git a/include/gui/SurfaceComposerClient.h b/include/gui/SurfaceComposerClient.h
index b058b8d..5776038 100644
--- a/include/gui/SurfaceComposerClient.h
+++ b/include/gui/SurfaceComposerClient.h
@@ -59,6 +59,13 @@
     // Forcibly remove connection before all references have gone away.
     void        dispose();
 
+    // callback when the composer is dies
+    status_t linkToComposerDeath(const sp<IBinder::DeathRecipient>& recipient,
+            void* cookie = NULL, uint32_t flags = 0);
+
+    // Get information about a display
+    static status_t getDisplayInfo(DisplayID dpy, DisplayInfo* info);
+
     // ------------------------------------------------------------------------
     // surface creation / destruction
 
@@ -80,13 +87,14 @@
             uint32_t flags = 0  // usage flags
     );
 
+    static sp<IBinder> createDisplay();
 
     // ------------------------------------------------------------------------
     // Composer parameters
     // All composer parameters must be changed within a transaction
     // several surfaces can be updated in one transaction, all changes are
     // committed at once when the transaction is closed.
-    // closeGlobalTransaction() usually requires an IPC with the server.
+    // closeGlobalTransaction() requires an IPC with the server.
 
     //! Open a composer transaction on all active SurfaceComposerClients.
     static void openGlobalTransaction();
@@ -97,12 +105,6 @@
     //! Set the orientation of the given display
     static int setOrientation(DisplayID dpy, int orientation, uint32_t flags);
 
-    // Get information about a display
-    static status_t getDisplayInfo(DisplayID dpy, DisplayInfo* info);
-
-    status_t linkToComposerDeath(const sp<IBinder::DeathRecipient>& recipient,
-            void* cookie = NULL, uint32_t flags = 0);
-
     status_t    hide(SurfaceID id);
     status_t    show(SurfaceID id, int32_t layer = -1);
     status_t    setFlags(SurfaceID id, uint32_t flags, uint32_t mask);
@@ -116,6 +118,16 @@
     status_t    setLayerStack(SurfaceID id, uint32_t layerStack);
     status_t    destroySurface(SurfaceID sid);
 
+    static void setDisplaySurface(const sp<IBinder>& token,
+            const sp<ISurfaceTexture>& surface);
+    static void setDisplayLayerStack(const sp<IBinder>& token,
+            uint32_t layerStack);
+    static void setDisplayOrientation(const sp<IBinder>& token,
+            uint32_t orientation);
+    static void setDisplayViewport(const sp<IBinder>& token,
+            const Rect& viewport);
+    static void setDisplayFrame(const sp<IBinder>& token, const Rect& frame);
+
 private:
     virtual void onFirstRef();
     Composer& getComposer();
diff --git a/include/private/gui/LayerState.h b/include/private/gui/LayerState.h
index 90e74a9..9765e28 100644
--- a/include/private/gui/LayerState.h
+++ b/include/private/gui/LayerState.h
@@ -106,14 +106,21 @@
         eOrientationSwapMask    = 0x01
     };
 
-    int32_t             displayId;
+    enum {
+        eSurfaceChanged     = 0x1,
+        eLayerStackChanged  = 0x2,
+        eTransformChanged   = 0x4
+    };
+
+    uint32_t what;
+    sp<IBinder> token;
     sp<ISurfaceTexture> surface;
-    uint32_t            layerStack;
-    uint32_t            orientation;
-    Rect                viewport;
-    Rect                frame;
-    status_t    write(Parcel& output) const;
-    status_t    read(const Parcel& input);
+    uint32_t layerStack;
+    uint32_t orientation;
+    Rect viewport;
+    Rect frame;
+    status_t write(Parcel& output) const;
+    status_t read(const Parcel& input);
 };
 
 }; // namespace android