blob: 6338a4868eccd705e6b9ffa7652fdd2fb312ae35 [file] [log] [blame]
Mike Klein0aa05082018-12-12 12:37:56 -05001/*
2 * Copyright 2018 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 Reed1af9b482019-01-07 11:01:57 -05009#include "SkFont.h"
Mike Klein0aa05082018-12-12 12:37:56 -050010#include "SkPath.h"
11
12// This GM shows off a flaw in delta-based rasterizers (DAA, CCPR, etc.).
13// See also the bottom of dashing4 and skia:6886.
14
Mike Klein1edcea92019-02-08 11:50:05 -050015static const int K = 49;
Mike Klein0aa05082018-12-12 12:37:56 -050016
Mike Klein1edcea92019-02-08 11:50:05 -050017DEF_SIMPLE_GM(daa, canvas, K+350, 5*K) {
Mike Klein0aa05082018-12-12 12:37:56 -050018 SkPaint paint;
19 paint.setAntiAlias(true);
20
Mike Klein1edcea92019-02-08 11:50:05 -050021 {
22 paint.setColor(SK_ColorBLACK);
23 canvas->drawString("Should be a green square with no red showing through.",
24 K*1.5f, K*0.5f, SkFont(), paint);
Mike Klein0aa05082018-12-12 12:37:56 -050025
Mike Klein1edcea92019-02-08 11:50:05 -050026 paint.setColor(SK_ColorRED);
27 canvas->drawRect({0,0,K,K}, paint);
Mike Klein0aa05082018-12-12 12:37:56 -050028
Mike Klein1edcea92019-02-08 11:50:05 -050029 SkPath path;
30 SkPoint tri1[] = {{0,0},{K,K},{0,K},{0,0}};
31 SkPoint tri2[] = {{0,0},{K,K},{K,0},{0,0}};
32 path.addPoly(tri1, SK_ARRAY_COUNT(tri1), false);
33 path.addPoly(tri2, SK_ARRAY_COUNT(tri2), false);
Mike Klein0aa05082018-12-12 12:37:56 -050034
Mike Klein1edcea92019-02-08 11:50:05 -050035 paint.setColor(SK_ColorGREEN);
36 canvas->drawPath(path, paint);
37 }
38
39 canvas->translate(0,K);
40 {
41 paint.setColor(SK_ColorBLACK);
42 canvas->drawString("Adjacent rects, two draws. Blue then green, no red?",
43 K*1.5f, K*0.5f, SkFont(), paint);
44
45 paint.setColor(SK_ColorRED);
46 canvas->drawRect({0,0,K,K}, paint);
47
48 {
49 SkPath path;
50 SkPoint rect1[] = {{0,0},{0,K},{K*0.5f,K},{K*0.5f,0}};
51 path.addPoly(rect1, SK_ARRAY_COUNT(rect1), false);
52
53 paint.setColor(SK_ColorBLUE);
54 canvas->drawPath(path, paint);
55 }
56
57 {
58 SkPath path;
59 SkPoint rect2[] = {{K*0.5f,0},{K*0.5f,K},{K,K},{K,0}};
60 path.addPoly(rect2, SK_ARRAY_COUNT(rect2), false);
61
62 paint.setColor(SK_ColorGREEN);
63 canvas->drawPath(path, paint);
64 }
65 }
66
67 canvas->translate(0,K);
68 {
69 paint.setColor(SK_ColorBLACK);
70 canvas->drawString("Adjacent rects, wound together. All green?",
71 K*1.5f, K*0.5f, SkFont(), paint);
72
73 paint.setColor(SK_ColorRED);
74 canvas->drawRect({0,0,K,K}, paint);
75
76 {
77 SkPath path;
78 SkPoint rect1[] = {{0,0},{0,K},{K*0.5f,K},{K*0.5f,0}};
79 SkPoint rect2[] = {{K*0.5f,0},{K*0.5f,K},{K,K},{K,0}};
80
81 path.addPoly(rect1, SK_ARRAY_COUNT(rect1), false);
82 path.addPoly(rect2, SK_ARRAY_COUNT(rect2), false);
83
84 paint.setColor(SK_ColorGREEN);
85 canvas->drawPath(path, paint);
86 }
87 }
88
89 canvas->translate(0,K);
90 {
91 paint.setColor(SK_ColorBLACK);
92 canvas->drawString("Adjacent rects, wound opposite. All green?",
93 K*1.5f, K*0.5f, SkFont(), paint);
94
95 paint.setColor(SK_ColorRED);
96 canvas->drawRect({0,0,K,K}, paint);
97
98 {
99 SkPath path;
100 SkPoint rect1[] = {{0,0},{0,K},{K*0.5f,K},{K*0.5f,0}};
101 SkPoint rect2[] = {{K*0.5f,0},{K,0},{K,K},{K*0.5f,K}};
102
103 path.addPoly(rect1, SK_ARRAY_COUNT(rect1), false);
104 path.addPoly(rect2, SK_ARRAY_COUNT(rect2), false);
105
106 paint.setColor(SK_ColorGREEN);
107 canvas->drawPath(path, paint);
108 }
109 }
110
111 canvas->translate(0,K);
112 {
113 paint.setColor(SK_ColorBLACK);
114 canvas->drawString("One poly, wound opposite. All green?",
115 K*1.5f, K*0.5f, SkFont(), paint);
116
117 paint.setColor(SK_ColorRED);
118 canvas->drawRect({0,0,K,K}, paint);
119
120 {
121 SkPath path;
122 SkPoint poly[] = {{K*0.5f,0},{0,0},{0,K},{K*0.5f,K},{K*0.5f,0},{K,0},{K,K},{K*0.5f,K}};
123
124 path.addPoly(poly, SK_ARRAY_COUNT(poly), false);
125
126 paint.setColor(SK_ColorGREEN);
127 canvas->drawPath(path, paint);
128 }
129 }
Mike Klein0aa05082018-12-12 12:37:56 -0500130}