mtklein | 7005a57 | 2015-05-21 10:33:09 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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/SkBlendMode.h" |
| 10 | #include "include/core/SkCanvas.h" |
| 11 | #include "include/core/SkColor.h" |
| 12 | #include "include/core/SkPaint.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "include/core/SkPath.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 14 | #include "include/core/SkRect.h" |
mtklein | 7005a57 | 2015-05-21 10:33:09 -0700 | [diff] [blame] | 15 | |
| 16 | DEF_SIMPLE_GM(PlusMergesAA, canvas, 256, 256) { |
| 17 | SkPaint p; |
| 18 | p.setColor(SK_ColorRED); |
| 19 | p.setAntiAlias(true); // <-- crucial to the test that we use AA |
| 20 | |
| 21 | // Draw a two red squares. |
| 22 | canvas->drawRect(SkRect::MakeWH(100, 100), p); |
| 23 | canvas->drawRect(SkRect::MakeXYWH(150, 0, 100, 100), p); |
| 24 | |
| 25 | p.setColor(0xf000ff00); |
| 26 | |
| 27 | // We'll draw a green square on top of each using two triangles. |
| 28 | SkPath upperLeft; |
| 29 | upperLeft.lineTo(100, 0); |
| 30 | upperLeft.lineTo(0, 100); |
| 31 | upperLeft.lineTo(0, 0); |
| 32 | |
| 33 | SkPath bottomRight; |
| 34 | bottomRight.moveTo(100, 0); |
| 35 | bottomRight.lineTo(100, 100); |
| 36 | bottomRight.lineTo(0, 100); |
| 37 | bottomRight.lineTo(100, 0); |
| 38 | |
| 39 | // The left square is drawn simply with SrcOver. It will show a red seam. |
| 40 | canvas->drawPath(upperLeft, p); |
| 41 | canvas->drawPath(bottomRight, p); |
| 42 | |
| 43 | // Using Plus on the right should merge the AA of seam together completely covering the red. |
| 44 | canvas->saveLayer(nullptr, nullptr); |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 45 | p.setBlendMode(SkBlendMode::kPlus); |
mtklein | 7005a57 | 2015-05-21 10:33:09 -0700 | [diff] [blame] | 46 | canvas->translate(150, 0); |
| 47 | canvas->drawPath(upperLeft, p); |
| 48 | canvas->drawPath(bottomRight, p); |
| 49 | canvas->restore(); |
| 50 | } |