blob: 47d6374c9537f0ba890288a9814fa85bc58fa825 [file] [log] [blame]
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +00001/*
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.h"
Mike Klein33d20552017-03-22 13:47:51 -04009#include "sk_tool_utils.h"
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000010#include "SkBlurImageFilter.h"
mtklein@google.comcfa7ba72013-09-16 18:19:30 +000011#include "SkRandom.h"
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000012
senorblanco@chromium.org54e01b22011-11-16 18:20:47 +000013#define WIDTH 500
14#define HEIGHT 500
15
halcanary2a243382015-09-09 08:16:41 -070016void imageblurgm_draw(SkScalar fSigmaX, SkScalar fSigmaY, SkCanvas* canvas) {
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000017 SkPaint paint;
robertphillips6e7025a2016-04-04 04:31:25 -070018 paint.setImageFilter(SkBlurImageFilter::Make(fSigmaX, fSigmaY, nullptr));
halcanary96fcdcc2015-08-27 07:41:13 -070019 canvas->saveLayer(nullptr, &paint);
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000020 const char* str = "The quick brown fox jumped over the lazy dog.";
mtklein@google.comcfa7ba72013-09-16 18:19:30 +000021
22 SkRandom rand;
senorblanco@chromium.org1e95d712012-07-18 19:52:53 +000023 SkPaint textPaint;
24 textPaint.setAntiAlias(true);
caryclark1818acb2015-07-24 12:09:25 -070025 sk_tool_utils::set_portable_typeface(&textPaint);
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000026 for (int i = 0; i < 25; ++i) {
mtklein@google.comcfa7ba72013-09-16 18:19:30 +000027 int x = rand.nextULessThan(WIDTH);
28 int y = rand.nextULessThan(HEIGHT);
caryclarkef14cb32015-07-16 14:16:04 -070029 textPaint.setColor(sk_tool_utils::color_to_565(rand.nextBits(24) | 0xFF000000));
mtklein@google.com26c6d582013-09-16 19:05:44 +000030 textPaint.setTextSize(rand.nextRangeScalar(0, 300));
Cary Clark2a475ea2017-04-28 15:35:12 -040031 canvas->drawString(str, SkIntToScalar(x),
senorblanco@chromium.org1e95d712012-07-18 19:52:53 +000032 SkIntToScalar(y), textPaint);
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000033 }
34 canvas->restore();
halcanary2a243382015-09-09 08:16:41 -070035}
36DEF_SIMPLE_GM_BG(imageblur, canvas, WIDTH, HEIGHT, SK_ColorBLACK) {
37 imageblurgm_draw(24.0f, 0.0f, canvas);
38}
39DEF_SIMPLE_GM_BG(imageblur_large, canvas, WIDTH, HEIGHT, SK_ColorBLACK) {
40 imageblurgm_draw(80.0f, 80.0f, canvas);
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000041}