blob: ec766fbca4b0d28a3417cfb6bd622cb6647e7487 [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
commit-bot@chromium.orgd2623a12013-08-08 02:52:05 +000016public:
reedbbf3e892014-06-20 11:33:59 -070017 CircularClipsGM() {
18 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
27protected:
commit-bot@chromium.orga90c6802014-04-30 13:20:45 +000028
mtkleincf5d9c92015-01-23 10:31:45 -080029 bool runAsBench() const SK_OVERRIDE { return true; }
30
mtklein72c9faa2015-01-09 10:06:39 -080031 SkString onShortName() SK_OVERRIDE {
commit-bot@chromium.orgd2623a12013-08-08 02:52:05 +000032 return SkString("circular-clips");
33 }
34
mtklein72c9faa2015-01-09 10:06:39 -080035 SkISize onISize() SK_OVERRIDE {
commit-bot@chromium.orgd2623a12013-08-08 02:52:05 +000036 return SkISize::Make(800, 600);
37 }
38
mtklein72c9faa2015-01-09 10:06:39 -080039 void onDraw(SkCanvas* canvas) SK_OVERRIDE {
commit-bot@chromium.orgd2623a12013-08-08 02:52:05 +000040 SkRegion::Op ops[] = {
41 SkRegion::kDifference_Op,
42 SkRegion::kIntersect_Op,
43 SkRegion::kUnion_Op,
44 SkRegion::kXOR_Op,
45 SkRegion::kReverseDifference_Op,
46 SkRegion::kReplace_Op,
47 };
48
reedbbf3e892014-06-20 11:33:59 -070049 SkRect rect = SkRect::MakeLTRB(fX1 - fR, fY - fR, fX2 + fR, fY + fR);
commit-bot@chromium.orgd2623a12013-08-08 02:52:05 +000050
51 SkPaint fillPaint;
52
53 for (size_t i = 0; i < 4; i++) {
reedbbf3e892014-06-20 11:33:59 -070054 fCircle1.toggleInverseFillType();
commit-bot@chromium.orgd2623a12013-08-08 02:52:05 +000055 if (i % 2 == 0) {
reedbbf3e892014-06-20 11:33:59 -070056 fCircle2.toggleInverseFillType();
commit-bot@chromium.orgd2623a12013-08-08 02:52:05 +000057 }
58
59 canvas->save();
60 for (size_t op = 0; op < SK_ARRAY_COUNT(ops); op++) {
61 canvas->save();
62
reedbbf3e892014-06-20 11:33:59 -070063 canvas->clipPath(fCircle1, SkRegion::kReplace_Op);
64 canvas->clipPath(fCircle2, ops[op]);
commit-bot@chromium.orgd2623a12013-08-08 02:52:05 +000065
66 canvas->drawRect(rect, fillPaint);
67
68 canvas->restore();
reedbbf3e892014-06-20 11:33:59 -070069 canvas->translate(0, 2 * fY);
commit-bot@chromium.orgd2623a12013-08-08 02:52:05 +000070 }
71 canvas->restore();
reedbbf3e892014-06-20 11:33:59 -070072 canvas->translate(fX1 + fX2, 0);
commit-bot@chromium.orgd2623a12013-08-08 02:52:05 +000073 }
74 }
75
76private:
reedbbf3e892014-06-20 11:33:59 -070077 typedef skiagm::GM INHERITED;
commit-bot@chromium.orgd2623a12013-08-08 02:52:05 +000078};
79
80//////////////////////////////////////////////////////////////////////////////
81
82DEF_GM( return new CircularClipsGM; )