Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
35 canvas->drawCircle(SkScalarHalf(size), SkScalarHalf(size), SkScalarHalf(size), paint);
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
SkColor4f color
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:500
void restore()
Definition SkCanvas.cpp:465
void translate(SkScalar dx, SkScalar dy)
@ 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)
void setMatrix(const SkM44 &matrix)
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
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()
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
void setBGColor(SkColor)
Definition gm.cpp:159
const Paint & paint
VkSurfaceKHR surface
Definition main.cc:49
#define DEF_GM(CODE)
Definition gm.h:40
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
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