diff options
author | Chet Haase <chet@google.com> | 2012-09-14 15:31:25 -0700 |
---|---|---|
committer | Chet Haase <chet@google.com> | 2012-09-17 11:21:34 -0700 |
commit | 603f6de35f21d74ae242d52d501f4f5c25ff4f4c (patch) | |
tree | b249a7750a60b445a43670b7ba540beecbe715db /libs/hwui/DisplayListRenderer.cpp | |
parent | cc5dd18d15a174799ad79d26633c268e8860c8ab (diff) | |
download | frameworks_base-603f6de35f21d74ae242d52d501f4f5c25ff4f4c.zip frameworks_base-603f6de35f21d74ae242d52d501f4f5c25ff4f4c.tar.gz frameworks_base-603f6de35f21d74ae242d52d501f4f5c25ff4f4c.tar.bz2 |
Fix occasional crash bug with layers
Launcher occasionally crashes with a stack trace indicating that the memory
of a Layer object is corrupt. It is possible for us to delete a Layer
structure and then, briefly, use it to draw a DisplayList again before
that DisplayList gets recreated (without the layer that got deleted).
When this happens, if the memory got corrupted, it's possible to crash.
The fix is to add Layer to the other objects which we currently refcount
(bitmaps, shaders, etc.). Then instead of deleting a Layer, we decrement the
refcount. We increment when creating it, then increment it again when it's
referenced from a DisplayList. Then we decrement the refcount instead of
deleting it, and decrement when we clear a DisplayList that refers to it.
Then when the refcount reaches 0, we delete it.
Issue #6994632 Native crash in launcher when trying to launch all apps screen
Change-Id: I0627be8d49bb2f9ba8d158a84b764bb4e7df934c
Diffstat (limited to 'libs/hwui/DisplayListRenderer.cpp')
-rw-r--r-- | libs/hwui/DisplayListRenderer.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/libs/hwui/DisplayListRenderer.cpp b/libs/hwui/DisplayListRenderer.cpp index c3444e6..cc72df6 100644 --- a/libs/hwui/DisplayListRenderer.cpp +++ b/libs/hwui/DisplayListRenderer.cpp @@ -182,6 +182,10 @@ void DisplayList::clearResources() { caches.resourceCache.decrementRefcountLocked(mSourcePaths.itemAt(i)); } + for (size_t i = 0; i < mLayers.size(); i++) { + caches.resourceCache.decrementRefcountLocked(mLayers.itemAt(i)); + } + caches.resourceCache.unlock(); for (size_t i = 0; i < mPaints.size(); i++) { @@ -206,6 +210,7 @@ void DisplayList::clearResources() { mPaints.clear(); mPaths.clear(); mMatrices.clear(); + mLayers.clear(); } void DisplayList::initFromDisplayListRenderer(const DisplayListRenderer& recorder, bool reusing) { @@ -264,6 +269,12 @@ void DisplayList::initFromDisplayListRenderer(const DisplayListRenderer& recorde caches.resourceCache.incrementRefcountLocked(sourcePaths.itemAt(i)); } + const Vector<Layer*>& layers = recorder.getLayers(); + for (size_t i = 0; i < layers.size(); i++) { + mLayers.add(layers.itemAt(i)); + caches.resourceCache.incrementRefcountLocked(layers.itemAt(i)); + } + caches.resourceCache.unlock(); const Vector<SkPaint*>& paints = recorder.getPaints(); @@ -1361,6 +1372,10 @@ void DisplayListRenderer::reset() { mCaches.resourceCache.decrementRefcountLocked(mSourcePaths.itemAt(i)); } + for (size_t i = 0; i < mLayers.size(); i++) { + mCaches.resourceCache.decrementRefcountLocked(mLayers.itemAt(i)); + } + mCaches.resourceCache.unlock(); mBitmapResources.clear(); @@ -1379,6 +1394,8 @@ void DisplayListRenderer::reset() { mMatrices.clear(); + mLayers.clear(); + mHasDrawOps = false; } @@ -1539,7 +1556,7 @@ status_t DisplayListRenderer::drawDisplayList(DisplayList* displayList, status_t DisplayListRenderer::drawLayer(Layer* layer, float x, float y, SkPaint* paint) { addOp(DisplayList::DrawLayer); - addInt((int) layer); + addLayer(layer); addPoint(x, y); addPaint(paint); return DrawGlInfo::kStatusDone; |