Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
badpaint.cpp
Go to the documentation of this file.
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/gm.h"
14#include "include/core/SkRect.h"
16#include "include/core/SkSize.h"
19
20using namespace skia_private;
21
22/** This GM draws with invalid paints. It should draw nothing other than the background. */
23class BadPaintGM : public skiagm::GM {
24 public:
26
27protected:
28 SkString getName() const override { return SkString("badpaint"); }
29
30 SkISize getISize() override { return SkISize::Make(100, 100); }
31
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
42 // Empty bitmap.
44 fPaints.back().setShader(emptyBmp.makeShader(SkSamplingOptions()));
45
46 // Non-invertible local matrix.
48 fPaints.back().setShader(blueBmp.makeShader(SkSamplingOptions(), badMatrix));
49 }
50
51 void onDraw(SkCanvas* canvas) override {
52 SkRect rect = SkRect::MakeXYWH(10, 10, 80, 80);
53 for (int i = 0; i < fPaints.size(); ++i) {
54 canvas->drawRect(rect, fPaints[i]);
55 }
56 }
57
58private:
59 TArray<SkPaint> fPaints;
60
61 using INHERITED = skiagm::GM;
62};
63
64/////////////////////////////////////////////////////////////////////////////////////
65
66DEF_GM(return new BadPaintGM;)
constexpr SkColor SK_ColorBLUE
Definition SkColor.h:135
constexpr SkColor SK_ColorGREEN
Definition SkColor.h:131
void onOnceBeforeDraw() override
Definition badpaint.cpp:32
SkISize getISize() override
Definition badpaint.cpp:30
SkString getName() const override
Definition badpaint.cpp:28
void onDraw(SkCanvas *canvas) override
Definition badpaint.cpp:51
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
Definition SkBitmap.cpp:669
void allocN32Pixels(int width, int height, bool isOpaque=false)
Definition SkBitmap.cpp:232
void eraseColor(SkColor4f) const
Definition SkBitmap.cpp:442
void drawRect(const SkRect &rect, const SkPaint &paint)
SkMatrix & setAll(SkScalar scaleX, SkScalar skewX, SkScalar transX, SkScalar skewY, SkScalar scaleY, SkScalar transY, SkScalar persp0, SkScalar persp1, SkScalar persp2)
Definition SkMatrix.h:562
void setColor(SkColor color)
Definition SkPaint.cpp:119
void setShader(sk_sp< SkShader > shader)
int size() const
Definition SkTArray.h:416
#define DEF_GM(CODE)
Definition gm.h:40
static constexpr SkISize Make(int32_t w, int32_t h)
Definition SkSize.h:20
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659