Fix for the performance regression in the updated batchDraw()

The code was checking the "waiting" flags, but they were not set.
This patch corrects that part and makes a few other tweaks to the
updated logic on top of requestAnimationFrame().
This commit is contained in:
VladimirTechMan
2019-02-02 20:17:27 +03:00
parent 31785f6323
commit 09bfaab9f2
2 changed files with 12 additions and 16 deletions

View File

@@ -249,13 +249,13 @@ export abstract class BaseLayer extends Container {
* @return {Konva.Layer} this
*/
batchDraw() {
if (this._waitingForDraw) {
return;
if (!this._waitingForDraw) {
this._waitingForDraw = true;
Util.requestAnimFrame(() => {
this.draw();
this._waitingForDraw = false;
});
}
Util.requestAnimFrame(() => {
this._waitingForDraw = false;
this.draw();
});
return this;
}

View File

@@ -542,20 +542,16 @@ export const Util = {
return -1;
}
},
_waiting: false,
animQueue: [],
requestAnimFrame(callback) {
Util.animQueue.push(callback);
if (Util._waiting) {
return;
}
requestAnimationFrame(() => {
Util.animQueue.forEach(cb => {
cb();
if (Util.animQueue.length === 1) {
requestAnimationFrame(function () {
const queue = Util.animQueue;
Util.animQueue = [];
queue.forEach(function (cb) { cb(); });
});
Util.animQueue = [];
Util._waiting = false;
});
}
},
createCanvasElement() {
var canvas = isBrowser