Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
imagefiltersscaled.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2014 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"
18#include "include/core/SkRect.h"
22#include "include/core/SkSize.h"
30#include "tools/ToolUtils.h"
31
32#include <utility>
33
34#define RESIZE_FACTOR SkIntToScalar(4)
35
39 SkScalar radius = std::min(x, y) * 4 / 5;
41 SkCanvas* canvas = surface->getCanvas();
42 canvas->clear(0x00000000);
43 SkColor colors[2];
44 colors[0] = SK_ColorWHITE;
45 colors[1] = SK_ColorBLACK;
47 paint.setShader(SkGradientShader::MakeRadial(SkPoint::Make(x, y), radius, colors, nullptr,
49 canvas->drawCircle(x, y, radius, paint);
50
51 return surface->makeImageSnapshot();
52}
53
54
55namespace skiagm {
56
57class ImageFiltersScaledGM : public GM {
58public:
60 this->setBGColor(0x00000000);
61 }
62
63protected:
64 SkString getName() const override { return SkString("imagefiltersscaled"); }
65
66 SkISize getISize() override { return SkISize::Make(1428, 500); }
67
68 void onOnceBeforeDraw() override {
69 fCheckerboard = ToolUtils::create_checkerboard_image(64, 64, 0xFFA0A0A0, 0xFF404040, 8);
70 fGradientCircle = make_gradient_circle(64, 64);
71 }
72
73 void onDraw(SkCanvas* canvas) override {
74 canvas->clear(SK_ColorBLACK);
75
76 sk_sp<SkImageFilter> gradient(SkImageFilters::Image(fGradientCircle,
80
81 SkPoint3 pointLocation = SkPoint3::Make(0, 0, SkIntToScalar(10));
82 SkPoint3 spotLocation = SkPoint3::Make(SkIntToScalar(-10),
83 SkIntToScalar(-10),
84 SkIntToScalar(20));
85 SkPoint3 spotTarget = SkPoint3::Make(SkIntToScalar(40), SkIntToScalar(40), 0);
86 SkScalar spotExponent = SK_Scalar1;
87 SkScalar cutoffAngle = SkIntToScalar(15);
88 SkScalar kd = SkIntToScalar(2);
89 SkScalar surfaceScale = SkIntToScalar(1);
90 SkColor white(0xFFFFFFFF);
91 SkMatrix resizeMatrix;
93
94 sk_sp<SkImageFilter> filters[] = {
96 SkImageFilters::DropShadow(5, 10, 3, 3, SK_ColorYELLOW, nullptr),
99 12,
100 std::move(gradient),
104 SkImageFilters::Offset(SkIntToScalar(32), 0, nullptr),
105 SkImageFilters::MatrixTransform(resizeMatrix, SkSamplingOptions(), nullptr),
107 SkDoubleToScalar(0.1), SkDoubleToScalar(0.05), 1, 0)),
108 SkImageFilters::PointLitDiffuse(pointLocation, white, surfaceScale, kd, nullptr),
110 spotTarget,
111 spotExponent,
112 cutoffAngle,
113 white,
114 surfaceScale,
115 kd,
116 nullptr),
117 };
118
119 SkVector scales[] = {
125 };
126
128 SkScalar margin = SkIntToScalar(16);
129 SkRect bounds = r;
130 bounds.outset(margin, margin);
131
132 for (size_t j = 0; j < std::size(scales); ++j) {
133 canvas->save();
134 for (size_t i = 0; i < std::size(filters); ++i) {
136 paint.setColor(SK_ColorBLUE);
137 paint.setImageFilter(filters[i]);
138 paint.setAntiAlias(true);
139 canvas->save();
140 canvas->scale(scales[j].fX, scales[j].fY);
141 canvas->clipRect(r);
142 if (5 == i) {
143 canvas->translate(SkIntToScalar(-32), 0);
144 } else if (6 == i) {
147 }
148 canvas->drawCircle(r.centerX(), r.centerY(), r.width()*2/5, paint);
149 canvas->restore();
150 canvas->translate(r.width() * scales[j].fX + margin, 0);
151 }
152 canvas->restore();
153 canvas->translate(0, r.height() * scales[j].fY + margin);
154 }
155 }
156
157private:
158 sk_sp<SkImage> fCheckerboard, fGradientCircle;
159
160 using INHERITED = GM;
161};
162
163//////////////////////////////////////////////////////////////////////////////
164
165DEF_GM(return new ImageFiltersScaledGM;)
166} // namespace skiagm
constexpr SkColor SK_ColorYELLOW
Definition SkColor.h:139
uint32_t SkColor
Definition SkColor.h:37
constexpr SkColor SK_ColorBLUE
Definition SkColor.h:135
constexpr SkColor SK_ColorBLACK
Definition SkColor.h:103
constexpr SkColor SK_ColorWHITE
Definition SkColor.h:122
#define SkScalarInvert(x)
Definition SkScalar.h:73
#define SK_Scalar1
Definition SkScalar.h:18
#define SkDoubleToScalar(x)
Definition SkScalar.h:64
#define SkIntToScalar(x)
Definition SkScalar.h:57
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
void restore()
Definition SkCanvas.cpp:465
void translate(SkScalar dx, SkScalar dy)
void clear(SkColor color)
Definition SkCanvas.h:1199
int save()
Definition SkCanvas.cpp:451
void scale(SkScalar sx, SkScalar sy)
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
static sk_sp< SkShader > MakeRadial(const SkPoint &center, SkScalar radius, const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
static sk_sp< SkImageFilter > PointLitDiffuse(const SkPoint3 &location, SkColor lightColor, SkScalar surfaceScale, SkScalar kd, 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 > 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 > DisplacementMap(SkColorChannel xChannelSelector, SkColorChannel yChannelSelector, SkScalar scale, sk_sp< SkImageFilter > displacement, sk_sp< SkImageFilter > color, const CropRect &cropRect={})
static sk_sp< SkImageFilter > Image(sk_sp< SkImage > image, const SkRect &srcRect, const SkRect &dstRect, const SkSamplingOptions &sampling)
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={})
static sk_sp< SkImageFilter > Shader(sk_sp< SkShader > shader, const CropRect &cropRect={})
static sk_sp< SkImageFilter > Dilate(SkScalar radiusX, SkScalar radiusY, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static sk_sp< SkImageFilter > SpotLitDiffuse(const SkPoint3 &location, const SkPoint3 &target, SkScalar falloffExponent, SkScalar cutoffAngle, SkColor lightColor, SkScalar surfaceScale, SkScalar kd, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
SkMatrix & setScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
Definition SkMatrix.cpp:296
void setBGColor(SkColor)
Definition gm.cpp:159
SkString getName() const override
void onDraw(SkCanvas *canvas) override
const Paint & paint
VkSurfaceKHR surface
Definition main.cc:49
float SkScalar
Definition extension.cpp:12
#define DEF_GM(CODE)
Definition gm.h:40
static sk_sp< SkImage > make_gradient_circle(int width, int height)
#define RESIZE_FACTOR
double y
double x
SK_API sk_sp< SkShader > MakeFractalNoise(SkScalar baseFrequencyX, SkScalar baseFrequencyY, int numOctaves, SkScalar seed, const SkISize *tileSize=nullptr)
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
sk_sp< SkImage > create_checkerboard_image(int w, int h, SkColor c1, SkColor c2, int checkSize)
static sk_sp< SkImage > make_gradient_circle(int width, int height)
int32_t height
int32_t width
static constexpr SkISize Make(int32_t w, int32_t h)
Definition SkSize.h:20
static SkImageInfo MakeN32Premul(int width, int height)
static SkPoint3 Make(SkScalar x, SkScalar y, SkScalar z)
Definition SkPoint3.h:18
float fX
x-axis value
static constexpr SkPoint Make(float x, float y)
float fY
y-axis value
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
static void checkerboard(SkCanvas *canvas, SkColor c1, SkColor c2, int size)