From 8d592f9a7df0e7a704682b27fe68e2f5ea7240da Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Mon, 12 Mar 2018 15:44:03 -0400 Subject: [PATCH] Move computation of decodeColor- Type and Space Bug: 70846442 Test: I5110881203c000474116a94a48f2afc9a9b62001 Delay computing decodeColorType until right before we may change it (and delay reinterpreting the pointer along with it). More interestingly, defer computing decodeColorSpace until *after* we may have changed the decodeColorType. Along with a change in Skia, this allows us to match the color type of inBitmap, as intended. Change-Id: If0ca4a61d338a13473a96faf900c84010ae46d41 --- core/jni/android/graphics/BitmapRegionDecoder.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/jni/android/graphics/BitmapRegionDecoder.cpp b/core/jni/android/graphics/BitmapRegionDecoder.cpp index 3b081eff110a6..f831c051182ec 100644 --- a/core/jni/android/graphics/BitmapRegionDecoder.cpp +++ b/core/jni/android/graphics/BitmapRegionDecoder.cpp @@ -155,12 +155,6 @@ static jobject nativeDecodeRegion(JNIEnv* env, jobject, jlong brdHandle, jint in env->SetObjectField(options, gOptions_outColorSpaceFieldID, 0); } - SkBitmapRegionDecoder* brd = reinterpret_cast(brdHandle); - - SkColorType decodeColorType = brd->computeOutputColorType(colorType); - sk_sp decodeColorSpace = brd->computeOutputColorSpace( - decodeColorType, colorSpace); - // Recycle a bitmap if possible. android::Bitmap* recycledBitmap = nullptr; size_t recycledBytes = 0; @@ -172,6 +166,9 @@ static jobject nativeDecodeRegion(JNIEnv* env, jobject, jlong brdHandle, jint in recycledBytes = bitmap::getBitmapAllocationByteCount(env, javaBitmap); } + SkBitmapRegionDecoder* brd = reinterpret_cast(brdHandle); + SkColorType decodeColorType = brd->computeOutputColorType(colorType); + // Set up the pixel allocator SkBRDAllocator* allocator = nullptr; RecyclingClippingPixelAllocator recycleAlloc(recycledBitmap, recycledBytes); @@ -184,6 +181,9 @@ static jobject nativeDecodeRegion(JNIEnv* env, jobject, jlong brdHandle, jint in allocator = &heapAlloc; } + sk_sp decodeColorSpace = brd->computeOutputColorSpace( + decodeColorType, colorSpace); + // Decode the region. SkIRect subset = SkIRect::MakeXYWH(inputX, inputY, inputWidth, inputHeight); SkBitmap bitmap;