aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/avoidxfermode2.cpp
blob: 9fe7d3321b42401af13d105083569c14a9c2a52f (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
/*
 * 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"

class AvoidXfermode2GM : public skiagm::GM {
public:
    AvoidXfermode2GM() { }

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

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

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

        SkRect r = SkRect::MakeXYWH(32, 32, 64, 64);

        SkPaint p0;
        p0.setColor(SK_ColorGREEN);
        p0.setAntiAlias(false);

        canvas->drawRect(r, p0);

        r = SkRect::MakeIWH(64, 64);

        // UL corner: replace the green with a tight tolerance
        SkPaint p1;
        p1.setColor(SK_ColorRED);
        p1.setXfermode(SkAvoidXfermode::Make(SK_ColorGREEN, 55,
                                             SkAvoidXfermode::kTargetColor_Mode));

        canvas->drawRect(r, p1);

        r.offsetTo(64, 0.0f);

        // UR corner: avoid the green with a tight tolerance
        SkPaint p2;
        p2.setColor(SK_ColorRED);
        p2.setXfermode(SkAvoidXfermode::Make(SK_ColorGREEN, 200,
                                             SkAvoidXfermode::kAvoidColor_Mode));

        canvas->drawRect(r, p2);

        r.offsetTo(0.0f, 64);

        // LL corner: replace the green with a loose tolerance
        SkPaint p3;
        p3.setColor(SK_ColorRED);
        p3.setXfermode(SkAvoidXfermode::Make(SK_ColorGREEN, 200,
                                             SkAvoidXfermode::kTargetColor_Mode));

        canvas->drawRect(r, p3);

        r.offsetTo(64, 64);

        // LR corner: avoid the green with a loose tolerance
        SkPaint p4;
        p4.setColor(SK_ColorRED);
        p4.setXfermode(SkAvoidXfermode::Make(SK_ColorGREEN, 55, SkAvoidXfermode::kAvoidColor_Mode));

        canvas->drawRect(r, p4);
    }

private:
    typedef GM INHERITED;
};

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

DEF_GM(return new AvoidXfermode2GM;)