diff options
author | Leon Scroggins III <scroggo@google.com> | 2013-09-19 11:34:06 -0400 |
---|---|---|
committer | Leon Scroggins III <scroggo@google.com> | 2013-09-19 16:22:57 -0400 |
commit | 1ffe727c0616ca11092a45c3dfb94479fe55fdd9 (patch) | |
tree | 9dda903f58b13f4cd3e112b3b18f8327d29ee21d | |
parent | 01fc088462d05478bcdf416fb02532d53e85dd6a (diff) | |
download | frameworks_base-1ffe727c0616ca11092a45c3dfb94479fe55fdd9.zip frameworks_base-1ffe727c0616ca11092a45c3dfb94479fe55fdd9.tar.gz frameworks_base-1ffe727c0616ca11092a45c3dfb94479fe55fdd9.tar.bz2 |
Skip writing zeroes to java allocated memory.
If pixel memory was just allocated by Java, tell our decoders not
to write 0s, since the memory was initialized to 0. Likewise,
when drawing to a bitmap with memory just allocated by Java, do
not erase to 0.
Depends on a change to external/skia to add the new option on
image decoders:
https://googleplex-android-review.git.corp.google.com/362663
BUG:10016979
Change-Id: I9a3dc969870f8516e7d8495fe96d0a6b8225eda2
-rw-r--r-- | core/jni/android/graphics/BitmapFactory.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/core/jni/android/graphics/BitmapFactory.cpp b/core/jni/android/graphics/BitmapFactory.cpp index 9c20de2..0d757f7 100644 --- a/core/jni/android/graphics/BitmapFactory.cpp +++ b/core/jni/android/graphics/BitmapFactory.cpp @@ -297,6 +297,9 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding (SkBitmap::Allocator*)&recyclingAllocator : (SkBitmap::Allocator*)&javaAllocator; if (decodeMode != SkImageDecoder::kDecodeBounds_Mode) { if (!willScale) { + // If the java allocator is being used to allocate the pixel memory, the decoder + // need not write zeroes, since the memory is initialized to 0. + decoder->setSkipWritingZeroes(outputAllocator == &javaAllocator); decoder->setAllocator(outputAllocator); } else if (javaBitmap != NULL) { // check for eventual scaled bounds at allocation time, so we don't decode the bitmap @@ -403,7 +406,12 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding if (!outputBitmap->allocPixels(outputAllocator, NULL)) { return nullObjectReturn("allocation failed for scaled bitmap"); } - outputBitmap->eraseColor(0); + + // If outputBitmap's pixels are newly allocated by Java, there is no need + // to erase to 0, since the pixels were initialized to 0. + if (outputAllocator != &javaAllocator) { + outputBitmap->eraseColor(0); + } SkPaint paint; paint.setFilterBitmap(true); |