OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkPerlinNoiseShader.h" | 9 #include "SkPerlinNoiseShader.h" |
10 | 10 |
11 namespace skiagm { | 11 namespace skiagm { |
12 | 12 |
13 class PerlinNoiseGM : public GM { | 13 class PerlinNoiseGM : public GM { |
14 public: | 14 public: |
15 PerlinNoiseGM() { | 15 PerlinNoiseGM() { |
16 this->setBGColor(0xFF000000); | 16 this->setBGColor(0xFF000000); |
17 fSize = SkISize::Make(80, 80); | 17 fSize = SkISize::Make(80, 80); |
18 } | 18 } |
19 | 19 |
20 protected: | 20 protected: |
21 virtual SkString onShortName() { | 21 virtual SkString onShortName() { |
22 return SkString("perlinnoise"); | 22 return SkString("perlinnoise"); |
23 } | 23 } |
24 | 24 |
25 virtual SkISize onISize() { | 25 virtual SkISize onISize() { |
26 return make_isize(500, 400); | 26 return make_isize(200, 400); |
27 } | 27 } |
28 | 28 |
29 void drawClippedRect(SkCanvas* canvas, int x, int y, const SkPaint& paint) { | 29 void drawClippedRect(SkCanvas* canvas, int x, int y, const SkPaint& paint) { |
30 canvas->save(); | 30 canvas->save(); |
31 canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y), | 31 canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y), |
32 SkIntToScalar(fSize.width()), SkIntToScalar(fSize.heigh
t()))); | 32 SkIntToScalar(fSize.width()), SkIntToScalar(fSize.heigh
t()))); |
33 SkRect r = SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y), | 33 SkRect r = SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y), |
34 SkIntToScalar(fSize.width()), | 34 SkIntToScalar(fSize.width()), |
35 SkIntToScalar(fSize.height())); | 35 SkIntToScalar(fSize.height())); |
36 canvas->drawRect(r, paint); | 36 canvas->drawRect(r, paint); |
(...skipping 12 matching lines...) Expand all Loading... |
49 paint.setShader(shader)->unref(); | 49 paint.setShader(shader)->unref(); |
50 drawClippedRect(canvas, x, y, paint); | 50 drawClippedRect(canvas, x, y, paint); |
51 } | 51 } |
52 | 52 |
53 virtual void onDraw(SkCanvas* canvas) { | 53 virtual void onDraw(SkCanvas* canvas) { |
54 canvas->clear(0x00000000); | 54 canvas->clear(0x00000000); |
55 | 55 |
56 test(canvas, 0, 0, SkPerlinNoiseShader::kFractalNoise_Type, | 56 test(canvas, 0, 0, SkPerlinNoiseShader::kFractalNoise_Type, |
57 0.1f, 0.1f, 2, 0, false); | 57 0.1f, 0.1f, 2, 0, false); |
58 test(canvas, 100, 0, SkPerlinNoiseShader::kFractalNoise_Type, | 58 test(canvas, 100, 0, SkPerlinNoiseShader::kFractalNoise_Type, |
59 0.4f, 0.2f, 3, 0, true); | |
60 test(canvas, 200, 0, SkPerlinNoiseShader::kFractalNoise_Type, | |
61 0.3f, 0.6f, 4, 0, false); | |
62 test(canvas, 300, 0, SkPerlinNoiseShader::kFractalNoise_Type, | |
63 0.2f, 0.4f, 5, 0, true); | 59 0.2f, 0.4f, 5, 0, true); |
64 test(canvas, 400, 0, SkPerlinNoiseShader::kFractalNoise_Type, | |
65 0.5f, 0.8f, 6, 0, false); | |
66 | 60 |
67 test(canvas, 0, 100, SkPerlinNoiseShader::kTurbulence_Type, | 61 test(canvas, 0, 100, SkPerlinNoiseShader::kTurbulence_Type, |
68 0.1f, 0.1f, 2, 0, true); | 62 0.1f, 0.1f, 2, 0, true); |
69 test(canvas, 100, 100, SkPerlinNoiseShader::kTurbulence_Type, | 63 test(canvas, 100, 100, SkPerlinNoiseShader::kTurbulence_Type, |
70 0.4f, 0.2f, 3, 0, false); | |
71 test(canvas, 200, 100, SkPerlinNoiseShader::kTurbulence_Type, | |
72 0.3f, 0.6f, 4, 0, true); | |
73 test(canvas, 300, 100, SkPerlinNoiseShader::kTurbulence_Type, | |
74 0.2f, 0.4f, 5, 0, false); | 64 0.2f, 0.4f, 5, 0, false); |
75 test(canvas, 400, 100, SkPerlinNoiseShader::kTurbulence_Type, | |
76 0.5f, 0.8f, 6, 0, true); | |
77 | 65 |
78 test(canvas, 0, 200, SkPerlinNoiseShader::kFractalNoise_Type, | 66 test(canvas, 0, 200, SkPerlinNoiseShader::kFractalNoise_Type, |
79 0.1f, 0.1f, 3, 1, false); | 67 0.1f, 0.1f, 3, 1, false); |
80 test(canvas, 100, 200, SkPerlinNoiseShader::kFractalNoise_Type, | 68 test(canvas, 100, 200, SkPerlinNoiseShader::kFractalNoise_Type, |
81 0.1f, 0.1f, 3, 2, false); | |
82 test(canvas, 200, 200, SkPerlinNoiseShader::kFractalNoise_Type, | |
83 0.1f, 0.1f, 3, 3, false); | |
84 test(canvas, 300, 200, SkPerlinNoiseShader::kFractalNoise_Type, | |
85 0.1f, 0.1f, 3, 4, false); | 69 0.1f, 0.1f, 3, 4, false); |
86 test(canvas, 400, 200, SkPerlinNoiseShader::kFractalNoise_Type, | |
87 0.1f, 0.1f, 3, 5, false); | |
88 | 70 |
89 canvas->scale(SkFloatToScalar(0.75f), SkFloatToScalar(1.0f)); | 71 canvas->scale(SkFloatToScalar(0.75f), SkFloatToScalar(1.0f)); |
90 | 72 |
91 test(canvas, 0, 300, SkPerlinNoiseShader::kFractalNoise_Type, | 73 test(canvas, 0, 300, SkPerlinNoiseShader::kFractalNoise_Type, |
92 0.1f, 0.1f, 2, 0, false); | 74 0.1f, 0.1f, 2, 0, false); |
93 test(canvas, 100, 300, SkPerlinNoiseShader::kFractalNoise_Type, | 75 test(canvas, 100, 300, SkPerlinNoiseShader::kFractalNoise_Type, |
94 0.4f, 0.2f, 3, 0, true); | |
95 test(canvas, 200, 300, SkPerlinNoiseShader::kFractalNoise_Type, | |
96 0.3f, 0.6f, 4, 0, false); | |
97 test(canvas, 300, 300, SkPerlinNoiseShader::kFractalNoise_Type, | |
98 0.2f, 0.4f, 5, 0, true); | 76 0.2f, 0.4f, 5, 0, true); |
99 test(canvas, 400, 300, SkPerlinNoiseShader::kFractalNoise_Type, | |
100 0.5f, 0.8f, 6, 0, false); | |
101 } | 77 } |
102 | 78 |
103 private: | 79 private: |
104 typedef GM INHERITED; | 80 typedef GM INHERITED; |
105 SkISize fSize; | 81 SkISize fSize; |
106 }; | 82 }; |
107 | 83 |
108 ////////////////////////////////////////////////////////////////////////////// | 84 ////////////////////////////////////////////////////////////////////////////// |
109 | 85 |
110 static GM* MyFactory(void*) { return new PerlinNoiseGM; } | 86 static GM* MyFactory(void*) { return new PerlinNoiseGM; } |
111 static GMRegistry reg(MyFactory); | 87 static GMRegistry reg(MyFactory); |
112 | 88 |
113 } | 89 } |
OLD | NEW |