Flutter Engine
The Flutter Engine
bigtileimagefilter.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"
15#include "include/core/SkRect.h"
18#include "include/core/SkSize.h"
22
23#include <utility>
24
27 SkCanvas* canvas = surface->getCanvas();
28 canvas->clear(0xFF000000);
29
31 paint.setColor(color);
32 paint.setStrokeWidth(3);
34
36
37 return surface->makeImageSnapshot();
38}
39
40namespace skiagm {
41
42class BigTileImageFilterGM : public GM {
43public:
45 this->setBGColor(0xFF000000);
46 }
47
48protected:
49 SkString getName() const override { return SkString("bigtileimagefilter"); }
50
51 SkISize getISize() override { return SkISize::Make(kWidth, kHeight); }
52
53 void onOnceBeforeDraw() override {
54 fRedImage = create_circle_texture(kBitmapSize, SK_ColorRED);
55 fGreenImage = create_circle_texture(kBitmapSize, SK_ColorGREEN);
56 }
57
58 void onDraw(SkCanvas* canvas) override {
59 canvas->clear(SK_ColorBLACK);
60
61 {
62 SkPaint p;
63
64 const SkRect bound = SkRect::MakeIWH(kWidth, kHeight);
65 sk_sp<SkImageFilter> imageSource(SkImageFilters::Image(fRedImage,
67
69 SkRect::MakeIWH(kBitmapSize, kBitmapSize), SkRect::MakeIWH(kWidth, kHeight),
70 std::move(imageSource)));
71
72 p.setImageFilter(std::move(tif));
73
74 canvas->saveLayer(&bound, &p);
75 canvas->restore();
76 }
77
78 {
79 SkPaint p2;
80
81 const SkRect bound2 = SkRect::MakeIWH(kBitmapSize, kBitmapSize);
82
84 SkRect::MakeIWH(kBitmapSize, kBitmapSize),
85 SkRect::MakeIWH(kBitmapSize, kBitmapSize),
86 nullptr));
87
88 p2.setImageFilter(std::move(tif));
89
90 canvas->translate(320, 320);
91 canvas->saveLayer(&bound2, &p2);
92 canvas->setMatrix(SkMatrix::I());
93
94 SkRect bound3 = SkRect::MakeXYWH(320, 320,
95 SkIntToScalar(kBitmapSize),
96 SkIntToScalar(kBitmapSize));
97 canvas->drawImageRect(fGreenImage.get(), bound2, bound3, SkSamplingOptions(), nullptr,
99 canvas->restore();
100 }
101 }
102
103private:
104 inline static constexpr int kWidth = 512;
105 inline static constexpr int kHeight = 512;
106 inline static constexpr int kBitmapSize = 64;
107
108 sk_sp<SkImage> fRedImage;
109 sk_sp<SkImage> fGreenImage;
110
111 using INHERITED = GM;
112};
113
114//////////////////////////////////////////////////////////////////////////////
115
116DEF_GM(return new BigTileImageFilterGM;)
117} // namespace skiagm
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
#define SkScalarHalf(a)
Definition: SkScalar.h:75
#define SkIntToScalar(x)
Definition: SkScalar.h:57
static sk_sp< SkImage > create_circle_texture(int size, SkColor color)
int saveLayer(const SkRect *bounds, const SkPaint *paint)
Definition: SkCanvas.cpp:496
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
@ kStrict_SrcRectConstraint
sample only inside bounds; slower
Definition: SkCanvas.h:1542
void clear(SkColor color)
Definition: SkCanvas.h:1199
void drawImageRect(const SkImage *, const SkRect &src, const SkRect &dst, const SkSamplingOptions &, const SkPaint *, SrcRectConstraint)
Definition: SkCanvas.cpp:2333
void setMatrix(const SkM44 &matrix)
Definition: SkCanvas.cpp:1349
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
Definition: SkCanvas.cpp:2707
static sk_sp< SkImageFilter > Image(sk_sp< SkImage > image, const SkRect &srcRect, const SkRect &dstRect, const SkSamplingOptions &sampling)
static sk_sp< SkImageFilter > Tile(const SkRect &src, const SkRect &dst, sk_sp< SkImageFilter > input)
static const SkMatrix & I()
Definition: SkMatrix.cpp:1544
void setImageFilter(sk_sp< SkImageFilter > imageFilter)
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
T * get() const
Definition: SkRefCnt.h:303
void onDraw(SkCanvas *canvas) override
SkString getName() const override
Definition: gm.h:110
GM(SkColor backgroundColor=SK_ColorWHITE)
Definition: gm.cpp:81
void setBGColor(SkColor)
Definition: gm.cpp:159
const Paint & paint
Definition: color_source.cc:38
DlColor color
VkSurfaceKHR surface
Definition: main.cc:49
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
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
DEF_GM(return F(C(clipbox), 0.0f, 0.0f, {})) DEF_GM(return F(C(clipbox)
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
static SkImageInfo MakeN32Premul(int width, int height)
static SkRect MakeIWH(int w, int h)
Definition: SkRect.h:623
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659