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

Side by Side Diff: gm/beziereffects.cpp

Issue 1122673002: Start on simplifying generateGeometry() overrides (Closed) Base URL: https://skia.googlesource.com/skia.git@ibcache
Patch Set: whitespace, remove debug return Created 5 years, 7 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') | 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 /* 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
11 #include "gm.h" 11 #include "gm.h"
12 12
13 #if SK_SUPPORT_GPU 13 #if SK_SUPPORT_GPU
14 14
15 #include "GrBatchTarget.h" 15 #include "GrBatchTarget.h"
16 #include "GrBufferAllocPool.h" 16 #include "GrBufferAllocPool.h"
17 #include "GrContext.h" 17 #include "GrContext.h"
18 #include "GrPathUtils.h" 18 #include "GrPathUtils.h"
19 #include "GrResourceProvider.h"
20 #include "GrTest.h" 19 #include "GrTest.h"
21 #include "GrTestBatch.h" 20 #include "GrTestBatch.h"
22 #include "SkColorPriv.h" 21 #include "SkColorPriv.h"
23 #include "SkDevice.h" 22 #include "SkDevice.h"
24 #include "SkGeometry.h" 23 #include "SkGeometry.h"
25 24
26 #include "effects/GrBezierEffect.h" 25 #include "effects/GrBezierEffect.h"
27 26
28 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) {
29 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]);
(...skipping 30 matching lines...) Expand all
60 SkPoint fPosition; 59 SkPoint fPosition;
61 float fKLM[4]; // The last value is ignored. The effect expects a vec4 f. 60 float fKLM[4]; // The last value is ignored. The effect expects a vec4 f.
62 }; 61 };
63 62
64 Geometry* geoData(int index) override { 63 Geometry* geoData(int index) override {
65 SkASSERT(0 == index); 64 SkASSERT(0 == index);
66 return &fGeometry; 65 return &fGeometry;
67 } 66 }
68 67
69 void onGenerateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeli ne) override { 68 void onGenerateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeli ne) override {
70 SkAutoTUnref<const GrIndexBuffer> indexBuffer( 69 QuadHelper helper;
71 batchTarget->resourceProvider()->refQuadIndexBuffer());
72
73 size_t vertexStride = this->geometryProcessor()->getVertexStride(); 70 size_t vertexStride = this->geometryProcessor()->getVertexStride();
74 const GrVertexBuffer* vertexBuffer; 71 SkASSERT(vertexStride == sizeof(Vertex));
75 int firstVertex; 72 Vertex* verts = reinterpret_cast<Vertex*>(helper.init(batchTarget, verte xStride, 1));
76 void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride, 73 if (!verts) {
77 kVertsPerCubic,
78 &vertexBuffer,
79 &firstVertex);
80
81 if (!vertices || !indexBuffer) {
82 SkDebugf("Could not allocate buffers\n");
83 return; 74 return;
84 } 75 }
85 76
86 SkASSERT(vertexStride == sizeof(Vertex));
87 Vertex* verts = reinterpret_cast<Vertex*>(vertices);
88
89 verts[0].fPosition.setRectFan(fGeometry.fBounds.fLeft, fGeometry.fBounds .fTop, 77 verts[0].fPosition.setRectFan(fGeometry.fBounds.fLeft, fGeometry.fBounds .fTop,
90 fGeometry.fBounds.fRight, fGeometry.fBound s.fBottom, 78 fGeometry.fBounds.fRight, fGeometry.fBound s.fBottom,
91 sizeof(Vertex)); 79 sizeof(Vertex));
92 for (int v = 0; v < 4; ++v) { 80 for (int v = 0; v < 4; ++v) {
93 verts[v].fKLM[0] = eval_line(verts[v].fPosition, fKlmEqs + 0, fSign) ; 81 verts[v].fKLM[0] = eval_line(verts[v].fPosition, fKlmEqs + 0, fSign) ;
94 verts[v].fKLM[1] = eval_line(verts[v].fPosition, fKlmEqs + 3, fSign) ; 82 verts[v].fKLM[1] = eval_line(verts[v].fPosition, fKlmEqs + 3, fSign) ;
95 verts[v].fKLM[2] = eval_line(verts[v].fPosition, fKlmEqs + 6, 1.f); 83 verts[v].fKLM[2] = eval_line(verts[v].fPosition, fKlmEqs + 6, 1.f);
96 } 84 }
97 85 helper.issueDraws(batchTarget);
98 GrDrawTarget::DrawInfo drawInfo;
99 drawInfo.setPrimitiveType(kTriangleFan_GrPrimitiveType);
100 drawInfo.setVertexBuffer(vertexBuffer);
101 drawInfo.setStartVertex(firstVertex);
102 drawInfo.setVertexCount(kVertsPerCubic);
103 drawInfo.setStartIndex(0);
104 drawInfo.setIndexCount(kIndicesPerCubic);
105 drawInfo.setIndexBuffer(indexBuffer);
106 batchTarget->draw(drawInfo);
107 } 86 }
108 87
109 Geometry fGeometry; 88 Geometry fGeometry;
110 SkScalar fKlmEqs[9]; 89 SkScalar fKlmEqs[9];
111 SkScalar fSign; 90 SkScalar fSign;
112 91
113 static const int kVertsPerCubic = 4; 92 static const int kVertsPerCubic = 4;
114 static const int kIndicesPerCubic = 6; 93 static const int kIndicesPerCubic = 6;
115 94
116 typedef GrTestBatch INHERITED; 95 typedef GrTestBatch INHERITED;
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 SkPoint fPosition; 447 SkPoint fPosition;
469 float fKLM[4]; // The last value is ignored. The effect expects a vec4 f. 448 float fKLM[4]; // The last value is ignored. The effect expects a vec4 f.
470 }; 449 };
471 450
472 Geometry* geoData(int index) override { 451 Geometry* geoData(int index) override {
473 SkASSERT(0 == index); 452 SkASSERT(0 == index);
474 return &fGeometry; 453 return &fGeometry;
475 } 454 }
476 455
477 void onGenerateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeli ne) override { 456 void onGenerateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeli ne) override {
478 SkAutoTUnref<const GrIndexBuffer> indexBuffer( 457 QuadHelper helper;
479 batchTarget->resourceProvider()->refQuadIndexBuffer());
480
481 size_t vertexStride = this->geometryProcessor()->getVertexStride(); 458 size_t vertexStride = this->geometryProcessor()->getVertexStride();
482 const GrVertexBuffer* vertexBuffer; 459 SkASSERT(vertexStride == sizeof(Vertex));
483 int firstVertex; 460 GrDrawTarget::DrawInfo drawInfo;
484 461 Vertex* verts = reinterpret_cast<Vertex*>(helper.init(batchTarget, verte xStride, 1));
485 void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride, 462 if (!verts) {
486 kVertsPerCubic,
487 &vertexBuffer,
488 &firstVertex);
489
490 if (!vertices || !indexBuffer) {
491 SkDebugf("Could not allocate buffers\n");
492 return; 463 return;
493 } 464 }
494
495 SkASSERT(vertexStride == sizeof(Vertex));
496 Vertex* verts = reinterpret_cast<Vertex*>(vertices);
497
498 verts[0].fPosition.setRectFan(fGeometry.fBounds.fLeft, fGeometry.fBounds .fTop, 465 verts[0].fPosition.setRectFan(fGeometry.fBounds.fLeft, fGeometry.fBounds .fTop,
499 fGeometry.fBounds.fRight, fGeometry.fBound s.fBottom, 466 fGeometry.fBounds.fRight, fGeometry.fBound s.fBottom,
500 sizeof(Vertex)); 467 sizeof(Vertex));
501
502 fDevToUV.apply<4, sizeof(Vertex), sizeof(SkPoint)>(verts); 468 fDevToUV.apply<4, sizeof(Vertex), sizeof(SkPoint)>(verts);
503 469 helper.issueDraws(batchTarget);
504
505 GrDrawTarget::DrawInfo drawInfo;
506 drawInfo.setPrimitiveType(kTriangles_GrPrimitiveType);
507 drawInfo.setVertexBuffer(vertexBuffer);
508 drawInfo.setStartVertex(firstVertex);
509 drawInfo.setVertexCount(kVertsPerCubic);
510 drawInfo.setStartIndex(0);
511 drawInfo.setIndexCount(kIndicesPerCubic);
512 drawInfo.setIndexBuffer(indexBuffer);
513 batchTarget->draw(drawInfo);
514 } 470 }
515 471
516 Geometry fGeometry; 472 Geometry fGeometry;
517 GrPathUtils::QuadUVMatrix fDevToUV; 473 GrPathUtils::QuadUVMatrix fDevToUV;
518 474
519 static const int kVertsPerCubic = 4; 475 static const int kVertsPerCubic = 4;
520 static const int kIndicesPerCubic = 6; 476 static const int kIndicesPerCubic = 6;
521 477
522 typedef GrTestBatch INHERITED; 478 typedef GrTestBatch INHERITED;
523 }; 479 };
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 typedef GM INHERITED; 616 typedef GM INHERITED;
661 }; 617 };
662 618
663 DEF_GM( return SkNEW(BezierCubicEffects); ) 619 DEF_GM( return SkNEW(BezierCubicEffects); )
664 DEF_GM( return SkNEW(BezierConicEffects); ) 620 DEF_GM( return SkNEW(BezierConicEffects); )
665 DEF_GM( return SkNEW(BezierQuadEffects); ) 621 DEF_GM( return SkNEW(BezierQuadEffects); )
666 622
667 } 623 }
668 624
669 #endif 625 #endif
OLDNEW
« no previous file with comments | « no previous file | gm/convexpolyeffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698