mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 13:41:21 +00:00
Added Task.unblock(), updated block check and update handling mechanism.
This commit is contained in:
@@ -201,16 +201,34 @@ Guacamole.Layer = function(width, height) {
|
|||||||
* @private
|
* @private
|
||||||
* @param {function} taskHandler The function to call when this task
|
* @param {function} taskHandler The function to call when this task
|
||||||
* runs, if any.
|
* runs, if any.
|
||||||
|
* @param {boolean} blocked Whether this task should start blocked.
|
||||||
*/
|
*/
|
||||||
function Task(taskHandler) {
|
function Task(taskHandler, blocked) {
|
||||||
|
|
||||||
|
var task = this;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether this Task is blocked.
|
||||||
|
*
|
||||||
|
* @type boolean
|
||||||
|
*/
|
||||||
|
this.blocked = blocked;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The handler this Task is associated with, if any.
|
* The handler this Task is associated with, if any.
|
||||||
*
|
*
|
||||||
* @type function
|
* @type function
|
||||||
*/
|
*/
|
||||||
this.handler = taskHandler;
|
this.handler = taskHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unblocks this Task, allowing it to run.
|
||||||
|
*/
|
||||||
|
this.unblock = function() {
|
||||||
|
task.blocked = false;
|
||||||
|
handlePendingTasks();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -220,21 +238,22 @@ Guacamole.Layer = function(width, height) {
|
|||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {function} handler The function to call when possible, if any.
|
* @param {function} handler The function to call when possible, if any.
|
||||||
|
* @param {boolean} blocked Whether the task should start blocked.
|
||||||
* @returns {Task} The Task created and added to the queue for future
|
* @returns {Task} The Task created and added to the queue for future
|
||||||
* running, if any, or null if the handler was run
|
* running, if any, or null if the handler was run
|
||||||
* immediately and no Task needed to be created.
|
* immediately and no Task needed to be created.
|
||||||
*/
|
*/
|
||||||
function scheduleTask(handler) {
|
function scheduleTask(handler, blocked) {
|
||||||
|
|
||||||
// If no pending tasks, just call (if available) and exit
|
// If no pending tasks, just call (if available) and exit
|
||||||
if (layer.isReady() && handler != null) {
|
if (layer.isReady() && !blocked && handler != null) {
|
||||||
handler();
|
handler();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If tasks are pending/executing, schedule a pending task
|
// If tasks are pending/executing, schedule a pending task
|
||||||
// and return a reference to it.
|
// and return a reference to it.
|
||||||
var task = new Task(handler);
|
var task = new Task(handler, blocked);
|
||||||
tasks.push(task);
|
tasks.push(task);
|
||||||
return task;
|
return task;
|
||||||
|
|
||||||
@@ -256,9 +275,9 @@ Guacamole.Layer = function(width, height) {
|
|||||||
|
|
||||||
// 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.blocked) {
|
||||||
tasks.shift();
|
tasks.shift();
|
||||||
task.handler();
|
if (task.handler) task.handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
tasksInProgress = false;
|
tasksInProgress = false;
|
||||||
@@ -345,21 +364,14 @@ Guacamole.Layer = function(width, height) {
|
|||||||
* @param {String} url The URL of the image to draw.
|
* @param {String} url The URL of the image to draw.
|
||||||
*/
|
*/
|
||||||
this.draw = function(x, y, url) {
|
this.draw = function(x, y, url) {
|
||||||
var task = scheduleTask(null);
|
|
||||||
|
var task = scheduleTask(function() {
|
||||||
|
if (layer.autosize != 0) fitRect(x, y, image.width, image.height);
|
||||||
|
displayContext.drawImage(image, x, y);
|
||||||
|
}, true);
|
||||||
|
|
||||||
var image = new Image();
|
var image = new Image();
|
||||||
image.onload = function() {
|
image.onload = task.unblock;
|
||||||
|
|
||||||
task.handler = function() {
|
|
||||||
if (layer.autosize != 0) fitRect(x, y, image.width, image.height);
|
|
||||||
displayContext.drawImage(image, x, y);
|
|
||||||
};
|
|
||||||
|
|
||||||
// As this task originally had no handler and may have blocked
|
|
||||||
// other tasks, handle any blocked tasks.
|
|
||||||
handlePendingTasks();
|
|
||||||
|
|
||||||
};
|
|
||||||
image.src = url;
|
image.src = url;
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -398,7 +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 srcCopied = null;
|
var srcLock = null;
|
||||||
|
|
||||||
function doCopyRect() {
|
function doCopyRect() {
|
||||||
if (layer.autosize != 0) fitRect(x, y, srcw, srch);
|
if (layer.autosize != 0) fitRect(x, y, srcw, srch);
|
||||||
@@ -408,8 +420,8 @@ Guacamole.Layer = function(width, height) {
|
|||||||
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 copy complete task, if it exists
|
||||||
if (srcCopied != null)
|
if (srcLock != null)
|
||||||
srcCopied.handler = function() {};
|
srcLock.unblock();
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we ARE the source layer, no need to sync.
|
// If we ARE the source layer, no need to sync.
|
||||||
@@ -422,24 +434,15 @@ Guacamole.Layer = function(width, height) {
|
|||||||
|
|
||||||
// Task which will be unblocked only when the source layer is ready
|
// Task which will be unblocked only when the source layer is ready
|
||||||
// This task will perform the copy
|
// This task will perform the copy
|
||||||
var task = scheduleTask(null);
|
var task = scheduleTask(doCopyRect, true);
|
||||||
|
|
||||||
// Task which will unblock the drawing task.
|
// Task which will unblock the drawing task.
|
||||||
var srcReady = srcLayer.sync(function() {
|
var srcReady = srcLayer.sync(task.unblock);
|
||||||
|
|
||||||
task.handler = doCopyRect;
|
|
||||||
|
|
||||||
// As this task originally had no handler and may have blocked
|
|
||||||
// other tasks, handle any blocked tasks.
|
|
||||||
handlePendingTasks();
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
// Task which will be unblocked only after the copy has
|
// Task which will be unblocked only after the copy has
|
||||||
// occurred (this will only be created if the draw task
|
// occurred (this will only be created if the draw task
|
||||||
// was postponed)
|
// was postponed)
|
||||||
if (srcReady != null)
|
if (srcReady != null) srcLock = srcLayer.sync(null, true);
|
||||||
srcCopied = srcLayer.sync(null);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user