blob: 75e7bd8350747f28826a8a0ccf7a0a0685a3582b [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -05009#include "include/core/SkCanvas.h"
10#include "include/core/SkPath.h"
11#include "include/core/SkPicture.h"
12#include "include/core/SkPictureRecorder.h"
13#include "include/core/SkRect.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040014#include "include/core/SkRefCnt.h"
15#include "include/core/SkScalar.h"
16#include "include/core/SkSize.h"
17#include "include/core/SkString.h"
caryclark@google.com45a75fb2013-04-25 13:34:40 +000018
19namespace skiagm {
20
21class PathOpsSkpClipGM : public GM {
22public:
23 PathOpsSkpClipGM() {
24 }
25
26protected:
mtklein36352bf2015-03-25 18:17:31 -070027 SkString onShortName() override {
caryclark@google.com45a75fb2013-04-25 13:34:40 +000028 return SkString("pathopsskpclip");
29 }
30
mtklein36352bf2015-03-25 18:17:31 -070031 SkISize onISize() override {
tfarinaf5393182014-06-09 23:59:03 -070032 return SkISize::Make(1200, 900);
caryclark@google.com45a75fb2013-04-25 13:34:40 +000033 }
34
mtklein36352bf2015-03-25 18:17:31 -070035 void onDraw(SkCanvas* canvas) override {
robertphillips@google.com84b18c72014-04-13 19:09:42 +000036 SkPictureRecorder recorder;
halcanary96fcdcc2015-08-27 07:41:13 -070037 SkCanvas* rec = recorder.beginRecording(1200, 900, nullptr, 0);
caryclark@google.com45a75fb2013-04-25 13:34:40 +000038 SkPath p;
39 SkRect r = {
40 SkIntToScalar(100),
41 SkIntToScalar(200),
42 SkIntToScalar(400),
43 SkIntToScalar(700)
44 };
45 p.addRoundRect(r, SkIntToScalar(50), SkIntToScalar(50));
reed66998382016-09-21 11:15:07 -070046 rec->clipPath(p, true);
caryclark@google.com45a75fb2013-04-25 13:34:40 +000047 rec->translate(SkIntToScalar(250), SkIntToScalar(250));
reed66998382016-09-21 11:15:07 -070048 rec->clipPath(p, true);
caryclark@google.com45a75fb2013-04-25 13:34:40 +000049 rec->drawColor(0xffff0000);
reedca2622b2016-03-18 07:25:55 -070050 sk_sp<SkPicture> pict(recorder.finishRecordingAsPicture());
caryclark@google.com45a75fb2013-04-25 13:34:40 +000051
52 canvas->setAllowSimplifyClip(true);
53 canvas->save();
robertphillips9b14f262014-06-04 05:40:44 -070054 canvas->drawPicture(pict);
caryclark@google.com45a75fb2013-04-25 13:34:40 +000055 canvas->restore();
56
57 canvas->setAllowSimplifyClip(false);
58 canvas->save();
59 canvas->translate(SkIntToScalar(1200 / 2), 0);
robertphillips9b14f262014-06-04 05:40:44 -070060 canvas->drawPicture(pict);
caryclark@google.com45a75fb2013-04-25 13:34:40 +000061 canvas->restore();
caryclark@google.com45a75fb2013-04-25 13:34:40 +000062 }
63
64private:
65 typedef GM INHERITED;
66};
67
68//////////////////////////////////////////////////////////////////////////////
69
Hal Canarye964c182019-01-23 10:22:01 -050070DEF_GM( return new PathOpsSkpClipGM; )
caryclark@google.com45a75fb2013-04-25 13:34:40 +000071
72}