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 <robertphillips@google.com>
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Brian Salomon 2021-04-28 12:39:21 -04:00 committed by Skia Commit-Bot
parent ffeef16664
commit 27c4202f4b
42 changed files with 319 additions and 364 deletions

View File

@ -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"

View File

@ -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<GrFragmentProcessor> wrap(std::unique_ptr<GrFragmentProce
DEF_SIMPLE_GPU_GM(fp_sample_chaining, ctx, rtCtx, canvas, 380, 306) {
SkBitmap bmp = make_test_bitmap();
GrBitmapTextureMaker maker(ctx, bmp, GrImageTexGenPolicy::kDraw);
int x = 10, y = 10;
auto nextCol = [&] { x += (64 + 10); };
@ -227,8 +226,8 @@ DEF_SIMPLE_GPU_GM(fp_sample_chaining, ctx, rtCtx, canvas, 380, 306) {
#if 0
auto fp = std::unique_ptr<GrFragmentProcessor>(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);

View File

@ -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;
}

View File

@ -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<GrFragmentProcessor> imgFP =
GrTextureEffect::Make(std::move(view), bmp.alphaType(), SkMatrix());
auto [view, ct] = GrMakeCachedBitmapProxyView(ctx, bmp, GrMipmapped::kNo);
std::unique_ptr<GrFragmentProcessor> 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);
}

View File

@ -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<GrFragmentProcessor> imgFP =
GrTextureEffect::Make(std::move(view), bmp.alphaType(), SkMatrix());
draw(std::move(imgFP), -128, 256, 0, 0);

View File

@ -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;
}

View File

@ -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);

View File

@ -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 <memory>
@ -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;

View File

@ -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",

View File

@ -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 {};

View File

@ -184,13 +184,13 @@ std::unique_ptr<GrFragmentProcessor> 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<GrFragmentProcessor>(
new ColorTableEffect(std::move(inputFP), std::move(view)));
return std::unique_ptr<GrFragmentProcessor>(new ColorTableEffect(std::move(inputFP),
std::move(view)));
}
///////////////////////////////////////////////////////////////////////////////

View File

@ -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<GrTextureProxy> 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 {};
}

View File

@ -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

View File

@ -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 {};
}

View File

@ -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));
}

View File

@ -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<SkSpecialImage> 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;
}

View File

@ -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;

View File

@ -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"

View File

@ -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<GrTextureProxy> 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<GrSurfaceProxyView, GrColorType>
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<GrTextureProxy> 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<GrSurfaceProxyView, GrColorType>
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) {

View File

@ -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<GrSurfaceProxyView, GrColorType>
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<GrSurfaceProxyView, GrColorType>
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<SkIDChangeListener> 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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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 {};
}

View File

@ -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 {};
}

View File

@ -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<GrFragmentProcessor> 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 {};
}

View File

@ -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<GrFragmentProcessor> 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;
}

View File

@ -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;
}

View File

@ -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"

View File

@ -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 {};
}

View File

@ -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 {};
}

View File

@ -59,8 +59,8 @@ static std::unique_ptr<GrFragmentProcessor> 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;
}

View File

@ -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 {};
}

View File

@ -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> 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> SkImage::MakeCrossContextFromPixmap(GrDirectContext* dContext,
std::unique_ptr<GrSemaphore> 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(),

View File

@ -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> 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;
}

View File

@ -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<SkCachedData> 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;

View File

@ -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<GrSurfaceProxyView, GrColorType> 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<GrFragmentProcessor> SkImage_Raster::onAsFragmentProcessor(
@ -437,13 +446,67 @@ std::unique_ptr<GrFragmentProcessor> 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

View File

@ -314,17 +314,8 @@ sk_sp<SkShader> SkImageShader::Make(sk_sp<SkImage> 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<GrFragmentProcessor> SkImageShader::asFragmentProcessor(
const GrFPArgs& args) const {

View File

@ -975,18 +975,13 @@ std::unique_ptr<GrFragmentProcessor> 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,

View File

@ -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.

View File

@ -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) {

View File

@ -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

View File

@ -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<SkSpecialImage> fullSImg(
sk_sp<SkSpecialImage> 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<SkSpecialImage> subSImg1(SkSpecialImage::MakeDeferredFromGpu(
sk_sp<SkSpecialImage> subSImg1 = SkSpecialImage::MakeDeferredFromGpu(
context,
subset,
kNeedNewImageUniqueID_SpecialImage,
std::move(view),
maker.colorType(),
ct,
nullptr,
SkSurfaceProps()));
SkSurfaceProps());
test_image(subSImg1, reporter, context, true);
}
{
sk_sp<SkSpecialImage> subSImg2(fullSImg->makeSubset(subset));
sk_sp<SkSpecialImage> subSImg2 = fullSImg->makeSubset(subset);
test_image(subSImg2, reporter, context, true);
}
}