* Handles frame update from worker - draws to mirror canvas * @param {Object} payload - Frame data with ImageBitmap
(payload)
| 1267 | * @param {Object} payload - Frame data with ImageBitmap |
| 1268 | */ |
| 1269 | function handleWorkerFrameUpdate(payload) { |
| 1270 | const { bitmap, width, height } = payload; |
| 1271 | |
| 1272 | try { |
| 1273 | // Create mirror canvas if needed or resize if dimensions changed |
| 1274 | if (!mirrorCanvas || mirrorCanvas.width !== width || mirrorCanvas.height !== height) { |
| 1275 | console.log('Creating/resizing mirror canvas:', width, 'x', height); |
| 1276 | |
| 1277 | if (mirrorCanvas) { |
| 1278 | document.body.removeChild(mirrorCanvas); |
| 1279 | } |
| 1280 | |
| 1281 | mirrorCanvas = createMirrorCanvas(width, height); |
| 1282 | mirrorCanvasContext = mirrorCanvas.getContext('2d', { willReadFrequently: false }); |
| 1283 | } |
| 1284 | |
| 1285 | // Draw bitmap to mirror canvas (hardware-accelerated) |
| 1286 | if (mirrorCanvasContext) { |
| 1287 | mirrorCanvasContext.drawImage(bitmap, 0, 0); |
| 1288 | } |
| 1289 | |
| 1290 | // Bitmap is transferred, no need to close it |
| 1291 | } catch (error) { |
| 1292 | console.error('Error drawing frame to mirror canvas:', error); |
| 1293 | } |
| 1294 | } |
| 1295 | |
| 1296 | /** |
| 1297 | * Initializes main-thread video recording with worker frame transfer |
no test coverage detected