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

Side by Side Diff: gm/beziereffects.cpp

Issue 1835283002: Simplify GrDrawBatch uploads and token uage. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add comments Created 4 years, 8 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 | gm/convexpolyeffect.cpp » ('j') | src/gpu/batches/GrDrawBatch.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2013 Google Inc. 3 * Copyright 2013 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 // This test only works with the GPU backend. 9 // This test only works with the GPU backend.
10 10
(...skipping 15 matching lines...) Expand all
26 26
27 static inline SkScalar eval_line(const SkPoint& p, const SkScalar lineEq[3], SkS calar sign) { 27 static inline SkScalar eval_line(const SkPoint& p, const SkScalar lineEq[3], SkS calar sign) {
28 return sign * (lineEq[0] * p.fX + lineEq[1] * p.fY + lineEq[2]); 28 return sign * (lineEq[0] * p.fX + lineEq[1] * p.fY + lineEq[2]);
29 } 29 }
30 30
31 namespace skiagm { 31 namespace skiagm {
32 32
33 class BezierCubicOrConicTestBatch : public GrTestBatch { 33 class BezierCubicOrConicTestBatch : public GrTestBatch {
34 public: 34 public:
35 DEFINE_BATCH_CLASS_ID 35 DEFINE_BATCH_CLASS_ID
36 struct Geometry : public GrTestBatch::Geometry {
37 SkRect fBounds;
38 };
39 36
40 const char* name() const override { return "BezierCubicOrConicTestBatch"; } 37 const char* name() const override { return "BezierCubicOrConicTestBatch"; }
41 38
42 static GrDrawBatch* Create(const GrGeometryProcessor* gp, const Geometry& ge o, 39 BezierCubicOrConicTestBatch(const GrGeometryProcessor* gp, const SkRect& bou nds,
43 const SkScalar klmEqs[9], SkScalar sign) { 40 GrColor color, const SkScalar klmEqs[9], SkScala r sign)
44 return new BezierCubicOrConicTestBatch(gp, geo, klmEqs, sign); 41 : INHERITED(ClassID(), bounds, color)
42 , fGeometryProcessor(SkRef(gp)) {
43 for (int i = 0; i < 9; i++) {
44 fKlmEqs[i] = klmEqs[i];
45 }
46 fSign = sign;
45 } 47 }
46 48
47 private: 49 private:
48 BezierCubicOrConicTestBatch(const GrGeometryProcessor* gp, const Geometry& g eo,
49 const SkScalar klmEqs[9], SkScalar sign)
50 : INHERITED(ClassID(), gp, geo.fBounds) {
51 for (int i = 0; i < 9; i++) {
52 fKlmEqs[i] = klmEqs[i];
53 }
54
55 fGeometry = geo;
56 fSign = sign;
57 }
58 50
59 struct Vertex { 51 struct Vertex {
60 SkPoint fPosition; 52 SkPoint fPosition;
61 float fKLM[4]; // The last value is ignored. The effect expects a vec4 f. 53 float fKLM[4]; // The last value is ignored. The effect expects a vec4 f.
62 }; 54 };
63 55
64 Geometry* geoData(int index) override { 56 void onPrepareDraws(Target* target) const override {
65 SkASSERT(0 == index);
66 return &fGeometry;
67 }
68
69 const Geometry* geoData(int index) const override {
70 SkASSERT(0 == index);
71 return &fGeometry;
72 }
73
74 void generateGeometry(Target* target) const override {
75 QuadHelper helper; 57 QuadHelper helper;
76 size_t vertexStride = this->geometryProcessor()->getVertexStride(); 58 size_t vertexStride = fGeometryProcessor->getVertexStride();
77 SkASSERT(vertexStride == sizeof(Vertex)); 59 SkASSERT(vertexStride == sizeof(Vertex));
78 Vertex* verts = reinterpret_cast<Vertex*>(helper.init(target, vertexStri de, 1)); 60 Vertex* verts = reinterpret_cast<Vertex*>(helper.init(target, vertexStri de, 1));
79 if (!verts) { 61 if (!verts) {
80 return; 62 return;
81 } 63 }
82 64 const SkRect& bounds = this->bounds();
83 verts[0].fPosition.setRectFan(fGeometry.fBounds.fLeft, fGeometry.fBounds .fTop, 65 verts[0].fPosition.setRectFan(bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom,
84 fGeometry.fBounds.fRight, fGeometry.fBound s.fBottom,
85 sizeof(Vertex)); 66 sizeof(Vertex));
86 for (int v = 0; v < 4; ++v) { 67 for (int v = 0; v < 4; ++v) {
87 verts[v].fKLM[0] = eval_line(verts[v].fPosition, fKlmEqs + 0, fSign) ; 68 verts[v].fKLM[0] = eval_line(verts[v].fPosition, fKlmEqs + 0, fSign) ;
88 verts[v].fKLM[1] = eval_line(verts[v].fPosition, fKlmEqs + 3, fSign) ; 69 verts[v].fKLM[1] = eval_line(verts[v].fPosition, fKlmEqs + 3, fSign) ;
89 verts[v].fKLM[2] = eval_line(verts[v].fPosition, fKlmEqs + 6, 1.f); 70 verts[v].fKLM[2] = eval_line(verts[v].fPosition, fKlmEqs + 6, 1.f);
90 } 71 }
91 helper.recordDraw(target); 72 helper.recordDraw(target, fGeometryProcessor);
92 } 73 }
93 74
94 Geometry fGeometry; 75 SkScalar fKlmEqs[9];
95 SkScalar fKlmEqs[9]; 76 SkScalar fSign;
96 SkScalar fSign; 77 SkAutoTUnref<const GrGeometryProcessor> fGeometryProcessor;
97 78
98 static const int kVertsPerCubic = 4; 79 static const int kVertsPerCubic = 4;
99 static const int kIndicesPerCubic = 6; 80 static const int kIndicesPerCubic = 6;
100 81
101 typedef GrTestBatch INHERITED; 82 typedef GrTestBatch INHERITED;
102 }; 83 };
103 84
104 /** 85 /**
105 * This GM directly exercises effects that draw Bezier curves in the GPU backend . 86 * This GM directly exercises effects that draw Bezier curves in the GPU backend .
106 */ 87 */
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 boundsPaint.setColor(0xff808080); 193 boundsPaint.setColor(0xff808080);
213 boundsPaint.setStrokeWidth(0); 194 boundsPaint.setStrokeWidth(0);
214 boundsPaint.setStyle(SkPaint::kStroke_Style); 195 boundsPaint.setStyle(SkPaint::kStroke_Style);
215 canvas->drawRect(bounds, boundsPaint); 196 canvas->drawRect(bounds, boundsPaint);
216 197
217 GrPipelineBuilder pipelineBuilder; 198 GrPipelineBuilder pipelineBuilder;
218 pipelineBuilder.setXPFactory( 199 pipelineBuilder.setXPFactory(
219 GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->u nref(); 200 GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->u nref();
220 pipelineBuilder.setRenderTarget(rt); 201 pipelineBuilder.setRenderTarget(rt);
221 202
222 BezierCubicOrConicTestBatch::Geometry geometry;
223 geometry.fColor = color;
224 geometry.fBounds = bounds;
225
226 SkAutoTUnref<GrDrawBatch> batch( 203 SkAutoTUnref<GrDrawBatch> batch(
227 BezierCubicOrConicTestBatch::Create(gp, geometry, kl mEqs, klmSigns[c])); 204 new BezierCubicOrConicTestBatch(gp, bounds, color, klmEq s, klmSigns[c]));
228 205
229 drawContext->drawContextPriv().testingOnly_drawBatch(pipelin eBuilder, batch); 206 drawContext->drawContextPriv().testingOnly_drawBatch(pipelin eBuilder, batch);
230 } 207 }
231 ++col; 208 ++col;
232 if (numCols == col) { 209 if (numCols == col) {
233 col = 0; 210 col = 0;
234 ++row; 211 ++row;
235 } 212 }
236 } 213 }
237 } 214 }
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 boundsPaint.setColor(0xff808080); 330 boundsPaint.setColor(0xff808080);
354 boundsPaint.setStrokeWidth(0); 331 boundsPaint.setStrokeWidth(0);
355 boundsPaint.setStyle(SkPaint::kStroke_Style); 332 boundsPaint.setStyle(SkPaint::kStroke_Style);
356 canvas->drawRect(bounds, boundsPaint); 333 canvas->drawRect(bounds, boundsPaint);
357 334
358 GrPipelineBuilder pipelineBuilder; 335 GrPipelineBuilder pipelineBuilder;
359 pipelineBuilder.setXPFactory( 336 pipelineBuilder.setXPFactory(
360 GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->u nref(); 337 GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->u nref();
361 pipelineBuilder.setRenderTarget(rt); 338 pipelineBuilder.setRenderTarget(rt);
362 339
363 BezierCubicOrConicTestBatch::Geometry geometry;
364 geometry.fColor = color;
365 geometry.fBounds = bounds;
366
367 SkAutoTUnref<GrDrawBatch> batch( 340 SkAutoTUnref<GrDrawBatch> batch(
368 BezierCubicOrConicTestBatch::Create(gp, geometry, kl mEqs, 1.f)); 341 new BezierCubicOrConicTestBatch(gp, bounds, color, klmEq s, 1.f));
369 342
370 drawContext->drawContextPriv().testingOnly_drawBatch(pipelin eBuilder, batch); 343 drawContext->drawContextPriv().testingOnly_drawBatch(pipelin eBuilder, batch);
371 } 344 }
372 ++col; 345 ++col;
373 if (numCols == col) { 346 if (numCols == col) {
374 col = 0; 347 col = 0;
375 ++row; 348 ++row;
376 } 349 }
377 } 350 }
378 } 351 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 } 390 }
418 391
419 typedef GM INHERITED; 392 typedef GM INHERITED;
420 }; 393 };
421 394
422 ////////////////////////////////////////////////////////////////////////////// 395 //////////////////////////////////////////////////////////////////////////////
423 396
424 class BezierQuadTestBatch : public GrTestBatch { 397 class BezierQuadTestBatch : public GrTestBatch {
425 public: 398 public:
426 DEFINE_BATCH_CLASS_ID 399 DEFINE_BATCH_CLASS_ID
427 struct Geometry : public GrTestBatch::Geometry {
428 SkRect fBounds;
429 };
430
431 const char* name() const override { return "BezierQuadTestBatch"; } 400 const char* name() const override { return "BezierQuadTestBatch"; }
432 401
433 static GrDrawBatch* Create(const GrGeometryProcessor* gp, const Geometry& ge o, 402 BezierQuadTestBatch(const GrGeometryProcessor* gp, const SkRect& bounds, GrC olor color,
434 const GrPathUtils::QuadUVMatrix& devToUV) { 403 const GrPathUtils::QuadUVMatrix& devToUV)
435 return new BezierQuadTestBatch(gp, geo, devToUV); 404 : INHERITED(ClassID(), bounds, color)
405 , fDevToUV(devToUV)
406 , fGeometryProcessor(SkRef(gp)) {
436 } 407 }
437 408
438 private: 409 private:
439 BezierQuadTestBatch(const GrGeometryProcessor* gp, const Geometry& geo,
440 const GrPathUtils::QuadUVMatrix& devToUV)
441 : INHERITED(ClassID(), gp, geo.fBounds)
442 , fGeometry(geo)
443 , fDevToUV(devToUV) {
444 }
445 410
446 struct Vertex { 411 struct Vertex {
447 SkPoint fPosition; 412 SkPoint fPosition;
448 float fKLM[4]; // The last value is ignored. The effect expects a vec4 f. 413 float fKLM[4]; // The last value is ignored. The effect expects a vec4 f.
449 }; 414 };
450 415
451 Geometry* geoData(int index) override { 416 void onPrepareDraws(Target* target) const override {
452 SkASSERT(0 == index);
453 return &fGeometry;
454 }
455
456 const Geometry* geoData(int index) const override {
457 SkASSERT(0 == index);
458 return &fGeometry;
459 }
460
461 void generateGeometry(Target* target) const override {
462 QuadHelper helper; 417 QuadHelper helper;
463 size_t vertexStride = this->geometryProcessor()->getVertexStride(); 418 size_t vertexStride = fGeometryProcessor->getVertexStride();
464 SkASSERT(vertexStride == sizeof(Vertex)); 419 SkASSERT(vertexStride == sizeof(Vertex));
465 Vertex* verts = reinterpret_cast<Vertex*>(helper.init(target, vertexStri de, 1)); 420 Vertex* verts = reinterpret_cast<Vertex*>(helper.init(target, vertexStri de, 1));
466 if (!verts) { 421 if (!verts) {
467 return; 422 return;
468 } 423 }
469 verts[0].fPosition.setRectFan(fGeometry.fBounds.fLeft, fGeometry.fBounds .fTop, 424 const SkRect& bounds = this->bounds();
470 fGeometry.fBounds.fRight, fGeometry.fBound s.fBottom, 425 verts[0].fPosition.setRectFan(bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom,
471 sizeof(Vertex)); 426 sizeof(Vertex));
472 fDevToUV.apply<4, sizeof(Vertex), sizeof(SkPoint)>(verts); 427 fDevToUV.apply<4, sizeof(Vertex), sizeof(SkPoint)>(verts);
473 helper.recordDraw(target); 428 helper.recordDraw(target, fGeometryProcessor);
474 } 429 }
475 430
476 Geometry fGeometry; 431 GrPathUtils::QuadUVMatrix fDevToUV;
477 GrPathUtils::QuadUVMatrix fDevToUV; 432 SkAutoTUnref<const GrGeometryProcessor> fGeometryProcessor;
478 433
479 static const int kVertsPerCubic = 4; 434 static const int kVertsPerCubic = 4;
480 static const int kIndicesPerCubic = 6; 435 static const int kIndicesPerCubic = 6;
481 436
482 typedef GrTestBatch INHERITED; 437 typedef GrTestBatch INHERITED;
483 }; 438 };
484 439
485 /** 440 /**
486 * This GM directly exercises effects that draw Bezier quad curves in the GPU ba ckend. 441 * This GM directly exercises effects that draw Bezier quad curves in the GPU ba ckend.
487 */ 442 */
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 boundsPaint.setStyle(SkPaint::kStroke_Style); 544 boundsPaint.setStyle(SkPaint::kStroke_Style);
590 canvas->drawRect(bounds, boundsPaint); 545 canvas->drawRect(bounds, boundsPaint);
591 546
592 GrPipelineBuilder pipelineBuilder; 547 GrPipelineBuilder pipelineBuilder;
593 pipelineBuilder.setXPFactory( 548 pipelineBuilder.setXPFactory(
594 GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->u nref(); 549 GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->u nref();
595 pipelineBuilder.setRenderTarget(rt); 550 pipelineBuilder.setRenderTarget(rt);
596 551
597 GrPathUtils::QuadUVMatrix DevToUV(pts); 552 GrPathUtils::QuadUVMatrix DevToUV(pts);
598 553
599 BezierQuadTestBatch::Geometry geometry; 554 SkAutoTUnref<GrDrawBatch> batch(
600 geometry.fColor = color; 555 new BezierQuadTestBatch(gp, bounds, color, DevToUV));
601 geometry.fBounds = bounds;
602
603 SkAutoTUnref<GrDrawBatch> batch(BezierQuadTestBatch::Create( gp, geometry,
604 DevToUV));
605 556
606 drawContext->drawContextPriv().testingOnly_drawBatch(pipelin eBuilder, batch); 557 drawContext->drawContextPriv().testingOnly_drawBatch(pipelin eBuilder, batch);
607 } 558 }
608 ++col; 559 ++col;
609 if (numCols == col) { 560 if (numCols == col) {
610 col = 0; 561 col = 0;
611 ++row; 562 ++row;
612 } 563 }
613 } 564 }
614 } 565 }
615 } 566 }
616 567
617 private: 568 private:
618 typedef GM INHERITED; 569 typedef GM INHERITED;
619 }; 570 };
620 571
621 DEF_GM(return new BezierCubicEffects;) 572 DEF_GM(return new BezierCubicEffects;)
622 DEF_GM(return new BezierConicEffects;) 573 DEF_GM(return new BezierConicEffects;)
623 DEF_GM(return new BezierQuadEffects;) 574 DEF_GM(return new BezierQuadEffects;)
624 } 575 }
625 576
626 #endif 577 #endif
OLDNEW
« no previous file with comments | « no previous file | gm/convexpolyeffect.cpp » ('j') | src/gpu/batches/GrDrawBatch.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698