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

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

Powered by Google App Engine
This is Rietveld 408576698