Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
imageblur.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2011 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"
11#include "include/core/SkFont.h"
17#include "src/base/SkRandom.h"
18#include "tools/ToolUtils.h"
20
21#define WIDTH 500
22#define HEIGHT 500
23
24void imageblurgm_draw(SkScalar fSigmaX, SkScalar fSigmaY, SkCanvas* canvas) {
26 paint.setImageFilter(SkImageFilters::Blur(fSigmaX, fSigmaY, nullptr));
27 canvas->saveLayer(nullptr, &paint);
28 const char* str = "The quick brown fox jumped over the lazy dog.";
29
30 SkRandom rand;
31 SkPaint textPaint;
33 for (int i = 0; i < 25; ++i) {
34 int x = rand.nextULessThan(WIDTH);
35 int y = rand.nextULessThan(HEIGHT);
36 textPaint.setColor(ToolUtils::color_to_565(rand.nextBits(24) | 0xFF000000));
37 font.setSize(rand.nextRangeScalar(0, 300));
38 canvas->drawString(str, SkIntToScalar(x), SkIntToScalar(y), font, textPaint);
39 }
40 canvas->restore();
41}
43 imageblurgm_draw(24.0f, 0.0f, canvas);
44}
45DEF_SIMPLE_GM_BG(imageblur_large, canvas, WIDTH, HEIGHT, SK_ColorBLACK) {
46 imageblurgm_draw(80.0f, 80.0f, canvas);
47}
constexpr SkColor SK_ColorBLACK
Definition SkColor.h:103
#define SkIntToScalar(x)
Definition SkScalar.h:57
int saveLayer(const SkRect *bounds, const SkPaint *paint)
Definition SkCanvas.cpp:500
void restore()
Definition SkCanvas.cpp:465
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition SkCanvas.h:1803
static sk_sp< SkImageFilter > Blur(SkScalar sigmaX, SkScalar sigmaY, SkTileMode tileMode, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
void setColor(SkColor color)
Definition SkPaint.cpp:119
SkScalar nextRangeScalar(SkScalar min, SkScalar max)
Definition SkRandom.h:106
uint32_t nextULessThan(uint32_t count)
Definition SkRandom.h:93
uint32_t nextBits(unsigned bitCount)
Definition SkRandom.h:72
const Paint & paint
float SkScalar
Definition extension.cpp:12
#define DEF_SIMPLE_GM_BG(NAME, CANVAS, W, H, BGCOLOR)
Definition gm.h:52
#define WIDTH
Definition imageblur.cpp:21
void imageblurgm_draw(SkScalar fSigmaX, SkScalar fSigmaY, SkCanvas *canvas)
Definition imageblur.cpp:24
#define HEIGHT
Definition imageblur.cpp:22
double y
double x
SkFont DefaultPortableFont()
SkColor color_to_565(SkColor color)