blob: c91488927956d4749252c2328cae593f13c55b4e [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"
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 SkPoint tri1[] = {{0,0},{K,K},{0,K},{0,0}};
35 SkPoint tri2[] = {{0,0},{K,K},{K,0},{0,0}};
Mike Reed92f6eb12020-08-25 11:48:41 -040036 SkPath path = SkPathBuilder().addPolygon(tri1, SK_ARRAY_COUNT(tri1), false)
37 .addPolygon(tri2, SK_ARRAY_COUNT(tri2), false)
38 .detach();
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 {
Mike Reed92f6eb12020-08-25 11:48:41 -040054 SkPath path = SkPath::Polygon({{0,0},{0,K},{K*0.5f,K},{K*0.5f,0}}, false);
Mike Klein1edcea92019-02-08 11:50:05 -050055 paint.setColor(SK_ColorBLUE);
56 canvas->drawPath(path, paint);
57 }
58
59 {
Mike Reed92f6eb12020-08-25 11:48:41 -040060 SkPath path = SkPath::Polygon({{K*0.5f,0},{K*0.5f,K},{K,K},{K,0}}, false);
Mike Klein1edcea92019-02-08 11:50:05 -050061 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 {
Mike Reed92f6eb12020-08-25 11:48:41 -040076 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();
Mike Klein1edcea92019-02-08 11:50:05 -050079
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 {
Mike Reed92f6eb12020-08-25 11:48:41 -040095 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();
Mike Klein1edcea92019-02-08 11:50:05 -050098
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
Mike Reed92f6eb12020-08-25 11:48:41 -0400113 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);
Mike Klein1edcea92019-02-08 11:50:05 -0500116
Mike Reed92f6eb12020-08-25 11:48:41 -0400117 paint.setColor(SK_ColorGREEN);
118 canvas->drawPath(path, paint);
Mike Klein1edcea92019-02-08 11:50:05 -0500119 }
Mike Klein0aa05082018-12-12 12:37:56 -0500120}