blob: e04692bfacc247c758cda8f9d1f156d6790e8cba [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:
commit-bot@chromium.orga90c6802014-04-30 13:20:45 +000027 virtual uint32_t onGetFlags() const SK_OVERRIDE {
28 return kSkipTiled_Flag;
29 }
30
caryclark@google.com45a75fb2013-04-25 13:34:40 +000031 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.com84b18c72014-04-13 19:09:42 +000040 SkPictureRecorder recorder;
commit-bot@chromium.org5fb2ce32014-04-17 23:35:06 +000041 SkCanvas* rec = recorder.beginRecording(1200, 900, NULL, 0);
caryclark@google.com45a75fb2013-04-25 13:34:40 +000042 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.com84b18c72014-04-13 19:09:42 +000054 SkAutoTUnref<SkPicture> pict(recorder.endRecording());
caryclark@google.com45a75fb2013-04-25 13:34:40 +000055
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.com45a75fb2013-04-25 13:34:40 +000066 }
67
68private:
69 typedef GM INHERITED;
70};
71
72//////////////////////////////////////////////////////////////////////////////
73
74static GM* MyFactory(void*) { return new PathOpsSkpClipGM; }
75static GMRegistry reg(MyFactory);
76
77}