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

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

Issue 746423007: Draft change to start pulling uniform color into GP (Closed) Base URL: https://skia.googlesource.com/skia.git@no_factories
Patch Set: missed some places to update uniform cache 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"
(...skipping 14 matching lines...) Expand all
25 25
26 // Copy GeometryProcesssor from DS or ODS 26 // Copy GeometryProcesssor from DS or ODS
27 if (gp) { 27 if (gp) {
28 SkASSERT(!pathProc); 28 SkASSERT(!pathProc);
29 SkASSERT(!(GrGpu::IsPathRenderingDrawType(drawType) || 29 SkASSERT(!(GrGpu::IsPathRenderingDrawType(drawType) ||
30 GrGpu::kStencilPath_DrawType == drawType)); 30 GrGpu::kStencilPath_DrawType == drawType));
31 fGeometryProcessor.reset(gp); 31 fGeometryProcessor.reset(gp);
32 fPrimitiveProcessor.reset(gp); 32 fPrimitiveProcessor.reset(gp);
33 } else { 33 } else {
34 SkASSERT(!gp && pathProc && (GrGpu::IsPathRenderingDrawType(drawType) || 34 SkASSERT(!gp && pathProc && (GrGpu::IsPathRenderingDrawType(drawType) ||
35 GrGpu::kStencilPath_DrawType == drawType)); 35 GrGpu::kStencilPath_DrawType == drawType));
36 fPrimitiveProcessor.reset(pathProc); 36 fPrimitiveProcessor.reset(pathProc);
37 } 37 }
38 38
39 39
40 const GrProcOptInfo& colorPOI = drawState.colorProcInfo(fPrimitiveProcessor) ; 40 const GrProcOptInfo& colorPOI = drawState.colorProcInfo(fPrimitiveProcessor) ;
41 const GrProcOptInfo& coveragePOI = drawState.coverageProcInfo(fPrimitiveProc essor); 41 const GrProcOptInfo& coveragePOI = drawState.coverageProcInfo(fPrimitiveProc essor);
42
43 fColor = colorPOI.inputColorToEffectiveStage();
44 // TODO fix this when coverage stages work correctly
45 // fCoverage = coveragePOI.inputColorToEffectiveStage();
46 fCoverage = fPrimitiveProcessor->coverage();
47 42
48 // Create XferProcessor from DS's XPFactory 43 // Create XferProcessor from DS's XPFactory
49 SkAutoTUnref<GrXferProcessor> xferProcessor( 44 SkAutoTUnref<GrXferProcessor> xferProcessor(
50 drawState.getXPFactory()->createXferProcessor(colorPOI, coveragePOI)); 45 drawState.getXPFactory()->createXferProcessor(colorPOI, coveragePOI));
51 46
47 GrColor color = GrColor_ILLEGAL;
48 if (colorPOI.firstEffectiveStageIndex() != 0) {
49 color = colorPOI.inputColorToEffectiveStage();
50 }
51
52 uint8_t coverage;
52 GrXferProcessor::OptFlags optFlags; 53 GrXferProcessor::OptFlags optFlags;
53 if (xferProcessor) { 54 if (xferProcessor) {
54 fXferProcessor.reset(xferProcessor.get()); 55 fXferProcessor.reset(xferProcessor.get());
55 56
56 optFlags = xferProcessor->getOptimizations(colorPOI, 57 optFlags = xferProcessor->getOptimizations(colorPOI,
57 coveragePOI, 58 coveragePOI,
58 drawState.isCoverageDrawing() , 59 drawState.isCoverageDrawing() ,
59 drawState.isColorWriteDisable d(), 60 drawState.isColorWriteDisable d(),
60 drawState.getStencil().doesWr ite(), 61 drawState.getStencil().doesWr ite(),
61 &fColor, 62 &color,
62 &fCoverage, 63 &coverage,
63 caps); 64 caps);
64 } 65 }
65 66
67 // We might get an updated color from the XP, so we need to make sure the NV PR color is correct
68 // TODO once pathProc is installed here as well, we don't need color on opts tate
69 if (GrColor_ILLEGAL == color) {
70 fColor = colorPOI.inputColorToEffectiveStage();
71 } else {
72 fColor = color;
73 }
74
75
66 // When path rendering the stencil settings are not always set on the draw s tate 76 // When path rendering the stencil settings are not always set on the draw s tate
67 // so we must check the draw type. In cases where we will skip drawing we si mply return a 77 // so we must check the draw type. In cases where we will skip drawing we si mply return a
68 // null GrOptDrawState. 78 // null GrOptDrawState.
69 if (!xferProcessor || ((GrXferProcessor::kSkipDraw_OptFlag & optFlags) && 79 if (!xferProcessor || ((GrXferProcessor::kSkipDraw_OptFlag & optFlags) &&
70 GrGpu::kStencilPath_DrawType != drawType)) { 80 GrGpu::kStencilPath_DrawType != drawType)) {
71 // Set the fields that don't default init and return. The lack of a rend er target will 81 // Set the fields that don't default init and return. The lack of a rend er target will
72 // indicate that this can be skipped. 82 // indicate that this can be skipped.
73 fFlags = 0; 83 fFlags = 0;
74 fDrawFace = GrDrawState::kInvalid_DrawFace; 84 fDrawFace = GrDrawState::kInvalid_DrawFace;
75 fViewMatrix.reset(); 85 fViewMatrix.reset();
(...skipping 15 matching lines...) Expand all
91 if (drawState.isHWAntialias()) { 101 if (drawState.isHWAntialias()) {
92 fFlags |= kHWAA_Flag; 102 fFlags |= kHWAA_Flag;
93 } 103 }
94 if (drawState.isColorWriteDisabled()) { 104 if (drawState.isColorWriteDisabled()) {
95 fFlags |= kDisableColorWrite_Flag; 105 fFlags |= kDisableColorWrite_Flag;
96 } 106 }
97 if (drawState.isDither()) { 107 if (drawState.isDither()) {
98 fFlags |= kDither_Flag; 108 fFlags |= kDither_Flag;
99 } 109 }
100 110
101 fDescInfo.fHasVertexColor = gp && gp->hasVertexColor(); 111 // TODO move local coords completely into GP
102
103 fDescInfo.fHasVertexCoverage = gp && gp->hasVertexCoverage();
104
105 bool hasLocalCoords = gp && gp->hasLocalCoords(); 112 bool hasLocalCoords = gp && gp->hasLocalCoords();
106 113
107 int firstColorStageIdx = colorPOI.firstEffectiveStageIndex(); 114 int firstColorStageIdx = colorPOI.firstEffectiveStageIndex();
108 fDescInfo.fInputColorIsUsed = colorPOI.inputColorIsUsed();
109 if (colorPOI.removeVertexAttrib()) {
110 fDescInfo.fHasVertexColor = false;
111 }
112 115
113 // TODO: Once we can handle single or four channel input into coverage stage s then we can use 116 // TODO: Once we can handle single or four channel input into coverage stage s then we can use
114 // drawState's coverageProcInfo (like color above) to set this initial infor mation. 117 // drawState's coverageProcInfo (like color above) to set this initial infor mation.
115 int firstCoverageStageIdx = 0; 118 int firstCoverageStageIdx = 0;
116 fDescInfo.fInputCoverageIsUsed = true;
117 119
118 GrXferProcessor::BlendInfo blendInfo; 120 GrXferProcessor::BlendInfo blendInfo;
119 fXferProcessor->getBlendInfo(&blendInfo); 121 fXferProcessor->getBlendInfo(&blendInfo);
120 122
121 this->adjustProgramFromOptimizations(drawState, optFlags, colorPOI, coverage POI, 123 this->adjustProgramFromOptimizations(drawState, optFlags, colorPOI, coverage POI,
122 &firstColorStageIdx, &firstCoverageStag eIdx); 124 &firstColorStageIdx, &firstCoverageStag eIdx);
123 125
124 fDescInfo.fRequiresLocalCoordAttrib = hasLocalCoords; 126 fDescInfo.fRequiresLocalCoordAttrib = hasLocalCoords;
125 127
126 // Copy Stages from DS to ODS 128 // Copy Stages from DS to ODS
127 for (int i = firstColorStageIdx; i < drawState.numColorStages(); ++i) { 129 for (int i = firstColorStageIdx; i < drawState.numColorStages(); ++i) {
128 SkNEW_APPEND_TO_TARRAY(&fFragmentStages, 130 SkNEW_APPEND_TO_TARRAY(&fFragmentStages,
129 GrPendingFragmentStage, 131 GrPendingFragmentStage,
130 (drawState.fColorStages[i], hasLocalCoords)); 132 (drawState.fColorStages[i], hasLocalCoords));
131 } 133 }
132 134
133 fNumColorStages = fFragmentStages.count(); 135 fNumColorStages = fFragmentStages.count();
134 for (int i = firstCoverageStageIdx; i < drawState.numCoverageStages(); ++i) { 136 for (int i = firstCoverageStageIdx; i < drawState.numCoverageStages(); ++i) {
135 SkNEW_APPEND_TO_TARRAY(&fFragmentStages, 137 SkNEW_APPEND_TO_TARRAY(&fFragmentStages,
136 GrPendingFragmentStage, 138 GrPendingFragmentStage,
137 (drawState.fCoverageStages[i], hasLocalCoords)); 139 (drawState.fCoverageStages[i], hasLocalCoords));
138 } 140 }
139 141
140 // let the GP init the batch tracker 142 // let the GP init the batch tracker
141 if (gp) { 143 if (gp) {
142 GrGeometryProcessor::InitBT init; 144 GrGeometryProcessor::InitBT init;
143 init.fOutputColor = fDescInfo.fInputColorIsUsed; 145 init.fColorIgnored = optFlags & GrXferProcessor::kClearColorStages_OptFl ag;
144 init.fOutputCoverage = fDescInfo.fInputCoverageIsUsed; 146 init.fOverrideColor = color;
145 init.fColor = this->getColor(); 147 init.fCoverageIgnored = optFlags & GrXferProcessor::kClearCoverageStages _OptFlag;
146 init.fCoverage = this->getCoverage();
147 fGeometryProcessor->initBatchTracker(&fBatchTracker, init); 148 fGeometryProcessor->initBatchTracker(&fBatchTracker, init);
148 } 149 }
149 } 150 }
150 151
151 void GrOptDrawState::adjustProgramFromOptimizations(const GrDrawState& ds, 152 void GrOptDrawState::adjustProgramFromOptimizations(const GrDrawState& ds,
152 GrXferProcessor::OptFlags fl ags, 153 GrXferProcessor::OptFlags fl ags,
153 const GrProcOptInfo& colorPO I, 154 const GrProcOptInfo& colorPO I,
154 const GrProcOptInfo& coverag ePOI, 155 const GrProcOptInfo& coverag ePOI,
155 int* firstColorStageIdx, 156 int* firstColorStageIdx,
156 int* firstCoverageStageIdx) { 157 int* firstCoverageStageIdx) {
157 fDescInfo.fReadsDst = false; 158 fDescInfo.fReadsDst = false;
158 fDescInfo.fReadsFragPosition = false; 159 fDescInfo.fReadsFragPosition = false;
159 160
160 if (flags & GrXferProcessor::kClearColorStages_OptFlag) { 161 if (flags & GrXferProcessor::kClearColorStages_OptFlag) {
161 fDescInfo.fInputColorIsUsed = true;
162 *firstColorStageIdx = ds.numColorStages(); 162 *firstColorStageIdx = ds.numColorStages();
163 fDescInfo.fHasVertexColor = false;
164 } else { 163 } else {
165 fDescInfo.fReadsDst = colorPOI.readsDst(); 164 fDescInfo.fReadsDst = colorPOI.readsDst();
166 fDescInfo.fReadsFragPosition = colorPOI.readsFragPosition(); 165 fDescInfo.fReadsFragPosition = colorPOI.readsFragPosition();
167 } 166 }
168 167
169 if (flags & GrXferProcessor::kClearCoverageStages_OptFlag) { 168 if (flags & GrXferProcessor::kClearCoverageStages_OptFlag) {
170 fDescInfo.fInputCoverageIsUsed = true;
171 *firstCoverageStageIdx = ds.numCoverageStages(); 169 *firstCoverageStageIdx = ds.numCoverageStages();
172 fDescInfo.fHasVertexCoverage = false;
173 } else { 170 } else {
174 if (coveragePOI.readsDst()) { 171 if (coveragePOI.readsDst()) {
175 fDescInfo.fReadsDst = true; 172 fDescInfo.fReadsDst = true;
176 } 173 }
177 if (coveragePOI.readsFragPosition()) { 174 if (coveragePOI.readsFragPosition()) {
178 fDescInfo.fReadsFragPosition = true; 175 fDescInfo.fReadsFragPosition = true;
179 } 176 }
180 } 177 }
181 } 178 }
182 179
183 void GrOptDrawState::finalize(GrGpu* gpu) { 180 void GrOptDrawState::finalize(GrGpu* gpu) {
184 gpu->buildProgramDesc(*this, fDescInfo, fDrawType, &fDesc); 181 gpu->buildProgramDesc(*this, fDescInfo, fDrawType, &fDesc);
185 fFinalized = true; 182 fFinalized = true;
186 } 183 }
187 184
188 //////////////////////////////////////////////////////////////////////////////// 185 ////////////////////////////////////////////////////////////////////////////////
189 186
190 bool GrOptDrawState::operator== (const GrOptDrawState& that) const { 187 bool GrOptDrawState::operator== (const GrOptDrawState& that) const {
191 if (fDescInfo != that.fDescInfo) { 188 if (fDescInfo != that.fDescInfo) {
192 return false; 189 return false;
193 } 190 }
194 191
195 if (!fDescInfo.fHasVertexColor && this->fColor != that.fColor) {
196 return false;
197 }
198
199 if (this->getRenderTarget() != that.getRenderTarget() || 192 if (this->getRenderTarget() != that.getRenderTarget() ||
200 this->fFragmentStages.count() != that.fFragmentStages.count() || 193 this->fFragmentStages.count() != that.fFragmentStages.count() ||
201 this->fNumColorStages != that.fNumColorStages || 194 this->fNumColorStages != that.fNumColorStages ||
202 this->fScissorState != that.fScissorState || 195 this->fScissorState != that.fScissorState ||
203 !this->fViewMatrix.cheapEqualTo(that.fViewMatrix) || 196 !this->fViewMatrix.cheapEqualTo(that.fViewMatrix) ||
204 this->fDrawType != that.fDrawType || 197 this->fDrawType != that.fDrawType ||
205 this->fFlags != that.fFlags || 198 this->fFlags != that.fFlags ||
206 this->fStencilSettings != that.fStencilSettings || 199 this->fStencilSettings != that.fStencilSettings ||
207 this->fDrawFace != that.fDrawFace || 200 this->fDrawFace != that.fDrawFace ||
208 this->fDstCopy.texture() != that.fDstCopy.texture()) { 201 this->fDstCopy.texture() != that.fDstCopy.texture()) {
209 return false; 202 return false;
210 } 203 }
211 204
212 if (!fDescInfo.fHasVertexCoverage && this->fCoverage != that.fCoverage) { 205 if (!this->getPrimitiveProcessor()->canMakeEqual(fBatchTracker,
206 *that.getPrimitiveProcessor (),
207 that.getBatchTracker())) {
213 return false; 208 return false;
214 } 209 }
215 210
216 if (this->hasGeometryProcessor()) {
217 if (!that.hasGeometryProcessor()) {
218 return false;
219 } else if (!this->getGeometryProcessor()->isEqual(*that.getGeometryProce ssor())) {
220 return false;
221 }
222 } else if (that.hasGeometryProcessor()) {
223 return false;
224 }
225
226 if (!this->getXferProcessor()->isEqual(*that.getXferProcessor())) { 211 if (!this->getXferProcessor()->isEqual(*that.getXferProcessor())) {
227 return false; 212 return false;
228 } 213 }
229 214
230 // The program desc comparison should have already assured that the stage co unts match. 215 // The program desc comparison should have already assured that the stage co unts match.
231 SkASSERT(this->numFragmentStages() == that.numFragmentStages()); 216 SkASSERT(this->numFragmentStages() == that.numFragmentStages());
232 for (int i = 0; i < this->numFragmentStages(); i++) { 217 for (int i = 0; i < this->numFragmentStages(); i++) {
233 218
234 if (this->getFragmentStage(i) != that.getFragmentStage(i)) { 219 if (this->getFragmentStage(i) != that.getFragmentStage(i)) {
235 return false; 220 return false;
236 } 221 }
237 } 222 }
223
224 // Now update the GrPrimitiveProcessor's batch tracker
225 fPrimitiveProcessor->makeEqual(&fBatchTracker, that.getBatchTracker());
238 return true; 226 return true;
239 } 227 }
240 228
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698