blob: c9092f4ad282b3df98cdb9e00528588ee5afc3df [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"
12#include "SkDevice.h"
13#include "SkPath.h"
14#include "SkPathOps.h"
15#include "SkPicture.h"
robertphillips@google.com770963f2014-04-18 18:04:41 +000016#include "SkPictureRecorder.h"
caryclark@google.com45a75fb2013-04-25 13:34:40 +000017#include "SkRect.h"
18
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;
commit-bot@chromium.org5fb2ce32014-04-17 23:35:06 +000037 SkCanvas* rec = recorder.beginRecording(1200, 900, NULL, 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));
46 rec->clipPath(p, SkRegion::kIntersect_Op, true);
47 rec->translate(SkIntToScalar(250), SkIntToScalar(250));
48 rec->clipPath(p, SkRegion::kIntersect_Op, true);
49 rec->drawColor(0xffff0000);
robertphillips@google.com84b18c72014-04-13 19:09:42 +000050 SkAutoTUnref<SkPicture> pict(recorder.endRecording());
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
70static GM* MyFactory(void*) { return new PathOpsSkpClipGM; }
71static GMRegistry reg(MyFactory);
72
73}