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/SkRect.h"
15 
16 DEF_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);
45       p.setBlendMode(SkBlendMode::kPlus);
46       canvas->translate(150, 0);
47       canvas->drawPath(upperLeft, p);
48       canvas->drawPath(bottomRight, p);
49     canvas->restore();
50 }
51