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

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

Issue 554833002: Calculate Primary and Secondary output types in the GrOptDrawState (Closed) Base URL: https://skia.googlesource.com/skia.git@optReadDst
Patch Set: Rebase 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
« no previous file with comments | « src/gpu/GrOptDrawState.h ('k') | src/gpu/gl/GrGLProgram.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 2014 Google Inc. 2 * Copyright 2014 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 "GrOptDrawState.h" 8 #include "GrOptDrawState.h"
9 9
10 #include "GrDrawState.h" 10 #include "GrDrawState.h"
11 #include "GrDrawTargetCaps.h"
12 #include "GrGpu.h"
11 13
12 GrOptDrawState::GrOptDrawState(const GrDrawState& drawState, 14 GrOptDrawState::GrOptDrawState(const GrDrawState& drawState,
13 BlendOptFlags blendOptFlags, 15 BlendOptFlags blendOptFlags,
14 GrBlendCoeff optSrcCoeff, 16 GrBlendCoeff optSrcCoeff,
15 GrBlendCoeff optDstCoeff) : INHERITED(drawState) { 17 GrBlendCoeff optDstCoeff,
18 const GrDrawTargetCaps& caps) : INHERITED(drawSta te) {
16 fColor = drawState.getColor(); 19 fColor = drawState.getColor();
17 fCoverage = drawState.getCoverage(); 20 fCoverage = drawState.getCoverage();
18 fViewMatrix = drawState.getViewMatrix(); 21 fViewMatrix = drawState.getViewMatrix();
19 fBlendConstant = drawState.getBlendConstant(); 22 fBlendConstant = drawState.getBlendConstant();
20 fFlagBits = drawState.getFlagBits(); 23 fFlagBits = drawState.getFlagBits();
21 fVAPtr = drawState.getVertexAttribs(); 24 fVAPtr = drawState.getVertexAttribs();
22 fVACount = drawState.getVertexAttribCount(); 25 fVACount = drawState.getVertexAttribCount();
23 fVAStride = drawState.getVertexStride(); 26 fVAStride = drawState.getVertexStride();
24 fStencilSettings = drawState.getStencil(); 27 fStencilSettings = drawState.getStencil();
25 fDrawFace = drawState.getDrawFace(); 28 fDrawFace = drawState.getDrawFace();
(...skipping 12 matching lines...) Expand all
38 if (drawState.hasGeometryProcessor()) { 41 if (drawState.hasGeometryProcessor()) {
39 fGeometryProcessor.reset(SkNEW_ARGS(GrEffectStage, (*drawState.getGeomet ryProcessor()))); 42 fGeometryProcessor.reset(SkNEW_ARGS(GrEffectStage, (*drawState.getGeomet ryProcessor())));
40 } else { 43 } else {
41 fGeometryProcessor.reset(NULL); 44 fGeometryProcessor.reset(NULL);
42 } 45 }
43 46
44 this->copyEffectiveColorStages(drawState); 47 this->copyEffectiveColorStages(drawState);
45 this->copyEffectiveCoverageStages(drawState); 48 this->copyEffectiveCoverageStages(drawState);
46 this->adjustFromBlendOpts(); 49 this->adjustFromBlendOpts();
47 this->getStageStats(); 50 this->getStageStats();
51 this->setOutputStateInfo(caps);
48 }; 52 };
49 53
54 void GrOptDrawState::setOutputStateInfo(const GrDrawTargetCaps& caps) {
55 // Set this default and then possibly change our mind if there is coverage.
56 fPrimaryOutputType = kModulate_PrimaryOutputType;
57 fSecondaryOutputType = kNone_SecondaryOutputType;
58
59 // If we do have coverage determine whether it matters.
60 bool separateCoverageFromColor = this->hasGeometryProcessor();
61 if (!this->isCoverageDrawing() &&
62 (this->numCoverageStages() > 0 ||
63 this->hasGeometryProcessor() ||
64 this->hasCoverageVertexAttribute())) {
65
66 if (caps.dualSourceBlendingSupport()) {
67 if (kZero_GrBlendCoeff == fDstBlend) {
68 // write the coverage value to second color
69 fSecondaryOutputType = kCoverage_SecondaryOutputType;
70 separateCoverageFromColor = true;
71 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff;
72 } else if (kSA_GrBlendCoeff == fDstBlend) {
73 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered.
74 fSecondaryOutputType = kCoverageISA_SecondaryOutputType;
75 separateCoverageFromColor = true;
76 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff;
77 } else if (kSC_GrBlendCoeff == fDstBlend) {
78 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered.
79 fSecondaryOutputType = kCoverageISC_SecondaryOutputType;
80 separateCoverageFromColor = true;
81 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff;
82 }
83 } else if (fReadsDst &&
84 kOne_GrBlendCoeff == fSrcBlend &&
85 kZero_GrBlendCoeff == fDstBlend) {
86 fPrimaryOutputType = kCombineWithDst_PrimaryOutputType;
87 separateCoverageFromColor = true;
88 }
89 }
90
91 // TODO: Once we have flag to know if we only multiply on stages, only push coverage into color
92 // stages if everything is multipy
93 if (!separateCoverageFromColor) {
94 for (int s = 0; s < this->numCoverageStages(); ++s) {
95 fColorStages.push_back(this->getCoverageStage(s));
96 }
97 fCoverageStages.reset();
98 }
99 }
100
50 void GrOptDrawState::adjustFromBlendOpts() { 101 void GrOptDrawState::adjustFromBlendOpts() {
51 102
52 switch (fBlendOptFlags) { 103 switch (fBlendOptFlags) {
53 case kNone_BlendOpt: 104 case kNone_BlendOpt:
54 case kSkipDraw_BlendOptFlag: 105 case kSkipDraw_BlendOptFlag:
55 break; 106 break;
56 case kCoverageAsAlpha_BlendOptFlag: 107 case kCoverageAsAlpha_BlendOptFlag:
57 fFlagBits |= kCoverageDrawing_StateBit; 108 fFlagBits |= kCoverageDrawing_StateBit;
58 break; 109 break;
59 case kEmitCoverage_BlendOptFlag: 110 case kEmitCoverage_BlendOptFlag:
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 const GrEffectStage& stage = *this->getGeometryProcessor(); 263 const GrEffectStage& stage = *this->getGeometryProcessor();
213 get_stage_stats(stage, &fReadsDst, &fReadsFragPosition); 264 get_stage_stats(stage, &fReadsDst, &fReadsFragPosition);
214 SkASSERT(fRequiresVertexShader); 265 SkASSERT(fRequiresVertexShader);
215 } 266 }
216 } 267 }
217 268
218 bool GrOptDrawState::operator== (const GrOptDrawState& that) const { 269 bool GrOptDrawState::operator== (const GrOptDrawState& that) const {
219 return this->isEqual(that); 270 return this->isEqual(that);
220 } 271 }
221 272
OLDNEW
« no previous file with comments | « src/gpu/GrOptDrawState.h ('k') | src/gpu/gl/GrGLProgram.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698