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@google.com | d28ba80 | 2013-09-20 19:33:52 +0000 | [diff] [blame] | 19 | return SkSurface::NewRasterPMColor(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; |
| 24 | paint.setColor(0xFF0088FF); |
| 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 | |
| 34 | static void draw_fatpath(SkCanvas* canvas, SkSurface* surface, |
| 35 | const SkPath paths[], int count) { |
| 36 | SkPaint paint; |
| 37 | |
junov@google.com | dbfac8a | 2012-12-06 21:47:40 +0000 | [diff] [blame] | 38 | surface->getCanvas()->clear(SK_ColorTRANSPARENT); |
reed@google.com | 4117a24 | 2012-10-30 20:26:58 +0000 | [diff] [blame] | 39 | for (int i = 0; i < count; ++i) { |
| 40 | surface->getCanvas()->drawPath(paths[i], paint); |
| 41 | } |
| 42 | surface->draw(canvas, 0, 0, NULL); |
| 43 | |
| 44 | paint.setAntiAlias(true); |
| 45 | paint.setColor(SK_ColorRED); |
| 46 | paint.setStyle(SkPaint::kStroke_Style); |
| 47 | for (int j = 0; j < count; ++j) { |
| 48 | canvas->drawPath(paths[j], paint); |
| 49 | } |
| 50 | |
| 51 | draw_pixel_centers(canvas); |
| 52 | } |
| 53 | |
| 54 | class FatPathFillGM : public skiagm::GM { |
| 55 | public: |
| 56 | FatPathFillGM() {} |
| 57 | |
| 58 | protected: |
| 59 | virtual SkString onShortName() { |
| 60 | return SkString("fatpathfill"); |
| 61 | } |
| 62 | |
| 63 | virtual SkISize onISize() { |
| 64 | return SkISize::Make(SMALL_W * ZOOM, SMALL_H * ZOOM * REPEAT_LOOP); |
| 65 | } |
| 66 | |
| 67 | virtual void onDraw(SkCanvas* canvas) { |
| 68 | SkAutoTUnref<SkSurface> surface(new_surface(SMALL_W, SMALL_H)); |
| 69 | |
| 70 | canvas->scale(ZOOM, ZOOM); |
| 71 | |
| 72 | SkPaint paint; |
| 73 | paint.setStyle(SkPaint::kStroke_Style); |
| 74 | paint.setStrokeWidth(SK_Scalar1); |
| 75 | |
| 76 | for (int i = 0; i < REPEAT_LOOP; ++i) { |
| 77 | SkPath line, path; |
skia.committer@gmail.com | e659c2e | 2012-12-04 02:01:25 +0000 | [diff] [blame] | 78 | line.moveTo(SkIntToScalar(1), SkIntToScalar(2)); |
robertphillips@google.com | 93f0332 | 2012-12-03 17:35:19 +0000 | [diff] [blame] | 79 | line.lineTo(SkIntToScalar(4 + i), SkIntToScalar(1)); |
reed@google.com | 4117a24 | 2012-10-30 20:26:58 +0000 | [diff] [blame] | 80 | paint.getFillPath(line, &path); |
| 81 | draw_fatpath(canvas, surface, &path, 1); |
skia.committer@gmail.com | e862d16 | 2012-10-31 02:01:18 +0000 | [diff] [blame] | 82 | |
reed@google.com | 4117a24 | 2012-10-30 20:26:58 +0000 | [diff] [blame] | 83 | canvas->translate(0, SMALL_H); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | private: |
| 88 | typedef skiagm::GM INHERITED; |
| 89 | }; |
| 90 | |
| 91 | /////////////////////////////////////////////////////////////////////////////// |
| 92 | |
| 93 | DEF_GM(return new FatPathFillGM;) |