std::graphics::window
Source: std/graphics/window.slk
std::graphics::window is the provider-neutral graphics helper for rendering
into a std::window handle. It exists above the raw graphics bindings so
applications can request a simple visible rendering path without naming the
active platform graphics provider directly.
The implementation routes macOS window clears through
std::graphics::metal. Unsupported targets return explicit errors and do not
require Metal, QuartzCore, AppKit, GTK, Vulkan, or OpenGL linkage through this
module unless a future provider is added and reached.
Exported API#
module std::graphics::window;
import std::graphics::metal;
import std::result;
import std::window;
export enum Backend {
Unsupported,
Metal,
}
export enum RenderErrorKind {
UnsupportedPlatform,
InvalidWindow,
RuntimeFailed,
}
export error RenderFailed { code: int }
impl RenderFailed {
public fn kind (self: &RenderFailed) -> RenderErrorKind;
}
export struct ClearColor {
red: f64,
green: f64,
blue: f64,
alpha: f64,
}
export type RenderResult = std::result::Result(bool, RenderFailed);
export fn failed (kind: RenderErrorKind) -> RenderFailed;
export fn backend () -> Backend;
export fn is_supported () -> bool;
export fn clear (window: std::window::Window, color: ClearColor) -> RenderResult;
Semantics#
backend()returnsBackend::Metalon macOS while the Metal facade is the selected provider; otherwise it returnsBackend::Unsupported.is_supported()returns whetherbackend()is notUnsupported.clear(...)requires a non-zerostd::window::Windowhandle from the active window provider.- On macOS,
clear(...)callsstd::graphics::metal::clear(...), which is implemented through the MetalContext/Framepath. The runtime derives the current AppKit content-view size and backing scale before configuring theCAMetalLayerdrawable size, with a fallback to the requested logical size stored in thestd::window::Windowvalue. - Unsupported targets return
Err(UnsupportedPlatform).
Example#
examples/std_macos_metal_window.slk uses std::window plus
std::graphics::window to run a stdlib-owned window loop and clear each frame
through the active graphics provider. On current macOS builds that provider is
Metal.
Source repository · Edit this page · View Markdown