blob: 9485fe000d487b2adb0144280dcc476b3f14ddd8 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -04009#include "include/core/SkCanvas.h"
10#include "include/core/SkColor.h"
11#include "include/core/SkFont.h"
12#include "include/core/SkImageFilter.h"
13#include "include/core/SkPaint.h"
14#include "include/core/SkScalar.h"
15#include "include/core/SkTypeface.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050016#include "include/effects/SkBlurImageFilter.h"
17#include "include/utils/SkRandom.h"
18#include "tools/ToolUtils.h"
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000019
senorblanco@chromium.org54e01b22011-11-16 18:20:47 +000020#define WIDTH 500
21#define HEIGHT 500
22
halcanary2a243382015-09-09 08:16:41 -070023void imageblurgm_draw(SkScalar fSigmaX, SkScalar fSigmaY, SkCanvas* canvas) {
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000024 SkPaint paint;
robertphillips6e7025a2016-04-04 04:31:25 -070025 paint.setImageFilter(SkBlurImageFilter::Make(fSigmaX, fSigmaY, nullptr));
halcanary96fcdcc2015-08-27 07:41:13 -070026 canvas->saveLayer(nullptr, &paint);
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000027 const char* str = "The quick brown fox jumped over the lazy dog.";
mtklein@google.comcfa7ba72013-09-16 18:19:30 +000028
29 SkRandom rand;
senorblanco@chromium.org1e95d712012-07-18 19:52:53 +000030 SkPaint textPaint;
Mike Kleinea3f0142019-03-20 11:12:10 -050031 SkFont font(ToolUtils::create_portable_typeface());
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000032 for (int i = 0; i < 25; ++i) {
mtklein@google.comcfa7ba72013-09-16 18:19:30 +000033 int x = rand.nextULessThan(WIDTH);
34 int y = rand.nextULessThan(HEIGHT);
Mike Kleinea3f0142019-03-20 11:12:10 -050035 textPaint.setColor(ToolUtils::color_to_565(rand.nextBits(24) | 0xFF000000));
Mike Reed1af9b482019-01-07 11:01:57 -050036 font.setSize(rand.nextRangeScalar(0, 300));
37 canvas->drawString(str, SkIntToScalar(x), SkIntToScalar(y), font, textPaint);
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000038 }
39 canvas->restore();
halcanary2a243382015-09-09 08:16:41 -070040}
41DEF_SIMPLE_GM_BG(imageblur, canvas, WIDTH, HEIGHT, SK_ColorBLACK) {
42 imageblurgm_draw(24.0f, 0.0f, canvas);
43}
44DEF_SIMPLE_GM_BG(imageblur_large, canvas, WIDTH, HEIGHT, SK_ColorBLACK) {
45 imageblurgm_draw(80.0f, 80.0f, canvas);
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000046}