Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
daa.cpp
Go to the documentation of this file.
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"
11#include "include/core/SkFont.h"
17
18// This GM shows off a flaw in delta-based rasterizers (DAA, CCPR, etc.).
19// See also the bottom of dashing4 and skia:6886.
20
21static const int K = 49;
22
23DEF_SIMPLE_GM(daa, canvas, K+350, 5*K) {
25 paint.setAntiAlias(true);
27
28 {
29 paint.setColor(SK_ColorBLACK);
30 canvas->drawString("Should be a green square with no red showing through.",
31 K*1.5f, K*0.5f, font, paint);
32
33 paint.setColor(SK_ColorRED);
34 canvas->drawRect({0,0,K,K}, paint);
35
36 SkPoint tri1[] = {{0,0},{K,K},{0,K},{0,0}};
37 SkPoint tri2[] = {{0,0},{K,K},{K,0},{0,0}};
38 SkPath path = SkPathBuilder().addPolygon(tri1, std::size(tri1), false)
39 .addPolygon(tri2, std::size(tri2), false)
40 .detach();
41
42 paint.setColor(SK_ColorGREEN);
43 canvas->drawPath(path, paint);
44 }
45
46 canvas->translate(0,K);
47 {
48 paint.setColor(SK_ColorBLACK);
49 canvas->drawString("Adjacent rects, two draws. Blue then green, no red?",
50 K*1.5f, K*0.5f, font, paint);
51
52 paint.setColor(SK_ColorRED);
53 canvas->drawRect({0,0,K,K}, paint);
54
55 {
56 SkPath path = SkPath::Polygon({{0,0},{0,K},{K*0.5f,K},{K*0.5f,0}}, false);
57 paint.setColor(SK_ColorBLUE);
58 canvas->drawPath(path, paint);
59 }
60
61 {
62 SkPath path = SkPath::Polygon({{K*0.5f,0},{K*0.5f,K},{K,K},{K,0}}, false);
63 paint.setColor(SK_ColorGREEN);
64 canvas->drawPath(path, paint);
65 }
66 }
67
68 canvas->translate(0,K);
69 {
70 paint.setColor(SK_ColorBLACK);
71 canvas->drawString("Adjacent rects, wound together. All green?",
72 K*1.5f, K*0.5f, font, paint);
73
74 paint.setColor(SK_ColorRED);
75 canvas->drawRect({0,0,K,K}, paint);
76
77 {
78 SkPath path = SkPathBuilder().addPolygon({{0,0},{0,K},{K*0.5f,K},{K*0.5f,0}}, false)
79 .addPolygon({{K*0.5f,0},{K*0.5f,K},{K,K},{K,0}}, false)
80 .detach();
81
82 paint.setColor(SK_ColorGREEN);
83 canvas->drawPath(path, paint);
84 }
85 }
86
87 canvas->translate(0,K);
88 {
89 paint.setColor(SK_ColorBLACK);
90 canvas->drawString("Adjacent rects, wound opposite. All green?",
91 K*1.5f, K*0.5f, font, paint);
92
93 paint.setColor(SK_ColorRED);
94 canvas->drawRect({0,0,K,K}, paint);
95
96 {
97 SkPath path = SkPathBuilder().addPolygon({{0,0},{0,K},{K*0.5f,K},{K*0.5f,0}}, false)
98 .addPolygon({{K*0.5f,0},{K,0},{K,K},{K*0.5f,K}}, false)
99 .detach();
100
101 paint.setColor(SK_ColorGREEN);
102 canvas->drawPath(path, paint);
103 }
104 }
105
106 canvas->translate(0,K);
107 {
108 paint.setColor(SK_ColorBLACK);
109 canvas->drawString("One poly, wound opposite. All green?",
110 K*1.5f, K*0.5f, font, paint);
111
112 paint.setColor(SK_ColorRED);
113 canvas->drawRect({0,0,K,K}, paint);
114
115 SkPath path = SkPath::Polygon({{K*0.5f,0},{0,0},{0,K},{K*0.5f,K},
116 {K*0.5f,0},{K,0},{K,K},{K*0.5f,K}},
117 false);
118
119 paint.setColor(SK_ColorGREEN);
120 canvas->drawPath(path, paint);
121 }
122}
constexpr SkColor SK_ColorBLUE
Definition SkColor.h:135
constexpr SkColor SK_ColorRED
Definition SkColor.h:126
constexpr SkColor SK_ColorBLACK
Definition SkColor.h:103
constexpr SkColor SK_ColorGREEN
Definition SkColor.h:131
SkPathBuilder & addPolygon(const SkPoint pts[], int count, bool isClosed)
static SkPath Polygon(const SkPoint pts[], int count, bool isClosed, SkPathFillType=SkPathFillType::kWinding, bool isVolatile=false)
Definition SkPath.cpp:3546
const Paint & paint
static const int K
Definition daa.cpp:21
#define DEF_SIMPLE_GM(NAME, CANVAS, W, H)
Definition gm.h:50
SkFont DefaultPortableFont()