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

Side by Side Diff: gm/convexpolyeffect.cpp

Issue 913153003: Revert of GMs now use batch (Closed) Base URL: https://skia.googlesource.com/skia.git@oval
Patch Set: Created 5 years, 10 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') | gyp/gmslides.gypi » ('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"
16 #include "GrBufferAllocPool.h"
17 #include "GrContext.h" 15 #include "GrContext.h"
18 #include "GrDefaultGeoProcFactory.h" 16 #include "GrDefaultGeoProcFactory.h"
19 #include "GrPathUtils.h" 17 #include "GrPathUtils.h"
20 #include "GrTest.h" 18 #include "GrTest.h"
21 #include "GrTestBatch.h"
22 #include "SkColorPriv.h" 19 #include "SkColorPriv.h"
23 #include "SkDevice.h" 20 #include "SkDevice.h"
24 #include "SkGeometry.h" 21 #include "SkGeometry.h"
25 #include "SkTLList.h" 22 #include "SkTLList.h"
26 23
27 #include "effects/GrConvexPolyEffect.h" 24 #include "effects/GrConvexPolyEffect.h"
28 25
29 namespace skiagm { 26 namespace skiagm {
30
31 class ConvexPolyTestBatch : public GrTestBatch {
32 public:
33 struct Geometry : public GrTestBatch::Geometry {
34 SkRect fBounds;
35 };
36
37 const char* name() const SK_OVERRIDE { return "ConvexPolyTestBatch"; }
38
39 static GrBatch* Create(const GrGeometryProcessor* gp, const Geometry& geo) {
40 return SkNEW_ARGS(ConvexPolyTestBatch, (gp, geo));
41 }
42
43 private:
44 ConvexPolyTestBatch(const GrGeometryProcessor* gp, const Geometry& geo)
45 : INHERITED(gp)
46 , fGeometry(geo) {
47 }
48
49 Geometry* geoData(int index) SK_OVERRIDE {
50 SkASSERT(0 == index);
51 return &fGeometry;
52 }
53
54 void onGenerateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeli ne) SK_OVERRIDE {
55 size_t vertexStride = this->geometryProcessor()->getVertexStride();
56
57 const GrVertexBuffer* vertexBuffer;
58 int firstVertex;
59
60 void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride,
61 kVertsPerCubic,
62 &vertexBuffer,
63 &firstVertex);
64
65 SkASSERT(vertexStride == sizeof(SkPoint));
66 SkPoint* verts = reinterpret_cast<SkPoint*>(vertices);
67
68 // Make sure any artifacts around the exterior of path are visible by us ing overly
69 // conservative bounding geometry.
70 fGeometry.fBounds.outset(5.f, 5.f);
71 fGeometry.fBounds.toQuad(verts);
72
73 GrDrawTarget::DrawInfo drawInfo;
74 drawInfo.setPrimitiveType(kTriangleFan_GrPrimitiveType);
75 drawInfo.setVertexBuffer(vertexBuffer);
76 drawInfo.setStartVertex(firstVertex);
77 drawInfo.setVertexCount(kVertsPerCubic);
78 drawInfo.setStartIndex(0);
79 drawInfo.setIndexCount(kIndicesPerCubic);
80 drawInfo.setIndexBuffer(batchTarget->quadIndexBuffer());
81 batchTarget->draw(drawInfo);
82 }
83
84 Geometry fGeometry;
85
86 static const int kVertsPerCubic = 4;
87 static const int kIndicesPerCubic = 6;
88
89 typedef GrTestBatch INHERITED;
90 };
91
92 /** 27 /**
93 * This GM directly exercises a GrProcessor that draws convex polygons. 28 * This GM directly exercises a GrProcessor that draws convex polygons.
94 */ 29 */
95 class ConvexPolyEffect : public GM { 30 class ConvexPolyEffect : public GM {
96 public: 31 public:
97 ConvexPolyEffect() { 32 ConvexPolyEffect() {
98 this->setBGColor(0xFFFFFFFF); 33 this->setBGColor(0xFFFFFFFF);
99 } 34 }
100 35
101 protected: 36 protected:
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget (); 96 GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget ();
162 if (NULL == rt) { 97 if (NULL == rt) {
163 this->drawGpuOnlyMessage(canvas); 98 this->drawGpuOnlyMessage(canvas);
164 return; 99 return;
165 } 100 }
166 GrContext* context = rt->getContext(); 101 GrContext* context = rt->getContext();
167 if (NULL == context) { 102 if (NULL == context) {
168 return; 103 return;
169 } 104 }
170 105
171 SkAutoTUnref<const GrGeometryProcessor> gp(
172 GrDefaultGeoProcFactory::Create(GrDefaultGeoProcFactory::kPositi on_GPType,
173 0xff000000));
174
175 SkScalar y = 0; 106 SkScalar y = 0;
176 for (SkTLList<SkPath>::Iter iter(fPaths, SkTLList<SkPath>::Iter::kHead_I terStart); 107 for (SkTLList<SkPath>::Iter iter(fPaths, SkTLList<SkPath>::Iter::kHead_I terStart);
177 iter.get(); 108 iter.get();
178 iter.next()) { 109 iter.next()) {
179 const SkPath* path = iter.get(); 110 const SkPath* path = iter.get();
180 SkScalar x = 0; 111 SkScalar x = 0;
181 112
182 for (int et = 0; et < kGrProcessorEdgeTypeCnt; ++et) { 113 for (int et = 0; et < kGrProcessorEdgeTypeCnt; ++et) {
183 GrTestTarget tt; 114 GrTestTarget tt;
184 context->getTestTarget(&tt); 115 context->getTestTarget(&tt);
185 if (NULL == tt.target()) { 116 if (NULL == tt.target()) {
186 SkDEBUGFAIL("Couldn't get Gr test target."); 117 SkDEBUGFAIL("Couldn't get Gr test target.");
187 return; 118 return;
188 } 119 }
189 SkMatrix m; 120 SkMatrix m;
190 SkPath p; 121 SkPath p;
191 m.setTranslate(x, y); 122 m.setTranslate(x, y);
192 path->transform(m, &p); 123 path->transform(m, &p);
193 124
194 GrPrimitiveEdgeType edgeType = (GrPrimitiveEdgeType) et; 125 GrPrimitiveEdgeType edgeType = (GrPrimitiveEdgeType) et;
195 SkAutoTUnref<GrFragmentProcessor> fp(GrConvexPolyEffect::Create( edgeType, p)); 126 SkAutoTUnref<GrFragmentProcessor> fp(GrConvexPolyEffect::Create( edgeType, p));
196 if (!fp) { 127 if (!fp) {
197 continue; 128 continue;
198 } 129 }
199 130
200 GrPipelineBuilder pipelineBuilder; 131 GrPipelineBuilder pipelineBuilder;
132 SkAutoTUnref<const GrGeometryProcessor> gp(
133 GrDefaultGeoProcFactory::Create(GrDefaultGeoProcFactory: :kPosition_GPType,
134 0xff000000));
201 pipelineBuilder.addCoverageProcessor(fp); 135 pipelineBuilder.addCoverageProcessor(fp);
202 pipelineBuilder.setRenderTarget(rt); 136 pipelineBuilder.setRenderTarget(rt);
203 137
204 ConvexPolyTestBatch::Geometry geometry; 138 GrDrawTarget::AutoReleaseGeometry geo(tt.target(), 4, gp->getVer texStride(), 0);
205 geometry.fColor = gp->color(); 139 SkASSERT(gp->getVertexStride() == sizeof(SkPoint));
206 geometry.fBounds = p.getBounds(); 140 SkPoint* verts = reinterpret_cast<SkPoint*>(geo.vertices());
207 141
208 SkAutoTUnref<GrBatch> batch(ConvexPolyTestBatch::Create(gp, geom etry)); 142 SkRect bounds = p.getBounds();
143 // Make sure any artifacts around the exterior of path are visib le by using overly
144 // conservative bounding geometry.
145 bounds.outset(5.f, 5.f);
146 bounds.toQuad(verts);
209 147
210 tt.target()->drawBatch(&pipelineBuilder, batch, NULL); 148 tt.target()->setIndexSourceToBuffer(context->getQuadIndexBuffer( ));
149 tt.target()->drawIndexed(&pipelineBuilder, gp, kTriangleFan_GrPr imitiveType,
150 0, 0, 4, 6);
211 151
212 x += SkScalarCeilToScalar(path->getBounds().width() + 10.f); 152 x += SkScalarCeilToScalar(path->getBounds().width() + 10.f);
213 } 153 }
214 154
215 // Draw AA and non AA paths using normal API for reference. 155 // Draw AA and non AA paths using normal API for reference.
216 canvas->save(); 156 canvas->save();
217 canvas->translate(x, y); 157 canvas->translate(x, y);
218 SkPaint paint; 158 SkPaint paint;
219 canvas->drawPath(*path, paint); 159 canvas->drawPath(*path, paint);
220 canvas->translate(path->getBounds().width() + 10.f, 0); 160 canvas->translate(path->getBounds().width() + 10.f, 0);
(...skipping 19 matching lines...) Expand all
240 } 180 }
241 SkRect rect = *iter.get(); 181 SkRect rect = *iter.get();
242 rect.offset(x, y); 182 rect.offset(x, y);
243 GrPrimitiveEdgeType edgeType = (GrPrimitiveEdgeType) et; 183 GrPrimitiveEdgeType edgeType = (GrPrimitiveEdgeType) et;
244 SkAutoTUnref<GrFragmentProcessor> fp(GrConvexPolyEffect::Create( edgeType, rect)); 184 SkAutoTUnref<GrFragmentProcessor> fp(GrConvexPolyEffect::Create( edgeType, rect));
245 if (!fp) { 185 if (!fp) {
246 continue; 186 continue;
247 } 187 }
248 188
249 GrPipelineBuilder pipelineBuilder; 189 GrPipelineBuilder pipelineBuilder;
190 SkAutoTUnref<const GrGeometryProcessor> gp(
191 GrDefaultGeoProcFactory::Create(GrDefaultGeoProcFactory: :kPosition_GPType,
192 0xff000000));
250 pipelineBuilder.addCoverageProcessor(fp); 193 pipelineBuilder.addCoverageProcessor(fp);
251 pipelineBuilder.setRenderTarget(rt); 194 pipelineBuilder.setRenderTarget(rt);
252 195
253 ConvexPolyTestBatch::Geometry geometry; 196 GrDrawTarget::AutoReleaseGeometry geo(tt.target(), 4, gp->getVer texStride(), 0);
254 geometry.fColor = gp->color(); 197 SkASSERT(gp->getVertexStride() == sizeof(SkPoint));
255 geometry.fBounds = rect; 198 SkPoint* verts = reinterpret_cast<SkPoint*>(geo.vertices());
256 199
257 SkAutoTUnref<GrBatch> batch(ConvexPolyTestBatch::Create(gp, geom etry)); 200 SkRect bounds = rect;
201 bounds.outset(5.f, 5.f);
202 bounds.toQuad(verts);
258 203
259 tt.target()->drawBatch(&pipelineBuilder, batch, NULL); 204 tt.target()->setIndexSourceToBuffer(context->getQuadIndexBuffer( ));
205 tt.target()->drawIndexed(&pipelineBuilder, gp, kTriangleFan_GrPr imitiveType,
206 0, 0, 4, 6);
260 207
261 x += SkScalarCeilToScalar(rect.width() + 10.f); 208 x += SkScalarCeilToScalar(rect.width() + 10.f);
262 } 209 }
263 210
264 // Draw rect without and with AA using normal API for reference 211 // Draw rect without and with AA using normal API for reference
265 canvas->save(); 212 canvas->save();
266 canvas->translate(x, y); 213 canvas->translate(x, y);
267 SkPaint paint; 214 SkPaint paint;
268 canvas->drawRect(*iter.get(), paint); 215 canvas->drawRect(*iter.get(), paint);
269 x += SkScalarCeilToScalar(iter.get()->width() + 10.f); 216 x += SkScalarCeilToScalar(iter.get()->width() + 10.f);
270 paint.setAntiAlias(true); 217 paint.setAntiAlias(true);
271 canvas->drawRect(*iter.get(), paint); 218 canvas->drawRect(*iter.get(), paint);
272 canvas->restore(); 219 canvas->restore();
273 220
274 y += SkScalarCeilToScalar(iter.get()->height() + 20.f); 221 y += SkScalarCeilToScalar(iter.get()->height() + 20.f);
275 } 222 }
276 } 223 }
277 224
278 private: 225 private:
279 SkTLList<SkPath> fPaths; 226 SkTLList<SkPath> fPaths;
280 SkTLList<SkRect> fRects; 227 SkTLList<SkRect> fRects;
281 228
282 typedef GM INHERITED; 229 typedef GM INHERITED;
283 }; 230 };
284 231
285 DEF_GM( return SkNEW(ConvexPolyEffect); ) 232 DEF_GM( return SkNEW(ConvexPolyEffect); )
286 } 233 }
287 234
288 #endif 235 #endif
OLDNEW
« no previous file with comments | « gm/beziereffects.cpp ('k') | gyp/gmslides.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698