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 | 7 |
8 #include "gl/builders/GrGLProgramBuilder.h" | 8 #include "gl/builders/GrGLProgramBuilder.h" |
9 #include "GrGLProgramDesc.h" | 9 #include "GrGLProgramDesc.h" |
10 #include "GrBackendEffectFactory.h" | 10 #include "GrBackendEffectFactory.h" |
11 #include "GrDrawEffect.h" | 11 #include "GrDrawEffect.h" |
12 #include "GrEffect.h" | 12 #include "GrEffect.h" |
13 #include "GrGpuGL.h" | 13 #include "GrGpuGL.h" |
14 #include "GrOptDrawState.h" | 14 #include "GrOptDrawState.h" |
15 | 15 |
16 #include "SkChecksum.h" | 16 #include "SkChecksum.h" |
17 | 17 |
18 bool GrGLProgramDesc::GetEffectKeyAndUpdateStats(const GrEffectStage& stage, | 18 bool GrGLProgramDesc::GetEffectKey(const GrEffectStage& stage, const GrGLCaps& c aps, |
19 const GrGLCaps& caps, | 19 bool useExplicitLocalCoords, GrEffectKeyBuild er* b, |
20 bool useExplicitLocalCoords, | 20 uint16_t* effectKeySize) { |
21 GrEffectKeyBuilder* b, | |
22 uint16_t* effectKeySize, | |
23 bool* setTrueIfReadsDst, | |
24 bool* setTrueIfReadsPos, | |
25 bool* setTrueIfRequiresVertexSh ader) { | |
26 const GrBackendEffectFactory& factory = stage.getEffect()->getFactory(); | 21 const GrBackendEffectFactory& factory = stage.getEffect()->getFactory(); |
27 GrDrawEffect drawEffect(stage, useExplicitLocalCoords); | 22 GrDrawEffect drawEffect(stage, useExplicitLocalCoords); |
28 if (stage.getEffect()->willReadDstColor()) { | |
29 *setTrueIfReadsDst = true; | |
30 } | |
31 if (stage.getEffect()->willReadFragmentPosition()) { | |
32 *setTrueIfReadsPos = true; | |
33 } | |
34 if (stage.getEffect()->requiresVertexShader()) { | |
35 *setTrueIfRequiresVertexShader = true; | |
36 } | |
37 factory.getGLEffectKey(drawEffect, caps, b); | 23 factory.getGLEffectKey(drawEffect, caps, b); |
38 size_t size = b->size(); | 24 size_t size = b->size(); |
39 if (size > SK_MaxU16) { | 25 if (size > SK_MaxU16) { |
40 *effectKeySize = 0; // suppresses a warning. | 26 *effectKeySize = 0; // suppresses a warning. |
41 return false; | 27 return false; |
42 } | 28 } |
43 *effectKeySize = SkToU16(size); | 29 *effectKeySize = SkToU16(size); |
44 if (!GrGLProgramEffects::GenEffectMetaKey(drawEffect, caps, b)) { | 30 if (!GrGLProgramEffects::GenEffectMetaKey(drawEffect, caps, b)) { |
45 return false; | 31 return false; |
46 } | 32 } |
(...skipping 19 matching lines...) Expand all Loading... | |
66 // descriptor will not affect program generation (because of the attribute | 52 // descriptor will not affect program generation (because of the attribute |
67 // bindings in use or other descriptor field settings) it should be set | 53 // bindings in use or other descriptor field settings) it should be set |
68 // to a canonical value to avoid duplicate programs with different keys. | 54 // to a canonical value to avoid duplicate programs with different keys. |
69 | 55 |
70 bool requiresColorAttrib = optState.hasColorVertexAttribute(); | 56 bool requiresColorAttrib = optState.hasColorVertexAttribute(); |
71 bool requiresCoverageAttrib = optState.hasCoverageVertexAttribute(); | 57 bool requiresCoverageAttrib = optState.hasCoverageVertexAttribute(); |
72 // we only need the local coords if we're actually going to generate effect code | 58 // we only need the local coords if we're actually going to generate effect code |
73 bool requiresLocalCoordAttrib = optState.numTotalStages() > 0 && | 59 bool requiresLocalCoordAttrib = optState.numTotalStages() > 0 && |
74 optState.hasLocalCoordAttribute(); | 60 optState.hasLocalCoordAttribute(); |
75 | 61 |
76 bool readsDst = false; | 62 bool readsDst = optState.readsDst(); |
bsalomon
2014/09/05 15:27:55
remove the vars?
egdaniel
2014/09/08 19:19:49
removed
| |
77 bool readFragPosition = false; | 63 bool readFragPosition = optState.readsFragPosition(); |
78 | 64 |
79 // Provide option for shader programs without vertex shader only when drawin g paths. | 65 // Provide option for shader programs without vertex shader only when drawin g paths. |
80 bool requiresVertexShader = !GrGpu::IsPathRenderingDrawType(drawType); | 66 bool requiresVertexShader = |
bsalomon
2014/09/05 15:27:55
I wonder whether this should just be an assert...
egdaniel
2014/09/08 19:19:49
Added assert below
On 2014/09/05 15:27:55, bsalom
| |
67 !GrGpu::IsPathRenderingDrawType(drawType) ? true : optState.requiresVert exShader(); | |
81 | 68 |
82 int numStages = optState.numTotalStages(); | 69 int numStages = optState.numTotalStages(); |
83 | 70 |
84 GR_STATIC_ASSERT(0 == kEffectKeyOffsetsAndLengthOffset % sizeof(uint32_t)); | 71 GR_STATIC_ASSERT(0 == kEffectKeyOffsetsAndLengthOffset % sizeof(uint32_t)); |
85 // Make room for everything up to and including the array of offsets to effe ct keys. | 72 // Make room for everything up to and including the array of offsets to effe ct keys. |
86 desc->fKey.reset(); | 73 desc->fKey.reset(); |
87 desc->fKey.push_back_n(kEffectKeyOffsetsAndLengthOffset + 2 * sizeof(uint16_ t) * numStages); | 74 desc->fKey.push_back_n(kEffectKeyOffsetsAndLengthOffset + 2 * sizeof(uint16_ t) * numStages); |
88 | 75 |
89 int offsetAndSizeIndex = 0; | 76 int offsetAndSizeIndex = 0; |
90 bool effectKeySuccess = true; | 77 bool effectKeySuccess = true; |
91 for (int s = 0; s < optState.numColorStages(); ++s) { | 78 for (int s = 0; s < optState.numColorStages(); ++s) { |
92 uint16_t* offsetAndSize = | 79 uint16_t* offsetAndSize = |
93 reinterpret_cast<uint16_t*>(desc->fKey.begin() + kEffectKeyOffsetsAn dLengthOffset + | 80 reinterpret_cast<uint16_t*>(desc->fKey.begin() + kEffectKeyOffsetsAn dLengthOffset + |
94 offsetAndSizeIndex * 2 * sizeof(uint16_t )); | 81 offsetAndSizeIndex * 2 * sizeof(uint16_t )); |
95 | 82 |
96 GrEffectKeyBuilder b(&desc->fKey); | 83 GrEffectKeyBuilder b(&desc->fKey); |
97 uint16_t effectKeySize; | 84 uint16_t effectKeySize; |
98 uint32_t effectOffset = desc->fKey.count(); | 85 uint32_t effectOffset = desc->fKey.count(); |
99 effectKeySuccess |= GetEffectKeyAndUpdateStats( | 86 effectKeySuccess |= GetEffectKey( |
100 optState.getColorStage(s), gpu->glCaps(), | 87 optState.getColorStage(s), gpu->glCaps(), |
101 requiresLocalCoordAttrib, &b, | 88 requiresLocalCoordAttrib, &b, |
102 &effectKeySize, &readsDst, | 89 &effectKeySize); |
103 &readFragPosition, &requiresVertexShader); | |
104 effectKeySuccess |= (effectOffset <= SK_MaxU16); | 90 effectKeySuccess |= (effectOffset <= SK_MaxU16); |
105 | 91 |
106 offsetAndSize[0] = SkToU16(effectOffset); | 92 offsetAndSize[0] = SkToU16(effectOffset); |
107 offsetAndSize[1] = effectKeySize; | 93 offsetAndSize[1] = effectKeySize; |
108 ++offsetAndSizeIndex; | 94 ++offsetAndSizeIndex; |
109 } | 95 } |
110 for (int s = 0; s < optState.numCoverageStages(); ++s) { | 96 for (int s = 0; s < optState.numCoverageStages(); ++s) { |
111 uint16_t* offsetAndSize = | 97 uint16_t* offsetAndSize = |
112 reinterpret_cast<uint16_t*>(desc->fKey.begin() + kEffectKeyOffsetsAn dLengthOffset + | 98 reinterpret_cast<uint16_t*>(desc->fKey.begin() + kEffectKeyOffsetsAn dLengthOffset + |
113 offsetAndSizeIndex * 2 * sizeof(uint16_t )); | 99 offsetAndSizeIndex * 2 * sizeof(uint16_t )); |
114 | 100 |
115 GrEffectKeyBuilder b(&desc->fKey); | 101 GrEffectKeyBuilder b(&desc->fKey); |
116 uint16_t effectKeySize; | 102 uint16_t effectKeySize; |
117 uint32_t effectOffset = desc->fKey.count(); | 103 uint32_t effectOffset = desc->fKey.count(); |
118 effectKeySuccess |= GetEffectKeyAndUpdateStats( | 104 effectKeySuccess |= GetEffectKey( |
119 optState.getCoverageStage(s), gpu->glCaps(), | 105 optState.getCoverageStage(s), gpu->glCaps(), |
120 requiresLocalCoordAttrib, &b, | 106 requiresLocalCoordAttrib, &b, |
121 &effectKeySize, &readsDst, | 107 &effectKeySize); |
122 &readFragPosition, &requiresVertexShader); | |
123 effectKeySuccess |= (effectOffset <= SK_MaxU16); | 108 effectKeySuccess |= (effectOffset <= SK_MaxU16); |
124 | 109 |
125 offsetAndSize[0] = SkToU16(effectOffset); | 110 offsetAndSize[0] = SkToU16(effectOffset); |
126 offsetAndSize[1] = effectKeySize; | 111 offsetAndSize[1] = effectKeySize; |
127 ++offsetAndSizeIndex; | 112 ++offsetAndSizeIndex; |
128 } | 113 } |
129 | 114 |
130 if (!effectKeySuccess) { | 115 if (!effectKeySuccess) { |
131 desc->fKey.reset(); | 116 desc->fKey.reset(); |
132 return false; | 117 return false; |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
279 *checksum = 0; | 264 *checksum = 0; |
280 *checksum = SkChecksum::Compute(reinterpret_cast<uint32_t*>(fKey.begin()), k eyLength); | 265 *checksum = SkChecksum::Compute(reinterpret_cast<uint32_t*>(fKey.begin()), k eyLength); |
281 } | 266 } |
282 | 267 |
283 GrGLProgramDesc& GrGLProgramDesc::operator= (const GrGLProgramDesc& other) { | 268 GrGLProgramDesc& GrGLProgramDesc::operator= (const GrGLProgramDesc& other) { |
284 size_t keyLength = other.keyLength(); | 269 size_t keyLength = other.keyLength(); |
285 fKey.reset(keyLength); | 270 fKey.reset(keyLength); |
286 memcpy(fKey.begin(), other.fKey.begin(), keyLength); | 271 memcpy(fKey.begin(), other.fKey.begin(), keyLength); |
287 return *this; | 272 return *this; |
288 } | 273 } |
OLD | NEW |