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"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkClipOp.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkPath.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/core/SkTypes.h"
|
|
|
|
#include "src/core/SkClipOpPriv.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;
|
|
|
|
|
2020-08-24 19:15:01 +00:00
|
|
|
fCircle1 = SkPath::Circle(fX1, fY, fR, SkPathDirection::kCW);
|
|
|
|
fCircle2 = SkPath::Circle(fX2, fY, fR, SkPathDirection::kCW);
|
2014-06-20 18:33:59 +00:00
|
|
|
}
|
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 {
|
2020-05-05 14:56:42 +00:00
|
|
|
return SkISize::Make(800, 200);
|
2013-08-08 02:52:05 +00:00
|
|
|
}
|
|
|
|
|
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,
|
2020-05-05 14:56:42 +00:00
|
|
|
kIntersect_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:
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = skiagm::GM;
|
2013-08-08 02:52:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
DEF_GM( return new CircularClipsGM; )
|