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