Skip to content

Commit cfe035e

Browse files
authored
feat: add optional external canvas for rendering (#471)
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
2 parents 6f8e057 + a38f216 commit cfe035e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/main-api/Renderer.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,15 @@ export interface RendererMainSettings {
267267
* @defaultValue `true`
268268
*/
269269
strictBounds?: boolean;
270+
271+
/**
272+
* Canvas object to use for rendering
273+
*
274+
* @remarks
275+
* This is used to render the scene graph. If not provided, a new canvas
276+
* element will be created and appended to the target element.
277+
*/
278+
canvas?: HTMLCanvasElement;
270279
}
271280

272281
/**
@@ -358,6 +367,7 @@ export class RendererMain extends EventEmitter {
358367
quadBufferSize: settings.quadBufferSize ?? 4 * 1024 * 1024,
359368
fontEngines: settings.fontEngines,
360369
strictBounds: settings.strictBounds ?? true,
370+
canvas: settings.canvas || document.createElement('canvas'),
361371
};
362372
this.settings = resolvedSettings;
363373

@@ -367,12 +377,12 @@ export class RendererMain extends EventEmitter {
367377
deviceLogicalPixelRatio,
368378
devicePhysicalPixelRatio,
369379
inspector,
380+
canvas,
370381
} = resolvedSettings;
371382

372383
const deviceLogicalWidth = appWidth * deviceLogicalPixelRatio;
373384
const deviceLogicalHeight = appHeight * deviceLogicalPixelRatio;
374385

375-
const canvas = document.createElement('canvas');
376386
this.canvas = canvas;
377387
canvas.width = deviceLogicalWidth * devicePhysicalPixelRatio;
378388
canvas.height = deviceLogicalHeight * devicePhysicalPixelRatio;

0 commit comments

Comments
 (0)