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

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

Issue 404473007: Cache the return values of getBlendOpts in GrDrawState (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Use one if in ARE Created 6 years, 5 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
« no previous file with comments | « src/gpu/GrDrawState.h ('k') | no next file » | 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
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
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());
61 this->setCoverage(paint.getCoverage()); 61 this->setCoverage(paint.getCoverage());
62 this->invalidateBlendOptFlags();
62 } 63 }
63 64
64 //////////////////////////////////////////////////////////////////////////////// 65 ////////////////////////////////////////////////////////////////////////////////
65 66
66 static size_t vertex_size(const GrVertexAttrib* attribs, int count) { 67 static size_t vertex_size(const GrVertexAttrib* attribs, int count) {
67 // this works as long as we're 4 byte-aligned 68 // this works as long as we're 4 byte-aligned
68 #ifdef SK_DEBUG 69 #ifdef SK_DEBUG
69 uint32_t overlapCheck = 0; 70 uint32_t overlapCheck = 0;
70 #endif 71 #endif
71 SkASSERT(count <= GrDrawState::kMaxVertexAttribCnt); 72 SkASSERT(count <= GrDrawState::kMaxVertexAttribCnt);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 fFixedFunctionVertexAttribIndices[attribs[i].fBinding] = i; 113 fFixedFunctionVertexAttribIndices[attribs[i].fBinding] = i;
113 } 114 }
114 #ifdef SK_DEBUG 115 #ifdef SK_DEBUG
115 size_t dwordCount = GrVertexAttribTypeSize(attribs[i].fType) >> 2; 116 size_t dwordCount = GrVertexAttribTypeSize(attribs[i].fType) >> 2;
116 uint32_t mask = (1 << dwordCount)-1; 117 uint32_t mask = (1 << dwordCount)-1;
117 size_t offsetShift = attribs[i].fOffset >> 2; 118 size_t offsetShift = attribs[i].fOffset >> 2;
118 SkASSERT(!(overlapCheck & (mask << offsetShift))); 119 SkASSERT(!(overlapCheck & (mask << offsetShift)));
119 overlapCheck |= (mask << offsetShift); 120 overlapCheck |= (mask << offsetShift);
120 #endif 121 #endif
121 } 122 }
123 this->invalidateBlendOptFlags();
122 // Positions must be specified. 124 // Positions must be specified.
123 SkASSERT(-1 != fFixedFunctionVertexAttribIndices[kPosition_GrVertexAttribBin ding]); 125 SkASSERT(-1 != fFixedFunctionVertexAttribIndices[kPosition_GrVertexAttribBin ding]);
124 } 126 }
125 127
126 //////////////////////////////////////////////////////////////////////////////// 128 ////////////////////////////////////////////////////////////////////////////////
127 129
128 void GrDrawState::setDefaultVertexAttribs() { 130 void GrDrawState::setDefaultVertexAttribs() {
129 static const GrVertexAttrib kPositionAttrib = 131 static const GrVertexAttrib kPositionAttrib =
130 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}; 132 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding};
131 133
132 fVAPtr = &kPositionAttrib; 134 fVAPtr = &kPositionAttrib;
133 fVACount = 1; 135 fVACount = 1;
134 136
135 // set all the fixed function indices to -1 except position. 137 // set all the fixed function indices to -1 except position.
136 memset(fFixedFunctionVertexAttribIndices, 138 memset(fFixedFunctionVertexAttribIndices,
137 0xff, 139 0xff,
138 sizeof(fFixedFunctionVertexAttribIndices)); 140 sizeof(fFixedFunctionVertexAttribIndices));
139 fFixedFunctionVertexAttribIndices[kPosition_GrVertexAttribBinding] = 0; 141 fFixedFunctionVertexAttribIndices[kPosition_GrVertexAttribBinding] = 0;
142 this->invalidateBlendOptFlags();
140 } 143 }
141 144
142 //////////////////////////////////////////////////////////////////////////////// 145 ////////////////////////////////////////////////////////////////////////////////
143 146
144 bool GrDrawState::validateVertexAttribs() const { 147 bool GrDrawState::validateVertexAttribs() const {
145 // check consistency of effects and attributes 148 // check consistency of effects and attributes
146 GrSLType slTypes[kMaxVertexAttribCnt]; 149 GrSLType slTypes[kMaxVertexAttribCnt];
147 for (int i = 0; i < kMaxVertexAttribCnt; ++i) { 150 for (int i = 0; i < kMaxVertexAttribCnt; ++i) {
148 slTypes[i] = static_cast<GrSLType>(-1); 151 slTypes[i] = static_cast<GrSLType>(-1);
149 } 152 }
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 */ 282 */
280 return kOne_GrBlendCoeff == fDstBlend || 283 return kOne_GrBlendCoeff == fDstBlend ||
281 kISA_GrBlendCoeff == fDstBlend || 284 kISA_GrBlendCoeff == fDstBlend ||
282 kISC_GrBlendCoeff == fDstBlend || 285 kISC_GrBlendCoeff == fDstBlend ||
283 this->isCoverageDrawing(); 286 this->isCoverageDrawing();
284 } 287 }
285 288
286 GrDrawState::BlendOptFlags GrDrawState::getBlendOpts(bool forceCoverage, 289 GrDrawState::BlendOptFlags GrDrawState::getBlendOpts(bool forceCoverage,
287 GrBlendCoeff* srcCoeff, 290 GrBlendCoeff* srcCoeff,
288 GrBlendCoeff* dstCoeff) con st { 291 GrBlendCoeff* dstCoeff) con st {
289
290 GrBlendCoeff bogusSrcCoeff, bogusDstCoeff; 292 GrBlendCoeff bogusSrcCoeff, bogusDstCoeff;
291 if (NULL == srcCoeff) { 293 if (NULL == srcCoeff) {
292 srcCoeff = &bogusSrcCoeff; 294 srcCoeff = &bogusSrcCoeff;
293 } 295 }
294 *srcCoeff = this->getSrcBlendCoeff();
295
296 if (NULL == dstCoeff) { 296 if (NULL == dstCoeff) {
297 dstCoeff = &bogusDstCoeff; 297 dstCoeff = &bogusDstCoeff;
298 } 298 }
299
300 if (forceCoverage) {
301 return this->calcBlendOpts(true, srcCoeff, dstCoeff);
302 }
303
304 if (0 == (fBlendOptFlags & kInvalid_BlendOptFlag)) {
305 *srcCoeff = fOptSrcBlend;
306 *dstCoeff = fOptDstBlend;
307 return fBlendOptFlags;
308 }
309
310 fBlendOptFlags = this->calcBlendOpts(forceCoverage, srcCoeff, dstCoeff);
311 fOptSrcBlend = *srcCoeff;
312 fOptDstBlend = *dstCoeff;
313
314 return fBlendOptFlags;
315 }
316
317 GrDrawState::BlendOptFlags GrDrawState::calcBlendOpts(bool forceCoverage,
318 GrBlendCoeff* srcCoeff,
319 GrBlendCoeff* dstCoeff) co nst {
320 *srcCoeff = this->getSrcBlendCoeff();
299 *dstCoeff = this->getDstBlendCoeff(); 321 *dstCoeff = this->getDstBlendCoeff();
300 322
301 if (this->isColorWriteDisabled()) { 323 if (this->isColorWriteDisabled()) {
302 *srcCoeff = kZero_GrBlendCoeff; 324 *srcCoeff = kZero_GrBlendCoeff;
303 *dstCoeff = kOne_GrBlendCoeff; 325 *dstCoeff = kOne_GrBlendCoeff;
304 } 326 }
305 327
306 bool srcAIsOne = this->srcAlphaWillBeOne(); 328 bool srcAIsOne = this->srcAlphaWillBeOne();
307 bool dstCoeffIsOne = kOne_GrBlendCoeff == *dstCoeff || 329 bool dstCoeffIsOne = kOne_GrBlendCoeff == *dstCoeff ||
308 (kSA_GrBlendCoeff == *dstCoeff && srcAIsOne); 330 (kSA_GrBlendCoeff == *dstCoeff && srcAIsOne);
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 fDrawState->fColorStages[s].saveCoordChange(&fSavedCoordChanges[i]); 488 fDrawState->fColorStages[s].saveCoordChange(&fSavedCoordChanges[i]);
467 fDrawState->fColorStages[s].localCoordChange(coordChangeMatrix); 489 fDrawState->fColorStages[s].localCoordChange(coordChangeMatrix);
468 } 490 }
469 491
470 int numCoverageStages = fDrawState->numCoverageStages(); 492 int numCoverageStages = fDrawState->numCoverageStages();
471 for (int s = 0; s < numCoverageStages; ++s, ++i) { 493 for (int s = 0; s < numCoverageStages; ++s, ++i) {
472 fDrawState->fCoverageStages[s].saveCoordChange(&fSavedCoordChanges[i]); 494 fDrawState->fCoverageStages[s].saveCoordChange(&fSavedCoordChanges[i]);
473 fDrawState->fCoverageStages[s].localCoordChange(coordChangeMatrix); 495 fDrawState->fCoverageStages[s].localCoordChange(coordChangeMatrix);
474 } 496 }
475 } 497 }
OLDNEW
« no previous file with comments | « src/gpu/GrDrawState.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698