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 "GrProcessor.h" | 9 #include "GrProcessor.h" |
10 #include "GrGLGpu.h" | 10 #include "GrGLGpu.h" |
11 #include "GrPipeline.h" | 11 #include "GrPipeline.h" |
12 #include "SkChecksum.h" | 12 #include "SkChecksum.h" |
13 #include "glsl/GrGLSLFragmentProcessor.h" | 13 #include "glsl/GrGLSLFragmentProcessor.h" |
14 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 14 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
15 | 15 |
| 16 /** |
| 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 |
| 19 * shader swizzle. |
| 20 */ |
| 21 static bool swizzle_requires_alpha_remapping(const GrGLSLCaps& caps, GrPixelConf
ig config) { |
| 22 if (!caps.mustSwizzleInShader()) { |
| 23 // Any remapping is handled using texture swizzling not shader modificat
ions. |
| 24 return false; |
| 25 } |
| 26 const char* swizzleMap = caps.getSwizzleMap(config); |
| 27 |
| 28 return SkToBool(memcmp(swizzleMap, "rgba", 4)); |
| 29 } |
16 | 30 |
17 static void add_texture_key(GrProcessorKeyBuilder* b, const GrProcessor& proc, | 31 static uint32_t gen_texture_key(const GrProcessor& proc, const GrGLCaps& caps) { |
18 const GrGLSLCaps& caps) { | 32 uint32_t key = 0; |
19 int numTextures = proc.numTextures(); | 33 int numTextures = proc.numTextures(); |
20 // Need two bytes per key (swizzle and target). | 34 int shift = 0; |
21 int word32Count = (proc.numTextures() + 1) / 2; | 35 for (int t = 0; t < numTextures; ++t) { |
22 if (0 == word32Count) { | 36 const GrTextureAccess& access = proc.textureAccess(t); |
23 return; | 37 if (swizzle_requires_alpha_remapping(*caps.glslCaps(), access.getTexture
()->config())) { |
| 38 key |= 1 << shift; |
| 39 } |
| 40 if (GR_GL_TEXTURE_EXTERNAL == static_cast<GrGLTexture*>(access.getTextur
e())->target()) { |
| 41 key |= 2 << shift; |
| 42 } |
| 43 shift += 2; |
24 } | 44 } |
25 uint16_t* k16 = SkTCast<uint16_t*>(b->add32n(word32Count)); | 45 return key; |
26 for (int i = 0; i < numTextures; ++i) { | |
27 const GrTextureAccess& access = proc.textureAccess(i); | |
28 bool isExternal = (GR_GL_TEXTURE_EXTERNAL == | |
29 static_cast<GrGLTexture*>(access.getTexture())->targe
t()); | |
30 k16[i] = caps.configTextureSwizzle(access.getTexture()->config()).asKey(
) | | |
31 (isExternal ? 0xFF00 : 0x0000); | |
32 } | |
33 } | 46 } |
34 | 47 |
35 /** | 48 /** |
36 * A function which emits a meta key into the key builder. This is required bec
ause shader code may | 49 * A function which emits a meta key into the key builder. This is required bec
ause shader code may |
37 * be dependent on properties of the effect that the effect itself doesn't use | 50 * be dependent on properties of the effect that the effect itself doesn't use |
38 * in its key (e.g. the pixel format of textures used). So we create a meta-key
for | 51 * in its key (e.g. the pixel format of textures used). So we create a meta-key
for |
39 * every effect using this function. It is also responsible for inserting the ef
fect's class ID | 52 * every effect using this function. It is also responsible for inserting the ef
fect's class ID |
40 * which must be different for every GrProcessor subclass. It can fail if an eff
ect uses too many | 53 * which must be different for every GrProcessor subclass. It can fail if an eff
ect uses too many |
41 * transforms, etc, for the space allotted in the meta-key. NOTE, both FPs and
GPs share this | 54 * textures, transforms, etc, for the space allotted in the meta-key. NOTE, bot
h FPs and GPs share |
42 * function because it is hairy, though FPs do not have attribs, and GPs do not
have transforms | 55 * this function because it is hairy, though FPs do not have attribs, and GPs do
not have transforms |
43 */ | 56 */ |
44 static bool gen_meta_key(const GrProcessor& proc, | 57 static bool gen_meta_key(const GrProcessor& proc, |
45 const GrGLCaps& caps, | 58 const GrGLCaps& caps, |
46 uint32_t transformKey, | 59 uint32_t transformKey, |
47 GrProcessorKeyBuilder* b) { | 60 GrProcessorKeyBuilder* b) { |
48 size_t processorKeySize = b->size(); | 61 size_t processorKeySize = b->size(); |
| 62 uint32_t textureKey = gen_texture_key(proc, caps); |
49 uint32_t classID = proc.classID(); | 63 uint32_t classID = proc.classID(); |
50 | 64 |
51 // Currently we allow 16 bits for the class id and the overall processor key
size. | 65 // Currently we allow 16 bits for the class id and the overall processor key
size. |
52 static const uint32_t kMetaKeyInvalidMask = ~((uint32_t) SK_MaxU16); | 66 static const uint32_t kMetaKeyInvalidMask = ~((uint32_t) SK_MaxU16); |
53 if ((processorKeySize | classID) & kMetaKeyInvalidMask) { | 67 if ((processorKeySize | classID) & kMetaKeyInvalidMask) { |
54 return false; | 68 return false; |
55 } | 69 } |
56 | 70 |
57 add_texture_key(b, proc, *caps.glslCaps()); | 71 uint32_t* key = b->add32n(3); |
58 | |
59 uint32_t* key = b->add32n(2); | |
60 key[0] = (classID << 16) | SkToU32(processorKeySize); | 72 key[0] = (classID << 16) | SkToU32(processorKeySize); |
61 key[1] = transformKey; | 73 key[1] = textureKey; |
| 74 key[2] = transformKey; |
62 return true; | 75 return true; |
63 } | 76 } |
64 | 77 |
65 static bool gen_frag_proc_and_meta_keys(const GrPrimitiveProcessor& primProc, | 78 static bool gen_frag_proc_and_meta_keys(const GrPrimitiveProcessor& primProc, |
66 const GrFragmentProcessor& fp, | 79 const GrFragmentProcessor& fp, |
67 const GrGLCaps& caps, | 80 const GrGLCaps& caps, |
68 GrProcessorKeyBuilder* b) { | 81 GrProcessorKeyBuilder* b) { |
69 for (int i = 0; i < fp.numChildProcessors(); ++i) { | 82 for (int i = 0; i < fp.numChildProcessors(); ++i) { |
70 if (!gen_frag_proc_and_meta_keys(primProc, fp.childProcessor(i), caps, b
)) { | 83 if (!gen_frag_proc_and_meta_keys(primProc, fp.childProcessor(i), caps, b
)) { |
71 return false; | 84 return false; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 } else { | 153 } else { |
141 header->fIgnoresCoverage = 0; | 154 header->fIgnoresCoverage = 0; |
142 } | 155 } |
143 | 156 |
144 header->fSnapVerticesToPixelCenters = pipeline.snapVerticesToPixelCenters(); | 157 header->fSnapVerticesToPixelCenters = pipeline.snapVerticesToPixelCenters(); |
145 header->fColorEffectCnt = pipeline.numColorFragmentProcessors(); | 158 header->fColorEffectCnt = pipeline.numColorFragmentProcessors(); |
146 header->fCoverageEffectCnt = pipeline.numCoverageFragmentProcessors(); | 159 header->fCoverageEffectCnt = pipeline.numCoverageFragmentProcessors(); |
147 glDesc->finalize(); | 160 glDesc->finalize(); |
148 return true; | 161 return true; |
149 } | 162 } |
OLD | NEW |