OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 | 10 |
11 #include "gm.h" | 11 #include "gm.h" |
12 #include "SkRandom.h" | 12 #include "SkRandom.h" |
13 | 13 |
14 #define W 400 | 14 #define W 400 |
15 #define H 400 | 15 #define H 400 |
16 #define N 50 | 16 #define N 50 |
17 | 17 |
18 static const SkScalar SW = SkIntToScalar(W); | 18 static const SkScalar SW = SkIntToScalar(W); |
19 static const SkScalar SH = SkIntToScalar(H); | 19 static const SkScalar SH = SkIntToScalar(H); |
20 | 20 |
21 static void rnd_rect(SkRect* r, SkPaint* paint, SkRandom& rand) { | 21 static void rnd_rect(SkRect* r, SkPaint* paint, SkLCGRandom& rand) { |
22 SkScalar x = rand.nextUScalar1() * W; | 22 SkScalar x = rand.nextUScalar1() * W; |
23 SkScalar y = rand.nextUScalar1() * H; | 23 SkScalar y = rand.nextUScalar1() * H; |
24 SkScalar w = rand.nextUScalar1() * (W >> 2); | 24 SkScalar w = rand.nextUScalar1() * (W >> 2); |
25 SkScalar h = rand.nextUScalar1() * (H >> 2); | 25 SkScalar h = rand.nextUScalar1() * (H >> 2); |
26 SkScalar hoffset = rand.nextSScalar1(); | 26 SkScalar hoffset = rand.nextSScalar1(); |
27 SkScalar woffset = rand.nextSScalar1(); | 27 SkScalar woffset = rand.nextSScalar1(); |
28 | 28 |
29 r->set(x, y, x + w, y + h); | 29 r->set(x, y, x + w, y + h); |
30 r->offset(-w/2 + woffset, -h/2 + hoffset); | 30 r->offset(-w/2 + woffset, -h/2 + hoffset); |
31 | 31 |
(...skipping 22 matching lines...) Expand all Loading... |
54 | 54 |
55 for (int y = 0; y < 2; y++) { | 55 for (int y = 0; y < 2; y++) { |
56 paint.setAntiAlias(!!y); | 56 paint.setAntiAlias(!!y); |
57 SkAutoCanvasRestore acr(canvas, true); | 57 SkAutoCanvasRestore acr(canvas, true); |
58 canvas->translate(0, SH * y); | 58 canvas->translate(0, SH * y); |
59 canvas->clipRect(SkRect::MakeLTRB( | 59 canvas->clipRect(SkRect::MakeLTRB( |
60 SkIntToScalar(2), SkIntToScalar(2) | 60 SkIntToScalar(2), SkIntToScalar(2) |
61 , SW - SkIntToScalar(2), SH - SkIn
tToScalar(2) | 61 , SW - SkIntToScalar(2), SH - SkIn
tToScalar(2) |
62 )); | 62 )); |
63 | 63 |
64 SkRandom rand; | 64 SkLCGRandom rand; |
65 for (int i = 0; i < N; i++) { | 65 for (int i = 0; i < N; i++) { |
66 SkRect r; | 66 SkRect r; |
67 rnd_rect(&r, &paint, rand); | 67 rnd_rect(&r, &paint, rand); |
68 canvas->drawOval(r, paint); | 68 canvas->drawOval(r, paint); |
69 rnd_rect(&r, &paint, rand); | 69 rnd_rect(&r, &paint, rand); |
70 canvas->drawRoundRect(r, r.width()/4, r.height()/4, paint); | 70 canvas->drawRoundRect(r, r.width()/4, r.height()/4, paint); |
71 rnd_rect(&r, &paint, rand); | 71 rnd_rect(&r, &paint, rand); |
72 } | 72 } |
73 } | 73 } |
74 } | 74 } |
75 | 75 |
76 private: | 76 private: |
77 typedef skiagm::GM INHERITED; | 77 typedef skiagm::GM INHERITED; |
78 }; | 78 }; |
79 | 79 |
80 class Strokes2GM : public skiagm::GM { | 80 class Strokes2GM : public skiagm::GM { |
81 SkPath fPath; | 81 SkPath fPath; |
82 public: | 82 public: |
83 Strokes2GM() { | 83 Strokes2GM() { |
84 SkRandom rand; | 84 SkLCGRandom rand; |
85 fPath.moveTo(0, 0); | 85 fPath.moveTo(0, 0); |
86 for (int i = 0; i < 13; i++) { | 86 for (int i = 0; i < 13; i++) { |
87 SkScalar x = rand.nextUScalar1() * (W >> 1); | 87 SkScalar x = rand.nextUScalar1() * (W >> 1); |
88 SkScalar y = rand.nextUScalar1() * (H >> 1); | 88 SkScalar y = rand.nextUScalar1() * (H >> 1); |
89 fPath.lineTo(x, y); | 89 fPath.lineTo(x, y); |
90 } | 90 } |
91 } | 91 } |
92 | 92 |
93 protected: | 93 protected: |
94 virtual SkString onShortName() { | 94 virtual SkString onShortName() { |
(...skipping 19 matching lines...) Expand all Loading... |
114 | 114 |
115 for (int y = 0; y < 2; y++) { | 115 for (int y = 0; y < 2; y++) { |
116 paint.setAntiAlias(!!y); | 116 paint.setAntiAlias(!!y); |
117 SkAutoCanvasRestore acr(canvas, true); | 117 SkAutoCanvasRestore acr(canvas, true); |
118 canvas->translate(0, SH * y); | 118 canvas->translate(0, SH * y); |
119 canvas->clipRect(SkRect::MakeLTRB(SkIntToScalar(2), | 119 canvas->clipRect(SkRect::MakeLTRB(SkIntToScalar(2), |
120 SkIntToScalar(2), | 120 SkIntToScalar(2), |
121 SW - SkIntToScalar(2), | 121 SW - SkIntToScalar(2), |
122 SH - SkIntToScalar(2))); | 122 SH - SkIntToScalar(2))); |
123 | 123 |
124 SkRandom rand; | 124 SkLCGRandom rand; |
125 for (int i = 0; i < N/2; i++) { | 125 for (int i = 0; i < N/2; i++) { |
126 SkRect r; | 126 SkRect r; |
127 rnd_rect(&r, &paint, rand); | 127 rnd_rect(&r, &paint, rand); |
128 rotate(SkIntToScalar(15), SW/2, SH/2, canvas); | 128 rotate(SkIntToScalar(15), SW/2, SH/2, canvas); |
129 canvas->drawPath(fPath, paint); | 129 canvas->drawPath(fPath, paint); |
130 } | 130 } |
131 } | 131 } |
132 } | 132 } |
133 | 133 |
134 private: | 134 private: |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 | 241 |
242 ////////////////////////////////////////////////////////////////////////////// | 242 ////////////////////////////////////////////////////////////////////////////// |
243 | 243 |
244 static skiagm::GM* F0(void*) { return new StrokesGM; } | 244 static skiagm::GM* F0(void*) { return new StrokesGM; } |
245 static skiagm::GM* F1(void*) { return new Strokes2GM; } | 245 static skiagm::GM* F1(void*) { return new Strokes2GM; } |
246 static skiagm::GM* F2(void*) { return new Strokes3GM; } | 246 static skiagm::GM* F2(void*) { return new Strokes3GM; } |
247 | 247 |
248 static skiagm::GMRegistry R0(F0); | 248 static skiagm::GMRegistry R0(F0); |
249 static skiagm::GMRegistry R1(F1); | 249 static skiagm::GMRegistry R1(F1); |
250 static skiagm::GMRegistry R2(F2); | 250 static skiagm::GMRegistry R2(F2); |
OLD | NEW |