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

Side by Side Diff: gm/convexpolyeffect.cpp

Issue 1835283002: Simplify GrDrawBatch uploads and token uage. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add comments Created 4 years, 8 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
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 "GrContext.h" 15 #include "GrContext.h"
16 #include "GrDefaultGeoProcFactory.h" 16 #include "GrDefaultGeoProcFactory.h"
17 #include "GrDrawContextPriv.h" 17 #include "GrDrawContextPriv.h"
18 #include "GrPathUtils.h" 18 #include "GrPathUtils.h"
19 #include "GrTest.h" 19 #include "GrTest.h"
20 #include "SkColorPriv.h" 20 #include "SkColorPriv.h"
21 #include "SkDevice.h" 21 #include "SkDevice.h"
22 #include "SkGeometry.h" 22 #include "SkGeometry.h"
23 #include "SkTLList.h" 23 #include "SkTLList.h"
24 24
25 #include "batches/GrTestBatch.h" 25 #include "batches/GrTestBatch.h"
26 #include "batches/GrVertexBatch.h" 26 #include "batches/GrVertexBatch.h"
27 27
28 #include "effects/GrConvexPolyEffect.h" 28 #include "effects/GrConvexPolyEffect.h"
29 29
30 /** outset rendered rect to visualize anti-aliased poly edges */
31 static SkRect outset(const SkRect& unsorted) {
32 SkRect r = unsorted;
33 r.outset(5.f, 5.f);
34 return r;
35 }
36
37 /** sorts a rect */
38 static SkRect sorted_rect(const SkRect& unsorted) {
39 SkRect r = unsorted;
40 r.sort();
41 return r;
42 }
43
30 namespace skiagm { 44 namespace skiagm {
31 45 class PolyBoundsBatch : public GrTestBatch {
32 class ConvexPolyTestBatch : public GrTestBatch {
33 public: 46 public:
34 DEFINE_BATCH_CLASS_ID 47 DEFINE_BATCH_CLASS_ID
35 struct Geometry : public GrTestBatch::Geometry {
36 SkRect fRect;
37 SkRect fBounds; // This will be == fRect, except fBounds must be sorted, whereas fRect can
38 // be inverted
39 };
40 48
41 const char* name() const override { return "ConvexPolyTestBatch"; } 49 const char* name() const override { return "PolyBoundsBatch"; }
42 50
43 static GrDrawBatch* Create(const GrGeometryProcessor* gp, const Geometry& ge o) { 51 PolyBoundsBatch(const SkRect& rect, GrColor color)
44 return new ConvexPolyTestBatch(gp, geo); 52 : INHERITED(ClassID(), outset(sorted_rect(rect)), color)
53 , fRect(outset(rect)) {
45 } 54 }
46 55
47 private: 56 private:
48 ConvexPolyTestBatch(const GrGeometryProcessor* gp, const Geometry& geo) 57 void onPrepareDraws(Target* target) const override {
49 : INHERITED(ClassID(), gp, geo.fBounds) 58 using namespace GrDefaultGeoProcFactory;
50 , fGeometry(geo) {
51 // Make sure any artifacts around the exterior of path are visible by us ing overly
52 // conservative bounding geometry.
53 fGeometry.fBounds.outset(5.f, 5.f);
54 fGeometry.fRect.outset(5.f, 5.f);
55 }
56 59
57 Geometry* geoData(int index) override { 60 Color color(this->color());
58 SkASSERT(0 == index); 61 Coverage coverage(Coverage::kSolid_Type);
59 return &fGeometry; 62 LocalCoords localCoords(LocalCoords::kUnused_Type);
60 } 63 SkAutoTUnref<const GrGeometryProcessor> gp(
64 GrDefaultGeoProcFactory::Create(color, coverage, localCoords, SkMatr ix::I()));
61 65
62 const Geometry* geoData(int index) const override { 66 size_t vertexStride = gp->getVertexStride();
63 SkASSERT(0 == index);
64 return &fGeometry;
65 }
66
67 void generateGeometry(Target* target) const override {
68 size_t vertexStride = this->geometryProcessor()->getVertexStride();
69 SkASSERT(vertexStride == sizeof(SkPoint)); 67 SkASSERT(vertexStride == sizeof(SkPoint));
70 QuadHelper helper; 68 QuadHelper helper;
71 SkPoint* verts = reinterpret_cast<SkPoint*>(helper.init(target, vertexSt ride, 1)); 69 SkPoint* verts = reinterpret_cast<SkPoint*>(helper.init(target, vertexSt ride, 1));
72 if (!verts) { 70 if (!verts) {
73 return; 71 return;
74 } 72 }
75 73
76 fGeometry.fRect.toQuad(verts); 74 fRect.toQuad(verts);
77 75
78 helper.recordDraw(target); 76 helper.recordDraw(target, gp);
79 } 77 }
80 78
81 Geometry fGeometry; 79 SkRect fRect;
82 80
83 typedef GrTestBatch INHERITED; 81 typedef GrTestBatch INHERITED;
84 }; 82 };
85 83
86 /** 84 /**
87 * This GM directly exercises a GrProcessor that draws convex polygons. 85 * This GM directly exercises a GrProcessor that draws convex polygons.
88 */ 86 */
89 class ConvexPolyEffect : public GM { 87 class ConvexPolyEffect : public GM {
90 public: 88 public:
91 ConvexPolyEffect() { 89 ConvexPolyEffect() {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 // vertically/horizontally thin rects that don't cover pixel centers 143 // vertically/horizontally thin rects that don't cover pixel centers
146 fRects.addToTail(SkRect::MakeLTRB(5.55f, 0.5f, 5.75f, 24.5f)); 144 fRects.addToTail(SkRect::MakeLTRB(5.55f, 0.5f, 5.75f, 24.5f));
147 fRects.addToTail(SkRect::MakeLTRB(5.5f, .05f, 29.5f, .25f)); 145 fRects.addToTail(SkRect::MakeLTRB(5.5f, .05f, 29.5f, .25f));
148 // small in x and y 146 // small in x and y
149 fRects.addToTail(SkRect::MakeLTRB(5.05f, .55f, 5.45f, .85f)); 147 fRects.addToTail(SkRect::MakeLTRB(5.05f, .55f, 5.45f, .85f));
150 // inverted in x and y 148 // inverted in x and y
151 fRects.addToTail(SkRect::MakeLTRB(100.f, 50.5f, 5.f, 0.5f)); 149 fRects.addToTail(SkRect::MakeLTRB(100.f, 50.5f, 5.f, 0.5f));
152 } 150 }
153 151
154 void onDraw(SkCanvas* canvas) override { 152 void onDraw(SkCanvas* canvas) override {
155 using namespace GrDefaultGeoProcFactory;
156 GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget (); 153 GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget ();
157 if (nullptr == rt) { 154 if (nullptr == rt) {
158 skiagm::GM::DrawGpuOnlyMessage(canvas); 155 skiagm::GM::DrawGpuOnlyMessage(canvas);
159 return; 156 return;
160 } 157 }
161 GrContext* context = rt->getContext(); 158 GrContext* context = rt->getContext();
162 if (nullptr == context) { 159 if (nullptr == context) {
163 return; 160 return;
164 } 161 }
165 162
166 SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(rt)); 163 SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(rt));
167 if (!drawContext) { 164 if (!drawContext) {
168 return; 165 return;
169 } 166 }
170 167
171 Color color(0xff000000);
172 Coverage coverage(Coverage::kSolid_Type);
173 LocalCoords localCoords(LocalCoords::kUnused_Type);
174 SkAutoTUnref<const GrGeometryProcessor> gp(
175 GrDefaultGeoProcFactory::Create(color, coverage, localCoords, Sk Matrix::I()));
176
177 SkScalar y = 0; 168 SkScalar y = 0;
178 for (PathList::Iter iter(fPaths, PathList::Iter::kHead_IterStart); 169 for (PathList::Iter iter(fPaths, PathList::Iter::kHead_IterStart);
179 iter.get(); 170 iter.get();
180 iter.next()) { 171 iter.next()) {
181 const SkPath* path = iter.get(); 172 const SkPath* path = iter.get();
182 SkScalar x = 0; 173 SkScalar x = 0;
183 174
184 for (int et = 0; et < kGrProcessorEdgeTypeCnt; ++et) { 175 for (int et = 0; et < kGrProcessorEdgeTypeCnt; ++et) {
185 const SkMatrix m = SkMatrix::MakeTrans(x, y); 176 const SkMatrix m = SkMatrix::MakeTrans(x, y);
186 SkPath p; 177 SkPath p;
187 path->transform(m, &p); 178 path->transform(m, &p);
188 179
189 GrPrimitiveEdgeType edgeType = (GrPrimitiveEdgeType) et; 180 GrPrimitiveEdgeType edgeType = (GrPrimitiveEdgeType) et;
190 SkAutoTUnref<GrFragmentProcessor> fp(GrConvexPolyEffect::Create( edgeType, p)); 181 SkAutoTUnref<GrFragmentProcessor> fp(GrConvexPolyEffect::Create( edgeType, p));
191 if (!fp) { 182 if (!fp) {
192 continue; 183 continue;
193 } 184 }
194 185
195 GrPipelineBuilder pipelineBuilder; 186 GrPipelineBuilder pipelineBuilder;
196 pipelineBuilder.setXPFactory( 187 pipelineBuilder.setXPFactory(
197 GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->unref (); 188 GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->unref ();
198 pipelineBuilder.addCoverageFragmentProcessor(fp); 189 pipelineBuilder.addCoverageFragmentProcessor(fp);
199 pipelineBuilder.setRenderTarget(rt); 190 pipelineBuilder.setRenderTarget(rt);
200 191
201 ConvexPolyTestBatch::Geometry geometry; 192 SkAutoTUnref<GrDrawBatch> batch(new PolyBoundsBatch(p.getBounds( ), 0xff000000));
202 geometry.fColor = color.fColor;
203 geometry.fRect = p.getBounds();
204 geometry.fBounds = p.getBounds();
205
206 SkAutoTUnref<GrDrawBatch> batch(ConvexPolyTestBatch::Create(gp, geometry));
207 193
208 drawContext->drawContextPriv().testingOnly_drawBatch(pipelineBui lder, batch); 194 drawContext->drawContextPriv().testingOnly_drawBatch(pipelineBui lder, batch);
209 195
210 x += SkScalarCeilToScalar(path->getBounds().width() + 10.f); 196 x += SkScalarCeilToScalar(path->getBounds().width() + 10.f);
211 } 197 }
212 198
213 // Draw AA and non AA paths using normal API for reference. 199 // Draw AA and non AA paths using normal API for reference.
214 canvas->save(); 200 canvas->save();
215 canvas->translate(x, y); 201 canvas->translate(x, y);
216 SkPaint paint; 202 SkPaint paint;
(...skipping 20 matching lines...) Expand all
237 if (!fp) { 223 if (!fp) {
238 continue; 224 continue;
239 } 225 }
240 226
241 GrPipelineBuilder pipelineBuilder; 227 GrPipelineBuilder pipelineBuilder;
242 pipelineBuilder.setXPFactory( 228 pipelineBuilder.setXPFactory(
243 GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->unref (); 229 GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->unref ();
244 pipelineBuilder.addCoverageFragmentProcessor(fp); 230 pipelineBuilder.addCoverageFragmentProcessor(fp);
245 pipelineBuilder.setRenderTarget(rt); 231 pipelineBuilder.setRenderTarget(rt);
246 232
247 ConvexPolyTestBatch::Geometry geometry; 233 SkAutoTUnref<GrDrawBatch> batch(new PolyBoundsBatch(rect, 0xff00 0000));
248 geometry.fColor = color.fColor;
249 geometry.fRect = rect;
250 geometry.fBounds = rect;
251 geometry.fBounds.sort();
252
253 SkAutoTUnref<GrDrawBatch> batch(ConvexPolyTestBatch::Create(gp, geometry));
254 234
255 drawContext->drawContextPriv().testingOnly_drawBatch(pipelineBui lder, batch); 235 drawContext->drawContextPriv().testingOnly_drawBatch(pipelineBui lder, batch);
256 236
257 x += SkScalarCeilToScalar(rect.width() + 10.f); 237 x += SkScalarCeilToScalar(rect.width() + 10.f);
258 } 238 }
259 239
260 // Draw rect without and with AA using normal API for reference 240 // Draw rect without and with AA using normal API for reference
261 canvas->save(); 241 canvas->save();
262 canvas->translate(x, y); 242 canvas->translate(x, y);
263 SkPaint paint; 243 SkPaint paint;
(...skipping 13 matching lines...) Expand all
277 PathList fPaths; 257 PathList fPaths;
278 RectList fRects; 258 RectList fRects;
279 259
280 typedef GM INHERITED; 260 typedef GM INHERITED;
281 }; 261 };
282 262
283 DEF_GM(return new ConvexPolyEffect;) 263 DEF_GM(return new ConvexPolyEffect;)
284 } 264 }
285 265
286 #endif 266 #endif
OLDNEW
« no previous file with comments | « gm/beziereffects.cpp ('k') | src/gpu/GrBatchAtlas.h » ('j') | src/gpu/batches/GrDrawBatch.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698