GrCustomStage::StageKey GrGLShaderBuilder::KeyForTextureAccess(const GrTextureAccess& access, const GrGLCaps& caps) { GrCustomStage::StageKey key = 0; // Assume that swizzle support implies that we never have to modify a shader to adjust // for texture format/swizzle settings. if (caps.textureSwizzleSupport()) { return key; } if (texture_requires_alpha_to_red_swizzle(caps, access)) { key = 1; } return key; }
GrGLShaderBuilder::DstReadKey GrGLShaderBuilder::KeyForDstRead(const GrTexture* dstCopy, const GrGLCaps& caps) { uint32_t key = kYesDstRead_DstReadKeyBit; if (caps.fbFetchSupport()) { return key; } SkASSERT(NULL != dstCopy); if (!caps.textureSwizzleSupport() && GrPixelConfigIsAlphaOnly(dstCopy->config())) { // The fact that the config is alpha-only must be considered when generating code. key |= kUseAlphaConfig_DstReadKeyBit; } if (kTopLeft_GrSurfaceOrigin == dstCopy->origin()) { key |= kTopLeftOrigin_DstReadKeyBit; } SkASSERT(static_cast<DstReadKey>(key) == key); return static_cast<DstReadKey>(key); }
/** * Do we need to either map r,g,b->a or a->r. configComponentMask indicates which channels are * present in the texture's config. swizzleComponentMask indicates the channels present in the * shader swizzle. */ static bool swizzle_requires_alpha_remapping(const GrGLCaps& caps, uint32_t configComponentMask, uint32_t swizzleComponentMask) { if (caps.textureSwizzleSupport()) { // Any remapping is handled using texture swizzling not shader modifications. return false; } // check if the texture is alpha-only if (kA_GrColorComponentFlag == configComponentMask) { if (caps.textureRedSupport() && (kA_GrColorComponentFlag & swizzleComponentMask)) { // we must map the swizzle 'a's to 'r'. return true; } if (kRGB_GrColorComponentFlags & swizzleComponentMask) { // The 'r', 'g', and/or 'b's must be mapped to 'a' according to our semantics that // alpha-only textures smear alpha across all four channels when read. return true; } } return false; }
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. 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; }