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

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

Issue 1213383005: Rework GrPipelineInfo (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fixed Created 5 years, 5 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 usesLocalCoords, 27 bool localCoordsWillBeRead,
28 bool coverageIgnored, 28 bool coverageWillBeIgnored,
29 uint8_t coverage) { 29 uint8_t coverage) {
30 return SkNEW_ARGS(DefaultGeoProc, (gpTypeFlags, 30 return SkNEW_ARGS(DefaultGeoProc, (gpTypeFlags,
31 color, 31 color,
32 viewMatrix, 32 viewMatrix,
33 localMatrix, 33 localMatrix,
34 coverage, 34 coverage,
35 usesLocalCoords, 35 localCoordsWillBeRead,
36 coverageIgnored)); 36 coverageWillBeIgnored));
37 } 37 }
38 38
39 const char* name() const override { return "DefaultGeometryProcessor"; } 39 const char* name() const override { return "DefaultGeometryProcessor"; }
40 40
41 const Attribute* inPosition() const { return fInPosition; } 41 const Attribute* inPosition() const { return fInPosition; }
42 const Attribute* inColor() const { return fInColor; } 42 const Attribute* inColor() const { return fInColor; }
43 const Attribute* inLocalCoords() const { return fInLocalCoords; } 43 const Attribute* inLocalCoords() const { return fInLocalCoords; }
44 const Attribute* inCoverage() const { return fInCoverage; } 44 const Attribute* inCoverage() const { return fInCoverage; }
45 GrColor color() const { return fColor; } 45 GrColor color() const { return fColor; }
46 bool colorIgnored() const { return GrColor_ILLEGAL == fColor; } 46 bool colorIgnored() const { return GrColor_ILLEGAL == fColor; }
47 bool hasVertexColor() const { return SkToBool(fInColor); } 47 bool hasVertexColor() const { return SkToBool(fInColor); }
48 const SkMatrix& viewMatrix() const { return fViewMatrix; } 48 const SkMatrix& viewMatrix() const { return fViewMatrix; }
49 const SkMatrix& localMatrix() const { return fLocalMatrix; } 49 const SkMatrix& localMatrix() const { return fLocalMatrix; }
50 bool usesLocalCoords() const { return fUsesLocalCoords; } 50 bool localCoordsWillBeRead() const { return fLocalCoordsWillBeRead; }
51 uint8_t coverage() const { return fCoverage; } 51 uint8_t coverage() const { return fCoverage; }
52 bool coverageIgnored() const { return fCoverageIgnored; } 52 bool coverageWillBeIgnored() const { return fCoverageWillBeIgnored; }
53 bool hasVertexCoverage() const { return SkToBool(fInCoverage); } 53 bool hasVertexCoverage() const { return SkToBool(fInCoverage); }
54 54
55 class GLProcessor : public GrGLGeometryProcessor { 55 class GLProcessor : public GrGLGeometryProcessor {
56 public: 56 public:
57 GLProcessor(const GrGeometryProcessor& gp, const GrBatchTracker&) 57 GLProcessor(const GrGeometryProcessor& gp, const GrBatchTracker&)
58 : fViewMatrix(SkMatrix::InvalidMatrix()), fColor(GrColor_ILLEGAL), f Coverage(0xff) {} 58 : fViewMatrix(SkMatrix::InvalidMatrix()), fColor(GrColor_ILLEGAL), f Coverage(0xff) {}
59 59
60 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { 60 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
61 const DefaultGeoProc& gp = args.fGP.cast<DefaultGeoProc>(); 61 const DefaultGeoProc& gp = args.fGP.cast<DefaultGeoProc>();
62 GrGLGPBuilder* pb = args.fPB; 62 GrGLGPBuilder* pb = args.fPB;
(...skipping 20 matching lines...) Expand all
83 // emit transforms with explicit local coords 83 // emit transforms with explicit local coords
84 this->emitTransforms(pb, gpArgs->fPositionVar, gp.inLocalCoords( )->fName, 84 this->emitTransforms(pb, gpArgs->fPositionVar, gp.inLocalCoords( )->fName,
85 gp.localMatrix(), args.fTransformsIn, args. fTransformsOut); 85 gp.localMatrix(), args.fTransformsIn, args. fTransformsOut);
86 } else { 86 } else {
87 // emit transforms with position 87 // emit transforms with position
88 this->emitTransforms(pb, gpArgs->fPositionVar, gp.inPosition()-> fName, 88 this->emitTransforms(pb, gpArgs->fPositionVar, gp.inPosition()-> fName,
89 gp.localMatrix(), args.fTransformsIn, args. fTransformsOut); 89 gp.localMatrix(), args.fTransformsIn, args. fTransformsOut);
90 } 90 }
91 91
92 // Setup coverage as pass through 92 // Setup coverage as pass through
93 if (!gp.coverageIgnored()) { 93 if (!gp.coverageWillBeIgnored()) {
94 if (gp.hasVertexCoverage()) { 94 if (gp.hasVertexCoverage()) {
95 fs->codeAppendf("float alpha = 1.0;"); 95 fs->codeAppendf("float alpha = 1.0;");
96 args.fPB->addPassThroughAttribute(gp.inCoverage(), "alpha"); 96 args.fPB->addPassThroughAttribute(gp.inCoverage(), "alpha");
97 fs->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage); 97 fs->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage);
98 } else if (gp.coverage() == 0xff) { 98 } else if (gp.coverage() == 0xff) {
99 fs->codeAppendf("%s = vec4(1);", args.fOutputCoverage); 99 fs->codeAppendf("%s = vec4(1);", args.fOutputCoverage);
100 } else { 100 } else {
101 const char* fragCoverage; 101 const char* fragCoverage;
102 fCoverageUniform = pb->addUniform(GrGLProgramBuilder::kFragm ent_Visibility, 102 fCoverageUniform = pb->addUniform(GrGLProgramBuilder::kFragm ent_Visibility,
103 kFloat_GrSLType, 103 kFloat_GrSLType,
104 kDefault_GrSLPrecision, 104 kDefault_GrSLPrecision,
105 "Coverage", 105 "Coverage",
106 &fragCoverage); 106 &fragCoverage);
107 fs->codeAppendf("%s = vec4(%s);", args.fOutputCoverage, frag Coverage); 107 fs->codeAppendf("%s = vec4(%s);", args.fOutputCoverage, frag Coverage);
108 } 108 }
109 } 109 }
110 } 110 }
111 111
112 static inline void GenKey(const GrGeometryProcessor& gp, 112 static inline void GenKey(const GrGeometryProcessor& gp,
113 const GrBatchTracker& bt, 113 const GrBatchTracker& bt,
114 const GrGLSLCaps&, 114 const GrGLSLCaps&,
115 GrProcessorKeyBuilder* b) { 115 GrProcessorKeyBuilder* b) {
116 const DefaultGeoProc& def = gp.cast<DefaultGeoProc>(); 116 const DefaultGeoProc& def = gp.cast<DefaultGeoProc>();
117 uint32_t key = def.fFlags; 117 uint32_t key = def.fFlags;
118 key |= def.colorIgnored() << 8; 118 key |= def.colorIgnored() << 8;
119 key |= def.coverageIgnored() << 9; 119 key |= def.coverageWillBeIgnored() << 9;
120 key |= def.hasVertexColor() << 10; 120 key |= def.hasVertexColor() << 10;
121 key |= def.hasVertexCoverage() << 11; 121 key |= def.hasVertexCoverage() << 11;
122 key |= def.coverage() == 0xff ? 0x1 << 12 : 0; 122 key |= def.coverage() == 0xff ? 0x1 << 12 : 0;
123 key |= def.usesLocalCoords() && def.localMatrix().hasPerspective() ? 0x1 << 24 : 0x0; 123 key |= def.localCoordsWillBeRead() && def.localMatrix().hasPerspecti ve() ? 0x1 << 24 :
124 0x0;
124 key |= ComputePosKey(def.viewMatrix()) << 25; 125 key |= ComputePosKey(def.viewMatrix()) << 25;
125 b->add32(key); 126 b->add32(key);
126 } 127 }
127 128
128 virtual void setData(const GrGLProgramDataManager& pdman, 129 virtual void setData(const GrGLProgramDataManager& pdman,
129 const GrPrimitiveProcessor& gp, 130 const GrPrimitiveProcessor& gp,
130 const GrBatchTracker& bt) override { 131 const GrBatchTracker& bt) override {
131 const DefaultGeoProc& dgp = gp.cast<DefaultGeoProc>(); 132 const DefaultGeoProc& dgp = gp.cast<DefaultGeoProc>();
132 133
133 if (!dgp.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dgp. viewMatrix())) { 134 if (!dgp.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dgp. viewMatrix())) {
134 fViewMatrix = dgp.viewMatrix(); 135 fViewMatrix = dgp.viewMatrix();
135 GrGLfloat viewMatrix[3 * 3]; 136 GrGLfloat viewMatrix[3 * 3];
136 GrGLGetMatrix<3>(viewMatrix, fViewMatrix); 137 GrGLGetMatrix<3>(viewMatrix, fViewMatrix);
137 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); 138 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix);
138 } 139 }
139 140
140 if (dgp.color() != fColor && !dgp.hasVertexColor()) { 141 if (dgp.color() != fColor && !dgp.hasVertexColor()) {
141 GrGLfloat c[4]; 142 GrGLfloat c[4];
142 GrColorToRGBAFloat(dgp.color(), c); 143 GrColorToRGBAFloat(dgp.color(), c);
143 pdman.set4fv(fColorUniform, 1, c); 144 pdman.set4fv(fColorUniform, 1, c);
144 fColor = dgp.color(); 145 fColor = dgp.color();
145 } 146 }
146 147
147 if (!dgp.coverageIgnored() && dgp.coverage() != fCoverage && !dgp.ha sVertexCoverage()) { 148 if (!dgp.coverageWillBeIgnored() &&
149 dgp.coverage() != fCoverage && !dgp.hasVertexCoverage()) {
148 pdman.set1f(fCoverageUniform, GrNormalizeByteToFloat(dgp.coverag e())); 150 pdman.set1f(fCoverageUniform, GrNormalizeByteToFloat(dgp.coverag e()));
149 fCoverage = dgp.coverage(); 151 fCoverage = dgp.coverage();
150 } 152 }
151 } 153 }
152 154
153 void setTransformData(const GrPrimitiveProcessor& primProc, 155 void setTransformData(const GrPrimitiveProcessor& primProc,
154 const GrGLProgramDataManager& pdman, 156 const GrGLProgramDataManager& pdman,
155 int index, 157 int index,
156 const SkTArray<const GrCoordTransform*, true>& tra nsforms) override { 158 const SkTArray<const GrCoordTransform*, true>& tra nsforms) override {
157 this->setTransformDataHelper<DefaultGeoProc>(primProc, pdman, index, transforms); 159 this->setTransformDataHelper<DefaultGeoProc>(primProc, pdman, index, transforms);
(...skipping 20 matching lines...) Expand all
178 const GrGLSLCaps&) const ov erride { 180 const GrGLSLCaps&) const ov erride {
179 return SkNEW_ARGS(GLProcessor, (*this, bt)); 181 return SkNEW_ARGS(GLProcessor, (*this, bt));
180 } 182 }
181 183
182 private: 184 private:
183 DefaultGeoProc(uint32_t gpTypeFlags, 185 DefaultGeoProc(uint32_t gpTypeFlags,
184 GrColor color, 186 GrColor color,
185 const SkMatrix& viewMatrix, 187 const SkMatrix& viewMatrix,
186 const SkMatrix& localMatrix, 188 const SkMatrix& localMatrix,
187 uint8_t coverage, 189 uint8_t coverage,
188 bool usesLocalCoords, 190 bool localCoordsWillBeRead,
189 bool coverageIgnored) 191 bool coverageWillBeIgnored)
190 : fInPosition(NULL) 192 : fInPosition(NULL)
191 , fInColor(NULL) 193 , fInColor(NULL)
192 , fInLocalCoords(NULL) 194 , fInLocalCoords(NULL)
193 , fInCoverage(NULL) 195 , fInCoverage(NULL)
194 , fColor(color) 196 , fColor(color)
195 , fViewMatrix(viewMatrix) 197 , fViewMatrix(viewMatrix)
196 , fLocalMatrix(localMatrix) 198 , fLocalMatrix(localMatrix)
197 , fCoverage(coverage) 199 , fCoverage(coverage)
198 , fFlags(gpTypeFlags) 200 , fFlags(gpTypeFlags)
199 , fUsesLocalCoords(usesLocalCoords) 201 , fLocalCoordsWillBeRead(localCoordsWillBeRead)
200 , fCoverageIgnored(coverageIgnored) { 202 , fCoverageWillBeIgnored(coverageWillBeIgnored) {
201 this->initClassID<DefaultGeoProc>(); 203 this->initClassID<DefaultGeoProc>();
202 bool hasColor = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kColor_G PType); 204 bool hasColor = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kColor_G PType);
203 bool hasLocalCoord = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kLo calCoord_GPType); 205 bool hasLocalCoord = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kLo calCoord_GPType);
204 bool hasCoverage = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kCove rage_GPType); 206 bool hasCoverage = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kCove rage_GPType);
205 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe rtexAttribType, 207 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe rtexAttribType,
206 kHigh_GrSLPrecision)); 208 kHigh_GrSLPrecision));
207 if (hasColor) { 209 if (hasColor) {
208 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVer texAttribType)); 210 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVer texAttribType));
209 } 211 }
210 if (hasLocalCoord) { 212 if (hasLocalCoord) {
211 fInLocalCoords = &this->addVertexAttrib(Attribute("inLocalCoord", 213 fInLocalCoords = &this->addVertexAttrib(Attribute("inLocalCoord",
212 kVec2f_GrVertexAtt ribType)); 214 kVec2f_GrVertexAtt ribType));
213 this->setHasLocalCoords(); 215 this->setHasLocalCoords();
214 } 216 }
215 if (hasCoverage) { 217 if (hasCoverage) {
216 fInCoverage = &this->addVertexAttrib(Attribute("inCoverage", 218 fInCoverage = &this->addVertexAttrib(Attribute("inCoverage",
217 kFloat_GrVertexAttr ibType)); 219 kFloat_GrVertexAttrib Type));
218 } 220 }
219 } 221 }
220 222
221 const Attribute* fInPosition; 223 const Attribute* fInPosition;
222 const Attribute* fInColor; 224 const Attribute* fInColor;
223 const Attribute* fInLocalCoords; 225 const Attribute* fInLocalCoords;
224 const Attribute* fInCoverage; 226 const Attribute* fInCoverage;
225 GrColor fColor; 227 GrColor fColor;
226 SkMatrix fViewMatrix; 228 SkMatrix fViewMatrix;
227 SkMatrix fLocalMatrix; 229 SkMatrix fLocalMatrix;
228 uint8_t fCoverage; 230 uint8_t fCoverage;
229 uint32_t fFlags; 231 uint32_t fFlags;
230 bool fUsesLocalCoords; 232 bool fLocalCoordsWillBeRead;
231 bool fCoverageIgnored; 233 bool fCoverageWillBeIgnored;
232 234
233 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; 235 GR_DECLARE_GEOMETRY_PROCESSOR_TEST;
234 236
235 typedef GrGeometryProcessor INHERITED; 237 typedef GrGeometryProcessor INHERITED;
236 }; 238 };
237 239
238 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DefaultGeoProc); 240 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DefaultGeoProc);
239 241
240 GrGeometryProcessor* DefaultGeoProc::TestCreate(SkRandom* random, 242 GrGeometryProcessor* DefaultGeoProc::TestCreate(SkRandom* random,
241 GrContext*, 243 GrContext*,
(...skipping 14 matching lines...) Expand all
256 GrRandomColor(random), 258 GrRandomColor(random),
257 GrTest::TestMatrix(random), 259 GrTest::TestMatrix(random),
258 GrTest::TestMatrix(random), 260 GrTest::TestMatrix(random),
259 random->nextBool(), 261 random->nextBool(),
260 random->nextBool(), 262 random->nextBool(),
261 GrRandomCoverage(random)); 263 GrRandomCoverage(random));
262 } 264 }
263 265
264 const GrGeometryProcessor* GrDefaultGeoProcFactory::Create(uint32_t gpTypeFlags, 266 const GrGeometryProcessor* GrDefaultGeoProcFactory::Create(uint32_t gpTypeFlags,
265 GrColor color, 267 GrColor color,
266 bool usesLocalCoords, 268 bool localCoordsWillB eRead,
267 bool coverageIgnored, 269 bool coverageWillBeIg nored,
268 const SkMatrix& viewM atrix, 270 const SkMatrix& viewM atrix,
269 const SkMatrix& local Matrix, 271 const SkMatrix& local Matrix,
270 uint8_t coverage) { 272 uint8_t coverage) {
271 return DefaultGeoProc::Create(gpTypeFlags, 273 return DefaultGeoProc::Create(gpTypeFlags,
272 color, 274 color,
273 viewMatrix, 275 viewMatrix,
274 localMatrix, 276 localMatrix,
275 usesLocalCoords, 277 localCoordsWillBeRead,
276 coverageIgnored, 278 coverageWillBeIgnored,
277 coverage); 279 coverage);
278 } 280 }
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