Loading libs/hwui/hwui/Bitmap.cpp +29 −0 Original line number Diff line number Diff line Loading @@ -264,6 +264,7 @@ Bitmap::Bitmap(void* address, size_t size, const SkImageInfo& info, size_t rowBy , mPixelStorageType(PixelStorageType::Heap) { mPixelStorage.heap.address = address; mPixelStorage.heap.size = size; traceBitmapCreate(); } Bitmap::Bitmap(SkPixelRef& pixelRef, const SkImageInfo& info) Loading @@ -272,6 +273,7 @@ Bitmap::Bitmap(SkPixelRef& pixelRef, const SkImageInfo& info) , mPixelStorageType(PixelStorageType::WrappedPixelRef) { pixelRef.ref(); mPixelStorage.wrapped.pixelRef = &pixelRef; traceBitmapCreate(); } Bitmap::Bitmap(void* address, int fd, size_t mappedSize, const SkImageInfo& info, size_t rowBytes) Loading @@ -281,6 +283,7 @@ Bitmap::Bitmap(void* address, int fd, size_t mappedSize, const SkImageInfo& info mPixelStorage.ashmem.address = address; mPixelStorage.ashmem.fd = fd; mPixelStorage.ashmem.size = mappedSize; traceBitmapCreate(); } #ifdef __ANDROID__ // Layoutlib does not support hardware acceleration Loading @@ -297,10 +300,12 @@ Bitmap::Bitmap(AHardwareBuffer* buffer, const SkImageInfo& info, size_t rowBytes setImmutable(); // HW bitmaps are always immutable mImage = SkImages::DeferredFromAHardwareBuffer(buffer, mInfo.alphaType(), mInfo.refColorSpace()); traceBitmapCreate(); } #endif Bitmap::~Bitmap() { traceBitmapDelete(); switch (mPixelStorageType) { case PixelStorageType::WrappedPixelRef: mPixelStorage.wrapped.pixelRef->unref(); Loading Loading @@ -572,4 +577,28 @@ void Bitmap::setGainmap(sp<uirenderer::Gainmap>&& gainmap) { mGainmap = std::move(gainmap); } std::mutex Bitmap::mLock{}; size_t Bitmap::mTotalBitmapBytes = 0; size_t Bitmap::mTotalBitmapCount = 0; void Bitmap::traceBitmapCreate() { if (ATRACE_ENABLED()) { std::lock_guard lock{mLock}; mTotalBitmapBytes += getAllocationByteCount(); mTotalBitmapCount++; ATRACE_INT64("Bitmap Memory", mTotalBitmapBytes); ATRACE_INT64("Bitmap Count", mTotalBitmapCount); } } void Bitmap::traceBitmapDelete() { if (ATRACE_ENABLED()) { std::lock_guard lock{mLock}; mTotalBitmapBytes -= getAllocationByteCount(); mTotalBitmapCount--; ATRACE_INT64("Bitmap Memory", mTotalBitmapBytes); ATRACE_INT64("Bitmap Count", mTotalBitmapCount); } } } // namespace android libs/hwui/hwui/Bitmap.h +8 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ #include <cutils/compiler.h> #include <utils/StrongPointer.h> #include <mutex> #include <optional> #ifdef __ANDROID__ // Layoutlib does not support hardware acceleration Loading Loading @@ -227,6 +228,13 @@ private: } mPixelStorage; sk_sp<SkImage> mImage; // Cache is used only for HW Bitmaps with Skia pipeline. // for tracing total number and memory usage of bitmaps static std::mutex mLock; static size_t mTotalBitmapBytes; static size_t mTotalBitmapCount; void traceBitmapCreate(); void traceBitmapDelete(); }; } // namespace android Loading
libs/hwui/hwui/Bitmap.cpp +29 −0 Original line number Diff line number Diff line Loading @@ -264,6 +264,7 @@ Bitmap::Bitmap(void* address, size_t size, const SkImageInfo& info, size_t rowBy , mPixelStorageType(PixelStorageType::Heap) { mPixelStorage.heap.address = address; mPixelStorage.heap.size = size; traceBitmapCreate(); } Bitmap::Bitmap(SkPixelRef& pixelRef, const SkImageInfo& info) Loading @@ -272,6 +273,7 @@ Bitmap::Bitmap(SkPixelRef& pixelRef, const SkImageInfo& info) , mPixelStorageType(PixelStorageType::WrappedPixelRef) { pixelRef.ref(); mPixelStorage.wrapped.pixelRef = &pixelRef; traceBitmapCreate(); } Bitmap::Bitmap(void* address, int fd, size_t mappedSize, const SkImageInfo& info, size_t rowBytes) Loading @@ -281,6 +283,7 @@ Bitmap::Bitmap(void* address, int fd, size_t mappedSize, const SkImageInfo& info mPixelStorage.ashmem.address = address; mPixelStorage.ashmem.fd = fd; mPixelStorage.ashmem.size = mappedSize; traceBitmapCreate(); } #ifdef __ANDROID__ // Layoutlib does not support hardware acceleration Loading @@ -297,10 +300,12 @@ Bitmap::Bitmap(AHardwareBuffer* buffer, const SkImageInfo& info, size_t rowBytes setImmutable(); // HW bitmaps are always immutable mImage = SkImages::DeferredFromAHardwareBuffer(buffer, mInfo.alphaType(), mInfo.refColorSpace()); traceBitmapCreate(); } #endif Bitmap::~Bitmap() { traceBitmapDelete(); switch (mPixelStorageType) { case PixelStorageType::WrappedPixelRef: mPixelStorage.wrapped.pixelRef->unref(); Loading Loading @@ -572,4 +577,28 @@ void Bitmap::setGainmap(sp<uirenderer::Gainmap>&& gainmap) { mGainmap = std::move(gainmap); } std::mutex Bitmap::mLock{}; size_t Bitmap::mTotalBitmapBytes = 0; size_t Bitmap::mTotalBitmapCount = 0; void Bitmap::traceBitmapCreate() { if (ATRACE_ENABLED()) { std::lock_guard lock{mLock}; mTotalBitmapBytes += getAllocationByteCount(); mTotalBitmapCount++; ATRACE_INT64("Bitmap Memory", mTotalBitmapBytes); ATRACE_INT64("Bitmap Count", mTotalBitmapCount); } } void Bitmap::traceBitmapDelete() { if (ATRACE_ENABLED()) { std::lock_guard lock{mLock}; mTotalBitmapBytes -= getAllocationByteCount(); mTotalBitmapCount--; ATRACE_INT64("Bitmap Memory", mTotalBitmapBytes); ATRACE_INT64("Bitmap Count", mTotalBitmapCount); } } } // namespace android
libs/hwui/hwui/Bitmap.h +8 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ #include <cutils/compiler.h> #include <utils/StrongPointer.h> #include <mutex> #include <optional> #ifdef __ANDROID__ // Layoutlib does not support hardware acceleration Loading Loading @@ -227,6 +228,13 @@ private: } mPixelStorage; sk_sp<SkImage> mImage; // Cache is used only for HW Bitmaps with Skia pipeline. // for tracing total number and memory usage of bitmaps static std::mutex mLock; static size_t mTotalBitmapBytes; static size_t mTotalBitmapCount; void traceBitmapCreate(); void traceBitmapDelete(); }; } // namespace android