Skip to content

Commit

Permalink
willReadFrequently
Browse files Browse the repository at this point in the history
  • Loading branch information
frank-weindel committed Jul 3, 2024
1 parent fa4127c commit 94a56e8
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/core/text-rendering/renderers/CanvasTextRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,17 @@ export class CanvasTextRenderer extends TextRenderer<CanvasTextRendererState> {
this.canvas = document.createElement('canvas');
}
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
let context = this.canvas.getContext('2d') as
| OffscreenCanvasRenderingContext2D
| CanvasRenderingContext2D
| null;
let context = this.canvas.getContext('2d', {
willReadFrequently: true,
}) as OffscreenCanvasRenderingContext2D | CanvasRenderingContext2D | null;
if (!context) {
// A browser may appear to support OffscreenCanvas but not actually support the Canvas '2d' context
// Here we try getting the context again after falling back to an HTMLCanvasElement.
// See: https://github.com/lightning-js/renderer/issues/26#issuecomment-1750438486
this.canvas = document.createElement('canvas');
context = this.canvas.getContext('2d');
context = this.canvas.getContext('2d', {
willReadFrequently: true,
});
}
assertTruthy(context);
this.context = context;
Expand Down

0 comments on commit 94a56e8

Please sign in to comment.