• 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/SkPathBuilder.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         SkPoint tri1[] = {{0,0},{K,K},{0,K},{0,0}};
35         SkPoint tri2[] = {{0,0},{K,K},{K,0},{0,0}};
36         SkPath path = SkPathBuilder().addPolygon(tri1, SK_ARRAY_COUNT(tri1), false)
37                                      .addPolygon(tri2, SK_ARRAY_COUNT(tri2), false)
38                                      .detach();
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 = SkPath::Polygon({{0,0},{0,K},{K*0.5f,K},{K*0.5f,0}}, false);
55             paint.setColor(SK_ColorBLUE);
56             canvas->drawPath(path, paint);
57         }
58 
59         {
60             SkPath path = SkPath::Polygon({{K*0.5f,0},{K*0.5f,K},{K,K},{K,0}}, false);
61             paint.setColor(SK_ColorGREEN);
62             canvas->drawPath(path, paint);
63         }
64     }
65 
66     canvas->translate(0,K);
67     {
68         paint.setColor(SK_ColorBLACK);
69         canvas->drawString("Adjacent rects, wound together.  All green?",
70                            K*1.5f, K*0.5f, SkFont(), paint);
71 
72         paint.setColor(SK_ColorRED);
73         canvas->drawRect({0,0,K,K}, paint);
74 
75         {
76             SkPath path = SkPathBuilder().addPolygon({{0,0},{0,K},{K*0.5f,K},{K*0.5f,0}}, false)
77                                          .addPolygon({{K*0.5f,0},{K*0.5f,K},{K,K},{K,0}}, false)
78                                          .detach();
79 
80             paint.setColor(SK_ColorGREEN);
81             canvas->drawPath(path, paint);
82         }
83     }
84 
85     canvas->translate(0,K);
86     {
87         paint.setColor(SK_ColorBLACK);
88         canvas->drawString("Adjacent rects, wound opposite.  All green?",
89                            K*1.5f, K*0.5f, SkFont(), paint);
90 
91         paint.setColor(SK_ColorRED);
92         canvas->drawRect({0,0,K,K}, paint);
93 
94         {
95             SkPath path = SkPathBuilder().addPolygon({{0,0},{0,K},{K*0.5f,K},{K*0.5f,0}}, false)
96                                          .addPolygon({{K*0.5f,0},{K,0},{K,K},{K*0.5f,K}}, false)
97                                          .detach();
98 
99             paint.setColor(SK_ColorGREEN);
100             canvas->drawPath(path, paint);
101         }
102     }
103 
104     canvas->translate(0,K);
105     {
106         paint.setColor(SK_ColorBLACK);
107         canvas->drawString("One poly, wound opposite.  All green?",
108                            K*1.5f, K*0.5f, SkFont(), paint);
109 
110         paint.setColor(SK_ColorRED);
111         canvas->drawRect({0,0,K,K}, paint);
112 
113         SkPath path = SkPath::Polygon({{K*0.5f,0},{0,0},{0,K},{K*0.5f,K},
114                                        {K*0.5f,0},{K,0},{K,K},{K*0.5f,K}},
115                                       false);
116 
117         paint.setColor(SK_ColorGREEN);
118         canvas->drawPath(path, paint);
119     }
120 }
121