blob: 9374f6fb913f14664f02a182024295e0bbd05d0e [file] [log] [blame]
commit-bot@chromium.orgd2623a12013-08-08 02:52:05 +00001/*
2 * Copyright 2013 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 "SkCanvas.h"
10#include "SkPath.h"
11
reedbbf3e892014-06-20 11:33:59 -070012class CircularClipsGM : public skiagm::GM {
13 SkScalar fX1, fX2, fY, fR;
14 SkPath fCircle1, fCircle2;
commit-bot@chromium.orgd2623a12013-08-08 02:52:05 +000015
caryclark63c684a2015-02-25 09:04:04 -080016protected:
mtklein36352bf2015-03-25 18:17:31 -070017 void onOnceBeforeDraw() override {
reedbbf3e892014-06-20 11:33:59 -070018 fX1 = 80;
19 fX2 = 120;
20 fY = 50;
21 fR = 40;
22
23 fCircle1.addCircle(fX1, fY, fR, SkPath::kCW_Direction);
24 fCircle2.addCircle(fX2, fY, fR, SkPath::kCW_Direction);
25 }
commit-bot@chromium.orgd2623a12013-08-08 02:52:05 +000026
commit-bot@chromium.orga90c6802014-04-30 13:20:45 +000027
mtklein36352bf2015-03-25 18:17:31 -070028 bool runAsBench() const override { return true; }
mtkleincf5d9c92015-01-23 10:31:45 -080029
mtklein36352bf2015-03-25 18:17:31 -070030 SkString onShortName() override {
commit-bot@chromium.orgd2623a12013-08-08 02:52:05 +000031 return SkString("circular-clips");
32 }
33
mtklein36352bf2015-03-25 18:17:31 -070034 SkISize onISize() override {
commit-bot@chromium.orgd2623a12013-08-08 02:52:05 +000035 return SkISize::Make(800, 600);
36 }
37
mtklein36352bf2015-03-25 18:17:31 -070038 void onDraw(SkCanvas* canvas) override {
Mike Reedc1f77742016-12-09 09:00:50 -050039 const SkClipOp ops[] = {
40 kDifference_SkClipOp,
41 kIntersect_SkClipOp,
42 kUnion_SkClipOp,
43 kXOR_SkClipOp,
44 kReverseDifference_SkClipOp,
45 kReplace_SkClipOp,
commit-bot@chromium.orgd2623a12013-08-08 02:52:05 +000046 };
47
reedbbf3e892014-06-20 11:33:59 -070048 SkRect rect = SkRect::MakeLTRB(fX1 - fR, fY - fR, fX2 + fR, fY + fR);
commit-bot@chromium.orgd2623a12013-08-08 02:52:05 +000049
50 SkPaint fillPaint;
51
bsalomonfcabe422015-04-28 12:43:01 -070052 // Giant background circular clips (AA, non-inverted, replace/isect)
53 fillPaint.setColor(0x80808080);
54 canvas->save();
55 canvas->scale(10, 10);
56 canvas->translate(-((fX1 + fX2)/2 - fR), -(fY - 2*fR/3));
reed66998382016-09-21 11:15:07 -070057 canvas->clipPath(fCircle1, true);
58 canvas->clipPath(fCircle2, true);
bsalomonfcabe422015-04-28 12:43:01 -070059
60 canvas->drawRect(rect, fillPaint);
61
62 canvas->restore();
halcanary9d524f22016-03-29 09:03:52 -070063
bsalomonfcabe422015-04-28 12:43:01 -070064 fillPaint.setColor(0xFF000000);
65
commit-bot@chromium.orgd2623a12013-08-08 02:52:05 +000066 for (size_t i = 0; i < 4; i++) {
reedbbf3e892014-06-20 11:33:59 -070067 fCircle1.toggleInverseFillType();
commit-bot@chromium.orgd2623a12013-08-08 02:52:05 +000068 if (i % 2 == 0) {
reedbbf3e892014-06-20 11:33:59 -070069 fCircle2.toggleInverseFillType();
commit-bot@chromium.orgd2623a12013-08-08 02:52:05 +000070 }
71
72 canvas->save();
73 for (size_t op = 0; op < SK_ARRAY_COUNT(ops); op++) {
74 canvas->save();
75
reed66998382016-09-21 11:15:07 -070076 canvas->clipPath(fCircle1);
reedbbf3e892014-06-20 11:33:59 -070077 canvas->clipPath(fCircle2, ops[op]);
commit-bot@chromium.orgd2623a12013-08-08 02:52:05 +000078
79 canvas->drawRect(rect, fillPaint);
80
81 canvas->restore();
reedbbf3e892014-06-20 11:33:59 -070082 canvas->translate(0, 2 * fY);
commit-bot@chromium.orgd2623a12013-08-08 02:52:05 +000083 }
84 canvas->restore();
reedbbf3e892014-06-20 11:33:59 -070085 canvas->translate(fX1 + fX2, 0);
commit-bot@chromium.orgd2623a12013-08-08 02:52:05 +000086 }
87 }
88
89private:
reedbbf3e892014-06-20 11:33:59 -070090 typedef skiagm::GM INHERITED;
commit-bot@chromium.orgd2623a12013-08-08 02:52:05 +000091};
92
93//////////////////////////////////////////////////////////////////////////////
94
95DEF_GM( return new CircularClipsGM; )