Skip to content

Commit

Permalink
feat: add optional external canvas for rendering (#471)
Browse files Browse the repository at this point in the history
This is used to already create a canvas object and render a logo, pass
this on to Lightning and it will be overwritten once the app comes up
  • Loading branch information
wouterlucas authored Dec 17, 2024
2 parents 6f8e057 + a38f216 commit cfe035e
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 cfe035e

Please sign in to comment.