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

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

Issue 845103005: GrBatchPrototype (Closed) Base URL: https://skia.googlesource.com/skia.git@lc2
Patch Set: cleanup Created 5 years, 11 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 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 "GrBatch.h"
10 #include "GrDrawState.h" 11 #include "GrDrawState.h"
11 #include "GrDrawTargetCaps.h" 12 #include "GrDrawTargetCaps.h"
12 #include "GrGpu.h" 13 #include "GrGpu.h"
13 #include "GrProcOptInfo.h" 14 #include "GrProcOptInfo.h"
14 #include "GrXferProcessor.h" 15 #include "GrXferProcessor.h"
15 16
16 GrOptDrawState::GrOptDrawState(const GrDrawState& drawState, 17 GrOptDrawState::GrOptDrawState(const GrDrawState& drawState,
17 const GrPrimitiveProcessor* primProc, 18 const GrPrimitiveProcessor* primProc,
18 const GrDrawTargetCaps& caps, 19 const GrDrawTargetCaps& caps,
19 const GrScissorState& scissorState, 20 const GrScissorState& scissorState,
20 const GrDeviceCoordTexture* dstCopy, 21 const GrDeviceCoordTexture* dstCopy,
21 GrGpu::DrawType drawType) 22 GrGpu::DrawType drawType)
22 : fFinalized(false) { 23 : fDrawType(drawType)
23 fDrawType = drawType; 24 , fFinalized(false) {
24
25 fPrimitiveProcessor.reset(primProc); 25 fPrimitiveProcessor.reset(primProc);
26 26
27
28 const GrProcOptInfo& colorPOI = drawState.colorProcInfo(fPrimitiveProcessor) ; 27 const GrProcOptInfo& colorPOI = drawState.colorProcInfo(fPrimitiveProcessor) ;
29 const GrProcOptInfo& coveragePOI = drawState.coverageProcInfo(fPrimitiveProc essor); 28 const GrProcOptInfo& coveragePOI = drawState.coverageProcInfo(fPrimitiveProc essor);
30 29
30 GrGeometryProcessor::InitBT init;
31 this->internalConstructor(&init, drawState, colorPOI, coveragePOI, caps, sci ssorState, dstCopy);
32
33 fPrimitiveProcessor->initBatchTracker(&fBatchTracker, init);
34 }
35
36 GrOptDrawState::GrOptDrawState(GrBatch* batch,
37 const GrDrawState& drawState,
38 const GrDrawTargetCaps& caps,
39 const GrScissorState& scissorState,
40 const GrDeviceCoordTexture* dstCopy,
41 GrGpu::DrawType drawType)
42 : fDrawType(drawType)
43 , fFinalized(false){
44 GrBatchOpt batchOpt;
45 batchOpt.fCanTweakAlphaForCoverage = drawState.canTweakAlphaForCoverage();
46 batch->initBatchOpt(batchOpt);
47 const GrProcOptInfo& colorPOI = drawState.colorProcInfo(batch);
48 const GrProcOptInfo& coveragePOI = drawState.coverageProcInfo(batch);
49
50 GrGeometryProcessor::InitBT init;
51 this->internalConstructor(&init, drawState, colorPOI, coveragePOI, caps, sci ssorState, dstCopy);
52
53 batch->initBatchTracker(init);
54 }
55
56 void GrOptDrawState::internalConstructor(GrGeometryProcessor::InitBT* init,
57 const GrDrawState& drawState,
58 const GrProcOptInfo& colorPOI,
59 const GrProcOptInfo& coveragePOI,
60 const GrDrawTargetCaps& caps,
61 const GrScissorState& scissorState,
62 const GrDeviceCoordTexture* dstCopy) {
31 // Create XferProcessor from DS's XPFactory 63 // Create XferProcessor from DS's XPFactory
32 SkAutoTUnref<GrXferProcessor> xferProcessor( 64 SkAutoTUnref<GrXferProcessor> xferProcessor(
33 drawState.getXPFactory()->createXferProcessor(colorPOI, coveragePOI)); 65 drawState.getXPFactory()->createXferProcessor(colorPOI, coveragePOI));
34 66
35 GrColor overrideColor = GrColor_ILLEGAL; 67 GrColor overrideColor = GrColor_ILLEGAL;
36 if (colorPOI.firstEffectiveStageIndex() != 0) { 68 if (colorPOI.firstEffectiveStageIndex() != 0) {
37 overrideColor = colorPOI.inputColorToEffectiveStage(); 69 overrideColor = colorPOI.inputColorToEffectiveStage();
38 } 70 }
39 71
40 GrXferProcessor::OptFlags optFlags; 72 GrXferProcessor::OptFlags optFlags;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 fNumColorStages = fFragmentStages.count(); 135 fNumColorStages = fFragmentStages.count();
104 for (int i = firstCoverageStageIdx; i < drawState.numCoverageStages(); ++i) { 136 for (int i = firstCoverageStageIdx; i < drawState.numCoverageStages(); ++i) {
105 SkNEW_APPEND_TO_TARRAY(&fFragmentStages, 137 SkNEW_APPEND_TO_TARRAY(&fFragmentStages,
106 GrPendingFragmentStage, 138 GrPendingFragmentStage,
107 (drawState.fCoverageStages[i])); 139 (drawState.fCoverageStages[i]));
108 usesLocalCoords = usesLocalCoords || 140 usesLocalCoords = usesLocalCoords ||
109 drawState.fCoverageStages[i].processor()->usesLocalCoo rds(); 141 drawState.fCoverageStages[i].processor()->usesLocalCoo rds();
110 } 142 }
111 143
112 // let the GP init the batch tracker 144 // let the GP init the batch tracker
113 GrGeometryProcessor::InitBT init; 145 init->fColorIgnored = SkToBool(optFlags & GrXferProcessor::kIgnoreColor_OptF lag);
114 init.fColorIgnored = SkToBool(optFlags & GrXferProcessor::kIgnoreColor_OptFl ag); 146 init->fOverrideColor = init->fColorIgnored ? GrColor_ILLEGAL : overrideColor ;
115 init.fOverrideColor = init.fColorIgnored ? GrColor_ILLEGAL : overrideColor; 147 init->fCoverageIgnored = SkToBool(optFlags & GrXferProcessor::kIgnoreCoverag e_OptFlag);
116 init.fCoverageIgnored = SkToBool(optFlags & GrXferProcessor::kIgnoreCoverage _OptFlag); 148 init->fUsesLocalCoords = usesLocalCoords;
117 init.fUsesLocalCoords = usesLocalCoords;
118 fPrimitiveProcessor->initBatchTracker(&fBatchTracker, init);
119 } 149 }
120 150
121 void GrOptDrawState::adjustProgramFromOptimizations(const GrDrawState& ds, 151 void GrOptDrawState::adjustProgramFromOptimizations(const GrDrawState& ds,
122 GrXferProcessor::OptFlags fl ags, 152 GrXferProcessor::OptFlags fl ags,
123 const GrProcOptInfo& colorPO I, 153 const GrProcOptInfo& colorPO I,
124 const GrProcOptInfo& coverag ePOI, 154 const GrProcOptInfo& coverag ePOI,
125 int* firstColorStageIdx, 155 int* firstColorStageIdx,
126 int* firstCoverageStageIdx) { 156 int* firstCoverageStageIdx) {
127 fDescInfo.fReadsDst = false; 157 fDescInfo.fReadsDst = false;
128 fDescInfo.fReadsFragPosition = false; 158 fDescInfo.fReadsFragPosition = false;
(...skipping 22 matching lines...) Expand all
151 } 181 }
152 } 182 }
153 183
154 void GrOptDrawState::finalize(GrGpu* gpu) { 184 void GrOptDrawState::finalize(GrGpu* gpu) {
155 gpu->buildProgramDesc(*this, fDescInfo, fDrawType, &fDesc); 185 gpu->buildProgramDesc(*this, fDescInfo, fDrawType, &fDesc);
156 fFinalized = true; 186 fFinalized = true;
157 } 187 }
158 188
159 //////////////////////////////////////////////////////////////////////////////// 189 ////////////////////////////////////////////////////////////////////////////////
160 190
161 bool GrOptDrawState::combineIfPossible(const GrOptDrawState& that) { 191 bool GrOptDrawState::combineIfPossible(GrOptDrawState& that) {
162 if (fDescInfo != that.fDescInfo) { 192 if (fDescInfo != that.fDescInfo) {
163 return false; 193 return false;
164 } 194 }
165 195
166 if (this->getRenderTarget() != that.getRenderTarget() || 196 if (this->getRenderTarget() != that.getRenderTarget() ||
167 this->fFragmentStages.count() != that.fFragmentStages.count() || 197 this->fFragmentStages.count() != that.fFragmentStages.count() ||
168 this->fNumColorStages != that.fNumColorStages || 198 this->fNumColorStages != that.fNumColorStages ||
169 this->fScissorState != that.fScissorState || 199 this->fScissorState != that.fScissorState ||
170 this->fDrawType != that.fDrawType || 200 this->fDrawType != that.fDrawType ||
171 this->fFlags != that.fFlags || 201 this->fFlags != that.fFlags ||
172 this->fStencilSettings != that.fStencilSettings || 202 this->fStencilSettings != that.fStencilSettings ||
173 this->fDrawFace != that.fDrawFace || 203 this->fDrawFace != that.fDrawFace ||
174 this->fDstCopy.texture() != that.fDstCopy.texture()) { 204 this->fDstCopy.texture() != that.fDstCopy.texture()) {
175 return false; 205 return false;
176 } 206 }
177 207
178 if (!this->getPrimitiveProcessor()->canMakeEqual(fBatchTracker, 208 // TODO remove this when we have Batch. This is confusing because some OptS tates have primitive
179 *that.getPrimitiveProcessor (), 209 // processors and some are associated with batches
180 that.getBatchTracker())) { 210 if (SkToBool(this->getPrimitiveProcessor()) != SkToBool(that.getPrimitivePro cessor())) {
211 return false;
212 }
213
214 if (this->getPrimitiveProcessor() && that.getPrimitiveProcessor() &&
215 !this->getPrimitiveProcessor()->canMakeEqual(fBatchTracker,
216 *that.getPrimitiveProce ssor(),
217 that.getBatchTracker()) ) {
181 return false; 218 return false;
182 } 219 }
183 220
184 if (!this->getXferProcessor()->isEqual(*that.getXferProcessor())) { 221 if (!this->getXferProcessor()->isEqual(*that.getXferProcessor())) {
185 return false; 222 return false;
186 } 223 }
187 224
188 // The program desc comparison should have already assured that the stage co unts match. 225 // The program desc comparison should have already assured that the stage co unts match.
189 SkASSERT(this->numFragmentStages() == that.numFragmentStages()); 226 SkASSERT(this->numFragmentStages() == that.numFragmentStages());
190 for (int i = 0; i < this->numFragmentStages(); i++) { 227 for (int i = 0; i < this->numFragmentStages(); i++) {
191 228
192 if (this->getFragmentStage(i) != that.getFragmentStage(i)) { 229 if (this->getFragmentStage(i) != that.getFragmentStage(i)) {
193 return false; 230 return false;
194 } 231 }
195 } 232 }
196
197 // Now update the GrPrimitiveProcessor's batch tracker
198 fPrimitiveProcessor->makeEqual(&fBatchTracker, that.getBatchTracker());
199 return true; 233 return true;
200 } 234 }
201 235
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698