| 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,60 +390,135 @@
|
| 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))
|
| return "Bad initial color.";
|
|
|
| - const int image_w = 15, image_h = 23;
|
| + const int image_width = 15, image_height = 23;
|
| pp::ImageData test_image(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL,
|
| - pp::Size(image_w, image_h), false);
|
| + pp::Size(image_width, image_height), false);
|
| FillImageWithGradient(&test_image);
|
| + pp::ImageData no_image(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL,
|
| + pp::Size(image_width, image_height), false);
|
| + FillRectInImage(&no_image, pp::Rect(0, 0, image_width, image_height), 0);
|
| + pp::ImageData readback_image(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL,
|
| + pp::Size(image_width, image_height), false);
|
| + pp::ImageData readback_scroll(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL,
|
| + pp::Size(image_width, image_height), false);
|
|
|
| + if (test_image.size() != pp::Size(image_width, image_height))
|
| + 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.
|
| + // Test Case 1. Incorrect usage when scrolling image to a free space.
|
| + // 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. So if
|
| + // 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_width, image_height);
|
| 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;
|
| + // Test Case 2.
|
| + // 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.";
|
| + // Test Case 3.
|
| + // 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.";
|
| + // Test Case 4.
|
| + // Same as TC3, but the clip covers part of the image.
|
| + // This part will be scrolled to the intended origin.
|
| + int part_w = image_width / 2, part_h = image_height / 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.
|
| + // Test Case 5
|
| + // 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_width, image_y + image_height);
|
| + 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.";
|
| +
|
| + // Test Case 6.
|
| + // 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_width, image_height);
|
| 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_width - dx, image_height - 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();
|
| }
|
|
|
|
|