Properly block source layer until copy to destination is complete.

This commit is contained in:
Michael Jumper
2012-01-26 11:48:19 -08:00
parent 8cc8ad9e5e
commit 684dcdd33f

View File

@@ -410,6 +410,7 @@ Guacamole.Layer = function(width, height) {
*/ */
this.copyRect = function(srcLayer, srcx, srcy, srcw, srch, x, y) { this.copyRect = function(srcLayer, srcx, srcy, srcw, srch, x, y) {
var drawComplete = false;
var srcLock = null; var srcLock = null;
function doCopyRect() { function doCopyRect() {
@@ -419,9 +420,12 @@ Guacamole.Layer = function(width, height) {
if (srcCanvas.width != 0 && srcCanvas.height != 0) if (srcCanvas.width != 0 && srcCanvas.height != 0)
displayContext.drawImage(srcCanvas, srcx, srcy, srcw, srch, x, y, srcw, srch); 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) if (srcLock != null)
srcLock.unblock(); srcLock.unblock();
// Flag operation as done
drawComplete = true;
} }
// If we ARE the source layer, no need to sync. // 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 // Otherwise synchronize copy operation with source layer
else { else {
// Task which will be unblocked only when the source layer is ready // Currently blocked draw task
// This task will perform the copy
var task = scheduleTask(doCopyRect, true); var task = scheduleTask(doCopyRect, true);
// Task which will unblock the drawing task. // Unblock draw task once source layer is ready
var srcReady = srcLayer.sync(task.unblock); srcLayer.sync(task.unblock);
// Task which will be unblocked only after the copy has // Block source layer until draw completes
// occurred (this will only be created if the draw task // Note that the draw MAY have already been performed at this point,
// was postponed) // in which case creating a lock on the source layer will lead to
if (srcReady != null) srcLock = srcLayer.sync(null, true); // deadlock (the draw task has already run and will thus never
// clear the lock)
if (!drawComplete)
srcLock = srcLayer.sync(null, true);
} }