blob: 21d9085fd0a5b75d6ec9e3f6930a1cb077aee783 [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"
Mike Klein33d20552017-03-22 13:47:51 -04009#include "sk_tool_utils.h"
reed@google.com4117a242012-10-30 20:26:58 +000010#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
reede8f30622016-03-23 18:59:25 -070019static sk_sp<SkSurface> new_surface(int width, int height) {
20 return SkSurface::MakeRasterN32Premul(width, height);
reed@google.com4117a242012-10-30 20:26:58 +000021}
22
23static void draw_pixel_centers(SkCanvas* canvas) {
24 SkPaint paint;
caryclark12596012015-07-29 05:27:47 -070025 paint.setColor(sk_tool_utils::color_to_565(0xFF0088FF));
reed@google.com4117a242012-10-30 20:26:58 +000026 paint.setAntiAlias(true);
skia.committer@gmail.come862d162012-10-31 02:01:18 +000027
reed@google.com4117a242012-10-30 20:26:58 +000028 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
reed41e010c2015-06-09 12:16:53 -070035static void draw_fatpath(SkCanvas* canvas, SkSurface* surface, const SkPath& path) {
reed@google.com4117a242012-10-30 20:26:58 +000036 SkPaint paint;
37
junov@google.comdbfac8a2012-12-06 21:47:40 +000038 surface->getCanvas()->clear(SK_ColorTRANSPARENT);
reed41e010c2015-06-09 12:16:53 -070039 surface->getCanvas()->drawPath(path, paint);
halcanary96fcdcc2015-08-27 07:41:13 -070040 surface->draw(canvas, 0, 0, nullptr);
reed@google.com4117a242012-10-30 20:26:58 +000041
42 paint.setAntiAlias(true);
43 paint.setColor(SK_ColorRED);
44 paint.setStyle(SkPaint::kStroke_Style);
reed41e010c2015-06-09 12:16:53 -070045 canvas->drawPath(path, paint);
reed@google.com4117a242012-10-30 20:26:58 +000046
47 draw_pixel_centers(canvas);
48}
49
halcanary2a243382015-09-09 08:16:41 -070050DEF_SIMPLE_GM(fatpathfill, canvas,
51 SMALL_W * ZOOM,
52 SMALL_H * ZOOM * REPEAT_LOOP) {
reede8f30622016-03-23 18:59:25 -070053 auto surface(new_surface(SMALL_W, SMALL_H));
reed@google.com4117a242012-10-30 20:26:58 +000054
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;
reed41e010c2015-06-09 12:16:53 -070063 line.moveTo(1, 2);
64 line.lineTo(SkIntToScalar(4 + i), 1);
reed@google.com4117a242012-10-30 20:26:58 +000065 paint.getFillPath(line, &path);
reede8f30622016-03-23 18:59:25 -070066 draw_fatpath(canvas, surface.get(), path);
skia.committer@gmail.come862d162012-10-31 02:01:18 +000067
reed@google.com4117a242012-10-30 20:26:58 +000068 canvas->translate(0, SMALL_H);
69 }
halcanary2a243382015-09-09 08:16:41 -070070}