OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "gm.h" | 8 #include "gm.h" |
9 #include "SkBlurImageFilter.h" | 9 #include "SkBlurImageFilter.h" |
| 10 #include "SkRandom.h" |
10 | 11 |
11 #define WIDTH 500 | 12 #define WIDTH 500 |
12 #define HEIGHT 500 | 13 #define HEIGHT 500 |
13 | 14 |
14 namespace skiagm { | 15 namespace skiagm { |
15 | 16 |
16 class ImageBlurGM : public GM { | 17 class ImageBlurGM : public GM { |
17 public: | 18 public: |
18 ImageBlurGM() { | 19 ImageBlurGM() { |
19 this->setBGColor(0xFF000000); | 20 this->setBGColor(0xFF000000); |
20 } | 21 } |
21 | 22 |
22 protected: | 23 protected: |
23 virtual SkString onShortName() { | 24 virtual SkString onShortName() { |
24 return SkString("imageblur"); | 25 return SkString("imageblur"); |
25 } | 26 } |
26 | 27 |
27 virtual SkISize onISize() { | 28 virtual SkISize onISize() { |
28 return make_isize(WIDTH, HEIGHT); | 29 return make_isize(WIDTH, HEIGHT); |
29 } | 30 } |
30 | 31 |
31 virtual void onDraw(SkCanvas* canvas) { | 32 virtual void onDraw(SkCanvas* canvas) { |
32 SkPaint paint; | 33 SkPaint paint; |
33 paint.setImageFilter(new SkBlurImageFilter(24.0f, 0.0f))->unref(); | 34 paint.setImageFilter(new SkBlurImageFilter(24.0f, 0.0f))->unref(); |
34 canvas->saveLayer(NULL, &paint); | 35 canvas->saveLayer(NULL, &paint); |
35 const char* str = "The quick brown fox jumped over the lazy dog."; | 36 const char* str = "The quick brown fox jumped over the lazy dog."; |
36 srand(1234); | 37 |
| 38 SkRandom rand; |
37 SkPaint textPaint; | 39 SkPaint textPaint; |
38 textPaint.setAntiAlias(true); | 40 textPaint.setAntiAlias(true); |
39 for (int i = 0; i < 25; ++i) { | 41 for (int i = 0; i < 25; ++i) { |
40 int x = rand() % WIDTH; | 42 int x = rand.nextULessThan(WIDTH); |
41 int y = rand() % HEIGHT; | 43 int y = rand.nextULessThan(HEIGHT); |
42 textPaint.setColor(rand() % 0x1000000 | 0xFF000000); | 44 textPaint.setColor(rand.nextBits(24) | 0xFF000000); |
43 textPaint.setTextSize(SkIntToScalar(rand() % 300)); | 45 textPaint.setTextSize(rand.nextULessThan(300)); |
44 canvas->drawText(str, strlen(str), SkIntToScalar(x), | 46 canvas->drawText(str, strlen(str), SkIntToScalar(x), |
45 SkIntToScalar(y), textPaint); | 47 SkIntToScalar(y), textPaint); |
46 } | 48 } |
47 canvas->restore(); | 49 canvas->restore(); |
48 } | 50 } |
49 | 51 |
50 private: | 52 private: |
51 typedef GM INHERITED; | 53 typedef GM INHERITED; |
52 }; | 54 }; |
53 | 55 |
54 ////////////////////////////////////////////////////////////////////////////// | 56 ////////////////////////////////////////////////////////////////////////////// |
55 | 57 |
56 static GM* MyFactory(void*) { return new ImageBlurGM; } | 58 static GM* MyFactory(void*) { return new ImageBlurGM; } |
57 static GMRegistry reg(MyFactory); | 59 static GMRegistry reg(MyFactory); |
58 | 60 |
59 } | 61 } |
OLD | NEW |