(width: f64, height: f64, title_ptr: *const u8, fullscreen: f64)
| 249 | |
| 250 | #[no_mangle] |
| 251 | pub extern "C" fn bloom_init_window(width: f64, height: f64, title_ptr: *const u8, fullscreen: f64) { |
| 252 | let title = str_from_header(title_ptr); |
| 253 | let mtm = MainThreadMarker::from(unsafe { MainThreadMarker::new_unchecked() }); |
| 254 | |
| 255 | // Headless mode: BLOOM_HEADLESS=1 keeps the NSWindow + CAMetalLayer |
| 256 | // alive (wgpu's Metal backend requires a CAMetalLayer-backed view) |
| 257 | // but hides the window and suppresses dock icon / focus. Needed |
| 258 | // so an agent can spin up the renderer in a batch loop without |
| 259 | // stealing the user's focus on every sample. |
| 260 | let headless = std::env::var("BLOOM_HEADLESS") |
| 261 | .map(|v| v == "1" || v.eq_ignore_ascii_case("true")) |
| 262 | .unwrap_or(false); |
| 263 | unsafe { HEADLESS = headless; } |
| 264 | |
| 265 | let app = NSApplication::sharedApplication(mtm); |
| 266 | if headless { |
| 267 | // Prohibited = no dock icon, no menu bar, no activation. |
| 268 | app.setActivationPolicy(NSApplicationActivationPolicy::Prohibited); |
| 269 | } else { |
| 270 | app.setActivationPolicy(NSApplicationActivationPolicy::Regular); |
| 271 | } |
| 272 | |
| 273 | // Far-off-screen origin keeps the window out of every display |
| 274 | // even if the OS insists on showing something. |
| 275 | let origin_x = if headless { -20000.0 } else { 100.0 }; |
| 276 | let content_rect = NSRect::new(NSPoint::new(origin_x, 100.0), NSSize::new(width, height)); |
| 277 | let style = NSWindowStyleMask::Titled |
| 278 | | NSWindowStyleMask::Closable |
| 279 | | NSWindowStyleMask::Miniaturizable |
| 280 | | NSWindowStyleMask::Resizable; |
| 281 | |
| 282 | let window = unsafe { |
| 283 | NSWindow::initWithContentRect_styleMask_backing_defer( |
| 284 | NSWindow::alloc(mtm), |
| 285 | content_rect, |
| 286 | style, |
| 287 | objc2_app_kit::NSBackingStoreType(2), // NSBackingStoreBuffered |
| 288 | false, |
| 289 | ) |
| 290 | }; |
| 291 | |
| 292 | let ns_title = NSString::from_str(title); |
| 293 | window.setTitle(&ns_title); |
| 294 | |
| 295 | // Don't persist window size/fullscreen state across launches. |
| 296 | // NSWindow restoration was resurrecting a prior fullscreen toggle on |
| 297 | // the 4K display, which silently rendered benchmarks at 4× the |
| 298 | // requested pixel count. |
| 299 | unsafe { let _: () = msg_send![&window, setRestorable: false]; } |
| 300 | |
| 301 | // BLOOM_NO_FULLSCREEN=1 hard-disables fullscreen capability: the |
| 302 | // window cannot be entered into fullscreen via the green button, |
| 303 | // cmd-ctrl-F, or inheriting a fullscreen Space from the launching |
| 304 | // terminal. Intended for benchmark harnesses where the 4K-display |
| 305 | // fullscreen path would otherwise silently quadruple render cost. |
| 306 | let no_fullscreen = std::env::var("BLOOM_NO_FULLSCREEN") |
| 307 | .map(|v| v == "1" || v.eq_ignore_ascii_case("true")) |
| 308 | .unwrap_or(false); |
nothing calls this directly
no test coverage detected