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