diff --git a/src/core/SkPictureImageGenerator.cpp b/src/core/SkPictureImageGenerator.cpp index 845971e72a..04cc5196ce 100644 --- a/src/core/SkPictureImageGenerator.cpp +++ b/src/core/SkPictureImageGenerator.cpp @@ -12,6 +12,7 @@ #include "include/core/SkPicture.h" #include "include/core/SkSurface.h" #include "src/core/SkTLazy.h" +#include "src/gpu/SkGr.h" #include "src/image/SkImage_Base.h" class SkPictureImageGenerator : public SkImageGenerator { @@ -92,7 +93,6 @@ bool SkPictureImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, #if SK_SUPPORT_GPU #include "include/gpu/GrRecordingContext.h" #include "src/gpu/GrRecordingContextPriv.h" -#include "src/gpu/SkGr.h" GrSurfaceProxyView SkPictureImageGenerator::onGenerateTexture(GrRecordingContext* ctx, const SkImageInfo& info, diff --git a/src/effects/imagefilters/SkMatrixConvolutionImageFilter.cpp b/src/effects/imagefilters/SkMatrixConvolutionImageFilter.cpp index c90f743552..3c14293692 100644 --- a/src/effects/imagefilters/SkMatrixConvolutionImageFilter.cpp +++ b/src/effects/imagefilters/SkMatrixConvolutionImageFilter.cpp @@ -16,11 +16,11 @@ #include "src/core/SkReadBuffer.h" #include "src/core/SkSpecialImage.h" #include "src/core/SkWriteBuffer.h" +#include "src/gpu/SkGr.h" #if SK_SUPPORT_GPU #include "src/gpu/GrRecordingContextPriv.h" #include "src/gpu/GrTextureProxy.h" -#include "src/gpu/SkGr.h" #include "src/gpu/effects/GrMatrixConvolutionEffect.h" #endif diff --git a/src/gpu/GrTextureProxy.h b/src/gpu/GrTextureProxy.h index 37ac1b188e..a0ac99a751 100644 --- a/src/gpu/GrTextureProxy.h +++ b/src/gpu/GrTextureProxy.h @@ -8,7 +8,6 @@ #ifndef GrTextureProxy_DEFINED #define GrTextureProxy_DEFINED -#include "include/gpu/GrBackendSurface.h" #include "src/gpu/GrSamplerState.h" #include "src/gpu/GrSurfaceProxy.h" diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index 41a2ede7d3..7a593bb872 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -163,14 +163,10 @@ static sk_sp make_bmp_proxy(GrProxyProvider* proxyProvider, return proxy; } -static std::tuple -make_cached_bitmap_view(GrRecordingContext* rContext, - const SkBitmap& bitmap, - GrMipmapped mipmapped, - uint32_t cacheID, - bool addListenerToBitmap) { - SkASSERT(cacheID != SK_InvalidUniqueID); - +std::tuple +GrMakeCachedBitmapProxyView(GrRecordingContext* rContext, + const SkBitmap& bitmap, + GrMipmapped mipmapped) { if (!bitmap.peekPixels(nullptr)) { return {}; } @@ -181,19 +177,14 @@ make_cached_bitmap_view(GrRecordingContext* rContext, GrUniqueKey key; SkIPoint origin = bitmap.pixelRefOrigin(); SkIRect subset = SkIRect::MakePtSize(origin, bitmap.dimensions()); - GrMakeKeyFromImageID(&key, cacheID, subset); + GrMakeKeyFromImageID(&key, bitmap.pixelRef()->getGenerationID(), subset); mipmapped = adjust_mipmapped(mipmapped, bitmap, caps); GrColorType ct = choose_bmp_texture_colortype(caps, bitmap); auto installKey = [&](GrTextureProxy* proxy) { - if (cacheID == bitmap.getGenerationID()) { - if (addListenerToBitmap) { - auto listener = GrMakeUniqueKeyInvalidationListener(&key, - proxyProvider->contextID()); - bitmap.pixelRef()->addGenIDChangeListener(std::move(listener)); - } - } + auto listener = GrMakeUniqueKeyInvalidationListener(&key, proxyProvider->contextID()); + bitmap.pixelRef()->addGenIDChangeListener(std::move(listener)); proxyProvider->assignUniqueKeyToProxy(key, proxy); }; @@ -238,22 +229,6 @@ make_cached_bitmap_view(GrRecordingContext* rContext, return {{std::move(mippedProxy), kTopLeft_GrSurfaceOrigin, swizzle}, ct}; } -std::tuple -GrMakeCachedBitmapProxyViewWithID(GrRecordingContext* rContext, - const SkBitmap& bitmap, - GrMipmapped mipmapped, - uint32_t cacheID) { - return make_cached_bitmap_view(rContext, bitmap, mipmapped, cacheID, /*add listener*/ false); -} - -std::tuple -GrMakeCachedBitmapProxyView(GrRecordingContext* rContext, - const SkBitmap& bitmap, - GrMipmapped mipmapped) { - uint32_t cacheID = bitmap.getGenerationID(); - return make_cached_bitmap_view(rContext, bitmap, mipmapped, cacheID, /*add listener*/ true); -} - std::tuple GrMakeUncachedBitmapProxyView(GrRecordingContext* rContext, const SkBitmap& bitmap, diff --git a/src/gpu/SkGr.h b/src/gpu/SkGr.h index d14cfca21c..8dba066c50 100644 --- a/src/gpu/SkGr.h +++ b/src/gpu/SkGr.h @@ -199,19 +199,7 @@ GrSurfaceProxyView GrCopyBaseMipMapToView(GrRecordingContext*, * if mipmapping isn't supported or for a 1x1 bitmap. If GrMipmapped is kNo it indicates mipmaps * aren't required but a previously created mipmapped texture may still be returned. A color type is * returned as color type conversion may be performed if there isn't a texture format equivalent of - * the bitmap's color type. cacheID is used in the cache key and is from the shared namespace of - * SkBitmap generation IDs and SkImage unique IDs. It must be valid. - */ -std::tuple -GrMakeCachedBitmapProxyViewWithID(GrRecordingContext*, - const SkBitmap&, - GrMipmapped, - uint32_t cacheID); - -/** - * Like GrMakeCachedBitmapProxyViewWithID but uses the bitmap's generation ID as the cache ID and - * also may add a listener to the SkBitmap that will invalidate the cached texture if the bitmap - * is deleted or its contents change. + * the bitmap's color type. */ std::tuple GrMakeCachedBitmapProxyView(GrRecordingContext*, @@ -219,8 +207,8 @@ GrMakeCachedBitmapProxyView(GrRecordingContext*, GrMipmapped = GrMipmapped::kNo); /** - * Like GrMakeCachedBitmapProxyView but always uploads the bitmap and never inserts into the cache. - * Unlike GrMakeCachedBitmapProxyView, the texture may be approx or scratch and budgeted or not. + * Like above but always uploads the bitmap and never inserts into the cache. Unlike above, the + * texture may be approx or scratch and budgeted or not. */ std::tuple GrMakeUncachedBitmapProxyView(GrRecordingContext*, diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp index 08b2545cc4..52fe5eec98 100644 --- a/src/image/SkImage_Raster.cpp +++ b/src/image/SkImage_Raster.cpp @@ -212,7 +212,6 @@ bool SkImage_Raster::onPinAsTexture(GrRecordingContext* rContext) const { } else { SkASSERT(fPinnedCount == 0); SkASSERT(fPinnedUniqueID == 0); - // It's important that we use the bitmap's gen ID here and not the image's unique ID. std::tie(fPinnedView, fPinnedColorType) = GrMakeCachedBitmapProxyView(rContext, fBitmap, GrMipmapped::kNo); @@ -429,7 +428,7 @@ std::tuple SkImage_Raster::onAsView( return {fPinnedView, fPinnedColorType}; } if (policy == GrImageTexGenPolicy::kDraw) { - return GrMakeCachedBitmapProxyViewWithID(rContext, fBitmap, mipmapped, this->uniqueID()); + return GrMakeCachedBitmapProxyView(rContext, fBitmap, mipmapped); } auto budgeted = (policy == GrImageTexGenPolicy::kNew_Uncached_Unbudgeted) ? SkBudgeted::kNo diff --git a/tests/PinnedImageTest.cpp b/tests/PinnedImageTest.cpp index de9e78851b..d29fdd16f0 100644 --- a/tests/PinnedImageTest.cpp +++ b/tests/PinnedImageTest.cpp @@ -51,9 +51,7 @@ static void basic_test(skiatest::Reporter* reporter, GrRecordingContext* rContex sk_sp gpuSurface = SkSurface::MakeRenderTarget(rContext, SkBudgeted::kYes, ii); SkCanvas* canvas = gpuSurface->getCanvas(); - // w/o pinning - the gpu caches the contents of the image and assumes the bitmap is immutable. - // This is actually undefined but we're assuming the GPU backend will cache the original and - // that it won't be purged before this test ends. + // w/o pinning - the gpu draw always reflects the current state of the underlying bitmap { canvas->drawImage(img, 0, 0); REPORTER_ASSERT(reporter, surface_is_expected_color(gpuSurface.get(), ii, SK_ColorRED)); @@ -61,29 +59,28 @@ static void basic_test(skiatest::Reporter* reporter, GrRecordingContext* rContex bmCanvas.clear(SK_ColorGREEN); canvas->drawImage(img, 0, 0); - REPORTER_ASSERT(reporter, surface_is_expected_color(gpuSurface.get(), ii, SK_ColorRED)); + REPORTER_ASSERT(reporter, surface_is_expected_color(gpuSurface.get(), ii, SK_ColorGREEN)); } // w/ pinning - the gpu draw is stuck at the pinned state { - bmCanvas.clear(SK_ColorBLUE); SkImage_pinAsTexture(img.get(), rContext); // pin at blue canvas->drawImage(img, 0, 0); - REPORTER_ASSERT(reporter, surface_is_expected_color(gpuSurface.get(), ii, SK_ColorBLUE)); + REPORTER_ASSERT(reporter, surface_is_expected_color(gpuSurface.get(), ii, SK_ColorGREEN)); - bmCanvas.clear(SK_ColorGREEN); + bmCanvas.clear(SK_ColorBLUE); canvas->drawImage(img, 0, 0); - REPORTER_ASSERT(reporter, surface_is_expected_color(gpuSurface.get(), ii, SK_ColorBLUE)); + REPORTER_ASSERT(reporter, surface_is_expected_color(gpuSurface.get(), ii, SK_ColorGREEN)); SkImage_unpinAsTexture(img.get(), rContext); } - // once unpinned revert to original cached texture + // once unpinned local changes will be picked up { canvas->drawImage(img, 0, 0); - REPORTER_ASSERT(reporter, surface_is_expected_color(gpuSurface.get(), ii, SK_ColorRED)); + REPORTER_ASSERT(reporter, surface_is_expected_color(gpuSurface.get(), ii, SK_ColorBLUE)); } }