blob: da7dbd5411126cb0f81e1e4ded2ba4c09e8bf103 [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"
Ben Wagner6a34f3a2019-05-01 10:59:30 -04009#include "include/core/SkBitmap.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "include/core/SkCanvas.h"
Ben Wagner6a34f3a2019-05-01 10:59:30 -040011#include "include/core/SkColor.h"
12#include "include/core/SkMatrix.h"
13#include "include/core/SkPaint.h"
14#include "include/core/SkRect.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050015#include "include/core/SkShader.h"
Ben Wagner6a34f3a2019-05-01 10:59:30 -040016#include "include/core/SkSize.h"
17#include "include/core/SkString.h"
18#include "include/private/SkTArray.h"
bsalomonbed83a62015-04-15 14:18:34 -070019
bsalomonbed83a62015-04-15 14:18:34 -070020/** This GM draws with invalid paints. It should draw nothing other than the background. */
21class BadPaintGM : public skiagm::GM {
22 public:
23 BadPaintGM() {}
24
25protected:
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
bsalomonbed83a62015-04-15 14:18:34 -070040 // Empty bitmap.
41 fPaints.push_back().setColor(SK_ColorGREEN);
Mike Reed50acf8f2019-04-08 13:20:23 -040042 fPaints.back().setShader(emptyBmp.makeShader());
bsalomonbed83a62015-04-15 14:18:34 -070043
44 // Non-invertible local matrix.
45 fPaints.push_back().setColor(SK_ColorGREEN);
Mike Reed50acf8f2019-04-08 13:20:23 -040046 fPaints.back().setShader(blueBmp.makeShader(&badMatrix));
bsalomonbed83a62015-04-15 14:18:34 -070047 }
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
56private:
57 SkTArray<SkPaint> fPaints;
58
59 typedef skiagm::GM INHERITED;
60};
61
62/////////////////////////////////////////////////////////////////////////////////////
63
halcanary385fe4d2015-08-26 13:07:48 -070064DEF_GM(return new BadPaintGM;)