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

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

Issue 1462123003: Create GrGLSLVaryingHandler class for program building (Closed) Base URL: https://skia.googlesource.com/skia.git@putCapsOnArgs
Patch Set: fix release builder Created 5 years 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.cpp ('k') | src/gpu/GrPathProcessor.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 "GrBatchFlushState.h" 10 #include "GrBatchFlushState.h"
11 #include "GrBatchTest.h" 11 #include "GrBatchTest.h"
12 #include "GrDrawTarget.h" 12 #include "GrDrawTarget.h"
13 #include "GrGeometryProcessor.h" 13 #include "GrGeometryProcessor.h"
14 #include "GrInvariantOutput.h" 14 #include "GrInvariantOutput.h"
15 #include "GrPipelineBuilder.h" 15 #include "GrPipelineBuilder.h"
16 #include "GrProcessor.h" 16 #include "GrProcessor.h"
17 #include "GrResourceProvider.h" 17 #include "GrResourceProvider.h"
18 #include "GrVertexBuffer.h" 18 #include "GrVertexBuffer.h"
19 #include "SkRRect.h" 19 #include "SkRRect.h"
20 #include "SkStrokeRec.h" 20 #include "SkStrokeRec.h"
21 #include "SkTLazy.h" 21 #include "SkTLazy.h"
22 #include "batches/GrVertexBatch.h" 22 #include "batches/GrVertexBatch.h"
23 #include "effects/GrRRectEffect.h" 23 #include "effects/GrRRectEffect.h"
24 #include "glsl/GrGLSLFragmentShaderBuilder.h" 24 #include "glsl/GrGLSLFragmentShaderBuilder.h"
25 #include "glsl/GrGLSLGeometryProcessor.h" 25 #include "glsl/GrGLSLGeometryProcessor.h"
26 #include "glsl/GrGLSLProgramBuilder.h" 26 #include "glsl/GrGLSLProgramBuilder.h"
27 #include "glsl/GrGLSLProgramDataManager.h" 27 #include "glsl/GrGLSLProgramDataManager.h"
28 #include "glsl/GrGLSLVarying.h"
28 #include "glsl/GrGLSLVertexShaderBuilder.h" 29 #include "glsl/GrGLSLVertexShaderBuilder.h"
29 #include "glsl/GrGLSLUtil.h" 30 #include "glsl/GrGLSLUtil.h"
30 31
31 // TODO(joshualitt) - Break this file up during GrBatch post implementation clea nup 32 // TODO(joshualitt) - Break this file up during GrBatch post implementation clea nup
32 33
33 namespace { 34 namespace {
34 // TODO(joshualitt) add per vertex colors 35 // TODO(joshualitt) add per vertex colors
35 struct CircleVertex { 36 struct CircleVertex {
36 SkPoint fPos; 37 SkPoint fPos;
37 SkPoint fOffset; 38 SkPoint fOffset;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 93
93 class GLSLProcessor : public GrGLSLGeometryProcessor { 94 class GLSLProcessor : public GrGLSLGeometryProcessor {
94 public: 95 public:
95 GLSLProcessor() 96 GLSLProcessor()
96 : fColor(GrColor_ILLEGAL) {} 97 : fColor(GrColor_ILLEGAL) {}
97 98
98 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ 99 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{
99 const CircleEdgeEffect& ce = args.fGP.cast<CircleEdgeEffect>(); 100 const CircleEdgeEffect& ce = args.fGP.cast<CircleEdgeEffect>();
100 GrGLSLGPBuilder* pb = args.fPB; 101 GrGLSLGPBuilder* pb = args.fPB;
101 GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; 102 GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder;
103 GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler;
102 104
103 // emit attributes 105 // emit attributes
104 vertBuilder->emitAttributes(ce); 106 varyingHandler->emitAttributes(ce);
105 107
106 GrGLSLVertToFrag v(kVec4f_GrSLType); 108 GrGLSLVertToFrag v(kVec4f_GrSLType);
107 args.fPB->addVarying("CircleEdge", &v); 109 varyingHandler->addVarying("CircleEdge", &v);
108 vertBuilder->codeAppendf("%s = %s;", v.vsOut(), ce.inCircleEdge()->f Name); 110 vertBuilder->codeAppendf("%s = %s;", v.vsOut(), ce.inCircleEdge()->f Name);
109 111
110 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; 112 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
111 // setup pass through color 113 // setup pass through color
112 if (!ce.colorIgnored()) { 114 if (!ce.colorIgnored()) {
113 this->setupUniformColor(pb, fragBuilder, args.fOutputColor, &fCo lorUniform); 115 this->setupUniformColor(pb, fragBuilder, args.fOutputColor, &fCo lorUniform);
114 } 116 }
115 117
116 // Setup position 118 // Setup position
117 this->setupPosition(pb, vertBuilder, gpArgs, ce.inPosition()->fName) ; 119 this->setupPosition(pb, vertBuilder, gpArgs, ce.inPosition()->fName) ;
118 120
119 // emit transforms 121 // emit transforms
120 this->emitTransforms(args.fPB, 122 this->emitTransforms(args.fPB,
121 vertBuilder, 123 vertBuilder,
124 varyingHandler,
122 gpArgs->fPositionVar, 125 gpArgs->fPositionVar,
123 ce.inPosition()->fName, 126 ce.inPosition()->fName,
124 ce.localMatrix(), 127 ce.localMatrix(),
125 args.fTransformsIn, 128 args.fTransformsIn,
126 args.fTransformsOut); 129 args.fTransformsOut);
127 130
128 fragBuilder->codeAppendf("float d = length(%s.xy);", v.fsIn()); 131 fragBuilder->codeAppendf("float d = length(%s.xy);", v.fsIn());
129 fragBuilder->codeAppendf("float edgeAlpha = clamp(%s.z * (1.0 - d), 0.0, 1.0);", 132 fragBuilder->codeAppendf("float edgeAlpha = clamp(%s.z * (1.0 - d), 0.0, 1.0);",
130 v.fsIn()); 133 v.fsIn());
131 if (ce.isStroked()) { 134 if (ce.isStroked()) {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 249
247 class GLSLProcessor : public GrGLSLGeometryProcessor { 250 class GLSLProcessor : public GrGLSLGeometryProcessor {
248 public: 251 public:
249 GLSLProcessor() 252 GLSLProcessor()
250 : fColor(GrColor_ILLEGAL) {} 253 : fColor(GrColor_ILLEGAL) {}
251 254
252 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ 255 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{
253 const EllipseEdgeEffect& ee = args.fGP.cast<EllipseEdgeEffect>(); 256 const EllipseEdgeEffect& ee = args.fGP.cast<EllipseEdgeEffect>();
254 GrGLSLGPBuilder* pb = args.fPB; 257 GrGLSLGPBuilder* pb = args.fPB;
255 GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; 258 GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder;
259 GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler;
256 260
257 // emit attributes 261 // emit attributes
258 vertBuilder->emitAttributes(ee); 262 varyingHandler->emitAttributes(ee);
259 263
260 GrGLSLVertToFrag ellipseOffsets(kVec2f_GrSLType); 264 GrGLSLVertToFrag ellipseOffsets(kVec2f_GrSLType);
261 args.fPB->addVarying("EllipseOffsets", &ellipseOffsets); 265 varyingHandler->addVarying("EllipseOffsets", &ellipseOffsets);
262 vertBuilder->codeAppendf("%s = %s;", ellipseOffsets.vsOut(), 266 vertBuilder->codeAppendf("%s = %s;", ellipseOffsets.vsOut(),
263 ee.inEllipseOffset()->fName); 267 ee.inEllipseOffset()->fName);
264 268
265 GrGLSLVertToFrag ellipseRadii(kVec4f_GrSLType); 269 GrGLSLVertToFrag ellipseRadii(kVec4f_GrSLType);
266 args.fPB->addVarying("EllipseRadii", &ellipseRadii); 270 varyingHandler->addVarying("EllipseRadii", &ellipseRadii);
267 vertBuilder->codeAppendf("%s = %s;", ellipseRadii.vsOut(), 271 vertBuilder->codeAppendf("%s = %s;", ellipseRadii.vsOut(),
268 ee.inEllipseRadii()->fName); 272 ee.inEllipseRadii()->fName);
269 273
270 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; 274 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
271 // setup pass through color 275 // setup pass through color
272 if (!ee.colorIgnored()) { 276 if (!ee.colorIgnored()) {
273 this->setupUniformColor(pb, fragBuilder, args.fOutputColor, &fCo lorUniform); 277 this->setupUniformColor(pb, fragBuilder, args.fOutputColor, &fCo lorUniform);
274 } 278 }
275 279
276 // Setup position 280 // Setup position
277 this->setupPosition(pb, vertBuilder, gpArgs, ee.inPosition()->fName) ; 281 this->setupPosition(pb, vertBuilder, gpArgs, ee.inPosition()->fName) ;
278 282
279 // emit transforms 283 // emit transforms
280 this->emitTransforms(args.fPB, 284 this->emitTransforms(args.fPB,
281 vertBuilder, 285 vertBuilder,
286 varyingHandler,
282 gpArgs->fPositionVar, 287 gpArgs->fPositionVar,
283 ee.inPosition()->fName, 288 ee.inPosition()->fName,
284 ee.localMatrix(), 289 ee.localMatrix(),
285 args.fTransformsIn, 290 args.fTransformsIn,
286 args.fTransformsOut); 291 args.fTransformsOut);
287 292
288 // for outer curve 293 // for outer curve
289 fragBuilder->codeAppendf("vec2 scaledOffset = %s*%s.xy;", ellipseOff sets.fsIn(), 294 fragBuilder->codeAppendf("vec2 scaledOffset = %s*%s.xy;", ellipseOff sets.fsIn(),
290 ellipseRadii.fsIn()); 295 ellipseRadii.fsIn());
291 fragBuilder->codeAppend("float test = dot(scaledOffset, scaledOffset ) - 1.0;"); 296 fragBuilder->codeAppend("float test = dot(scaledOffset, scaledOffset ) - 1.0;");
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 431
427 class GLSLProcessor : public GrGLSLGeometryProcessor { 432 class GLSLProcessor : public GrGLSLGeometryProcessor {
428 public: 433 public:
429 GLSLProcessor() 434 GLSLProcessor()
430 : fViewMatrix(SkMatrix::InvalidMatrix()), fColor(GrColor_ILLEGAL) {} 435 : fViewMatrix(SkMatrix::InvalidMatrix()), fColor(GrColor_ILLEGAL) {}
431 436
432 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { 437 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
433 const DIEllipseEdgeEffect& ee = args.fGP.cast<DIEllipseEdgeEffect>() ; 438 const DIEllipseEdgeEffect& ee = args.fGP.cast<DIEllipseEdgeEffect>() ;
434 GrGLSLGPBuilder* pb = args.fPB; 439 GrGLSLGPBuilder* pb = args.fPB;
435 GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; 440 GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder;
441 GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler;
436 442
437 // emit attributes 443 // emit attributes
438 vertBuilder->emitAttributes(ee); 444 varyingHandler->emitAttributes(ee);
439 445
440 GrGLSLVertToFrag offsets0(kVec2f_GrSLType); 446 GrGLSLVertToFrag offsets0(kVec2f_GrSLType);
441 args.fPB->addVarying("EllipseOffsets0", &offsets0); 447 varyingHandler->addVarying("EllipseOffsets0", &offsets0);
442 vertBuilder->codeAppendf("%s = %s;", offsets0.vsOut(), 448 vertBuilder->codeAppendf("%s = %s;", offsets0.vsOut(),
443 ee.inEllipseOffsets0()->fName); 449 ee.inEllipseOffsets0()->fName);
444 450
445 GrGLSLVertToFrag offsets1(kVec2f_GrSLType); 451 GrGLSLVertToFrag offsets1(kVec2f_GrSLType);
446 args.fPB->addVarying("EllipseOffsets1", &offsets1); 452 varyingHandler->addVarying("EllipseOffsets1", &offsets1);
447 vertBuilder->codeAppendf("%s = %s;", offsets1.vsOut(), 453 vertBuilder->codeAppendf("%s = %s;", offsets1.vsOut(),
448 ee.inEllipseOffsets1()->fName); 454 ee.inEllipseOffsets1()->fName);
449 455
450 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; 456 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
451 // setup pass through color 457 // setup pass through color
452 if (!ee.colorIgnored()) { 458 if (!ee.colorIgnored()) {
453 this->setupUniformColor(pb, fragBuilder, args.fOutputColor, &fCo lorUniform); 459 this->setupUniformColor(pb, fragBuilder, args.fOutputColor, &fCo lorUniform);
454 } 460 }
455 461
456 // Setup position 462 // Setup position
457 this->setupPosition(pb, 463 this->setupPosition(pb,
458 vertBuilder, 464 vertBuilder,
459 gpArgs, 465 gpArgs,
460 ee.inPosition()->fName, 466 ee.inPosition()->fName,
461 ee.viewMatrix(), 467 ee.viewMatrix(),
462 &fViewMatrixUniform); 468 &fViewMatrixUniform);
463 469
464 // emit transforms 470 // emit transforms
465 this->emitTransforms(args.fPB, 471 this->emitTransforms(args.fPB,
466 vertBuilder, 472 vertBuilder,
473 varyingHandler,
467 gpArgs->fPositionVar, 474 gpArgs->fPositionVar,
468 ee.inPosition()->fName, 475 ee.inPosition()->fName,
469 args.fTransformsIn, 476 args.fTransformsIn,
470 args.fTransformsOut); 477 args.fTransformsOut);
471 478
472 SkAssertResult(fragBuilder->enableFeature( 479 SkAssertResult(fragBuilder->enableFeature(
473 GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeatur e)); 480 GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeatur e));
474 // for outer curve 481 // for outer curve
475 fragBuilder->codeAppendf("vec2 scaledOffset = %s.xy;", offsets0.fsIn ()); 482 fragBuilder->codeAppendf("vec2 scaledOffset = %s.xy;", offsets0.fsIn ());
476 fragBuilder->codeAppend("float test = dot(scaledOffset, scaledOffset ) - 1.0;"); 483 fragBuilder->codeAppend("float test = dot(scaledOffset, scaledOffset ) - 1.0;");
(...skipping 1589 matching lines...) Expand 10 before | Expand all | Expand 10 after
2066 } 2073 }
2067 2074
2068 DRAW_BATCH_TEST_DEFINE(RRectBatch) { 2075 DRAW_BATCH_TEST_DEFINE(RRectBatch) {
2069 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); 2076 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random);
2070 GrColor color = GrRandomColor(random); 2077 GrColor color = GrRandomColor(random);
2071 const SkRRect& rrect = GrTest::TestRRectSimple(random); 2078 const SkRRect& rrect = GrTest::TestRRectSimple(random);
2072 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra ndom)); 2079 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra ndom));
2073 } 2080 }
2074 2081
2075 #endif 2082 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrDefaultGeoProcFactory.cpp ('k') | src/gpu/GrPathProcessor.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698