diff options
author | Jamie Gennis <jgennis@google.com> | 2012-08-23 20:19:38 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-08-24 11:12:28 -0700 |
commit | 0bceb84773882b796d9dacbaf96167cb15928d78 (patch) | |
tree | 736cce3bc182dc3a903754e258555a6fa99cb168 /services/surfaceflinger | |
parent | 490aee0fc5012acf2bf0b1dfe9c09e6fcca606fc (diff) | |
download | frameworks_native-0bceb84773882b796d9dacbaf96167cb15928d78.zip frameworks_native-0bceb84773882b796d9dacbaf96167cb15928d78.tar.gz frameworks_native-0bceb84773882b796d9dacbaf96167cb15928d78.tar.bz2 |
surfaceflinger: fix display id selection
This change fixes display ID selection so that it never chooses negative
numbers as display IDs.
Change-Id: I5af1acc7b1270b371595e096b18e2a6ad250c7ba
Diffstat (limited to 'services/surfaceflinger')
-rw-r--r-- | services/surfaceflinger/SurfaceFlinger.cpp | 21 | ||||
-rw-r--r-- | services/surfaceflinger/SurfaceFlinger.h | 5 |
2 files changed, 25 insertions, 1 deletions
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index e6e258f..7b070ba 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -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; diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h index 1f79906..754a2cc 100644 --- a/services/surfaceflinger/SurfaceFlinger.h +++ b/services/surfaceflinger/SurfaceFlinger.h @@ -364,6 +364,11 @@ private: } /* ------------------------------------------------------------------------ + * Display management + */ + int32_t chooseNewDisplayIdLocked() const; + + /* ------------------------------------------------------------------------ * Debugging & dumpsys */ void listLayersLocked(const Vector<String16>& args, size_t& index, |