Split GrFragmentProcessor into its own header
Review URL: https://codereview.chromium.org/660573002
diff --git a/gyp/gpu.gypi b/gyp/gpu.gypi
index a853cf5..11a6d74 100644
--- a/gyp/gpu.gypi
+++ b/gyp/gpu.gypi
@@ -17,6 +17,7 @@
'<(skia_include_path)/gpu/GrContextFactory.h',
'<(skia_include_path)/gpu/GrCoordTransform.h',
'<(skia_include_path)/gpu/GrFontScaler.h',
+ '<(skia_include_path)/gpu/GrFragmentProcessor.h',
'<(skia_include_path)/gpu/GrGlyph.h',
'<(skia_include_path)/gpu/GrGpuResource.h',
'<(skia_include_path)/gpu/GrPaint.h',
diff --git a/include/gpu/GrFragmentProcessor.h b/include/gpu/GrFragmentProcessor.h
new file mode 100644
index 0000000..28778fd
--- /dev/null
+++ b/include/gpu/GrFragmentProcessor.h
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef GrFragmentProcessor_DEFINED
+#define GrFragmentProcessor_DEFINED
+
+#include "GrProcessor.h"
+
+class GrCoordTransform;
+
+/** Provides custom fragment shader code. Fragment processors receive an input color (vec4f) and
+ produce an output color. They may reference textures and uniforms. They may use
+ GrCoordTransforms to receive a transformation of the local coordinates that map from local space
+ to the fragment being processed.
+ */
+class GrFragmentProcessor : public GrProcessor {
+public:
+ GrFragmentProcessor()
+ : INHERITED()
+ , fWillReadDstColor(false)
+ , fWillUseInputColor(true) {}
+
+ virtual const GrBackendFragmentProcessorFactory& getFactory() const = 0;
+
+ int numTransforms() const { return fCoordTransforms.count(); }
+
+ /** Returns the coordinate transformation at index. index must be valid according to
+ numTransforms(). */
+ const GrCoordTransform& coordTransform(int index) const { return *fCoordTransforms[index]; }
+
+ /** Will this prceossor read the destination pixel value? */
+ bool willReadDstColor() const { return fWillReadDstColor; }
+
+ /** Will this prceossor read the source color value? */
+ bool willUseInputColor() const { return fWillUseInputColor; }
+
+ /** Returns true if this and other prceossor conservatively draw identically. It can only return
+ true when the two prceossor are of the same subclass (i.e. they return the same object from
+ from getFactory()).
+
+ A return value of true from isEqual() should not be used to test whether the prceossor would
+ generate the same shader code. To test for identical code generation use the prceossor' keys
+ computed by the GrBackendProcessorFactory. */
+ bool isEqual(const GrFragmentProcessor& other) const {
+ if (&this->getFactory() != &other.getFactory()) {
+ return false;
+ }
+ bool result = this->onIsEqual(other);
+#ifdef SK_DEBUG
+ if (result) {
+ this->assertTexturesEqual(other);
+ }
+#endif
+ return result;
+ }
+
+protected:
+ /**
+ * Fragment Processor subclasses call this from their constructor to register coordinate
+ * transformations. The processor subclass manages the lifetime of the transformations (this
+ * function only stores a pointer). The GrCoordTransform is typically a member field of the
+ * GrProcessor subclass. When the matrix has perspective, the transformed coordinates will have
+ * 3 components. Otherwise they'll have 2. This must only be called from the constructor because
+ * GrProcessors are immutable.
+ */
+ void addCoordTransform(const GrCoordTransform*);
+
+ /**
+ * If the prceossor subclass will read the destination pixel value then it must call this function
+ * from its constructor. Otherwise, when its generated backend-specific prceossor class attempts
+ * to generate code that reads the destination pixel it will fail.
+ */
+ void setWillReadDstColor() { fWillReadDstColor = true; }
+
+ /**
+ * If the prceossor will generate a result that does not depend on the input color value then it
+ * must call this function from its constructor. Otherwise, when its generated backend-specific
+ * code might fail during variable binding due to unused variables.
+ */
+ void setWillNotUseInputColor() { fWillUseInputColor = false; }
+
+private:
+ /** Subclass implements this to support isEqual(). It will only be called if it is known that
+ the two prceossor are of the same subclass (i.e. they return the same object from
+ getFactory()).*/
+ virtual bool onIsEqual(const GrFragmentProcessor& other) const = 0;
+
+ SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms;
+ bool fWillReadDstColor;
+ bool fWillUseInputColor;
+
+ typedef GrProcessor INHERITED;
+};
+
+/**
+ * This creates an effect outside of the effect memory pool. The effect's destructor will be called
+ * at global destruction time. NAME will be the name of the created GrProcessor.
+ */
+#define GR_CREATE_STATIC_FRAGMENT_PROCESSOR(NAME, FP_CLASS, ARGS) \
+static SkAlignedSStorage<sizeof(FP_CLASS)> g_##NAME##_Storage; \
+static GrFragmentProcessor* NAME SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), FP_CLASS, ARGS); \
+static SkAutoTDestroy<GrFragmentProcessor> NAME##_ad(NAME);
+
+#endif
diff --git a/include/gpu/GrGeometryProcessor.h b/include/gpu/GrGeometryProcessor.h
index fe7905a..5b509ca 100644
--- a/include/gpu/GrGeometryProcessor.h
+++ b/include/gpu/GrGeometryProcessor.h
@@ -9,7 +9,7 @@
#define GrGeometryProcessor_DEFINED
#include "GrProcessor.h"
-class GrBackendGeometryProcessorFactory;
+#include "GrShaderVar.h"
/**
* A GrGeomteryProcessor is used to perform computation in the vertex shader and
@@ -37,6 +37,12 @@
const VertexAttribArray& getVertexAttribs() const { return fVertexAttribs; }
+ /** Returns true if this and other effect conservatively draw identically. It can only return
+ true when the two effects are of the same subclass (i.e. they return the same object from
+ from getFactory()).
+ A return value of true from isEqual() should not be used to test whether the effects would
+ generate the same shader code. To test for identical code generation use the effects' keys
+ computed by the GrBackendEffectFactory. */
bool isEqual(const GrGeometryProcessor& that) const {
if (&this->getFactory() != &that.getFactory()) {
return false;
diff --git a/include/gpu/GrProcessor.h b/include/gpu/GrProcessor.h
index 7991a06..b41f94d 100644
--- a/include/gpu/GrProcessor.h
+++ b/include/gpu/GrProcessor.h
@@ -12,12 +12,8 @@
#include "GrColor.h"
#include "GrProcessorUnitTest.h"
#include "GrProgramElement.h"
-#include "GrShaderVar.h"
#include "GrTextureAccess.h"
-#include "GrTypesPriv.h"
-#include "SkString.h"
-class GrBackendProcessorFactory;
class GrContext;
class GrCoordTransform;
@@ -240,93 +236,4 @@
typedef GrProgramElement INHERITED;
};
-class GrFragmentProcessor : public GrProcessor {
-public:
- GrFragmentProcessor()
- : INHERITED()
- , fWillReadDstColor(false)
- , fWillUseInputColor(true) {}
-
- virtual const GrBackendFragmentProcessorFactory& getFactory() const = 0;
-
- int numTransforms() const { return fCoordTransforms.count(); }
-
- /** Returns the coordinate transformation at index. index must be valid according to
- numTransforms(). */
- const GrCoordTransform& coordTransform(int index) const { return *fCoordTransforms[index]; }
-
- /** Will this effect read the destination pixel value? */
- bool willReadDstColor() const { return fWillReadDstColor; }
-
- /** Will this effect read the source color value? */
- bool willUseInputColor() const { return fWillUseInputColor; }
-
- /** Returns true if this and other effect conservatively draw identically. It can only return
- true when the two effects are of the same subclass (i.e. they return the same object from
- from getFactory()).
-
- A return value of true from isEqual() should not be used to test whether the effects would
- generate the same shader code. To test for identical code generation use the effects' keys
- computed by the GrBackendEffectFactory. */
- bool isEqual(const GrFragmentProcessor& other) const {
- if (&this->getFactory() != &other.getFactory()) {
- return false;
- }
- bool result = this->onIsEqual(other);
-#ifdef SK_DEBUG
- if (result) {
- this->assertTexturesEqual(other);
- }
-#endif
- return result;
- }
-
-protected:
- /**
- * Fragment Processor subclasses call this from their constructor to register coordinate
- * transformations. The processor subclass manages the lifetime of the transformations (this
- * function only stores a pointer). The GrCoordTransform is typically a member field of the
- * GrProcessor subclass. When the matrix has perspective, the transformed coordinates will have
- * 3 components. Otherwise they'll have 2. This must only be called from the constructor because
- * GrProcessors are immutable.
- */
- void addCoordTransform(const GrCoordTransform*);
-
- /**
- * If the effect subclass will read the destination pixel value then it must call this function
- * from its constructor. Otherwise, when its generated backend-specific effect class attempts
- * to generate code that reads the destination pixel it will fail.
- */
- void setWillReadDstColor() { fWillReadDstColor = true; }
-
- /**
- * If the effect will generate a result that does not depend on the input color value then it
- * must call this function from its constructor. Otherwise, when its generated backend-specific
- * code might fail during variable binding due to unused variables.
- */
- void setWillNotUseInputColor() { fWillUseInputColor = false; }
-
-private:
- /** Subclass implements this to support isEqual(). It will only be called if it is known that
- the two effects are of the same subclass (i.e. they return the same object from
- getFactory()).*/
- virtual bool onIsEqual(const GrFragmentProcessor& other) const = 0;
-
- SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms;
- bool fWillReadDstColor;
- bool fWillUseInputColor;
-
- typedef GrProcessor INHERITED;
-};
-
-/**
- * This creates an effect outside of the effect memory pool. The effect's destructor will be called
- * at global destruction time. NAME will be the name of the created GrProcessor.
- */
-#define GR_CREATE_STATIC_FRAGMENT_PROCESSOR(NAME, EFFECT_CLASS, ARGS) \
-static SkAlignedSStorage<sizeof(EFFECT_CLASS)> g_##NAME##_Storage; \
-static GrFragmentProcessor* \
-NAME SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), EFFECT_CLASS, ARGS); \
-static SkAutoTDestroy<GrFragmentProcessor> NAME##_ad(NAME);
-
#endif
diff --git a/include/gpu/GrProcessorStage.h b/include/gpu/GrProcessorStage.h
index c961572..6f8496d 100644
--- a/include/gpu/GrProcessorStage.h
+++ b/include/gpu/GrProcessorStage.h
@@ -13,8 +13,7 @@
#include "GrBackendProcessorFactory.h"
#include "GrCoordTransform.h"
-#include "GrProcessor.h"
-#include "GrGeometryProcessor.h"
+#include "GrFragmentProcessor.h"
#include "GrProgramElementRef.h"
#include "SkMatrix.h"
#include "SkShader.h"
diff --git a/src/core/SkXfermode.cpp b/src/core/SkXfermode.cpp
index c131842..8a8c622 100644
--- a/src/core/SkXfermode.cpp
+++ b/src/core/SkXfermode.cpp
@@ -775,7 +775,7 @@
#if SK_SUPPORT_GPU
-#include "GrProcessor.h"
+#include "GrFragmentProcessor.h"
#include "GrCoordTransform.h"
#include "GrProcessorUnitTest.h"
#include "GrTBackendProcessorFactory.h"
diff --git a/src/effects/SkAlphaThresholdFilter.cpp b/src/effects/SkAlphaThresholdFilter.cpp
index 10e06ba..016780f 100644
--- a/src/effects/SkAlphaThresholdFilter.cpp
+++ b/src/effects/SkAlphaThresholdFilter.cpp
@@ -48,7 +48,7 @@
#if SK_SUPPORT_GPU
#include "GrContext.h"
#include "GrCoordTransform.h"
-#include "GrProcessor.h"
+#include "GrFragmentProcessor.h"
#include "gl/GrGLProcessor.h"
#include "gl/builders/GrGLProgramBuilder.h"
#include "GrTBackendProcessorFactory.h"
diff --git a/src/effects/SkBlurMaskFilter.cpp b/src/effects/SkBlurMaskFilter.cpp
index c4f0a46..6f69aaf 100644
--- a/src/effects/SkBlurMaskFilter.cpp
+++ b/src/effects/SkBlurMaskFilter.cpp
@@ -20,7 +20,7 @@
#if SK_SUPPORT_GPU
#include "GrContext.h"
#include "GrTexture.h"
-#include "GrProcessor.h"
+#include "GrFragmentProcessor.h"
#include "gl/GrGLProcessor.h"
#include "gl/builders/GrGLProgramBuilder.h"
#include "effects/GrSimpleTextureEffect.h"
diff --git a/src/effects/SkColorFilters.cpp b/src/effects/SkColorFilters.cpp
index 9616ad5..d96aadf 100644
--- a/src/effects/SkColorFilters.cpp
+++ b/src/effects/SkColorFilters.cpp
@@ -123,7 +123,7 @@
///////////////////////////////////////////////////////////////////////////////
#if SK_SUPPORT_GPU
#include "GrBlend.h"
-#include "GrProcessor.h"
+#include "GrFragmentProcessor.h"
#include "GrProcessorUnitTest.h"
#include "GrTBackendProcessorFactory.h"
#include "gl/GrGLProcessor.h"
diff --git a/src/effects/SkColorMatrixFilter.cpp b/src/effects/SkColorMatrixFilter.cpp
index ee6de61..4aee11a 100644
--- a/src/effects/SkColorMatrixFilter.cpp
+++ b/src/effects/SkColorMatrixFilter.cpp
@@ -332,7 +332,7 @@
}
#if SK_SUPPORT_GPU
-#include "GrProcessor.h"
+#include "GrFragmentProcessor.h"
#include "GrTBackendProcessorFactory.h"
#include "gl/GrGLProcessor.h"
#include "gl/builders/GrGLProgramBuilder.h"
diff --git a/src/effects/SkLightingImageFilter.cpp b/src/effects/SkLightingImageFilter.cpp
index a280d5f..0e063d9 100644
--- a/src/effects/SkLightingImageFilter.cpp
+++ b/src/effects/SkLightingImageFilter.cpp
@@ -18,7 +18,7 @@
#include "effects/GrSingleTextureEffect.h"
#include "gl/GrGLProcessor.h"
#include "gl/builders/GrGLProgramBuilder.h"
-#include "GrProcessor.h"
+#include "GrFragmentProcessor.h"
#include "GrTBackendProcessorFactory.h"
class GrGLDiffuseLightingEffect;
diff --git a/src/effects/SkTableColorFilter.cpp b/src/effects/SkTableColorFilter.cpp
index b630e8b..1da6c55 100644
--- a/src/effects/SkTableColorFilter.cpp
+++ b/src/effects/SkTableColorFilter.cpp
@@ -275,7 +275,7 @@
#if SK_SUPPORT_GPU
-#include "GrProcessor.h"
+#include "GrFragmentProcessor.h"
#include "GrTBackendProcessorFactory.h"
#include "gl/GrGLProcessor.h"
#include "gl/builders/GrGLProgramBuilder.h"
diff --git a/src/effects/gradients/SkGradientShaderPriv.h b/src/effects/gradients/SkGradientShaderPriv.h
index 603349c..15f94d4 100644
--- a/src/effects/gradients/SkGradientShaderPriv.h
+++ b/src/effects/gradients/SkGradientShaderPriv.h
@@ -298,6 +298,7 @@
#if SK_SUPPORT_GPU
#include "GrCoordTransform.h"
+#include "GrFragmentProcessor.h"
#include "gl/GrGLProcessor.h"
class GrFragmentStage;
diff --git a/src/gpu/GrDrawState.h b/src/gpu/GrDrawState.h
index d58d8c6..3043fd7 100644
--- a/src/gpu/GrDrawState.h
+++ b/src/gpu/GrDrawState.h
@@ -11,6 +11,7 @@
#include "GrBlend.h"
#include "GrDrawTargetCaps.h"
+#include "GrGeometryProcessor.h"
#include "GrGpuResourceRef.h"
#include "GrProcessorStage.h"
#include "GrRenderTarget.h"
diff --git a/src/gpu/effects/GrSingleTextureEffect.h b/src/gpu/effects/GrSingleTextureEffect.h
index 899755c..ad13c2e 100644
--- a/src/gpu/effects/GrSingleTextureEffect.h
+++ b/src/gpu/effects/GrSingleTextureEffect.h
@@ -8,7 +8,7 @@
#ifndef GrSingleTextureEffect_DEFINED
#define GrSingleTextureEffect_DEFINED
-#include "GrProcessor.h"
+#include "GrFragmentProcessor.h"
#include "SkMatrix.h"
#include "GrCoordTransform.h"
diff --git a/tests/GpuColorFilterTest.cpp b/tests/GpuColorFilterTest.cpp
index 90f2220..c8f5630 100644
--- a/tests/GpuColorFilterTest.cpp
+++ b/tests/GpuColorFilterTest.cpp
@@ -10,7 +10,7 @@
#include "GrContext.h"
#include "GrContextFactory.h"
-#include "GrProcessor.h"
+#include "GrFragmentProcessor.h"
#include "SkColorFilter.h"
#include "SkGr.h"
#include "Test.h"