Repository navigation
perf(linux): cap compositor preview readback dimensions #1487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -664,6 +664,27 @@ export class CompositorViewService { | |
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Proportionally scales a Linux preview rectangle down so its largest side | ||
| * does not exceed `OPENSCREEN_LINUX_PREVIEW_MAX_DIM` (default 854 px), | ||
| * rounding dimensions down to even numbers. | ||
| */ | ||
| private scaleLinuxPreviewRect(rect: CompositorViewRect): CompositorViewRect { | ||
| if (process.platform !== "linux") { | ||
| return rect; | ||
| } | ||
| const maxDim = Number(process.env.OPENSCREEN_LINUX_PREVIEW_MAX_DIM) || 854; | ||
| if (maxDim < 2 || (rect.width <= maxDim && rect.height <= maxDim)) { | ||
| return rect; | ||
| } | ||
| const scale = maxDim / Math.max(rect.width, rect.height); | ||
| return { | ||
| ...rect, | ||
| width: Math.max(2, Math.floor((rect.width * scale) / 2) * 2), | ||
| height: Math.max(2, Math.floor((rect.height * scale) / 2) * 2), | ||
|
Comment on lines
+683
to
+684
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| }; | ||
| } | ||
|
|
||
| /** Allocates an offscreen compositor view sized to `rect.width`x`rect.height`. | ||
| * `rect.x` / `rect.y` are vestigial (ignored native-side) — the renderer | ||
| * keeps them on the wire so the existing `CompositorViewRect` shape stays | ||
|
|
@@ -673,6 +694,7 @@ export class CompositorViewService { | |
| rect: CompositorViewRect, | ||
| paths?: { screenPath?: string; webcamPath?: string; cursorPath?: string }, | ||
| ): number { | ||
| const scaledRect = this.scaleLinuxPreviewRect(rect); | ||
| const addon = this.ensureAddon(); | ||
| if (!addon) { | ||
| // synthetic negative ids let callers do bookkeeping | ||
|
|
@@ -681,11 +703,16 @@ export class CompositorViewService { | |
| // stay independent. | ||
| this.syntheticIdCounter -= 1; | ||
| const id = this.syntheticIdCounter; | ||
| this.rects.set(id, rect); | ||
| this.rects.set(id, scaledRect); | ||
| return id; | ||
| } | ||
| const id = addon.createView(rect, paths?.screenPath, paths?.webcamPath, paths?.cursorPath); | ||
| this.rects.set(id, rect); | ||
| const id = addon.createView( | ||
| scaledRect, | ||
| paths?.screenPath, | ||
| paths?.webcamPath, | ||
| paths?.cursorPath, | ||
| ); | ||
| this.rects.set(id, scaledRect); | ||
| this.shareFrames(addon, id); | ||
| return id; | ||
| } | ||
|
|
@@ -721,13 +748,15 @@ export class CompositorViewService { | |
| this.ensureAddon()?.setSharedFrames?.(id, false); | ||
| } | ||
|
|
||
| /** Updates the offscreen compositor view dimensions for `id`. */ | ||
| setRect(id: number, rect: CompositorViewRect): void { | ||
| const scaledRect = this.scaleLinuxPreviewRect(rect); | ||
| const addon = this.ensureAddon(); | ||
| this.rects.set(id, rect); | ||
| this.rects.set(id, scaledRect); | ||
| if (!addon) { | ||
| return; | ||
| } | ||
| addon.setRect(id, rect); | ||
| addon.setRect(id, scaledRect); | ||
| } | ||
|
|
||
| /** Reads the most recently rendered frame for `id`, but only if its generation is newer | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: getopenscreen/openscreen
Length of output: 1146
Script executed:
Repository: getopenscreen/openscreen
Length of output: 12572
Script executed:
Repository: getopenscreen/openscreen
Length of output: 19127
Script executed:
Repository: getopenscreen/openscreen
Length of output: 32890
Script executed:
Repository: getopenscreen/openscreen
Length of output: 18016
Fall back to the default for invalid preview limits.
If
OPENSCREEN_LINUX_PREVIEW_MAX_DIMis-1, this guard returns the original rectangle. Large Linux previews can then use uncapped readback and IPC transfers during playback or scrubbing. Use the default limit when the configured value is non-finite or less than 2.