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 #include "SkRandom.h" |
11 | 11 |
12 #define WIDTH 500 | 12 #define WIDTH 500 |
13 #define HEIGHT 500 | 13 #define HEIGHT 500 |
14 | 14 |
15 namespace skiagm { | 15 namespace skiagm { |
16 | 16 |
17 class ImageBlurGM : public GM { | 17 class ImageBlurGM : public GM { |
18 public: | 18 public: |
19 ImageBlurGM() { | 19 ImageBlurGM(SkScalar sigmaX, SkScalar sigmaY) |
20 : fSigmaX(sigmaX), fSigmaY(sigmaY) { | |
20 this->setBGColor(0xFF000000); | 21 this->setBGColor(0xFF000000); |
21 } | 22 } |
22 | 23 |
23 protected: | 24 protected: |
24 virtual SkString onShortName() { | 25 virtual SkString onShortName() { |
25 return SkString("imageblur"); | 26 SkString name; |
27 name.printf("imageblur_%.2f_%.2f", | |
Stephen White
2013/12/19 15:27:03
This will cause the tools to consider the imageblu
zheng.xu
2013/12/20 04:29:54
Done.
| |
28 SkScalarToFloat(fSigmaX), SkScalarToFloat(fSigmaY)); | |
29 return name; | |
26 } | 30 } |
27 | 31 |
28 virtual SkISize onISize() { | 32 virtual SkISize onISize() { |
29 return make_isize(WIDTH, HEIGHT); | 33 return make_isize(WIDTH, HEIGHT); |
30 } | 34 } |
31 | 35 |
32 virtual void onDraw(SkCanvas* canvas) { | 36 virtual void onDraw(SkCanvas* canvas) { |
33 SkPaint paint; | 37 SkPaint paint; |
34 paint.setImageFilter(new SkBlurImageFilter(24.0f, 0.0f))->unref(); | 38 paint.setImageFilter(new SkBlurImageFilter(fSigmaX, fSigmaY))->unref(); |
35 canvas->saveLayer(NULL, &paint); | 39 canvas->saveLayer(NULL, &paint); |
36 const char* str = "The quick brown fox jumped over the lazy dog."; | 40 const char* str = "The quick brown fox jumped over the lazy dog."; |
37 | 41 |
38 SkRandom rand; | 42 SkRandom rand; |
39 SkPaint textPaint; | 43 SkPaint textPaint; |
40 textPaint.setAntiAlias(true); | 44 textPaint.setAntiAlias(true); |
41 for (int i = 0; i < 25; ++i) { | 45 for (int i = 0; i < 25; ++i) { |
42 int x = rand.nextULessThan(WIDTH); | 46 int x = rand.nextULessThan(WIDTH); |
43 int y = rand.nextULessThan(HEIGHT); | 47 int y = rand.nextULessThan(HEIGHT); |
44 textPaint.setColor(rand.nextBits(24) | 0xFF000000); | 48 textPaint.setColor(rand.nextBits(24) | 0xFF000000); |
45 textPaint.setTextSize(rand.nextRangeScalar(0, 300)); | 49 textPaint.setTextSize(rand.nextRangeScalar(0, 300)); |
46 canvas->drawText(str, strlen(str), SkIntToScalar(x), | 50 canvas->drawText(str, strlen(str), SkIntToScalar(x), |
47 SkIntToScalar(y), textPaint); | 51 SkIntToScalar(y), textPaint); |
48 } | 52 } |
49 canvas->restore(); | 53 canvas->restore(); |
50 } | 54 } |
51 | 55 |
52 private: | 56 private: |
57 SkScalar fSigmaX; | |
58 SkScalar fSigmaY; | |
59 | |
53 typedef GM INHERITED; | 60 typedef GM INHERITED; |
54 }; | 61 }; |
55 | 62 |
56 ////////////////////////////////////////////////////////////////////////////// | 63 ////////////////////////////////////////////////////////////////////////////// |
57 | 64 |
58 static GM* MyFactory(void*) { return new ImageBlurGM; } | 65 static GM* MyFactory1(void*) { return new ImageBlurGM(24.0f, 0.0f); } |
59 static GMRegistry reg(MyFactory); | 66 static GMRegistry reg1(MyFactory1); |
67 | |
68 static GM* MyFactory2(void*) { return new ImageBlurGM(80.0f, 80.0f); } | |
69 static GMRegistry reg2(MyFactory2); | |
60 | 70 |
61 } | 71 } |
OLD | NEW |