Debian Codegraph @

gm/fatpathfill.cpp

raw
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
8 #include "gm/gm.h"
9 #include "include/core/SkCanvas.h"
10 #include "include/core/SkColor.h"
11 #include "include/core/SkPaint.h"
12 #include "include/core/SkPath.h"
13 #include "include/core/SkPathBuilder.h"
14 #include "include/core/SkPathUtils.h"
15 #include "include/core/SkRefCnt.h"
16 #include "include/core/SkScalar.h"
17 #include "include/core/SkSurface.h"
18 #include "tools/ToolUtils.h"
19
20 #define ZOOM 32
21 #define SMALL_W 9
22 #define SMALL_H 3
23 #define REPEAT_LOOP 5
24
25 static sk_sp<SkSurface> new_surface(int width, int height) {
26 return SkSurfaces::Raster(SkImageInfo::MakeN32Premul(width, height));
27 }
28
29 static void draw_pixel_centers(SkCanvas* canvas) {
30 SkPaint paint;
31 paint.setColor(ToolUtils::color_to_565(0xFF0088FF));
32 paint.setAntiAlias(true);
33
34 for (int y = 0; y < SMALL_H; ++y) {
35 for (int x = 0; x < SMALL_W; ++x) {
36 canvas->drawCircle(x + 0.5f, y + 0.5f, 1.5f / ZOOM, paint);
37 }
38 }
39 }
40
41 static void draw_fatpath(SkCanvas* canvas, SkSurface* surface, const SkPath& path) {
42 SkPaint paint;
43
44 surface->getCanvas()->clear(SK_ColorTRANSPARENT);
45 surface->getCanvas()->drawPath(path, paint);
46 surface->draw(canvas, 0, 0);
47
48 paint.setAntiAlias(true);
49 paint.setColor(SK_ColorRED);
50 paint.setStyle(SkPaint::kStroke_Style);
51 canvas->drawPath(path, paint);
52
53 draw_pixel_centers(canvas);
54 }
55
56 DEF_SIMPLE_GM(fatpathfill, canvas,
57 SMALL_W * ZOOM,
58 SMALL_H * ZOOM * REPEAT_LOOP) {
59 auto surface(new_surface(SMALL_W, SMALL_H));
60
61 canvas->scale(ZOOM, ZOOM);
62
63 SkPaint paint;
64 paint.setStyle(SkPaint::kStroke_Style);
65 paint.setStrokeWidth(SK_Scalar1);
66
67 for (int i = 0; i < REPEAT_LOOP; ++i) {
68 SkPath line = SkPath::Line({1, 2}, {SkIntToScalar(4 + i), 1});
69 SkPathBuilder builder;
70 skpathutils::FillPathWithPaint(line, paint, &builder);
71 draw_fatpath(canvas, surface.get(), builder.detach());
72
73 canvas->translate(0, SMALL_H);
74 }
75 }