Skip to content

Commit

Permalink
feat: add optional external canvas for rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterlucas committed Dec 11, 2024
1 parent 7b9353f commit a38f216
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/main-api/Renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,15 @@ export interface RendererMainSettings {
* @defaultValue `true`
*/
strictBounds?: boolean;

/**
* Canvas object to use for rendering
*
* @remarks
* This is used to render the scene graph. If not provided, a new canvas
* element will be created and appended to the target element.
*/
canvas?: HTMLCanvasElement;
}

/**
Expand Down Expand Up @@ -358,6 +367,7 @@ export class RendererMain extends EventEmitter {
quadBufferSize: settings.quadBufferSize ?? 4 * 1024 * 1024,
fontEngines: settings.fontEngines,
strictBounds: settings.strictBounds ?? true,
canvas: settings.canvas || document.createElement('canvas'),
};
this.settings = resolvedSettings;

Expand All @@ -367,12 +377,12 @@ export class RendererMain extends EventEmitter {
deviceLogicalPixelRatio,
devicePhysicalPixelRatio,
inspector,
canvas,
} = resolvedSettings;

const deviceLogicalWidth = appWidth * deviceLogicalPixelRatio;
const deviceLogicalHeight = appHeight * deviceLogicalPixelRatio;

const canvas = document.createElement('canvas');
this.canvas = canvas;
canvas.width = deviceLogicalWidth * devicePhysicalPixelRatio;
canvas.height = deviceLogicalHeight * devicePhysicalPixelRatio;
Expand Down

0 comments on commit a38f216

Please sign in to comment.