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

Side by Side Diff: gm/convexpolyeffect.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 | « gm/beziereffects.cpp ('k') | src/gpu/GrAAConvexPathRenderer.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 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
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(
57 batchTarget->resourceProvider()->refQuadIndexBuffer());
58
59 size_t vertexStride = this->geometryProcessor()->getVertexStride(); 55 size_t vertexStride = this->geometryProcessor()->getVertexStride();
60 const GrVertexBuffer* vertexBuffer; 56 SkASSERT(vertexStride == sizeof(SkPoint));
61 int firstVertex; 57 QuadHelper helper;
62 58 SkPoint* verts = reinterpret_cast<SkPoint*>(helper.init(batchTarget, ver texStride, 1));
63 void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride, 59 if (!verts) {
64 kVertsPerCubic,
65 &vertexBuffer,
66 &firstVertex);
67
68 if (!vertices || !indexBuffer) {
69 SkDebugf("Could not allocate buffers\n");
70 return; 60 return;
71 } 61 }
72 62
73 SkASSERT(vertexStride == sizeof(SkPoint));
74 SkPoint* verts = reinterpret_cast<SkPoint*>(vertices);
75
76 // Make sure any artifacts around the exterior of path are visible by us ing overly 63 // Make sure any artifacts around the exterior of path are visible by us ing overly
77 // conservative bounding geometry. 64 // conservative bounding geometry.
78 fGeometry.fBounds.outset(5.f, 5.f); 65 fGeometry.fBounds.outset(5.f, 5.f);
79 fGeometry.fBounds.toQuad(verts); 66 fGeometry.fBounds.toQuad(verts);
80 67
81 GrDrawTarget::DrawInfo drawInfo; 68 helper.issueDraws(batchTarget);
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);
90 } 69 }
91 70
92 Geometry fGeometry; 71 Geometry fGeometry;
93 72
94 static const int kVertsPerCubic = 4;
95 static const int kIndicesPerCubic = 6;
96
97 typedef GrTestBatch INHERITED; 73 typedef GrTestBatch INHERITED;
98 }; 74 };
99 75
100 /** 76 /**
101 * This GM directly exercises a GrProcessor that draws convex polygons. 77 * This GM directly exercises a GrProcessor that draws convex polygons.
102 */ 78 */
103 class ConvexPolyEffect : public GM { 79 class ConvexPolyEffect : public GM {
104 public: 80 public:
105 ConvexPolyEffect() { 81 ConvexPolyEffect() {
106 this->setBGColor(0xFFFFFFFF); 82 this->setBGColor(0xFFFFFFFF);
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 SkTLList<SkPath> fPaths; 262 SkTLList<SkPath> fPaths;
287 SkTLList<SkRect> fRects; 263 SkTLList<SkRect> fRects;
288 264
289 typedef GM INHERITED; 265 typedef GM INHERITED;
290 }; 266 };
291 267
292 DEF_GM( return SkNEW(ConvexPolyEffect); ) 268 DEF_GM( return SkNEW(ConvexPolyEffect); )
293 } 269 }
294 270
295 #endif 271 #endif
OLDNEW
« no previous file with comments | « gm/beziereffects.cpp ('k') | src/gpu/GrAAConvexPathRenderer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698