From 684dcdd33fb8ebd694b4e060971b5d5a166a607a Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 26 Jan 2012 11:48:19 -0800 Subject: [PATCH] Properly block source layer until copy to destination is complete. --- .../src/main/resources/layer.js | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index a8539b01a..64ee9a75b 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -410,6 +410,7 @@ Guacamole.Layer = function(width, height) { */ this.copyRect = function(srcLayer, srcx, srcy, srcw, srch, x, y) { + var drawComplete = false; var srcLock = null; function doCopyRect() { @@ -419,9 +420,12 @@ Guacamole.Layer = function(width, height) { if (srcCanvas.width != 0 && srcCanvas.height != 0) displayContext.drawImage(srcCanvas, srcx, srcy, srcw, srch, x, y, srcw, srch); - // Unblock the copy complete task, if it exists + // Unblock the source layer now that draw is complete if (srcLock != null) srcLock.unblock(); + + // Flag operation as done + drawComplete = true; } // If we ARE the source layer, no need to sync. @@ -432,17 +436,19 @@ Guacamole.Layer = function(width, height) { // Otherwise synchronize copy operation with source layer else { - // Task which will be unblocked only when the source layer is ready - // This task will perform the copy + // Currently blocked draw task var task = scheduleTask(doCopyRect, true); - // Task which will unblock the drawing task. - var srcReady = srcLayer.sync(task.unblock); + // Unblock draw task once source layer is ready + srcLayer.sync(task.unblock); - // Task which will be unblocked only after the copy has - // occurred (this will only be created if the draw task - // was postponed) - if (srcReady != null) srcLock = srcLayer.sync(null, true); + // Block source layer until draw completes + // Note that the draw MAY have already been performed at this point, + // in which case creating a lock on the source layer will lead to + // deadlock (the draw task has already run and will thus never + // clear the lock) + if (!drawComplete) + srcLock = srcLayer.sync(null, true); }