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