Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
imageblurclampmode.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2017 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"
15#include "include/core/SkRect.h"
18#include "include/core/SkSize.h"
22#include "tools/ToolUtils.h"
23
24#include <initializer_list>
25#include <utility>
26
29 auto surface = ToolUtils::makeSurface(canvas, info);
30 SkCanvas* c = surface->getCanvas();
32 paint.setAntiAlias(true);
33
34 paint.setColor(SK_ColorBLUE);
35 c->drawRect(SkRect::MakeIWH(info.width(), info.height()), paint);
36 paint.setColor(SK_ColorGREEN);
37 c->drawCircle(125, 100, 100, paint);
38 paint.setColor(SK_ColorRED);
39 c->drawRect(SkRect::MakeIWH(80, 80), paint);
40
41 return surface->makeImageSnapshot();
42}
43
44static void draw_image(SkCanvas* canvas, const sk_sp<SkImage> image, sk_sp<SkImageFilter> filter) {
45 SkAutoCanvasRestore acr(canvas, true);
47 paint.setImageFilter(std::move(filter));
48
49 canvas->translate(SkIntToScalar(30), 0);
50 canvas->clipIRect(image->bounds());
51 canvas->drawImage(image, 0, 0, SkSamplingOptions(), &paint);
52}
53
54namespace skiagm {
55
56// This GM draws one rectangle, one green inscribed circle, and one red square
57// with different blur settings.
58class ImageBlurClampModeGM : public GM {
59public:
61 this->setBGColor(0xFFCCCCCC);
62 }
63
64protected:
65 SkString getName() const override { return SkString("imageblurclampmode"); }
66
67 SkISize getISize() override { return SkISize::Make(850, 920); }
68
69 bool runAsBench() const override { return true; }
70
71 void onDraw(SkCanvas* canvas) override {
74
75 canvas->translate(0, 30);
76 // Test different kernel size, including the one to launch 2d Gaussian
77 // blur.
78 for (auto sigma: { 0.6f, 3.0f, 8.0f, 20.0f }) {
79 canvas->save();
80
81 // x-only blur
82 filter = SkImageFilters::Blur(
83 sigma, 0.0f, SkTileMode::kClamp, nullptr, image->bounds());
84 draw_image(canvas, image, std::move(filter));
85 canvas->translate(image->width() + 20, 0);
86
87 // y-only blur
88 filter = SkImageFilters::Blur(
89 0.0f, sigma, SkTileMode::kClamp, nullptr, image->bounds());
90 draw_image(canvas, image, std::move(filter));
91 canvas->translate(image->width() + 20, 0);
92
93 // both directions
94 filter = SkImageFilters::Blur(
95 sigma, sigma, SkTileMode::kClamp, nullptr, image->bounds());
96 draw_image(canvas, image, std::move(filter));
97 canvas->translate(image->width() + 20, 0);
98
99 canvas->restore();
100
101 canvas->translate(0, image->height() + 20);
102 }
103 }
104
105private:
106 using INHERITED = GM;
107};
108
109//////////////////////////////////////////////////////////////////////////////
110
111DEF_GM(return new ImageBlurClampModeGM;)
112} // namespace skiagm
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
static void draw_image(SkCanvas *canvas, SkImage *img)
constexpr SkColor SK_ColorBLUE
Definition SkColor.h:135
constexpr SkColor SK_ColorRED
Definition SkColor.h:126
constexpr SkColor SK_ColorGREEN
Definition SkColor.h:131
#define SkIntToScalar(x)
Definition SkScalar.h:57
void drawRect(const SkRect &rect, const SkPaint &paint)
void restore()
Definition SkCanvas.cpp:465
void translate(SkScalar dx, SkScalar dy)
void clipIRect(const SkIRect &irect, SkClipOp op=SkClipOp::kIntersect)
Definition SkCanvas.h:991
int save()
Definition SkCanvas.cpp:451
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition SkCanvas.h:1528
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
static sk_sp< SkImageFilter > Blur(SkScalar sigmaX, SkScalar sigmaY, SkTileMode tileMode, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
int width() const
Definition SkImage.h:285
int height() const
Definition SkImage.h:291
SkIRect bounds() const
Definition SkImage.h:303
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
sk_sp< SkImage > image
Definition examples.cpp:29
#define DEF_GM(CODE)
Definition gm.h:40
static void draw_image(SkCanvas *canvas, const sk_sp< 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 constexpr SkISize Make(int32_t w, int32_t h)
Definition SkSize.h:20
static SkImageInfo MakeN32Premul(int width, int height)
static SkRect MakeIWH(int w, int h)
Definition SkRect.h:623