Flutter Engine
The Flutter Engine
dropshadowimagefilter.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2013 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/SkFont.h"
17#include "include/core/SkRect.h"
24#include "tools/ToolUtils.h"
26
27#include <utility>
28
29///////////////////////////////////////////////////////////////////////////////
30
31static void draw_paint(SkCanvas* canvas, const SkRect& r, sk_sp<SkImageFilter> imf) {
33 paint.setImageFilter(std::move(imf));
34 paint.setColor(SK_ColorBLACK);
35 canvas->save();
36 canvas->clipRect(r);
37 canvas->drawPaint(paint);
38 canvas->restore();
39}
40
41static void draw_path(SkCanvas* canvas, const SkRect& r, sk_sp<SkImageFilter> imf) {
43 paint.setColor(SK_ColorGREEN);
44 paint.setImageFilter(std::move(imf));
45 paint.setAntiAlias(true);
46 canvas->save();
47 canvas->clipRect(r);
48 canvas->drawCircle(r.centerX(), r.centerY(), r.width()/3, paint);
49 canvas->restore();
50}
51
52static void draw_text(SkCanvas* canvas, const SkRect& r, sk_sp<SkImageFilter> imf) {
54 paint.setImageFilter(std::move(imf));
55 paint.setColor(SK_ColorGREEN);
56 paint.setAntiAlias(true);
57
59 canvas->save();
60 canvas->clipRect(r);
62 canvas->restore();
63}
64
65static void draw_bitmap(SkCanvas* canvas, const SkRect& r, sk_sp<SkImageFilter> imf) {
67
69 r.roundOut(&bounds);
70
71 auto surf = SkSurfaces::Raster(SkImageInfo::MakeN32Premul(bounds.width(), bounds.height()));
72 draw_path(surf->getCanvas(), r, nullptr);
73
74 paint.setImageFilter(std::move(imf));
75 canvas->save();
76 canvas->clipRect(r);
77 surf->draw(canvas, 0, 0, SkSamplingOptions(), &paint);
78 canvas->restore();
79}
80
81///////////////////////////////////////////////////////////////////////////////
82
83DEF_SIMPLE_GM(dropshadowimagefilter, canvas, 400, 656) {
84 void (*drawProc[])(SkCanvas*, const SkRect&, sk_sp<SkImageFilter>) = {
86 };
87
89 sk_sp<SkImageFilter> cfif(SkImageFilters::ColorFilter(std::move(cf), nullptr));
90 SkIRect cropRect = SkIRect::MakeXYWH(10, 10, 44, 44);
91 SkIRect bogusRect = SkIRect::MakeXYWH(-100, -100, 10, 10);
92
93 sk_sp<SkImageFilter> filters[] = {
94 nullptr,
95 SkImageFilters::DropShadow(7.0f, 0.0f, 0.0f, 3.0f, SK_ColorBLUE, nullptr),
96 SkImageFilters::DropShadow(0.0f, 7.0f, 3.0f, 0.0f, SK_ColorBLUE, nullptr),
97 SkImageFilters::DropShadow(7.0f, 7.0f, 3.0f, 3.0f, SK_ColorBLUE, nullptr),
98 SkImageFilters::DropShadow(7.0f, 7.0f, 3.0f, 3.0f, SK_ColorBLUE, std::move(cfif)),
99 SkImageFilters::DropShadow(7.0f, 7.0f, 3.0f, 3.0f, SK_ColorBLUE, nullptr, &cropRect),
100 SkImageFilters::DropShadow(7.0f, 7.0f, 3.0f, 3.0f, SK_ColorBLUE, nullptr, &bogusRect),
101 SkImageFilters::DropShadowOnly(7.0f, 7.0f, 3.0f, 3.0f, SK_ColorBLUE, nullptr),
102 };
103
106 SkScalar DX = r.width() + MARGIN;
107 SkScalar DY = r.height() + MARGIN;
108
109 canvas->translate(MARGIN, MARGIN);
110 for (size_t j = 0; j < std::size(drawProc); ++j) {
111 canvas->save();
112 for (size_t i = 0; i < std::size(filters); ++i) {
113 drawProc[j](canvas, r, filters[i]);
114 canvas->translate(0, DY);
115 }
116 canvas->restore();
117 canvas->translate(DX, 0);
118 }
119}
@ kSrcIn
r = s * da
constexpr SkColor SK_ColorMAGENTA
Definition: SkColor.h:147
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
#define SkIntToScalar(x)
Definition: SkScalar.h:57
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1361
void restore()
Definition: SkCanvas.cpp:461
void drawPaint(const SkPaint &paint)
Definition: SkCanvas.cpp:1668
int save()
Definition: SkCanvas.cpp:447
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
Definition: SkCanvas.cpp:2707
static sk_sp< SkColorFilter > Blend(const SkColor4f &c, sk_sp< SkColorSpace >, SkBlendMode mode)
Definition: SkFont.h:35
static sk_sp< SkImageFilter > ColorFilter(sk_sp< SkColorFilter > cf, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
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 > DropShadowOnly(SkScalar dx, SkScalar dy, SkScalar sigmaX, SkScalar sigmaY, SkColor color, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static void DrawString(SkCanvas *canvas, const char text[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint, Align align=kLeft_Align)
Definition: SkTextUtils.h:34
const Paint & paint
Definition: color_source.cc:38
#define MARGIN
static void draw_bitmap(SkCanvas *canvas, const SkRect &r, sk_sp< SkImageFilter > imf)
static void draw_text(SkCanvas *canvas, const SkRect &r, sk_sp< SkImageFilter > imf)
static void draw_path(SkCanvas *canvas, const SkRect &r, sk_sp< SkImageFilter > imf)
DEF_SIMPLE_GM(dropshadowimagefilter, canvas, 400, 656)
static void draw_paint(SkCanvas *canvas, const SkRect &r, sk_sp< SkImageFilter > imf)
float SkScalar
Definition: extension.cpp:12
Optional< SkRect > bounds
Definition: SkRecords.h:189
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
sk_sp< SkTypeface > DefaultPortableTypeface()
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
font
Font Metadata and Metrics.
SkSamplingOptions(SkFilterMode::kLinear))
Definition: SkRect.h:32
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition: SkRect.h:104
static SkImageInfo MakeN32Premul(int width, int height)
void roundOut(SkIRect *dst) const
Definition: SkRect.h:1241
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