2013-08-08 02:52:05 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkPath.h"
|
2013-08-08 02:52:05 +00:00
|
|
|
|
2014-06-20 18:33:59 +00:00
|
|
|
class CircularClipsGM : public skiagm::GM {
|
|
|
|
SkScalar fX1, fX2, fY, fR;
|
|
|
|
SkPath fCircle1, fCircle2;
|
2013-08-08 02:52:05 +00:00
|
|
|
|
2015-02-25 17:04:04 +00:00
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
void onOnceBeforeDraw() override {
|
2014-06-20 18:33:59 +00:00
|
|
|
fX1 = 80;
|
|
|
|
fX2 = 120;
|
|
|
|
fY = 50;
|
|
|
|
fR = 40;
|
|
|
|
|
|
|
|
fCircle1.addCircle(fX1, fY, fR, SkPath::kCW_Direction);
|
|
|
|
fCircle2.addCircle(fX2, fY, fR, SkPath::kCW_Direction);
|
|
|
|
}
|
2013-08-08 02:52:05 +00:00
|
|
|
|
2014-04-30 13:20:45 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
bool runAsBench() const override { return true; }
|
2015-01-23 18:31:45 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2013-08-08 02:52:05 +00:00
|
|
|
return SkString("circular-clips");
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2013-08-08 02:52:05 +00:00
|
|
|
return SkISize::Make(800, 600);
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2016-12-09 14:00:50 +00:00
|
|
|
const SkClipOp ops[] = {
|
|
|
|
kDifference_SkClipOp,
|
|
|
|
kIntersect_SkClipOp,
|
|
|
|
kUnion_SkClipOp,
|
|
|
|
kXOR_SkClipOp,
|
|
|
|
kReverseDifference_SkClipOp,
|
|
|
|
kReplace_SkClipOp,
|
2013-08-08 02:52:05 +00:00
|
|
|
};
|
|
|
|
|
2014-06-20 18:33:59 +00:00
|
|
|
SkRect rect = SkRect::MakeLTRB(fX1 - fR, fY - fR, fX2 + fR, fY + fR);
|
2013-08-08 02:52:05 +00:00
|
|
|
|
|
|
|
SkPaint fillPaint;
|
|
|
|
|
2015-04-28 19:43:01 +00:00
|
|
|
// Giant background circular clips (AA, non-inverted, replace/isect)
|
|
|
|
fillPaint.setColor(0x80808080);
|
|
|
|
canvas->save();
|
|
|
|
canvas->scale(10, 10);
|
|
|
|
canvas->translate(-((fX1 + fX2)/2 - fR), -(fY - 2*fR/3));
|
2016-09-21 18:15:07 +00:00
|
|
|
canvas->clipPath(fCircle1, true);
|
|
|
|
canvas->clipPath(fCircle2, true);
|
2015-04-28 19:43:01 +00:00
|
|
|
|
|
|
|
canvas->drawRect(rect, fillPaint);
|
|
|
|
|
|
|
|
canvas->restore();
|
2016-03-29 16:03:52 +00:00
|
|
|
|
2015-04-28 19:43:01 +00:00
|
|
|
fillPaint.setColor(0xFF000000);
|
|
|
|
|
2013-08-08 02:52:05 +00:00
|
|
|
for (size_t i = 0; i < 4; i++) {
|
2014-06-20 18:33:59 +00:00
|
|
|
fCircle1.toggleInverseFillType();
|
2013-08-08 02:52:05 +00:00
|
|
|
if (i % 2 == 0) {
|
2014-06-20 18:33:59 +00:00
|
|
|
fCircle2.toggleInverseFillType();
|
2013-08-08 02:52:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
canvas->save();
|
|
|
|
for (size_t op = 0; op < SK_ARRAY_COUNT(ops); op++) {
|
|
|
|
canvas->save();
|
|
|
|
|
2016-09-21 18:15:07 +00:00
|
|
|
canvas->clipPath(fCircle1);
|
2014-06-20 18:33:59 +00:00
|
|
|
canvas->clipPath(fCircle2, ops[op]);
|
2013-08-08 02:52:05 +00:00
|
|
|
|
|
|
|
canvas->drawRect(rect, fillPaint);
|
|
|
|
|
|
|
|
canvas->restore();
|
2014-06-20 18:33:59 +00:00
|
|
|
canvas->translate(0, 2 * fY);
|
2013-08-08 02:52:05 +00:00
|
|
|
}
|
|
|
|
canvas->restore();
|
2014-06-20 18:33:59 +00:00
|
|
|
canvas->translate(fX1 + fX2, 0);
|
2013-08-08 02:52:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-06-20 18:33:59 +00:00
|
|
|
typedef skiagm::GM INHERITED;
|
2013-08-08 02:52:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
DEF_GM( return new CircularClipsGM; )
|