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 "GrContext.h" | 15 #include "GrContext.h" |
16 #include "GrDefaultGeoProcFactory.h" | 16 #include "GrDefaultGeoProcFactory.h" |
17 #include "GrDrawContext.h" | |
17 #include "GrPathUtils.h" | 18 #include "GrPathUtils.h" |
18 #include "GrTest.h" | 19 #include "GrTest.h" |
19 #include "SkColorPriv.h" | 20 #include "SkColorPriv.h" |
20 #include "SkDevice.h" | 21 #include "SkDevice.h" |
21 #include "SkGeometry.h" | 22 #include "SkGeometry.h" |
22 #include "SkTLList.h" | 23 #include "SkTLList.h" |
23 | 24 |
24 #include "batches/GrTestBatch.h" | 25 #include "batches/GrTestBatch.h" |
25 #include "batches/GrVertexBatch.h" | 26 #include "batches/GrVertexBatch.h" |
26 | 27 |
27 #include "effects/GrConvexPolyEffect.h" | 28 #include "effects/GrConvexPolyEffect.h" |
28 | 29 |
29 namespace skiagm { | 30 namespace skiagm { |
30 | 31 |
31 class ConvexPolyTestBatch : public GrTestBatch { | 32 class ConvexPolyTestBatch : public GrTestBatch { |
32 public: | 33 public: |
33 DEFINE_BATCH_CLASS_ID | 34 DEFINE_BATCH_CLASS_ID |
34 struct Geometry : public GrTestBatch::Geometry { | 35 struct Geometry : public GrTestBatch::Geometry { |
robertphillips
2016/01/12 20:56:33
Why do we need fRect ?
| |
36 SkRect fRect; | |
35 SkRect fBounds; | 37 SkRect fBounds; |
36 }; | 38 }; |
37 | 39 |
38 const char* name() const override { return "ConvexPolyTestBatch"; } | 40 const char* name() const override { return "ConvexPolyTestBatch"; } |
39 | 41 |
40 static GrDrawBatch* Create(const GrGeometryProcessor* gp, const Geometry& ge o) { | 42 static GrDrawBatch* Create(const GrGeometryProcessor* gp, const Geometry& ge o) { |
41 return new ConvexPolyTestBatch(gp, geo); | 43 return new ConvexPolyTestBatch(gp, geo); |
42 } | 44 } |
43 | 45 |
44 private: | 46 private: |
45 ConvexPolyTestBatch(const GrGeometryProcessor* gp, const Geometry& geo) | 47 ConvexPolyTestBatch(const GrGeometryProcessor* gp, const Geometry& geo) |
46 : INHERITED(ClassID(), gp, geo.fBounds) | 48 : INHERITED(ClassID(), gp, geo.fBounds) |
47 , fGeometry(geo) { | 49 , fGeometry(geo) { |
48 // Make sure any artifacts around the exterior of path are visible by us ing overly | 50 // Make sure any artifacts around the exterior of path are visible by us ing overly |
49 // conservative bounding geometry. | 51 // conservative bounding geometry. |
50 fGeometry.fBounds.outset(5.f, 5.f); | 52 fGeometry.fBounds.outset(5.f, 5.f); |
53 fGeometry.fRect.outset(5.f, 5.f); | |
51 } | 54 } |
52 | 55 |
53 Geometry* geoData(int index) override { | 56 Geometry* geoData(int index) override { |
54 SkASSERT(0 == index); | 57 SkASSERT(0 == index); |
55 return &fGeometry; | 58 return &fGeometry; |
56 } | 59 } |
57 | 60 |
58 const Geometry* geoData(int index) const override { | 61 const Geometry* geoData(int index) const override { |
59 SkASSERT(0 == index); | 62 SkASSERT(0 == index); |
60 return &fGeometry; | 63 return &fGeometry; |
61 } | 64 } |
62 | 65 |
63 void generateGeometry(Target* target) const override { | 66 void generateGeometry(Target* target) const override { |
64 size_t vertexStride = this->geometryProcessor()->getVertexStride(); | 67 size_t vertexStride = this->geometryProcessor()->getVertexStride(); |
65 SkASSERT(vertexStride == sizeof(SkPoint)); | 68 SkASSERT(vertexStride == sizeof(SkPoint)); |
66 QuadHelper helper; | 69 QuadHelper helper; |
67 SkPoint* verts = reinterpret_cast<SkPoint*>(helper.init(target, vertexSt ride, 1)); | 70 SkPoint* verts = reinterpret_cast<SkPoint*>(helper.init(target, vertexSt ride, 1)); |
68 if (!verts) { | 71 if (!verts) { |
69 return; | 72 return; |
70 } | 73 } |
71 | 74 |
72 fGeometry.fBounds.toQuad(verts); | 75 fGeometry.fRect.toQuad(verts); |
73 | 76 |
74 helper.recordDraw(target); | 77 helper.recordDraw(target); |
75 } | 78 } |
76 | 79 |
77 Geometry fGeometry; | 80 Geometry fGeometry; |
78 | 81 |
79 typedef GrTestBatch INHERITED; | 82 typedef GrTestBatch INHERITED; |
80 }; | 83 }; |
81 | 84 |
82 /** | 85 /** |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
152 GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget (); | 155 GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget (); |
153 if (nullptr == rt) { | 156 if (nullptr == rt) { |
154 skiagm::GM::DrawGpuOnlyMessage(canvas); | 157 skiagm::GM::DrawGpuOnlyMessage(canvas); |
155 return; | 158 return; |
156 } | 159 } |
157 GrContext* context = rt->getContext(); | 160 GrContext* context = rt->getContext(); |
158 if (nullptr == context) { | 161 if (nullptr == context) { |
159 return; | 162 return; |
160 } | 163 } |
161 | 164 |
165 GrDrawContext* drawContext = context->drawContext(rt); | |
166 | |
162 Color color(0xff000000); | 167 Color color(0xff000000); |
163 Coverage coverage(Coverage::kSolid_Type); | 168 Coverage coverage(Coverage::kSolid_Type); |
164 LocalCoords localCoords(LocalCoords::kUnused_Type); | 169 LocalCoords localCoords(LocalCoords::kUnused_Type); |
165 SkAutoTUnref<const GrGeometryProcessor> gp( | 170 SkAutoTUnref<const GrGeometryProcessor> gp( |
166 GrDefaultGeoProcFactory::Create(color, coverage, localCoords, Sk Matrix::I())); | 171 GrDefaultGeoProcFactory::Create(color, coverage, localCoords, Sk Matrix::I())); |
167 | 172 |
168 SkScalar y = 0; | 173 SkScalar y = 0; |
169 for (PathList::Iter iter(fPaths, PathList::Iter::kHead_IterStart); | 174 for (PathList::Iter iter(fPaths, PathList::Iter::kHead_IterStart); |
170 iter.get(); | 175 iter.get(); |
171 iter.next()) { | 176 iter.next()) { |
172 const SkPath* path = iter.get(); | 177 const SkPath* path = iter.get(); |
173 SkScalar x = 0; | 178 SkScalar x = 0; |
174 | 179 |
175 for (int et = 0; et < kGrProcessorEdgeTypeCnt; ++et) { | 180 for (int et = 0; et < kGrProcessorEdgeTypeCnt; ++et) { |
176 GrTestTarget tt; | |
177 context->getTestTarget(&tt, rt); | |
178 if (nullptr == tt.target()) { | |
179 SkDEBUGFAIL("Couldn't get Gr test target."); | |
180 return; | |
181 } | |
182 const SkMatrix m = SkMatrix::MakeTrans(x, y); | 181 const SkMatrix m = SkMatrix::MakeTrans(x, y); |
183 SkPath p; | 182 SkPath p; |
184 path->transform(m, &p); | 183 path->transform(m, &p); |
185 | 184 |
186 GrPrimitiveEdgeType edgeType = (GrPrimitiveEdgeType) et; | 185 GrPrimitiveEdgeType edgeType = (GrPrimitiveEdgeType) et; |
187 SkAutoTUnref<GrFragmentProcessor> fp(GrConvexPolyEffect::Create( edgeType, p)); | 186 SkAutoTUnref<GrFragmentProcessor> fp(GrConvexPolyEffect::Create( edgeType, p)); |
188 if (!fp) { | 187 if (!fp) { |
189 continue; | 188 continue; |
190 } | 189 } |
191 | 190 |
192 GrPipelineBuilder pipelineBuilder; | 191 GrPipelineBuilder pipelineBuilder; |
193 pipelineBuilder.setXPFactory( | 192 pipelineBuilder.setXPFactory( |
194 GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->unref (); | 193 GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->unref (); |
195 pipelineBuilder.addCoverageFragmentProcessor(fp); | 194 pipelineBuilder.addCoverageFragmentProcessor(fp); |
196 pipelineBuilder.setRenderTarget(rt); | 195 pipelineBuilder.setRenderTarget(rt); |
197 | 196 |
198 ConvexPolyTestBatch::Geometry geometry; | 197 ConvexPolyTestBatch::Geometry geometry; |
199 geometry.fColor = color.fColor; | 198 geometry.fColor = color.fColor; |
199 geometry.fRect = p.getBounds(); | |
200 geometry.fBounds = p.getBounds(); | 200 geometry.fBounds = p.getBounds(); |
201 | 201 |
202 SkAutoTUnref<GrDrawBatch> batch(ConvexPolyTestBatch::Create(gp, geometry)); | 202 SkAutoTUnref<GrDrawBatch> batch(ConvexPolyTestBatch::Create(gp, geometry)); |
203 | 203 |
204 tt.target()->drawBatch(pipelineBuilder, batch); | 204 drawContext->internal_drawBatch(&pipelineBuilder, batch); |
205 | 205 |
206 x += SkScalarCeilToScalar(path->getBounds().width() + 10.f); | 206 x += SkScalarCeilToScalar(path->getBounds().width() + 10.f); |
207 } | 207 } |
208 | 208 |
209 // Draw AA and non AA paths using normal API for reference. | 209 // Draw AA and non AA paths using normal API for reference. |
210 canvas->save(); | 210 canvas->save(); |
211 canvas->translate(x, y); | 211 canvas->translate(x, y); |
212 SkPaint paint; | 212 SkPaint paint; |
213 canvas->drawPath(*path, paint); | 213 canvas->drawPath(*path, paint); |
214 canvas->translate(path->getBounds().width() + 10.f, 0); | 214 canvas->translate(path->getBounds().width() + 10.f, 0); |
215 paint.setAntiAlias(true); | 215 paint.setAntiAlias(true); |
216 canvas->drawPath(*path, paint); | 216 canvas->drawPath(*path, paint); |
217 canvas->restore(); | 217 canvas->restore(); |
218 | 218 |
219 y += SkScalarCeilToScalar(path->getBounds().height() + 20.f); | 219 y += SkScalarCeilToScalar(path->getBounds().height() + 20.f); |
220 } | 220 } |
221 | 221 |
222 for (RectList::Iter iter(fRects, RectList::Iter::kHead_IterStart); | 222 for (RectList::Iter iter(fRects, RectList::Iter::kHead_IterStart); |
223 iter.get(); | 223 iter.get(); |
224 iter.next()) { | 224 iter.next()) { |
225 | 225 |
226 SkScalar x = 0; | 226 SkScalar x = 0; |
227 | 227 |
228 for (int et = 0; et < kGrProcessorEdgeTypeCnt; ++et) { | 228 for (int et = 0; et < kGrProcessorEdgeTypeCnt; ++et) { |
229 GrTestTarget tt; | |
230 context->getTestTarget(&tt, rt); | |
231 if (nullptr == tt.target()) { | |
232 SkDEBUGFAIL("Couldn't get Gr test target."); | |
233 return; | |
234 } | |
235 SkRect rect = *iter.get(); | 229 SkRect rect = *iter.get(); |
236 rect.offset(x, y); | 230 rect.offset(x, y); |
237 GrPrimitiveEdgeType edgeType = (GrPrimitiveEdgeType) et; | 231 GrPrimitiveEdgeType edgeType = (GrPrimitiveEdgeType) et; |
238 SkAutoTUnref<GrFragmentProcessor> fp(GrConvexPolyEffect::Create( edgeType, rect)); | 232 SkAutoTUnref<GrFragmentProcessor> fp(GrConvexPolyEffect::Create( edgeType, rect)); |
239 if (!fp) { | 233 if (!fp) { |
240 continue; | 234 continue; |
241 } | 235 } |
242 | 236 |
243 GrPipelineBuilder pipelineBuilder; | 237 GrPipelineBuilder pipelineBuilder; |
244 pipelineBuilder.setXPFactory( | 238 pipelineBuilder.setXPFactory( |
245 GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->unref (); | 239 GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->unref (); |
246 pipelineBuilder.addCoverageFragmentProcessor(fp); | 240 pipelineBuilder.addCoverageFragmentProcessor(fp); |
247 pipelineBuilder.setRenderTarget(rt); | 241 pipelineBuilder.setRenderTarget(rt); |
248 | 242 |
249 ConvexPolyTestBatch::Geometry geometry; | 243 ConvexPolyTestBatch::Geometry geometry; |
250 geometry.fColor = color.fColor; | 244 geometry.fColor = color.fColor; |
245 geometry.fRect = rect; | |
251 geometry.fBounds = rect; | 246 geometry.fBounds = rect; |
247 geometry.fBounds.sort(); | |
252 | 248 |
253 SkAutoTUnref<GrDrawBatch> batch(ConvexPolyTestBatch::Create(gp, geometry)); | 249 SkAutoTUnref<GrDrawBatch> batch(ConvexPolyTestBatch::Create(gp, geometry)); |
254 | 250 |
255 tt.target()->drawBatch(pipelineBuilder, batch); | 251 drawContext->internal_drawBatch(&pipelineBuilder, batch); |
256 | 252 |
257 x += SkScalarCeilToScalar(rect.width() + 10.f); | 253 x += SkScalarCeilToScalar(rect.width() + 10.f); |
258 } | 254 } |
259 | 255 |
260 // Draw rect without and with AA using normal API for reference | 256 // Draw rect without and with AA using normal API for reference |
261 canvas->save(); | 257 canvas->save(); |
262 canvas->translate(x, y); | 258 canvas->translate(x, y); |
263 SkPaint paint; | 259 SkPaint paint; |
264 canvas->drawRect(*iter.get(), paint); | 260 canvas->drawRect(*iter.get(), paint); |
265 x += SkScalarCeilToScalar(iter.get()->width() + 10.f); | 261 x += SkScalarCeilToScalar(iter.get()->width() + 10.f); |
(...skipping 11 matching lines...) Expand all Loading... | |
277 PathList fPaths; | 273 PathList fPaths; |
278 RectList fRects; | 274 RectList fRects; |
279 | 275 |
280 typedef GM INHERITED; | 276 typedef GM INHERITED; |
281 }; | 277 }; |
282 | 278 |
283 DEF_GM(return new ConvexPolyEffect;) | 279 DEF_GM(return new ConvexPolyEffect;) |
284 } | 280 } |
285 | 281 |
286 #endif | 282 #endif |
OLD | NEW |