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 | |
| 8 | #include "gm.h" |
| 9 | #include "SkCanvas.h" |
| 10 | #include "SkPath.h" |
| 11 | |
reed | bbf3e89 | 2014-06-20 11:33:59 -0700 | [diff] [blame] | 12 | class CircularClipsGM : public skiagm::GM { |
| 13 | SkScalar fX1, fX2, fY, fR; |
| 14 | SkPath fCircle1, fCircle2; |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 15 | |
caryclark | 63c684a | 2015-02-25 09:04:04 -0800 | [diff] [blame] | 16 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 17 | void onOnceBeforeDraw() override { |
reed | bbf3e89 | 2014-06-20 11:33:59 -0700 | [diff] [blame] | 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.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 26 | |
commit-bot@chromium.org | a90c680 | 2014-04-30 13:20:45 +0000 | [diff] [blame] | 27 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 28 | bool runAsBench() const override { return true; } |
mtklein | cf5d9c9 | 2015-01-23 10:31:45 -0800 | [diff] [blame] | 29 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 30 | SkString onShortName() override { |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 31 | return SkString("circular-clips"); |
| 32 | } |
| 33 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 34 | SkISize onISize() override { |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 35 | return SkISize::Make(800, 600); |
| 36 | } |
| 37 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 38 | void onDraw(SkCanvas* canvas) override { |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 39 | SkRegion::Op ops[] = { |
| 40 | SkRegion::kDifference_Op, |
| 41 | SkRegion::kIntersect_Op, |
| 42 | SkRegion::kUnion_Op, |
| 43 | SkRegion::kXOR_Op, |
| 44 | SkRegion::kReverseDifference_Op, |
| 45 | SkRegion::kReplace_Op, |
| 46 | }; |
| 47 | |
reed | bbf3e89 | 2014-06-20 11:33:59 -0700 | [diff] [blame] | 48 | 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] | 49 | |
| 50 | SkPaint fillPaint; |
| 51 | |
bsalomon | fcabe42 | 2015-04-28 12:43:01 -0700 | [diff] [blame] | 52 | // 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)); |
| 57 | canvas->clipPath(fCircle1, SkRegion::kReplace_Op, true); |
| 58 | canvas->clipPath(fCircle2, SkRegion::kIntersect_Op, true); |
| 59 | |
| 60 | canvas->drawRect(rect, fillPaint); |
| 61 | |
| 62 | canvas->restore(); |
| 63 | |
| 64 | fillPaint.setColor(0xFF000000); |
| 65 | |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 66 | for (size_t i = 0; i < 4; i++) { |
reed | bbf3e89 | 2014-06-20 11:33:59 -0700 | [diff] [blame] | 67 | fCircle1.toggleInverseFillType(); |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 68 | if (i % 2 == 0) { |
reed | bbf3e89 | 2014-06-20 11:33:59 -0700 | [diff] [blame] | 69 | fCircle2.toggleInverseFillType(); |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | canvas->save(); |
| 73 | for (size_t op = 0; op < SK_ARRAY_COUNT(ops); op++) { |
| 74 | canvas->save(); |
| 75 | |
reed | bbf3e89 | 2014-06-20 11:33:59 -0700 | [diff] [blame] | 76 | canvas->clipPath(fCircle1, SkRegion::kReplace_Op); |
| 77 | canvas->clipPath(fCircle2, ops[op]); |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 78 | |
| 79 | canvas->drawRect(rect, fillPaint); |
| 80 | |
| 81 | canvas->restore(); |
reed | bbf3e89 | 2014-06-20 11:33:59 -0700 | [diff] [blame] | 82 | canvas->translate(0, 2 * fY); |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 83 | } |
| 84 | canvas->restore(); |
reed | bbf3e89 | 2014-06-20 11:33:59 -0700 | [diff] [blame] | 85 | canvas->translate(fX1 + fX2, 0); |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 86 | } |
| 87 | } |
| 88 | |
| 89 | private: |
reed | bbf3e89 | 2014-06-20 11:33:59 -0700 | [diff] [blame] | 90 | typedef skiagm::GM INHERITED; |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | ////////////////////////////////////////////////////////////////////////////// |
| 94 | |
| 95 | DEF_GM( return new CircularClipsGM; ) |