diff options
author | Leon Scroggins III <scroggo@google.com> | 2020-02-19 16:38:24 -0500 |
---|---|---|
committer | Leon Scroggins <scroggo@google.com> | 2020-02-20 13:41:17 +0000 |
commit | 3d334d816a639a5fca93b9ef6319849833073b2f (patch) | |
tree | 4c19914e1665fdc774bb63413dc21dc67f5420bb /libs | |
parent | b96b334d4366102fa21e6fb771229ce42e6ac86c (diff) | |
download | base-3d334d816a639a5fca93b9ef6319849833073b2f.tar.gz |
Make Bitmap::createFrom() account for zero stride
Bug: 143470518
Test: android.graphics.cts.ImageDecoderTest#testConserveMemoryPlusHardware
Follow up to ag/10045682, which was resolving a merge conflict. The
original fix (https://android-review.googlesource.com/1203783) was
on the single Bitmap constructor which took a GraphicBuffer parameter.
The conflict was with ag/9130111, which switched the input to an
AHardwareBuffer and split this version of Bitmap::createFrom into two
methods. The constructor no longer has access to the information
regarding the buffer stride, so that got moved into Bitmap::createFrom.
But both versions should have the fix. (In fact, it appears that the
version that did *not* have the fix is the one being called in
testConserveMemoryPlusHardware.)
Move the rowBytes computation into a common method so that both will
have the fix.
Change-Id: I16f77528abdb331af556bbe5d0485fe342f2325e
Diffstat (limited to 'libs')
-rw-r--r-- | libs/hwui/hwui/Bitmap.cpp | 14 | ||||
-rw-r--r-- | libs/hwui/hwui/Bitmap.h | 6 |
2 files changed, 14 insertions, 6 deletions
diff --git a/libs/hwui/hwui/Bitmap.cpp b/libs/hwui/hwui/Bitmap.cpp index 914c04645289..56d951cdb338 100644 --- a/libs/hwui/hwui/Bitmap.cpp +++ b/libs/hwui/hwui/Bitmap.cpp @@ -150,11 +150,7 @@ sk_sp<Bitmap> Bitmap::createFrom(AHardwareBuffer* hardwareBuffer, sk_sp<SkColorS AHardwareBuffer_Desc bufferDesc; AHardwareBuffer_describe(hardwareBuffer, &bufferDesc); SkImageInfo info = uirenderer::BufferDescriptionToImageInfo(bufferDesc, colorSpace); - - // If the stride is 0 we have to use the width as an approximation (eg, compressed buffer) - const auto bufferStride = bufferDesc.stride > 0 ? bufferDesc.stride : bufferDesc.width; - const size_t rowBytes = info.bytesPerPixel() * bufferStride; - return sk_sp<Bitmap>(new Bitmap(hardwareBuffer, info, rowBytes, palette)); + return createFrom(hardwareBuffer, info, bufferDesc, palette); } sk_sp<Bitmap> Bitmap::createFrom(AHardwareBuffer* hardwareBuffer, SkColorType colorType, @@ -164,8 +160,14 @@ sk_sp<Bitmap> Bitmap::createFrom(AHardwareBuffer* hardwareBuffer, SkColorType co AHardwareBuffer_describe(hardwareBuffer, &bufferDesc); SkImageInfo info = SkImageInfo::Make(bufferDesc.width, bufferDesc.height, colorType, alphaType, colorSpace); + return createFrom(hardwareBuffer, info, bufferDesc, palette); +} - const size_t rowBytes = info.bytesPerPixel() * bufferDesc.stride; +sk_sp<Bitmap> Bitmap::createFrom(AHardwareBuffer* hardwareBuffer, const SkImageInfo& info, + const AHardwareBuffer_Desc& bufferDesc, BitmapPalette palette) { + // If the stride is 0 we have to use the width as an approximation (eg, compressed buffer) + const auto bufferStride = bufferDesc.stride > 0 ? bufferDesc.stride : bufferDesc.width; + const size_t rowBytes = info.bytesPerPixel() * bufferStride; return sk_sp<Bitmap>(new Bitmap(hardwareBuffer, info, rowBytes, palette)); } #endif diff --git a/libs/hwui/hwui/Bitmap.h b/libs/hwui/hwui/Bitmap.h index 3bfb7800f735..b8b59947a57b 100644 --- a/libs/hwui/hwui/Bitmap.h +++ b/libs/hwui/hwui/Bitmap.h @@ -169,6 +169,12 @@ private: #ifdef __ANDROID__ // Layoutlib does not support hardware acceleration Bitmap(AHardwareBuffer* buffer, const SkImageInfo& info, size_t rowBytes, BitmapPalette palette); + + // Common code for the two public facing createFrom(AHardwareBuffer*, ...) + // methods. + // bufferDesc is only used to compute rowBytes. + static sk_sp<Bitmap> createFrom(AHardwareBuffer* hardwareBuffer, const SkImageInfo& info, + const AHardwareBuffer_Desc& bufferDesc, BitmapPalette palette); #endif virtual ~Bitmap(); |