diff options
Diffstat (limited to 'src/gpu')
-rw-r--r-- | src/gpu/GrDrawState.h | 1 | ||||
-rw-r--r-- | src/gpu/GrEffect.cpp | 8 | ||||
-rw-r--r-- | src/gpu/effects/GrConfigConversionEffect.cpp | 8 | ||||
-rw-r--r-- | src/gpu/effects/GrConvolutionEffect.cpp | 13 | ||||
-rw-r--r-- | src/gpu/effects/GrSingleTextureEffect.cpp | 6 | ||||
-rw-r--r-- | src/gpu/effects/GrTextureDomainEffect.cpp | 8 | ||||
-rw-r--r-- | src/gpu/gl/GrGLEffect.h | 14 | ||||
-rw-r--r-- | src/gpu/gl/GrGLProgram.cpp | 33 | ||||
-rw-r--r-- | src/gpu/gl/GrGLProgram.h | 20 | ||||
-rw-r--r-- | src/gpu/gl/GrGLShaderBuilder.cpp | 7 | ||||
-rw-r--r-- | src/gpu/gl/GrGLShaderBuilder.h | 5 | ||||
-rw-r--r-- | src/gpu/gl/GrGpuGL.h | 3 | ||||
-rw-r--r-- | src/gpu/gl/GrGpuGL_program.cpp | 37 |
13 files changed, 77 insertions, 86 deletions
diff --git a/src/gpu/GrDrawState.h b/src/gpu/GrDrawState.h index 54372ce836..3c6c3a371a 100644 --- a/src/gpu/GrDrawState.h +++ b/src/gpu/GrDrawState.h @@ -8,6 +8,7 @@ #ifndef GrDrawState_DEFINED #define GrDrawState_DEFINED +#include "GrBackendEffectFactory.h" #include "GrColor.h" #include "GrMatrix.h" #include "GrRefCnt.h" diff --git a/src/gpu/GrEffect.cpp b/src/gpu/GrEffect.cpp index 6423aef5dc..09032bf0f9 100644 --- a/src/gpu/GrEffect.cpp +++ b/src/gpu/GrEffect.cpp @@ -5,8 +5,9 @@ * found in the LICENSE file. */ -#include "GrContext.h" #include "GrEffect.h" +#include "GrBackendEffectFactory.h" +#include "GrContext.h" #include "GrMemoryPool.h" #include "SkTLS.h" @@ -49,6 +50,11 @@ bool GrEffect::isOpaque(bool inputTextureIsOpaque) const { return false; } +const char* GrEffect::name() const { + return this->getFactory().name(); +} + + bool GrEffect::isEqual(const GrEffect& s) const { if (this->numTextures() != s.numTextures()) { return false; diff --git a/src/gpu/effects/GrConfigConversionEffect.cpp b/src/gpu/effects/GrConfigConversionEffect.cpp index edb0aa58df..086064545e 100644 --- a/src/gpu/effects/GrConfigConversionEffect.cpp +++ b/src/gpu/effects/GrConfigConversionEffect.cpp @@ -6,6 +6,7 @@ */ #include "GrConfigConversionEffect.h" +#include "GrTBackendEffectFactory.h" #include "gl/GrGLEffect.h" class GrGLConfigConversionEffect : public GrGLEffect { @@ -18,7 +19,7 @@ public: } virtual void emitCode(GrGLShaderBuilder* builder, - const GrEffect&, + const GrEffectStage&, EffectKey, const char* vertexCoords, const char* outputColor, @@ -59,8 +60,9 @@ public: GrGLSLMulVarBy4f(&builder->fFSCode, 2, outputColor, inputColor); } - static inline EffectKey GenKey(const GrEffect& s, const GrGLCaps&) { - const GrConfigConversionEffect& effect = static_cast<const GrConfigConversionEffect&>(s); + static inline EffectKey GenKey(const GrEffectStage& s, const GrGLCaps&) { + const GrConfigConversionEffect& effect = + static_cast<const GrConfigConversionEffect&>(*s.getEffect()); return static_cast<int>(effect.swapsRedAndBlue()) | (effect.pmConversion() << 1); } diff --git a/src/gpu/effects/GrConvolutionEffect.cpp b/src/gpu/effects/GrConvolutionEffect.cpp index 5e0c7f6f5f..d0d9f5d68b 100644 --- a/src/gpu/effects/GrConvolutionEffect.cpp +++ b/src/gpu/effects/GrConvolutionEffect.cpp @@ -9,7 +9,7 @@ #include "gl/GrGLEffect.h" #include "gl/GrGLSL.h" #include "gl/GrGLTexture.h" -#include "GrBackendEffectFactory.h" +#include "GrTBackendEffectFactory.h" // For brevity typedef GrGLUniformManager::UniformHandle UniformHandle; @@ -20,7 +20,7 @@ public: GrGLConvolutionEffect(const GrBackendEffectFactory&, const GrEffect&); virtual void emitCode(GrGLShaderBuilder*, - const GrEffect&, + const GrEffectStage&, EffectKey, const char* vertexCoords, const char* outputColor, @@ -29,7 +29,7 @@ public: virtual void setData(const GrGLUniformManager& uman, const GrEffectStage&) SK_OVERRIDE; - static inline EffectKey GenKey(const GrEffect&, const GrGLCaps&); + static inline EffectKey GenKey(const GrEffectStage&, const GrGLCaps&); private: int width() const { return Gr1DKernelEffect::WidthFromRadius(fRadius); } @@ -52,7 +52,7 @@ GrGLConvolutionEffect::GrGLConvolutionEffect(const GrBackendEffectFactory& facto } void GrGLConvolutionEffect::emitCode(GrGLShaderBuilder* builder, - const GrEffect&, + const GrEffectStage&, EffectKey, const char* vertexCoords, const char* outputColor, @@ -107,9 +107,8 @@ void GrGLConvolutionEffect::setData(const GrGLUniformManager& uman, const GrEffe uman.set1fv(fKernelUni, 0, this->width(), conv.kernel()); } -GrGLEffect::EffectKey GrGLConvolutionEffect::GenKey(const GrEffect& s, - const GrGLCaps& caps) { - return static_cast<const GrConvolutionEffect&>(s).radius(); +GrGLEffect::EffectKey GrGLConvolutionEffect::GenKey(const GrEffectStage& s, const GrGLCaps&) { + return static_cast<const GrConvolutionEffect&>(*s.getEffect()).radius(); } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/gpu/effects/GrSingleTextureEffect.cpp b/src/gpu/effects/GrSingleTextureEffect.cpp index 514e92693d..8866153962 100644 --- a/src/gpu/effects/GrSingleTextureEffect.cpp +++ b/src/gpu/effects/GrSingleTextureEffect.cpp @@ -9,7 +9,7 @@ #include "gl/GrGLEffect.h" #include "gl/GrGLSL.h" #include "gl/GrGLTexture.h" -#include "GrBackendEffectFactory.h" +#include "GrTBackendEffectFactory.h" #include "GrTexture.h" class GrGLSingleTextureEffect : public GrGLEffect { @@ -19,7 +19,7 @@ public: } virtual void emitCode(GrGLShaderBuilder* builder, - const GrEffect&, + const GrEffectStage&, EffectKey, const char* vertexCoords, const char* outputColor, @@ -31,7 +31,7 @@ public: builder->fFSCode.append(";\n"); } - static inline EffectKey GenKey(const GrEffect&, const GrGLCaps&) { return 0; } + static inline EffectKey GenKey(const GrEffectStage&, const GrGLCaps&) { return 0; } private: diff --git a/src/gpu/effects/GrTextureDomainEffect.cpp b/src/gpu/effects/GrTextureDomainEffect.cpp index ab98e5ef5f..fcfae14907 100644 --- a/src/gpu/effects/GrTextureDomainEffect.cpp +++ b/src/gpu/effects/GrTextureDomainEffect.cpp @@ -6,15 +6,15 @@ */ #include "GrTextureDomainEffect.h" +#include "GrTBackendEffectFactory.h" #include "gl/GrGLEffect.h" -#include "GrBackendEffectFactory.h" class GrGLTextureDomainEffect : public GrGLEffect { public: GrGLTextureDomainEffect(const GrBackendEffectFactory&, const GrEffect&); virtual void emitCode(GrGLShaderBuilder*, - const GrEffect&, + const GrEffectStage&, EffectKey, const char* vertexCoords, const char* outputColor, @@ -23,7 +23,7 @@ public: virtual void setData(const GrGLUniformManager&, const GrEffectStage&) SK_OVERRIDE; - static inline EffectKey GenKey(const GrEffect&, const GrGLCaps&) { return 0; } + static inline EffectKey GenKey(const GrEffectStage&, const GrGLCaps&) { return 0; } private: GrGLUniformManager::UniformHandle fNameUni; @@ -38,7 +38,7 @@ GrGLTextureDomainEffect::GrGLTextureDomainEffect(const GrBackendEffectFactory& f } void GrGLTextureDomainEffect::emitCode(GrGLShaderBuilder* builder, - const GrEffect&, + const GrEffectStage&, EffectKey, const char* vertexCoords, const char* outputColor, diff --git a/src/gpu/gl/GrGLEffect.h b/src/gpu/gl/GrGLEffect.h index 74d3f0f1a3..30b8455a68 100644 --- a/src/gpu/gl/GrGLEffect.h +++ b/src/gpu/gl/GrGLEffect.h @@ -8,14 +8,13 @@ #ifndef GrGLEffect_DEFINED #define GrGLEffect_DEFINED -#include "GrAllocator.h" -#include "GrEffectStage.h" +#include "GrBackendEffectFactory.h" #include "GrGLProgram.h" #include "GrGLShaderBuilder.h" #include "GrGLShaderVar.h" #include "GrGLSL.h" -struct GrGLInterface; +class GrEffectStage; class GrGLTexture; /** @file @@ -23,7 +22,7 @@ class GrGLTexture; include/gpu/GrEffect.h. Objects of type GrGLEffect are responsible for emitting the GLSL code that implements a GrEffect and for uploading uniforms at draw time. They also must have a function: - static inline EffectKey GenKey(const GrEffect&, const GrGLCaps&) + static inline EffectKey GenKey(const GrEffectStage&, const GrGLCaps&) that is used to implement a program cache. When two GrEffects produce the same key this means that their GrGLEffects would emit the same GLSL code. @@ -33,7 +32,8 @@ class GrGLTexture; class GrGLEffect { public: - typedef GrEffect::EffectKey EffectKey; + typedef GrBackendEffectFactory::EffectKey EffectKey; + enum { // the number of bits in EffectKey available to GenKey kEffectKeyBits = GrBackendEffectFactory::kEffectKeyBits, @@ -50,7 +50,7 @@ public: stages. @param builder Interface used to emit code in the shaders. - @param effect The effect that generated this program stage. + @param stage The effect stage that generated this program stage. @param key The key that was computed by EffectKey() from the generating GrEffect. @param vertexCoords A vec2 of texture coordinates in the VS, which may be altered. This will be removed soon and stages will be responsible for computing their own @@ -67,7 +67,7 @@ public: reads in the generated code. */ virtual void emitCode(GrGLShaderBuilder* builder, - const GrEffect& effect, + const GrEffectStage& stage, EffectKey key, const char* vertexCoords, const char* outputColor, diff --git a/src/gpu/gl/GrGLProgram.cpp b/src/gpu/gl/GrGLProgram.cpp index 35867c25f1..f9912aafb6 100644 --- a/src/gpu/gl/GrGLProgram.cpp +++ b/src/gpu/gl/GrGLProgram.cpp @@ -53,8 +53,8 @@ inline const char* dual_source_output_name() { return "dualSourceOut"; } GrGLProgram* GrGLProgram::Create(const GrGLContextInfo& gl, const Desc& desc, - const GrEffect** effects) { - GrGLProgram* program = SkNEW_ARGS(GrGLProgram, (gl, desc, effects)); + const GrEffectStage* stages[]) { + GrGLProgram* program = SkNEW_ARGS(GrGLProgram, (gl, desc, stages)); if (!program->succeeded()) { delete program; program = NULL; @@ -64,7 +64,7 @@ GrGLProgram* GrGLProgram::Create(const GrGLContextInfo& gl, GrGLProgram::GrGLProgram(const GrGLContextInfo& gl, const Desc& desc, - const GrEffect** effects) + const GrEffectStage* stages[]) : fContextInfo(gl) , fUniformManager(gl) { fDesc = desc; @@ -86,7 +86,7 @@ GrGLProgram::GrGLProgram(const GrGLContextInfo& gl, fTextureOrigin[s] = GrSurface::kBottomLeft_Origin; } - this->genProgram(effects); + this->genProgram(stages); } GrGLProgram::~GrGLProgram() { @@ -500,7 +500,7 @@ bool GrGLProgram::compileShaders(const GrGLShaderBuilder& builder) { return true; } -bool GrGLProgram::genProgram(const GrEffect** effects) { +bool GrGLProgram::genProgram(const GrEffectStage* stages[]) { GrAssert(0 == fProgramID); GrGLShaderBuilder builder(fContextInfo, fUniformManager); @@ -624,7 +624,7 @@ bool GrGLProgram::genProgram(const GrEffect** effects) { } builder.setCurrentStage(s); - fEffects[s] = GenStageCode(effects[s], + fEffects[s] = GenStageCode(*stages[s], fDesc.fStages[s], &fUniforms.fStages[s], inColor.size() ? inColor.c_str() : NULL, @@ -729,7 +729,7 @@ bool GrGLProgram::genProgram(const GrEffect** effects) { inCoverage.append("4"); } builder.setCurrentStage(s); - fEffects[s] = GenStageCode(effects[s], + fEffects[s] = GenStageCode(*stages[s], fDesc.fStages[s], &fUniforms.fStages[s], inCoverage.size() ? inCoverage.c_str() : NULL, @@ -896,14 +896,15 @@ void GrGLProgram::initSamplerUniforms() { // Stage code generation // TODO: Move this function to GrGLShaderBuilder -GrGLEffect* GrGLProgram::GenStageCode(const GrEffect* effect, - const StageDesc& desc, - StageUniforms* uniforms, - const char* fsInColor, // NULL means no incoming color - const char* fsOutColor, - const char* vsInCoord, - GrGLShaderBuilder* builder) { - +GrGLEffect* GrGLProgram::GenStageCode(const GrEffectStage& stage, + const StageDesc& desc, + StageUniforms* uniforms, + const char* fsInColor, // NULL means no incoming color + const char* fsOutColor, + const char* vsInCoord, + GrGLShaderBuilder* builder) { + + const GrEffect* effect = stage.getEffect(); GrGLEffect* glEffect = effect->getFactory().createGLInstance(*effect); /// Vertex Shader Stuff @@ -956,7 +957,7 @@ GrGLEffect* GrGLProgram::GenStageCode(const GrEffect* effect, builder->fVSCode.appendf("\t{ // %s\n", glEffect->name()); builder->fFSCode.appendf("\t{ // %s \n", glEffect->name()); glEffect->emitCode(builder, - *effect, + stage, desc.fEffectKey, varyingVSName, fsOutColor, diff --git a/src/gpu/gl/GrGLProgram.h b/src/gpu/gl/GrGLProgram.h index 5fad7cc64c..000ebe8f19 100644 --- a/src/gpu/gl/GrGLProgram.h +++ b/src/gpu/gl/GrGLProgram.h @@ -43,7 +43,7 @@ public: static GrGLProgram* Create(const GrGLContextInfo& gl, const Desc& desc, - const GrEffect** effects); + const GrEffectStage* stages[]); virtual ~GrGLProgram(); @@ -163,24 +163,24 @@ private: GrGLProgram(const GrGLContextInfo& gl, const Desc& desc, - const GrEffect** effects); + const GrEffectStage* stages[]); bool succeeded() const { return 0 != fProgramID; } /** * This is the heavy initialization routine for building a GLProgram. */ - bool genProgram(const GrEffect** effects); + bool genProgram(const GrEffectStage* stages[]); void genInputColor(GrGLShaderBuilder* builder, SkString* inColor); - static GrGLEffect* GenStageCode(const GrEffect* effect, - const StageDesc& desc, // TODO: Eliminate this - StageUniforms* stageUniforms, // TODO: Eliminate this - const char* fsInColor, // NULL means no incoming color - const char* fsOutColor, - const char* vsInCoord, - GrGLShaderBuilder* builder); + static GrGLEffect* GenStageCode(const GrEffectStage& stage, + const StageDesc& desc, // TODO: Eliminate this + StageUniforms* stageUniforms, // TODO: Eliminate this + const char* fsInColor, // NULL means no incoming color + const char* fsOutColor, + const char* vsInCoord, + GrGLShaderBuilder* builder); void genGeometryShader(GrGLShaderBuilder* segments) const; diff --git a/src/gpu/gl/GrGLShaderBuilder.cpp b/src/gpu/gl/GrGLShaderBuilder.cpp index d659cf7eca..ec7199b782 100644 --- a/src/gpu/gl/GrGLShaderBuilder.cpp +++ b/src/gpu/gl/GrGLShaderBuilder.cpp @@ -153,9 +153,10 @@ void GrGLShaderBuilder::appendTextureLookupAndModulate( GrGLSLModulate4f(out, modulation, lookup.c_str()); } -GrEffect::EffectKey GrGLShaderBuilder::KeyForTextureAccess(const GrTextureAccess& access, - const GrGLCaps& caps) { - GrEffect::EffectKey key = 0; +GrBackendEffectFactory::EffectKey GrGLShaderBuilder::KeyForTextureAccess( + const GrTextureAccess& access, + const GrGLCaps& caps) { + GrBackendEffectFactory::EffectKey key = 0; // Assume that swizzle support implies that we never have to modify a shader to adjust // for texture format/swizzle settings. diff --git a/src/gpu/gl/GrGLShaderBuilder.h b/src/gpu/gl/GrGLShaderBuilder.h index b67f2f00b2..8f5d6956ac 100644 --- a/src/gpu/gl/GrGLShaderBuilder.h +++ b/src/gpu/gl/GrGLShaderBuilder.h @@ -9,6 +9,7 @@ #define GrGLShaderBuilder_DEFINED #include "GrAllocator.h" +#include "GrBackendEffectFactory.h" #include "GrEffect.h" #include "gl/GrGLShaderVar.h" #include "gl/GrGLSL.h" @@ -122,8 +123,8 @@ public: /** Generates a EffectKey for the shader code based on the texture access parameters and the capabilities of the GL context. This is useful for keying the shader programs that may have multiple representations, based on the type/format of textures used. */ - static GrEffect::EffectKey KeyForTextureAccess(const GrTextureAccess& access, - const GrGLCaps& caps); + static GrBackendEffectFactory::EffectKey KeyForTextureAccess(const GrTextureAccess&, + const GrGLCaps&); /** If texture swizzling is available using tex parameters then it is preferred over mangling the generated shader code. This potentially allows greater reuse of cached shaders. */ diff --git a/src/gpu/gl/GrGpuGL.h b/src/gpu/gl/GrGpuGL.h index 466c4a75e4..f56d783199 100644 --- a/src/gpu/gl/GrGpuGL.h +++ b/src/gpu/gl/GrGpuGL.h @@ -163,7 +163,7 @@ private: ProgramCache(const GrGLContextInfo& gl); void abandon(); - GrGLProgram* getProgram(const GrGLProgram::Desc& desc, const GrEffect** stages); + GrGLProgram* getProgram(const GrGLProgram::Desc& desc, const GrEffectStage* stages[]); private: enum { kKeySize = sizeof(ProgramDesc), @@ -237,7 +237,6 @@ private: void buildProgram(bool isPoints, BlendOptFlags blendOpts, GrBlendCoeff dstCoeff, - const GrEffect** effects, ProgramDesc* desc); // Inits GrDrawTarget::Caps, subclass may enable additional caps. diff --git a/src/gpu/gl/GrGpuGL_program.cpp b/src/gpu/gl/GrGpuGL_program.cpp index ba36abef36..6d6110da8f 100644 --- a/src/gpu/gl/GrGpuGL_program.cpp +++ b/src/gpu/gl/GrGpuGL_program.cpp @@ -33,7 +33,7 @@ void GrGpuGL::ProgramCache::abandon() { } GrGLProgram* GrGpuGL::ProgramCache::getProgram(const ProgramDesc& desc, - const GrEffect** stages) { + const GrEffectStage* stages[]) { Entry newEntry; newEntry.fKey.setKeyData(desc.asKey()); @@ -345,11 +345,14 @@ bool GrGpuGL::flushGraphicsState(DrawType type) { return false; } - const GrEffect* effects[GrDrawState::kNumStages]; + const GrEffectStage* stages[GrDrawState::kNumStages]; + for (int i = 0; i < GrDrawState::kNumStages; ++i) { + stages[i] = drawState.isStageEnabled(i) ? &drawState.getStage(i) : NULL; + } GrGLProgram::Desc desc; - this->buildProgram(kDrawPoints_DrawType == type, blendOpts, dstCoeff, effects, &desc); + this->buildProgram(kDrawPoints_DrawType == type, blendOpts, dstCoeff, &desc); - fCurrentProgram.reset(fProgramCache->getProgram(desc, effects)); + fCurrentProgram.reset(fProgramCache->getProgram(desc, stages)); if (NULL == fCurrentProgram.get()) { GrAssert(!"Failed to create program!"); return false; @@ -558,30 +561,9 @@ void GrGpuGL::setupGeometry(int* startVertex, fHWGeometryState.fArrayPtrsDirty = false; } -namespace { - -void setup_effect(GrGLProgram::Desc::StageDesc* stageDesc, - const GrEffectStage& stage, - const GrGLCaps& caps, - const GrEffect** effects, - GrGLProgram* program, int index) { - const GrEffect* effect = stage.getEffect(); - if (effect) { - const GrBackendEffectFactory& factory = effect->getFactory(); - stageDesc->fEffectKey = factory.glEffectKey(*effect, caps); - effects[index] = effect; - } else { - stageDesc->fEffectKey = 0; - effects[index] = NULL; - } -} - -} - void GrGpuGL::buildProgram(bool isPoints, BlendOptFlags blendOpts, GrBlendCoeff dstCoeff, - const GrEffect** effects, ProgramDesc* desc) { const GrDrawState& drawState = this->getDrawState(); @@ -687,12 +669,11 @@ void GrGpuGL::buildProgram(bool isPoints, // This will go away when effects manage their own texture matrix. stageDesc.fOptFlags |= StageDesc::kIdentityMatrix_OptFlagBit; } - setup_effect(&stageDesc, stage, this->glCaps(), effects, fCurrentProgram.get(), s); - + const GrBackendEffectFactory& factory = effect->getFactory(); + stageDesc.fEffectKey = factory.glEffectKey(stage, this->glCaps()); } else { stageDesc.fOptFlags = 0; stageDesc.fEffectKey = 0; - effects[s] = NULL; } } |