robertphillips | 028b98a | 2015-01-14 09:44:02 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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 | |
| 10 | namespace skiagm { |
| 11 | |
| 12 | // This GM exercises the use case found in crbug.com/423834. |
| 13 | // The following pattern: |
robertphillips | e85a32d | 2015-02-10 08:16:55 -0800 | [diff] [blame] | 14 | // save(); |
| 15 | // clipRect(rect, noAA); |
| 16 | // drawRect(bigRect, noAA); |
| 17 | // restore(); |
| 18 | // |
| 19 | // drawRect(rect, noAA); |
robertphillips | 028b98a | 2015-01-14 09:44:02 -0800 | [diff] [blame] | 20 | // can leave 1 pixel wide remnants of the first rect. |
| 21 | class ClipDrawDrawGM : public GM { |
| 22 | public: |
robertphillips | e85a32d | 2015-02-10 08:16:55 -0800 | [diff] [blame] | 23 | ClipDrawDrawGM() { this->setBGColor(0xFFCCCCCC); } |
robertphillips | 028b98a | 2015-01-14 09:44:02 -0800 | [diff] [blame] | 24 | |
| 25 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 26 | SkString onShortName() override { return SkString("clipdrawdraw"); } |
robertphillips | 028b98a | 2015-01-14 09:44:02 -0800 | [diff] [blame] | 27 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 28 | SkISize onISize() override { return SkISize::Make(512, 512); } |
robertphillips | 028b98a | 2015-01-14 09:44:02 -0800 | [diff] [blame] | 29 | |
robertphillips | e85a32d | 2015-02-10 08:16:55 -0800 | [diff] [blame] | 30 | static void Draw(SkCanvas* canvas, const SkRect& rect) { |
robertphillips | 028b98a | 2015-01-14 09:44:02 -0800 | [diff] [blame] | 31 | SkPaint p; |
robertphillips | 028b98a | 2015-01-14 09:44:02 -0800 | [diff] [blame] | 32 | p.setAntiAlias(false); |
robertphillips | 028b98a | 2015-01-14 09:44:02 -0800 | [diff] [blame] | 33 | |
robertphillips | e85a32d | 2015-02-10 08:16:55 -0800 | [diff] [blame] | 34 | const SkRect bigRect = SkRect::MakeWH(600, 600); |
robertphillips | 028b98a | 2015-01-14 09:44:02 -0800 | [diff] [blame] | 35 | |
| 36 | canvas->save(); |
robertphillips | e85a32d | 2015-02-10 08:16:55 -0800 | [diff] [blame] | 37 | // draw a black rect through the clip |
| 38 | canvas->save(); |
| 39 | canvas->clipRect(rect); |
| 40 | canvas->drawRect(bigRect, p); |
| 41 | canvas->restore(); |
robertphillips | 028b98a | 2015-01-14 09:44:02 -0800 | [diff] [blame] | 42 | |
robertphillips | e85a32d | 2015-02-10 08:16:55 -0800 | [diff] [blame] | 43 | // now draw the white rect on top |
| 44 | p.setColor(SK_ColorWHITE); |
| 45 | canvas->drawRect(rect, p); |
robertphillips | 028b98a | 2015-01-14 09:44:02 -0800 | [diff] [blame] | 46 | canvas->restore(); |
| 47 | } |
| 48 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 49 | void onDraw(SkCanvas* canvas) override { |
robertphillips | e85a32d | 2015-02-10 08:16:55 -0800 | [diff] [blame] | 50 | // Vertical remnant |
| 51 | const SkRect rect1 = SkRect::MakeLTRB(136.5f, 137.5f, 338.5f, 293.5f); |
| 52 | |
| 53 | // Horizontal remnant |
| 54 | // 179.488 rounds the right way (i.e., 179), 179.499 rounds the wrong way (i.e., 180) |
| 55 | const SkRect rect2 = SkRect::MakeLTRB(207.5f, 179.499f, 530.5f, 429.5f); |
| 56 | |
| 57 | Draw(canvas, rect1); |
| 58 | Draw(canvas, rect2); |
robertphillips | 028b98a | 2015-01-14 09:44:02 -0800 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | private: |
| 62 | typedef GM INHERITED; |
| 63 | }; |
| 64 | |
| 65 | ////////////////////////////////////////////////////////////////////////////// |
| 66 | |
| 67 | DEF_GM(return SkNEW(ClipDrawDrawGM);) |
| 68 | |
| 69 | } |