From 27c4202f4bd68d9184a02c6f2a631f422cac33d2 Mon Sep 17 00:00:00 2001 From: Brian Salomon Date: Wed, 28 Apr 2021 12:39:21 -0400 Subject: [PATCH] Remove GrBitmapTextureMaker. Replace with two methods in SkGr.h that make cached/uncached texture proxies from SkBitmap. Move code that makes a GrFP from the proxy to SkImage_Raster::asFragmentProcessor. Bug: skia:11877 Change-Id: I51a0ae687561be9b0e44b98ee50f171e42476d94 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/401920 Reviewed-by: Robert Phillips Reviewed-by: Michael Ludwig Commit-Queue: Brian Salomon --- gm/dsl_processor_test.cpp | 1 - gm/fp_sample_chaining.cpp | 7 +- gm/fpcoordinateoverride.cpp | 5 +- gm/sample_matrix_constant.cpp | 14 +- gm/sample_matrix_variable.cpp | 5 +- gm/swizzle.cpp | 5 +- gm/texelsubset.cpp | 11 +- gm/yuvtorgbsubset.cpp | 7 +- gn/gpu.gni | 2 - src/core/SkSpecialImage.cpp | 2 +- src/effects/SkTableColorFilter.cpp | 6 +- src/gpu/GrBitmapTextureMaker.cpp | 129 ------------------ src/gpu/GrBitmapTextureMaker.h | 39 ------ src/gpu/GrBlurUtils.cpp | 11 +- src/gpu/GrSWMaskHelper.cpp | 7 +- src/gpu/SkGpuDevice.cpp | 3 +- src/gpu/SkGpuDevice.h | 5 - src/gpu/SkGpuDevice_drawTexture.cpp | 1 - src/gpu/SkGr.cpp | 127 +++++++++++++++-- src/gpu/SkGr.h | 34 +++-- .../effects/GrCircleBlurFragmentProcessor.fp | 6 +- src/gpu/effects/GrConfigConversionEffect.fp | 5 +- src/gpu/effects/GrMatrixConvolutionEffect.cpp | 5 +- src/gpu/effects/GrRRectBlurEffect.fp | 5 +- src/gpu/effects/GrRectBlurEffect.fp | 5 +- .../GrCircleBlurFragmentProcessor.cpp | 6 +- .../generated/GrConfigConversionEffect.cpp | 3 +- .../generated/GrConfigConversionEffect.h | 2 +- .../effects/generated/GrRRectBlurEffect.cpp | 5 +- src/gpu/effects/generated/GrRectBlurEffect.h | 5 +- src/gpu/gradients/GrGradientShader.cpp | 4 +- src/gpu/ops/GrShadowRRectOp.cpp | 5 +- src/image/SkImage_Gpu.cpp | 8 +- src/image/SkImage_GpuYUVA.cpp | 4 +- src/image/SkImage_Lazy.cpp | 37 +++-- src/image/SkImage_Raster.cpp | 85 ++++++++++-- src/shaders/SkImageShader.cpp | 9 -- src/shaders/SkPerlinNoiseShader.cpp | 13 +- tests/GrSurfaceTest.cpp | 8 +- tests/ImageFilterCacheTest.cpp | 5 +- tests/ProcessorTest.cpp | 17 +-- tests/SpecialImageTest.cpp | 20 ++- 42 files changed, 319 insertions(+), 364 deletions(-) delete mode 100644 src/gpu/GrBitmapTextureMaker.cpp delete mode 100644 src/gpu/GrBitmapTextureMaker.h diff --git a/gm/dsl_processor_test.cpp b/gm/dsl_processor_test.cpp index b7cfad0894..6a960edc74 100644 --- a/gm/dsl_processor_test.cpp +++ b/gm/dsl_processor_test.cpp @@ -8,7 +8,6 @@ #include "gm/gm.h" #include "include/core/SkFont.h" #include "include/effects/SkRuntimeEffect.h" -#include "src/gpu/GrBitmapTextureMaker.h" #include "src/gpu/GrDirectContextPriv.h" #include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h" #include "src/gpu/ops/GrFillRectOp.h" diff --git a/gm/fp_sample_chaining.cpp b/gm/fp_sample_chaining.cpp index 38e9b1dcc7..2d99da65fd 100644 --- a/gm/fp_sample_chaining.cpp +++ b/gm/fp_sample_chaining.cpp @@ -8,8 +8,8 @@ #include "gm/gm.h" #include "include/core/SkFont.h" #include "include/effects/SkRuntimeEffect.h" -#include "src/gpu/GrBitmapTextureMaker.h" #include "src/gpu/GrDirectContextPriv.h" +#include "src/gpu/SkGr.h" #include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h" #include "src/gpu/ops/GrFillRectOp.h" #include "tools/ToolUtils.h" @@ -214,7 +214,6 @@ static std::unique_ptr wrap(std::unique_ptr(new TestPatternEffect()); #else - auto view = maker.view(GrMipmapped::kNo); - auto fp = GrTextureEffect::Make(std::move(view), maker.alphaType()); + auto view = std::get<0>(GrMakeCachedBitmapProxyView(ctx, bmp, GrMipmapped::kNo)); + auto fp = GrTextureEffect::Make(std::move(view), bmp.alphaType()); #endif for (EffectType effectType : effects) { fp = wrap(std::move(fp), effectType); diff --git a/gm/fpcoordinateoverride.cpp b/gm/fpcoordinateoverride.cpp index e86d2e7a48..494942b1e3 100644 --- a/gm/fpcoordinateoverride.cpp +++ b/gm/fpcoordinateoverride.cpp @@ -17,11 +17,11 @@ #include "include/core/SkString.h" #include "include/core/SkTileMode.h" #include "include/core/SkTypes.h" -#include "src/gpu/GrBitmapTextureMaker.h" #include "src/gpu/GrCaps.h" #include "src/gpu/GrDirectContextPriv.h" #include "src/gpu/GrFragmentProcessor.h" #include "src/gpu/GrSurfaceDrawContext.h" +#include "src/gpu/SkGr.h" #include "src/gpu/effects/GrRRectEffect.h" #include "src/gpu/effects/GrSkSLFP.h" #include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h" @@ -77,8 +77,7 @@ DEF_SIMPLE_GPU_GM_BG(fpcoordinateoverride, ctx, rtCtx, canvas, 512, 512, SkBitmap bmp; GetResourceAsBitmap("images/mandrill_512_q075.jpg", &bmp); - GrBitmapTextureMaker maker(ctx, bmp, GrImageTexGenPolicy::kDraw); - auto view = maker.view(GrMipmapped::kNo); + auto view = std::get<0>(GrMakeCachedBitmapProxyView(ctx, bmp, GrMipmapped::kNo)); if (!view) { return; } diff --git a/gm/sample_matrix_constant.cpp b/gm/sample_matrix_constant.cpp index 5c55fb7e1d..2e4b1c9242 100644 --- a/gm/sample_matrix_constant.cpp +++ b/gm/sample_matrix_constant.cpp @@ -8,8 +8,8 @@ #include "gm/gm.h" #include "include/effects/SkGradientShader.h" #include "src/core/SkMatrixProvider.h" -#include "src/gpu/GrBitmapTextureMaker.h" #include "src/gpu/GrDirectContextPriv.h" +#include "src/gpu/SkGr.h" #include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h" #include "src/gpu/ops/GrFillRectOp.h" #include "tools/Resources.h" @@ -77,14 +77,12 @@ DEF_SIMPLE_GPU_GM(sample_matrix_constant, ctx, rtCtx, canvas, 1024, 256) { { SkBitmap bmp; GetResourceAsBitmap("images/mandrill_256.png", &bmp); - GrBitmapTextureMaker maker(ctx, bmp, GrImageTexGenPolicy::kDraw); - auto view = maker.view(GrMipmapped::kNo); - std::unique_ptr imgFP = - GrTextureEffect::Make(std::move(view), bmp.alphaType(), SkMatrix()); + auto [view, ct] = GrMakeCachedBitmapProxyView(ctx, bmp, GrMipmapped::kNo); + std::unique_ptr imgFP = GrTextureEffect::Make(view, + bmp.alphaType(), + SkMatrix()); draw(std::move(imgFP), 0, 0); - view = maker.view(GrMipmapped::kNo); - imgFP = - GrTextureEffect::Make(std::move(view), bmp.alphaType(), SkMatrix()); + imgFP = GrTextureEffect::Make(std::move(view), bmp.alphaType(), SkMatrix()); draw2(std::move(imgFP), 256, 0); } diff --git a/gm/sample_matrix_variable.cpp b/gm/sample_matrix_variable.cpp index 423222c64e..111518d83e 100644 --- a/gm/sample_matrix_variable.cpp +++ b/gm/sample_matrix_variable.cpp @@ -8,8 +8,8 @@ #include "gm/gm.h" #include "include/effects/SkGradientShader.h" #include "src/core/SkMatrixProvider.h" -#include "src/gpu/GrBitmapTextureMaker.h" #include "src/gpu/GrDirectContextPriv.h" +#include "src/gpu/SkGr.h" #include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h" #include "src/gpu/ops/GrFillRectOp.h" #include "tools/Resources.h" @@ -79,8 +79,7 @@ DEF_SIMPLE_GPU_GM(sample_matrix_variable, ctx, rtCtx, canvas, 512, 256) { { SkBitmap bmp; GetResourceAsBitmap("images/mandrill_256.png", &bmp); - GrBitmapTextureMaker maker(ctx, bmp, GrImageTexGenPolicy::kDraw); - auto view = maker.view(GrMipmapped::kNo); + auto view = std::get<0>(GrMakeCachedBitmapProxyView(ctx, bmp, GrMipmapped::kNo)); std::unique_ptr imgFP = GrTextureEffect::Make(std::move(view), bmp.alphaType(), SkMatrix()); draw(std::move(imgFP), -128, 256, 0, 0); diff --git a/gm/swizzle.cpp b/gm/swizzle.cpp index de1db5cc9e..644f27657f 100644 --- a/gm/swizzle.cpp +++ b/gm/swizzle.cpp @@ -11,10 +11,10 @@ #include "include/core/SkMatrix.h" #include "include/core/SkRect.h" #include "include/core/SkTypes.h" -#include "src/gpu/GrBitmapTextureMaker.h" #include "src/gpu/GrDirectContextPriv.h" #include "src/gpu/GrFragmentProcessor.h" #include "src/gpu/GrSurfaceDrawContext.h" +#include "src/gpu/SkGr.h" #include "src/gpu/ops/GrFillRectOp.h" #include "tools/Resources.h" #include "tools/ToolUtils.h" @@ -24,8 +24,7 @@ DEF_SIMPLE_GPU_GM(swizzle, ctx, rtCtx, canvas, 512, 512) { SkBitmap bmp; GetResourceAsBitmap("images/mandrill_512_q075.jpg", &bmp); - GrBitmapTextureMaker maker(ctx, bmp, GrImageTexGenPolicy::kDraw); - auto view = maker.view(GrMipmapped::kNo); + auto view = std::get<0>(GrMakeCachedBitmapProxyView(ctx, bmp, GrMipmapped::kNo)); if (!view) { return; } diff --git a/gm/texelsubset.cpp b/gm/texelsubset.cpp index 24cbe21a2b..d477fb7b27 100644 --- a/gm/texelsubset.cpp +++ b/gm/texelsubset.cpp @@ -16,15 +16,12 @@ #include "include/core/SkRect.h" #include "include/core/SkSize.h" #include "include/core/SkString.h" -#include "include/effects/SkGradientShader.h" -#include "include/private/GrTypesPriv.h" #include "include/private/SkTArray.h" -#include "src/gpu/GrBitmapTextureMaker.h" #include "src/gpu/GrDirectContextPriv.h" #include "src/gpu/GrProxyProvider.h" #include "src/gpu/GrSamplerState.h" #include "src/gpu/GrSurfaceDrawContext.h" -#include "src/gpu/GrTextureProxy.h" +#include "src/gpu/SkGr.h" #include "tools/Resources.h" #include "tools/gpu/TestOps.h" @@ -92,8 +89,7 @@ protected: if (mipmapped == GrMipmapped::kYes && !context->priv().caps()->mipmapSupport()) { return DrawResult::kSkip; } - GrBitmapTextureMaker maker(context, fBitmap, GrImageTexGenPolicy::kDraw); - auto view = maker.view(mipmapped); + auto view = std::get<0>(GrMakeCachedBitmapProxyView(context, fBitmap, mipmapped)); if (!view) { *errorMsg = "Failed to create proxy."; return DrawResult::kFail; @@ -126,8 +122,7 @@ protected: SkBitmap subsetBmp; fBitmap.extractSubset(&subsetBmp, texelSubset); subsetBmp.setImmutable(); - GrBitmapTextureMaker subsetMaker(context, subsetBmp, GrImageTexGenPolicy::kDraw); - auto subsetView = subsetMaker.view(mipmapped); + auto subsetView = std::get<0>(GrMakeCachedBitmapProxyView(context, subsetBmp, mipmapped)); SkRect localRect = SkRect::Make(fBitmap.bounds()).makeOutset(kDrawPad, kDrawPad); diff --git a/gm/yuvtorgbsubset.cpp b/gm/yuvtorgbsubset.cpp index 04081c3e60..433aa1e0ba 100644 --- a/gm/yuvtorgbsubset.cpp +++ b/gm/yuvtorgbsubset.cpp @@ -18,13 +18,12 @@ #include "include/core/SkString.h" #include "include/core/SkYUVAInfo.h" #include "include/core/SkYUVAPixmaps.h" -#include "src/gpu/GrBitmapTextureMaker.h" -#include "src/gpu/GrDirectContextPriv.h" #include "src/gpu/GrPaint.h" #include "src/gpu/GrSamplerState.h" #include "src/gpu/GrSurfaceDrawContext.h" #include "src/gpu/GrTextureProxy.h" #include "src/gpu/GrYUVATextureProxies.h" +#include "src/gpu/SkGr.h" #include "src/gpu/effects/GrYUVtoRGBEffect.h" #include @@ -96,9 +95,7 @@ protected: SkBitmap bitmap; bitmap.installPixels(fPixmaps.plane(i)); bitmap.setImmutable(); - GrBitmapTextureMaker maker( - context, bitmap, GrImageTexGenPolicy::kNew_Uncached_Budgeted); - views[i] = maker.view(GrMipmapped::kNo); + views[i] = std::get<0>(GrMakeCachedBitmapProxyView(context, bitmap, GrMipmapped::kNo)); if (!views[i]) { *errorMsg = "Failed to create proxy"; return context->abandoned() ? DrawResult::kSkip : DrawResult::kFail; diff --git a/gn/gpu.gni b/gn/gpu.gni index b5b1cca867..155055a137 100644 --- a/gn/gpu.gni +++ b/gn/gpu.gni @@ -50,8 +50,6 @@ skia_gpu_sources = [ "$_src/gpu/GrBackendUtils.cpp", "$_src/gpu/GrBackendUtils.h", "$_src/gpu/GrBaseContextPriv.h", - "$_src/gpu/GrBitmapTextureMaker.cpp", - "$_src/gpu/GrBitmapTextureMaker.h", "$_src/gpu/GrBlend.h", "$_src/gpu/GrBlockAllocator.cpp", "$_src/gpu/GrBlockAllocator.h", diff --git a/src/core/SkSpecialImage.cpp b/src/core/SkSpecialImage.cpp index cc6bb5f60f..b330c8108a 100644 --- a/src/core/SkSpecialImage.cpp +++ b/src/core/SkSpecialImage.cpp @@ -217,7 +217,7 @@ public: #if SK_SUPPORT_GPU GrSurfaceProxyView onView(GrRecordingContext* context) const override { if (context) { - return GrMakeCachedBitmapProxyView(context, fBitmap); + return std::get<0>(GrMakeCachedBitmapProxyView(context, fBitmap, GrMipmapped::kNo)); } return {}; diff --git a/src/effects/SkTableColorFilter.cpp b/src/effects/SkTableColorFilter.cpp index fb07f48538..7fc5728b94 100644 --- a/src/effects/SkTableColorFilter.cpp +++ b/src/effects/SkTableColorFilter.cpp @@ -184,13 +184,13 @@ std::unique_ptr ColorTableEffect::Make( SkASSERT(kPremul_SkAlphaType == bitmap.alphaType()); SkASSERT(bitmap.isImmutable()); - auto view = GrMakeCachedBitmapProxyView(context, bitmap); + auto view = std::get<0>(GrMakeCachedBitmapProxyView(context, bitmap, GrMipmapped::kNo)); if (!view) { return nullptr; } - return std::unique_ptr( - new ColorTableEffect(std::move(inputFP), std::move(view))); + return std::unique_ptr(new ColorTableEffect(std::move(inputFP), + std::move(view))); } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/gpu/GrBitmapTextureMaker.cpp b/src/gpu/GrBitmapTextureMaker.cpp deleted file mode 100644 index b9167cb063..0000000000 --- a/src/gpu/GrBitmapTextureMaker.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "src/gpu/GrBitmapTextureMaker.h" - -#include "include/core/SkBitmap.h" -#include "include/core/SkPixelRef.h" -#include "include/gpu/GrRecordingContext.h" -#include "include/private/SkIDChangeListener.h" -#include "src/gpu/GrGpuResourcePriv.h" -#include "src/gpu/GrProxyProvider.h" -#include "src/gpu/GrRecordingContextPriv.h" -#include "src/gpu/GrSurfaceContext.h" -#include "src/gpu/SkGr.h" - -static GrImageInfo get_image_info(GrRecordingContext* context, const SkBitmap& bitmap) { - GrColorType ct = SkColorTypeToGrColorType(bitmap.info().colorType()); - GrBackendFormat format = context->priv().caps()->getDefaultBackendFormat(ct, GrRenderable::kNo); - if (!format.isValid()) { - ct = GrColorType::kRGBA_8888; - } - return {ct, bitmap.alphaType(), bitmap.refColorSpace(), bitmap.dimensions()}; -} - -GrBitmapTextureMaker::GrBitmapTextureMaker(GrRecordingContext* context, - const SkBitmap& bitmap, - SkBackingFit fit) - : GrBitmapTextureMaker(context, bitmap, GrImageTexGenPolicy::kNew_Uncached_Budgeted, fit) {} - -GrBitmapTextureMaker::GrBitmapTextureMaker(GrRecordingContext* context, - const SkBitmap& bitmap, - GrImageTexGenPolicy cachePolicy) - : GrBitmapTextureMaker(context, bitmap, cachePolicy, SkBackingFit::kExact) {} - -GrBitmapTextureMaker::GrBitmapTextureMaker(GrRecordingContext* context, - const SkBitmap& bitmap, - GrImageTexGenPolicy cachePolicy, - SkBackingFit fit) - : INHERITED(context, get_image_info(context, bitmap)) - , fBitmap(bitmap) - , fFit(fit) - , fBudgeted(cachePolicy == GrImageTexGenPolicy::kNew_Uncached_Unbudgeted - ? SkBudgeted::kNo - : SkBudgeted::kYes) { - if (cachePolicy == GrImageTexGenPolicy::kDraw) { - SkIPoint origin = bitmap.pixelRefOrigin(); - SkIRect subset = SkIRect::MakeXYWH(origin.fX, origin.fY, bitmap.width(), - bitmap.height()); - GrMakeKeyFromImageID(&fKey, bitmap.pixelRef()->getGenerationID(), subset); - } -} - -GrSurfaceProxyView GrBitmapTextureMaker::refOriginalTextureProxyView(GrMipmapped mipMapped) { - GrProxyProvider* proxyProvider = this->context()->priv().proxyProvider(); - sk_sp proxy; - GrSwizzle swizzle; - - auto installKey = [&](GrTextureProxy* proxy) { - auto listener = GrMakeUniqueKeyInvalidationListener(&fKey, proxyProvider->contextID()); - fBitmap.pixelRef()->addGenIDChangeListener(std::move(listener)); - proxyProvider->assignUniqueKeyToProxy(fKey, proxy); - }; - - if (fKey.isValid()) { - proxy = proxyProvider->findOrCreateProxyByUniqueKey(fKey); - if (proxy) { - swizzle = this->context()->priv().caps()->getReadSwizzle(proxy->backendFormat(), - this->colorType()); - if (mipMapped == GrMipmapped::kNo || proxy->mipmapped() == GrMipmapped::kYes) { - return {std::move(proxy), kTopLeft_GrSurfaceOrigin, swizzle}; - } - } - } - - if (!proxy) { - if (this->colorType() != SkColorTypeToGrColorType(fBitmap.info().colorType())) { - SkASSERT(this->colorType() == GrColorType::kRGBA_8888); - SkBitmap copy8888; - if (!copy8888.tryAllocPixels(fBitmap.info().makeColorType(kRGBA_8888_SkColorType)) || - !fBitmap.readPixels(copy8888.pixmap())) { - return {}; - } - copy8888.setImmutable(); - proxy = proxyProvider->createProxyFromBitmap(copy8888, mipMapped, fFit, fBudgeted); - } else { - proxy = proxyProvider->createProxyFromBitmap(fBitmap, mipMapped, fFit, fBudgeted); - } - if (proxy) { - swizzle = this->context()->priv().caps()->getReadSwizzle(proxy->backendFormat(), - this->colorType()); - SkASSERT(mipMapped == GrMipmapped::kNo || proxy->mipmapped() == GrMipmapped::kYes); - if (fKey.isValid()) { - installKey(proxy.get()); - } - return {std::move(proxy), kTopLeft_GrSurfaceOrigin, swizzle}; - } - } - - if (proxy) { - SkASSERT(mipMapped == GrMipmapped::kYes); - SkASSERT(proxy->mipmapped() == GrMipmapped::kNo); - SkASSERT(fKey.isValid()); - // We need a mipped proxy, but we found a proxy earlier that wasn't mipped. Thus we generate - // a new mipped surface and copy the original proxy into the base layer. We will then let - // the gpu generate the rest of the mips. - auto mippedProxy = GrCopyBaseMipMapToTextureProxy(this->context(), proxy, - kTopLeft_GrSurfaceOrigin); - if (!mippedProxy) { - // We failed to make a mipped proxy with the base copied into it. This could have - // been from failure to make the proxy or failure to do the copy. Thus we will fall - // back to just using the non mipped proxy; See skbug.com/7094. - return {std::move(proxy), kTopLeft_GrSurfaceOrigin, swizzle}; - } - // In this case we are stealing the key from the original proxy which should only happen - // when we have just generated mipmaps for an originally unmipped proxy/texture. This - // means that all future uses of the key will access the mipmapped version. The texture - // backing the unmipped version will remain in the resource cache until the last texture - // proxy referencing it is deleted at which time it too will be deleted or recycled. - SkASSERT(proxy->getUniqueKey() == fKey); - proxyProvider->removeUniqueKeyFromProxy(proxy.get()); - installKey(mippedProxy->asTextureProxy()); - return {std::move(mippedProxy), kTopLeft_GrSurfaceOrigin, swizzle}; - } - return {}; -} diff --git a/src/gpu/GrBitmapTextureMaker.h b/src/gpu/GrBitmapTextureMaker.h deleted file mode 100644 index ae6ff1b9ae..0000000000 --- a/src/gpu/GrBitmapTextureMaker.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef GrBitmapTextureMaker_DEFINED -#define GrBitmapTextureMaker_DEFINED - -#include "include/core/SkBitmap.h" -#include "src/gpu/GrTextureMaker.h" -#include "src/gpu/SkGr.h" - -/** This class manages the conversion of SW-backed bitmaps to GrTextures. If the input bitmap is - non-volatile the texture is cached using a key created from the pixels' image id and the - subset of the pixelref specified by the bitmap. */ -class GrBitmapTextureMaker final : public GrTextureMaker { -public: - GrBitmapTextureMaker(GrRecordingContext*, const SkBitmap&, GrImageTexGenPolicy); - - // Always uncached-budgeted. It doesn't make sense to have kApprox cached textures. Moreover,we - // create kApprox textures intermediate buffers and those ought to be budgeted. - GrBitmapTextureMaker(GrRecordingContext*, const SkBitmap&, SkBackingFit); - -private: - GrBitmapTextureMaker(GrRecordingContext*, const SkBitmap&, GrImageTexGenPolicy, SkBackingFit); - - GrSurfaceProxyView refOriginalTextureProxyView(GrMipmapped) override; - - const SkBitmap fBitmap; - const SkBackingFit fFit; - const SkBudgeted fBudgeted; - GrUniqueKey fKey; - - using INHERITED = GrTextureMaker; -}; - -#endif diff --git a/src/gpu/GrBlurUtils.cpp b/src/gpu/GrBlurUtils.cpp index d5ac783a93..ebf8b28758 100644 --- a/src/gpu/GrBlurUtils.cpp +++ b/src/gpu/GrBlurUtils.cpp @@ -9,7 +9,6 @@ #include "include/gpu/GrDirectContext.h" #include "include/gpu/GrRecordingContext.h" -#include "src/gpu/GrBitmapTextureMaker.h" #include "src/gpu/GrCaps.h" #include "src/gpu/GrDirectContextPriv.h" #include "src/gpu/GrFixedClip.h" @@ -20,6 +19,7 @@ #include "src/gpu/GrSurfaceDrawContext.h" #include "src/gpu/GrTextureProxy.h" #include "src/gpu/GrThreadSafeCache.h" +#include "src/gpu/SkGr.h" #include "src/gpu/effects/GrTextureEffect.h" #include "src/gpu/geometry/GrStyledShape.h" @@ -157,9 +157,12 @@ static GrSurfaceProxyView sw_create_filtered_mask(GrRecordingContext* rContext, } bm.setImmutable(); - GrBitmapTextureMaker maker(rContext, bm, SkBackingFit::kApprox); - filteredMaskView = maker.view(GrMipmapped::kNo); - if (!filteredMaskView.proxy()) { + std::tie(filteredMaskView, std::ignore) = GrMakeUncachedBitmapProxyView( + rContext, + bm, + GrMipmapped::kNo, + SkBackingFit::kApprox); + if (!filteredMaskView) { return {}; } diff --git a/src/gpu/GrSWMaskHelper.cpp b/src/gpu/GrSWMaskHelper.cpp index d477534fc1..22df7e7a55 100644 --- a/src/gpu/GrSWMaskHelper.cpp +++ b/src/gpu/GrSWMaskHelper.cpp @@ -9,12 +9,12 @@ #include "include/gpu/GrRecordingContext.h" #include "src/core/SkMatrixProvider.h" -#include "src/gpu/GrBitmapTextureMaker.h" #include "src/gpu/GrCaps.h" #include "src/gpu/GrProxyProvider.h" #include "src/gpu/GrRecordingContextPriv.h" #include "src/gpu/GrSurfaceContext.h" #include "src/gpu/GrTextureProxy.h" +#include "src/gpu/SkGr.h" #include "src/gpu/geometry/GrStyledShape.h" /* @@ -145,7 +145,7 @@ bool GrSWMaskHelper::init(const SkIRect& resultBounds) { return true; } -GrSurfaceProxyView GrSWMaskHelper::toTextureView(GrRecordingContext* context, SkBackingFit fit) { +GrSurfaceProxyView GrSWMaskHelper::toTextureView(GrRecordingContext* rContext, SkBackingFit fit) { SkImageInfo ii = SkImageInfo::MakeA8(fPixels->width(), fPixels->height()); size_t rowBytes = fPixels->rowBytes(); @@ -155,6 +155,5 @@ GrSurfaceProxyView GrSWMaskHelper::toTextureView(GrRecordingContext* context, Sk nullptr)); bitmap.setImmutable(); - GrBitmapTextureMaker maker(context, bitmap, fit); - return maker.view(GrMipmapped::kNo); + return std::get<0>(GrMakeUncachedBitmapProxyView(rContext, bitmap, GrMipmapped::kNo, fit)); } diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index 41fb1740e0..8fea05f88d 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -30,7 +30,6 @@ #include "src/core/SkStroke.h" #include "src/core/SkTLazy.h" #include "src/core/SkVerticesPriv.h" -#include "src/gpu/GrBitmapTextureMaker.h" #include "src/gpu/GrBlurUtils.h" #include "src/gpu/GrDirectContextPriv.h" #include "src/gpu/GrGpu.h" @@ -666,7 +665,7 @@ void SkGpuDevice::drawPath(const SkPath& origSrcPath, const SkPaint& paint, bool sk_sp SkGpuDevice::makeSpecial(const SkBitmap& bitmap) { // TODO: this makes a tight copy of 'bitmap' but it doesn't have to be (given SkSpecialImage's // semantics). Since this is cached we would have to bake the fit into the cache key though. - auto view = GrMakeCachedBitmapProxyView(fContext.get(), bitmap); + auto view = std::get<0>(GrMakeCachedBitmapProxyView(fContext.get(), bitmap)); if (!view) { return nullptr; } diff --git a/src/gpu/SkGpuDevice.h b/src/gpu/SkGpuDevice.h index e6ee5fb935..e62fc3cbab 100644 --- a/src/gpu/SkGpuDevice.h +++ b/src/gpu/SkGpuDevice.h @@ -16,11 +16,6 @@ #include "src/gpu/GrSurfaceDrawContext.h" #include "src/gpu/SkGr.h" -class GrAccelData; -class GrTextureMaker; -class GrTextureProducer; -struct GrCachedLayer; - class SkSpecialImage; class SkSurface; class SkVertices; diff --git a/src/gpu/SkGpuDevice_drawTexture.cpp b/src/gpu/SkGpuDevice_drawTexture.cpp index d12c3abbeb..088bacd008 100644 --- a/src/gpu/SkGpuDevice_drawTexture.cpp +++ b/src/gpu/SkGpuDevice_drawTexture.cpp @@ -14,7 +14,6 @@ #include "src/core/SkImagePriv.h" #include "src/core/SkMaskFilterBase.h" #include "src/core/SkSpecialImage.h" -#include "src/gpu/GrBitmapTextureMaker.h" #include "src/gpu/GrBlurUtils.h" #include "src/gpu/GrCaps.h" #include "src/gpu/GrColorSpaceXform.h" diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index 69177da0b1..7a593bb872 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -13,7 +13,6 @@ #include "include/core/SkPixelRef.h" #include "include/effects/SkRuntimeEffect.h" #include "include/gpu/GrRecordingContext.h" -#include "include/gpu/GrTypes.h" #include "include/private/SkIDChangeListener.h" #include "include/private/SkImageInfoPriv.h" #include "include/private/SkTPin.h" @@ -29,8 +28,8 @@ #include "src/core/SkPaintPriv.h" #include "src/core/SkResourceCache.h" #include "src/core/SkTraceEvent.h" -#include "src/gpu/GrBitmapTextureMaker.h" #include "src/gpu/GrCaps.h" +#include "src/gpu/GrColorInfo.h" #include "src/gpu/GrColorSpaceXform.h" #include "src/gpu/GrGpuResourcePriv.h" #include "src/gpu/GrPaint.h" @@ -125,22 +124,130 @@ GrSurfaceProxyView GrCopyBaseMipMapToView(GrRecordingContext* context, return {GrCopyBaseMipMapToTextureProxy(context, proxy, origin, budgeted), origin, swizzle}; } -GrSurfaceProxyView GrRefCachedBitmapView(GrRecordingContext* ctx, const SkBitmap& bitmap, - GrMipmapped mipMapped) { - GrBitmapTextureMaker maker(ctx, bitmap, GrImageTexGenPolicy::kDraw); - return maker.view(mipMapped); +static GrMipmapped adjust_mipmapped(GrMipmapped mipmapped, + const SkBitmap& bitmap, + const GrCaps* caps) { + if (!caps->mipmapSupport() || bitmap.dimensions().area() <= 1) { + return GrMipmapped::kNo; + } + return mipmapped; } -GrSurfaceProxyView GrMakeCachedBitmapProxyView(GrRecordingContext* context, - const SkBitmap& bitmap) { +static GrColorType choose_bmp_texture_colortype(const GrCaps* caps, const SkBitmap& bitmap) { + GrColorType ct = SkColorTypeToGrColorType(bitmap.info().colorType()); + if (caps->getDefaultBackendFormat(ct, GrRenderable::kNo).isValid()) { + return ct; + } + return GrColorType::kRGBA_8888; +} + +static sk_sp make_bmp_proxy(GrProxyProvider* proxyProvider, + const SkBitmap& bitmap, + GrColorType ct, + GrMipmapped mipmapped, + SkBackingFit fit, + SkBudgeted budgeted) { + SkBitmap bmpToUpload; + if (ct != SkColorTypeToGrColorType(bitmap.info().colorType())) { + SkColorType skCT = GrColorTypeToSkColorType(ct); + if (!bmpToUpload.tryAllocPixels(bitmap.info().makeColorType(skCT)) || + !bitmap.readPixels(bmpToUpload.pixmap())) { + return {}; + } + bmpToUpload.setImmutable(); + } else { + bmpToUpload = bitmap; + } + auto proxy = proxyProvider->createProxyFromBitmap(bmpToUpload, mipmapped, fit, budgeted); + SkASSERT(!proxy || mipmapped == GrMipmapped::kNo || proxy->mipmapped() == GrMipmapped::kYes); + return proxy; +} + +std::tuple +GrMakeCachedBitmapProxyView(GrRecordingContext* rContext, + const SkBitmap& bitmap, + GrMipmapped mipmapped) { if (!bitmap.peekPixels(nullptr)) { return {}; } - GrBitmapTextureMaker maker(context, bitmap, GrImageTexGenPolicy::kDraw); - return maker.view(GrMipmapped::kNo); + GrProxyProvider* proxyProvider = rContext->priv().proxyProvider(); + const GrCaps* caps = rContext->priv().caps(); + + GrUniqueKey key; + SkIPoint origin = bitmap.pixelRefOrigin(); + SkIRect subset = SkIRect::MakePtSize(origin, bitmap.dimensions()); + GrMakeKeyFromImageID(&key, bitmap.pixelRef()->getGenerationID(), subset); + + mipmapped = adjust_mipmapped(mipmapped, bitmap, caps); + GrColorType ct = choose_bmp_texture_colortype(caps, bitmap); + + auto installKey = [&](GrTextureProxy* proxy) { + auto listener = GrMakeUniqueKeyInvalidationListener(&key, proxyProvider->contextID()); + bitmap.pixelRef()->addGenIDChangeListener(std::move(listener)); + proxyProvider->assignUniqueKeyToProxy(key, proxy); + }; + + sk_sp proxy = proxyProvider->findOrCreateProxyByUniqueKey(key); + if (!proxy) { + proxy = make_bmp_proxy(proxyProvider, + bitmap, + ct, + mipmapped, + SkBackingFit::kExact, + SkBudgeted::kYes); + if (!proxy) { + return {}; + } + SkASSERT(mipmapped == GrMipmapped::kNo || proxy->mipmapped() == GrMipmapped::kYes); + installKey(proxy.get()); + } + + GrSwizzle swizzle = caps->getReadSwizzle(proxy->backendFormat(), ct); + if (mipmapped == GrMipmapped::kNo || proxy->mipmapped() == GrMipmapped::kYes) { + return {{std::move(proxy), kTopLeft_GrSurfaceOrigin, swizzle}, ct}; + } + + // We need a mipped proxy, but we found a proxy earlier that wasn't mipped. Thus we generate + // a new mipped surface and copy the original proxy into the base layer. We will then let + // the gpu generate the rest of the mips. + auto mippedProxy = GrCopyBaseMipMapToTextureProxy(rContext, proxy, kTopLeft_GrSurfaceOrigin); + if (!mippedProxy) { + // We failed to make a mipped proxy with the base copied into it. This could have + // been from failure to make the proxy or failure to do the copy. Thus we will fall + // back to just using the non mipped proxy; See skbug.com/7094. + return {{std::move(proxy), kTopLeft_GrSurfaceOrigin, swizzle}, ct}; + } + // In this case we are stealing the key from the original proxy which should only happen + // when we have just generated mipmaps for an originally unmipped proxy/texture. This + // means that all future uses of the key will access the mipmapped version. The texture + // backing the unmipped version will remain in the resource cache until the last texture + // proxy referencing it is deleted at which time it too will be deleted or recycled. + SkASSERT(proxy->getUniqueKey() == key); + proxyProvider->removeUniqueKeyFromProxy(proxy.get()); + installKey(mippedProxy->asTextureProxy()); + return {{std::move(mippedProxy), kTopLeft_GrSurfaceOrigin, swizzle}, ct}; } +std::tuple +GrMakeUncachedBitmapProxyView(GrRecordingContext* rContext, + const SkBitmap& bitmap, + GrMipmapped mipmapped, + SkBackingFit fit, + SkBudgeted budgeted) { + GrProxyProvider* proxyProvider = rContext->priv().proxyProvider(); + const GrCaps* caps = rContext->priv().caps(); + + mipmapped = adjust_mipmapped(mipmapped, bitmap, caps); + GrColorType ct = choose_bmp_texture_colortype(caps, bitmap); + + if (auto proxy = make_bmp_proxy(proxyProvider, bitmap, ct, mipmapped, fit, budgeted)) { + GrSwizzle swizzle = caps->getReadSwizzle(proxy->backendFormat(), ct); + SkASSERT(mipmapped == GrMipmapped::kNo || proxy->mipmapped() == GrMipmapped::kYes); + return {{std::move(proxy), kTopLeft_GrSurfaceOrigin, swizzle}, ct}; + } + return {}; +} /////////////////////////////////////////////////////////////////////////////// SkPMColor4f SkColorToPMColor4f(SkColor c, const GrColorInfo& colorInfo) { diff --git a/src/gpu/SkGr.h b/src/gpu/SkGr.h index 92ce7af999..8dba066c50 100644 --- a/src/gpu/SkGr.h +++ b/src/gpu/SkGr.h @@ -178,14 +178,6 @@ enum class GrImageTexGenPolicy : int { kNew_Uncached_Budgeted }; -/** - * Returns a view that wraps a texture representing the bitmap. The texture is inserted into the - * cache (unless the bitmap is marked volatile and can be retrieved again via this function. - * A MIP mapped texture may be returned even when GrMipmapped is kNo. The function will succeed - * with a non-MIP mapped texture if GrMipmapped is kYes but MIP mapping is not supported. - */ -GrSurfaceProxyView GrRefCachedBitmapView(GrRecordingContext*, const SkBitmap&, GrMipmapped); - /** * Creates a new texture with mipmap levels and copies the baseProxy into the base layer. */ @@ -202,10 +194,28 @@ GrSurfaceProxyView GrCopyBaseMipMapToView(GrRecordingContext*, SkBudgeted = SkBudgeted::kYes); /* - * Create a texture proxy from the provided bitmap and add it to the texture cache - * using the key also extracted from 'bitmp'. + * Create a texture proxy from the provided bitmap and add it to the texture cache using the key + * also extracted from the bitmap. If GrMipmapped is kYes a non-mipmapped result may be returned + * 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. */ -GrSurfaceProxyView GrMakeCachedBitmapProxyView(GrRecordingContext*, const SkBitmap& bitmap); +std::tuple +GrMakeCachedBitmapProxyView(GrRecordingContext*, + const SkBitmap&, + GrMipmapped = GrMipmapped::kNo); + +/** + * 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*, + const SkBitmap&, + GrMipmapped = GrMipmapped::kNo, + SkBackingFit = SkBackingFit::kExact, + SkBudgeted = SkBudgeted::kYes); /** * Our key includes the offset, width, and height so that bitmaps created by extractSubset() @@ -226,8 +236,6 @@ void GrMakeKeyFromImageID(GrUniqueKey* key, uint32_t imageID, const SkIRect& ima */ sk_sp GrMakeUniqueKeyInvalidationListener(GrUniqueKey*, uint32_t contextID); -constexpr SkCubicResampler kInvalidCubicResampler{-1.f, -1.f}; - static inline bool GrValidCubicResampler(SkCubicResampler cubic) { return cubic.B >= 0 && cubic.C >= 0; } diff --git a/src/gpu/effects/GrCircleBlurFragmentProcessor.fp b/src/gpu/effects/GrCircleBlurFragmentProcessor.fp index e0764b0ab1..63c5fbde0c 100644 --- a/src/gpu/effects/GrCircleBlurFragmentProcessor.fp +++ b/src/gpu/effects/GrCircleBlurFragmentProcessor.fp @@ -40,10 +40,10 @@ uniform half4 circleData; @cpp { #include "include/gpu/GrRecordingContext.h" #include "src/core/SkGpuBlurUtils.h" - #include "src/gpu/GrBitmapTextureMaker.h" #include "src/gpu/GrProxyProvider.h" #include "src/gpu/GrRecordingContextPriv.h" #include "src/gpu/GrThreadSafeCache.h" + #include "src/gpu/SkGr.h" // Computes an unnormalized half kernel (right side). Returns the summation of all the half // kernel values. @@ -268,11 +268,9 @@ uniform half4 circleData; create_circle_profile(bm.getAddr8(0, 0), sigma * scale, circleR * scale, kProfileTextureWidth); } - bm.setImmutable(); - GrBitmapTextureMaker maker(rContext, bm, GrImageTexGenPolicy::kNew_Uncached_Budgeted); - profileView = maker.view(GrMipmapped::kNo); + profileView = std::get<0>(GrMakeUncachedBitmapProxyView(rContext, bm)); if (!profileView) { return nullptr; } diff --git a/src/gpu/effects/GrConfigConversionEffect.fp b/src/gpu/effects/GrConfigConversionEffect.fp index b22b67f8c5..301645f9e7 100644 --- a/src/gpu/effects/GrConfigConversionEffect.fp +++ b/src/gpu/effects/GrConfigConversionEffect.fp @@ -9,10 +9,10 @@ in fragmentProcessor inputFP; @header { #include "include/gpu/GrDirectContext.h" - #include "src/gpu/GrBitmapTextureMaker.h" #include "src/gpu/GrDirectContextPriv.h" #include "src/gpu/GrImageInfo.h" #include "src/gpu/GrSurfaceDrawContext.h" + #include "src/gpu/SkGr.h" } @class { @@ -55,8 +55,7 @@ in fragmentProcessor inputFP; bitmap.installPixels(pmII, srcData, 4 * kSize); bitmap.setImmutable(); - GrBitmapTextureMaker maker(dContext, bitmap, GrImageTexGenPolicy::kNew_Uncached_Budgeted); - auto dataView = maker.view(GrMipmapped::kNo); + auto dataView = std::get<0>(GrMakeUncachedBitmapProxyView(dContext, bitmap)); if (!dataView) { return false; } diff --git a/src/gpu/effects/GrMatrixConvolutionEffect.cpp b/src/gpu/effects/GrMatrixConvolutionEffect.cpp index 606323500d..bbea594b4c 100644 --- a/src/gpu/effects/GrMatrixConvolutionEffect.cpp +++ b/src/gpu/effects/GrMatrixConvolutionEffect.cpp @@ -7,13 +7,13 @@ #include "src/gpu/effects/GrMatrixConvolutionEffect.h" #include "include/private/SkHalf.h" -#include "src/gpu/GrBitmapTextureMaker.h" #include "src/gpu/GrDirectContextPriv.h" #include "src/gpu/GrProxyProvider.h" #include "src/gpu/GrRecordingContextPriv.h" #include "src/gpu/GrTexture.h" #include "src/gpu/GrTextureProxy.h" #include "src/gpu/GrThreadSafeCache.h" +#include "src/gpu/SkGr.h" #include "src/gpu/effects/GrTextureEffect.h" #include "src/gpu/glsl/GrGLSLFragmentProcessor.h" #include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h" @@ -128,8 +128,7 @@ GrMatrixConvolutionEffect::KernelWrapper::Make(GrRecordingContext* rContext, } bm.setImmutable(); - GrBitmapTextureMaker maker(rContext, bm, GrImageTexGenPolicy::kNew_Uncached_Budgeted); - view = maker.view(GrMipmapped::kNo); + view = std::get<0>(GrMakeUncachedBitmapProxyView(rContext, bm)); if (!view) { return {}; } diff --git a/src/gpu/effects/GrRRectBlurEffect.fp b/src/gpu/effects/GrRRectBlurEffect.fp index 2da6386522..f0eee4f64b 100644 --- a/src/gpu/effects/GrRRectBlurEffect.fp +++ b/src/gpu/effects/GrRRectBlurEffect.fp @@ -39,7 +39,6 @@ uniform half blurRadius; #include "src/core/SkAutoMalloc.h" #include "src/core/SkGpuBlurUtils.h" #include "src/core/SkRRectPriv.h" - #include "src/gpu/GrBitmapTextureMaker.h" #include "src/gpu/GrCaps.h" #include "src/gpu/GrDirectContextPriv.h" #include "src/gpu/GrPaint.h" @@ -48,6 +47,7 @@ uniform half blurRadius; #include "src/gpu/GrStyle.h" #include "src/gpu/GrSurfaceDrawContext.h" #include "src/gpu/GrThreadSafeCache.h" + #include "src/gpu/SkGr.h" #include "src/gpu/effects/GrTextureEffect.h" static constexpr auto kBlurredRRectMaskOrigin = kTopLeft_GrSurfaceOrigin; @@ -235,8 +235,7 @@ uniform half blurRadius; result.setImmutable(); - GrBitmapTextureMaker maker(rContext, result, GrImageTexGenPolicy::kNew_Uncached_Budgeted); - auto view = maker.view(GrMipmapped::kNo); + auto view = std::get<0>(GrMakeUncachedBitmapProxyView(rContext, result)); if (!view) { return {}; } diff --git a/src/gpu/effects/GrRectBlurEffect.fp b/src/gpu/effects/GrRectBlurEffect.fp index 8111c77f8f..f57d0854aa 100644 --- a/src/gpu/effects/GrRectBlurEffect.fp +++ b/src/gpu/effects/GrRectBlurEffect.fp @@ -13,11 +13,11 @@ #include "src/core/SkBlurMask.h" #include "src/core/SkGpuBlurUtils.h" #include "src/core/SkMathPriv.h" -#include "src/gpu/GrBitmapTextureMaker.h" #include "src/gpu/GrProxyProvider.h" #include "src/gpu/GrRecordingContextPriv.h" #include "src/gpu/GrShaderCaps.h" #include "src/gpu/GrThreadSafeCache.h" +#include "src/gpu/SkGr.h" #include "src/gpu/effects/GrTextureEffect.h" } @@ -80,8 +80,7 @@ static std::unique_ptr MakeIntegralFP(GrRecordingContext* r return {}; } - GrBitmapTextureMaker maker(rContext, bitmap, GrImageTexGenPolicy::kNew_Uncached_Budgeted); - view = maker.view(GrMipmapped::kNo); + view = std::get<0>(GrMakeUncachedBitmapProxyView(rContext, bitmap)); if (!view) { return {}; } diff --git a/src/gpu/effects/generated/GrCircleBlurFragmentProcessor.cpp b/src/gpu/effects/generated/GrCircleBlurFragmentProcessor.cpp index 728f2e1367..81c4527b90 100644 --- a/src/gpu/effects/generated/GrCircleBlurFragmentProcessor.cpp +++ b/src/gpu/effects/generated/GrCircleBlurFragmentProcessor.cpp @@ -12,10 +12,10 @@ #include "include/gpu/GrRecordingContext.h" #include "src/core/SkGpuBlurUtils.h" -#include "src/gpu/GrBitmapTextureMaker.h" #include "src/gpu/GrProxyProvider.h" #include "src/gpu/GrRecordingContextPriv.h" #include "src/gpu/GrThreadSafeCache.h" +#include "src/gpu/SkGr.h" // Computes an unnormalized half kernel (right side). Returns the summation of all the half // kernel values. @@ -250,11 +250,9 @@ static std::unique_ptr create_profile_effect(GrRecordingCon create_circle_profile( bm.getAddr8(0, 0), sigma * scale, circleR * scale, kProfileTextureWidth); } - bm.setImmutable(); - GrBitmapTextureMaker maker(rContext, bm, GrImageTexGenPolicy::kNew_Uncached_Budgeted); - profileView = maker.view(GrMipmapped::kNo); + profileView = std::get<0>(GrMakeUncachedBitmapProxyView(rContext, bm)); if (!profileView) { return nullptr; } diff --git a/src/gpu/effects/generated/GrConfigConversionEffect.cpp b/src/gpu/effects/generated/GrConfigConversionEffect.cpp index 8f65e0d30f..9f3c906556 100644 --- a/src/gpu/effects/generated/GrConfigConversionEffect.cpp +++ b/src/gpu/effects/generated/GrConfigConversionEffect.cpp @@ -121,8 +121,7 @@ bool GrConfigConversionEffect::TestForPreservingPMConversions(GrDirectContext* d bitmap.installPixels(pmII, srcData, 4 * kSize); bitmap.setImmutable(); - GrBitmapTextureMaker maker(dContext, bitmap, GrImageTexGenPolicy::kNew_Uncached_Budgeted); - auto dataView = maker.view(GrMipmapped::kNo); + auto dataView = std::get<0>(GrMakeUncachedBitmapProxyView(dContext, bitmap)); if (!dataView) { return false; } diff --git a/src/gpu/effects/generated/GrConfigConversionEffect.h b/src/gpu/effects/generated/GrConfigConversionEffect.h index d8e0c0e7c3..c148ced8e1 100644 --- a/src/gpu/effects/generated/GrConfigConversionEffect.h +++ b/src/gpu/effects/generated/GrConfigConversionEffect.h @@ -15,10 +15,10 @@ #include "include/core/SkTypes.h" #include "include/gpu/GrDirectContext.h" -#include "src/gpu/GrBitmapTextureMaker.h" #include "src/gpu/GrDirectContextPriv.h" #include "src/gpu/GrImageInfo.h" #include "src/gpu/GrSurfaceDrawContext.h" +#include "src/gpu/SkGr.h" #include "src/gpu/GrFragmentProcessor.h" diff --git a/src/gpu/effects/generated/GrRRectBlurEffect.cpp b/src/gpu/effects/generated/GrRRectBlurEffect.cpp index e2f0aa4246..03b9f09c70 100644 --- a/src/gpu/effects/generated/GrRRectBlurEffect.cpp +++ b/src/gpu/effects/generated/GrRRectBlurEffect.cpp @@ -15,7 +15,6 @@ #include "src/core/SkAutoMalloc.h" #include "src/core/SkGpuBlurUtils.h" #include "src/core/SkRRectPriv.h" -#include "src/gpu/GrBitmapTextureMaker.h" #include "src/gpu/GrCaps.h" #include "src/gpu/GrDirectContextPriv.h" #include "src/gpu/GrPaint.h" @@ -24,6 +23,7 @@ #include "src/gpu/GrStyle.h" #include "src/gpu/GrSurfaceDrawContext.h" #include "src/gpu/GrThreadSafeCache.h" +#include "src/gpu/SkGr.h" #include "src/gpu/effects/GrTextureEffect.h" static constexpr auto kBlurredRRectMaskOrigin = kTopLeft_GrSurfaceOrigin; @@ -231,8 +231,7 @@ static GrSurfaceProxyView create_mask_on_cpu(GrRecordingContext* rContext, result.setImmutable(); - GrBitmapTextureMaker maker(rContext, result, GrImageTexGenPolicy::kNew_Uncached_Budgeted); - auto view = maker.view(GrMipmapped::kNo); + auto view = std::get<0>(GrMakeUncachedBitmapProxyView(rContext, result)); if (!view) { return {}; } diff --git a/src/gpu/effects/generated/GrRectBlurEffect.h b/src/gpu/effects/generated/GrRectBlurEffect.h index 262733d55a..b7f3778e87 100644 --- a/src/gpu/effects/generated/GrRectBlurEffect.h +++ b/src/gpu/effects/generated/GrRectBlurEffect.h @@ -21,11 +21,11 @@ #include "src/core/SkBlurMask.h" #include "src/core/SkGpuBlurUtils.h" #include "src/core/SkMathPriv.h" -#include "src/gpu/GrBitmapTextureMaker.h" #include "src/gpu/GrProxyProvider.h" #include "src/gpu/GrRecordingContextPriv.h" #include "src/gpu/GrShaderCaps.h" #include "src/gpu/GrThreadSafeCache.h" +#include "src/gpu/SkGr.h" #include "src/gpu/effects/GrTextureEffect.h" #include "src/gpu/GrFragmentProcessor.h" @@ -60,8 +60,7 @@ public: return {}; } - GrBitmapTextureMaker maker(rContext, bitmap, GrImageTexGenPolicy::kNew_Uncached_Budgeted); - view = maker.view(GrMipmapped::kNo); + view = std::get<0>(GrMakeUncachedBitmapProxyView(rContext, bitmap)); if (!view) { return {}; } diff --git a/src/gpu/gradients/GrGradientShader.cpp b/src/gpu/gradients/GrGradientShader.cpp index 228e735bd1..a802893fd7 100644 --- a/src/gpu/gradients/GrGradientShader.cpp +++ b/src/gpu/gradients/GrGradientShader.cpp @@ -59,8 +59,8 @@ static std::unique_ptr make_textured_colorizer(const SkPMCo SkASSERT(1 == bitmap.height() && SkIsPow2(bitmap.width())); SkASSERT(bitmap.isImmutable()); - auto view = GrMakeCachedBitmapProxyView(args.fContext, bitmap); - if (!view.proxy()) { + auto view = std::get<0>(GrMakeCachedBitmapProxyView(args.fContext, bitmap, GrMipmapped::kNo)); + if (!view) { SkDebugf("Gradient won't draw. Could not create texture."); return nullptr; } diff --git a/src/gpu/ops/GrShadowRRectOp.cpp b/src/gpu/ops/GrShadowRRectOp.cpp index 0d272aee80..125816c383 100644 --- a/src/gpu/ops/GrShadowRRectOp.cpp +++ b/src/gpu/ops/GrShadowRRectOp.cpp @@ -9,7 +9,6 @@ #include "include/gpu/GrRecordingContext.h" #include "src/core/SkRRectPriv.h" -#include "src/gpu/GrBitmapTextureMaker.h" #include "src/gpu/GrDrawOpTest.h" #include "src/gpu/GrMemoryPool.h" #include "src/gpu/GrOpFlushState.h" @@ -17,6 +16,7 @@ #include "src/gpu/GrProxyProvider.h" #include "src/gpu/GrRecordingContextPriv.h" #include "src/gpu/GrThreadSafeCache.h" +#include "src/gpu/SkGr.h" #include "src/gpu/effects/GrShadowGeoProc.h" #include "src/gpu/ops/GrSimpleMeshDrawOpHelper.h" @@ -691,8 +691,7 @@ static GrSurfaceProxyView create_falloff_texture(GrRecordingContext* rContext) { } bitmap.setImmutable(); - GrBitmapTextureMaker maker(rContext, bitmap, GrImageTexGenPolicy::kNew_Uncached_Budgeted); - view = maker.view(GrMipmapped::kNo); + view = std::get<0>(GrMakeUncachedBitmapProxyView(rContext, bitmap)); if (!view) { return {}; } diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp index 0687ff7047..9058df5c47 100644 --- a/src/image/SkImage_Gpu.cpp +++ b/src/image/SkImage_Gpu.cpp @@ -22,7 +22,6 @@ #include "src/gpu/GrAHardwareBufferUtils.h" #include "src/gpu/GrBackendTextureImageGenerator.h" #include "src/gpu/GrBackendUtils.h" -#include "src/gpu/GrBitmapTextureMaker.h" #include "src/gpu/GrCaps.h" #include "src/gpu/GrColorSpaceXform.h" #include "src/gpu/GrContextThreadSafeProxyPriv.h" @@ -666,9 +665,8 @@ sk_sp SkImage::MakeCrossContextFromPixmap(GrDirectContext* dContext, // Turn the pixmap into a GrTextureProxy SkBitmap bmp; bmp.installPixels(*pixmap); - GrBitmapTextureMaker bitmapMaker(dContext, bmp, GrImageTexGenPolicy::kNew_Uncached_Budgeted); - GrMipmapped mipMapped = buildMips ? GrMipmapped::kYes : GrMipmapped::kNo; - auto view = bitmapMaker.view(mipMapped); + GrMipmapped mipmapped = buildMips ? GrMipmapped::kYes : GrMipmapped::kNo; + auto [view, ct] = GrMakeUncachedBitmapProxyView(dContext, bmp, mipmapped); if (!view) { return SkImage::MakeRasterCopy(*pixmap); } @@ -681,7 +679,7 @@ sk_sp SkImage::MakeCrossContextFromPixmap(GrDirectContext* dContext, std::unique_ptr sema = gpu->prepareTextureForCrossContextUsage(texture.get()); - SkColorType skCT = GrColorTypeToSkColorType(bitmapMaker.colorType()); + SkColorType skCT = GrColorTypeToSkColorType(ct); auto gen = GrBackendTextureImageGenerator::Make(std::move(texture), view.origin(), std::move(sema), skCT, pixmap->alphaType(), diff --git a/src/image/SkImage_GpuYUVA.cpp b/src/image/SkImage_GpuYUVA.cpp index c1165f8df8..387978c292 100644 --- a/src/image/SkImage_GpuYUVA.cpp +++ b/src/image/SkImage_GpuYUVA.cpp @@ -16,7 +16,6 @@ #include "src/core/SkAutoPixmapStorage.h" #include "src/core/SkMipmap.h" #include "src/core/SkScopeExit.h" -#include "src/gpu/GrBitmapTextureMaker.h" #include "src/gpu/GrClip.h" #include "src/gpu/GrDirectContextPriv.h" #include "src/gpu/GrGpu.h" @@ -295,8 +294,7 @@ sk_sp SkImage::MakeFromYUVAPixmaps(GrRecordingContext* context, // Turn the pixmap into a GrTextureProxy SkBitmap bmp; bmp.installPixels(pixmapsToUpload->plane(i)); - GrBitmapTextureMaker bitmapMaker(context, bmp, GrImageTexGenPolicy::kNew_Uncached_Budgeted); - views[i] = bitmapMaker.view(buildMips); + std::tie(views[i], std::ignore) = GrMakeUncachedBitmapProxyView(context, bmp, buildMips); if (!views[i]) { return nullptr; } diff --git a/src/image/SkImage_Lazy.cpp b/src/image/SkImage_Lazy.cpp index c0facdf4e8..344dd110b1 100644 --- a/src/image/SkImage_Lazy.cpp +++ b/src/image/SkImage_Lazy.cpp @@ -21,7 +21,6 @@ #include "include/private/GrResourceKey.h" #include "src/core/SkResourceCache.h" #include "src/core/SkYUVPlanesCache.h" -#include "src/gpu/GrBitmapTextureMaker.h" #include "src/gpu/GrCaps.h" #include "src/gpu/GrColorSpaceXform.h" #include "src/gpu/GrGpuResourcePriv.h" @@ -32,6 +31,7 @@ #include "src/gpu/GrSamplerState.h" #include "src/gpu/GrSurfaceFillContext.h" #include "src/gpu/GrYUVATextureProxies.h" +#include "src/gpu/SkGr.h" #include "src/gpu/effects/GrYUVtoRGBEffect.h" #endif @@ -310,9 +310,10 @@ GrSurfaceProxyView SkImage_Lazy::textureProxyViewFromPlanes(GrRecordingContext* SkRef(dataStorage.get())); bitmap.setImmutable(); - GrBitmapTextureMaker maker(ctx, bitmap, fit); - views[i] = maker.view(GrMipmapped::kNo); - + std::tie(views[i], std::ignore) = GrMakeUncachedBitmapProxyView(ctx, + bitmap, + GrMipmapped::kNo, + fit); if (!views[i]) { return {}; } @@ -405,7 +406,7 @@ sk_sp SkImage_Lazy::getPlanes( */ GrSurfaceProxyView SkImage_Lazy::lockTextureProxyView(GrRecordingContext* rContext, GrImageTexGenPolicy texGenPolicy, - GrMipmapped mipMapped) const { + GrMipmapped mipmapped) const { // Values representing the various texture lock paths we can take. Used for logging the path // taken to a histogram. enum LockTexturePath { @@ -444,7 +445,7 @@ GrSurfaceProxyView SkImage_Lazy::lockTextureProxyView(GrRecordingContext* rConte if (proxy) { GrSwizzle swizzle = caps->getReadSwizzle(proxy->backendFormat(), ct); GrSurfaceProxyView view(std::move(proxy), kTopLeft_GrSurfaceOrigin, swizzle); - if (mipMapped == GrMipmapped::kNo || + if (mipmapped == GrMipmapped::kNo || view.asTextureProxy()->mipmapped() == GrMipmapped::kYes) { return view; } else { @@ -468,7 +469,10 @@ GrSurfaceProxyView SkImage_Lazy::lockTextureProxyView(GrRecordingContext* rConte // 2. Ask the generator to natively create one. { ScopedGenerator generator(fSharedGenerator); - if (auto view = generator->generateTexture(rContext, this->imageInfo(), {0,0}, mipMapped, + if (auto view = generator->generateTexture(rContext, + this->imageInfo(), + {0,0}, + mipmapped, texGenPolicy)) { installKey(view); return view; @@ -477,7 +481,7 @@ GrSurfaceProxyView SkImage_Lazy::lockTextureProxyView(GrRecordingContext* rConte // 3. Ask the generator to return YUV planes, which the GPU can convert. If we will be mipping // the texture we skip this step so the CPU generate non-planar MIP maps for us. - if (mipMapped == GrMipmapped::kNo && !rContext->priv().options().fDisableGpuYUVConversion) { + if (mipmapped == GrMipmapped::kNo && !rContext->priv().options().fDisableGpuYUVConversion) { // TODO: Update to create the mipped surface in the textureProxyViewFromPlanes generator and // draw the base layer directly into the mipped surface. SkBudgeted budgeted = texGenPolicy == GrImageTexGenPolicy::kNew_Uncached_Unbudgeted @@ -494,13 +498,16 @@ GrSurfaceProxyView SkImage_Lazy::lockTextureProxyView(GrRecordingContext* rConte auto hint = texGenPolicy == GrImageTexGenPolicy::kDraw ? CachingHint::kAllow_CachingHint : CachingHint::kDisallow_CachingHint; if (SkBitmap bitmap; this->getROPixels(nullptr, &bitmap, hint)) { - // We always pass uncached here because we will cache it external to the maker based on - // *our* cache policy. We're just using the maker to generate the texture. - auto makerPolicy = texGenPolicy == GrImageTexGenPolicy::kNew_Uncached_Unbudgeted - ? GrImageTexGenPolicy::kNew_Uncached_Unbudgeted - : GrImageTexGenPolicy::kNew_Uncached_Budgeted; - GrBitmapTextureMaker bitmapMaker(rContext, bitmap, makerPolicy); - auto view = bitmapMaker.view(mipMapped); + // We always make an uncached bitmap here because we will cache it based on passed in policy + // with *our* key, not a key derived from bitmap. We're just making the proxy here. + auto budgeted = texGenPolicy == GrImageTexGenPolicy::kNew_Uncached_Unbudgeted + ? SkBudgeted::kNo + : SkBudgeted::kYes; + auto view = std::get<0>(GrMakeUncachedBitmapProxyView(rContext, + bitmap, + mipmapped, + SkBackingFit::kExact, + budgeted)); if (view) { installKey(view); return view; diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp index 9c1e73b8f3..d993bf041c 100644 --- a/src/image/SkImage_Raster.cpp +++ b/src/image/SkImage_Raster.cpp @@ -20,9 +20,10 @@ #include "src/shaders/SkBitmapProcShader.h" #if SK_SUPPORT_GPU -#include "src/gpu/GrBitmapTextureMaker.h" #include "src/gpu/GrTextureAdjuster.h" #include "src/gpu/SkGr.h" +#include "src/gpu/effects/GrBicubicEffect.h" +#include "src/gpu/effects/GrTextureEffect.h" #endif // fixes https://bug.skia.org/5096 @@ -212,15 +213,15 @@ bool SkImage_Raster::onPinAsTexture(GrRecordingContext* rContext) const { } else { SkASSERT(fPinnedCount == 0); SkASSERT(fPinnedUniqueID == 0); - GrBitmapTextureMaker maker(rContext, fBitmap, GrImageTexGenPolicy::kDraw); - fPinnedView = maker.view(GrMipmapped::kNo); + std::tie(fPinnedView, fPinnedColorType) = GrMakeCachedBitmapProxyView(rContext, + fBitmap, + GrMipmapped::kNo); if (!fPinnedView) { + fPinnedColorType = GrColorType::kUnknown; return false; } - SkASSERT(fPinnedView.asTextureProxy()); fPinnedUniqueID = fBitmap.getGenerationID(); fPinnedContextID = rContext->priv().contextID(); - fPinnedColorType = maker.colorType(); } // Note: we only increment if the texture was successfully pinned ++fPinnedCount; @@ -425,9 +426,17 @@ std::tuple SkImage_Raster::onAsView( GrTextureAdjuster adjuster(rContext, fPinnedView, colorInfo, fPinnedUniqueID); return {adjuster.view(mipmapped), adjuster.colorType()}; } - - GrBitmapTextureMaker maker(rContext, fBitmap, policy); - return {maker.view(mipmapped), maker.colorType()}; + if (policy == GrImageTexGenPolicy::kDraw) { + return GrMakeCachedBitmapProxyView(rContext, fBitmap, mipmapped); + } + auto budgeted = (policy == GrImageTexGenPolicy::kNew_Uncached_Unbudgeted) + ? SkBudgeted::kNo + : SkBudgeted::kYes; + return GrMakeUncachedBitmapProxyView(rContext, + fBitmap, + mipmapped, + SkBackingFit::kExact, + budgeted); } std::unique_ptr SkImage_Raster::onAsFragmentProcessor( @@ -437,13 +446,67 @@ std::unique_ptr SkImage_Raster::onAsFragmentProcessor( const SkMatrix& m, const SkRect* subset, const SkRect* domain) const { + auto mm = sampling.mipmap == SkMipmapMode::kNone ? GrMipmapped::kNo : GrMipmapped::kYes; + auto [view, ct] = this->asView(context, mm); + if (!view) { + return nullptr; + } + const GrCaps& caps = *context->priv().caps(); auto wmx = SkTileModeToWrapMode(tileModes[0]); auto wmy = SkTileModeToWrapMode(tileModes[1]); - GrBitmapTextureMaker maker(context, fBitmap, GrImageTexGenPolicy::kDraw); if (sampling.useCubic) { - return maker.createBicubicFragmentProcessor(m, subset, domain, wmx, wmy, sampling.cubic); + if (subset) { + if (domain) { + return GrBicubicEffect::MakeSubset(std::move(view), + this->alphaType(), + m, + wmx, + wmy, + *subset, + *domain, + sampling.cubic, + GrBicubicEffect::Direction::kXY, + *context->priv().caps()); + } + return GrBicubicEffect::MakeSubset(std::move(view), + this->alphaType(), + m, + wmx, + wmy, + *subset, + sampling.cubic, + GrBicubicEffect::Direction::kXY, + *context->priv().caps()); + } + return GrBicubicEffect::Make(std::move(view), + this->alphaType(), + m, + wmx, + wmy, + sampling.cubic, + GrBicubicEffect::Direction::kXY, + *context->priv().caps()); } + GrSamplerState sampler(wmx, wmy, sampling.filter, sampling.mipmap); - return maker.createFragmentProcessor(m, subset, domain, sampler); + if (subset) { + if (domain) { + return GrTextureEffect::MakeSubset(std::move(view), + this->alphaType(), + m, + sampler, + *subset, + *domain, + caps); + } + return GrTextureEffect::MakeSubset(std::move(view), + this->alphaType(), + m, + sampler, + *subset, + caps); + } else { + return GrTextureEffect::Make(std::move(view), this->alphaType(), m, sampler, caps); + } } #endif diff --git a/src/shaders/SkImageShader.cpp b/src/shaders/SkImageShader.cpp index 4a3d5ef075..8f01590d99 100755 --- a/src/shaders/SkImageShader.cpp +++ b/src/shaders/SkImageShader.cpp @@ -314,17 +314,8 @@ sk_sp SkImageShader::Make(sk_sp image, #if SK_SUPPORT_GPU -#include "include/gpu/GrRecordingContext.h" -#include "src/gpu/GrBitmapTextureMaker.h" -#include "src/gpu/GrCaps.h" #include "src/gpu/GrColorInfo.h" -#include "src/gpu/GrImageTextureMaker.h" -#include "src/gpu/GrRecordingContextPriv.h" -#include "src/gpu/GrTextureAdjuster.h" -#include "src/gpu/SkGr.h" -#include "src/gpu/effects/GrBicubicEffect.h" #include "src/gpu/effects/GrBlendFragmentProcessor.h" -#include "src/gpu/effects/GrTextureEffect.h" std::unique_ptr SkImageShader::asFragmentProcessor( const GrFPArgs& args) const { diff --git a/src/shaders/SkPerlinNoiseShader.cpp b/src/shaders/SkPerlinNoiseShader.cpp index c39d29eaa0..83430c7106 100644 --- a/src/shaders/SkPerlinNoiseShader.cpp +++ b/src/shaders/SkPerlinNoiseShader.cpp @@ -975,18 +975,13 @@ std::unique_ptr SkPerlinNoiseShaderImpl::asFragmentProcesso return GrFragmentProcessor::MakeColor(SK_PMColor4fTRANSPARENT); } - // Need to assert that the textures we'll create are power of 2 so that now copy is needed. We - // also know that we will not be using mipmaps. If things things weren't true we should go - // through GrBitmapTextureMaker to handle needed copies. const SkBitmap& permutationsBitmap = paintingData->getPermutationsBitmap(); - SkASSERT(SkIsPow2(permutationsBitmap.width()) && SkIsPow2(permutationsBitmap.height())); - auto permutationsView = GrMakeCachedBitmapProxyView(context, permutationsBitmap); + const SkBitmap& noiseBitmap = paintingData->getNoiseBitmap(); - const SkBitmap& noiseBitmap = paintingData->getNoiseBitmap(); - SkASSERT(SkIsPow2(noiseBitmap.width()) && SkIsPow2(noiseBitmap.height())); - auto noiseView = GrMakeCachedBitmapProxyView(context, noiseBitmap); + auto permutationsView = std::get<0>(GrMakeCachedBitmapProxyView(context, permutationsBitmap)); + auto noiseView = std::get<0>(GrMakeCachedBitmapProxyView(context, noiseBitmap)); - if (permutationsView.proxy() && noiseView.proxy()) { + if (permutationsView && noiseView) { auto inner = GrPerlinNoise2Effect::Make(fType, fNumOctaves, fStitchTiles, diff --git a/tests/GrSurfaceTest.cpp b/tests/GrSurfaceTest.cpp index 68d0b2782f..79aae770eb 100644 --- a/tests/GrSurfaceTest.cpp +++ b/tests/GrSurfaceTest.cpp @@ -12,7 +12,6 @@ #include "src/core/SkCanvasPriv.h" #include "src/core/SkCompressedDataUtils.h" #include "src/gpu/GrBackendUtils.h" -#include "src/gpu/GrBitmapTextureMaker.h" #include "src/gpu/GrDirectContextPriv.h" #include "src/gpu/GrGpu.h" #include "src/gpu/GrImageInfo.h" @@ -21,6 +20,7 @@ #include "src/gpu/GrResourceProvider.h" #include "src/gpu/GrSurfaceDrawContext.h" #include "src/gpu/GrTexture.h" +#include "src/gpu/SkGr.h" #include "tests/Test.h" #include "tests/TestUtils.h" #include "tools/gpu/BackendTextureImageFactory.h" @@ -398,11 +398,9 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadOnlyTexture, reporter, context_info) { copySrcBitmap.installPixels(write); copySrcBitmap.setImmutable(); - GrBitmapTextureMaker maker(dContext, copySrcBitmap, - GrImageTexGenPolicy::kNew_Uncached_Budgeted); - auto copySrc = maker.view(GrMipmapped::kNo); + auto copySrc = std::get<0>(GrMakeUncachedBitmapProxyView(dContext, copySrcBitmap)); - REPORTER_ASSERT(reporter, copySrc.proxy()); + REPORTER_ASSERT(reporter, copySrc); auto copyResult = surfContext->testCopy(copySrc.refProxy()); REPORTER_ASSERT(reporter, copyResult == (ioType == kRW_GrIOType)); // Try the low level copy. diff --git a/tests/ImageFilterCacheTest.cpp b/tests/ImageFilterCacheTest.cpp index 26f71ccd21..19603b0947 100644 --- a/tests/ImageFilterCacheTest.cpp +++ b/tests/ImageFilterCacheTest.cpp @@ -202,18 +202,17 @@ DEF_TEST(ImageFilterCache_ImageBackedRaster, reporter) { } #include "include/gpu/GrDirectContext.h" -#include "src/gpu/GrBitmapTextureMaker.h" #include "src/gpu/GrDirectContextPriv.h" #include "src/gpu/GrProxyProvider.h" #include "src/gpu/GrResourceProvider.h" #include "src/gpu/GrSurfaceProxyPriv.h" #include "src/gpu/GrTexture.h" #include "src/gpu/GrTextureProxy.h" +#include "src/gpu/SkGr.h" static GrSurfaceProxyView create_proxy_view(GrRecordingContext* rContext) { SkBitmap srcBM = create_bm(); - GrBitmapTextureMaker maker(rContext, srcBM, GrImageTexGenPolicy::kNew_Uncached_Budgeted); - return maker.view(GrMipmapped::kNo); + return std::get<0>(GrMakeUncachedBitmapProxyView(rContext, srcBM)); } DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCache_ImageBackedGPU, reporter, ctxInfo) { diff --git a/tests/ProcessorTest.cpp b/tests/ProcessorTest.cpp index 52d8c88fb6..746c58901e 100644 --- a/tests/ProcessorTest.cpp +++ b/tests/ProcessorTest.cpp @@ -8,7 +8,6 @@ #include "tests/Test.h" #include "include/gpu/GrDirectContext.h" -#include "src/gpu/GrBitmapTextureMaker.h" #include "src/gpu/GrClip.h" #include "src/gpu/GrDirectContextPriv.h" #include "src/gpu/GrGpuResource.h" @@ -17,6 +16,7 @@ #include "src/gpu/GrProxyProvider.h" #include "src/gpu/GrResourceProvider.h" #include "src/gpu/GrSurfaceDrawContext.h" +#include "src/gpu/SkGr.h" #include "src/gpu/glsl/GrGLSLFragmentProcessor.h" #include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h" #include "src/gpu/ops/GrFillRectOp.h" @@ -285,10 +285,8 @@ class TestFPGenerator { ii, rgbaData, ii.minRowBytes(), [](void* addr, void* context) { delete[](GrColor*) addr; }, nullptr); bitmap.setImmutable(); - GrBitmapTextureMaker maker(fContext, bitmap, - GrImageTexGenPolicy::kNew_Uncached_Budgeted); - GrSurfaceProxyView view = maker.view(GrMipmapped::kNo); - if (!view.proxy() || !view.proxy()->instantiate(fResourceProvider)) { + auto view = std::get<0>(GrMakeUncachedBitmapProxyView(fContext, bitmap)); + if (!view || !view.proxy()->instantiate(fResourceProvider)) { SkDebugf("Unable to instantiate RGBA8888 test texture."); return false; } @@ -312,10 +310,8 @@ class TestFPGenerator { ii, alphaData, ii.minRowBytes(), [](void* addr, void* context) { delete[](uint8_t*) addr; }, nullptr); bitmap.setImmutable(); - GrBitmapTextureMaker maker(fContext, bitmap, - GrImageTexGenPolicy::kNew_Uncached_Budgeted); - GrSurfaceProxyView view = maker.view(GrMipmapped::kNo); - if (!view.proxy() || !view.proxy()->instantiate(fResourceProvider)) { + auto view = std::get<0>(GrMakeUncachedBitmapProxyView(fContext, bitmap)); + if (!view || !view.proxy()->instantiate(fResourceProvider)) { SkDebugf("Unable to instantiate A8 test texture."); return false; } @@ -386,8 +382,7 @@ GrSurfaceProxyView make_input_texture(GrRecordingContext* context, SkBitmap bitmap; bitmap.installPixels(ii, pixel, ii.minRowBytes()); bitmap.setImmutable(); - GrBitmapTextureMaker maker(context, bitmap, GrImageTexGenPolicy::kNew_Uncached_Budgeted); - return maker.view(GrMipmapped::kNo); + return std::get<0>(GrMakeUncachedBitmapProxyView(context, bitmap)); } // We tag logged data as unpremul to avoid conversion when encoding as PNG. The input texture diff --git a/tests/SpecialImageTest.cpp b/tests/SpecialImageTest.cpp index a45b725baf..90f233a304 100644 --- a/tests/SpecialImageTest.cpp +++ b/tests/SpecialImageTest.cpp @@ -15,7 +15,6 @@ #include "src/core/SkAutoPixmapStorage.h" #include "src/core/SkSpecialImage.h" #include "src/core/SkSpecialSurface.h" -#include "src/gpu/GrBitmapTextureMaker.h" #include "src/gpu/GrDirectContextPriv.h" #include "src/gpu/GrProxyProvider.h" #include "src/gpu/GrSurfaceProxy.h" @@ -189,37 +188,36 @@ DEF_TEST(SpecialImage_Image_Legacy, reporter) { DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_Gpu, reporter, ctxInfo) { auto context = ctxInfo.directContext(); SkBitmap bm = create_bm(); - GrBitmapTextureMaker maker(context, bm, GrImageTexGenPolicy::kNew_Uncached_Budgeted); - auto view = maker.view(GrMipmapped::kNo); - if (!view.proxy()) { + auto [view, ct] = GrMakeUncachedBitmapProxyView(context, bm); + if (!view) { return; } - sk_sp fullSImg( + sk_sp fullSImg = SkSpecialImage::MakeDeferredFromGpu(context, SkIRect::MakeWH(kFullSize, kFullSize), kNeedNewImageUniqueID_SpecialImage, view, - maker.colorType(), + ct, nullptr, - SkSurfaceProps())); + SkSurfaceProps()); const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize); { - sk_sp subSImg1(SkSpecialImage::MakeDeferredFromGpu( + sk_sp subSImg1 = SkSpecialImage::MakeDeferredFromGpu( context, subset, kNeedNewImageUniqueID_SpecialImage, std::move(view), - maker.colorType(), + ct, nullptr, - SkSurfaceProps())); + SkSurfaceProps()); test_image(subSImg1, reporter, context, true); } { - sk_sp subSImg2(fullSImg->makeSubset(subset)); + sk_sp subSImg2 = fullSImg->makeSubset(subset); test_image(subSImg2, reporter, context, true); } }