blob: 2765ceb5de73157ed1695a5f4388ae23472404e1 [file] [log] [blame]
Stan Iliev5f1bb0a2016-12-12 17:39:55 -05001/*
2 * Copyright 2016 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#include "gm.h"
8#include "SkCanvas.h"
9#include "SkPath.h"
10#include "SkClipOpPriv.h"
11
12namespace skiagm {
13
14//this test exercise SkCanvas::setDeviceClipRestriction behavior
15class ComplexClip4GM : public GM {
16public:
17 ComplexClip4GM(bool aaclip)
18 : fDoAAClip(aaclip) {
19 this->setBGColor(0xFFDEDFDE);
20 }
21
22protected:
23
24
25 SkString onShortName() {
26 SkString str;
27 str.printf("complexclip4_%s",
28 fDoAAClip ? "aa" : "bw");
29 return str;
30 }
31
32 SkISize onISize() { return SkISize::Make(970, 780); }
33
34 virtual void onDraw(SkCanvas* canvas) {
35 SkPaint p;
36 p.setAntiAlias(fDoAAClip);
37 p.setColor(SK_ColorYELLOW);
38
39 canvas->save();
40 // draw a yellow rect through a rect clip
41 canvas->save();
42 canvas->androidFramework_setDeviceClipRestriction(SkIRect::MakeLTRB(100, 100, 300, 300));
43 canvas->drawColor(SK_ColorGREEN);
44 canvas->clipRect(SkRect::MakeLTRB(100, 200, 400, 500),
45 kReplace_SkClipOp, fDoAAClip);
46 canvas->drawRect(SkRect::MakeLTRB(100, 200, 400, 500), p);
47 canvas->restore();
48
49 // draw a yellow rect through a diamond clip
50 canvas->save();
51 canvas->androidFramework_setDeviceClipRestriction(SkIRect::MakeLTRB(500, 100, 800, 300));
52 canvas->drawColor(SK_ColorGREEN);
53
54 SkPath pathClip;
55 pathClip.moveTo(SkIntToScalar(650), SkIntToScalar(200));
56 pathClip.lineTo(SkIntToScalar(900), SkIntToScalar(300));
57 pathClip.lineTo(SkIntToScalar(650), SkIntToScalar(400));
58 pathClip.lineTo(SkIntToScalar(650), SkIntToScalar(300));
59 pathClip.close();
60 canvas->clipPath(pathClip, kReplace_SkClipOp, fDoAAClip);
61 canvas->drawRect(SkRect::MakeLTRB(500, 200, 900, 500), p);
62 canvas->restore();
63
64 // draw a yellow rect through a round rect clip
65 canvas->save();
66 canvas->androidFramework_setDeviceClipRestriction(SkIRect::MakeLTRB(500, 500, 800, 700));
67 canvas->drawColor(SK_ColorGREEN);
68
69 canvas->clipRRect(SkRRect::MakeOval(SkRect::MakeLTRB(500, 600, 900, 750)),
70 kReplace_SkClipOp, fDoAAClip);
71 canvas->drawRect(SkRect::MakeLTRB(500, 600, 900, 750), p);
72 canvas->restore();
73
74 // fill the clip with yellow color showing that androidFramework_setDeviceClipRestriction
75 // intersects with the current clip
76 canvas->save();
77 canvas->clipRect(SkRect::MakeLTRB(100, 400, 300, 750),
78 kIntersect_SkClipOp, fDoAAClip);
79 canvas->drawColor(SK_ColorGREEN);
80 canvas->androidFramework_setDeviceClipRestriction(SkIRect::MakeLTRB(150, 450, 250, 700));
81 canvas->drawColor(SK_ColorYELLOW);
82 canvas->restore();
83
84 canvas->restore();
85 }
86private:
87
88 bool fDoAAClip;
89
90 typedef GM INHERITED;
91};
92
93//////////////////////////////////////////////////////////////////////////////
94
95DEF_GM(return new ComplexClip4GM(false);)
96DEF_GM(return new ComplexClip4GM(true);)
97}