UNPKG

@visactor/vrender-core

Version:

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

59 lines (56 loc) 2.13 kB
import { wrapCanvas } from "../../../canvas/util"; import { application } from "../../../application"; export class OffscreenLayerHandlerContribution { constructor() { this.offscreen = !0, this.type = "dynamic", this.global = 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 = 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) {} } //# sourceMappingURL=offscreen2d-contribution.js.map