diff options
author | Brian Salomon <bsalomon@google.com> | 2017-07-27 11:53:21 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-07-27 16:18:33 +0000 |
commit | b133ffe76973865955a93644092307cf3d98662c (patch) | |
tree | 18787d632702d7841c49088166c307fbea094427 | |
parent | 164f6ecb842f530017acb7ee814b2a55444f4462 (diff) |
Remove Gr1DKernelEffect "helper" class.
Change-Id: I748e49eeacb782fb738c08d5475c442dbce3ad5a
Reviewed-on: https://skia-review.googlesource.com/27500
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
-rw-r--r-- | gn/gpu.gni | 1 | ||||
-rw-r--r-- | src/core/SkGpuBlurUtils.cpp | 18 | ||||
-rw-r--r-- | src/effects/SkMorphologyImageFilter.cpp | 142 | ||||
-rw-r--r-- | src/gpu/effects/Gr1DKernelEffect.h | 67 | ||||
-rw-r--r-- | src/gpu/effects/GrGaussianConvolutionFragmentProcessor.cpp | 30 | ||||
-rw-r--r-- | src/gpu/effects/GrGaussianConvolutionFragmentProcessor.h | 16 |
6 files changed, 104 insertions, 170 deletions
diff --git a/gn/gpu.gni b/gn/gpu.gni index 1158eb041c..b29310e40a 100644 --- a/gn/gpu.gni +++ b/gn/gpu.gni @@ -305,7 +305,6 @@ skia_gpu_sources = [ "$_src/gpu/ccpr/GrCoverageCountingPathRenderer.cpp", "$_src/gpu/ccpr/GrCoverageCountingPathRenderer.h", - "$_src/gpu/effects/Gr1DKernelEffect.h", "$_src/gpu/effects/GrBlurredEdgeFragmentProcessor.cpp", "$_src/gpu/effects/GrBlurredEdgeFragmentProcessor.h", "$_src/gpu/effects/GrCircleEffect.cpp", diff --git a/src/core/SkGpuBlurUtils.cpp b/src/core/SkGpuBlurUtils.cpp index cb2351e9c4..5121cc53ec 100644 --- a/src/core/SkGpuBlurUtils.cpp +++ b/src/core/SkGpuBlurUtils.cpp @@ -20,6 +20,8 @@ #define MAX_BLUR_SIGMA 4.0f +using Direction = GrGaussianConvolutionFragmentProcessor::Direction; + static void scale_irect_roundout(SkIRect* rect, float xScale, float yScale) { rect->fLeft = SkScalarFloorToInt(rect->fLeft * xScale); rect->fTop = SkScalarFloorToInt(rect->fTop * yScale); @@ -71,7 +73,7 @@ static void convolve_gaussian_1d(GrRenderTargetContext* renderTargetContext, const SkIRect& dstRect, const SkIPoint& srcOffset, sk_sp<GrTextureProxy> proxy, - Gr1DKernelEffect::Direction direction, + Direction direction, int radius, float sigma, GrTextureDomain::Mode mode, @@ -120,7 +122,7 @@ static void convolve_gaussian(GrRenderTargetContext* renderTargetContext, const GrClip& clip, const SkIRect& srcRect, sk_sp<GrTextureProxy> proxy, - Gr1DKernelEffect::Direction direction, + Direction direction, int radius, float sigma, const SkIRect& srcBounds, @@ -137,7 +139,7 @@ static void convolve_gaussian(GrRenderTargetContext* renderTargetContext, SkIRect midRect = srcBounds, leftRect, rightRect; midRect.offset(srcOffset); SkIRect topRect, bottomRect; - if (direction == Gr1DKernelEffect::kX_Direction) { + if (Direction::kX == direction) { bounds[0] = srcBounds.left(); bounds[1] = srcBounds.right(); topRect = SkIRect::MakeLTRB(0, 0, dstRect.right(), midRect.top()); @@ -327,9 +329,8 @@ sk_sp<GrRenderTargetContext> GaussianBlur(GrContext* context, return nullptr; } - convolve_gaussian(dstRenderTargetContext.get(), clip, srcRect, - std::move(srcProxy), Gr1DKernelEffect::kX_Direction, radiusX, sigmaX, - localSrcBounds, srcOffset, mode); + convolve_gaussian(dstRenderTargetContext.get(), clip, srcRect, std::move(srcProxy), + Direction::kX, radiusX, sigmaX, localSrcBounds, srcOffset, mode); srcProxy = dstRenderTargetContext->asTextureProxyRef(); if (!srcProxy) { @@ -363,9 +364,8 @@ sk_sp<GrRenderTargetContext> GaussianBlur(GrContext* context, return nullptr; } - convolve_gaussian(dstRenderTargetContext.get(), clip, srcRect, - std::move(srcProxy), Gr1DKernelEffect::kY_Direction, radiusY, sigmaY, - localSrcBounds, srcOffset, mode); + convolve_gaussian(dstRenderTargetContext.get(), clip, srcRect, std::move(srcProxy), + Direction::kY, radiusY, sigmaY, localSrcBounds, srcOffset, mode); srcProxy = dstRenderTargetContext->asTextureProxyRef(); if (!srcProxy) { diff --git a/src/effects/SkMorphologyImageFilter.cpp b/src/effects/SkMorphologyImageFilter.cpp index e2e8dbacbc..62c7c2e3b4 100644 --- a/src/effects/SkMorphologyImageFilter.cpp +++ b/src/effects/SkMorphologyImageFilter.cpp @@ -17,20 +17,19 @@ #include "SkWriteBuffer.h" #if SK_SUPPORT_GPU +#include "../private/GrGLSL.h" #include "GrContext.h" +#include "GrCoordTransform.h" #include "GrFixedClip.h" #include "GrRenderTargetContext.h" #include "GrTexture.h" #include "GrTextureProxy.h" - #include "SkGr.h" -#include "effects/Gr1DKernelEffect.h" #include "effects/GrProxyMove.h" #include "glsl/GrGLSLFragmentProcessor.h" #include "glsl/GrGLSLFragmentShaderBuilder.h" #include "glsl/GrGLSLProgramDataManager.h" #include "glsl/GrGLSLUniformHandler.h" -#include "../private/GrGLSL.h" #endif sk_sp<SkImageFilter> SkDilateImageFilter::Make(int radiusX, int radiusY, @@ -139,54 +138,52 @@ void SkDilateImageFilter::toString(SkString* str) const { * kernel is selected as the new color. The new color is modulated by the input * color. */ -class GrMorphologyEffect : public Gr1DKernelEffect { +class GrMorphologyEffect : public GrFragmentProcessor { public: - enum MorphologyType { - kErode_MorphologyType, - kDilate_MorphologyType, - }; + enum class Direction { kX, kY }; + enum class Type { kErode, kDilate }; - static sk_sp<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy, - Direction dir, int radius, MorphologyType type) { - return sk_sp<GrFragmentProcessor>(new GrMorphologyEffect(std::move(proxy), - dir, radius, type)); + static sk_sp<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy, Direction dir, int radius, + Type type) { + return sk_sp<GrFragmentProcessor>( + new GrMorphologyEffect(std::move(proxy), dir, radius, type, nullptr)); } static sk_sp<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy, Direction dir, int radius, - MorphologyType type, const float bounds[2]) { + Type type, const float bounds[2]) { return sk_sp<GrFragmentProcessor>(new GrMorphologyEffect(std::move(proxy), dir, radius, type, bounds)); } - ~GrMorphologyEffect() override; - - MorphologyType type() const { return fType; } + Type type() const { return fType; } bool useRange() const { return fUseRange; } const float* range() const { return fRange; } + Direction direction() const { return fDirection; } + int radius() const { return fRadius; } + int width() const { return 2 * fRadius + 1; } const char* name() const override { return "Morphology"; } -protected: - - MorphologyType fType; +private: + GrCoordTransform fCoordTransform; + TextureSampler fTextureSampler; + Direction fDirection; + int fRadius; + Type fType; bool fUseRange; float fRange[2]; -private: GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; bool onIsEqual(const GrFragmentProcessor&) const override; - GrMorphologyEffect(sk_sp<GrTextureProxy>, - Direction, int radius, MorphologyType); - GrMorphologyEffect(sk_sp<GrTextureProxy>, - Direction, int radius, MorphologyType, const float bounds[2]); + GrMorphologyEffect(sk_sp<GrTextureProxy>, Direction, int radius, Type, const float range[2]); GR_DECLARE_FRAGMENT_PROCESSOR_TEST - typedef Gr1DKernelEffect INHERITED; + typedef GrFragmentProcessor INHERITED; }; /////////////////////////////////////////////////////////////////////////////// @@ -224,11 +221,11 @@ void GrGLMorphologyEffect::emitCode(EmitArgs& args) { SkString coords2D = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]); const char* func; switch (me.type()) { - case GrMorphologyEffect::kErode_MorphologyType: + case GrMorphologyEffect::Type::kErode: fragBuilder->codeAppendf("\t\t%s = vec4(1, 1, 1, 1);\n", args.fOutputColor); func = "min"; break; - case GrMorphologyEffect::kDilate_MorphologyType: + case GrMorphologyEffect::Type::kDilate: fragBuilder->codeAppendf("\t\t%s = vec4(0, 0, 0, 0);\n", args.fOutputColor); func = "max"; break; @@ -240,10 +237,10 @@ void GrGLMorphologyEffect::emitCode(EmitArgs& args) { const char* dir; switch (me.direction()) { - case Gr1DKernelEffect::kX_Direction: + case GrMorphologyEffect::Direction::kX: dir = "x"; break; - case Gr1DKernelEffect::kY_Direction: + case GrMorphologyEffect::Direction::kY: dir = "y"; break; default: @@ -251,7 +248,7 @@ void GrGLMorphologyEffect::emitCode(EmitArgs& args) { dir = ""; // suppress warning } - int width = GrMorphologyEffect::WidthFromRadius(me.radius()); + int width = me.width(); // vec2 coord = coord2D; fragBuilder->codeAppendf("\t\tvec2 coord = %s;\n", coords2D.c_str()); @@ -282,8 +279,8 @@ void GrGLMorphologyEffect::GenKey(const GrProcessor& proc, const GrShaderCaps&, GrProcessorKeyBuilder* b) { const GrMorphologyEffect& m = proc.cast<GrMorphologyEffect>(); uint32_t key = static_cast<uint32_t>(m.radius()); - key |= (m.type() << 8); - key |= (m.direction() << 9); + key |= (static_cast<uint32_t>(m.type()) << 8); + key |= (static_cast<uint32_t>(m.direction()) << 9); if (m.useRange()) { key |= 1 << 10; } @@ -298,10 +295,10 @@ void GrGLMorphologyEffect::onSetData(const GrGLSLProgramDataManager& pdman, float pixelSize = 0.0f; switch (m.direction()) { - case Gr1DKernelEffect::kX_Direction: + case GrMorphologyEffect::Direction::kX: pixelSize = 1.0f / texture.width(); break; - case Gr1DKernelEffect::kY_Direction: + case GrMorphologyEffect::Direction::kY: pixelSize = 1.0f / texture.height(); break; default: @@ -311,7 +308,7 @@ void GrGLMorphologyEffect::onSetData(const GrGLSLProgramDataManager& pdman, if (m.useRange()) { const float* range = m.range(); - if (Gr1DKernelEffect::kY_Direction == m.direction() && + if (GrMorphologyEffect::Direction::kY == m.direction() && proxy->origin() == kBottomLeft_GrSurfaceOrigin) { pdman.set2f(fRangeUni, 1.0f - (range[1]*pixelSize), 1.0f - (range[0]*pixelSize)); } else { @@ -325,29 +322,22 @@ void GrGLMorphologyEffect::onSetData(const GrGLSLProgramDataManager& pdman, GrMorphologyEffect::GrMorphologyEffect(sk_sp<GrTextureProxy> proxy, Direction direction, int radius, - MorphologyType type) - : INHERITED{ModulateByConfigOptimizationFlags(proxy->config()), GR_PROXY_MOVE(proxy), - direction, radius} - , fType(type) - , fUseRange(false) { - this->initClassID<GrMorphologyEffect>(); -} - -GrMorphologyEffect::GrMorphologyEffect(sk_sp<GrTextureProxy> proxy, - Direction direction, - int radius, - MorphologyType type, + Type type, const float range[2]) - : INHERITED{ModulateByConfigOptimizationFlags(proxy->config()), GR_PROXY_MOVE(proxy), - direction, radius} + : INHERITED(ModulateByConfigOptimizationFlags(proxy->config())) + , fCoordTransform(proxy.get()) + , fTextureSampler(std::move(proxy)) + , fDirection(direction) + , fRadius(radius) , fType(type) - , fUseRange(true) { + , fUseRange(SkToBool(range)) { this->initClassID<GrMorphologyEffect>(); - fRange[0] = range[0]; - fRange[1] = range[1]; -} - -GrMorphologyEffect::~GrMorphologyEffect() { + this->addCoordTransform(&fCoordTransform); + this->addTextureSampler(&fTextureSampler); + if (fUseRange) { + fRange[0] = range[0]; + fRange[1] = range[1]; + } } void GrMorphologyEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps, @@ -376,26 +366,25 @@ sk_sp<GrFragmentProcessor> GrMorphologyEffect::TestCreate(GrProcessorTestData* d : GrProcessorUnitTest::kAlphaTextureIdx; sk_sp<GrTextureProxy> proxy = d->textureProxy(texIdx); - Direction dir = d->fRandom->nextBool() ? kX_Direction : kY_Direction; + Direction dir = d->fRandom->nextBool() ? Direction::kX : Direction::kY; static const int kMaxRadius = 10; int radius = d->fRandom->nextRangeU(1, kMaxRadius); - MorphologyType type = d->fRandom->nextBool() ? GrMorphologyEffect::kErode_MorphologyType - : GrMorphologyEffect::kDilate_MorphologyType; + Type type = d->fRandom->nextBool() ? GrMorphologyEffect::Type::kErode + : GrMorphologyEffect::Type::kDilate; return GrMorphologyEffect::Make(std::move(proxy), dir, radius, type); } #endif - static void apply_morphology_rect(GrRenderTargetContext* renderTargetContext, const GrClip& clip, sk_sp<GrTextureProxy> proxy, const SkIRect& srcRect, const SkIRect& dstRect, int radius, - GrMorphologyEffect::MorphologyType morphType, + GrMorphologyEffect::Type morphType, const float bounds[2], - Gr1DKernelEffect::Direction direction) { + GrMorphologyEffect::Direction direction) { GrPaint paint; paint.setGammaCorrect(renderTargetContext->isGammaCorrect()); @@ -413,8 +402,8 @@ static void apply_morphology_rect_no_bounds(GrRenderTargetContext* renderTargetC const SkIRect& srcRect, const SkIRect& dstRect, int radius, - GrMorphologyEffect::MorphologyType morphType, - Gr1DKernelEffect::Direction direction) { + GrMorphologyEffect::Type morphType, + GrMorphologyEffect::Direction direction) { GrPaint paint; paint.setGammaCorrect(renderTargetContext->isGammaCorrect()); @@ -431,13 +420,13 @@ static void apply_morphology_pass(GrRenderTargetContext* renderTargetContext, const SkIRect& srcRect, const SkIRect& dstRect, int radius, - GrMorphologyEffect::MorphologyType morphType, - Gr1DKernelEffect::Direction direction) { + GrMorphologyEffect::Type morphType, + GrMorphologyEffect::Direction direction) { float bounds[2] = { 0.0f, 1.0f }; SkIRect lowerSrcRect = srcRect, lowerDstRect = dstRect; SkIRect middleSrcRect = srcRect, middleDstRect = dstRect; SkIRect upperSrcRect = srcRect, upperDstRect = dstRect; - if (direction == Gr1DKernelEffect::kX_Direction) { + if (direction == GrMorphologyEffect::Direction::kX) { bounds[0] = SkIntToScalar(srcRect.left()) + 0.5f; bounds[1] = SkIntToScalar(srcRect.right()) - 0.5f; lowerSrcRect.fRight = srcRect.left() + radius; @@ -475,7 +464,7 @@ static sk_sp<SkSpecialImage> apply_morphology( GrContext* context, SkSpecialImage* input, const SkIRect& rect, - GrMorphologyEffect::MorphologyType morphType, + GrMorphologyEffect::Type morphType, SkISize radius, const SkImageFilter::OutputProperties& outputProperties) { sk_sp<GrTextureProxy> srcTexture(input->asTextureProxyRef(context)); @@ -498,14 +487,12 @@ static sk_sp<SkSpecialImage> apply_morphology( return nullptr; } - apply_morphology_pass(dstRTContext.get(), clip, std::move(srcTexture), - srcRect, dstRect, radius.fWidth, morphType, - Gr1DKernelEffect::kX_Direction); + apply_morphology_pass(dstRTContext.get(), clip, std::move(srcTexture), srcRect, dstRect, + radius.fWidth, morphType, GrMorphologyEffect::Direction::kX); SkIRect clearRect = SkIRect::MakeXYWH(dstRect.fLeft, dstRect.fBottom, dstRect.width(), radius.fHeight); - GrColor clearColor = GrMorphologyEffect::kErode_MorphologyType == morphType - ? SK_ColorWHITE - : SK_ColorTRANSPARENT; + GrColor clearColor = + GrMorphologyEffect::Type::kErode == morphType ? SK_ColorWHITE : SK_ColorTRANSPARENT; dstRTContext->clear(&clearRect, clearColor, false); srcTexture = dstRTContext->asTextureProxyRef(); @@ -518,9 +505,8 @@ static sk_sp<SkSpecialImage> apply_morphology( return nullptr; } - apply_morphology_pass(dstRTContext.get(), clip, std::move(srcTexture), - srcRect, dstRect, radius.fHeight, morphType, - Gr1DKernelEffect::kY_Direction); + apply_morphology_pass(dstRTContext.get(), clip, std::move(srcTexture), srcRect, dstRect, + radius.fHeight, morphType, GrMorphologyEffect::Direction::kY); srcTexture = dstRTContext->asTextureProxyRef(); } @@ -577,8 +563,8 @@ sk_sp<SkSpecialImage> SkMorphologyImageFilter::onFilterImage(SkSpecialImage* sou // fall-back, which saves us from having to do the xform during the filter itself. input = ImageToColorSpace(input.get(), ctx.outputProperties()); - auto type = (kDilate_Op == this->op()) ? GrMorphologyEffect::kDilate_MorphologyType - : GrMorphologyEffect::kErode_MorphologyType; + auto type = (kDilate_Op == this->op()) ? GrMorphologyEffect::Type::kDilate + : GrMorphologyEffect::Type::kErode; sk_sp<SkSpecialImage> result(apply_morphology(context, input.get(), srcBounds, type, SkISize::Make(width, height), ctx.outputProperties())); diff --git a/src/gpu/effects/Gr1DKernelEffect.h b/src/gpu/effects/Gr1DKernelEffect.h deleted file mode 100644 index 8eac5cd7ad..0000000000 --- a/src/gpu/effects/Gr1DKernelEffect.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2012 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef Gr1DKernelEffect_DEFINED -#define Gr1DKernelEffect_DEFINED - -#include "GrCoordTransform.h" -#include "GrFragmentProcessor.h" -#include "SkMatrix.h" - -/** - * Base class for 1D kernel effects. The kernel operates either in X or Y and - * has a pixel radius. The kernel is specified in the src texture's space - * and the kernel center is pinned to a texel's center. The radius specifies - * the number of texels on either side of the center texel in X or Y that are - * read. Since the center pixel is also read, the total width is one larger than - * two times the radius. - */ - -class Gr1DKernelEffect : public GrFragmentProcessor { -public: - enum Direction { - kX_Direction, - kY_Direction, - }; - - ~Gr1DKernelEffect() override {} - - static int WidthFromRadius(int radius) { return 2 * radius + 1; } - - int radius() const { return fRadius; } - int width() const { return WidthFromRadius(fRadius); } - Direction direction() const { return fDirection; } - - SkString dumpInfo() const override { - SkString str; - str.appendf("Direction: %s, Radius: %d ", kX_Direction == fDirection ? "X" : "Y", fRadius); - str.append(INHERITED::dumpInfo()); - return str; - } - -protected: - Gr1DKernelEffect(OptimizationFlags optFlags, sk_sp<GrTextureProxy> proxy, Direction direction, - int radius) - : INHERITED(optFlags) - , fCoordTransform(proxy.get()) - , fTextureSampler(std::move(proxy)) - , fDirection(direction) - , fRadius(radius) { - this->addCoordTransform(&fCoordTransform); - this->addTextureSampler(&fTextureSampler); - } - -private: - GrCoordTransform fCoordTransform; - TextureSampler fTextureSampler; - Direction fDirection; - int fRadius; - - typedef GrFragmentProcessor INHERITED; -}; - -#endif diff --git a/src/gpu/effects/GrGaussianConvolutionFragmentProcessor.cpp b/src/gpu/effects/GrGaussianConvolutionFragmentProcessor.cpp index 8e8c3001b0..423b25dc0f 100644 --- a/src/gpu/effects/GrGaussianConvolutionFragmentProcessor.cpp +++ b/src/gpu/effects/GrGaussianConvolutionFragmentProcessor.cpp @@ -17,7 +17,8 @@ #include "glsl/GrGLSLUniformHandler.h" // For brevity -typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; +using UniformHandle = GrGLSLProgramDataManager::UniformHandle; +using Direction = GrGaussianConvolutionFragmentProcessor::Direction; class GrGLConvolutionEffect : public GrGLSLFragmentProcessor { public: @@ -48,7 +49,7 @@ void GrGLConvolutionEffect::emitCode(EmitArgs& args) { kDefault_GrSLPrecision, "Bounds"); } - int width = Gr1DKernelEffect::WidthFromRadius(ce.radius()); + int width = ce.width(); int arrayCount = (width + 3) / 4; SkASSERT(4 * arrayCount >= width); @@ -82,7 +83,7 @@ void GrGLConvolutionEffect::emitCode(EmitArgs& args) { // float, and then mul weight*texture_sample by the float. However, the Adreno 430 seems // to have a bug that caused corruption. const char* bounds = uniformHandler->getUniformCStr(fBoundsUni); - const char* component = ce.direction() == Gr1DKernelEffect::kY_Direction ? "y" : "x"; + const char* component = ce.direction() == Direction::kY ? "y" : "x"; switch (ce.mode()) { case GrTextureDomain::kClamp_Mode: { @@ -127,10 +128,10 @@ void GrGLConvolutionEffect::onSetData(const GrGLSLProgramDataManager& pdman, float imageIncrement[2] = {0}; float ySign = proxy->origin() != kTopLeft_GrSurfaceOrigin ? 1.0f : -1.0f; switch (conv.direction()) { - case Gr1DKernelEffect::kX_Direction: + case Direction::kX: imageIncrement[0] = 1.0f / texture.width(); break; - case Gr1DKernelEffect::kY_Direction: + case Direction::kY: imageIncrement[1] = ySign / texture.height(); break; default: @@ -145,7 +146,7 @@ void GrGLConvolutionEffect::onSetData(const GrGLSLProgramDataManager& pdman, bounds[0] += SK_ScalarHalf; bounds[1] -= SK_ScalarHalf; } - if (Gr1DKernelEffect::kX_Direction == conv.direction()) { + if (Direction::kX == conv.direction()) { SkScalar inv = SkScalarInvert(SkIntToScalar(texture.width())); pdman.set2f(fBoundsUni, inv * bounds[0], inv * bounds[1]); } else { @@ -157,7 +158,7 @@ void GrGLConvolutionEffect::onSetData(const GrGLSLProgramDataManager& pdman, } } } - int width = Gr1DKernelEffect::WidthFromRadius(conv.radius()); + int width = conv.width(); int arrayCount = (width + 3) / 4; SkASSERT(4 * arrayCount >= width); @@ -170,7 +171,7 @@ void GrGLConvolutionEffect::GenKey(const GrProcessor& processor, const GrShaderC processor.cast<GrGaussianConvolutionFragmentProcessor>(); uint32_t key = conv.radius(); key <<= 3; - key |= GrGaussianConvolutionFragmentProcessor::kY_Direction == conv.direction() ? 0x4 : 0x0; + key |= Direction::kY == conv.direction() ? 0x4 : 0x0; key |= static_cast<uint32_t>(conv.mode()); b->add32(key); } @@ -201,10 +202,15 @@ GrGaussianConvolutionFragmentProcessor::GrGaussianConvolutionFragmentProcessor( float gaussianSigma, GrTextureDomain::Mode mode, int bounds[2]) - : INHERITED{ModulateByConfigOptimizationFlags(proxy->config()), GR_PROXY_MOVE(proxy), - direction, radius} + : INHERITED(ModulateByConfigOptimizationFlags(proxy->config())) + , fCoordTransform(proxy.get()) + , fTextureSampler(std::move(proxy)) + , fRadius(radius) + , fDirection(direction) , fMode(mode) { this->initClassID<GrGaussianConvolutionFragmentProcessor>(); + this->addCoordTransform(&fCoordTransform); + this->addTextureSampler(&fTextureSampler); SkASSERT(radius <= kMaxKernelRadius); fill_in_1D_guassian_kernel(fKernel, this->width(), gaussianSigma, this->radius()); @@ -248,11 +254,11 @@ sk_sp<GrFragmentProcessor> GrGaussianConvolutionFragmentProcessor::TestCreate( Direction dir; if (d->fRandom->nextBool()) { - dir = kX_Direction; + dir = Direction::kX; bounds[0] = d->fRandom->nextRangeU(0, proxy->width()-1); bounds[1] = d->fRandom->nextRangeU(bounds[0], proxy->width()-1); } else { - dir = kY_Direction; + dir = Direction::kY; bounds[0] = d->fRandom->nextRangeU(0, proxy->height()-1); bounds[1] = d->fRandom->nextRangeU(bounds[0], proxy->height()-1); } diff --git a/src/gpu/effects/GrGaussianConvolutionFragmentProcessor.h b/src/gpu/effects/GrGaussianConvolutionFragmentProcessor.h index 7496c35d44..bdc4384a2c 100644 --- a/src/gpu/effects/GrGaussianConvolutionFragmentProcessor.h +++ b/src/gpu/effects/GrGaussianConvolutionFragmentProcessor.h @@ -8,7 +8,8 @@ #ifndef GrGaussianConvolutionFragmentProcessor_DEFINED #define GrGaussianConvolutionFragmentProcessor_DEFINED -#include "Gr1DKernelEffect.h" +#include "GrCoordTransform.h" +#include "GrFragmentProcessor.h" #include "GrTextureDomain.h" /** @@ -16,8 +17,10 @@ * Each texel is multiplied by it's weight and summed to determine the filtered color. The output * color is set to a modulation of the filtered and input colors. */ -class GrGaussianConvolutionFragmentProcessor : public Gr1DKernelEffect { +class GrGaussianConvolutionFragmentProcessor : public GrFragmentProcessor { public: + enum class Direction { kX, kY }; + /// Convolve with a Gaussian kernel static sk_sp<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy, Direction dir, @@ -35,6 +38,9 @@ public: const int* bounds() const { return fBounds; } bool useBounds() const { return fMode != GrTextureDomain::kIgnore_Mode; } + int radius() const { return fRadius; } + int width() const { return 2 * fRadius + 1; } + Direction direction() const { return fDirection; } GrTextureDomain::Mode mode() const { return fMode; } @@ -63,13 +69,17 @@ private: GR_DECLARE_FRAGMENT_PROCESSOR_TEST + GrCoordTransform fCoordTransform; + TextureSampler fTextureSampler; // TODO: Inline the kernel constants into the generated shader code. This may involve pulling // some of the logic from SkGpuBlurUtils into this class related to radius/sigma calculations. float fKernel[kMaxKernelWidth]; int fBounds[2]; + int fRadius; + Direction fDirection; GrTextureDomain::Mode fMode; - typedef Gr1DKernelEffect INHERITED; + typedef GrFragmentProcessor INHERITED; }; #endif |