commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "gm/gm.h" |
| 9 | #include "include/core/SkCanvas.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 10 | #include "include/core/SkClipOp.h" |
| 11 | #include "include/core/SkPaint.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "include/core/SkPath.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 13 | #include "include/core/SkRect.h" |
| 14 | #include "include/core/SkScalar.h" |
| 15 | #include "include/core/SkSize.h" |
| 16 | #include "include/core/SkString.h" |
| 17 | #include "include/core/SkTypes.h" |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 18 | |
reed | bbf3e89 | 2014-06-20 11:33:59 -0700 | [diff] [blame] | 19 | class CircularClipsGM : public skiagm::GM { |
| 20 | SkScalar fX1, fX2, fY, fR; |
| 21 | SkPath fCircle1, fCircle2; |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 22 | |
caryclark | 63c684a | 2015-02-25 09:04:04 -0800 | [diff] [blame] | 23 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 24 | void onOnceBeforeDraw() override { |
reed | bbf3e89 | 2014-06-20 11:33:59 -0700 | [diff] [blame] | 25 | fX1 = 80; |
| 26 | fX2 = 120; |
| 27 | fY = 50; |
| 28 | fR = 40; |
| 29 | |
Mike Reed | 58cc97a | 2020-08-24 15:15:01 -0400 | [diff] [blame] | 30 | fCircle1 = SkPath::Circle(fX1, fY, fR, SkPathDirection::kCW); |
| 31 | fCircle2 = SkPath::Circle(fX2, fY, fR, SkPathDirection::kCW); |
reed | bbf3e89 | 2014-06-20 11:33:59 -0700 | [diff] [blame] | 32 | } |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 33 | |
commit-bot@chromium.org | a90c680 | 2014-04-30 13:20:45 +0000 | [diff] [blame] | 34 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 35 | bool runAsBench() const override { return true; } |
mtklein | cf5d9c9 | 2015-01-23 10:31:45 -0800 | [diff] [blame] | 36 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 37 | SkString onShortName() override { |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 38 | return SkString("circular-clips"); |
| 39 | } |
| 40 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 41 | SkISize onISize() override { |
Michael Ludwig | 9689e39 | 2020-05-05 10:56:42 -0400 | [diff] [blame] | 42 | return SkISize::Make(800, 200); |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 43 | } |
| 44 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 45 | void onDraw(SkCanvas* canvas) override { |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 46 | const SkClipOp ops[] = { |
Michael Ludwig | 2f6e2f8 | 2021-08-03 13:08:50 -0400 | [diff] [blame] | 47 | SkClipOp::kDifference, |
| 48 | SkClipOp::kIntersect |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 49 | }; |
| 50 | |
reed | bbf3e89 | 2014-06-20 11:33:59 -0700 | [diff] [blame] | 51 | SkRect rect = SkRect::MakeLTRB(fX1 - fR, fY - fR, fX2 + fR, fY + fR); |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 52 | |
| 53 | SkPaint fillPaint; |
| 54 | |
bsalomon | fcabe42 | 2015-04-28 12:43:01 -0700 | [diff] [blame] | 55 | // Giant background circular clips (AA, non-inverted, replace/isect) |
| 56 | fillPaint.setColor(0x80808080); |
| 57 | canvas->save(); |
| 58 | canvas->scale(10, 10); |
| 59 | canvas->translate(-((fX1 + fX2)/2 - fR), -(fY - 2*fR/3)); |
reed | 6699838 | 2016-09-21 11:15:07 -0700 | [diff] [blame] | 60 | canvas->clipPath(fCircle1, true); |
| 61 | canvas->clipPath(fCircle2, true); |
bsalomon | fcabe42 | 2015-04-28 12:43:01 -0700 | [diff] [blame] | 62 | |
| 63 | canvas->drawRect(rect, fillPaint); |
| 64 | |
| 65 | canvas->restore(); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 66 | |
bsalomon | fcabe42 | 2015-04-28 12:43:01 -0700 | [diff] [blame] | 67 | fillPaint.setColor(0xFF000000); |
| 68 | |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 69 | for (size_t i = 0; i < 4; i++) { |
reed | bbf3e89 | 2014-06-20 11:33:59 -0700 | [diff] [blame] | 70 | fCircle1.toggleInverseFillType(); |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 71 | if (i % 2 == 0) { |
reed | bbf3e89 | 2014-06-20 11:33:59 -0700 | [diff] [blame] | 72 | fCircle2.toggleInverseFillType(); |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | canvas->save(); |
| 76 | for (size_t op = 0; op < SK_ARRAY_COUNT(ops); op++) { |
| 77 | canvas->save(); |
| 78 | |
reed | 6699838 | 2016-09-21 11:15:07 -0700 | [diff] [blame] | 79 | canvas->clipPath(fCircle1); |
reed | bbf3e89 | 2014-06-20 11:33:59 -0700 | [diff] [blame] | 80 | canvas->clipPath(fCircle2, ops[op]); |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 81 | |
| 82 | canvas->drawRect(rect, fillPaint); |
| 83 | |
| 84 | canvas->restore(); |
reed | bbf3e89 | 2014-06-20 11:33:59 -0700 | [diff] [blame] | 85 | canvas->translate(0, 2 * fY); |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 86 | } |
| 87 | canvas->restore(); |
reed | bbf3e89 | 2014-06-20 11:33:59 -0700 | [diff] [blame] | 88 | canvas->translate(fX1 + fX2, 0); |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 89 | } |
| 90 | } |
| 91 | |
| 92 | private: |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 93 | using INHERITED = skiagm::GM; |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | ////////////////////////////////////////////////////////////////////////////// |
| 97 | |
| 98 | DEF_GM( return new CircularClipsGM; ) |