@@ -664,6 +664,22 @@ export class CompositorViewService {
664664 ) ;
665665 }
666666
667+ private scaleLinuxPreviewRect ( rect : CompositorViewRect ) : CompositorViewRect {
668+ if ( process . platform !== "linux" ) {
669+ return rect ;
670+ }
671+ const maxDim = Number ( process . env . OPENSCREEN_LINUX_PREVIEW_MAX_DIM ) || 854 ;
672+ if ( maxDim <= 0 || ( rect . width <= maxDim && rect . height <= maxDim ) ) {
673+ return rect ;
674+ }
675+ const scale = maxDim / Math . max ( rect . width , rect . height ) ;
676+ return {
677+ ...rect ,
678+ width : Math . max ( 2 , Math . round ( ( rect . width * scale ) / 2 ) * 2 ) ,
679+ height : Math . max ( 2 , Math . round ( ( rect . height * scale ) / 2 ) * 2 ) ,
680+ } ;
681+ }
682+
667683 /** Allocates an offscreen compositor view sized to `rect.width`x`rect.height`.
668684 * `rect.x` / `rect.y` are vestigial (ignored native-side) — the renderer
669685 * keeps them on the wire so the existing `CompositorViewRect` shape stays
@@ -673,6 +689,7 @@ export class CompositorViewService {
673689 rect : CompositorViewRect ,
674690 paths ?: { screenPath ?: string ; webcamPath ?: string ; cursorPath ?: string } ,
675691 ) : number {
692+ const scaledRect = this . scaleLinuxPreviewRect ( rect ) ;
676693 const addon = this . ensureAddon ( ) ;
677694 if ( ! addon ) {
678695 // synthetic negative ids let callers do bookkeeping
@@ -681,11 +698,16 @@ export class CompositorViewService {
681698 // stay independent.
682699 this . syntheticIdCounter -= 1 ;
683700 const id = this . syntheticIdCounter ;
684- this . rects . set ( id , rect ) ;
701+ this . rects . set ( id , scaledRect ) ;
685702 return id ;
686703 }
687- const id = addon . createView ( rect , paths ?. screenPath , paths ?. webcamPath , paths ?. cursorPath ) ;
688- this . rects . set ( id , rect ) ;
704+ const id = addon . createView (
705+ scaledRect ,
706+ paths ?. screenPath ,
707+ paths ?. webcamPath ,
708+ paths ?. cursorPath ,
709+ ) ;
710+ this . rects . set ( id , scaledRect ) ;
689711 this . shareFrames ( addon , id ) ;
690712 return id ;
691713 }
@@ -722,12 +744,13 @@ export class CompositorViewService {
722744 }
723745
724746 setRect ( id : number , rect : CompositorViewRect ) : void {
747+ const scaledRect = this . scaleLinuxPreviewRect ( rect ) ;
725748 const addon = this . ensureAddon ( ) ;
726- this . rects . set ( id , rect ) ;
749+ this . rects . set ( id , scaledRect ) ;
727750 if ( ! addon ) {
728751 return ;
729752 }
730- addon . setRect ( id , rect ) ;
753+ addon . setRect ( id , scaledRect ) ;
731754 }
732755
733756 /** Reads the most recently rendered frame for `id`, but only if its generation is newer
0 commit comments