summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Cody Northrop <cnorthrop@google.com> 2017-03-31 12:00:08 -0600
committer Cody Northrop <cnorthrop@google.com> 2017-03-31 16:05:33 -0600
commitbc7552874052ee33f1b35b4474e20c003d216391 (patch)
tree9bd2f17d91d6999b8ad82405d897e29e7f2962a1
parent34ca5f2ab8cc891957567915def5bc32a36e6d82 (diff)
surfaceflinger: Generate unique layer names
Add a counter to layer names to make it clear when there are duplicates. layer foo#0 layer foo#1 layer bar#0 layer bar#1 layer bar#2 Bug: b/32543755 Test: Build, install, run game with duplicate layers, see unique names. Change-Id: I915531d7adbdc506c429b86a685665fb6c56d25e
-rw-r--r--services/surfaceflinger/SurfaceFlinger.cpp30
-rw-r--r--services/surfaceflinger/SurfaceFlinger.h2
-rw-r--r--services/surfaceflinger/SurfaceFlinger_hwc1.cpp30
3 files changed, 58 insertions, 4 deletions
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index f82b363cb5..0f6b39713e 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -2839,15 +2839,17 @@ status_t SurfaceFlinger::createLayer(
sp<Layer> layer;
+ String8 uniqueName = getUniqueLayerName(name);
+
switch (flags & ISurfaceComposerClient::eFXSurfaceMask) {
case ISurfaceComposerClient::eFXSurfaceNormal:
result = createNormalLayer(client,
- name, w, h, flags, format,
+ uniqueName, w, h, flags, format,
handle, gbp, &layer);
break;
case ISurfaceComposerClient::eFXSurfaceDim:
result = createDimLayer(client,
- name, w, h, flags,
+ uniqueName, w, h, flags,
handle, gbp, &layer);
break;
default:
@@ -2871,6 +2873,30 @@ status_t SurfaceFlinger::createLayer(
return result;
}
+String8 SurfaceFlinger::getUniqueLayerName(const String8& name)
+{
+ bool matchFound = true;
+ uint32_t dupeCounter = 0;
+
+ // Tack on our counter whether there is a hit or not, so everyone gets a tag
+ String8 uniqueName = name + "#" + String8(std::to_string(dupeCounter).c_str());
+
+ // Loop over layers until we're sure there is no matching name
+ while (matchFound) {
+ matchFound = false;
+ mDrawingState.traverseInZOrder([&](Layer* layer) {
+ if (layer->getName() == uniqueName) {
+ matchFound = true;
+ uniqueName = name + "#" + String8(std::to_string(++dupeCounter).c_str());
+ }
+ });
+ }
+
+ ALOGD_IF(dupeCounter > 0, "duplicate layer name: changing %s to %s", name.c_str(), uniqueName.c_str());
+
+ return uniqueName;
+}
+
status_t SurfaceFlinger::createNormalLayer(const sp<Client>& client,
const String8& name, uint32_t w, uint32_t h, uint32_t flags, PixelFormat& format,
sp<IBinder>* handle, sp<IGraphicBufferProducer>* gbp, sp<Layer>* outLayer)
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index 581bbfdede..4ecbddd9a2 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -364,6 +364,8 @@ private:
uint32_t w, uint32_t h, uint32_t flags, sp<IBinder>* outHandle,
sp<IGraphicBufferProducer>* outGbp, sp<Layer>* outLayer);
+ String8 getUniqueLayerName(const String8& name);
+
// called in response to the window-manager calling
// ISurfaceComposerClient::destroySurface()
status_t onLayerRemoved(const sp<Client>& client, const sp<IBinder>& handle);
diff --git a/services/surfaceflinger/SurfaceFlinger_hwc1.cpp b/services/surfaceflinger/SurfaceFlinger_hwc1.cpp
index c26847f927..a6c0b9c686 100644
--- a/services/surfaceflinger/SurfaceFlinger_hwc1.cpp
+++ b/services/surfaceflinger/SurfaceFlinger_hwc1.cpp
@@ -2637,15 +2637,17 @@ status_t SurfaceFlinger::createLayer(
sp<Layer> layer;
+ String8 uniqueName = getUniqueLayerName(name);
+
switch (flags & ISurfaceComposerClient::eFXSurfaceMask) {
case ISurfaceComposerClient::eFXSurfaceNormal:
result = createNormalLayer(client,
- name, w, h, flags, format,
+ uniqueName, w, h, flags, format,
handle, gbp, &layer);
break;
case ISurfaceComposerClient::eFXSurfaceDim:
result = createDimLayer(client,
- name, w, h, flags,
+ uniqueName, w, h, flags,
handle, gbp, &layer);
break;
default:
@@ -2669,6 +2671,30 @@ status_t SurfaceFlinger::createLayer(
return result;
}
+String8 SurfaceFlinger::getUniqueLayerName(const String8& name)
+{
+ bool matchFound = true;
+ uint32_t dupeCounter = 0;
+
+ // Tack on our counter whether there is a hit or not, so everyone gets a tag
+ String8 uniqueName = name + "#" + String8(std::to_string(dupeCounter).c_str());
+
+ // Loop over layers until we're sure there is no matching name
+ while (matchFound) {
+ matchFound = false;
+ mDrawingState.traverseInZOrder([&](Layer* layer) {
+ if (layer->getName() == uniqueName) {
+ matchFound = true;
+ uniqueName = name + "#" + String8(std::to_string(++dupeCounter).c_str());
+ }
+ });
+ }
+
+ ALOGD_IF(dupeCounter > 0, "duplicate layer name: changing %s to %s", name.c_str(), uniqueName.c_str());
+
+ return uniqueName;
+}
+
status_t SurfaceFlinger::createNormalLayer(const sp<Client>& client,
const String8& name, uint32_t w, uint32_t h, uint32_t flags, PixelFormat& format,
sp<IBinder>* handle, sp<IGraphicBufferProducer>* gbp, sp<Layer>* outLayer)