| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 #include "GrGLProgramDesc.h" | 7 #include "GrGLProgramDesc.h" |
| 8 | 8 |
| 9 #include "GrGLFragmentProcessor.h" | 9 #include "GrGLFragmentProcessor.h" |
| 10 #include "GrProcessor.h" | 10 #include "GrProcessor.h" |
| 11 #include "GrGLGpu.h" | 11 #include "GrGLGpu.h" |
| 12 #include "GrPipeline.h" | 12 #include "GrPipeline.h" |
| 13 #include "SkChecksum.h" | 13 #include "SkChecksum.h" |
| 14 #include "gl/builders/GrGLFragmentShaderBuilder.h" | 14 #include "gl/builders/GrGLFragmentShaderBuilder.h" |
| 15 | 15 |
| 16 /** | 16 /** |
| 17 * Do we need to either map r,g,b->a or a->r. configComponentMask indicates whic
h channels are | 17 * Do we need to either map r,g,b->a or a->r. configComponentMask indicates whic
h channels are |
| 18 * present in the texture's config. swizzleComponentMask indicates the channels
present in the | 18 * present in the texture's config. swizzleComponentMask indicates the channels
present in the |
| 19 * shader swizzle. | 19 * shader swizzle. |
| 20 */ | 20 */ |
| 21 static bool swizzle_requires_alpha_remapping(const GrGLCaps& caps, | 21 static bool swizzle_requires_alpha_remapping(const GrGLSLCaps& caps, GrPixelConf
ig config) { |
| 22 uint32_t configComponentMask, | 22 if (!caps.mustSwizzleInShader()) { |
| 23 uint32_t swizzleComponentMask) { | |
| 24 if (caps.textureSwizzleSupport()) { | |
| 25 // Any remapping is handled using texture swizzling not shader modificat
ions. | 23 // Any remapping is handled using texture swizzling not shader modificat
ions. |
| 26 return false; | 24 return false; |
| 27 } | 25 } |
| 28 // check if the texture is alpha-only | 26 const char* swizzleMap = caps.getSwizzleMap(config); |
| 29 if (kA_GrColorComponentFlag == configComponentMask) { | 27 |
| 30 if (caps.textureRedSupport() && (kA_GrColorComponentFlag & swizzleCompon
entMask)) { | 28 return SkToBool(memcmp(swizzleMap, "rgba", 4)); |
| 31 // we must map the swizzle 'a's to 'r'. | |
| 32 return true; | |
| 33 } | |
| 34 if (kRGB_GrColorComponentFlags & swizzleComponentMask) { | |
| 35 // The 'r', 'g', and/or 'b's must be mapped to 'a' according to our
semantics that | |
| 36 // alpha-only textures smear alpha across all four channels when rea
d. | |
| 37 return true; | |
| 38 } | |
| 39 } | |
| 40 return false; | |
| 41 } | 29 } |
| 42 | 30 |
| 43 static uint32_t gen_texture_key(const GrProcessor& proc, const GrGLCaps& caps) { | 31 static uint32_t gen_texture_key(const GrProcessor& proc, const GrGLCaps& caps) { |
| 44 uint32_t key = 0; | 32 uint32_t key = 0; |
| 45 int numTextures = proc.numTextures(); | 33 int numTextures = proc.numTextures(); |
| 46 for (int t = 0; t < numTextures; ++t) { | 34 for (int t = 0; t < numTextures; ++t) { |
| 47 const GrTextureAccess& access = proc.textureAccess(t); | 35 const GrTextureAccess& access = proc.textureAccess(t); |
| 48 uint32_t configComponentMask = GrPixelConfigComponentMask(access.getText
ure()->config()); | 36 if (swizzle_requires_alpha_remapping(*caps.glslCaps(), access.getTexture
()->config())) { |
| 49 if (swizzle_requires_alpha_remapping(caps, configComponentMask, access.s
wizzleMask())) { | |
| 50 key |= 1 << t; | 37 key |= 1 << t; |
| 51 } | 38 } |
| 52 } | 39 } |
| 53 return key; | 40 return key; |
| 54 } | 41 } |
| 55 | 42 |
| 56 /** | 43 /** |
| 57 * A function which emits a meta key into the key builder. This is required bec
ause shader code may | 44 * A function which emits a meta key into the key builder. This is required bec
ause shader code may |
| 58 * be dependent on properties of the effect that the effect itself doesn't use | 45 * be dependent on properties of the effect that the effect itself doesn't use |
| 59 * in its key (e.g. the pixel format of textures used). So we create a meta-key
for | 46 * in its key (e.g. the pixel format of textures used). So we create a meta-key
for |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 GrGLFragmentShaderBuilder::KeyForFragmentPosition(pipeline.getRe
nderTarget()); | 149 GrGLFragmentShaderBuilder::KeyForFragmentPosition(pipeline.getRe
nderTarget()); |
| 163 } else { | 150 } else { |
| 164 header->fFragPosKey = 0; | 151 header->fFragPosKey = 0; |
| 165 } | 152 } |
| 166 header->fSnapVerticesToPixelCenters = pipeline.snapVerticesToPixelCenters(); | 153 header->fSnapVerticesToPixelCenters = pipeline.snapVerticesToPixelCenters(); |
| 167 header->fColorEffectCnt = pipeline.numColorFragmentProcessors(); | 154 header->fColorEffectCnt = pipeline.numColorFragmentProcessors(); |
| 168 header->fCoverageEffectCnt = pipeline.numCoverageFragmentProcessors(); | 155 header->fCoverageEffectCnt = pipeline.numCoverageFragmentProcessors(); |
| 169 glDesc->finalize(); | 156 glDesc->finalize(); |
| 170 return true; | 157 return true; |
| 171 } | 158 } |
| OLD | NEW |