UNPKG

@visactor/vrender-core

Version:

```typescript import { xxx } from '@visactor/vrender-core'; ```

65 lines (60 loc) 2.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: !0 }), exports.OffscreenLayerHandlerContribution = void 0; const util_1 = require("../../../canvas/util"), application_1 = require("../../../application"); class OffscreenLayerHandlerContribution { constructor() { this.offscreen = !0, this.type = "dynamic", this.global = application_1.application.global; } setDpr(dpr) { this.canvas.dpr = dpr; } init(layer, window, params) { this.layer = layer; const nativeCanvas = this.global.createOffscreenCanvas({ width: params.width, height: params.height, dpr: window.dpr }), canvas = (0, util_1.wrapCanvas)({ nativeCanvas: nativeCanvas, width: params.width, height: params.height, dpr: window.dpr, canvasControled: !0 }); this.canvas = canvas, this.context = canvas.getContext(); } resize(w, h) { this.canvas.resize(w, h); } resizeView(w, h) { this.canvas.resize(w, h); } render(group, params) { var _a; params.renderService.render(group, Object.assign(Object.assign({ context: this.context, viewBox: params.stage.window.getViewBox(), transMatrix: params.stage.window.getViewBoxTransform() }, params), { clear: null !== (_a = params.background) && void 0 !== _a ? _a : "#ffffff" })); } prepare(dirtyBounds, params) {} release() { this.canvas.release(); } getContext() { return this.context; } drawTo(target, group, params) { const context = target.getContext(), targetDpr = target.dpr, {viewBox: viewBox} = params, x = viewBox.x1, y = viewBox.y1, width = viewBox.width(), height = viewBox.height(); context.nativeContext.save(), context.nativeContext.setTransform(targetDpr, 0, 0, targetDpr, 0, 0), params.clear && context.clearRect(x, y, width, height), context.drawImage(this.canvas.nativeCanvas, 0, 0, this.canvas.width, this.canvas.height, x, y, width, height), context.nativeContext.restore(); } merge(layerHandlers) {} } exports.OffscreenLayerHandlerContribution = OffscreenLayerHandlerContribution; //# sourceMappingURL=offscreen2d-contribution.js.map