Fixed layer resize(), avoid multiple handlePengingTasks() calls

This commit is contained in:
Michael Jumper
2011-08-18 18:00:45 -07:00
parent 6c41eb5aad
commit b7a5cc7013

View File

@@ -97,9 +97,36 @@ Guacamole.Layer = function(width, height) {
* @param {Number} newHeight The new height to assign to this Layer. * @param {Number} newHeight The new height to assign to this Layer.
*/ */
function resize(newWidth, newHeight) { 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.width = newWidth;
display.height = newHeight; display.height = newHeight;
// Redraw old data, if any
if (oldData)
displayContext.drawImage(oldData,
0, 0, width, height,
0, 0, width, height);
width = newWidth; width = newWidth;
height = newHeight; 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 * Run any Tasks which were pending but are now ready to run and are not
* blocked by other Tasks. * blocked by other Tasks.
@@ -202,6 +231,11 @@ Guacamole.Layer = function(width, height) {
*/ */
function handlePendingTasks() { function handlePendingTasks() {
if (tasksInProgress)
return;
tasksInProgress = true;
// Draw all pending tasks. // Draw all pending tasks.
var task; var task;
while ((task = tasks[0]) != null && task.handler) { while ((task = tasks[0]) != null && task.handler) {
@@ -209,6 +243,8 @@ Guacamole.Layer = function(width, height) {
task.handler(); task.handler();
} }
tasksInProgress = false;
} }
/** /**
@@ -475,6 +511,7 @@ Guacamole.Layer = function(width, height) {
}; };
// Initialize canvas dimensions // Initialize canvas dimensions
resize(width, height); display.width = width;
display.height = height;
}; };