aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/avoidxfermode3.cpp
blob: c88b2a2ab18c54abca5cb0d49a1a18dd79d78d55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/

#include "gm.h"

#include "SkAvoidXfermode.h"

// This GM exercises how the avoid xfer mode interacts with partial coverage
class AvoidXfermode3GM : public skiagm::GM {
public:
    AvoidXfermode3GM() { }

protected:
    SkString onShortName() override {
        return SkString("avoidxfermode3");
    }

    SkISize onISize() override { return SkISize::Make(128, 128); }

    void onDraw(SkCanvas* canvas) override {
        canvas->drawARGB(255, 0, 0, 0);

        SkRect r = SkRect::MakeXYWH(16.5f, 16.5f, 96.0f, 96.0f);

        SkPaint p0;
        p0.setColor(SK_ColorWHITE);
        p0.setAntiAlias(true);

        canvas->drawRect(r, p0);

        r = SkRect::MakeXYWH(3.5f, 3.5f, 59.0f, 59.0f);

        // UL corner: replace white with green with a tight tolerance
        SkPaint p1;
        p1.setColor(SK_ColorGREEN);
        p1.setAntiAlias(true);
        p1.setXfermode(SkAvoidXfermode::Create(SK_ColorWHITE,
                                               5,
                                               SkAvoidXfermode::kTargetColor_Mode))->unref();

        canvas->drawRect(r, p1);

        r.offsetTo(65.5f, 3.5f);

        // UR corner: draw red everywhere except white with a tight tolerance
        SkPaint p2;
        p2.setColor(SK_ColorRED);
        p2.setAntiAlias(true);
        p2.setXfermode(SkAvoidXfermode::Create(SK_ColorWHITE,
                                               250,
                                               SkAvoidXfermode::kAvoidColor_Mode))->unref();

        canvas->drawRect(r, p2);

        r.offsetTo(3.5f, 65.5f);

        // LL corner: replace white with blue with a loose tolerance
        SkPaint p3;
        p3.setColor(SK_ColorBLUE);
        p3.setAntiAlias(true);
        p3.setXfermode(SkAvoidXfermode::Create(SK_ColorWHITE,
                                               250,
                                               SkAvoidXfermode::kTargetColor_Mode))->unref();

        canvas->drawRect(r, p3);

        r.offsetTo(65.5f, 65.5f);

        // LR corner: draw yellow everywhere except white with a loose tolerance
        SkPaint p4;
        p4.setColor(SK_ColorYELLOW);
        p4.setAntiAlias(true);
        p4.setXfermode(SkAvoidXfermode::Create(SK_ColorWHITE,
                                               5,
                                               SkAvoidXfermode::kAvoidColor_Mode))->unref();

        canvas->drawRect(r, p4);
    }

private:
    typedef GM INHERITED;
};

//////////////////////////////////////////////////////////////////////////////

DEF_GM(return new AvoidXfermode3GM;)