Flutter Engine
The Flutter Engine
giantbitmap.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2011 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"
16#include "include/core/SkSize.h"
19
20/*
21 * Want to ensure that our bitmap sampler (in bitmap shader) keeps plenty of
22 * precision when scaling very large images (where the dx might get very small.
23 */
24
25#define W 257
26#define H 161
27
28class GiantBitmapGM : public skiagm::GM {
29 SkBitmap* fBM;
30 SkTileMode fMode;
31 bool fDoFilter;
32 bool fDoRotate;
33
34 const SkBitmap& getBitmap() {
35 if (nullptr == fBM) {
36 fBM = new SkBitmap;
37 fBM->allocN32Pixels(W, H);
39
40 const SkColor colors[] = {
42 };
43
44 SkCanvas canvas(*fBM);
46 paint.setAntiAlias(true);
47 paint.setStrokeWidth(SkIntToScalar(20));
48
49#if 0
50 for (int y = -H*2; y < H; y += 50) {
52 paint.setColor(colors[y/50 & 0x3]);
53 canvas.drawLine(0, yy, SkIntToScalar(W), yy + SkIntToScalar(W),
54 paint);
55 }
56#else
57 for (int x = -W; x < W; x += 60) {
58 paint.setColor(colors[x/60 & 0x3]);
59
61 canvas.drawLine(xx, 0, xx, SkIntToScalar(H),
62 paint);
63 }
64#endif
65 }
66 return *fBM;
67 }
68
69public:
70 GiantBitmapGM(SkTileMode mode, bool doFilter, bool doRotate) : fBM(nullptr) {
71 fMode = mode;
72 fDoFilter = doFilter;
73 fDoRotate = doRotate;
74 }
75
76 ~GiantBitmapGM() override { delete fBM; }
77
78protected:
79 SkString getName() const override {
80 SkString str("giantbitmap_");
81 switch (fMode) {
83 str.append("clamp");
84 break;
86 str.append("repeat");
87 break;
89 str.append("mirror");
90 break;
92 str.append("decal");
93 break;
94 default:
95 break;
96 }
97 str.append(fDoFilter ? "_bilerp" : "_point");
98 str.append(fDoRotate ? "_rotate" : "_scale");
99 return str;
100 }
101
102 SkISize getISize() override { return SkISize::Make(640, 480); }
103
104 void onDraw(SkCanvas* canvas) override {
106
107 SkMatrix m;
108 if (fDoRotate) {
109 m.setSkew(SK_Scalar1, 0, 0, 0);
110 } else {
111 SkScalar scale = 11*SK_Scalar1/12;
112 m.setScale(scale, scale);
113 }
114 paint.setShader(getBitmap().makeShader(
115 fMode, fMode,
118 m));
119
120 canvas->translate(50, 50);
121
122 canvas->drawPaint(paint);
123 }
124
125private:
126 using INHERITED = GM;
127};
128
129///////////////////////////////////////////////////////////////////////////////
130
131DEF_GM( return new GiantBitmapGM(SkTileMode::kClamp, false, false); )
132DEF_GM( return new GiantBitmapGM(SkTileMode::kRepeat, false, false); )
133DEF_GM( return new GiantBitmapGM(SkTileMode::kMirror, false, false); )
134DEF_GM( return new GiantBitmapGM(SkTileMode::kClamp, true, false); )
135DEF_GM( return new GiantBitmapGM(SkTileMode::kRepeat, true, false); )
136DEF_GM( return new GiantBitmapGM(SkTileMode::kMirror, true, false); )
137
138DEF_GM( return new GiantBitmapGM(SkTileMode::kClamp, false, true); )
139DEF_GM( return new GiantBitmapGM(SkTileMode::kRepeat, false, true); )
140DEF_GM( return new GiantBitmapGM(SkTileMode::kMirror, false, true); )
141DEF_GM( return new GiantBitmapGM(SkTileMode::kClamp, true, true); )
142DEF_GM( return new GiantBitmapGM(SkTileMode::kRepeat, true, true); )
143DEF_GM( return new GiantBitmapGM(SkTileMode::kMirror, true, true); )
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
#define SK_Scalar1
Definition: SkScalar.h:18
#define SkIntToScalar(x)
Definition: SkScalar.h:57
SkTileMode
Definition: SkTileMode.h:13
GiantBitmapGM(SkTileMode mode, bool doFilter, bool doRotate)
Definition: giantbitmap.cpp:70
SkString getName() const override
Definition: giantbitmap.cpp:79
SkISize getISize() override
void onDraw(SkCanvas *canvas) override
~GiantBitmapGM() override
Definition: giantbitmap.cpp:76
void allocN32Pixels(int width, int height, bool isOpaque=false)
Definition: SkBitmap.cpp:232
void eraseColor(SkColor4f) const
Definition: SkBitmap.cpp:442
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void drawPaint(const SkPaint &paint)
Definition: SkCanvas.cpp:1668
void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint &paint)
Definition: SkCanvas.cpp:2700
void append(const char text[])
Definition: SkString.h:203
Definition: gm.h:110
GM(SkColor backgroundColor=SK_ColorWHITE)
Definition: gm.cpp:81
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
#define W
Definition: giantbitmap.cpp:25
#define H
Definition: giantbitmap.cpp:26
#define DEF_GM(CODE)
Definition: gm.h:40
double y
double x
PODArray< SkColor > colors
Definition: SkRecords.h:276
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition: switches.h:228
SkSamplingOptions(SkFilterMode::kLinear))
const Scalar scale
Definition: SkMD5.cpp:130
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
SkBlendMode fMode
Definition: xfermodes.cpp:52