diff options
author | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-10-23 17:30:45 +0000 |
---|---|---|
committer | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-10-23 17:30:45 +0000 |
commit | 374e75956e7a56bbbd2da5509f9c4117512515d2 (patch) | |
tree | 530913490fa933364b30aeef8d5779c9405c7b65 /src | |
parent | 158618ec62c36b8261e195f04567e09ed76f6534 (diff) |
Combine the emit functions in GrGLProgramStage.
R=robertphillips@google.com
Review URL: https://codereview.appspot.com/6741064
git-svn-id: http://skia.googlecode.com/svn/trunk@6057 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r-- | src/effects/SkBlendImageFilter.cpp | 6 | ||||
-rw-r--r-- | src/effects/SkColorMatrixFilter.cpp | 6 | ||||
-rw-r--r-- | src/effects/SkLightingImageFilter.cpp | 6 | ||||
-rw-r--r-- | src/effects/SkMagnifierImageFilter.cpp | 6 | ||||
-rw-r--r-- | src/effects/SkMatrixConvolutionImageFilter.cpp | 6 | ||||
-rw-r--r-- | src/effects/SkMorphologyImageFilter.cpp | 6 | ||||
-rw-r--r-- | src/effects/SkTableColorFilter.cpp | 4 | ||||
-rw-r--r-- | src/effects/gradients/SkGradientShaderPriv.h | 4 | ||||
-rw-r--r-- | src/gpu/effects/GrConfigConversionEffect.cpp | 4 | ||||
-rw-r--r-- | src/gpu/effects/GrConvolutionEffect.cpp | 6 | ||||
-rw-r--r-- | src/gpu/effects/GrSingleTextureEffect.cpp | 4 | ||||
-rw-r--r-- | src/gpu/effects/GrTextureDomainEffect.cpp | 6 | ||||
-rw-r--r-- | src/gpu/gl/GrGLProgram.cpp | 11 | ||||
-rw-r--r-- | src/gpu/gl/GrGLProgramStage.cpp | 6 | ||||
-rw-r--r-- | src/gpu/gl/GrGLProgramStage.h | 101 |
15 files changed, 103 insertions, 79 deletions
diff --git a/src/effects/SkBlendImageFilter.cpp b/src/effects/SkBlendImageFilter.cpp index d14b5fc612..455ddcb72e 100644 --- a/src/effects/SkBlendImageFilter.cpp +++ b/src/effects/SkBlendImageFilter.cpp @@ -110,7 +110,7 @@ bool SkBlendImageFilter::onFilterImage(Proxy* proxy, /////////////////////////////////////////////////////////////////////////////// #if SK_SUPPORT_GPU -class GrGLBlendEffect : public GrGLProgramStage { +class GrGLBlendEffect : public GrGLLegacyProgramStage { public: GrGLBlendEffect(const GrProgramStageFactory& factory, const GrCustomStage& stage); @@ -127,7 +127,7 @@ public: static inline StageKey GenKey(const GrCustomStage& s, const GrGLCaps&); private: - typedef GrGLProgramStage INHERITED; + typedef GrGLLegacyProgramStage INHERITED; SkBlendImageFilter::Mode fMode; }; @@ -235,7 +235,7 @@ const GrProgramStageFactory& GrBlendEffect::getFactory() const { GrGLBlendEffect::GrGLBlendEffect(const GrProgramStageFactory& factory, const GrCustomStage& stage) - : GrGLProgramStage(factory), + : INHERITED(factory), fMode(static_cast<const GrBlendEffect&>(stage).mode()) { } diff --git a/src/effects/SkColorMatrixFilter.cpp b/src/effects/SkColorMatrixFilter.cpp index feb2d623f1..6af7dec8d5 100644 --- a/src/effects/SkColorMatrixFilter.cpp +++ b/src/effects/SkColorMatrixFilter.cpp @@ -339,14 +339,14 @@ public: GR_DECLARE_CUSTOM_STAGE_TEST; - class GLProgramStage : public GrGLProgramStage { + class GLProgramStage : public GrGLLegacyProgramStage { public: // this class always generates the same code. static StageKey GenKey(const GrCustomStage& s, const GrGLCaps&) { return 0; } GLProgramStage(const GrProgramStageFactory& factory, const GrCustomStage& stage) - : GrGLProgramStage(factory) + : INHERITED(factory) , fMatrixHandle(GrGLUniformManager::kInvalidUniformHandle) , fVectorHandle(GrGLUniformManager::kInvalidUniformHandle) { } @@ -408,6 +408,8 @@ public: private: SkColorMatrix fMatrix; + + typedef GrGLLegacyProgramStage INHERITED; }; GR_DEFINE_CUSTOM_STAGE_TEST(ColorMatrixEffect); diff --git a/src/effects/SkLightingImageFilter.cpp b/src/effects/SkLightingImageFilter.cpp index 07acde3f3e..6f089b0019 100644 --- a/src/effects/SkLightingImageFilter.cpp +++ b/src/effects/SkLightingImageFilter.cpp @@ -939,7 +939,7 @@ SkLight* create_random_light(SkRandom* random) { } -class GrGLLightingEffect : public GrGLProgramStage { +class GrGLLightingEffect : public GrGLLegacyProgramStage { public: GrGLLightingEffect(const GrProgramStageFactory& factory, const GrCustomStage& stage); @@ -960,7 +960,7 @@ public: virtual void setData(const GrGLUniformManager&, const GrCustomStage&) SK_OVERRIDE; private: - typedef GrGLProgramStage INHERITED; + typedef GrGLLegacyProgramStage INHERITED; UniformHandle fImageIncrementUni; UniformHandle fSurfaceScaleUni; @@ -1055,7 +1055,7 @@ GrCustomStage* GrDiffuseLightingEffect::TestCreate(SkRandom* random, GrGLLightingEffect::GrGLLightingEffect(const GrProgramStageFactory& factory, const GrCustomStage& stage) - : GrGLProgramStage(factory) + : INHERITED(factory) , fImageIncrementUni(kInvalidUniformHandle) , fSurfaceScaleUni(kInvalidUniformHandle) { const GrLightingEffect& m = static_cast<const GrLightingEffect&>(stage); diff --git a/src/effects/SkMagnifierImageFilter.cpp b/src/effects/SkMagnifierImageFilter.cpp index 3b7f9e3ac5..42d2b6b454 100644 --- a/src/effects/SkMagnifierImageFilter.cpp +++ b/src/effects/SkMagnifierImageFilter.cpp @@ -72,7 +72,7 @@ private: // For brevity typedef GrGLUniformManager::UniformHandle UniformHandle; -class GrGLMagnifierEffect : public GrGLProgramStage { +class GrGLMagnifierEffect : public GrGLLegacyProgramStage { public: GrGLMagnifierEffect(const GrProgramStageFactory& factory, const GrCustomStage& stage); @@ -96,12 +96,12 @@ private: UniformHandle fZoomVar; UniformHandle fInsetVar; - typedef GrGLProgramStage INHERITED; + typedef GrGLLegacyProgramStage INHERITED; }; GrGLMagnifierEffect::GrGLMagnifierEffect(const GrProgramStageFactory& factory, const GrCustomStage& stage) - : GrGLProgramStage(factory) + : INHERITED(factory) , fOffsetVar(GrGLUniformManager::kInvalidUniformHandle) , fZoomVar(GrGLUniformManager::kInvalidUniformHandle) , fInsetVar(GrGLUniformManager::kInvalidUniformHandle) { diff --git a/src/effects/SkMatrixConvolutionImageFilter.cpp b/src/effects/SkMatrixConvolutionImageFilter.cpp index e6067ea96a..ccc8859013 100644 --- a/src/effects/SkMatrixConvolutionImageFilter.cpp +++ b/src/effects/SkMatrixConvolutionImageFilter.cpp @@ -279,7 +279,7 @@ private: typedef GrSingleTextureEffect INHERITED; }; -class GrGLMatrixConvolutionEffect : public GrGLProgramStage { +class GrGLMatrixConvolutionEffect : public GrGLLegacyProgramStage { public: GrGLMatrixConvolutionEffect(const GrProgramStageFactory& factory, const GrCustomStage& stage); @@ -307,11 +307,13 @@ private: UniformHandle fTargetUni; UniformHandle fGainUni; UniformHandle fBiasUni; + + typedef GrGLLegacyProgramStage INHERITED; }; GrGLMatrixConvolutionEffect::GrGLMatrixConvolutionEffect(const GrProgramStageFactory& factory, const GrCustomStage& stage) - : GrGLProgramStage(factory) + : INHERITED(factory) , fKernelUni(GrGLUniformManager::kInvalidUniformHandle) , fImageIncrementUni(GrGLUniformManager::kInvalidUniformHandle) , fTargetUni(GrGLUniformManager::kInvalidUniformHandle) diff --git a/src/effects/SkMorphologyImageFilter.cpp b/src/effects/SkMorphologyImageFilter.cpp index 3c2c28450d..7d241cecf8 100644 --- a/src/effects/SkMorphologyImageFilter.cpp +++ b/src/effects/SkMorphologyImageFilter.cpp @@ -266,7 +266,7 @@ private: /////////////////////////////////////////////////////////////////////////////// -class GrGLMorphologyEffect : public GrGLProgramStage { +class GrGLMorphologyEffect : public GrGLLegacyProgramStage { public: GrGLMorphologyEffect (const GrProgramStageFactory& factory, const GrCustomStage& stage); @@ -290,12 +290,12 @@ private: GrMorphologyEffect::MorphologyType fType; GrGLUniformManager::UniformHandle fImageIncrementUni; - typedef GrGLProgramStage INHERITED; + typedef GrGLLegacyProgramStage INHERITED; }; GrGLMorphologyEffect::GrGLMorphologyEffect(const GrProgramStageFactory& factory, const GrCustomStage& stage) - : GrGLProgramStage(factory) + : INHERITED(factory) , fImageIncrementUni(GrGLUniformManager::kInvalidUniformHandle) { const GrMorphologyEffect& m = static_cast<const GrMorphologyEffect&>(stage); fRadius = m.radius(); diff --git a/src/effects/SkTableColorFilter.cpp b/src/effects/SkTableColorFilter.cpp index 6066e684f9..7d8fbf81ae 100644 --- a/src/effects/SkTableColorFilter.cpp +++ b/src/effects/SkTableColorFilter.cpp @@ -244,7 +244,7 @@ private: typedef GrCustomStage INHERITED; }; -class GLColorTableEffect : public GrGLProgramStage { +class GLColorTableEffect : public GrGLLegacyProgramStage { public: GLColorTableEffect(const GrProgramStageFactory& factory, const GrCustomStage& stage); @@ -263,7 +263,7 @@ public: private: - typedef GrGLProgramStage INHERITED; + typedef GrGLLegacyProgramStage INHERITED; }; GLColorTableEffect::GLColorTableEffect( diff --git a/src/effects/gradients/SkGradientShaderPriv.h b/src/effects/gradients/SkGradientShaderPriv.h index 8c0bae9c97..28571d2f0b 100644 --- a/src/effects/gradients/SkGradientShaderPriv.h +++ b/src/effects/gradients/SkGradientShaderPriv.h @@ -271,7 +271,7 @@ private: /////////////////////////////////////////////////////////////////////////////// // Base class for GL gradient custom stages -class GrGLGradientStage : public GrGLProgramStage { +class GrGLGradientStage : public GrGLLegacyProgramStage { public: GrGLGradientStage(const GrProgramStageFactory& factory); @@ -293,7 +293,7 @@ private: GrScalar fCachedYCoord; GrGLUniformManager::UniformHandle fFSYUni; - typedef GrGLProgramStage INHERITED; + typedef GrGLLegacyProgramStage INHERITED; }; #endif diff --git a/src/gpu/effects/GrConfigConversionEffect.cpp b/src/gpu/effects/GrConfigConversionEffect.cpp index b9c9f63ae3..9d6435060d 100644 --- a/src/gpu/effects/GrConfigConversionEffect.cpp +++ b/src/gpu/effects/GrConfigConversionEffect.cpp @@ -8,7 +8,7 @@ #include "GrConfigConversionEffect.h" #include "gl/GrGLProgramStage.h" -class GrGLConfigConversionEffect : public GrGLProgramStage { +class GrGLConfigConversionEffect : public GrGLLegacyProgramStage { public: GrGLConfigConversionEffect(const GrProgramStageFactory& factory, const GrCustomStage& s) : INHERITED (factory) { @@ -67,7 +67,7 @@ private: bool fSwapRedAndBlue; GrConfigConversionEffect::PMConversion fPMConversion; - typedef GrGLProgramStage INHERITED; + typedef GrGLLegacyProgramStage INHERITED; }; diff --git a/src/gpu/effects/GrConvolutionEffect.cpp b/src/gpu/effects/GrConvolutionEffect.cpp index d7750826b9..726c2c39a7 100644 --- a/src/gpu/effects/GrConvolutionEffect.cpp +++ b/src/gpu/effects/GrConvolutionEffect.cpp @@ -15,7 +15,7 @@ typedef GrGLUniformManager::UniformHandle UniformHandle; static const UniformHandle kInvalidUniformHandle = GrGLUniformManager::kInvalidUniformHandle; -class GrGLConvolutionEffect : public GrGLProgramStage { +class GrGLConvolutionEffect : public GrGLLegacyProgramStage { public: GrGLConvolutionEffect(const GrProgramStageFactory& factory, const GrCustomStage& stage); @@ -39,12 +39,12 @@ private: UniformHandle fKernelUni; UniformHandle fImageIncrementUni; - typedef GrGLProgramStage INHERITED; + typedef GrGLLegacyProgramStage INHERITED; }; GrGLConvolutionEffect::GrGLConvolutionEffect(const GrProgramStageFactory& factory, const GrCustomStage& stage) - : GrGLProgramStage(factory) + : INHERITED(factory) , fKernelUni(kInvalidUniformHandle) , fImageIncrementUni(kInvalidUniformHandle) { const GrConvolutionEffect& c = diff --git a/src/gpu/effects/GrSingleTextureEffect.cpp b/src/gpu/effects/GrSingleTextureEffect.cpp index f6f7b8c5bd..51d302592c 100644 --- a/src/gpu/effects/GrSingleTextureEffect.cpp +++ b/src/gpu/effects/GrSingleTextureEffect.cpp @@ -12,7 +12,7 @@ #include "GrProgramStageFactory.h" #include "GrTexture.h" -class GrGLSingleTextureEffect : public GrGLProgramStage { +class GrGLSingleTextureEffect : public GrGLLegacyProgramStage { public: GrGLSingleTextureEffect(const GrProgramStageFactory& factory, const GrCustomStage& stage) : INHERITED (factory) { } @@ -32,7 +32,7 @@ public: private: - typedef GrGLProgramStage INHERITED; + typedef GrGLLegacyProgramStage INHERITED; }; /////////////////////////////////////////////////////////////////////////////// diff --git a/src/gpu/effects/GrTextureDomainEffect.cpp b/src/gpu/effects/GrTextureDomainEffect.cpp index 219a752ab2..f40604156a 100644 --- a/src/gpu/effects/GrTextureDomainEffect.cpp +++ b/src/gpu/effects/GrTextureDomainEffect.cpp @@ -9,7 +9,7 @@ #include "gl/GrGLProgramStage.h" #include "GrProgramStageFactory.h" -class GrGLTextureDomainEffect : public GrGLProgramStage { +class GrGLTextureDomainEffect : public GrGLLegacyProgramStage { public: GrGLTextureDomainEffect(const GrProgramStageFactory& factory, const GrCustomStage& stage); @@ -29,12 +29,12 @@ public: private: GrGLUniformManager::UniformHandle fNameUni; - typedef GrGLProgramStage INHERITED; + typedef GrGLLegacyProgramStage INHERITED; }; GrGLTextureDomainEffect::GrGLTextureDomainEffect(const GrProgramStageFactory& factory, const GrCustomStage& stage) - : GrGLProgramStage(factory) + : INHERITED(factory) , fNameUni(GrGLUniformManager::kInvalidUniformHandle) { } diff --git a/src/gpu/gl/GrGLProgram.cpp b/src/gpu/gl/GrGLProgram.cpp index aca42f7c0b..bc17ebf8ea 100644 --- a/src/gpu/gl/GrGLProgram.cpp +++ b/src/gpu/gl/GrGLProgram.cpp @@ -932,9 +932,6 @@ GrGLProgramStage* GrGLProgram::GenStageCode(const GrCustomStage* stage, &varyingFSName); builder->setupTextureAccess(varyingFSName, texCoordVaryingType); - // Must setup variables after calling setupTextureAccess - glStage->setupVariables(builder); - int numTextures = stage->numTextures(); SkSTArray<8, GrGLShaderBuilder::TextureSampler> textureSamplers; @@ -955,13 +952,11 @@ GrGLProgramStage* GrGLProgram::GenStageCode(const GrCustomStage* stage, vector_all_coords(GrSLTypeToVecLength(texCoordVaryingType))); } - builder->fVSCode.appendf("\t{ // %s\n", glStage->name()); - glStage->emitVS(builder, varyingVSName); - builder->fVSCode.appendf("\t}\n"); - // Enclose custom code in a block to avoid namespace conflicts + builder->fVSCode.appendf("\t{ // %s\n", glStage->name()); builder->fFSCode.appendf("\t{ // %s \n", glStage->name()); - glStage->emitFS(builder, fsOutColor, fsInColor, textureSamplers); + glStage->emitCode(builder, varyingVSName, fsOutColor, fsInColor, textureSamplers); + builder->fVSCode.appendf("\t}\n"); builder->fFSCode.appendf("\t}\n"); return glStage; diff --git a/src/gpu/gl/GrGLProgramStage.cpp b/src/gpu/gl/GrGLProgramStage.cpp index 8a70608004..06a6f6db52 100644 --- a/src/gpu/gl/GrGLProgramStage.cpp +++ b/src/gpu/gl/GrGLProgramStage.cpp @@ -17,11 +17,7 @@ GrGLProgramStage::~GrGLProgramStage() { /////////////////////////////////////////////////////////////////////////////// -void GrGLProgramStage::setupVariables(GrGLShaderBuilder*) { - -} - -void GrGLProgramStage::setData(const GrGLUniformManager&, const GrCustomStage&) { +void GrGLProgramStage::setData(const GrGLUniformManager&, const GrCustomStage&) { } GrGLProgramStage::StageKey GrGLProgramStage::GenTextureKey(const GrCustomStage& stage, diff --git a/src/gpu/gl/GrGLProgramStage.h b/src/gpu/gl/GrGLProgramStage.h index 2cb5ae5542..d835c0bb6b 100644 --- a/src/gpu/gl/GrGLProgramStage.h +++ b/src/gpu/gl/GrGLProgramStage.h @@ -19,12 +19,15 @@ struct GrGLInterface; class GrGLTexture; /** @file - This file contains specializations for OpenGL of the shader stages - declared in src/gpu/GrCustomStage.h. All the functions emit - GLSL shader code and OpenGL calls. - - These objects are created by a factory function on the - GrCustomStage. + This file contains specializations for OpenGL of the shader stages declared in + include/gpu/GrCustomStage.h. Objects of type GrGLProgramStage are responsible for emitting the + GLSL code that implements a GrCustomStage and for uploading uniforms at draw time. They also + must have a function: + static inline StageKey GenKey(const GrCustomStage&, const GrGLCaps&) + that is used to implement a program cache. When two GrCustomStages produce the same key this + means that their GrGLProgramStages would emit the same GLSL code. + + These objects are created by the factory object returned by the GrCustomStage::getFactory(). */ class GrGLProgramStage { @@ -42,37 +45,35 @@ public: virtual ~GrGLProgramStage(); - /** Create any uniforms or varyings the vertex shader requires. */ - virtual void setupVariables(GrGLShaderBuilder* builder); - - /** Appends vertex code to the appropriate SkString - on the state. - The code will be inside an otherwise-empty block. - Vertex shader input is a vec2 of coordinates, which may - be altered. - The code will be inside an otherwise-empty block. */ - virtual void emitVS(GrGLShaderBuilder* builder, - const char* vertexCoords) = 0; - - /** Appends fragment code to the appropriate SkString - on the state. - The code will be inside an otherwise-empty block. - Fragment shader inputs are a vec2 of coordinates, one texture, - and a color; output is a color. The input color may be NULL which - indicates that the input color is solid white. TODO: Better system - for communicating optimization info (e.g. input color is solid white, - trans black, known to be opaque, etc.) that allows the custom stage - to communicate back similar known info about its output. + /** Called when the program stage should insert its code into the shaders. The code in each + shader will be in its own block ({}) and so locally scoped names will not collide across + stages. + + @param builder Interface used to emit code in the shaders. + @param vertexCoords A vec2 of texture coordinates in the VS, which may be altered. This will + be removed soon and stages will be responsible for computing their own + coords. + @param outputColor A predefined vec4 in the FS in which the stage should place its output + color (or coverage). + @param inputColor A vec4 that holds the input color to the stage in the FS. This may be + NULL in which case the implied input is solid white (all ones). + TODO: Better system for communicating optimization info (e.g. input + color is solid white, trans black, known to be opaque, etc.) that allows + the custom stage to communicate back similar known info about its + output. + @param samplers One entry for each GrTextureAccess of the GrCustomStage that generated + the GrGLProgramStage. These can be passed to the builder to emit texture + reads in the generated code. */ - virtual void emitFS(GrGLShaderBuilder* builder, - const char* outputColor, - const char* inputColor, - const TextureSamplerArray&) = 0; - - /** A GrGLCustomStage instance can be reused with any GrCustomStage - that produces the same stage key; this function reads data from - a stage and uploads any uniform variables required by the shaders - created in emit*(). */ + virtual void emitCode(GrGLShaderBuilder* builder, + const char* vertexCoords, + const char* outputColor, + const char* inputColor, + const TextureSamplerArray& samplers) = 0; + + /** A GrGLProgramStage instance can be reused with any GrCustomStage that produces the same + stage key; this function reads data from a stage and uploads any uniform variables required + by the shaders created in emitCode(). */ virtual void setData(const GrGLUniformManager&, const GrCustomStage& stage); const char* name() const { return fFactory.name(); } @@ -84,4 +85,32 @@ protected: const GrProgramStageFactory& fFactory; }; +/** + * This allows program stages that implemented an older set of virtual functions on GrGLProgramStage + * to continue to work by change their parent class to this class. New program stages should not use + * this interface. It will be removed once older stages are modified to implement emitCode(). + */ +class GrGLLegacyProgramStage : public GrGLProgramStage { +public: + GrGLLegacyProgramStage(const GrProgramStageFactory& factory) : GrGLProgramStage(factory) {} + + virtual void setupVariables(GrGLShaderBuilder* builder) {}; + virtual void emitVS(GrGLShaderBuilder* builder, + const char* vertexCoords) = 0; + virtual void emitFS(GrGLShaderBuilder* builder, + const char* outputColor, + const char* inputColor, + const TextureSamplerArray&) = 0; + + virtual void emitCode(GrGLShaderBuilder* builder, + const char* vertexCoords, + const char* outputColor, + const char* inputColor, + const TextureSamplerArray& samplers) { + this->setupVariables(builder); + this->emitVS(builder, vertexCoords); + this->emitFS(builder, outputColor, inputColor, samplers); + } +}; + #endif |