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

Side by Side Diff: gm/beziereffects.cpp

Issue 1126613003: Revert of Move instanced index buffer creation to flush time (Closed) Base URL: https://skia.googlesource.com/skia.git@master
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"
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 size_t vertexStride = this->geometryProcessor()->getVertexStride();
71 batchTarget->resourceProvider()->refQuadIndexBuffer());
72 70
73 size_t vertexStride = this->geometryProcessor()->getVertexStride();
74 const GrVertexBuffer* vertexBuffer; 71 const GrVertexBuffer* vertexBuffer;
75 int firstVertex; 72 int firstVertex;
73
76 void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride, 74 void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride,
77 kVertsPerCubic, 75 kVertsPerCubic,
78 &vertexBuffer, 76 &vertexBuffer,
79 &firstVertex); 77 &firstVertex);
80 78
81 if (!vertices || !indexBuffer) { 79 if (!vertices || !batchTarget->quadIndexBuffer()) {
82 SkDebugf("Could not allocate buffers\n"); 80 SkDebugf("Could not allocate buffers\n");
83 return; 81 return;
84 } 82 }
85 83
86 SkASSERT(vertexStride == sizeof(Vertex)); 84 SkASSERT(vertexStride == sizeof(Vertex));
87 Vertex* verts = reinterpret_cast<Vertex*>(vertices); 85 Vertex* verts = reinterpret_cast<Vertex*>(vertices);
88 86
89 verts[0].fPosition.setRectFan(fGeometry.fBounds.fLeft, fGeometry.fBounds .fTop, 87 verts[0].fPosition.setRectFan(fGeometry.fBounds.fLeft, fGeometry.fBounds .fTop,
90 fGeometry.fBounds.fRight, fGeometry.fBound s.fBottom, 88 fGeometry.fBounds.fRight, fGeometry.fBound s.fBottom,
91 sizeof(Vertex)); 89 sizeof(Vertex));
92 for (int v = 0; v < 4; ++v) { 90 for (int v = 0; v < 4; ++v) {
93 verts[v].fKLM[0] = eval_line(verts[v].fPosition, fKlmEqs + 0, fSign) ; 91 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) ; 92 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); 93 verts[v].fKLM[2] = eval_line(verts[v].fPosition, fKlmEqs + 6, 1.f);
96 } 94 }
97 95
98 GrDrawTarget::DrawInfo drawInfo; 96 GrDrawTarget::DrawInfo drawInfo;
99 drawInfo.setPrimitiveType(kTriangleFan_GrPrimitiveType); 97 drawInfo.setPrimitiveType(kTriangleFan_GrPrimitiveType);
100 drawInfo.setVertexBuffer(vertexBuffer); 98 drawInfo.setVertexBuffer(vertexBuffer);
101 drawInfo.setStartVertex(firstVertex); 99 drawInfo.setStartVertex(firstVertex);
102 drawInfo.setVertexCount(kVertsPerCubic); 100 drawInfo.setVertexCount(kVertsPerCubic);
103 drawInfo.setStartIndex(0); 101 drawInfo.setStartIndex(0);
104 drawInfo.setIndexCount(kIndicesPerCubic); 102 drawInfo.setIndexCount(kIndicesPerCubic);
105 drawInfo.setIndexBuffer(indexBuffer); 103 drawInfo.setIndexBuffer(batchTarget->quadIndexBuffer());
106 batchTarget->draw(drawInfo); 104 batchTarget->draw(drawInfo);
107 } 105 }
108 106
109 Geometry fGeometry; 107 Geometry fGeometry;
110 SkScalar fKlmEqs[9]; 108 SkScalar fKlmEqs[9];
111 SkScalar fSign; 109 SkScalar fSign;
112 110
113 static const int kVertsPerCubic = 4; 111 static const int kVertsPerCubic = 4;
114 static const int kIndicesPerCubic = 6; 112 static const int kIndicesPerCubic = 6;
115 113
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 SkPoint fPosition; 466 SkPoint fPosition;
469 float fKLM[4]; // The last value is ignored. The effect expects a vec4 f. 467 float fKLM[4]; // The last value is ignored. The effect expects a vec4 f.
470 }; 468 };
471 469
472 Geometry* geoData(int index) override { 470 Geometry* geoData(int index) override {
473 SkASSERT(0 == index); 471 SkASSERT(0 == index);
474 return &fGeometry; 472 return &fGeometry;
475 } 473 }
476 474
477 void onGenerateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeli ne) override { 475 void onGenerateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeli ne) override {
478 SkAutoTUnref<const GrIndexBuffer> indexBuffer( 476 size_t vertexStride = this->geometryProcessor()->getVertexStride();
479 batchTarget->resourceProvider()->refQuadIndexBuffer());
480 477
481 size_t vertexStride = this->geometryProcessor()->getVertexStride();
482 const GrVertexBuffer* vertexBuffer; 478 const GrVertexBuffer* vertexBuffer;
483 int firstVertex; 479 int firstVertex;
484 480
485 void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride, 481 void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride,
486 kVertsPerCubic, 482 kVertsPerCubic,
487 &vertexBuffer, 483 &vertexBuffer,
488 &firstVertex); 484 &firstVertex);
489 485
490 if (!vertices || !indexBuffer) { 486 if (!vertices || !batchTarget->quadIndexBuffer()) {
491 SkDebugf("Could not allocate buffers\n"); 487 SkDebugf("Could not allocate buffers\n");
492 return; 488 return;
493 } 489 }
494 490
495 SkASSERT(vertexStride == sizeof(Vertex)); 491 SkASSERT(vertexStride == sizeof(Vertex));
496 Vertex* verts = reinterpret_cast<Vertex*>(vertices); 492 Vertex* verts = reinterpret_cast<Vertex*>(vertices);
497 493
498 verts[0].fPosition.setRectFan(fGeometry.fBounds.fLeft, fGeometry.fBounds .fTop, 494 verts[0].fPosition.setRectFan(fGeometry.fBounds.fLeft, fGeometry.fBounds .fTop,
499 fGeometry.fBounds.fRight, fGeometry.fBound s.fBottom, 495 fGeometry.fBounds.fRight, fGeometry.fBound s.fBottom,
500 sizeof(Vertex)); 496 sizeof(Vertex));
501 497
502 fDevToUV.apply<4, sizeof(Vertex), sizeof(SkPoint)>(verts); 498 fDevToUV.apply<4, sizeof(Vertex), sizeof(SkPoint)>(verts);
503 499
504 500
505 GrDrawTarget::DrawInfo drawInfo; 501 GrDrawTarget::DrawInfo drawInfo;
506 drawInfo.setPrimitiveType(kTriangles_GrPrimitiveType); 502 drawInfo.setPrimitiveType(kTriangles_GrPrimitiveType);
507 drawInfo.setVertexBuffer(vertexBuffer); 503 drawInfo.setVertexBuffer(vertexBuffer);
508 drawInfo.setStartVertex(firstVertex); 504 drawInfo.setStartVertex(firstVertex);
509 drawInfo.setVertexCount(kVertsPerCubic); 505 drawInfo.setVertexCount(kVertsPerCubic);
510 drawInfo.setStartIndex(0); 506 drawInfo.setStartIndex(0);
511 drawInfo.setIndexCount(kIndicesPerCubic); 507 drawInfo.setIndexCount(kIndicesPerCubic);
512 drawInfo.setIndexBuffer(indexBuffer); 508 drawInfo.setIndexBuffer(batchTarget->quadIndexBuffer());
513 batchTarget->draw(drawInfo); 509 batchTarget->draw(drawInfo);
514 } 510 }
515 511
516 Geometry fGeometry; 512 Geometry fGeometry;
517 GrPathUtils::QuadUVMatrix fDevToUV; 513 GrPathUtils::QuadUVMatrix fDevToUV;
518 514
519 static const int kVertsPerCubic = 4; 515 static const int kVertsPerCubic = 4;
520 static const int kIndicesPerCubic = 6; 516 static const int kIndicesPerCubic = 6;
521 517
522 typedef GrTestBatch INHERITED; 518 typedef GrTestBatch INHERITED;
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 typedef GM INHERITED; 656 typedef GM INHERITED;
661 }; 657 };
662 658
663 DEF_GM( return SkNEW(BezierCubicEffects); ) 659 DEF_GM( return SkNEW(BezierCubicEffects); )
664 DEF_GM( return SkNEW(BezierConicEffects); ) 660 DEF_GM( return SkNEW(BezierConicEffects); )
665 DEF_GM( return SkNEW(BezierQuadEffects); ) 661 DEF_GM( return SkNEW(BezierQuadEffects); )
666 662
667 } 663 }
668 664
669 #endif 665 #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