| 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 #include "SkPathPriv.h" | 9 #include "SkPathPriv.h" |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 angle += angleStep; | 21 angle += angleStep; |
| 22 } | 22 } |
| 23 } | 23 } |
| 24 | 24 |
| 25 namespace skiagm { | 25 namespace skiagm { |
| 26 | 26 |
| 27 // This GM is intended to exercise Ganesh's handling of convex line-only | 27 // This GM is intended to exercise Ganesh's handling of convex line-only |
| 28 // paths | 28 // paths |
| 29 class ConvexLineOnlyPathsGM : public GM { | 29 class ConvexLineOnlyPathsGM : public GM { |
| 30 public: | 30 public: |
| 31 ConvexLineOnlyPathsGM() { | 31 ConvexLineOnlyPathsGM(bool doStrokeAndFill) : fDoStrokeAndFill(doStrokeAndFi
ll) { |
| 32 this->setBGColor(0xFFFFFFFF); | 32 this->setBGColor(0xFFFFFFFF); |
| 33 } | 33 } |
| 34 | 34 |
| 35 protected: | 35 protected: |
| 36 SkString onShortName() override { return SkString("convex-lineonly-paths");
} | 36 SkString onShortName() override { |
| 37 if (fDoStrokeAndFill) { |
| 38 return SkString("convex-lineonly-paths-stroke-and-fill"); |
| 39 } |
| 40 return SkString("convex-lineonly-paths"); |
| 41 } |
| 37 SkISize onISize() override { return SkISize::Make(kGMWidth, kGMHeight); } | 42 SkISize onISize() override { return SkISize::Make(kGMWidth, kGMHeight); } |
| 38 bool runAsBench() const override { return true; } | 43 bool runAsBench() const override { return true; } |
| 39 | 44 |
| 40 static SkPath GetPath(int index, int offset, SkPath::Direction dir) { | 45 static SkPath GetPath(int index, int offset, SkPath::Direction dir) { |
| 41 // narrow rect | 46 // narrow rect |
| 42 const SkPoint gPoints0[] = { | 47 const SkPoint gPoints0[] = { |
| 43 { -1.5f, -50.0f }, | 48 { -1.5f, -50.0f }, |
| 44 { 1.5f, -50.0f }, | 49 { 1.5f, -50.0f }, |
| 45 { 1.5f, 50.0f }, | 50 { 1.5f, 50.0f }, |
| 46 { -1.5f, 50.0f } | 51 { -1.5f, 50.0f } |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 // Draw a single path several times, shrinking it, flipping its direction | 256 // Draw a single path several times, shrinking it, flipping its direction |
| 252 // and changing its start vertex each time. | 257 // and changing its start vertex each time. |
| 253 void drawPath(SkCanvas* canvas, int index, SkPoint* offset) { | 258 void drawPath(SkCanvas* canvas, int index, SkPoint* offset) { |
| 254 | 259 |
| 255 SkPoint center; | 260 SkPoint center; |
| 256 { | 261 { |
| 257 SkPath path = GetPath(index, 0, SkPath::kCW_Direction); | 262 SkPath path = GetPath(index, 0, SkPath::kCW_Direction); |
| 258 if (offset->fX+path.getBounds().width() > kGMWidth) { | 263 if (offset->fX+path.getBounds().width() > kGMWidth) { |
| 259 offset->fX = 0; | 264 offset->fX = 0; |
| 260 offset->fY += kMaxPathHeight; | 265 offset->fY += kMaxPathHeight; |
| 266 if (fDoStrokeAndFill) { |
| 267 offset->fX += kStrokeWidth / 2.0f; |
| 268 offset->fY += kStrokeWidth / 2.0f; |
| 269 } |
| 261 } | 270 } |
| 262 center = { offset->fX + SkScalarHalf(path.getBounds().width()), offs
et->fY}; | 271 center = { offset->fX + SkScalarHalf(path.getBounds().width()), offs
et->fY}; |
| 263 offset->fX += path.getBounds().width(); | 272 offset->fX += path.getBounds().width(); |
| 273 if (fDoStrokeAndFill) { |
| 274 offset->fX += kStrokeWidth; |
| 275 } |
| 264 } | 276 } |
| 265 | 277 |
| 266 const SkColor colors[2] = { SK_ColorBLACK, SK_ColorWHITE }; | 278 const SkColor colors[2] = { SK_ColorBLACK, SK_ColorWHITE }; |
| 267 const SkPath::Direction dirs[2] = { SkPath::kCW_Direction, SkPath::kCCW_
Direction }; | 279 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 }
; | 280 const float scales[] = { 1.0f, 0.75f, 0.5f, 0.25f, 0.1f, 0.01f, 0.001f }
; |
| 281 const SkPaint::Join joins[3] = { SkPaint::kRound_Join, |
| 282 SkPaint::kBevel_Join, |
| 283 SkPaint::kMiter_Join }; |
| 269 | 284 |
| 270 SkPaint paint; | 285 SkPaint paint; |
| 271 paint.setAntiAlias(true); | 286 paint.setAntiAlias(true); |
| 272 | 287 |
| 273 for (size_t i = 0; i < SK_ARRAY_COUNT(scales); ++i) { | 288 for (size_t i = 0; i < SK_ARRAY_COUNT(scales); ++i) { |
| 274 SkPath path = GetPath(index, (int) i, dirs[i%2]); | 289 SkPath path = GetPath(index, (int) i, dirs[i%2]); |
| 290 if (fDoStrokeAndFill) { |
| 291 paint.setStyle(SkPaint::kStrokeAndFill_Style); |
| 292 paint.setStrokeJoin(joins[i%3]); |
| 293 paint.setStrokeWidth(SkIntToScalar(kStrokeWidth)); |
| 294 } |
| 275 | 295 |
| 276 canvas->save(); | 296 canvas->save(); |
| 277 canvas->translate(center.fX, center.fY); | 297 canvas->translate(center.fX, center.fY); |
| 278 canvas->scale(scales[i], scales[i]); | 298 canvas->scale(scales[i], scales[i]); |
| 279 paint.setColor(colors[i%2]); | 299 paint.setColor(colors[i%2]); |
| 280 canvas->drawPath(path, paint); | 300 canvas->drawPath(path, paint); |
| 281 canvas->restore(); | 301 canvas->restore(); |
| 282 } | 302 } |
| 283 } | 303 } |
| 284 | 304 |
| 285 void onDraw(SkCanvas* canvas) override { | 305 void onDraw(SkCanvas* canvas) override { |
| 286 // the right edge of the last drawn path | 306 // the right edge of the last drawn path |
| 287 SkPoint offset = { 0, SkScalarHalf(kMaxPathHeight) }; | 307 SkPoint offset = { 0, SkScalarHalf(kMaxPathHeight) }; |
| 308 if (fDoStrokeAndFill) { |
| 309 offset.fX += kStrokeWidth / 2.0f; |
| 310 offset.fY += kStrokeWidth / 2.0f; |
| 311 } |
| 288 | 312 |
| 289 for (int i = 0; i < kNumPaths; ++i) { | 313 for (int i = 0; i < kNumPaths; ++i) { |
| 290 this->drawPath(canvas, i, &offset); | 314 this->drawPath(canvas, i, &offset); |
| 291 } | 315 } |
| 292 | 316 |
| 293 // Repro for crbug.com/472723 (Missing AA on portions of graphic with GP
U rasterization) | 317 // Repro for crbug.com/472723 (Missing AA on portions of graphic with GP
U rasterization) |
| 294 { | 318 { |
| 295 canvas->translate(356.0f, 50.0f); | 319 canvas->translate(356.0f, 50.0f); |
| 296 | 320 |
| 297 SkPaint p; | 321 SkPaint p; |
| 298 p.setAntiAlias(true); | 322 p.setAntiAlias(true); |
| 323 if (fDoStrokeAndFill) { |
| 324 p.setStyle(SkPaint::kStrokeAndFill_Style); |
| 325 p.setStrokeJoin(SkPaint::kMiter_Join); |
| 326 p.setStrokeWidth(SkIntToScalar(kStrokeWidth)); |
| 327 } |
| 299 | 328 |
| 300 SkPath p1; | 329 SkPath p1; |
| 301 p1.moveTo(60.8522949f, 364.671021f); | 330 p1.moveTo(60.8522949f, 364.671021f); |
| 302 p1.lineTo(59.4380493f, 364.671021f); | 331 p1.lineTo(59.4380493f, 364.671021f); |
| 303 p1.lineTo(385.414276f, 690.647217f); | 332 p1.lineTo(385.414276f, 690.647217f); |
| 304 p1.lineTo(386.121399f, 689.940125f); | 333 p1.lineTo(386.121399f, 689.940125f); |
| 305 canvas->drawPath(p1, p); | 334 canvas->drawPath(p1, p); |
| 306 } | 335 } |
| 307 } | 336 } |
| 308 | 337 |
| 309 private: | 338 private: |
| 339 static const int kStrokeWidth = 10; |
| 310 static const int kNumPaths = 20; | 340 static const int kNumPaths = 20; |
| 311 static const int kMaxPathHeight = 100; | 341 static const int kMaxPathHeight = 100; |
| 312 static const int kGMWidth = 512; | 342 static const int kGMWidth = 512; |
| 313 static const int kGMHeight = 512; | 343 static const int kGMHeight = 512; |
| 314 | 344 |
| 345 bool fDoStrokeAndFill; |
| 346 |
| 315 typedef GM INHERITED; | 347 typedef GM INHERITED; |
| 316 }; | 348 }; |
| 317 | 349 |
| 318 ////////////////////////////////////////////////////////////////////////////// | 350 ////////////////////////////////////////////////////////////////////////////// |
| 319 | 351 |
| 320 DEF_GM(return new ConvexLineOnlyPathsGM;) | 352 DEF_GM(return new ConvexLineOnlyPathsGM(false);) |
| 353 DEF_GM(return new ConvexLineOnlyPathsGM(true);) |
| 321 } | 354 } |
| OLD | NEW |