Skip to content

Commit ab06124

Browse files
committed
feat: add more debug logging for tracing rendering issues with skia-canvas
1 parent a2b0cc0 commit ab06124

7 files changed

Lines changed: 34 additions & 16 deletions

File tree

packages/input-gateway/src/inputManagerHandler.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,6 @@ export class InputManagerHandler {
138138
}
139139

140140
async initInputManager(settings: DeviceSettings): Promise<void> {
141-
this.#logger.info('Initializing Input Manager with the following settings:')
142-
143141
this.#deviceSettings = settings
144142

145143
this.#inputManager = await this.#createInputManager(settings)

packages/input-manager/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
"fold-to-ascii": "^5.0.1",
9999
"lru-cache": "11.0.2",
100100
"osc": "^2.4.4",
101-
"skia-canvas": "2.0.1",
101+
"skia-canvas": "2.0.2",
102102
"xkeys": "^3.1.1"
103103
},
104104
"peerDependencies": {

packages/input-manager/src/feedback/bitmap/index.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import path from 'path'
55
import fs from 'fs/promises'
66
import { constants as fsConstants } from 'fs'
77
import process from 'process'
8+
import { Logger } from '../../logger'
89

910
async 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+
}

packages/input-manager/src/feedback/bitmap/lib/TextContext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CanvasRenderingContext2D } from 'skia-canvas'
1+
import { CanvasRenderingContext2D, CanvasTextAlign } from 'skia-canvas'
22
import { createFill } from './fill'
33

44
enum TRBLPositions {

packages/input-manager/src/feedback/bitmap/typeRenderers/base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CanvasRenderingContext2D } from 'skia-canvas'
1+
import { CanvasRenderingContext2D, CanvasTextAlign } from 'skia-canvas'
22
import { BitmapStyleProps, Feedback } from '../../feedback'
33
import { TextContext } from '../lib/TextContext'
44
import { GlobalImageCache } from '../lib/ImageCache'

packages/input-manager/src/inputManager.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,18 @@ class InputManager extends EventEmitter<DeviceEvents> {
7272
async init(): Promise<void> {
7373
this.#devices = {}
7474

75-
await initBitmapFeedback()
75+
await initBitmapFeedback(this.#logger.child({ module: 'bitmapFeedback' }))
76+
77+
this.#logger.silly(`Feedback services intialization done`)
7678

7779
await Promise.allSettled(
7880
Object.entries<SomeDeviceConfig>(this.config.devices).map(async ([deviceId, deviceConfig]) =>
7981
this.createDevice(deviceId, deviceConfig ?? {})
8082
)
8183
)
8284

85+
this.#logger.silly(`Device creation done`)
86+
8387
this.#refreshInterval = setInterval(this.refreshDevicesInterval, REFRESH_INTERVAL)
8488
}
8589

yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,7 +1806,7 @@ __metadata:
18061806
fold-to-ascii: "npm:^5.0.1"
18071807
lru-cache: "npm:11.0.2"
18081808
osc: "npm:^2.4.4"
1809-
skia-canvas: "npm:2.0.1"
1809+
skia-canvas: "npm:2.0.2"
18101810
xkeys: "npm:^3.1.1"
18111811
peerDependencies:
18121812
"@sofie-automation/shared-lib": "*"
@@ -10109,17 +10109,17 @@ __metadata:
1010910109
languageName: node
1011010110
linkType: hard
1011110111

10112-
"skia-canvas@npm:2.0.1":
10113-
version: 2.0.1
10114-
resolution: "skia-canvas@npm:2.0.1"
10112+
"skia-canvas@npm:2.0.2":
10113+
version: 2.0.2
10114+
resolution: "skia-canvas@npm:2.0.2"
1011510115
dependencies:
1011610116
"@mapbox/node-pre-gyp": "npm:^1.0.11"
1011710117
cargo-cp-artifact: "npm:^0.1"
1011810118
glob: "npm:^11.0.0"
1011910119
path-browserify: "npm:^1.0.1"
1012010120
simple-get: "npm:^4.0.1"
1012110121
string-split-by: "npm:^1.0.0"
10122-
checksum: 10/d1bc96fa1c9870af7be8ab3ce2896102602b071919e7e6fb165714fd00c27535e413fb16241f0b0727b8c88877df5b9373a856bf0f4bebf218ecbec797904830
10122+
checksum: 10/1811540520da10b008a5a14690c3eadd89ac691691808a87c0ed05d3dda3d191acd7cad505a0bad67e228cab7b832d0e452994992fb5cdaf96542c1c3c1bde40
1012310123
languageName: node
1012410124
linkType: hard
1012510125

0 commit comments

Comments
 (0)