Fix issue with VideoFrameMetadata merging for bool=true fields.

The code was written assuming that if (metadata.value) was false,
it shouldn't be merged. This is fine for optional fields, but not
bool fields.

Specifically in this bug, `texture_origin_is_top_left` defaults to
true, but is set to false when a canvas backed VideoFrame is made.
The old path would fail to copy the false value over.

This fixes the merge process and adds a test for this case. It also
adds a missing 'dcomp_surface' to the merge process.

R=tguilbert

Fixed: 1277865
Change-Id: I96f7a8032327adaa150ffe7412883bcfb051f71e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3385357
Commit-Queue: Dale Curtis <dalecurtis@chromium.org>
Auto-Submit: Dale Curtis <dalecurtis@chromium.org>
Reviewed-by: Thomas Guilbert <tguilbert@chromium.org>
Commit-Queue: Thomas Guilbert <tguilbert@chromium.org>
Cr-Commit-Position: refs/heads/main@{#958843}
diff --git a/webcodecs/videoFrame-canvasImageSource.html b/webcodecs/videoFrame-canvasImageSource.html
index 7857269..ea47085 100644
--- a/webcodecs/videoFrame-canvasImageSource.html
+++ b/webcodecs/videoFrame-canvasImageSource.html
@@ -89,12 +89,7 @@
   frame.close();
 }, 'SVGImageElement constructed VideoFrame');
 
-test(t => {
-  let canvas = document.querySelector('canvas');
-  canvas.width = 320;
-  canvas.height = 240;
-
-  // Draw and verify four colors image.
+function drawFourColors(canvas) {
   let ctx = canvas.getContext('2d');
   ctx.fillStyle = '#FFFF00'; // yellow
   ctx.fillRect(0, 0, canvas.width / 2, canvas.height / 2);
@@ -105,6 +100,16 @@
   ctx.fillStyle = '#00FF00'; // green
   ctx.fillRect(canvas.width / 2, canvas.height / 2, canvas.width / 2,
                canvas.height / 2);
+}
+
+test(t => {
+  let canvas = document.querySelector('canvas');
+  canvas.width = 320;
+  canvas.height = 240;
+
+  // Draw and verify four colors image.
+  drawFourColors(canvas);
+  let ctx = canvas.getContext('2d');
   verifyFourColorsImage(canvas.width, canvas.height, ctx);
 
   let frame = new VideoFrame(canvas);
@@ -113,4 +118,25 @@
   verifyFourColorsImage(canvas.width, canvas.height, ctx);
   frame.close();
 }, 'Canvas element constructed VideoFrame');
+
+test(t => {
+  let canvas = document.querySelector('canvas');
+  canvas.width = 320;
+  canvas.height = 240;
+
+  // Draw and verify four colors image.
+  drawFourColors(canvas);
+  let ctx = canvas.getContext('2d');
+  verifyFourColorsImage(canvas.width, canvas.height, ctx);
+
+  // Set a different timestamp to try and ensure the same frame isn't reused.
+  let frame = new VideoFrame(canvas, {timestamp: 0});
+  let frame_copy = new VideoFrame(frame, {timestamp: 1});
+  frame.close();
+
+  ctx.clearRect(0, 0, canvas.width, canvas.height);
+  ctx.drawImage(frame_copy, 0, 0);
+  verifyFourColorsImage(canvas.width, canvas.height, ctx);
+  frame_copy.close();
+}, 'Copy of canvas element constructed VideoFrame');
 </script>