Bug 1363428 - Allow passing in an existing canvas to capture.canvas, r=ato
MozReview-Commit-ID: EGvEr7XfHH9
--- a/testing/marionette/capture.js
+++ b/testing/marionette/capture.js
@@ -39,17 +39,17 @@ capture.element = function (node, highli
let rect = node.getBoundingClientRect();
return capture.canvas(
win,
rect.left,
rect.top,
rect.width,
rect.height,
- highlights);
+ {highlights});
};
/**
* Take a screenshot of the window's viewport by taking into account
* the current offsets.
*
* @param {DOMWindow} win
* The DOM window providing the document element to capture,
@@ -65,17 +65,17 @@ capture.viewport = function (win, highli
let rootNode = win.document.documentElement;
return capture.canvas(
win,
win.pageXOffset,
win.pageYOffset,
rootNode.clientWidth,
rootNode.clientHeight,
- highlights);
+ {highlights});
};
/**
* Low-level interface to draw a rectangle off the framebuffer.
*
* @param {DOMWindow} win
* The DOM window used for the framebuffer, and providing the interfaces
* for creating an HTMLCanvasElement.
@@ -85,27 +85,31 @@ capture.viewport = function (win, highli
* The top, Y axis offset of the rectangle.
* @param {number} width
* The width dimension of the rectangle to paint.
* @param {number} height
* The height dimension of the rectangle to paint.
* @param {Array.<Node>=} highlights
* Optional array of nodes, around which a border will be marked to
* highlight them in the screenshot.
+ * @param {HTMLCanvasElement=} canvas
+ * Optional canvas to reuse for the screenshot.
*
* @return {HTMLCanvasElement}
* The canvas on which the selection from the window's framebuffer
* has been painted on.
*/
-capture.canvas = function (win, left, top, width, height, highlights = []) {
+capture.canvas = function (win, left, top, width, height, {highlights = [], canvas = null} = {}) {
let scale = win.devicePixelRatio;
- let canvas = win.document.createElementNS(XHTML_NS, "canvas");
- canvas.width = width * scale;
- canvas.height = height * scale;
+ if (canvas === null) {
+ canvas = win.document.createElementNS(XHTML_NS, "canvas");
+ canvas.width = width * scale;
+ canvas.height = height * scale;
+ }
let ctx = canvas.getContext(CONTEXT_2D);
let flags = ctx.DRAWWINDOW_DRAW_CARET;
// Disabled in bug 1243415 for webplatform-test failures due to out of view elements.
// Needs https://github.com/w3c/web-platform-tests/issues/4383 fixed.
// ctx.DRAWWINDOW_DRAW_VIEW;
// Bug 1009762 - Crash in [@ mozilla::gl::ReadPixelsIntoDataSurface]
// ctx.DRAWWINDOW_USE_WIDGET_LAYERS;
@@ -185,9 +189,9 @@ function hex(buffer) {
for (let i = 0; i < view.byteLength; i += 4) {
let value = view.getUint32(i);
let stringValue = value.toString(16);
let padding = '00000000';
let paddedValue = (padding + stringValue).slice(-padding.length);
hexCodes.push(paddedValue);
}
return hexCodes.join("");
-};
\ No newline at end of file
+};