Flutter Engine
The Flutter Engine
Functions
dropshadowimagefilter.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkBlendMode.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorFilter.h"
#include "include/core/SkFont.h"
#include "include/core/SkImageFilter.h"
#include "include/core/SkPaint.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkScalar.h"
#include "include/core/SkTypeface.h"
#include "include/core/SkTypes.h"
#include "include/effects/SkImageFilters.h"
#include "include/utils/SkTextUtils.h"
#include "tools/ToolUtils.h"
#include "tools/fonts/FontToolUtils.h"
#include <utility>

Go to the source code of this file.

Functions

static void draw_paint (SkCanvas *canvas, const SkRect &r, sk_sp< SkImageFilter > imf)
 
static void draw_path (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_bitmap (SkCanvas *canvas, const SkRect &r, sk_sp< SkImageFilter > imf)
 
 DEF_SIMPLE_GM (dropshadowimagefilter, canvas, 400, 656)
 

Function Documentation

◆ DEF_SIMPLE_GM()

DEF_SIMPLE_GM ( dropshadowimagefilter  ,
canvas  ,
400  ,
656   
)

Definition at line 83 of file dropshadowimagefilter.cpp.

83 {
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
#define SkIntToScalar(x)
Definition: SkScalar.h:57
static sk_sp< SkColorFilter > Blend(const SkColor4f &c, sk_sp< SkColorSpace >, SkBlendMode mode)
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={})
#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)
static void draw_paint(SkCanvas *canvas, const SkRect &r, sk_sp< SkImageFilter > imf)
float SkScalar
Definition: extension.cpp:12
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
Definition: SkRect.h:32
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition: SkRect.h:104
constexpr float height() const
Definition: SkRect.h:769
constexpr float width() const
Definition: SkRect.h:762
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609

◆ draw_bitmap()

static void draw_bitmap ( SkCanvas canvas,
const SkRect r,
sk_sp< SkImageFilter imf 
)
static

Definition at line 65 of file dropshadowimagefilter.cpp.

65 {
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}
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1361
void restore()
Definition: SkCanvas.cpp:461
int save()
Definition: SkCanvas.cpp:447
const Paint & paint
Definition: color_source.cc:38
Optional< SkRect > bounds
Definition: SkRecords.h:189
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
SkSamplingOptions(SkFilterMode::kLinear))
static SkImageInfo MakeN32Premul(int width, int height)
void roundOut(SkIRect *dst) const
Definition: SkRect.h:1241

◆ draw_paint()

static void draw_paint ( SkCanvas canvas,
const SkRect r,
sk_sp< SkImageFilter imf 
)
static

Definition at line 31 of file dropshadowimagefilter.cpp.

31 {
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}
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
void drawPaint(const SkPaint &paint)
Definition: SkCanvas.cpp:1668

◆ draw_path()

static void draw_path ( SkCanvas canvas,
const SkRect r,
sk_sp< SkImageFilter imf 
)
static

Definition at line 41 of file dropshadowimagefilter.cpp.

41 {
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}
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
Definition: SkCanvas.cpp:2707
constexpr float centerX() const
Definition: SkRect.h:776
constexpr float centerY() const
Definition: SkRect.h:785

◆ draw_text()

static void draw_text ( SkCanvas canvas,
const SkRect r,
sk_sp< SkImageFilter imf 
)
static

Definition at line 52 of file dropshadowimagefilter.cpp.

52 {
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}
Definition: SkFont.h:35
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
sk_sp< SkTypeface > DefaultPortableTypeface()
font
Font Metadata and Metrics.