Flutter Engine
The Flutter Engine
filterbug.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2016 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"
17#include "include/core/SkRect.h"
20#include "include/core/SkSize.h"
23
24static sk_sp<SkImage> make_image(int firstBlackRow, int lastBlackRow) {
25 static const int kWidth = 25;
26 static const int kHeight = 27;
27
28 SkBitmap bm;
31 for (int y = firstBlackRow; y < lastBlackRow; ++y) {
32 for (int x = 0; x < kWidth; ++x) {
33 *bm.getAddr32(x, y) = SkPackARGB32(0xFF, 0x0, 0x0, 0x0);
34 }
35 }
36
38 bm.setImmutable();
39
40 return bm.asImage();
41}
42
43// GM to reproduce crbug.com/673261.
44class FilterBugGM : public skiagm::GM {
45public:
47
48protected:
49 SkString getName() const override { return SkString("filterbug"); }
50
51 SkISize getISize() override { return SkISize::Make(150, 150); }
52
53 void onOnceBeforeDraw() override {
54 // The top texture has 5 black rows on top and then 22 white rows on the bottom
55 fTop = make_image(0, 5);
56 // The bottom texture has 5 black rows on the bottom and then 22 white rows on the top
57 fBot = make_image(22, 27);
58 }
59
60 void onDraw(SkCanvas* canvas) override {
61 static const SkSamplingOptions kSampling(SkCubicResampler::Mitchell());
62 static const bool kDoAA = true;
63
64 {
65 SkRect r1 = SkRect::MakeXYWH(50.0f, 0.0f, 50.0f, 50.0f);
66 SkPaint p1;
67 p1.setAntiAlias(kDoAA);
68 SkMatrix localMat;
69 localMat.setScaleTranslate(2.0f, 2.0f, 50.0f, 0.0f);
71 kSampling, &localMat));
72
73 canvas->drawRect(r1, p1);
74 }
75
76 {
77 SkRect r2 = SkRect::MakeXYWH(50.0f, 50.0f, 50.0f, 36.0f);
78
79 SkPaint p2;
81 p2.setAntiAlias(kDoAA);
82
83 canvas->drawRect(r2, p2);
84 }
85
86 {
87 SkRect r3 = SkRect::MakeXYWH(50.0f, 86.0f, 50.0f, 50.0f);
88
89 SkPaint p3;
90 p3.setAntiAlias(kDoAA);
91 SkMatrix localMat;
92 localMat.setScaleTranslate(2.0f, 2.0f, 50.0f, 86.0f);
94 kSampling, &localMat));
95
96 canvas->drawRect(r3, p3);
97 }
98 }
99
100private:
101 sk_sp<SkImage> fTop;
102 sk_sp<SkImage> fBot;
103
104 using INHERITED = skiagm::GM;
105};
106
107//////////////////////////////////////////////////////////////////////////////
108
109DEF_GM(return new FilterBugGM;)
@ kOpaque_SkAlphaType
pixel is opaque
Definition: SkAlphaType.h:28
static SkPMColor SkPackARGB32(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Definition: SkColorPriv.h:106
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
void onOnceBeforeDraw() override
Definition: filterbug.cpp:53
SkISize getISize() override
Definition: filterbug.cpp:51
void onDraw(SkCanvas *canvas) override
Definition: filterbug.cpp:60
SkString getName() const override
Definition: filterbug.cpp:49
sk_sp< SkImage > asImage() const
Definition: SkBitmap.cpp:645
void setImmutable()
Definition: SkBitmap.cpp:400
void allocN32Pixels(int width, int height, bool isOpaque=false)
Definition: SkBitmap.cpp:232
bool setAlphaType(SkAlphaType alphaType)
Definition: SkBitmap.cpp:148
uint32_t * getAddr32(int x, int y) const
Definition: SkBitmap.h:1260
void eraseColor(SkColor4f) const
Definition: SkBitmap.cpp:442
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
Definition: SkImage.cpp:179
void setScaleTranslate(SkScalar sx, SkScalar sy, SkScalar tx, SkScalar ty)
Definition: SkMatrix.h:1803
void setColor(SkColor color)
Definition: SkPaint.cpp:119
void setAntiAlias(bool aa)
Definition: SkPaint.h:170
void setShader(sk_sp< SkShader > shader)
Definition: gm.h:110
void setBGColor(SkColor)
Definition: gm.cpp:159
static sk_sp< SkImage > make_image(int firstBlackRow, int lastBlackRow)
Definition: filterbug.cpp:24
#define DEF_GM(CODE)
Definition: gm.h:40
double y
double x
static constexpr SkCubicResampler Mitchell()
Definition: SkSize.h:16
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
constexpr size_t kHeight
constexpr size_t kWidth