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 #include "GrDrawTargetCaps.h" | 10 #include "GrDrawTargetCaps.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); | 68 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); |
69 this->setRenderTarget(that.fRenderTarget.get()); | 69 this->setRenderTarget(that.fRenderTarget.get()); |
70 fColor = that.fColor; | 70 fColor = that.fColor; |
71 fViewMatrix = that.fViewMatrix; | 71 fViewMatrix = that.fViewMatrix; |
72 fSrcBlend = that.fSrcBlend; | 72 fSrcBlend = that.fSrcBlend; |
73 fDstBlend = that.fDstBlend; | 73 fDstBlend = that.fDstBlend; |
74 fBlendConstant = that.fBlendConstant; | 74 fBlendConstant = that.fBlendConstant; |
75 fFlagBits = that.fFlagBits; | 75 fFlagBits = that.fFlagBits; |
76 fVACount = that.fVACount; | 76 fVACount = that.fVACount; |
77 fVAPtr = that.fVAPtr; | 77 fVAPtr = that.fVAPtr; |
78 fVertexSize = that.fVertexSize; | 78 fVAStride = that.fVAStride; |
79 fStencilSettings = that.fStencilSettings; | 79 fStencilSettings = that.fStencilSettings; |
80 fCoverage = that.fCoverage; | 80 fCoverage = that.fCoverage; |
81 fDrawFace = that.fDrawFace; | 81 fDrawFace = that.fDrawFace; |
82 fColorStages = that.fColorStages; | 82 fColorStages = that.fColorStages; |
83 fCoverageStages = that.fCoverageStages; | 83 fCoverageStages = that.fCoverageStages; |
84 fOptSrcBlend = that.fOptSrcBlend; | 84 fOptSrcBlend = that.fOptSrcBlend; |
85 fOptDstBlend = that.fOptDstBlend; | 85 fOptDstBlend = that.fOptDstBlend; |
86 fBlendOptFlags = that.fBlendOptFlags; | 86 fBlendOptFlags = that.fBlendOptFlags; |
87 | 87 |
88 fHints = that.fHints; | 88 fHints = that.fHints; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 this->setState(GrDrawState::kDither_StateBit, paint.isDither()); | 171 this->setState(GrDrawState::kDither_StateBit, paint.isDither()); |
172 this->setState(GrDrawState::kHWAntialias_StateBit, paint.isAntiAlias()); | 172 this->setState(GrDrawState::kHWAntialias_StateBit, paint.isAntiAlias()); |
173 | 173 |
174 this->setBlendFunc(paint.getSrcBlendCoeff(), paint.getDstBlendCoeff()); | 174 this->setBlendFunc(paint.getSrcBlendCoeff(), paint.getDstBlendCoeff()); |
175 this->setCoverage(paint.getCoverage()); | 175 this->setCoverage(paint.getCoverage()); |
176 this->invalidateBlendOptFlags(); | 176 this->invalidateBlendOptFlags(); |
177 } | 177 } |
178 | 178 |
179 //////////////////////////////////////////////////////////////////////////////// | 179 //////////////////////////////////////////////////////////////////////////////// |
180 | 180 |
181 static size_t vertex_size(const GrVertexAttrib* attribs, int count) { | 181 static void validate_vertex_size(const GrVertexAttrib* attribs, int count, size_ t stride) { |
bsalomon
2014/08/27 17:46:27
validate_vertex_attribs?
egdaniel
2014/08/27 18:33:55
Done.
| |
182 // this works as long as we're 4 byte-aligned | 182 // this works as long as we're 4 byte-aligned |
183 #ifdef SK_DEBUG | 183 #ifdef SK_DEBUG |
184 uint32_t overlapCheck = 0; | 184 uint32_t overlapCheck = 0; |
185 #endif | |
186 SkASSERT(count <= GrRODrawState::kMaxVertexAttribCnt); | 185 SkASSERT(count <= GrRODrawState::kMaxVertexAttribCnt); |
187 size_t size = 0; | |
188 for (int index = 0; index < count; ++index) { | 186 for (int index = 0; index < count; ++index) { |
189 size_t attribSize = GrVertexAttribTypeSize(attribs[index].fType); | 187 size_t attribSize = GrVertexAttribTypeSize(attribs[index].fType); |
190 size += attribSize; | 188 size_t attribOffset = attribs[index].fOffset; |
191 #ifdef SK_DEBUG | 189 SkASSERT(attribOffset + attribSize <= stride); |
192 size_t dwordCount = attribSize >> 2; | 190 size_t dwordCount = attribSize >> 2; |
193 uint32_t mask = (1 << dwordCount)-1; | 191 uint32_t mask = (1 << dwordCount)-1; |
194 size_t offsetShift = attribs[index].fOffset >> 2; | 192 size_t offsetShift = attribOffset >> 2; |
195 SkASSERT(!(overlapCheck & (mask << offsetShift))); | 193 SkASSERT(!(overlapCheck & (mask << offsetShift))); |
196 overlapCheck |= (mask << offsetShift); | 194 overlapCheck |= (mask << offsetShift); |
197 #endif | 195 #endif |
198 } | 196 } |
199 return size; | |
200 } | 197 } |
201 | 198 |
202 //////////////////////////////////////////////////////////////////////////////// | 199 //////////////////////////////////////////////////////////////////////////////// |
203 | 200 |
204 void GrDrawState::setVertexAttribs(const GrVertexAttrib* attribs, int count) { | 201 void GrDrawState::setVertexAttribs(const GrVertexAttrib* attribs, int count, siz e_t stride) { |
205 SkASSERT(count <= kMaxVertexAttribCnt); | 202 SkASSERT(count <= kMaxVertexAttribCnt); |
206 | 203 |
207 fVAPtr = attribs; | 204 fVAPtr = attribs; |
208 fVACount = count; | 205 fVACount = count; |
209 fVertexSize = vertex_size(fVAPtr, fVACount); | 206 fVAStride = stride; |
207 validate_vertex_size(fVAPtr, fVACount, fVAStride); | |
210 | 208 |
211 // Set all the indices to -1 | 209 // Set all the indices to -1 |
212 memset(fFixedFunctionVertexAttribIndices, | 210 memset(fFixedFunctionVertexAttribIndices, |
213 0xff, | 211 0xff, |
214 sizeof(fFixedFunctionVertexAttribIndices)); | 212 sizeof(fFixedFunctionVertexAttribIndices)); |
215 #ifdef SK_DEBUG | 213 #ifdef SK_DEBUG |
216 uint32_t overlapCheck = 0; | 214 uint32_t overlapCheck = 0; |
217 #endif | 215 #endif |
218 for (int i = 0; i < count; ++i) { | 216 for (int i = 0; i < count; ++i) { |
219 if (attribs[i].fBinding < kGrFixedFunctionVertexAttribBindingCnt) { | 217 if (attribs[i].fBinding < kGrFixedFunctionVertexAttribBindingCnt) { |
(...skipping 17 matching lines...) Expand all Loading... | |
237 } | 235 } |
238 | 236 |
239 //////////////////////////////////////////////////////////////////////////////// | 237 //////////////////////////////////////////////////////////////////////////////// |
240 | 238 |
241 void GrDrawState::setDefaultVertexAttribs() { | 239 void GrDrawState::setDefaultVertexAttribs() { |
242 static const GrVertexAttrib kPositionAttrib = | 240 static const GrVertexAttrib kPositionAttrib = |
243 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}; | 241 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}; |
244 | 242 |
245 fVAPtr = &kPositionAttrib; | 243 fVAPtr = &kPositionAttrib; |
246 fVACount = 1; | 244 fVACount = 1; |
247 fVertexSize = GrVertexAttribTypeSize(kVec2f_GrVertexAttribType); | 245 fVAStride = GrVertexAttribTypeSize(kVec2f_GrVertexAttribType); |
248 | 246 |
249 // set all the fixed function indices to -1 except position. | 247 // set all the fixed function indices to -1 except position. |
250 memset(fFixedFunctionVertexAttribIndices, | 248 memset(fFixedFunctionVertexAttribIndices, |
251 0xff, | 249 0xff, |
252 sizeof(fFixedFunctionVertexAttribIndices)); | 250 sizeof(fFixedFunctionVertexAttribIndices)); |
253 fFixedFunctionVertexAttribIndices[kPosition_GrVertexAttribBinding] = 0; | 251 fFixedFunctionVertexAttribIndices[kPosition_GrVertexAttribBinding] = 0; |
254 this->invalidateBlendOptFlags(); | 252 this->invalidateBlendOptFlags(); |
255 } | 253 } |
256 | 254 |
257 //////////////////////////////////////////////////////////////////////////////// | 255 //////////////////////////////////////////////////////////////////////////////// |
(...skipping 14 matching lines...) Expand all Loading... | |
272 } | 270 } |
273 | 271 |
274 ////////////////////////////////////////////////////////////////////////////// | 272 ////////////////////////////////////////////////////////////////////////////// |
275 | 273 |
276 GrDrawState::AutoVertexAttribRestore::AutoVertexAttribRestore( | 274 GrDrawState::AutoVertexAttribRestore::AutoVertexAttribRestore( |
277 GrDrawState* drawState) { | 275 GrDrawState* drawState) { |
278 SkASSERT(NULL != drawState); | 276 SkASSERT(NULL != drawState); |
279 fDrawState = drawState; | 277 fDrawState = drawState; |
280 fVAPtr = drawState->fVAPtr; | 278 fVAPtr = drawState->fVAPtr; |
281 fVACount = drawState->fVACount; | 279 fVACount = drawState->fVACount; |
280 fVAStride = drawState->fVAStride; | |
282 fDrawState->setDefaultVertexAttribs(); | 281 fDrawState->setDefaultVertexAttribs(); |
283 } | 282 } |
284 | 283 |
285 //////////////////////////////////////////////////////////////////////////////s | 284 //////////////////////////////////////////////////////////////////////////////s |
286 | 285 |
287 void GrDrawState::AutoRestoreEffects::set(GrDrawState* ds) { | 286 void GrDrawState::AutoRestoreEffects::set(GrDrawState* ds) { |
288 if (NULL != fDrawState) { | 287 if (NULL != fDrawState) { |
289 int m = fDrawState->numColorStages() - fColorEffectCnt; | 288 int m = fDrawState->numColorStages() - fColorEffectCnt; |
290 SkASSERT(m >= 0); | 289 SkASSERT(m >= 0); |
291 fDrawState->fColorStages.pop_back_n(m); | 290 fDrawState->fColorStages.pop_back_n(m); |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
561 //////////////////////////////////////////////////////////////////////////////// | 560 //////////////////////////////////////////////////////////////////////////////// |
562 | 561 |
563 bool GrDrawState::canIgnoreColorAttribute() const { | 562 bool GrDrawState::canIgnoreColorAttribute() const { |
564 if (fBlendOptFlags & kInvalid_BlendOptFlag) { | 563 if (fBlendOptFlags & kInvalid_BlendOptFlag) { |
565 this->getBlendOpts(); | 564 this->getBlendOpts(); |
566 } | 565 } |
567 return SkToBool(fBlendOptFlags & (GrRODrawState::kEmitTransBlack_BlendOptFla g | | 566 return SkToBool(fBlendOptFlags & (GrRODrawState::kEmitTransBlack_BlendOptFla g | |
568 GrRODrawState::kEmitCoverage_BlendOptFlag) ); | 567 GrRODrawState::kEmitCoverage_BlendOptFlag) ); |
569 } | 568 } |
570 | 569 |
OLD | NEW |