• 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.h"
9 #include "SkBlurImageFilter.h"
10 #include "SkRandom.h"
11 
12 #define WIDTH 500
13 #define HEIGHT 500
14 
15 namespace skiagm {
16 
17 class ImageBlurGM : public GM {
18 public:
ImageBlurGM()19     ImageBlurGM() {
20         this->setBGColor(0xFF000000);
21     }
22 
23 protected:
onShortName()24     virtual SkString onShortName() {
25         return SkString("imageblur");
26     }
27 
onISize()28     virtual SkISize onISize() {
29         return make_isize(WIDTH, HEIGHT);
30     }
31 
onDraw(SkCanvas * canvas)32     virtual void onDraw(SkCanvas* canvas) {
33         SkPaint paint;
34         paint.setImageFilter(new SkBlurImageFilter(24.0f, 0.0f))->unref();
35         canvas->saveLayer(NULL, &paint);
36         const char* str = "The quick brown fox jumped over the lazy dog.";
37 
38         SkRandom rand;
39         SkPaint textPaint;
40         textPaint.setAntiAlias(true);
41         for (int i = 0; i < 25; ++i) {
42             int x = rand.nextULessThan(WIDTH);
43             int y = rand.nextULessThan(HEIGHT);
44             textPaint.setColor(rand.nextBits(24) | 0xFF000000);
45             textPaint.setTextSize(rand.nextRangeScalar(0, 300));
46             canvas->drawText(str, strlen(str), SkIntToScalar(x),
47                              SkIntToScalar(y), textPaint);
48         }
49         canvas->restore();
50     }
51 
52 private:
53     typedef GM INHERITED;
54 };
55 
56 //////////////////////////////////////////////////////////////////////////////
57 
MyFactory(void *)58 static GM* MyFactory(void*) { return new ImageBlurGM; }
59 static GMRegistry reg(MyFactory);
60 
61 }
62