Split up find_or_create_rrect_blur_mask_fp
Prepare this method for cpu-side generation of the rrect blur mask in DDL-mode
Bug: 1108408
Change-Id: I902ad507cd53f5f5b1d418a8b52f96dddffd0b18
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/314621
Reviewed-by: Adlai Holler <adlai@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/effects/generated/GrRRectBlurEffect.cpp b/src/gpu/effects/generated/GrRRectBlurEffect.cpp
index 8c70129..cd2c2f8 100644
--- a/src/gpu/effects/generated/GrRRectBlurEffect.cpp
+++ b/src/gpu/effects/generated/GrRRectBlurEffect.cpp
@@ -22,17 +22,18 @@
#include "src/gpu/GrStyle.h"
#include "src/gpu/effects/GrTextureEffect.h"
-static std::unique_ptr<GrFragmentProcessor> find_or_create_rrect_blur_mask_fp(
- GrRecordingContext* context,
- const SkRRect& rrectToDraw,
- const SkISize& dimensions,
- float xformedSigma) {
+static constexpr auto kBlurredRRectMaskOrigin = kBottomLeft_GrSurfaceOrigin;
+
+static void make_blurred_rrect_key(GrUniqueKey* key,
+ const SkRRect& rrectToDraw,
+ float xformedSigma) {
static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
- GrUniqueKey key;
- GrUniqueKey::Builder builder(&key, kDomain, 9, "RoundRect Blur Mask");
+
+ GrUniqueKey::Builder builder(key, kDomain, 9, "RoundRect Blur Mask");
builder[0] = SkScalarCeilToInt(xformedSigma - 1 / 6.0f);
int index = 1;
+ // TODO: this is overkill for _simple_ circular rrects
for (auto c : {SkRRect::kUpperLeft_Corner, SkRRect::kUpperRight_Corner,
SkRRect::kLowerRight_Corner, SkRRect::kLowerLeft_Corner}) {
SkASSERT(SkScalarIsInt(rrectToDraw.radii(c).fX) && SkScalarIsInt(rrectToDraw.radii(c).fY));
@@ -40,27 +41,17 @@
builder[index++] = SkScalarCeilToInt(rrectToDraw.radii(c).fY);
}
builder.finish();
+}
- // It seems like we could omit this matrix and modify the shader code to not normalize
- // the coords used to sample the texture effect. However, the "proxyDims" value in the
- // shader is not always the actual the proxy dimensions. This is because 'dimensions' here
- // was computed using integer corner radii as determined in
- // SkComputeBlurredRRectParams whereas the shader code uses the float radius to compute
- // 'proxyDims'. Why it draws correctly with these unequal values is a mystery for the ages.
- auto m = SkMatrix::Scale(dimensions.width(), dimensions.height());
- static constexpr auto kMaskOrigin = kBottomLeft_GrSurfaceOrigin;
- GrProxyProvider* proxyProvider = context->priv().proxyProvider();
-
- if (auto view = proxyProvider->findCachedProxyWithColorTypeFallback(key, kMaskOrigin,
- GrColorType::kAlpha_8, 1)) {
- return GrTextureEffect::Make(std::move(view), kPremul_SkAlphaType, m);
- }
-
+static GrSurfaceProxyView create_mask_on_gpu(GrRecordingContext* context,
+ const SkRRect& rrectToDraw,
+ const SkISize& dimensions,
+ float xformedSigma) {
auto rtc = GrRenderTargetContext::MakeWithFallback(
context, GrColorType::kAlpha_8, nullptr, SkBackingFit::kExact, dimensions, 1,
- GrMipmapped::kNo, GrProtected::kNo, kMaskOrigin);
+ GrMipmapped::kNo, GrProtected::kNo, kBlurredRRectMaskOrigin);
if (!rtc) {
- return nullptr;
+ return {};
}
GrPaint paint;
@@ -71,7 +62,7 @@
GrSurfaceProxyView srcView = rtc->readSurfaceView();
if (!srcView) {
- return nullptr;
+ return {};
}
SkASSERT(srcView.asTextureProxy());
auto rtc2 = SkGpuBlurUtils::GaussianBlur(context,
@@ -86,15 +77,42 @@
SkTileMode::kClamp,
SkBackingFit::kExact);
if (!rtc2) {
- return nullptr;
+ return {};
}
- GrSurfaceProxyView mask = rtc2->readSurfaceView();
+ return rtc2->readSurfaceView();
+}
+
+static std::unique_ptr<GrFragmentProcessor> find_or_create_rrect_blur_mask_fp(
+ GrRecordingContext* context,
+ const SkRRect& rrectToDraw,
+ const SkISize& dimensions,
+ float xformedSigma) {
+ GrUniqueKey key;
+
+ make_blurred_rrect_key(&key, rrectToDraw, xformedSigma);
+
+ // It seems like we could omit this matrix and modify the shader code to not normalize
+ // the coords used to sample the texture effect. However, the "proxyDims" value in the
+ // shader is not always the actual the proxy dimensions. This is because 'dimensions' here
+ // was computed using integer corner radii as determined in
+ // SkComputeBlurredRRectParams whereas the shader code uses the float radius to compute
+ // 'proxyDims'. Why it draws correctly with these unequal values is a mystery for the ages.
+ auto m = SkMatrix::Scale(dimensions.width(), dimensions.height());
+ GrProxyProvider* proxyProvider = context->priv().proxyProvider();
+
+ if (auto view = proxyProvider->findCachedProxyWithColorTypeFallback(
+ key, kBlurredRRectMaskOrigin, GrColorType::kAlpha_8, 1)) {
+ return GrTextureEffect::Make(std::move(view), kPremul_SkAlphaType, m);
+ }
+
+ auto mask = create_mask_on_gpu(context, rrectToDraw, dimensions, xformedSigma);
if (!mask) {
return nullptr;
}
+
SkASSERT(mask.asTextureProxy());
- SkASSERT(mask.origin() == kMaskOrigin);
+ SkASSERT(mask.origin() == kBlurredRRectMaskOrigin);
proxyProvider->assignUniqueKeyToProxy(key, mask.asTextureProxy());
return GrTextureEffect::Make(std::move(mask), kPremul_SkAlphaType, m);
}
@@ -182,18 +200,18 @@
args.fUniformHandler->getUniformCStr(proxyRectVar),
args.fUniformHandler->getUniformCStr(blurRadiusVar),
args.fUniformHandler->getUniformCStr(cornerRadiusVar));
- SkString _sample9345 = this->invokeChild(0, args);
+ SkString _sample10076 = this->invokeChild(0, args);
fragBuilder->codeAppendf(
R"SkSL(
half4 inputColor = %s;)SkSL",
- _sample9345.c_str());
- SkString _coords9393("float2(texCoord)");
- SkString _sample9393 = this->invokeChild(1, args, _coords9393.c_str());
+ _sample10076.c_str());
+ SkString _coords10124("float2(texCoord)");
+ SkString _sample10124 = this->invokeChild(1, args, _coords10124.c_str());
fragBuilder->codeAppendf(
R"SkSL(
%s = inputColor * %s;
)SkSL",
- args.fOutputColor, _sample9393.c_str());
+ args.fOutputColor, _sample10124.c_str());
}
private: