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>
This commit is contained in:
Greg Daniel 2020-02-11 15:49:27 -05:00 committed by Skia Commit-Bot
parent 0234170cc6
commit 43956128ba
21 changed files with 307 additions and 275 deletions

View File

@ -289,8 +289,7 @@ public:
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 @@ private:
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 @@ std::unique_ptr<GrFragmentProcessor> ColorTableEffect::Make(GrRecordingContext*
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,

View File

@ -45,9 +45,9 @@ protected:
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 @@ void SkAlphaThresholdFilterImpl::flatten(SkWriteBuffer& buffer) const {
}
#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 @@ sk_sp<GrTextureProxy> SkAlphaThresholdFilterImpl::createMaskTexture(GrRecordingC
iter.next();
}
return rtContext->asTextureProxyRef();
return rtContext->readSurfaceView();
}
#endif
@ -161,8 +161,8 @@ sk_sp<SkSpecialImage> SkAlphaThresholdFilterImpl::onFilterImage(const Context& c
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 @@ sk_sp<SkSpecialImage> 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;
}

View File

@ -138,7 +138,7 @@ sk_sp<SkSpecialImage> 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,

View File

@ -18,12 +18,12 @@ in uniform half outerThreshold;
}
@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 @@ 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);
}

View File

@ -188,13 +188,13 @@ uniform half4 circleData;
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 @@ uniform half4 circleData;
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;
}

View File

@ -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(),

View File

@ -28,10 +28,10 @@ uniform half blurRadius;
}
@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 @@ uniform half blurRadius;
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 @@ uniform half blurRadius;
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;
}

View File

@ -46,8 +46,7 @@ layout(key) in bool isFast;
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 @@ static sk_sp<GrTextureProxy> CreateIntegralTexture(GrRecordingContext* context,
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 @@ static sk_sp<GrTextureProxy> CreateIntegralTexture(GrRecordingContext* context,
}
const float sixSigma = 6 * sigma;
auto integral = CreateIntegralTexture(context, sixSigma);
GrSurfaceProxyView integral = CreateIntegralTexture(context, sixSigma);
if (!integral) {
return nullptr;
}

View File

@ -122,7 +122,12 @@ std::unique_ptr<GrFragmentProcessor> 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

View File

@ -19,12 +19,12 @@ class GrAlphaThresholdFragmentProcessor : public GrFragmentProcessor {
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 @@ public:
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) {

View File

@ -166,12 +166,12 @@ static void create_half_plane_profile(uint8_t* profile, int profileWidth) {
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 @@ static sk_sp<GrTextureProxy> create_profile_texture(GrRecordingContext* context,
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;
}

View File

@ -29,7 +29,7 @@ public:
private:
GrCircleBlurFragmentProcessor(SkRect circleRect, float textureRadius, float solidRadius,
sk_sp<GrSurfaceProxy> blurProfileSampler)
GrSurfaceProxyView blurProfileSampler)
: INHERITED(kGrCircleBlurFragmentProcessor_ClassID,
(OptimizationFlags)kCompatibleWithCoverageAsAlpha_OptimizationFlag)
, circleRect(circleRect)

View File

@ -189,7 +189,11 @@ std::unique_ptr<GrFragmentProcessor> 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(),

View File

@ -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 @@ public:
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)

View File

@ -39,8 +39,8 @@ std::unique_ptr<GrFragmentProcessor> GrRRectBlurEffect::Make(GrRecordingContext*
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;
}

View File

@ -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 @@ public:
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 @@ public:
private:
GrRRectBlurEffect(float sigma, SkRect rect, float cornerRadius,
sk_sp<GrSurfaceProxy> ninePatchSampler)
GrSurfaceProxyView ninePatchSampler)
: INHERITED(kGrRRectBlurEffect_ClassID,
(OptimizationFlags)kCompatibleWithCoverageAsAlpha_OptimizationFlag)
, sigma(sigma)

View File

@ -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 @@ public:
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 @@ 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<GrSurfaceProxy> integral, float invSixSigma, bool isFast,
GrRectBlurEffect(SkRect rect, GrSurfaceProxyView integral, float invSixSigma, bool isFast,
GrSamplerState samplerParams)
: INHERITED(kGrRectBlurEffect_ClassID,
(OptimizationFlags)kCompatibleWithCoverageAsAlpha_OptimizationFlag)

View File

@ -65,7 +65,7 @@ static std::unique_ptr<GrFragmentProcessor> 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

View File

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

View File

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

View File

@ -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<GrSurfaceProxy>";
case CType::kGrSurfaceProxyView:
return "GrSurfaceProxyView";
case CType::kGrFragmentProcessor:
return "std::unique_ptr<GrFragmentProcessor>";
default: