copyRect should be synchronized with source layer/buffer's updates (as it may not be finished drawing by the time a copy is issued)

This commit is contained in:
Michael Jumper
2011-02-12 18:22:39 -08:00
parent 27a94eb48a
commit fabeca7414

View File

@@ -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);
});
});
};