Index: src/gpu/gl/GrGLShaderBuilder.h |
diff --git a/src/gpu/gl/GrGLShaderBuilder.h b/src/gpu/gl/GrGLShaderBuilder.h |
index b67846a621e05b5feb9e0cf26d2a1c64e78a42be..46b2489b26f300ec57886f4baea6c8bc4710b6ad 100644 |
--- a/src/gpu/gl/GrGLShaderBuilder.h |
+++ b/src/gpu/gl/GrGLShaderBuilder.h |
@@ -13,13 +13,14 @@ |
#include "GrColor.h" |
#include "GrEffect.h" |
#include "gl/GrGLSL.h" |
-#include "gl/GrGLUniformManager.h" |
+#include "gl/GrGLUniform.h" |
#include <stdarg.h> |
class GrGLContextInfo; |
class GrEffectStage; |
class GrGLProgramDesc; |
+class GrGLProgram; |
/** |
Contains all the incremental state of a shader as it is being built,as well as helpers to |
@@ -27,6 +28,29 @@ class GrGLProgramDesc; |
*/ |
class GrGLShaderBuilder { |
public: |
+ /** Structure containing information about a uniform during the program build phase. */ |
+ class Uniform { |
+ public: |
+ GrGLUniform* glUniform() const { return fGLUniform; } |
+ |
+ const char* c_str() const { return fVariable.c_str(); } |
+ |
+ void appendArrayAccess(int index, SkString* out) const { |
+ fVariable.appendArrayAccess(index, out); |
+ } |
+ |
+ void appendArrayAccess(const char* indexName, SkString* out) const { |
+ fVariable.appendArrayAccess(indexName, out); |
+ } |
+ |
+ private: |
+ GrGLShaderVar fVariable; |
+ uint32_t fVisibility; |
+ GrGLUniform* fGLUniform; |
+ |
+ friend class GrGLShaderBuilder; |
+ }; |
+ |
/** |
* Passed to GrGLEffects to add texture reads to their shader code. |
*/ |
@@ -34,7 +58,7 @@ public: |
public: |
TextureSampler() |
: fConfigComponentMask(0) |
- , fSamplerUniform(GrGLUniformManager::kInvalidUniformHandle) { |
+ , fSamplerUniform(NULL) { |
// we will memcpy the first 4 bytes from passed in swizzle. This ensures the string is |
// terminated. |
fSwizzle[4] = '\0'; |
@@ -44,7 +68,7 @@ public: |
TextureSampler& operator= (const TextureSampler& other) { |
GrAssert(0 == fConfigComponentMask); |
- GrAssert(GrGLUniformManager::kInvalidUniformHandle == fSamplerUniform); |
+ GrAssert(NULL == fSamplerUniform); |
fConfigComponentMask = other.fConfigComponentMask; |
fSamplerUniform = other.fSamplerUniform; |
@@ -67,7 +91,7 @@ public: |
int idx) { |
GrAssert(!this->isInitialized()); |
GrAssert(0 != configComponentMask); |
- GrAssert(GrGLUniformManager::kInvalidUniformHandle == fSamplerUniform); |
+ GrAssert(NULL == fSamplerUniform); |
GrAssert(NULL != builder); |
SkString name; |
@@ -75,7 +99,7 @@ public: |
fSamplerUniform = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, |
kSampler2D_GrSLType, |
name.c_str()); |
- GrAssert(GrGLUniformManager::kInvalidUniformHandle != fSamplerUniform); |
+ GrAssert(NULL != fSamplerUniform); |
fConfigComponentMask = configComponentMask; |
memcpy(fSwizzle, swizzle, 4); |
@@ -91,7 +115,7 @@ public: |
uint32_t fConfigComponentMask; |
char fSwizzle[5]; |
- GrGLUniformManager::UniformHandle fSamplerUniform; |
+ Uniform* fSamplerUniform; |
friend class GrGLShaderBuilder; // to call init(). |
}; |
@@ -104,7 +128,7 @@ public: |
kFragment_ShaderType = 0x4, |
}; |
- GrGLShaderBuilder(const GrGLContextInfo&, GrGLUniformManager&, const GrGLProgramDesc&); |
+ GrGLShaderBuilder(const GrGLContextInfo&, GrGLProgram&, const GrGLProgramDesc&); |
/** |
* Use of these features may require a GLSL extension to be enabled. Shaders may not compile |
@@ -216,26 +240,12 @@ public: |
it will refer to the final uniform name after return. Use the addUniformArray variant to add |
an array of uniforms. |
*/ |
- GrGLUniformManager::UniformHandle addUniform(uint32_t visibility, |
- GrSLType type, |
- const char* name, |
- const char** outName = NULL) { |
+ Uniform* addUniform(uint32_t visibility, GrSLType type, const char* name, |
+ const char** outName = NULL) { |
return this->addUniformArray(visibility, type, name, GrGLShaderVar::kNonArray, outName); |
} |
- GrGLUniformManager::UniformHandle addUniformArray(uint32_t visibility, |
- GrSLType type, |
- const char* name, |
- int arrayCount, |
- const char** outName = NULL); |
- |
- const GrGLShaderVar& getUniformVariable(GrGLUniformManager::UniformHandle) const; |
- |
- /** |
- * Shortcut for getUniformVariable(u).c_str() |
- */ |
- const char* getUniformCStr(GrGLUniformManager::UniformHandle u) const { |
- return this->getUniformVariable(u).c_str(); |
- } |
+ Uniform* addUniformArray(uint32_t visibility, GrSLType type, const char* name, int arrayCount, |
+ const char** outName = NULL); |
/** Add a vertex attribute to the current program that is passed in from the vertex data. |
Returns false if the attribute was already there, true otherwise. */ |
@@ -297,18 +307,18 @@ public: |
int effectCnt, |
SkString* inOutFSColor, |
GrSLConstantVec* fsInOutColorKnownValue, |
- SkTArray<GrGLUniformManager::UniformHandle, true>* effectSamplerHandles[], |
+ SkTArray<GrGLUniform*, true>* effectSamplerHandles[], |
GrGLEffect* glEffects[]); |
- GrGLUniformManager::UniformHandle getRTHeightUniform() const { return fRTHeightUniform; } |
- GrGLUniformManager::UniformHandle getDstCopyTopLeftUniform() const { |
+ GrGLUniform* getRTHeightUniform() const { return fRTHeightUniform; } |
+ GrGLUniform* getDstCopyTopLeftUniform() const { |
return fDstCopyTopLeftUniform; |
} |
- GrGLUniformManager::UniformHandle getDstCopyScaleUniform() const { |
+ GrGLUniform* getDstCopyScaleUniform() const { |
return fDstCopyScaleUniform; |
} |
- GrGLUniformManager::UniformHandle getDstCopySamplerUniform() const { |
- return fDstCopySampler.fSamplerUniform; |
+ GrGLUniform* getDstCopySamplerUniform() const { |
+ return fDstCopySampler.fSamplerUniform ? fDstCopySampler.fSamplerUniform->glUniform() : NULL; |
} |
struct AttributePair { |
@@ -324,7 +334,7 @@ public: |
const SkString* getEffectAttributeName(int attributeIndex) const; |
// TODO: Make this do all the compiling, linking, etc. |
- void finished(GrGLuint programID); |
+ void finished(const GrGLContext&, GrGLuint programID); |
const GrGLContextInfo& ctxInfo() const { return fCtxInfo; } |
@@ -337,8 +347,11 @@ private: |
void appendDecls(const VarArray&, SkString*) const; |
void appendUniformDecls(ShaderType, SkString*) const; |
- typedef GrGLUniformManager::BuilderUniform BuilderUniform; |
- GrGLUniformManager::BuilderUniformArray fUniforms; |
+ // This uses an allocator rather than array so that the GrGLShaderVars don't move in memory |
+ // after they are inserted. Users of GrGLShaderBuilder get refs to the vars and ptrs to their |
+ // name strings. Otherwise, we'd have to hand out copies. |
+ typedef GrTAllocator<Uniform> UniformArray; |
+ UniformArray fUniforms; |
// TODO: Everything below here private. |
public: |
@@ -437,7 +450,7 @@ private: |
}; |
const GrGLContextInfo& fCtxInfo; |
- GrGLUniformManager& fUniformManager; |
+ GrGLProgram& fProgram; |
uint32_t fFSFeaturesAddedMask; |
SkString fFSFunctions; |
SkString fFSExtensions; |
@@ -451,9 +464,9 @@ private: |
bool fSetupFragPosition; |
TextureSampler fDstCopySampler; |
- GrGLUniformManager::UniformHandle fRTHeightUniform; |
- GrGLUniformManager::UniformHandle fDstCopyTopLeftUniform; |
- GrGLUniformManager::UniformHandle fDstCopyScaleUniform; |
+ GrGLUniform* fRTHeightUniform; |
+ GrGLUniform* fDstCopyTopLeftUniform; |
+ GrGLUniform* fDstCopyScaleUniform; |
bool fTopLeftFragPosRead; |