blob: 6a27c65beb9ffaccf9cc2a385fdb2c4ae2d17efd [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"
9#include "SkBlurImageFilter.h"
mtklein@google.comcfa7ba72013-09-16 18:19:30 +000010#include "SkRandom.h"
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000011
senorblanco@chromium.org54e01b22011-11-16 18:20:47 +000012#define WIDTH 500
13#define HEIGHT 500
14
halcanary2a243382015-09-09 08:16:41 -070015void imageblurgm_draw(SkScalar fSigmaX, SkScalar fSigmaY, SkCanvas* canvas) {
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000016 SkPaint paint;
robertphillips6e7025a2016-04-04 04:31:25 -070017 paint.setImageFilter(SkBlurImageFilter::Make(fSigmaX, fSigmaY, nullptr));
halcanary96fcdcc2015-08-27 07:41:13 -070018 canvas->saveLayer(nullptr, &paint);
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000019 const char* str = "The quick brown fox jumped over the lazy dog.";
mtklein@google.comcfa7ba72013-09-16 18:19:30 +000020
21 SkRandom rand;
senorblanco@chromium.org1e95d712012-07-18 19:52:53 +000022 SkPaint textPaint;
23 textPaint.setAntiAlias(true);
caryclark1818acb2015-07-24 12:09:25 -070024 sk_tool_utils::set_portable_typeface(&textPaint);
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000025 for (int i = 0; i < 25; ++i) {
mtklein@google.comcfa7ba72013-09-16 18:19:30 +000026 int x = rand.nextULessThan(WIDTH);
27 int y = rand.nextULessThan(HEIGHT);
caryclarkef14cb32015-07-16 14:16:04 -070028 textPaint.setColor(sk_tool_utils::color_to_565(rand.nextBits(24) | 0xFF000000));
mtklein@google.com26c6d582013-09-16 19:05:44 +000029 textPaint.setTextSize(rand.nextRangeScalar(0, 300));
tomhudson@google.com75589252012-04-10 17:42:21 +000030 canvas->drawText(str, strlen(str), SkIntToScalar(x),
senorblanco@chromium.org1e95d712012-07-18 19:52:53 +000031 SkIntToScalar(y), textPaint);
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000032 }
33 canvas->restore();
halcanary2a243382015-09-09 08:16:41 -070034}
35DEF_SIMPLE_GM_BG(imageblur, canvas, WIDTH, HEIGHT, SK_ColorBLACK) {
36 imageblurgm_draw(24.0f, 0.0f, canvas);
37}
38DEF_SIMPLE_GM_BG(imageblur_large, canvas, WIDTH, HEIGHT, SK_ColorBLACK) {
39 imageblurgm_draw(80.0f, 80.0f, canvas);
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000040}