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) { |
| 19 | SkImage::Info info = { |
| 20 | width, |
| 21 | height, |
| 22 | SkImage::kPMColor_ColorType, |
| 23 | SkImage::kPremul_AlphaType |
| 24 | }; |
mike@reedtribe.org | b947625 | 2012-11-15 02:37:45 +0000 | [diff] [blame^] | 25 | return SkSurface::NewRaster(info); |
reed@google.com | 4117a24 | 2012-10-30 20:26:58 +0000 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | static void draw_pixel_centers(SkCanvas* canvas) { |
| 29 | SkPaint paint; |
| 30 | paint.setColor(0xFF0088FF); |
| 31 | paint.setAntiAlias(true); |
skia.committer@gmail.com | e862d16 | 2012-10-31 02:01:18 +0000 | [diff] [blame] | 32 | |
reed@google.com | 4117a24 | 2012-10-30 20:26:58 +0000 | [diff] [blame] | 33 | for (int y = 0; y < SMALL_H; ++y) { |
| 34 | for (int x = 0; x < SMALL_W; ++x) { |
| 35 | canvas->drawCircle(x + 0.5f, y + 0.5f, 1.5f / ZOOM, paint); |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | static void draw_fatpath(SkCanvas* canvas, SkSurface* surface, |
| 41 | const SkPath paths[], int count) { |
| 42 | SkPaint paint; |
| 43 | |
| 44 | surface->getCanvas()->clear(0); |
| 45 | for (int i = 0; i < count; ++i) { |
| 46 | surface->getCanvas()->drawPath(paths[i], paint); |
| 47 | } |
| 48 | surface->draw(canvas, 0, 0, NULL); |
| 49 | |
| 50 | paint.setAntiAlias(true); |
| 51 | paint.setColor(SK_ColorRED); |
| 52 | paint.setStyle(SkPaint::kStroke_Style); |
| 53 | for (int j = 0; j < count; ++j) { |
| 54 | canvas->drawPath(paths[j], paint); |
| 55 | } |
| 56 | |
| 57 | draw_pixel_centers(canvas); |
| 58 | } |
| 59 | |
| 60 | class FatPathFillGM : public skiagm::GM { |
| 61 | public: |
| 62 | FatPathFillGM() {} |
| 63 | |
| 64 | protected: |
| 65 | virtual SkString onShortName() { |
| 66 | return SkString("fatpathfill"); |
| 67 | } |
| 68 | |
| 69 | virtual SkISize onISize() { |
| 70 | return SkISize::Make(SMALL_W * ZOOM, SMALL_H * ZOOM * REPEAT_LOOP); |
| 71 | } |
| 72 | |
| 73 | virtual void onDraw(SkCanvas* canvas) { |
| 74 | SkAutoTUnref<SkSurface> surface(new_surface(SMALL_W, SMALL_H)); |
| 75 | |
| 76 | canvas->scale(ZOOM, ZOOM); |
| 77 | |
| 78 | SkPaint paint; |
| 79 | paint.setStyle(SkPaint::kStroke_Style); |
| 80 | paint.setStrokeWidth(SK_Scalar1); |
| 81 | |
| 82 | for (int i = 0; i < REPEAT_LOOP; ++i) { |
| 83 | SkPath line, path; |
| 84 | line.moveTo(1, 2); line.lineTo(4 + i, 1); |
| 85 | paint.getFillPath(line, &path); |
| 86 | draw_fatpath(canvas, surface, &path, 1); |
skia.committer@gmail.com | e862d16 | 2012-10-31 02:01:18 +0000 | [diff] [blame] | 87 | |
reed@google.com | 4117a24 | 2012-10-30 20:26:58 +0000 | [diff] [blame] | 88 | canvas->translate(0, SMALL_H); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | private: |
| 93 | typedef skiagm::GM INHERITED; |
| 94 | }; |
| 95 | |
| 96 | /////////////////////////////////////////////////////////////////////////////// |
| 97 | |
| 98 | DEF_GM(return new FatPathFillGM;) |
| 99 | |