blob: 5144b46fb49e0566c727d3ef46a5520c97140fc4 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -04009#include "include/core/SkBlendMode.h"
10#include "include/core/SkCanvas.h"
11#include "include/core/SkColor.h"
12#include "include/core/SkPaint.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "include/core/SkPath.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040014#include "include/core/SkRect.h"
mtklein7005a572015-05-21 10:33:09 -070015
16DEF_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);
reed374772b2016-10-05 17:33:02 -070045 p.setBlendMode(SkBlendMode::kPlus);
mtklein7005a572015-05-21 10:33:09 -070046 canvas->translate(150, 0);
47 canvas->drawPath(upperLeft, p);
48 canvas->drawPath(bottomRight, p);
49 canvas->restore();
50}