kagura_platform

    Backend-agnostic windowing/platform contracts for Kagura (PlatformDriver trait, surface tokens, native/web hook injection points; extracted from kagura_engine)

    Download zip
    Author
    Version
    0.6.0
    License
    Apache-2.0
    Last updated
    15 days ago
    Downloads
    19

    Dependencies

    #mizchi/kagura_platform

    services/ defines injectable clocks, file access and frame scheduling; fetch/ defines byte loading and the cancellable BytesFetcher contract. They have no browser/OS FFI or graphics-device lifetime. Runtime integrations install implementations before constructing application state.

    各プラットフォーム実装が従う共通 contract。platform/ 直下を独立した MoonBit module として配布します。OS・DOM・GPU API を直接呼びません。

    • PlatformDriver: 初期化、イベント、入力、ウィンドウ状態の契約。 pub(open) とし、別 module でも実装できるようにします。
    • WindowOptions / MonitorInfo / cursor・fullscreen の状態: 共通 API の型。
    • WebCanvasHooks / DesktopNativeHooks: host を注入する型付き境界。
    • WebCanvasPlatform / DesktopGlfwPlatform: hook を呼ぶ既存の shell。 ともに PlatformDriver と mizchi/gfx.SurfaceProvider を実装します。 未注入時の決定的な fallback はテスト・headless 用です。

    #依存方向

    platform_web ──→ platform ──→ kagura_core / gfx ↑ engine

    実装は platform_<target>/、配布名は mizchi/kagura_platform_<target> とします。 現在の JS 実装は platform_web/。contract は実装を import せず、実装同士も 依存させません。新しい実装はこの contract と共有のライフサイクル検証に従います。 型の変更は先に contract で定義し、実装で独自の入力・ウィンドウ型を増やしません。

    platform_web/runtime_hooks/ とトップレベルの platform_native/ は独立した既存 module です。 描画・音声・フォントと host を結線するため engine に依存する起動時の統合層で、 この contract の配布内容には含めません。JS の platform hook は platform_web の 公開 API を通し、native は DesktopNativeHooks に従って注入します。 native の既存 import 名は mizchi/native_runtime_hooks です。

    just platform-test で共通契約と JS adapter、配布の分離、依存方向を検証します。 just check-release は全 release module の境界を検査します。

    PlatformDriver

    pub(open) trait PlatformDriver {
    fn initialize(Self, options : WindowOptions) -> Unit raise
    fn poll_events(Self) -> Unit
    fn should_close(Self) -> Bool
    fn outside_size(Self) ->
    OutsideSize

    fn capture_input(Self, tick : Int) ->
    InputSnapshot

    fn monitor_info(Self) -> MonitorInfo
    fn set_fullscreen(Self, enabled : Bool) -> Unit
    fn is_fullscreen(Self) -> Bool
    fn set_cursor_mode(Self, mode : CursorMode) -> Unit
    fn cursor_mode(Self) -> CursorMode
    fn set_device_scale_factor(Self, scale : Double) -> Unit
    fn device_scale_factor(Self) -> Double
    fn set_vsync_enabled(Self, enabled : Bool) -> Unit
    fn is_vsync_enabled(Self) -> Bool
    fn close_window(Self) -> Unit
    fn request_attention(Self) -> Unit
    fn set_mouse_touch_fallback(Self, enabled : Bool) -> Unit
    fn mouse_touch_fallback_enabled(Self) -> Bool
    fn fullscreen_request_status(Self) -> AsyncRequestStatus
    fn cursor_mode_request_status(Self) -> AsyncRequestStatus
    }

    AsyncRequestStatus

    pub enum AsyncRequestStatus {
    Idle
    Pending
    Confirmed
    Rejected
    } derive(
    Debug
    )

    AsyncRequestStatus::output

    fn AsyncRequestStatus::output(self : AsyncRequestStatus, logger : &Logger) -> Unit

    AsyncRequestStatus::to_string

    fn AsyncRequestStatus::to_string(self : AsyncRequestStatus) -> String

    CursorMode

    pub enum CursorMode {
    Visible
    Hidden
    Captured
    } derive(
    Debug
    )

    impl Show for CursorMode

    CursorMode::output

    fn CursorMode::output(self : CursorMode, logger : &Logger) -> Unit

    CursorMode::to_string

    fn CursorMode::to_string(self : CursorMode) -> String

    DesktopGlfwPlatform

    pub struct DesktopGlfwPlatform {
    initialized : Bool
    poll_count : Int
    close_after_polls : Int
    native_active : Bool
    options : WindowOptions
    current_input :
    InputSnapshot

    fullscreen : Bool
    cursor_mode : CursorMode
    device_scale_factor : Double
    vsync_enabled : Bool
    close_requested : Bool
    attention_requests : Int
    mouse_touch_fallback : Bool
    fullscreen_request_status : AsyncRequestStatus
    cursor_mode_request_status : AsyncRequestStatus
    }

    DesktopGlfwPlatform::capture_input

    DesktopGlfwPlatform::close_window

    fn DesktopGlfwPlatform::close_window(self : DesktopGlfwPlatform) -> Unit

    DesktopGlfwPlatform::current_surface

    DesktopGlfwPlatform::cursor_mode

    DesktopGlfwPlatform::cursor_mode_request_status

    fn DesktopGlfwPlatform::cursor_mode_request_status(self : DesktopGlfwPlatform) -> AsyncRequestStatus

    DesktopGlfwPlatform::device_scale_factor

    fn DesktopGlfwPlatform::device_scale_factor(self : DesktopGlfwPlatform) -> Double

    DesktopGlfwPlatform::fullscreen_request_status

    fn DesktopGlfwPlatform::fullscreen_request_status(self : DesktopGlfwPlatform) -> AsyncRequestStatus

    DesktopGlfwPlatform::initialize

    fn DesktopGlfwPlatform::initialize(self : DesktopGlfwPlatform, options : WindowOptions) -> Unit raise

    DesktopGlfwPlatform::is_fullscreen

    fn DesktopGlfwPlatform::is_fullscreen(self : DesktopGlfwPlatform) -> Bool

    DesktopGlfwPlatform::is_vsync_enabled

    fn DesktopGlfwPlatform::is_vsync_enabled(self : DesktopGlfwPlatform) -> Bool

    DesktopGlfwPlatform::monitor_info

    DesktopGlfwPlatform::mouse_touch_fallback_enabled

    fn DesktopGlfwPlatform::mouse_touch_fallback_enabled(self : DesktopGlfwPlatform) -> Bool

    DesktopGlfwPlatform::outside_size

    DesktopGlfwPlatform::poll_events

    fn DesktopGlfwPlatform::poll_events(self : DesktopGlfwPlatform) -> Unit

    DesktopGlfwPlatform::request_attention

    fn DesktopGlfwPlatform::request_attention(self : DesktopGlfwPlatform) -> Unit

    DesktopGlfwPlatform::set_cursor_mode

    fn DesktopGlfwPlatform::set_cursor_mode(self : DesktopGlfwPlatform, mode : CursorMode) -> Unit

    DesktopGlfwPlatform::set_device_scale_factor

    fn DesktopGlfwPlatform::set_device_scale_factor(self : DesktopGlfwPlatform, scale : Double) -> Unit

    DesktopGlfwPlatform::set_fullscreen

    fn DesktopGlfwPlatform::set_fullscreen(self : DesktopGlfwPlatform, enabled : Bool) -> Unit

    DesktopGlfwPlatform::set_mouse_touch_fallback

    fn DesktopGlfwPlatform::set_mouse_touch_fallback(self : DesktopGlfwPlatform, enabled : Bool) -> Unit

    DesktopGlfwPlatform::set_vsync_enabled

    fn DesktopGlfwPlatform::set_vsync_enabled(self : DesktopGlfwPlatform, enabled : Bool) -> Unit

    DesktopGlfwPlatform::should_close

    fn DesktopGlfwPlatform::should_close(self : DesktopGlfwPlatform) -> Bool

    DesktopNativeHooks

    pub struct DesktopNativeHooks {
    try_initialize : (WindowOptions) -> Bool
    poll : (Bool) -> Unit
    should_close : () -> Bool
    outside_size : (Int, Int) ->
    OutsideSize

    capture_input : (Bool, Int) ->
    InputSnapshot

    set_fullscreen : (Bool, Bool) -> Bool
    is_fullscreen : (Bool, Bool) -> Bool
    set_cursor_mode : (Bool, CursorMode) -> CursorMode
    cursor_mode : (Bool, CursorMode) -> CursorMode
    set_device_scale_factor : (Bool, Double) -> Double
    device_scale_factor : (Bool, Double) -> Double
    set_vsync_enabled : (Bool, Bool) -> Bool
    is_vsync_enabled : (Bool, Bool) -> Bool
    close_window : (Bool) -> Unit
    request_attention : (Bool) -> Unit
    set_mouse_touch_fallback : (Bool, Bool) -> Unit
    mouse_touch_fallback_enabled : (Bool) -> Bool
    }

    FullscreenMode

    pub enum FullscreenMode {
    Windowed
    Borderless
    Exclusive
    } derive(
    Debug
    )

    FullscreenMode::output

    fn FullscreenMode::output(self : FullscreenMode, logger : &Logger) -> Unit

    FullscreenMode::to_string

    fn FullscreenMode::to_string(self : FullscreenMode) -> String

    MonitorInfo

    pub struct MonitorInfo {
    width : Int
    height : Int
    device_scale_factor : Double
    refresh_rate_hz : Int
    } derive(
    Debug
    )

    impl Show for MonitorInfo

    MonitorInfo::output

    fn MonitorInfo::output(self : MonitorInfo, logger : &Logger) -> Unit

    MonitorInfo::to_string

    fn MonitorInfo::to_string(self : MonitorInfo) -> String

    WebCanvasHooks

    pub struct WebCanvasHooks {
    try_initialize : (String, WindowOptions) -> Bool
    poll : (Bool) -> Unit
    should_close : () -> Bool
    outside_size : (Int, Int) ->
    OutsideSize

    current_surface : (String, WindowOptions) ->
    SurfaceToken

    capture_input : (Bool, Int) ->
    InputSnapshot

    set_fullscreen : (String, Bool, Bool) -> Bool
    is_fullscreen : (String, Bool, Bool) -> Bool
    set_cursor_mode : (String, Bool, CursorMode) -> CursorMode
    cursor_mode : (String, Bool, CursorMode) -> CursorMode
    set_device_scale_factor : (String, Bool, Double) -> Double
    device_scale_factor : (String, Bool, Double) -> Double
    set_vsync_enabled : (String, Bool, Bool) -> Bool
    is_vsync_enabled : (String, Bool, Bool) -> Bool
    close_window : (String, Bool) -> Unit
    request_attention : (String, Bool) -> Unit
    set_mouse_touch_fallback : (String, Bool, Bool) -> Unit
    mouse_touch_fallback_enabled : (String, Bool) -> Bool
    fullscreen_request_status : (String, Bool, Int) -> Int
    cursor_mode_request_status : (String, Bool, Int) -> Int
    }

    WebCanvasPlatform

    pub struct WebCanvasPlatform {
    canvas_selector : String
    initialized : Bool
    poll_count : Int
    close_after_polls : Int
    web_active : Bool
    options : WindowOptions
    current_input :
    InputSnapshot

    fullscreen : Bool
    cursor_mode : CursorMode
    device_scale_factor : Double
    vsync_enabled : Bool
    close_requested : Bool
    attention_requests : Int
    mouse_touch_fallback : Bool
    fullscreen_request_status : AsyncRequestStatus
    cursor_mode_request_status : AsyncRequestStatus
    }

    WebCanvasPlatform::capture_input

    WebCanvasPlatform::close_window

    fn WebCanvasPlatform::close_window(self : WebCanvasPlatform) -> Unit

    WebCanvasPlatform::current_surface

    WebCanvasPlatform::cursor_mode

    WebCanvasPlatform::cursor_mode_request_status

    fn WebCanvasPlatform::cursor_mode_request_status(self : WebCanvasPlatform) -> AsyncRequestStatus

    WebCanvasPlatform::device_scale_factor

    fn WebCanvasPlatform::device_scale_factor(self : WebCanvasPlatform) -> Double

    WebCanvasPlatform::fullscreen_request_status

    fn WebCanvasPlatform::fullscreen_request_status(self : WebCanvasPlatform) -> AsyncRequestStatus

    WebCanvasPlatform::initialize

    fn WebCanvasPlatform::initialize(self : WebCanvasPlatform, options : WindowOptions) -> Unit raise

    WebCanvasPlatform::is_fullscreen

    fn WebCanvasPlatform::is_fullscreen(self : WebCanvasPlatform) -> Bool

    WebCanvasPlatform::is_vsync_enabled

    fn WebCanvasPlatform::is_vsync_enabled(self : WebCanvasPlatform) -> Bool

    WebCanvasPlatform::monitor_info

    fn WebCanvasPlatform::monitor_info(self : WebCanvasPlatform) -> MonitorInfo

    WebCanvasPlatform::mouse_touch_fallback_enabled

    fn WebCanvasPlatform::mouse_touch_fallback_enabled(self : WebCanvasPlatform) -> Bool

    WebCanvasPlatform::outside_size

    WebCanvasPlatform::poll_events

    fn WebCanvasPlatform::poll_events(self : WebCanvasPlatform) -> Unit

    WebCanvasPlatform::request_attention

    fn WebCanvasPlatform::request_attention(self : WebCanvasPlatform) -> Unit

    WebCanvasPlatform::set_cursor_mode

    fn WebCanvasPlatform::set_cursor_mode(self : WebCanvasPlatform, mode : CursorMode) -> Unit

    WebCanvasPlatform::set_device_scale_factor

    fn WebCanvasPlatform::set_device_scale_factor(self : WebCanvasPlatform, scale : Double) -> Unit

    WebCanvasPlatform::set_fullscreen

    fn WebCanvasPlatform::set_fullscreen(self : WebCanvasPlatform, enabled : Bool) -> Unit

    WebCanvasPlatform::set_mouse_touch_fallback

    fn WebCanvasPlatform::set_mouse_touch_fallback(self : WebCanvasPlatform, enabled : Bool) -> Unit

    WebCanvasPlatform::set_vsync_enabled

    fn WebCanvasPlatform::set_vsync_enabled(self : WebCanvasPlatform, enabled : Bool) -> Unit

    WebCanvasPlatform::should_close

    fn WebCanvasPlatform::should_close(self : WebCanvasPlatform) -> Bool

    WindowOptions

    pub struct WindowOptions {
    title : String
    width : Int
    height : Int
    transparent : Bool
    resizable : Bool
    focused : Bool
    } derive(
    Debug
    )

    WindowOptions::output

    fn WindowOptions::output(self : WindowOptions, logger : &Logger) -> Unit

    WindowOptions::to_string

    fn WindowOptions::to_string(self : WindowOptions) -> String

    async_request_status_from_int

    fn async_request_status_from_int(status : Int) -> AsyncRequestStatus

    async_request_status_to_int

    fn async_request_status_to_int(status : AsyncRequestStatus) -> Int

    create_desktop_glfw_platform

    fn create_desktop_glfw_platform() -> DesktopGlfwPlatform

    create_web_canvas_platform

    fn create_web_canvas_platform(canvas_selector : String) -> WebCanvasPlatform

    cursor_mode_from_int

    fn cursor_mode_from_int(mode : Int) -> CursorMode

    cursor_mode_to_int

    fn cursor_mode_to_int(mode : CursorMode) -> Int

    fullscreen_mode_from_int

    fn fullscreen_mode_from_int(mode : Int) -> FullscreenMode

    fullscreen_mode_to_int

    fn fullscreen_mode_to_int(mode : FullscreenMode) -> Int

    new_desktop_native_hooks

    fn new_desktop_native_hooks(try_initialize : (WindowOptions) -> Bool, poll : (Bool) -> Unit, should_close : () -> Bool, outside_size : (Int, Int) ->
    OutsideSize
    , capture_input : (Bool, Int) ->
    InputSnapshot
    , set_fullscreen : (Bool, Bool) -> Bool, is_fullscreen : (Bool, Bool) -> Bool, set_cursor_mode : (Bool, CursorMode) -> CursorMode, cursor_mode : (Bool, CursorMode) -> CursorMode, set_device_scale_factor : (Bool, Double) -> Double, device_scale_factor : (Bool, Double) -> Double, set_vsync_enabled : (Bool, Bool) -> Bool, is_vsync_enabled : (Bool, Bool) -> Bool, close_window : (Bool) -> Unit, request_attention : (Bool) -> Unit, set_mouse_touch_fallback : (Bool, Bool) -> Unit, mouse_touch_fallback_enabled : (Bool) -> Bool) -> DesktopNativeHooks

    new_web_canvas_hooks

    fn new_web_canvas_hooks(try_initialize : (String, WindowOptions) -> Bool, poll : (Bool) -> Unit, should_close : () -> Bool, outside_size : (Int, Int) ->
    OutsideSize
    , current_surface : (String, WindowOptions) ->
    SurfaceToken
    , capture_input : (Bool, Int) ->
    InputSnapshot
    , set_fullscreen : (String, Bool, Bool) -> Bool, is_fullscreen : (String, Bool, Bool) -> Bool, set_cursor_mode : (String, Bool, CursorMode) -> CursorMode, cursor_mode : (String, Bool, CursorMode) -> CursorMode, set_device_scale_factor : (String, Bool, Double) -> Double, device_scale_factor : (String, Bool, Double) -> Double, set_vsync_enabled : (String, Bool, Bool) -> Bool, is_vsync_enabled : (String, Bool, Bool) -> Bool, close_window : (String, Bool) -> Unit, request_attention : (String, Bool) -> Unit, set_mouse_touch_fallback : (String, Bool, Bool) -> Unit, mouse_touch_fallback_enabled : (String, Bool) -> Bool, fullscreen_request_status : (String, Bool, Int) -> Int, cursor_mode_request_status : (String, Bool, Int) -> Int) -> WebCanvasHooks

    new_window_options

    fn new_window_options(title : String, width : Int, height : Int, transparent : Bool, resizable : Bool, focused? : Bool) -> WindowOptions

    reset_desktop_native_hooks

    fn reset_desktop_native_hooks() -> Unit

    reset_web_canvas_hooks

    fn reset_web_canvas_hooks() -> Unit

    set_desktop_native_hooks

    fn set_desktop_native_hooks(hooks : DesktopNativeHooks) -> Unit

    set_web_canvas_hooks

    fn set_web_canvas_hooks(hooks : WebCanvasHooks) -> Unit