canvas: batch all canvas operations to optimize perfs
This commit is contained in:
parent
a0040ab488
commit
93d8391b5b
10 changed files with 31 additions and 11 deletions
|
|
@ -1,5 +1,21 @@
|
|||
var _widgets_base = require('./_widgets_base')
|
||||
|
||||
var drawQueue = {},
|
||||
flushDrawQueue = ()=>{
|
||||
for (var h in drawQueue) {
|
||||
drawQueue[h].draw()
|
||||
}
|
||||
drawQueue = {}
|
||||
},
|
||||
drawQueueLoop = ()=>{
|
||||
requestAnimationFrame(flushDrawQueue)
|
||||
setTimeout(drawQueueLoop, 1000 / 60)
|
||||
}
|
||||
|
||||
drawQueueLoop()
|
||||
|
||||
|
||||
|
||||
module.exports = class _canvas_base extends _widgets_base {
|
||||
|
||||
constructor(options) {
|
||||
|
|
@ -80,7 +96,7 @@ module.exports = class _canvas_base extends _widgets_base {
|
|||
this.ctx.textBaseline = "middle"
|
||||
this.ctx.textAlign = this.textAlign
|
||||
|
||||
requestAnimationFrame(this.draw.bind(this))
|
||||
requestAnimationFrame(this.batchDraw.bind(this))
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -102,6 +118,10 @@ module.exports = class _canvas_base extends _widgets_base {
|
|||
|
||||
}
|
||||
|
||||
batchDraw() {
|
||||
drawQueue[this.hash] = this
|
||||
}
|
||||
|
||||
draw(){
|
||||
throw 'Calling unimplemented draw() method'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -172,7 +172,7 @@ module.exports = class Input extends _canvas_base {
|
|||
if (options.sentOnce) options.send = false
|
||||
|
||||
this.stringValue = this.getStringValue()
|
||||
this.draw()
|
||||
this.batchDraw()
|
||||
|
||||
if (options.send && !options.fromSync) this.sendValue()
|
||||
if (options.sync) this.changed(options)
|
||||
|
|
|
|||
|
|
@ -182,7 +182,7 @@ module.exports = class Formula extends _widgets_base {
|
|||
|
||||
if (this.getProp('condition').length && !this.conditionState) {
|
||||
this.input.stringValue = '* ' + this.input.stringValue
|
||||
this.input.draw()
|
||||
this.input.batchDraw()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -228,7 +228,7 @@ module.exports = class MultiXy extends _pads_base {
|
|||
}
|
||||
|
||||
this.updateHandlesPosition()
|
||||
this.draw()
|
||||
this.batchDraw()
|
||||
|
||||
for (var i=0;i<this.npoints * 2;i=i+2) {
|
||||
[this.value[i],this.value[i+1]] = this.pads[i/2].getValue()
|
||||
|
|
|
|||
|
|
@ -179,7 +179,7 @@ module.exports = class Rgb extends _pads_base {
|
|||
}
|
||||
|
||||
|
||||
this.draw()
|
||||
this.batchDraw()
|
||||
|
||||
this.showValue()
|
||||
|
||||
|
|
|
|||
|
|
@ -187,7 +187,7 @@ module.exports = class Xy extends _pads_base {
|
|||
if (options.send) this.sendValue()
|
||||
if (options.sync) this.changed(options)
|
||||
|
||||
this.draw()
|
||||
this.batchDraw()
|
||||
|
||||
this.showValue()
|
||||
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ module.exports = class _plots_base extends _canvas_base {
|
|||
|
||||
if (this.linkedWidgets.indexOf(e.id)==-1 || !widgetManager.getWidgetById(e.id).length) return
|
||||
this.updateData()
|
||||
this.draw()
|
||||
this.batchDraw()
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -153,7 +153,7 @@ module.exports = class _plots_base extends _canvas_base {
|
|||
setValue(v, options={}) {
|
||||
|
||||
this.data = v
|
||||
this.draw()
|
||||
this.batchDraw()
|
||||
|
||||
if (options.sync) this.changed(options)
|
||||
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ module.exports = class Visualizer extends _plots_base {
|
|||
if (Math.floor(this.ticks) > 0) {
|
||||
this.shiftData(Math.floor(this.ticks))
|
||||
this.ticks -= Math.floor(this.ticks)
|
||||
this.draw()
|
||||
this.batchDraw()
|
||||
}
|
||||
|
||||
this.lastUpdate = t
|
||||
|
|
|
|||
|
|
@ -205,7 +205,7 @@ module.exports = class _sliders_base extends _canvas_base {
|
|||
|
||||
if (!options.dragged) this.percent = this.valueToPercent(this.value)
|
||||
|
||||
if (!this.noDraw) this.draw()
|
||||
if (!this.noDraw) this.batchDraw()
|
||||
|
||||
this.showValue()
|
||||
|
||||
|
|
|
|||
|
|
@ -414,7 +414,7 @@ module.exports = class Range extends _widgets_base {
|
|||
if (options.send) this.sendValue()
|
||||
if (options.sync) this.changed(options)
|
||||
|
||||
this.faders[1].draw()
|
||||
this.faders[1].batchDraw()
|
||||
|
||||
this.showValue()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue