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