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" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 return true; | 46 return true; |
47 } | 47 } |
48 | 48 |
49 bool GrGLProgramDesc::Build(const GrDrawState& drawState, | 49 bool GrGLProgramDesc::Build(const GrDrawState& drawState, |
50 GrGpu::DrawType drawType, | 50 GrGpu::DrawType drawType, |
51 GrDrawState::BlendOptFlags blendOpts, | 51 GrDrawState::BlendOptFlags blendOpts, |
52 GrBlendCoeff srcCoeff, | 52 GrBlendCoeff srcCoeff, |
53 GrBlendCoeff dstCoeff, | 53 GrBlendCoeff dstCoeff, |
54 const GrGpuGL* gpu, | 54 const GrGpuGL* gpu, |
55 const GrDeviceCoordTexture* dstCopy, | 55 const GrDeviceCoordTexture* dstCopy, |
56 const GrEffectStage** geometryProcessor, | |
56 SkTArray<const GrEffectStage*, true>* colorStages, | 57 SkTArray<const GrEffectStage*, true>* colorStages, |
57 SkTArray<const GrEffectStage*, true>* coverageStages , | 58 SkTArray<const GrEffectStage*, true>* coverageStages , |
58 GrGLProgramDesc* desc) { | 59 GrGLProgramDesc* desc) { |
59 colorStages->reset(); | 60 colorStages->reset(); |
60 coverageStages->reset(); | 61 coverageStages->reset(); |
61 | 62 |
62 // This should already have been caught | 63 // This should already have been caught |
63 SkASSERT(!(GrDrawState::kSkipDraw_BlendOptFlag & blendOpts)); | 64 SkASSERT(!(GrDrawState::kSkipDraw_BlendOptFlag & blendOpts)); |
64 | 65 |
65 bool skipCoverage = SkToBool(blendOpts & GrDrawState::kEmitTransBlack_BlendO ptFlag); | 66 bool skipCoverage = SkToBool(blendOpts & GrDrawState::kEmitTransBlack_BlendO ptFlag); |
66 | 67 |
67 bool skipColor = SkToBool(blendOpts & (GrDrawState::kEmitTransBlack_BlendOpt Flag | | 68 bool skipColor = SkToBool(blendOpts & (GrDrawState::kEmitTransBlack_BlendOpt Flag | |
68 GrDrawState::kEmitCoverage_BlendOptFl ag)); | 69 GrDrawState::kEmitCoverage_BlendOptFl ag)); |
69 | 70 |
70 int firstEffectiveColorStage = 0; | 71 int firstEffectiveColorStage = 0; |
71 bool inputColorIsUsed = true; | 72 bool inputColorIsUsed = true; |
73 | |
74 if (drawState.hasGeometryProcessor()) { | |
75 const GrEffect* effect = drawState.getGeometryProcessor()->getEffect(); | |
76 inputColorIsUsed = effect->willUseInputColor(); | |
bsalomon
2014/09/03 21:07:00
I'm not sure that this is right since the GP is co
| |
77 } | |
78 | |
72 if (!skipColor) { | 79 if (!skipColor) { |
73 firstEffectiveColorStage = drawState.numColorStages(); | 80 firstEffectiveColorStage = drawState.numColorStages(); |
74 while (firstEffectiveColorStage > 0 && inputColorIsUsed) { | 81 while (firstEffectiveColorStage > 0 && inputColorIsUsed) { |
75 --firstEffectiveColorStage; | 82 --firstEffectiveColorStage; |
76 const GrEffect* effect = drawState.getColorStage(firstEffectiveColor Stage).getEffect(); | 83 const GrEffect* effect = drawState.getColorStage(firstEffectiveColor Stage).getEffect(); |
77 inputColorIsUsed = effect->willUseInputColor(); | 84 inputColorIsUsed = effect->willUseInputColor(); |
78 } | 85 } |
79 } | 86 } |
80 | 87 |
81 int firstEffectiveCoverageStage = 0; | 88 int firstEffectiveCoverageStage = 0; |
(...skipping 18 matching lines...) Expand all Loading... | |
100 bool requiresLocalCoordAttrib = !(skipCoverage && skipColor) && | 107 bool requiresLocalCoordAttrib = !(skipCoverage && skipColor) && |
101 drawState.hasLocalCoordAttribute(); | 108 drawState.hasLocalCoordAttribute(); |
102 | 109 |
103 bool readsDst = false; | 110 bool readsDst = false; |
104 bool readFragPosition = false; | 111 bool readFragPosition = false; |
105 | 112 |
106 // Provide option for shader programs without vertex shader only when drawin g paths. | 113 // Provide option for shader programs without vertex shader only when drawin g paths. |
107 bool requiresVertexShader = !GrGpu::IsPathRenderingDrawType(drawType); | 114 bool requiresVertexShader = !GrGpu::IsPathRenderingDrawType(drawType); |
108 | 115 |
109 int numStages = 0; | 116 int numStages = 0; |
117 if (drawState.hasGeometryProcessor()) { | |
118 numStages++; | |
119 } | |
110 if (!skipColor) { | 120 if (!skipColor) { |
111 numStages += drawState.numColorStages() - firstEffectiveColorStage; | 121 numStages += drawState.numColorStages() - firstEffectiveColorStage; |
112 } | 122 } |
113 if (!skipCoverage) { | 123 if (!skipCoverage) { |
114 numStages += drawState.numCoverageStages() - firstEffectiveCoverageStage ; | 124 numStages += drawState.numCoverageStages() - firstEffectiveCoverageStage ; |
115 } | 125 } |
116 GR_STATIC_ASSERT(0 == kEffectKeyOffsetsAndLengthOffset % sizeof(uint32_t)); | 126 GR_STATIC_ASSERT(0 == kEffectKeyOffsetsAndLengthOffset % sizeof(uint32_t)); |
117 // Make room for everything up to and including the array of offsets to effe ct keys. | 127 // Make room for everything up to and including the array of offsets to effe ct keys. |
118 desc->fKey.reset(); | 128 desc->fKey.reset(); |
119 desc->fKey.push_back_n(kEffectKeyOffsetsAndLengthOffset + 2 * sizeof(uint16_ t) * numStages); | 129 desc->fKey.push_back_n(kEffectKeyOffsetsAndLengthOffset + 2 * sizeof(uint16_ t) * numStages); |
120 | 130 |
121 int offsetAndSizeIndex = 0; | 131 int offsetAndSizeIndex = 0; |
122 bool effectKeySuccess = true; | 132 bool effectKeySuccess = true; |
133 | |
134 KeyHeader* header = desc->header(); | |
135 // make sure any padding in the header is zeroed. | |
136 memset(desc->header(), 0, kHeaderSize); | |
137 | |
138 // We can only have one effect which touches the vertex shader | |
139 if (drawState.hasGeometryProcessor()) { | |
140 uint16_t* offsetAndSize = | |
141 reinterpret_cast<uint16_t*>(desc->fKey.begin() + kEffectKeyOffse tsAndLengthOffset + | |
142 offsetAndSizeIndex * 2 * sizeof(uint 16_t)); | |
143 | |
144 GrEffectKeyBuilder b(&desc->fKey); | |
145 uint16_t effectKeySize; | |
146 uint32_t effectOffset = desc->fKey.count(); | |
147 effectKeySuccess |= GetEffectKeyAndUpdateStats( | |
148 *drawState.getGeometryProcessor(), gpu->glCa ps(), | |
149 requiresLocalCoordAttrib, &b, | |
150 &effectKeySize, &readsDst, | |
151 &readFragPosition, &requiresVertexShader); | |
152 effectKeySuccess |= (effectOffset <= SK_MaxU16); | |
153 | |
154 offsetAndSize[0] = SkToU16(effectOffset); | |
155 offsetAndSize[1] = effectKeySize; | |
156 ++offsetAndSizeIndex; | |
157 *geometryProcessor = drawState.getGeometryProcessor(); | |
158 SkASSERT(requiresVertexShader); | |
159 header->fHasGeometryProcessor = true; | |
160 } | |
161 | |
123 if (!skipColor) { | 162 if (!skipColor) { |
124 for (int s = firstEffectiveColorStage; s < drawState.numColorStages(); + +s) { | 163 for (int s = firstEffectiveColorStage; s < drawState.numColorStages(); + +s) { |
125 uint16_t* offsetAndSize = | 164 uint16_t* offsetAndSize = |
126 reinterpret_cast<uint16_t*>(desc->fKey.begin() + kEffectKeyOffse tsAndLengthOffset + | 165 reinterpret_cast<uint16_t*>(desc->fKey.begin() + kEffectKeyOffse tsAndLengthOffset + |
127 offsetAndSizeIndex * 2 * sizeof(uint 16_t)); | 166 offsetAndSizeIndex * 2 * sizeof(uint 16_t)); |
128 | 167 |
168 bool effectRequiresVertexShader = false; | |
129 GrEffectKeyBuilder b(&desc->fKey); | 169 GrEffectKeyBuilder b(&desc->fKey); |
130 uint16_t effectKeySize; | 170 uint16_t effectKeySize; |
131 uint32_t effectOffset = desc->fKey.count(); | 171 uint32_t effectOffset = desc->fKey.count(); |
132 effectKeySuccess |= GetEffectKeyAndUpdateStats( | 172 effectKeySuccess |= GetEffectKeyAndUpdateStats( |
133 drawState.getColorStage(s), gpu->glCaps(), | 173 drawState.getColorStage(s), gpu->glCaps(), |
134 requiresLocalCoordAttrib, &b, | 174 requiresLocalCoordAttrib, &b, |
135 &effectKeySize, &readsDst, | 175 &effectKeySize, &readsDst, |
136 &readFragPosition, &requiresVertexShader); | 176 &readFragPosition, &effectRequiresVertexShad er); |
137 effectKeySuccess |= (effectOffset <= SK_MaxU16); | 177 effectKeySuccess |= (effectOffset <= SK_MaxU16); |
138 | 178 |
139 offsetAndSize[0] = SkToU16(effectOffset); | 179 offsetAndSize[0] = SkToU16(effectOffset); |
140 offsetAndSize[1] = effectKeySize; | 180 offsetAndSize[1] = effectKeySize; |
141 ++offsetAndSizeIndex; | 181 ++offsetAndSizeIndex; |
182 SkASSERT(!effectRequiresVertexShader); | |
142 } | 183 } |
143 } | 184 } |
144 if (!skipCoverage) { | 185 if (!skipCoverage) { |
145 for (int s = firstEffectiveCoverageStage; s < drawState.numCoverageStage s(); ++s) { | 186 for (int s = firstEffectiveCoverageStage; s < drawState.numCoverageStage s(); ++s) { |
146 uint16_t* offsetAndSize = | 187 uint16_t* offsetAndSize = |
147 reinterpret_cast<uint16_t*>(desc->fKey.begin() + kEffectKeyOffse tsAndLengthOffset + | 188 reinterpret_cast<uint16_t*>(desc->fKey.begin() + kEffectKeyOffse tsAndLengthOffset + |
148 offsetAndSizeIndex * 2 * sizeof(uint 16_t)); | 189 offsetAndSizeIndex * 2 * sizeof(uint 16_t)); |
149 | 190 |
191 bool effectRequiresVertexShader = false; | |
150 GrEffectKeyBuilder b(&desc->fKey); | 192 GrEffectKeyBuilder b(&desc->fKey); |
151 uint16_t effectKeySize; | 193 uint16_t effectKeySize; |
152 uint32_t effectOffset = desc->fKey.count(); | 194 uint32_t effectOffset = desc->fKey.count(); |
153 effectKeySuccess |= GetEffectKeyAndUpdateStats( | 195 effectKeySuccess |= GetEffectKeyAndUpdateStats( |
154 drawState.getCoverageStage(s), gpu->glCaps() , | 196 drawState.getCoverageStage(s), gpu->glCaps() , |
155 requiresLocalCoordAttrib, &b, | 197 requiresLocalCoordAttrib, &b, |
156 &effectKeySize, &readsDst, | 198 &effectKeySize, &readsDst, |
157 &readFragPosition, &requiresVertexShader); | 199 &readFragPosition, &effectRequiresVertexShad er); |
158 effectKeySuccess |= (effectOffset <= SK_MaxU16); | 200 effectKeySuccess |= (effectOffset <= SK_MaxU16); |
159 | 201 |
160 offsetAndSize[0] = SkToU16(effectOffset); | 202 offsetAndSize[0] = SkToU16(effectOffset); |
161 offsetAndSize[1] = effectKeySize; | 203 offsetAndSize[1] = effectKeySize; |
162 ++offsetAndSizeIndex; | 204 ++offsetAndSizeIndex; |
205 SkASSERT(!effectRequiresVertexShader); | |
163 } | 206 } |
164 } | 207 } |
165 if (!effectKeySuccess) { | 208 if (!effectKeySuccess) { |
166 desc->fKey.reset(); | 209 desc->fKey.reset(); |
167 return false; | 210 return false; |
168 } | 211 } |
169 | 212 |
170 KeyHeader* header = desc->header(); | |
171 // make sure any padding in the header is zeroed. | |
172 memset(desc->header(), 0, kHeaderSize); | |
173 | |
174 // Because header is a pointer into the dynamic array, we can't push any new data into the key | 213 // Because header is a pointer into the dynamic array, we can't push any new data into the key |
175 // below here. | 214 // below here. |
176 | 215 |
177 header->fRequiresVertexShader = requiresVertexShader || requiresLocalCoordAt trib; | 216 header->fRequiresVertexShader = requiresVertexShader || requiresLocalCoordAt trib; |
178 header->fEmitsPointSize = GrGpu::kDrawPoints_DrawType == drawType; | 217 header->fEmitsPointSize = GrGpu::kDrawPoints_DrawType == drawType; |
179 | 218 |
180 // Currently the experimental GS will only work with triangle prims (and it doesn't do anything | 219 // Currently the experimental GS will only work with triangle prims (and it doesn't do anything |
181 // other than pass through values from the VS to the FS anyway). | 220 // other than pass through values from the VS to the FS anyway). |
182 #if GR_GL_EXPERIMENTAL_GS | 221 #if GR_GL_EXPERIMENTAL_GS |
183 #if 0 | 222 #if 0 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
252 } else { | 291 } else { |
253 header->fCoverageAttributeIndex = -1; | 292 header->fCoverageAttributeIndex = -1; |
254 } | 293 } |
255 | 294 |
256 // Here we deal with whether/how we handle color and coverage separately. | 295 // Here we deal with whether/how we handle color and coverage separately. |
257 | 296 |
258 // Set this default and then possibly change our mind if there is coverage. | 297 // Set this default and then possibly change our mind if there is coverage. |
259 header->fCoverageOutput = kModulate_CoverageOutput; | 298 header->fCoverageOutput = kModulate_CoverageOutput; |
260 | 299 |
261 // If we do have coverage determine whether it matters. | 300 // If we do have coverage determine whether it matters. |
262 bool separateCoverageFromColor = false; | 301 bool separateCoverageFromColor = drawState.hasGeometryProcessor(); |
263 if (!drawState.isCoverageDrawing() && !skipCoverage && | 302 if (!drawState.isCoverageDrawing() && !skipCoverage && |
264 (drawState.numCoverageStages() > 0 || requiresCoverageAttrib)) { | 303 (drawState.numCoverageStages() > 0 || |
304 drawState.hasGeometryProcessor() || | |
305 requiresCoverageAttrib)) { | |
265 | 306 |
266 if (gpu->caps()->dualSourceBlendingSupport() && | 307 if (gpu->caps()->dualSourceBlendingSupport() && |
267 !(blendOpts & (GrDrawState::kEmitCoverage_BlendOptFlag | | 308 !(blendOpts & (GrDrawState::kEmitCoverage_BlendOptFlag | |
268 GrDrawState::kCoverageAsAlpha_BlendOptFlag))) { | 309 GrDrawState::kCoverageAsAlpha_BlendOptFlag))) { |
269 if (kZero_GrBlendCoeff == dstCoeff) { | 310 if (kZero_GrBlendCoeff == dstCoeff) { |
270 // write the coverage value to second color | 311 // write the coverage value to second color |
271 header->fCoverageOutput = kSecondaryCoverage_CoverageOutput; | 312 header->fCoverageOutput = kSecondaryCoverage_CoverageOutput; |
272 separateCoverageFromColor = true; | 313 separateCoverageFromColor = true; |
273 } else if (kSA_GrBlendCoeff == dstCoeff) { | 314 } else if (kSA_GrBlendCoeff == dstCoeff) { |
274 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered. | 315 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered. |
275 header->fCoverageOutput = kSecondaryCoverageISA_CoverageOutput; | 316 header->fCoverageOutput = kSecondaryCoverageISA_CoverageOutput; |
276 separateCoverageFromColor = true; | 317 separateCoverageFromColor = true; |
277 } else if (kSC_GrBlendCoeff == dstCoeff) { | 318 } else if (kSC_GrBlendCoeff == dstCoeff) { |
278 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered. | 319 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered. |
279 header->fCoverageOutput = kSecondaryCoverageISC_CoverageOutput; | 320 header->fCoverageOutput = kSecondaryCoverageISC_CoverageOutput; |
280 separateCoverageFromColor = true; | 321 separateCoverageFromColor = true; |
281 } | 322 } |
282 } else if (readsDst && | 323 } else if (readsDst && |
283 kOne_GrBlendCoeff == srcCoeff && | 324 kOne_GrBlendCoeff == srcCoeff && |
284 kZero_GrBlendCoeff == dstCoeff) { | 325 kZero_GrBlendCoeff == dstCoeff) { |
285 header->fCoverageOutput = kCombineWithDst_CoverageOutput; | 326 header->fCoverageOutput = kCombineWithDst_CoverageOutput; |
286 separateCoverageFromColor = true; | 327 separateCoverageFromColor = true; |
287 } | 328 } |
288 } | 329 } |
330 | |
289 if (!skipColor) { | 331 if (!skipColor) { |
290 for (int s = firstEffectiveColorStage; s < drawState.numColorStages(); + +s) { | 332 for (int s = firstEffectiveColorStage; s < drawState.numColorStages(); + +s) { |
291 colorStages->push_back(&drawState.getColorStage(s)); | 333 colorStages->push_back(&drawState.getColorStage(s)); |
292 } | 334 } |
293 } | 335 } |
294 if (!skipCoverage) { | 336 if (!skipCoverage) { |
295 SkTArray<const GrEffectStage*, true>* array; | 337 SkTArray<const GrEffectStage*, true>* array; |
296 if (separateCoverageFromColor) { | 338 if (separateCoverageFromColor) { |
297 array = coverageStages; | 339 array = coverageStages; |
298 } else { | 340 } else { |
(...skipping 19 matching lines...) Expand all Loading... | |
318 *checksum = 0; | 360 *checksum = 0; |
319 *checksum = SkChecksum::Compute(reinterpret_cast<uint32_t*>(fKey.begin()), k eyLength); | 361 *checksum = SkChecksum::Compute(reinterpret_cast<uint32_t*>(fKey.begin()), k eyLength); |
320 } | 362 } |
321 | 363 |
322 GrGLProgramDesc& GrGLProgramDesc::operator= (const GrGLProgramDesc& other) { | 364 GrGLProgramDesc& GrGLProgramDesc::operator= (const GrGLProgramDesc& other) { |
323 size_t keyLength = other.keyLength(); | 365 size_t keyLength = other.keyLength(); |
324 fKey.reset(keyLength); | 366 fKey.reset(keyLength); |
325 memcpy(fKey.begin(), other.fKey.begin(), keyLength); | 367 memcpy(fKey.begin(), other.fKey.begin(), keyLength); |
326 return *this; | 368 return *this; |
327 } | 369 } |
OLD | NEW |