blob: 34adf8a1cf941a2275fa769b20d3597ab2436fa7 [file] [log] [blame]
georgeb3eba472014-09-09 11:33:57 -07001/*
2 * Copyright 2011 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 "SkCanvas.h"
10#include "SkPath.h"
11
12class ClipStrokeRectGM : public skiagm::GM {
13public:
14 ClipStrokeRectGM() {
15
16 }
17
18protected:
mtklein36352bf2015-03-25 18:17:31 -070019 SkString onShortName() override {
georgeb3eba472014-09-09 11:33:57 -070020 return SkString("clip_strokerect");
21 }
22
mtklein36352bf2015-03-25 18:17:31 -070023 SkISize onISize() override {
georgeb3eba472014-09-09 11:33:57 -070024 return SkISize::Make(200, 400);
25 }
26
mtklein36352bf2015-03-25 18:17:31 -070027 void onDraw(SkCanvas* canvas) override {
georgeb3eba472014-09-09 11:33:57 -070028 SkPaint p;
29 p.setColor(SK_ColorRED);
30 p.setAntiAlias(true);
31 p.setStyle(SkPaint::kStroke_Style);
32 p.setStrokeWidth(22);
33
34 SkRect r = SkRect::MakeXYWH(20, 20, 100, 100);
35 // setting the height of this to 19 causes failure
36 SkRect rect = SkRect::MakeXYWH(20, 0, 100, 20);
37
38 canvas->save();
reed66998382016-09-21 11:15:07 -070039 canvas->clipRect(rect, true);
georgeb3eba472014-09-09 11:33:57 -070040 canvas->drawRect(r, p);
41 canvas->restore();
42
43 p.setColor(SK_ColorBLUE);
44 p.setStrokeWidth(2);
45 canvas->drawRect(rect, p);
46
47 p.setColor(SK_ColorRED);
48 p.setAntiAlias(true);
49 p.setStyle(SkPaint::kStroke_Style);
50 p.setStrokeWidth(22);
51
52 SkRect r2 = SkRect::MakeXYWH(20, 140, 100, 100);
53 // setting the height of this to 19 causes failure
54 SkRect rect2 = SkRect::MakeXYWH(20, 120, 100, 19);
55
56 canvas->save();
reed66998382016-09-21 11:15:07 -070057 canvas->clipRect(rect2, true);
georgeb3eba472014-09-09 11:33:57 -070058 canvas->drawRect(r2, p);
59 canvas->restore();
60
61 p.setColor(SK_ColorBLUE);
62 p.setStrokeWidth(2);
63 canvas->drawRect(rect2, p);
64 }
65
georgeb3eba472014-09-09 11:33:57 -070066private:
67 typedef skiagm::GM INHERITED;
68};
69
halcanary385fe4d2015-08-26 13:07:48 -070070DEF_GM(return new ClipStrokeRectGM;)