| 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 GrGLSLCaps& caps, GrPixelConf
ig config) { | 21 static bool swizzle_requires_alpha_remapping(const GrGLCaps& caps, |
| 22 if (!caps.mustSwizzleInShader()) { | 22 uint32_t configComponentMask, |
| 23 uint32_t swizzleComponentMask) { |
| 24 if (caps.textureSwizzleSupport()) { |
| 23 // Any remapping is handled using texture swizzling not shader modificat
ions. | 25 // Any remapping is handled using texture swizzling not shader modificat
ions. |
| 24 return false; | 26 return false; |
| 25 } | 27 } |
| 26 const char* swizzleMap = caps.getSwizzleMap(config); | 28 // check if the texture is alpha-only |
| 27 | 29 if (kA_GrColorComponentFlag == configComponentMask) { |
| 28 return SkToBool(memcmp(swizzleMap, "rgba", 4)); | 30 if (caps.textureRedSupport() && (kA_GrColorComponentFlag & swizzleCompon
entMask)) { |
| 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; |
| 29 } | 41 } |
| 30 | 42 |
| 31 static uint32_t gen_texture_key(const GrProcessor& proc, const GrGLCaps& caps) { | 43 static uint32_t gen_texture_key(const GrProcessor& proc, const GrGLCaps& caps) { |
| 32 uint32_t key = 0; | 44 uint32_t key = 0; |
| 33 int numTextures = proc.numTextures(); | 45 int numTextures = proc.numTextures(); |
| 34 for (int t = 0; t < numTextures; ++t) { | 46 for (int t = 0; t < numTextures; ++t) { |
| 35 const GrTextureAccess& access = proc.textureAccess(t); | 47 const GrTextureAccess& access = proc.textureAccess(t); |
| 36 if (swizzle_requires_alpha_remapping(*caps.glslCaps(), access.getTexture
()->config())) { | 48 uint32_t configComponentMask = GrPixelConfigComponentMask(access.getText
ure()->config()); |
| 49 if (swizzle_requires_alpha_remapping(caps, configComponentMask, access.s
wizzleMask())) { |
| 37 key |= 1 << t; | 50 key |= 1 << t; |
| 38 } | 51 } |
| 39 } | 52 } |
| 40 return key; | 53 return key; |
| 41 } | 54 } |
| 42 | 55 |
| 43 /** | 56 /** |
| 44 * A function which emits a meta key into the key builder. This is required bec
ause shader code may | 57 * A function which emits a meta key into the key builder. This is required bec
ause shader code may |
| 45 * be dependent on properties of the effect that the effect itself doesn't use | 58 * be dependent on properties of the effect that the effect itself doesn't use |
| 46 * in its key (e.g. the pixel format of textures used). So we create a meta-key
for | 59 * 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... |
| 149 GrGLFragmentShaderBuilder::KeyForFragmentPosition(pipeline.getRe
nderTarget()); | 162 GrGLFragmentShaderBuilder::KeyForFragmentPosition(pipeline.getRe
nderTarget()); |
| 150 } else { | 163 } else { |
| 151 header->fFragPosKey = 0; | 164 header->fFragPosKey = 0; |
| 152 } | 165 } |
| 153 header->fSnapVerticesToPixelCenters = pipeline.snapVerticesToPixelCenters(); | 166 header->fSnapVerticesToPixelCenters = pipeline.snapVerticesToPixelCenters(); |
| 154 header->fColorEffectCnt = pipeline.numColorFragmentProcessors(); | 167 header->fColorEffectCnt = pipeline.numColorFragmentProcessors(); |
| 155 header->fCoverageEffectCnt = pipeline.numCoverageFragmentProcessors(); | 168 header->fCoverageEffectCnt = pipeline.numCoverageFragmentProcessors(); |
| 156 glDesc->finalize(); | 169 glDesc->finalize(); |
| 157 return true; | 170 return true; |
| 158 } | 171 } |
| OLD | NEW |