From 15a108550e3d74b406927d85c8e69018761adf49 Mon Sep 17 00:00:00 2001 From: sergeyv Date: Tue, 27 Dec 2016 14:32:03 -0800 Subject: [PATCH] Fix getConfig on recycled bitmap Test: android.graphics.cts.BitmapTest#testGetConfigOnRecycled bug:33789983 Change-Id: Ic91c16cbd83acdd6002021b44da57636ee27742d --- core/jni/android/graphics/Bitmap.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/core/jni/android/graphics/Bitmap.cpp b/core/jni/android/graphics/Bitmap.cpp index 8f74bf8a4b6fa..3c0b25cb30bf3 100755 --- a/core/jni/android/graphics/Bitmap.cpp +++ b/core/jni/android/graphics/Bitmap.cpp @@ -52,6 +52,7 @@ public: mAllocationSize = mBitmap->getAllocationByteCount(); mRowBytes = mBitmap->rowBytes(); mGenerationId = mBitmap->getGenerationID(); + mIsHardware = mBitmap->isHardware(); mBitmap.reset(); } @@ -118,6 +119,13 @@ public: return mGenerationId; } + bool isHardware() { + if (mBitmap) { + return mBitmap->isHardware(); + } + return mIsHardware; + } + ~BitmapWrapper() { } private: @@ -127,6 +135,7 @@ private: size_t mAllocationSize; size_t mRowBytes; uint32_t mGenerationId; + bool mIsHardware; }; // Convenience class that does not take a global ref on the pixels, relying @@ -775,7 +784,7 @@ static jint Bitmap_rowBytes(JNIEnv* env, jobject, jlong bitmapHandle) { static jint Bitmap_config(JNIEnv* env, jobject, jlong bitmapHandle) { LocalScopedBitmap bitmap(bitmapHandle); - if (bitmap->bitmap().isHardware()) { + if (bitmap->isHardware()) { return GraphicsJNI::hardwareLegacyBitmapConfig(); } return GraphicsJNI::colorTypeToLegacyBitmapConfig(bitmap->info().colorType()); @@ -1208,7 +1217,7 @@ static jboolean Bitmap_sameAs(JNIEnv* env, jobject, jlong bm0Handle, jlong bm1Ha // Paying the price for making Hardware Bitmap as Config: // later check for colorType will pass successfully, // because Hardware Config internally may be RGBA8888 or smth like that. - if (bitmap0->bitmap().isHardware() != bitmap1->bitmap().isHardware()) { + if (bitmap0->isHardware() != bitmap1->isHardware()) { return JNI_FALSE; }