2016-01-29 16:44:17 +00:00
|
|
|
/*
|
|
|
|
* 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 "Resources.h"
|
|
|
|
|
|
|
|
#include "SkAvoidXfermode.h"
|
|
|
|
#include "SkStream.h"
|
|
|
|
|
|
|
|
class AvoidXfermodeGM : public skiagm::GM {
|
|
|
|
public:
|
|
|
|
AvoidXfermodeGM() { }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SkString onShortName() override {
|
|
|
|
return SkString("avoidxfermode");
|
|
|
|
}
|
|
|
|
|
|
|
|
SkISize onISize() override { return SkISize::Make(128, 128); }
|
|
|
|
|
|
|
|
void onOnceBeforeDraw() override {
|
2016-03-18 19:13:47 +00:00
|
|
|
if (!GetResourceAsBitmap("color_wheel.png", &fBM)) {
|
2016-01-29 16:44:17 +00:00
|
|
|
fBM.allocN32Pixels(1, 1);
|
|
|
|
fBM.eraseARGB(255, 255, 0 , 0); // red == bad
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void onDraw(SkCanvas* canvas) override {
|
|
|
|
canvas->drawBitmap(fBM, 0, 0);
|
|
|
|
|
|
|
|
SkRect r = SkRect::MakeIWH(64, 64);
|
|
|
|
|
|
|
|
// UL corner: replace white with black with a tight tolerance
|
|
|
|
SkPaint p1;
|
|
|
|
p1.setColor(SK_ColorBLACK);
|
2016-03-29 18:32:50 +00:00
|
|
|
p1.setXfermode(SkAvoidXfermode::Make(SK_ColorWHITE, 5, SkAvoidXfermode::kTargetColor_Mode));
|
2016-01-29 16:44:17 +00:00
|
|
|
|
|
|
|
canvas->drawRect(r, p1);
|
|
|
|
|
|
|
|
r.offsetTo(64, 0.0f);
|
|
|
|
|
|
|
|
// UR corner: draw black everywhere except white with a tight tolerance
|
|
|
|
SkPaint p2;
|
|
|
|
p2.setColor(SK_ColorBLACK);
|
2016-03-29 18:32:50 +00:00
|
|
|
p2.setXfermode(SkAvoidXfermode::Make(SK_ColorWHITE, 250,
|
|
|
|
SkAvoidXfermode::kAvoidColor_Mode));
|
2016-01-29 16:44:17 +00:00
|
|
|
|
|
|
|
canvas->drawRect(r, p2);
|
|
|
|
|
|
|
|
r.offsetTo(0.0f, 64);
|
|
|
|
|
2016-02-03 17:42:49 +00:00
|
|
|
// LL corner: replace red with transparent blue with a loose tolerance
|
2016-01-29 16:44:17 +00:00
|
|
|
SkPaint p3;
|
2016-02-03 17:42:49 +00:00
|
|
|
p3.setColor(0x7F0000FF);
|
2016-03-29 18:32:50 +00:00
|
|
|
p3.setXfermode(SkAvoidXfermode::Make(SK_ColorRED, 250, SkAvoidXfermode::kTargetColor_Mode));
|
2016-01-29 16:44:17 +00:00
|
|
|
|
|
|
|
canvas->drawRect(r, p3);
|
|
|
|
|
|
|
|
r.offsetTo(64, 64);
|
|
|
|
|
|
|
|
// LR corner: draw black everywhere except red with a loose tolerance
|
|
|
|
SkPaint p4;
|
|
|
|
p4.setColor(SK_ColorBLACK);
|
2016-03-29 18:32:50 +00:00
|
|
|
p4.setXfermode(SkAvoidXfermode::Make(SK_ColorRED, 5, SkAvoidXfermode::kAvoidColor_Mode));
|
2016-01-29 16:44:17 +00:00
|
|
|
|
|
|
|
canvas->drawRect(r, p4);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkBitmap fBM;
|
|
|
|
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
DEF_GM(return new AvoidXfermodeGM;)
|