blob: 6f286bae26bf6c95cf4751220c8d10359d436272 [file] [log] [blame]
bsalomonbed83a62015-04-15 14:18:34 -07001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
9#include "include/core/SkCanvas.h"
10#include "include/core/SkShader.h"
bsalomonbed83a62015-04-15 14:18:34 -070011
bsalomonbed83a62015-04-15 14:18:34 -070012/** This GM draws with invalid paints. It should draw nothing other than the background. */
13class BadPaintGM : public skiagm::GM {
14 public:
15 BadPaintGM() {}
16
17protected:
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
bsalomonbed83a62015-04-15 14:18:34 -070032 // Empty bitmap.
33 fPaints.push_back().setColor(SK_ColorGREEN);
Mike Reed50acf8f2019-04-08 13:20:23 -040034 fPaints.back().setShader(emptyBmp.makeShader());
bsalomonbed83a62015-04-15 14:18:34 -070035
36 // Non-invertible local matrix.
37 fPaints.push_back().setColor(SK_ColorGREEN);
Mike Reed50acf8f2019-04-08 13:20:23 -040038 fPaints.back().setShader(blueBmp.makeShader(&badMatrix));
bsalomonbed83a62015-04-15 14:18:34 -070039 }
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
48private:
49 SkTArray<SkPaint> fPaints;
50
51 typedef skiagm::GM INHERITED;
52};
53
54/////////////////////////////////////////////////////////////////////////////////////
55
halcanary385fe4d2015-08-26 13:07:48 -070056DEF_GM(return new BadPaintGM;)