blob: 69e8b69a8f23a78f733c5511f73f8b70996a974b [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:
mtklein72c9faa2015-01-09 10:06:39 -080028 uint32_t onGetFlags() const SK_OVERRIDE {
mtkleincf5d9c92015-01-23 10:31:45 -080029 return kSkipTiled_Flag;
commit-bot@chromium.orga90c6802014-04-30 13:20:45 +000030 }
31
mtkleincf5d9c92015-01-23 10:31:45 -080032 bool runAsBench() const SK_OVERRIDE { return true; }
33
mtklein72c9faa2015-01-09 10:06:39 -080034 SkString onShortName() SK_OVERRIDE {
commit-bot@chromium.orgd2623a12013-08-08 02:52:05 +000035 return SkString("circular-clips");
36 }
37
mtklein72c9faa2015-01-09 10:06:39 -080038 SkISize onISize() SK_OVERRIDE {
commit-bot@chromium.orgd2623a12013-08-08 02:52:05 +000039 return SkISize::Make(800, 600);
40 }
41
mtklein72c9faa2015-01-09 10:06:39 -080042 void onDraw(SkCanvas* canvas) SK_OVERRIDE {
commit-bot@chromium.orgd2623a12013-08-08 02:52:05 +000043 SkRegion::Op ops[] = {
44 SkRegion::kDifference_Op,
45 SkRegion::kIntersect_Op,
46 SkRegion::kUnion_Op,
47 SkRegion::kXOR_Op,
48 SkRegion::kReverseDifference_Op,
49 SkRegion::kReplace_Op,
50 };
51
reedbbf3e892014-06-20 11:33:59 -070052 SkRect rect = SkRect::MakeLTRB(fX1 - fR, fY - fR, fX2 + fR, fY + fR);
commit-bot@chromium.orgd2623a12013-08-08 02:52:05 +000053
54 SkPaint fillPaint;
55
56 for (size_t i = 0; i < 4; i++) {
reedbbf3e892014-06-20 11:33:59 -070057 fCircle1.toggleInverseFillType();
commit-bot@chromium.orgd2623a12013-08-08 02:52:05 +000058 if (i % 2 == 0) {
reedbbf3e892014-06-20 11:33:59 -070059 fCircle2.toggleInverseFillType();
commit-bot@chromium.orgd2623a12013-08-08 02:52:05 +000060 }
61
62 canvas->save();
63 for (size_t op = 0; op < SK_ARRAY_COUNT(ops); op++) {
64 canvas->save();
65
reedbbf3e892014-06-20 11:33:59 -070066 canvas->clipPath(fCircle1, SkRegion::kReplace_Op);
67 canvas->clipPath(fCircle2, ops[op]);
commit-bot@chromium.orgd2623a12013-08-08 02:52:05 +000068
69 canvas->drawRect(rect, fillPaint);
70
71 canvas->restore();
reedbbf3e892014-06-20 11:33:59 -070072 canvas->translate(0, 2 * fY);
commit-bot@chromium.orgd2623a12013-08-08 02:52:05 +000073 }
74 canvas->restore();
reedbbf3e892014-06-20 11:33:59 -070075 canvas->translate(fX1 + fX2, 0);
commit-bot@chromium.orgd2623a12013-08-08 02:52:05 +000076 }
77 }
78
79private:
reedbbf3e892014-06-20 11:33:59 -070080 typedef skiagm::GM INHERITED;
commit-bot@chromium.orgd2623a12013-08-08 02:52:05 +000081};
82
83//////////////////////////////////////////////////////////////////////////////
84
85DEF_GM( return new CircularClipsGM; )