summaryrefslogtreecommitdiffstats
path: root/services/surfaceflinger/SurfaceFlinger.cpp
diff options
context:
space:
mode:
authorDan Stoza <stoza@google.com>2015-04-30 13:29:25 -0700
committerDan Stoza <stoza@google.com>2015-04-30 15:10:00 -0700
commit7d89d06a6fe1bfadfe277f19dbb7e4aa021444e0 (patch)
treee4bc2cff57d40c689c8b325a94f67ce02883e381 /services/surfaceflinger/SurfaceFlinger.cpp
parent84f1d9c288f35fa399f97207b6af43a261d5989a (diff)
downloadframeworks_native-7d89d06a6fe1bfadfe277f19dbb7e4aa021444e0.zip
frameworks_native-7d89d06a6fe1bfadfe277f19dbb7e4aa021444e0.tar.gz
frameworks_native-7d89d06a6fe1bfadfe277f19dbb7e4aa021444e0.tar.bz2
SurfaceFlinger: Limit to 4k Layers
Sets a limit of 4k Layers which SurfaceFlinger will allow to be in existence at any given time. An attempt to create Layers in excess of this limit will fail with NO_MEMORY. Bug: 20674586 Change-Id: I2dfaf59643d826f982b2fa44e8a9ed643176d972 (cherry picked from commit e7f8dde3f3c398c1ea1bec14e76725a760f71d31)
Diffstat (limited to 'services/surfaceflinger/SurfaceFlinger.cpp')
-rw-r--r--services/surfaceflinger/SurfaceFlinger.cpp29
1 files changed, 21 insertions, 8 deletions
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 1419557..0d57ae5 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -2018,18 +2018,25 @@ void SurfaceFlinger::drawWormhole(const sp<const DisplayDevice>& hw, const Regio
engine.fillRegionWithColor(region, height, 0, 0, 0, 0);
}
-void SurfaceFlinger::addClientLayer(const sp<Client>& client,
+status_t SurfaceFlinger::addClientLayer(const sp<Client>& client,
const sp<IBinder>& handle,
const sp<IGraphicBufferProducer>& gbc,
const sp<Layer>& lbc)
{
+ // add this layer to the current state list
+ {
+ Mutex::Autolock _l(mStateLock);
+ if (mCurrentState.layersSortedByZ.size() >= MAX_LAYERS) {
+ return NO_MEMORY;
+ }
+ mCurrentState.layersSortedByZ.add(lbc);
+ mGraphicBufferProducerList.add(IInterface::asBinder(gbc));
+ }
+
// attach this layer to the client
client->attachLayer(handle, lbc);
- // add this layer to the current state list
- Mutex::Autolock _l(mStateLock);
- mCurrentState.layersSortedByZ.add(lbc);
- mGraphicBufferProducerList.add(IInterface::asBinder(gbc));
+ return NO_ERROR;
}
status_t SurfaceFlinger::removeLayer(const sp<Layer>& layer) {
@@ -2286,10 +2293,16 @@ status_t SurfaceFlinger::createLayer(
break;
}
- if (result == NO_ERROR) {
- addClientLayer(client, *handle, *gbp, layer);
- setTransactionFlags(eTransactionNeeded);
+ if (result != NO_ERROR) {
+ return result;
}
+
+ result = addClientLayer(client, *handle, *gbp, layer);
+ if (result != NO_ERROR) {
+ return result;
+ }
+
+ setTransactionFlags(eTransactionNeeded);
return result;
}