diff options
author | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-03-28 13:46:42 +0000 |
---|---|---|
committer | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-03-28 13:46:42 +0000 |
commit | c3abb7baff528b64f175e08350a92a0d72ca24be (patch) | |
tree | 1c7d5f5add169b4b6dcbef689beae307510f114f | |
parent | f99c97497d5b682825a2dade1892d6466227e74c (diff) | |
download | src-c3abb7baff528b64f175e08350a92a0d72ca24be.tar.gz |
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/src@8428 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | effects/SkBlendImageFilter.cpp | 2 | ||||
-rw-r--r-- | effects/SkColorMatrixFilter.cpp | 12 | ||||
-rw-r--r-- | effects/SkTableColorFilter.cpp | 8 | ||||
-rw-r--r-- | effects/gradients/SkGradientShader.cpp | 4 | ||||
-rw-r--r-- | gpu/GrDrawState.cpp | 8 | ||||
-rw-r--r-- | gpu/GrGpu.cpp | 2 | ||||
-rw-r--r-- | gpu/GrGpu.h | 4 | ||||
-rw-r--r-- | gpu/GrTextureAccess.cpp | 14 | ||||
-rw-r--r-- | gpu/effects/GrSingleTextureEffect.h | 4 | ||||
-rw-r--r-- | gpu/gl/GrGLCaps.cpp | 4 | ||||
-rw-r--r-- | gpu/gl/GrGLCaps.h | 2 | ||||
-rw-r--r-- | gpu/gl/GrGLShaderBuilder.cpp | 25 | ||||
-rw-r--r-- | gpu/gl/GrGLShaderBuilder.h | 45 |
13 files changed, 71 insertions, 63 deletions
diff --git a/effects/SkBlendImageFilter.cpp b/effects/SkBlendImageFilter.cpp index 1c85fe5f..330e87d7 100644 --- a/effects/SkBlendImageFilter.cpp +++ b/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/effects/SkColorMatrixFilter.cpp b/effects/SkColorMatrixFilter.cpp index c2ab3fd7..661544bf 100644 --- a/effects/SkColorMatrixFilter.cpp +++ b/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/effects/SkTableColorFilter.cpp b/effects/SkTableColorFilter.cpp index d20283f5..9979fae2 100644 --- a/effects/SkTableColorFilter.cpp +++ b/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/effects/gradients/SkGradientShader.cpp b/effects/gradients/SkGradientShader.cpp index d3b2fd41..684355d5 100644 --- a/effects/gradients/SkGradientShader.cpp +++ b/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/gpu/GrDrawState.cpp b/gpu/GrDrawState.cpp index e1089995..f9e12cc2 100644 --- a/gpu/GrDrawState.cpp +++ b/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/gpu/GrGpu.cpp b/gpu/GrGpu.cpp index c9e876a7..73e4d3e4 100644 --- a/gpu/GrGpu.cpp +++ b/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/gpu/GrGpu.h b/gpu/GrGpu.h index 41ebb73c..602197b5 100644 --- a/gpu/GrGpu.h +++ b/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/gpu/GrTextureAccess.cpp b/gpu/GrTextureAccess.cpp index 5c3a36dc..499b1f23 100644 --- a/gpu/GrTextureAccess.cpp +++ b/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/gpu/effects/GrSingleTextureEffect.h b/gpu/effects/GrSingleTextureEffect.h index 82037cf6..3e0af65f 100644 --- a/gpu/effects/GrSingleTextureEffect.h +++ b/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/gpu/gl/GrGLCaps.cpp b/gpu/gl/GrGLCaps.cpp index 5e555f96..1f3cf164 100644 --- a/gpu/gl/GrGLCaps.cpp +++ b/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/gpu/gl/GrGLCaps.h b/gpu/gl/GrGLCaps.h index 920140f1..4599e57b 100644 --- a/gpu/gl/GrGLCaps.h +++ b/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/gpu/gl/GrGLShaderBuilder.cpp b/gpu/gl/GrGLShaderBuilder.cpp index 3808402a..a5c96c7d 100644 --- a/gpu/gl/GrGLShaderBuilder.cpp +++ b/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/gpu/gl/GrGLShaderBuilder.h b/gpu/gl/GrGLShaderBuilder.h index 9d641438..d947771b 100644 --- a/gpu/gl/GrGLShaderBuilder.h +++ b/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<TextureSampler> TextureSamplerArray; |