diff options
Diffstat (limited to 'src/gpu/effects')
-rw-r--r-- | src/gpu/effects/Gr1DKernelEffect.h | 12 | ||||
-rw-r--r-- | src/gpu/effects/GrConvolutionEffect.cpp | 15 | ||||
-rw-r--r-- | src/gpu/effects/GrConvolutionEffect.h | 3 | ||||
-rw-r--r-- | src/gpu/effects/GrGradientEffects.cpp | 32 | ||||
-rw-r--r-- | src/gpu/effects/GrGradientEffects.h | 35 | ||||
-rw-r--r-- | src/gpu/effects/GrMorphologyEffect.cpp | 12 | ||||
-rw-r--r-- | src/gpu/effects/GrMorphologyEffect.h | 2 | ||||
-rw-r--r-- | src/gpu/effects/GrSingleTextureEffect.cpp | 29 | ||||
-rw-r--r-- | src/gpu/effects/GrSingleTextureEffect.h | 28 |
9 files changed, 116 insertions, 52 deletions
diff --git a/src/gpu/effects/Gr1DKernelEffect.h b/src/gpu/effects/Gr1DKernelEffect.h index b6e116fa96..9ef765268c 100644 --- a/src/gpu/effects/Gr1DKernelEffect.h +++ b/src/gpu/effects/Gr1DKernelEffect.h @@ -8,7 +8,7 @@ #ifndef Gr1DKernelEffect_DEFINED #define Gr1DKernelEffect_DEFINED -#include "GrCustomStage.h" +#include "GrSingleTextureEffect.h" /** * Base class for 1D kernel effects. The kernel operates either in X or Y and @@ -18,7 +18,7 @@ * read. Since the center pixel is also read, the total width is one larger than * two times the radius. */ -class Gr1DKernelEffect : public GrCustomStage { +class Gr1DKernelEffect : public GrSingleTextureEffect { public: enum Direction { @@ -26,9 +26,11 @@ public: kY_Direction, }; - Gr1DKernelEffect(Direction direction, + Gr1DKernelEffect(GrTexture* texture, + Direction direction, int radius) - : fDirection(direction) + : GrSingleTextureEffect(texture) + , fDirection(direction) , fRadius(radius) {} virtual ~Gr1DKernelEffect() {}; @@ -44,7 +46,7 @@ private: Direction fDirection; int fRadius; - typedef GrCustomStage INHERITED; + typedef GrSingleTextureEffect INHERITED; }; #endif diff --git a/src/gpu/effects/GrConvolutionEffect.cpp b/src/gpu/effects/GrConvolutionEffect.cpp index 42dc2b49f1..4970d6270d 100644 --- a/src/gpu/effects/GrConvolutionEffect.cpp +++ b/src/gpu/effects/GrConvolutionEffect.cpp @@ -28,7 +28,6 @@ public: virtual void initUniforms(const GrGLInterface*, int programID) SK_OVERRIDE; virtual void setData(const GrGLInterface*, - const GrGLTexture&, const GrCustomStage&, int stageNum) SK_OVERRIDE; @@ -118,11 +117,11 @@ void GrGLConvolutionEffect::initUniforms(const GrGLInterface* gl, } void GrGLConvolutionEffect::setData(const GrGLInterface* gl, - const GrGLTexture& texture, const GrCustomStage& data, int stageNum) { const GrConvolutionEffect& conv = static_cast<const GrConvolutionEffect&>(data); + GrTexture& texture = *data.texture(0); // the code we generated was for a specific kernel radius GrAssert(conv.radius() == fRadius); float imageIncrement[2] = { 0 }; @@ -148,10 +147,11 @@ GrGLProgramStage::StageKey GrGLConvolutionEffect::GenKey( /////////////////////////////////////////////////////////////////////////////// -GrConvolutionEffect::GrConvolutionEffect(Direction direction, +GrConvolutionEffect::GrConvolutionEffect(GrTexture* texture, + Direction direction, int radius, const float* kernel) - : Gr1DKernelEffect(direction, radius) { + : Gr1DKernelEffect(texture, direction, radius) { GrAssert(radius <= kMaxKernelRadius); int width = this->width(); if (NULL != kernel) { @@ -171,9 +171,10 @@ const GrProgramStageFactory& GrConvolutionEffect::getFactory() const { bool GrConvolutionEffect::isEqual(const GrCustomStage& sBase) const { const GrConvolutionEffect& s = static_cast<const GrConvolutionEffect&>(sBase); - return (this->radius() == s.radius() && - this->direction() == s.direction() && - 0 == memcmp(fKernel, s.fKernel, this->width() * sizeof(float))); + return (INHERITED::isEqual(sBase) && + this->radius() == s.radius() && + this->direction() == s.direction() && + 0 == memcmp(fKernel, s.fKernel, this->width() * sizeof(float))); } void GrConvolutionEffect::setGaussianKernel(float sigma) { diff --git a/src/gpu/effects/GrConvolutionEffect.h b/src/gpu/effects/GrConvolutionEffect.h index fd6883b430..58cad83b53 100644 --- a/src/gpu/effects/GrConvolutionEffect.h +++ b/src/gpu/effects/GrConvolutionEffect.h @@ -21,7 +21,8 @@ class GrConvolutionEffect : public Gr1DKernelEffect { public: - GrConvolutionEffect(Direction, int halfWidth, const float* kernel = NULL); + GrConvolutionEffect(GrTexture*, Direction, + int halfWidth, const float* kernel = NULL); virtual ~GrConvolutionEffect(); void setKernel(const float* kernel) { diff --git a/src/gpu/effects/GrGradientEffects.cpp b/src/gpu/effects/GrGradientEffects.cpp index 604595692d..d4719b3a24 100644 --- a/src/gpu/effects/GrGradientEffects.cpp +++ b/src/gpu/effects/GrGradientEffects.cpp @@ -49,7 +49,8 @@ void GrGLRadialGradient::emitFS(GrGLShaderBuilder* state, ///////////////////////////////////////////////////////////////////// -GrRadialGradient::GrRadialGradient() { +GrRadialGradient::GrRadialGradient(GrTexture* texture) + : GrSingleTextureEffect(texture) { } @@ -63,7 +64,7 @@ const GrProgramStageFactory& GrRadialGradient::getFactory() const { } bool GrRadialGradient::isEqual(const GrCustomStage& sBase) const { - return true; + return INHERITED::isEqual(sBase); } ///////////////////////////////////////////////////////////////////// @@ -86,7 +87,6 @@ public: const char* samplerName) SK_OVERRIDE; virtual void initUniforms(const GrGLInterface*, int programID) SK_OVERRIDE; virtual void setData(const GrGLInterface*, - const GrGLTexture&, const GrCustomStage&, int stageNum) SK_OVERRIDE; @@ -257,7 +257,6 @@ void GrGLRadial2Gradient::initUniforms(const GrGLInterface* gl, int programID) { } void GrGLRadial2Gradient::setData(const GrGLInterface* gl, - const GrGLTexture& texture, const GrCustomStage& baseData, int stageNum) { const GrRadial2Gradient& data = @@ -296,10 +295,12 @@ void GrGLRadial2Gradient::setData(const GrGLInterface* gl, ///////////////////////////////////////////////////////////////////// -GrRadial2Gradient::GrRadial2Gradient(GrScalar center, +GrRadial2Gradient::GrRadial2Gradient(GrTexture* texture, + GrScalar center, GrScalar radius, bool posRoot) - : fCenterX1 (center) + : GrSingleTextureEffect(texture) + , fCenterX1 (center) , fRadius0 (radius) , fPosRoot (posRoot) { @@ -316,7 +317,8 @@ const GrProgramStageFactory& GrRadial2Gradient::getFactory() const { bool GrRadial2Gradient::isEqual(const GrCustomStage& sBase) const { const GrRadial2Gradient& s = static_cast<const GrRadial2Gradient&>(sBase); - return (this->fCenterX1 == s.fCenterX1 && + return (INHERITED::isEqual(sBase) && + this->fCenterX1 == s.fCenterX1 && this->fRadius0 == s.fRadius0 && this->fPosRoot == s.fPosRoot); } @@ -341,7 +343,6 @@ public: const char* samplerName) SK_OVERRIDE; virtual void initUniforms(const GrGLInterface*, int programID) SK_OVERRIDE; virtual void setData(const GrGLInterface*, - const GrGLTexture&, const GrCustomStage&, int stageNum) SK_OVERRIDE; @@ -571,7 +572,6 @@ void GrGLConical2Gradient::initUniforms(const GrGLInterface* gl, int programID) } void GrGLConical2Gradient::setData(const GrGLInterface* gl, - const GrGLTexture& texture, const GrCustomStage& baseData, int stageNum) { const GrConical2Gradient& data = @@ -612,10 +612,12 @@ void GrGLConical2Gradient::setData(const GrGLInterface* gl, ///////////////////////////////////////////////////////////////////// -GrConical2Gradient::GrConical2Gradient(GrScalar center, +GrConical2Gradient::GrConical2Gradient(GrTexture* texture, + GrScalar center, GrScalar radius, GrScalar diffRadius) - : fCenterX1 (center) + : GrSingleTextureEffect (texture) + , fCenterX1 (center) , fRadius0 (radius) , fDiffRadius (diffRadius) { @@ -632,7 +634,8 @@ const GrProgramStageFactory& GrConical2Gradient::getFactory() const { bool GrConical2Gradient::isEqual(const GrCustomStage& sBase) const { const GrConical2Gradient& s = static_cast<const GrConical2Gradient&>(sBase); - return (this->fCenterX1 == s.fCenterX1 && + return (INHERITED::isEqual(sBase) && + this->fCenterX1 == s.fCenterX1 && this->fRadius0 == s.fRadius0 && this->fDiffRadius == s.fDiffRadius); } @@ -677,7 +680,8 @@ void GrGLSweepGradient::emitFS(GrGLShaderBuilder* state, ///////////////////////////////////////////////////////////////////// -GrSweepGradient::GrSweepGradient() { +GrSweepGradient::GrSweepGradient(GrTexture* texture) + : GrSingleTextureEffect(texture) { } @@ -690,6 +694,6 @@ const GrProgramStageFactory& GrSweepGradient::getFactory() const { } bool GrSweepGradient::isEqual(const GrCustomStage& sBase) const { - return true; + return INHERITED::isEqual(sBase); } diff --git a/src/gpu/effects/GrGradientEffects.h b/src/gpu/effects/GrGradientEffects.h index cf6827f251..37e4642eab 100644 --- a/src/gpu/effects/GrGradientEffects.h +++ b/src/gpu/effects/GrGradientEffects.h @@ -8,7 +8,7 @@ #ifndef GrGradientEffects_DEFINED #define GrGradientEffects_DEFINED -#include "GrCustomStage.h" +#include "GrSingleTextureEffect.h" #include "GrTypes.h" #include "GrScalar.h" @@ -37,11 +37,11 @@ class GrGLRadialGradient; -class GrRadialGradient : public GrCustomStage { +class GrRadialGradient : public GrSingleTextureEffect { public: - GrRadialGradient(); + GrRadialGradient(GrTexture* texture); virtual ~GrRadialGradient(); static const char* Name() { return "Radial Gradient"; } @@ -52,24 +52,23 @@ public: private: - typedef GrCustomStage INHERITED; + typedef GrSingleTextureEffect INHERITED; }; class GrGLRadial2Gradient; -class GrRadial2Gradient : public GrCustomStage { +class GrRadial2Gradient : public GrSingleTextureEffect { public: - GrRadial2Gradient(GrScalar center, GrScalar radius, bool posRoot); + GrRadial2Gradient(GrTexture* texture, GrScalar center, GrScalar radius, bool posRoot); virtual ~GrRadial2Gradient(); static const char* Name() { return "Two-Point Radial Gradient"; } virtual const GrProgramStageFactory& getFactory() const SK_OVERRIDE; virtual bool isEqual(const GrCustomStage&) const SK_OVERRIDE; - // The radial gradient parameters can collapse to a linear (instead - // of quadratic) equation. + // The radial gradient parameters can collapse to a linear (instead of quadratic) equation. bool isDegenerate() const { return GR_Scalar1 == fCenterX1; } GrScalar center() const { return fCenterX1; } GrScalar radius() const { return fRadius0; } @@ -89,26 +88,24 @@ private: // @} - typedef GrCustomStage INHERITED; + typedef GrSingleTextureEffect INHERITED; }; class GrGLConical2Gradient; -class GrConical2Gradient : public GrCustomStage { +class GrConical2Gradient : public GrSingleTextureEffect { public: - GrConical2Gradient(GrScalar center, GrScalar radius, GrScalar diffRadius); + GrConical2Gradient(GrTexture* texture, GrScalar center, GrScalar radius, GrScalar diffRadius); virtual ~GrConical2Gradient(); static const char* Name() { return "Two-Point Conical Gradient"; } virtual const GrProgramStageFactory& getFactory() const SK_OVERRIDE; virtual bool isEqual(const GrCustomStage&) const SK_OVERRIDE; - // The radial gradient parameters can collapse to a linear (instead - // of quadratic) equation. - bool isDegenerate() const { return SkScalarAbs(fDiffRadius) == - SkScalarAbs(fCenterX1); } + // The radial gradient parameters can collapse to a linear (instead of quadratic) equation. + bool isDegenerate() const { return SkScalarAbs(fDiffRadius) == SkScalarAbs(fCenterX1); } GrScalar center() const { return fCenterX1; } GrScalar diffRadius() const { return fDiffRadius; } GrScalar radius() const { return fRadius0; } @@ -127,16 +124,16 @@ private: // @} - typedef GrCustomStage INHERITED; + typedef GrSingleTextureEffect INHERITED; }; class GrGLSweepGradient; -class GrSweepGradient : public GrCustomStage { +class GrSweepGradient : public GrSingleTextureEffect { public: - GrSweepGradient(); + GrSweepGradient(GrTexture* texture); virtual ~GrSweepGradient(); static const char* Name() { return "Sweep Gradient"; } @@ -147,7 +144,7 @@ public: protected: - typedef GrCustomStage INHERITED; + typedef GrSingleTextureEffect INHERITED; }; #endif diff --git a/src/gpu/effects/GrMorphologyEffect.cpp b/src/gpu/effects/GrMorphologyEffect.cpp index 43e870285f..3ea2cbd125 100644 --- a/src/gpu/effects/GrMorphologyEffect.cpp +++ b/src/gpu/effects/GrMorphologyEffect.cpp @@ -31,7 +31,6 @@ public: virtual void initUniforms(const GrGLInterface*, int programID) SK_OVERRIDE; virtual void setData(const GrGLInterface*, - const GrGLTexture&, const GrCustomStage&, int stageNum) SK_OVERRIDE; @@ -124,11 +123,12 @@ GrGLProgramStage::StageKey GrGLMorphologyEffect::GenKey( } void GrGLMorphologyEffect ::setData(const GrGLInterface* gl, - const GrGLTexture& texture, const GrCustomStage& data, int stageNum) { const Gr1DKernelEffect& kern = static_cast<const Gr1DKernelEffect&>(data); + GrGLTexture& texture = + *static_cast<GrGLTexture*>(data.texture(0)); // the code we generated was for a specific kernel radius GrAssert(kern.radius() == fRadius); float imageIncrement[2] = { 0 }; @@ -147,10 +147,11 @@ void GrGLMorphologyEffect ::setData(const GrGLInterface* gl, /////////////////////////////////////////////////////////////////////////////// -GrMorphologyEffect::GrMorphologyEffect(Direction direction, +GrMorphologyEffect::GrMorphologyEffect(GrTexture* texture, + Direction direction, int radius, MorphologyType type) - : Gr1DKernelEffect(direction, radius) + : Gr1DKernelEffect(texture, direction, radius) , fType(type) { } @@ -164,7 +165,8 @@ const GrProgramStageFactory& GrMorphologyEffect::getFactory() const { bool GrMorphologyEffect::isEqual(const GrCustomStage& sBase) const { const GrMorphologyEffect& s = static_cast<const GrMorphologyEffect&>(sBase); - return (this->radius() == s.radius() && + return (INHERITED::isEqual(sBase) && + this->radius() == s.radius() && this->direction() == s.direction() && this->type() == s.type()); } diff --git a/src/gpu/effects/GrMorphologyEffect.h b/src/gpu/effects/GrMorphologyEffect.h index c784460819..c8bd2d51db 100644 --- a/src/gpu/effects/GrMorphologyEffect.h +++ b/src/gpu/effects/GrMorphologyEffect.h @@ -25,7 +25,7 @@ public: typedef GrContext::MorphologyType MorphologyType; - GrMorphologyEffect(Direction, int radius, MorphologyType); + GrMorphologyEffect(GrTexture*, Direction, int radius, MorphologyType); virtual ~GrMorphologyEffect(); MorphologyType type() const { return fType; } diff --git a/src/gpu/effects/GrSingleTextureEffect.cpp b/src/gpu/effects/GrSingleTextureEffect.cpp new file mode 100644 index 0000000000..a373ebe4e1 --- /dev/null +++ b/src/gpu/effects/GrSingleTextureEffect.cpp @@ -0,0 +1,29 @@ +/* + * Copyright 2012 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "effects/GrSingleTextureEffect.h" +#include "GrTexture.h" + +GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture) + : fTexture (texture) { + SkSafeRef(fTexture); +} + +GrSingleTextureEffect::~GrSingleTextureEffect() { + SkSafeUnref(fTexture); +} + +unsigned int GrSingleTextureEffect::numTextures() const { + return 1; +} + +GrTexture* GrSingleTextureEffect::texture(unsigned int index) const { + GrAssert(0 == index); + return fTexture; +} + + diff --git a/src/gpu/effects/GrSingleTextureEffect.h b/src/gpu/effects/GrSingleTextureEffect.h new file mode 100644 index 0000000000..9a6bd1cae3 --- /dev/null +++ b/src/gpu/effects/GrSingleTextureEffect.h @@ -0,0 +1,28 @@ +/* + * 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 GrSingleTextureEffect_DEFINED +#define GrSingleTextureEffect_DEFINED + +#include "GrCustomStage.h" + +class GrSingleTextureEffect : public GrCustomStage { + +public: + GrSingleTextureEffect(GrTexture* texture); + virtual ~GrSingleTextureEffect(); + + virtual unsigned int numTextures() const SK_OVERRIDE; + virtual GrTexture* texture(unsigned int index) const SK_OVERRIDE; + +private: + GrTexture* fTexture; + + typedef GrCustomStage INHERITED; +}; + +#endif |