blob: 02cb3a8f5778e6e7fa67d6a25a2f1a8b6b6355c8 [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 Reed92f6eb12020-08-25 11:48:41 -040013#include "include/core/SkPathBuilder.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040014#include "include/core/SkPoint.h"
15#include "include/core/SkTypes.h"
Kevin Lubickbca43ec2023-10-30 10:11:22 -040016#include "tools/fonts/FontToolUtils.h"
Mike Klein0aa05082018-12-12 12:37:56 -050017
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
Mike Klein1edcea92019-02-08 11:50:05 -050021static const int K = 49;
Mike Klein0aa05082018-12-12 12:37:56 -050022
Mike Klein1edcea92019-02-08 11:50:05 -050023DEF_SIMPLE_GM(daa, canvas, K+350, 5*K) {
Mike Klein0aa05082018-12-12 12:37:56 -050024 SkPaint paint;
25 paint.setAntiAlias(true);
Kevin Lubickbca43ec2023-10-30 10:11:22 -040026 SkFont font = ToolUtils::DefaultPortableFont();
Mike Klein0aa05082018-12-12 12:37:56 -050027
Mike Klein1edcea92019-02-08 11:50:05 -050028 {
29 paint.setColor(SK_ColorBLACK);
30 canvas->drawString("Should be a green square with no red showing through.",
Kevin Lubickbca43ec2023-10-30 10:11:22 -040031 K*1.5f, K*0.5f, font, paint);
Mike Klein0aa05082018-12-12 12:37:56 -050032
Mike Klein1edcea92019-02-08 11:50:05 -050033 paint.setColor(SK_ColorRED);
34 canvas->drawRect({0,0,K,K}, paint);
Mike Klein0aa05082018-12-12 12:37:56 -050035
Mike Klein1edcea92019-02-08 11:50:05 -050036 SkPoint tri1[] = {{0,0},{K,K},{0,K},{0,0}};
37 SkPoint tri2[] = {{0,0},{K,K},{K,0},{0,0}};
Herb Derbyc37b3862022-06-21 09:49:17 -040038 SkPath path = SkPathBuilder().addPolygon(tri1, std::size(tri1), false)
39 .addPolygon(tri2, std::size(tri2), false)
Mike Reed92f6eb12020-08-25 11:48:41 -040040 .detach();
Mike Klein0aa05082018-12-12 12:37:56 -050041
Mike Klein1edcea92019-02-08 11:50:05 -050042 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?",
Kevin Lubickbca43ec2023-10-30 10:11:22 -040050 K*1.5f, K*0.5f, font, paint);
Mike Klein1edcea92019-02-08 11:50:05 -050051
52 paint.setColor(SK_ColorRED);
53 canvas->drawRect({0,0,K,K}, paint);
54
55 {
Mike Reed92f6eb12020-08-25 11:48:41 -040056 SkPath path = SkPath::Polygon({{0,0},{0,K},{K*0.5f,K},{K*0.5f,0}}, false);
Mike Klein1edcea92019-02-08 11:50:05 -050057 paint.setColor(SK_ColorBLUE);
58 canvas->drawPath(path, paint);
59 }
60
61 {
Mike Reed92f6eb12020-08-25 11:48:41 -040062 SkPath path = SkPath::Polygon({{K*0.5f,0},{K*0.5f,K},{K,K},{K,0}}, false);
Mike Klein1edcea92019-02-08 11:50:05 -050063 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?",
Kevin Lubickbca43ec2023-10-30 10:11:22 -040072 K*1.5f, K*0.5f, font, paint);
Mike Klein1edcea92019-02-08 11:50:05 -050073
74 paint.setColor(SK_ColorRED);
75 canvas->drawRect({0,0,K,K}, paint);
76
77 {
Mike Reed92f6eb12020-08-25 11:48:41 -040078 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();
Mike Klein1edcea92019-02-08 11:50:05 -050081
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?",
Kevin Lubickbca43ec2023-10-30 10:11:22 -040091 K*1.5f, K*0.5f, font, paint);
Mike Klein1edcea92019-02-08 11:50:05 -050092
93 paint.setColor(SK_ColorRED);
94 canvas->drawRect({0,0,K,K}, paint);
95
96 {
Mike Reed92f6eb12020-08-25 11:48:41 -040097 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();
Mike Klein1edcea92019-02-08 11:50:05 -0500100
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?",
Kevin Lubickbca43ec2023-10-30 10:11:22 -0400110 K*1.5f, K*0.5f, font, paint);
Mike Klein1edcea92019-02-08 11:50:05 -0500111
112 paint.setColor(SK_ColorRED);
113 canvas->drawRect({0,0,K,K}, paint);
114
Mike Reed92f6eb12020-08-25 11:48:41 -0400115 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);
Mike Klein1edcea92019-02-08 11:50:05 -0500118
Mike Reed92f6eb12020-08-25 11:48:41 -0400119 paint.setColor(SK_ColorGREEN);
120 canvas->drawPath(path, paint);
Mike Klein1edcea92019-02-08 11:50:05 -0500121 }
Mike Klein0aa05082018-12-12 12:37:56 -0500122}