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

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

Issue 509153002: Initial change to create GeometryProcessor (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fixing mac compiler warning Created 6 years, 3 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
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 #include "GrDrawTargetCaps.h" 10 #include "GrDrawTargetCaps.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 } 47 }
48 return kAOrB_CombinedState; 48 return kAOrB_CombinedState;
49 } 49 }
50 50
51 //////////////////////////////////////////////////////////////////////////////s 51 //////////////////////////////////////////////////////////////////////////////s
52 52
53 GrDrawState::GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatr ix) { 53 GrDrawState::GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatr ix) {
54 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) 54 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;)
55 *this = state; 55 *this = state;
56 if (!preConcatMatrix.isIdentity()) { 56 if (!preConcatMatrix.isIdentity()) {
57 if (this->getGeometryProcessor()) {
58 fGeometryProcessor->localCoordChange(preConcatMatrix);
59 }
57 for (int i = 0; i < this->numColorStages(); ++i) { 60 for (int i = 0; i < this->numColorStages(); ++i) {
58 fColorStages[i].localCoordChange(preConcatMatrix); 61 fColorStages[i].localCoordChange(preConcatMatrix);
59 } 62 }
60 for (int i = 0; i < this->numCoverageStages(); ++i) { 63 for (int i = 0; i < this->numCoverageStages(); ++i) {
61 fCoverageStages[i].localCoordChange(preConcatMatrix); 64 fCoverageStages[i].localCoordChange(preConcatMatrix);
62 } 65 }
63 this->invalidateBlendOptFlags(); 66 this->invalidateBlendOptFlags();
64 } 67 }
65 } 68 }
66 69
67 GrDrawState& GrDrawState::operator=(const GrDrawState& that) { 70 GrDrawState& GrDrawState::operator=(const GrDrawState& that) {
68 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); 71 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages());
69 this->setRenderTarget(that.fRenderTarget.get()); 72 this->setRenderTarget(that.fRenderTarget.get());
70 fColor = that.fColor; 73 fColor = that.fColor;
71 fViewMatrix = that.fViewMatrix; 74 fViewMatrix = that.fViewMatrix;
72 fSrcBlend = that.fSrcBlend; 75 fSrcBlend = that.fSrcBlend;
73 fDstBlend = that.fDstBlend; 76 fDstBlend = that.fDstBlend;
74 fBlendConstant = that.fBlendConstant; 77 fBlendConstant = that.fBlendConstant;
75 fFlagBits = that.fFlagBits; 78 fFlagBits = that.fFlagBits;
76 fVACount = that.fVACount; 79 fVACount = that.fVACount;
77 fVAPtr = that.fVAPtr; 80 fVAPtr = that.fVAPtr;
78 fVAStride = that.fVAStride; 81 fVAStride = that.fVAStride;
79 fStencilSettings = that.fStencilSettings; 82 fStencilSettings = that.fStencilSettings;
80 fCoverage = that.fCoverage; 83 fCoverage = that.fCoverage;
81 fDrawFace = that.fDrawFace; 84 fDrawFace = that.fDrawFace;
85 fGeometryProcessor.reset(SkSafeRef(that.fGeometryProcessor.get()));
82 fColorStages = that.fColorStages; 86 fColorStages = that.fColorStages;
83 fCoverageStages = that.fCoverageStages; 87 fCoverageStages = that.fCoverageStages;
84 fOptSrcBlend = that.fOptSrcBlend; 88 fOptSrcBlend = that.fOptSrcBlend;
85 fOptDstBlend = that.fOptDstBlend; 89 fOptDstBlend = that.fOptDstBlend;
86 fBlendOptFlags = that.fBlendOptFlags; 90 fBlendOptFlags = that.fBlendOptFlags;
87 91
88 fHints = that.fHints; 92 fHints = that.fHints;
89 93
90 memcpy(fFixedFunctionVertexAttribIndices, 94 memcpy(fFixedFunctionVertexAttribIndices,
91 that.fFixedFunctionVertexAttribIndices, 95 that.fFixedFunctionVertexAttribIndices,
92 sizeof(fFixedFunctionVertexAttribIndices)); 96 sizeof(fFixedFunctionVertexAttribIndices));
93 return *this; 97 return *this;
94 } 98 }
95 99
96 void GrDrawState::onReset(const SkMatrix* initialViewMatrix) { 100 void GrDrawState::onReset(const SkMatrix* initialViewMatrix) {
97 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); 101 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages());
102 fGeometryProcessor.reset(NULL);
98 fColorStages.reset(); 103 fColorStages.reset();
99 fCoverageStages.reset(); 104 fCoverageStages.reset();
100 105
101 fRenderTarget.reset(NULL); 106 fRenderTarget.reset(NULL);
102 107
103 this->setDefaultVertexAttribs(); 108 this->setDefaultVertexAttribs();
104 109
105 fColor = 0xffffffff; 110 fColor = 0xffffffff;
106 if (NULL == initialViewMatrix) { 111 if (NULL == initialViewMatrix) {
107 fViewMatrix.reset(); 112 fViewMatrix.reset();
(...skipping 13 matching lines...) Expand all
121 this->invalidateBlendOptFlags(); 126 this->invalidateBlendOptFlags();
122 } 127 }
123 128
124 bool GrDrawState::setIdentityViewMatrix() { 129 bool GrDrawState::setIdentityViewMatrix() {
125 if (this->numTotalStages()) { 130 if (this->numTotalStages()) {
126 SkMatrix invVM; 131 SkMatrix invVM;
127 if (!fViewMatrix.invert(&invVM)) { 132 if (!fViewMatrix.invert(&invVM)) {
128 // sad trombone sound 133 // sad trombone sound
129 return false; 134 return false;
130 } 135 }
136 if (this->getGeometryProcessor()) {
137 fGeometryProcessor->localCoordChange(invVM);
138 }
131 for (int s = 0; s < this->numColorStages(); ++s) { 139 for (int s = 0; s < this->numColorStages(); ++s) {
132 fColorStages[s].localCoordChange(invVM); 140 fColorStages[s].localCoordChange(invVM);
133 } 141 }
134 for (int s = 0; s < this->numCoverageStages(); ++s) { 142 for (int s = 0; s < this->numCoverageStages(); ++s) {
135 fCoverageStages[s].localCoordChange(invVM); 143 fCoverageStages[s].localCoordChange(invVM);
136 } 144 }
137 } 145 }
138 fViewMatrix.reset(); 146 fViewMatrix.reset();
139 return true; 147 return true;
140 } 148 }
141 149
142 void GrDrawState::setFromPaint(const GrPaint& paint, const SkMatrix& vm, GrRende rTarget* rt) { 150 void GrDrawState::setFromPaint(const GrPaint& paint, const SkMatrix& vm, GrRende rTarget* rt) {
143 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); 151 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages());
144 152
153 fGeometryProcessor.reset(NULL);
145 fColorStages.reset(); 154 fColorStages.reset();
146 fCoverageStages.reset(); 155 fCoverageStages.reset();
147 156
148 for (int i = 0; i < paint.numColorStages(); ++i) { 157 for (int i = 0; i < paint.numColorStages(); ++i) {
149 fColorStages.push_back(paint.getColorStage(i)); 158 fColorStages.push_back(paint.getColorStage(i));
150 } 159 }
151 160
152 for (int i = 0; i < paint.numCoverageStages(); ++i) { 161 for (int i = 0; i < paint.numCoverageStages(); ++i) {
153 fCoverageStages.push_back(paint.getCoverageStage(i)); 162 fCoverageStages.push_back(paint.getCoverageStage(i));
154 } 163 }
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 fVAPtr = drawState->fVAPtr; 288 fVAPtr = drawState->fVAPtr;
280 fVACount = drawState->fVACount; 289 fVACount = drawState->fVACount;
281 fVAStride = drawState->fVAStride; 290 fVAStride = drawState->fVAStride;
282 fDrawState->setDefaultVertexAttribs(); 291 fDrawState->setDefaultVertexAttribs();
283 } 292 }
284 293
285 //////////////////////////////////////////////////////////////////////////////s 294 //////////////////////////////////////////////////////////////////////////////s
286 295
287 void GrDrawState::AutoRestoreEffects::set(GrDrawState* ds) { 296 void GrDrawState::AutoRestoreEffects::set(GrDrawState* ds) {
288 if (NULL != fDrawState) { 297 if (NULL != fDrawState) {
298 fDrawState->fGeometryProcessor.reset(SkSafeRef(fGeometryProcessor.get()) );
299
289 int m = fDrawState->numColorStages() - fColorEffectCnt; 300 int m = fDrawState->numColorStages() - fColorEffectCnt;
290 SkASSERT(m >= 0); 301 SkASSERT(m >= 0);
291 fDrawState->fColorStages.pop_back_n(m); 302 fDrawState->fColorStages.pop_back_n(m);
292 303
293 int n = fDrawState->numCoverageStages() - fCoverageEffectCnt; 304 int n = fDrawState->numCoverageStages() - fCoverageEffectCnt;
294 SkASSERT(n >= 0); 305 SkASSERT(n >= 0);
295 fDrawState->fCoverageStages.pop_back_n(n); 306 fDrawState->fCoverageStages.pop_back_n(n);
296 if (m + n > 0) { 307 if (m + n > 0) {
297 fDrawState->invalidateBlendOptFlags(); 308 fDrawState->invalidateBlendOptFlags();
298 } 309 }
299 SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;) 310 SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;)
300 } 311 }
301 fDrawState = ds; 312 fDrawState = ds;
302 if (NULL != ds) { 313 if (NULL != ds) {
314 fGeometryProcessor.reset(SkSafeRef(ds->fGeometryProcessor.get()));
303 fColorEffectCnt = ds->numColorStages(); 315 fColorEffectCnt = ds->numColorStages();
304 fCoverageEffectCnt = ds->numCoverageStages(); 316 fCoverageEffectCnt = ds->numCoverageStages();
305 SkDEBUGCODE(++ds->fBlockEffectRemovalCnt;) 317 SkDEBUGCODE(++ds->fBlockEffectRemovalCnt;)
306 } 318 }
307 } 319 }
308 320
309 //////////////////////////////////////////////////////////////////////////////// 321 ////////////////////////////////////////////////////////////////////////////////
310 322
311 GrRODrawState::BlendOptFlags GrDrawState::getBlendOpts(bool forceCoverage, 323 GrRODrawState::BlendOptFlags GrDrawState::getBlendOpts(bool forceCoverage,
312 GrBlendCoeff* srcCoeff, 324 GrBlendCoeff* srcCoeff,
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 434
423 void GrDrawState::AutoViewMatrixRestore::restore() { 435 void GrDrawState::AutoViewMatrixRestore::restore() {
424 if (NULL != fDrawState) { 436 if (NULL != fDrawState) {
425 SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;) 437 SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;)
426 fDrawState->fViewMatrix = fViewMatrix; 438 fDrawState->fViewMatrix = fViewMatrix;
427 SkASSERT(fDrawState->numColorStages() >= fNumColorStages); 439 SkASSERT(fDrawState->numColorStages() >= fNumColorStages);
428 int numCoverageStages = fSavedCoordChanges.count() - fNumColorStages; 440 int numCoverageStages = fSavedCoordChanges.count() - fNumColorStages;
429 SkASSERT(fDrawState->numCoverageStages() >= numCoverageStages); 441 SkASSERT(fDrawState->numCoverageStages() >= numCoverageStages);
430 442
431 int i = 0; 443 int i = 0;
444 if (fHasGeometryProcessor) {
445 SkASSERT(fDrawState->getGeometryProcessor());
446 fDrawState->fGeometryProcessor->restoreCoordChange(fSavedCoordChange s[i++]);
447 }
432 for (int s = 0; s < fNumColorStages; ++s, ++i) { 448 for (int s = 0; s < fNumColorStages; ++s, ++i) {
433 fDrawState->fColorStages[s].restoreCoordChange(fSavedCoordChanges[i] ); 449 fDrawState->fColorStages[s].restoreCoordChange(fSavedCoordChanges[i] );
434 } 450 }
435 for (int s = 0; s < numCoverageStages; ++s, ++i) { 451 for (int s = 0; s < numCoverageStages; ++s, ++i) {
436 fDrawState->fCoverageStages[s].restoreCoordChange(fSavedCoordChanges [i]); 452 fDrawState->fCoverageStages[s].restoreCoordChange(fSavedCoordChanges [i]);
437 } 453 }
438 fDrawState = NULL; 454 fDrawState = NULL;
439 } 455 }
440 } 456 }
441 457
(...skipping 22 matching lines...) Expand all
464 } 480 }
465 481
466 if (drawState->getViewMatrix().isIdentity()) { 482 if (drawState->getViewMatrix().isIdentity()) {
467 return true; 483 return true;
468 } 484 }
469 485
470 fViewMatrix = drawState->getViewMatrix(); 486 fViewMatrix = drawState->getViewMatrix();
471 if (0 == drawState->numTotalStages()) { 487 if (0 == drawState->numTotalStages()) {
472 drawState->fViewMatrix.reset(); 488 drawState->fViewMatrix.reset();
473 fDrawState = drawState; 489 fDrawState = drawState;
490 fHasGeometryProcessor = false;
474 fNumColorStages = 0; 491 fNumColorStages = 0;
475 fSavedCoordChanges.reset(0); 492 fSavedCoordChanges.reset(0);
476 SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;) 493 SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;)
477 return true; 494 return true;
478 } else { 495 } else {
479 SkMatrix inv; 496 SkMatrix inv;
480 if (!fViewMatrix.invert(&inv)) { 497 if (!fViewMatrix.invert(&inv)) {
481 return false; 498 return false;
482 } 499 }
483 drawState->fViewMatrix.reset(); 500 drawState->fViewMatrix.reset();
484 fDrawState = drawState; 501 fDrawState = drawState;
485 this->doEffectCoordChanges(inv); 502 this->doEffectCoordChanges(inv);
486 SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;) 503 SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;)
487 return true; 504 return true;
488 } 505 }
489 } 506 }
490 507
491 void GrDrawState::AutoViewMatrixRestore::doEffectCoordChanges(const SkMatrix& co ordChangeMatrix) { 508 void GrDrawState::AutoViewMatrixRestore::doEffectCoordChanges(const SkMatrix& co ordChangeMatrix) {
492 fSavedCoordChanges.reset(fDrawState->numTotalStages()); 509 fSavedCoordChanges.reset(fDrawState->numTotalStages());
493 int i = 0; 510 int i = 0;
494 511
512 fHasGeometryProcessor = false;
513 if (fDrawState->getGeometryProcessor()) {
514 fDrawState->fGeometryProcessor->saveCoordChange(&fSavedCoordChanges[i++] );
515 fDrawState->fGeometryProcessor->localCoordChange(coordChangeMatrix);
516 fHasGeometryProcessor = true;
517 }
518
495 fNumColorStages = fDrawState->numColorStages(); 519 fNumColorStages = fDrawState->numColorStages();
496 for (int s = 0; s < fNumColorStages; ++s, ++i) { 520 for (int s = 0; s < fNumColorStages; ++s, ++i) {
497 fDrawState->getColorStage(s).saveCoordChange(&fSavedCoordChanges[i]); 521 fDrawState->getColorStage(s).saveCoordChange(&fSavedCoordChanges[i]);
498 fDrawState->fColorStages[s].localCoordChange(coordChangeMatrix); 522 fDrawState->fColorStages[s].localCoordChange(coordChangeMatrix);
499 } 523 }
500 524
501 int numCoverageStages = fDrawState->numCoverageStages(); 525 int numCoverageStages = fDrawState->numCoverageStages();
502 for (int s = 0; s < numCoverageStages; ++s, ++i) { 526 for (int s = 0; s < numCoverageStages; ++s, ++i) {
503 fDrawState->getCoverageStage(s).saveCoordChange(&fSavedCoordChanges[i]); 527 fDrawState->getCoverageStage(s).saveCoordChange(&fSavedCoordChanges[i]);
504 fDrawState->fCoverageStages[s].localCoordChange(coordChangeMatrix); 528 fDrawState->fCoverageStages[s].localCoordChange(coordChangeMatrix);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 uint32_t coverageComponentFlags; 560 uint32_t coverageComponentFlags;
537 if (this->hasCoverageVertexAttribute()) { 561 if (this->hasCoverageVertexAttribute()) {
538 coverageComponentFlags = 0; 562 coverageComponentFlags = 0;
539 coverage = 0; // suppresses any warnings. 563 coverage = 0; // suppresses any warnings.
540 } else { 564 } else {
541 coverageComponentFlags = kRGBA_GrColorComponentFlags; 565 coverageComponentFlags = kRGBA_GrColorComponentFlags;
542 coverage = this->getCoverageColor(); 566 coverage = this->getCoverageColor();
543 } 567 }
544 568
545 // Run through the coverage stages 569 // Run through the coverage stages
570 if (this->getGeometryProcessor()) {
571 const GrEffect* effect = fGeometryProcessor->getEffect();
572 effect->getConstantColorComponents(&coverage, &coverageComponentFlag s);
573 }
546 for (int s = 0; s < this->numCoverageStages(); ++s) { 574 for (int s = 0; s < this->numCoverageStages(); ++s) {
547 const GrEffect* effect = this->getCoverageStage(s).getEffect(); 575 const GrEffect* effect = this->getCoverageStage(s).getEffect();
548 effect->getConstantColorComponents(&coverage, &coverageComponentFlag s); 576 effect->getConstantColorComponents(&coverage, &coverageComponentFlag s);
549 } 577 }
550 578
551 // Since the shader will multiply coverage and color, the only way the f inal A==1 is if 579 // Since the shader will multiply coverage and color, the only way the f inal A==1 is if
552 // coverage and color both have A==1. 580 // coverage and color both have A==1.
553 return (kA_GrColorComponentFlag & validComponentFlags & coverageComponen tFlags) && 581 return (kA_GrColorComponentFlag & validComponentFlags & coverageComponen tFlags) &&
554 0xFF == GrColorUnpackA(color) && 0xFF == GrColorUnpackA(coverage ); 582 0xFF == GrColorUnpackA(color) && 0xFF == GrColorUnpackA(coverage );
555 583
556 } 584 }
557 585
558 return (kA_GrColorComponentFlag & validComponentFlags) && 0xFF == GrColorUnp ackA(color); 586 return (kA_GrColorComponentFlag & validComponentFlags) && 0xFF == GrColorUnp ackA(color);
559 } 587 }
560 588
561 //////////////////////////////////////////////////////////////////////////////// 589 ////////////////////////////////////////////////////////////////////////////////
562 590
563 bool GrDrawState::canIgnoreColorAttribute() const { 591 bool GrDrawState::canIgnoreColorAttribute() const {
564 if (fBlendOptFlags & kInvalid_BlendOptFlag) { 592 if (fBlendOptFlags & kInvalid_BlendOptFlag) {
565 this->getBlendOpts(); 593 this->getBlendOpts();
566 } 594 }
567 return SkToBool(fBlendOptFlags & (GrRODrawState::kEmitTransBlack_BlendOptFla g | 595 return SkToBool(fBlendOptFlags & (GrRODrawState::kEmitTransBlack_BlendOptFla g |
568 GrRODrawState::kEmitCoverage_BlendOptFlag) ); 596 GrRODrawState::kEmitCoverage_BlendOptFlag) );
569 } 597 }
570 598
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698