OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "gm.h" | 8 #include "gm.h" |
9 | 9 |
10 static void create_ngon(int n, SkPoint* pts, SkScalar width, SkScalar height) { | 10 static void create_ngon(int n, SkPoint* pts, SkScalar width, SkScalar height) { |
(...skipping 10 matching lines...) Expand all Loading... |
21 } | 21 } |
22 } | 22 } |
23 | 23 |
24 namespace skiagm { | 24 namespace skiagm { |
25 | 25 |
26 // This GM is intended to exercise Ganesh's handling of convex line-only | 26 // This GM is intended to exercise Ganesh's handling of convex line-only |
27 // paths | 27 // paths |
28 class ConvexLineOnlyPathsGM : public GM { | 28 class ConvexLineOnlyPathsGM : public GM { |
29 public: | 29 public: |
30 ConvexLineOnlyPathsGM() { | 30 ConvexLineOnlyPathsGM() { |
31 fOffset.set(0, SkScalarHalf(kMaxPathHeight)); | |
32 this->setBGColor(0xFFFFFFFF); | 31 this->setBGColor(0xFFFFFFFF); |
33 } | 32 } |
34 | 33 |
35 protected: | 34 protected: |
36 SkString onShortName() override { return SkString("convex-lineonly-paths");
} | 35 SkString onShortName() override { return SkString("convex-lineonly-paths");
} |
37 SkISize onISize() override { return SkISize::Make(kGMWidth, kGMHeight); } | 36 SkISize onISize() override { return SkISize::Make(kGMWidth, kGMHeight); } |
38 bool runAsBench() const override { return true; } | 37 bool runAsBench() const override { return true; } |
39 | 38 |
40 static SkPath GetPath(int index, int offset, SkPath::Direction dir) { | 39 static SkPath GetPath(int index, int offset, SkPath::Direction dir) { |
41 // narrow rect | 40 // narrow rect |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 SkASSERT(dir == actualDir); | 242 SkASSERT(dir == actualDir); |
244 SkRect bounds = path.getBounds(); | 243 SkRect bounds = path.getBounds(); |
245 SkASSERT(SkScalarNearlyEqual(bounds.centerX(), 0.0f)); | 244 SkASSERT(SkScalarNearlyEqual(bounds.centerX(), 0.0f)); |
246 SkASSERT(bounds.height() <= kMaxPathHeight); | 245 SkASSERT(bounds.height() <= kMaxPathHeight); |
247 #endif | 246 #endif |
248 return path; | 247 return path; |
249 } | 248 } |
250 | 249 |
251 // Draw a single path several times, shrinking it, flipping its direction | 250 // Draw a single path several times, shrinking it, flipping its direction |
252 // and changing its start vertex each time. | 251 // and changing its start vertex each time. |
253 void drawPath(SkCanvas* canvas, int index) { | 252 void drawPath(SkCanvas* canvas, int index, SkPoint* offset) { |
254 | 253 |
255 SkPoint center; | 254 SkPoint center; |
256 { | 255 { |
257 SkPath path = GetPath(index, 0, SkPath::kCW_Direction); | 256 SkPath path = GetPath(index, 0, SkPath::kCW_Direction); |
258 if (fOffset.fX+path.getBounds().width() > kGMWidth) { | 257 if (offset->fX+path.getBounds().width() > kGMWidth) { |
259 fOffset.fX = 0; | 258 offset->fX = 0; |
260 fOffset.fY += kMaxPathHeight; | 259 offset->fY += kMaxPathHeight; |
261 } | 260 } |
262 center = { fOffset.fX + SkScalarHalf(path.getBounds().width()), fOff
set.fY}; | 261 center = { offset->fX + SkScalarHalf(path.getBounds().width()), offs
et->fY}; |
263 fOffset.fX += path.getBounds().width(); | 262 offset->fX += path.getBounds().width(); |
264 } | 263 } |
265 | 264 |
266 const SkColor colors[2] = { SK_ColorBLACK, SK_ColorWHITE }; | 265 const SkColor colors[2] = { SK_ColorBLACK, SK_ColorWHITE }; |
267 const SkPath::Direction dirs[2] = { SkPath::kCW_Direction, SkPath::kCCW_
Direction }; | 266 const SkPath::Direction dirs[2] = { SkPath::kCW_Direction, SkPath::kCCW_
Direction }; |
268 const float scales[] = { 1.0f, 0.75f, 0.5f, 0.25f, 0.1f, 0.01f, 0.001f }
; | 267 const float scales[] = { 1.0f, 0.75f, 0.5f, 0.25f, 0.1f, 0.01f, 0.001f }
; |
269 | 268 |
270 SkPaint paint; | 269 SkPaint paint; |
271 paint.setAntiAlias(true); | 270 paint.setAntiAlias(true); |
272 | 271 |
273 for (size_t i = 0; i < SK_ARRAY_COUNT(scales); ++i) { | 272 for (size_t i = 0; i < SK_ARRAY_COUNT(scales); ++i) { |
274 SkPath path = GetPath(index, (int) i, dirs[i%2]); | 273 SkPath path = GetPath(index, (int) i, dirs[i%2]); |
275 | 274 |
276 canvas->save(); | 275 canvas->save(); |
277 canvas->translate(center.fX, center.fY); | 276 canvas->translate(center.fX, center.fY); |
278 canvas->scale(scales[i], scales[i]); | 277 canvas->scale(scales[i], scales[i]); |
279 paint.setColor(colors[i%2]); | 278 paint.setColor(colors[i%2]); |
280 canvas->drawPath(path, paint); | 279 canvas->drawPath(path, paint); |
281 canvas->restore(); | 280 canvas->restore(); |
282 } | 281 } |
283 } | 282 } |
284 | 283 |
285 void onDraw(SkCanvas* canvas) override { | 284 void onDraw(SkCanvas* canvas) override { |
| 285 // the right edge of the last drawn path |
| 286 SkPoint offset = { 0, SkScalarHalf(kMaxPathHeight) }; |
| 287 |
286 for (int i = 0; i < kNumPaths; ++i) { | 288 for (int i = 0; i < kNumPaths; ++i) { |
287 this->drawPath(canvas, i); | 289 this->drawPath(canvas, i, &offset); |
288 } | 290 } |
289 | 291 |
290 // Repro for crbug.com/472723 (Missing AA on portions of graphic with GP
U rasterization) | 292 // Repro for crbug.com/472723 (Missing AA on portions of graphic with GP
U rasterization) |
291 { | 293 { |
292 canvas->translate(356.0f, 50.0f); | 294 canvas->translate(356.0f, 50.0f); |
293 | 295 |
294 SkPaint p; | 296 SkPaint p; |
295 p.setAntiAlias(true); | 297 p.setAntiAlias(true); |
296 | 298 |
297 SkPath p1; | 299 SkPath p1; |
298 p1.moveTo(60.8522949f, 364.671021f); | 300 p1.moveTo(60.8522949f, 364.671021f); |
299 p1.lineTo(59.4380493f, 364.671021f); | 301 p1.lineTo(59.4380493f, 364.671021f); |
300 p1.lineTo(385.414276f, 690.647217f); | 302 p1.lineTo(385.414276f, 690.647217f); |
301 p1.lineTo(386.121399f, 689.940125f); | 303 p1.lineTo(386.121399f, 689.940125f); |
302 canvas->drawPath(p1, p); | 304 canvas->drawPath(p1, p); |
303 } | 305 } |
304 } | 306 } |
305 | 307 |
306 private: | 308 private: |
307 static const int kNumPaths = 20; | 309 static const int kNumPaths = 20; |
308 static const int kMaxPathHeight = 100; | 310 static const int kMaxPathHeight = 100; |
309 static const int kGMWidth = 512; | 311 static const int kGMWidth = 512; |
310 static const int kGMHeight = 512; | 312 static const int kGMHeight = 512; |
311 | 313 |
312 SkPoint fOffset; // the right edge of the last drawn path | |
313 | |
314 typedef GM INHERITED; | 314 typedef GM INHERITED; |
315 }; | 315 }; |
316 | 316 |
317 ////////////////////////////////////////////////////////////////////////////// | 317 ////////////////////////////////////////////////////////////////////////////// |
318 | 318 |
319 DEF_GM( return SkNEW(ConvexLineOnlyPathsGM); ) | 319 DEF_GM( return SkNEW(ConvexLineOnlyPathsGM); ) |
320 | 320 |
321 } | 321 } |
OLD | NEW |