From b8eb2e89edf914caf5479baeffcb670d3e93f496 Mon Sep 17 00:00:00 2001 From: "bsalomon@google.com" Date: Thu, 28 Mar 2013 13:46:42 +0000 Subject: Make GrGLShaderBuilder::TextureSampler extract only required info from GrTextureAccess. This will make it possible to init a TextureSampler without a texture or a specific config. Also unify two separate bitfields of color components in GPU code. Review URL: https://codereview.chromium.org/13121002 git-svn-id: http://skia.googlecode.com/svn/trunk@8428 2bbb7eff-a529-9590-31e7-b0007b416f81 --- include/gpu/GrColor.h | 40 ++++++++++++++++++++++++++ include/gpu/GrEffect.h | 21 +++----------- include/gpu/GrTextureAccess.h | 12 ++------ include/gpu/GrTypes.h | 3 +- src/effects/SkBlendImageFilter.cpp | 2 +- src/effects/SkColorMatrixFilter.cpp | 12 ++++---- src/effects/SkTableColorFilter.cpp | 8 +++--- src/effects/gradients/SkGradientShader.cpp | 4 +-- src/gpu/GrDrawState.cpp | 8 +++--- src/gpu/GrGpu.cpp | 2 +- src/gpu/GrGpu.h | 4 +-- src/gpu/GrTextureAccess.cpp | 14 +++++----- src/gpu/effects/GrSingleTextureEffect.h | 4 +-- src/gpu/gl/GrGLCaps.cpp | 4 +-- src/gpu/gl/GrGLCaps.h | 2 +- src/gpu/gl/GrGLShaderBuilder.cpp | 25 +++++------------ src/gpu/gl/GrGLShaderBuilder.h | 45 +++++++++++++++++++++--------- 17 files changed, 119 insertions(+), 91 deletions(-) diff --git a/include/gpu/GrColor.h b/include/gpu/GrColor.h index af12ac69bc..43d932be0d 100644 --- a/include/gpu/GrColor.h +++ b/include/gpu/GrColor.h @@ -67,4 +67,44 @@ static inline void GrColorToRGBAFloat(GrColor color, float rgba[4]) { rgba[3] = GrColorUnpackA(color) * ONE_OVER_255; } +/** + * Flags used for bitfields of color components. They are defined so that the bit order reflects the + * GrColor shift order. + */ +enum GrColorComponentFlags { + kR_GrColorComponentFlag = 1 << (GrColor_SHIFT_R / 8), + kG_GrColorComponentFlag = 1 << (GrColor_SHIFT_G / 8), + kB_GrColorComponentFlag = 1 << (GrColor_SHIFT_B / 8), + kA_GrColorComponentFlag = 1 << (GrColor_SHIFT_A / 8), + + kRGB_GrColorComponentFlags = (kR_GrColorComponentFlag | kG_GrColorComponentFlag | + kB_GrColorComponentFlag), + + kRGBA_GrColorComponentFlags = (kR_GrColorComponentFlag | kG_GrColorComponentFlag | + kB_GrColorComponentFlag | kA_GrColorComponentFlag) +}; + +static inline uint32_t GrPixelConfigComponentMask(GrPixelConfig config) { + GrAssert(config >= 0 && config < kGrPixelConfigCnt); + static const uint32_t kFlags[] = { + 0, // kUnknown_GrPixelConfig + kA_GrColorComponentFlag, // kAlpha_8_GrPixelConfig + kRGBA_GrColorComponentFlags, // kIndex_8_GrPixelConfig + kRGB_GrColorComponentFlags, // kRGB_565_GrPixelConfig + kRGBA_GrColorComponentFlags, // kRGBA_4444_GrPixelConfig + kRGBA_GrColorComponentFlags, // kRGBA_8888_GrPixelConfig + kRGBA_GrColorComponentFlags, // kBGRA_8888_GrPixelConfig + }; + return kFlags[config]; + + GR_STATIC_ASSERT(0 == kUnknown_GrPixelConfig); + GR_STATIC_ASSERT(1 == kAlpha_8_GrPixelConfig); + GR_STATIC_ASSERT(2 == kIndex_8_GrPixelConfig); + GR_STATIC_ASSERT(3 == kRGB_565_GrPixelConfig); + GR_STATIC_ASSERT(4 == kRGBA_4444_GrPixelConfig); + GR_STATIC_ASSERT(5 == kRGBA_8888_GrPixelConfig); + GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig); + GR_STATIC_ASSERT(SK_ARRAY_COUNT(kFlags) == kGrPixelConfigCnt); +} + #endif diff --git a/include/gpu/GrEffect.h b/include/gpu/GrEffect.h index 883438603d..de4b2a14fb 100644 --- a/include/gpu/GrEffect.h +++ b/include/gpu/GrEffect.h @@ -86,25 +86,12 @@ public: virtual ~GrEffect(); - /** - * Flags for getConstantColorComponents. They are defined so that the bit order reflects the - * GrColor shift order. - */ - enum ValidComponentFlags { - kR_ValidComponentFlag = 1 << (GrColor_SHIFT_R / 8), - kG_ValidComponentFlag = 1 << (GrColor_SHIFT_G / 8), - kB_ValidComponentFlag = 1 << (GrColor_SHIFT_B / 8), - kA_ValidComponentFlag = 1 << (GrColor_SHIFT_A / 8), - - kAll_ValidComponentFlags = (kR_ValidComponentFlag | kG_ValidComponentFlag | - kB_ValidComponentFlag | kA_ValidComponentFlag) - }; - /** * This function is used to perform optimizations. When called the color and validFlags params - * indicate whether the input components to this effect in the FS will have known values. The - * function updates both params to indicate known values of its output. A component of the color - * param only has meaning if the corresponding bit in validFlags is set. + * indicate whether the input components to this effect in the FS will have known values. + * validFlags is a bitfield of GrColorComponentFlags. The function updates both params to + * indicate known values of its output. A component of the color param only has meaning if the + * corresponding bit in validFlags is set. */ virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const = 0; diff --git a/include/gpu/GrTextureAccess.h b/include/gpu/GrTextureAccess.h index b03e6e6dc9..e5ea535d99 100644 --- a/include/gpu/GrTextureAccess.h +++ b/include/gpu/GrTextureAccess.h @@ -162,16 +162,8 @@ public: */ const char* getSwizzle() const { return fSwizzle; } - enum { - kR_SwizzleFlag = 0x1, - kG_SwizzleFlag = 0x2, - kB_SwizzleFlag = 0x4, - kA_SwizzleFlag = 0x8, - - kRGB_SwizzleMask = (kR_SwizzleFlag | kG_SwizzleFlag | kB_SwizzleFlag), - }; - - /** Returns a mask indicating which components are referenced in the swizzle. */ + /** Returns a mask indicating which components are referenced in the swizzle. The return + is a bitfield of GrColorComponentFlags. */ uint32_t swizzleMask() const { return fSwizzleMask; } const GrTextureParams& getParams() const { return fParams; } diff --git a/include/gpu/GrTypes.h b/include/gpu/GrTypes.h index f0153dfc56..5e48dac460 100644 --- a/include/gpu/GrTypes.h +++ b/include/gpu/GrTypes.h @@ -284,8 +284,9 @@ enum GrPixelConfig { */ kBGRA_8888_GrPixelConfig, - kGrPixelConfigCount + kLast_GrPixelConfig = kBGRA_8888_GrPixelConfig }; +static const int kGrPixelConfigCnt = kLast_GrPixelConfig + 1; // Aliases for pixel configs that match skia's byte order. #ifndef SK_CPU_LENDIAN diff --git a/src/effects/SkBlendImageFilter.cpp b/src/effects/SkBlendImageFilter.cpp index 1c85fe5f29..330e87d76d 100644 --- a/src/effects/SkBlendImageFilter.cpp +++ b/src/effects/SkBlendImageFilter.cpp @@ -215,7 +215,7 @@ void GrBlendEffect::getConstantColorComponents(GrColor* color, uint32_t* validFl // communicate this.) if (GrPixelConfigIsOpaque(fForegroundAccess.getTexture()->config()) || GrPixelConfigIsOpaque(fBackgroundAccess.getTexture()->config())) { - *validFlags = kA_ValidComponentFlag; + *validFlags = kA_GrColorComponentFlag; *color = GrColorPackRGBA(0, 0, 0, 0xff); } else { *validFlags = 0; diff --git a/src/effects/SkColorMatrixFilter.cpp b/src/effects/SkColorMatrixFilter.cpp index c2ab3fd73f..661544bf29 100644 --- a/src/effects/SkColorMatrixFilter.cpp +++ b/src/effects/SkColorMatrixFilter.cpp @@ -344,11 +344,11 @@ public: // The matrix is defined such the 4th row determines the output alpha. The first four // columns of that row multiply the input r, g, b, and a, respectively, and the last column // is the "translation". - static const ValidComponentFlags kRGBAFlags[] = { - kR_ValidComponentFlag, - kG_ValidComponentFlag, - kB_ValidComponentFlag, - kA_ValidComponentFlag + static const uint32_t kRGBAFlags[] = { + kR_GrColorComponentFlag, + kG_GrColorComponentFlag, + kB_GrColorComponentFlag, + kA_GrColorComponentFlag }; static const int kShifts[] = { GrColor_SHIFT_R, GrColor_SHIFT_G, GrColor_SHIFT_B, GrColor_SHIFT_A, @@ -373,7 +373,7 @@ public: } } outputA += fMatrix.fMat[kAlphaRowTranslateIdx]; - *validFlags = kA_ValidComponentFlag; + *validFlags = kA_GrColorComponentFlag; // We pin the color to [0,1]. This would happen to the *final* color output from the frag // shader but currently the effect does not pin its own output. So in the case of over/ // underflow this may deviate from the actual result. Maybe the effect should pin its diff --git a/src/effects/SkTableColorFilter.cpp b/src/effects/SkTableColorFilter.cpp index d20283f5b1..9979fae27b 100644 --- a/src/effects/SkTableColorFilter.cpp +++ b/src/effects/SkTableColorFilter.cpp @@ -348,16 +348,16 @@ void ColorTableEffect::getConstantColorComponents(GrColor* color, uint32_t* vali // If we kept the table in the effect then we could actually run known inputs through the // table. if (fFlags & SkTable_ColorFilter::kR_Flag) { - *validFlags &= ~kR_ValidComponentFlag; + *validFlags &= ~kR_GrColorComponentFlag; } if (fFlags & SkTable_ColorFilter::kG_Flag) { - *validFlags &= ~kG_ValidComponentFlag; + *validFlags &= ~kG_GrColorComponentFlag; } if (fFlags & SkTable_ColorFilter::kB_Flag) { - *validFlags &= ~kB_ValidComponentFlag; + *validFlags &= ~kB_GrColorComponentFlag; } if (fFlags & SkTable_ColorFilter::kA_Flag) { - *validFlags &= ~kA_ValidComponentFlag; + *validFlags &= ~kA_GrColorComponentFlag; } } diff --git a/src/effects/gradients/SkGradientShader.cpp b/src/effects/gradients/SkGradientShader.cpp index d3b2fd41f8..684355d5df 100644 --- a/src/effects/gradients/SkGradientShader.cpp +++ b/src/effects/gradients/SkGradientShader.cpp @@ -866,8 +866,8 @@ bool GrGradientEffect::onIsEqual(const GrEffect& effect) const { } void GrGradientEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const { - if (fIsOpaque && (kA_ValidComponentFlag & *validFlags) && 0xff == GrColorUnpackA(*color)) { - *validFlags = kA_ValidComponentFlag; + if (fIsOpaque && (kA_GrColorComponentFlag & *validFlags) && 0xff == GrColorUnpackA(*color)) { + *validFlags = kA_GrColorComponentFlag; } else { *validFlags = 0; } diff --git a/src/gpu/GrDrawState.cpp b/src/gpu/GrDrawState.cpp index e10899958b..f9e12cc207 100644 --- a/src/gpu/GrDrawState.cpp +++ b/src/gpu/GrDrawState.cpp @@ -236,7 +236,7 @@ bool GrDrawState::srcAlphaWillBeOne(GrAttribBindings bindings) const { validComponentFlags = 0; color = 0; // not strictly necessary but we get false alarms from tools about uninit. } else { - validComponentFlags = GrEffect::kAll_ValidComponentFlags; + validComponentFlags = kRGBA_GrColorComponentFlags; color = this->getColor(); } @@ -275,7 +275,7 @@ bool GrDrawState::srcAlphaWillBeOne(GrAttribBindings bindings) const { } } } - return (GrEffect::kA_ValidComponentFlag & validComponentFlags) && 0xff == GrColorUnpackA(color); + return (kA_GrColorComponentFlag & validComponentFlags) && 0xff == GrColorUnpackA(color); } bool GrDrawState::hasSolidCoverage(GrAttribBindings bindings) const { @@ -291,7 +291,7 @@ bool GrDrawState::hasSolidCoverage(GrAttribBindings bindings) const { validComponentFlags = 0; } else { coverage = fCommon.fCoverage; - validComponentFlags = GrEffect::kAll_ValidComponentFlags; + validComponentFlags = kRGBA_GrColorComponentFlags; } // Run through the coverage stages and see if the coverage will be all ones at the end. @@ -301,7 +301,7 @@ bool GrDrawState::hasSolidCoverage(GrAttribBindings bindings) const { (*effect)->getConstantColorComponents(&coverage, &validComponentFlags); } } - return (GrEffect::kAll_ValidComponentFlags == validComponentFlags) && (0xffffffff == coverage); + return (kRGBA_GrColorComponentFlags == validComponentFlags) && (0xffffffff == coverage); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp index c9e876a717..73e4d3e441 100644 --- a/src/gpu/GrGpu.cpp +++ b/src/gpu/GrGpu.cpp @@ -49,7 +49,7 @@ GrGpu::GrGpu(GrContext* context) poolState.fPoolStartIndex = DEBUG_INVAL_START_IDX; #endif - for (int i = 0; i < kGrPixelConfigCount; ++i) { + for (int i = 0; i < kGrPixelConfigCnt; ++i) { fConfigRenderSupport[i] = false; }; } diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h index 41ebb73cef..602197b582 100644 --- a/src/gpu/GrGpu.h +++ b/src/gpu/GrGpu.h @@ -299,7 +299,7 @@ public: * Can the provided configuration act as a color render target? */ bool isConfigRenderable(GrPixelConfig config) const { - GrAssert(kGrPixelConfigCount > config); + GrAssert(kGrPixelConfigCnt > config); return fConfigRenderSupport[config]; } @@ -403,7 +403,7 @@ protected: // Derived classes need access to this so they can fill it out in their // constructors - bool fConfigRenderSupport[kGrPixelConfigCount]; + bool fConfigRenderSupport[kGrPixelConfigCnt]; // Helpers for setting up geometry state void finalizeReservedVertices(); diff --git a/src/gpu/GrTextureAccess.cpp b/src/gpu/GrTextureAccess.cpp index 5c3a36dce3..499b1f237f 100644 --- a/src/gpu/GrTextureAccess.cpp +++ b/src/gpu/GrTextureAccess.cpp @@ -6,7 +6,7 @@ */ #include "GrTextureAccess.h" - +#include "GrColor.h" #include "GrTexture.h" GrTextureAccess::GrTextureAccess() { @@ -68,7 +68,7 @@ void GrTextureAccess::reset(GrTexture* texture, fTexture.reset(SkRef(texture)); fParams = params; memcpy(fSwizzle, "rgba", 5); - fSwizzleMask = (kRGB_SwizzleMask | kA_SwizzleFlag); + fSwizzleMask = kRGBA_GrColorComponentFlags; } void GrTextureAccess::reset(GrTexture* texture, @@ -78,7 +78,7 @@ void GrTextureAccess::reset(GrTexture* texture, fTexture.reset(SkRef(texture)); fParams.reset(tileXAndY, bilerp); memcpy(fSwizzle, "rgba", 5); - fSwizzleMask = (kRGB_SwizzleMask | kA_SwizzleFlag); + fSwizzleMask = kRGBA_GrColorComponentFlags; } void GrTextureAccess::setSwizzle(const char* swizzle) { @@ -88,16 +88,16 @@ void GrTextureAccess::setSwizzle(const char* swizzle) { fSwizzle[i] = swizzle[i]; switch (swizzle[i]) { case 'r': - fSwizzleMask |= kR_SwizzleFlag; + fSwizzleMask |= kR_GrColorComponentFlag; break; case 'g': - fSwizzleMask |= kG_SwizzleFlag; + fSwizzleMask |= kG_GrColorComponentFlag; break; case 'b': - fSwizzleMask |= kB_SwizzleFlag; + fSwizzleMask |= kB_GrColorComponentFlag; break; case 'a': - fSwizzleMask |= kA_SwizzleFlag; + fSwizzleMask |= kA_GrColorComponentFlag; break; default: GrCrash("Unexpected swizzle string character."); diff --git a/src/gpu/effects/GrSingleTextureEffect.h b/src/gpu/effects/GrSingleTextureEffect.h index 82037cf6e9..3e0af65fcb 100644 --- a/src/gpu/effects/GrSingleTextureEffect.h +++ b/src/gpu/effects/GrSingleTextureEffect.h @@ -54,9 +54,9 @@ protected: * texture. */ void updateConstantColorComponentsForModulation(GrColor* color, uint32_t* validFlags) const { - if ((*validFlags & kA_ValidComponentFlag) && 0xFF == GrColorUnpackA(*color) && + if ((*validFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUnpackA(*color) && GrPixelConfigIsOpaque(this->texture(0)->config())) { - *validFlags = kA_ValidComponentFlag; + *validFlags = kA_GrColorComponentFlag; } else { *validFlags = 0; } diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp index 5e555f9653..1f3cf16464 100644 --- a/src/gpu/gl/GrGLCaps.cpp +++ b/src/gpu/gl/GrGLCaps.cpp @@ -462,7 +462,7 @@ void GrGLCaps::markColorConfigAndStencilFormatAsVerified( #if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT return; #endif - GrAssert((unsigned)config < kGrPixelConfigCount); + GrAssert((unsigned)config < kGrPixelConfigCnt); GrAssert(fStencilFormats.count() == fStencilVerifiedColorConfigs.count()); int count = fStencilFormats.count(); // we expect a really small number of possible formats so linear search @@ -485,7 +485,7 @@ bool GrGLCaps::isColorConfigAndStencilFormatVerified( #if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT return false; #endif - GrAssert((unsigned)config < kGrPixelConfigCount); + GrAssert((unsigned)config < kGrPixelConfigCnt); int count = fStencilFormats.count(); // we expect a really small number of possible formats so linear search // should be OK diff --git a/src/gpu/gl/GrGLCaps.h b/src/gpu/gl/GrGLCaps.h index 920140f1e6..4599e57bdf 100644 --- a/src/gpu/gl/GrGLCaps.h +++ b/src/gpu/gl/GrGLCaps.h @@ -252,7 +252,7 @@ private: } } - static const int kNumUints = (kGrPixelConfigCount + 31) / 32; + static const int kNumUints = (kGrPixelConfigCnt + 31) / 32; uint32_t fVerifiedColorConfigs[kNumUints]; void markVerified(GrPixelConfig config) { diff --git a/src/gpu/gl/GrGLShaderBuilder.cpp b/src/gpu/gl/GrGLShaderBuilder.cpp index 3808402ab4..a5c96c7dd6 100644 --- a/src/gpu/gl/GrGLShaderBuilder.cpp +++ b/src/gpu/gl/GrGLShaderBuilder.cpp @@ -40,10 +40,10 @@ inline const char* sample_function_name(GrSLType type, GrGLSLGeneration glslGen) inline bool swizzle_requires_alpha_remapping(const GrGLCaps& caps, const GrTextureAccess& access) { if (GrPixelConfigIsAlphaOnly(access.getTexture()->config())) { - if (caps.textureRedSupport() && (GrTextureAccess::kA_SwizzleFlag & access.swizzleMask())) { + if (caps.textureRedSupport() && (kA_GrColorComponentFlag & access.swizzleMask())) { return true; } - if (GrTextureAccess::kRGB_SwizzleMask & access.swizzleMask()) { + if (kRGB_GrColorComponentFlags & access.swizzleMask()) { return true; } } @@ -51,14 +51,15 @@ inline bool swizzle_requires_alpha_remapping(const GrGLCaps& caps, } void append_swizzle(SkString* outAppend, - const GrTextureAccess& access, + const GrGLShaderBuilder::TextureSampler& texSampler, const GrGLCaps& caps) { - const char* swizzle = access.getSwizzle(); + const char* swizzle = texSampler.swizzle(); char mangledSwizzle[5]; // The swizzling occurs using texture params instead of shader-mangling if ARB_texture_swizzle // is available. - if (!caps.textureSwizzleSupport() && GrPixelConfigIsAlphaOnly(access.getTexture()->config())) { + if (!caps.textureSwizzleSupport() && + (kA_GrColorComponentFlag == texSampler.configComponentMask())) { char alphaChar = caps.textureRedSupport() ? 'r' : 'a'; int i; for (i = 0; '\0' != swizzle[i]; ++i) { @@ -151,14 +152,13 @@ void GrGLShaderBuilder::appendTextureLookup(SkString* out, const GrGLShaderBuilder::TextureSampler& sampler, const char* coordName, GrSLType varyingType) const { - GrAssert(NULL != sampler.textureAccess()); GrAssert(NULL != coordName); out->appendf("%s(%s, %s)", sample_function_name(varyingType, fCtxInfo.glslGeneration()), this->getUniformCStr(sampler.fSamplerUniform), coordName); - append_swizzle(out, *sampler.textureAccess(), *fCtxInfo.caps()); + append_swizzle(out, sampler, *fCtxInfo.caps()); } void GrGLShaderBuilder::appendTextureLookup(ShaderType type, @@ -191,17 +191,6 @@ GrBackendEffectFactory::EffectKey GrGLShaderBuilder::KeyForTextureAccess( if (!caps.textureSwizzleSupport() && swizzle_requires_alpha_remapping(caps, access)) { key = 1; } -#if GR_DEBUG - // Assert that key is set iff the swizzle will be modified. - SkString origString(access.getSwizzle()); - origString.prepend("."); - SkString modifiedString; - append_swizzle(&modifiedString, access, caps); - if (!modifiedString.size()) { - modifiedString = ".rgba"; - } - GrAssert(SkToBool(key) == (modifiedString != origString)); -#endif return key; } diff --git a/src/gpu/gl/GrGLShaderBuilder.h b/src/gpu/gl/GrGLShaderBuilder.h index 9d64143802..d947771b3e 100644 --- a/src/gpu/gl/GrGLShaderBuilder.h +++ b/src/gpu/gl/GrGLShaderBuilder.h @@ -10,6 +10,7 @@ #include "GrAllocator.h" #include "GrBackendEffectFactory.h" +#include "GrColor.h" #include "GrEffect.h" #include "gl/GrGLSL.h" #include "gl/GrGLUniformManager.h" @@ -31,31 +32,40 @@ public: class TextureSampler { public: TextureSampler() - : fTextureAccess(NULL) - , fSamplerUniform(GrGLUniformManager::kInvalidUniformHandle) {} + : fConfigComponentMask(0) + , fSamplerUniform(GrGLUniformManager::kInvalidUniformHandle) { + // we will memcpy the first 4 bytes from passed in swizzle. This ensures the string is + // terminated. + fSwizzle[4] = '\0'; + } TextureSampler(const TextureSampler& other) { *this = other; } TextureSampler& operator= (const TextureSampler& other) { - GrAssert(NULL == fTextureAccess); + GrAssert(0 == fConfigComponentMask); GrAssert(GrGLUniformManager::kInvalidUniformHandle == fSamplerUniform); - fTextureAccess = other.fTextureAccess; + fConfigComponentMask = other.fConfigComponentMask; fSamplerUniform = other.fSamplerUniform; return *this; } - const GrTextureAccess* textureAccess() const { return fTextureAccess; } + // bitfield of GrColorComponentFlags present in the texture's config. + uint32_t configComponentMask() const { return fConfigComponentMask; } + + const char* swizzle() const { return fSwizzle; } private: // The idx param is used to ensure multiple samplers within a single effect have unique - // uniform names. - void init(GrGLShaderBuilder* builder, const GrTextureAccess* access, int idx) { - GrAssert(NULL == fTextureAccess); + // uniform names. swizzle is a four char max string made up of chars 'r', 'g', 'b', and 'a'. + void init(GrGLShaderBuilder* builder, + uint32_t configComponentMask, + const char* swizzle, + int idx) { + GrAssert(0 == fConfigComponentMask); GrAssert(GrGLUniformManager::kInvalidUniformHandle == fSamplerUniform); GrAssert(NULL != builder); - GrAssert(NULL != access); SkString name; name.printf("Sampler%d_", idx); fSamplerUniform = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, @@ -63,14 +73,23 @@ public: name.c_str()); GrAssert(GrGLUniformManager::kInvalidUniformHandle != fSamplerUniform); - fTextureAccess = access; + fConfigComponentMask = configComponentMask; + memcpy(fSwizzle, swizzle, 4); + } + + void init(GrGLShaderBuilder* builder, const GrTextureAccess* access, int idx) { + GrAssert(NULL != access); + this->init(builder, + GrPixelConfigComponentMask(access->getTexture()->config()), + access->getSwizzle(), + idx); } - const GrTextureAccess* fTextureAccess; + uint32_t fConfigComponentMask; + char fSwizzle[5]; GrGLUniformManager::UniformHandle fSamplerUniform; - friend class GrGLShaderBuilder; // to access fSamplerUniform - friend class GrGLProgram; // to construct these and access fSamplerUniform. + friend class GrGLShaderBuilder; // to call init(). }; typedef SkTArray TextureSamplerArray; -- cgit v1.2.3