diff options
author | Ethan Nicholas <ethannicholas@google.com> | 2017-12-20 12:00:11 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-12-20 19:56:36 +0000 |
commit | 297d6efe852ebb98a324a71c79df8f7bbdcc3b94 (patch) | |
tree | b5757cfba889257ea6f5ef6cb749f69d20e9296c /src/gpu/effects/GrRRectBlurEffect.h | |
parent | 5ade1f6fd91371a2b985986ff099cc37836a443d (diff) |
converted GrRRectBlurEffect to SkSL
Bug: skia:
Change-Id: Ifd192db07e02d69d445277a361760ce4a452f603
Reviewed-on: https://skia-review.googlesource.com/87441
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Diffstat (limited to 'src/gpu/effects/GrRRectBlurEffect.h')
-rw-r--r-- | src/gpu/effects/GrRRectBlurEffect.h | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/src/gpu/effects/GrRRectBlurEffect.h b/src/gpu/effects/GrRRectBlurEffect.h new file mode 100644 index 0000000000..def7244181 --- /dev/null +++ b/src/gpu/effects/GrRRectBlurEffect.h @@ -0,0 +1,124 @@ +/* + * Copyright 2017 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +/* + * This file was autogenerated from GrRRectBlurEffect.fp; do not modify. + */ +#ifndef GrRRectBlurEffect_DEFINED +#define GrRRectBlurEffect_DEFINED +#include "SkTypes.h" +#if SK_SUPPORT_GPU + +#include "GrClip.h" +#include "GrContext.h" +#include "GrPaint.h" +#include "GrRenderTargetContext.h" +#include "GrStyle.h" +#include "SkBlurMaskFilter.h" +#include "SkGpuBlurUtils.h" +#include "GrFragmentProcessor.h" +#include "GrCoordTransform.h" +class GrRRectBlurEffect : public GrFragmentProcessor { +public: + static sk_sp<GrTextureProxy> find_or_create_rrect_blur_mask(GrContext* context, + const SkRRect& rrectToDraw, + const SkISize& size, + float xformedSigma) { + static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); + GrUniqueKey key; + GrUniqueKey::Builder builder(&key, kDomain, 9); + builder[0] = SkScalarCeilToInt(xformedSigma - 1 / 6.0f); + + int index = 1; + 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)); + builder[index++] = SkScalarCeilToInt(rrectToDraw.radii(c).fX); + builder[index++] = SkScalarCeilToInt(rrectToDraw.radii(c).fY); + } + builder.finish(); + + sk_sp<GrTextureProxy> mask(context->resourceProvider()->findOrCreateProxyByUniqueKey( + key, kBottomLeft_GrSurfaceOrigin)); + if (!mask) { + // TODO: this could be approx but the texture coords will need to be updated + sk_sp<GrRenderTargetContext> rtc(context->makeDeferredRenderTargetContextWithFallback( + SkBackingFit::kExact, size.fWidth, size.fHeight, kAlpha_8_GrPixelConfig, + nullptr)); + if (!rtc) { + return nullptr; + } + + GrPaint paint; + + rtc->clear(nullptr, 0x0, GrRenderTargetContext::CanClearFullscreen::kYes); + rtc->drawRRect(GrNoClip(), std::move(paint), GrAA::kYes, SkMatrix::I(), rrectToDraw, + GrStyle::SimpleFill()); + + sk_sp<GrTextureProxy> srcProxy(rtc->asTextureProxyRef()); + if (!srcProxy) { + return nullptr; + } + sk_sp<GrRenderTargetContext> rtc2( + SkGpuBlurUtils::GaussianBlur(context, + std::move(srcProxy), + nullptr, + SkIRect::MakeWH(size.fWidth, size.fHeight), + SkIRect::EmptyIRect(), + xformedSigma, + xformedSigma, + GrTextureDomain::kIgnore_Mode, + SkBackingFit::kExact)); + if (!rtc2) { + return nullptr; + } + + mask = rtc2->asTextureProxyRef(); + if (!mask) { + return nullptr; + } + SkASSERT(mask->origin() == kBottomLeft_GrSurfaceOrigin); + context->resourceProvider()->assignUniqueKeyToProxy(key, mask.get()); + } + + return mask; + } + float sigma() const { return fSigma; } + SkRect rect() const { return fRect; } + float cornerRadius() const { return fCornerRadius; } + + static std::unique_ptr<GrFragmentProcessor> Make(GrContext* context, float sigma, + float xformedSigma, const SkRRect& srcRRect, + const SkRRect& devRRect); + GrRRectBlurEffect(const GrRRectBlurEffect& src); + std::unique_ptr<GrFragmentProcessor> clone() const override; + const char* name() const override { return "RRectBlurEffect"; } + +private: + GrRRectBlurEffect(float sigma, SkRect rect, float cornerRadius, + sk_sp<GrTextureProxy> ninePatchSampler) + : INHERITED(kGrRRectBlurEffect_ClassID, + (OptimizationFlags)kCompatibleWithCoverageAsAlpha_OptimizationFlag) + , fSigma(sigma) + , fRect(rect) + , fCornerRadius(cornerRadius) + , fNinePatchSampler(std::move(ninePatchSampler)) { + this->addTextureSampler(&fNinePatchSampler); + } + GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; + void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; + bool onIsEqual(const GrFragmentProcessor&) const override; + GR_DECLARE_FRAGMENT_PROCESSOR_TEST + float fSigma; + SkRect fRect; + float fCornerRadius; + TextureSampler fNinePatchSampler; + typedef GrFragmentProcessor INHERITED; +}; +#endif +#endif |