@visactor/vrender-core
Version:
## Description
57 lines (52 loc) • 3.14 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: !0
}), exports.IncrementalAutoRenderPlugin = void 0;
const application_1 = require("../../application"), generator_1 = require("../../common/generator");
class IncrementalAutoRenderPlugin {
constructor() {
this.name = "IncrementalAutoRenderPlugin", this.activeEvent = "onRegister", this.nextFrameRenderGroupSet = new Set,
this.willNextFrameRender = !1, this.nextUserParams = {}, this._uid = generator_1.Generator.GenAutoIncrementId(),
this.key = this.name + this._uid;
}
activate(context) {
this.pluginService = context, application_1.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_1.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_1.application.graphicService.hooks.onAddIncremental.taps = application_1.application.graphicService.hooks.onAddIncremental.taps.filter((item => item.name !== this.key)),
application_1.application.graphicService.hooks.onClearIncremental.taps = application_1.application.graphicService.hooks.onClearIncremental.taps.filter((item => item.name !== this.key));
}
renderNextFrame(group) {
this.nextFrameRenderGroupSet.add(group), this.willNextFrameRender || (this.willNextFrameRender = !0,
application_1.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());
}
}
exports.IncrementalAutoRenderPlugin = IncrementalAutoRenderPlugin;
//# sourceMappingURL=incremental-auto-render-plugin.js.map