OSDN Git Service

Plumb display name into SurfaceFlinger
authorAndy McFadden <fadden@android.com>
Tue, 18 Sep 2012 01:27:17 +0000 (18:27 -0700)
committerAndy McFadden <fadden@android.com>
Tue, 18 Sep 2012 16:20:23 +0000 (09:20 -0700)
The Surface createDisplay() call takes a display name for debugging.
This change carries it through SurfaceFlinger and displays it in
the "dumpsys SurfaceFlinger" output.

Bug 7058158

Change-Id: I79f3474a8656ff1beb7b478e0dbf2c5de666118a

include/gui/ISurfaceComposer.h
include/gui/SurfaceComposerClient.h
libs/gui/ISurfaceComposer.cpp
libs/gui/SurfaceComposerClient.cpp
services/surfaceflinger/DisplayDevice.cpp
services/surfaceflinger/DisplayDevice.h
services/surfaceflinger/SurfaceFlinger.cpp
services/surfaceflinger/SurfaceFlinger.h

index f4af705..a20caf9 100644 (file)
@@ -68,7 +68,7 @@ public:
     /* create a display
      * requires ACCESS_SURFACE_FLINGER permission.
      */
-    virtual sp<IBinder> createDisplay() = 0;
+    virtual sp<IBinder> createDisplay(const String8& displayName) = 0;
 
     /* get the token for the existing default displays. possible values
      * for id are eDisplayIdMain and eDisplayIdHdmi.
index 57c72c9..7a14c6a 100644 (file)
@@ -85,7 +85,7 @@ public:
     );
 
     //! Create a display
-    static sp<IBinder> createDisplay();
+    static sp<IBinder> createDisplay(const String8& displayName);
 
     //! Get the token for the existing default displays.
     //! Possible values for id are eDisplayIdMain and eDisplayIdHdmi.
index 6bcc41d..07d2b79 100644 (file)
@@ -179,10 +179,11 @@ public:
         return result;
     }
 
-    virtual sp<IBinder> createDisplay()
+    virtual sp<IBinder> createDisplay(const String8& displayName)
     {
         Parcel data, reply;
         data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
+        data.writeString8(displayName);
         remote()->transact(BnSurfaceComposer::CREATE_DISPLAY, data, &reply);
         return reply.readStrongBinder();
     }
@@ -305,7 +306,8 @@ status_t BnSurfaceComposer::onTransact(
         } break;
         case CREATE_DISPLAY: {
             CHECK_INTERFACE(ISurfaceComposer, data, reply);
-            sp<IBinder> display(createDisplay());
+            String8 displayName = data.readString8();
+            sp<IBinder> display(createDisplay(displayName));
             reply->writeStrongBinder(display);
             return NO_ERROR;
         } break;
index 9b43ae8..9cf9cb5 100644 (file)
@@ -128,7 +128,7 @@ class Composer : public Singleton<Composer>
     DisplayState& getDisplayStateLocked(const sp<IBinder>& token);
 
 public:
-    sp<IBinder> createDisplay();
+    sp<IBinder> createDisplay(const String8& displayName);
     sp<IBinder> getBuiltInDisplay(int32_t id);
 
     status_t setPosition(const sp<SurfaceComposerClient>& client, SurfaceID id,
@@ -168,8 +168,8 @@ ANDROID_SINGLETON_STATIC_INSTANCE(Composer);
 
 // ---------------------------------------------------------------------------
 
-sp<IBinder> Composer::createDisplay() {
-    return ComposerService::getComposerService()->createDisplay();
+sp<IBinder> Composer::createDisplay(const String8& displayName) {
+    return ComposerService::getComposerService()->createDisplay(displayName);
 }
 
 sp<IBinder> Composer::getBuiltInDisplay(int32_t id) {
@@ -442,8 +442,8 @@ sp<SurfaceControl> SurfaceComposerClient::createSurface(
     return result;
 }
 
-sp<IBinder> SurfaceComposerClient::createDisplay() {
-    return Composer::getInstance().createDisplay();
+sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName) {
+    return Composer::getInstance().createDisplay(displayName);
 }
 
 sp<IBinder> SurfaceComposerClient::getBuiltInDisplay(int32_t id) {
index 2708a90..78024b8 100644 (file)
@@ -149,6 +149,20 @@ void DisplayDevice::init(EGLConfig config)
     // get an h/w composer ID
     mHwcDisplayId = mFlinger->allocateHwcDisplayId(mType);
 
+    // Name the display.  The name will be replaced shortly if the display
+    // was created with createDisplay().
+    switch (mType) {
+        case DISPLAY_PRIMARY:
+            mDisplayName = "Built-in Screen";
+            break;
+        case DISPLAY_EXTERNAL:
+            mDisplayName = "HDMI Screen";
+            break;
+        default:
+            mDisplayName = "Virtual Screen";    // e.g. Overlay #n
+            break;
+    }
+
     // initialize the display orientation transform.
     setProjection(DisplayState::eOrientationDefault, mViewport, mFrame);
 }
index 4a3f0a0..e3b8d57 100644 (file)
@@ -118,11 +118,16 @@ public:
     }
     inline Rect bounds() const { return getBounds(); }
 
+    void setDisplayName(const String8& displayName) {
+        mDisplayName = displayName;
+    }
+    const String8& getDisplayName() const { return mDisplayName; }
+
     static EGLBoolean makeCurrent(EGLDisplay dpy,
             const sp<const DisplayDevice>& hw, EGLContext ctx);
 
     /* ------------------------------------------------------------------------
-     * blank / unplank management
+     * blank / unblank management
      */
     void releaseScreen() const;
     void acquireScreen() const;
