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 "GrPipeline.h" | 10 #include "GrPipeline.h" |
11 #include "GrRenderTargetPriv.h" | 11 #include "GrRenderTargetPriv.h" |
12 #include "SkChecksum.h" | 12 #include "SkChecksum.h" |
13 #include "gl/GrGLDefines.h" | 13 #include "gl/GrGLDefines.h" |
14 #include "gl/GrGLTexture.h" | 14 #include "gl/GrGLTexture.h" |
15 #include "gl/GrGLTypes.h" | 15 #include "gl/GrGLTypes.h" |
16 #include "glsl/GrGLSLFragmentProcessor.h" | 16 #include "glsl/GrGLSLFragmentProcessor.h" |
17 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 17 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
18 #include "glsl/GrGLSLCaps.h" | 18 #include "glsl/GrGLSLCaps.h" |
19 | 19 |
20 static uint8_t texture_target_key(GrGLenum target) { | 20 static uint16_t texture_key(GrSLType samplerType, GrPixelConfig config, GrShader
Flags visibility, |
21 switch (target) { | 21 const GrGLSLCaps& caps) { |
22 case GR_GL_TEXTURE_2D: | 22 enum { |
23 return 0; | 23 kFirstSamplerType = kSampler2D_GrSLType, |
24 case GR_GL_TEXTURE_EXTERNAL: | 24 kLastSamplerType = kSampler2DRect_GrSLType, |
25 return 1; | 25 kSamplerTypeKeyBits = 4 |
26 case GR_GL_TEXTURE_RECTANGLE: | 26 }; |
27 return 2; | 27 GR_STATIC_ASSERT(kLastSamplerType - kFirstSamplerType < (1 << kSamplerTypeKe
yBits)); |
28 default: | 28 |
29 SkFAIL("Unexpected texture target."); | 29 SkASSERT((int)samplerType >= kFirstSamplerType && (int)samplerType <= kLastS
amplerType); |
30 return 0; | 30 int samplerTypeKey = samplerType - kFirstSamplerType; |
31 } | 31 |
| 32 return SkToU16(caps.configTextureSwizzle(config).asKey() | |
| 33 (samplerTypeKey << 8) | |
| 34 (caps.samplerPrecision(config, visibility) << (8 + kSamplerTy
peKeyBits))); |
32 } | 35 } |
33 | 36 |
34 static void add_texture_key(GrProcessorKeyBuilder* b, const GrProcessor& proc, | 37 static void add_texture_key(GrProcessorKeyBuilder* b, const GrProcessor& proc, |
35 const GrGLSLCaps& caps) { | 38 const GrGLSLCaps& caps) { |
36 int numTextures = proc.numTextures(); | 39 int numTextures = proc.numTextures(); |
37 // Need two bytes per key (swizzle and target). | 40 // Need two bytes per key (swizzle, sampler type, and precision). |
38 int word32Count = (proc.numTextures() + 1) / 2; | 41 int word32Count = (proc.numTextures() + 1) / 2; |
39 if (0 == word32Count) { | 42 if (0 == word32Count) { |
40 return; | 43 return; |
41 } | 44 } |
42 uint16_t* k16 = SkTCast<uint16_t*>(b->add32n(word32Count)); | 45 uint16_t* k16 = SkTCast<uint16_t*>(b->add32n(word32Count)); |
43 for (int i = 0; i < numTextures; ++i) { | 46 for (int i = 0; i < numTextures; ++i) { |
44 const GrTextureAccess& access = proc.textureAccess(i); | 47 const GrTextureAccess& access = proc.textureAccess(i); |
45 GrGLTexture* texture = static_cast<GrGLTexture*>(access.getTexture()); | 48 const GrTexture* tex = access.getTexture(); |
46 k16[i] = SkToU16(caps.configTextureSwizzle(texture->config()).asKey() | | 49 k16[i] = texture_key(tex->samplerType(), tex->config(), access.getVisibi
lity(), caps); |
47 (texture_target_key(texture->target()) << 8)); | |
48 } | 50 } |
49 // zero the last 16 bits if the number of textures is odd. | 51 // zero the last 16 bits if the number of textures is odd. |
50 if (numTextures & 0x1) { | 52 if (numTextures & 0x1) { |
51 k16[numTextures] = 0; | 53 k16[numTextures] = 0; |
52 } | 54 } |
53 } | 55 } |
54 | 56 |
55 /** | 57 /** |
56 * A function which emits a meta key into the key builder. This is required bec
ause shader code may | 58 * A function which emits a meta key into the key builder. This is required bec
ause shader code may |
57 * be dependent on properties of the effect that the effect itself doesn't use | 59 * be dependent on properties of the effect that the effect itself doesn't use |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 } else { | 174 } else { |
173 header->fIgnoresCoverage = 0; | 175 header->fIgnoresCoverage = 0; |
174 } | 176 } |
175 | 177 |
176 header->fSnapVerticesToPixelCenters = pipeline.snapVerticesToPixelCenters(); | 178 header->fSnapVerticesToPixelCenters = pipeline.snapVerticesToPixelCenters(); |
177 header->fColorEffectCnt = pipeline.numColorFragmentProcessors(); | 179 header->fColorEffectCnt = pipeline.numColorFragmentProcessors(); |
178 header->fCoverageEffectCnt = pipeline.numCoverageFragmentProcessors(); | 180 header->fCoverageEffectCnt = pipeline.numCoverageFragmentProcessors(); |
179 glDesc->finalize(); | 181 glDesc->finalize(); |
180 return true; | 182 return true; |
181 } | 183 } |
OLD | NEW |