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

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

Issue 2327613002: Remove GrPrimitiveProcessor::hasTransformedLocalCoords (Closed)
Patch Set: Created 4 years, 3 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 | « no previous file | src/gpu/GrGeometryProcessor.h » ('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 "SkRefCnt.h" 11 #include "SkRefCnt.h"
12 #include "glsl/GrGLSLFragmentShaderBuilder.h" 12 #include "glsl/GrGLSLFragmentShaderBuilder.h"
13 #include "glsl/GrGLSLGeometryProcessor.h" 13 #include "glsl/GrGLSLGeometryProcessor.h"
14 #include "glsl/GrGLSLVertexShaderBuilder.h" 14 #include "glsl/GrGLSLVertexShaderBuilder.h"
15 #include "glsl/GrGLSLVarying.h" 15 #include "glsl/GrGLSLVarying.h"
16 #include "glsl/GrGLSLUniformHandler.h" 16 #include "glsl/GrGLSLUniformHandler.h"
17 #include "glsl/GrGLSLUtil.h" 17 #include "glsl/GrGLSLUtil.h"
18 18
19 /* 19 /*
20 * The default Geometry Processor simply takes position and multiplies it by the uniform view 20 * The default Geometry Processor simply takes position and multiplies it by the uniform view
21 * matrix. It also leaves coverage untouched. Behind the scenes, we may add per vertex color or 21 * matrix. It also leaves coverage untouched. Behind the scenes, we may add per vertex color or
22 * local coords. 22 * local coords.
23 */ 23 */
24 24
25 enum GPFlag { 25 enum GPFlag {
26 kColor_GPFlag = 0x1, 26 kColor_GPFlag = 0x1,
27 kLocalCoord_GPFlag = 0x2, 27 kLocalCoord_GPFlag = 0x2,
28 kCoverage_GPFlag= 0x4, 28 kCoverage_GPFlag= 0x4,
29 kTransformedLocalCoord_GPFlag = 0x8,
30 }; 29 };
31 30
32 class DefaultGeoProc : public GrGeometryProcessor { 31 class DefaultGeoProc : public GrGeometryProcessor {
33 public: 32 public:
34 static sk_sp<GrGeometryProcessor> Make(uint32_t gpTypeFlags, 33 static sk_sp<GrGeometryProcessor> Make(uint32_t gpTypeFlags,
35 GrColor color, 34 GrColor color,
36 const SkMatrix& viewMatrix, 35 const SkMatrix& viewMatrix,
37 const SkMatrix& localMatrix, 36 const SkMatrix& localMatrix,
38 bool localCoordsWillBeRead, 37 bool localCoordsWillBeRead,
39 bool coverageWillBeIgnored, 38 bool coverageWillBeIgnored,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 if (gp.hasExplicitLocalCoords()) { 94 if (gp.hasExplicitLocalCoords()) {
96 // emit transforms with explicit local coords 95 // emit transforms with explicit local coords
97 this->emitTransforms(vertBuilder, 96 this->emitTransforms(vertBuilder,
98 varyingHandler, 97 varyingHandler,
99 uniformHandler, 98 uniformHandler,
100 gpArgs->fPositionVar, 99 gpArgs->fPositionVar,
101 gp.inLocalCoords()->fName, 100 gp.inLocalCoords()->fName,
102 gp.localMatrix(), 101 gp.localMatrix(),
103 args.fTransformsIn, 102 args.fTransformsIn,
104 args.fTransformsOut); 103 args.fTransformsOut);
105 } else if(gp.hasTransformedLocalCoords()) {
106 // transforms have already been applied to vertex attributes on the cpu
107 this->emitTransforms(vertBuilder,
108 varyingHandler,
109 gp.inLocalCoords()->fName,
110 args.fTransformsIn,
111 args.fTransformsOut);
112 } else { 104 } else {
113 // emit transforms with position 105 // emit transforms with position
114 this->emitTransforms(vertBuilder, 106 this->emitTransforms(vertBuilder,
115 varyingHandler, 107 varyingHandler,
116 uniformHandler, 108 uniformHandler,
117 gpArgs->fPositionVar, 109 gpArgs->fPositionVar,
118 gp.inPosition()->fName, 110 gp.inPosition()->fName,
119 gp.localMatrix(), 111 gp.localMatrix(),
120 args.fTransformsIn, 112 args.fTransformsIn,
121 args.fTransformsOut); 113 args.fTransformsOut);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 , fColor(color) 216 , fColor(color)
225 , fViewMatrix(viewMatrix) 217 , fViewMatrix(viewMatrix)
226 , fLocalMatrix(localMatrix) 218 , fLocalMatrix(localMatrix)
227 , fCoverage(coverage) 219 , fCoverage(coverage)
228 , fFlags(gpTypeFlags) 220 , fFlags(gpTypeFlags)
229 , fLocalCoordsWillBeRead(localCoordsWillBeRead) 221 , fLocalCoordsWillBeRead(localCoordsWillBeRead)
230 , fCoverageWillBeIgnored(coverageWillBeIgnored) { 222 , fCoverageWillBeIgnored(coverageWillBeIgnored) {
231 this->initClassID<DefaultGeoProc>(); 223 this->initClassID<DefaultGeoProc>();
232 bool hasColor = SkToBool(gpTypeFlags & kColor_GPFlag); 224 bool hasColor = SkToBool(gpTypeFlags & kColor_GPFlag);
233 bool hasExplicitLocalCoords = SkToBool(gpTypeFlags & kLocalCoord_GPFlag) ; 225 bool hasExplicitLocalCoords = SkToBool(gpTypeFlags & kLocalCoord_GPFlag) ;
234 bool hasTransformedLocalCoords = SkToBool(gpTypeFlags & kTransformedLoca lCoord_GPFlag);
235 bool hasLocalCoord = hasExplicitLocalCoords || hasTransformedLocalCoords ;
236 bool hasCoverage = SkToBool(gpTypeFlags & kCoverage_GPFlag); 226 bool hasCoverage = SkToBool(gpTypeFlags & kCoverage_GPFlag);
237 fInPosition = &this->addVertexAttrib("inPosition", kVec2f_GrVertexAttrib Type, 227 fInPosition = &this->addVertexAttrib("inPosition", kVec2f_GrVertexAttrib Type,
238 kHigh_GrSLPrecision); 228 kHigh_GrSLPrecision);
239 if (hasColor) { 229 if (hasColor) {
240 fInColor = &this->addVertexAttrib("inColor", kVec4ub_GrVertexAttribT ype); 230 fInColor = &this->addVertexAttrib("inColor", kVec4ub_GrVertexAttribT ype);
241 } 231 }
242 if (hasLocalCoord) { 232 if (hasExplicitLocalCoords) {
243 fInLocalCoords = &this->addVertexAttrib("inLocalCoord", kVec2f_GrVer texAttribType); 233 fInLocalCoords = &this->addVertexAttrib("inLocalCoord", kVec2f_GrVer texAttribType);
244 if (hasExplicitLocalCoords) { 234 this->setHasExplicitLocalCoords();
245 this->setHasExplicitLocalCoords();
246 } else {
247 SkASSERT(hasTransformedLocalCoords);
248 this->setHasTransformedLocalCoords();
249 }
250 } 235 }
251 if (hasCoverage) { 236 if (hasCoverage) {
252 fInCoverage = &this->addVertexAttrib("inCoverage", kFloat_GrVertexAt tribType); 237 fInCoverage = &this->addVertexAttrib("inCoverage", kFloat_GrVertexAt tribType);
253 } 238 }
254 } 239 }
255 240
256 const Attribute* fInPosition; 241 const Attribute* fInPosition;
257 const Attribute* fInColor; 242 const Attribute* fInColor;
258 const Attribute* fInLocalCoords; 243 const Attribute* fInLocalCoords;
259 const Attribute* fInCoverage; 244 const Attribute* fInCoverage;
(...skipping 16 matching lines...) Expand all
276 uint32_t flags = 0; 261 uint32_t flags = 0;
277 if (d->fRandom->nextBool()) { 262 if (d->fRandom->nextBool()) {
278 flags |= kColor_GPFlag; 263 flags |= kColor_GPFlag;
279 } 264 }
280 if (d->fRandom->nextBool()) { 265 if (d->fRandom->nextBool()) {
281 flags |= kCoverage_GPFlag; 266 flags |= kCoverage_GPFlag;
282 } 267 }
283 if (d->fRandom->nextBool()) { 268 if (d->fRandom->nextBool()) {
284 flags |= kLocalCoord_GPFlag; 269 flags |= kLocalCoord_GPFlag;
285 } 270 }
286 if (d->fRandom->nextBool()) {
287 flags |= kTransformedLocalCoord_GPFlag;
288 }
289 271
290 return DefaultGeoProc::Make(flags, 272 return DefaultGeoProc::Make(flags,
291 GrRandomColor(d->fRandom), 273 GrRandomColor(d->fRandom),
292 GrTest::TestMatrix(d->fRandom), 274 GrTest::TestMatrix(d->fRandom),
293 GrTest::TestMatrix(d->fRandom), 275 GrTest::TestMatrix(d->fRandom),
294 d->fRandom->nextBool(), 276 d->fRandom->nextBool(),
295 d->fRandom->nextBool(), 277 d->fRandom->nextBool(),
296 GrRandomCoverage(d->fRandom)); 278 GrRandomCoverage(d->fRandom));
297 } 279 }
298 280
299 sk_sp<GrGeometryProcessor> GrDefaultGeoProcFactory::Make(const Color& color, 281 sk_sp<GrGeometryProcessor> GrDefaultGeoProcFactory::Make(const Color& color,
300 const Coverage& coverag e, 282 const Coverage& coverag e,
301 const LocalCoords& loca lCoords, 283 const LocalCoords& loca lCoords,
302 const SkMatrix& viewMat rix) { 284 const SkMatrix& viewMat rix) {
303 uint32_t flags = 0; 285 uint32_t flags = 0;
304 flags |= color.fType == Color::kAttribute_Type ? kColor_GPFlag : 0; 286 flags |= color.fType == Color::kAttribute_Type ? kColor_GPFlag : 0;
305 flags |= coverage.fType == Coverage::kAttribute_Type ? kCoverage_GPFlag : 0; 287 flags |= coverage.fType == Coverage::kAttribute_Type ? kCoverage_GPFlag : 0;
306 flags |= localCoords.fType == LocalCoords::kHasExplicit_Type ? kLocalCoord_G PFlag : 0; 288 flags |= localCoords.fType == LocalCoords::kHasExplicit_Type ? kLocalCoord_G PFlag : 0;
307 flags |= localCoords.fType == LocalCoords::kHasTransformed_Type ?
308 kTransformedLocalCoord_GPFlag : 0;
309 289
310 uint8_t inCoverage = coverage.fCoverage; 290 uint8_t inCoverage = coverage.fCoverage;
311 bool coverageWillBeIgnored = coverage.fType == Coverage::kNone_Type; 291 bool coverageWillBeIgnored = coverage.fType == Coverage::kNone_Type;
312 bool localCoordsWillBeRead = localCoords.fType != LocalCoords::kUnused_Type; 292 bool localCoordsWillBeRead = localCoords.fType != LocalCoords::kUnused_Type;
313 293
314 GrColor inColor = color.fColor; 294 GrColor inColor = color.fColor;
315 return DefaultGeoProc::Make(flags, 295 return DefaultGeoProc::Make(flags,
316 inColor, 296 inColor,
317 viewMatrix, 297 viewMatrix,
318 localCoords.fMatrix ? *localCoords.fMatrix : SkM atrix::I(), 298 localCoords.fMatrix ? *localCoords.fMatrix : SkM atrix::I(),
(...skipping 16 matching lines...) Expand all
335 } 315 }
336 316
337 if (localCoords.hasLocalMatrix()) { 317 if (localCoords.hasLocalMatrix()) {
338 invert.preConcat(*localCoords.fMatrix); 318 invert.preConcat(*localCoords.fMatrix);
339 } 319 }
340 } 320 }
341 321
342 LocalCoords inverted(LocalCoords::kUsePosition_Type, &invert); 322 LocalCoords inverted(LocalCoords::kUsePosition_Type, &invert);
343 return Make(color, coverage, inverted, SkMatrix::I()); 323 return Make(color, coverage, inverted, SkMatrix::I());
344 } 324 }
OLDNEW
« no previous file with comments | « no previous file | src/gpu/GrGeometryProcessor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698