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 | |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 16 | public: |
reed | bbf3e89 | 2014-06-20 11:33:59 -0700 | [diff] [blame] | 17 | 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.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 26 | |
| 27 | protected: |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame^] | 28 | uint32_t onGetFlags() const SK_OVERRIDE { |
reed | bbf3e89 | 2014-06-20 11:33:59 -0700 | [diff] [blame] | 29 | return kSkipTiled_Flag | kAsBench_Flag; |
commit-bot@chromium.org | a90c680 | 2014-04-30 13:20:45 +0000 | [diff] [blame] | 30 | } |
| 31 | |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame^] | 32 | SkString onShortName() SK_OVERRIDE { |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 33 | return SkString("circular-clips"); |
| 34 | } |
| 35 | |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame^] | 36 | SkISize onISize() SK_OVERRIDE { |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 37 | return SkISize::Make(800, 600); |
| 38 | } |
| 39 | |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame^] | 40 | void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 41 | SkRegion::Op ops[] = { |
| 42 | SkRegion::kDifference_Op, |
| 43 | SkRegion::kIntersect_Op, |
| 44 | SkRegion::kUnion_Op, |
| 45 | SkRegion::kXOR_Op, |
| 46 | SkRegion::kReverseDifference_Op, |
| 47 | SkRegion::kReplace_Op, |
| 48 | }; |
| 49 | |
reed | bbf3e89 | 2014-06-20 11:33:59 -0700 | [diff] [blame] | 50 | 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] | 51 | |
| 52 | SkPaint fillPaint; |
| 53 | |
| 54 | for (size_t i = 0; i < 4; i++) { |
reed | bbf3e89 | 2014-06-20 11:33:59 -0700 | [diff] [blame] | 55 | fCircle1.toggleInverseFillType(); |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 56 | if (i % 2 == 0) { |
reed | bbf3e89 | 2014-06-20 11:33:59 -0700 | [diff] [blame] | 57 | fCircle2.toggleInverseFillType(); |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | canvas->save(); |
| 61 | for (size_t op = 0; op < SK_ARRAY_COUNT(ops); op++) { |
| 62 | canvas->save(); |
| 63 | |
reed | bbf3e89 | 2014-06-20 11:33:59 -0700 | [diff] [blame] | 64 | canvas->clipPath(fCircle1, SkRegion::kReplace_Op); |
| 65 | canvas->clipPath(fCircle2, ops[op]); |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 66 | |
| 67 | canvas->drawRect(rect, fillPaint); |
| 68 | |
| 69 | canvas->restore(); |
reed | bbf3e89 | 2014-06-20 11:33:59 -0700 | [diff] [blame] | 70 | canvas->translate(0, 2 * fY); |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 71 | } |
| 72 | canvas->restore(); |
reed | bbf3e89 | 2014-06-20 11:33:59 -0700 | [diff] [blame] | 73 | canvas->translate(fX1 + fX2, 0); |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 74 | } |
| 75 | } |
| 76 | |
| 77 | private: |
reed | bbf3e89 | 2014-06-20 11:33:59 -0700 | [diff] [blame] | 78 | typedef skiagm::GM INHERITED; |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | ////////////////////////////////////////////////////////////////////////////// |
| 82 | |
| 83 | DEF_GM( return new CircularClipsGM; ) |