blob: 46e810eeb040019f5d389a170dfc4c9442ee7e92 [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
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
reede8f30622016-03-23 18:59:25 -070018static sk_sp<SkSurface> new_surface(int width, int height) {
19 return SkSurface::MakeRasterN32Premul(width, height);
reed@google.com4117a242012-10-30 20:26:58 +000020}
21
22static void draw_pixel_centers(SkCanvas* canvas) {
23 SkPaint paint;
caryclark12596012015-07-29 05:27:47 -070024 paint.setColor(sk_tool_utils::color_to_565(0xFF0088FF));
reed@google.com4117a242012-10-30 20:26:58 +000025 paint.setAntiAlias(true);
skia.committer@gmail.come862d162012-10-31 02:01:18 +000026
reed@google.com4117a242012-10-30 20:26:58 +000027 for (int y = 0; y < SMALL_H; ++y) {
28 for (int x = 0; x < SMALL_W; ++x) {
29 canvas->drawCircle(x + 0.5f, y + 0.5f, 1.5f / ZOOM, paint);
30 }
31 }
32}
33
reed41e010c2015-06-09 12:16:53 -070034static void draw_fatpath(SkCanvas* canvas, SkSurface* surface, const SkPath& path) {
reed@google.com4117a242012-10-30 20:26:58 +000035 SkPaint paint;
36
junov@google.comdbfac8a2012-12-06 21:47:40 +000037 surface->getCanvas()->clear(SK_ColorTRANSPARENT);
reed41e010c2015-06-09 12:16:53 -070038 surface->getCanvas()->drawPath(path, paint);
halcanary96fcdcc2015-08-27 07:41:13 -070039 surface->draw(canvas, 0, 0, nullptr);
reed@google.com4117a242012-10-30 20:26:58 +000040
41 paint.setAntiAlias(true);
42 paint.setColor(SK_ColorRED);
43 paint.setStyle(SkPaint::kStroke_Style);
reed41e010c2015-06-09 12:16:53 -070044 canvas->drawPath(path, paint);
reed@google.com4117a242012-10-30 20:26:58 +000045
46 draw_pixel_centers(canvas);
47}
48
halcanary2a243382015-09-09 08:16:41 -070049DEF_SIMPLE_GM(fatpathfill, canvas,
50 SMALL_W * ZOOM,
51 SMALL_H * ZOOM * REPEAT_LOOP) {
reede8f30622016-03-23 18:59:25 -070052 auto surface(new_surface(SMALL_W, SMALL_H));
reed@google.com4117a242012-10-30 20:26:58 +000053
54 canvas->scale(ZOOM, ZOOM);
55
56 SkPaint paint;
57 paint.setStyle(SkPaint::kStroke_Style);
58 paint.setStrokeWidth(SK_Scalar1);
59
60 for (int i = 0; i < REPEAT_LOOP; ++i) {
61 SkPath line, path;
reed41e010c2015-06-09 12:16:53 -070062 line.moveTo(1, 2);
63 line.lineTo(SkIntToScalar(4 + i), 1);
reed@google.com4117a242012-10-30 20:26:58 +000064 paint.getFillPath(line, &path);
reede8f30622016-03-23 18:59:25 -070065 draw_fatpath(canvas, surface.get(), path);
skia.committer@gmail.come862d162012-10-31 02:01:18 +000066
reed@google.com4117a242012-10-30 20:26:58 +000067 canvas->translate(0, SMALL_H);
68 }
halcanary2a243382015-09-09 08:16:41 -070069}