| 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/gm.h" |
| 9 |
#include "include/core/SkBlendMode.h" |
| 10 |
#include "include/core/SkCanvas.h" |
| 11 |
#include "include/core/SkColor.h" |
| 12 |
#include "include/core/SkPaint.h" |
| 13 |
#include "include/core/SkPath.h" |
| 14 |
#include "include/core/SkPathBuilder.h" |
| 15 |
#include "include/core/SkRect.h" |
| 16 |
|
| 17 |
DEF_SIMPLE_GM(PlusMergesAA, canvas, 256, 256) { |
| 18 |
SkPaint p; |
| 19 |
p.setColor(SK_ColorRED); |
| 20 |
p.setAntiAlias(true); // <-- crucial to the test that we use AA |
| 21 |
|
| 22 |
// Draw a two red squares. |
| 23 |
canvas->drawRect(SkRect::MakeWH(100, 100), p); |
| 24 |
canvas->drawRect(SkRect::MakeXYWH(150, 0, 100, 100), p); |
| 25 |
|
| 26 |
p.setColor(0xf000ff00); |
| 27 |
|
| 28 |
// We'll draw a green square on top of each using two triangles. |
| 29 |
SkPath upperLeft = SkPathBuilder() |
| 30 |
.lineTo(100, 0) |
| 31 |
.lineTo(0, 100) |
| 32 |
.lineTo(0, 0) |
| 33 |
.detach(); |
| 34 |
|
| 35 |
SkPath bottomRight = SkPathBuilder() |
| 36 |
.moveTo(100, 0) |
| 37 |
.lineTo(100, 100) |
| 38 |
.lineTo(0, 100) |
| 39 |
.lineTo(100, 0) |
| 40 |
.detach(); |
| 41 |
|
| 42 |
// The left square is drawn simply with SrcOver. It will show a red seam. |
| 43 |
canvas->drawPath(upperLeft, p); |
| 44 |
canvas->drawPath(bottomRight, p); |
| 45 |
|
| 46 |
// Using Plus on the right should merge the AA of seam together completely covering the red. |
| 47 |
canvas->saveLayer(nullptr, nullptr); |
| 48 |
p.setBlendMode(SkBlendMode::kPlus); |
| 49 |
canvas->translate(150, 0); |
| 50 |
canvas->drawPath(upperLeft, p); |
| 51 |
canvas->drawPath(bottomRight, p); |
| 52 |
canvas->restore(); |
| 53 |
} |