Enable willReadFrequently for canvas 2D contexts

Adds the willReadFrequently: true option to all getContext('2d') calls on temporary canvases in Canvas, CanvasLayers, and SAMDetectorIntegration modules. This improves performance for frequent pixel data reads, addressing potential browser optimization issues.
This commit is contained in:
Dariusz L
2025-07-23 16:58:19 +02:00
parent 5235f7b961
commit bccb9da641
5 changed files with 17 additions and 15 deletions

View File

@@ -338,7 +338,7 @@ async function handleSAMDetectorResult(node: ComfyNode, resultImage: HTMLImageEl
const tempCanvas = document.createElement('canvas');
tempCanvas.width = canvas.width;
tempCanvas.height = canvas.height;
const tempCtx = tempCanvas.getContext('2d', {willReadFrequently: true});
const tempCtx = tempCanvas.getContext('2d', { willReadFrequently: true });
if (tempCtx) {
tempCtx.drawImage(resultImage, 0, 0, canvas.width, canvas.height);