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