@@ -5,15 +5,15 @@ import path from 'path'
55import fs from 'fs/promises'
66import { constants as fsConstants } from 'fs'
77import process from 'process'
8+ import { Logger } from '../../logger'
89
910async function makeBitmapFromFeedback (
1011 feedback : SomeBitmapFeedback ,
1112 width : number ,
1213 height : number ,
1314 isPressed : boolean
1415) : Promise < Buffer > {
15- const canvas = new Canvas ( width , height )
16- const ctx = canvas . getContext ( '2d' )
16+ const { ctx } = createCanvasAndContext ( )
1717
1818 ctx . fillStyle = 'black'
1919 ctx . fillRect ( 0 , 0 , width , height )
@@ -47,10 +47,12 @@ export async function getBitmap(
4747 return bitmap
4848}
4949
50- export async function init ( ) : Promise < void > {
50+ export async function init ( logger : Logger ) : Promise < void > {
5151 // Create a canvas, just to boot up Skia, load the fonts, etc.
52- const canvas = new Canvas ( )
53- const ctx = canvas . getContext ( '2d' )
52+ const { canvas, ctx } = createCanvasAndContext ( )
53+ logger . silly (
54+ `skia-canvas initialized, using GPU: ${ canvas . gpu } , engine info: ${ JSON . stringify ( ( canvas as any ) . engine ) } `
55+ )
5456
5557 const fonts = [ 'roboto-condensed-regular.ttf' , 'roboto-condensed-700.ttf' ]
5658
@@ -61,8 +63,10 @@ export async function init(): Promise<void> {
6163 ]
6264
6365 const foundFiles = await findFiles ( fonts , searchPaths )
66+ logger . silly ( `Found ${ foundFiles . length } fonts to be loaded` )
6467
6568 FontLibrary . use ( 'RobotoCnd' , foundFiles )
69+ logger . silly ( 'Fonts loaded into FontLibrary' )
6670
6771 void canvas , ctx
6872}
@@ -85,3 +89,15 @@ async function findFiles(files: string[], paths: string[]): Promise<string[]> {
8589
8690 return result
8791}
92+
93+ function createCanvasAndContext ( width ?: number , height ?: number ) {
94+ const canvas = new Canvas ( width , height )
95+
96+ if ( process . env [ 'SKIA_CANVAS_DISABLE_GPU' ] === '1' ) {
97+ canvas . gpu = false
98+ }
99+
100+ const ctx = canvas . getContext ( '2d' )
101+
102+ return { canvas, ctx }
103+ }
0 commit comments