diff options
| -rw-r--r-- | libs/hwui/Android.bp | 1 | ||||
| -rw-r--r-- | libs/hwui/hwui/Bitmap.cpp | 37 | ||||
| -rw-r--r-- | libs/hwui/hwui/Bitmap.h | 1 |
3 files changed, 39 insertions, 0 deletions
diff --git a/libs/hwui/Android.bp b/libs/hwui/Android.bp index 34af1f9ea039..db581471e2ca 100644 --- a/libs/hwui/Android.bp +++ b/libs/hwui/Android.bp @@ -129,6 +129,7 @@ cc_defaults { "libandroidfw", "libcrypto", "libsync", + "libui", ], static_libs: [ "libEGL_blobCache", diff --git a/libs/hwui/hwui/Bitmap.cpp b/libs/hwui/hwui/Bitmap.cpp index b3eaa0ce5979..92d875bf7f1e 100644 --- a/libs/hwui/hwui/Bitmap.cpp +++ b/libs/hwui/hwui/Bitmap.cpp @@ -18,6 +18,10 @@ #include "HardwareBitmapUploader.h" #include "Properties.h" #ifdef __ANDROID__ // Layoutlib does not support render thread +#include <private/android/AHardwareBufferHelpers.h> +#include <ui/GraphicBuffer.h> +#include <ui/GraphicBufferMapper.h> + #include "renderthread/RenderProxy.h" #endif #include "utils/Color.h" @@ -51,6 +55,34 @@ namespace android { +#ifdef __ANDROID__ +static uint64_t AHardwareBuffer_getAllocationSize(AHardwareBuffer* aHardwareBuffer) { + GraphicBuffer* buffer = AHardwareBuffer_to_GraphicBuffer(aHardwareBuffer); + auto& mapper = GraphicBufferMapper::get(); + uint64_t size = 0; + auto err = mapper.getAllocationSize(buffer->handle, &size); + if (err == OK) { + if (size > 0) { + return size; + } else { + ALOGW("Mapper returned size = 0 for buffer format: 0x%x size: %d x %d", buffer->format, + buffer->width, buffer->height); + // Fall-through to estimate + } + } + + // Estimation time! + // Stride could be = 0 if it's ill-defined (eg, compressed buffer), in which case we use the + // width of the buffer instead + size = std::max(buffer->width, buffer->stride) * buffer->height; + // Require bpp to be at least 1. This is too low for many formats, but it's better than 0 + // Also while we could make increasingly better estimates, the reality is that mapper@4 + // should be common enough at this point that we won't ever hit this anyway + size *= std::max(1u, bytesPerPixel(buffer->format)); + return size; +} +#endif + bool Bitmap::computeAllocationSize(size_t rowBytes, int height, size_t* size) { return 0 <= height && height <= std::numeric_limits<size_t>::max() && !__builtin_mul_overflow(rowBytes, (size_t)height, size) && @@ -261,6 +293,7 @@ Bitmap::Bitmap(AHardwareBuffer* buffer, const SkImageInfo& info, size_t rowBytes , mPalette(palette) , mPaletteGenerationId(getGenerationID()) { mPixelStorage.hardware.buffer = buffer; + mPixelStorage.hardware.size = AHardwareBuffer_getAllocationSize(buffer); AHardwareBuffer_acquire(buffer); setImmutable(); // HW bitmaps are always immutable mImage = SkImage::MakeFromAHardwareBuffer(buffer, mInfo.alphaType(), mInfo.refColorSpace()); @@ -317,6 +350,10 @@ size_t Bitmap::getAllocationByteCount() const { return mPixelStorage.heap.size; case PixelStorageType::Ashmem: return mPixelStorage.ashmem.size; +#ifdef __ANDROID__ + case PixelStorageType::Hardware: + return mPixelStorage.hardware.size; +#endif default: return rowBytes() * height(); } diff --git a/libs/hwui/hwui/Bitmap.h b/libs/hwui/hwui/Bitmap.h index 912d311c3678..dd344e2f5517 100644 --- a/libs/hwui/hwui/Bitmap.h +++ b/libs/hwui/hwui/Bitmap.h @@ -221,6 +221,7 @@ private: #ifdef __ANDROID__ // Layoutlib does not support hardware acceleration struct { AHardwareBuffer* buffer; + uint64_t size; } hardware; #endif } mPixelStorage; |