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

Side by Side Diff: gm/beziereffects.cpp

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