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