From fabeca74147bb89a53a1ac8a8947423dd6cd5269 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sat, 12 Feb 2011 18:22:39 -0800 Subject: [PATCH] copyRect should be synchronized with source layer/buffer's updates (as it may not be finished drawing by the time a copy is issued) --- .../src/main/resources/layer.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index 2614de0ad..4c29726a2 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -140,13 +140,23 @@ function Layer(width, height) { image.src = url; }; + // Run arbitrary function as soon as currently pending operations complete. + // Future operations will not block this function from being called (unlike + // the ready handler, which requires no pending updates) + display.sync = function(handler) { + var updateId = currentUpdate++; + setUpdate(updateId, handler); + } display.copyRect = function(srcLayer, srcx, srcy, w, h, x, y) { var updateId = currentUpdate++; - - setUpdate(updateId, function() { - if (autosize != 0) fitRect(x, y, w, h); - displayContext.drawImage(srcLayer, srcx, srcy, w, h, x, y, w, h); + + // Synchronize copy operation with source layer + srcLayer.sync(function() { + setUpdate(updateId, function() { + if (autosize != 0) fitRect(x, y, w, h); + displayContext.drawImage(srcLayer, srcx, srcy, w, h, x, y, w, h); + }); }); };