OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ppapi/tests/test_graphics_2d.h" | 5 #include "ppapi/tests/test_graphics_2d.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "ppapi/c/dev/ppb_testing_dev.h" | 9 #include "ppapi/c/dev/ppb_testing_dev.h" |
10 #include "ppapi/c/pp_errors.h" | 10 #include "ppapi/c/pp_errors.h" |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 // ReadImageData. | 226 // ReadImageData. |
227 if (testing_interface_->ReadImageData(image.pp_resource(), | 227 if (testing_interface_->ReadImageData(image.pp_resource(), |
228 image.pp_resource(), | 228 image.pp_resource(), |
229 &zero_zero)) | 229 &zero_zero)) |
230 return "ReadImageData succeeded with a different resource"; | 230 return "ReadImageData succeeded with a different resource"; |
231 if (testing_interface_->ReadImageData(null_context.pp_resource(), | 231 if (testing_interface_->ReadImageData(null_context.pp_resource(), |
232 image.pp_resource(), | 232 image.pp_resource(), |
233 &zero_zero)) | 233 &zero_zero)) |
234 return "ReadImageData succeeded with a NULL resource"; | 234 return "ReadImageData succeeded with a NULL resource"; |
235 | 235 |
236 return ""; | 236 PASS(); |
237 } | 237 } |
238 | 238 |
239 std::string TestGraphics2D::TestInvalidSize() { | 239 std::string TestGraphics2D::TestInvalidSize() { |
240 pp::Graphics2D a(pp::Size(16, 0), false); | 240 pp::Graphics2D a(pp::Size(16, 0), false); |
241 if (!a.is_null()) | 241 if (!a.is_null()) |
242 return "0 height accepted"; | 242 return "0 height accepted"; |
243 | 243 |
244 pp::Graphics2D b(pp::Size(0, 16), false); | 244 pp::Graphics2D b(pp::Size(0, 16), false); |
245 if (!b.is_null()) | 245 if (!b.is_null()) |
246 return "0 width accepted"; | 246 return "0 width accepted"; |
247 | 247 |
248 // Need to use the C API since pp::Size prevents negative sizes. | 248 // Need to use the C API since pp::Size prevents negative sizes. |
249 PP_Size size; | 249 PP_Size size; |
250 size.width = 16; | 250 size.width = 16; |
251 size.height = -16; | 251 size.height = -16; |
252 ASSERT_FALSE(!!graphics_2d_interface_->Create( | 252 ASSERT_FALSE(!!graphics_2d_interface_->Create( |
253 pp::Module::Get()->pp_module(), &size, PP_FALSE)); | 253 pp::Module::Get()->pp_module(), &size, PP_FALSE)); |
254 | 254 |
255 size.width = -16; | 255 size.width = -16; |
256 size.height = 16; | 256 size.height = 16; |
257 ASSERT_FALSE(!!graphics_2d_interface_->Create( | 257 ASSERT_FALSE(!!graphics_2d_interface_->Create( |
258 pp::Module::Get()->pp_module(), &size, PP_FALSE)); | 258 pp::Module::Get()->pp_module(), &size, PP_FALSE)); |
259 | 259 |
260 return ""; | 260 PASS(); |
261 } | 261 } |
262 | 262 |
263 std::string TestGraphics2D::TestHumongous() { | 263 std::string TestGraphics2D::TestHumongous() { |
264 pp::Graphics2D a(pp::Size(100000, 100000), false); | 264 pp::Graphics2D a(pp::Size(100000, 100000), false); |
265 if (!a.is_null()) | 265 if (!a.is_null()) |
266 return "Humongous device created"; | 266 return "Humongous device created"; |
267 return ""; | 267 PASS(); |
268 } | 268 } |
269 | 269 |
270 std::string TestGraphics2D::TestInitToZero() { | 270 std::string TestGraphics2D::TestInitToZero() { |
271 const int w = 15, h = 17; | 271 const int w = 15, h = 17; |
272 pp::Graphics2D dc(pp::Size(w, h), false); | 272 pp::Graphics2D dc(pp::Size(w, h), false); |
273 if (dc.is_null()) | 273 if (dc.is_null()) |
274 return "Failure creating a boring device"; | 274 return "Failure creating a boring device"; |
275 | 275 |
276 // Make an image with nonzero data in it (so we can test that zeros were | 276 // Make an image with nonzero data in it (so we can test that zeros were |
277 // actually read versus ReadImageData being a NOP). | 277 // actually read versus ReadImageData being a NOP). |
278 pp::ImageData image(PP_IMAGEDATAFORMAT_BGRA_PREMUL, pp::Size(w, h), true); | 278 pp::ImageData image(PP_IMAGEDATAFORMAT_BGRA_PREMUL, pp::Size(w, h), true); |
279 if (image.is_null()) | 279 if (image.is_null()) |
280 return "Failure to allocate an image"; | 280 return "Failure to allocate an image"; |
281 memset(image.data(), 0xFF, image.stride() * image.size().height() * 4); | 281 memset(image.data(), 0xFF, image.stride() * image.size().height() * 4); |
282 | 282 |
283 // Read out the initial data from the device & check. | 283 // Read out the initial data from the device & check. |
284 if (!ReadImageData(dc, &image, pp::Point(0, 0))) | 284 if (!ReadImageData(dc, &image, pp::Point(0, 0))) |
285 return "Couldn't read image data"; | 285 return "Couldn't read image data"; |
286 if (!IsSquareInImage(image, 0, pp::Rect(0, 0, w, h), 0)) | 286 if (!IsSquareInImage(image, 0, pp::Rect(0, 0, w, h), 0)) |
287 return "Got a nonzero pixel"; | 287 return "Got a nonzero pixel"; |
288 | 288 |
289 return ""; | 289 PASS(); |
290 } | 290 } |
291 | 291 |
292 std::string TestGraphics2D::TestDescribe() { | 292 std::string TestGraphics2D::TestDescribe() { |
293 const int w = 15, h = 17; | 293 const int w = 15, h = 17; |
294 pp::Graphics2D dc(pp::Size(w, h), false); | 294 pp::Graphics2D dc(pp::Size(w, h), false); |
295 if (dc.is_null()) | 295 if (dc.is_null()) |
296 return "Failure creating a boring device"; | 296 return "Failure creating a boring device"; |
297 | 297 |
298 PP_Size size; | 298 PP_Size size; |
299 size.width = -1; | 299 size.width = -1; |
300 size.height = -1; | 300 size.height = -1; |
301 PP_Bool is_always_opaque = PP_TRUE; | 301 PP_Bool is_always_opaque = PP_TRUE; |
302 if (!graphics_2d_interface_->Describe(dc.pp_resource(), &size, | 302 if (!graphics_2d_interface_->Describe(dc.pp_resource(), &size, |
303 &is_always_opaque)) | 303 &is_always_opaque)) |
304 return "Describe failed"; | 304 return "Describe failed"; |
305 if (size.width != w || size.height != h || is_always_opaque != PP_FALSE) | 305 if (size.width != w || size.height != h || is_always_opaque != PP_FALSE) |
306 return "Mismatch of data."; | 306 return "Mismatch of data."; |
307 | 307 |
308 return ""; | 308 PASS(); |
309 } | 309 } |
310 | 310 |
311 std::string TestGraphics2D::TestPaint() { | 311 std::string TestGraphics2D::TestPaint() { |
312 const int w = 15, h = 17; | 312 const int w = 15, h = 17; |
313 pp::Graphics2D dc(pp::Size(w, h), false); | 313 pp::Graphics2D dc(pp::Size(w, h), false); |
314 if (dc.is_null()) | 314 if (dc.is_null()) |
315 return "Failure creating a boring device"; | 315 return "Failure creating a boring device"; |
316 | 316 |
317 // Make sure the device background is 0. | 317 // Make sure the device background is 0. |
318 if (!IsDCUniformColor(dc, 0)) | 318 if (!IsDCUniformColor(dc, 0)) |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 const int subset_x = 2, subset_y = 1; | 376 const int subset_x = 2, subset_y = 1; |
377 *subset.GetAddr32(pp::Point(subset_x, subset_y)) = subset_color; | 377 *subset.GetAddr32(pp::Point(subset_x, subset_y)) = subset_color; |
378 dc.PaintImageData(subset, pp::Point(-subset_x, -subset_y), | 378 dc.PaintImageData(subset, pp::Point(-subset_x, -subset_y), |
379 pp::Rect(subset_x, subset_y, 1, 1)); | 379 pp::Rect(subset_x, subset_y, 1, 1)); |
380 if (!FlushAndWaitForDone(&dc)) | 380 if (!FlushAndWaitForDone(&dc)) |
381 return "Couldn't flush repaint"; | 381 return "Couldn't flush repaint"; |
382 if (!IsSquareInDC(dc, background_color, pp::Rect(0, 0, 1, 1), | 382 if (!IsSquareInDC(dc, background_color, pp::Rect(0, 0, 1, 1), |
383 subset_color)) | 383 subset_color)) |
384 return "Subset paint failed."; | 384 return "Subset paint failed."; |
385 | 385 |
386 return ""; | 386 PASS(); |
387 } | 387 } |
388 | 388 |
389 std::string TestGraphics2D::TestScroll() { | 389 std::string TestGraphics2D::TestScroll() { |
390 const int w = 115, h = 117; | 390 const int w = 115, h = 117; |
391 pp::Graphics2D dc(pp::Size(w, h), false); | 391 pp::Graphics2D dc(pp::Size(w, h), false); |
392 if (dc.is_null()) | 392 if (dc.is_null()) |
393 return "Failure creating a boring device."; | 393 return "Failure creating a boring device."; |
394 | 394 |
395 // Make sure the device background is 0. | 395 // Make sure the device background is 0. |
396 if (!IsDCUniformColor(dc, 0)) | 396 if (!IsDCUniformColor(dc, 0)) |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 | 438 |
439 image_x += dx; | 439 image_x += dx; |
440 image_y += dy; | 440 image_y += dy; |
441 | 441 |
442 if (!ReadImageData(dc, &readback, pp::Point(image_x, image_y))) | 442 if (!ReadImageData(dc, &readback, pp::Point(image_x, image_y))) |
443 return "TC2, Couldn't read back image data."; | 443 return "TC2, Couldn't read back image data."; |
444 | 444 |
445 if (!CompareImages(test_image, readback)) | 445 if (!CompareImages(test_image, readback)) |
446 return "TC2, Read back image is not the same as test image."; | 446 return "TC2, Read back image is not the same as test image."; |
447 | 447 |
448 return ""; | 448 PASS(); |
449 } | 449 } |
450 | 450 |
451 std::string TestGraphics2D::TestReplace() { | 451 std::string TestGraphics2D::TestReplace() { |
452 const int w = 15, h = 17; | 452 const int w = 15, h = 17; |
453 pp::Graphics2D dc(pp::Size(w, h), false); | 453 pp::Graphics2D dc(pp::Size(w, h), false); |
454 if (dc.is_null()) | 454 if (dc.is_null()) |
455 return "Failure creating a boring device"; | 455 return "Failure creating a boring device"; |
456 | 456 |
457 // Replacing with a different size image should fail. | 457 // Replacing with a different size image should fail. |
458 pp::ImageData weird_size(PP_IMAGEDATAFORMAT_BGRA_PREMUL, | 458 pp::ImageData weird_size(PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 dc.PaintImageData(swapped, pp::Point(0, 0)); | 491 dc.PaintImageData(swapped, pp::Point(0, 0)); |
492 | 492 |
493 // Flush and make sure the result is correct. | 493 // Flush and make sure the result is correct. |
494 if (!FlushAndWaitForDone(&dc)) | 494 if (!FlushAndWaitForDone(&dc)) |
495 return "Couldn't flush"; | 495 return "Couldn't flush"; |
496 | 496 |
497 // The background should be green from the swapped image. | 497 // The background should be green from the swapped image. |
498 if (!IsDCUniformColor(dc, swapped_color)) | 498 if (!IsDCUniformColor(dc, swapped_color)) |
499 return "Flushed color incorrect (or failure in readback)."; | 499 return "Flushed color incorrect (or failure in readback)."; |
500 | 500 |
501 return ""; | 501 PASS(); |
502 } | 502 } |
503 | 503 |
504 std::string TestGraphics2D::TestFlush() { | 504 std::string TestGraphics2D::TestFlush() { |
505 // Tests that synchronous flushes (NULL callback) fail on the main thread | 505 // Tests that synchronous flushes (NULL callback) fail on the main thread |
506 // (which is the current one). | 506 // (which is the current one). |
507 const int w = 15, h = 17; | 507 const int w = 15, h = 17; |
508 pp::Graphics2D dc(pp::Size(w, h), false); | 508 pp::Graphics2D dc(pp::Size(w, h), false); |
509 if (dc.is_null()) | 509 if (dc.is_null()) |
510 return "Failure creating a boring device"; | 510 return "Failure creating a boring device"; |
511 | 511 |
(...skipping 21 matching lines...) Expand all Loading... |
533 if (rv != PP_OK && rv != PP_ERROR_WOULDBLOCK) | 533 if (rv != PP_OK && rv != PP_ERROR_WOULDBLOCK) |
534 return "Couldn't flush first time for multiple flush test."; | 534 return "Couldn't flush first time for multiple flush test."; |
535 | 535 |
536 if (rv != PP_OK) { | 536 if (rv != PP_OK) { |
537 // If the first flush would block, then a second should fail. | 537 // If the first flush would block, then a second should fail. |
538 rv = dc_nopaints.Flush(pp::CompletionCallback(&FlushCallbackNOP, NULL)); | 538 rv = dc_nopaints.Flush(pp::CompletionCallback(&FlushCallbackNOP, NULL)); |
539 if (rv == PP_OK || rv == PP_ERROR_WOULDBLOCK) | 539 if (rv == PP_OK || rv == PP_ERROR_WOULDBLOCK) |
540 return "Second flush succeeded before callback ran."; | 540 return "Second flush succeeded before callback ran."; |
541 } | 541 } |
542 | 542 |
543 return ""; | 543 PASS(); |
544 } | 544 } |
OLD | NEW |