Make GrGLConvolutionEffect, GrGLMorphologyEffect, and GrGLMagnifierEffect derive...
authorbsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 29 Oct 2012 12:47:51 +0000 (12:47 +0000)
committerbsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 29 Oct 2012 12:47:51 +0000 (12:47 +0000)
R=robertphillips@google.com
Review URL: https://codereview.appspot.com/6786052

git-svn-id: http://skia.googlecode.com/svn/branches/gpu_dev@6164 2bbb7eff-a529-9590-31e7-b0007b416f81

src/effects/SkMagnifierImageFilter.cpp
src/effects/SkMorphologyImageFilter.cpp
src/gpu/effects/GrConvolutionEffect.cpp

index 61a31ae..524a4bb 100644 (file)
@@ -72,18 +72,18 @@ private:
 // For brevity
 typedef GrGLUniformManager::UniformHandle UniformHandle;
 
-class GrGLMagnifierEffect : public GrGLLegacyEffect {
+class GrGLMagnifierEffect : public GrGLEffect {
 public:
     GrGLMagnifierEffect(const GrBackendEffectFactory& factory,
                         const GrEffect& effect);
 
-    virtual void setupVariables(GrGLShaderBuilder* state) SK_OVERRIDE;
-    virtual void emitVS(GrGLShaderBuilder* state,
-                        const char* vertexCoords) SK_OVERRIDE;
-    virtual void emitFS(GrGLShaderBuilder* state,
-                        const char* outputColor,
-                        const char* inputColor,
-                        const TextureSamplerArray&) SK_OVERRIDE;
+    virtual void emitCode(GrGLShaderBuilder*,
+                          const GrEffect&,
+                          EffectKey,
+                          const char* vertexCoords,
+                          const char* outputColor,
+                          const char* inputColor,
+                          const TextureSamplerArray&) SK_OVERRIDE;
 
     virtual void setData(const GrGLUniformManager& uman, const GrEffectStage& stage) SK_OVERRIDE;
 
@@ -95,7 +95,7 @@ private:
     UniformHandle  fZoomVar;
     UniformHandle  fInsetVar;
 
-    typedef GrGLLegacyEffect INHERITED;
+    typedef GrGLEffect INHERITED;
 };
 
 GrGLMagnifierEffect::GrGLMagnifierEffect(const GrBackendEffectFactory& factory,
@@ -106,41 +106,37 @@ GrGLMagnifierEffect::GrGLMagnifierEffect(const GrBackendEffectFactory& factory,
     , fInsetVar(GrGLUniformManager::kInvalidUniformHandle) {
 }
 
-void GrGLMagnifierEffect::setupVariables(GrGLShaderBuilder* state) {
-    fOffsetVar = state->addUniform(
+void GrGLMagnifierEffect::emitCode(GrGLShaderBuilder* builder,
+                                   const GrEffect&,
+                                   EffectKey,
+                                   const char* vertexCoords,
+                                   const char* outputColor,
+                                   const char* inputColor,
+                                   const TextureSamplerArray& samplers) {
+    fOffsetVar = builder->addUniform(
         GrGLShaderBuilder::kFragment_ShaderType |
         GrGLShaderBuilder::kVertex_ShaderType,
         kVec2f_GrSLType, "uOffset");
-    fZoomVar = state->addUniform(
+    fZoomVar = builder->addUniform(
         GrGLShaderBuilder::kFragment_ShaderType |
         GrGLShaderBuilder::kVertex_ShaderType,
         kVec2f_GrSLType, "uZoom");
-    fInsetVar = state->addUniform(
+    fInsetVar = builder->addUniform(
         GrGLShaderBuilder::kFragment_ShaderType |
         GrGLShaderBuilder::kVertex_ShaderType,
         kVec2f_GrSLType, "uInset");
-}
-
-void GrGLMagnifierEffect::emitVS(GrGLShaderBuilder* state,
-                                 const char* vertexCoords) {
-}
 
-void GrGLMagnifierEffect::emitFS(GrGLShaderBuilder* state,
-                                 const char* outputColor,
-                                 const char* inputColor,
-                                 const TextureSamplerArray& samplers) {
-    SkString* code = &state->fFSCode;
+    SkString* code = &builder->fFSCode;
 
-    code->appendf("\t\tvec2 coord = %s;\n", state->defaultTexCoordsName());
+    code->appendf("\t\tvec2 coord = %s;\n", builder->defaultTexCoordsName());
     code->appendf("\t\tvec2 zoom_coord = %s + %s / %s;\n",
-                  state->getUniformCStr(fOffsetVar),
-                  state->defaultTexCoordsName(),
-                  state->getUniformCStr(fZoomVar));
+                  builder->getUniformCStr(fOffsetVar),
+                  builder->defaultTexCoordsName(),
+                  builder->getUniformCStr(fZoomVar));
 
     code->appendf("\t\tvec2 delta = min(coord, vec2(1.0, 1.0) - coord);\n");
 
-    code->appendf(
-        "\t\tdelta = delta / %s;\n", state->getUniformCStr(fInsetVar));
+    code->appendf("\t\tdelta = delta / %s;\n", builder->getUniformCStr(fInsetVar));
 
     code->appendf("\t\tfloat weight = 0.0;\n");
     code->appendf("\t\tif (delta.s < 2.0 && delta.t < 2.0) {\n");
@@ -150,13 +146,12 @@ void GrGLMagnifierEffect::emitFS(GrGLShaderBuilder* state,
     code->appendf("\t\t\tweight = min(dist * dist, 1.0);\n");
     code->appendf("\t\t} else {\n");
     code->appendf("\t\t\tvec2 delta_squared = delta * delta;\n");
-    code->appendf(
-        "\t\t\tweight = min(min(delta_squared.s, delta_squared.y), 1.0);\n");
+    code->appendf("\t\t\tweight = min(min(delta_squared.s, delta_squared.y), 1.0);\n");
     code->appendf("\t\t}\n");
 
     code->appendf("\t\tvec2 mix_coord = mix(coord, zoom_coord, weight);\n");
     code->appendf("\t\tvec4 output_color = ");
-    state->appendTextureLookup(code, samplers[0], "mix_coord");
+    builder->appendTextureLookup(code, samplers[0], "mix_coord");
     code->append(";\n");
 
     code->appendf("\t\t%s = output_color;", outputColor);
index 9fa46e2..6b09914 100644 (file)
@@ -266,18 +266,18 @@ private:
 
 ///////////////////////////////////////////////////////////////////////////////
 
-class GrGLMorphologyEffect  : public GrGLLegacyEffect {
+class GrGLMorphologyEffect  : public GrGLEffect {
 public:
     GrGLMorphologyEffect (const GrBackendEffectFactory& factory,
                           const GrEffect& effect);
 
-    virtual void setupVariables(GrGLShaderBuilder* builder) SK_OVERRIDE;
-    virtual void emitVS(GrGLShaderBuilder* state,
-                        const char* vertexCoords) SK_OVERRIDE {};
-    virtual void emitFS(GrGLShaderBuilder* state,
-                        const char* outputColor,
-                        const char* inputColor,
-                        const TextureSamplerArray&) SK_OVERRIDE;
+    virtual void emitCode(GrGLShaderBuilder*,
+                          const GrEffect&,
+                          EffectKey,
+                          const char* vertexCoords,
+                          const char* outputColor,
+                          const char* inputColor,
+                          const TextureSamplerArray&) SK_OVERRIDE;
 
     static inline EffectKey GenKey(const GrEffect& s, const GrGLCaps& caps);
 
@@ -290,7 +290,7 @@ private:
     GrMorphologyEffect::MorphologyType  fType;
     GrGLUniformManager::UniformHandle   fImageIncrementUni;
 
-    typedef GrGLLegacyEffect INHERITED;
+    typedef GrGLEffect INHERITED;
 };
 
 GrGLMorphologyEffect::GrGLMorphologyEffect(const GrBackendEffectFactory& factory,
@@ -302,15 +302,16 @@ GrGLMorphologyEffect::GrGLMorphologyEffect(const GrBackendEffectFactory& factory
     fType = m.type();
 }
 
-void GrGLMorphologyEffect::setupVariables(GrGLShaderBuilder* builder) {
+void GrGLMorphologyEffect::emitCode(GrGLShaderBuilder* builder,
+                                    const GrEffect&,
+                                    EffectKey,
+                                    const char* vertexCoords,
+                                    const char* outputColor,
+                                    const char* inputColor,
+                                    const TextureSamplerArray& samplers) {
     fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
                                              kVec2f_GrSLType, "ImageIncrement");
-}
 
-void GrGLMorphologyEffect::emitFS(GrGLShaderBuilder* builder,
-                                  const char* outputColor,
-                                  const char* inputColor,
-                                  const TextureSamplerArray& samplers) {
     SkString* code = &builder->fFSCode;
 
     const char* func;
index 51275a4..5e0c7f6 100644 (file)
 typedef GrGLUniformManager::UniformHandle UniformHandle;
 static const UniformHandle kInvalidUniformHandle = GrGLUniformManager::kInvalidUniformHandle;
 
-class GrGLConvolutionEffect : public GrGLLegacyEffect {
+class GrGLConvolutionEffect : public GrGLEffect {
 public:
     GrGLConvolutionEffect(const GrBackendEffectFactory&, const GrEffect&);
 
-    virtual void setupVariables(GrGLShaderBuilder* builder) SK_OVERRIDE;
-    virtual void emitVS(GrGLShaderBuilder* builder,
-                        const char* vertexCoords) SK_OVERRIDE {};
-    virtual void emitFS(GrGLShaderBuilder* builder,
-                        const char* outputColor,
-                        const char* inputColor,
-                        const TextureSamplerArray&) SK_OVERRIDE;
+    virtual void emitCode(GrGLShaderBuilder*,
+                          const GrEffect&,
+                          EffectKey,
+                          const char* vertexCoords,
+                          const char* outputColor,
+                          const char* inputColor,
+                          const TextureSamplerArray&) SK_OVERRIDE;
 
     virtual void setData(const GrGLUniformManager& uman, const GrEffectStage&) SK_OVERRIDE;
 
@@ -38,7 +38,7 @@ private:
     UniformHandle   fKernelUni;
     UniformHandle   fImageIncrementUni;
 
-    typedef GrGLLegacyEffect INHERITED;
+    typedef GrGLEffect INHERITED;
 };
 
 GrGLConvolutionEffect::GrGLConvolutionEffect(const GrBackendEffectFactory& factory,
@@ -51,17 +51,17 @@ GrGLConvolutionEffect::GrGLConvolutionEffect(const GrBackendEffectFactory& facto
     fRadius = c.radius();
 }
 
-void GrGLConvolutionEffect::setupVariables(GrGLShaderBuilder* builder) {
+void GrGLConvolutionEffect::emitCode(GrGLShaderBuilder* builder,
+                                     const GrEffect&,
+                                     EffectKey,
+                                     const char* vertexCoords,
+                                     const char* outputColor,
+                                     const char* inputColor,
+                                     const TextureSamplerArray& samplers) {
     fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
                                              kVec2f_GrSLType, "ImageIncrement");
     fKernelUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_ShaderType,
                                           kFloat_GrSLType, "Kernel", this->width());
-}
-
-void GrGLConvolutionEffect::emitFS(GrGLShaderBuilder* builder,
-                                   const char* outputColor,
-                                   const char* inputColor,
-                                   const TextureSamplerArray& samplers) {
     SkString* code = &builder->fFSCode;
 
     code->appendf("\t\t%s = vec4(0, 0, 0, 0);\n", outputColor);