blob: dd7ab2e68335ee1cdaa0d381fc27f8494e33c87b [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"
Kevin Lubickdc6cc022023-01-13 11:24:27 -050018#include "include/private/base/SkTArray.h"
bsalomonbed83a62015-04-15 14:18:34 -070019
Herb Derbyec96c212023-03-06 10:31:22 -050020using namespace skia_private;
21
bsalomonbed83a62015-04-15 14:18:34 -070022/** This GM draws with invalid paints. It should draw nothing other than the background. */
23class BadPaintGM : public skiagm::GM {
24 public:
25 BadPaintGM() {}
26
27protected:
Leandro Lovisolo24fa2112023-08-15 19:05:17 +000028 SkString getName() const override { return SkString("badpaint"); }
bsalomonbed83a62015-04-15 14:18:34 -070029
Leandro Lovisolo8f023882023-08-15 21:13:52 +000030 SkISize getISize() override { return SkISize::Make(100, 100); }
bsalomonbed83a62015-04-15 14:18:34 -070031
32 void onOnceBeforeDraw() override {
33 SkBitmap emptyBmp;
34
35 SkBitmap blueBmp;
36 blueBmp.allocN32Pixels(10, 10);
37 blueBmp.eraseColor(SK_ColorBLUE);
38
39 SkMatrix badMatrix;
40 badMatrix.setAll(0, 0, 0, 0, 0, 0, 0, 0, 0);
41
bsalomonbed83a62015-04-15 14:18:34 -070042 // Empty bitmap.
43 fPaints.push_back().setColor(SK_ColorGREEN);
Mike Reed82abece2020-12-12 09:51:11 -050044 fPaints.back().setShader(emptyBmp.makeShader(SkSamplingOptions()));
bsalomonbed83a62015-04-15 14:18:34 -070045
46 // Non-invertible local matrix.
47 fPaints.push_back().setColor(SK_ColorGREEN);
Mike Reed82abece2020-12-12 09:51:11 -050048 fPaints.back().setShader(blueBmp.makeShader(SkSamplingOptions(), badMatrix));
bsalomonbed83a62015-04-15 14:18:34 -070049 }
50
51 void onDraw(SkCanvas* canvas) override {
52 SkRect rect = SkRect::MakeXYWH(10, 10, 80, 80);
Herb Derbyffacce52022-11-09 10:51:34 -050053 for (int i = 0; i < fPaints.size(); ++i) {
bsalomonbed83a62015-04-15 14:18:34 -070054 canvas->drawRect(rect, fPaints[i]);
55 }
56 }
57
58private:
Herb Derbyec96c212023-03-06 10:31:22 -050059 TArray<SkPaint> fPaints;
bsalomonbed83a62015-04-15 14:18:34 -070060
John Stiles7571f9e2020-09-02 22:42:33 -040061 using INHERITED = skiagm::GM;
bsalomonbed83a62015-04-15 14:18:34 -070062};
63
64/////////////////////////////////////////////////////////////////////////////////////
65
halcanary385fe4d2015-08-26 13:07:48 -070066DEF_GM(return new BadPaintGM;)