Flutter Engine
The Flutter Engine
Functions
plus.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkBlendMode.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPath.h"
#include "include/core/SkRect.h"

Go to the source code of this file.

Functions

 DEF_SIMPLE_GM (PlusMergesAA, canvas, 256, 256)
 

Function Documentation

◆ DEF_SIMPLE_GM()

DEF_SIMPLE_GM ( PlusMergesAA  ,
canvas  ,
256  ,
256   
)

Definition at line 16 of file plus.cpp.

16 {
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
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