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" |
Mike Klein | 33d2055 | 2017-03-22 13:47:51 -0400 | [diff] [blame] | 9 | #include "sk_tool_utils.h" |
reed@google.com | 4117a24 | 2012-10-30 20:26:58 +0000 | [diff] [blame] | 10 | #include "SkCanvas.h" |
| 11 | #include "SkPath.h" |
| 12 | #include "SkSurface.h" |
| 13 | |
| 14 | #define ZOOM 32 |
| 15 | #define SMALL_W 9 |
| 16 | #define SMALL_H 3 |
| 17 | #define REPEAT_LOOP 5 |
| 18 | |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 19 | static sk_sp<SkSurface> new_surface(int width, int height) { |
| 20 | return SkSurface::MakeRasterN32Premul(width, height); |
reed@google.com | 4117a24 | 2012-10-30 20:26:58 +0000 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | static void draw_pixel_centers(SkCanvas* canvas) { |
| 24 | SkPaint paint; |
caryclark | 1259601 | 2015-07-29 05:27:47 -0700 | [diff] [blame] | 25 | paint.setColor(sk_tool_utils::color_to_565(0xFF0088FF)); |
reed@google.com | 4117a24 | 2012-10-30 20:26:58 +0000 | [diff] [blame] | 26 | paint.setAntiAlias(true); |
skia.committer@gmail.com | e862d16 | 2012-10-31 02:01:18 +0000 | [diff] [blame] | 27 | |
reed@google.com | 4117a24 | 2012-10-30 20:26:58 +0000 | [diff] [blame] | 28 | for (int y = 0; y < SMALL_H; ++y) { |
| 29 | for (int x = 0; x < SMALL_W; ++x) { |
| 30 | canvas->drawCircle(x + 0.5f, y + 0.5f, 1.5f / ZOOM, paint); |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 | |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 35 | static void draw_fatpath(SkCanvas* canvas, SkSurface* surface, const SkPath& path) { |
reed@google.com | 4117a24 | 2012-10-30 20:26:58 +0000 | [diff] [blame] | 36 | SkPaint paint; |
| 37 | |
junov@google.com | dbfac8a | 2012-12-06 21:47:40 +0000 | [diff] [blame] | 38 | surface->getCanvas()->clear(SK_ColorTRANSPARENT); |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 39 | surface->getCanvas()->drawPath(path, paint); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 40 | surface->draw(canvas, 0, 0, nullptr); |
reed@google.com | 4117a24 | 2012-10-30 20:26:58 +0000 | [diff] [blame] | 41 | |
| 42 | paint.setAntiAlias(true); |
| 43 | paint.setColor(SK_ColorRED); |
| 44 | paint.setStyle(SkPaint::kStroke_Style); |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 45 | canvas->drawPath(path, paint); |
reed@google.com | 4117a24 | 2012-10-30 20:26:58 +0000 | [diff] [blame] | 46 | |
| 47 | draw_pixel_centers(canvas); |
| 48 | } |
| 49 | |
halcanary | 2a24338 | 2015-09-09 08:16:41 -0700 | [diff] [blame] | 50 | DEF_SIMPLE_GM(fatpathfill, canvas, |
| 51 | SMALL_W * ZOOM, |
| 52 | SMALL_H * ZOOM * REPEAT_LOOP) { |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 53 | auto surface(new_surface(SMALL_W, SMALL_H)); |
reed@google.com | 4117a24 | 2012-10-30 20:26:58 +0000 | [diff] [blame] | 54 | |
| 55 | canvas->scale(ZOOM, ZOOM); |
| 56 | |
| 57 | SkPaint paint; |
| 58 | paint.setStyle(SkPaint::kStroke_Style); |
| 59 | paint.setStrokeWidth(SK_Scalar1); |
| 60 | |
| 61 | for (int i = 0; i < REPEAT_LOOP; ++i) { |
| 62 | SkPath line, path; |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 63 | line.moveTo(1, 2); |
| 64 | line.lineTo(SkIntToScalar(4 + i), 1); |
reed@google.com | 4117a24 | 2012-10-30 20:26:58 +0000 | [diff] [blame] | 65 | paint.getFillPath(line, &path); |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 66 | draw_fatpath(canvas, surface.get(), path); |
skia.committer@gmail.com | e862d16 | 2012-10-31 02:01:18 +0000 | [diff] [blame] | 67 | |
reed@google.com | 4117a24 | 2012-10-30 20:26:58 +0000 | [diff] [blame] | 68 | canvas->translate(0, SMALL_H); |
| 69 | } |
halcanary | 2a24338 | 2015-09-09 08:16:41 -0700 | [diff] [blame] | 70 | } |