Flutter Engine
The Flutter Engine
plus.cpp
Go to the documentation of this file.
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"
13#include "include/core/SkPath.h"
14#include "include/core/SkRect.h"
15
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);
45 p.setBlendMode(SkBlendMode::kPlus);
46 canvas->translate(150, 0);
47 canvas->drawPath(upperLeft, p);
48 canvas->drawPath(bottomRight, p);
49 canvas->restore();
50}
@ kPlus
r = min(s + d, 1)
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
Definition: SkPath.h:59
SkPath & moveTo(SkScalar x, SkScalar y)
Definition: SkPath.cpp:688
SkPath & lineTo(SkScalar x, SkScalar y)
Definition: SkPath.cpp:728
DEF_SIMPLE_GM(PlusMergesAA, canvas, 256, 256)
Definition: plus.cpp:16
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609