From bcee0e9174c09ae5340d4dd7c7aacbda8336d72b Mon Sep 17 00:00:00 2001 From: amhsirak Date: Tue, 4 Mar 2025 22:38:45 +0530 Subject: [PATCH] feat: draw screenshot --- src/components/recorder/Renderer.tsx | 31 +++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/components/recorder/Renderer.tsx b/src/components/recorder/Renderer.tsx index 00859858..2b88ae06 100644 --- a/src/components/recorder/Renderer.tsx +++ b/src/components/recorder/Renderer.tsx @@ -47,5 +47,34 @@ export class CanvasRenderer { this.lastMemoryCheck = performance.now(); } - + /** + * Renders a screenshot to the canvas, optimized for performance + */ + public drawScreenshot( + screenshot: string | ImageBitmap | HTMLImageElement, + x: number = 0, + y: number = 0, + width?: number, + height?: number + ): void { + // Cancel any pending frame request + if (this.lastFrameRequest !== null) { + cancelAnimationFrame(this.lastFrameRequest); + } + + // Check memory usage periodically + this.memoryCheckCounter++; + const now = performance.now(); + + if (this.memoryCheckCounter >= 30 || now - this.lastMemoryCheck > 5000) { + this.checkMemoryUsage(); + this.memoryCheckCounter = 0; + this.lastMemoryCheck = now; + } + + // Request a new frame + this.lastFrameRequest = requestAnimationFrame(() => { + this.renderFrame(screenshot, x, y, width, height); + }); + } } \ No newline at end of file