Flutter Engine
The Flutter Engine
complexclip_blur_tiled.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2016 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"
14#include "include/core/SkRect.h"
17#include "include/core/SkSize.h"
21#include "tools/ToolUtils.h"
22
23#define WIDTH 512
24#define HEIGHT 512
25
26namespace skiagm {
27
28class ComplexClipBlurTiledGM : public GM {
29public:
31 }
32
33protected:
34 SkString getName() const override { return SkString("complexclip_blur_tiled"); }
35
36 SkISize getISize() override { return SkISize::Make(WIDTH, HEIGHT); }
37
38 void onDraw(SkCanvas* canvas) override {
39 SkPaint blurPaint;
40 blurPaint.setImageFilter(SkImageFilters::Blur(5.0f, 5.0f, nullptr));
41 const SkScalar tileSize = SkIntToScalar(128);
43 int ts = SkScalarCeilToInt(tileSize);
45 auto tileSurface(ToolUtils::makeSurface(canvas, info));
46 SkCanvas* tileCanvas = tileSurface->getCanvas();
47 for (SkScalar y = bounds.top(); y < bounds.bottom(); y += tileSize) {
48 for (SkScalar x = bounds.left(); x < bounds.right(); x += tileSize) {
49 tileCanvas->save();
50 tileCanvas->clear(0);
51 tileCanvas->translate(-x, -y);
53 tileCanvas->saveLayer(&rect, &blurPaint);
54 SkRRect rrect = SkRRect::MakeRectXY(rect.makeInset(20, 20), 25, 25);
55 tileCanvas->clipRRect(rrect, SkClipOp::kDifference, true);
57 tileCanvas->drawRect(rect, paint);
58 tileCanvas->restore();
59 tileCanvas->restore();
60 canvas->drawImage(tileSurface->makeImageSnapshot().get(), x, y);
61 }
62 }
63 }
64
65private:
66 using INHERITED = GM;
67};
68
69//////////////////////////////////////////////////////////////////////////////
70
71DEF_GM(return new ComplexClipBlurTiledGM;)
72
73} // namespace skiagm
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
#define SkScalarCeilToInt(x)
Definition: SkScalar.h:36
#define SkIntToScalar(x)
Definition: SkScalar.h:57
int saveLayer(const SkRect *bounds, const SkPaint *paint)
Definition: SkCanvas.cpp:496
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
SkRect getLocalClipBounds() const
Definition: SkCanvas.cpp:1586
void clear(SkColor color)
Definition: SkCanvas.h:1199
int save()
Definition: SkCanvas.cpp:447
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
void clipRRect(const SkRRect &rrect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1439
static sk_sp< SkImageFilter > Blur(SkScalar sigmaX, SkScalar sigmaY, SkTileMode tileMode, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
void setImageFilter(sk_sp< SkImageFilter > imageFilter)
static SkRRect MakeRectXY(const SkRect &rect, SkScalar xRad, SkScalar yRad)
Definition: SkRRect.h:180
void onDraw(SkCanvas *canvas) override
Definition: gm.h:110
GM(SkColor backgroundColor=SK_ColorWHITE)
Definition: gm.cpp:81
const Paint & paint
Definition: color_source.cc:38
#define WIDTH
#define HEIGHT
float SkScalar
Definition: extension.cpp:12
double y
double x
Optional< SkRect > bounds
Definition: SkRecords.h:189
SkRRect rrect
Definition: SkRecords.h:232
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
sk_sp< SkSurface > makeSurface(SkCanvas *canvas, const SkImageInfo &info, const SkSurfaceProps *props)
Definition: ToolUtils.cpp:512
DEF_GM(return F(C(clipbox), 0.0f, 0.0f, {})) DEF_GM(return F(C(clipbox)
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
static SkImageInfo MakeN32Premul(int width, int height)
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609