• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/gm.h"
9 #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"
16 #include "include/effects/SkImageFilters.h"
17 #include "include/utils/SkRandom.h"
18 #include "tools/ToolUtils.h"
19 
20 #define WIDTH 500
21 #define HEIGHT 500
22 
imageblurgm_draw(SkScalar fSigmaX,SkScalar fSigmaY,SkCanvas * canvas)23 void imageblurgm_draw(SkScalar fSigmaX, SkScalar fSigmaY, SkCanvas* canvas) {
24         SkPaint paint;
25         paint.setImageFilter(SkImageFilters::Blur(fSigmaX, fSigmaY, nullptr));
26         canvas->saveLayer(nullptr, &paint);
27         const char* str = "The quick brown fox jumped over the lazy dog.";
28 
29         SkRandom rand;
30         SkPaint textPaint;
31         SkFont   font(ToolUtils::create_portable_typeface());
32         for (int i = 0; i < 25; ++i) {
33             int x = rand.nextULessThan(WIDTH);
34             int y = rand.nextULessThan(HEIGHT);
35             textPaint.setColor(ToolUtils::color_to_565(rand.nextBits(24) | 0xFF000000));
36             font.setSize(rand.nextRangeScalar(0, 300));
37             canvas->drawString(str, SkIntToScalar(x), SkIntToScalar(y), font, textPaint);
38         }
39         canvas->restore();
40 }
DEF_SIMPLE_GM_BG(imageblur,canvas,WIDTH,HEIGHT,SK_ColorBLACK)41 DEF_SIMPLE_GM_BG(imageblur,       canvas, WIDTH, HEIGHT, SK_ColorBLACK) {
42     imageblurgm_draw(24.0f, 0.0f, canvas);
43 }
DEF_SIMPLE_GM_BG(imageblur_large,canvas,WIDTH,HEIGHT,SK_ColorBLACK)44 DEF_SIMPLE_GM_BG(imageblur_large, canvas, WIDTH, HEIGHT, SK_ColorBLACK) {
45     imageblurgm_draw(80.0f, 80.0f, canvas);
46 }
47