diff options
author | Raphael Moll <raphael@google.com> | 2023-12-21 01:07:33 +0000 |
---|---|---|
committer | Raphael Moll <raphael@google.com> | 2024-01-08 21:35:18 +0000 |
commit | 25874ec22f679bbf09aef54f8941ba9034d6c3a3 (patch) | |
tree | a92b9c25f4ef848ea12b438aada807c44de23c6e | |
parent | ee03ecfce775d72496014250a3933eb3c0a4f085 (diff) | |
download | base-25874ec22f679bbf09aef54f8941ba9034d6c3a3.tar.gz |
[RNG] Bitmap::allocateHardwareBitmap() must copy source content.
The RNG version of Bitmap::allocateHardwareBitmap() is implemented on
top of Bitmap::allocateHeapBitmap(). However, per the class comment
description, this factory method should also copy the content of the
source bitmap into the newly allocated bitmap.
Bug: 310222823,242670053
Test: m -j robolectric_native_runtime dist
Change-Id: Ib657fd33b7862411977832da14ce39ec8b22812e
-rw-r--r-- | libs/hwui/hwui/Bitmap.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/libs/hwui/hwui/Bitmap.cpp b/libs/hwui/hwui/Bitmap.cpp index 1a89cfd5d0ad..b47aa60a3899 100644 --- a/libs/hwui/hwui/Bitmap.cpp +++ b/libs/hwui/hwui/Bitmap.cpp @@ -106,7 +106,13 @@ sk_sp<Bitmap> Bitmap::allocateHardwareBitmap(const SkBitmap& bitmap) { #ifdef __ANDROID__ // Layoutlib does not support hardware acceleration return uirenderer::HardwareBitmapUploader::allocateHardwareBitmap(bitmap); #else - return Bitmap::allocateHeapBitmap(bitmap.info()); + sk_sp<Bitmap> dest = Bitmap::allocateHeapBitmap(bitmap.info()); + + // Per header description, factories that accept const SkBitmap& should copy + // the contents of the provided bitmap into the newly allocated buffer. + memcpy(dest->mPixelStorage.heap.address, bitmap.getPixels(), bitmap.computeByteSize()); + + return dest; #endif } |