Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: src/gpu/GrDrawState.cpp

Issue 22850006: Replace uses of GrAssert by SkASSERT. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/gpu/GrDrawState.h ('k') | src/gpu/GrDrawTarget.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 (!fCommon.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 fCommon.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 GrAssert(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));
(...skipping 22 matching lines...) Expand all
63 this->setCoverage(paint.getCoverage()); 63 this->setCoverage(paint.getCoverage());
64 } 64 }
65 65
66 //////////////////////////////////////////////////////////////////////////////// 66 ////////////////////////////////////////////////////////////////////////////////
67 67
68 static size_t vertex_size(const GrVertexAttrib* attribs, int count) { 68 static size_t vertex_size(const GrVertexAttrib* attribs, int count) {
69 // this works as long as we're 4 byte-aligned 69 // this works as long as we're 4 byte-aligned
70 #if GR_DEBUG 70 #if GR_DEBUG
71 uint32_t overlapCheck = 0; 71 uint32_t overlapCheck = 0;
72 #endif 72 #endif
73 GrAssert(count <= GrDrawState::kMaxVertexAttribCnt); 73 SkASSERT(count <= GrDrawState::kMaxVertexAttribCnt);
74 size_t size = 0; 74 size_t size = 0;
75 for (int index = 0; index < count; ++index) { 75 for (int index = 0; index < count; ++index) {
76 size_t attribSize = GrVertexAttribTypeSize(attribs[index].fType); 76 size_t attribSize = GrVertexAttribTypeSize(attribs[index].fType);
77 size += attribSize; 77 size += attribSize;
78 #if GR_DEBUG 78 #if GR_DEBUG
79 size_t dwordCount = attribSize >> 2; 79 size_t dwordCount = attribSize >> 2;
80 uint32_t mask = (1 << dwordCount)-1; 80 uint32_t mask = (1 << dwordCount)-1;
81 size_t offsetShift = attribs[index].fOffset >> 2; 81 size_t offsetShift = attribs[index].fOffset >> 2;
82 GrAssert(!(overlapCheck & (mask << offsetShift))); 82 SkASSERT(!(overlapCheck & (mask << offsetShift)));
83 overlapCheck |= (mask << offsetShift); 83 overlapCheck |= (mask << offsetShift);
84 #endif 84 #endif
85 } 85 }
86 return size; 86 return size;
87 } 87 }
88 88
89 size_t GrDrawState::getVertexSize() const { 89 size_t GrDrawState::getVertexSize() const {
90 return vertex_size(fCommon.fVAPtr, fCommon.fVACount); 90 return vertex_size(fCommon.fVAPtr, fCommon.fVACount);
91 } 91 }
92 92
93 //////////////////////////////////////////////////////////////////////////////// 93 ////////////////////////////////////////////////////////////////////////////////
94 94
95 void GrDrawState::setVertexAttribs(const GrVertexAttrib* attribs, int count) { 95 void GrDrawState::setVertexAttribs(const GrVertexAttrib* attribs, int count) {
96 GrAssert(count <= kMaxVertexAttribCnt); 96 SkASSERT(count <= kMaxVertexAttribCnt);
97 97
98 fCommon.fVAPtr = attribs; 98 fCommon.fVAPtr = attribs;
99 fCommon.fVACount = count; 99 fCommon.fVACount = count;
100 100
101 // Set all the indices to -1 101 // Set all the indices to -1
102 memset(fCommon.fFixedFunctionVertexAttribIndices, 102 memset(fCommon.fFixedFunctionVertexAttribIndices,
103 0xff, 103 0xff,
104 sizeof(fCommon.fFixedFunctionVertexAttribIndices)); 104 sizeof(fCommon.fFixedFunctionVertexAttribIndices));
105 #if GR_DEBUG 105 #if GR_DEBUG
106 uint32_t overlapCheck = 0; 106 uint32_t overlapCheck = 0;
107 #endif 107 #endif
108 for (int i = 0; i < count; ++i) { 108 for (int i = 0; i < count; ++i) {
109 if (attribs[i].fBinding < kGrFixedFunctionVertexAttribBindingCnt) { 109 if (attribs[i].fBinding < kGrFixedFunctionVertexAttribBindingCnt) {
110 // The fixed function attribs can only be specified once 110 // The fixed function attribs can only be specified once
111 GrAssert(-1 == fCommon.fFixedFunctionVertexAttribIndices[attribs[i]. fBinding]); 111 SkASSERT(-1 == fCommon.fFixedFunctionVertexAttribIndices[attribs[i]. fBinding]);
112 GrAssert(GrFixedFunctionVertexAttribVectorCount(attribs[i].fBinding) == 112 SkASSERT(GrFixedFunctionVertexAttribVectorCount(attribs[i].fBinding) ==
113 GrVertexAttribTypeVectorCount(attribs[i].fType)); 113 GrVertexAttribTypeVectorCount(attribs[i].fType));
114 fCommon.fFixedFunctionVertexAttribIndices[attribs[i].fBinding] = i; 114 fCommon.fFixedFunctionVertexAttribIndices[attribs[i].fBinding] = i;
115 } 115 }
116 #if GR_DEBUG 116 #if GR_DEBUG
117 size_t dwordCount = GrVertexAttribTypeSize(attribs[i].fType) >> 2; 117 size_t dwordCount = GrVertexAttribTypeSize(attribs[i].fType) >> 2;
118 uint32_t mask = (1 << dwordCount)-1; 118 uint32_t mask = (1 << dwordCount)-1;
119 size_t offsetShift = attribs[i].fOffset >> 2; 119 size_t offsetShift = attribs[i].fOffset >> 2;
120 GrAssert(!(overlapCheck & (mask << offsetShift))); 120 SkASSERT(!(overlapCheck & (mask << offsetShift)));
121 overlapCheck |= (mask << offsetShift); 121 overlapCheck |= (mask << offsetShift);
122 #endif 122 #endif
123 } 123 }
124 // Positions must be specified. 124 // Positions must be specified.
125 GrAssert(-1 != fCommon.fFixedFunctionVertexAttribIndices[kPosition_GrVertexA ttribBinding]); 125 SkASSERT(-1 != fCommon.fFixedFunctionVertexAttribIndices[kPosition_GrVertexA ttribBinding]);
126 } 126 }
127 127
128 //////////////////////////////////////////////////////////////////////////////// 128 ////////////////////////////////////////////////////////////////////////////////
129 129
130 void GrDrawState::setDefaultVertexAttribs() { 130 void GrDrawState::setDefaultVertexAttribs() {
131 static const GrVertexAttrib kPositionAttrib = 131 static const GrVertexAttrib kPositionAttrib =
132 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}; 132 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding};
133 133
134 fCommon.fVAPtr = &kPositionAttrib; 134 fCommon.fVAPtr = &kPositionAttrib;
135 fCommon.fVACount = 1; 135 fCommon.fVACount = 1;
(...skipping 11 matching lines...) Expand all
147 // check consistency of effects and attributes 147 // check consistency of effects and attributes
148 GrSLType slTypes[kMaxVertexAttribCnt]; 148 GrSLType slTypes[kMaxVertexAttribCnt];
149 for (int i = 0; i < kMaxVertexAttribCnt; ++i) { 149 for (int i = 0; i < kMaxVertexAttribCnt; ++i) {
150 slTypes[i] = static_cast<GrSLType>(-1); 150 slTypes[i] = static_cast<GrSLType>(-1);
151 } 151 }
152 int totalStages = fColorStages.count() + fCoverageStages.count(); 152 int totalStages = fColorStages.count() + fCoverageStages.count();
153 for (int s = 0; s < totalStages; ++s) { 153 for (int s = 0; s < totalStages; ++s) {
154 int covIdx = s - fColorStages.count(); 154 int covIdx = s - fColorStages.count();
155 const GrEffectStage& stage = covIdx < 0 ? fColorStages[s] : fCoverageSta ges[covIdx]; 155 const GrEffectStage& stage = covIdx < 0 ? fColorStages[s] : fCoverageSta ges[covIdx];
156 const GrEffectRef* effect = stage.getEffect(); 156 const GrEffectRef* effect = stage.getEffect();
157 GrAssert(NULL != effect); 157 SkASSERT(NULL != effect);
158 // make sure that any attribute indices have the correct binding type, t hat the attrib 158 // make sure that any attribute indices have the correct binding type, t hat the attrib
159 // type and effect's shader lang type are compatible, and that attribute s shared by 159 // type and effect's shader lang type are compatible, and that attribute s shared by
160 // multiple effects use the same shader lang type. 160 // multiple effects use the same shader lang type.
161 const int* attributeIndices = stage.getVertexAttribIndices(); 161 const int* attributeIndices = stage.getVertexAttribIndices();
162 int numAttributes = stage.getVertexAttribIndexCount(); 162 int numAttributes = stage.getVertexAttribIndexCount();
163 for (int i = 0; i < numAttributes; ++i) { 163 for (int i = 0; i < numAttributes; ++i) {
164 int attribIndex = attributeIndices[i]; 164 int attribIndex = attributeIndices[i];
165 if (attribIndex >= fCommon.fVACount || 165 if (attribIndex >= fCommon.fVACount ||
166 kEffect_GrVertexAttribBinding != fCommon.fVAPtr[attribIndex].fBi nding) { 166 kEffect_GrVertexAttribBinding != fCommon.fVAPtr[attribIndex].fBi nding) {
167 return false; 167 return false;
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 } 395 }
396 return kNone_BlendOpt; 396 return kNone_BlendOpt;
397 } 397 }
398 398
399 //////////////////////////////////////////////////////////////////////////////// 399 ////////////////////////////////////////////////////////////////////////////////
400 400
401 void GrDrawState::AutoViewMatrixRestore::restore() { 401 void GrDrawState::AutoViewMatrixRestore::restore() {
402 if (NULL != fDrawState) { 402 if (NULL != fDrawState) {
403 GR_DEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;) 403 GR_DEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;)
404 fDrawState->fCommon.fViewMatrix = fViewMatrix; 404 fDrawState->fCommon.fViewMatrix = fViewMatrix;
405 GrAssert(fDrawState->numColorStages() >= fNumColorStages); 405 SkASSERT(fDrawState->numColorStages() >= fNumColorStages);
406 int numCoverageStages = fSavedCoordChanges.count() - fNumColorStages; 406 int numCoverageStages = fSavedCoordChanges.count() - fNumColorStages;
407 GrAssert(fDrawState->numCoverageStages() >= numCoverageStages); 407 SkASSERT(fDrawState->numCoverageStages() >= numCoverageStages);
408 408
409 int i = 0; 409 int i = 0;
410 for (int s = 0; s < fNumColorStages; ++s, ++i) { 410 for (int s = 0; s < fNumColorStages; ++s, ++i) {
411 fDrawState->fColorStages[s].restoreCoordChange(fSavedCoordChanges[i] ); 411 fDrawState->fColorStages[s].restoreCoordChange(fSavedCoordChanges[i] );
412 } 412 }
413 for (int s = 0; s < numCoverageStages; ++s, ++i) { 413 for (int s = 0; s < numCoverageStages; ++s, ++i) {
414 fDrawState->fCoverageStages[s].restoreCoordChange(fSavedCoordChanges [i]); 414 fDrawState->fCoverageStages[s].restoreCoordChange(fSavedCoordChanges [i]);
415 } 415 }
416 fDrawState = NULL; 416 fDrawState = NULL;
417 } 417 }
418 } 418 }
419 419
420 void GrDrawState::AutoViewMatrixRestore::set(GrDrawState* drawState, 420 void GrDrawState::AutoViewMatrixRestore::set(GrDrawState* drawState,
421 const SkMatrix& preconcatMatrix) { 421 const SkMatrix& preconcatMatrix) {
422 this->restore(); 422 this->restore();
423 423
424 GrAssert(NULL == fDrawState); 424 SkASSERT(NULL == fDrawState);
425 if (NULL == drawState || preconcatMatrix.isIdentity()) { 425 if (NULL == drawState || preconcatMatrix.isIdentity()) {
426 return; 426 return;
427 } 427 }
428 fDrawState = drawState; 428 fDrawState = drawState;
429 429
430 fViewMatrix = drawState->getViewMatrix(); 430 fViewMatrix = drawState->getViewMatrix();
431 drawState->fCommon.fViewMatrix.preConcat(preconcatMatrix); 431 drawState->fCommon.fViewMatrix.preConcat(preconcatMatrix);
432 432
433 this->doEffectCoordChanges(preconcatMatrix); 433 this->doEffectCoordChanges(preconcatMatrix);
434 GR_DEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;) 434 GR_DEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;)
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 fDrawState->fColorStages[s].saveCoordChange(&fSavedCoordChanges[i]); 475 fDrawState->fColorStages[s].saveCoordChange(&fSavedCoordChanges[i]);
476 fDrawState->fColorStages[s].localCoordChange(coordChangeMatrix); 476 fDrawState->fColorStages[s].localCoordChange(coordChangeMatrix);
477 } 477 }
478 478
479 int numCoverageStages = fDrawState->numCoverageStages(); 479 int numCoverageStages = fDrawState->numCoverageStages();
480 for (int s = 0; s < numCoverageStages; ++s, ++i) { 480 for (int s = 0; s < numCoverageStages; ++s, ++i) {
481 fDrawState->fCoverageStages[s].saveCoordChange(&fSavedCoordChanges[i]); 481 fDrawState->fCoverageStages[s].saveCoordChange(&fSavedCoordChanges[i]);
482 fDrawState->fCoverageStages[s].localCoordChange(coordChangeMatrix); 482 fDrawState->fCoverageStages[s].localCoordChange(coordChangeMatrix);
483 } 483 }
484 } 484 }
OLDNEW
« no previous file with comments | « src/gpu/GrDrawState.h ('k') | src/gpu/GrDrawTarget.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698