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 "GrGLProgramDesc.h" | 8 #include "GrGLProgramDesc.h" |
9 #include "GrBackendEffectFactory.h" | 9 #include "GrBackendEffectFactory.h" |
10 #include "GrDrawEffect.h" | 10 #include "GrDrawEffect.h" |
11 #include "GrEffect.h" | 11 #include "GrEffect.h" |
12 #include "GrGLShaderBuilder.h" | 12 #include "GrGLShaderBuilder.h" |
13 #include "GrGpuGL.h" | 13 #include "GrGpuGL.h" |
14 | 14 |
15 #include "SkChecksum.h" | 15 #include "SkChecksum.h" |
16 | 16 |
17 void GrGLProgramDesc::Build(const GrDrawState& drawState, | 17 void GrGLProgramDesc::Build(const GrDrawState& drawState, |
18 bool isPoints, | 18 bool isPoints, |
19 GrDrawState::BlendOptFlags blendOpts, | 19 GrDrawState::BlendOptFlags blendOpts, |
20 GrBlendCoeff srcCoeff, | 20 GrBlendCoeff srcCoeff, |
21 GrBlendCoeff dstCoeff, | 21 GrBlendCoeff dstCoeff, |
22 const GrGpuGL* gpu, | 22 const GrGpuGL* gpu, |
23 const GrDeviceCoordTexture* dstCopy, | 23 const GrDeviceCoordTexture* dstCopy, |
24 const GrEffectStage* stages[], | 24 SkTArray<const GrEffectStage*, true>* colorStages, |
| 25 SkTArray<const GrEffectStage*, true>* coverageStages
, |
25 GrGLProgramDesc* desc) { | 26 GrGLProgramDesc* desc) { |
| 27 colorStages->reset(); |
| 28 coverageStages->reset(); |
| 29 |
26 // This should already have been caught | 30 // This should already have been caught |
27 GrAssert(!(GrDrawState::kSkipDraw_BlendOptFlag & blendOpts)); | 31 GrAssert(!(GrDrawState::kSkipDraw_BlendOptFlag & blendOpts)); |
28 | 32 |
29 bool skipCoverage = SkToBool(blendOpts & GrDrawState::kEmitTransBlack_BlendO
ptFlag); | 33 bool skipCoverage = SkToBool(blendOpts & GrDrawState::kEmitTransBlack_BlendO
ptFlag); |
30 | 34 |
31 bool skipColor = SkToBool(blendOpts & (GrDrawState::kEmitTransBlack_BlendOpt
Flag | | 35 bool skipColor = SkToBool(blendOpts & (GrDrawState::kEmitTransBlack_BlendOpt
Flag | |
32 GrDrawState::kEmitCoverage_BlendOptFl
ag)); | 36 GrDrawState::kEmitCoverage_BlendOptFl
ag)); |
33 | 37 |
34 // The descriptor is used as a cache key. Thus when a field of the | 38 // The descriptor is used as a cache key. Thus when a field of the |
35 // descriptor will not affect program generation (because of the attribute | 39 // descriptor will not affect program generation (because of the attribute |
36 // bindings in use or other descriptor field settings) it should be set | 40 // bindings in use or other descriptor field settings) it should be set |
37 // to a canonical value to avoid duplicate programs with different keys. | 41 // to a canonical value to avoid duplicate programs with different keys. |
38 | 42 |
39 bool requiresColorAttrib = !skipColor && drawState.hasColorVertexAttribute()
; | 43 bool requiresColorAttrib = !skipColor && drawState.hasColorVertexAttribute()
; |
40 bool requiresCoverageAttrib = !skipCoverage && drawState.hasCoverageVertexAt
tribute(); | 44 bool requiresCoverageAttrib = !skipCoverage && drawState.hasCoverageVertexAt
tribute(); |
41 // we only need the local coords if we're actually going to generate effect
code | 45 // we only need the local coords if we're actually going to generate effect
code |
42 bool requiresLocalCoordAttrib = !(skipCoverage && skipColor) && | 46 bool requiresLocalCoordAttrib = !(skipCoverage && skipColor) && |
43 drawState.hasLocalCoordAttribute(); | 47 drawState.hasLocalCoordAttribute(); |
44 | 48 |
45 bool colorIsTransBlack = SkToBool(blendOpts & GrDrawState::kEmitTransBlack_B
lendOptFlag); | 49 bool colorIsTransBlack = SkToBool(blendOpts & GrDrawState::kEmitTransBlack_B
lendOptFlag); |
46 bool colorIsSolidWhite = (blendOpts & GrDrawState::kEmitCoverage_BlendOptFla
g) || | 50 bool colorIsSolidWhite = (blendOpts & GrDrawState::kEmitCoverage_BlendOptFla
g) || |
47 (!requiresColorAttrib && 0xffffffff == drawState.ge
tColor()); | 51 (!requiresColorAttrib && 0xffffffff == drawState.ge
tColor()); |
48 | 52 |
49 // Do an initial loop over the stages to count them. We count the color and
coverage effects | 53 // Do an initial loop over the stages to count them. We count the color and
coverage effects |
50 // separately here. Later we may decide the distinction doesn't matter and w
ill count all | 54 // separately here. Later we may decide the distinction doesn't matter and w
ill count all |
51 // effects as color in desc. Two things will allow simplication of this mess
: GrDrawState will | 55 // effects as color in desc. Two things will allow simplication of this mess
: GrDrawState will |
52 // have tight lists of color and coverage stages rather than a fixed size ar
ray with NULLS and | 56 // have tight lists of color and coverage stages rather than a fixed size ar
ray with NULLS and |
53 // the xfermode-color filter will be removed. | 57 // the xfermode-color filter will be removed. |
54 int colorEffectCnt = 0; | |
55 int coverageEffectCnt = 0; | |
56 if (!skipColor) { | 58 if (!skipColor) { |
57 for (int s = 0; s < drawState.getFirstCoverageStage(); ++s) { | 59 for (int s = 0; s < drawState.getFirstCoverageStage(); ++s) { |
58 if (drawState.isStageEnabled(s)) { | 60 if (drawState.isStageEnabled(s)) { |
59 stages[colorEffectCnt] = &drawState.getStage(s); | 61 colorStages->push_back(&drawState.getStage(s)); |
60 ++colorEffectCnt; | |
61 } | 62 } |
62 } | 63 } |
63 } | 64 } |
64 if (!skipCoverage) { | 65 if (!skipCoverage) { |
65 for (int s = drawState.getFirstCoverageStage(); s < GrDrawState::kNumSta
ges; ++s) { | 66 for (int s = drawState.getFirstCoverageStage(); s < GrDrawState::kNumSta
ges; ++s) { |
66 if (drawState.isStageEnabled(s)) { | 67 if (drawState.isStageEnabled(s)) { |
67 stages[colorEffectCnt + coverageEffectCnt] = &drawState.getStage
(s); | 68 coverageStages->push_back(&drawState.getStage(s)); |
68 ++coverageEffectCnt; | |
69 } | 69 } |
70 } | 70 } |
71 } | 71 } |
72 | 72 |
73 size_t newKeyLength = KeyLength(colorEffectCnt + coverageEffectCnt); | 73 size_t newKeyLength = KeyLength(colorStages->count() + coverageStages->count
()); |
74 bool allocChanged; | 74 bool allocChanged; |
75 desc->fKey.reset(newKeyLength, SkAutoMalloc::kAlloc_OnShrink, &allocChanged)
; | 75 desc->fKey.reset(newKeyLength, SkAutoMalloc::kAlloc_OnShrink, &allocChanged)
; |
76 if (allocChanged || !desc->fInitialized) { | 76 if (allocChanged || !desc->fInitialized) { |
77 // make sure any padding in the header is zero if we we haven't used thi
s allocation before. | 77 // make sure any padding in the header is zero if we we haven't used thi
s allocation before. |
78 memset(desc->header(), 0, kHeaderSize); | 78 memset(desc->header(), 0, kHeaderSize); |
79 } | 79 } |
80 // write the key length | 80 // write the key length |
81 *desc->atOffset<uint32_t, kLengthOffset>() = newKeyLength; | 81 *desc->atOffset<uint32_t, kLengthOffset>() = newKeyLength; |
82 | 82 |
83 KeyHeader* header = desc->header(); | 83 KeyHeader* header = desc->header(); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 } | 182 } |
183 | 183 |
184 // Here we deal with whether/how we handle color and coverage separately. | 184 // Here we deal with whether/how we handle color and coverage separately. |
185 | 185 |
186 // Set these defaults and then possibly change our mind if there is coverage
. | 186 // Set these defaults and then possibly change our mind if there is coverage
. |
187 header->fDiscardIfZeroCoverage = false; | 187 header->fDiscardIfZeroCoverage = false; |
188 header->fCoverageOutput = kModulate_CoverageOutput; | 188 header->fCoverageOutput = kModulate_CoverageOutput; |
189 | 189 |
190 // If we do have coverage determine whether it matters. | 190 // If we do have coverage determine whether it matters. |
191 bool separateCoverageFromColor = false; | 191 bool separateCoverageFromColor = false; |
192 if (!drawState.isCoverageDrawing() && (coverageEffectCnt > 0 || requiresCove
rageAttrib)) { | 192 if (!drawState.isCoverageDrawing() && (coverageStages->count() > 0 || requir
esCoverageAttrib)) { |
193 // color filter is applied between color/coverage computation | 193 // color filter is applied between color/coverage computation |
194 if (SkXfermode::kDst_Mode != header->fColorFilterXfermode) { | 194 if (SkXfermode::kDst_Mode != header->fColorFilterXfermode) { |
195 separateCoverageFromColor = true; | 195 separateCoverageFromColor = true; |
196 } | 196 } |
197 | 197 |
198 // If we're stenciling then we want to discard samples that have zero co
verage | 198 // If we're stenciling then we want to discard samples that have zero co
verage |
199 if (drawState.getStencil().doesWrite()) { | 199 if (drawState.getStencil().doesWrite()) { |
200 header->fDiscardIfZeroCoverage = true; | 200 header->fDiscardIfZeroCoverage = true; |
201 separateCoverageFromColor = true; | 201 separateCoverageFromColor = true; |
202 } | 202 } |
(...skipping 15 matching lines...) Expand all Loading... |
218 separateCoverageFromColor = true; | 218 separateCoverageFromColor = true; |
219 } | 219 } |
220 } else if (readsDst && | 220 } else if (readsDst && |
221 kOne_GrBlendCoeff == srcCoeff && | 221 kOne_GrBlendCoeff == srcCoeff && |
222 kZero_GrBlendCoeff == dstCoeff) { | 222 kZero_GrBlendCoeff == dstCoeff) { |
223 header->fCoverageOutput = kCombineWithDst_CoverageOutput; | 223 header->fCoverageOutput = kCombineWithDst_CoverageOutput; |
224 separateCoverageFromColor = true; | 224 separateCoverageFromColor = true; |
225 } | 225 } |
226 } | 226 } |
227 if (separateCoverageFromColor) { | 227 if (separateCoverageFromColor) { |
228 header->fColorEffectCnt = colorEffectCnt; | 228 header->fColorEffectCnt = colorStages->count(); |
229 header->fCoverageEffectCnt = coverageEffectCnt; | 229 header->fCoverageEffectCnt = coverageStages->count(); |
230 } else { | 230 } else { |
231 header->fColorEffectCnt = colorEffectCnt + coverageEffectCnt; | 231 header->fColorEffectCnt = colorStages->count() + coverageStages->count()
; |
232 header->fCoverageEffectCnt = 0; | 232 header->fCoverageEffectCnt = 0; |
| 233 colorStages->push_back_n(coverageStages->count(), coverageStages->begin(
)); |
| 234 coverageStages->reset(); |
233 } | 235 } |
234 | 236 |
235 *desc->checksum() = 0; | 237 *desc->checksum() = 0; |
236 *desc->checksum() = SkChecksum::Compute(reinterpret_cast<uint32_t*>(desc->fK
ey.get()), | 238 *desc->checksum() = SkChecksum::Compute(reinterpret_cast<uint32_t*>(desc->fK
ey.get()), |
237 newKeyLength); | 239 newKeyLength); |
238 desc->fInitialized = true; | 240 desc->fInitialized = true; |
239 } | 241 } |
240 | 242 |
241 GrGLProgramDesc& GrGLProgramDesc::operator= (const GrGLProgramDesc& other) { | 243 GrGLProgramDesc& GrGLProgramDesc::operator= (const GrGLProgramDesc& other) { |
242 fInitialized = other.fInitialized; | 244 fInitialized = other.fInitialized; |
243 if (fInitialized) { | 245 if (fInitialized) { |
244 size_t keyLength = other.keyLength(); | 246 size_t keyLength = other.keyLength(); |
245 fKey.reset(keyLength); | 247 fKey.reset(keyLength); |
246 memcpy(fKey.get(), other.fKey.get(), keyLength); | 248 memcpy(fKey.get(), other.fKey.get(), keyLength); |
247 } | 249 } |
248 return *this; | 250 return *this; |
249 } | 251 } |
OLD | NEW |