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

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

Issue 791743003: Remove GP from drawstate, revision of invariant output for GP (Closed) Base URL: https://skia.googlesource.com/skia.git@color-to-gp
Patch Set: cleanup Created 6 years 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 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" 11 #include "GrDrawTargetCaps.h"
12 #include "GrGpu.h" 12 #include "GrGpu.h"
13 #include "GrProcOptInfo.h" 13 #include "GrProcOptInfo.h"
14 #include "GrXferProcessor.h" 14 #include "GrXferProcessor.h"
15 15
16 GrOptDrawState::GrOptDrawState(const GrDrawState& drawState, 16 GrOptDrawState::GrOptDrawState(const GrDrawState& drawState,
17 GrColor color, 17 const GrGeometryProcessor* gp,
18 uint8_t coverage, 18 const GrPathProcessor* pp,
19 const GrDrawTargetCaps& caps, 19 const GrDrawTargetCaps& caps,
20 const ScissorState& scissorState, 20 const ScissorState& scissorState,
21 const GrDeviceCoordTexture* dstCopy, 21 const GrDeviceCoordTexture* dstCopy,
22 GrGpu::DrawType drawType) 22 GrGpu::DrawType drawType)
23 : fFinalized(false) { 23 : fFinalized(false) {
24 GrColor coverageColor = GrColorPackRGBA(coverage, coverage, coverage, covera ge);
25 fDrawType = drawType; 24 fDrawType = drawType;
26 25
27 const GrProcOptInfo& colorPOI = drawState.colorProcInfo(color); 26 // Copy GeometryProcesssor from DS or ODS
28 const GrProcOptInfo& coveragePOI = drawState.coverageProcInfo(coverageColor) ; 27 if (gp) {
28 SkASSERT(!pp);
29 SkASSERT(!(GrGpu::IsPathRenderingDrawType(drawType) ||
30 GrGpu::kStencilPath_DrawType == drawType));
31 fGeometryProcessor.reset(gp);
32 fPrimitiveProcessor.reset(gp);
33 } else {
34 SkASSERT(!gp && pp && (GrGpu::IsPathRenderingDrawType(drawType) ||
35 GrGpu::kStencilPath_DrawType == drawType));
36 fPrimitiveProcessor.reset(pp);
37 }
38
39
40 const GrProcOptInfo& colorPOI = drawState.colorProcInfo(fPrimitiveProcessor) ;
41 const GrProcOptInfo& coveragePOI = drawState.coverageProcInfo(fPrimitiveProc essor);
29 42
30 fColor = colorPOI.inputColorToEffectiveStage(); 43 fColor = colorPOI.inputColorToEffectiveStage();
31 fCoverage = coverage; 44 // TODO fix this when coverage stages work correctly
45 // fCoverage = coveragePOI.inputColorToEffectiveStage();
46 fCoverage = fPrimitiveProcessor->coverage();
32 47
33 // Create XferProcessor from DS's XPFactory 48 // Create XferProcessor from DS's XPFactory
34 SkAutoTUnref<GrXferProcessor> xferProcessor( 49 SkAutoTUnref<GrXferProcessor> xferProcessor(
35 drawState.getXPFactory()->createXferProcessor(colorPOI, coveragePOI)); 50 drawState.getXPFactory()->createXferProcessor(colorPOI, coveragePOI));
36 51
37 GrXferProcessor::OptFlags optFlags; 52 GrXferProcessor::OptFlags optFlags;
38 if (xferProcessor) { 53 if (xferProcessor) {
39 fXferProcessor.reset(xferProcessor.get()); 54 fXferProcessor.reset(xferProcessor.get());
40 55
41 optFlags = xferProcessor->getOptimizations(colorPOI, 56 optFlags = xferProcessor->getOptimizations(colorPOI,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 if (drawState.isHWAntialias()) { 93 if (drawState.isHWAntialias()) {
79 fFlags |= kHWAA_Flag; 94 fFlags |= kHWAA_Flag;
80 } 95 }
81 if (drawState.isColorWriteDisabled()) { 96 if (drawState.isColorWriteDisabled()) {
82 fFlags |= kDisableColorWrite_Flag; 97 fFlags |= kDisableColorWrite_Flag;
83 } 98 }
84 if (drawState.isDither()) { 99 if (drawState.isDither()) {
85 fFlags |= kDither_Flag; 100 fFlags |= kDither_Flag;
86 } 101 }
87 102
88 fDescInfo.fHasVertexColor = drawState.hasGeometryProcessor() && 103 fDescInfo.fHasVertexColor = gp && gp->hasVertexColor();
89 drawState.getGeometryProcessor()->hasVertexColor ();
90 104
91 fDescInfo.fHasVertexCoverage = drawState.hasGeometryProcessor() && 105 fDescInfo.fHasVertexCoverage = gp && gp->hasVertexCoverage();
92 drawState.getGeometryProcessor()->hasVertexCo verage();
93 106
94 bool hasLocalCoords = drawState.hasGeometryProcessor() && 107 bool hasLocalCoords = gp && gp->hasLocalCoords();
95 drawState.getGeometryProcessor()->hasLocalCoords();
96 108
97 int firstColorStageIdx = colorPOI.firstEffectiveStageIndex(); 109 int firstColorStageIdx = colorPOI.firstEffectiveStageIndex();
98 fDescInfo.fInputColorIsUsed = colorPOI.inputColorIsUsed(); 110 fDescInfo.fInputColorIsUsed = colorPOI.inputColorIsUsed();
99 if (colorPOI.removeVertexAttrib()) { 111 if (colorPOI.removeVertexAttrib()) {
100 fDescInfo.fHasVertexColor = false; 112 fDescInfo.fHasVertexColor = false;
101 } 113 }
102 114
103 // TODO: Once we can handle single or four channel input into coverage stage s then we can use 115 // TODO: Once we can handle single or four channel input into coverage stage s then we can use
104 // drawState's coverageProcInfo (like color above) to set this initial infor mation. 116 // drawState's coverageProcInfo (like color above) to set this initial infor mation.
105 int firstCoverageStageIdx = 0; 117 int firstCoverageStageIdx = 0;
106 fDescInfo.fInputCoverageIsUsed = true; 118 fDescInfo.fInputCoverageIsUsed = true;
107 119
108
109 GrXferProcessor::BlendInfo blendInfo; 120 GrXferProcessor::BlendInfo blendInfo;
110 fXferProcessor->getBlendInfo(&blendInfo); 121 fXferProcessor->getBlendInfo(&blendInfo);
111 fSrcBlend = blendInfo.fSrcBlend; 122 fSrcBlend = blendInfo.fSrcBlend;
112 fDstBlend = blendInfo.fDstBlend; 123 fDstBlend = blendInfo.fDstBlend;
113 fBlendConstant = blendInfo.fBlendConstant; 124 fBlendConstant = blendInfo.fBlendConstant;
114 125
115 this->adjustProgramFromOptimizations(drawState, optFlags, colorPOI, coverage POI, 126 this->adjustProgramFromOptimizations(drawState, optFlags, colorPOI, coverage POI,
116 &firstColorStageIdx, &firstCoverageStag eIdx); 127 &firstColorStageIdx, &firstCoverageStag eIdx);
117 128
118 fDescInfo.fRequiresLocalCoordAttrib = hasLocalCoords; 129 fDescInfo.fRequiresLocalCoordAttrib = hasLocalCoords;
119 130
120 // Copy GeometryProcesssor from DS or ODS
121 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType) ||
122 GrGpu::kStencilPath_DrawType ||
123 drawState.hasGeometryProcessor());
124 fGeometryProcessor.reset(drawState.getGeometryProcessor());
125
126 // Copy Stages from DS to ODS 131 // Copy Stages from DS to ODS
127 for (int i = firstColorStageIdx; i < drawState.numColorStages(); ++i) { 132 for (int i = firstColorStageIdx; i < drawState.numColorStages(); ++i) {
128 SkNEW_APPEND_TO_TARRAY(&fFragmentStages, 133 SkNEW_APPEND_TO_TARRAY(&fFragmentStages,
129 GrPendingFragmentStage, 134 GrPendingFragmentStage,
130 (drawState.fColorStages[i], hasLocalCoords)); 135 (drawState.fColorStages[i], hasLocalCoords));
131 } 136 }
132 137
133 fNumColorStages = fFragmentStages.count(); 138 fNumColorStages = fFragmentStages.count();
134 for (int i = firstCoverageStageIdx; i < drawState.numCoverageStages(); ++i) { 139 for (int i = firstCoverageStageIdx; i < drawState.numCoverageStages(); ++i) {
135 SkNEW_APPEND_TO_TARRAY(&fFragmentStages, 140 SkNEW_APPEND_TO_TARRAY(&fFragmentStages,
136 GrPendingFragmentStage, 141 GrPendingFragmentStage,
137 (drawState.fCoverageStages[i], hasLocalCoords)); 142 (drawState.fCoverageStages[i], hasLocalCoords));
138 } 143 }
139 144
140 // let the GP init the batch tracker 145 // let the GP init the batch tracker
141 if (drawState.hasGeometryProcessor()) { 146 if (gp) {
142 GrGeometryProcessor::InitBT init; 147 GrGeometryProcessor::InitBT init;
143 init.fOutputColor = fDescInfo.fInputColorIsUsed; 148 init.fOutputColor = fDescInfo.fInputColorIsUsed;
144 init.fOutputCoverage = fDescInfo.fInputCoverageIsUsed; 149 init.fOutputCoverage = fDescInfo.fInputCoverageIsUsed;
145 init.fColor = this->getColor(); 150 init.fColor = this->getColor();
146 init.fCoverage = this->getCoverage(); 151 init.fCoverage = this->getCoverage();
147 fGeometryProcessor->initBatchTracker(&fBatchTracker, init); 152 fGeometryProcessor->initBatchTracker(&fBatchTracker, init);
148 } 153 }
149 154
150 this->setOutputStateInfo(drawState, coverageColor, optFlags, caps); 155 this->setOutputStateInfo(drawState, optFlags, caps);
151 } 156 }
152 157
153 void GrOptDrawState::setOutputStateInfo(const GrDrawState& ds, 158 void GrOptDrawState::setOutputStateInfo(const GrDrawState& ds,
154 GrColor coverage,
155 GrXferProcessor::OptFlags optFlags, 159 GrXferProcessor::OptFlags optFlags,
156 const GrDrawTargetCaps& caps) { 160 const GrDrawTargetCaps& caps) {
157 // Set this default and then possibly change our mind if there is coverage. 161 // Set this default and then possibly change our mind if there is coverage.
158 fDescInfo.fPrimaryOutputType = GrProgramDesc::kModulate_PrimaryOutputType; 162 fDescInfo.fPrimaryOutputType = GrProgramDesc::kModulate_PrimaryOutputType;
159 fDescInfo.fSecondaryOutputType = GrProgramDesc::kNone_SecondaryOutputType; 163 fDescInfo.fSecondaryOutputType = GrProgramDesc::kNone_SecondaryOutputType;
160 164
161 // Determine whether we should use dual source blending or shader code to ke ep coverage 165 // Determine whether we should use dual source blending or shader code to ke ep coverage
162 // separate from color. 166 // separate from color.
163 bool keepCoverageSeparate = !(optFlags & GrXferProcessor::kSetCoverageDrawin g_OptFlag); 167 bool keepCoverageSeparate = !(optFlags & GrXferProcessor::kSetCoverageDrawin g_OptFlag);
164 if (keepCoverageSeparate && !ds.hasSolidCoverage(coverage)) { 168 if (keepCoverageSeparate && !ds.hasSolidCoverage(fPrimitiveProcessor.get())) {
165 if (caps.dualSourceBlendingSupport()) { 169 if (caps.dualSourceBlendingSupport()) {
166 if (kZero_GrBlendCoeff == fDstBlend) { 170 if (kZero_GrBlendCoeff == fDstBlend) {
167 // write the coverage value to second color 171 // write the coverage value to second color
168 fDescInfo.fSecondaryOutputType = GrProgramDesc::kCoverage_Second aryOutputType; 172 fDescInfo.fSecondaryOutputType = GrProgramDesc::kCoverage_Second aryOutputType;
169 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; 173 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff;
170 } else if (kSA_GrBlendCoeff == fDstBlend) { 174 } else if (kSA_GrBlendCoeff == fDstBlend) {
171 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered. 175 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered.
172 fDescInfo.fSecondaryOutputType = GrProgramDesc::kCoverageISA_Sec ondaryOutputType; 176 fDescInfo.fSecondaryOutputType = GrProgramDesc::kCoverageISA_Sec ondaryOutputType;
173 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; 177 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff;
174 } else if (kSC_GrBlendCoeff == fDstBlend) { 178 } else if (kSC_GrBlendCoeff == fDstBlend) {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 SkASSERT(this->numFragmentStages() == that.numFragmentStages()); 270 SkASSERT(this->numFragmentStages() == that.numFragmentStages());
267 for (int i = 0; i < this->numFragmentStages(); i++) { 271 for (int i = 0; i < this->numFragmentStages(); i++) {
268 272
269 if (this->getFragmentStage(i) != that.getFragmentStage(i)) { 273 if (this->getFragmentStage(i) != that.getFragmentStage(i)) {
270 return false; 274 return false;
271 } 275 }
272 } 276 }
273 return true; 277 return true;
274 } 278 }
275 279
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698