broadway: Fix flicker when resizing windows

Resizing a canvas causes a clear, so we have to save the previous
content and restore to avoid flickering.
This commit is contained in:
Alexander Larsson 2011-03-15 10:18:07 +01:00
parent e3a2176a1f
commit 2635a27814

View File

@ -276,9 +276,25 @@ function handleCommands(cmd_obj)
i = i + 3; i = i + 3;
var h = base64_16(cmd, i); var h = base64_16(cmd, i);
i = i + 3; i = i + 3;
flushSurface(surfaces[id]); var surface = surfaces[id];
surfaces[id].canvas.width = w;
surfaces[id].canvas.height = h; /* Flush any outstanding draw ops before changing size */
flushSurface(surface);
/* Canvas resize clears the data, so we need to save it first */
var tmpCanvas = document.createElement("canvas");
tmpCanvas.width = surface.canvas.width;
tmpCanvas.height = surface.canvas.height;
var tmpContext = tmpCanvas.getContext("2d");
tmpContext.globalCompositeOperation = "copy";
tmpContext.drawImage(surface.canvas, 0, 0, tmpCanvas.width, tmpCanvas.height);
surface.canvas.width = w;
surface.canvas.height = h;
surface.globalCompositeOperation = "copy";
surface.drawImage(tmpCanvas, 0, 0, tmpCanvas.width, tmpCanvas.height);
break; break;
/* put image data surface */ /* put image data surface */