Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(317)

Unified Diff: src/gpu/glsl/GrGLSLFragmentShaderBuilder.h

Issue 1709153002: Add more specialized fragment builders (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Make MSVC happy Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/glsl/GrGLSLFragmentProcessor.cpp ('k') | src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/glsl/GrGLSLFragmentShaderBuilder.h
diff --git a/src/gpu/glsl/GrGLSLFragmentShaderBuilder.h b/src/gpu/glsl/GrGLSLFragmentShaderBuilder.h
index a437a194ca2c228a61ac148b0a43aa8e6de3bc21..4dab6f2a09bd2582fc30576c8331f27c0569b062 100644
--- a/src/gpu/glsl/GrGLSLFragmentShaderBuilder.h
+++ b/src/gpu/glsl/GrGLSLFragmentShaderBuilder.h
@@ -16,17 +16,14 @@ class GrRenderTarget;
class GrGLSLVarying;
/*
- * This base class encapsulates the functionality which the GP uses to build fragment shaders
+ * This base class encapsulates the common functionality which all processors use to build fragment
+ * shaders.
*/
class GrGLSLFragmentBuilder : public GrGLSLShaderBuilder {
public:
- GrGLSLFragmentBuilder(GrGLSLProgramBuilder* program)
- : INHERITED(program)
- , fHasCustomColorOutput(false)
- , fHasSecondaryOutput(false) {
- fSubstageIndices.push_back(0);
- }
+ GrGLSLFragmentBuilder(GrGLSLProgramBuilder* program) : INHERITED(program) {}
virtual ~GrGLSLFragmentBuilder() {}
+
/**
* Use of these features may require a GLSL extension to be enabled. Shaders may not compile
* if code is added that uses one of these features without calling enableFeature()
@@ -54,74 +51,65 @@ public:
is in device space (e.g. 0,0 is the top left and pixel centers are at half-integers). */
virtual const char* fragmentPosition() = 0;
- /**
- * Fragment procs with child procs should call these functions before/after calling emitCode
- * on a child proc.
- */
- void onBeforeChildProcEmitCode();
- void onAfterChildProcEmitCode();
-
- const SkString& getMangleString() const { return fMangleString; }
-
- bool hasCustomColorOutput() const { return fHasCustomColorOutput; }
- bool hasSecondaryOutput() const { return fHasSecondaryOutput; }
-
+ // TODO: remove this method.
void declAppendf(const char* fmt, ...);
-protected:
- bool fHasCustomColorOutput;
- bool fHasSecondaryOutput;
-
private:
- /*
- * State that tracks which child proc in the proc tree is currently emitting code. This is
- * used to update the fMangleString, which is used to mangle the names of uniforms and functions
- * emitted by the proc. fSubstageIndices is a stack: its count indicates how many levels deep
- * we are in the tree, and its second-to-last value is the index of the child proc at that
- * level which is currently emitting code. For example, if fSubstageIndices = [3, 1, 2, 0], that
- * means we're currently emitting code for the base proc's 3rd child's 1st child's 2nd child.
- */
- SkTArray<int> fSubstageIndices;
+ typedef GrGLSLShaderBuilder INHERITED;
+};
- /*
- * The mangle string is used to mangle the names of uniforms/functions emitted by the child
- * procs so no duplicate uniforms/functions appear in the generated shader program. The mangle
- * string is simply based on fSubstageIndices. For example, if fSubstageIndices = [3, 1, 2, 0],
- * then the manglestring will be "_c3_c1_c2", and any uniform/function emitted by that proc will
- * have "_c3_c1_c2" appended to its name, which can be interpreted as "base proc's 3rd child's
- * 1st child's 2nd child".
+/*
+ * This class is used by fragment processors to build their fragment code.
+ */
+class GrGLSLFPFragmentBuilder : virtual public GrGLSLFragmentBuilder {
+public:
+ /** Appease the compiler; the derived class initializes GrGLSLFragmentBuilder. */
+ GrGLSLFPFragmentBuilder() : GrGLSLFragmentBuilder(nullptr) {}
+
+ /**
+ * Fragment procs with child procs should call these functions before/after calling emitCode
+ * on a child proc.
*/
- SkString fMangleString;
+ virtual void onBeforeChildProcEmitCode() = 0;
+ virtual void onAfterChildProcEmitCode() = 0;
- friend class GrGLPathProcessor;
+ virtual const SkString& getMangleString() const = 0;
+};
- typedef GrGLSLShaderBuilder INHERITED;
+/*
+ * This class is used by primitive processors to build their fragment code.
+ */
+class GrGLSLPPFragmentBuilder : public GrGLSLFPFragmentBuilder {
+public:
+ /** Appease the compiler; the derived class initializes GrGLSLFragmentBuilder. */
+ GrGLSLPPFragmentBuilder() : GrGLSLFragmentBuilder(nullptr) {}
};
/*
- * Fragment processor's, in addition to all of the above, may need to use dst color so they use
- * this builder to create their shader. Because this is the only shader builder the FP sees, we
- * just call it FPShaderBuilder
+ * This class is used by Xfer processors to build their fragment code.
*/
-class GrGLSLXPFragmentBuilder : public GrGLSLFragmentBuilder {
+class GrGLSLXPFragmentBuilder : virtual public GrGLSLFragmentBuilder {
public:
- GrGLSLXPFragmentBuilder(GrGLSLProgramBuilder* program) : INHERITED(program) {}
+ /** Appease the compiler; the derived class initializes GrGLSLFragmentBuilder. */
+ GrGLSLXPFragmentBuilder() : GrGLSLFragmentBuilder(nullptr) {}
+
+ virtual bool hasCustomColorOutput() const = 0;
+ virtual bool hasSecondaryOutput() const = 0;
- /** Returns the variable name that holds the color of the destination pixel. This may be nullptr if
- no effect advertised that it will read the destination. */
+ /** Returns the variable name that holds the color of the destination pixel. This may be nullptr
+ * if no effect advertised that it will read the destination. */
virtual const char* dstColor() = 0;
/** Adds any necessary layout qualifiers in order to legalize the supplied blend equation with
this shader. It is only legal to call this method with an advanced blend equation, and only
if these equations are supported. */
virtual void enableAdvancedBlendEquationIfNeeded(GrBlendEquation) = 0;
-
-private:
- typedef GrGLSLFragmentBuilder INHERITED;
};
-// TODO rename to Fragment Builder
-class GrGLSLFragmentShaderBuilder : public GrGLSLXPFragmentBuilder {
+/*
+ * This class implements the various fragment builder interfaces.
+ */
+class GrGLSLFragmentShaderBuilder : public GrGLSLPPFragmentBuilder, public GrGLSLXPFragmentBuilder {
public:
typedef uint8_t FragPosKey;
@@ -132,13 +120,21 @@ public:
GrGLSLFragmentShaderBuilder(GrGLSLProgramBuilder* program, uint8_t fragPosKey);
- // true public interface, defined explicitly in the abstract interfaces above
+ // Shared GrGLSLFragmentBuilder interface.
bool enableFeature(GLSLFeature) override;
virtual SkString ensureFSCoords2D(const GrGLSLTransformedCoordsArray& coords,
int index) override;
const char* fragmentPosition() override;
- const char* dstColor() override;
+ // GrGLSLFPFragmentBuilder interface.
+ const SkString& getMangleString() const override { return fMangleString; }
+ void onBeforeChildProcEmitCode() override;
+ void onAfterChildProcEmitCode() override;
+
+ // GrGLSLXPFragmentBuilder interface.
+ bool hasCustomColorOutput() const override { return fHasCustomColorOutput; }
+ bool hasSecondaryOutput() const override { return fHasSecondaryOutput; }
+ const char* dstColor() override;
void enableAdvancedBlendEquationIfNeeded(GrBlendEquation) override;
private:
@@ -176,9 +172,31 @@ private:
static const char* kDstTextureColorName;
+ /*
+ * State that tracks which child proc in the proc tree is currently emitting code. This is
+ * used to update the fMangleString, which is used to mangle the names of uniforms and functions
+ * emitted by the proc. fSubstageIndices is a stack: its count indicates how many levels deep
+ * we are in the tree, and its second-to-last value is the index of the child proc at that
+ * level which is currently emitting code. For example, if fSubstageIndices = [3, 1, 2, 0], that
+ * means we're currently emitting code for the base proc's 3rd child's 1st child's 2nd child.
+ */
+ SkTArray<int> fSubstageIndices;
+
+ /*
+ * The mangle string is used to mangle the names of uniforms/functions emitted by the child
+ * procs so no duplicate uniforms/functions appear in the generated shader program. The mangle
+ * string is simply based on fSubstageIndices. For example, if fSubstageIndices = [3, 1, 2, 0],
+ * then the manglestring will be "_c3_c1_c2", and any uniform/function emitted by that proc will
+ * have "_c3_c1_c2" appended to its name, which can be interpreted as "base proc's 3rd child's
+ * 1st child's 2nd child".
+ */
+ SkString fMangleString;
+
bool fSetupFragPosition;
bool fTopLeftFragPosRead;
+ bool fHasCustomColorOutput;
int fCustomColorOutputIndex;
+ bool fHasSecondaryOutput;
// some state to verify shaders and effects are consistent, this is reset between effects by
// the program creator
@@ -187,8 +205,6 @@ private:
friend class GrGLSLProgramBuilder;
friend class GrGLProgramBuilder;
-
- typedef GrGLSLXPFragmentBuilder INHERITED;
};
#endif
« no previous file with comments | « src/gpu/glsl/GrGLSLFragmentProcessor.cpp ('k') | src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698