blob: bd82d179d243483974196d0b440bfb7a2d0a4214 [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"
Ben Wagner7fde8e12019-05-01 17:28:53 -040013#include "include/core/SkRefCnt.h"
14#include "include/core/SkScalar.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050015#include "include/core/SkSurface.h"
16#include "tools/ToolUtils.h"
reed@google.com4117a242012-10-30 20:26:58 +000017
18#define ZOOM 32
19#define SMALL_W 9
20#define SMALL_H 3
21#define REPEAT_LOOP 5
22
reede8f30622016-03-23 18:59:25 -070023static sk_sp<SkSurface> new_surface(int width, int height) {
24 return SkSurface::MakeRasterN32Premul(width, height);
reed@google.com4117a242012-10-30 20:26:58 +000025}
26
27static void draw_pixel_centers(SkCanvas* canvas) {
28 SkPaint paint;
Mike Kleinea3f0142019-03-20 11:12:10 -050029 paint.setColor(ToolUtils::color_to_565(0xFF0088FF));
reed@google.com4117a242012-10-30 20:26:58 +000030 paint.setAntiAlias(true);
skia.committer@gmail.come862d162012-10-31 02:01:18 +000031
reed@google.com4117a242012-10-30 20:26:58 +000032 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
reed41e010c2015-06-09 12:16:53 -070039static void draw_fatpath(SkCanvas* canvas, SkSurface* surface, const SkPath& path) {
reed@google.com4117a242012-10-30 20:26:58 +000040 SkPaint paint;
41
junov@google.comdbfac8a2012-12-06 21:47:40 +000042 surface->getCanvas()->clear(SK_ColorTRANSPARENT);
reed41e010c2015-06-09 12:16:53 -070043 surface->getCanvas()->drawPath(path, paint);
halcanary96fcdcc2015-08-27 07:41:13 -070044 surface->draw(canvas, 0, 0, nullptr);
reed@google.com4117a242012-10-30 20:26:58 +000045
46 paint.setAntiAlias(true);
47 paint.setColor(SK_ColorRED);
48 paint.setStyle(SkPaint::kStroke_Style);
reed41e010c2015-06-09 12:16:53 -070049 canvas->drawPath(path, paint);
reed@google.com4117a242012-10-30 20:26:58 +000050
51 draw_pixel_centers(canvas);
52}
53
halcanary2a243382015-09-09 08:16:41 -070054DEF_SIMPLE_GM(fatpathfill, canvas,
55 SMALL_W * ZOOM,
56 SMALL_H * ZOOM * REPEAT_LOOP) {
reede8f30622016-03-23 18:59:25 -070057 auto surface(new_surface(SMALL_W, SMALL_H));
reed@google.com4117a242012-10-30 20:26:58 +000058
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;
reed41e010c2015-06-09 12:16:53 -070067 line.moveTo(1, 2);
68 line.lineTo(SkIntToScalar(4 + i), 1);
reed@google.com4117a242012-10-30 20:26:58 +000069 paint.getFillPath(line, &path);
reede8f30622016-03-23 18:59:25 -070070 draw_fatpath(canvas, surface.get(), path);
skia.committer@gmail.come862d162012-10-31 02:01:18 +000071
reed@google.com4117a242012-10-30 20:26:58 +000072 canvas->translate(0, SMALL_H);
73 }
halcanary2a243382015-09-09 08:16:41 -070074}