aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/effects/GrRectBlurEffect.h
diff options
context:
space:
mode:
authorGravatar Ethan Nicholas <ethannicholas@google.com>2017-10-16 12:35:44 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-10-16 16:58:41 +0000
commit823994624aa5e805e16833ecd3d748fc769a164d (patch)
tree5066101c7fd3f697bf3d95b3166ad0168dc404d3 /src/gpu/effects/GrRectBlurEffect.h
parentd982d0579e7681ec512c0ab612f9664b7a235e79 (diff)
converted GrRectBlurEffect to SkSL
Bug: skia: Change-Id: I3a8e16fd2792e6fb5711815d8aad46ae30c2872e Reviewed-on: https://skia-review.googlesource.com/59163 Commit-Queue: Ethan Nicholas <ethannicholas@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src/gpu/effects/GrRectBlurEffect.h')
-rw-r--r--src/gpu/effects/GrRectBlurEffect.h100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/gpu/effects/GrRectBlurEffect.h b/src/gpu/effects/GrRectBlurEffect.h
new file mode 100644
index 0000000000..7a8bc2c005
--- /dev/null
+++ b/src/gpu/effects/GrRectBlurEffect.h
@@ -0,0 +1,100 @@
+/*
+ * 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 GrRectBlurEffect.fp; do not modify.
+ */
+#ifndef GrRectBlurEffect_DEFINED
+#define GrRectBlurEffect_DEFINED
+#include "SkTypes.h"
+#if SK_SUPPORT_GPU
+
+#include "GrResourceProvider.h"
+#include "../effects/SkBlurMask.h"
+#include "GrFragmentProcessor.h"
+#include "GrCoordTransform.h"
+#include "GrColorSpaceXform.h"
+class GrRectBlurEffect : public GrFragmentProcessor {
+public:
+ static sk_sp<GrTextureProxy> CreateBlurProfileTexture(GrResourceProvider* resourceProvider,
+ float sigma) {
+ unsigned int profileSize = SkScalarCeilToInt(6 * sigma);
+
+ static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
+ GrUniqueKey key;
+ GrUniqueKey::Builder builder(&key, kDomain, 1);
+ builder[0] = profileSize;
+ builder.finish();
+
+ sk_sp<GrTextureProxy> blurProfile(
+ resourceProvider->findOrCreateProxyByUniqueKey(key, kTopLeft_GrSurfaceOrigin));
+ if (!blurProfile) {
+ GrSurfaceDesc texDesc;
+ texDesc.fOrigin = kTopLeft_GrSurfaceOrigin;
+ texDesc.fWidth = profileSize;
+ texDesc.fHeight = 1;
+ texDesc.fConfig = kAlpha_8_GrPixelConfig;
+
+ std::unique_ptr<uint8_t[]> profile(SkBlurMask::ComputeBlurProfile(sigma));
+
+ blurProfile = GrSurfaceProxy::MakeDeferred(resourceProvider, texDesc, SkBudgeted::kYes,
+ profile.get(), 0);
+ if (!blurProfile) {
+ return nullptr;
+ }
+
+ SkASSERT(blurProfile->origin() == kTopLeft_GrSurfaceOrigin);
+ resourceProvider->assignUniqueKeyToProxy(key, blurProfile.get());
+ }
+
+ return blurProfile;
+ }
+ SkRect rect() const { return fRect; }
+ float sigma() const { return fSigma; }
+
+ static std::unique_ptr<GrFragmentProcessor> Make(GrResourceProvider* resourceProvider,
+ const SkRect& rect, float sigma) {
+ int doubleProfileSize = SkScalarCeilToInt(12 * sigma);
+
+ if (doubleProfileSize >= rect.width() || doubleProfileSize >= rect.height()) {
+ // if the blur sigma is too large so the gaussian overlaps the whole
+ // rect in either direction, fall back to CPU path for now.
+ return nullptr;
+ }
+
+ sk_sp<GrTextureProxy> blurProfile(CreateBlurProfileTexture(resourceProvider, sigma));
+ if (!blurProfile) {
+ return nullptr;
+ }
+
+ return std::unique_ptr<GrFragmentProcessor>(
+ new GrRectBlurEffect(rect, sigma, std::move(blurProfile)));
+ }
+ GrRectBlurEffect(const GrRectBlurEffect& src);
+ std::unique_ptr<GrFragmentProcessor> clone() const override;
+ const char* name() const override { return "RectBlurEffect"; }
+
+private:
+ GrRectBlurEffect(SkRect rect, float sigma, sk_sp<GrTextureProxy> blurProfile)
+ : INHERITED(kGrRectBlurEffect_ClassID,
+ (OptimizationFlags)kCompatibleWithCoverageAsAlpha_OptimizationFlag)
+ , fRect(rect)
+ , fSigma(sigma)
+ , fBlurProfile(std::move(blurProfile)) {
+ this->addTextureSampler(&fBlurProfile);
+ }
+ GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
+ void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
+ bool onIsEqual(const GrFragmentProcessor&) const override;
+ GR_DECLARE_FRAGMENT_PROCESSOR_TEST
+ SkRect fRect;
+ float fSigma;
+ TextureSampler fBlurProfile;
+ typedef GrFragmentProcessor INHERITED;
+};
+#endif
+#endif