OSDN Git Service

surfaceflinger: fix display id selection
authorJamie Gennis <jgennis@google.com>
Fri, 24 Aug 2012 03:19:38 +0000 (20:19 -0700)
committerAndroid (Google) Code Review <android-gerrit@google.com>
Fri, 24 Aug 2012 18:12:28 +0000 (11:12 -0700)
This change fixes display ID selection so that it never chooses negative
numbers as display IDs.

Change-Id: I5af1acc7b1270b371595e096b18e2a6ad250c7ba

services/surfaceflinger/SurfaceFlinger.cpp
services/surfaceflinger/SurfaceFlinger.h

index e6e258f..7b070ba 100644 (file)
@@ -162,6 +162,24 @@ sp<ISurfaceComposerClient> SurfaceFlinger::createConnection()
     return bclient;
 }
 
+int32_t SurfaceFlinger::chooseNewDisplayIdLocked() const
+{
+    int32_t id = DisplayDevice::DISPLAY_ID_COUNT - 1;
+    bool available;
+    do {
+        id++;
+        available = true;
+        for (size_t i = 0; i < mCurrentState.displays.size(); i++) {
+            const DisplayDeviceState& dds(mCurrentState.displays.valueAt(i));
+            if (dds.id == id) {
+                available = false;
+                break;
+            }
+        }
+    } while (!available);
+    return id;
+}
+
 sp<IBinder> SurfaceFlinger::createDisplay()
 {
     class DisplayToken : public BBinder {
@@ -181,7 +199,8 @@ sp<IBinder> SurfaceFlinger::createDisplay()
     sp<BBinder> token = new DisplayToken(this);
 
     Mutex::Autolock _l(mStateLock);
-    DisplayDeviceState info(intptr_t(token.get())); // FIXME: we shouldn't use the address for the id
+    int32_t id = chooseNewDisplayIdLocked();
+    DisplayDeviceState info(id);
     mCurrentState.displays.add(token, info);
 
     return token;
index 1f79906..754a2cc 100644 (file)
@@ -364,6 +364,11 @@ private:
     }
 
     /* ------------------------------------------------------------------------
+     * Display management
+     */
+    int32_t chooseNewDisplayIdLocked() const;
+
+    /* ------------------------------------------------------------------------
      * Debugging & dumpsys
      */
     void listLayersLocked(const Vector<String16>& args, size_t& index,