• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.h"
9 #include "SkPath.h"
10 
11 DEF_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);
40       p.setBlendMode(SkBlendMode::kPlus);
41       canvas->translate(150, 0);
42       canvas->drawPath(upperLeft, p);
43       canvas->drawPath(bottomRight, p);
44     canvas->restore();
45 }
46