am 74261d84: Merge "Don\'t null the reference to Bitmap pixels until we\'re really ready" into jb-mr1-dev
* commit '74261d847f64ccfeba0a7f08f6c59473a3b6647d': Don't null the reference to Bitmap pixels until we're really ready
This commit is contained in:
@@ -261,14 +261,14 @@ static void Bitmap_destructor(JNIEnv* env, jobject, SkBitmap* bitmap) {
|
|||||||
delete bitmap;
|
delete bitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Bitmap_recycle(JNIEnv* env, jobject, SkBitmap* bitmap) {
|
static jboolean Bitmap_recycle(JNIEnv* env, jobject, SkBitmap* bitmap) {
|
||||||
#ifdef USE_OPENGL_RENDERER
|
#ifdef USE_OPENGL_RENDERER
|
||||||
if (android::uirenderer::Caches::hasInstance()) {
|
if (android::uirenderer::Caches::hasInstance()) {
|
||||||
android::uirenderer::Caches::getInstance().resourceCache.recycle(bitmap);
|
return android::uirenderer::Caches::getInstance().resourceCache.recycle(bitmap);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
#endif // USE_OPENGL_RENDERER
|
#endif // USE_OPENGL_RENDERER
|
||||||
bitmap->setPixels(NULL, NULL);
|
bitmap->setPixels(NULL, NULL);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// These must match the int values in Bitmap.java
|
// These must match the int values in Bitmap.java
|
||||||
@@ -665,7 +665,7 @@ static JNINativeMethod gBitmapMethods[] = {
|
|||||||
{ "nativeCopy", "(IIZ)Landroid/graphics/Bitmap;",
|
{ "nativeCopy", "(IIZ)Landroid/graphics/Bitmap;",
|
||||||
(void*)Bitmap_copy },
|
(void*)Bitmap_copy },
|
||||||
{ "nativeDestructor", "(I)V", (void*)Bitmap_destructor },
|
{ "nativeDestructor", "(I)V", (void*)Bitmap_destructor },
|
||||||
{ "nativeRecycle", "(I)V", (void*)Bitmap_recycle },
|
{ "nativeRecycle", "(I)Z", (void*)Bitmap_recycle },
|
||||||
{ "nativeCompress", "(IIILjava/io/OutputStream;[B)Z",
|
{ "nativeCompress", "(IIILjava/io/OutputStream;[B)Z",
|
||||||
(void*)Bitmap_compress },
|
(void*)Bitmap_compress },
|
||||||
{ "nativeErase", "(II)V", (void*)Bitmap_erase },
|
{ "nativeErase", "(II)V", (void*)Bitmap_erase },
|
||||||
|
|||||||
@@ -201,9 +201,14 @@ public final class Bitmap implements Parcelable {
|
|||||||
*/
|
*/
|
||||||
public void recycle() {
|
public void recycle() {
|
||||||
if (!mRecycled) {
|
if (!mRecycled) {
|
||||||
|
if (nativeRecycle(mNativeBitmap)) {
|
||||||
|
// return value indicates whether native pixel object was actually recycled.
|
||||||
|
// false indicates that it is still in use at the native level and these
|
||||||
|
// objects should not be collected now. They will be collected later when the
|
||||||
|
// Bitmap itself is collected.
|
||||||
mBuffer = null;
|
mBuffer = null;
|
||||||
nativeRecycle(mNativeBitmap);
|
|
||||||
mNinePatchChunk = null;
|
mNinePatchChunk = null;
|
||||||
|
}
|
||||||
mRecycled = true;
|
mRecycled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1391,7 +1396,7 @@ public final class Bitmap implements Parcelable {
|
|||||||
private static native Bitmap nativeCopy(int srcBitmap, int nativeConfig,
|
private static native Bitmap nativeCopy(int srcBitmap, int nativeConfig,
|
||||||
boolean isMutable);
|
boolean isMutable);
|
||||||
private static native void nativeDestructor(int nativeBitmap);
|
private static native void nativeDestructor(int nativeBitmap);
|
||||||
private static native void nativeRecycle(int nativeBitmap);
|
private static native boolean nativeRecycle(int nativeBitmap);
|
||||||
|
|
||||||
private static native boolean nativeCompress(int nativeBitmap, int format,
|
private static native boolean nativeCompress(int nativeBitmap, int format,
|
||||||
int quality, OutputStream stream,
|
int quality, OutputStream stream,
|
||||||
|
|||||||
@@ -265,27 +265,38 @@ void ResourceCache::destructorLocked(SkiaColorFilter* resource) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourceCache::recycle(SkBitmap* resource) {
|
/**
|
||||||
|
* Return value indicates whether resource was actually recycled, which happens when RefCnt
|
||||||
|
* reaches 0.
|
||||||
|
*/
|
||||||
|
bool ResourceCache::recycle(SkBitmap* resource) {
|
||||||
Mutex::Autolock _l(mLock);
|
Mutex::Autolock _l(mLock);
|
||||||
recycleLocked(resource);
|
return recycleLocked(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourceCache::recycleLocked(SkBitmap* resource) {
|
/**
|
||||||
|
* Return value indicates whether resource was actually recycled, which happens when RefCnt
|
||||||
|
* reaches 0.
|
||||||
|
*/
|
||||||
|
bool ResourceCache::recycleLocked(SkBitmap* resource) {
|
||||||
ssize_t index = mCache->indexOfKey(resource);
|
ssize_t index = mCache->indexOfKey(resource);
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
// not tracking this resource; just recycle the pixel data
|
// not tracking this resource; just recycle the pixel data
|
||||||
resource->setPixels(NULL, NULL);
|
resource->setPixels(NULL, NULL);
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
ResourceReference* ref = mCache->valueAt(index);
|
ResourceReference* ref = mCache->valueAt(index);
|
||||||
if (ref == NULL) {
|
if (ref == NULL) {
|
||||||
// Should not get here - shouldn't get a call to recycle if we're not yet tracking it
|
// Should not get here - shouldn't get a call to recycle if we're not yet tracking it
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
ref->recycled = true;
|
ref->recycled = true;
|
||||||
if (ref->refCount == 0) {
|
if (ref->refCount == 0) {
|
||||||
deleteResourceReferenceLocked(resource, ref);
|
deleteResourceReferenceLocked(resource, ref);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
// Still referring to resource, don't recycle yet
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -99,8 +99,8 @@ public:
|
|||||||
void destructorLocked(SkiaShader* resource);
|
void destructorLocked(SkiaShader* resource);
|
||||||
void destructorLocked(SkiaColorFilter* resource);
|
void destructorLocked(SkiaColorFilter* resource);
|
||||||
|
|
||||||
void recycle(SkBitmap* resource);
|
bool recycle(SkBitmap* resource);
|
||||||
void recycleLocked(SkBitmap* resource);
|
bool recycleLocked(SkBitmap* resource);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void deleteResourceReferenceLocked(void* resource, ResourceReference* ref);
|
void deleteResourceReferenceLocked(void* resource, ResourceReference* ref);
|
||||||
|
|||||||
Reference in New Issue
Block a user