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

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

Issue 866573002: XPFactory lazily initializie in drawstate / GrPaint (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: feedbackinc 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 2012 Google Inc. 2 * Copyright 2012 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 "GrDrawState.h" 8 #include "GrDrawState.h"
9 9
10 #include "GrBlend.h" 10 #include "GrBlend.h"
11 #include "GrOptDrawState.h" 11 #include "GrOptDrawState.h"
12 #include "GrPaint.h" 12 #include "GrPaint.h"
13 #include "GrProcOptInfo.h" 13 #include "GrProcOptInfo.h"
14 #include "GrXferProcessor.h" 14 #include "GrXferProcessor.h"
15 #include "effects/GrPorterDuffXferProcessor.h" 15 #include "effects/GrPorterDuffXferProcessor.h"
16 16
17 bool GrDrawState::isEqual(const GrDrawState& that, bool explicitLocalCoords) con st { 17 //////////////////////////////////////////////////////////////////////////////
bsalomon 2015/01/21 23:03:06 remove?
18 if (this->getRenderTarget() != that.getRenderTarget() ||
19 this->fColorStages.count() != that.fColorStages.count() ||
20 this->fCoverageStages.count() != that.fCoverageStages.count() ||
21 this->fFlagBits != that.fFlagBits ||
22 this->fStencilSettings != that.fStencilSettings ||
23 this->fDrawFace != that.fDrawFace) {
24 return false;
25 }
26 18
27 if (!this->getXPFactory()->isEqual(*that.getXPFactory())) {
28 return false;
29 }
30 19
31 for (int i = 0; i < this->numColorStages(); i++) { 20 GrDrawState::GrDrawState()
32 if (this->getColorStage(i) != that.getColorStage(i)) { 21 : SkDEBUGCODE(fBlockEffectRemovalCnt(0))
33 return false; 22 , fFlagBits(0x0)
34 } 23 , fDrawFace(kBoth_DrawFace)
35 } 24 , fColorProcInfoValid(false)
36 for (int i = 0; i < this->numCoverageStages(); i++) { 25 , fCoverageProcInfoValid(false)
37 if (this->getCoverageStage(i) != that.getCoverageStage(i)) { 26 , fColorCache(GrColor_ILLEGAL)
38 return false; 27 , fCoverageCache(GrColor_ILLEGAL)
39 } 28 , fColorPrimProc(NULL)
40 } 29 , fCoveragePrimProc(NULL) {
41 30 SkASSERT(0 == fBlockEffectRemovalCnt);
bsalomon 2015/01/21 23:03:06 no need to assert, we just set it
42 return true;
43 } 31 }
44 32
45 //////////////////////////////////////////////////////////////////////////////
46
47 GrDrawState& GrDrawState::operator=(const GrDrawState& that) { 33 GrDrawState& GrDrawState::operator=(const GrDrawState& that) {
48 fRenderTarget.reset(SkSafeRef(that.fRenderTarget.get())); 34 fRenderTarget.reset(SkSafeRef(that.fRenderTarget.get()));
49 fFlagBits = that.fFlagBits; 35 fFlagBits = that.fFlagBits;
50 fStencilSettings = that.fStencilSettings; 36 fStencilSettings = that.fStencilSettings;
51 fDrawFace = that.fDrawFace; 37 fDrawFace = that.fDrawFace;
52 fXPFactory.reset(SkRef(that.getXPFactory())); 38 fXPFactory.reset(SkRef(that.getXPFactory()));
53 fColorStages = that.fColorStages; 39 fColorStages = that.fColorStages;
54 fCoverageStages = that.fCoverageStages; 40 fCoverageStages = that.fCoverageStages;
55 41
56 fColorProcInfoValid = that.fColorProcInfoValid; 42 fColorProcInfoValid = that.fColorProcInfoValid;
57 fCoverageProcInfoValid = that.fCoverageProcInfoValid; 43 fCoverageProcInfoValid = that.fCoverageProcInfoValid;
58 fColorCache = that.fColorCache; 44 fColorCache = that.fColorCache;
59 fCoverageCache = that.fCoverageCache; 45 fCoverageCache = that.fCoverageCache;
60 fColorPrimProc = that.fColorPrimProc; 46 fColorPrimProc = that.fColorPrimProc;
61 fCoveragePrimProc = that.fCoveragePrimProc; 47 fCoveragePrimProc = that.fCoveragePrimProc;
62 if (fColorProcInfoValid) { 48 if (fColorProcInfoValid) {
63 fColorProcInfo = that.fColorProcInfo; 49 fColorProcInfo = that.fColorProcInfo;
64 } 50 }
65 if (fCoverageProcInfoValid) { 51 if (fCoverageProcInfoValid) {
66 fCoverageProcInfo = that.fCoverageProcInfo; 52 fCoverageProcInfo = that.fCoverageProcInfo;
67 } 53 }
68 return *this; 54 return *this;
69 } 55 }
70 56
71 void GrDrawState::onReset() {
72 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numFragmentStages());
73 fRenderTarget.reset(NULL);
74
75 fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode));
76 fColorStages.reset();
77 fCoverageStages.reset();
78
79 fFlagBits = 0x0;
80 fStencilSettings.setDisabled();
81 fDrawFace = kBoth_DrawFace;
82
83 fColorProcInfoValid = false;
84 fCoverageProcInfoValid = false;
85
86 fColorCache = GrColor_ILLEGAL;
87 fCoverageCache = GrColor_ILLEGAL;
88
89 fColorPrimProc = NULL;
90 fCoveragePrimProc = NULL;
91 }
92
93 void GrDrawState::setFromPaint(const GrPaint& paint, GrRenderTarget* rt) { 57 void GrDrawState::setFromPaint(const GrPaint& paint, GrRenderTarget* rt) {
94 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numFragmentStages()); 58 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numFragmentStages());
95 59
96 fColorStages.reset(); 60 fColorStages.reset();
97 fCoverageStages.reset(); 61 fCoverageStages.reset();
98 62
99 for (int i = 0; i < paint.numColorStages(); ++i) { 63 for (int i = 0; i < paint.numColorStages(); ++i) {
100 fColorStages.push_back(paint.getColorStage(i)); 64 fColorStages.push_back(paint.getColorStage(i));
101 } 65 }
102 66
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 if (caps.dualSourceBlendingSupport()) { 99 if (caps.dualSourceBlendingSupport()) {
136 return true; 100 return true;
137 } 101 }
138 102
139 this->calcColorInvariantOutput(color); 103 this->calcColorInvariantOutput(color);
140 104
141 // The coverage isn't actually white, its unknown, but this will produce the same effect 105 // The coverage isn't actually white, its unknown, but this will produce the same effect
142 // TODO we want to cache the result of this call, but we can probably clean up the interface 106 // TODO we want to cache the result of this call, but we can probably clean up the interface
143 // so we don't have to pass in a seemingly known coverage 107 // so we don't have to pass in a seemingly known coverage
144 this->calcCoverageInvariantOutput(GrColor_WHITE); 108 this->calcCoverageInvariantOutput(GrColor_WHITE);
145 return fXPFactory->canApplyCoverage(fColorProcInfo, fCoverageProcInfo); 109 return this->getXPFactory()->canApplyCoverage(fColorProcInfo, fCoverageProcI nfo);
146 } 110 }
147 111
148 //////////////////////////////////////////////////////////////////////////////s 112 //////////////////////////////////////////////////////////////////////////////s
149 113
150 bool GrDrawState::willEffectReadDstColor() const { 114 bool GrDrawState::willEffectReadDstColor() const {
151 return fXPFactory->willReadDst(); 115 return this->getXPFactory()->willReadDst();
152 } 116 }
153 117
154 void GrDrawState::AutoRestoreEffects::set(GrDrawState* ds) { 118 void GrDrawState::AutoRestoreEffects::set(GrDrawState* ds) {
155 if (fDrawState) { 119 if (fDrawState) {
156 int m = fDrawState->numColorStages() - fColorEffectCnt; 120 int m = fDrawState->numColorStages() - fColorEffectCnt;
157 SkASSERT(m >= 0); 121 SkASSERT(m >= 0);
158 fDrawState->fColorStages.pop_back_n(m); 122 fDrawState->fColorStages.pop_back_n(m);
159 123
160 int n = fDrawState->numCoverageStages() - fCoverageEffectCnt; 124 int n = fDrawState->numCoverageStages() - fCoverageEffectCnt;
161 SkASSERT(n >= 0); 125 SkASSERT(n >= 0);
(...skipping 10 matching lines...) Expand all
172 fCoverageEffectCnt = ds->numCoverageStages(); 136 fCoverageEffectCnt = ds->numCoverageStages();
173 SkDEBUGCODE(++ds->fBlockEffectRemovalCnt;) 137 SkDEBUGCODE(++ds->fBlockEffectRemovalCnt;)
174 } 138 }
175 } 139 }
176 140
177 //////////////////////////////////////////////////////////////////////////////// 141 ////////////////////////////////////////////////////////////////////////////////
178 142
179 // Some blend modes allow folding a fractional coverage value into the color's a lpha channel, while 143 // Some blend modes allow folding a fractional coverage value into the color's a lpha channel, while
180 // others will blend incorrectly. 144 // others will blend incorrectly.
181 bool GrDrawState::canTweakAlphaForCoverage() const { 145 bool GrDrawState::canTweakAlphaForCoverage() const {
182 return fXPFactory->canTweakAlphaForCoverage(); 146 return this->getXPFactory()->canTweakAlphaForCoverage();
183 } 147 }
184 148
185 //////////////////////////////////////////////////////////////////////////////// 149 ////////////////////////////////////////////////////////////////////////////////
186 150
187 GrDrawState::~GrDrawState() { 151 GrDrawState::~GrDrawState() {
188 SkASSERT(0 == fBlockEffectRemovalCnt); 152 SkASSERT(0 == fBlockEffectRemovalCnt);
189 } 153 }
190 154
191 //////////////////////////////////////////////////////////////////////////////// 155 ////////////////////////////////////////////////////////////////////////////////
192 156
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 void GrDrawState::calcCoverageInvariantOutput(GrColor coverage) const { 193 void GrDrawState::calcCoverageInvariantOutput(GrColor coverage) const {
230 if (!fCoverageProcInfoValid || coverage != fCoverageCache) { 194 if (!fCoverageProcInfoValid || coverage != fCoverageCache) {
231 GrColorComponentFlags flags = kRGBA_GrColorComponentFlags; 195 GrColorComponentFlags flags = kRGBA_GrColorComponentFlags;
232 fCoverageProcInfo.calcWithInitialValues(fCoverageStages.begin(), 196 fCoverageProcInfo.calcWithInitialValues(fCoverageStages.begin(),
233 this->numCoverageStages(), cover age, flags, 197 this->numCoverageStages(), cover age, flags,
234 true); 198 true);
235 fCoverageProcInfoValid = true; 199 fCoverageProcInfoValid = true;
236 fCoverageCache = coverage; 200 fCoverageCache = coverage;
237 } 201 }
238 } 202 }
OLDNEW
« src/gpu/GrContext.cpp ('K') | « src/gpu/GrDrawState.h ('k') | src/gpu/GrPaint.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698