From 9a076a13d9ded7d889d6b7d2a153b28ba4102412 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 18 Aug 2011 18:00:45 -0700 Subject: [PATCH] Fixed layer resize(), avoid multiple handlePengingTasks() calls --- src/main/resources/layer.js | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/main/resources/layer.js b/src/main/resources/layer.js index eb0ba7e..3ef8aeb 100644 --- a/src/main/resources/layer.js +++ b/src/main/resources/layer.js @@ -97,9 +97,36 @@ Guacamole.Layer = function(width, height) { * @param {Number} newHeight The new height to assign to this Layer. */ function resize(newWidth, newHeight) { + + + // Only preserve old data if width/height are both non-zero + var oldData = null; + if (width != 0 && height != 0) { + + // Create canvas and context for holding old data + oldData = document.createElement("canvas"); + oldData.width = width; + oldData.height = height; + + var oldDataContext = oldData.getContext("2d"); + + // Copy image data from current + oldDataContext.drawImage(display, + 0, 0, width, height, + 0, 0, width, height); + + } + + // Resize canvas display.width = newWidth; display.height = newHeight; + // Redraw old data, if any + if (oldData) + displayContext.drawImage(oldData, + 0, 0, width, height, + 0, 0, width, height); + width = newWidth; height = newHeight; } @@ -195,6 +222,8 @@ Guacamole.Layer = function(width, height) { } + var tasksInProgress = false; + /** * Run any Tasks which were pending but are now ready to run and are not * blocked by other Tasks. @@ -202,6 +231,11 @@ Guacamole.Layer = function(width, height) { */ function handlePendingTasks() { + if (tasksInProgress) + return; + + tasksInProgress = true; + // Draw all pending tasks. var task; while ((task = tasks[0]) != null && task.handler) { @@ -209,6 +243,8 @@ Guacamole.Layer = function(width, height) { task.handler(); } + tasksInProgress = false; + } /** @@ -475,6 +511,7 @@ Guacamole.Layer = function(width, height) { }; // Initialize canvas dimensions - resize(width, height); + display.width = width; + display.height = height; }; -- 1.7.10.4