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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "gm/gm.h" |
| 9 | #include "include/core/SkCanvas.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 10 | #include "include/core/SkColor.h" |
| 11 | #include "include/core/SkPaint.h" |
| 12 | #include "include/core/SkRect.h" |
| 13 | #include "include/core/SkSize.h" |
| 14 | #include "include/core/SkString.h" |
george | b3eba47 | 2014-09-09 11:33:57 -0700 | [diff] [blame] | 15 | |
| 16 | class ClipStrokeRectGM : public skiagm::GM { |
| 17 | public: |
| 18 | ClipStrokeRectGM() { |
| 19 | |
| 20 | } |
| 21 | |
| 22 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 23 | SkString onShortName() override { |
george | b3eba47 | 2014-09-09 11:33:57 -0700 | [diff] [blame] | 24 | return SkString("clip_strokerect"); |
| 25 | } |
| 26 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 27 | SkISize onISize() override { |
george | b3eba47 | 2014-09-09 11:33:57 -0700 | [diff] [blame] | 28 | return SkISize::Make(200, 400); |
| 29 | } |
| 30 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 31 | void onDraw(SkCanvas* canvas) override { |
george | b3eba47 | 2014-09-09 11:33:57 -0700 | [diff] [blame] | 32 | SkPaint p; |
| 33 | p.setColor(SK_ColorRED); |
| 34 | p.setAntiAlias(true); |
| 35 | p.setStyle(SkPaint::kStroke_Style); |
| 36 | p.setStrokeWidth(22); |
| 37 | |
| 38 | SkRect r = SkRect::MakeXYWH(20, 20, 100, 100); |
| 39 | // setting the height of this to 19 causes failure |
| 40 | SkRect rect = SkRect::MakeXYWH(20, 0, 100, 20); |
| 41 | |
| 42 | canvas->save(); |
reed | 6699838 | 2016-09-21 11:15:07 -0700 | [diff] [blame] | 43 | canvas->clipRect(rect, true); |
george | b3eba47 | 2014-09-09 11:33:57 -0700 | [diff] [blame] | 44 | canvas->drawRect(r, p); |
| 45 | canvas->restore(); |
| 46 | |
| 47 | p.setColor(SK_ColorBLUE); |
| 48 | p.setStrokeWidth(2); |
| 49 | canvas->drawRect(rect, p); |
| 50 | |
| 51 | p.setColor(SK_ColorRED); |
| 52 | p.setAntiAlias(true); |
| 53 | p.setStyle(SkPaint::kStroke_Style); |
| 54 | p.setStrokeWidth(22); |
| 55 | |
| 56 | SkRect r2 = SkRect::MakeXYWH(20, 140, 100, 100); |
| 57 | // setting the height of this to 19 causes failure |
| 58 | SkRect rect2 = SkRect::MakeXYWH(20, 120, 100, 19); |
| 59 | |
| 60 | canvas->save(); |
reed | 6699838 | 2016-09-21 11:15:07 -0700 | [diff] [blame] | 61 | canvas->clipRect(rect2, true); |
george | b3eba47 | 2014-09-09 11:33:57 -0700 | [diff] [blame] | 62 | canvas->drawRect(r2, p); |
| 63 | canvas->restore(); |
| 64 | |
| 65 | p.setColor(SK_ColorBLUE); |
| 66 | p.setStrokeWidth(2); |
| 67 | canvas->drawRect(rect2, p); |
| 68 | } |
| 69 | |
george | b3eba47 | 2014-09-09 11:33:57 -0700 | [diff] [blame] | 70 | private: |
| 71 | typedef skiagm::GM INHERITED; |
| 72 | }; |
| 73 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 74 | DEF_GM(return new ClipStrokeRectGM;) |