OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library canvas_rendering_context_2d_test; import '../../pkg/unittest/lib/unittes
t.dart'; | 5 library canvas_rendering_context_2d_test; import '../../pkg/unittest/lib/unittes
t.dart'; |
6 import '../../pkg/unittest/lib/html_individual_config.dart'; | 6 import '../../pkg/unittest/lib/html_individual_config.dart'; |
7 import 'dart:html'; | 7 import 'dart:html'; |
8 import 'dart:math'; | 8 import 'dart:math'; |
9 | 9 |
10 // Some rounding errors in the browsers. | 10 // Some rounding errors in the browsers. |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 context = canvas.context2D; | 29 context = canvas.context2D; |
30 } | 30 } |
31 | 31 |
32 void createOtherCanvas() { | 32 void createOtherCanvas() { |
33 otherCanvas = new CanvasElement(); | 33 otherCanvas = new CanvasElement(); |
34 otherCanvas.width = 10; | 34 otherCanvas.width = 10; |
35 otherCanvas.height = 10; | 35 otherCanvas.height = 10; |
36 otherContext = otherCanvas.context2D; | 36 otherContext = otherCanvas.context2D; |
37 otherContext.fillStyle = "red"; | 37 otherContext.fillStyle = "red"; |
38 otherContext.fillRect(0, 0, otherCanvas.width, otherCanvas.height); | 38 otherContext.fillRect(0.0, 0.0, |
| 39 otherCanvas.width.toDouble(), otherCanvas.height.toDouble()); |
39 } | 40 } |
40 | 41 |
41 void setupFunc() { | 42 void setupFunc() { |
42 createCanvas(); | 43 createCanvas(); |
43 createOtherCanvas(); | 44 createOtherCanvas(); |
44 video = new VideoElement(); | 45 video = new VideoElement(); |
45 } | 46 } |
46 | 47 |
47 void tearDownFunc() { | 48 void tearDownFunc() { |
48 canvas = null; | 49 canvas = null; |
49 context = null; | 50 context = null; |
50 otherCanvas = null; | 51 otherCanvas = null; |
51 otherContext = null; | 52 otherContext = null; |
52 video = null; | 53 video = null; |
53 } | 54 } |
54 | 55 |
55 List<int> readPixel(int x, int y) { | 56 List<int> readPixel(num x, num y) { |
56 var imageData = context.getImageData(x, y, 1, 1); | 57 var imageData = context.getImageData(x.toDouble(), y.toDouble(), 1.0, 1.0); |
57 return imageData.data; | 58 return imageData.data; |
58 } | 59 } |
59 | 60 |
60 /// Returns true if the pixel has some data in it, false otherwise. | 61 /// Returns true if the pixel has some data in it, false otherwise. |
61 bool isPixelFilled(int x, int y) => readPixel(x,y).any((p) => p != 0); | 62 bool isPixelFilled(num x, num y) => readPixel(x,y).any((p) => p != 0); |
62 | 63 |
63 String pixelDataToString(List<int> data, int x, int y) { | 64 String pixelDataToString(List<int> data, num x, num y) { |
64 return '[${data.join(", ")}]'; | 65 return '[${data.join(", ")}]'; |
65 } | 66 } |
66 | 67 |
67 String _filled(bool v) => v ? "filled" : "unfilled"; | 68 String _filled(bool v) => v ? "filled" : "unfilled"; |
68 | 69 |
69 void expectPixelFilled(int x, int y, [bool filled = true]) { | 70 void expectPixelFilled(num x, num y, [bool filled = true]) { |
70 expect(isPixelFilled(x, y), filled, reason: | 71 expect(isPixelFilled(x.toInt(), y.toInt()), filled, reason: |
71 'Pixel at ($x, $y) was expected to' | 72 'Pixel at ($x, $y) was expected to' |
72 ' be: <${_filled(filled)}> but was: <${_filled(!filled)}> with data: ' | 73 ' be: <${_filled(filled)}> but was: <${_filled(!filled)}> with data: ' |
73 '${pixelDataToString(readPixel(x, y), x, y)}'); | 74 '${pixelDataToString(readPixel(x, y), x, y)}'); |
74 } | 75 } |
75 | 76 |
76 void expectPixelUnfilled(int x, int y) { | 77 void expectPixelUnfilled(num x, num y) { |
77 expectPixelFilled(x, y, false); | 78 expectPixelFilled(x, y, false); |
78 } | 79 } |
79 | 80 |
80 main() { | 81 main() { |
81 useHtmlIndividualConfiguration(); | 82 useHtmlIndividualConfiguration(); |
82 | 83 |
83 group('pixel_manipulation', () { | 84 group('pixel_manipulation', () { |
84 setUp(setupFunc); | 85 setUp(setupFunc); |
85 tearDown(tearDownFunc); | 86 tearDown(tearDownFunc); |
86 | 87 |
87 test('setFillColorRgb', () { | 88 test('setFillColorRgb', () { |
88 context.setFillColorRgb(255, 0, 255, 1); | 89 context.setFillColorRgb(255, 0, 255, 1); |
89 context.fillRect(0, 0, canvas.width, canvas.height); | 90 context.fillRect(0.0, 0.0, |
| 91 canvas.width.toDouble(), canvas.height.toDouble()); |
90 expect(readPixel(2, 2), [255, 0, 255, 255]); | 92 expect(readPixel(2, 2), [255, 0, 255, 255]); |
91 }); | 93 }); |
92 | 94 |
93 test('setFillColorHsl hue', () { | 95 test('setFillColorHsl hue', () { |
94 context.setFillColorHsl(0, 100, 50); | 96 context.setFillColorHsl(0, 100, 50); |
95 context.fillRect(0, 0, canvas.width, canvas.height); | 97 context.fillRect(0.0, 0.0, |
| 98 canvas.width.toDouble(), canvas.height.toDouble()); |
96 checkPixel(readPixel(2, 2), [255, 0, 0, 255]); | 99 checkPixel(readPixel(2, 2), [255, 0, 0, 255]); |
97 }); | 100 }); |
98 | 101 |
99 test('setFillColorHsl hue 2', () { | 102 test('setFillColorHsl hue 2', () { |
100 context.setFillColorHsl(240, 100, 50); | 103 context.setFillColorHsl(240, 100, 50); |
101 context.fillRect(0, 0, canvas.width, canvas.height); | 104 context.fillRect(0.0, 0.0, |
| 105 canvas.width.toDouble(), canvas.height.toDouble()); |
102 checkPixel(readPixel(2, 2), [0, 0, 255, 255]); | 106 checkPixel(readPixel(2, 2), [0, 0, 255, 255]); |
103 }); | 107 }); |
104 | 108 |
105 test('setFillColorHsl sat', () { | 109 test('setFillColorHsl sat', () { |
106 context.setFillColorHsl(0, 0, 50); | 110 context.setFillColorHsl(0, 0, 50); |
107 context.fillRect(0, 0, canvas.width, canvas.height); | 111 context.fillRect(0.0, 0.0, |
| 112 canvas.width.toDouble(), canvas.height.toDouble()); |
108 checkPixel(readPixel(2, 2), [127, 127, 127, 255]); | 113 checkPixel(readPixel(2, 2), [127, 127, 127, 255]); |
109 }); | 114 }); |
110 | 115 |
111 test('setStrokeColorRgb', () { | 116 test('setStrokeColorRgb', () { |
112 context.setStrokeColorRgb(255, 0, 255, 1); | 117 context.setStrokeColorRgb(255, 0, 255, 1); |
113 context.lineWidth = 10; | 118 context.lineWidth = 10.0; |
114 context.strokeRect(0, 0, canvas.width, canvas.height); | 119 context.strokeRect(0.0, 0.0, |
| 120 canvas.width.toDouble(), canvas.height.toDouble()); |
115 expect(readPixel(2, 2), [255, 0, 255, 255]); | 121 expect(readPixel(2, 2), [255, 0, 255, 255]); |
116 }); | 122 }); |
117 | 123 |
118 test('setStrokeColorHsl hue', () { | 124 test('setStrokeColorHsl hue', () { |
119 context.setStrokeColorHsl(0, 100, 50); | 125 context.setStrokeColorHsl(0, 100, 50); |
120 context.lineWidth = 10; | 126 context.lineWidth = 10.0; |
121 context.strokeRect(0, 0, canvas.width, canvas.height); | 127 context.strokeRect(0.0, 0.0, |
| 128 canvas.width.toDouble(), canvas.height.toDouble()); |
122 expect(readPixel(2, 2), [255, 0, 0, 255]); | 129 expect(readPixel(2, 2), [255, 0, 0, 255]); |
123 }); | 130 }); |
124 | 131 |
125 test('setStrokeColorHsl hue 2', () { | 132 test('setStrokeColorHsl hue 2', () { |
126 context.setStrokeColorHsl(240, 100, 50); | 133 context.setStrokeColorHsl(240, 100, 50); |
127 context.lineWidth = 10; | 134 context.lineWidth = 10.0; |
128 context.strokeRect(0, 0, canvas.width, canvas.height); | 135 context.strokeRect(0.0, 0.0, |
| 136 canvas.width.toDouble(), canvas.height.toDouble()); |
129 expect(readPixel(2, 2), [0, 0, 255, 255]); | 137 expect(readPixel(2, 2), [0, 0, 255, 255]); |
130 }); | 138 }); |
131 | 139 |
132 test('setStrokeColorHsl sat', () { | 140 test('setStrokeColorHsl sat', () { |
133 context.setStrokeColorHsl(0, 0, 50); | 141 context.setStrokeColorHsl(0, 0, 50); |
134 context.lineWidth = 10; | 142 context.lineWidth = 10.0; |
135 context.strokeRect(0, 0, canvas.width, canvas.height); | 143 context.strokeRect(0.0, 0.0, |
| 144 canvas.width.toDouble(), canvas.height.toDouble()); |
136 checkPixel(readPixel(2, 2), [127, 127, 127, 255]); | 145 checkPixel(readPixel(2, 2), [127, 127, 127, 255]); |
137 }); | 146 }); |
138 | 147 |
139 test('fillStyle', () { | 148 test('fillStyle', () { |
140 context.fillStyle = "red"; | 149 context.fillStyle = "red"; |
141 context.fillRect(0, 0, canvas.width, canvas.height); | 150 context.fillRect(0.0, 0.0, |
| 151 canvas.width.toDouble(), canvas.height.toDouble()); |
142 checkPixel(readPixel(2, 2), [255, 0, 0, 255]); | 152 checkPixel(readPixel(2, 2), [255, 0, 0, 255]); |
143 }); | 153 }); |
144 | 154 |
145 test('strokeStyle', () { | 155 test('strokeStyle', () { |
146 context.strokeStyle = "blue"; | 156 context.strokeStyle = "blue"; |
147 context.lineWidth = 10; | 157 context.lineWidth = 10.0; |
148 context.strokeRect(0, 0, canvas.width, canvas.height); | 158 context.strokeRect(0.0, 0.0, |
| 159 canvas.width.toDouble(), canvas.height.toDouble()); |
149 expect(readPixel(2, 2), [0, 0, 255, 255]); | 160 expect(readPixel(2, 2), [0, 0, 255, 255]); |
150 }); | 161 }); |
151 | 162 |
152 test('fillStyle linearGradient', () { | 163 test('fillStyle linearGradient', () { |
153 var gradient = context.createLinearGradient(0,0,20,20); | 164 var gradient = context.createLinearGradient(0.0,0.0,20.0,20.0); |
154 gradient.addColorStop(0,'red'); | 165 gradient.addColorStop(0.0,'red'); |
155 gradient.addColorStop(1,'blue'); | 166 gradient.addColorStop(1.0,'blue'); |
156 context.fillStyle = gradient; | 167 context.fillStyle = gradient; |
157 context.fillRect(0, 0, canvas.width, canvas.height); | 168 context.fillRect(0.0, 0.0, |
| 169 canvas.width.toDouble(), canvas.height.toDouble()); |
158 expect(context.fillStyle is CanvasGradient, isTrue); | 170 expect(context.fillStyle is CanvasGradient, isTrue); |
159 }); | 171 }); |
160 | 172 |
161 test('putImageData', () { | 173 test('putImageData', () { |
162 context.fillStyle = 'green'; | 174 context.fillStyle = 'green'; |
163 context.fillRect(0, 0, canvas.width, canvas.height); | 175 context.fillRect(0.0, 0.0, |
| 176 canvas.width.toDouble(), canvas.height.toDouble()); |
164 | 177 |
165 ImageData expectedData = context.getImageData(0, 0, 10, 10); | 178 ImageData expectedData = context.getImageData(0.0, 0.0, 10.0, 10.0); |
166 expectedData.data[0] = 25; | 179 expectedData.data[0] = 25; |
167 expectedData.data[1] = 65; | 180 expectedData.data[1] = 65; |
168 expectedData.data[2] = 255; | 181 expectedData.data[2] = 255; |
169 // Set alpha to 255 to make the pixels show up. | 182 // Set alpha to 255 to make the pixels show up. |
170 expectedData.data[3] = 255; | 183 expectedData.data[3] = 255; |
171 | 184 |
172 context.putImageData(expectedData, 0, 0); | 185 context.putImageData(expectedData, 0.0, 0.0); |
173 | 186 |
174 var resultingData = context.getImageData(0, 0, 10, 10); | 187 var resultingData = context.getImageData(0.0, 0.0, 10.0, 10.0); |
175 // Make sure that we read back what we wrote. | 188 // Make sure that we read back what we wrote. |
176 expect(resultingData.data, expectedData.data); | 189 expect(resultingData.data, expectedData.data); |
177 }); | 190 }); |
178 | 191 |
179 test('putImageData dirty rectangle', () { | 192 test('putImageData dirty rectangle', () { |
180 context.fillStyle = 'green'; | 193 context.fillStyle = 'green'; |
181 context.fillRect(0, 0, canvas.width, canvas.height); | 194 context.fillRect(0.0, 0.0, canvas.width.toDouble(), canvas.height.toDouble
()); |
182 | 195 |
183 ImageData drawnData = context.getImageData(0, 0, 10, 10); | 196 ImageData drawnData = context.getImageData(0.0, 0.0, 10.0, 10.0); |
184 drawnData.data[0] = 25; | 197 drawnData.data[0] = 25; |
185 drawnData.data[1] = 65; | 198 drawnData.data[1] = 65; |
186 drawnData.data[2] = 255; | 199 drawnData.data[2] = 255; |
187 drawnData.data[3] = 255; | 200 drawnData.data[3] = 255; |
188 | 201 |
189 // Draw these pixels to the 2nd pixel. | 202 // Draw these pixels to the 2nd pixel. |
190 drawnData.data[2 * 4 + 0] = 25; | 203 drawnData.data[2 * 4 + 0] = 25; |
191 drawnData.data[2 * 4 + 1] = 65; | 204 drawnData.data[2 * 4 + 1] = 65; |
192 drawnData.data[2 * 4 + 2] = 255; | 205 drawnData.data[2 * 4 + 2] = 255; |
193 drawnData.data[2 * 4 + 3] = 255; | 206 drawnData.data[2 * 4 + 3] = 255; |
194 | 207 |
195 // Draw these pixels to the 8th pixel. | 208 // Draw these pixels to the 8th pixel. |
196 drawnData.data[7 * 4 + 0] = 25; | 209 drawnData.data[7 * 4 + 0] = 25; |
197 drawnData.data[7 * 4 + 1] = 65; | 210 drawnData.data[7 * 4 + 1] = 65; |
198 drawnData.data[7 * 4 + 2] = 255; | 211 drawnData.data[7 * 4 + 2] = 255; |
199 drawnData.data[7 * 4 + 3] = 255; | 212 drawnData.data[7 * 4 + 3] = 255; |
200 | 213 |
201 // Use a dirty rectangle to limit what pixels are drawn. | 214 // Use a dirty rectangle to limit what pixels are drawn. |
202 context.putImageData(drawnData, 0, 0, 1, 0, 5, 5); | 215 context.putImageData(drawnData, 0.0, 0.0, 1.0, 0.0, 5.0, 5.0); |
203 | 216 |
204 // Expect the data to be all green, as we skip all drawn pixels. | 217 // Expect the data to be all green, as we skip all drawn pixels. |
205 ImageData expectedData = context.createImageData(10, 10); | 218 ImageData expectedData = context.createImageData(10.0, 10.0); |
206 for (int i = 0; i < expectedData.data.length; i++) { | 219 for (int i = 0; i < expectedData.data.length; i++) { |
207 switch (i % 4) { | 220 switch (i % 4) { |
208 case 0: | 221 case 0: |
209 expectedData.data[i] = 0; | 222 expectedData.data[i] = 0; |
210 break; | 223 break; |
211 case 1: | 224 case 1: |
212 expectedData.data[i] = 128; | 225 expectedData.data[i] = 128; |
213 break; | 226 break; |
214 case 2: | 227 case 2: |
215 expectedData.data[i] = 0; | 228 expectedData.data[i] = 0; |
216 break; | 229 break; |
217 case 3: | 230 case 3: |
218 expectedData.data[i] = 255; | 231 expectedData.data[i] = 255; |
219 break; | 232 break; |
220 } | 233 } |
221 } | 234 } |
222 // Third pixel was copied. | 235 // Third pixel was copied. |
223 expectedData.data[2 * 4 + 0] = 25; | 236 expectedData.data[2 * 4 + 0] = 25; |
224 expectedData.data[2 * 4 + 1] = 65; | 237 expectedData.data[2 * 4 + 1] = 65; |
225 expectedData.data[2 * 4 + 2] = 255; | 238 expectedData.data[2 * 4 + 2] = 255; |
226 expectedData.data[2 * 4 + 3] = 255; | 239 expectedData.data[2 * 4 + 3] = 255; |
227 | 240 |
228 // Make sure that our data is all green. | 241 // Make sure that our data is all green. |
229 var resultingData = context.getImageData(0, 0, 10, 10); | 242 var resultingData = context.getImageData(0.0, 0.0, 10.0, 10.0); |
230 expect(resultingData.data, expectedData.data); | 243 expect(resultingData.data, expectedData.data); |
231 }); | 244 }); |
232 | 245 |
233 test('putImageData throws with wrong number of arguments', () { | 246 test('putImageData throws with wrong number of arguments', () { |
234 ImageData expectedData = context.getImageData(0, 0, 10, 10); | 247 ImageData expectedData = context.getImageData(0.0, 0.0, 10.0, 10.0); |
235 | 248 |
236 // TODO(antonm): in Dartium ArgumentError should be thrown too. | 249 // TODO(antonm): in Dartium ArgumentError should be thrown too. |
237 expect(() => context.putImageData(expectedData, 0, 0, 1), | 250 expect(() => context.putImageData(expectedData, 0.0, 0.0, 1.0), |
238 throws); | 251 throws); |
239 expect(() => context.putImageData(expectedData, 0, 0, 1, 1), | 252 expect(() => context.putImageData(expectedData, 0.0, 0.0, 1.0, 1.0), |
240 throws); | 253 throws); |
241 expect(() => context.putImageData(expectedData, 0, 0, 1, 1, 5), | 254 expect(() => context.putImageData(expectedData, 0.0, 0.0, 1.0, 1.0, 5.0), |
242 throws); | 255 throws); |
243 }); | 256 }); |
244 }); | 257 }); |
245 | 258 |
246 group('arc', () { | 259 group('arc', () { |
247 setUp(setupFunc); | 260 setUp(setupFunc); |
248 tearDown(tearDownFunc); | 261 tearDown(tearDownFunc); |
249 | 262 |
250 test('default arc should be clockwise', () { | 263 test('default arc should be clockwise', () { |
251 context.beginPath(); | 264 context.beginPath(); |
252 final r = 10; | 265 final r = 10.0; |
253 | 266 |
254 // Center of arc. | 267 // Center of arc. |
255 final cx = 20; | 268 final cx = 20.0; |
256 final cy = 20; | 269 final cy = 20.0; |
257 // Arc centered at (20, 20) with radius 10 will go clockwise | 270 // Arc centered at (20, 20) with radius 10 will go clockwise |
258 // from (20 + r, 20) to (20, 20 + r), which is 1/4 of a circle. | 271 // from (20 + r, 20) to (20, 20 + r), which is 1/4 of a circle. |
259 context.arc(cx, cy, r, 0, PI/2); | 272 context.arc(cx, cy, r, 0.0, PI/2); |
260 | 273 |
261 context.strokeStyle = 'green'; | 274 context.strokeStyle = 'green'; |
262 context.lineWidth = 2; | 275 context.lineWidth = 2.0; |
263 context.stroke(); | 276 context.stroke(); |
264 | 277 |
265 // Center should not be filled. | 278 // Center should not be filled. |
266 expectPixelUnfilled(cx, cy); | 279 expectPixelUnfilled(cx, cy); |
267 | 280 |
268 // (cx + r, cy) should be filled. | 281 // (cx + r, cy) should be filled. |
269 expectPixelFilled(cx + r, cy, true); | 282 expectPixelFilled(cx + r, cy, true); |
270 // (cx, cy + r) should be filled. | 283 // (cx, cy + r) should be filled. |
271 expectPixelFilled(cx, cy + r, true); | 284 expectPixelFilled(cx, cy + r, true); |
272 // (cx - r, cy) should be empty. | 285 // (cx - r, cy) should be empty. |
273 expectPixelFilled(cx - r, cy, false); | 286 expectPixelFilled(cx - r, cy, false); |
274 // (cx, cy - r) should be empty. | 287 // (cx, cy - r) should be empty. |
275 expectPixelFilled(cx, cy - r, false); | 288 expectPixelFilled(cx, cy - r, false); |
276 | 289 |
277 // (cx + r/SQRT2, cy + r/SQRT2) should be filled. | 290 // (cx + r/SQRT2, cy + r/SQRT2) should be filled. |
278 expectPixelFilled((cx + r/SQRT2).toInt(), (cy + r/SQRT2).toInt(), true); | 291 expectPixelFilled((cx + r/SQRT2).toInt(), (cy + r/SQRT2).toInt(), true); |
279 | 292 |
280 // (cx - r/SQRT2, cy - r/SQRT2) should be empty. | 293 // (cx - r/SQRT2, cy - r/SQRT2) should be empty. |
281 expectPixelFilled((cx - r/SQRT2).toInt(), (cy + r/SQRT2).toInt(), false); | 294 expectPixelFilled((cx - r/SQRT2).toInt(), (cy + r/SQRT2).toInt(), false); |
282 | 295 |
283 // (cx + r/SQRT2, cy + r/SQRT2) should be empty. | 296 // (cx + r/SQRT2, cy + r/SQRT2) should be empty. |
284 expectPixelFilled((cx - r/SQRT2).toInt(), (cy - r/SQRT2).toInt(), false); | 297 expectPixelFilled((cx - r/SQRT2).toInt(), (cy - r/SQRT2).toInt(), false); |
285 | 298 |
286 // (cx - r/SQRT2, cy - r/SQRT2) should be empty. | 299 // (cx - r/SQRT2, cy - r/SQRT2) should be empty. |
287 expectPixelFilled((cx + r/SQRT2).toInt(), (cy - r/SQRT2).toInt(), false); | 300 expectPixelFilled((cx + r/SQRT2).toInt(), (cy - r/SQRT2).toInt(), false); |
288 }); | 301 }); |
289 | 302 |
290 test('arc anticlockwise', () { | 303 test('arc anticlockwise', () { |
291 context.beginPath(); | 304 context.beginPath(); |
292 final r = 10; | 305 final r = 10.0; |
293 | 306 |
294 // Center of arc. | 307 // Center of arc. |
295 final cx = 20; | 308 final cx = 20.0; |
296 final cy = 20; | 309 final cy = 20.0; |
297 // Arc centered at (20, 20) with radius 10 will go anticlockwise | 310 // Arc centered at (20, 20) with radius 10 will go anticlockwise |
298 // from (20 + r, 20) to (20, 20 + r), which is 3/4 of a circle. | 311 // from (20 + r, 20) to (20, 20 + r), which is 3/4 of a circle. |
299 // Because of the way arc work, when going anti-clockwise, the end points | 312 // Because of the way arc work, when going anti-clockwise, the end points |
300 // are not included, so small values are added to radius to make a little | 313 // are not included, so small values are added to radius to make a little |
301 // more than a 3/4 circle. | 314 // more than a 3/4 circle. |
302 context.arc(cx, cy, r, .1, PI/2 - .1, true); | 315 context.arc(cx, cy, r, .1, PI/2 - .1, true); |
303 | 316 |
304 context.strokeStyle = 'green'; | 317 context.strokeStyle = 'green'; |
305 context.lineWidth = 2; | 318 context.lineWidth = 2.0; |
306 context.stroke(); | 319 context.stroke(); |
307 | 320 |
308 // Center should not be filled. | 321 // Center should not be filled. |
309 expectPixelUnfilled(cx, cy); | 322 expectPixelUnfilled(cx, cy); |
310 | 323 |
311 // (cx + r, cy) should be filled. | 324 // (cx + r, cy) should be filled. |
312 expectPixelFilled(cx + r, cy, true); | 325 expectPixelFilled(cx + r, cy, true); |
313 // (cx, cy + r) should be filled. | 326 // (cx, cy + r) should be filled. |
314 expectPixelFilled(cx, cy + r, true); | 327 expectPixelFilled(cx, cy + r, true); |
315 // (cx - r, cy) should be filled. | 328 // (cx - r, cy) should be filled. |
(...skipping 17 matching lines...) Expand all Loading... |
333 | 346 |
334 group('drawImage_image_element', () { | 347 group('drawImage_image_element', () { |
335 setUp(setupFunc); | 348 setUp(setupFunc); |
336 tearDown(tearDownFunc); | 349 tearDown(tearDownFunc); |
337 // Draw an image to the canvas from an image element. | 350 // Draw an image to the canvas from an image element. |
338 test('with 3 params', () { | 351 test('with 3 params', () { |
339 var dataUrl = otherCanvas.toDataUrl('image/gif'); | 352 var dataUrl = otherCanvas.toDataUrl('image/gif'); |
340 var img = new ImageElement(); | 353 var img = new ImageElement(); |
341 | 354 |
342 img.onLoad.listen(expectAsync1((_) { | 355 img.onLoad.listen(expectAsync1((_) { |
343 context.drawImage(img, 50, 50); | 356 context.drawImage(img, 50.0, 50.0); |
344 | 357 |
345 expectPixelFilled(50, 50); | 358 expectPixelFilled(50, 50); |
346 expectPixelFilled(55, 55); | 359 expectPixelFilled(55, 55); |
347 expectPixelFilled(59, 59); | 360 expectPixelFilled(59, 59); |
348 expectPixelUnfilled(60, 60); | 361 expectPixelUnfilled(60, 60); |
349 expectPixelUnfilled(0, 0); | 362 expectPixelUnfilled(0, 0); |
350 expectPixelUnfilled(70, 70); | 363 expectPixelUnfilled(70, 70); |
351 })); | 364 })); |
352 img.onError.listen((_) { | 365 img.onError.listen((_) { |
353 guardAsync(() { | 366 guardAsync(() { |
(...skipping 24 matching lines...) Expand all Loading... |
378 guardAsync(() { | 391 guardAsync(() { |
379 fail('URL failed to load.'); | 392 fail('URL failed to load.'); |
380 }); | 393 }); |
381 }); | 394 }); |
382 img.src = dataUrl; | 395 img.src = dataUrl; |
383 }); | 396 }); |
384 | 397 |
385 // Draw an image to the canvas from an image element and scale it. | 398 // Draw an image to the canvas from an image element and scale it. |
386 test('with 9 params', () { | 399 test('with 9 params', () { |
387 otherContext.fillStyle = "blue"; | 400 otherContext.fillStyle = "blue"; |
388 otherContext.fillRect(5, 5, 5, 5); | 401 otherContext.fillRect(5.0, 5.0, 5.0, 5.0); |
389 var dataUrl = otherCanvas.toDataUrl('image/gif'); | 402 var dataUrl = otherCanvas.toDataUrl('image/gif'); |
390 var img = new ImageElement(); | 403 var img = new ImageElement(); |
391 | 404 |
392 img.onLoad.listen(expectAsync1((_) { | 405 img.onLoad.listen(expectAsync1((_) { |
393 // This will take a 6x6 square from the first canvas from position 2,2 | 406 // This will take a 6x6 square from the first canvas from position 2,2 |
394 // and then scale it to a 20x20 square and place it to the second | 407 // and then scale it to a 20x20 square and place it to the second |
395 // canvas at 50,50. | 408 // canvas at 50,50. |
396 context.drawImageToRect(img, new Rect(50, 50, 20, 20), | 409 context.drawImageToRect(img, new Rect(50, 50, 20, 20), |
397 sourceRect: new Rect(2, 2, 6, 6)); | 410 sourceRect: new Rect(2, 2, 6, 6)); |
398 | 411 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 'W5khoVWX1ZQOIOBASPjg4QCYloA4AEAAAAAAAASsIEIuoEIVLCBCFS6gQhUsoEDH0O2d' | 489 'W5khoVWX1ZQOIOBASPjg4QCYloA4AEAAAAAAAASsIEIuoEIVLCBCFS6gQhUsoEDH0O2d' |
477 'QEAAAAAAABZ54EAo72BAACA8AIAnQEqCAAIAABHCIWFiIWEiAICAnWqA/gD+gINTRgA/' | 490 'QEAAAAAAABZ54EAo72BAACA8AIAnQEqCAAIAABHCIWFiIWEiAICAnWqA/gD+gINTRgA/' |
478 'v0hRf/kb+PnRv/I4//8WE8DijI//FRAo5WBACgAsQEAARAQABgAGFgv9AAIAAAcU7trA' | 491 'v0hRf/kb+PnRv/I4//8WE8DijI//FRAo5WBACgAsQEAARAQABgAGFgv9AAIAAAcU7trA' |
479 'QAAAAAAAA67jLOBALeH94EB8YIBfw=='; | 492 'QAAAAAAAA67jLOBALeH94EB8YIBfw=='; |
480 group('drawImage_video_element', () { | 493 group('drawImage_video_element', () { |
481 setUp(setupFunc); | 494 setUp(setupFunc); |
482 tearDown(tearDownFunc); | 495 tearDown(tearDownFunc); |
483 | 496 |
484 test('with 3 params', () { | 497 test('with 3 params', () { |
485 video.onCanPlay.listen(expectAsync1((_) { | 498 video.onCanPlay.listen(expectAsync1((_) { |
486 context.drawImage(video, 50, 50); | 499 context.drawImage(video, 50.0, 50.0); |
487 | 500 |
488 expectPixelFilled(50, 50); | 501 expectPixelFilled(50, 50); |
489 expectPixelFilled(54, 54); | 502 expectPixelFilled(54, 54); |
490 expectPixelFilled(57, 57); | 503 expectPixelFilled(57, 57); |
491 expectPixelUnfilled(58, 58); | 504 expectPixelUnfilled(58, 58); |
492 expectPixelUnfilled(0, 0); | 505 expectPixelUnfilled(0, 0); |
493 expectPixelUnfilled(70, 70); | 506 expectPixelUnfilled(70, 70); |
494 })); | 507 })); |
495 | 508 |
496 video.onError.listen((_) { | 509 video.onError.listen((_) { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 } | 621 } |
609 }); | 622 }); |
610 }); | 623 }); |
611 | 624 |
612 group('drawImage_canvas_element', () { | 625 group('drawImage_canvas_element', () { |
613 setUp(setupFunc); | 626 setUp(setupFunc); |
614 tearDown(tearDownFunc); | 627 tearDown(tearDownFunc); |
615 | 628 |
616 test('with 3 params', () { | 629 test('with 3 params', () { |
617 // Draw an image to the canvas from a canvas element. | 630 // Draw an image to the canvas from a canvas element. |
618 context.drawImage(otherCanvas, 50, 50); | 631 context.drawImage(otherCanvas, 50.0, 50.0); |
619 | 632 |
620 expectPixelFilled(50, 50); | 633 expectPixelFilled(50, 50); |
621 expectPixelFilled(55, 55); | 634 expectPixelFilled(55, 55); |
622 expectPixelFilled(59, 59); | 635 expectPixelFilled(59, 59); |
623 expectPixelUnfilled(60, 60); | 636 expectPixelUnfilled(60, 60); |
624 expectPixelUnfilled(0, 0); | 637 expectPixelUnfilled(0, 0); |
625 expectPixelUnfilled(70, 70); | 638 expectPixelUnfilled(70, 70); |
626 }); | 639 }); |
627 test('with 5 params', () { | 640 test('with 5 params', () { |
628 // Draw an image to the canvas from a canvas element. | 641 // Draw an image to the canvas from a canvas element. |
629 context.drawImageToRect(otherCanvas, new Rect(50, 50, 20, 20)); | 642 context.drawImageToRect(otherCanvas, new Rect(50, 50, 20, 20)); |
630 | 643 |
631 expectPixelFilled(50, 50); | 644 expectPixelFilled(50, 50); |
632 expectPixelFilled(55, 55); | 645 expectPixelFilled(55, 55); |
633 expectPixelFilled(59, 59); | 646 expectPixelFilled(59, 59); |
634 expectPixelFilled(60, 60); | 647 expectPixelFilled(60, 60); |
635 expectPixelFilled(69, 69); | 648 expectPixelFilled(69, 69); |
636 expectPixelUnfilled(70, 70); | 649 expectPixelUnfilled(70, 70); |
637 expectPixelUnfilled(0, 0); | 650 expectPixelUnfilled(0, 0); |
638 expectPixelUnfilled(80, 80); | 651 expectPixelUnfilled(80, 80); |
639 }); | 652 }); |
640 test('with 9 params', () { | 653 test('with 9 params', () { |
641 // Draw an image to the canvas from a canvas element. | 654 // Draw an image to the canvas from a canvas element. |
642 otherContext.fillStyle = "blue"; | 655 otherContext.fillStyle = "blue"; |
643 otherContext.fillRect(5, 5, 5, 5); | 656 otherContext.fillRect(5.0, 5.0, 5.0, 5.0); |
644 context.drawImageToRect(otherCanvas, new Rect(50, 50, 20, 20), | 657 context.drawImageToRect(otherCanvas, new Rect(50, 50, 20, 20), |
645 sourceRect: new Rect(2, 2, 6, 6)); | 658 sourceRect: new Rect(2, 2, 6, 6)); |
646 | 659 |
647 checkPixel(readPixel(50, 50), [255, 0, 0, 255]); | 660 checkPixel(readPixel(50, 50), [255, 0, 0, 255]); |
648 checkPixel(readPixel(55, 55), [255, 0, 0, 255]); | 661 checkPixel(readPixel(55, 55), [255, 0, 0, 255]); |
649 checkPixel(readPixel(60, 50), [255, 0, 0, 255]); | 662 checkPixel(readPixel(60, 50), [255, 0, 0, 255]); |
650 checkPixel(readPixel(65, 65), [0, 0, 255, 255]); | 663 checkPixel(readPixel(65, 65), [0, 0, 255, 255]); |
651 checkPixel(readPixel(69, 69), [0, 0, 255, 255]); | 664 checkPixel(readPixel(69, 69), [0, 0, 255, 255]); |
652 expectPixelFilled(50, 50); | 665 expectPixelFilled(50, 50); |
653 expectPixelFilled(55, 55); | 666 expectPixelFilled(55, 55); |
654 expectPixelFilled(59, 59); | 667 expectPixelFilled(59, 59); |
655 expectPixelFilled(60, 60); | 668 expectPixelFilled(60, 60); |
656 expectPixelFilled(69, 69); | 669 expectPixelFilled(69, 69); |
657 expectPixelUnfilled(70, 70); | 670 expectPixelUnfilled(70, 70); |
658 expectPixelUnfilled(0, 0); | 671 expectPixelUnfilled(0, 0); |
659 expectPixelUnfilled(80, 80); | 672 expectPixelUnfilled(80, 80); |
660 }); | 673 }); |
661 | 674 |
662 test('createImageData', () { | 675 test('createImageData', () { |
663 var imageData = context.createImageData(15, 15); | 676 var imageData = context.createImageData(15.0, 15.0); |
664 expect(imageData.width, 15); | 677 expect(imageData.width, 15); |
665 expect(imageData.height, 15); | 678 expect(imageData.height, 15); |
666 | 679 |
667 var other = context.createImageDataFromImageData(imageData); | 680 var other = context.createImageDataFromImageData(imageData); |
668 expect(other.width, 15); | 681 expect(other.width, 15); |
669 expect(other.height, 15); | 682 expect(other.height, 15); |
670 }); | 683 }); |
671 }); | 684 }); |
672 } | 685 } |
OLD | NEW |