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

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

Issue 1111603004: removing equality / compute invariant loops from GrGeometryProcessors (Closed) Base URL: https://skia.googlesource.com/skia.git@cleanup1
Patch Set: tweaks 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,
28 uint8_t coverage) { 27 uint8_t coverage) {
29 return SkNEW_ARGS(DefaultGeoProc, (gpTypeFlags, 28 return SkNEW_ARGS(DefaultGeoProc, (gpTypeFlags,
30 color, 29 color,
31 viewMatrix, 30 viewMatrix,
32 localMatrix, 31 localMatrix,
33 opaqueVertexColors,
34 coverage)); 32 coverage));
35 } 33 }
36 34
37 const char* name() const override { return "DefaultGeometryProcessor"; } 35 const char* name() const override { return "DefaultGeometryProcessor"; }
38 36
39 const Attribute* inPosition() const { return fInPosition; } 37 const Attribute* inPosition() const { return fInPosition; }
40 const Attribute* inColor() const { return fInColor; } 38 const Attribute* inColor() const { return fInColor; }
41 const Attribute* inLocalCoords() const { return fInLocalCoords; } 39 const Attribute* inLocalCoords() const { return fInLocalCoords; }
42 const Attribute* inCoverage() const { return fInCoverage; } 40 const Attribute* inCoverage() const { return fInCoverage; }
43 uint8_t coverage() const { return fCoverage; } 41 uint8_t coverage() const { return fCoverage; }
(...skipping 12 matching lines...) Expand all
56 } else if (hasVertexCoverage) { 54 } else if (hasVertexCoverage) {
57 SkASSERT(fInCoverage); 55 SkASSERT(fInCoverage);
58 local->fInputCoverageType = kAttribute_GrGPInput; 56 local->fInputCoverageType = kAttribute_GrGPInput;
59 } else { 57 } else {
60 local->fInputCoverageType = kUniform_GrGPInput; 58 local->fInputCoverageType = kUniform_GrGPInput;
61 local->fCoverage = this->coverage(); 59 local->fCoverage = this->coverage();
62 } 60 }
63 local->fUsesLocalCoords = init.fUsesLocalCoords; 61 local->fUsesLocalCoords = init.fUsesLocalCoords;
64 } 62 }
65 63
66 bool onCanMakeEqual(const GrBatchTracker& m,
67 const GrGeometryProcessor& that,
68 const GrBatchTracker& t) const override {
69 const BatchTracker& mine = m.cast<BatchTracker>();
70 const BatchTracker& theirs = t.cast<BatchTracker>();
71 return CanCombineLocalMatrices(*this, mine.fUsesLocalCoords,
72 that, theirs.fUsesLocalCoords) &&
73 CanCombineOutput(mine.fInputColorType, mine.fColor,
74 theirs.fInputColorType, theirs.fColor) &&
75 CanCombineOutput(mine.fInputCoverageType, mine.fCoverage,
76 theirs.fInputCoverageType, theirs.fCoverage);
77 }
78
79 class GLProcessor : public GrGLGeometryProcessor { 64 class GLProcessor : public GrGLGeometryProcessor {
80 public: 65 public:
81 GLProcessor(const GrGeometryProcessor& gp, const GrBatchTracker&) 66 GLProcessor(const GrGeometryProcessor& gp, const GrBatchTracker&)
82 : fColor(GrColor_ILLEGAL), fCoverage(0xff) {} 67 : fColor(GrColor_ILLEGAL), fCoverage(0xff) {}
83 68
84 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { 69 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
85 const DefaultGeoProc& gp = args.fGP.cast<DefaultGeoProc>(); 70 const DefaultGeoProc& gp = args.fGP.cast<DefaultGeoProc>();
86 GrGLGPBuilder* pb = args.fPB; 71 GrGLGPBuilder* pb = args.fPB;
87 GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder(); 72 GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder();
88 GrGLFragmentBuilder* fs = args.fPB->getFragmentShaderBuilder(); 73 GrGLFragmentBuilder* fs = args.fPB->getFragmentShaderBuilder();
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, 160 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt,
176 const GrGLSLCaps&) const ov erride { 161 const GrGLSLCaps&) const ov erride {
177 return SkNEW_ARGS(GLProcessor, (*this, bt)); 162 return SkNEW_ARGS(GLProcessor, (*this, bt));
178 } 163 }
179 164
180 private: 165 private:
181 DefaultGeoProc(uint32_t gpTypeFlags, 166 DefaultGeoProc(uint32_t gpTypeFlags,
182 GrColor color, 167 GrColor color,
183 const SkMatrix& viewMatrix, 168 const SkMatrix& viewMatrix,
184 const SkMatrix& localMatrix, 169 const SkMatrix& localMatrix,
185 bool opaqueVertexColors,
186 uint8_t coverage) 170 uint8_t coverage)
187 : INHERITED(color, viewMatrix, localMatrix, opaqueVertexColors) 171 : INHERITED(color, viewMatrix, localMatrix)
188 , fInPosition(NULL) 172 , fInPosition(NULL)
189 , fInColor(NULL) 173 , fInColor(NULL)
190 , fInLocalCoords(NULL) 174 , fInLocalCoords(NULL)
191 , fInCoverage(NULL) 175 , fInCoverage(NULL)
192 , fCoverage(coverage) 176 , fCoverage(coverage)
193 , fFlags(gpTypeFlags) { 177 , fFlags(gpTypeFlags) {
194 this->initClassID<DefaultGeoProc>(); 178 this->initClassID<DefaultGeoProc>();
195 bool hasColor = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kColor_G PType); 179 bool hasColor = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kColor_G PType);
196 bool hasLocalCoord = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kLo calCoord_GPType); 180 bool hasLocalCoord = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kLo calCoord_GPType);
197 bool hasCoverage = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kCove rage_GPType); 181 bool hasCoverage = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kCove rage_GPType);
198 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe rtexAttribType)); 182 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe rtexAttribType));
199 if (hasColor) { 183 if (hasColor) {
200 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVer texAttribType)); 184 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVer texAttribType));
201 this->setHasVertexColor();
202 } 185 }
203 if (hasLocalCoord) { 186 if (hasLocalCoord) {
204 fInLocalCoords = &this->addVertexAttrib(Attribute("inLocalCoord", 187 fInLocalCoords = &this->addVertexAttrib(Attribute("inLocalCoord",
205 kVec2f_GrVertexA ttribType)); 188 kVec2f_GrVertexA ttribType));
206 this->setHasLocalCoords(); 189 this->setHasLocalCoords();
207 } 190 }
208 if (hasCoverage) { 191 if (hasCoverage) {
209 fInCoverage = &this->addVertexAttrib(Attribute("inCoverage", 192 fInCoverage = &this->addVertexAttrib(Attribute("inCoverage",
210 kFloat_GrVertexAttr ibType)); 193 kFloat_GrVertexAttr ibType));
211 } 194 }
212 } 195 }
213 196
214 bool onIsEqual(const GrGeometryProcessor& other) const override {
215 const DefaultGeoProc& gp = other.cast<DefaultGeoProc>();
216 return gp.fFlags == this->fFlags;
217 }
218
219 void onGetInvariantOutputCoverage(GrInitInvariantOutput* out) const override {
220 if (fInCoverage) {
221 out->setUnknownSingleComponent();
222 } else {
223 // uniform coverage
224 out->setKnownSingleComponent(this->coverage());
225 }
226 }
227
228 struct BatchTracker { 197 struct BatchTracker {
229 GrGPInput fInputColorType; 198 GrGPInput fInputColorType;
230 GrGPInput fInputCoverageType; 199 GrGPInput fInputCoverageType;
231 GrColor fColor; 200 GrColor fColor;
232 GrColor fCoverage; 201 GrColor fCoverage;
233 bool fUsesLocalCoords; 202 bool fUsesLocalCoords;
234 }; 203 };
235 204
236 const Attribute* fInPosition; 205 const Attribute* fInPosition;
237 const Attribute* fInColor; 206 const Attribute* fInColor;
(...skipping 21 matching lines...) Expand all
259 flags |= GrDefaultGeoProcFactory::kCoverage_GPType; 228 flags |= GrDefaultGeoProcFactory::kCoverage_GPType;
260 } 229 }
261 if (random->nextBool()) { 230 if (random->nextBool()) {
262 flags |= GrDefaultGeoProcFactory::kLocalCoord_GPType; 231 flags |= GrDefaultGeoProcFactory::kLocalCoord_GPType;
263 } 232 }
264 233
265 return DefaultGeoProc::Create(flags, 234 return DefaultGeoProc::Create(flags,
266 GrRandomColor(random), 235 GrRandomColor(random),
267 GrTest::TestMatrix(random), 236 GrTest::TestMatrix(random),
268 GrTest::TestMatrix(random), 237 GrTest::TestMatrix(random),
269 random->nextBool(),
270 GrRandomCoverage(random)); 238 GrRandomCoverage(random));
271 } 239 }
272 240
273 const GrGeometryProcessor* GrDefaultGeoProcFactory::Create(uint32_t gpTypeFlags, 241 const GrGeometryProcessor* GrDefaultGeoProcFactory::Create(uint32_t gpTypeFlags,
274 GrColor color, 242 GrColor color,
275 const SkMatrix& viewM atrix, 243 const SkMatrix& viewM atrix,
276 const SkMatrix& local Matrix, 244 const SkMatrix& local Matrix,
277 bool opaqueVertexColo rs,
278 uint8_t coverage) { 245 uint8_t coverage) {
279 return DefaultGeoProc::Create(gpTypeFlags, 246 return DefaultGeoProc::Create(gpTypeFlags,
280 color, 247 color,
281 viewMatrix, 248 viewMatrix,
282 localMatrix, 249 localMatrix,
283 opaqueVertexColors,
284 coverage); 250 coverage);
285 } 251 }
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