OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <stdlib.h> | 7 #include <stdlib.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include "ppapi/c/dev/ppb_testing_dev.h" | 10 #include "ppapi/c/dev/ppb_testing_dev.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 InitTestingInterface(); | 41 InitTestingInterface(); |
42 } | 42 } |
43 | 43 |
44 void TestGraphics2D::RunTest() { | 44 void TestGraphics2D::RunTest() { |
45 RUN_TEST(InvalidResource); | 45 RUN_TEST(InvalidResource); |
46 RUN_TEST(InvalidSize); | 46 RUN_TEST(InvalidSize); |
47 RUN_TEST(Humongous); | 47 RUN_TEST(Humongous); |
48 RUN_TEST(InitToZero); | 48 RUN_TEST(InitToZero); |
49 RUN_TEST(Describe); | 49 RUN_TEST(Describe); |
50 RUN_TEST_FORCEASYNC_AND_NOT(Paint); | 50 RUN_TEST_FORCEASYNC_AND_NOT(Paint); |
51 // RUN_TEST_FORCEASYNC_AND_NOT(Scroll); // TODO(brettw) implement. | 51 RUN_TEST_FORCEASYNC_AND_NOT(Scroll); |
52 RUN_TEST_FORCEASYNC_AND_NOT(Replace); | 52 RUN_TEST_FORCEASYNC_AND_NOT(Replace); |
53 RUN_TEST_FORCEASYNC_AND_NOT(Flush); | 53 RUN_TEST_FORCEASYNC_AND_NOT(Flush); |
54 } | 54 } |
55 | 55 |
56 void TestGraphics2D::QuitMessageLoop() { | 56 void TestGraphics2D::QuitMessageLoop() { |
57 testing_interface_->QuitMessageLoop(instance_->pp_instance()); | 57 testing_interface_->QuitMessageLoop(instance_->pp_instance()); |
58 } | 58 } |
59 | 59 |
60 bool TestGraphics2D::ReadImageData(const pp::Graphics2D& dc, | 60 bool TestGraphics2D::ReadImageData(const pp::Graphics2D& dc, |
61 pp::ImageData* image, | 61 pp::ImageData* image, |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 return "Subset paint failed."; | 383 return "Subset paint failed."; |
384 | 384 |
385 PASS(); | 385 PASS(); |
386 } | 386 } |
387 | 387 |
388 std::string TestGraphics2D::TestScroll() { | 388 std::string TestGraphics2D::TestScroll() { |
389 const int w = 115, h = 117; | 389 const int w = 115, h = 117; |
390 pp::Graphics2D dc(instance_, pp::Size(w, h), false); | 390 pp::Graphics2D dc(instance_, pp::Size(w, h), false); |
391 if (dc.is_null()) | 391 if (dc.is_null()) |
392 return "Failure creating a boring device."; | 392 return "Failure creating a boring device."; |
| 393 if (!instance_->BindGraphics(dc)) |
| 394 return "Failure to bind the boring device."; |
393 | 395 |
394 // Make sure the device background is 0. | 396 // Make sure the device background is 0. |
395 if (!IsDCUniformColor(dc, 0)) | 397 if (!IsDCUniformColor(dc, 0)) |
396 return "Bad initial color."; | 398 return "Bad initial color."; |
397 | 399 |
398 const int image_w = 15, image_h = 23; | 400 const int image_width = 15, image_height = 23; |
399 pp::ImageData test_image(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, | 401 pp::ImageData test_image(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
400 pp::Size(image_w, image_h), false); | 402 pp::Size(image_width, image_height), false); |
401 FillImageWithGradient(&test_image); | 403 FillImageWithGradient(&test_image); |
| 404 pp::ImageData no_image(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
| 405 pp::Size(image_width, image_height), false); |
| 406 FillRectInImage(&no_image, pp::Rect(0, 0, image_width, image_height), 0); |
| 407 pp::ImageData readback_image(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
| 408 pp::Size(image_width, image_height), false); |
| 409 pp::ImageData readback_scroll(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
| 410 pp::Size(image_width, image_height), false); |
| 411 |
| 412 if (test_image.size() != pp::Size(image_width, image_height)) |
| 413 return "Wrong test image size\n"; |
402 | 414 |
403 int image_x = 51, image_y = 72; | 415 int image_x = 51, image_y = 72; |
404 dc.PaintImageData(test_image, pp::Point(image_x, image_y)); | 416 dc.PaintImageData(test_image, pp::Point(image_x, image_y)); |
405 if (!FlushAndWaitForDone(&dc)) | 417 if (!FlushAndWaitForDone(&dc)) |
406 return "Couldn't flush to fill backing store."; | 418 return "Couldn't flush to fill backing store."; |
407 | 419 |
408 // TC1, Scroll image to a free space. | 420 // Test Case 1. Incorrect usage when scrolling image to a free space. |
| 421 // The clip area is *not* the area to shift around within the graphics device |
| 422 // by specified amount. It's the area to which the scroll is limited. So if |
| 423 // the clip area is the size of the image and the amount points to free space, |
| 424 // the scroll won't result in additional images. |
409 int dx = -40, dy = -48; | 425 int dx = -40, dy = -48; |
410 pp::Rect clip = pp::Rect(image_x, image_y, test_image.size().width(), | 426 int scroll_x = image_x + dx, scroll_y = image_y + dy; |
411 test_image.size().height()); | 427 pp::Rect clip(image_x, image_y, image_width, image_height); |
412 dc.Scroll(clip, pp::Point(dx, dy)); | 428 dc.Scroll(clip, pp::Point(dx, dy)); |
413 | |
414 if (!FlushAndWaitForDone(&dc)) | 429 if (!FlushAndWaitForDone(&dc)) |
415 return "TC1, Couldn't flush to scroll."; | 430 return "TC1, Couldn't flush to scroll."; |
| 431 if (!ReadImageData(dc, &readback_scroll, pp::Point(scroll_x, scroll_y))) |
| 432 return "TC1, Couldn't read back scrolled image data."; |
| 433 if (!CompareImages(no_image, readback_scroll)) |
| 434 return "TC1, Read back scrolled image is not the same as no image."; |
416 | 435 |
417 image_x += dx; | 436 // Test Case 2. |
418 image_y += dy; | 437 // The amount is intended to place the image in the free space outside |
| 438 // of the original, but the clip area extends beyond the graphics device area. |
| 439 // This scroll is invalid and will be a noop. |
| 440 scroll_x = 11, scroll_y = 24; |
| 441 clip = pp::Rect(0, 0, w, h + 1); |
| 442 dc.Scroll(clip, pp::Point(scroll_x - image_x, scroll_y - image_y)); |
| 443 if (!FlushAndWaitForDone(&dc)) |
| 444 return "TC2, Couldn't flush to scroll."; |
| 445 if (!ReadImageData(dc, &readback_scroll, pp::Point(scroll_x, scroll_y))) |
| 446 return "TC2, Couldn't read back scrolled image data."; |
| 447 if (!CompareImages(no_image, readback_scroll)) |
| 448 return "TC2, Read back scrolled image is not the same as no image."; |
419 | 449 |
420 pp::ImageData readback(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, | 450 // Test Case 3. |
421 pp::Size(image_w, image_h), false); | 451 // The amount is intended to place the image in the free space outside |
422 if (!ReadImageData(dc, &readback, pp::Point(image_x, image_y))) | 452 // of the original, but the clip area does not cover the image, |
423 return "TC1, Couldn't read back image data."; | 453 // so there is nothing to scroll. |
| 454 scroll_x = 11, scroll_y = 24; |
| 455 clip = pp::Rect(0, 0, image_x, image_y); |
| 456 dc.Scroll(clip, pp::Point(scroll_x - image_x, scroll_y - image_y)); |
| 457 if (!FlushAndWaitForDone(&dc)) |
| 458 return "TC3, Couldn't flush to scroll."; |
| 459 if (!ReadImageData(dc, &readback_scroll, pp::Point(scroll_x, scroll_y))) |
| 460 return "TC3, Couldn't read back scrolled image data."; |
| 461 if (!CompareImages(no_image, readback_scroll)) |
| 462 return "TC3, Read back scrolled image is not the same as no image."; |
424 | 463 |
425 if (!CompareImages(test_image, readback)) | 464 // Test Case 4. |
426 return "TC1, Read back image is not the same as test image."; | 465 // Same as TC3, but the clip covers part of the image. |
| 466 // This part will be scrolled to the intended origin. |
| 467 int part_w = image_width / 2, part_h = image_height / 2; |
| 468 clip = pp::Rect(0, 0, image_x + part_w, image_y + part_h); |
| 469 dc.Scroll(clip, pp::Point(scroll_x - image_x, scroll_y - image_y)); |
| 470 if (!FlushAndWaitForDone(&dc)) |
| 471 return "TC4, Couldn't flush to scroll."; |
| 472 if (!ReadImageData(dc, &readback_scroll, pp::Point(scroll_x, scroll_y))) |
| 473 return "TC4, Couldn't read back scrolled image data."; |
| 474 if (CompareImages(test_image, readback_scroll)) |
| 475 return "TC4, Read back scrolled image is the same as test image."; |
| 476 pp::Rect part_rect(part_w, part_h); |
| 477 if (!CompareImageRect(test_image, part_rect, readback_scroll, part_rect)) |
| 478 return "TC4, Read back scrolled image is not the same as part test image."; |
427 | 479 |
428 // TC2, Scroll image to an overlapping space. | 480 // Test Case 5 |
| 481 // Same as TC3, but the clip area covers the entire image. |
| 482 // It will be scrolled to the intended origin. |
| 483 clip = pp::Rect(0, 0, image_x + image_width, image_y + image_height); |
| 484 dc.Scroll(clip, pp::Point(scroll_x - image_x, scroll_y - image_y)); |
| 485 if (!FlushAndWaitForDone(&dc)) |
| 486 return "TC5, Couldn't flush to scroll."; |
| 487 if (!ReadImageData(dc, &readback_scroll, pp::Point(scroll_x, scroll_y))) |
| 488 return "TC5, Couldn't read back scrolled image data."; |
| 489 if (!CompareImages(test_image, readback_scroll)) |
| 490 return "TC5, Read back scrolled image is not the same as test image."; |
| 491 |
| 492 // Note that the undefined area left by the scroll does not actually get |
| 493 // cleared, so the original image is still there. This is not guaranteed and |
| 494 // is not something for users to rely on, but we can test for this here, so |
| 495 // we know when the underlying behavior changes. |
| 496 if (!ReadImageData(dc, &readback_image, pp::Point(image_x, image_y))) |
| 497 return "Couldn't read back original image data."; |
| 498 if (!CompareImages(test_image, readback_image)) |
| 499 return "Read back original image is not the same as test image."; |
| 500 |
| 501 // Test Case 6. |
| 502 // Scroll image to an overlapping space. The clip area is limited |
| 503 // to the image, so this will just modify its area. |
429 dx = 6; | 504 dx = 6; |
430 dy = 9; | 505 dy = 9; |
431 clip = pp::Rect(image_x, image_y, test_image.size().width(), | 506 scroll_x = image_x + dx; |
432 test_image.size().height()); | 507 scroll_y = image_y + dy; |
| 508 clip = pp::Rect(image_x, image_y, image_width, image_height); |
433 dc.Scroll(clip, pp::Point(dx, dy)); | 509 dc.Scroll(clip, pp::Point(dx, dy)); |
434 | |
435 if (!FlushAndWaitForDone(&dc)) | 510 if (!FlushAndWaitForDone(&dc)) |
436 return "TC2, Couldn't flush to scroll."; | 511 return "TC6, Couldn't flush to scroll."; |
437 | 512 if (!ReadImageData(dc, &readback_image, pp::Point(image_x, image_y))) |
438 image_x += dx; | 513 return "TC6, Couldn't read back image data."; |
439 image_y += dy; | 514 if (CompareImages(test_image, readback_image)) |
440 | 515 return "TC6, Read back image is still the same as test image."; |
441 if (!ReadImageData(dc, &readback, pp::Point(image_x, image_y))) | 516 pp::Rect scroll_rect(image_width - dx, image_height - dy); |
442 return "TC2, Couldn't read back image data."; | 517 if (!ReadImageData(dc, &readback_scroll, pp::Point(scroll_x, scroll_y))) |
443 | 518 return "TC6, Couldn't read back scrolled image data."; |
444 if (!CompareImages(test_image, readback)) | 519 if (!CompareImageRect(test_image, scroll_rect, readback_scroll, scroll_rect)) |
445 return "TC2, Read back image is not the same as test image."; | 520 return "TC6, Read back scrolled image is not the same as part test image."; |
446 | 521 |
447 PASS(); | 522 PASS(); |
448 } | 523 } |
449 | 524 |
450 std::string TestGraphics2D::TestReplace() { | 525 std::string TestGraphics2D::TestReplace() { |
451 const int w = 15, h = 17; | 526 const int w = 15, h = 17; |
452 pp::Graphics2D dc(instance_, pp::Size(w, h), false); | 527 pp::Graphics2D dc(instance_, pp::Size(w, h), false); |
453 if (dc.is_null()) | 528 if (dc.is_null()) |
454 return "Failure creating a boring device"; | 529 return "Failure creating a boring device"; |
455 | 530 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 if (rv != PP_OK_COMPLETIONPENDING) | 621 if (rv != PP_OK_COMPLETIONPENDING) |
547 return "Second flush must fail asynchronously."; | 622 return "Second flush must fail asynchronously."; |
548 } else { | 623 } else { |
549 if (rv == PP_OK || rv == PP_OK_COMPLETIONPENDING) | 624 if (rv == PP_OK || rv == PP_OK_COMPLETIONPENDING) |
550 return "Second flush succeeded before callback ran."; | 625 return "Second flush succeeded before callback ran."; |
551 } | 626 } |
552 } | 627 } |
553 | 628 |
554 PASS(); | 629 PASS(); |
555 } | 630 } |
OLD | NEW |