bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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" |
| 10 | #include "include/core/SkShader.h" |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 11 | |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 12 | /** This GM draws with invalid paints. It should draw nothing other than the background. */ |
| 13 | class BadPaintGM : public skiagm::GM { |
| 14 | public: |
| 15 | BadPaintGM() {} |
| 16 | |
| 17 | protected: |
| 18 | SkString onShortName() override { return SkString("badpaint"); } |
| 19 | |
| 20 | SkISize onISize() override { return SkISize::Make(100, 100); } |
| 21 | |
| 22 | void onOnceBeforeDraw() override { |
| 23 | SkBitmap emptyBmp; |
| 24 | |
| 25 | SkBitmap blueBmp; |
| 26 | blueBmp.allocN32Pixels(10, 10); |
| 27 | blueBmp.eraseColor(SK_ColorBLUE); |
| 28 | |
| 29 | SkMatrix badMatrix; |
| 30 | badMatrix.setAll(0, 0, 0, 0, 0, 0, 0, 0, 0); |
| 31 | |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 32 | // Empty bitmap. |
| 33 | fPaints.push_back().setColor(SK_ColorGREEN); |
Mike Reed | 50acf8f | 2019-04-08 13:20:23 -0400 | [diff] [blame] | 34 | fPaints.back().setShader(emptyBmp.makeShader()); |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 35 | |
| 36 | // Non-invertible local matrix. |
| 37 | fPaints.push_back().setColor(SK_ColorGREEN); |
Mike Reed | 50acf8f | 2019-04-08 13:20:23 -0400 | [diff] [blame] | 38 | fPaints.back().setShader(blueBmp.makeShader(&badMatrix)); |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | void onDraw(SkCanvas* canvas) override { |
| 42 | SkRect rect = SkRect::MakeXYWH(10, 10, 80, 80); |
| 43 | for (int i = 0; i < fPaints.count(); ++i) { |
| 44 | canvas->drawRect(rect, fPaints[i]); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | private: |
| 49 | SkTArray<SkPaint> fPaints; |
| 50 | |
| 51 | typedef skiagm::GM INHERITED; |
| 52 | }; |
| 53 | |
| 54 | ///////////////////////////////////////////////////////////////////////////////////// |
| 55 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 56 | DEF_GM(return new BadPaintGM;) |