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

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

Issue 827973002: ViewMatrix uniform upload moved to GeometryProcessor (Closed) Base URL: https://skia.googlesource.com/skia.git@vm-on-gp
Patch Set: feedback inc 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
« no previous file with comments | « src/gpu/GrOptDrawState.cpp ('k') | src/gpu/effects/GrBezierEffect.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 2013 Google Inc. 2 * Copyright 2013 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 "GrOvalRenderer.h" 8 #include "GrOvalRenderer.h"
9 9
10 #include "GrProcessor.h" 10 #include "GrProcessor.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), ce.inCircleEdge()->fNa me); 94 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), ce.inCircleEdge()->fNa me);
95 95
96 // Setup pass through color 96 // Setup pass through color
97 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputC olor, NULL, 97 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputC olor, NULL,
98 &fColorUniform); 98 &fColorUniform);
99 99
100 // setup coord outputs 100 // setup coord outputs
101 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), ce.i nPosition()->fName); 101 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), ce.i nPosition()->fName);
102 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), ce.inPo sition()->fName); 102 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), ce.inPo sition()->fName);
103 103
104 // setup uniform viewMatrix
105 this->addUniformViewMatrix(pb);
106
104 // setup position varying 107 // setup position varying
105 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPositi on(), 108 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPositi on(),
106 vsBuilder->uViewM(), ce.inPosition()->fName); 109 this->uViewM(), ce.inPosition()->fName);
107 110
108 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilde r(); 111 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilde r();
109 fsBuilder->codeAppendf("float d = length(%s.xy);", v.fsIn()); 112 fsBuilder->codeAppendf("float d = length(%s.xy);", v.fsIn());
110 fsBuilder->codeAppendf("float edgeAlpha = clamp(%s.z * (1.0 - d), 0. 0, 1.0);", v.fsIn()); 113 fsBuilder->codeAppendf("float edgeAlpha = clamp(%s.z * (1.0 - d), 0. 0, 1.0);", v.fsIn());
111 if (ce.isStroked()) { 114 if (ce.isStroked()) {
112 fsBuilder->codeAppendf("float innerAlpha = clamp(%s.z * (d - %s. w), 0.0, 1.0);", 115 fsBuilder->codeAppendf("float innerAlpha = clamp(%s.z * (d - %s. w), 0.0, 1.0);",
113 v.fsIn(), v.fsIn()); 116 v.fsIn(), v.fsIn());
114 fsBuilder->codeAppend("edgeAlpha *= innerAlpha;"); 117 fsBuilder->codeAppend("edgeAlpha *= innerAlpha;");
115 } 118 }
116 119
117 fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage ); 120 fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage );
118 } 121 }
119 122
120 static void GenKey(const GrGeometryProcessor& processor, 123 static void GenKey(const GrGeometryProcessor& processor,
121 const GrBatchTracker& bt, 124 const GrBatchTracker& bt,
122 const GrGLCaps&, 125 const GrGLCaps&,
123 GrProcessorKeyBuilder* b) { 126 GrProcessorKeyBuilder* b) {
124 const BatchTracker& local = bt.cast<BatchTracker>(); 127 const BatchTracker& local = bt.cast<BatchTracker>();
125 const CircleEdgeEffect& circleEffect = processor.cast<CircleEdgeEffe ct>(); 128 const CircleEdgeEffect& circleEffect = processor.cast<CircleEdgeEffe ct>();
126 uint16_t key = circleEffect.isStroked() ? 0x1 : 0x0; 129 uint16_t key = circleEffect.isStroked() ? 0x1 : 0x0;
127 key |= local.fUsesLocalCoords && processor.localMatrix().hasPerspect ive() ? 0x2 : 0x0; 130 key |= local.fUsesLocalCoords && processor.localMatrix().hasPerspect ive() ? 0x2 : 0x0;
128 b->add32(key << 16 | local.fInputColorType); 131 b->add32(key << 16 | local.fInputColorType);
129 } 132 }
130 133
131 virtual void setData(const GrGLProgramDataManager& pdman, 134 virtual void setData(const GrGLProgramDataManager& pdman,
132 const GrPrimitiveProcessor& gp, 135 const GrPrimitiveProcessor& gp,
133 const GrBatchTracker& bt) SK_OVERRIDE { 136 const GrBatchTracker& bt) SK_OVERRIDE {
137 this->setUniformViewMatrix(pdman, gp.viewMatrix());
138
134 const BatchTracker& local = bt.cast<BatchTracker>(); 139 const BatchTracker& local = bt.cast<BatchTracker>();
135 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != f Color) { 140 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != f Color) {
136 GrGLfloat c[4]; 141 GrGLfloat c[4];
137 GrColorToRGBAFloat(local.fColor, c); 142 GrColorToRGBAFloat(local.fColor, c);
138 pdman.set4fv(fColorUniform, 1, c); 143 pdman.set4fv(fColorUniform, 1, c);
139 fColor = local.fColor; 144 fColor = local.fColor;
140 } 145 }
141 } 146 }
142 147
143 private: 148 private:
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 ee.inEllipseRadii()->fName); 272 ee.inEllipseRadii()->fName);
268 273
269 // Setup pass through color 274 // Setup pass through color
270 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputC olor, NULL, 275 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputC olor, NULL,
271 &fColorUniform); 276 &fColorUniform);
272 277
273 // setup coord outputs 278 // setup coord outputs
274 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), ee.i nPosition()->fName); 279 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), ee.i nPosition()->fName);
275 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), ee.inPo sition()->fName); 280 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), ee.inPo sition()->fName);
276 281
282 // setup uniform viewMatrix
283 this->addUniformViewMatrix(pb);
284
277 // setup position varying 285 // setup position varying
278 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPositi on(), 286 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPositi on(),
279 vsBuilder->uViewM(), ee.inPosition()->fName); 287 this->uViewM(), ee.inPosition()->fName);
280 288
281 // for outer curve 289 // for outer curve
282 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilde r(); 290 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilde r();
283 fsBuilder->codeAppendf("vec2 scaledOffset = %s*%s.xy;", ellipseOffse ts.fsIn(), 291 fsBuilder->codeAppendf("vec2 scaledOffset = %s*%s.xy;", ellipseOffse ts.fsIn(),
284 ellipseRadii.fsIn()); 292 ellipseRadii.fsIn());
285 fsBuilder->codeAppend("float test = dot(scaledOffset, scaledOffset) - 1.0;"); 293 fsBuilder->codeAppend("float test = dot(scaledOffset, scaledOffset) - 1.0;");
286 fsBuilder->codeAppendf("vec2 grad = 2.0*scaledOffset*%s.xy;", ellips eRadii.fsIn()); 294 fsBuilder->codeAppendf("vec2 grad = 2.0*scaledOffset*%s.xy;", ellips eRadii.fsIn());
287 fsBuilder->codeAppend("float grad_dot = dot(grad, grad);"); 295 fsBuilder->codeAppend("float grad_dot = dot(grad, grad);");
288 296
289 // avoid calling inversesqrt on zero. 297 // avoid calling inversesqrt on zero.
(...skipping 22 matching lines...) Expand all
312 const BatchTracker& local = bt.cast<BatchTracker>(); 320 const BatchTracker& local = bt.cast<BatchTracker>();
313 const EllipseEdgeEffect& ellipseEffect = processor.cast<EllipseEdgeE ffect>(); 321 const EllipseEdgeEffect& ellipseEffect = processor.cast<EllipseEdgeE ffect>();
314 uint16_t key = ellipseEffect.isStroked() ? 0x1 : 0x0; 322 uint16_t key = ellipseEffect.isStroked() ? 0x1 : 0x0;
315 key |= local.fUsesLocalCoords && processor.localMatrix().hasPerspect ive() ? 0x2 : 0x0; 323 key |= local.fUsesLocalCoords && processor.localMatrix().hasPerspect ive() ? 0x2 : 0x0;
316 b->add32(key << 16 | local.fInputColorType); 324 b->add32(key << 16 | local.fInputColorType);
317 } 325 }
318 326
319 virtual void setData(const GrGLProgramDataManager& pdman, 327 virtual void setData(const GrGLProgramDataManager& pdman,
320 const GrPrimitiveProcessor& gp, 328 const GrPrimitiveProcessor& gp,
321 const GrBatchTracker& bt) SK_OVERRIDE { 329 const GrBatchTracker& bt) SK_OVERRIDE {
330 this->setUniformViewMatrix(pdman, gp.viewMatrix());
331
322 const BatchTracker& local = bt.cast<BatchTracker>(); 332 const BatchTracker& local = bt.cast<BatchTracker>();
323 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != f Color) { 333 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != f Color) {
324 GrGLfloat c[4]; 334 GrGLfloat c[4];
325 GrColorToRGBAFloat(local.fColor, c); 335 GrColorToRGBAFloat(local.fColor, c);
326 pdman.set4fv(fColorUniform, 1, c); 336 pdman.set4fv(fColorUniform, 1, c);
327 fColor = local.fColor; 337 fColor = local.fColor;
328 } 338 }
329 } 339 }
330 340
331 private: 341 private:
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 ee.inEllipseOffsets1()->fName); 472 ee.inEllipseOffsets1()->fName);
463 473
464 // Setup pass through color 474 // Setup pass through color
465 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputC olor, NULL, 475 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputC olor, NULL,
466 &fColorUniform); 476 &fColorUniform);
467 477
468 // setup coord outputs 478 // setup coord outputs
469 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), ee.i nPosition()->fName); 479 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), ee.i nPosition()->fName);
470 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), ee.inPo sition()->fName); 480 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), ee.inPo sition()->fName);
471 481
482 // setup uniform viewMatrix
483 this->addUniformViewMatrix(pb);
484
472 // setup position varying 485 // setup position varying
473 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPositi on(), 486 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPositi on(),
474 vsBuilder->uViewM(), ee.inPosition()->fName); 487 this->uViewM(), ee.inPosition()->fName);
475 488
476 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilde r(); 489 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilde r();
477 SkAssertResult(fsBuilder->enableFeature( 490 SkAssertResult(fsBuilder->enableFeature(
478 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature) ); 491 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature) );
479 // for outer curve 492 // for outer curve
480 fsBuilder->codeAppendf("vec2 scaledOffset = %s.xy;", offsets0.fsIn() ); 493 fsBuilder->codeAppendf("vec2 scaledOffset = %s.xy;", offsets0.fsIn() );
481 fsBuilder->codeAppend("float test = dot(scaledOffset, scaledOffset) - 1.0;"); 494 fsBuilder->codeAppend("float test = dot(scaledOffset, scaledOffset) - 1.0;");
482 fsBuilder->codeAppendf("vec2 duvdx = dFdx(%s);", offsets0.fsIn()); 495 fsBuilder->codeAppendf("vec2 duvdx = dFdx(%s);", offsets0.fsIn());
483 fsBuilder->codeAppendf("vec2 duvdy = dFdy(%s);", offsets0.fsIn()); 496 fsBuilder->codeAppendf("vec2 duvdy = dFdy(%s);", offsets0.fsIn());
484 fsBuilder->codeAppendf("vec2 grad = vec2(2.0*%s.x*duvdx.x + 2.0*%s.y *duvdx.y," 497 fsBuilder->codeAppendf("vec2 grad = vec2(2.0*%s.x*duvdx.x + 2.0*%s.y *duvdx.y,"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 const DIEllipseEdgeEffect& ellipseEffect = processor.cast<DIEllipseE dgeEffect>(); 535 const DIEllipseEdgeEffect& ellipseEffect = processor.cast<DIEllipseE dgeEffect>();
523 uint16_t key = ellipseEffect.getMode(); 536 uint16_t key = ellipseEffect.getMode();
524 key |= local.fUsesLocalCoords && processor.localMatrix().hasPerspect ive() ? 0x1 << 8 : 537 key |= local.fUsesLocalCoords && processor.localMatrix().hasPerspect ive() ? 0x1 << 8 :
525 0x0; 538 0x0;
526 b->add32(key << 16 | local.fInputColorType); 539 b->add32(key << 16 | local.fInputColorType);
527 } 540 }
528 541
529 virtual void setData(const GrGLProgramDataManager& pdman, 542 virtual void setData(const GrGLProgramDataManager& pdman,
530 const GrPrimitiveProcessor& gp, 543 const GrPrimitiveProcessor& gp,
531 const GrBatchTracker& bt) SK_OVERRIDE { 544 const GrBatchTracker& bt) SK_OVERRIDE {
545 this->setUniformViewMatrix(pdman, gp.viewMatrix());
546
532 const BatchTracker& local = bt.cast<BatchTracker>(); 547 const BatchTracker& local = bt.cast<BatchTracker>();
533 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != f Color) { 548 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != f Color) {
534 GrGLfloat c[4]; 549 GrGLfloat c[4];
535 GrColorToRGBAFloat(local.fColor, c); 550 GrColorToRGBAFloat(local.fColor, c);
536 pdman.set4fv(fColorUniform, 1, c); 551 pdman.set4fv(fColorUniform, 1, c);
537 fColor = local.fColor; 552 fColor = local.fColor;
538 } 553 }
539 } 554 }
540 555
541 private: 556 private:
(...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after
1383 int indexCnt = isStrokeOnly ? SK_ARRAY_COUNT(gRRectIndices) - 6 : 1398 int indexCnt = isStrokeOnly ? SK_ARRAY_COUNT(gRRectIndices) - 6 :
1384 SK_ARRAY_COUNT(gRRectIndices); 1399 SK_ARRAY_COUNT(gRRectIndices);
1385 target->setIndexSourceToBuffer(indexBuffer); 1400 target->setIndexSourceToBuffer(indexBuffer);
1386 target->drawIndexedInstances(drawState, effect, kTriangles_GrPrimitiveTy pe, 1, 16, indexCnt, 1401 target->drawIndexedInstances(drawState, effect, kTriangles_GrPrimitiveTy pe, 1, 16, indexCnt,
1387 &bounds); 1402 &bounds);
1388 } 1403 }
1389 1404
1390 target->resetIndexSource(); 1405 target->resetIndexSource();
1391 return true; 1406 return true;
1392 } 1407 }
OLDNEW
« no previous file with comments | « src/gpu/GrOptDrawState.cpp ('k') | src/gpu/effects/GrBezierEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698