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