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

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

Powered by Google App Engine
This is Rietveld 408576698