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" |
| 12 | #include "SkDevice.h" |
| 13 | #include "SkPath.h" |
| 14 | #include "SkPathOps.h" |
| 15 | #include "SkPicture.h" |
robertphillips@google.com | 770963f | 2014-04-18 18:04:41 +0000 | [diff] [blame] | 16 | #include "SkPictureRecorder.h" |
caryclark@google.com | 45a75fb | 2013-04-25 13:34:40 +0000 | [diff] [blame] | 17 | #include "SkRect.h" |
| 18 | |
| 19 | namespace skiagm { |
| 20 | |
| 21 | class PathOpsSkpClipGM : public GM { |
| 22 | public: |
| 23 | PathOpsSkpClipGM() { |
| 24 | } |
| 25 | |
| 26 | protected: |
commit-bot@chromium.org | a90c680 | 2014-04-30 13:20:45 +0000 | [diff] [blame] | 27 | virtual uint32_t onGetFlags() const SK_OVERRIDE { |
| 28 | return kSkipTiled_Flag; |
| 29 | } |
| 30 | |
caryclark@google.com | 45a75fb | 2013-04-25 13:34:40 +0000 | [diff] [blame] | 31 | virtual SkString onShortName() SK_OVERRIDE { |
| 32 | return SkString("pathopsskpclip"); |
| 33 | } |
| 34 | |
| 35 | virtual SkISize onISize() SK_OVERRIDE { |
| 36 | return make_isize(1200, 900); |
| 37 | } |
| 38 | |
| 39 | virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 40 | SkPictureRecorder recorder; |
commit-bot@chromium.org | 5fb2ce3 | 2014-04-17 23:35:06 +0000 | [diff] [blame] | 41 | SkCanvas* rec = recorder.beginRecording(1200, 900, NULL, 0); |
caryclark@google.com | 45a75fb | 2013-04-25 13:34:40 +0000 | [diff] [blame] | 42 | SkPath p; |
| 43 | SkRect r = { |
| 44 | SkIntToScalar(100), |
| 45 | SkIntToScalar(200), |
| 46 | SkIntToScalar(400), |
| 47 | SkIntToScalar(700) |
| 48 | }; |
| 49 | p.addRoundRect(r, SkIntToScalar(50), SkIntToScalar(50)); |
| 50 | rec->clipPath(p, SkRegion::kIntersect_Op, true); |
| 51 | rec->translate(SkIntToScalar(250), SkIntToScalar(250)); |
| 52 | rec->clipPath(p, SkRegion::kIntersect_Op, true); |
| 53 | rec->drawColor(0xffff0000); |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 54 | SkAutoTUnref<SkPicture> pict(recorder.endRecording()); |
caryclark@google.com | 45a75fb | 2013-04-25 13:34:40 +0000 | [diff] [blame] | 55 | |
| 56 | canvas->setAllowSimplifyClip(true); |
| 57 | canvas->save(); |
| 58 | canvas->drawPicture(*pict); |
| 59 | canvas->restore(); |
| 60 | |
| 61 | canvas->setAllowSimplifyClip(false); |
| 62 | canvas->save(); |
| 63 | canvas->translate(SkIntToScalar(1200 / 2), 0); |
| 64 | canvas->drawPicture(*pict); |
| 65 | canvas->restore(); |
caryclark@google.com | 45a75fb | 2013-04-25 13:34:40 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | private: |
| 69 | typedef GM INHERITED; |
| 70 | }; |
| 71 | |
| 72 | ////////////////////////////////////////////////////////////////////////////// |
| 73 | |
| 74 | static GM* MyFactory(void*) { return new PathOpsSkpClipGM; } |
| 75 | static GMRegistry reg(MyFactory); |
| 76 | |
| 77 | } |