Mike Klein | 0aa0508 | 2018-12-12 12:37:56 -0500 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "gm/gm.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 9 | #include "include/core/SkCanvas.h" |
| 10 | #include "include/core/SkColor.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/core/SkFont.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 12 | #include "include/core/SkPaint.h" |
Mike Reed | 92f6eb1 | 2020-08-25 11:48:41 -0400 | [diff] [blame] | 13 | #include "include/core/SkPathBuilder.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 14 | #include "include/core/SkPoint.h" |
| 15 | #include "include/core/SkTypes.h" |
Kevin Lubick | bca43ec | 2023-10-30 10:11:22 -0400 | [diff] [blame] | 16 | #include "tools/fonts/FontToolUtils.h" |
Mike Klein | 0aa0508 | 2018-12-12 12:37:56 -0500 | [diff] [blame] | 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 | |
Mike Klein | 1edcea9 | 2019-02-08 11:50:05 -0500 | [diff] [blame] | 21 | static const int K = 49; |
Mike Klein | 0aa0508 | 2018-12-12 12:37:56 -0500 | [diff] [blame] | 22 | |
Mike Klein | 1edcea9 | 2019-02-08 11:50:05 -0500 | [diff] [blame] | 23 | DEF_SIMPLE_GM(daa, canvas, K+350, 5*K) { |
Mike Klein | 0aa0508 | 2018-12-12 12:37:56 -0500 | [diff] [blame] | 24 | SkPaint paint; |
| 25 | paint.setAntiAlias(true); |
Kevin Lubick | bca43ec | 2023-10-30 10:11:22 -0400 | [diff] [blame] | 26 | SkFont font = ToolUtils::DefaultPortableFont(); |
Mike Klein | 0aa0508 | 2018-12-12 12:37:56 -0500 | [diff] [blame] | 27 | |
Mike Klein | 1edcea9 | 2019-02-08 11:50:05 -0500 | [diff] [blame] | 28 | { |
| 29 | paint.setColor(SK_ColorBLACK); |
| 30 | canvas->drawString("Should be a green square with no red showing through.", |
Kevin Lubick | bca43ec | 2023-10-30 10:11:22 -0400 | [diff] [blame] | 31 | K*1.5f, K*0.5f, font, paint); |
Mike Klein | 0aa0508 | 2018-12-12 12:37:56 -0500 | [diff] [blame] | 32 | |
Mike Klein | 1edcea9 | 2019-02-08 11:50:05 -0500 | [diff] [blame] | 33 | paint.setColor(SK_ColorRED); |
| 34 | canvas->drawRect({0,0,K,K}, paint); |
Mike Klein | 0aa0508 | 2018-12-12 12:37:56 -0500 | [diff] [blame] | 35 | |
Mike Klein | 1edcea9 | 2019-02-08 11:50:05 -0500 | [diff] [blame] | 36 | SkPoint tri1[] = {{0,0},{K,K},{0,K},{0,0}}; |
| 37 | SkPoint tri2[] = {{0,0},{K,K},{K,0},{0,0}}; |
Herb Derby | c37b386 | 2022-06-21 09:49:17 -0400 | [diff] [blame] | 38 | SkPath path = SkPathBuilder().addPolygon(tri1, std::size(tri1), false) |
| 39 | .addPolygon(tri2, std::size(tri2), false) |
Mike Reed | 92f6eb1 | 2020-08-25 11:48:41 -0400 | [diff] [blame] | 40 | .detach(); |
Mike Klein | 0aa0508 | 2018-12-12 12:37:56 -0500 | [diff] [blame] | 41 | |
Mike Klein | 1edcea9 | 2019-02-08 11:50:05 -0500 | [diff] [blame] | 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?", |
Kevin Lubick | bca43ec | 2023-10-30 10:11:22 -0400 | [diff] [blame] | 50 | K*1.5f, K*0.5f, font, paint); |
Mike Klein | 1edcea9 | 2019-02-08 11:50:05 -0500 | [diff] [blame] | 51 | |
| 52 | paint.setColor(SK_ColorRED); |
| 53 | canvas->drawRect({0,0,K,K}, paint); |
| 54 | |
| 55 | { |
Mike Reed | 92f6eb1 | 2020-08-25 11:48:41 -0400 | [diff] [blame] | 56 | SkPath path = SkPath::Polygon({{0,0},{0,K},{K*0.5f,K},{K*0.5f,0}}, false); |
Mike Klein | 1edcea9 | 2019-02-08 11:50:05 -0500 | [diff] [blame] | 57 | paint.setColor(SK_ColorBLUE); |
| 58 | canvas->drawPath(path, paint); |
| 59 | } |
| 60 | |
| 61 | { |
Mike Reed | 92f6eb1 | 2020-08-25 11:48:41 -0400 | [diff] [blame] | 62 | SkPath path = SkPath::Polygon({{K*0.5f,0},{K*0.5f,K},{K,K},{K,0}}, false); |
Mike Klein | 1edcea9 | 2019-02-08 11:50:05 -0500 | [diff] [blame] | 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?", |
Kevin Lubick | bca43ec | 2023-10-30 10:11:22 -0400 | [diff] [blame] | 72 | K*1.5f, K*0.5f, font, paint); |
Mike Klein | 1edcea9 | 2019-02-08 11:50:05 -0500 | [diff] [blame] | 73 | |
| 74 | paint.setColor(SK_ColorRED); |
| 75 | canvas->drawRect({0,0,K,K}, paint); |
| 76 | |
| 77 | { |
Mike Reed | 92f6eb1 | 2020-08-25 11:48:41 -0400 | [diff] [blame] | 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(); |
Mike Klein | 1edcea9 | 2019-02-08 11:50:05 -0500 | [diff] [blame] | 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?", |
Kevin Lubick | bca43ec | 2023-10-30 10:11:22 -0400 | [diff] [blame] | 91 | K*1.5f, K*0.5f, font, paint); |
Mike Klein | 1edcea9 | 2019-02-08 11:50:05 -0500 | [diff] [blame] | 92 | |
| 93 | paint.setColor(SK_ColorRED); |
| 94 | canvas->drawRect({0,0,K,K}, paint); |
| 95 | |
| 96 | { |
Mike Reed | 92f6eb1 | 2020-08-25 11:48:41 -0400 | [diff] [blame] | 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(); |
Mike Klein | 1edcea9 | 2019-02-08 11:50:05 -0500 | [diff] [blame] | 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?", |
Kevin Lubick | bca43ec | 2023-10-30 10:11:22 -0400 | [diff] [blame] | 110 | K*1.5f, K*0.5f, font, paint); |
Mike Klein | 1edcea9 | 2019-02-08 11:50:05 -0500 | [diff] [blame] | 111 | |
| 112 | paint.setColor(SK_ColorRED); |
| 113 | canvas->drawRect({0,0,K,K}, paint); |
| 114 | |
Mike Reed | 92f6eb1 | 2020-08-25 11:48:41 -0400 | [diff] [blame] | 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); |
Mike Klein | 1edcea9 | 2019-02-08 11:50:05 -0500 | [diff] [blame] | 118 | |
Mike Reed | 92f6eb1 | 2020-08-25 11:48:41 -0400 | [diff] [blame] | 119 | paint.setColor(SK_ColorGREEN); |
| 120 | canvas->drawPath(path, paint); |
Mike Klein | 1edcea9 | 2019-02-08 11:50:05 -0500 | [diff] [blame] | 121 | } |
Mike Klein | 0aa0508 | 2018-12-12 12:37:56 -0500 | [diff] [blame] | 122 | } |