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

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

Issue 1110993002: Revert of removing equality / compute invariant loops from GrGeometryProcessors (Closed) Base URL: https://skia.googlesource.com/skia.git@cleanup1
Patch Set: Created 5 years, 7 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
« no previous file with comments | « src/gpu/GrDefaultGeoProcFactory.h ('k') | src/gpu/GrDefaultPathRenderer.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "GrDefaultGeoProcFactory.h" 8 #include "GrDefaultGeoProcFactory.h"
9 9
10 #include "GrInvariantOutput.h" 10 #include "GrInvariantOutput.h"
11 #include "gl/GrGLGeometryProcessor.h" 11 #include "gl/GrGLGeometryProcessor.h"
12 #include "gl/builders/GrGLProgramBuilder.h" 12 #include "gl/builders/GrGLProgramBuilder.h"
13 13
14 /* 14 /*
15 * The default Geometry Processor simply takes position and multiplies it by the uniform view 15 * The default Geometry Processor simply takes position and multiplies it by the uniform view
16 * matrix. It also leaves coverage untouched. Behind the scenes, we may add per vertex color or 16 * matrix. It also leaves coverage untouched. Behind the scenes, we may add per vertex color or
17 * local coords. 17 * local coords.
18 */ 18 */
19 typedef GrDefaultGeoProcFactory Flag; 19 typedef GrDefaultGeoProcFactory Flag;
20 20
21 class DefaultGeoProc : public GrGeometryProcessor { 21 class DefaultGeoProc : public GrGeometryProcessor {
22 public: 22 public:
23 static GrGeometryProcessor* Create(uint32_t gpTypeFlags, 23 static GrGeometryProcessor* Create(uint32_t gpTypeFlags,
24 GrColor color, 24 GrColor color,
25 const SkMatrix& viewMatrix, 25 const SkMatrix& viewMatrix,
26 const SkMatrix& localMatrix, 26 const SkMatrix& localMatrix,
27 bool opaqueVertexColors,
27 uint8_t coverage) { 28 uint8_t coverage) {
28 return SkNEW_ARGS(DefaultGeoProc, (gpTypeFlags, 29 return SkNEW_ARGS(DefaultGeoProc, (gpTypeFlags,
29 color, 30 color,
30 viewMatrix, 31 viewMatrix,
31 localMatrix, 32 localMatrix,
33 opaqueVertexColors,
32 coverage)); 34 coverage));
33 } 35 }
34 36
35 const char* name() const override { return "DefaultGeometryProcessor"; } 37 const char* name() const override { return "DefaultGeometryProcessor"; }
36 38
37 const Attribute* inPosition() const { return fInPosition; } 39 const Attribute* inPosition() const { return fInPosition; }
38 const Attribute* inColor() const { return fInColor; } 40 const Attribute* inColor() const { return fInColor; }
39 const Attribute* inLocalCoords() const { return fInLocalCoords; } 41 const Attribute* inLocalCoords() const { return fInLocalCoords; }
40 const Attribute* inCoverage() const { return fInCoverage; } 42 const Attribute* inCoverage() const { return fInCoverage; }
41 uint8_t coverage() const { return fCoverage; } 43 uint8_t coverage() const { return fCoverage; }
42 44
43 void initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const override { 45 void initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const override {
44 BatchTracker* local = bt->cast<BatchTracker>(); 46 BatchTracker* local = bt->cast<BatchTracker>();
45 local->fInputColorType = GetColorInputType(&local->fColor, this->color() , init, 47 local->fInputColorType = GetColorInputType(&local->fColor, this->color() , init,
46 SkToBool(fInColor)); 48 SkToBool(fInColor));
47 49
48 bool hasVertexCoverage = SkToBool(fInCoverage) && !init.fCoverageIgnored ; 50 bool hasVertexCoverage = SkToBool(fInCoverage) && !init.fCoverageIgnored ;
49 bool covIsSolidWhite = !hasVertexCoverage && 0xff == this->coverage(); 51 bool covIsSolidWhite = !hasVertexCoverage && 0xff == this->coverage();
50 if (covIsSolidWhite) { 52 if (covIsSolidWhite) {
51 local->fInputCoverageType = kAllOnes_GrGPInput; 53 local->fInputCoverageType = kAllOnes_GrGPInput;
52 } else if (!hasVertexCoverage) { 54 } else if (!hasVertexCoverage) {
53 local->fInputCoverageType = kUniform_GrGPInput; 55 local->fInputCoverageType = kUniform_GrGPInput;
54 local->fCoverage = this->coverage(); 56 local->fCoverage = this->coverage();
55 } else if (hasVertexCoverage) { 57 } else if (hasVertexCoverage) {
56 SkASSERT(fInCoverage); 58 SkASSERT(fInCoverage);
57 local->fInputCoverageType = kAttribute_GrGPInput; 59 local->fInputCoverageType = kAttribute_GrGPInput;
58 } else { 60 } else {
59 local->fInputCoverageType = kIgnored_GrGPInput; 61 local->fInputCoverageType = kIgnored_GrGPInput;
60 } 62 }
63
61 local->fUsesLocalCoords = init.fUsesLocalCoords; 64 local->fUsesLocalCoords = init.fUsesLocalCoords;
62 } 65 }
63 66
67 bool onCanMakeEqual(const GrBatchTracker& m,
68 const GrGeometryProcessor& that,
69 const GrBatchTracker& t) const override {
70 const BatchTracker& mine = m.cast<BatchTracker>();
71 const BatchTracker& theirs = t.cast<BatchTracker>();
72 return CanCombineLocalMatrices(*this, mine.fUsesLocalCoords,
73 that, theirs.fUsesLocalCoords) &&
74 CanCombineOutput(mine.fInputColorType, mine.fColor,
75 theirs.fInputColorType, theirs.fColor) &&
76 CanCombineOutput(mine.fInputCoverageType, mine.fCoverage,
77 theirs.fInputCoverageType, theirs.fCoverage);
78 }
79
64 class GLProcessor : public GrGLGeometryProcessor { 80 class GLProcessor : public GrGLGeometryProcessor {
65 public: 81 public:
66 GLProcessor(const GrGeometryProcessor& gp, const GrBatchTracker&) 82 GLProcessor(const GrGeometryProcessor& gp, const GrBatchTracker&)
67 : fColor(GrColor_ILLEGAL), fCoverage(0xff) {} 83 : fColor(GrColor_ILLEGAL), fCoverage(0xff) {}
68 84
69 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { 85 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
70 const DefaultGeoProc& gp = args.fGP.cast<DefaultGeoProc>(); 86 const DefaultGeoProc& gp = args.fGP.cast<DefaultGeoProc>();
71 GrGLGPBuilder* pb = args.fPB; 87 GrGLGPBuilder* pb = args.fPB;
72 GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder(); 88 GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder();
73 GrGLGPFragmentBuilder* fs = args.fPB->getFragmentShaderBuilder(); 89 GrGLGPFragmentBuilder* fs = args.fPB->getFragmentShaderBuilder();
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, 176 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt,
161 const GrGLCaps&) const over ride { 177 const GrGLCaps&) const over ride {
162 return SkNEW_ARGS(GLProcessor, (*this, bt)); 178 return SkNEW_ARGS(GLProcessor, (*this, bt));
163 } 179 }
164 180
165 private: 181 private:
166 DefaultGeoProc(uint32_t gpTypeFlags, 182 DefaultGeoProc(uint32_t gpTypeFlags,
167 GrColor color, 183 GrColor color,
168 const SkMatrix& viewMatrix, 184 const SkMatrix& viewMatrix,
169 const SkMatrix& localMatrix, 185 const SkMatrix& localMatrix,
186 bool opaqueVertexColors,
170 uint8_t coverage) 187 uint8_t coverage)
171 : INHERITED(color, viewMatrix, localMatrix) 188 : INHERITED(color, viewMatrix, localMatrix, opaqueVertexColors)
172 , fInPosition(NULL) 189 , fInPosition(NULL)
173 , fInColor(NULL) 190 , fInColor(NULL)
174 , fInLocalCoords(NULL) 191 , fInLocalCoords(NULL)
175 , fInCoverage(NULL) 192 , fInCoverage(NULL)
176 , fCoverage(coverage) 193 , fCoverage(coverage)
177 , fFlags(gpTypeFlags) { 194 , fFlags(gpTypeFlags) {
178 this->initClassID<DefaultGeoProc>(); 195 this->initClassID<DefaultGeoProc>();
179 bool hasColor = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kColor_G PType); 196 bool hasColor = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kColor_G PType);
180 bool hasLocalCoord = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kLo calCoord_GPType); 197 bool hasLocalCoord = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kLo calCoord_GPType);
181 bool hasCoverage = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kCove rage_GPType); 198 bool hasCoverage = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kCove rage_GPType);
182 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe rtexAttribType)); 199 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe rtexAttribType));
183 if (hasColor) { 200 if (hasColor) {
184 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVer texAttribType)); 201 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVer texAttribType));
202 this->setHasVertexColor();
185 } 203 }
186 if (hasLocalCoord) { 204 if (hasLocalCoord) {
187 fInLocalCoords = &this->addVertexAttrib(Attribute("inLocalCoord", 205 fInLocalCoords = &this->addVertexAttrib(Attribute("inLocalCoord",
188 kVec2f_GrVertexA ttribType)); 206 kVec2f_GrVertexA ttribType));
189 this->setHasLocalCoords(); 207 this->setHasLocalCoords();
190 } 208 }
191 if (hasCoverage) { 209 if (hasCoverage) {
192 fInCoverage = &this->addVertexAttrib(Attribute("inCoverage", 210 fInCoverage = &this->addVertexAttrib(Attribute("inCoverage",
193 kFloat_GrVertexAttr ibType)); 211 kFloat_GrVertexAttr ibType));
194 } 212 }
195 } 213 }
196 214
215 bool onIsEqual(const GrGeometryProcessor& other) const override {
216 const DefaultGeoProc& gp = other.cast<DefaultGeoProc>();
217 return gp.fFlags == this->fFlags;
218 }
219
220 void onGetInvariantOutputCoverage(GrInitInvariantOutput* out) const override {
221 if (fInCoverage) {
222 out->setUnknownSingleComponent();
223 } else {
224 // uniform coverage
225 out->setKnownSingleComponent(this->coverage());
226 }
227 }
228
197 struct BatchTracker { 229 struct BatchTracker {
198 GrGPInput fInputColorType; 230 GrGPInput fInputColorType;
199 GrGPInput fInputCoverageType; 231 GrGPInput fInputCoverageType;
200 GrColor fColor; 232 GrColor fColor;
201 GrColor fCoverage; 233 GrColor fCoverage;
202 bool fUsesLocalCoords; 234 bool fUsesLocalCoords;
203 }; 235 };
204 236
205 const Attribute* fInPosition; 237 const Attribute* fInPosition;
206 const Attribute* fInColor; 238 const Attribute* fInColor;
(...skipping 21 matching lines...) Expand all
228 flags |= GrDefaultGeoProcFactory::kCoverage_GPType; 260 flags |= GrDefaultGeoProcFactory::kCoverage_GPType;
229 } 261 }
230 if (random->nextBool()) { 262 if (random->nextBool()) {
231 flags |= GrDefaultGeoProcFactory::kLocalCoord_GPType; 263 flags |= GrDefaultGeoProcFactory::kLocalCoord_GPType;
232 } 264 }
233 265
234 return DefaultGeoProc::Create(flags, 266 return DefaultGeoProc::Create(flags,
235 GrRandomColor(random), 267 GrRandomColor(random),
236 GrProcessorUnitTest::TestMatrix(random), 268 GrProcessorUnitTest::TestMatrix(random),
237 GrProcessorUnitTest::TestMatrix(random), 269 GrProcessorUnitTest::TestMatrix(random),
270 random->nextBool(),
238 GrRandomCoverage(random)); 271 GrRandomCoverage(random));
239 } 272 }
240 273
241 const GrGeometryProcessor* GrDefaultGeoProcFactory::Create(uint32_t gpTypeFlags, 274 const GrGeometryProcessor* GrDefaultGeoProcFactory::Create(uint32_t gpTypeFlags,
242 GrColor color, 275 GrColor color,
243 const SkMatrix& viewM atrix, 276 const SkMatrix& viewM atrix,
244 const SkMatrix& local Matrix, 277 const SkMatrix& local Matrix,
278 bool opaqueVertexColo rs,
245 uint8_t coverage) { 279 uint8_t coverage) {
246 return DefaultGeoProc::Create(gpTypeFlags, 280 return DefaultGeoProc::Create(gpTypeFlags,
247 color, 281 color,
248 viewMatrix, 282 viewMatrix,
249 localMatrix, 283 localMatrix,
284 opaqueVertexColors,
250 coverage); 285 coverage);
251 } 286 }
OLDNEW
« no previous file with comments | « src/gpu/GrDefaultGeoProcFactory.h ('k') | src/gpu/GrDefaultPathRenderer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698