blob: 9364ed73b67d851a36ab128c9887f41f315a5920 [file] [log] [blame]
Chris Daltondb5210f2019-07-24 11:27:15 -04001/*
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
10#include "include/core/SkCanvas.h"
Chris Daltondb5210f2019-07-24 11:27:15 -040011#include "include/core/SkPaint.h"
Mike Reede9d783c2020-08-17 14:14:13 -040012#include "include/core/SkPathBuilder.h"
Chris Daltondb5210f2019-07-24 11:27:15 -040013
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
Mike Reede9d783c2020-08-17 14:14:13 -040055 SkPathBuilder maze;
Chris Daltondb5210f2019-07-24 11:27:15 -040056 for (size_t y = 0; y < SK_ARRAY_COUNT(kRows); ++y) {
57 for (size_t x = 0; x < SK_ARRAY_COUNT(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 < SK_ARRAY_COUNT(kCols); ++x) {
65 for (size_t y = 0; y < SK_ARRAY_COUNT(kCols[0]); ++y) {
66 if (kCols[x][y]) {
67 maze.moveTo(x, y);
68 maze.lineTo(x, y+1);
69 }
70 }
71 }
72
73 SkPaint paint;
74 paint.setStyle(SkPaint::kStroke_Style);
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);
Mike Reede9d783c2020-08-17 14:14:13 -040082 canvas->drawPath(maze.detach(), paint);
Chris Daltondb5210f2019-07-24 11:27:15 -040083}
84
85constexpr static int kWidth = 500;
86constexpr static int kHeight = 420;
87
88DEF_SIMPLE_GM(labyrinth_square, canvas, kWidth, kHeight) {
89 draw_labyrinth(canvas, SkPaint::kSquare_Cap);
90}
91
92DEF_SIMPLE_GM(labyrinth_round, canvas, kWidth, kHeight) {
93 draw_labyrinth(canvas, SkPaint::kRound_Cap);
94}
95
96DEF_SIMPLE_GM(labyrinth_butt, canvas, kWidth, kHeight) {
97 draw_labyrinth(canvas, SkPaint::kButt_Cap);
98}