Flutter Engine
The Flutter Engine
imageblurtiled.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"
10#include "include/core/SkFont.h"
13#include "include/core/SkRect.h"
15#include "include/core/SkSize.h"
20#include "tools/ToolUtils.h"
22
23#define WIDTH 640
24#define HEIGHT 480
25
26namespace skiagm {
27
28class ImageBlurTiledGM : public GM {
29public:
31 : fSigmaX(sigmaX), fSigmaY(sigmaY) {
32 }
33
34protected:
35 SkString getName() const override { return SkString("imageblurtiled"); }
36
37 SkISize getISize() override { return SkISize::Make(WIDTH, HEIGHT); }
38
39 void onDraw(SkCanvas* canvas) override {
41 paint.setImageFilter(SkImageFilters::Blur(fSigmaX, fSigmaY, nullptr));
42 const SkScalar tileSize = SkIntToScalar(128);
44 for (SkScalar y = bounds.top(); y < bounds.bottom(); y += tileSize) {
45 for (SkScalar x = bounds.left(); x < bounds.right(); x += tileSize) {
46 canvas->save();
47 canvas->clipRect(SkRect::MakeXYWH(x, y, tileSize, tileSize));
48 canvas->saveLayer(nullptr, &paint);
49 const char* str[] = {
50 "The quick",
51 "brown fox",
52 "jumped over",
53 "the lazy dog.",
54 };
56 int posY = 0;
57 for (unsigned i = 0; i < std::size(str); i++) {
58 posY += 100;
59 canvas->drawString(str[i], 0, SkIntToScalar(posY), font, SkPaint());
60 }
61 canvas->restore();
62 canvas->restore();
63 }
64 }
65 }
66
67private:
68 SkScalar fSigmaX;
69 SkScalar fSigmaY;
70
71 using INHERITED = GM;
72};
73
74//////////////////////////////////////////////////////////////////////////////
75
76DEF_GM(return new ImageBlurTiledGM(3.0f, 3.0f);)
77
78} // namespace skiagm
#define SkIntToScalar(x)
Definition: SkScalar.h:57
int saveLayer(const SkRect *bounds, const SkPaint *paint)
Definition: SkCanvas.cpp:496
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1361
void restore()
Definition: SkCanvas.cpp:461
SkRect getLocalClipBounds() const
Definition: SkCanvas.cpp:1586
int save()
Definition: SkCanvas.cpp:447
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.h:1803
Definition: SkFont.h:35
static sk_sp< SkImageFilter > Blur(SkScalar sigmaX, SkScalar sigmaY, SkTileMode tileMode, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
Definition: gm.h:110
GM(SkColor backgroundColor=SK_ColorWHITE)
Definition: gm.cpp:81
void onDraw(SkCanvas *canvas) override
SkString getName() const override
SkISize getISize() override
ImageBlurTiledGM(SkScalar sigmaX, SkScalar sigmaY)
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
#define WIDTH
#define HEIGHT
double y
double x
Optional< SkRect > bounds
Definition: SkRecords.h:189
sk_sp< SkTypeface > DefaultPortableTypeface()
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
font
Font Metadata and Metrics.
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 constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659