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