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.h"
9 #include "sk_tool_utils.h"
10 #include "SkBlurImageFilter.h"
11 #include "SkRandom.h"
12
13 #define WIDTH 500
14 #define HEIGHT 500
15
imageblurgm_draw(SkScalar fSigmaX,SkScalar fSigmaY,SkCanvas * canvas)16 void imageblurgm_draw(SkScalar fSigmaX, SkScalar fSigmaY, SkCanvas* canvas) {
17 SkPaint paint;
18 paint.setImageFilter(SkBlurImageFilter::Make(fSigmaX, fSigmaY, nullptr));
19 canvas->saveLayer(nullptr, &paint);
20 const char* str = "The quick brown fox jumped over the lazy dog.";
21
22 SkRandom rand;
23 SkPaint textPaint;
24 SkFont font(sk_tool_utils::create_portable_typeface());
25 for (int i = 0; i < 25; ++i) {
26 int x = rand.nextULessThan(WIDTH);
27 int y = rand.nextULessThan(HEIGHT);
28 textPaint.setColor(sk_tool_utils::color_to_565(rand.nextBits(24) | 0xFF000000));
29 font.setSize(rand.nextRangeScalar(0, 300));
30 canvas->drawString(str, SkIntToScalar(x), SkIntToScalar(y), font, textPaint);
31 }
32 canvas->restore();
33 }
DEF_SIMPLE_GM_BG(imageblur,canvas,WIDTH,HEIGHT,SK_ColorBLACK)34 DEF_SIMPLE_GM_BG(imageblur, canvas, WIDTH, HEIGHT, SK_ColorBLACK) {
35 imageblurgm_draw(24.0f, 0.0f, canvas);
36 }
DEF_SIMPLE_GM_BG(imageblur_large,canvas,WIDTH,HEIGHT,SK_ColorBLACK)37 DEF_SIMPLE_GM_BG(imageblur_large, canvas, WIDTH, HEIGHT, SK_ColorBLACK) {
38 imageblurgm_draw(80.0f, 80.0f, canvas);
39 }
40