Chromium Code Reviews| Index: ppapi/tests/test_graphics_2d.cc |
| =================================================================== |
| --- ppapi/tests/test_graphics_2d.cc (revision 109319) |
| +++ ppapi/tests/test_graphics_2d.cc (working copy) |
| @@ -48,7 +48,7 @@ |
| RUN_TEST(InitToZero); |
| RUN_TEST(Describe); |
| RUN_TEST_FORCEASYNC_AND_NOT(Paint); |
| - // RUN_TEST_FORCEASYNC_AND_NOT(Scroll); // TODO(brettw) implement. |
| + RUN_TEST_FORCEASYNC_AND_NOT(Scroll); |
| RUN_TEST_FORCEASYNC_AND_NOT(Replace); |
| RUN_TEST_FORCEASYNC_AND_NOT(Flush); |
| } |
| @@ -390,6 +390,8 @@ |
| pp::Graphics2D dc(instance_, pp::Size(w, h), false); |
| if (dc.is_null()) |
| return "Failure creating a boring device."; |
| + if (!instance_->BindGraphics(dc)) |
| + return "Failure to bind the boring device."; |
| // Make sure the device background is 0. |
| if (!IsDCUniformColor(dc, 0)) |
| @@ -399,51 +401,119 @@ |
| pp::ImageData test_image(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
| pp::Size(image_w, image_h), false); |
| FillImageWithGradient(&test_image); |
| + pp::ImageData no_image(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
| + pp::Size(image_w, image_h), false); |
| + FillRectInImage(&no_image, pp::Rect(0, 0, image_w, image_h), 0); |
| + pp::ImageData readback_image(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
| + pp::Size(image_w, image_h), false); |
| + pp::ImageData readback_scroll(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
| + pp::Size(image_w, image_h), false); |
| + if (test_image.size() != pp::Size(image_w, image_h)) |
| + return "Wrong test image size\n"; |
| + |
| int image_x = 51, image_y = 72; |
| dc.PaintImageData(test_image, pp::Point(image_x, image_y)); |
| if (!FlushAndWaitForDone(&dc)) |
| return "Couldn't flush to fill backing store."; |
| - // TC1, Scroll image to a free space. |
| + // 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.
|
| + // The clip area is *not* the area to shift around within the graphics device |
| + // 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.
|
| + // the clip area is the size of the image and the amount points to free space, |
| + // the scroll won't result in additional images. |
| int dx = -40, dy = -48; |
| - pp::Rect clip = pp::Rect(image_x, image_y, test_image.size().width(), |
| - test_image.size().height()); |
| + int scroll_x = image_x + dx, scroll_y = image_y + dy; |
| + pp::Rect clip(image_x, image_y, image_w, image_h); |
| dc.Scroll(clip, pp::Point(dx, dy)); |
| - |
| if (!FlushAndWaitForDone(&dc)) |
| return "TC1, Couldn't flush to scroll."; |
| + if (!ReadImageData(dc, &readback_scroll, pp::Point(scroll_x, scroll_y))) |
| + return "TC1, Couldn't read back scrolled image data."; |
| + if (!CompareImages(no_image, readback_scroll)) |
| + return "TC1, Read back scrolled image is not the same as no image."; |
| - image_x += dx; |
| - image_y += dy; |
| + // TC2, The amount is intended to place the image in the free space outside |
| + // of the original, but the clip area extends beyond the graphics device area. |
| + // This scroll is invalid and will be a noop. |
| + scroll_x = 11, scroll_y = 24; |
| + clip = pp::Rect(0, 0, w, h + 1); |
| + dc.Scroll(clip, pp::Point(scroll_x - image_x, scroll_y - image_y)); |
| + if (!FlushAndWaitForDone(&dc)) |
| + return "TC2, Couldn't flush to scroll."; |
| + if (!ReadImageData(dc, &readback_scroll, pp::Point(scroll_x, scroll_y))) |
| + return "TC2, Couldn't read back scrolled image data."; |
| + if (!CompareImages(no_image, readback_scroll)) |
| + return "TC2, Read back scrolled image is not the same as no image."; |
| - pp::ImageData readback(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
| - pp::Size(image_w, image_h), false); |
| - if (!ReadImageData(dc, &readback, pp::Point(image_x, image_y))) |
| - return "TC1, Couldn't read back image data."; |
| + // TC3, The amount is intended to place the image in the free space outside |
| + // of the original, but the clip area does not cover the image, |
| + // so there is nothing to scroll. |
| + scroll_x = 11, scroll_y = 24; |
| + clip = pp::Rect(0, 0, image_x, image_y); |
| + dc.Scroll(clip, pp::Point(scroll_x - image_x, scroll_y - image_y)); |
| + if (!FlushAndWaitForDone(&dc)) |
| + return "TC3, Couldn't flush to scroll."; |
| + if (!ReadImageData(dc, &readback_scroll, pp::Point(scroll_x, scroll_y))) |
| + return "TC3, Couldn't read back scrolled image data."; |
| + if (!CompareImages(no_image, readback_scroll)) |
| + return "TC3, Read back scrolled image is not the same as no image."; |
| - if (!CompareImages(test_image, readback)) |
| - return "TC1, Read back image is not the same as test image."; |
| + // TC4, same as TC3, but the clip covers part of the image. |
| + // This part will be scrolled to the intended origin. |
| + int part_w = image_w / 2, part_h = image_h / 2; |
| + clip = pp::Rect(0, 0, image_x + part_w, image_y + part_h); |
| + dc.Scroll(clip, pp::Point(scroll_x - image_x, scroll_y - image_y)); |
| + if (!FlushAndWaitForDone(&dc)) |
| + return "TC4, Couldn't flush to scroll."; |
| + if (!ReadImageData(dc, &readback_scroll, pp::Point(scroll_x, scroll_y))) |
| + return "TC4, Couldn't read back scrolled image data."; |
| + if (CompareImages(test_image, readback_scroll)) |
| + return "TC4, Read back scrolled image is the same as test image."; |
| + pp::Rect part_rect(part_w, part_h); |
| + if (!CompareImageRect(test_image, part_rect, readback_scroll, part_rect)) |
| + return "TC4, Read back scrolled image is not the same as part test image."; |
| - // TC2, Scroll image to an overlapping space. |
| + // TC5, same as TC3, but the clip area covers the entire image. |
| + // It will be scrolled to the intended origin. |
| + clip = pp::Rect(0, 0, image_x + image_w, image_y + image_h); |
| + dc.Scroll(clip, pp::Point(scroll_x - image_x, scroll_y - image_y)); |
| + if (!FlushAndWaitForDone(&dc)) |
| + return "TC5, Couldn't flush to scroll."; |
| + if (!ReadImageData(dc, &readback_scroll, pp::Point(scroll_x, scroll_y))) |
| + return "TC5, Couldn't read back scrolled image data."; |
| + if (!CompareImages(test_image, readback_scroll)) |
| + return "TC5, Read back scrolled image is not the same as test image."; |
| + |
| + // Note that the undefined area left by the scroll does not actually get |
| + // cleared, so the original image is still there. This is not guaranteed and |
| + // is not something for users to rely on, but we can test for this here, so |
| + // we know when the underlying behavior changes. |
| + if (!ReadImageData(dc, &readback_image, pp::Point(image_x, image_y))) |
| + return "Couldn't read back original image data."; |
| + if (!CompareImages(test_image, readback_image)) |
| + return "Read back original image is not the same as test image."; |
| + |
| + // TC6, Scroll image to an overlapping space. The clip area is limited |
| + // to the image, so this will just modify its area. |
| dx = 6; |
| dy = 9; |
| - clip = pp::Rect(image_x, image_y, test_image.size().width(), |
| - test_image.size().height()); |
| + scroll_x = image_x + dx; |
| + scroll_y = image_y + dy; |
| + clip = pp::Rect(image_x, image_y, image_w, image_h); |
| dc.Scroll(clip, pp::Point(dx, dy)); |
| - |
| if (!FlushAndWaitForDone(&dc)) |
| - return "TC2, Couldn't flush to scroll."; |
| + return "TC6, Couldn't flush to scroll."; |
| + if (!ReadImageData(dc, &readback_image, pp::Point(image_x, image_y))) |
| + return "TC6, Couldn't read back image data."; |
| + if (CompareImages(test_image, readback_image)) |
| + return "TC6, Read back image is still the same as test image."; |
| + pp::Rect scroll_rect(image_w - dx, image_h - dy); |
| + if (!ReadImageData(dc, &readback_scroll, pp::Point(scroll_x, scroll_y))) |
| + return "TC6, Couldn't read back scrolled image data."; |
| + if (!CompareImageRect(test_image, scroll_rect, readback_scroll, scroll_rect)) |
| + return "TC6, Read back scrolled image is not the same as part test image."; |
| - image_x += dx; |
| - image_y += dy; |
| - |
| - if (!ReadImageData(dc, &readback, pp::Point(image_x, image_y))) |
| - return "TC2, Couldn't read back image data."; |
| - |
| - if (!CompareImages(test_image, readback)) |
| - return "TC2, Read back image is not the same as test image."; |
| - |
| PASS(); |
| } |