Flutter Engine
The Flutter Engine
labyrinth.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2019 Google LLC.
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
13
14/**
15 * Repro case for https://bugs.chromium.org/p/chromium/issues/detail?id=913223
16 *
17 * The original bug was filed against square caps, but here we also draw the labyrinth using round
18 * and butt caps.
19 *
20 * Square and round caps expose over-coverage on overlaps when using coverage counting.
21 *
22 * Butt caps expose under-coverage on abutted strokes when using a 'max()' coverage function.
23 */
24static void draw_labyrinth(SkCanvas* canvas, SkPaint::Cap cap) {
25 constexpr static bool kRows[11][12] = {
26 {1,1,1,1,1,1,1,1,1,1,1,1},
27 {0,1,0,1,0,1,0,0,0,0,1,1},
28 {0,0,0,0,1,0,0,0,0,1,1,1},
29 {1,0,1,0,0,0,0,1,0,0,0,0},
30 {0,1,1,0,0,0,0,0,0,1,1,1},
31 {1,0,0,1,0,0,0,0,1,1,1,0},
32 {0,1,0,1,1,1,0,0,1,1,1,0},
33 {1,0,1,0,1,1,1,1,0,1,1,1},
34 {0,0,1,0,0,1,0,0,0,0,0,1},
35 {0,1,1,1,0,0,1,1,1,1,0,0},
36 {1,1,1,1,1,1,1,1,1,1,1,1},
37 };
38
39 constexpr static bool kCols[13][10] = {
40 {1,1,1,1,0,1,1,1,1,1},
41 {0,0,1,0,0,0,1,1,1,0},
42 {0,1,1,0,1,1,1,0,0,1},
43 {1,1,0,0,0,0,1,0,1,0},
44 {0,0,1,0,1,0,0,0,0,1},
45 {0,0,1,1,1,0,0,0,1,0},
46 {0,1,0,1,1,1,0,0,0,0},
47 {1,1,1,0,1,1,1,0,1,0},
48 {1,1,0,1,1,0,0,0,1,0},
49 {0,0,1,0,0,0,0,0,0,1},
50 {0,0,1,1,0,0,0,0,1,0},
51 {0,0,0,0,0,0,1,0,0,1},
52 {1,1,1,1,1,1,0,1,1,1},
53 };
54
55 SkPathBuilder maze;
56 for (size_t y = 0; y < std::size(kRows); ++y) {
57 for (size_t x = 0; x < std::size(kRows[0]); ++x) {
58 if (kRows[y][x]) {
59 maze.moveTo(x, y);
60 maze.lineTo(x+1, y);
61 }
62 }
63 }
64 for (size_t x = 0; x < std::size(kCols); ++x) {
65 for (size_t y = 0; y < std::size(kCols[0]); ++y) {
66 if (kCols[x][y]) {
67 maze.moveTo(x, y);
68 maze.lineTo(x, y+1);
69 }
70 }
71 }
72
75 paint.setStrokeWidth(.1f);
76 paint.setColor(0xff406060);
77 paint.setAntiAlias(true);
78 paint.setStrokeCap(cap);
79
80 canvas->translate(10.5, 10.5);
81 canvas->scale(40, 40);
82 canvas->drawPath(maze.detach(), paint);
83}
84
85constexpr static int kWidth = 500;
86constexpr static int kHeight = 420;
87
88DEF_SIMPLE_GM(labyrinth_square, canvas, kWidth, kHeight) {
90}
91
92DEF_SIMPLE_GM(labyrinth_round, canvas, kWidth, kHeight) {
94}
95
96DEF_SIMPLE_GM(labyrinth_butt, canvas, kWidth, kHeight) {
98}
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
void scale(SkScalar sx, SkScalar sy)
Definition: SkCanvas.cpp:1289
@ kRound_Cap
adds circle
Definition: SkPaint.h:335
@ kButt_Cap
no stroke extension
Definition: SkPaint.h:334
@ kSquare_Cap
adds square
Definition: SkPaint.h:336
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
SkPathBuilder & lineTo(SkPoint pt)
SkPathBuilder & moveTo(SkPoint pt)
const Paint & paint
Definition: color_source.cc:38
static void draw_labyrinth(SkCanvas *canvas, SkPaint::Cap cap)
Definition: labyrinth.cpp:24
DEF_SIMPLE_GM(labyrinth_square, canvas, kWidth, kHeight)
Definition: labyrinth.cpp:88
static constexpr int kWidth
Definition: labyrinth.cpp:85
static constexpr int kHeight
Definition: labyrinth.cpp:86
double y
double x
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259