diff --git a/src/effects/SkTableColorFilter.cpp b/src/effects/SkTableColorFilter.cpp index 0a5412fe7b..3373ff992f 100644 --- a/src/effects/SkTableColorFilter.cpp +++ b/src/effects/SkTableColorFilter.cpp @@ -289,8 +289,7 @@ public: const char* name() const override { return "ColorTableEffect"; } std::unique_ptr clone() const override { - return std::unique_ptr( - new ColorTableEffect(sk_ref_sp(fTextureSampler.view().proxy()))); + return std::unique_ptr(new ColorTableEffect(fTextureSampler.view())); } private: @@ -300,10 +299,11 @@ private: bool onIsEqual(const GrFragmentProcessor&) const override { return true; } - ColorTableEffect(sk_sp proxy) - : INHERITED(kColorTableEffect_ClassID, - kNone_OptimizationFlags) // Not bothering with table-specific optimizations. - , fTextureSampler(std::move(proxy)) { + ColorTableEffect(GrSurfaceProxyView view) + : INHERITED( + kColorTableEffect_ClassID, + kNone_OptimizationFlags) // Not bothering with table-specific optimizations. + , fTextureSampler(std::move(view)) { this->setTextureSamplerCnt(1); } @@ -378,11 +378,11 @@ std::unique_ptr ColorTableEffect::Make(GrRecordingContext* SkASSERT(bitmap.isImmutable()); auto view = GrMakeCachedBitmapProxyView(context, bitmap); - if (!view.proxy()) { + if (!view) { return nullptr; } - return std::unique_ptr(new ColorTableEffect(view.detachProxy())); + return std::unique_ptr(new ColorTableEffect(std::move(view))); } void ColorTableEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps, diff --git a/src/effects/imagefilters/SkAlphaThresholdFilter.cpp b/src/effects/imagefilters/SkAlphaThresholdFilter.cpp index 86ab4787de..9984491aab 100644 --- a/src/effects/imagefilters/SkAlphaThresholdFilter.cpp +++ b/src/effects/imagefilters/SkAlphaThresholdFilter.cpp @@ -45,9 +45,9 @@ protected: sk_sp onFilterImage(const Context&, SkIPoint* offset) const override; #if SK_SUPPORT_GPU - sk_sp createMaskTexture(GrRecordingContext*, - const SkMatrix&, - const SkIRect& bounds) const; + GrSurfaceProxyView createMaskTexture(GrRecordingContext*, + const SkMatrix&, + const SkIRect& bounds) const; #endif private: @@ -100,13 +100,13 @@ void SkAlphaThresholdFilterImpl::flatten(SkWriteBuffer& buffer) const { } #if SK_SUPPORT_GPU -sk_sp SkAlphaThresholdFilterImpl::createMaskTexture(GrRecordingContext* context, - const SkMatrix& inMatrix, - const SkIRect& bounds) const { +GrSurfaceProxyView SkAlphaThresholdFilterImpl::createMaskTexture(GrRecordingContext* context, + const SkMatrix& inMatrix, + const SkIRect& bounds) const { auto rtContext = GrRenderTargetContext::MakeWithFallback( context, GrColorType::kAlpha_8, nullptr, SkBackingFit::kApprox, bounds.size()); if (!rtContext) { - return nullptr; + return {}; } SkRegion::Iterator iter(fRegion); @@ -125,7 +125,7 @@ sk_sp SkAlphaThresholdFilterImpl::createMaskTexture(GrRecordingC iter.next(); } - return rtContext->asTextureProxyRef(); + return rtContext->readSurfaceView(); } #endif @@ -161,8 +161,8 @@ sk_sp SkAlphaThresholdFilterImpl::onFilterImage(const Context& c SkMatrix matrix(ctx.ctm()); matrix.postTranslate(SkIntToScalar(-offset->fX), SkIntToScalar(-offset->fY)); - sk_sp maskProxy(this->createMaskTexture(context, matrix, bounds)); - if (!maskProxy) { + GrSurfaceProxyView maskView = this->createMaskTexture(context, matrix, bounds); + if (!maskView) { return nullptr; } @@ -175,10 +175,8 @@ sk_sp SkAlphaThresholdFilterImpl::onFilterImage(const Context& c return nullptr; } - auto thresholdFP = GrAlphaThresholdFragmentProcessor::Make(std::move(maskProxy), - fInnerThreshold, - fOuterThreshold, - bounds); + auto thresholdFP = GrAlphaThresholdFragmentProcessor::Make( + std::move(maskView), fInnerThreshold, fOuterThreshold, bounds); if (!thresholdFP) { return nullptr; } diff --git a/src/effects/imagefilters/SkMagnifierImageFilter.cpp b/src/effects/imagefilters/SkMagnifierImageFilter.cpp index 7a3d38c8e7..dc4fc2a88e 100644 --- a/src/effects/imagefilters/SkMagnifierImageFilter.cpp +++ b/src/effects/imagefilters/SkMagnifierImageFilter.cpp @@ -138,7 +138,7 @@ sk_sp SkMagnifierImageFilterImpl::onFilterImage(const Context& c (1.f - invYZoom) * input->subset().y()); // TODO: Update generated fp file Make functions to take views instead of proxies - auto fp = GrMagnifierEffect::Make(inputView.detachProxy(), + auto fp = GrMagnifierEffect::Make(std::move(inputView), bounds, srcRect, invXZoom, diff --git a/src/gpu/effects/GrAlphaThresholdFragmentProcessor.fp b/src/gpu/effects/GrAlphaThresholdFragmentProcessor.fp index ad8251e781..9013d4edbc 100644 --- a/src/gpu/effects/GrAlphaThresholdFragmentProcessor.fp +++ b/src/gpu/effects/GrAlphaThresholdFragmentProcessor.fp @@ -18,12 +18,12 @@ in uniform half outerThreshold; } @make { - static std::unique_ptr Make(sk_sp mask, + static std::unique_ptr Make(GrSurfaceProxyView mask, float innerThreshold, float outerThreshold, const SkIRect& bounds) { return std::unique_ptr(new GrAlphaThresholdFragmentProcessor( - mask, innerThreshold, outerThreshold, bounds)); + std::move(mask), innerThreshold, outerThreshold, bounds)); } } @@ -72,6 +72,11 @@ void main() { uint32_t x = testData->fRandom->nextULessThan(kMaxWidth - width); uint32_t y = testData->fRandom->nextULessThan(kMaxHeight - height); SkIRect bounds = SkIRect::MakeXYWH(x, y, width, height); - return GrAlphaThresholdFragmentProcessor::Make(std::move(maskProxy), innerThresh, outerThresh, + + GrSurfaceOrigin origin = maskProxy->origin(); + GrSwizzle swizzle = maskProxy->textureSwizzle(); + GrSurfaceProxyView view(std::move(maskProxy), origin, swizzle); + + return GrAlphaThresholdFragmentProcessor::Make(std::move(view), innerThresh, outerThresh, bounds); } diff --git a/src/gpu/effects/GrCircleBlurFragmentProcessor.fp b/src/gpu/effects/GrCircleBlurFragmentProcessor.fp index 33b6171df7..0a24cee081 100644 --- a/src/gpu/effects/GrCircleBlurFragmentProcessor.fp +++ b/src/gpu/effects/GrCircleBlurFragmentProcessor.fp @@ -188,13 +188,13 @@ uniform half4 circleData; profile[profileWidth - 1] = 0; } - static sk_sp create_profile_texture(GrRecordingContext* context, - const SkRect& circle, - float sigma, - float* solidRadius, float* textureRadius) { + static GrSurfaceProxyView create_profile_texture(GrRecordingContext* context, + const SkRect& circle, + float sigma, + float* solidRadius, float* textureRadius) { float circleR = circle.width() / 2.0f; if (circleR < SK_ScalarNearlyZero) { - return nullptr; + return {}; } // Profile textures are cached by the ratio of sigma to circle radius and by the size of the // profile texture (binned by powers of 2). @@ -231,45 +231,46 @@ uniform half4 circleData; builder.finish(); GrProxyProvider* proxyProvider = context->priv().proxyProvider(); - sk_sp blurProfile = proxyProvider->findOrCreateProxyByUniqueKey( - key, GrColorType::kAlpha_8, kTopLeft_GrSurfaceOrigin); - if (!blurProfile) { - static constexpr int kProfileTextureWidth = 512; - - SkBitmap bm; - if (!bm.tryAllocPixels(SkImageInfo::MakeA8(kProfileTextureWidth, 1))) { - return nullptr; - } - - if (useHalfPlaneApprox) { - create_half_plane_profile(bm.getAddr8(0, 0), kProfileTextureWidth); - } else { - // Rescale params to the size of the texture we're creating. - SkScalar scale = kProfileTextureWidth / *textureRadius; - create_circle_profile(bm.getAddr8(0, 0), sigma * scale, circleR * scale, - kProfileTextureWidth); - } - - bm.setImmutable(); - - GrBitmapTextureMaker maker(context, bm); - auto[blurView, grCT] = maker.view(GrMipMapped::kNo); - blurProfile = blurView.asTextureProxyRef(); - if (!blurProfile) { - return nullptr; - } - proxyProvider->assignUniqueKeyToProxy(key, blurProfile.get()); + if (sk_sp blurProfile = proxyProvider->findOrCreateProxyByUniqueKey( + key, GrColorType::kAlpha_8, kTopLeft_GrSurfaceOrigin)) { + GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(blurProfile->backendFormat(), + GrColorType::kAlpha_8); + return {std::move(blurProfile), kTopLeft_GrSurfaceOrigin, swizzle}; } - return blurProfile; + static constexpr int kProfileTextureWidth = 512; + + SkBitmap bm; + if (!bm.tryAllocPixels(SkImageInfo::MakeA8(kProfileTextureWidth, 1))) { + return {}; + } + + if (useHalfPlaneApprox) { + create_half_plane_profile(bm.getAddr8(0, 0), kProfileTextureWidth); + } else { + // Rescale params to the size of the texture we're creating. + SkScalar scale = kProfileTextureWidth / *textureRadius; + create_circle_profile(bm.getAddr8(0, 0), sigma * scale, circleR * scale, + kProfileTextureWidth); + } + + bm.setImmutable(); + + GrBitmapTextureMaker maker(context, bm); + auto[blurView, grCT] = maker.view(GrMipMapped::kNo); + if (!blurView) { + return {}; + } + proxyProvider->assignUniqueKeyToProxy(key, blurView.asTextureProxy()); + return blurView; } std::unique_ptr GrCircleBlurFragmentProcessor::Make( GrRecordingContext* context, const SkRect& circle, float sigma) { float solidRadius; float textureRadius; - sk_sp profile(create_profile_texture(context, circle, sigma, - &solidRadius, &textureRadius)); + GrSurfaceProxyView profile = create_profile_texture(context, circle, sigma, + &solidRadius, &textureRadius); if (!profile) { return nullptr; } diff --git a/src/gpu/effects/GrMagnifierEffect.fp b/src/gpu/effects/GrMagnifierEffect.fp index e9f8317ec8..e862edd886 100644 --- a/src/gpu/effects/GrMagnifierEffect.fp +++ b/src/gpu/effects/GrMagnifierEffect.fp @@ -82,7 +82,11 @@ void main() { SkIRect bounds = SkIRect::MakeWH(SkIntToScalar(kMaxWidth), SkIntToScalar(kMaxHeight)); SkRect srcRect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height)); - auto effect = GrMagnifierEffect::Make(std::move(proxy), + GrSurfaceOrigin origin = proxy->origin(); + GrSwizzle swizzle = proxy->textureSwizzle(); + GrSurfaceProxyView view(std::move(proxy), origin, swizzle); + + auto effect = GrMagnifierEffect::Make(std::move(view), bounds, srcRect, srcRect.width() / bounds.width(), diff --git a/src/gpu/effects/GrRRectBlurEffect.fp b/src/gpu/effects/GrRRectBlurEffect.fp index 765bd60d12..3505878b35 100644 --- a/src/gpu/effects/GrRRectBlurEffect.fp +++ b/src/gpu/effects/GrRRectBlurEffect.fp @@ -28,10 +28,10 @@ uniform half blurRadius; } @class { - static sk_sp find_or_create_rrect_blur_mask(GrRecordingContext* context, - const SkRRect& rrectToDraw, - const SkISize& dimensions, - float xformedSigma) { + static GrSurfaceProxyView find_or_create_rrect_blur_mask(GrRecordingContext* context, + const SkRRect& rrectToDraw, + const SkISize& dimensions, + float xformedSigma) { static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); GrUniqueKey key; GrUniqueKey::Builder builder(&key, kDomain, 9, "RoundRect Blur Mask"); @@ -49,49 +49,54 @@ uniform half blurRadius; GrProxyProvider* proxyProvider = context->priv().proxyProvider(); - sk_sp mask(proxyProvider->findOrCreateProxyByUniqueKey( - key, GrColorType::kAlpha_8, kBottomLeft_GrSurfaceOrigin)); - if (!mask) { - auto rtc = GrRenderTargetContext::MakeWithFallback( - context, GrColorType::kAlpha_8, nullptr, SkBackingFit::kExact, dimensions); - if (!rtc) { - return nullptr; - } - - GrPaint paint; - - rtc->clear(nullptr, SK_PMColor4fTRANSPARENT, - GrRenderTargetContext::CanClearFullscreen::kYes); - rtc->drawRRect(GrNoClip(), std::move(paint), GrAA::kYes, SkMatrix::I(), rrectToDraw, - GrStyle::SimpleFill()); - - GrSurfaceProxyView srcView = rtc->readSurfaceView(); - if (!srcView.asTextureProxy()) { - return nullptr; - } - auto rtc2 = SkGpuBlurUtils::GaussianBlur(context, - std::move(srcView), - rtc->colorInfo().colorType(), - rtc->colorInfo().alphaType(), - nullptr, - SkIRect::MakeSize(dimensions), - SkIRect::MakeSize(dimensions), - xformedSigma, - xformedSigma, - SkTileMode::kClamp, - SkBackingFit::kExact); - if (!rtc2) { - return nullptr; - } - - mask = rtc2->asTextureProxyRef(); - if (!mask) { - return nullptr; - } - SkASSERT(mask->origin() == kBottomLeft_GrSurfaceOrigin); - proxyProvider->assignUniqueKeyToProxy(key, mask.get()); + if (sk_sp mask = proxyProvider->findOrCreateProxyByUniqueKey( + key, GrColorType::kAlpha_8, kBottomLeft_GrSurfaceOrigin)) { + GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(mask->backendFormat(), + GrColorType::kAlpha_8); + return {std::move(mask), kBottomLeft_GrSurfaceOrigin, swizzle}; } + auto rtc = GrRenderTargetContext::MakeWithFallback( + context, GrColorType::kAlpha_8, nullptr, SkBackingFit::kExact, dimensions); + if (!rtc) { + return {}; + } + + GrPaint paint; + + rtc->clear(nullptr, SK_PMColor4fTRANSPARENT, + GrRenderTargetContext::CanClearFullscreen::kYes); + rtc->drawRRect(GrNoClip(), std::move(paint), GrAA::kYes, SkMatrix::I(), rrectToDraw, + GrStyle::SimpleFill()); + + GrSurfaceProxyView srcView = rtc->readSurfaceView(); + if (!srcView) { + return {}; + } + SkASSERT(srcView.asTextureProxy()); + auto rtc2 = SkGpuBlurUtils::GaussianBlur(context, + std::move(srcView), + rtc->colorInfo().colorType(), + rtc->colorInfo().alphaType(), + nullptr, + SkIRect::MakeSize(dimensions), + SkIRect::MakeSize(dimensions), + xformedSigma, + xformedSigma, + SkTileMode::kClamp, + SkBackingFit::kExact); + if (!rtc2) { + return {}; + } + + GrSurfaceProxyView mask = rtc2->readSurfaceView(); + if (!mask) { + return {}; + } + SkASSERT(mask.asTextureProxy()); + SkASSERT(mask.origin() == kBottomLeft_GrSurfaceOrigin); + proxyProvider->assignUniqueKeyToProxy(key, mask.asTextureProxy()); + return mask; } } @@ -142,8 +147,8 @@ uniform half blurRadius; return nullptr; } - sk_sp mask(find_or_create_rrect_blur_mask(context, rrectToDraw, - dimensions, xformedSigma)); + GrSurfaceProxyView mask = find_or_create_rrect_blur_mask(context, rrectToDraw, dimensions, + xformedSigma); if (!mask) { return nullptr; } diff --git a/src/gpu/effects/GrRectBlurEffect.fp b/src/gpu/effects/GrRectBlurEffect.fp index 5ce2c64128..d74c1e272f 100644 --- a/src/gpu/effects/GrRectBlurEffect.fp +++ b/src/gpu/effects/GrRectBlurEffect.fp @@ -46,8 +46,7 @@ layout(key) in bool isFast; samplerParams } @class { -static sk_sp CreateIntegralTexture(GrRecordingContext* context, - float sixSigma) { +static GrSurfaceProxyView CreateIntegralTexture(GrRecordingContext* context, float sixSigma) { // The texture we're producing represents the integral of a normal distribution over a six-sigma // range centered at zero. We want enough resolution so that the linear interpolation done in // texture lookup doesn't introduce noticeable artifacts. We conservatively choose to have 2 @@ -63,34 +62,36 @@ static sk_sp CreateIntegralTexture(GrRecordingContext* context, builder.finish(); GrProxyProvider* proxyProvider = context->priv().proxyProvider(); - sk_sp proxy(proxyProvider->findOrCreateProxyByUniqueKey( - key, GrColorType::kAlpha_8, kTopLeft_GrSurfaceOrigin)); - if (!proxy) { - SkBitmap bitmap; - if (!bitmap.tryAllocPixels(SkImageInfo::MakeA8(width, 1))) { - return nullptr; - } - *bitmap.getAddr8(0, 0) = 255; - const float invWidth = 1.f / width; - for (int i = 1; i < width - 1; ++i) { - float x = (i + 0.5f) * invWidth; - x = (-6 * x + 3) * SK_ScalarRoot2Over2; - float integral = 0.5f * (std::erf(x) + 1.f); - *bitmap.getAddr8(i, 0) = SkToU8(sk_float_round2int(255.f * integral)); - } - *bitmap.getAddr8(width - 1, 0) = 0; - bitmap.setImmutable(); - - GrBitmapTextureMaker maker(context, bitmap); - auto[view, grCT] = maker.view(GrMipMapped::kNo); - if (!view.proxy()) { - return nullptr; - } - proxy = view.asTextureProxyRef(); - SkASSERT(proxy->origin() == kTopLeft_GrSurfaceOrigin); - proxyProvider->assignUniqueKeyToProxy(key, proxy.get()); + if (sk_sp proxy = proxyProvider->findOrCreateProxyByUniqueKey( + key, GrColorType::kAlpha_8, kTopLeft_GrSurfaceOrigin)) { + GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(proxy->backendFormat(), + GrColorType::kAlpha_8); + return {std::move(proxy), kTopLeft_GrSurfaceOrigin, swizzle}; } - return proxy; + + SkBitmap bitmap; + if (!bitmap.tryAllocPixels(SkImageInfo::MakeA8(width, 1))) { + return {}; + } + *bitmap.getAddr8(0, 0) = 255; + const float invWidth = 1.f / width; + for (int i = 1; i < width - 1; ++i) { + float x = (i + 0.5f) * invWidth; + x = (-6 * x + 3) * SK_ScalarRoot2Over2; + float integral = 0.5f * (std::erf(x) + 1.f); + *bitmap.getAddr8(i, 0) = SkToU8(sk_float_round2int(255.f * integral)); + } + *bitmap.getAddr8(width - 1, 0) = 0; + bitmap.setImmutable(); + + GrBitmapTextureMaker maker(context, bitmap); + auto[view, grCT] = maker.view(GrMipMapped::kNo); + if (!view) { + return {}; + } + SkASSERT(view.origin() == kTopLeft_GrSurfaceOrigin); + proxyProvider->assignUniqueKeyToProxy(key, view.asTextureProxy()); + return view; } } @@ -110,7 +111,7 @@ static sk_sp CreateIntegralTexture(GrRecordingContext* context, } const float sixSigma = 6 * sigma; - auto integral = CreateIntegralTexture(context, sixSigma); + GrSurfaceProxyView integral = CreateIntegralTexture(context, sixSigma); if (!integral) { return nullptr; } diff --git a/src/gpu/effects/generated/GrAlphaThresholdFragmentProcessor.cpp b/src/gpu/effects/generated/GrAlphaThresholdFragmentProcessor.cpp index a9e3d6cc27..03141a9525 100644 --- a/src/gpu/effects/generated/GrAlphaThresholdFragmentProcessor.cpp +++ b/src/gpu/effects/generated/GrAlphaThresholdFragmentProcessor.cpp @@ -122,7 +122,12 @@ std::unique_ptr GrAlphaThresholdFragmentProcessor::TestCrea uint32_t x = testData->fRandom->nextULessThan(kMaxWidth - width); uint32_t y = testData->fRandom->nextULessThan(kMaxHeight - height); SkIRect bounds = SkIRect::MakeXYWH(x, y, width, height); - return GrAlphaThresholdFragmentProcessor::Make(std::move(maskProxy), innerThresh, outerThresh, + + GrSurfaceOrigin origin = maskProxy->origin(); + GrSwizzle swizzle = maskProxy->textureSwizzle(); + GrSurfaceProxyView view(std::move(maskProxy), origin, swizzle); + + return GrAlphaThresholdFragmentProcessor::Make(std::move(view), innerThresh, outerThresh, bounds); } #endif diff --git a/src/gpu/effects/generated/GrAlphaThresholdFragmentProcessor.h b/src/gpu/effects/generated/GrAlphaThresholdFragmentProcessor.h index 0c5fdbed1e..05ceb9f4a0 100644 --- a/src/gpu/effects/generated/GrAlphaThresholdFragmentProcessor.h +++ b/src/gpu/effects/generated/GrAlphaThresholdFragmentProcessor.h @@ -19,12 +19,12 @@ class GrAlphaThresholdFragmentProcessor : public GrFragmentProcessor { public: inline OptimizationFlags optFlags(float outerThreshold); - static std::unique_ptr Make(sk_sp mask, + static std::unique_ptr Make(GrSurfaceProxyView mask, float innerThreshold, float outerThreshold, const SkIRect& bounds) { return std::unique_ptr(new GrAlphaThresholdFragmentProcessor( - mask, innerThreshold, outerThreshold, bounds)); + std::move(mask), innerThreshold, outerThreshold, bounds)); } GrAlphaThresholdFragmentProcessor(const GrAlphaThresholdFragmentProcessor& src); std::unique_ptr clone() const override; @@ -35,12 +35,12 @@ public: float outerThreshold; private: - GrAlphaThresholdFragmentProcessor(sk_sp mask, float innerThreshold, + GrAlphaThresholdFragmentProcessor(GrSurfaceProxyView mask, float innerThreshold, float outerThreshold, const SkIRect& bounds) : INHERITED(kGrAlphaThresholdFragmentProcessor_ClassID, kNone_OptimizationFlags) , maskCoordTransform( SkMatrix::MakeTrans(SkIntToScalar(-bounds.x()), SkIntToScalar(-bounds.y())), - mask.get()) + mask.proxy()) , mask(std::move(mask)) , innerThreshold(innerThreshold) , outerThreshold(outerThreshold) { diff --git a/src/gpu/effects/generated/GrCircleBlurFragmentProcessor.cpp b/src/gpu/effects/generated/GrCircleBlurFragmentProcessor.cpp index 68eeb042f7..86ef9c1400 100644 --- a/src/gpu/effects/generated/GrCircleBlurFragmentProcessor.cpp +++ b/src/gpu/effects/generated/GrCircleBlurFragmentProcessor.cpp @@ -166,12 +166,12 @@ static void create_half_plane_profile(uint8_t* profile, int profileWidth) { profile[profileWidth - 1] = 0; } -static sk_sp create_profile_texture(GrRecordingContext* context, - const SkRect& circle, float sigma, - float* solidRadius, float* textureRadius) { +static GrSurfaceProxyView create_profile_texture(GrRecordingContext* context, const SkRect& circle, + float sigma, float* solidRadius, + float* textureRadius) { float circleR = circle.width() / 2.0f; if (circleR < SK_ScalarNearlyZero) { - return nullptr; + return {}; } // Profile textures are cached by the ratio of sigma to circle radius and by the size of the // profile texture (binned by powers of 2). @@ -208,45 +208,46 @@ static sk_sp create_profile_texture(GrRecordingContext* context, builder.finish(); GrProxyProvider* proxyProvider = context->priv().proxyProvider(); - sk_sp blurProfile = proxyProvider->findOrCreateProxyByUniqueKey( - key, GrColorType::kAlpha_8, kTopLeft_GrSurfaceOrigin); - if (!blurProfile) { - static constexpr int kProfileTextureWidth = 512; - - SkBitmap bm; - if (!bm.tryAllocPixels(SkImageInfo::MakeA8(kProfileTextureWidth, 1))) { - return nullptr; - } - - if (useHalfPlaneApprox) { - create_half_plane_profile(bm.getAddr8(0, 0), kProfileTextureWidth); - } else { - // Rescale params to the size of the texture we're creating. - SkScalar scale = kProfileTextureWidth / *textureRadius; - create_circle_profile(bm.getAddr8(0, 0), sigma * scale, circleR * scale, - kProfileTextureWidth); - } - - bm.setImmutable(); - - GrBitmapTextureMaker maker(context, bm); - auto[blurView, grCT] = maker.view(GrMipMapped::kNo); - blurProfile = blurView.asTextureProxyRef(); - if (!blurProfile) { - return nullptr; - } - proxyProvider->assignUniqueKeyToProxy(key, blurProfile.get()); + if (sk_sp blurProfile = proxyProvider->findOrCreateProxyByUniqueKey( + key, GrColorType::kAlpha_8, kTopLeft_GrSurfaceOrigin)) { + GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(blurProfile->backendFormat(), + GrColorType::kAlpha_8); + return {std::move(blurProfile), kTopLeft_GrSurfaceOrigin, swizzle}; } - return blurProfile; + static constexpr int kProfileTextureWidth = 512; + + SkBitmap bm; + if (!bm.tryAllocPixels(SkImageInfo::MakeA8(kProfileTextureWidth, 1))) { + return {}; + } + + if (useHalfPlaneApprox) { + create_half_plane_profile(bm.getAddr8(0, 0), kProfileTextureWidth); + } else { + // Rescale params to the size of the texture we're creating. + SkScalar scale = kProfileTextureWidth / *textureRadius; + create_circle_profile(bm.getAddr8(0, 0), sigma * scale, circleR * scale, + kProfileTextureWidth); + } + + bm.setImmutable(); + + GrBitmapTextureMaker maker(context, bm); + auto[blurView, grCT] = maker.view(GrMipMapped::kNo); + if (!blurView) { + return {}; + } + proxyProvider->assignUniqueKeyToProxy(key, blurView.asTextureProxy()); + return blurView; } std::unique_ptr GrCircleBlurFragmentProcessor::Make( GrRecordingContext* context, const SkRect& circle, float sigma) { float solidRadius; float textureRadius; - sk_sp profile( - create_profile_texture(context, circle, sigma, &solidRadius, &textureRadius)); + GrSurfaceProxyView profile = + create_profile_texture(context, circle, sigma, &solidRadius, &textureRadius); if (!profile) { return nullptr; } diff --git a/src/gpu/effects/generated/GrCircleBlurFragmentProcessor.h b/src/gpu/effects/generated/GrCircleBlurFragmentProcessor.h index a0e039692a..bbd74d357c 100644 --- a/src/gpu/effects/generated/GrCircleBlurFragmentProcessor.h +++ b/src/gpu/effects/generated/GrCircleBlurFragmentProcessor.h @@ -29,7 +29,7 @@ public: private: GrCircleBlurFragmentProcessor(SkRect circleRect, float textureRadius, float solidRadius, - sk_sp blurProfileSampler) + GrSurfaceProxyView blurProfileSampler) : INHERITED(kGrCircleBlurFragmentProcessor_ClassID, (OptimizationFlags)kCompatibleWithCoverageAsAlpha_OptimizationFlag) , circleRect(circleRect) diff --git a/src/gpu/effects/generated/GrMagnifierEffect.cpp b/src/gpu/effects/generated/GrMagnifierEffect.cpp index 6c6858e2e0..8c858103dc 100644 --- a/src/gpu/effects/generated/GrMagnifierEffect.cpp +++ b/src/gpu/effects/generated/GrMagnifierEffect.cpp @@ -189,7 +189,11 @@ std::unique_ptr GrMagnifierEffect::TestCreate(GrProcessorTe SkIRect bounds = SkIRect::MakeWH(SkIntToScalar(kMaxWidth), SkIntToScalar(kMaxHeight)); SkRect srcRect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height)); - auto effect = GrMagnifierEffect::Make(std::move(proxy), + GrSurfaceOrigin origin = proxy->origin(); + GrSwizzle swizzle = proxy->textureSwizzle(); + GrSurfaceProxyView view(std::move(proxy), origin, swizzle); + + auto effect = GrMagnifierEffect::Make(std::move(view), bounds, srcRect, srcRect.width() / bounds.width(), diff --git a/src/gpu/effects/generated/GrMagnifierEffect.h b/src/gpu/effects/generated/GrMagnifierEffect.h index efb16e7841..e774b0cb47 100644 --- a/src/gpu/effects/generated/GrMagnifierEffect.h +++ b/src/gpu/effects/generated/GrMagnifierEffect.h @@ -17,11 +17,11 @@ #include "src/gpu/GrFragmentProcessor.h" class GrMagnifierEffect : public GrFragmentProcessor { public: - static std::unique_ptr Make(sk_sp src, SkIRect bounds, + static std::unique_ptr Make(GrSurfaceProxyView src, SkIRect bounds, SkRect srcRect, float xInvZoom, float yInvZoom, float xInvInset, float yInvInset) { return std::unique_ptr(new GrMagnifierEffect( - src, bounds, srcRect, xInvZoom, yInvZoom, xInvInset, yInvInset)); + std::move(src), bounds, srcRect, xInvZoom, yInvZoom, xInvInset, yInvInset)); } GrMagnifierEffect(const GrMagnifierEffect& src); std::unique_ptr clone() const override; @@ -36,10 +36,10 @@ public: float yInvInset; private: - GrMagnifierEffect(sk_sp src, SkIRect bounds, SkRect srcRect, float xInvZoom, + GrMagnifierEffect(GrSurfaceProxyView src, SkIRect bounds, SkRect srcRect, float xInvZoom, float yInvZoom, float xInvInset, float yInvInset) : INHERITED(kGrMagnifierEffect_ClassID, kNone_OptimizationFlags) - , srcCoordTransform(SkMatrix::I(), src.get()) + , srcCoordTransform(SkMatrix::I(), src.proxy()) , src(std::move(src)) , bounds(bounds) , srcRect(srcRect) diff --git a/src/gpu/effects/generated/GrRRectBlurEffect.cpp b/src/gpu/effects/generated/GrRRectBlurEffect.cpp index 71f50d7b3c..68607b1e03 100644 --- a/src/gpu/effects/generated/GrRRectBlurEffect.cpp +++ b/src/gpu/effects/generated/GrRRectBlurEffect.cpp @@ -39,8 +39,8 @@ std::unique_ptr GrRRectBlurEffect::Make(GrRecordingContext* return nullptr; } - sk_sp mask( - find_or_create_rrect_blur_mask(context, rrectToDraw, dimensions, xformedSigma)); + GrSurfaceProxyView mask = + find_or_create_rrect_blur_mask(context, rrectToDraw, dimensions, xformedSigma); if (!mask) { return nullptr; } diff --git a/src/gpu/effects/generated/GrRRectBlurEffect.h b/src/gpu/effects/generated/GrRRectBlurEffect.h index 7c8d74841f..c078a835f9 100644 --- a/src/gpu/effects/generated/GrRRectBlurEffect.h +++ b/src/gpu/effects/generated/GrRRectBlurEffect.h @@ -30,10 +30,10 @@ #include "src/gpu/GrFragmentProcessor.h" class GrRRectBlurEffect : public GrFragmentProcessor { public: - static sk_sp find_or_create_rrect_blur_mask(GrRecordingContext* context, - const SkRRect& rrectToDraw, - const SkISize& dimensions, - float xformedSigma) { + static GrSurfaceProxyView find_or_create_rrect_blur_mask(GrRecordingContext* context, + const SkRRect& rrectToDraw, + const SkISize& dimensions, + float xformedSigma) { static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); GrUniqueKey key; GrUniqueKey::Builder builder(&key, kDomain, 9, "RoundRect Blur Mask"); @@ -51,49 +51,54 @@ public: GrProxyProvider* proxyProvider = context->priv().proxyProvider(); - sk_sp mask(proxyProvider->findOrCreateProxyByUniqueKey( - key, GrColorType::kAlpha_8, kBottomLeft_GrSurfaceOrigin)); - if (!mask) { - auto rtc = GrRenderTargetContext::MakeWithFallback( - context, GrColorType::kAlpha_8, nullptr, SkBackingFit::kExact, dimensions); - if (!rtc) { - return nullptr; - } - - GrPaint paint; - - rtc->clear(nullptr, SK_PMColor4fTRANSPARENT, - GrRenderTargetContext::CanClearFullscreen::kYes); - rtc->drawRRect(GrNoClip(), std::move(paint), GrAA::kYes, SkMatrix::I(), rrectToDraw, - GrStyle::SimpleFill()); - - GrSurfaceProxyView srcView = rtc->readSurfaceView(); - if (!srcView.asTextureProxy()) { - return nullptr; - } - auto rtc2 = SkGpuBlurUtils::GaussianBlur(context, - std::move(srcView), - rtc->colorInfo().colorType(), - rtc->colorInfo().alphaType(), - nullptr, - SkIRect::MakeSize(dimensions), - SkIRect::MakeSize(dimensions), - xformedSigma, - xformedSigma, - SkTileMode::kClamp, - SkBackingFit::kExact); - if (!rtc2) { - return nullptr; - } - - mask = rtc2->asTextureProxyRef(); - if (!mask) { - return nullptr; - } - SkASSERT(mask->origin() == kBottomLeft_GrSurfaceOrigin); - proxyProvider->assignUniqueKeyToProxy(key, mask.get()); + if (sk_sp mask = proxyProvider->findOrCreateProxyByUniqueKey( + key, GrColorType::kAlpha_8, kBottomLeft_GrSurfaceOrigin)) { + GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(mask->backendFormat(), + GrColorType::kAlpha_8); + return {std::move(mask), kBottomLeft_GrSurfaceOrigin, swizzle}; } + auto rtc = GrRenderTargetContext::MakeWithFallback(context, GrColorType::kAlpha_8, nullptr, + SkBackingFit::kExact, dimensions); + if (!rtc) { + return {}; + } + + GrPaint paint; + + rtc->clear(nullptr, SK_PMColor4fTRANSPARENT, + GrRenderTargetContext::CanClearFullscreen::kYes); + rtc->drawRRect(GrNoClip(), std::move(paint), GrAA::kYes, SkMatrix::I(), rrectToDraw, + GrStyle::SimpleFill()); + + GrSurfaceProxyView srcView = rtc->readSurfaceView(); + if (!srcView) { + return {}; + } + SkASSERT(srcView.asTextureProxy()); + auto rtc2 = SkGpuBlurUtils::GaussianBlur(context, + std::move(srcView), + rtc->colorInfo().colorType(), + rtc->colorInfo().alphaType(), + nullptr, + SkIRect::MakeSize(dimensions), + SkIRect::MakeSize(dimensions), + xformedSigma, + xformedSigma, + SkTileMode::kClamp, + SkBackingFit::kExact); + if (!rtc2) { + return {}; + } + + GrSurfaceProxyView mask = rtc2->readSurfaceView(); + if (!mask) { + return {}; + } + SkASSERT(mask.asTextureProxy()); + SkASSERT(mask.origin() == kBottomLeft_GrSurfaceOrigin); + proxyProvider->assignUniqueKeyToProxy(key, mask.asTextureProxy()); + return mask; } @@ -112,7 +117,7 @@ public: private: GrRRectBlurEffect(float sigma, SkRect rect, float cornerRadius, - sk_sp ninePatchSampler) + GrSurfaceProxyView ninePatchSampler) : INHERITED(kGrRRectBlurEffect_ClassID, (OptimizationFlags)kCompatibleWithCoverageAsAlpha_OptimizationFlag) , sigma(sigma) diff --git a/src/gpu/effects/generated/GrRectBlurEffect.h b/src/gpu/effects/generated/GrRectBlurEffect.h index 8a9f44cf64..75cb512d8c 100644 --- a/src/gpu/effects/generated/GrRectBlurEffect.h +++ b/src/gpu/effects/generated/GrRectBlurEffect.h @@ -29,8 +29,7 @@ #include "src/gpu/GrFragmentProcessor.h" class GrRectBlurEffect : public GrFragmentProcessor { public: - static sk_sp CreateIntegralTexture(GrRecordingContext* context, - float sixSigma) { + static GrSurfaceProxyView CreateIntegralTexture(GrRecordingContext* context, float sixSigma) { // The texture we're producing represents the integral of a normal distribution over a // six-sigma range centered at zero. We want enough resolution so that the linear // interpolation done in texture lookup doesn't introduce noticeable artifacts. We @@ -46,34 +45,36 @@ public: builder.finish(); GrProxyProvider* proxyProvider = context->priv().proxyProvider(); - sk_sp proxy(proxyProvider->findOrCreateProxyByUniqueKey( - key, GrColorType::kAlpha_8, kTopLeft_GrSurfaceOrigin)); - if (!proxy) { - SkBitmap bitmap; - if (!bitmap.tryAllocPixels(SkImageInfo::MakeA8(width, 1))) { - return nullptr; - } - *bitmap.getAddr8(0, 0) = 255; - const float invWidth = 1.f / width; - for (int i = 1; i < width - 1; ++i) { - float x = (i + 0.5f) * invWidth; - x = (-6 * x + 3) * SK_ScalarRoot2Over2; - float integral = 0.5f * (std::erf(x) + 1.f); - *bitmap.getAddr8(i, 0) = SkToU8(sk_float_round2int(255.f * integral)); - } - *bitmap.getAddr8(width - 1, 0) = 0; - bitmap.setImmutable(); - - GrBitmapTextureMaker maker(context, bitmap); - auto[view, grCT] = maker.view(GrMipMapped::kNo); - if (!view.proxy()) { - return nullptr; - } - proxy = view.asTextureProxyRef(); - SkASSERT(proxy->origin() == kTopLeft_GrSurfaceOrigin); - proxyProvider->assignUniqueKeyToProxy(key, proxy.get()); + if (sk_sp proxy = proxyProvider->findOrCreateProxyByUniqueKey( + key, GrColorType::kAlpha_8, kTopLeft_GrSurfaceOrigin)) { + GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(proxy->backendFormat(), + GrColorType::kAlpha_8); + return {std::move(proxy), kTopLeft_GrSurfaceOrigin, swizzle}; } - return proxy; + + SkBitmap bitmap; + if (!bitmap.tryAllocPixels(SkImageInfo::MakeA8(width, 1))) { + return {}; + } + *bitmap.getAddr8(0, 0) = 255; + const float invWidth = 1.f / width; + for (int i = 1; i < width - 1; ++i) { + float x = (i + 0.5f) * invWidth; + x = (-6 * x + 3) * SK_ScalarRoot2Over2; + float integral = 0.5f * (std::erf(x) + 1.f); + *bitmap.getAddr8(i, 0) = SkToU8(sk_float_round2int(255.f * integral)); + } + *bitmap.getAddr8(width - 1, 0) = 0; + bitmap.setImmutable(); + + GrBitmapTextureMaker maker(context, bitmap); + auto[view, grCT] = maker.view(GrMipMapped::kNo); + if (!view) { + return {}; + } + SkASSERT(view.origin() == kTopLeft_GrSurfaceOrigin); + proxyProvider->assignUniqueKeyToProxy(key, view.asTextureProxy()); + return view; } static std::unique_ptr Make(GrRecordingContext* context, @@ -91,7 +92,7 @@ public: } const float sixSigma = 6 * sigma; - auto integral = CreateIntegralTexture(context, sixSigma); + GrSurfaceProxyView integral = CreateIntegralTexture(context, sixSigma); if (!integral) { return nullptr; } @@ -125,7 +126,7 @@ public: bool isFast; private: - GrRectBlurEffect(SkRect rect, sk_sp integral, float invSixSigma, bool isFast, + GrRectBlurEffect(SkRect rect, GrSurfaceProxyView integral, float invSixSigma, bool isFast, GrSamplerState samplerParams) : INHERITED(kGrRectBlurEffect_ClassID, (OptimizationFlags)kCompatibleWithCoverageAsAlpha_OptimizationFlag) diff --git a/src/gpu/gradients/GrGradientShader.cpp b/src/gpu/gradients/GrGradientShader.cpp index 0fbcd43ad8..59624f2bb7 100644 --- a/src/gpu/gradients/GrGradientShader.cpp +++ b/src/gpu/gradients/GrGradientShader.cpp @@ -65,7 +65,7 @@ static std::unique_ptr make_textured_colorizer(const SkPMCo return nullptr; } - return GrTextureGradientColorizer::Make(view.detachProxy()); + return GrTextureGradientColorizer::Make(std::move(view)); } // Analyze the shader's color stops and positions and chooses an appropriate colorizer to represent diff --git a/src/gpu/gradients/generated/GrTextureGradientColorizer.h b/src/gpu/gradients/generated/GrTextureGradientColorizer.h index caaf9859ba..1e373e0b4e 100644 --- a/src/gpu/gradients/generated/GrTextureGradientColorizer.h +++ b/src/gpu/gradients/generated/GrTextureGradientColorizer.h @@ -17,8 +17,9 @@ #include "src/gpu/GrFragmentProcessor.h" class GrTextureGradientColorizer : public GrFragmentProcessor { public: - static std::unique_ptr Make(sk_sp gradient) { - return std::unique_ptr(new GrTextureGradientColorizer(gradient)); + static std::unique_ptr Make(GrSurfaceProxyView gradient) { + return std::unique_ptr( + new GrTextureGradientColorizer(std::move(gradient))); } GrTextureGradientColorizer(const GrTextureGradientColorizer& src); std::unique_ptr clone() const override; @@ -26,7 +27,7 @@ public: TextureSampler gradient; private: - GrTextureGradientColorizer(sk_sp gradient) + GrTextureGradientColorizer(GrSurfaceProxyView gradient) : INHERITED(kGrTextureGradientColorizer_ClassID, kNone_OptimizationFlags) , gradient(std::move(gradient), GrSamplerState::Filter::kBilerp) { this->setTextureSamplerCnt(1); diff --git a/src/sksl/SkSLHCodeGenerator.cpp b/src/sksl/SkSLHCodeGenerator.cpp index c28431558e..6d40b619b0 100644 --- a/src/sksl/SkSLHCodeGenerator.cpp +++ b/src/sksl/SkSLHCodeGenerator.cpp @@ -66,7 +66,7 @@ Layout::CType HCodeGenerator::ParameterCType(const Context& context, const Type& } else if (type == *context.fFloat4x4_Type || type == *context.fHalf4x4_Type) { return Layout::CType::kSkM44; } else if (type.kind() == Type::kSampler_Kind) { - return Layout::CType::kGrSurfaceProxy; + return Layout::CType::kGrSurfaceProxyView; } else if (type == *context.fFragmentProcessor_Type) { return Layout::CType::kGrFragmentProcessor; } @@ -191,7 +191,8 @@ void HCodeGenerator::writeMake() { fFullName.c_str()); separator = ""; for (const auto& param : fSectionAndParameterHelper.getParameters()) { - if (param->fType.nonnullable() == *fContext.fFragmentProcessor_Type) { + if (param->fType.nonnullable() == *fContext.fFragmentProcessor_Type || + param->fType.nonnullable().kind() == Type::kSampler_Kind) { this->writef("%sstd::move(%s)", separator, String(param->fName).c_str()); } else { this->writef("%s%s", separator, String(param->fName).c_str()); @@ -241,7 +242,7 @@ void HCodeGenerator::writeConstructor() { const Section& s = *transforms[i]; String field = CoordTransformName(s.fArgument.c_str(), i); if (s.fArgument.size()) { - this->writef("\n , %s(%s, %s.get())", field.c_str(), s.fText.c_str(), + this->writef("\n , %s(%s, %s.proxy())", field.c_str(), s.fText.c_str(), FieldName(s.fArgument.c_str()).c_str()); } else { diff --git a/src/sksl/ir/SkSLLayout.h b/src/sksl/ir/SkSLLayout.h index 5a35c59baa..10c994e021 100644 --- a/src/sksl/ir/SkSLLayout.h +++ b/src/sksl/ir/SkSLLayout.h @@ -95,7 +95,7 @@ struct Layout { kSkIPoint, kSkMatrix, kSkM44, - kGrSurfaceProxy, + kGrSurfaceProxyView, kGrFragmentProcessor, }; @@ -177,8 +177,8 @@ struct Layout { return "SkMatrix"; case CType::kSkM44: return "SkM44"; - case CType::kGrSurfaceProxy: - return "sk_sp"; + case CType::kGrSurfaceProxyView: + return "GrSurfaceProxyView"; case CType::kGrFragmentProcessor: return "std::unique_ptr"; default: