moui_skia_renderer

Native Skia renderer provider for MoUI

moui
renderer
skia
gui
Download zip
Author
Version
0.1.11
License
Apache-2.0
Last updated
yesterday
Downloads
73

#MoUI Skia Renderer

Native Skia renderer provider for wzzc-dev/moui.

NativePlatformSurface

pub(open) trait NativePlatformSurface {
fn surface_route(Self) -> SkiaSurfaceRoute
fn gpu_promoted(Self) -> Bool
fn platform_label(Self) -> String
}

SkiaRendererError

pub(all) suberror SkiaRendererError {
SkiaUnavailable
SurfaceUnavailable
CanvasUnavailable
ReadPixelsUnavailable
GpuContextUnavailable(String)
PresentFailed(String)
} derive(Eq, ToJson,
Debug
)

SkiaRendererError::message

fn SkiaRendererError::message(self : SkiaRendererError) -> String

HostGpuPresentOutcome

pub(all) struct HostGpuPresentOutcome {
// private fields
}

Outcome of a HostGpuPresentTarget::present_gpu call.

  • succeeded: whether the platform presented the drawable successfully.
  • next_surface: Some(surface) to swap the renderer's surface for the next frame (per-drawable GPU backends); None to keep the current surface (long-lived GPU backends).

HostGpuPresentOutcome::new

HostGpuPresentOutcome::next_surface

HostGpuPresentOutcome::succeeded

fn HostGpuPresentOutcome::succeeded(self : HostGpuPresentOutcome) -> Bool

HostGpuPresentTarget

pub struct HostGpuPresentTarget {
// private fields
}

Present target for the direct host-GPU-surface route. The presenter takes a flushed @skia_native.Surface and lets the platform present its underlying drawable (Metal CAMetalDrawable, VkSwapchainKHR image, EGLSurface backbuffer, or D3D12 swapchain backbuffer). No SkiaPixelFrame, no Bytes, no CGImage/UIImage/NSImage/Bitmap/PixelMap intermediate.

HostGpuPresentTarget is a sibling of SkiaPresentTarget; both are accepted by create_with_present_target_and_route. A renderer is bound to exactly one of them. When gpu_target = Some(_), target_kind() returns HostGpuSurface and the render loop bypasses read_frame.