@@ -160,6 +165,7 @@ private:
     PixelFormat     mFormat;
     uint32_t        mFlags;
     mutable uint32_t mPageFlipCount;
+    String8         mDisplayName;
 
     /*
      * Can only accessed from the main thread, these members
index bdd8c67..27677d6 100644 (file)
@@ -159,7 +159,7 @@ sp<ISurfaceComposerClient> SurfaceFlinger::createConnection()
     return bclient;
 }
 
-sp<IBinder> SurfaceFlinger::createDisplay()
+sp<IBinder> SurfaceFlinger::createDisplay(const String8& displayName)
 {
     class DisplayToken : public BBinder {
         sp<SurfaceFlinger> flinger;
@@ -179,6 +179,7 @@ sp<IBinder> SurfaceFlinger::createDisplay()
 
     Mutex::Autolock _l(mStateLock);
     DisplayDeviceState info(DisplayDevice::DISPLAY_VIRTUAL);
+    info.displayName = displayName;
     mCurrentState.displays.add(token, info);
 
     return token;
@@ -573,7 +574,7 @@ void SurfaceFlinger::connectDisplay(const sp<ISurfaceTexture>& surface) {
     }
 
     if (token == 0) {
-        token = createDisplay();
+        token = createDisplay(String8("Display from connectDisplay"));
     }
 
     { // scope for the lock
@@ -1047,6 +1048,7 @@ void SurfaceFlinger::handleTransactionLocked(uint32_t transactionFlags)
                         hw->setLayerStack(state.layerStack);
                         hw->setProjection(state.orientation,
                                 state.viewport, state.frame);
+                        hw->setDisplayName(state.displayName);
                         mDisplays.add(display, hw);
                         if (hw->getDisplayType() < DisplayDevice::NUM_DISPLAY_TYPES) {
                             // notify the system that this display is now up
@@ -2019,14 +2021,16 @@ void SurfaceFlinger::dumpAllLocked(
      * Dump Display state
      */
 
+    snprintf(buffer, SIZE, "Displays (%d entries)\n", mDisplays.size());
+    result.append(buffer);
     for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) {
         const sp<const DisplayDevice>& hw(mDisplays[dpy]);
         snprintf(buffer, SIZE,
-                "+ DisplayDevice[%u]\n"
+                "+ DisplayDevice[%u] '%s'\n"
                 "   type=%x, layerStack=%u, (%4dx%4d), orient=%2d (type=%08x), "
                 "flips=%u, secure=%d, numLayers=%u, v:[%d,%d,%d,%d], f:[%d,%d,%d,%d], "
                 "transform:[[%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f]]\n",
-                dpy,
+                dpy, (const char*) hw->getDisplayName(),
                 hw->getDisplayType(), hw->getLayerStack(),
                 hw->getWidth(), hw->getHeight(),
                 hw->getOrientation(), hw->getTransform().getType(),
index a648621..e2bc69c 100644 (file)
@@ -173,6 +173,7 @@ private:
         Rect viewport;
         Rect frame;
         uint8_t orientation;
+        String8 displayName;
     };
 
     struct State {
@@ -192,7 +193,7 @@ private:
      */
     virtual sp<ISurfaceComposerClient> createConnection();
     virtual sp<IGraphicBufferAlloc> createGraphicBufferAlloc();
-    virtual sp<IBinder> createDisplay();
+    virtual sp<IBinder> createDisplay(const String8& displayName);
     virtual sp<IBinder> getBuiltInDisplay(int32_t id);
     virtual void setTransactionState(const Vector<ComposerState>& state,
             const Vector<DisplayState>& displays, uint32_t flags);