UNPKG

@visactor/vrender-core

Version:
51 lines (48 loc) 2.85 kB
import { application } from "../../application"; import { Generator } from "../../common/generator"; export class IncrementalAutoRenderPlugin { constructor() { this.name = "IncrementalAutoRenderPlugin", this.activeEvent = "onRegister", this.nextFrameRenderGroupSet = new Set, this.willNextFrameRender = !1, this.nextUserParams = {}, this._uid = Generator.GenAutoIncrementId(), this.key = this.name + this._uid; } activate(context) { this.pluginService = context, application.graphicService.hooks.onAddIncremental.tap(this.key, ((graphic, group, stage) => { graphic.glyphHost && (graphic = graphic.glyphHost), graphic.stage === context.stage && null != graphic.stage && (this.nextUserParams.startAtId = group._uid, this.renderNextFrame(group)); })), application.graphicService.hooks.onClearIncremental.tap(this.key, ((group, stage) => { group.stage === context.stage && null != group.stage && (this.nextUserParams.startAtId = group._uid, this.nextUserParams.restartIncremental = !0, this.renderNextFrame(group)); })); } deactivate(context) { application.graphicService.hooks.onAddIncremental.taps = application.graphicService.hooks.onAddIncremental.taps.filter((item => item.name !== this.key)), application.graphicService.hooks.onClearIncremental.taps = application.graphicService.hooks.onClearIncremental.taps.filter((item => item.name !== this.key)); } renderNextFrame(group) { this.nextFrameRenderGroupSet.add(group), this.willNextFrameRender || (this.willNextFrameRender = !0, application.global.getRequestAnimationFrame()((() => { this._doRenderInThisFrame(), this.willNextFrameRender = !1; }))); } _doRenderInThisFrame() { const stage = this.pluginService.stage; this.nextFrameRenderGroupSet.size && (this.nextFrameRenderGroupSet.forEach((group => { const layer = group.layer; if (!layer || !group.layer.subLayers) return; const subLayer = group.layer.subLayers.get(group._uid); subLayer && subLayer.drawContribution && subLayer.drawContribution.draw(stage.renderService, Object.assign({ stage: stage, layer: layer, viewBox: stage.window.getViewBox(), transMatrix: stage.window.getViewBoxTransform(), clear: "transparent", renderService: stage.renderService, updateBounds: !1, startAtId: group._uid, context: subLayer.layer.getNativeHandler().getContext() }, this.nextUserParams)); })), this.nextUserParams = {}, this.nextFrameRenderGroupSet.clear()); } } //# sourceMappingURL=incremental-auto-render-plugin.js.map