Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
localmatriximagefilter.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"
16#include "include/core/SkRect.h"
21#include "tools/ToolUtils.h"
22
23#include <utility>
24
25static sk_sp<SkImage> make_image(SkCanvas* rootCanvas) {
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}
35
36static void show_image(SkCanvas* canvas, SkImage* image, sk_sp<SkImageFilter> filter) {
41 canvas->drawRect(r, paint);
42
44 paint.setImageFilter(filter);
45 canvas->drawImage(image, 0, 0, SkSamplingOptions(), &paint);
46}
47
49
50// Show the effect of localmatriximagefilter with various matrices, on various filters
51DEF_SIMPLE_GM(localmatriximagefilter, canvas, 640, 640) {
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}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
constexpr SkColor SK_ColorRED
Definition SkColor.h:126
#define SK_ScalarHalf
Definition SkScalar.h:19
void drawRect(const SkRect &rect, const SkPaint &paint)
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition SkCanvas.h:1528
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={})
int width() const
Definition SkImage.h:285
int height() const
Definition SkImage.h:291
static SkMatrix Scale(SkScalar sx, SkScalar sy)
Definition SkMatrix.h:75
static SkMatrix Translate(SkScalar dx, SkScalar dy)
Definition SkMatrix.h:91
@ kStroke_Style
set to stroke geometry
Definition SkPaint.h:194
@ kFill_Style
set to fill geometry
Definition SkPaint.h:193
T * get() const
Definition SkRefCnt.h:303
const Paint & paint
VkSurfaceKHR surface
Definition main.cc:49
sk_sp< SkImage > image
Definition examples.cpp:29
float SkScalar
Definition extension.cpp:12
#define DEF_SIMPLE_GM(NAME, CANVAS, W, H)
Definition gm.h:50
sk_sp< SkImageFilter >(* ImageFilterFactory)()
static void show_image(SkCanvas *canvas, SkImage *image, sk_sp< SkImageFilter > filter)
static sk_sp< SkImage > make_image()
Definition mipmap.cpp:21
sk_sp< SkSurface > makeSurface(SkCanvas *canvas, const SkImageInfo &info, const SkSurfaceProps *props)
static SkImageInfo MakeN32Premul(int width, int height)
static SkRect MakeIWH(int w, int h)
Definition SkRect.h:623
SkRect makeOutset(float dx, float dy) const
Definition SkRect.h:1002