blob: 51ac2cb1039ff4552f6409b9875c5f6f0d73ff80 [file] [log] [blame]
mtklein7005a572015-05-21 10:33:09 -07001/*
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"
bungemand3ebb482015-08-05 13:57:49 -07009#include "SkPath.h"
mtklein7005a572015-05-21 10:33:09 -070010
11DEF_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);
reed374772b2016-10-05 17:33:02 -070040 p.setBlendMode(SkBlendMode::kPlus);
mtklein7005a572015-05-21 10:33:09 -070041 canvas->translate(150, 0);
42 canvas->drawPath(upperLeft, p);
43 canvas->drawPath(bottomRight, p);
44 canvas->restore();
45}