blob: c88b2a2ab18c54abca5cb0d49a1a18dd79d78d55 [file] [log] [blame]
robertphillipsffad53a2016-02-03 10:46:01 -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
10#include "SkAvoidXfermode.h"
11
12// This GM exercises how the avoid xfer mode interacts with partial coverage
13class AvoidXfermode3GM : public skiagm::GM {
14public:
15 AvoidXfermode3GM() { }
16
17protected:
18 SkString onShortName() override {
19 return SkString("avoidxfermode3");
20 }
21
22 SkISize onISize() override { return SkISize::Make(128, 128); }
23
24 void onDraw(SkCanvas* canvas) override {
25 canvas->drawARGB(255, 0, 0, 0);
26
27 SkRect r = SkRect::MakeXYWH(16.5f, 16.5f, 96.0f, 96.0f);
28
29 SkPaint p0;
30 p0.setColor(SK_ColorWHITE);
31 p0.setAntiAlias(true);
32
33 canvas->drawRect(r, p0);
34
35 r = SkRect::MakeXYWH(3.5f, 3.5f, 59.0f, 59.0f);
36
37 // UL corner: replace white with green with a tight tolerance
38 SkPaint p1;
39 p1.setColor(SK_ColorGREEN);
40 p1.setAntiAlias(true);
41 p1.setXfermode(SkAvoidXfermode::Create(SK_ColorWHITE,
42 5,
43 SkAvoidXfermode::kTargetColor_Mode))->unref();
44
45 canvas->drawRect(r, p1);
46
47 r.offsetTo(65.5f, 3.5f);
48
49 // UR corner: draw red everywhere except white with a tight tolerance
50 SkPaint p2;
51 p2.setColor(SK_ColorRED);
52 p2.setAntiAlias(true);
53 p2.setXfermode(SkAvoidXfermode::Create(SK_ColorWHITE,
54 250,
55 SkAvoidXfermode::kAvoidColor_Mode))->unref();
56
57 canvas->drawRect(r, p2);
58
59 r.offsetTo(3.5f, 65.5f);
60
61 // LL corner: replace white with blue with a loose tolerance
62 SkPaint p3;
63 p3.setColor(SK_ColorBLUE);
64 p3.setAntiAlias(true);
65 p3.setXfermode(SkAvoidXfermode::Create(SK_ColorWHITE,
66 250,
67 SkAvoidXfermode::kTargetColor_Mode))->unref();
68
69 canvas->drawRect(r, p3);
70
71 r.offsetTo(65.5f, 65.5f);
72
73 // LR corner: draw yellow everywhere except white with a loose tolerance
74 SkPaint p4;
75 p4.setColor(SK_ColorYELLOW);
76 p4.setAntiAlias(true);
77 p4.setXfermode(SkAvoidXfermode::Create(SK_ColorWHITE,
78 5,
79 SkAvoidXfermode::kAvoidColor_Mode))->unref();
80
81 canvas->drawRect(r, p4);
82 }
83
84private:
85 typedef GM INHERITED;
86};
87
88//////////////////////////////////////////////////////////////////////////////
89
90DEF_GM(return new AvoidXfermode3GM;)