@shopify/react-native-skia
Version:
High-performance React Native Graphics using Skia
46 lines (36 loc) • 1.22 kB
JavaScript
import { Host } from "./Host";
import { JsiSkSurface } from "./JsiSkSurface";
export class JsiSkSurfaceFactory extends Host {
constructor(CanvasKit) {
super(CanvasKit);
}
Make(width, height) {
const surface = this.CanvasKit.MakeSurface(width, height);
if (!surface) {
return null;
}
return new JsiSkSurface(this.CanvasKit, surface);
}
MakeOffscreen(width, height) {
// OffscreenCanvas may be unvailable in some environments.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const OC = globalThis.OffscreenCanvas;
let surface;
if (OC === undefined) {
surface = this.CanvasKit.MakeSurface(width, height);
} else {
const offscreen = new OC(width, height);
const webglContext = this.CanvasKit.GetWebGLContext(offscreen);
const grContext = this.CanvasKit.MakeWebGLContext(webglContext);
if (!grContext) {
throw new Error("Could not make a graphics context");
}
surface = this.CanvasKit.MakeRenderTarget(grContext, width, height);
}
if (!surface) {
return null;
}
return new JsiSkSurface(this.CanvasKit, surface);
}
}
//# sourceMappingURL=JsiSkSurfaceFactory.js.map