blob: 039ed4017b15904416b3037a590b42cea0044055 [file] [log] [blame]
robertphillipsafb188d2016-02-03 09:42:49 -08001/*
2 * Copyright 2016 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 "SkAvoidXfermode.h"
10
11class AvoidXfermode2GM : public skiagm::GM {
12public:
13 AvoidXfermode2GM() { }
14
15protected:
16 SkString onShortName() override {
17 return SkString("avoidxfermode2");
18 }
19
20 SkISize onISize() override { return SkISize::Make(128, 128); }
21
22 void onDraw(SkCanvas* canvas) override {
23 canvas->drawARGB(255, 0, 0, 0);
24
25 SkRect r = SkRect::MakeXYWH(32, 32, 64, 64);
26
27 SkPaint p0;
28 p0.setColor(SK_ColorGREEN);
29 p0.setAntiAlias(false);
30
31 canvas->drawRect(r, p0);
32
33 r = SkRect::MakeIWH(64, 64);
34
35 // UL corner: replace the green with a tight tolerance
36 SkPaint p1;
37 p1.setColor(SK_ColorRED);
38 p1.setXfermode(SkAvoidXfermode::Create(SK_ColorGREEN,
39 55,
40 SkAvoidXfermode::kTargetColor_Mode))->unref();
41
42 canvas->drawRect(r, p1);
43
44 r.offsetTo(64, 0.0f);
45
46 // UR corner: avoid the green with a tight tolerance
47 SkPaint p2;
48 p2.setColor(SK_ColorRED);
49 p2.setXfermode(SkAvoidXfermode::Create(SK_ColorGREEN,
50 200,
51 SkAvoidXfermode::kAvoidColor_Mode))->unref();
52
53 canvas->drawRect(r, p2);
54
55 r.offsetTo(0.0f, 64);
56
57 // LL corner: replace the green with a loose tolerance
58 SkPaint p3;
59 p3.setColor(SK_ColorRED);
60 p3.setXfermode(SkAvoidXfermode::Create(SK_ColorGREEN,
61 200,
62 SkAvoidXfermode::kTargetColor_Mode))->unref();
63
64 canvas->drawRect(r, p3);
65
66 r.offsetTo(64, 64);
67
68 // LR corner: avoid the green with a loose tolerance
69 SkPaint p4;
70 p4.setColor(SK_ColorRED);
71 p4.setXfermode(SkAvoidXfermode::Create(SK_ColorGREEN,
72 55,
73 SkAvoidXfermode::kAvoidColor_Mode))->unref();
74
75 canvas->drawRect(r, p4);
76 }
77
78private:
79 typedef GM INHERITED;
80};
81
82//////////////////////////////////////////////////////////////////////////////
83
84DEF_GM(return new AvoidXfermode2GM;)