• Home
  • 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/gm.h"
9 #include "include/core/SkCanvas.h"
10 #include "include/core/SkColor.h"
11 #include "include/core/SkFont.h"
12 #include "include/core/SkPaint.h"
13 #include "include/core/SkPath.h"
14 #include "include/core/SkPoint.h"
15 #include "include/core/SkTypes.h"
16 
17 // This GM shows off a flaw in delta-based rasterizers (DAA, CCPR, etc.).
18 // See also the bottom of dashing4 and skia:6886.
19 
20 static const int K = 49;
21 
22 DEF_SIMPLE_GM(daa, canvas, K+350, 5*K) {
23     SkPaint paint;
24     paint.setAntiAlias(true);
25 
26     {
27         paint.setColor(SK_ColorBLACK);
28         canvas->drawString("Should be a green square with no red showing through.",
29                            K*1.5f, K*0.5f, SkFont(), paint);
30 
31         paint.setColor(SK_ColorRED);
32         canvas->drawRect({0,0,K,K}, paint);
33 
34         SkPath path;
35         SkPoint tri1[] = {{0,0},{K,K},{0,K},{0,0}};
36         SkPoint tri2[] = {{0,0},{K,K},{K,0},{0,0}};
37         path.addPoly(tri1, SK_ARRAY_COUNT(tri1), false);
38         path.addPoly(tri2, SK_ARRAY_COUNT(tri2), false);
39 
40         paint.setColor(SK_ColorGREEN);
41         canvas->drawPath(path, paint);
42     }
43 
44     canvas->translate(0,K);
45     {
46         paint.setColor(SK_ColorBLACK);
47         canvas->drawString("Adjacent rects, two draws.  Blue then green, no red?",
48                            K*1.5f, K*0.5f, SkFont(), paint);
49 
50         paint.setColor(SK_ColorRED);
51         canvas->drawRect({0,0,K,K}, paint);
52 
53         {
54             SkPath path;
55             SkPoint rect1[] = {{0,0},{0,K},{K*0.5f,K},{K*0.5f,0}};
56             path.addPoly(rect1, SK_ARRAY_COUNT(rect1), false);
57 
58             paint.setColor(SK_ColorBLUE);
59             canvas->drawPath(path, paint);
60         }
61 
62         {
63             SkPath path;
64             SkPoint rect2[] = {{K*0.5f,0},{K*0.5f,K},{K,K},{K,0}};
65             path.addPoly(rect2, SK_ARRAY_COUNT(rect2), false);
66 
67             paint.setColor(SK_ColorGREEN);
68             canvas->drawPath(path, paint);
69         }
70     }
71 
72     canvas->translate(0,K);
73     {
74         paint.setColor(SK_ColorBLACK);
75         canvas->drawString("Adjacent rects, wound together.  All green?",
76                            K*1.5f, K*0.5f, SkFont(), paint);
77 
78         paint.setColor(SK_ColorRED);
79         canvas->drawRect({0,0,K,K}, paint);
80 
81         {
82             SkPath path;
83             SkPoint rect1[] = {{0,0},{0,K},{K*0.5f,K},{K*0.5f,0}};
84             SkPoint rect2[] = {{K*0.5f,0},{K*0.5f,K},{K,K},{K,0}};
85 
86             path.addPoly(rect1, SK_ARRAY_COUNT(rect1), false);
87             path.addPoly(rect2, SK_ARRAY_COUNT(rect2), false);
88 
89             paint.setColor(SK_ColorGREEN);
90             canvas->drawPath(path, paint);
91         }
92     }
93 
94     canvas->translate(0,K);
95     {
96         paint.setColor(SK_ColorBLACK);
97         canvas->drawString("Adjacent rects, wound opposite.  All green?",
98                            K*1.5f, K*0.5f, SkFont(), paint);
99 
100         paint.setColor(SK_ColorRED);
101         canvas->drawRect({0,0,K,K}, paint);
102 
103         {
104             SkPath path;
105             SkPoint rect1[] = {{0,0},{0,K},{K*0.5f,K},{K*0.5f,0}};
106             SkPoint rect2[] = {{K*0.5f,0},{K,0},{K,K},{K*0.5f,K}};
107 
108             path.addPoly(rect1, SK_ARRAY_COUNT(rect1), false);
109             path.addPoly(rect2, SK_ARRAY_COUNT(rect2), false);
110 
111             paint.setColor(SK_ColorGREEN);
112             canvas->drawPath(path, paint);
113         }
114     }
115 
116     canvas->translate(0,K);
117     {
118         paint.setColor(SK_ColorBLACK);
119         canvas->drawString("One poly, wound opposite.  All green?",
120                            K*1.5f, K*0.5f, SkFont(), paint);
121 
122         paint.setColor(SK_ColorRED);
123         canvas->drawRect({0,0,K,K}, paint);
124 
125         {
126             SkPath path;
127             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}};
128 
129             path.addPoly(poly, SK_ARRAY_COUNT(poly), false);
130 
131             paint.setColor(SK_ColorGREEN);
132             canvas->drawPath(path, paint);
133         }
134     }
135 }
136