Loading libs/hwui/hwui/Bitmap.cpp +6 −0 Original line number Diff line number Diff line Loading @@ -40,6 +40,7 @@ #include <SkEncodedImageFormat.h> #include <SkHighContrastFilter.h> #include <SkImageEncoder.h> #include <SkImageAndroid.h> #include <SkImagePriv.h> #include <SkJpegGainmapEncoder.h> #include <SkPixmap.h> Loading Loading @@ -370,7 +371,12 @@ sk_sp<SkImage> Bitmap::makeImage() { // Note we don't cache in this case, because the raster image holds a pointer to this Bitmap // internally and ~Bitmap won't be invoked. // TODO: refactor Bitmap to not derive from SkPixelRef, which would allow caching here. #ifdef __ANDROID__ // pinnable images are only supported with the Ganesh GPU backend compiled in. image = sk_image_factory::MakePinnableFromRasterBitmap(skiaBitmap); #else image = SkMakeImageFromRasterBitmap(skiaBitmap, kNever_SkCopyPixelsMode); #endif } return image; } Loading libs/hwui/jni/android_graphics_HardwareRenderer.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -27,7 +27,7 @@ #include <SkColorSpace.h> #include <SkData.h> #include <SkImage.h> #include <SkImagePriv.h> #include <SkImageAndroid.h> #include <SkPicture.h> #include <SkPixmap.h> #include <SkSerialProcs.h> Loading Loading @@ -493,7 +493,7 @@ public: return sk_ref_sp(img); } bm.setImmutable(); return SkMakeImageFromRasterBitmap(bm, kNever_SkCopyPixelsMode); return sk_image_factory::MakePinnableFromRasterBitmap(bm); } return sk_ref_sp(img); } Loading libs/hwui/pipeline/skia/SkiaPipeline.cpp +5 −5 Original line number Diff line number Diff line Loading @@ -21,9 +21,9 @@ #include <SkColorSpace.h> #include <SkData.h> #include <SkImage.h> #include <SkImageAndroid.h> #include <SkImageEncoder.h> #include <SkImageInfo.h> #include <SkImagePriv.h> #include <SkMatrix.h> #include <SkMultiPictureDocument.h> #include <SkOverdrawCanvas.h> Loading Loading @@ -75,7 +75,7 @@ bool SkiaPipeline::pinImages(std::vector<SkImage*>& mutableImages) { return false; } for (SkImage* image : mutableImages) { if (SkImage_pinAsTexture(image, mRenderThread.getGrContext())) { if (skgpu::ganesh::PinAsTexture(mRenderThread.getGrContext(), image)) { mPinnedImages.emplace_back(sk_ref_sp(image)); } else { return false; Loading @@ -86,7 +86,7 @@ bool SkiaPipeline::pinImages(std::vector<SkImage*>& mutableImages) { void SkiaPipeline::unpinImages() { for (auto& image : mPinnedImages) { SkImage_unpinAsTexture(image.get(), mRenderThread.getGrContext()); skgpu::ganesh::UnpinTexture(mRenderThread.getGrContext(), image.get()); } mPinnedImages.clear(); } Loading Loading @@ -222,8 +222,8 @@ void SkiaPipeline::prepareToDraw(const RenderThread& thread, Bitmap* bitmap) { ATRACE_FORMAT("Bitmap#prepareToDraw %dx%d", bitmap->width(), bitmap->height()); auto image = bitmap->makeImage(); if (image.get()) { SkImage_pinAsTexture(image.get(), context); SkImage_unpinAsTexture(image.get(), context); skgpu::ganesh::PinAsTexture(context, image.get()); skgpu::ganesh::UnpinTexture(context, image.get()); // A submit is necessary as there may not be a frame coming soon, so without a call // to submit these texture uploads can just sit in the queue building up until // we run out of RAM Loading libs/hwui/tests/unit/CacheManagerTests.cpp +4 −5 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ #include "renderthread/EglManager.h" #include "tests/common/TestUtils.h" #include <SkImagePriv.h> #include <SkImageAndroid.h> #include "include/gpu/GpuTypes.h" // from Skia using namespace android; Loading Loading @@ -57,9 +57,8 @@ RENDERTHREAD_SKIA_PIPELINE_TEST(CacheManager, DISABLED_trimMemory) { // create an image and pin it so that we have something with a unique key in the cache sk_sp<Bitmap> bitmap = Bitmap::allocateHeapBitmap(SkImageInfo::MakeA8(width, height)); sk_sp<SkImage> image = bitmap->makeImage(); ASSERT_TRUE(SkImage_pinAsTexture(image.get(), grContext)); sk_sp<SkImage> image = bitmap->makeImage(); // calls skgpu::ganesh::PinAsTexture under the hood. ASSERT_TRUE(skgpu::ganesh::PinAsTexture(grContext, image.get())); // attempt to trim all memory while we still hold strong refs renderThread.cacheManager().trimMemory(TrimLevel::COMPLETE); ASSERT_TRUE(0 == grContext->getResourceCachePurgeableBytes()); Loading @@ -71,7 +70,7 @@ RENDERTHREAD_SKIA_PIPELINE_TEST(CacheManager, DISABLED_trimMemory) { } // unpin the image which should add a unique purgeable key to the cache SkImage_unpinAsTexture(image.get(), grContext); skgpu::ganesh::UnpinTexture(grContext, image.get()); // verify that we have enough purgeable bytes const size_t purgeableBytes = grContext->getResourceCachePurgeableBytes(); Loading Loading
libs/hwui/hwui/Bitmap.cpp +6 −0 Original line number Diff line number Diff line Loading @@ -40,6 +40,7 @@ #include <SkEncodedImageFormat.h> #include <SkHighContrastFilter.h> #include <SkImageEncoder.h> #include <SkImageAndroid.h> #include <SkImagePriv.h> #include <SkJpegGainmapEncoder.h> #include <SkPixmap.h> Loading Loading @@ -370,7 +371,12 @@ sk_sp<SkImage> Bitmap::makeImage() { // Note we don't cache in this case, because the raster image holds a pointer to this Bitmap // internally and ~Bitmap won't be invoked. // TODO: refactor Bitmap to not derive from SkPixelRef, which would allow caching here. #ifdef __ANDROID__ // pinnable images are only supported with the Ganesh GPU backend compiled in. image = sk_image_factory::MakePinnableFromRasterBitmap(skiaBitmap); #else image = SkMakeImageFromRasterBitmap(skiaBitmap, kNever_SkCopyPixelsMode); #endif } return image; } Loading
libs/hwui/jni/android_graphics_HardwareRenderer.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -27,7 +27,7 @@ #include <SkColorSpace.h> #include <SkData.h> #include <SkImage.h> #include <SkImagePriv.h> #include <SkImageAndroid.h> #include <SkPicture.h> #include <SkPixmap.h> #include <SkSerialProcs.h> Loading Loading @@ -493,7 +493,7 @@ public: return sk_ref_sp(img); } bm.setImmutable(); return SkMakeImageFromRasterBitmap(bm, kNever_SkCopyPixelsMode); return sk_image_factory::MakePinnableFromRasterBitmap(bm); } return sk_ref_sp(img); } Loading
libs/hwui/pipeline/skia/SkiaPipeline.cpp +5 −5 Original line number Diff line number Diff line Loading @@ -21,9 +21,9 @@ #include <SkColorSpace.h> #include <SkData.h> #include <SkImage.h> #include <SkImageAndroid.h> #include <SkImageEncoder.h> #include <SkImageInfo.h> #include <SkImagePriv.h> #include <SkMatrix.h> #include <SkMultiPictureDocument.h> #include <SkOverdrawCanvas.h> Loading Loading @@ -75,7 +75,7 @@ bool SkiaPipeline::pinImages(std::vector<SkImage*>& mutableImages) { return false; } for (SkImage* image : mutableImages) { if (SkImage_pinAsTexture(image, mRenderThread.getGrContext())) { if (skgpu::ganesh::PinAsTexture(mRenderThread.getGrContext(), image)) { mPinnedImages.emplace_back(sk_ref_sp(image)); } else { return false; Loading @@ -86,7 +86,7 @@ bool SkiaPipeline::pinImages(std::vector<SkImage*>& mutableImages) { void SkiaPipeline::unpinImages() { for (auto& image : mPinnedImages) { SkImage_unpinAsTexture(image.get(), mRenderThread.getGrContext()); skgpu::ganesh::UnpinTexture(mRenderThread.getGrContext(), image.get()); } mPinnedImages.clear(); } Loading Loading @@ -222,8 +222,8 @@ void SkiaPipeline::prepareToDraw(const RenderThread& thread, Bitmap* bitmap) { ATRACE_FORMAT("Bitmap#prepareToDraw %dx%d", bitmap->width(), bitmap->height()); auto image = bitmap->makeImage(); if (image.get()) { SkImage_pinAsTexture(image.get(), context); SkImage_unpinAsTexture(image.get(), context); skgpu::ganesh::PinAsTexture(context, image.get()); skgpu::ganesh::UnpinTexture(context, image.get()); // A submit is necessary as there may not be a frame coming soon, so without a call // to submit these texture uploads can just sit in the queue building up until // we run out of RAM Loading
libs/hwui/tests/unit/CacheManagerTests.cpp +4 −5 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ #include "renderthread/EglManager.h" #include "tests/common/TestUtils.h" #include <SkImagePriv.h> #include <SkImageAndroid.h> #include "include/gpu/GpuTypes.h" // from Skia using namespace android; Loading Loading @@ -57,9 +57,8 @@ RENDERTHREAD_SKIA_PIPELINE_TEST(CacheManager, DISABLED_trimMemory) { // create an image and pin it so that we have something with a unique key in the cache sk_sp<Bitmap> bitmap = Bitmap::allocateHeapBitmap(SkImageInfo::MakeA8(width, height)); sk_sp<SkImage> image = bitmap->makeImage(); ASSERT_TRUE(SkImage_pinAsTexture(image.get(), grContext)); sk_sp<SkImage> image = bitmap->makeImage(); // calls skgpu::ganesh::PinAsTexture under the hood. ASSERT_TRUE(skgpu::ganesh::PinAsTexture(grContext, image.get())); // attempt to trim all memory while we still hold strong refs renderThread.cacheManager().trimMemory(TrimLevel::COMPLETE); ASSERT_TRUE(0 == grContext->getResourceCachePurgeableBytes()); Loading @@ -71,7 +70,7 @@ RENDERTHREAD_SKIA_PIPELINE_TEST(CacheManager, DISABLED_trimMemory) { } // unpin the image which should add a unique purgeable key to the cache SkImage_unpinAsTexture(image.get(), grContext); skgpu::ganesh::UnpinTexture(grContext, image.get()); // verify that we have enough purgeable bytes const size_t purgeableBytes = grContext->getResourceCachePurgeableBytes(); Loading