diff options
author | Dan Stoza | 2015-04-30 15:29:25 -0500 |
---|---|---|
committer | Dan Stoza | 2015-04-30 16:29:30 -0500 |
commit | e7f8dde3f3c398c1ea1bec14e76725a760f71d31 (patch) | |
tree | dc6efec8d9882d68e3ade36567e6d2f01d5cdac3 /services | |
parent | 8de71a2408f632407c25942a39c31f78c7f64ffd (diff) | |
download | frameworks-native-e7f8dde3f3c398c1ea1bec14e76725a760f71d31.tar.gz frameworks-native-e7f8dde3f3c398c1ea1bec14e76725a760f71d31.tar.xz frameworks-native-e7f8dde3f3c398c1ea1bec14e76725a760f71d31.zip |
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
Diffstat (limited to 'services')
-rw-r--r-- | services/surfaceflinger/SurfaceFlinger.cpp | 29 | ||||
-rw-r--r-- | services/surfaceflinger/SurfaceFlinger.h | 4 |
2 files changed, 24 insertions, 9 deletions
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index df4ac2e66..715b92f11 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp | |||
@@ -1994,18 +1994,25 @@ void SurfaceFlinger::drawWormhole(const sp<const DisplayDevice>& hw, const Regio | |||
1994 | engine.fillRegionWithColor(region, height, 0, 0, 0, 0); | 1994 | engine.fillRegionWithColor(region, height, 0, 0, 0, 0); |
1995 | } | 1995 | } |
1996 | 1996 | ||
1997 | void SurfaceFlinger::addClientLayer(const sp<Client>& client, | 1997 | status_t SurfaceFlinger::addClientLayer(const sp<Client>& client, |
1998 | const sp<IBinder>& handle, | 1998 | const sp<IBinder>& handle, |
1999 | const sp<IGraphicBufferProducer>& gbc, | 1999 | const sp<IGraphicBufferProducer>& gbc, |
2000 | const sp<Layer>& lbc) | 2000 | const sp<Layer>& lbc) |
2001 | { | 2001 | { |
2002 | // add this layer to the current state list | ||
2003 | { | ||
2004 | Mutex::Autolock _l(mStateLock); | ||
2005 | if (mCurrentState.layersSortedByZ.size() >= MAX_LAYERS) { | ||
2006 | return NO_MEMORY; | ||
2007 | } | ||
2008 | mCurrentState.layersSortedByZ.add(lbc); | ||
2009 | mGraphicBufferProducerList.add(IInterface::asBinder(gbc)); | ||
2010 | } | ||
2011 | |||
2002 | // attach this layer to the client | 2012 | // attach this layer to the client |
2003 | client->attachLayer(handle, lbc); | 2013 | client->attachLayer(handle, lbc); |
2004 | 2014 | ||
2005 | // add this layer to the current state list | 2015 | return NO_ERROR; |
2006 | Mutex::Autolock _l(mStateLock); | ||
2007 | mCurrentState.layersSortedByZ.add(lbc); | ||
2008 | mGraphicBufferProducerList.add(IInterface::asBinder(gbc)); | ||
2009 | } | 2016 | } |
2010 | 2017 | ||
2011 | status_t SurfaceFlinger::removeLayer(const sp<Layer>& layer) { | 2018 | status_t SurfaceFlinger::removeLayer(const sp<Layer>& layer) { |
@@ -2262,10 +2269,16 @@ status_t SurfaceFlinger::createLayer( | |||
2262 | break; | 2269 | break; |
2263 | } | 2270 | } |
2264 | 2271 | ||
2265 | if (result == NO_ERROR) { | 2272 | if (result != NO_ERROR) { |
2266 | addClientLayer(client, *handle, *gbp, layer); | 2273 | return result; |
2267 | setTransactionFlags(eTransactionNeeded); | ||
2268 | } | 2274 | } |
2275 | |||
2276 | result = addClientLayer(client, *handle, *gbp, layer); | ||
2277 | if (result != NO_ERROR) { | ||
2278 | return result; | ||
2279 | } | ||
2280 | |||
2281 | setTransactionFlags(eTransactionNeeded); | ||
2269 | return result; | 2282 | return result; |
2270 | } | 2283 | } |
2271 | 2284 | ||
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h index a06d1be1b..74f903148 100644 --- a/services/surfaceflinger/SurfaceFlinger.h +++ b/services/surfaceflinger/SurfaceFlinger.h | |||
@@ -144,6 +144,8 @@ private: | |||
144 | // every half hour. | 144 | // every half hour. |
145 | enum { LOG_FRAME_STATS_PERIOD = 30*60*60 }; | 145 | enum { LOG_FRAME_STATS_PERIOD = 30*60*60 }; |
146 | 146 | ||
147 | static const size_t MAX_LAYERS = 4096; | ||
148 | |||
147 | // We're reference counted, never destroy SurfaceFlinger directly | 149 | // We're reference counted, never destroy SurfaceFlinger directly |
148 | virtual ~SurfaceFlinger(); | 150 | virtual ~SurfaceFlinger(); |
149 | 151 | ||
@@ -305,7 +307,7 @@ private: | |||
305 | status_t removeLayer(const sp<Layer>& layer); | 307 | status_t removeLayer(const sp<Layer>& layer); |
306 | 308 | ||
307 | // add a layer to SurfaceFlinger | 309 | // add a layer to SurfaceFlinger |
308 | void addClientLayer(const sp<Client>& client, | 310 | status_t addClientLayer(const sp<Client>& client, |
309 | const sp<IBinder>& handle, | 311 | const sp<IBinder>& handle, |
310 | const sp<IGraphicBufferProducer>& gbc, | 312 | const sp<IGraphicBufferProducer>& gbc, |
311 | const sp<Layer>& lbc); | 313 | const sp<Layer>& lbc); |