OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "GrDrawState.h" | 8 #include "GrDrawState.h" |
9 #include "GrPaint.h" | 9 #include "GrPaint.h" |
10 | 10 |
11 bool GrDrawState::setIdentityViewMatrix() { | 11 bool GrDrawState::setIdentityViewMatrix() { |
12 if (fColorStages.count() || fCoverageStages.count()) { | 12 if (fColorStages.count() || fCoverageStages.count()) { |
13 SkMatrix invVM; | 13 SkMatrix invVM; |
14 if (!fCommon.fViewMatrix.invert(&invVM)) { | 14 if (!fViewMatrix.invert(&invVM)) { |
15 // sad trombone sound | 15 // sad trombone sound |
16 return false; | 16 return false; |
17 } | 17 } |
18 for (int s = 0; s < fColorStages.count(); ++s) { | 18 for (int s = 0; s < fColorStages.count(); ++s) { |
19 fColorStages[s].localCoordChange(invVM); | 19 fColorStages[s].localCoordChange(invVM); |
20 } | 20 } |
21 for (int s = 0; s < fCoverageStages.count(); ++s) { | 21 for (int s = 0; s < fCoverageStages.count(); ++s) { |
22 fCoverageStages[s].localCoordChange(invVM); | 22 fCoverageStages[s].localCoordChange(invVM); |
23 } | 23 } |
24 } | 24 } |
25 fCommon.fViewMatrix.reset(); | 25 fViewMatrix.reset(); |
26 return true; | 26 return true; |
27 } | 27 } |
28 | 28 |
29 void GrDrawState::setFromPaint(const GrPaint& paint, const SkMatrix& vm, GrRende
rTarget* rt) { | 29 void GrDrawState::setFromPaint(const GrPaint& paint, const SkMatrix& vm, GrRende
rTarget* rt) { |
30 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); | 30 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); |
31 | 31 |
32 fColorStages.reset(); | 32 fColorStages.reset(); |
33 fCoverageStages.reset(); | 33 fCoverageStages.reset(); |
34 | 34 |
35 for (int i = 0; i < paint.numColorStages(); ++i) { | 35 for (int i = 0; i < paint.numColorStages(); ++i) { |
36 fColorStages.push_back(paint.getColorStage(i)); | 36 fColorStages.push_back(paint.getColorStage(i)); |
37 } | 37 } |
38 | 38 |
39 for (int i = 0; i < paint.numCoverageStages(); ++i) { | 39 for (int i = 0; i < paint.numCoverageStages(); ++i) { |
40 fCoverageStages.push_back(paint.getCoverageStage(i)); | 40 fCoverageStages.push_back(paint.getCoverageStage(i)); |
41 } | 41 } |
42 | 42 |
43 this->setRenderTarget(rt); | 43 this->setRenderTarget(rt); |
44 | 44 |
45 fCommon.fViewMatrix = vm; | 45 fViewMatrix = vm; |
46 | 46 |
47 // These have no equivalent in GrPaint, set them to defaults | 47 // These have no equivalent in GrPaint, set them to defaults |
48 fCommon.fBlendConstant = 0x0; | 48 fBlendConstant = 0x0; |
49 fCommon.fDrawFace = kBoth_DrawFace; | 49 fDrawFace = kBoth_DrawFace; |
50 fCommon.fStencilSettings.setDisabled(); | 50 fStencilSettings.setDisabled(); |
51 this->resetStateFlags(); | 51 this->resetStateFlags(); |
52 | 52 |
53 // Enable the clip bit | 53 // Enable the clip bit |
54 this->enableState(GrDrawState::kClip_StateBit); | 54 this->enableState(GrDrawState::kClip_StateBit); |
55 | 55 |
56 this->setColor(paint.getColor()); | 56 this->setColor(paint.getColor()); |
57 this->setState(GrDrawState::kDither_StateBit, paint.isDither()); | 57 this->setState(GrDrawState::kDither_StateBit, paint.isDither()); |
58 this->setState(GrDrawState::kHWAntialias_StateBit, paint.isAntiAlias()); | 58 this->setState(GrDrawState::kHWAntialias_StateBit, paint.isAntiAlias()); |
59 | 59 |
60 this->setBlendFunc(paint.getSrcBlendCoeff(), paint.getDstBlendCoeff()); | 60 this->setBlendFunc(paint.getSrcBlendCoeff(), paint.getDstBlendCoeff()); |
(...skipping 17 matching lines...) Expand all Loading... |
78 uint32_t mask = (1 << dwordCount)-1; | 78 uint32_t mask = (1 << dwordCount)-1; |
79 size_t offsetShift = attribs[index].fOffset >> 2; | 79 size_t offsetShift = attribs[index].fOffset >> 2; |
80 SkASSERT(!(overlapCheck & (mask << offsetShift))); | 80 SkASSERT(!(overlapCheck & (mask << offsetShift))); |
81 overlapCheck |= (mask << offsetShift); | 81 overlapCheck |= (mask << offsetShift); |
82 #endif | 82 #endif |
83 } | 83 } |
84 return size; | 84 return size; |
85 } | 85 } |
86 | 86 |
87 size_t GrDrawState::getVertexSize() const { | 87 size_t GrDrawState::getVertexSize() const { |
88 return vertex_size(fCommon.fVAPtr, fCommon.fVACount); | 88 return vertex_size(fVAPtr, fVACount); |
89 } | 89 } |
90 | 90 |
91 //////////////////////////////////////////////////////////////////////////////// | 91 //////////////////////////////////////////////////////////////////////////////// |
92 | 92 |
93 void GrDrawState::setVertexAttribs(const GrVertexAttrib* attribs, int count) { | 93 void GrDrawState::setVertexAttribs(const GrVertexAttrib* attribs, int count) { |
94 SkASSERT(count <= kMaxVertexAttribCnt); | 94 SkASSERT(count <= kMaxVertexAttribCnt); |
95 | 95 |
96 fCommon.fVAPtr = attribs; | 96 fVAPtr = attribs; |
97 fCommon.fVACount = count; | 97 fVACount = count; |
98 | 98 |
99 // Set all the indices to -1 | 99 // Set all the indices to -1 |
100 memset(fCommon.fFixedFunctionVertexAttribIndices, | 100 memset(fFixedFunctionVertexAttribIndices, |
101 0xff, | 101 0xff, |
102 sizeof(fCommon.fFixedFunctionVertexAttribIndices)); | 102 sizeof(fFixedFunctionVertexAttribIndices)); |
103 #ifdef SK_DEBUG | 103 #ifdef SK_DEBUG |
104 uint32_t overlapCheck = 0; | 104 uint32_t overlapCheck = 0; |
105 #endif | 105 #endif |
106 for (int i = 0; i < count; ++i) { | 106 for (int i = 0; i < count; ++i) { |
107 if (attribs[i].fBinding < kGrFixedFunctionVertexAttribBindingCnt) { | 107 if (attribs[i].fBinding < kGrFixedFunctionVertexAttribBindingCnt) { |
108 // The fixed function attribs can only be specified once | 108 // The fixed function attribs can only be specified once |
109 SkASSERT(-1 == fCommon.fFixedFunctionVertexAttribIndices[attribs[i].
fBinding]); | 109 SkASSERT(-1 == fFixedFunctionVertexAttribIndices[attribs[i].fBinding
]); |
110 SkASSERT(GrFixedFunctionVertexAttribVectorCount(attribs[i].fBinding)
== | 110 SkASSERT(GrFixedFunctionVertexAttribVectorCount(attribs[i].fBinding)
== |
111 GrVertexAttribTypeVectorCount(attribs[i].fType)); | 111 GrVertexAttribTypeVectorCount(attribs[i].fType)); |
112 fCommon.fFixedFunctionVertexAttribIndices[attribs[i].fBinding] = i; | 112 fFixedFunctionVertexAttribIndices[attribs[i].fBinding] = i; |
113 } | 113 } |
114 #ifdef SK_DEBUG | 114 #ifdef SK_DEBUG |
115 size_t dwordCount = GrVertexAttribTypeSize(attribs[i].fType) >> 2; | 115 size_t dwordCount = GrVertexAttribTypeSize(attribs[i].fType) >> 2; |
116 uint32_t mask = (1 << dwordCount)-1; | 116 uint32_t mask = (1 << dwordCount)-1; |
117 size_t offsetShift = attribs[i].fOffset >> 2; | 117 size_t offsetShift = attribs[i].fOffset >> 2; |
118 SkASSERT(!(overlapCheck & (mask << offsetShift))); | 118 SkASSERT(!(overlapCheck & (mask << offsetShift))); |
119 overlapCheck |= (mask << offsetShift); | 119 overlapCheck |= (mask << offsetShift); |
120 #endif | 120 #endif |
121 } | 121 } |
122 // Positions must be specified. | 122 // Positions must be specified. |
123 SkASSERT(-1 != fCommon.fFixedFunctionVertexAttribIndices[kPosition_GrVertexA
ttribBinding]); | 123 SkASSERT(-1 != fFixedFunctionVertexAttribIndices[kPosition_GrVertexAttribBin
ding]); |
124 } | 124 } |
125 | 125 |
126 //////////////////////////////////////////////////////////////////////////////// | 126 //////////////////////////////////////////////////////////////////////////////// |
127 | 127 |
128 void GrDrawState::setDefaultVertexAttribs() { | 128 void GrDrawState::setDefaultVertexAttribs() { |
129 static const GrVertexAttrib kPositionAttrib = | 129 static const GrVertexAttrib kPositionAttrib = |
130 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}; | 130 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}; |
131 | 131 |
132 fCommon.fVAPtr = &kPositionAttrib; | 132 fVAPtr = &kPositionAttrib; |
133 fCommon.fVACount = 1; | 133 fVACount = 1; |
134 | 134 |
135 // set all the fixed function indices to -1 except position. | 135 // set all the fixed function indices to -1 except position. |
136 memset(fCommon.fFixedFunctionVertexAttribIndices, | 136 memset(fFixedFunctionVertexAttribIndices, |
137 0xff, | 137 0xff, |
138 sizeof(fCommon.fFixedFunctionVertexAttribIndices)); | 138 sizeof(fFixedFunctionVertexAttribIndices)); |
139 fCommon.fFixedFunctionVertexAttribIndices[kPosition_GrVertexAttribBinding] =
0; | 139 fFixedFunctionVertexAttribIndices[kPosition_GrVertexAttribBinding] = 0; |
140 } | 140 } |
141 | 141 |
142 //////////////////////////////////////////////////////////////////////////////// | 142 //////////////////////////////////////////////////////////////////////////////// |
143 | 143 |
144 bool GrDrawState::validateVertexAttribs() const { | 144 bool GrDrawState::validateVertexAttribs() const { |
145 // check consistency of effects and attributes | 145 // check consistency of effects and attributes |
146 GrSLType slTypes[kMaxVertexAttribCnt]; | 146 GrSLType slTypes[kMaxVertexAttribCnt]; |
147 for (int i = 0; i < kMaxVertexAttribCnt; ++i) { | 147 for (int i = 0; i < kMaxVertexAttribCnt; ++i) { |
148 slTypes[i] = static_cast<GrSLType>(-1); | 148 slTypes[i] = static_cast<GrSLType>(-1); |
149 } | 149 } |
150 int totalStages = fColorStages.count() + fCoverageStages.count(); | 150 int totalStages = fColorStages.count() + fCoverageStages.count(); |
151 for (int s = 0; s < totalStages; ++s) { | 151 for (int s = 0; s < totalStages; ++s) { |
152 int covIdx = s - fColorStages.count(); | 152 int covIdx = s - fColorStages.count(); |
153 const GrEffectStage& stage = covIdx < 0 ? fColorStages[s] : fCoverageSta
ges[covIdx]; | 153 const GrEffectStage& stage = covIdx < 0 ? fColorStages[s] : fCoverageSta
ges[covIdx]; |
154 const GrEffectRef* effect = stage.getEffect(); | 154 const GrEffectRef* effect = stage.getEffect(); |
155 SkASSERT(NULL != effect); | 155 SkASSERT(NULL != effect); |
156 // make sure that any attribute indices have the correct binding type, t
hat the attrib | 156 // make sure that any attribute indices have the correct binding type, t
hat the attrib |
157 // type and effect's shader lang type are compatible, and that attribute
s shared by | 157 // type and effect's shader lang type are compatible, and that attribute
s shared by |
158 // multiple effects use the same shader lang type. | 158 // multiple effects use the same shader lang type. |
159 const int* attributeIndices = stage.getVertexAttribIndices(); | 159 const int* attributeIndices = stage.getVertexAttribIndices(); |
160 int numAttributes = stage.getVertexAttribIndexCount(); | 160 int numAttributes = stage.getVertexAttribIndexCount(); |
161 for (int i = 0; i < numAttributes; ++i) { | 161 for (int i = 0; i < numAttributes; ++i) { |
162 int attribIndex = attributeIndices[i]; | 162 int attribIndex = attributeIndices[i]; |
163 if (attribIndex >= fCommon.fVACount || | 163 if (attribIndex >= fVACount || |
164 kEffect_GrVertexAttribBinding != fCommon.fVAPtr[attribIndex].fBi
nding) { | 164 kEffect_GrVertexAttribBinding != fVAPtr[attribIndex].fBinding) { |
165 return false; | 165 return false; |
166 } | 166 } |
167 | 167 |
168 GrSLType effectSLType = (*effect)->vertexAttribType(i); | 168 GrSLType effectSLType = (*effect)->vertexAttribType(i); |
169 GrVertexAttribType attribType = fCommon.fVAPtr[attribIndex].fType; | 169 GrVertexAttribType attribType = fVAPtr[attribIndex].fType; |
170 int slVecCount = GrSLTypeVectorCount(effectSLType); | 170 int slVecCount = GrSLTypeVectorCount(effectSLType); |
171 int attribVecCount = GrVertexAttribTypeVectorCount(attribType); | 171 int attribVecCount = GrVertexAttribTypeVectorCount(attribType); |
172 if (slVecCount != attribVecCount || | 172 if (slVecCount != attribVecCount || |
173 (static_cast<GrSLType>(-1) != slTypes[attribIndex] && | 173 (static_cast<GrSLType>(-1) != slTypes[attribIndex] && |
174 slTypes[attribIndex] != effectSLType)) { | 174 slTypes[attribIndex] != effectSLType)) { |
175 return false; | 175 return false; |
176 } | 176 } |
177 slTypes[attribIndex] = effectSLType; | 177 slTypes[attribIndex] = effectSLType; |
178 } | 178 } |
179 } | 179 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 if (this->isCoverageDrawing()) { | 242 if (this->isCoverageDrawing()) { |
243 return true; | 243 return true; |
244 } | 244 } |
245 | 245 |
246 GrColor coverage; | 246 GrColor coverage; |
247 uint32_t validComponentFlags; | 247 uint32_t validComponentFlags; |
248 // Initialize to an unknown starting coverage if per-vertex coverage is spec
ified. | 248 // Initialize to an unknown starting coverage if per-vertex coverage is spec
ified. |
249 if (this->hasCoverageVertexAttribute()) { | 249 if (this->hasCoverageVertexAttribute()) { |
250 validComponentFlags = 0; | 250 validComponentFlags = 0; |
251 } else { | 251 } else { |
252 coverage = fCommon.fCoverage; | 252 coverage = fCoverage; |
253 validComponentFlags = kRGBA_GrColorComponentFlags; | 253 validComponentFlags = kRGBA_GrColorComponentFlags; |
254 } | 254 } |
255 | 255 |
256 // Run through the coverage stages and see if the coverage will be all ones
at the end. | 256 // Run through the coverage stages and see if the coverage will be all ones
at the end. |
257 for (int s = 0; s < fCoverageStages.count(); ++s) { | 257 for (int s = 0; s < fCoverageStages.count(); ++s) { |
258 const GrEffectRef* effect = fCoverageStages[s].getEffect(); | 258 const GrEffectRef* effect = fCoverageStages[s].getEffect(); |
259 (*effect)->getConstantColorComponents(&coverage, &validComponentFlags); | 259 (*effect)->getConstantColorComponents(&coverage, &validComponentFlags); |
260 } | 260 } |
261 return (kRGBA_GrColorComponentFlags == validComponentFlags) && (0xffffffff =
= coverage); | 261 return (kRGBA_GrColorComponentFlags == validComponentFlags) && (0xffffffff =
= coverage); |
262 } | 262 } |
263 | 263 |
264 //////////////////////////////////////////////////////////////////////////////// | 264 //////////////////////////////////////////////////////////////////////////////// |
265 | 265 |
266 // Some blend modes allow folding a fractional coverage value into the color's a
lpha channel, while | 266 // Some blend modes allow folding a fractional coverage value into the color's a
lpha channel, while |
267 // others will blend incorrectly. | 267 // others will blend incorrectly. |
268 bool GrDrawState::canTweakAlphaForCoverage() const { | 268 bool GrDrawState::canTweakAlphaForCoverage() const { |
269 /* | 269 /* |
270 The fractional coverage is f. | 270 The fractional coverage is f. |
271 The src and dst coeffs are Cs and Cd. | 271 The src and dst coeffs are Cs and Cd. |
272 The dst and src colors are S and D. | 272 The dst and src colors are S and D. |
273 We want the blend to compute: f*Cs*S + (f*Cd + (1-f))D. By tweaking the sou
rce color's alpha | 273 We want the blend to compute: f*Cs*S + (f*Cd + (1-f))D. By tweaking the sou
rce color's alpha |
274 we're replacing S with S'=fS. It's obvious that that first term will always
be ok. The second | 274 we're replacing S with S'=fS. It's obvious that that first term will always
be ok. The second |
275 term can be rearranged as [1-(1-Cd)f]D. By substituting in the various poss
ibilities for Cd we | 275 term can be rearranged as [1-(1-Cd)f]D. By substituting in the various poss
ibilities for Cd we |
276 find that only 1, ISA, and ISC produce the correct destination when applied
to S' and D. | 276 find that only 1, ISA, and ISC produce the correct destination when applied
to S' and D. |
277 Also, if we're directly rendering coverage (isCoverageDrawing) then coverag
e is treated as | 277 Also, if we're directly rendering coverage (isCoverageDrawing) then coverag
e is treated as |
278 color by definition. | 278 color by definition. |
279 */ | 279 */ |
280 return kOne_GrBlendCoeff == fCommon.fDstBlend || | 280 return kOne_GrBlendCoeff == fDstBlend || |
281 kISA_GrBlendCoeff == fCommon.fDstBlend || | 281 kISA_GrBlendCoeff == fDstBlend || |
282 kISC_GrBlendCoeff == fCommon.fDstBlend || | 282 kISC_GrBlendCoeff == fDstBlend || |
283 this->isCoverageDrawing(); | 283 this->isCoverageDrawing(); |
284 } | 284 } |
285 | 285 |
286 GrDrawState::BlendOptFlags GrDrawState::getBlendOpts(bool forceCoverage, | 286 GrDrawState::BlendOptFlags GrDrawState::getBlendOpts(bool forceCoverage, |
287 GrBlendCoeff* srcCoeff, | 287 GrBlendCoeff* srcCoeff, |
288 GrBlendCoeff* dstCoeff) con
st { | 288 GrBlendCoeff* dstCoeff) con
st { |
289 | 289 |
290 GrBlendCoeff bogusSrcCoeff, bogusDstCoeff; | 290 GrBlendCoeff bogusSrcCoeff, bogusDstCoeff; |
291 if (NULL == srcCoeff) { | 291 if (NULL == srcCoeff) { |
292 srcCoeff = &bogusSrcCoeff; | 292 srcCoeff = &bogusSrcCoeff; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 return kDisableBlend_BlendOptFlag; | 385 return kDisableBlend_BlendOptFlag; |
386 } | 386 } |
387 return kNone_BlendOpt; | 387 return kNone_BlendOpt; |
388 } | 388 } |
389 | 389 |
390 //////////////////////////////////////////////////////////////////////////////// | 390 //////////////////////////////////////////////////////////////////////////////// |
391 | 391 |
392 void GrDrawState::AutoViewMatrixRestore::restore() { | 392 void GrDrawState::AutoViewMatrixRestore::restore() { |
393 if (NULL != fDrawState) { | 393 if (NULL != fDrawState) { |
394 SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;) | 394 SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;) |
395 fDrawState->fCommon.fViewMatrix = fViewMatrix; | 395 fDrawState->fViewMatrix = fViewMatrix; |
396 SkASSERT(fDrawState->numColorStages() >= fNumColorStages); | 396 SkASSERT(fDrawState->numColorStages() >= fNumColorStages); |
397 int numCoverageStages = fSavedCoordChanges.count() - fNumColorStages; | 397 int numCoverageStages = fSavedCoordChanges.count() - fNumColorStages; |
398 SkASSERT(fDrawState->numCoverageStages() >= numCoverageStages); | 398 SkASSERT(fDrawState->numCoverageStages() >= numCoverageStages); |
399 | 399 |
400 int i = 0; | 400 int i = 0; |
401 for (int s = 0; s < fNumColorStages; ++s, ++i) { | 401 for (int s = 0; s < fNumColorStages; ++s, ++i) { |
402 fDrawState->fColorStages[s].restoreCoordChange(fSavedCoordChanges[i]
); | 402 fDrawState->fColorStages[s].restoreCoordChange(fSavedCoordChanges[i]
); |
403 } | 403 } |
404 for (int s = 0; s < numCoverageStages; ++s, ++i) { | 404 for (int s = 0; s < numCoverageStages; ++s, ++i) { |
405 fDrawState->fCoverageStages[s].restoreCoordChange(fSavedCoordChanges
[i]); | 405 fDrawState->fCoverageStages[s].restoreCoordChange(fSavedCoordChanges
[i]); |
406 } | 406 } |
407 fDrawState = NULL; | 407 fDrawState = NULL; |
408 } | 408 } |
409 } | 409 } |
410 | 410 |
411 void GrDrawState::AutoViewMatrixRestore::set(GrDrawState* drawState, | 411 void GrDrawState::AutoViewMatrixRestore::set(GrDrawState* drawState, |
412 const SkMatrix& preconcatMatrix) { | 412 const SkMatrix& preconcatMatrix) { |
413 this->restore(); | 413 this->restore(); |
414 | 414 |
415 SkASSERT(NULL == fDrawState); | 415 SkASSERT(NULL == fDrawState); |
416 if (NULL == drawState || preconcatMatrix.isIdentity()) { | 416 if (NULL == drawState || preconcatMatrix.isIdentity()) { |
417 return; | 417 return; |
418 } | 418 } |
419 fDrawState = drawState; | 419 fDrawState = drawState; |
420 | 420 |
421 fViewMatrix = drawState->getViewMatrix(); | 421 fViewMatrix = drawState->getViewMatrix(); |
422 drawState->fCommon.fViewMatrix.preConcat(preconcatMatrix); | 422 drawState->fViewMatrix.preConcat(preconcatMatrix); |
423 | 423 |
424 this->doEffectCoordChanges(preconcatMatrix); | 424 this->doEffectCoordChanges(preconcatMatrix); |
425 SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;) | 425 SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;) |
426 } | 426 } |
427 | 427 |
428 bool GrDrawState::AutoViewMatrixRestore::setIdentity(GrDrawState* drawState) { | 428 bool GrDrawState::AutoViewMatrixRestore::setIdentity(GrDrawState* drawState) { |
429 this->restore(); | 429 this->restore(); |
430 | 430 |
431 if (NULL == drawState) { | 431 if (NULL == drawState) { |
432 return false; | 432 return false; |
433 } | 433 } |
434 | 434 |
435 if (drawState->getViewMatrix().isIdentity()) { | 435 if (drawState->getViewMatrix().isIdentity()) { |
436 return true; | 436 return true; |
437 } | 437 } |
438 | 438 |
439 fViewMatrix = drawState->getViewMatrix(); | 439 fViewMatrix = drawState->getViewMatrix(); |
440 if (0 == drawState->numTotalStages()) { | 440 if (0 == drawState->numTotalStages()) { |
441 drawState->fCommon.fViewMatrix.reset(); | 441 drawState->fViewMatrix.reset(); |
442 fDrawState = drawState; | 442 fDrawState = drawState; |
443 fNumColorStages = 0; | 443 fNumColorStages = 0; |
444 fSavedCoordChanges.reset(0); | 444 fSavedCoordChanges.reset(0); |
445 SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;) | 445 SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;) |
446 return true; | 446 return true; |
447 } else { | 447 } else { |
448 SkMatrix inv; | 448 SkMatrix inv; |
449 if (!fViewMatrix.invert(&inv)) { | 449 if (!fViewMatrix.invert(&inv)) { |
450 return false; | 450 return false; |
451 } | 451 } |
452 drawState->fCommon.fViewMatrix.reset(); | 452 drawState->fViewMatrix.reset(); |
453 fDrawState = drawState; | 453 fDrawState = drawState; |
454 this->doEffectCoordChanges(inv); | 454 this->doEffectCoordChanges(inv); |
455 SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;) | 455 SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;) |
456 return true; | 456 return true; |
457 } | 457 } |
458 } | 458 } |
459 | 459 |
460 void GrDrawState::AutoViewMatrixRestore::doEffectCoordChanges(const SkMatrix& co
ordChangeMatrix) { | 460 void GrDrawState::AutoViewMatrixRestore::doEffectCoordChanges(const SkMatrix& co
ordChangeMatrix) { |
461 fSavedCoordChanges.reset(fDrawState->numTotalStages()); | 461 fSavedCoordChanges.reset(fDrawState->numTotalStages()); |
462 int i = 0; | 462 int i = 0; |
463 | 463 |
464 fNumColorStages = fDrawState->numColorStages(); | 464 fNumColorStages = fDrawState->numColorStages(); |
465 for (int s = 0; s < fNumColorStages; ++s, ++i) { | 465 for (int s = 0; s < fNumColorStages; ++s, ++i) { |
466 fDrawState->fColorStages[s].saveCoordChange(&fSavedCoordChanges[i]); | 466 fDrawState->fColorStages[s].saveCoordChange(&fSavedCoordChanges[i]); |
467 fDrawState->fColorStages[s].localCoordChange(coordChangeMatrix); | 467 fDrawState->fColorStages[s].localCoordChange(coordChangeMatrix); |
468 } | 468 } |
469 | 469 |
470 int numCoverageStages = fDrawState->numCoverageStages(); | 470 int numCoverageStages = fDrawState->numCoverageStages(); |
471 for (int s = 0; s < numCoverageStages; ++s, ++i) { | 471 for (int s = 0; s < numCoverageStages; ++s, ++i) { |
472 fDrawState->fCoverageStages[s].saveCoordChange(&fSavedCoordChanges[i]); | 472 fDrawState->fCoverageStages[s].saveCoordChange(&fSavedCoordChanges[i]); |
473 fDrawState->fCoverageStages[s].localCoordChange(coordChangeMatrix); | 473 fDrawState->fCoverageStages[s].localCoordChange(coordChangeMatrix); |
474 } | 474 } |
475 } | 475 } |
OLD | NEW |