reed@google.com | 4117a24 | 2012-10-30 20:26:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "gm.h" |
| 9 | #include "SkCanvas.h" |
| 10 | #include "SkPath.h" |
| 11 | #include "SkSurface.h" |
| 12 | |
| 13 | #define ZOOM 32 |
| 14 | #define SMALL_W 9 |
| 15 | #define SMALL_H 3 |
| 16 | #define REPEAT_LOOP 5 |
| 17 | |
| 18 | static SkSurface* new_surface(int width, int height) { |
reed | 3054be1 | 2014-12-10 07:24:28 -0800 | [diff] [blame] | 19 | return SkSurface::NewRasterN32Premul(width, height); |
reed@google.com | 4117a24 | 2012-10-30 20:26:58 +0000 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | static void draw_pixel_centers(SkCanvas* canvas) { |
| 23 | SkPaint paint; |
caryclark | 1259601 | 2015-07-29 05:27:47 -0700 | [diff] [blame] | 24 | paint.setColor(sk_tool_utils::color_to_565(0xFF0088FF)); |
reed@google.com | 4117a24 | 2012-10-30 20:26:58 +0000 | [diff] [blame] | 25 | paint.setAntiAlias(true); |
skia.committer@gmail.com | e862d16 | 2012-10-31 02:01:18 +0000 | [diff] [blame] | 26 | |
reed@google.com | 4117a24 | 2012-10-30 20:26:58 +0000 | [diff] [blame] | 27 | for (int y = 0; y < SMALL_H; ++y) { |
| 28 | for (int x = 0; x < SMALL_W; ++x) { |
| 29 | canvas->drawCircle(x + 0.5f, y + 0.5f, 1.5f / ZOOM, paint); |
| 30 | } |
| 31 | } |
| 32 | } |
| 33 | |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 34 | static void draw_fatpath(SkCanvas* canvas, SkSurface* surface, const SkPath& path) { |
reed@google.com | 4117a24 | 2012-10-30 20:26:58 +0000 | [diff] [blame] | 35 | SkPaint paint; |
| 36 | |
junov@google.com | dbfac8a | 2012-12-06 21:47:40 +0000 | [diff] [blame] | 37 | surface->getCanvas()->clear(SK_ColorTRANSPARENT); |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 38 | surface->getCanvas()->drawPath(path, paint); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame^] | 39 | surface->draw(canvas, 0, 0, nullptr); |
reed@google.com | 4117a24 | 2012-10-30 20:26:58 +0000 | [diff] [blame] | 40 | |
| 41 | paint.setAntiAlias(true); |
| 42 | paint.setColor(SK_ColorRED); |
| 43 | paint.setStyle(SkPaint::kStroke_Style); |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 44 | canvas->drawPath(path, paint); |
reed@google.com | 4117a24 | 2012-10-30 20:26:58 +0000 | [diff] [blame] | 45 | |
| 46 | draw_pixel_centers(canvas); |
| 47 | } |
| 48 | |
| 49 | class FatPathFillGM : public skiagm::GM { |
| 50 | public: |
| 51 | FatPathFillGM() {} |
| 52 | |
| 53 | protected: |
commit-bot@chromium.org | a90c680 | 2014-04-30 13:20:45 +0000 | [diff] [blame] | 54 | |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 55 | SkString onShortName() override { |
reed@google.com | 4117a24 | 2012-10-30 20:26:58 +0000 | [diff] [blame] | 56 | return SkString("fatpathfill"); |
| 57 | } |
| 58 | |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 59 | SkISize onISize() override { |
reed@google.com | 4117a24 | 2012-10-30 20:26:58 +0000 | [diff] [blame] | 60 | return SkISize::Make(SMALL_W * ZOOM, SMALL_H * ZOOM * REPEAT_LOOP); |
| 61 | } |
| 62 | |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 63 | void onDraw(SkCanvas* canvas) override { |
reed@google.com | 4117a24 | 2012-10-30 20:26:58 +0000 | [diff] [blame] | 64 | SkAutoTUnref<SkSurface> surface(new_surface(SMALL_W, SMALL_H)); |
| 65 | |
| 66 | canvas->scale(ZOOM, ZOOM); |
| 67 | |
| 68 | SkPaint paint; |
| 69 | paint.setStyle(SkPaint::kStroke_Style); |
| 70 | paint.setStrokeWidth(SK_Scalar1); |
| 71 | |
| 72 | for (int i = 0; i < REPEAT_LOOP; ++i) { |
| 73 | SkPath line, path; |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 74 | line.moveTo(1, 2); |
| 75 | line.lineTo(SkIntToScalar(4 + i), 1); |
reed@google.com | 4117a24 | 2012-10-30 20:26:58 +0000 | [diff] [blame] | 76 | paint.getFillPath(line, &path); |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 77 | draw_fatpath(canvas, surface, path); |
skia.committer@gmail.com | e862d16 | 2012-10-31 02:01:18 +0000 | [diff] [blame] | 78 | |
reed@google.com | 4117a24 | 2012-10-30 20:26:58 +0000 | [diff] [blame] | 79 | canvas->translate(0, SMALL_H); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | private: |
| 84 | typedef skiagm::GM INHERITED; |
| 85 | }; |
| 86 | |
| 87 | /////////////////////////////////////////////////////////////////////////////// |
| 88 | |
| 89 | DEF_GM(return new FatPathFillGM;) |