Bug 1380346 - Let CaptureStreamTestHelper2D.drawColor draw squares wherever you want. r=jib

It was supporting a simpler case of only drawing in the upper left corner of
the input canvas. This supports that by default still, but also allows the
caller to exactly specify coordinates and size of the rectangle to draw.

MozReview-Commit-ID: GVQh0HqejqU

--HG--
extra : rebase_source : fb48fd1681f0545c53b5cb49b2791f42270ca83c
This commit is contained in:
Andreas Pehrson 2017-09-14 19:00:20 +02:00
parent f9cccebd1e
commit f421080879

View File

@ -219,7 +219,12 @@ CaptureStreamTestHelper2D.prototype.clear = function(canvas) {
};
/* Draw the color |color| to the source canvas |canvas|. Format [R,G,B,A]. */
CaptureStreamTestHelper2D.prototype.drawColor = function(canvas, color) {
CaptureStreamTestHelper2D.prototype.drawColor = function(canvas, color,
{ offsetX = 0,
offsetY = 0,
width = canvas.width / 2,
height = canvas.height / 2,
} = {}) {
var ctx = canvas.getContext('2d');
var rgba = color.data.slice(); // Copy to not overwrite the original array
rgba[3] = rgba[3] / 255.0; // Convert opacity to double in range [0,1]
@ -227,7 +232,7 @@ CaptureStreamTestHelper2D.prototype.drawColor = function(canvas, color) {
ctx.fillStyle = "rgba(" + rgba.join(',') + ")";
// Only fill top left corner to test that output is not flipped or rotated.
ctx.fillRect(0, 0, canvas.width / 2, canvas.height / 2);
ctx.fillRect(offsetX, offsetY, width, height);
};
/* Test that the given 2d canvas is NOT origin-clean. */