OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkMagnifierImageFilter.h" | 9 #include "SkMagnifierImageFilter.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 ImageMagnifierGM : public GM { | 17 class ImageMagnifierGM : public GM { |
17 public: | 18 public: |
18 ImageMagnifierGM() { | 19 ImageMagnifierGM() { |
19 this->setBGColor(0xFF000000); | 20 this->setBGColor(0xFF000000); |
(...skipping 17 matching lines...) Expand all Loading... |
37 SkPaint paint; | 38 SkPaint paint; |
38 paint.setImageFilter( | 39 paint.setImageFilter( |
39 new SkMagnifierImageFilter( | 40 new SkMagnifierImageFilter( |
40 SkRect::MakeXYWH(SkIntToScalar(125), SkIntToScalar(125), | 41 SkRect::MakeXYWH(SkIntToScalar(125), SkIntToScalar(125), |
41 SkIntToScalar(WIDTH / 2), | 42 SkIntToScalar(WIDTH / 2), |
42 SkIntToScalar(HEIGHT / 2)), | 43 SkIntToScalar(HEIGHT / 2)), |
43 100))->unref(); | 44 100))->unref(); |
44 canvas->saveLayer(NULL, &paint); | 45 canvas->saveLayer(NULL, &paint); |
45 paint.setAntiAlias(true); | 46 paint.setAntiAlias(true); |
46 const char* str = "The quick brown fox jumped over the lazy dog."; | 47 const char* str = "The quick brown fox jumped over the lazy dog."; |
47 srand(1234); | 48 SkRandom rand; |
48 for (int i = 0; i < 25; ++i) { | 49 for (int i = 0; i < 25; ++i) { |
49 int x = rand() % WIDTH; | 50 int x = rand.nextULessThan(WIDTH); |
50 int y = rand() % HEIGHT; | 51 int y = rand.nextULessThan(HEIGHT); |
51 paint.setColor(rand() % 0x1000000 | 0xFF000000); | 52 paint.setColor(rand.nextBits(24) | 0xFF000000); |
52 paint.setTextSize(SkIntToScalar(rand() % 300)); | 53 paint.setTextSize(rand.nextULessThan(300)); |
53 canvas->drawText(str, strlen(str), SkIntToScalar(x), | 54 canvas->drawText(str, strlen(str), SkIntToScalar(x), |
54 SkIntToScalar(y), paint); | 55 SkIntToScalar(y), paint); |
55 } | 56 } |
56 canvas->restore(); | 57 canvas->restore(); |
57 } | 58 } |
58 | 59 |
59 private: | 60 private: |
60 typedef GM INHERITED; | 61 typedef GM INHERITED; |
61 }; | 62 }; |
62 | 63 |
63 ////////////////////////////////////////////////////////////////////////////// | 64 ////////////////////////////////////////////////////////////////////////////// |
64 | 65 |
65 static GM* MyFactory(void*) { return new ImageMagnifierGM; } | 66 static GM* MyFactory(void*) { return new ImageMagnifierGM; } |
66 static GMRegistry reg(MyFactory); | 67 static GMRegistry reg(MyFactory); |
67 | 68 |
68 } | 69 } |
OLD | NEW |