Commit be5a7b1b authored by Fernando Serboncini's avatar Fernando Serboncini Committed by Commit Bot

Fix CopyImageAtAndCapturePixel for new Mojo sequencer

The old function assumed that a async mojo calls between two sync calls
would happen in sequence. This is not true at all.

Bug: 872076
Change-Id: I9b7f78be76352c6133638665c60b156902fff1eb
Reviewed-on: https://chromium-review.googlesource.com/1176078
Commit-Queue: Fernando Serboncini <fserb@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@chromium.org>
Cr-Commit-Position: refs/heads/master@{#583386}
parent e516ef4d
...@@ -192,11 +192,9 @@ void CopyImageAtAndCapturePixels( ...@@ -192,11 +192,9 @@ void CopyImageAtAndCapturePixels(
&sequence_number_before); &sequence_number_before);
web_frame->CopyImageAt(blink::WebPoint(x, y)); web_frame->CopyImageAt(blink::WebPoint(x, y));
uint64_t sequence_number_after = 0; uint64_t sequence_number_after = 0;
clipboard->GetSequenceNumber(ui::CLIPBOARD_TYPE_COPY_PASTE, while (sequence_number_before == sequence_number_after) {
&sequence_number_after); clipboard->GetSequenceNumber(ui::CLIPBOARD_TYPE_COPY_PASTE,
if (sequence_number_before == sequence_number_after) { &sequence_number_after);
std::move(callback).Run(SkBitmap());
return;
} }
SkBitmap bitmap; SkBitmap bitmap;
......
...@@ -1765,7 +1765,7 @@ crbug.com/761798 [ Mac ] inspector-protocol/emulation/device-emulation-desktop.j ...@@ -1765,7 +1765,7 @@ crbug.com/761798 [ Mac ] inspector-protocol/emulation/device-emulation-desktop.j
crbug.com/771233 [ Win10 ] http/tests/devtools/audits2/ [ Skip ] crbug.com/771233 [ Win10 ] http/tests/devtools/audits2/ [ Skip ]
crbug.com/865477 [ Mac ] virtual/gpu/fast/canvas/OffscreenCanvas-commit-copyImage.html [ Failure ] crbug.com/865477 [ Mac ] virtual/gpu/fast/canvas/OffscreenCanvas-copyImage.html [ Failure ]
crbug.com/410974 fast/scroll-behavior/scroll-customization/scrollstate-basic.html [ Pass Failure ] crbug.com/410974 fast/scroll-behavior/scroll-customization/scrollstate-basic.html [ Pass Failure ]
crbug.com/410974 fast/scroll-behavior/scroll-customization/scrollstate-consume-deltas.html [ Pass Failure ] crbug.com/410974 fast/scroll-behavior/scroll-customization/scrollstate-consume-deltas.html [ Pass Failure ]
......
<!-- This test checks copyImageAt() with position parameter
that actually doesn't point to an Image(Canvas).
(Negative test for crbug.com/392765) -->
<head>
<script src="../resources/js-test.js"></script>
<script>
function main()
{
if (!window.testRunner) {
testFailed("Requires window.testRunner");
} else {
testRunner.waitUntilDone();
testRunner.dumpAsText();
window.requestAnimationFrame(runTest);
}
}
function runTest() {
try {
testRunner.copyImageAtAndCapturePixelsAsyncThen(50, 50, completionCallback);
} catch (e) {
debug('error in runTest');
debug(e);
testRunner.notifyDone();
}
}
var width, height;
function completionCallback(w, h, snapshot) {
try {
width = w;
height = h;
shouldBeEqualToNumber("width", 0);
shouldBeEqualToNumber("height", 0);
} catch (e) {
debug('error in completionCallback');
debug(e);
testRunner.notifyDone();
return;
}
testRunner.notifyDone();
}
main();
</script>
</head>
<body>
<div id="console"></div>
</body>
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<script src="../../resources/testharnessreport.js"></script> <script src="../../resources/testharnessreport.js"></script>
<script> <script>
var t = async_test("CopyImageOnTransferredCanvas"); const t = async_test("CopyImageOnTransferredCanvas");
function main() { function main() {
assert_true(!!window.testRunner, "This test requires window.testRunner."); assert_true(!!window.testRunner, "This test requires window.testRunner.");
...@@ -19,9 +19,9 @@ function main() { ...@@ -19,9 +19,9 @@ function main() {
} }
function initTest() { function initTest() {
var canv = document.getElementById("myCanvas"); const canv = document.getElementById("myCanvas");
var off = canv.transferControlToOffscreen(); const off = canv.transferControlToOffscreen();
var ctx = off.getContext("2d"); const ctx = off.getContext("2d");
ctx.fillStyle = "#f00"; ctx.fillStyle = "#f00";
ctx.fillRect(0, 0, 128, 128); ctx.fillRect(0, 0, 128, 128);
...@@ -35,42 +35,39 @@ function initTest() { ...@@ -35,42 +35,39 @@ function initTest() {
requestAnimationFrame(runTest); requestAnimationFrame(runTest);
} }
function copyImage() {
testRunner.copyImageAtAndCapturePixelsAsyncThen(100, 100, completionCallback);
}
function runTest() { function runTest() {
// We need setTimeout as a frame barrier for the image frame to be // We need a frame barrier for the image frame to be propagated to the
// propagated to the placeholder canvas. // placeholder canvas.
requestAnimationFrame(() => { requestAnimationFrame(() => {
requestAnimationFrame(() => { requestAnimationFrame(copyImage);
requestAnimationFrame(copyImage); });
});
});
} }
function completionCallback(width, height, snapshot) { function copyImage() {
t.step(function() { testRunner.copyImageAtAndCapturePixelsAsyncThen(128, 128,
t.step_func_done((width, height, snapshot) => {
assert_equals(width, 256, "The copied image has a width of 256."); assert_equals(width, 256, "The copied image has a width of 256.");
assert_equals(height, 256, "The copied image has a height of 256."); assert_equals(height, 256, "The copied image has a height of 256.");
var data = new Uint8Array(snapshot); const data = new Uint8Array(snapshot);
var pixelLeftTop = data.subarray(0, 4);
assert_array_equals(pixelLeftTop, [255, 0, 0, 255], "The copied image's top left is red");
var pixelRightTop = data.subarray(4 * 128, 4* 128 + 4); const pixelLeftTop = data.subarray(0, 4);
assert_array_equals(pixelRightTop, [0, 255, 0, 255], "The copied image's top right is green"); assert_array_equals(pixelLeftTop, [255, 0, 0, 255],
"The copied image's top left is red");
var pixelLeftBottom = data.subarray(4 * 256 * 128, 4 * 256 * 128 + 4); const pixelRightTop = data.subarray(4 * 128, 4* 128 + 4);
assert_array_equals(pixelLeftBottom, [0, 0, 255, 255], "The copied image's bottom left is blue"); assert_array_equals(pixelRightTop, [0, 255, 0, 255],
"The copied image's top right is green");
var rightBottomPixelPosition = 4 * 256 * 128 + 4 * 128; const pixelLeftBottom = data.subarray(4 * 256 * 128, 4 * 256 * 128 + 4);
var pixelRightBottom = data.subarray(rightBottomPixelPosition, rightBottomPixelPosition + 4); assert_array_equals(pixelLeftBottom, [0, 0, 255, 255],
assert_array_equals(pixelRightBottom, [255, 255, 0, 255], "The copied image's bottom right is yellow"); "The copied image's bottom left is blue");
}); const pixelRightBottom = data.subarray(4 * 256 * 128 + 4 * 128,
t.done(); 4 * 256 * 128 + 4 * 128 + 4);
assert_array_equals(pixelRightBottom, [255, 255, 0, 255],
"The copied image's bottom right is yellow");
}));
} }
main(); main();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment