Chromium Code Reviews| 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_w = 15, image_h = 23; |
|
bbudge
2011/11/15 01:34:10
nit: x, y, width, height are the usual field names
polina
2011/11/15 01:43:12
Done.
| |
| 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_w, image_h), false); |
| 401 FillImageWithGradient(&test_image); | 403 FillImageWithGradient(&test_image); |
| 404 pp::ImageData no_image(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, | |
| 405 pp::Size(image_w, image_h), false); | |
| 406 FillRectInImage(&no_image, pp::Rect(0, 0, image_w, image_h), 0); | |
| 407 pp::ImageData readback_image(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, | |
| 408 pp::Size(image_w, image_h), false); | |
| 409 pp::ImageData readback_scroll(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, | |
| 410 pp::Size(image_w, image_h), false); | |
| 411 | |
| 412 if (test_image.size() != pp::Size(image_w, image_h)) | |
| 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 // TC1, Scroll image to a free space. Incorrect usage. |
|
bbudge
2011/11/15 01:34:10
TC1 -> Test Case #1
Even better would be a descrip
polina
2011/11/15 01:43:12
Done.
| |
| 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 to. So if | |
|
bbudge
2011/11/15 01:34:10
nit: remove the dangling 'to' - you don't need it.
polina
2011/11/15 01:43:12
Done.
| |
| 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_w, image_h); |
| 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 // TC2, The amount is intended to place the image in the free space outside |
| 418 image_y += dy; | 437 // of the original, but the clip area extends beyond the graphics device area. |
| 438 // This scroll is invalid and will be a noop. | |
| 439 scroll_x = 11, scroll_y = 24; | |
| 440 clip = pp::Rect(0, 0, w, h + 1); | |
| 441 dc.Scroll(clip, pp::Point(scroll_x - image_x, scroll_y - image_y)); | |
| 442 if (!FlushAndWaitForDone(&dc)) | |
| 443 return "TC2, Couldn't flush to scroll."; | |
| 444 if (!ReadImageData(dc, &readback_scroll, pp::Point(scroll_x, scroll_y))) | |
| 445 return "TC2, Couldn't read back scrolled image data."; | |
| 446 if (!CompareImages(no_image, readback_scroll)) | |
| 447 return "TC2, Read back scrolled image is not the same as no image."; | |
| 419 | 448 |
| 420 pp::ImageData readback(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, | 449 // TC3, The amount is intended to place the image in the free space outside |
| 421 pp::Size(image_w, image_h), false); | 450 // of the original, but the clip area does not cover the image, |
| 422 if (!ReadImageData(dc, &readback, pp::Point(image_x, image_y))) | 451 // so there is nothing to scroll. |
| 423 return "TC1, Couldn't read back image data."; | 452 scroll_x = 11, scroll_y = 24; |
| 453 clip = pp::Rect(0, 0, image_x, image_y); | |
| 454 dc.Scroll(clip, pp::Point(scroll_x - image_x, scroll_y - image_y)); | |
| 455 if (!FlushAndWaitForDone(&dc)) | |
| 456 return "TC3, Couldn't flush to scroll."; | |
| 457 if (!ReadImageData(dc, &readback_scroll, pp::Point(scroll_x, scroll_y))) | |
| 458 return "TC3, Couldn't read back scrolled image data."; | |
| 459 if (!CompareImages(no_image, readback_scroll)) | |
| 460 return "TC3, Read back scrolled image is not the same as no image."; | |
| 424 | 461 |
| 425 if (!CompareImages(test_image, readback)) | 462 // TC4, same as TC3, but the clip covers part of the image. |
| 426 return "TC1, Read back image is not the same as test image."; | 463 // This part will be scrolled to the intended origin. |
| 464 int part_w = image_w / 2, part_h = image_h / 2; | |
| 465 clip = pp::Rect(0, 0, image_x + part_w, image_y + part_h); | |
| 466 dc.Scroll(clip, pp::Point(scroll_x - image_x, scroll_y - image_y)); | |
| 467 if (!FlushAndWaitForDone(&dc)) | |
| 468 return "TC4, Couldn't flush to scroll."; | |
| 469 if (!ReadImageData(dc, &readback_scroll, pp::Point(scroll_x, scroll_y))) | |
| 470 return "TC4, Couldn't read back scrolled image data."; | |
| 471 if (CompareImages(test_image, readback_scroll)) | |
| 472 return "TC4, Read back scrolled image is the same as test image."; | |
| 473 pp::Rect part_rect(part_w, part_h); | |
| 474 if (!CompareImageRect(test_image, part_rect, readback_scroll, part_rect)) | |
| 475 return "TC4, Read back scrolled image is not the same as part test image."; | |
| 427 | 476 |
| 428 // TC2, Scroll image to an overlapping space. | 477 // TC5, same as TC3, but the clip area covers the entire image. |
| 478 // It will be scrolled to the intended origin. | |
| 479 clip = pp::Rect(0, 0, image_x + image_w, image_y + image_h); | |
| 480 dc.Scroll(clip, pp::Point(scroll_x - image_x, scroll_y - image_y)); | |
| 481 if (!FlushAndWaitForDone(&dc)) | |
| 482 return "TC5, Couldn't flush to scroll."; | |
| 483 if (!ReadImageData(dc, &readback_scroll, pp::Point(scroll_x, scroll_y))) | |
| 484 return "TC5, Couldn't read back scrolled image data."; | |
| 485 if (!CompareImages(test_image, readback_scroll)) | |
| 486 return "TC5, Read back scrolled image is not the same as test image."; | |
| 487 | |
| 488 // Note that the undefined area left by the scroll does not actually get | |
| 489 // cleared, so the original image is still there. This is not guaranteed and | |
| 490 // is not something for users to rely on, but we can test for this here, so | |
| 491 // we know when the underlying behavior changes. | |
| 492 if (!ReadImageData(dc, &readback_image, pp::Point(image_x, image_y))) | |
| 493 return "Couldn't read back original image data."; | |
| 494 if (!CompareImages(test_image, readback_image)) | |
| 495 return "Read back original image is not the same as test image."; | |
| 496 | |
| 497 // TC6, Scroll image to an overlapping space. The clip area is limited | |
| 498 // to the image, so this will just modify its area. | |
| 429 dx = 6; | 499 dx = 6; |
| 430 dy = 9; | 500 dy = 9; |
| 431 clip = pp::Rect(image_x, image_y, test_image.size().width(), | 501 scroll_x = image_x + dx; |
| 432 test_image.size().height()); | 502 scroll_y = image_y + dy; |
| 503 clip = pp::Rect(image_x, image_y, image_w, image_h); | |
| 433 dc.Scroll(clip, pp::Point(dx, dy)); | 504 dc.Scroll(clip, pp::Point(dx, dy)); |
| 434 | |
| 435 if (!FlushAndWaitForDone(&dc)) | 505 if (!FlushAndWaitForDone(&dc)) |
| 436 return "TC2, Couldn't flush to scroll."; | 506 return "TC6, Couldn't flush to scroll."; |
| 437 | 507 if (!ReadImageData(dc, &readback_image, pp::Point(image_x, image_y))) |
| 438 image_x += dx; | 508 return "TC6, Couldn't read back image data."; |
| 439 image_y += dy; | 509 if (CompareImages(test_image, readback_image)) |
| 440 | 510 return "TC6, Read back image is still the same as test image."; |
| 441 if (!ReadImageData(dc, &readback, pp::Point(image_x, image_y))) | 511 pp::Rect scroll_rect(image_w - dx, image_h - dy); |
| 442 return "TC2, Couldn't read back image data."; | 512 if (!ReadImageData(dc, &readback_scroll, pp::Point(scroll_x, scroll_y))) |
| 443 | 513 return "TC6, Couldn't read back scrolled image data."; |
| 444 if (!CompareImages(test_image, readback)) | 514 if (!CompareImageRect(test_image, scroll_rect, readback_scroll, scroll_rect)) |
| 445 return "TC2, Read back image is not the same as test image."; | 515 return "TC6, Read back scrolled image is not the same as part test image."; |
| 446 | 516 |
| 447 PASS(); | 517 PASS(); |
| 448 } | 518 } |
| 449 | 519 |
| 450 std::string TestGraphics2D::TestReplace() { | 520 std::string TestGraphics2D::TestReplace() { |
| 451 const int w = 15, h = 17; | 521 const int w = 15, h = 17; |
| 452 pp::Graphics2D dc(instance_, pp::Size(w, h), false); | 522 pp::Graphics2D dc(instance_, pp::Size(w, h), false); |
| 453 if (dc.is_null()) | 523 if (dc.is_null()) |
| 454 return "Failure creating a boring device"; | 524 return "Failure creating a boring device"; |
| 455 | 525 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 546 if (rv != PP_OK_COMPLETIONPENDING) | 616 if (rv != PP_OK_COMPLETIONPENDING) |
| 547 return "Second flush must fail asynchronously."; | 617 return "Second flush must fail asynchronously."; |
| 548 } else { | 618 } else { |
| 549 if (rv == PP_OK || rv == PP_OK_COMPLETIONPENDING) | 619 if (rv == PP_OK || rv == PP_OK_COMPLETIONPENDING) |
| 550 return "Second flush succeeded before callback ran."; | 620 return "Second flush succeeded before callback ran."; |
| 551 } | 621 } |
| 552 } | 622 } |
| 553 | 623 |
| 554 PASS(); | 624 PASS(); |
| 555 } | 625 } |
| OLD | NEW |