diff options
author | 2023-03-13 18:30:55 +0000 | |
---|---|---|
committer | 2023-03-14 16:51:25 +0000 | |
commit | 93671088f41c289adea1498ec1814b90d17e38cd (patch) | |
tree | 6acc54909a735229cbf567fe4870f5fb9b4d50e1 | |
parent | 4280e22a04ae4ed38e89cf7eeb4484d306ce8329 (diff) |
Move Android to new SkImage_RasterPinnable-based APIs
These landed in https://skia-review.git.corp.google.com/c/skia/+/651760
and were rolled shortly there after.
Change-Id: I347db430e594a4e8ab9d391b85549362022f9b21
Bug: skbug.com/13983
-rw-r--r-- | libs/hwui/hwui/Bitmap.cpp | 6 | ||||
-rw-r--r-- | libs/hwui/jni/android_graphics_HardwareRenderer.cpp | 4 | ||||
-rw-r--r-- | libs/hwui/pipeline/skia/SkiaPipeline.cpp | 10 | ||||
-rw-r--r-- | libs/hwui/tests/unit/CacheManagerTests.cpp | 9 |
4 files changed, 17 insertions, 12 deletions
diff --git a/libs/hwui/hwui/Bitmap.cpp b/libs/hwui/hwui/Bitmap.cpp index b3eaa0ce5979..9b97d0a2bf3e 100644 --- a/libs/hwui/hwui/Bitmap.cpp +++ b/libs/hwui/hwui/Bitmap.cpp @@ -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> @@ -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; } diff --git a/libs/hwui/jni/android_graphics_HardwareRenderer.cpp b/libs/hwui/jni/android_graphics_HardwareRenderer.cpp index 6a7411f5d859..bc14460ce328 100644 --- a/libs/hwui/jni/android_graphics_HardwareRenderer.cpp +++ b/libs/hwui/jni/android_graphics_HardwareRenderer.cpp @@ -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> @@ -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); } diff --git a/libs/hwui/pipeline/skia/SkiaPipeline.cpp b/libs/hwui/pipeline/skia/SkiaPipeline.cpp index 6628463bcabf..3515d0a5d506 100644 --- a/libs/hwui/pipeline/skia/SkiaPipeline.cpp +++ b/libs/hwui/pipeline/skia/SkiaPipeline.cpp @@ -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> @@ -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; @@ -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(); } @@ -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 diff --git a/libs/hwui/tests/unit/CacheManagerTests.cpp b/libs/hwui/tests/unit/CacheManagerTests.cpp index 2b90bda87ecd..03a955c83870 100644 --- a/libs/hwui/tests/unit/CacheManagerTests.cpp +++ b/libs/hwui/tests/unit/CacheManagerTests.cpp @@ -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; @@ -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()); @@ -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(); |