From 0bceb84773882b796d9dacbaf96167cb15928d78 Mon Sep 17 00:00:00 2001 From: Jamie Gennis Date: Thu, 23 Aug 2012 20:19:38 -0700 Subject: [PATCH] surfaceflinger: fix display id selection This change fixes display ID selection so that it never chooses negative numbers as display IDs. Change-Id: I5af1acc7b1270b371595e096b18e2a6ad250c7ba --- services/surfaceflinger/SurfaceFlinger.cpp | 21 ++++++++++++++++++++- services/surfaceflinger/SurfaceFlinger.h | 5 +++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index e6e258f4e..7b070bac9 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -162,6 +162,24 @@ sp 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 SurfaceFlinger::createDisplay() { class DisplayToken : public BBinder { @@ -181,7 +199,8 @@ sp SurfaceFlinger::createDisplay() sp 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 1f799068d..754a2cc20 100644 --- a/services/surfaceflinger/SurfaceFlinger.h +++ b/services/surfaceflinger/SurfaceFlinger.h @@ -363,6 +363,11 @@ private: return mProtectedTexName; } + /* ------------------------------------------------------------------------ + * Display management + */ + int32_t chooseNewDisplayIdLocked() const; + /* ------------------------------------------------------------------------ * Debugging & dumpsys */