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" |
Mike Klein | 0aa0508 | 2018-12-12 12:37:56 -0500 | [diff] [blame] | 16 | |
| 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 Klein | 1edcea9 | 2019-02-08 11:50:05 -0500 | [diff] [blame] | 20 | static const int K = 49; |
Mike Klein | 0aa0508 | 2018-12-12 12:37:56 -0500 | [diff] [blame] | 21 | |
Mike Klein | 1edcea9 | 2019-02-08 11:50:05 -0500 | [diff] [blame] | 22 | DEF_SIMPLE_GM(daa, canvas, K+350, 5*K) { |
Mike Klein | 0aa0508 | 2018-12-12 12:37:56 -0500 | [diff] [blame] | 23 | SkPaint paint; |
| 24 | paint.setAntiAlias(true); |
| 25 | |
Mike Klein | 1edcea9 | 2019-02-08 11:50:05 -0500 | [diff] [blame] | 26 | { |
| 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 Klein | 0aa0508 | 2018-12-12 12:37:56 -0500 | [diff] [blame] | 30 | |
Mike Klein | 1edcea9 | 2019-02-08 11:50:05 -0500 | [diff] [blame] | 31 | paint.setColor(SK_ColorRED); |
| 32 | canvas->drawRect({0,0,K,K}, paint); |
Mike Klein | 0aa0508 | 2018-12-12 12:37:56 -0500 | [diff] [blame] | 33 | |
Mike Klein | 1edcea9 | 2019-02-08 11:50:05 -0500 | [diff] [blame] | 34 | SkPoint tri1[] = {{0,0},{K,K},{0,K},{0,0}}; |
| 35 | SkPoint tri2[] = {{0,0},{K,K},{K,0},{0,0}}; |
Mike Reed | 92f6eb1 | 2020-08-25 11:48:41 -0400 | [diff] [blame] | 36 | SkPath path = SkPathBuilder().addPolygon(tri1, SK_ARRAY_COUNT(tri1), false) |
| 37 | .addPolygon(tri2, SK_ARRAY_COUNT(tri2), false) |
| 38 | .detach(); |
Mike Klein | 0aa0508 | 2018-12-12 12:37:56 -0500 | [diff] [blame] | 39 | |
Mike Klein | 1edcea9 | 2019-02-08 11:50:05 -0500 | [diff] [blame] | 40 | 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 Reed | 92f6eb1 | 2020-08-25 11:48:41 -0400 | [diff] [blame] | 54 | 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] | 55 | paint.setColor(SK_ColorBLUE); |
| 56 | canvas->drawPath(path, paint); |
| 57 | } |
| 58 | |
| 59 | { |
Mike Reed | 92f6eb1 | 2020-08-25 11:48:41 -0400 | [diff] [blame] | 60 | 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] | 61 | 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 Reed | 92f6eb1 | 2020-08-25 11:48:41 -0400 | [diff] [blame] | 76 | 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 Klein | 1edcea9 | 2019-02-08 11:50:05 -0500 | [diff] [blame] | 79 | |
| 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 Reed | 92f6eb1 | 2020-08-25 11:48:41 -0400 | [diff] [blame] | 95 | 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 Klein | 1edcea9 | 2019-02-08 11:50:05 -0500 | [diff] [blame] | 98 | |
| 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 Reed | 92f6eb1 | 2020-08-25 11:48:41 -0400 | [diff] [blame] | 113 | 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 Klein | 1edcea9 | 2019-02-08 11:50:05 -0500 | [diff] [blame] | 116 | |
Mike Reed | 92f6eb1 | 2020-08-25 11:48:41 -0400 | [diff] [blame] | 117 | paint.setColor(SK_ColorGREEN); |
| 118 | canvas->drawPath(path, paint); |
Mike Klein | 1edcea9 | 2019-02-08 11:50:05 -0500 | [diff] [blame] | 119 | } |
Mike Klein | 0aa0508 | 2018-12-12 12:37:56 -0500 | [diff] [blame] | 120 | } |