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

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

Issue 2339203002: Stop flattening GrCoordTransforms in parent GrFragmentProcessors. (Closed)
Patch Set: Fix issue of taking ref to a temporary 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 | « src/gpu/GrFragmentProcessor.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"
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 // Setup position 154 // Setup position
155 this->setupPosition(vertBuilder, gpArgs, cgp.fInPosition->fName); 155 this->setupPosition(vertBuilder, gpArgs, cgp.fInPosition->fName);
156 156
157 // emit transforms 157 // emit transforms
158 this->emitTransforms(vertBuilder, 158 this->emitTransforms(vertBuilder,
159 varyingHandler, 159 varyingHandler,
160 uniformHandler, 160 uniformHandler,
161 gpArgs->fPositionVar, 161 gpArgs->fPositionVar,
162 cgp.fInPosition->fName, 162 cgp.fInPosition->fName,
163 cgp.fLocalMatrix, 163 cgp.fLocalMatrix,
164 args.fTransformsIn, 164 args.fFPCoordTransformHandler);
165 args.fTransformsOut);
166 165
167 fragBuilder->codeAppend("float d = length(circleEdge.xy);"); 166 fragBuilder->codeAppend("float d = length(circleEdge.xy);");
168 fragBuilder->codeAppend("float distanceToOuterEdge = circleEdge.z * (1.0 - d);"); 167 fragBuilder->codeAppend("float distanceToOuterEdge = circleEdge.z * (1.0 - d);");
169 fragBuilder->codeAppend("float edgeAlpha = clamp(distanceToOuterEdge , 0.0, 1.0);"); 168 fragBuilder->codeAppend("float edgeAlpha = clamp(distanceToOuterEdge , 0.0, 1.0);");
170 if (cgp.fStroke) { 169 if (cgp.fStroke) {
171 fragBuilder->codeAppend("float distanceToInnerEdge = circleEdge. z * (d - circleEdge.w);"); 170 fragBuilder->codeAppend("float distanceToInnerEdge = circleEdge. z * (d - circleEdge.w);");
172 fragBuilder->codeAppend("float innerAlpha = clamp(distanceToInne rEdge, 0.0, 1.0);"); 171 fragBuilder->codeAppend("float innerAlpha = clamp(distanceToInne rEdge, 0.0, 1.0);");
173 fragBuilder->codeAppend("edgeAlpha *= innerAlpha;"); 172 fragBuilder->codeAppend("edgeAlpha *= innerAlpha;");
174 } 173 }
175 174
(...skipping 27 matching lines...) Expand all
203 const CircleGeometryProcessor& cgp = gp.cast<CircleGeometryProcessor >(); 202 const CircleGeometryProcessor& cgp = gp.cast<CircleGeometryProcessor >();
204 uint16_t key; 203 uint16_t key;
205 key = cgp.fStroke ? 0x01 : 0x0; 204 key = cgp.fStroke ? 0x01 : 0x0;
206 key |= cgp.fLocalMatrix.hasPerspective() ? 0x02 : 0x0; 205 key |= cgp.fLocalMatrix.hasPerspective() ? 0x02 : 0x0;
207 key |= cgp.fInClipPlane ? 0x04 : 0x0; 206 key |= cgp.fInClipPlane ? 0x04 : 0x0;
208 key |= cgp.fInIsectPlane ? 0x08 : 0x0; 207 key |= cgp.fInIsectPlane ? 0x08 : 0x0;
209 key |= cgp.fInUnionPlane ? 0x10 : 0x0; 208 key |= cgp.fInUnionPlane ? 0x10 : 0x0;
210 b->add32(key); 209 b->add32(key);
211 } 210 }
212 211
213 void setData(const GrGLSLProgramDataManager&, const GrPrimitiveProcessor &) override {} 212 void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitivePro cessor& primProc,
214 213 FPCoordTransformIter&& transformIter) override {
215 void setTransformData(const GrPrimitiveProcessor& primProc,
216 const GrGLSLProgramDataManager& pdman,
217 int index,
218 const SkTArray<const GrCoordTransform*, true>& tra nsforms) override {
219 this->setTransformDataHelper(primProc.cast<CircleGeometryProcessor>( ).fLocalMatrix, 214 this->setTransformDataHelper(primProc.cast<CircleGeometryProcessor>( ).fLocalMatrix,
220 pdman, index, transforms); 215 pdman, &transformIter);
221 } 216 }
222 217
223 private: 218 private:
224 typedef GrGLSLGeometryProcessor INHERITED; 219 typedef GrGLSLGeometryProcessor INHERITED;
225 }; 220 };
226 221
227 SkMatrix fLocalMatrix; 222 SkMatrix fLocalMatrix;
228 const Attribute* fInPosition; 223 const Attribute* fInPosition;
229 const Attribute* fInColor; 224 const Attribute* fInColor;
230 const Attribute* fInCircleEdge; 225 const Attribute* fInCircleEdge;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 // Setup position 307 // Setup position
313 this->setupPosition(vertBuilder, gpArgs, egp.fInPosition->fName); 308 this->setupPosition(vertBuilder, gpArgs, egp.fInPosition->fName);
314 309
315 // emit transforms 310 // emit transforms
316 this->emitTransforms(vertBuilder, 311 this->emitTransforms(vertBuilder,
317 varyingHandler, 312 varyingHandler,
318 uniformHandler, 313 uniformHandler,
319 gpArgs->fPositionVar, 314 gpArgs->fPositionVar,
320 egp.fInPosition->fName, 315 egp.fInPosition->fName,
321 egp.fLocalMatrix, 316 egp.fLocalMatrix,
322 args.fTransformsIn, 317 args.fFPCoordTransformHandler);
323 args.fTransformsOut);
324 318
325 // for outer curve 319 // for outer curve
326 fragBuilder->codeAppendf("vec2 scaledOffset = %s*%s.xy;", ellipseOff sets.fsIn(), 320 fragBuilder->codeAppendf("vec2 scaledOffset = %s*%s.xy;", ellipseOff sets.fsIn(),
327 ellipseRadii.fsIn()); 321 ellipseRadii.fsIn());
328 fragBuilder->codeAppend("float test = dot(scaledOffset, scaledOffset ) - 1.0;"); 322 fragBuilder->codeAppend("float test = dot(scaledOffset, scaledOffset ) - 1.0;");
329 fragBuilder->codeAppendf("vec2 grad = 2.0*scaledOffset*%s.xy;", elli pseRadii.fsIn()); 323 fragBuilder->codeAppendf("vec2 grad = 2.0*scaledOffset*%s.xy;", elli pseRadii.fsIn());
330 fragBuilder->codeAppend("float grad_dot = dot(grad, grad);"); 324 fragBuilder->codeAppend("float grad_dot = dot(grad, grad);");
331 325
332 // avoid calling inversesqrt on zero. 326 // avoid calling inversesqrt on zero.
333 fragBuilder->codeAppend("grad_dot = max(grad_dot, 1.0e-4);"); 327 fragBuilder->codeAppend("grad_dot = max(grad_dot, 1.0e-4);");
(...skipping 16 matching lines...) Expand all
350 344
351 static void GenKey(const GrGeometryProcessor& gp, 345 static void GenKey(const GrGeometryProcessor& gp,
352 const GrGLSLCaps&, 346 const GrGLSLCaps&,
353 GrProcessorKeyBuilder* b) { 347 GrProcessorKeyBuilder* b) {
354 const EllipseGeometryProcessor& egp = gp.cast<EllipseGeometryProcess or>(); 348 const EllipseGeometryProcessor& egp = gp.cast<EllipseGeometryProcess or>();
355 uint16_t key = egp.fStroke ? 0x1 : 0x0; 349 uint16_t key = egp.fStroke ? 0x1 : 0x0;
356 key |= egp.fLocalMatrix.hasPerspective() ? 0x2 : 0x0; 350 key |= egp.fLocalMatrix.hasPerspective() ? 0x2 : 0x0;
357 b->add32(key); 351 b->add32(key);
358 } 352 }
359 353
360 void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitivePro cessor& gp) override { 354 void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitivePro cessor& primProc,
361 } 355 FPCoordTransformIter&& transformIter) override {
362 356 const EllipseGeometryProcessor& egp = primProc.cast<EllipseGeometryP rocessor>();
363 void setTransformData(const GrPrimitiveProcessor& primProc, 357 this->setTransformDataHelper(egp.fLocalMatrix, pdman, &transformIter );
364 const GrGLSLProgramDataManager& pdman,
365 int index,
366 const SkTArray<const GrCoordTransform*, true>& tra nsforms) override {
367 this->setTransformDataHelper(primProc.cast<EllipseGeometryProcessor> ().fLocalMatrix,
368 pdman, index, transforms);
369 } 358 }
370 359
371 private: 360 private:
372 typedef GrGLSLGeometryProcessor INHERITED; 361 typedef GrGLSLGeometryProcessor INHERITED;
373 }; 362 };
374 363
375 const Attribute* fInPosition; 364 const Attribute* fInPosition;
376 const Attribute* fInColor; 365 const Attribute* fInColor;
377 const Attribute* fInEllipseOffset; 366 const Attribute* fInEllipseOffset;
378 const Attribute* fInEllipseRadii; 367 const Attribute* fInEllipseRadii;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 diegp.fInPosition->fName, 454 diegp.fInPosition->fName,
466 diegp.fViewMatrix, 455 diegp.fViewMatrix,
467 &fViewMatrixUniform); 456 &fViewMatrixUniform);
468 457
469 // emit transforms 458 // emit transforms
470 this->emitTransforms(vertBuilder, 459 this->emitTransforms(vertBuilder,
471 varyingHandler, 460 varyingHandler,
472 uniformHandler, 461 uniformHandler,
473 gpArgs->fPositionVar, 462 gpArgs->fPositionVar,
474 diegp.fInPosition->fName, 463 diegp.fInPosition->fName,
475 args.fTransformsIn, 464 args.fFPCoordTransformHandler);
476 args.fTransformsOut);
477 465
478 SkAssertResult(fragBuilder->enableFeature( 466 SkAssertResult(fragBuilder->enableFeature(
479 GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeatur e)); 467 GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeatur e));
480 // for outer curve 468 // for outer curve
481 fragBuilder->codeAppendf("vec2 scaledOffset = %s.xy;", offsets0.fsIn ()); 469 fragBuilder->codeAppendf("vec2 scaledOffset = %s.xy;", offsets0.fsIn ());
482 fragBuilder->codeAppend("float test = dot(scaledOffset, scaledOffset ) - 1.0;"); 470 fragBuilder->codeAppend("float test = dot(scaledOffset, scaledOffset ) - 1.0;");
483 fragBuilder->codeAppendf("vec2 duvdx = dFdx(%s);", offsets0.fsIn()); 471 fragBuilder->codeAppendf("vec2 duvdx = dFdx(%s);", offsets0.fsIn());
484 fragBuilder->codeAppendf("vec2 duvdy = dFdy(%s);", offsets0.fsIn()); 472 fragBuilder->codeAppendf("vec2 duvdy = dFdy(%s);", offsets0.fsIn());
485 fragBuilder->codeAppendf("vec2 grad = vec2(2.0*%s.x*duvdx.x + 2.0*%s .y*duvdx.y," 473 fragBuilder->codeAppendf("vec2 grad = vec2(2.0*%s.x*duvdx.x + 2.0*%s .y*duvdx.y,"
486 " 2.0*%s.x*duvdy.x + 2.0*%s .y*duvdy.y);", 474 " 2.0*%s.x*duvdy.x + 2.0*%s .y*duvdy.y);",
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 506
519 static void GenKey(const GrGeometryProcessor& gp, 507 static void GenKey(const GrGeometryProcessor& gp,
520 const GrGLSLCaps&, 508 const GrGLSLCaps&,
521 GrProcessorKeyBuilder* b) { 509 GrProcessorKeyBuilder* b) {
522 const DIEllipseGeometryProcessor& diegp = gp.cast<DIEllipseGeometryP rocessor>(); 510 const DIEllipseGeometryProcessor& diegp = gp.cast<DIEllipseGeometryP rocessor>();
523 uint16_t key = static_cast<uint16_t>(diegp.fStyle); 511 uint16_t key = static_cast<uint16_t>(diegp.fStyle);
524 key |= ComputePosKey(diegp.fViewMatrix) << 10; 512 key |= ComputePosKey(diegp.fViewMatrix) << 10;
525 b->add32(key); 513 b->add32(key);
526 } 514 }
527 515
528 void setData(const GrGLSLProgramDataManager& pdman, 516 void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitivePro cessor& gp,
529 const GrPrimitiveProcessor& gp) override { 517 FPCoordTransformIter&& transformIter) override {
530 const DIEllipseGeometryProcessor& diegp = gp.cast<DIEllipseGeometryP rocessor>(); 518 const DIEllipseGeometryProcessor& diegp = gp.cast<DIEllipseGeometryP rocessor>();
531 519
532 if (!diegp.fViewMatrix.isIdentity() && !fViewMatrix.cheapEqualTo(die gp.fViewMatrix)) { 520 if (!diegp.fViewMatrix.isIdentity() && !fViewMatrix.cheapEqualTo(die gp.fViewMatrix)) {
533 fViewMatrix = diegp.fViewMatrix; 521 fViewMatrix = diegp.fViewMatrix;
534 float viewMatrix[3 * 3]; 522 float viewMatrix[3 * 3];
535 GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); 523 GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix);
536 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); 524 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix);
537 } 525 }
526 this->setTransformDataHelper(SkMatrix::I(), pdman, &transformIter);
538 } 527 }
539 528
540 private: 529 private:
541 SkMatrix fViewMatrix; 530 SkMatrix fViewMatrix;
542 UniformHandle fViewMatrixUniform; 531 UniformHandle fViewMatrixUniform;
543 532
544 typedef GrGLSLGeometryProcessor INHERITED; 533 typedef GrGLSLGeometryProcessor INHERITED;
545 }; 534 };
546 535
547 const Attribute* fInPosition; 536 const Attribute* fInPosition;
(...skipping 1625 matching lines...) Expand 10 before | Expand all | Expand 10 after
2173 } 2162 }
2174 2163
2175 DRAW_BATCH_TEST_DEFINE(RRectBatch) { 2164 DRAW_BATCH_TEST_DEFINE(RRectBatch) {
2176 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); 2165 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random);
2177 GrColor color = GrRandomColor(random); 2166 GrColor color = GrRandomColor(random);
2178 const SkRRect& rrect = GrTest::TestRRectSimple(random); 2167 const SkRRect& rrect = GrTest::TestRRectSimple(random);
2179 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra ndom)); 2168 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra ndom));
2180 } 2169 }
2181 2170
2182 #endif 2171 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrFragmentProcessor.cpp ('k') | src/gpu/GrPathProcessor.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698