Flutter Engine
The Flutter Engine
filterindiabox.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"
13#include "include/core/SkRect.h"
15#include "include/core/SkSize.h"
18#include "tools/DecodeUtils.h"
19#include "tools/Resources.h"
20#include "tools/ToolUtils.h"
21
22namespace {
23static SkSize computeSize(const SkBitmap& bm, const SkMatrix& mat) {
25 SkIntToScalar(bm.height()));
26 mat.mapRect(&bounds);
27 return SkSize::Make(bounds.width(), bounds.height());
28}
29
30static void draw_cell(SkCanvas* canvas, const SkBitmap& bm, const SkMatrix& mat, SkScalar dx,
32 SkAutoCanvasRestore acr(canvas, true);
33
34 canvas->translate(dx, 0);
35 canvas->concat(mat);
36 canvas->drawImage(bm.asImage(), 0, 0, sampling);
37}
38
39static void draw_row(SkCanvas* canvas, const SkBitmap& bm, const SkMatrix& mat, SkScalar dx) {
40 draw_cell(canvas, bm, mat, 0 * dx, SkSamplingOptions());
45}
46
47class FilterIndiaBoxGM : public skiagm::GM {
48 SkBitmap fBM;
50
51 void onOnceBeforeDraw() override {
52 constexpr char kResource[] = "images/box.gif";
53 if (!ToolUtils::GetResourceAsBitmap(kResource, &fBM)) {
54 fBM.allocN32Pixels(1, 1);
55 fBM.eraseARGB(255, 255, 0 , 0); // red == bad
56 }
57 fBM.setImmutable();
58
59 SkScalar cx = SkScalarHalf(fBM.width());
60 SkScalar cy = SkScalarHalf(fBM.height());
61
62 float vertScale = 30.0f/55.0f;
63 float horizScale = 150.0f/200.0f;
64
65 fMatrix[0].setScale(horizScale, vertScale);
66 fMatrix[1].setRotate(30, cx, cy); fMatrix[1].postScale(horizScale, vertScale);
67 }
68
69 SkString getName() const override { return SkString("filterindiabox"); }
70
71 SkISize getISize() override { return {680, 130}; }
72
73 void onDraw(SkCanvas* canvas) override {
74 canvas->translate(10, 10);
75 for (size_t i = 0; i < std::size(fMatrix); ++i) {
76 SkSize size = computeSize(fBM, fMatrix[i]);
77 size.fWidth += 20;
78 size.fHeight += 20;
79
80 draw_row(canvas, fBM, fMatrix[i], size.fWidth);
81 canvas->translate(0, size.fHeight);
82 }
83 }
84};
85} // namespace
86
87DEF_GM( return new FilterIndiaBoxGM(); )
SkMatrix fMatrix
Definition: FillRRectOp.cpp:74
#define SkScalarHalf(a)
Definition: SkScalar.h:75
#define SkIntToScalar(x)
Definition: SkScalar.h:57
static SkScalar draw_row(SkCanvas *canvas, sk_sp< SkImage > img)
void eraseARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b) const
Definition: SkBitmap.h:817
sk_sp< SkImage > asImage() const
Definition: SkBitmap.cpp:645
void setImmutable()
Definition: SkBitmap.cpp:400
int width() const
Definition: SkBitmap.h:149
void allocN32Pixels(int width, int height, bool isOpaque=false)
Definition: SkBitmap.cpp:232
int height() const
Definition: SkBitmap.h:158
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void concat(const SkMatrix &matrix)
Definition: SkCanvas.cpp:1318
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
SkMatrix & postScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
Definition: SkMatrix.cpp:360
SkMatrix & setScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
Definition: SkMatrix.cpp:296
SkMatrix & setRotate(SkScalar degrees, SkScalar px, SkScalar py)
Definition: SkMatrix.cpp:452
bool mapRect(SkRect *dst, const SkRect &src, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
Definition: SkMatrix.cpp:1141
Definition: gm.h:110
virtual SkISize getISize()=0
virtual void onOnceBeforeDraw()
Definition: gm.cpp:167
virtual SkString getName() const =0
virtual DrawResult onDraw(SkCanvas *, SkString *errorMsg)
Definition: gm.cpp:139
static void draw_cell(SkCanvas *canvas, sk_sp< SkShader > src, sk_sp< SkShader > dst, SkBlendMode mode, SkAlpha alpha)
float SkScalar
Definition: extension.cpp:12
#define DEF_GM(CODE)
Definition: gm.h:40
Optional< SkRect > bounds
Definition: SkRecords.h:189
SkSamplingOptions sampling
Definition: SkRecords.h:337
skia_private::AutoTArray< sk_sp< SkImageFilter > > filters TypedMatrix matrix TypedMatrix matrix SkScalar dx
Definition: SkRecords.h:208
bool GetResourceAsBitmap(const char *resource, SkBitmap *dst)
Definition: DecodeUtils.h:21
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 keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
SkSamplingOptions(SkFilterMode::kLinear))
static constexpr SkCubicResampler Mitchell()
Definition: SkSize.h:16
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609
Definition: SkSize.h:52
static constexpr SkSize Make(SkScalar w, SkScalar h)
Definition: SkSize.h:56