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

Unified Diff: src/gpu/gl/builders/GrGLFragmentShaderBuilder.h

Issue 611653002: Cleanup of shader building system (Closed) Base URL: https://skia.googlesource.com/skia.git@solo_gp
Patch Set: more cleanup Created 6 years, 3 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
Index: src/gpu/gl/builders/GrGLFragmentShaderBuilder.h
diff --git a/src/gpu/gl/builders/GrGLFragmentShaderBuilder.h b/src/gpu/gl/builders/GrGLFragmentShaderBuilder.h
index 38d569e734189f552713d4ba07160ba2672ab897..aa6ac1cc9202fed8f9148527dbefd8b70f31d91e 100644
--- a/src/gpu/gl/builders/GrGLFragmentShaderBuilder.h
+++ b/src/gpu/gl/builders/GrGLFragmentShaderBuilder.h
@@ -7,9 +7,8 @@
#ifndef GrGLFragmentShaderBuilder_DEFINED
#define GrGLFragmentShaderBuilder_DEFINED
-#include "GrGLShaderBuilder.h"
-class GrGLProgramBuilder;
+#include "GrGLShaderBuilder.h"
/*
* This base class encapsulates the functionality which all GrProcessors are allowed to use in their
@@ -55,9 +54,10 @@ private:
* 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
*/
-class GrGLFragmentProcessorShaderBuilder : public GrGLProcessorFragmentShaderBuilder {
+class GrGLFragmentProcessorFragmentShaderBuilder : public GrGLProcessorFragmentShaderBuilder {
public:
- GrGLFragmentProcessorShaderBuilder(GrGLProgramBuilder* program) : INHERITED(program) {}
+ GrGLFragmentProcessorFragmentShaderBuilder(GrGLProgramBuilder* program) : INHERITED(program) {}
+
/** Returns the variable name that holds the color of the destination pixel. This may be NULL if
no effect advertised that it will read the destination. */
virtual const char* dstColor() = 0;
@@ -66,7 +66,7 @@ private:
typedef GrGLProcessorFragmentShaderBuilder INHERITED;
};
-class GrGLFragmentShaderBuilder : public GrGLFragmentProcessorShaderBuilder {
+class GrGLFragmentShaderBuilder : public GrGLFragmentProcessorFragmentShaderBuilder {
public:
typedef uint8_t DstReadKey;
typedef uint8_t FragPosKey;
@@ -83,39 +83,40 @@ public:
GrGLFragmentShaderBuilder(GrGLProgramBuilder* program, const GrGLProgramDesc& desc);
- virtual const char* dstColor() SK_OVERRIDE;
-
+ // true public interface, defined explicitly in the abstract interfaces above
virtual bool enableFeature(GLSLFeature) SK_OVERRIDE;
-
virtual SkString ensureFSCoords2D(const GrGLProcessor::TransformedCoordsArray& coords,
int index) SK_OVERRIDE;
-
virtual const char* fragmentPosition() SK_OVERRIDE;
+ virtual const char* dstColor() SK_OVERRIDE;
+
+ // Private public interface, used by GrGLProgramBuilder to build a fragment shader
+ void emitCodeToReadDstTexture();
+ void enableCustomOutput();
+ void enableSecondaryOutput();
+ const char* getPrimaryColorOutputName() const;
+ const char* getSecondaryColorOutputName() const;
+ bool compileAndAttachShaders(GrGLuint programId, SkTDArray<GrGLuint>* shaderIds) const;
+ void bindFragmentShaderLocations(GrGLuint programID);
-private:
/*
- * An internal call for GrGLFullProgramBuilder to use to add varyings to the vertex shader
+ * An internal call for GrGLProgramBuilder to use to add varyings to the vertex shader
*/
void addVarying(GrSLType type,
const char* name,
const char** fsInName,
GrGLShaderVar::Precision fsPrecision = GrGLShaderVar::kDefault_Precision);
- /*
- * Private functions used by GrGLProgramBuilder for compilation
- */
- void bindProgramLocations(GrGLuint programId);
- bool compileAndAttachShaders(GrGLuint programId, SkTDArray<GrGLuint>* shaderIds) const;
- void emitCodeBeforeEffects();
- void emitCodeAfterEffects(const GrGLSLExpr4& inputColor, const GrGLSLExpr4& inputCoverage);
-
- /** Enables using the secondary color output and returns the name of the var in which it is
- to be stored */
- const char* enableSecondaryOutput();
-
- /** Gets the name of the primary color output. */
- const char* getColorOutputName() const;
+ // As GLProcessors emit code, there are some conditions we need to verify. We use the below
+ // state to track this. The reset call is called per processor emitted.
+ bool hasReadDstColor() const { return fHasReadDstColor; }
+ bool hasReadFragmentPosition() const { return fHasReadFragmentPosition; }
+ void reset() {
+ fHasReadDstColor = false;
+ fHasReadFragmentPosition = false;
+ }
+private:
/**
* Features that should only be enabled by GrGLFragmentShaderBuilder itself.
*/
@@ -132,21 +133,29 @@ private:
kTopLeftOrigin_DstReadKeyBit = 0x4, // Set if dst-copy origin is top-left.
};
+ // Interpretation of FragPosKey when generating code
enum {
kNoFragPosRead_FragPosKey = 0, // The fragment positition will not be needed.
kTopLeftFragPosRead_FragPosKey = 0x1,// Read frag pos relative to top-left.
kBottomLeftFragPosRead_FragPosKey = 0x2,// Read frag pos relative to bottom-left.
};
+ static const char* kDstCopyColorName;
+
bool fHasCustomColorOutput;
bool fHasSecondaryOutput;
bool fSetupFragPosition;
bool fTopLeftFragPosRead;
+ // some state to verify shaders and effects are consistent, this is reset between effects by
+ // the program creator
+ bool fHasReadDstColor;
+ bool fHasReadFragmentPosition;
+
+ friend class GrGLESNvprProgramBuilder;
friend class GrGLProgramBuilder;
- friend class GrGLFullProgramBuilder;
- typedef GrGLFragmentProcessorShaderBuilder INHERITED;
+ typedef GrGLFragmentProcessorFragmentShaderBuilder INHERITED;
};
#endif

Powered by Google App Engine
This is Rietveld 408576698