2010-10-08 08:37:55 -07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <SkPixelRef.h>
|
|
|
|
#include "ResourceCache.h"
|
|
|
|
#include "Caches.h"
|
|
|
|
|
|
|
|
namespace android {
|
|
|
|
namespace uirenderer {
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Resource cache
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void ResourceCache::logCache() {
|
2011-12-20 16:23:08 +00:00
|
|
|
ALOGD("ResourceCache: cacheReport:");
|
2010-10-08 08:37:55 -07:00
|
|
|
for (size_t i = 0; i < mCache->size(); ++i) {
|
|
|
|
ResourceReference* ref = mCache->valueAt(i);
|
2011-12-20 16:23:08 +00:00
|
|
|
ALOGD(" ResourceCache: mCache(%d): resource, ref = 0x%p, 0x%p",
|
2010-10-08 08:37:55 -07:00
|
|
|
i, mCache->keyAt(i), mCache->valueAt(i));
|
2011-12-20 16:23:08 +00:00
|
|
|
ALOGD(" ResourceCache: mCache(%d): refCount, recycled, destroyed, type = %d, %d, %d, %d",
|
2010-10-08 08:37:55 -07:00
|
|
|
i, ref->refCount, ref->recycled, ref->destroyed, ref->resourceType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ResourceCache::ResourceCache() {
|
2010-11-11 16:30:16 -08:00
|
|
|
Mutex::Autolock _l(mLock);
|
2012-09-07 11:58:36 -07:00
|
|
|
mCache = new KeyedVector<void*, ResourceReference*>();
|
2010-10-08 08:37:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
ResourceCache::~ResourceCache() {
|
2010-11-11 16:30:16 -08:00
|
|
|
Mutex::Autolock _l(mLock);
|
2010-10-08 08:37:55 -07:00
|
|
|
delete mCache;
|
|
|
|
}
|
|
|
|
|
2012-09-07 11:58:36 -07:00
|
|
|
void ResourceCache::lock() {
|
|
|
|
mLock.lock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResourceCache::unlock() {
|
|
|
|
mLock.unlock();
|
|
|
|
}
|
|
|
|
|
2010-10-08 08:37:55 -07:00
|
|
|
void ResourceCache::incrementRefcount(void* resource, ResourceType resourceType) {
|
2010-11-11 16:30:16 -08:00
|
|
|
Mutex::Autolock _l(mLock);
|
2012-09-07 11:58:36 -07:00
|
|
|
incrementRefcountLocked(resource, resourceType);
|
2010-10-08 08:37:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ResourceCache::incrementRefcount(SkBitmap* bitmapResource) {
|
2011-02-22 13:55:04 -05:00
|
|
|
SkSafeRef(bitmapResource->pixelRef());
|
|
|
|
SkSafeRef(bitmapResource->getColorTable());
|
2012-05-15 11:10:01 -07:00
|
|
|
incrementRefcount((void*) bitmapResource, kBitmap);
|
2010-10-08 08:37:55 -07:00
|
|
|
}
|
|
|
|
|
2011-02-04 12:50:55 -08:00
|
|
|
void ResourceCache::incrementRefcount(SkPath* pathResource) {
|
2012-05-15 11:10:01 -07:00
|
|
|
incrementRefcount((void*) pathResource, kPath);
|
2011-02-04 12:50:55 -08:00
|
|
|
}
|
|
|
|
|
2010-10-08 08:37:55 -07:00
|
|
|
void ResourceCache::incrementRefcount(SkiaShader* shaderResource) {
|
2011-02-22 13:55:04 -05:00
|
|
|
SkSafeRef(shaderResource->getSkShader());
|
2011-01-14 18:51:01 -08:00
|
|
|
incrementRefcount((void*) shaderResource, kShader);
|
2010-10-08 08:37:55 -07:00
|
|
|
}
|
|
|
|
|
2010-10-22 16:17:12 -07:00
|
|
|
void ResourceCache::incrementRefcount(SkiaColorFilter* filterResource) {
|
2011-02-22 13:55:04 -05:00
|
|
|
SkSafeRef(filterResource->getSkColorFilter());
|
2011-01-14 18:51:01 -08:00
|
|
|
incrementRefcount((void*) filterResource, kColorFilter);
|
2010-10-22 16:17:12 -07:00
|
|
|
}
|
|
|
|
|
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
2012-09-14 15:31:25 -07:00
|
|
|
void ResourceCache::incrementRefcount(Layer* layerResource) {
|
|
|
|
incrementRefcount((void*) layerResource, kLayer);
|
|
|
|
}
|
|
|
|
|
2012-09-07 11:58:36 -07:00
|
|
|
void ResourceCache::incrementRefcountLocked(void* resource, ResourceType resourceType) {
|
2012-07-20 11:36:03 -07:00
|
|
|
ssize_t index = mCache->indexOfKey(resource);
|
|
|
|
ResourceReference* ref = index >= 0 ? mCache->valueAt(index) : NULL;
|
2012-09-07 11:58:36 -07:00
|
|
|
if (ref == NULL || mCache->size() == 0) {
|
|
|
|
ref = new ResourceReference(resourceType);
|
|
|
|
mCache->add(resource, ref);
|
2010-10-08 08:37:55 -07:00
|
|
|
}
|
2012-09-07 11:58:36 -07:00
|
|
|
ref->refCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResourceCache::incrementRefcountLocked(SkBitmap* bitmapResource) {
|
|
|
|
SkSafeRef(bitmapResource->pixelRef());
|
|
|
|
SkSafeRef(bitmapResource->getColorTable());
|
|
|
|
incrementRefcountLocked((void*) bitmapResource, kBitmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResourceCache::incrementRefcountLocked(SkPath* pathResource) {
|
|
|
|
incrementRefcountLocked((void*) pathResource, kPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResourceCache::incrementRefcountLocked(SkiaShader* shaderResource) {
|
|
|
|
SkSafeRef(shaderResource->getSkShader());
|
|
|
|
incrementRefcountLocked((void*) shaderResource, kShader);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResourceCache::incrementRefcountLocked(SkiaColorFilter* filterResource) {
|
|
|
|
SkSafeRef(filterResource->getSkColorFilter());
|
|
|
|
incrementRefcountLocked((void*) filterResource, kColorFilter);
|
|
|
|
}
|
|
|
|
|
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
2012-09-14 15:31:25 -07:00
|
|
|
void ResourceCache::incrementRefcountLocked(Layer* layerResource) {
|
|
|
|
incrementRefcountLocked((void*) layerResource, kLayer);
|
|
|
|
}
|
|
|
|
|
2012-09-07 11:58:36 -07:00
|
|
|
void ResourceCache::decrementRefcount(void* resource) {
|
|
|
|
Mutex::Autolock _l(mLock);
|
|
|
|
decrementRefcountLocked(resource);
|
2010-10-08 08:37:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ResourceCache::decrementRefcount(SkBitmap* bitmapResource) {
|
2011-02-22 13:55:04 -05:00
|
|
|
SkSafeUnref(bitmapResource->pixelRef());
|
|
|
|
SkSafeUnref(bitmapResource->getColorTable());
|
2011-01-14 18:51:01 -08:00
|
|
|
decrementRefcount((void*) bitmapResource);
|
2010-10-08 08:37:55 -07:00
|
|
|
}
|
|
|
|
|
2011-02-04 12:50:55 -08:00
|
|
|
void ResourceCache::decrementRefcount(SkPath* pathResource) {
|
|
|
|
decrementRefcount((void*) pathResource);
|
|
|
|
}
|
|
|
|
|
2010-10-08 08:37:55 -07:00
|
|
|
void ResourceCache::decrementRefcount(SkiaShader* shaderResource) {
|
2011-02-22 13:55:04 -05:00
|
|
|
SkSafeUnref(shaderResource->getSkShader());
|
2011-01-14 18:51:01 -08:00
|
|
|
decrementRefcount((void*) shaderResource);
|
2010-10-08 08:37:55 -07:00
|
|
|
}
|
|
|
|
|
2010-10-22 16:17:12 -07:00
|
|
|
void ResourceCache::decrementRefcount(SkiaColorFilter* filterResource) {
|
2011-02-22 13:55:04 -05:00
|
|
|
SkSafeUnref(filterResource->getSkColorFilter());
|
2011-01-14 18:51:01 -08:00
|
|
|
decrementRefcount((void*) filterResource);
|
2010-10-22 16:17:12 -07:00
|
|
|
}
|
|
|
|
|
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
2012-09-14 15:31:25 -07:00
|
|
|
void ResourceCache::decrementRefcount(Layer* layerResource) {
|
|
|
|
decrementRefcount((void*) layerResource);
|
|
|
|
}
|
|
|
|
|
2012-09-07 11:58:36 -07:00
|
|
|
void ResourceCache::decrementRefcountLocked(void* resource) {
|
2012-07-20 11:36:03 -07:00
|
|
|
ssize_t index = mCache->indexOfKey(resource);
|
2012-09-07 11:58:36 -07:00
|
|
|
ResourceReference* ref = index >= 0 ? mCache->valueAt(index) : NULL;
|
2010-10-08 08:37:55 -07:00
|
|
|
if (ref == NULL) {
|
2012-09-07 11:58:36 -07:00
|
|
|
// Should not get here - shouldn't get a call to decrement if we're not yet tracking it
|
2010-10-08 08:37:55 -07:00
|
|
|
return;
|
|
|
|
}
|
2012-09-07 11:58:36 -07:00
|
|
|
ref->refCount--;
|
2010-10-08 08:37:55 -07:00
|
|
|
if (ref->refCount == 0) {
|
|
|
|
deleteResourceReference(resource, ref);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-07 11:58:36 -07:00
|
|
|
void ResourceCache::decrementRefcountLocked(SkBitmap* bitmapResource) {
|
|
|
|
SkSafeUnref(bitmapResource->pixelRef());
|
|
|
|
SkSafeUnref(bitmapResource->getColorTable());
|
|
|
|
decrementRefcountLocked((void*) bitmapResource);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResourceCache::decrementRefcountLocked(SkPath* pathResource) {
|
|
|
|
decrementRefcountLocked((void*) pathResource);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResourceCache::decrementRefcountLocked(SkiaShader* shaderResource) {
|
|
|
|
SkSafeUnref(shaderResource->getSkShader());
|
|
|
|
decrementRefcountLocked((void*) shaderResource);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResourceCache::decrementRefcountLocked(SkiaColorFilter* filterResource) {
|
|
|
|
SkSafeUnref(filterResource->getSkColorFilter());
|
|
|
|
decrementRefcountLocked((void*) filterResource);
|
|
|
|
}
|
|
|
|
|
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
2012-09-14 15:31:25 -07:00
|
|
|
void ResourceCache::decrementRefcountLocked(Layer* layerResource) {
|
|
|
|
decrementRefcountLocked((void*) layerResource);
|
|
|
|
}
|
|
|
|
|
2011-02-04 12:50:55 -08:00
|
|
|
void ResourceCache::destructor(SkPath* resource) {
|
|
|
|
Mutex::Autolock _l(mLock);
|
2012-09-07 11:58:36 -07:00
|
|
|
destructorLocked(resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResourceCache::destructorLocked(SkPath* resource) {
|
2012-07-20 11:36:03 -07:00
|
|
|
ssize_t index = mCache->indexOfKey(resource);
|
|
|
|
ResourceReference* ref = index >= 0 ? mCache->valueAt(index) : NULL;
|
2011-02-04 12:50:55 -08:00
|
|
|
if (ref == NULL) {
|
|
|
|
// If we're not tracking this resource, just delete it
|
|
|
|
if (Caches::hasInstance()) {
|
|
|
|
Caches::getInstance().pathCache.removeDeferred(resource);
|
|
|
|
}
|
|
|
|
delete resource;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ref->destroyed = true;
|
|
|
|
if (ref->refCount == 0) {
|
|
|
|
deleteResourceReference(resource, ref);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-08 08:37:55 -07:00
|
|
|
void ResourceCache::destructor(SkBitmap* resource) {
|
2010-11-11 16:30:16 -08:00
|
|
|
Mutex::Autolock _l(mLock);
|
2012-09-07 11:58:36 -07:00
|
|
|
destructorLocked(resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResourceCache::destructorLocked(SkBitmap* resource) {
|
2012-07-20 11:36:03 -07:00
|
|
|
ssize_t index = mCache->indexOfKey(resource);
|
|
|
|
ResourceReference* ref = index >= 0 ? mCache->valueAt(index) : NULL;
|
2010-10-08 08:37:55 -07:00
|
|
|
if (ref == NULL) {
|
|
|
|
// If we're not tracking this resource, just delete it
|
|
|
|
if (Caches::hasInstance()) {
|
2010-11-11 15:36:56 -08:00
|
|
|
Caches::getInstance().textureCache.removeDeferred(resource);
|
2010-10-08 08:37:55 -07:00
|
|
|
}
|
|
|
|
delete resource;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ref->destroyed = true;
|
|
|
|
if (ref->refCount == 0) {
|
|
|
|
deleteResourceReference(resource, ref);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResourceCache::destructor(SkiaShader* resource) {
|
2010-11-11 16:30:16 -08:00
|
|
|
Mutex::Autolock _l(mLock);
|
2012-09-07 11:58:36 -07:00
|
|
|
destructorLocked(resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResourceCache::destructorLocked(SkiaShader* resource) {
|
2012-07-20 11:36:03 -07:00
|
|
|
ssize_t index = mCache->indexOfKey(resource);
|
|
|
|
ResourceReference* ref = index >= 0 ? mCache->valueAt(index) : NULL;
|
2010-10-08 08:37:55 -07:00
|
|
|
if (ref == NULL) {
|
|
|
|
// If we're not tracking this resource, just delete it
|
|
|
|
delete resource;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ref->destroyed = true;
|
|
|
|
if (ref->refCount == 0) {
|
|
|
|
deleteResourceReference(resource, ref);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-22 16:17:12 -07:00
|
|
|
void ResourceCache::destructor(SkiaColorFilter* resource) {
|
2010-11-11 16:30:16 -08:00
|
|
|
Mutex::Autolock _l(mLock);
|
2012-09-07 11:58:36 -07:00
|
|
|
destructorLocked(resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResourceCache::destructorLocked(SkiaColorFilter* resource) {
|
2012-07-20 11:36:03 -07:00
|
|
|
ssize_t index = mCache->indexOfKey(resource);
|
|
|
|
ResourceReference* ref = index >= 0 ? mCache->valueAt(index) : NULL;
|
2010-10-22 16:17:12 -07:00
|
|
|
if (ref == NULL) {
|
|
|
|
// If we're not tracking this resource, just delete it
|
|
|
|
delete resource;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ref->destroyed = true;
|
|
|
|
if (ref->refCount == 0) {
|
|
|
|
deleteResourceReference(resource, ref);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-07 11:58:36 -07:00
|
|
|
void ResourceCache::recycle(SkBitmap* resource) {
|
|
|
|
Mutex::Autolock _l(mLock);
|
|
|
|
recycleLocked(resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResourceCache::recycleLocked(SkBitmap* resource) {
|
|
|
|
ssize_t index = mCache->indexOfKey(resource);
|
|
|
|
if (index < 0) {
|
|
|
|
// not tracking this resource; just recycle the pixel data
|
|
|
|
resource->setPixels(NULL, NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ResourceReference* ref = mCache->valueAt(index);
|
|
|
|
if (ref == NULL) {
|
|
|
|
// Should not get here - shouldn't get a call to recycle if we're not yet tracking it
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ref->recycled = true;
|
|
|
|
if (ref->refCount == 0) {
|
|
|
|
deleteResourceReference(resource, ref);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-11 16:30:16 -08:00
|
|
|
/**
|
|
|
|
* This method should only be called while the mLock mutex is held (that mutex is grabbed
|
|
|
|
* by the various destructor() and recycle() methods which call this method).
|
|
|
|
*/
|
2010-10-08 08:37:55 -07:00
|
|
|
void ResourceCache::deleteResourceReference(void* resource, ResourceReference* ref) {
|
|
|
|
if (ref->recycled && ref->resourceType == kBitmap) {
|
|
|
|
((SkBitmap*) resource)->setPixels(NULL, NULL);
|
|
|
|
}
|
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
2012-09-14 15:31:25 -07:00
|
|
|
if (ref->destroyed || ref->resourceType == kLayer) {
|
2010-10-08 08:37:55 -07:00
|
|
|
switch (ref->resourceType) {
|
2011-06-22 16:14:36 -07:00
|
|
|
case kBitmap: {
|
|
|
|
SkBitmap* bitmap = (SkBitmap*) resource;
|
2010-10-08 08:37:55 -07:00
|
|
|
if (Caches::hasInstance()) {
|
2010-11-11 15:36:56 -08:00
|
|
|
Caches::getInstance().textureCache.removeDeferred(bitmap);
|
2010-10-08 08:37:55 -07:00
|
|
|
}
|
|
|
|
delete bitmap;
|
|
|
|
}
|
|
|
|
break;
|
2011-06-22 16:14:36 -07:00
|
|
|
case kPath: {
|
|
|
|
SkPath* path = (SkPath*) resource;
|
2011-02-04 12:50:55 -08:00
|
|
|
if (Caches::hasInstance()) {
|
|
|
|
Caches::getInstance().pathCache.removeDeferred(path);
|
|
|
|
}
|
|
|
|
delete path;
|
|
|
|
}
|
|
|
|
break;
|
2011-06-22 16:14:36 -07:00
|
|
|
case kShader: {
|
|
|
|
SkiaShader* shader = (SkiaShader*) resource;
|
2010-10-08 08:37:55 -07:00
|
|
|
delete shader;
|
2010-10-22 16:17:12 -07:00
|
|
|
}
|
|
|
|
break;
|
2011-06-22 16:14:36 -07:00
|
|
|
case kColorFilter: {
|
|
|
|
SkiaColorFilter* filter = (SkiaColorFilter*) resource;
|
2010-10-22 16:17:12 -07:00
|
|
|
delete filter;
|
|
|
|
}
|
|
|
|
break;
|
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
2012-09-14 15:31:25 -07:00
|
|
|
case kLayer: {
|
|
|
|
Layer* layer = (Layer*) resource;
|
|
|
|
delete layer;
|
|
|
|
}
|
|
|
|
break;
|
2010-10-08 08:37:55 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
mCache->removeItem(resource);
|
|
|
|
delete ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
}; // namespace uirenderer
|
|
|
|
}; // namespace android
|