Update generated effects to use views.
Bug: skia:9556
Change-Id: Iad4f7f2db2624e699184691d8aae2aaded81eb28
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/270198
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
diff --git a/src/effects/SkTableColorFilter.cpp b/src/effects/SkTableColorFilter.cpp
index 0a5412f..3373ff9 100644
--- a/src/effects/SkTableColorFilter.cpp
+++ b/src/effects/SkTableColorFilter.cpp
@@ -289,8 +289,7 @@
const char* name() const override { return "ColorTableEffect"; }
std::unique_ptr<GrFragmentProcessor> clone() const override {
- return std::unique_ptr<GrFragmentProcessor>(
- new ColorTableEffect(sk_ref_sp(fTextureSampler.view().proxy())));
+ return std::unique_ptr<GrFragmentProcessor>(new ColorTableEffect(fTextureSampler.view()));
}
private:
@@ -300,10 +299,11 @@
bool onIsEqual(const GrFragmentProcessor&) const override { return true; }
- ColorTableEffect(sk_sp<GrSurfaceProxy> 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 @@
SkASSERT(bitmap.isImmutable());
auto view = GrMakeCachedBitmapProxyView(context, bitmap);
- if (!view.proxy()) {
+ if (!view) {
return nullptr;
}
- return std::unique_ptr<GrFragmentProcessor>(new ColorTableEffect(view.detachProxy()));
+ return std::unique_ptr<GrFragmentProcessor>(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 86ab478..9984491 100644
--- a/src/effects/imagefilters/SkAlphaThresholdFilter.cpp
+++ b/src/effects/imagefilters/SkAlphaThresholdFilter.cpp
@@ -45,9 +45,9 @@
sk_sp<SkSpecialImage> onFilterImage(const Context&, SkIPoint* offset) const override;
#if SK_SUPPORT_GPU
- sk_sp<GrTextureProxy> createMaskTexture(GrRecordingContext*,
- const SkMatrix&,
- const SkIRect& bounds) const;
+ GrSurfaceProxyView createMaskTexture(GrRecordingContext*,
+ const SkMatrix&,
+ const SkIRect& bounds) const;
#endif
private:
@@ -100,13 +100,13 @@
}
#if SK_SUPPORT_GPU
-sk_sp<GrTextureProxy> 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 @@
iter.next();
}
- return rtContext->asTextureProxyRef();
+ return rtContext->readSurfaceView();
}
#endif
@@ -161,8 +161,8 @@
SkMatrix matrix(ctx.ctm());
matrix.postTranslate(SkIntToScalar(-offset->fX), SkIntToScalar(-offset->fY));
- sk_sp<GrTextureProxy> maskProxy(this->createMaskTexture(context, matrix, bounds));
- if (!maskProxy) {
+ GrSurfaceProxyView maskView = this->createMaskTexture(context, matrix, bounds);
+ if (!maskView) {
return nullptr;
}
@@ -175,10 +175,8 @@
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 7a3d38c..dc4fc2a 100644
--- a/src/effects/imagefilters/SkMagnifierImageFilter.cpp
+++ b/src/effects/imagefilters/SkMagnifierImageFilter.cpp
@@ -138,7 +138,7 @@
(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 ad8251e..9013d4e 100644
--- a/src/gpu/effects/GrAlphaThresholdFragmentProcessor.fp
+++ b/src/gpu/effects/GrAlphaThresholdFragmentProcessor.fp
@@ -18,12 +18,12 @@
}
@make {
- static std::unique_ptr<GrFragmentProcessor> Make(sk_sp<GrSurfaceProxy> mask,
+ static std::unique_ptr<GrFragmentProcessor> Make(GrSurfaceProxyView mask,
float innerThreshold,
float outerThreshold,
const SkIRect& bounds) {
return std::unique_ptr<GrFragmentProcessor>(new GrAlphaThresholdFragmentProcessor(
- mask, innerThreshold, outerThreshold, bounds));
+ std::move(mask), innerThreshold, outerThreshold, bounds));
}
}
@@ -72,6 +72,11 @@
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 33b6171..0a24cee 100644
--- a/src/gpu/effects/GrCircleBlurFragmentProcessor.fp
+++ b/src/gpu/effects/GrCircleBlurFragmentProcessor.fp
@@ -188,13 +188,13 @@
profile[profileWidth - 1] = 0;
}
- static sk_sp<GrTextureProxy> 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 @@
builder.finish();
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
- sk_sp<GrTextureProxy> 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<GrTextureProxy> 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<GrFragmentProcessor> GrCircleBlurFragmentProcessor::Make(
GrRecordingContext* context, const SkRect& circle, float sigma) {
float solidRadius;
float textureRadius;
- sk_sp<GrTextureProxy> 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 e9f8317..e862edd 100644
--- a/src/gpu/effects/GrMagnifierEffect.fp
+++ b/src/gpu/effects/GrMagnifierEffect.fp
@@ -82,7 +82,11 @@
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 765bd60..3505878 100644
--- a/src/gpu/effects/GrRRectBlurEffect.fp
+++ b/src/gpu/effects/GrRRectBlurEffect.fp
@@ -28,10 +28,10 @@
}
@class {
- static sk_sp<GrTextureProxy> 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 @@
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
- sk_sp<GrTextureProxy> 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<GrTextureProxy> 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 @@
return nullptr;
}
- sk_sp<GrTextureProxy> 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 5ce2c64..d74c1e2 100644
--- a/src/gpu/effects/GrRectBlurEffect.fp
+++ b/src/gpu/effects/GrRectBlurEffect.fp
@@ -46,8 +46,7 @@
samplerParams
}
@class {
-static sk_sp<GrTextureProxy> 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 @@
builder.finish();
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
- sk_sp<GrTextureProxy> 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<GrTextureProxy> 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 @@
}
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 a9e3d6c..03141a9 100644
--- a/src/gpu/effects/generated/GrAlphaThresholdFragmentProcessor.cpp
+++ b/src/gpu/effects/generated/GrAlphaThresholdFragmentProcessor.cpp
@@ -122,7 +122,12 @@
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 0c5fdbe..05ceb9f 100644
--- a/src/gpu/effects/generated/GrAlphaThresholdFragmentProcessor.h
+++ b/src/gpu/effects/generated/GrAlphaThresholdFragmentProcessor.h
@@ -19,12 +19,12 @@
public:
inline OptimizationFlags optFlags(float outerThreshold);
- static std::unique_ptr<GrFragmentProcessor> Make(sk_sp<GrSurfaceProxy> mask,
+ static std::unique_ptr<GrFragmentProcessor> Make(GrSurfaceProxyView mask,
float innerThreshold,
float outerThreshold,
const SkIRect& bounds) {
return std::unique_ptr<GrFragmentProcessor>(new GrAlphaThresholdFragmentProcessor(
- mask, innerThreshold, outerThreshold, bounds));
+ std::move(mask), innerThreshold, outerThreshold, bounds));
}
GrAlphaThresholdFragmentProcessor(const GrAlphaThresholdFragmentProcessor& src);
std::unique_ptr<GrFragmentProcessor> clone() const override;
@@ -35,12 +35,12 @@
float outerThreshold;
private:
- GrAlphaThresholdFragmentProcessor(sk_sp<GrSurfaceProxy> 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 68eeb04..86ef9c1 100644
--- a/src/gpu/effects/generated/GrCircleBlurFragmentProcessor.cpp
+++ b/src/gpu/effects/generated/GrCircleBlurFragmentProcessor.cpp
@@ -166,12 +166,12 @@
profile[profileWidth - 1] = 0;
}
-static sk_sp<GrTextureProxy> 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 @@
builder.finish();
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
- sk_sp<GrTextureProxy> 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<GrTextureProxy> 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<GrFragmentProcessor> GrCircleBlurFragmentProcessor::Make(
GrRecordingContext* context, const SkRect& circle, float sigma) {
float solidRadius;
float textureRadius;
- sk_sp<GrTextureProxy> 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 a0e0396..bbd74d3 100644
--- a/src/gpu/effects/generated/GrCircleBlurFragmentProcessor.h
+++ b/src/gpu/effects/generated/GrCircleBlurFragmentProcessor.h
@@ -29,7 +29,7 @@
private:
GrCircleBlurFragmentProcessor(SkRect circleRect, float textureRadius, float solidRadius,
- sk_sp<GrSurfaceProxy> 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 6c6858e..8c85810 100644
--- a/src/gpu/effects/generated/GrMagnifierEffect.cpp
+++ b/src/gpu/effects/generated/GrMagnifierEffect.cpp
@@ -189,7 +189,11 @@
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 efb16e7..e774b0c 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<GrFragmentProcessor> Make(sk_sp<GrSurfaceProxy> src, SkIRect bounds,
+ static std::unique_ptr<GrFragmentProcessor> Make(GrSurfaceProxyView src, SkIRect bounds,
SkRect srcRect, float xInvZoom, float yInvZoom,
float xInvInset, float yInvInset) {
return std::unique_ptr<GrFragmentProcessor>(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<GrFragmentProcessor> clone() const override;
@@ -36,10 +36,10 @@
float yInvInset;
private:
- GrMagnifierEffect(sk_sp<GrSurfaceProxy> 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 71f50d7..68607b1 100644
--- a/src/gpu/effects/generated/GrRRectBlurEffect.cpp
+++ b/src/gpu/effects/generated/GrRRectBlurEffect.cpp
@@ -39,8 +39,8 @@
return nullptr;
}
- sk_sp<GrTextureProxy> 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 7c8d748..c078a83 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<GrTextureProxy> 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 @@
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
- sk_sp<GrTextureProxy> 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<GrTextureProxy> 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 @@
private:
GrRRectBlurEffect(float sigma, SkRect rect, float cornerRadius,
- sk_sp<GrSurfaceProxy> 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 8a9f44c..75cb512 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<GrTextureProxy> 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 @@
builder.finish();
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
- sk_sp<GrTextureProxy> 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<GrTextureProxy> 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<GrFragmentProcessor> Make(GrRecordingContext* context,
@@ -91,7 +92,7 @@
}
const float sixSigma = 6 * sigma;
- auto integral = CreateIntegralTexture(context, sixSigma);
+ GrSurfaceProxyView integral = CreateIntegralTexture(context, sixSigma);
if (!integral) {
return nullptr;
}
@@ -125,7 +126,7 @@
bool isFast;
private:
- GrRectBlurEffect(SkRect rect, sk_sp<GrSurfaceProxy> 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 0fbcd43..59624f2 100644
--- a/src/gpu/gradients/GrGradientShader.cpp
+++ b/src/gpu/gradients/GrGradientShader.cpp
@@ -65,7 +65,7 @@
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 caaf985..1e373e0 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<GrFragmentProcessor> Make(sk_sp<GrSurfaceProxy> gradient) {
- return std::unique_ptr<GrFragmentProcessor>(new GrTextureGradientColorizer(gradient));
+ static std::unique_ptr<GrFragmentProcessor> Make(GrSurfaceProxyView gradient) {
+ return std::unique_ptr<GrFragmentProcessor>(
+ new GrTextureGradientColorizer(std::move(gradient)));
}
GrTextureGradientColorizer(const GrTextureGradientColorizer& src);
std::unique_ptr<GrFragmentProcessor> clone() const override;
@@ -26,7 +27,7 @@
TextureSampler gradient;
private:
- GrTextureGradientColorizer(sk_sp<GrSurfaceProxy> 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 c284315..6d40b61 100644
--- a/src/sksl/SkSLHCodeGenerator.cpp
+++ b/src/sksl/SkSLHCodeGenerator.cpp
@@ -66,7 +66,7 @@
} 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 @@
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 @@
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 5a35c59..10c994e 100644
--- a/src/sksl/ir/SkSLLayout.h
+++ b/src/sksl/ir/SkSLLayout.h
@@ -95,7 +95,7 @@
kSkIPoint,
kSkMatrix,
kSkM44,
- kGrSurfaceProxy,
+ kGrSurfaceProxyView,
kGrFragmentProcessor,
};
@@ -177,8 +177,8 @@
return "SkMatrix";
case CType::kSkM44:
return "SkM44";
- case CType::kGrSurfaceProxy:
- return "sk_sp<GrSurfaceProxy>";
+ case CType::kGrSurfaceProxyView:
+ return "GrSurfaceProxyView";
case CType::kGrFragmentProcessor:
return "std::unique_ptr<GrFragmentProcessor>";
default: