Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
thinconcavepaths.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2017 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"
11#include "include/core/SkPath.h"
13
14namespace {
15// Test thin stroked rect (stroked "by hand", not by stroking).
16void draw_thin_stroked_rect(SkCanvas* canvas, const SkPaint& paint, SkScalar width) {
18 path.moveTo(10 + width, 10 + width);
19 path.lineTo(40, 10 + width);
20 path.lineTo(40, 20);
21 path.lineTo(10 + width, 20);
22 path.moveTo(10, 10);
23 path.lineTo(10, 20 + width);
24 path.lineTo(40 + width, 20 + width);
25 path.lineTo(40 + width, 10);
26 canvas->drawPath(path, paint);
27}
28
29void draw_thin_right_angle(SkCanvas* canvas, const SkPaint& paint, SkScalar width) {
31 path.moveTo(10 + width, 10 + width);
32 path.lineTo(40, 10 + width);
33 path.lineTo(40, 20);
34 path.lineTo(40 + width, 20 + width);
35 path.lineTo(40 + width, 10);
36 path.lineTo(10, 10);
37 canvas->drawPath(path, paint);
38}
39
40// Test thin horizontal line (<1 pixel) which should give lower alpha.
41void draw_golf_club(SkCanvas* canvas, const SkPaint& paint, SkScalar width) {
43 path.moveTo(20, 10);
44 path.lineTo(80, 10);
45 path.lineTo(80, 10 + width);
46 path.lineTo(30, 10 + width);
47 path.lineTo(30, 20);
48 path.lineTo(20, 20);
49 canvas->drawPath(path, paint);
50}
51
52// Test thin lines between two filled regions. The outer edges overlap, but
53// there are no inverted edges to fix.
54void draw_barbell(SkCanvas* canvas, const SkPaint& paint, SkScalar width) {
55 SkScalar offset = width * 0.5f;
57 path.moveTo(30, 5);
58 path.lineTo(40 - offset, 15 - offset);
59 path.lineTo(60 + offset, 15 - offset);
60 path.lineTo(70, 5);
61 path.lineTo(70, 25);
62 path.lineTo(60 + offset, 15 + offset);
63 path.lineTo(40 - offset, 15 + offset);
64 path.lineTo(30, 25);
65 canvas->drawPath(path, paint);
66}
67
68// Test a thin rectangle and triangle. The top and bottom inner edges of the
69// rectangle and all inner edges of the triangle invert on stroking.
70void draw_thin_rect_and_triangle(SkCanvas* canvas, const SkPaint& paint, SkScalar width) {
72 path.moveTo(30, 5);
73 path.lineTo(30 + width, 5);
74 path.lineTo(30 + width, 25);
75 path.lineTo(30, 25);
76 path.moveTo(40, 5);
77 path.lineTo(40 + width, 5);
78 path.lineTo(40, 25);
79 canvas->drawPath(path, paint);
80}
81
82// Two triangles joined by a very thin bridge. The tiny triangle formed
83// by the inner edges at the bridge is inverted.
84// (These are actually now more phat pants than hipster pants.)
85void draw_hipster_pants(SkCanvas* canvas, const SkPaint& paint, SkScalar width) {
87 path.moveTo(10, 10);
88 path.lineTo(10, 20);
89 path.lineTo(50, 10 + width);
90 path.lineTo(90, 20);
91 path.lineTo(90, 10);
92 canvas->drawPath(path, paint);
93}
94
95// A thin z-shape whose interior inverts on stroking. The top and bottom inner edges invert, and
96// the connector edges at the "elbows" intersect the inner edges.
97void draw_skinny_snake(SkCanvas* canvas, const SkPaint& paint, SkScalar width) {
99 path.moveTo(20 + width, 10);
100 path.lineTo(20 + width, 20);
101 path.lineTo(10 + width, 30);
102 path.lineTo(10 + width, 40);
103 path.lineTo(10 - width, 40);
104 path.lineTo(10 - width, 30);
105 path.lineTo(20 - width, 20);
106 path.lineTo(20 - width, 10);
107 canvas->drawPath(path, paint);
108}
109
110// Test pointy features whose outer edges extend far to the right on stroking.
111void draw_pointy_golf_club(SkCanvas* canvas, const SkPaint& paint, SkScalar width) {
112 SkPath path;
113 path.moveTo(20, 10);
114 path.lineTo(80, 10 + width * 0.5);
115 path.lineTo(30, 10 + width);
116 path.lineTo(30, 20);
117 path.lineTo(20, 20);
118 canvas->drawPath(path, paint);
119}
120
121void draw_small_i(SkCanvas* canvas, const SkPaint& paint, SkScalar width) {
122 SkPath path;
123 path.moveTo(1.25 - width, 18.75 + width);
124 path.lineTo(1.25 - width, 12.25 - width);
125 path.lineTo(2.50 + width, 12.25 - width);
126 path.lineTo(2.50 + width, 18.75 + width);
127 path.moveTo(1.25 - width, 11.75 + width);
128 path.lineTo(1.25 - width, 10.25 - width);
129 path.lineTo(2.50 + width, 10.25 - width);
130 path.lineTo(2.50 + width, 11.75 + width);
131 canvas->drawPath(path, paint);
132}
133
134
135
136} // namespace
137
138DEF_SIMPLE_GM(thinconcavepaths, canvas, 550, 400) {
140
141 paint.setAntiAlias(true);
142 paint.setStyle(SkPaint::kFill_Style);
143
144 canvas->save();
145 for (SkScalar width = 0.5f; width < 2.05f; width += 0.25f) {
146 draw_thin_stroked_rect(canvas, paint, width);
147 canvas->translate(0, 25);
148 }
149 canvas->restore();
150 canvas->translate(50, 0);
151 canvas->save();
152 for (SkScalar width = 0.5f; width < 2.05f; width += 0.25f) {
153 draw_thin_right_angle(canvas, paint, width);
154 canvas->translate(0, 25);
155 }
156 canvas->restore();
157 canvas->translate(40, 0);
158 canvas->save();
159 for (SkScalar width = 0.2f; width < 2.1f; width += 0.2f) {
160 draw_golf_club(canvas, paint, width);
161 canvas->translate(0, 30);
162 }
163 canvas->restore();
164 canvas->translate(70, 0);
165 canvas->save();
166 for (SkScalar width = 0.2f; width < 2.1f; width += 0.2f) {
167 draw_thin_rect_and_triangle(canvas, paint, width);
168 canvas->translate(0, 30);
169 }
170 canvas->restore();
171 canvas->translate(30, 0);
172 canvas->save();
173
174 for (SkScalar width = 0.2f; width < 2.1f; width += 0.2f) {
175 draw_barbell(canvas, paint, width);
176 canvas->translate(0, 30);
177 }
178 canvas->restore();
179 canvas->translate(80, 0);
180 canvas->save();
181 for (SkScalar width = 0.2f; width < 2.1f; width += 0.2f) {
182 draw_hipster_pants(canvas, paint, width);
183 canvas->translate(0, 30);
184 }
185 canvas->restore();
186 canvas->translate(100, 0);
187 canvas->save();
188 for (SkScalar width = 0.2f; width < 2.1f; width += 0.2f) {
189 draw_skinny_snake(canvas, paint, width);
190 canvas->translate(0, 30);
191 }
192 canvas->restore();
193 canvas->translate(30, 0);
194 canvas->save();
195 for (SkScalar width = 0.2f; width < 2.1f; width += 0.2f) {
196 draw_pointy_golf_club(canvas, paint, width);
197 canvas->translate(0, 30);
198 }
199 canvas->restore();
200 canvas->translate(100, 0);
201 canvas->save();
202 for (SkScalar width = 0.0f; width < 0.5f; width += 0.05f) {
203 draw_small_i(canvas, paint, width);
204 canvas->translate(0, 30);
205 }
206 canvas->restore();
207 canvas->translate(100, 0);
208}
void restore()
Definition SkCanvas.cpp:465
void translate(SkScalar dx, SkScalar dy)
int save()
Definition SkCanvas.cpp:451
void drawPath(const SkPath &path, const SkPaint &paint)
@ kFill_Style
set to fill geometry
Definition SkPaint.h:193
const Paint & paint
float SkScalar
Definition extension.cpp:12
#define DEF_SIMPLE_GM(NAME, CANVAS, W, H)
Definition gm.h:50
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition switches.h:57
int32_t width
Point offset