blob: 22ea408e279909d8bcc7c6e1ed634a32a2a69e11 [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;
xidachen467ddc02015-12-10 12:08:44 -080017 SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(fSigmaX, fSigmaY));
18 paint.setImageFilter(blur);
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));
tomhudson@google.com75589252012-04-10 17:42:21 +000031 canvas->drawText(str, strlen(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}