blob: 4e575cae245058cdfac76b6413a686e73e4a19e2 [file] [log] [blame]
caryclark@google.com45a75fb2013-04-25 13:34:40 +00001/*
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.com45a75fb2013-04-25 13:34:40 +000012#include "SkPath.h"
13#include "SkPathOps.h"
14#include "SkPicture.h"
robertphillips@google.com770963f2014-04-18 18:04:41 +000015#include "SkPictureRecorder.h"
caryclark@google.com45a75fb2013-04-25 13:34:40 +000016#include "SkRect.h"
17
18namespace skiagm {
19
20class PathOpsSkpClipGM : public GM {
21public:
22 PathOpsSkpClipGM() {
23 }
24
25protected:
mtklein36352bf2015-03-25 18:17:31 -070026 SkString onShortName() override {
caryclark@google.com45a75fb2013-04-25 13:34:40 +000027 return SkString("pathopsskpclip");
28 }
29
mtklein36352bf2015-03-25 18:17:31 -070030 SkISize onISize() override {
tfarinaf5393182014-06-09 23:59:03 -070031 return SkISize::Make(1200, 900);
caryclark@google.com45a75fb2013-04-25 13:34:40 +000032 }
33
mtklein36352bf2015-03-25 18:17:31 -070034 void onDraw(SkCanvas* canvas) override {
robertphillips@google.com84b18c72014-04-13 19:09:42 +000035 SkPictureRecorder recorder;
halcanary96fcdcc2015-08-27 07:41:13 -070036 SkCanvas* rec = recorder.beginRecording(1200, 900, nullptr, 0);
caryclark@google.com45a75fb2013-04-25 13:34:40 +000037 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));
45 rec->clipPath(p, SkRegion::kIntersect_Op, true);
46 rec->translate(SkIntToScalar(250), SkIntToScalar(250));
47 rec->clipPath(p, SkRegion::kIntersect_Op, true);
48 rec->drawColor(0xffff0000);
reedca2622b2016-03-18 07:25:55 -070049 sk_sp<SkPicture> pict(recorder.finishRecordingAsPicture());
caryclark@google.com45a75fb2013-04-25 13:34:40 +000050
51 canvas->setAllowSimplifyClip(true);
52 canvas->save();
robertphillips9b14f262014-06-04 05:40:44 -070053 canvas->drawPicture(pict);
caryclark@google.com45a75fb2013-04-25 13:34:40 +000054 canvas->restore();
55
56 canvas->setAllowSimplifyClip(false);
57 canvas->save();
58 canvas->translate(SkIntToScalar(1200 / 2), 0);
robertphillips9b14f262014-06-04 05:40:44 -070059 canvas->drawPicture(pict);
caryclark@google.com45a75fb2013-04-25 13:34:40 +000060 canvas->restore();
caryclark@google.com45a75fb2013-04-25 13:34:40 +000061 }
62
63private:
64 typedef GM INHERITED;
65};
66
67//////////////////////////////////////////////////////////////////////////////
68
69static GM* MyFactory(void*) { return new PathOpsSkpClipGM; }
70static GMRegistry reg(MyFactory);
71
72}