// Platform description. Replaces `tycho_window.Platform`, which could only name
// three operating systems and could not express "Linux but headless" or
// "Linux but KMS".
#derive(Eq, Debug)
pub(all) enum Os {
Linux
Windows
MacOS
Android
IOS
Web
}
#derive(Eq, Debug)
pub(all) enum WindowSystem {
X11
Wayland
Xcb
Win32
Cocoa
UIKit
Android
Canvas
Headless
}
#derive(Eq, Debug)
pub(all) enum SurfaceKind {
Xlib
Xcb
Wayland
Win32
Metal
Android
CanvasGpu
Headless
}
#derive(Eq, Debug)
pub(all) struct Target {
os : Os
window_system : WindowSystem
}
fn os_of(code : Int) -> Os {
match code {
1 => Windows
2 => MacOS
3 => Android
4 => IOS
5 => Web
_ => Linux
}
}
fn window_system_of(code : Int) -> WindowSystem {
match code {
1 => Wayland
2 => Win32
3 => Cocoa
4 => UIKit
5 => Android
6 => Canvas
7 => Headless
_ => X11
}
}
///|
/// The target this binary is running on, as reported by the backend.
pub fn Target::current() -> Target {
{
os: os_of(@be.backend_plat_os()),
window_system: window_system_of(@be.backend_plat_window_system()),
}
}
///|
/// Whether a Vulkan surface can exist here at all. Web has no Vulkan loader.
pub fn Target::supports_vulkan(self : Target) -> Bool {
self.os != Os::Web
}
///|
/// Whether Direct3D 12 can exist on this OS.
pub fn Target::supports_dx12(self : Target) -> Bool {
self.os == Os::Windows
}
///|
/// Whether Apple Metal can exist on this OS (macOS / iOS).
pub fn Target::supports_metal(self : Target) -> Bool {
self.os == Os::MacOS || self.os == Os::IOS
}
///|
/// Whether WebGPU (browser or wgpu-native / Dawn) is part of the target matrix.
pub fn Target::supports_webgpu(self : Target) -> Bool {
self.os != Os::Android && self.os != Os::IOS
}
///|
/// Whether this target is a mobile OS (iOS / Android) with host-driven
/// lifecycle and touch input.
pub fn Target::is_mobile(self : Target) -> Bool {
self.os == Os::IOS || self.os == Os::Android
}
///|
/// Whether the OS owns the render surface (`CAMetalLayer` on iOS,
/// `ANativeWindow` on Android) rather than the engine creating a desktop window.
pub fn Target::uses_external_surface(self : Target) -> Bool {
self.os == Os::IOS || self.os == Os::Android
}
///|
pub fn Os::name(self : Os) -> String {
match self {
Linux => "linux"
Windows => "windows"
MacOS => "macos"
Android => "android"
IOS => "ios"
Web => "web"
}
}
///|
pub fn WindowSystem::name(self : WindowSystem) -> String {
match self {
X11 => "x11"
Wayland => "wayland"
Xcb => "xcb"
Win32 => "win32"
Cocoa => "cocoa"
UIKit => "uikit"
Android => "android"
Canvas => "canvas"
Headless => "headless"
}
}