blob: 37af9126d0d991db592ce13e83806fc9d8627dcb [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -04009#include "include/core/SkCanvas.h"
10#include "include/core/SkColor.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkFont.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040012#include "include/core/SkPaint.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "include/core/SkPath.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040014#include "include/core/SkPoint.h"
15#include "include/core/SkTypes.h"
Mike Klein0aa05082018-12-12 12:37:56 -050016
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
Mike Klein1edcea92019-02-08 11:50:05 -050020static const int K = 49;
Mike Klein0aa05082018-12-12 12:37:56 -050021
Mike Klein1edcea92019-02-08 11:50:05 -050022DEF_SIMPLE_GM(daa, canvas, K+350, 5*K) {
Mike Klein0aa05082018-12-12 12:37:56 -050023 SkPaint paint;
24 paint.setAntiAlias(true);
25
Mike Klein1edcea92019-02-08 11:50:05 -050026 {
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);
Mike Klein0aa05082018-12-12 12:37:56 -050030
Mike Klein1edcea92019-02-08 11:50:05 -050031 paint.setColor(SK_ColorRED);
32 canvas->drawRect({0,0,K,K}, paint);
Mike Klein0aa05082018-12-12 12:37:56 -050033
Mike Klein1edcea92019-02-08 11:50:05 -050034 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);
Mike Klein0aa05082018-12-12 12:37:56 -050039
Mike Klein1edcea92019-02-08 11:50:05 -050040 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 }
Mike Klein0aa05082018-12-12 12:37:56 -0500135}