george | b3eba47 | 2014-09-09 11:33:57 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 12 | class ClipStrokeRectGM : public skiagm::GM { |
| 13 | public: |
| 14 | ClipStrokeRectGM() { |
| 15 | |
| 16 | } |
| 17 | |
| 18 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 19 | SkString onShortName() override { |
george | b3eba47 | 2014-09-09 11:33:57 -0700 | [diff] [blame] | 20 | return SkString("clip_strokerect"); |
| 21 | } |
| 22 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 23 | SkISize onISize() override { |
george | b3eba47 | 2014-09-09 11:33:57 -0700 | [diff] [blame] | 24 | return SkISize::Make(200, 400); |
| 25 | } |
| 26 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 27 | void onDraw(SkCanvas* canvas) override { |
george | b3eba47 | 2014-09-09 11:33:57 -0700 | [diff] [blame] | 28 | 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(); |
reed | 6699838 | 2016-09-21 11:15:07 -0700 | [diff] [blame] | 39 | canvas->clipRect(rect, true); |
george | b3eba47 | 2014-09-09 11:33:57 -0700 | [diff] [blame] | 40 | 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(); |
reed | 6699838 | 2016-09-21 11:15:07 -0700 | [diff] [blame] | 57 | canvas->clipRect(rect2, true); |
george | b3eba47 | 2014-09-09 11:33:57 -0700 | [diff] [blame] | 58 | canvas->drawRect(r2, p); |
| 59 | canvas->restore(); |
| 60 | |
| 61 | p.setColor(SK_ColorBLUE); |
| 62 | p.setStrokeWidth(2); |
| 63 | canvas->drawRect(rect2, p); |
| 64 | } |
| 65 | |
george | b3eba47 | 2014-09-09 11:33:57 -0700 | [diff] [blame] | 66 | private: |
| 67 | typedef skiagm::GM INHERITED; |
| 68 | }; |
| 69 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 70 | DEF_GM(return new ClipStrokeRectGM;) |