blob: 2228b4ad0ce874fc8b4763e4f33deff8df9243af [file] [log] [blame]
reed@google.com4117a242012-10-30 20:26:58 +00001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
9#include "include/core/SkCanvas.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040010#include "include/core/SkColor.h"
11#include "include/core/SkPaint.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "include/core/SkPath.h"
Kevin Lubick177a7122022-12-12 10:25:15 -050013#include "include/core/SkPathUtils.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040014#include "include/core/SkRefCnt.h"
15#include "include/core/SkScalar.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050016#include "include/core/SkSurface.h"
17#include "tools/ToolUtils.h"
reed@google.com4117a242012-10-30 20:26:58 +000018
19#define ZOOM 32
20#define SMALL_W 9
21#define SMALL_H 3
22#define REPEAT_LOOP 5
23
reede8f30622016-03-23 18:59:25 -070024static sk_sp<SkSurface> new_surface(int width, int height) {
Kevin Lubick5c93acf2023-05-09 12:11:43 -040025 return SkSurfaces::Raster(SkImageInfo::MakeN32Premul(width, height));
reed@google.com4117a242012-10-30 20:26:58 +000026}
27
28static void draw_pixel_centers(SkCanvas* canvas) {
29 SkPaint paint;
Mike Kleinea3f0142019-03-20 11:12:10 -050030 paint.setColor(ToolUtils::color_to_565(0xFF0088FF));
reed@google.com4117a242012-10-30 20:26:58 +000031 paint.setAntiAlias(true);
skia.committer@gmail.come862d162012-10-31 02:01:18 +000032
reed@google.com4117a242012-10-30 20:26:58 +000033 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
reed41e010c2015-06-09 12:16:53 -070040static void draw_fatpath(SkCanvas* canvas, SkSurface* surface, const SkPath& path) {
reed@google.com4117a242012-10-30 20:26:58 +000041 SkPaint paint;
42
junov@google.comdbfac8a2012-12-06 21:47:40 +000043 surface->getCanvas()->clear(SK_ColorTRANSPARENT);
reed41e010c2015-06-09 12:16:53 -070044 surface->getCanvas()->drawPath(path, paint);
Mike Reedb746b1f2021-01-06 08:43:51 -050045 surface->draw(canvas, 0, 0);
reed@google.com4117a242012-10-30 20:26:58 +000046
47 paint.setAntiAlias(true);
48 paint.setColor(SK_ColorRED);
49 paint.setStyle(SkPaint::kStroke_Style);
reed41e010c2015-06-09 12:16:53 -070050 canvas->drawPath(path, paint);
reed@google.com4117a242012-10-30 20:26:58 +000051
52 draw_pixel_centers(canvas);
53}
54
halcanary2a243382015-09-09 08:16:41 -070055DEF_SIMPLE_GM(fatpathfill, canvas,
56 SMALL_W * ZOOM,
57 SMALL_H * ZOOM * REPEAT_LOOP) {
reede8f30622016-03-23 18:59:25 -070058 auto surface(new_surface(SMALL_W, SMALL_H));
reed@google.com4117a242012-10-30 20:26:58 +000059
60 canvas->scale(ZOOM, ZOOM);
61
62 SkPaint paint;
63 paint.setStyle(SkPaint::kStroke_Style);
64 paint.setStrokeWidth(SK_Scalar1);
65
66 for (int i = 0; i < REPEAT_LOOP; ++i) {
67 SkPath line, path;
reed41e010c2015-06-09 12:16:53 -070068 line.moveTo(1, 2);
69 line.lineTo(SkIntToScalar(4 + i), 1);
Kevin Lubickf5491282022-12-15 08:37:49 -050070 skpathutils::FillPathWithPaint(line, paint, &path);
reede8f30622016-03-23 18:59:25 -070071 draw_fatpath(canvas, surface.get(), path);
skia.committer@gmail.come862d162012-10-31 02:01:18 +000072
reed@google.com4117a242012-10-30 20:26:58 +000073 canvas->translate(0, SMALL_H);
74 }
halcanary2a243382015-09-09 08:16:41 -070075}