@native-sdk/cli 0.0.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +176 -0
- package/README.md +50 -1
- package/app.zon +30 -0
- package/bin/native.js +156 -0
- package/build/app.zig +716 -0
- package/build.zig +2593 -0
- package/build.zig.zon +24 -0
- package/native-sdk.d.ts +615 -0
- package/package.json +44 -8
- package/skill-data/automation/SKILL.md +248 -0
- package/skill-data/core/SKILL.md +249 -0
- package/skill-data/core/references/app-model-runtime.md +141 -0
- package/skill-data/core/references/bridge-security-native-capabilities.md +230 -0
- package/skill-data/core/references/frontend-assets.md +124 -0
- package/skill-data/core/references/project-anatomy.md +108 -0
- package/skill-data/core/references/web-engines-packaging-debugging.md +199 -0
- package/skill-data/native-ui/SKILL.md +1080 -0
- package/skills/native-sdk/SKILL.md +33 -0
- package/src/app_runner/root.zig +740 -0
- package/src/assets/root.zig +20 -0
- package/src/automation/protocol.zig +285 -0
- package/src/automation/root.zig +13 -0
- package/src/automation/server.zig +506 -0
- package/src/automation/snapshot.zig +1202 -0
- package/src/automation/watcher.zig +165 -0
- package/src/bridge/root.zig +507 -0
- package/src/debug/root.zig +246 -0
- package/src/embed/app_exports.zig +11 -0
- package/src/embed/c_api.zig +793 -0
- package/src/embed/c_exports.zig +10 -0
- package/src/embed/chrome.zig +168 -0
- package/src/embed/conversions.zig +359 -0
- package/src/embed/host.zig +960 -0
- package/src/embed/root.zig +81 -0
- package/src/embed/tests.zig +2552 -0
- package/src/embed/types.zig +382 -0
- package/src/embed/ui_host.zig +289 -0
- package/src/extensions/root.zig +197 -0
- package/src/frontend/root.zig +48 -0
- package/src/js/root.zig +65 -0
- package/src/platform/android/NativeSdkActivity.java +1370 -0
- package/src/platform/android/android_host.c +696 -0
- package/src/platform/android/files.zig +9 -0
- package/src/platform/android/native_sdk_app.h +237 -0
- package/src/platform/ios/files.zig +8 -0
- package/src/platform/ios/native_sdk_app.h +289 -0
- package/src/platform/ios/uikit_host.m +2739 -0
- package/src/platform/linux/cef_host.cpp +599 -0
- package/src/platform/linux/gtk_host.c +5362 -0
- package/src/platform/linux/gtk_host.h +265 -0
- package/src/platform/linux/root.zig +1519 -0
- package/src/platform/macos/appkit_host.h +604 -0
- package/src/platform/macos/appkit_host.m +10392 -0
- package/src/platform/macos/automation_host.h +14 -0
- package/src/platform/macos/automation_host.m +12 -0
- package/src/platform/macos/cef_host.mm +3028 -0
- package/src/platform/macos/root.zig +2260 -0
- package/src/platform/null_platform.zig +2232 -0
- package/src/platform/null_platform_tests.zig +670 -0
- package/src/platform/policy_values.zig +14 -0
- package/src/platform/root.zig +181 -0
- package/src/platform/types.zig +2681 -0
- package/src/platform/windows/cef_host.cpp +3 -0
- package/src/platform/windows/root.zig +1521 -0
- package/src/platform/windows/webview2_host.cpp +6230 -0
- package/src/primitives/app_dirs/root.zig +440 -0
- package/src/primitives/app_manifest/root.zig +109 -0
- package/src/primitives/app_manifest/tests.zig +758 -0
- package/src/primitives/app_manifest/types.zig +587 -0
- package/src/primitives/app_manifest/validation.zig +828 -0
- package/src/primitives/assets/root.zig +520 -0
- package/src/primitives/canvas/a11y_audit.zig +390 -0
- package/src/primitives/canvas/a11y_audit_tests.zig +225 -0
- package/src/primitives/canvas/app_icon.zig +1590 -0
- package/src/primitives/canvas/chart.zig +392 -0
- package/src/primitives/canvas/chart_tests.zig +751 -0
- package/src/primitives/canvas/commands.zig +446 -0
- package/src/primitives/canvas/drawing.zig +309 -0
- package/src/primitives/canvas/equality.zig +316 -0
- package/src/primitives/canvas/events.zig +696 -0
- package/src/primitives/canvas/font_coverage.zig +118 -0
- package/src/primitives/canvas/font_ttf.zig +510 -0
- package/src/primitives/canvas/font_ttf_tests.zig +280 -0
- package/src/primitives/canvas/fonts/Geist-Regular.ttf +0 -0
- package/src/primitives/canvas/fonts/GeistMono-Regular.ttf +0 -0
- package/src/primitives/canvas/frame.zig +679 -0
- package/src/primitives/canvas/frame_metrics.zig +462 -0
- package/src/primitives/canvas/gpu.zig +639 -0
- package/src/primitives/canvas/hash.zig +112 -0
- package/src/primitives/canvas/icons/alert.svg +1 -0
- package/src/primitives/canvas/icons/archive.svg +1 -0
- package/src/primitives/canvas/icons/arrow-down.svg +1 -0
- package/src/primitives/canvas/icons/arrow-right.svg +1 -0
- package/src/primitives/canvas/icons/arrow-up.svg +1 -0
- package/src/primitives/canvas/icons/check-circle.svg +1 -0
- package/src/primitives/canvas/icons/check.svg +1 -0
- package/src/primitives/canvas/icons/chevron-down.svg +1 -0
- package/src/primitives/canvas/icons/chevron-left.svg +1 -0
- package/src/primitives/canvas/icons/chevron-right.svg +1 -0
- package/src/primitives/canvas/icons/chevron-up.svg +1 -0
- package/src/primitives/canvas/icons/circle-dot.svg +1 -0
- package/src/primitives/canvas/icons/clock.svg +1 -0
- package/src/primitives/canvas/icons/copy.svg +1 -0
- package/src/primitives/canvas/icons/download.svg +1 -0
- package/src/primitives/canvas/icons/edit.svg +1 -0
- package/src/primitives/canvas/icons/ellipsis.svg +1 -0
- package/src/primitives/canvas/icons/external-link.svg +1 -0
- package/src/primitives/canvas/icons/eye.svg +1 -0
- package/src/primitives/canvas/icons/file-text.svg +1 -0
- package/src/primitives/canvas/icons/folder-open.svg +1 -0
- package/src/primitives/canvas/icons/folder.svg +1 -0
- package/src/primitives/canvas/icons/git-branch.svg +1 -0
- package/src/primitives/canvas/icons/git-merge.svg +1 -0
- package/src/primitives/canvas/icons/git-pull-request.svg +1 -0
- package/src/primitives/canvas/icons/info.svg +1 -0
- package/src/primitives/canvas/icons/menu.svg +1 -0
- package/src/primitives/canvas/icons/missing.svg +1 -0
- package/src/primitives/canvas/icons/moon.svg +1 -0
- package/src/primitives/canvas/icons/music.svg +1 -0
- package/src/primitives/canvas/icons/panel-left.svg +1 -0
- package/src/primitives/canvas/icons/panel-right.svg +1 -0
- package/src/primitives/canvas/icons/pause.svg +1 -0
- package/src/primitives/canvas/icons/play.svg +1 -0
- package/src/primitives/canvas/icons/plus.svg +1 -0
- package/src/primitives/canvas/icons/refresh-cw.svg +1 -0
- package/src/primitives/canvas/icons/repeat.svg +1 -0
- package/src/primitives/canvas/icons/save.svg +1 -0
- package/src/primitives/canvas/icons/search.svg +1 -0
- package/src/primitives/canvas/icons/send.svg +1 -0
- package/src/primitives/canvas/icons/settings.svg +1 -0
- package/src/primitives/canvas/icons/shuffle.svg +1 -0
- package/src/primitives/canvas/icons/skip-back.svg +1 -0
- package/src/primitives/canvas/icons/skip-forward.svg +1 -0
- package/src/primitives/canvas/icons/sun.svg +1 -0
- package/src/primitives/canvas/icons/terminal.svg +1 -0
- package/src/primitives/canvas/icons/trash.svg +1 -0
- package/src/primitives/canvas/icons/volume.svg +1 -0
- package/src/primitives/canvas/icons/wrench.svg +1 -0
- package/src/primitives/canvas/icons/x-circle.svg +1 -0
- package/src/primitives/canvas/icons/x.svg +1 -0
- package/src/primitives/canvas/icons.zig +249 -0
- package/src/primitives/canvas/layout_audit.zig +744 -0
- package/src/primitives/canvas/layout_audit_tests.zig +426 -0
- package/src/primitives/canvas/markdown.zig +1031 -0
- package/src/primitives/canvas/markdown_hostile_tests.zig +471 -0
- package/src/primitives/canvas/markdown_tests.zig +538 -0
- package/src/primitives/canvas/plan_key_index.zig +120 -0
- package/src/primitives/canvas/png.zig +355 -0
- package/src/primitives/canvas/reference.zig +1457 -0
- package/src/primitives/canvas/reference_blur.zig +104 -0
- package/src/primitives/canvas/reference_memo.zig +322 -0
- package/src/primitives/canvas/reference_paths.zig +184 -0
- package/src/primitives/canvas/reference_tests.zig +1650 -0
- package/src/primitives/canvas/render.zig +747 -0
- package/src/primitives/canvas/render_effects.zig +255 -0
- package/src/primitives/canvas/render_fingerprints.zig +256 -0
- package/src/primitives/canvas/render_generic_resources.zig +376 -0
- package/src/primitives/canvas/render_images.zig +247 -0
- package/src/primitives/canvas/render_layers.zig +260 -0
- package/src/primitives/canvas/render_paths.zig +347 -0
- package/src/primitives/canvas/render_resources.zig +51 -0
- package/src/primitives/canvas/render_tests.zig +3186 -0
- package/src/primitives/canvas/root.zig +744 -0
- package/src/primitives/canvas/serialization.zig +1528 -0
- package/src/primitives/canvas/svg_icon.zig +636 -0
- package/src/primitives/canvas/svg_icon_tests.zig +312 -0
- package/src/primitives/canvas/test_support.zig +422 -0
- package/src/primitives/canvas/testdata/markdown_document.md +83 -0
- package/src/primitives/canvas/tests.zig +30 -0
- package/src/primitives/canvas/text.zig +82 -0
- package/src/primitives/canvas/text_atlas.zig +408 -0
- package/src/primitives/canvas/text_batch_tests.zig +431 -0
- package/src/primitives/canvas/text_interaction.zig +615 -0
- package/src/primitives/canvas/text_layout.zig +1069 -0
- package/src/primitives/canvas/text_layout_cache.zig +281 -0
- package/src/primitives/canvas/text_layout_hash.zig +113 -0
- package/src/primitives/canvas/text_layout_types.zig +128 -0
- package/src/primitives/canvas/text_measure_cache.zig +279 -0
- package/src/primitives/canvas/text_metrics.zig +309 -0
- package/src/primitives/canvas/text_metrics_tests.zig +262 -0
- package/src/primitives/canvas/text_span_tests.zig +608 -0
- package/src/primitives/canvas/text_spans.zig +1010 -0
- package/src/primitives/canvas/text_tests.zig +1949 -0
- package/src/primitives/canvas/themes/geist.zig +470 -0
- package/src/primitives/canvas/tokens.zig +1522 -0
- package/src/primitives/canvas/ui.zig +2686 -0
- package/src/primitives/canvas/ui_markup.zig +3791 -0
- package/src/primitives/canvas/ui_markup_binary.zig +522 -0
- package/src/primitives/canvas/ui_markup_binary_tests.zig +591 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +2565 -0
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +1669 -0
- package/src/primitives/canvas/ui_markup_contract.zig +1620 -0
- package/src/primitives/canvas/ui_markup_contract_tests.zig +953 -0
- package/src/primitives/canvas/ui_markup_edit.zig +416 -0
- package/src/primitives/canvas/ui_markup_edit_tests.zig +341 -0
- package/src/primitives/canvas/ui_markup_expr.zig +1152 -0
- package/src/primitives/canvas/ui_markup_expr_tests.zig +779 -0
- package/src/primitives/canvas/ui_markup_huge_model_tests.zig +505 -0
- package/src/primitives/canvas/ui_markup_reflect.zig +127 -0
- package/src/primitives/canvas/ui_markup_tests.zig +1545 -0
- package/src/primitives/canvas/ui_markup_view.zig +2352 -0
- package/src/primitives/canvas/ui_markup_view_tests.zig +3709 -0
- package/src/primitives/canvas/ui_provenance.zig +96 -0
- package/src/primitives/canvas/ui_provenance_tests.zig +186 -0
- package/src/primitives/canvas/ui_schema.zig +825 -0
- package/src/primitives/canvas/ui_schema_tests.zig +128 -0
- package/src/primitives/canvas/ui_tests.zig +1432 -0
- package/src/primitives/canvas/vector.zig +919 -0
- package/src/primitives/canvas/vector_tests.zig +547 -0
- package/src/primitives/canvas/virtual_extent_tests.zig +317 -0
- package/src/primitives/canvas/virtual_extents.zig +540 -0
- package/src/primitives/canvas/widget_access.zig +208 -0
- package/src/primitives/canvas/widget_anchored_tests.zig +264 -0
- package/src/primitives/canvas/widget_builtin_tests.zig +3160 -0
- package/src/primitives/canvas/widget_invalidation.zig +748 -0
- package/src/primitives/canvas/widget_layout.zig +2055 -0
- package/src/primitives/canvas/widget_layout_tests.zig +2691 -0
- package/src/primitives/canvas/widget_metrics.zig +228 -0
- package/src/primitives/canvas/widget_render.zig +2534 -0
- package/src/primitives/canvas/widget_render_controls.zig +1563 -0
- package/src/primitives/canvas/widget_render_scroll.zig +136 -0
- package/src/primitives/canvas/widget_render_style.zig +626 -0
- package/src/primitives/canvas/widget_render_surfaces.zig +794 -0
- package/src/primitives/canvas/widget_routing.zig +475 -0
- package/src/primitives/canvas/widget_runtime.zig +307 -0
- package/src/primitives/canvas/widget_runtime_tests.zig +3015 -0
- package/src/primitives/canvas/widget_semantics.zig +480 -0
- package/src/primitives/canvas/widget_semantics_tests.zig +2129 -0
- package/src/primitives/canvas/widget_tests.zig +8 -0
- package/src/primitives/canvas/widget_text_input.zig +351 -0
- package/src/primitives/canvas/widget_text_select.zig +147 -0
- package/src/primitives/canvas/widget_tree.zig +232 -0
- package/src/primitives/canvas/widgets.zig +1319 -0
- package/src/primitives/diagnostics/root.zig +445 -0
- package/src/primitives/geometry/root.zig +889 -0
- package/src/primitives/json/root.zig +272 -0
- package/src/primitives/platform_info/root.zig +450 -0
- package/src/primitives/trace/root.zig +569 -0
- package/src/root.zig +165 -0
- package/src/runtime/api.zig +431 -0
- package/src/runtime/async_bridge.zig +49 -0
- package/src/runtime/automation_commands.zig +686 -0
- package/src/runtime/automation_liveness_tests.zig +140 -0
- package/src/runtime/automation_snapshot.zig +246 -0
- package/src/runtime/automation_widget_dispatch.zig +617 -0
- package/src/runtime/bridge_dispatch_tests.zig +202 -0
- package/src/runtime/bridge_payload.zig +194 -0
- package/src/runtime/bridge_permission_tests.zig +551 -0
- package/src/runtime/bridge_responses.zig +414 -0
- package/src/runtime/builtin_bridge.zig +554 -0
- package/src/runtime/canvas_budget_edge_tests.zig +415 -0
- package/src/runtime/canvas_font_tests.zig +410 -0
- package/src/runtime/canvas_fonts.zig +229 -0
- package/src/runtime/canvas_frame.zig +1734 -0
- package/src/runtime/canvas_frame_animation_tests.zig +609 -0
- package/src/runtime/canvas_frame_cache_tests.zig +333 -0
- package/src/runtime/canvas_frame_helpers.zig +414 -0
- package/src/runtime/canvas_frame_invalidation_tests.zig +544 -0
- package/src/runtime/canvas_frame_packet_tests.zig +1353 -0
- package/src/runtime/canvas_frame_patch_tests.zig +1051 -0
- package/src/runtime/canvas_frame_retained_tests.zig +753 -0
- package/src/runtime/canvas_frame_tests.zig +9 -0
- package/src/runtime/canvas_frame_text_layout_budget_tests.zig +149 -0
- package/src/runtime/canvas_image_tests.zig +362 -0
- package/src/runtime/canvas_images.zig +224 -0
- package/src/runtime/canvas_limits.zig +317 -0
- package/src/runtime/canvas_screenshot_tests.zig +289 -0
- package/src/runtime/canvas_widget_accessibility_tests.zig +1494 -0
- package/src/runtime/canvas_widget_anchored_tests.zig +678 -0
- package/src/runtime/canvas_widget_chart_tests.zig +249 -0
- package/src/runtime/canvas_widget_clipboard_tests.zig +399 -0
- package/src/runtime/canvas_widget_context_menu.zig +318 -0
- package/src/runtime/canvas_widget_context_menu_tests.zig +462 -0
- package/src/runtime/canvas_widget_control_tests.zig +2164 -0
- package/src/runtime/canvas_widget_disclosure_tests.zig +440 -0
- package/src/runtime/canvas_widget_display.zig +677 -0
- package/src/runtime/canvas_widget_event_tests.zig +1779 -0
- package/src/runtime/canvas_widget_events.zig +1098 -0
- package/src/runtime/canvas_widget_floating_tests.zig +695 -0
- package/src/runtime/canvas_widget_layout_tests.zig +26 -0
- package/src/runtime/canvas_widget_runtime.zig +1335 -0
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +582 -0
- package/src/runtime/canvas_widget_scroll_drivers.zig +202 -0
- package/src/runtime/canvas_widget_scroll_tests.zig +1549 -0
- package/src/runtime/canvas_widget_semantics_tests.zig +810 -0
- package/src/runtime/canvas_widget_split_tree_tests.zig +1031 -0
- package/src/runtime/canvas_widget_state.zig +798 -0
- package/src/runtime/canvas_widget_text_tests.zig +2104 -0
- package/src/runtime/canvas_widget_window_drag_tests.zig +284 -0
- package/src/runtime/clock.zig +231 -0
- package/src/runtime/core.zig +927 -0
- package/src/runtime/effects.zig +4197 -0
- package/src/runtime/effects_audio_tests.zig +690 -0
- package/src/runtime/effects_clipboard_tests.zig +317 -0
- package/src/runtime/effects_fetch_tests.zig +1031 -0
- package/src/runtime/effects_file_tests.zig +407 -0
- package/src/runtime/effects_tests.zig +1251 -0
- package/src/runtime/flow.zig +1175 -0
- package/src/runtime/frame_profile.zig +221 -0
- package/src/runtime/gpu_surface_events.zig +639 -0
- package/src/runtime/launch_timing.zig +59 -0
- package/src/runtime/markdown_app_tests.zig +224 -0
- package/src/runtime/native_command_event_tests.zig +431 -0
- package/src/runtime/platform_bridge_tests.zig +8 -0
- package/src/runtime/platform_config_tests.zig +392 -0
- package/src/runtime/root.zig +150 -0
- package/src/runtime/runtime_event_tests.zig +1079 -0
- package/src/runtime/session_journal.zig +1522 -0
- package/src/runtime/session_record.zig +332 -0
- package/src/runtime/session_replay.zig +274 -0
- package/src/runtime/session_state.zig +30 -0
- package/src/runtime/session_tests.zig +399 -0
- package/src/runtime/shell_layout.zig +472 -0
- package/src/runtime/shell_layout_tests.zig +1246 -0
- package/src/runtime/shell_view_tests.zig +604 -0
- package/src/runtime/state.zig +110 -0
- package/src/runtime/system_services.zig +392 -0
- package/src/runtime/test_support.zig +79 -0
- package/src/runtime/tests.zig +30 -0
- package/src/runtime/ui_app.zig +3290 -0
- package/src/runtime/ui_app_huge_model_tests.zig +351 -0
- package/src/runtime/ui_app_provenance.zig +370 -0
- package/src/runtime/ui_app_tests.zig +3254 -0
- package/src/runtime/ui_app_virtual_variable_tests.zig +485 -0
- package/src/runtime/ui_app_window_tests.zig +442 -0
- package/src/runtime/validation.zig +206 -0
- package/src/runtime/view.zig +908 -0
- package/src/runtime/view_canvas.zig +850 -0
- package/src/runtime/view_widget_control.zig +433 -0
- package/src/runtime/view_widget_scroll.zig +360 -0
- package/src/runtime/view_widget_text.zig +275 -0
- package/src/runtime/view_widget_tree.zig +843 -0
- package/src/runtime/webview_view_bridge_tests.zig +664 -0
- package/src/runtime/widget_bridge.zig +231 -0
- package/src/runtime/window_command_bridge_tests.zig +403 -0
- package/src/runtime/window_storage.zig +255 -0
- package/src/runtime/window_view_runtime.zig +727 -0
- package/src/runtime/window_views.zig +334 -0
- package/src/security/root.zig +118 -0
- package/src/tooling/android.zig +1172 -0
- package/src/tooling/assets.zig +128 -0
- package/src/tooling/buildgraph.zig +379 -0
- package/src/tooling/cef.zig +671 -0
- package/src/tooling/codesign.zig +172 -0
- package/src/tooling/components/identity_tests.zig +185 -0
- package/src/tooling/components/stepper.zig +113 -0
- package/src/tooling/components/timeline.native +27 -0
- package/src/tooling/components/timeline_item.zig +131 -0
- package/src/tooling/default_icon.icns +0 -0
- package/src/tooling/default_icon.png +0 -0
- package/src/tooling/dev.zig +172 -0
- package/src/tooling/doctor.zig +349 -0
- package/src/tooling/eject_components.zig +170 -0
- package/src/tooling/embedlib.zig +290 -0
- package/src/tooling/ios.zig +528 -0
- package/src/tooling/manifest.zig +1939 -0
- package/src/tooling/package.zig +2388 -0
- package/src/tooling/process_tree.zig +114 -0
- package/src/tooling/raw_manifest.zig +193 -0
- package/src/tooling/root.zig +22 -0
- package/src/tooling/templates.zig +3191 -0
- package/src/tooling/toolchain.zig +371 -0
- package/src/tooling/verbs.zig +204 -0
- package/src/tooling/web_engine.zig +135 -0
- package/src/tooling/xcodeproj.zig +462 -0
- package/src/window_state/root.zig +507 -0
- package/index.js +0 -2
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
const platform = @import("../platform/root.zig");
|
|
2
|
+
|
|
3
|
+
pub const max_mobile_command_name_bytes: usize = 128;
|
|
4
|
+
pub const max_mobile_input_text_bytes: usize = 512;
|
|
5
|
+
pub const max_mobile_asset_root_bytes: usize = platform.max_webview_url_bytes;
|
|
6
|
+
pub const max_mobile_asset_entry_bytes: usize = platform.max_window_source_path_bytes;
|
|
7
|
+
pub const mobile_gpu_surface_label = "mobile-surface";
|
|
8
|
+
|
|
9
|
+
pub const MobileWidgetRole = enum(c_int) {
|
|
10
|
+
none = 0,
|
|
11
|
+
group = 1,
|
|
12
|
+
text = 2,
|
|
13
|
+
image = 3,
|
|
14
|
+
button = 4,
|
|
15
|
+
textbox = 5,
|
|
16
|
+
tooltip = 6,
|
|
17
|
+
dialog = 7,
|
|
18
|
+
menu = 8,
|
|
19
|
+
menuitem = 9,
|
|
20
|
+
list = 10,
|
|
21
|
+
listitem = 11,
|
|
22
|
+
row = 12,
|
|
23
|
+
grid = 13,
|
|
24
|
+
gridcell = 14,
|
|
25
|
+
tab = 15,
|
|
26
|
+
checkbox = 16,
|
|
27
|
+
switch_control = 17,
|
|
28
|
+
slider = 18,
|
|
29
|
+
progressbar = 19,
|
|
30
|
+
radio = 20,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
pub const MobileWidgetFlag = enum(u32) {
|
|
34
|
+
focused = 1 << 0,
|
|
35
|
+
hovered = 1 << 1,
|
|
36
|
+
pressed = 1 << 2,
|
|
37
|
+
selected = 1 << 3,
|
|
38
|
+
disabled = 1 << 4,
|
|
39
|
+
focusable = 1 << 5,
|
|
40
|
+
expanded = 1 << 6,
|
|
41
|
+
collapsed = 1 << 7,
|
|
42
|
+
required = 1 << 8,
|
|
43
|
+
read_only = 1 << 9,
|
|
44
|
+
invalid = 1 << 10,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
pub const MobileWidgetAction = enum(u32) {
|
|
48
|
+
focus = 1 << 0,
|
|
49
|
+
press = 1 << 1,
|
|
50
|
+
toggle = 1 << 2,
|
|
51
|
+
increment = 1 << 3,
|
|
52
|
+
decrement = 1 << 4,
|
|
53
|
+
set_text = 1 << 5,
|
|
54
|
+
set_selection = 1 << 6,
|
|
55
|
+
select = 1 << 7,
|
|
56
|
+
drag = 1 << 8,
|
|
57
|
+
drop_files = 1 << 9,
|
|
58
|
+
dismiss = 1 << 10,
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
pub const MobileWidgetActionKind = enum(c_int) {
|
|
62
|
+
focus = 0,
|
|
63
|
+
press = 1,
|
|
64
|
+
toggle = 2,
|
|
65
|
+
increment = 3,
|
|
66
|
+
decrement = 4,
|
|
67
|
+
set_text = 5,
|
|
68
|
+
set_selection = 6,
|
|
69
|
+
set_composition = 7,
|
|
70
|
+
commit_composition = 8,
|
|
71
|
+
cancel_composition = 9,
|
|
72
|
+
select = 10,
|
|
73
|
+
drag = 11,
|
|
74
|
+
drop_files = 12,
|
|
75
|
+
dismiss = 13,
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
pub const MobileWidgetSemantics = extern struct {
|
|
79
|
+
id: u64 = 0,
|
|
80
|
+
parent_id: u64 = 0,
|
|
81
|
+
role: c_int = @intFromEnum(MobileWidgetRole.none),
|
|
82
|
+
flags: u32 = 0,
|
|
83
|
+
actions: u32 = 0,
|
|
84
|
+
x: f32 = 0,
|
|
85
|
+
y: f32 = 0,
|
|
86
|
+
width: f32 = 0,
|
|
87
|
+
height: f32 = 0,
|
|
88
|
+
value: f32 = 0,
|
|
89
|
+
has_value: c_int = 0,
|
|
90
|
+
label: ?[*]const u8 = null,
|
|
91
|
+
label_len: usize = 0,
|
|
92
|
+
text: ?[*]const u8 = null,
|
|
93
|
+
text_len: usize = 0,
|
|
94
|
+
placeholder: ?[*]const u8 = null,
|
|
95
|
+
placeholder_len: usize = 0,
|
|
96
|
+
text_selection_start: isize = -1,
|
|
97
|
+
text_selection_end: isize = -1,
|
|
98
|
+
text_composition_start: isize = -1,
|
|
99
|
+
text_composition_end: isize = -1,
|
|
100
|
+
grid_row_index: isize = -1,
|
|
101
|
+
grid_column_index: isize = -1,
|
|
102
|
+
grid_row_count: isize = -1,
|
|
103
|
+
grid_column_count: isize = -1,
|
|
104
|
+
list_item_index: isize = -1,
|
|
105
|
+
list_item_count: isize = -1,
|
|
106
|
+
scroll_offset: f32 = 0,
|
|
107
|
+
scroll_viewport_extent: f32 = 0,
|
|
108
|
+
scroll_content_extent: f32 = 0,
|
|
109
|
+
has_scroll: c_int = 0,
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
pub const MobileWidgetTextGeometry = extern struct {
|
|
113
|
+
id: u64 = 0,
|
|
114
|
+
has_caret_bounds: c_int = 0,
|
|
115
|
+
caret_x: f32 = 0,
|
|
116
|
+
caret_y: f32 = 0,
|
|
117
|
+
caret_width: f32 = 0,
|
|
118
|
+
caret_height: f32 = 0,
|
|
119
|
+
has_selection_bounds: c_int = 0,
|
|
120
|
+
selection_x: f32 = 0,
|
|
121
|
+
selection_y: f32 = 0,
|
|
122
|
+
selection_width: f32 = 0,
|
|
123
|
+
selection_height: f32 = 0,
|
|
124
|
+
selection_rect_count: usize = 0,
|
|
125
|
+
has_composition_bounds: c_int = 0,
|
|
126
|
+
composition_x: f32 = 0,
|
|
127
|
+
composition_y: f32 = 0,
|
|
128
|
+
composition_width: f32 = 0,
|
|
129
|
+
composition_height: f32 = 0,
|
|
130
|
+
composition_rect_count: usize = 0,
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
pub const MobileWidgetActionRequest = extern struct {
|
|
134
|
+
id: u64 = 0,
|
|
135
|
+
action: c_int = @intFromEnum(MobileWidgetActionKind.focus),
|
|
136
|
+
text: ?[*]const u8 = null,
|
|
137
|
+
text_len: usize = 0,
|
|
138
|
+
selection_anchor: usize = 0,
|
|
139
|
+
selection_focus: usize = 0,
|
|
140
|
+
has_selection: c_int = 0,
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
/// Focus / IME-intent state for the mobile surface. `active` is nonzero
|
|
144
|
+
/// when an editable text widget owns focus — the platform shim shows the
|
|
145
|
+
/// system keyboard while it is set and hides it when it clears.
|
|
146
|
+
/// `widget_id` is the focused widget (editable or not; 0 when nothing is
|
|
147
|
+
/// focused) and the bounds are its frame in view points, so the shim can
|
|
148
|
+
/// keep the caret visible above the keyboard.
|
|
149
|
+
pub const MobileTextInputState = extern struct {
|
|
150
|
+
active: c_int = 0,
|
|
151
|
+
widget_id: u64 = 0,
|
|
152
|
+
x: f32 = 0,
|
|
153
|
+
y: f32 = 0,
|
|
154
|
+
width: f32 = 0,
|
|
155
|
+
height: f32 = 0,
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
pub const MobileViewportState = extern struct {
|
|
159
|
+
width: f32 = 0,
|
|
160
|
+
height: f32 = 0,
|
|
161
|
+
scale: f32 = 1,
|
|
162
|
+
has_surface: c_int = 0,
|
|
163
|
+
safe_top: f32 = 0,
|
|
164
|
+
safe_right: f32 = 0,
|
|
165
|
+
safe_bottom: f32 = 0,
|
|
166
|
+
safe_left: f32 = 0,
|
|
167
|
+
keyboard_top: f32 = 0,
|
|
168
|
+
keyboard_right: f32 = 0,
|
|
169
|
+
keyboard_bottom: f32 = 0,
|
|
170
|
+
keyboard_left: f32 = 0,
|
|
171
|
+
content_x: f32 = 0,
|
|
172
|
+
content_y: f32 = 0,
|
|
173
|
+
content_width: f32 = 0,
|
|
174
|
+
content_height: f32 = 0,
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
/// Platform text-measure callback registered through
|
|
178
|
+
/// `native_sdk_app_set_text_measure`: returns the typographic width of a
|
|
179
|
+
/// single-line UTF-8 run at `size` for `font_id` (1 = sans, 2 = mono),
|
|
180
|
+
/// measured with the same font resolution the shim's presentation would
|
|
181
|
+
/// draw with (CoreText on iOS, mirroring the desktop
|
|
182
|
+
/// `native_sdk_appkit_measure_text` seam). Return a negative value to
|
|
183
|
+
/// fall back to the deterministic estimator for that run (e.g. invalid
|
|
184
|
+
/// UTF-8).
|
|
185
|
+
pub const MobileTextMeasureFn = *const fn (
|
|
186
|
+
context: ?*anyopaque,
|
|
187
|
+
font_id: u64,
|
|
188
|
+
size: f64,
|
|
189
|
+
text: ?[*]const u8,
|
|
190
|
+
text_len: usize,
|
|
191
|
+
) callconv(.c) f64;
|
|
192
|
+
|
|
193
|
+
// ------------------------------------------------------------------ audio
|
|
194
|
+
//
|
|
195
|
+
// The platform audio service over the embed C ABI. A mobile shim that owns
|
|
196
|
+
// a real audio player (the iOS toolkit host: AVAudioPlayer for local files
|
|
197
|
+
// and verified cache entries, AVPlayer for progressive URL streams)
|
|
198
|
+
// registers this callback table through `native_sdk_app_set_audio_service`
|
|
199
|
+
// and reports everything asynchronous back through
|
|
200
|
+
// `native_sdk_app_audio_event`. Hosts without a registered service decline
|
|
201
|
+
// audio honestly: `audio_playback`/`audio_streaming` report unsupported and
|
|
202
|
+
// `fx.playAudio` degrades to one explicit `.failed` Msg — never a silent
|
|
203
|
+
// fake player inside a real app.
|
|
204
|
+
|
|
205
|
+
/// Synchronous local-file load. Returns 0 when the player loaded and
|
|
206
|
+
/// decoded the file (the asynchronous `.loaded` acknowledgment with the
|
|
207
|
+
/// real duration follows as an audio event), 1 when the file is missing
|
|
208
|
+
/// or unreadable, anything else for a decode failure — the exact
|
|
209
|
+
/// contract of the macOS host's `native_sdk_appkit_audio_load`.
|
|
210
|
+
pub const MobileAudioLoadFn = *const fn (
|
|
211
|
+
context: ?*anyopaque,
|
|
212
|
+
path: ?[*]const u8,
|
|
213
|
+
path_len: usize,
|
|
214
|
+
) callconv(.c) c_int;
|
|
215
|
+
|
|
216
|
+
/// URL source resolution. Returns 1 when a verified cache entry at
|
|
217
|
+
/// `cache_path` is playing locally (no network), 0 when a progressive
|
|
218
|
+
/// stream started (the `.loaded` acknowledgment follows when the item is
|
|
219
|
+
/// ready; the same bytes fill `cache_path` for the next play, gated by
|
|
220
|
+
/// `expected_bytes`), anything else when the URL itself is unusable.
|
|
221
|
+
pub const MobileAudioLoadUrlFn = *const fn (
|
|
222
|
+
context: ?*anyopaque,
|
|
223
|
+
url: ?[*]const u8,
|
|
224
|
+
url_len: usize,
|
|
225
|
+
cache_path: ?[*]const u8,
|
|
226
|
+
cache_path_len: usize,
|
|
227
|
+
expected_bytes: u64,
|
|
228
|
+
) callconv(.c) c_int;
|
|
229
|
+
|
|
230
|
+
/// Transport calls without arguments (play/pause/stop). Play returns
|
|
231
|
+
/// nonzero when it applied to a loaded player and 0 when there is no
|
|
232
|
+
/// player to start; pause and stop results are advisory.
|
|
233
|
+
pub const MobileAudioTransportFn = *const fn (context: ?*anyopaque) callconv(.c) c_int;
|
|
234
|
+
|
|
235
|
+
/// Seek to an absolute position (the player clamps to the duration).
|
|
236
|
+
/// Returns nonzero when it applied, 0 when there is no player.
|
|
237
|
+
pub const MobileAudioSeekFn = *const fn (context: ?*anyopaque, position_ms: u64) callconv(.c) c_int;
|
|
238
|
+
|
|
239
|
+
/// Set playback volume (0.0–1.0, pre-clamped by the runtime). The result
|
|
240
|
+
/// is advisory.
|
|
241
|
+
pub const MobileAudioSetVolumeFn = *const fn (context: ?*anyopaque, volume: f64) callconv(.c) c_int;
|
|
242
|
+
|
|
243
|
+
/// The audio service callback table (`native_sdk_audio_service_t` in the
|
|
244
|
+
/// shim headers). Registration is tiered and all-or-nothing per tier:
|
|
245
|
+
/// local playback needs every entry except `load_url`; `load_url` on top
|
|
246
|
+
/// of that enables streaming (`audio_streaming`). A table with only some
|
|
247
|
+
/// playback entries is refused — a player that can start but not stop is
|
|
248
|
+
/// not a player.
|
|
249
|
+
pub const MobileAudioService = extern struct {
|
|
250
|
+
load: ?MobileAudioLoadFn = null,
|
|
251
|
+
load_url: ?MobileAudioLoadUrlFn = null,
|
|
252
|
+
play: ?MobileAudioTransportFn = null,
|
|
253
|
+
pause: ?MobileAudioTransportFn = null,
|
|
254
|
+
stop: ?MobileAudioTransportFn = null,
|
|
255
|
+
seek: ?MobileAudioSeekFn = null,
|
|
256
|
+
set_volume: ?MobileAudioSetVolumeFn = null,
|
|
257
|
+
|
|
258
|
+
pub fn playbackComplete(self: MobileAudioService) bool {
|
|
259
|
+
return self.load != null and self.play != null and self.pause != null and
|
|
260
|
+
self.stop != null and self.seek != null and self.set_volume != null;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
pub fn empty(self: MobileAudioService) bool {
|
|
264
|
+
return self.load == null and self.load_url == null and self.play == null and
|
|
265
|
+
self.pause == null and self.stop == null and self.seek == null and
|
|
266
|
+
self.set_volume == null;
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
// ------------------------------------------------------------ image decode
|
|
271
|
+
//
|
|
272
|
+
// The platform image-decode service over the embed C ABI. A mobile shim
|
|
273
|
+
// that owns a real image codec (the iOS toolkit host: CGImageSource, the
|
|
274
|
+
// same ImageIO family the macOS host decodes through; the Android toolkit
|
|
275
|
+
// host: BitmapFactory over JNI) registers this callback table through
|
|
276
|
+
// `native_sdk_app_set_image_service`, and the runtime's
|
|
277
|
+
// `fx.registerImageBytes` decodes encoded bytes (PNG, JPEG, ...) through
|
|
278
|
+
// it — the same `PlatformServices.decode_image_fn` seam the desktop
|
|
279
|
+
// platform codecs serve. Hosts without a registered service decline
|
|
280
|
+
// honestly: `registerImageBytes` reports `error.UnsupportedService` and
|
|
281
|
+
// image/avatar widgets keep their fallback (initials) — never a bundled
|
|
282
|
+
// codec pretending to be the platform's.
|
|
283
|
+
|
|
284
|
+
/// Synchronous decode of encoded image bytes into tightly packed,
|
|
285
|
+
/// row-major, straight-alpha (non-premultiplied) RGBA8 written into
|
|
286
|
+
/// `pixels`, reporting the dimensions through the out parameters. Returns
|
|
287
|
+
/// 1 when the image decoded (`*out_width * *out_height * 4` bytes fill a
|
|
288
|
+
/// prefix of `pixels`), -1 when the decoded pixels do not fit
|
|
289
|
+
/// `pixels_len`, anything else for undecodable bytes — the exact contract
|
|
290
|
+
/// of the macOS host's `native_sdk_appkit_decode_image`.
|
|
291
|
+
pub const MobileImageDecodeFn = *const fn (
|
|
292
|
+
context: ?*anyopaque,
|
|
293
|
+
bytes: ?[*]const u8,
|
|
294
|
+
bytes_len: usize,
|
|
295
|
+
pixels: ?[*]u8,
|
|
296
|
+
pixels_len: usize,
|
|
297
|
+
out_width: ?*usize,
|
|
298
|
+
out_height: ?*usize,
|
|
299
|
+
) callconv(.c) c_int;
|
|
300
|
+
|
|
301
|
+
/// The image service callback table (`native_sdk_image_service_t` in the
|
|
302
|
+
/// shim headers). One tier today: a table with `decode` registers the
|
|
303
|
+
/// platform codec, an empty table clears it back to the honest decline.
|
|
304
|
+
pub const MobileImageService = extern struct {
|
|
305
|
+
decode: ?MobileImageDecodeFn = null,
|
|
306
|
+
|
|
307
|
+
pub fn complete(self: MobileImageService) bool {
|
|
308
|
+
return self.decode != null;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
pub fn empty(self: MobileImageService) bool {
|
|
312
|
+
return self.decode == null;
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
/// Dimensions of a canvas render produced by
|
|
317
|
+
/// `native_sdk_app_render_pixels` (tightly packed RGBA8).
|
|
318
|
+
pub const MobileCanvasPixels = extern struct {
|
|
319
|
+
width: usize = 0,
|
|
320
|
+
height: usize = 0,
|
|
321
|
+
byte_len: usize = 0,
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
/// Result of `native_sdk_app_render_pixels_damage`: the surface
|
|
325
|
+
/// dimensions (identical meaning to `MobileCanvasPixels`) plus the
|
|
326
|
+
/// damaged region this call wrote into the caller's RETAINED buffer, in
|
|
327
|
+
/// device pixels. `damage_width == 0 or damage_height == 0` means
|
|
328
|
+
/// nothing changed since the previous call — the buffer already shows
|
|
329
|
+
/// the current frame and the host skips its upload entirely. A first
|
|
330
|
+
/// call (and any size or scale change) reports the full surface.
|
|
331
|
+
pub const MobileCanvasPixelsDamage = extern struct {
|
|
332
|
+
width: usize = 0,
|
|
333
|
+
height: usize = 0,
|
|
334
|
+
byte_len: usize = 0,
|
|
335
|
+
damage_x: usize = 0,
|
|
336
|
+
damage_y: usize = 0,
|
|
337
|
+
damage_width: usize = 0,
|
|
338
|
+
damage_height: usize = 0,
|
|
339
|
+
/// The retained-canvas revision the buffer now REFLECTS. The host's
|
|
340
|
+
/// re-render gate must compare `native_sdk_app_gpu_frame_state`'s
|
|
341
|
+
/// `canvas_revision` against THIS value, not against its own last
|
|
342
|
+
/// sighting: a revision whose frame has not presented yet delivers
|
|
343
|
+
/// empty damage with the OLD revision, telling the host to call
|
|
344
|
+
/// again next tick (the runtime presents one frame pump after the
|
|
345
|
+
/// change that produced it — gating on sightings alone strands that
|
|
346
|
+
/// present's damage and leaves stale pixels on the glass).
|
|
347
|
+
revision: u64 = 0,
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
pub const MobileGpuFrameState = extern struct {
|
|
351
|
+
surface_id: u64 = 0,
|
|
352
|
+
window_id: u64 = 0,
|
|
353
|
+
width: f32 = 0,
|
|
354
|
+
height: f32 = 0,
|
|
355
|
+
scale: f32 = 1,
|
|
356
|
+
frame_index: u64 = 0,
|
|
357
|
+
timestamp_ns: u64 = 0,
|
|
358
|
+
frame_interval_ns: u64 = platform.default_gpu_frame_interval_ns,
|
|
359
|
+
input_timestamp_ns: u64 = 0,
|
|
360
|
+
input_latency_ns: u64 = 0,
|
|
361
|
+
input_latency_budget_ns: u64 = platform.default_gpu_frame_interval_ns,
|
|
362
|
+
input_latency_budget_exceeded_count: usize = 0,
|
|
363
|
+
input_latency_budget_ok: c_int = 1,
|
|
364
|
+
first_frame_latency_ns: u64 = 0,
|
|
365
|
+
first_frame_latency_budget_ns: u64 = platform.default_gpu_first_frame_latency_budget_ns,
|
|
366
|
+
first_frame_latency_budget_exceeded_count: usize = 0,
|
|
367
|
+
first_frame_latency_budget_ok: c_int = 1,
|
|
368
|
+
nonblank: c_int = 0,
|
|
369
|
+
sample_color: u32 = 0,
|
|
370
|
+
status: c_int = @intFromEnum(platform.GpuSurfaceStatus.unavailable),
|
|
371
|
+
vsync: c_int = 0,
|
|
372
|
+
canvas_revision: u64 = 0,
|
|
373
|
+
canvas_command_count: usize = 0,
|
|
374
|
+
canvas_frame_requires_render: c_int = 0,
|
|
375
|
+
canvas_frame_full_repaint: c_int = 0,
|
|
376
|
+
canvas_frame_batch_count: usize = 0,
|
|
377
|
+
canvas_frame_budget_exceeded_count: usize = 0,
|
|
378
|
+
canvas_frame_budget_ok: c_int = 1,
|
|
379
|
+
widget_revision: u64 = 0,
|
|
380
|
+
widget_node_count: usize = 0,
|
|
381
|
+
widget_semantics_count: usize = 0,
|
|
382
|
+
};
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
//! Mobile embed host that drives a user `UiApp` (Model/Msg/update/view)
|
|
2
|
+
//! behind the same C ABI the fixed WebView shell answers.
|
|
3
|
+
//!
|
|
4
|
+
//! `UiAppHost(AppDef)` is the mobile equivalent of the desktop app runner:
|
|
5
|
+
//! the static library is compiled *with* the app. `AppDef` is the app's
|
|
6
|
+
//! root module (wired as the `"app"` import by `native_sdk.addMobileLib`)
|
|
7
|
+
//! and must declare:
|
|
8
|
+
//!
|
|
9
|
+
//! - `pub const Model` / `pub const Msg`
|
|
10
|
+
//! - `pub fn initModel() Model`
|
|
11
|
+
//! - `pub fn mobileOptions() native_sdk.UiApp(Model, Msg).Options` — the
|
|
12
|
+
//! same options a desktop `UiApp` takes. The scene must contain a
|
|
13
|
+
//! `gpu_surface` view labeled `mobile-surface` in the first window and
|
|
14
|
+
//! `canvas_label` must be `mobile-surface` (use `mobile_shell_scene` /
|
|
15
|
+
//! `mobile_gpu_surface_label` for the canonical single-surface scene).
|
|
16
|
+
//! - optional `pub const features: native_sdk.UiAppFeatures`
|
|
17
|
+
//!
|
|
18
|
+
//! The host owns a `NullPlatform` runtime (M1: no real surface — M2 adds
|
|
19
|
+
//! presentation) and pumps the `UiApp` loop from the shim's frame callback:
|
|
20
|
+
//! `native_sdk_app_frame` synthesizes the `gpu_surface_frame` event a
|
|
21
|
+
//! desktop platform's display link would deliver, which installs the widget
|
|
22
|
+
//! tree on the first tick and re-presents afterwards. Frames render through
|
|
23
|
+
//! the CPU reference renderer; the presented pixels are retrievable over
|
|
24
|
+
//! the ABI via `native_sdk_app_render_pixels`.
|
|
25
|
+
|
|
26
|
+
const std = @import("std");
|
|
27
|
+
const app_manifest = @import("app_manifest");
|
|
28
|
+
const canvas = @import("canvas");
|
|
29
|
+
const runtime = @import("../runtime/root.zig");
|
|
30
|
+
const platform = @import("../platform/root.zig");
|
|
31
|
+
const types = @import("types.zig");
|
|
32
|
+
const host = @import("host.zig");
|
|
33
|
+
const conversions = @import("conversions.zig");
|
|
34
|
+
|
|
35
|
+
const EmbeddedApp = host.EmbeddedApp;
|
|
36
|
+
const mobile_gpu_surface_label = types.mobile_gpu_surface_label;
|
|
37
|
+
const max_mobile_command_name_bytes = types.max_mobile_command_name_bytes;
|
|
38
|
+
const max_mobile_asset_root_bytes = types.max_mobile_asset_root_bytes;
|
|
39
|
+
const max_mobile_asset_entry_bytes = types.max_mobile_asset_entry_bytes;
|
|
40
|
+
const nowNanoseconds = conversions.nowNanoseconds;
|
|
41
|
+
|
|
42
|
+
/// Canonical mobile scene: one window, one gpu_surface view labeled
|
|
43
|
+
/// `mobile-surface` filling it. Apps that need nothing else point their
|
|
44
|
+
/// `Options.scene` here.
|
|
45
|
+
pub const mobile_shell_views = [_]app_manifest.ShellView{.{
|
|
46
|
+
.label = mobile_gpu_surface_label,
|
|
47
|
+
.kind = .gpu_surface,
|
|
48
|
+
.fill = true,
|
|
49
|
+
.gpu_backend = .metal,
|
|
50
|
+
}};
|
|
51
|
+
|
|
52
|
+
pub const mobile_shell_windows = [_]app_manifest.ShellWindow{.{
|
|
53
|
+
.label = "main",
|
|
54
|
+
.views = &mobile_shell_views,
|
|
55
|
+
}};
|
|
56
|
+
|
|
57
|
+
pub const mobile_shell_scene: app_manifest.ShellConfig = .{ .windows = &mobile_shell_windows };
|
|
58
|
+
|
|
59
|
+
pub fn UiAppHost(comptime AppDef: type) type {
|
|
60
|
+
const features: runtime.UiAppFeatures = if (@hasDecl(AppDef, "features")) AppDef.features else .{};
|
|
61
|
+
return struct {
|
|
62
|
+
const Self = @This();
|
|
63
|
+
|
|
64
|
+
pub const MobileUi = runtime.UiAppWithFeatures(AppDef.Model, AppDef.Msg, features);
|
|
65
|
+
|
|
66
|
+
null_platform: platform.NullPlatform,
|
|
67
|
+
ui: MobileUi,
|
|
68
|
+
/// The UiApp's own runtime.App (typed dispatch into update/view);
|
|
69
|
+
/// the host wraps it so ABI-facing counters observe every event.
|
|
70
|
+
inner_app: runtime.App,
|
|
71
|
+
embedded: EmbeddedApp,
|
|
72
|
+
started: bool = false,
|
|
73
|
+
frame_index: u64 = 0,
|
|
74
|
+
last_error: ?anyerror = null,
|
|
75
|
+
command_count: usize = 0,
|
|
76
|
+
last_command_name: [max_mobile_command_name_bytes + 1]u8 = [_]u8{0} ** (max_mobile_command_name_bytes + 1),
|
|
77
|
+
asset_root: [max_mobile_asset_root_bytes]u8 = undefined,
|
|
78
|
+
asset_root_len: usize = 0,
|
|
79
|
+
asset_entry: [max_mobile_asset_entry_bytes]u8 = undefined,
|
|
80
|
+
asset_entry_len: usize = 0,
|
|
81
|
+
automation_dir: [max_mobile_asset_root_bytes]u8 = undefined,
|
|
82
|
+
automation_dir_len: usize = 0,
|
|
83
|
+
automation_io: ?*std.Io.Threaded = null,
|
|
84
|
+
text_measure: host.MobileTextMeasure = .{},
|
|
85
|
+
audio: host.MobileAudio = .{},
|
|
86
|
+
// Image decode stays declined until the shim registers a real
|
|
87
|
+
// codec (`native_sdk_app_set_image_service`): the null platform's
|
|
88
|
+
// strict test decoder is opt-in (`image_decode`, default off), so
|
|
89
|
+
// with no registration `fx.registerImageBytes` reports
|
|
90
|
+
// UnsupportedService and image/avatar widgets keep their fallback.
|
|
91
|
+
image: host.MobileImage = .{},
|
|
92
|
+
/// Standing host chrome reports (see `host.setFormFactor` /
|
|
93
|
+
/// `host.setChromeTabsProjected`): composed into every
|
|
94
|
+
/// viewport-driven chrome publish.
|
|
95
|
+
form_factor: platform.FormFactor = .unknown,
|
|
96
|
+
chrome_tabs_projected: bool = false,
|
|
97
|
+
/// Presented-pixel capture behind
|
|
98
|
+
/// `native_sdk_app_render_pixels_damage` (see
|
|
99
|
+
/// `host.installPresentCapture`): the last present's borrowed
|
|
100
|
+
/// pixels plus accumulated damage, and the chained platform
|
|
101
|
+
/// pixel presenter the capture bridge forwards to.
|
|
102
|
+
presented: host.MobilePresentedCanvas = .{},
|
|
103
|
+
present_pixels_chain: ?host.MobilePresentPixelsFn = null,
|
|
104
|
+
/// Render memo for the pixel present path (heavyweight command
|
|
105
|
+
/// replay + scale-once image panels); attached to the runtime by
|
|
106
|
+
/// `host.installPresentCapture`, freed on destroy.
|
|
107
|
+
render_memo: canvas.ReferenceRenderMemo = undefined,
|
|
108
|
+
|
|
109
|
+
pub fn create() !*Self {
|
|
110
|
+
const allocator = std.heap.page_allocator;
|
|
111
|
+
const self = try allocator.create(Self);
|
|
112
|
+
errdefer allocator.destroy(self);
|
|
113
|
+
const options = AppDef.mobileOptions();
|
|
114
|
+
if (!std.mem.eql(u8, options.canvas_label, mobile_gpu_surface_label)) return error.InvalidViewOptions;
|
|
115
|
+
if (!sceneHasMobileSurface(options.scene)) return error.ViewNotFound;
|
|
116
|
+
self.null_platform = platform.NullPlatform.init(.{});
|
|
117
|
+
self.null_platform.gpu_surfaces = true;
|
|
118
|
+
// Audio is declined until the shim registers a real service
|
|
119
|
+
// (`native_sdk_app_set_audio_service`): without one,
|
|
120
|
+
// `fx.playAudio` degrades to one explicit `.failed` Msg
|
|
121
|
+
// instead of the null platform's hermetic fake player
|
|
122
|
+
// pretending to play. Cleared before `platform()` is
|
|
123
|
+
// snapshotted below.
|
|
124
|
+
self.null_platform.audio_playback = false;
|
|
125
|
+
self.null_platform.audio_streaming = false;
|
|
126
|
+
// The null packet presenter records only counts; disabling it
|
|
127
|
+
// routes presentation through the CPU pixel path so frames
|
|
128
|
+
// produce real pixels (the buffer M2's surface blit consumes).
|
|
129
|
+
self.null_platform.gpu_surface_packets = false;
|
|
130
|
+
self.started = false;
|
|
131
|
+
self.frame_index = 0;
|
|
132
|
+
self.last_error = null;
|
|
133
|
+
self.command_count = 0;
|
|
134
|
+
self.last_command_name = [_]u8{0} ** (max_mobile_command_name_bytes + 1);
|
|
135
|
+
self.asset_root = undefined;
|
|
136
|
+
self.asset_root_len = 0;
|
|
137
|
+
self.asset_entry = undefined;
|
|
138
|
+
self.asset_entry_len = 0;
|
|
139
|
+
self.automation_dir = undefined;
|
|
140
|
+
self.automation_dir_len = 0;
|
|
141
|
+
self.automation_io = null;
|
|
142
|
+
self.text_measure = .{};
|
|
143
|
+
self.audio = .{};
|
|
144
|
+
self.image = .{};
|
|
145
|
+
self.form_factor = .unknown;
|
|
146
|
+
self.chrome_tabs_projected = false;
|
|
147
|
+
self.presented = .{};
|
|
148
|
+
self.present_pixels_chain = null;
|
|
149
|
+
// In-place init + pointer-targeted model assignment:
|
|
150
|
+
// `initModel()`'s result writes straight into the heap
|
|
151
|
+
// struct via result-location semantics, so a multi-MB Model
|
|
152
|
+
// never materializes on this stack frame.
|
|
153
|
+
MobileUi.initInPlace(&self.ui, allocator, options);
|
|
154
|
+
self.ui.model = AppDef.initModel();
|
|
155
|
+
self.inner_app = self.ui.app();
|
|
156
|
+
self.embedded.initInPlace(.{
|
|
157
|
+
.context = self,
|
|
158
|
+
.name = options.name,
|
|
159
|
+
.scene_fn = hostScene,
|
|
160
|
+
.event_fn = hostEvent,
|
|
161
|
+
.stop_fn = hostStop,
|
|
162
|
+
}, self.null_platform.platform());
|
|
163
|
+
// The damage seam: capture pixel presents (chained through
|
|
164
|
+
// the null platform's recording present, so nonblank
|
|
165
|
+
// sampling keeps working), drop the packet presenters no
|
|
166
|
+
// mobile shim consumes, and keep the keyed baseline alive
|
|
167
|
+
// across pixel presents so changed frames raster only their
|
|
168
|
+
// dirty region.
|
|
169
|
+
host.installPresentCapture(self);
|
|
170
|
+
return self;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
pub fn destroy(self: *Self) void {
|
|
174
|
+
host.disableAutomation(self);
|
|
175
|
+
self.render_memo.deinit();
|
|
176
|
+
self.ui.deinit();
|
|
177
|
+
std.heap.page_allocator.destroy(self);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
pub fn start(self: *Self) anyerror!void {
|
|
181
|
+
self.started = true;
|
|
182
|
+
try self.embedded.start();
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/// Host-pumped frame step: the shim's display-link (or test) tick.
|
|
186
|
+
/// Synthesizes the `gpu_surface_frame` event a platform loop would
|
|
187
|
+
/// deliver for the mobile surface — first tick installs the widget
|
|
188
|
+
/// tree, later ticks re-present — then runs the runtime frame
|
|
189
|
+
/// (automation, diagnostics). `nonblank`/`sample_color` report the
|
|
190
|
+
/// previously presented pixels, mirroring how real platforms report
|
|
191
|
+
/// the surface's current contents.
|
|
192
|
+
pub fn frame(self: *Self) anyerror!void {
|
|
193
|
+
const surface = self.embedded.runtime.surface;
|
|
194
|
+
if (self.started and surface.size.width > 0 and surface.size.height > 0) {
|
|
195
|
+
self.frame_index += 1;
|
|
196
|
+
const presented = self.null_platform.gpu_surface_present_count > 0;
|
|
197
|
+
const sample = self.null_platform.gpu_surface_present_sample_rgba;
|
|
198
|
+
const sample_color = (@as(u32, sample[0]) << 24) |
|
|
199
|
+
(@as(u32, sample[1]) << 16) |
|
|
200
|
+
(@as(u32, sample[2]) << 8) |
|
|
201
|
+
@as(u32, sample[3]);
|
|
202
|
+
try self.embedded.runtime.dispatchPlatformEvent(self.embedded.app, .{ .gpu_surface_frame = .{
|
|
203
|
+
.window_id = 1,
|
|
204
|
+
.label = mobile_gpu_surface_label,
|
|
205
|
+
.size = surface.size,
|
|
206
|
+
.scale_factor = surface.scale_factor,
|
|
207
|
+
.frame_index = self.frame_index,
|
|
208
|
+
.timestamp_ns = nowNanoseconds(),
|
|
209
|
+
.nonblank = presented and sample_color != 0,
|
|
210
|
+
.sample_color = sample_color,
|
|
211
|
+
.status = .ready,
|
|
212
|
+
} });
|
|
213
|
+
}
|
|
214
|
+
try self.embedded.frame();
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
fn hostScene(context: *anyopaque) anyerror!app_manifest.ShellConfig {
|
|
218
|
+
const self: *Self = @ptrCast(@alignCast(context));
|
|
219
|
+
return self.ui.options.scene;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/// The app's declared platform-chrome tab set — the shell
|
|
223
|
+
/// metadata a projecting host builds a REAL native tab bar
|
|
224
|
+
/// from. Static manifest data, valid for the app's lifetime.
|
|
225
|
+
pub fn chromeTabs(self: *const Self) []const app_manifest.ShellTab {
|
|
226
|
+
return self.ui.options.scene.chrome.tabs;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/// The declared primary floating action, when the app declared
|
|
230
|
+
/// one beside its tab set.
|
|
231
|
+
pub fn chromePrimaryAction(self: *const Self) ?app_manifest.ShellPrimaryAction {
|
|
232
|
+
return self.ui.options.scene.chrome.primary_action;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/// The model's current selected tab id (the UiApp's
|
|
236
|
+
/// `selected_tab_fn` derivation, re-derived after every
|
|
237
|
+
/// rebuild) — what the projected bar mirrors.
|
|
238
|
+
pub fn chromeSelectedTab(self: *const Self) []const u8 {
|
|
239
|
+
return self.ui.chromeSelectedTab();
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/// The model's current navigation depth (the UiApp's
|
|
243
|
+
/// `navigation_depth_fn` derivation, re-derived after every
|
|
244
|
+
/// rebuild), or -1 when the app declares none — what a
|
|
245
|
+
/// projecting host polls to present push/pop transitions.
|
|
246
|
+
pub fn chromeNavigationDepth(self: *const Self) isize {
|
|
247
|
+
return self.ui.chromeNavigationDepth();
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/// The declared back command the platform back gesture
|
|
251
|
+
/// dispatches on completion ("" when the app declares no
|
|
252
|
+
/// navigation projection). Static app data.
|
|
253
|
+
pub fn chromeNavigationBackCommand(self: *const Self) []const u8 {
|
|
254
|
+
return self.ui.chromeNavigationBackCommand();
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
fn hostEvent(context: *anyopaque, runtime_value: *runtime.Runtime, event: runtime.Event) anyerror!void {
|
|
258
|
+
const self: *Self = @ptrCast(@alignCast(context));
|
|
259
|
+
switch (event) {
|
|
260
|
+
.command => |command_event| {
|
|
261
|
+
self.command_count += 1;
|
|
262
|
+
const count = @min(command_event.name.len, max_mobile_command_name_bytes);
|
|
263
|
+
@memcpy(self.last_command_name[0..count], command_event.name[0..count]);
|
|
264
|
+
self.last_command_name[count] = 0;
|
|
265
|
+
},
|
|
266
|
+
else => {},
|
|
267
|
+
}
|
|
268
|
+
try self.inner_app.event(runtime_value, event);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/// Forward the stop hook to the inner UiApp: a shim-driven
|
|
272
|
+
/// shutdown (`native_sdk_app_stop` dispatching `.app_shutdown`)
|
|
273
|
+
/// tears the effects channel down while the host's service
|
|
274
|
+
/// table is alive, so the later `destroy` → `ui.deinit` repeats
|
|
275
|
+
/// nothing against the platform.
|
|
276
|
+
fn hostStop(context: *anyopaque, runtime_value: *runtime.Runtime) anyerror!void {
|
|
277
|
+
const self: *Self = @ptrCast(@alignCast(context));
|
|
278
|
+
try self.inner_app.stop(runtime_value);
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
fn sceneHasMobileSurface(scene: app_manifest.ShellConfig) bool {
|
|
284
|
+
if (scene.windows.len == 0) return false;
|
|
285
|
+
for (scene.windows[0].views) |view| {
|
|
286
|
+
if (view.kind == .gpu_surface and std.mem.eql(u8, view.label, mobile_gpu_surface_label)) return true;
|
|
287
|
+
}
|
|
288
|
+
return false;
|
|
289
|
+
}
|