Flutter Engine
The Flutter Engine
imagefiltersstroked.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"
14#include "include/core/SkRect.h"
17#include "include/core/SkSize.h"
21
22#define RESIZE_FACTOR_X SkIntToScalar(2)
23#define RESIZE_FACTOR_Y SkIntToScalar(5)
24
25namespace skiagm {
26
27class ImageFiltersStrokedGM : public GM {
28public:
30 this->setBGColor(0x00000000);
31 }
32
33protected:
34 SkString getName() const override { return SkString("imagefiltersstroked"); }
35
36 SkISize getISize() override { return SkISize::Make(860, 500); }
37
38 static void draw_circle(SkCanvas* canvas, const SkRect& r, const SkPaint& paint) {
39 canvas->drawCircle(r.centerX(), r.centerY(),
40 r.width() * 2 / 5, paint);
41 }
42
43 static void draw_line(SkCanvas* canvas, const SkRect& r, const SkPaint& paint) {
44 canvas->drawLine(r.fLeft, r.fBottom, r.fRight, r.fTop, paint);
45 }
46
47 static void draw_rect(SkCanvas* canvas, const SkRect& r, const SkPaint& paint) {
48 canvas->drawRect(r, paint);
49 }
50
51 void onDraw(SkCanvas* canvas) override {
52 void (*drawProc[])(SkCanvas*, const SkRect&, const SkPaint&) = {
54 };
55
56 canvas->clear(SK_ColorBLACK);
57
58 SkMatrix resizeMatrix;
60
61 sk_sp<SkImageFilter> filters[] = {
62 SkImageFilters::Blur(5, 5, nullptr),
63 SkImageFilters::DropShadow(10, 10, 3, 3, SK_ColorGREEN, nullptr),
64 SkImageFilters::Offset(-16, 32, nullptr),
65 SkImageFilters::MatrixTransform(resizeMatrix, SkSamplingOptions(), nullptr),
66 };
67
68 SkRect r = SkRect::MakeWH(64, 64);
69 SkScalar margin = 32;
71 paint.setColor(SK_ColorWHITE);
72 paint.setAntiAlias(true);
73 paint.setStrokeWidth(10);
75
76 for (size_t i = 0; i < std::size(drawProc); ++i) {
77 canvas->translate(0, margin);
78 canvas->save();
79 for (size_t j = 0; j < std::size(filters); ++j) {
80 canvas->translate(margin, 0);
81 canvas->save();
82 if (2 == j) {
83 canvas->translate(16, -32);
84 } else if (3 == j) {
87 }
88 paint.setImageFilter(filters[j]);
89 drawProc[i](canvas, r, paint);
90 canvas->restore();
91 canvas->translate(r.width() + margin, 0);
92 }
93 canvas->restore();
94 canvas->translate(0, r.height());
95 }
96 }
97
98private:
99 using INHERITED = GM;
100};
101
102//////////////////////////////////////////////////////////////////////////////
103
104DEF_GM(return new ImageFiltersStrokedGM;)
105
106} // namespace skiagm
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 SkScalarInvert(x)
Definition: SkScalar.h:73
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint &paint)
Definition: SkCanvas.cpp:2700
void clear(SkColor color)
Definition: SkCanvas.h:1199
int save()
Definition: SkCanvas.cpp:447
void scale(SkScalar sx, SkScalar sy)
Definition: SkCanvas.cpp:1289
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
Definition: SkCanvas.cpp:2707
static sk_sp< SkImageFilter > DropShadow(SkScalar dx, SkScalar dy, SkScalar sigmaX, SkScalar sigmaY, SkColor color, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static sk_sp< SkImageFilter > Blur(SkScalar sigmaX, SkScalar sigmaY, SkTileMode tileMode, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static sk_sp< SkImageFilter > MatrixTransform(const SkMatrix &matrix, const SkSamplingOptions &sampling, sk_sp< SkImageFilter > input)
static sk_sp< SkImageFilter > Offset(SkScalar dx, SkScalar dy, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
SkMatrix & setScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
Definition: SkMatrix.cpp:296
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
Definition: gm.h:110
GM(SkColor backgroundColor=SK_ColorWHITE)
Definition: gm.cpp:81
void setBGColor(SkColor)
Definition: gm.cpp:159
static void draw_circle(SkCanvas *canvas, const SkRect &r, const SkPaint &paint)
static void draw_rect(SkCanvas *canvas, const SkRect &r, const SkPaint &paint)
static void draw_line(SkCanvas *canvas, const SkRect &r, const SkPaint &paint)
void onDraw(SkCanvas *canvas) override
SkString getName() const override
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
#define RESIZE_FACTOR_Y
#define RESIZE_FACTOR_X
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)
SkSamplingOptions(SkFilterMode::kLinear))
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
SkScalar fBottom
larger y-axis bounds
Definition: extension.cpp:17
SkScalar fLeft
smaller x-axis bounds
Definition: extension.cpp:14
SkScalar fRight
larger x-axis bounds
Definition: extension.cpp:16
constexpr float centerX() const
Definition: SkRect.h:776
constexpr float height() const
Definition: SkRect.h:769
constexpr float centerY() const
Definition: SkRect.h:785
constexpr float width() const
Definition: SkRect.h:762
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609
SkScalar fTop
smaller y-axis bounds
Definition: extension.cpp:15