OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 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 "GrDefaultGeoProcFactory.h" | 18 #include "GrDefaultGeoProcFactory.h" |
19 #include "GrPathUtils.h" | 19 #include "GrPathUtils.h" |
| 20 #include "GrResourceProvider.h" |
20 #include "GrTest.h" | 21 #include "GrTest.h" |
21 #include "GrTestBatch.h" | 22 #include "GrTestBatch.h" |
22 #include "SkColorPriv.h" | 23 #include "SkColorPriv.h" |
23 #include "SkDevice.h" | 24 #include "SkDevice.h" |
24 #include "SkGeometry.h" | 25 #include "SkGeometry.h" |
25 #include "SkTLList.h" | 26 #include "SkTLList.h" |
26 | 27 |
27 #include "effects/GrConvexPolyEffect.h" | 28 #include "effects/GrConvexPolyEffect.h" |
28 | 29 |
29 namespace skiagm { | 30 namespace skiagm { |
(...skipping 15 matching lines...) Expand all Loading... |
45 : INHERITED(gp, geo.fBounds) | 46 : INHERITED(gp, geo.fBounds) |
46 , fGeometry(geo) { | 47 , fGeometry(geo) { |
47 } | 48 } |
48 | 49 |
49 Geometry* geoData(int index) override { | 50 Geometry* geoData(int index) override { |
50 SkASSERT(0 == index); | 51 SkASSERT(0 == index); |
51 return &fGeometry; | 52 return &fGeometry; |
52 } | 53 } |
53 | 54 |
54 void onGenerateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeli
ne) override { | 55 void onGenerateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeli
ne) override { |
| 56 SkAutoTUnref<const GrIndexBuffer> indexBuffer( |
| 57 batchTarget->resourceProvider()->refQuadIndexBuffer()); |
| 58 |
55 size_t vertexStride = this->geometryProcessor()->getVertexStride(); | 59 size_t vertexStride = this->geometryProcessor()->getVertexStride(); |
56 SkASSERT(vertexStride == sizeof(SkPoint)); | 60 const GrVertexBuffer* vertexBuffer; |
57 QuadHelper helper; | 61 int firstVertex; |
58 SkPoint* verts = reinterpret_cast<SkPoint*>(helper.init(batchTarget, ver
texStride, 1)); | 62 |
59 if (!verts) { | 63 void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride, |
| 64 kVertsPerCubic, |
| 65 &vertexBuffer, |
| 66 &firstVertex); |
| 67 |
| 68 if (!vertices || !indexBuffer) { |
| 69 SkDebugf("Could not allocate buffers\n"); |
60 return; | 70 return; |
61 } | 71 } |
62 | 72 |
| 73 SkASSERT(vertexStride == sizeof(SkPoint)); |
| 74 SkPoint* verts = reinterpret_cast<SkPoint*>(vertices); |
| 75 |
63 // Make sure any artifacts around the exterior of path are visible by us
ing overly | 76 // Make sure any artifacts around the exterior of path are visible by us
ing overly |
64 // conservative bounding geometry. | 77 // conservative bounding geometry. |
65 fGeometry.fBounds.outset(5.f, 5.f); | 78 fGeometry.fBounds.outset(5.f, 5.f); |
66 fGeometry.fBounds.toQuad(verts); | 79 fGeometry.fBounds.toQuad(verts); |
67 | 80 |
68 helper.issueDraws(batchTarget); | 81 GrDrawTarget::DrawInfo drawInfo; |
| 82 drawInfo.setPrimitiveType(kTriangleFan_GrPrimitiveType); |
| 83 drawInfo.setVertexBuffer(vertexBuffer); |
| 84 drawInfo.setStartVertex(firstVertex); |
| 85 drawInfo.setVertexCount(kVertsPerCubic); |
| 86 drawInfo.setStartIndex(0); |
| 87 drawInfo.setIndexCount(kIndicesPerCubic); |
| 88 drawInfo.setIndexBuffer(indexBuffer); |
| 89 batchTarget->draw(drawInfo); |
69 } | 90 } |
70 | 91 |
71 Geometry fGeometry; | 92 Geometry fGeometry; |
72 | 93 |
| 94 static const int kVertsPerCubic = 4; |
| 95 static const int kIndicesPerCubic = 6; |
| 96 |
73 typedef GrTestBatch INHERITED; | 97 typedef GrTestBatch INHERITED; |
74 }; | 98 }; |
75 | 99 |
76 /** | 100 /** |
77 * This GM directly exercises a GrProcessor that draws convex polygons. | 101 * This GM directly exercises a GrProcessor that draws convex polygons. |
78 */ | 102 */ |
79 class ConvexPolyEffect : public GM { | 103 class ConvexPolyEffect : public GM { |
80 public: | 104 public: |
81 ConvexPolyEffect() { | 105 ConvexPolyEffect() { |
82 this->setBGColor(0xFFFFFFFF); | 106 this->setBGColor(0xFFFFFFFF); |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 SkTLList<SkPath> fPaths; | 286 SkTLList<SkPath> fPaths; |
263 SkTLList<SkRect> fRects; | 287 SkTLList<SkRect> fRects; |
264 | 288 |
265 typedef GM INHERITED; | 289 typedef GM INHERITED; |
266 }; | 290 }; |
267 | 291 |
268 DEF_GM( return SkNEW(ConvexPolyEffect); ) | 292 DEF_GM( return SkNEW(ConvexPolyEffect); ) |
269 } | 293 } |
270 | 294 |
271 #endif | 295 #endif |
OLD | NEW |