caryclark@google.com | 45a75fb | 2013-04-25 13:34:40 +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 "SkBitmap.h" |
| 10 | #include "SkCanvas.h" |
| 11 | #include "SkClipStack.h" |
caryclark@google.com | 45a75fb | 2013-04-25 13:34:40 +0000 | [diff] [blame] | 12 | #include "SkPath.h" |
| 13 | #include "SkPathOps.h" |
| 14 | #include "SkPicture.h" |
robertphillips@google.com | 770963f | 2014-04-18 18:04:41 +0000 | [diff] [blame] | 15 | #include "SkPictureRecorder.h" |
caryclark@google.com | 45a75fb | 2013-04-25 13:34:40 +0000 | [diff] [blame] | 16 | #include "SkRect.h" |
| 17 | |
| 18 | namespace skiagm { |
| 19 | |
| 20 | class PathOpsSkpClipGM : public GM { |
| 21 | public: |
| 22 | PathOpsSkpClipGM() { |
| 23 | } |
| 24 | |
| 25 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 26 | SkString onShortName() override { |
caryclark@google.com | 45a75fb | 2013-04-25 13:34:40 +0000 | [diff] [blame] | 27 | return SkString("pathopsskpclip"); |
| 28 | } |
| 29 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 30 | SkISize onISize() override { |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 31 | return SkISize::Make(1200, 900); |
caryclark@google.com | 45a75fb | 2013-04-25 13:34:40 +0000 | [diff] [blame] | 32 | } |
| 33 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 34 | void onDraw(SkCanvas* canvas) override { |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 35 | SkPictureRecorder recorder; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 36 | SkCanvas* rec = recorder.beginRecording(1200, 900, nullptr, 0); |
caryclark@google.com | 45a75fb | 2013-04-25 13:34:40 +0000 | [diff] [blame] | 37 | SkPath p; |
| 38 | SkRect r = { |
| 39 | SkIntToScalar(100), |
| 40 | SkIntToScalar(200), |
| 41 | SkIntToScalar(400), |
| 42 | SkIntToScalar(700) |
| 43 | }; |
| 44 | p.addRoundRect(r, SkIntToScalar(50), SkIntToScalar(50)); |
reed | 6699838 | 2016-09-21 11:15:07 -0700 | [diff] [blame^] | 45 | rec->clipPath(p, true); |
caryclark@google.com | 45a75fb | 2013-04-25 13:34:40 +0000 | [diff] [blame] | 46 | rec->translate(SkIntToScalar(250), SkIntToScalar(250)); |
reed | 6699838 | 2016-09-21 11:15:07 -0700 | [diff] [blame^] | 47 | rec->clipPath(p, true); |
caryclark@google.com | 45a75fb | 2013-04-25 13:34:40 +0000 | [diff] [blame] | 48 | rec->drawColor(0xffff0000); |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 49 | sk_sp<SkPicture> pict(recorder.finishRecordingAsPicture()); |
caryclark@google.com | 45a75fb | 2013-04-25 13:34:40 +0000 | [diff] [blame] | 50 | |
| 51 | canvas->setAllowSimplifyClip(true); |
| 52 | canvas->save(); |
robertphillips | 9b14f26 | 2014-06-04 05:40:44 -0700 | [diff] [blame] | 53 | canvas->drawPicture(pict); |
caryclark@google.com | 45a75fb | 2013-04-25 13:34:40 +0000 | [diff] [blame] | 54 | canvas->restore(); |
| 55 | |
| 56 | canvas->setAllowSimplifyClip(false); |
| 57 | canvas->save(); |
| 58 | canvas->translate(SkIntToScalar(1200 / 2), 0); |
robertphillips | 9b14f26 | 2014-06-04 05:40:44 -0700 | [diff] [blame] | 59 | canvas->drawPicture(pict); |
caryclark@google.com | 45a75fb | 2013-04-25 13:34:40 +0000 | [diff] [blame] | 60 | canvas->restore(); |
caryclark@google.com | 45a75fb | 2013-04-25 13:34:40 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | private: |
| 64 | typedef GM INHERITED; |
| 65 | }; |
| 66 | |
| 67 | ////////////////////////////////////////////////////////////////////////////// |
| 68 | |
| 69 | static GM* MyFactory(void*) { return new PathOpsSkpClipGM; } |
| 70 | static GMRegistry reg(MyFactory); |
| 71 | |
| 72 | } |