Flutter Engine
The Flutter Engine
Typedefs | Functions
localmatriximagefilter.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageFilter.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkPaint.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkScalar.h"
#include "include/core/SkSurface.h"
#include "include/effects/SkImageFilters.h"
#include "tools/ToolUtils.h"
#include <utility>

Go to the source code of this file.

Typedefs

typedef sk_sp< SkImageFilter >(* ImageFilterFactory) ()
 

Functions

static sk_sp< SkImagemake_image (SkCanvas *rootCanvas)
 
static void show_image (SkCanvas *canvas, SkImage *image, sk_sp< SkImageFilter > filter)
 
 DEF_SIMPLE_GM (localmatriximagefilter, canvas, 640, 640)
 

Typedef Documentation

◆ ImageFilterFactory

typedef sk_sp< SkImageFilter >(* ImageFilterFactory) ()

Definition at line 48 of file localmatriximagefilter.cpp.

Function Documentation

◆ DEF_SIMPLE_GM()

DEF_SIMPLE_GM ( localmatriximagefilter  ,
canvas  ,
640  ,
640   
)

Definition at line 51 of file localmatriximagefilter.cpp.

51 {
52 sk_sp<SkImage> image0(make_image(canvas));
53
54 const ImageFilterFactory factories[] = {
55 []{ return SkImageFilters::Blur(8, 8, nullptr); },
56 []{ return SkImageFilters::Dilate(8, 8, nullptr); },
57 []{ return SkImageFilters::Erode(8, 8, nullptr); },
58 []{ return SkImageFilters::Offset(8, 8, nullptr); },
59 };
60
61 const SkMatrix matrices[] = {
63 SkMatrix::Scale(2, 2),
65 };
66
67 const SkScalar spacer = image0->width() * 3.0f / 2;
68
69 canvas->translate(40, 40);
70 for (auto&& factory : factories) {
71 sk_sp<SkImageFilter> filter(factory());
72
73 canvas->save();
74 show_image(canvas, image0.get(), filter);
75 for (const auto& matrix : matrices) {
76 sk_sp<SkImageFilter> localFilter(filter->makeWithLocalMatrix(matrix));
77 canvas->translate(spacer, 0);
78 show_image(canvas, image0.get(), std::move(localFilter));
79 }
80 canvas->restore();
81 canvas->translate(0, spacer);
82 }
83}
#define SK_ScalarHalf
Definition: SkScalar.h:19
static sk_sp< SkImageFilter > Erode(SkScalar radiusX, SkScalar radiusY, 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 > Offset(SkScalar dx, SkScalar dy, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static sk_sp< SkImageFilter > Dilate(SkScalar radiusX, SkScalar radiusY, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static SkMatrix Scale(SkScalar sx, SkScalar sy)
Definition: SkMatrix.h:75
static SkMatrix Translate(SkScalar dx, SkScalar dy)
Definition: SkMatrix.h:91
float SkScalar
Definition: extension.cpp:12
sk_sp< SkImageFilter >(* ImageFilterFactory)()
static void show_image(SkCanvas *canvas, SkImage *image, sk_sp< SkImageFilter > filter)
static sk_sp< SkImage > make_image(SkCanvas *rootCanvas)
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258

◆ make_image()

static sk_sp< SkImage > make_image ( SkCanvas rootCanvas)
static

Definition at line 25 of file localmatriximagefilter.cpp.

25 {
27 auto surface(ToolUtils::makeSurface(rootCanvas, info));
28
30 paint.setAntiAlias(true);
31 paint.setColor(SK_ColorRED);
32 surface->getCanvas()->drawCircle(50, 50, 50, paint);
33 return surface->makeImageSnapshot();
34}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
const Paint & paint
Definition: color_source.cc:38
VkSurfaceKHR surface
Definition: main.cc:49
sk_sp< SkSurface > makeSurface(SkCanvas *canvas, const SkImageInfo &info, const SkSurfaceProps *props)
Definition: ToolUtils.cpp:512
static SkImageInfo MakeN32Premul(int width, int height)

◆ show_image()

static void show_image ( SkCanvas canvas,
SkImage image,
sk_sp< SkImageFilter filter 
)
static

Definition at line 36 of file localmatriximagefilter.cpp.

36 {
41 canvas->drawRect(r, paint);
42
44 paint.setImageFilter(filter);
45 canvas->drawImage(image, 0, 0, SkSamplingOptions(), &paint);
46}
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
int width() const
Definition: SkImage.h:285
int height() const
Definition: SkImage.h:291
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
@ kFill_Style
set to fill geometry
Definition: SkPaint.h:193
sk_sp< const SkImage > image
Definition: SkRecords.h:269
SkSamplingOptions(SkFilterMode::kLinear))
static SkRect MakeIWH(int w, int h)
Definition: SkRect.h:623
SkRect makeOutset(float dx, float dy) const
Definition: SkRect.h:1002