• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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"
9 #include "SkFont.h"
10 #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 
15 static const int K = 49;
16 
17 DEF_SIMPLE_GM(daa, canvas, K+350, 5*K) {
18     SkPaint paint;
19     paint.setAntiAlias(true);
20 
21     {
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);
25 
26         paint.setColor(SK_ColorRED);
27         canvas->drawRect({0,0,K,K}, paint);
28 
29         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);
34 
35         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     }
130 }
131