create_window_surface is invoked lazily immediately before the first render, after the native event loop can provide a drawable, and again on each resize after attachment. It receives the GpuContext the renderer created internally (via create_gpu_context) and the current surface metrics, and returns a window-backed Surface (e.g. one wrapping a Metal CAMetalDrawable's MTLTexture). When it returns None, the renderer raises SurfaceUnavailable. The constructor's offscreen GPU surface is a typed placeholder only; no commands are recorded into it, so the first rendered frame still goes directly to the host drawable with no readback.

present_gpu is invoked each frame after flush_and_submit. It receives the same GpuContext and the flushed Surface. It returns the optional Surface to use for the next frame. GPU backends whose Skia Surface is bound to a per-frame drawable (Metal CAMetalDrawable, Vulkan swapchain image) return a fresh Surface; backends that reuse the same Surface (e.g. a long-lived EGLSurface/D3D12 swapchain backbuffer wrapped via SkSurfaces::WrapBackendSurface) return None to keep the current one. Returning Some(surface) causes the renderer to swap self.surface to the returned value before the next frame.

HostGpuPresentTarget::description

fn HostGpuPresentTarget::description(self : HostGpuPresentTarget) -> String

NativeGpuPlatform

pub(all) enum NativeGpuPlatform {
MacOS
Windows
Linux
Android
IOS
HarmonyOS
} derive(Eq, ToJson,
Debug
)

NativeRendererMode

pub(all) enum NativeRendererMode {
Auto
SkiaGpu
SkiaRaster
} derive(Eq, ToJson,
Debug
)

NativeRendererMode::label

fn NativeRendererMode::label(self : NativeRendererMode) -> String

NativeRendererMode::parse

fn NativeRendererMode::parse(value : String) -> NativeRendererMode?

SkiaEmojiFontFallbackDiagnostic

pub struct SkiaEmojiFontFallbackDiagnostic {
// private fields
} derive(Eq, ToJson,
Debug
)

SkiaEmojiFontFallbackDiagnostic::cluster_count

SkiaEmojiFontFallbackDiagnostic::deterministic_color_emoji_ready

fn SkiaEmojiFontFallbackDiagnostic::deterministic_color_emoji_ready(self : SkiaEmojiFontFallbackDiagnostic) -> Bool

SkiaEmojiFontFallbackDiagnostic::emoji_fallback_attempted

fn SkiaEmojiFontFallbackDiagnostic::emoji_fallback_attempted(self : SkiaEmojiFontFallbackDiagnostic) -> Bool

SkiaEmojiFontFallbackDiagnostic::emoji_hint

SkiaEmojiFontFallbackDiagnostic::fallback_character

SkiaEmojiFontFallbackDiagnostic::fallback_language_tag_count

fn SkiaEmojiFontFallbackDiagnostic::fallback_language_tag_count(self : SkiaEmojiFontFallbackDiagnostic) -> Int

SkiaEmojiFontFallbackDiagnostic::fallback_language_tags

fn SkiaEmojiFontFallbackDiagnostic::fallback_language_tags(self : SkiaEmojiFontFallbackDiagnostic) -> Array[String]

SkiaEmojiFontFallbackDiagnostic::fallback_request_language_count

fn SkiaEmojiFontFallbackDiagnostic::fallback_request_language_count(self : SkiaEmojiFontFallbackDiagnostic) -> Int

SkiaEmojiFontFallbackDiagnostic::fallback_request_ready

fn SkiaEmojiFontFallbackDiagnostic::fallback_request_ready(self : SkiaEmojiFontFallbackDiagnostic) -> Bool

SkiaEmojiFontFallbackDiagnostic::fallback_script_tag

fn SkiaEmojiFontFallbackDiagnostic::fallback_script_tag(self : SkiaEmojiFontFallbackDiagnostic) -> String

SkiaEmojiFontFallbackDiagnostic::font_family

SkiaEmojiFontFallbackDiagnostic::font_source

SkiaEmojiFontFallbackDiagnostic::glyph_count

SkiaEmojiFontFallbackDiagnostic::glyph_format

SkiaEmojiFontFallbackDiagnostic::glyph_height

SkiaEmojiFontFallbackDiagnostic::glyph_key

SkiaEmojiFontFallbackDiagnostic::glyph_width

SkiaEmojiFontFallbackDiagnostic::missing_glyph_recovery_ready

fn SkiaEmojiFontFallbackDiagnostic::missing_glyph_recovery_ready(self : SkiaEmojiFontFallbackDiagnostic) -> Bool

SkiaEmojiFontFallbackDiagnostic::resolved_font_name

fn SkiaEmojiFontFallbackDiagnostic::resolved_font_name(self : SkiaEmojiFontFallbackDiagnostic) -> String

SkiaEmojiFontFallbackDiagnostic::resolved_missing_glyph_count

fn SkiaEmojiFontFallbackDiagnostic::resolved_missing_glyph_count(self : SkiaEmojiFontFallbackDiagnostic) -> Int

SkiaEmojiFontFallbackDiagnostic::shaper

SkiaEmojiFontFallbackDiagnostic::text

SkiaEmojiFontFallbackDiagnostic::text_system_id

SkiaFontResolution

pub(all) enum SkiaFontResolution {
SystemFontMgr
EmptyTypeface
} derive(Eq, ToJson,
Debug
)

SkiaHybridRenderer

pub struct SkiaHybridRenderer {
// private fields
}

A renderer owner that keeps the raster factory and GPU queue model under one lifecycle. Recorded queue completions are internal handoff signals; only the window-backed presenter can produce a public Presented completion.

SkiaHybridRenderer::drain_present_completions

SkiaHybridRenderer::fallback_to_raster

fn SkiaHybridRenderer::fallback_to_raster(self : SkiaHybridRenderer) -> Bool

SkiaHybridRenderer::requested_mode

SkiaHybridRenderer::surface_route

SkiaPixelFrame

pub struct SkiaPixelFrame {
// private fields
} derive(Eq,
Debug
)

SkiaPixelFrame::height

fn SkiaPixelFrame::height(self : SkiaPixelFrame) -> Int

SkiaPixelFrame::pixels

fn SkiaPixelFrame::pixels(self : SkiaPixelFrame) -> Bytes

SkiaPixelFrame::row_bytes

fn SkiaPixelFrame::row_bytes(self : SkiaPixelFrame) -> Int

SkiaPixelFrame::scale_factor

fn SkiaPixelFrame::scale_factor(self : SkiaPixelFrame) -> Double

SkiaPixelFrame::width

fn SkiaPixelFrame::width(self : SkiaPixelFrame) -> Int

SkiaPresentKind

pub(all) enum SkiaPresentKind {
CpuPixelFrame
HostGpuSurface
} derive(Eq, ToJson,
Debug
)

Discriminator for which present path a SkiaRasterRenderer is wired to.

  • CpuPixelFrame: the renderer reads pixels back via Surface::read_pixels and hands a SkiaPixelFrame to the platform presenter. This is the only path wired today on every platform and remains the default/test fallback per ADR 0006.
  • HostGpuSurface: the renderer is bound to a HostGpuPresentTarget. The platform presenter owns a window-backed GPU surface (Metal drawable, Vulkan swapchain, EGL surface, D3D12 swapchain) and Skia flushes the drawable directly. read_pixels and the second CPU copy are skipped.

SkiaPresentTarget

pub struct SkiaPresentTarget {
// private fields
}

SkiaPresentTarget::new

fn SkiaPresentTarget::new(description~ : String, present~ : (SkiaPixelFrame) -> Bool) -> SkiaPresentTarget

SkiaRasterRenderer

pub struct SkiaRasterRenderer {
// private fields
}

SkiaRasterRenderer::apply_image_resource_load_completion

SkiaRasterRenderer::dispose

fn SkiaRasterRenderer::dispose(self : SkiaRasterRenderer) -> Unit

SkiaRasterRenderer::draw_platform_view_pixels

fn SkiaRasterRenderer::draw_platform_view_pixels(self : SkiaRasterRenderer, pixels : Bytes, src_width : Int, src_height : Int, src_stride : Int, dst_x : Double, dst_y : Double, dst_width : Double, dst_height : Double) -> Unit

This should be called after render_frame but before the window system presents

SkiaRasterRenderer::gpu_target

Returns the bound HostGpuPresentTarget when the renderer is on the direct GPU present path. Returns None for the legacy CPU pixel-frame route.

SkiaRasterRenderer::last_frame

SkiaRasterRenderer::present_count

fn SkiaRasterRenderer::present_count(self : SkiaRasterRenderer) -> Int

SkiaRasterRenderer::record_frame_picture

Record a frame into an immutable picture for replay by a native renderer worker. No MoonBit object crosses the thread boundary.

SkiaRasterRenderer::render

SkiaRasterRenderer::resize

SkiaRasterRenderer::set_platform_view_draw_fn

fn SkiaRasterRenderer::set_platform_view_draw_fn(self : SkiaRasterRenderer, draw_fn : () -> Unit?) -> Unit

Set a callback to draw platform view pixels after command rendering but before flush.

SkiaRasterRenderer::surface_diagnostic_summary

fn SkiaRasterRenderer::surface_diagnostic_summary(self : SkiaRasterRenderer) -> String

SkiaRasterRenderer::surface_is_gpu

fn SkiaRasterRenderer::surface_is_gpu(self : SkiaRasterRenderer) -> Bool

SkiaRasterRenderer::surface_route

SkiaRasterRenderer::target_kind

Returns which present path the renderer is bound to. CpuPixelFrame reads pixels back via Surface::read_pixels and hands a SkiaPixelFrame to the platform presenter; HostGpuSurface lets the platform present a window-backed GPU drawable directly with no CPU readback.

SkiaRasterRenderer::text_system

SkiaRasterRenderer::to_renderer_session

Adapt a live Skia renderer to the renderer-neutral host lifecycle.

SkiaRasterRenderer::unsupported_command_count

fn SkiaRasterRenderer::unsupported_command_count(self : SkiaRasterRenderer) -> Int

SkiaRasterRenderer::unsupported_command_diagnostics

fn SkiaRasterRenderer::unsupported_command_diagnostics(self : SkiaRasterRenderer) -> Array[SkiaUnsupportedCommandDiagnostic]

SkiaSurfaceRoute

pub(all) enum SkiaSurfaceRoute {
RasterSurfaceRoute
MetalGpuSurfaceRoute
VulkanGpuSurfaceRoute
EglGpuSurfaceRoute
Direct3DGpuSurfaceRoute
} derive(Eq, ToJson,
Debug
)

Renderer-local route used to select the concrete Skia GPU API. Platform and graphics API names never cross the root moui/render boundary.

SkiaSurfaceRoute::is_gpu

fn SkiaSurfaceRoute::is_gpu(self : SkiaSurfaceRoute) -> Bool

SkiaSurfaceRoute::is_implemented

fn SkiaSurfaceRoute::is_implemented(self : SkiaSurfaceRoute) -> Bool

SkiaSurfaceRoute::label

fn SkiaSurfaceRoute::label(self : SkiaSurfaceRoute) -> String

SkiaTextSelectionGeometryDiagnostic

pub struct SkiaTextSelectionGeometryDiagnostic {
// private fields
} derive(Eq, ToJson,
Debug
)

SkiaTextSelectionGeometryDiagnostic::bidi_visual_order_observed

fn SkiaTextSelectionGeometryDiagnostic::bidi_visual_order_observed(self : SkiaTextSelectionGeometryDiagnostic) -> Bool

SkiaTextSelectionGeometryDiagnostic::hit_test_inside

SkiaTextSelectionGeometryDiagnostic::hit_test_line_index

SkiaTextSelectionGeometryDiagnostic::hit_test_offset

SkiaTextSelectionGeometryDiagnostic::line_count

SkiaTextSelectionGeometryDiagnostic::selected_line_count

SkiaTextSelectionGeometryDiagnostic::selection_range

SkiaTextSelectionGeometryDiagnostic::selection_rect_count

SkiaTextSelectionGeometryDiagnostic::text

SkiaTextSelectionGeometryDiagnostic::visual_order_differs

SkiaTextSelectionGeometryDiagnostic::visual_segment_count

SkiaTextVisualOrderDiagnostic

pub struct SkiaTextVisualOrderDiagnostic {
// private fields
} derive(Eq, ToJson,
Debug
)

SkiaTextVisualOrderDiagnostic::glyph_count

SkiaTextVisualOrderDiagnostic::logical_cluster_count

fn SkiaTextVisualOrderDiagnostic::logical_cluster_count(self : SkiaTextVisualOrderDiagnostic) -> Int

SkiaTextVisualOrderDiagnostic::logical_text

SkiaTextVisualOrderDiagnostic::segment_count

SkiaTextVisualOrderDiagnostic::visual_cluster_count

fn SkiaTextVisualOrderDiagnostic::visual_cluster_count(self : SkiaTextVisualOrderDiagnostic) -> Int

SkiaTextVisualOrderDiagnostic::visual_order_differs

fn SkiaTextVisualOrderDiagnostic::visual_order_differs(self : SkiaTextVisualOrderDiagnostic) -> Bool

SkiaTextVisualOrderDiagnostic::visual_text

SkiaTextVisualOrderDiagnostic::width

SkiaUnsupportedCommandDiagnostic

pub struct SkiaUnsupportedCommandDiagnostic {
// private fields
} derive(Eq, ToJson,
Debug
)

SkiaUnsupportedCommandDiagnostic::command

SkiaUnsupportedCommandDiagnostic::reason

create_hybrid_renderer

fn create_hybrid_renderer(platform : NativeGpuPlatform, requested : NativeRendererMode, metrics :
SurfaceMetrics
, target : SkiaPresentTarget, gpu_available~ : Bool, gpu_promoted~ : Bool, gpu_target? : HostGpuPresentTarget?, font_resolution? : SkiaFontResolution, async_image_loading? : Bool) -> SkiaHybridRenderer raise SkiaRendererError

create_with_present_target

fn create_with_present_target(metrics :
SurfaceMetrics
, target : SkiaPresentTarget, font_resolution? : SkiaFontResolution, async_image_loading? : Bool) -> SkiaRasterRenderer raise SkiaRendererError

create_with_present_target_and_route

fn create_with_present_target_and_route(metrics :
SurfaceMetrics
, target : SkiaPresentTarget, surface_route? : SkiaSurfaceRoute, gpu_target? : HostGpuPresentTarget?, font_resolution? : SkiaFontResolution, async_image_loading? : Bool) -> SkiaRasterRenderer raise SkiaRendererError

from_env

Resolve the environment policy entirely inside the Skia renderer package.

gpu

Build a Skia direct GPU provider. The platform policy belongs to this renderer module and interprets the opaque native handles after binding.

raster

Build a Skia CPU raster provider from the renderer-neutral host contract.

renderer_descriptor

resolve_surface_route

fn[P : NativePlatformSurface] resolve_surface_route(platform : P, requested : NativeRendererMode, gpu_available~ : Bool, gpu_promoted~ : Bool) -> SkiaSurfaceRoute

skia_available

fn skia_available() -> Bool

skia_emoji_font_fallback_diagnostic

fn skia_emoji_font_fallback_diagnostic(text? : String, font? :
FontSpec
, font_resolution? : SkiaFontResolution) -> SkiaEmojiFontFallbackDiagnostic?

skia_gpu_metal_preflight_summary

fn skia_gpu_metal_preflight_summary() -> String

skia_gpu_native_descriptor

skia_image_load_completion

skia_image_load_completion_from_bytes

fn skia_image_load_completion_from_bytes(source : String, bytes : Bytes, background_io? : Bool, background_decode? : Bool) ->
ImageResourceLoadCompletion

skia_provider_capabilities

Skia owns the capability declarations used by both its raster and GPU providers. The backend enum is descriptive metadata; the id is the report identity used by composition roots.

skia_raster_native_descriptor

skia_text_selection_geometry_diagnostic

fn skia_text_selection_geometry_diagnostic(text : String, selection? :
TextRange
?, font? :
FontSpec
, max_width? : Double, font_resolution? : SkiaFontResolution) -> SkiaTextSelectionGeometryDiagnostic?

skia_text_system

fn skia_text_system(resolution? : SkiaFontResolution) ->
TextSystem

skia_text_visual_order_diagnostic

fn skia_text_visual_order_diagnostic(text : String, font? :
FontSpec
, font_resolution? : SkiaFontResolution) -> SkiaTextVisualOrderDiagnostic?