@@ -9,7 +9,7 @@ import RuntimeMetrics from './RuntimeMetrics.js';
99import FrameClock from './FrameClock.js' ;
1010import FixedTicker from './FixedTicker.js' ;
1111import EventBus from '../events/EventBus.js' ;
12- import { backgroundImage , fullscreenBezel , FullscreenService } from '../runtime/index.js' ;
12+ import { backgroundImage , fullscreenBezel , FullscreenService , resolvePreferredFullscreenTarget } from '../runtime/index.js' ;
1313import { AudioService } from '../audio/index.js' ;
1414import { Logger } from '../logging/index.js' ;
1515import { SettingsSystem } from '../release/index.js' ;
@@ -41,6 +41,11 @@ export default class Engine {
4141 this . canvas . height = height ;
4242
4343 this . renderer = new CanvasRenderer ( this . ctx ) ;
44+ this . documentRef = globalThis . document ?? null ;
45+ this . fullscreenTarget = resolvePreferredFullscreenTarget ( {
46+ canvas,
47+ documentRef : this . documentRef ,
48+ } ) || canvas ;
4449 this . input = input ;
4550 this . events = events || new EventBus ( ) ;
4651 this . metrics = metrics || new RuntimeMetrics ( ) ;
@@ -50,15 +55,16 @@ export default class Engine {
5055 maxCatchUpSteps : Number . POSITIVE_INFINITY ,
5156 } ) ;
5257 this . fullscreen = fullscreen || FullscreenService . fromBrowser ( {
53- documentRef : globalThis . document ?? null ,
54- target : canvas ,
58+ documentRef : this . documentRef ,
59+ target : this . fullscreenTarget ,
5560 } ) ;
5661 this . backgroundImageLayer = backgroundImageLayer || new backgroundImage ( {
57- documentRef : globalThis . document ?? null
62+ documentRef : this . documentRef
5863 } ) ;
5964 this . fullscreenBezelLayer = fullscreenBezelLayer || new fullscreenBezel ( {
6065 canvas,
61- documentRef : globalThis . document ?? null
66+ host : this . fullscreenTarget ,
67+ documentRef : this . documentRef
6268 } ) ;
6369 this . audio = audio || new AudioService ( ) ;
6470 this . logger = logger || new Logger ( { channel : 'engine' } ) ;
@@ -105,10 +111,15 @@ export default class Engine {
105111 this . audio . attach ( this . canvas ) ;
106112 }
107113 if ( this . fullscreen && typeof this . fullscreen . attach === 'function' ) {
108- this . fullscreen . attach ( this . canvas ) ;
114+ this . fullscreen . attach ( this . fullscreenTarget ) ;
109115 }
110116 if ( this . fullscreenBezelLayer && typeof this . fullscreenBezelLayer . attach === 'function' ) {
111117 this . fullscreenBezelLayer . attach ( ) ;
118+ const fullscreenActive = this . fullscreen ?. getState ?. ( ) . active === true ;
119+ const fullscreenElement = this . fullscreen ?. documentRef ?. fullscreenElement
120+ || this . documentRef ?. fullscreenElement
121+ || null ;
122+ this . fullscreenBezelLayer . sync ( { fullscreenActive, fullscreenElement } ) ;
112123 }
113124
114125 this . frameClock . reset ( ) ;
@@ -161,12 +172,15 @@ export default class Engine {
161172
162173 const renderStart = performance . now ( ) ;
163174 this . renderer . clear ( ) ;
164- this . backgroundImageLayer ?. render ?. ( this . renderer ) ;
175+ this . backgroundImageLayer ?. render ?. ( this . renderer , { scene : this . scene , engine : this } ) ;
165176 if ( this . scene && typeof this . scene . render === 'function' ) {
166177 this . scene . render ( this . renderer , this ) ;
167178 }
168179 const fullscreenActive = this . fullscreen ?. getState ?. ( ) . active === true ;
169- this . fullscreenBezelLayer ?. sync ?. ( { fullscreenActive } ) ;
180+ const fullscreenElement = this . fullscreen ?. documentRef ?. fullscreenElement
181+ || this . documentRef ?. fullscreenElement
182+ || null ;
183+ this . fullscreenBezelLayer ?. sync ?. ( { fullscreenActive, fullscreenElement } ) ;
170184 renderDurationMs = performance . now ( ) - renderStart ;
171185
172186 this . metrics . recordFrame ( {
0 commit comments