@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,639 @@
|
|
|
1
|
+
const geometry = @import("geometry");
|
|
2
|
+
const canvas = @import("root.zig");
|
|
3
|
+
const drawing_model = @import("drawing.zig");
|
|
4
|
+
const text_model = @import("text.zig");
|
|
5
|
+
const render_model = @import("render.zig");
|
|
6
|
+
|
|
7
|
+
const Error = canvas.Error;
|
|
8
|
+
const ObjectId = canvas.ObjectId;
|
|
9
|
+
const ImageId = canvas.ImageId;
|
|
10
|
+
const FontId = canvas.FontId;
|
|
11
|
+
const Affine = drawing_model.Affine;
|
|
12
|
+
const Color = drawing_model.Color;
|
|
13
|
+
const Radius = drawing_model.Radius;
|
|
14
|
+
const LinearGradient = drawing_model.LinearGradient;
|
|
15
|
+
const Fill = drawing_model.Fill;
|
|
16
|
+
const PathElement = drawing_model.PathElement;
|
|
17
|
+
const ImageFit = drawing_model.ImageFit;
|
|
18
|
+
const ImageSampling = drawing_model.ImageSampling;
|
|
19
|
+
const Glyph = text_model.Glyph;
|
|
20
|
+
const TextLayoutOptions = text_model.TextLayoutOptions;
|
|
21
|
+
const GlyphAtlasCacheAction = text_model.GlyphAtlasCacheAction;
|
|
22
|
+
const TextLayoutCacheAction = text_model.TextLayoutCacheAction;
|
|
23
|
+
const RenderPipelineKind = render_model.RenderPipelineKind;
|
|
24
|
+
const RenderCommand = render_model.RenderCommand;
|
|
25
|
+
const RenderBatch = render_model.RenderBatch;
|
|
26
|
+
const RenderPipelineCacheAction = render_model.RenderPipelineCacheAction;
|
|
27
|
+
const RenderPathGeometryCacheAction = render_model.RenderPathGeometryCacheAction;
|
|
28
|
+
const RenderImage = render_model.RenderImage;
|
|
29
|
+
const RenderImageCacheAction = render_model.RenderImageCacheAction;
|
|
30
|
+
const RenderLayerCacheAction = render_model.RenderLayerCacheAction;
|
|
31
|
+
const RenderResourceCacheAction = render_model.RenderResourceCacheAction;
|
|
32
|
+
const VisualEffectCacheAction = render_model.VisualEffectCacheAction;
|
|
33
|
+
|
|
34
|
+
pub const CanvasRenderPassLoadAction = enum {
|
|
35
|
+
skip,
|
|
36
|
+
load,
|
|
37
|
+
clear,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
pub const RenderEncoderBeginPass = struct {
|
|
41
|
+
load_action: CanvasRenderPassLoadAction = .skip,
|
|
42
|
+
surface_size: geometry.SizeF = .{},
|
|
43
|
+
scale: f32 = 1,
|
|
44
|
+
dirty_bounds: ?geometry.RectF = null,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
pub const RenderEncoderCommand = union(enum) {
|
|
48
|
+
begin_pass: RenderEncoderBeginPass,
|
|
49
|
+
set_scissor: geometry.RectF,
|
|
50
|
+
pipeline_cache: RenderPipelineCacheAction,
|
|
51
|
+
path_geometry_cache: RenderPathGeometryCacheAction,
|
|
52
|
+
image_cache: RenderImageCacheAction,
|
|
53
|
+
layer_cache: RenderLayerCacheAction,
|
|
54
|
+
resource_cache: RenderResourceCacheAction,
|
|
55
|
+
visual_effect_cache: VisualEffectCacheAction,
|
|
56
|
+
glyph_atlas_cache: GlyphAtlasCacheAction,
|
|
57
|
+
text_layout_cache: TextLayoutCacheAction,
|
|
58
|
+
bind_pipeline: RenderPipelineKind,
|
|
59
|
+
draw_batch: RenderBatch,
|
|
60
|
+
end_pass,
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
pub const RenderEncoderPlan = struct {
|
|
64
|
+
commands: []const RenderEncoderCommand = &.{},
|
|
65
|
+
|
|
66
|
+
pub fn commandCount(self: RenderEncoderPlan) usize {
|
|
67
|
+
return self.commands.len;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
pub fn cacheActionCount(self: RenderEncoderPlan) usize {
|
|
71
|
+
var count: usize = 0;
|
|
72
|
+
for (self.commands) |command| {
|
|
73
|
+
switch (command) {
|
|
74
|
+
.pipeline_cache, .path_geometry_cache, .image_cache, .layer_cache, .resource_cache, .visual_effect_cache, .glyph_atlas_cache, .text_layout_cache => count += 1,
|
|
75
|
+
else => {},
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return count;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
pub fn bindPipelineCount(self: RenderEncoderPlan) usize {
|
|
82
|
+
var count: usize = 0;
|
|
83
|
+
for (self.commands) |command| {
|
|
84
|
+
switch (command) {
|
|
85
|
+
.bind_pipeline => count += 1,
|
|
86
|
+
else => {},
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return count;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
pub fn drawBatchCount(self: RenderEncoderPlan) usize {
|
|
93
|
+
var count: usize = 0;
|
|
94
|
+
for (self.commands) |command| {
|
|
95
|
+
switch (command) {
|
|
96
|
+
.draw_batch => count += 1,
|
|
97
|
+
else => {},
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return count;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
pub const CanvasGpuCommandKind = enum {
|
|
105
|
+
fill_rect_solid,
|
|
106
|
+
fill_rect_gradient,
|
|
107
|
+
fill_rounded_rect_solid,
|
|
108
|
+
fill_rounded_rect_gradient,
|
|
109
|
+
stroke_rect_solid,
|
|
110
|
+
stroke_rect_gradient,
|
|
111
|
+
draw_line_solid,
|
|
112
|
+
draw_line_gradient,
|
|
113
|
+
fill_path,
|
|
114
|
+
stroke_path,
|
|
115
|
+
draw_image,
|
|
116
|
+
draw_text,
|
|
117
|
+
shadow,
|
|
118
|
+
blur,
|
|
119
|
+
unsupported,
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
pub const CanvasGpuRoundedRect = struct {
|
|
123
|
+
rect: geometry.RectF = .{},
|
|
124
|
+
radius: Radius = .{},
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
pub const CanvasGpuStrokeRect = struct {
|
|
128
|
+
rect: geometry.RectF = .{},
|
|
129
|
+
radius: Radius = .{},
|
|
130
|
+
width: f32 = 1,
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
pub const CanvasGpuLine = struct {
|
|
134
|
+
from: geometry.PointF = .{},
|
|
135
|
+
to: geometry.PointF = .{},
|
|
136
|
+
width: f32 = 1,
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
pub const CanvasGpuShape = union(enum) {
|
|
140
|
+
none,
|
|
141
|
+
rect: geometry.RectF,
|
|
142
|
+
rounded_rect: CanvasGpuRoundedRect,
|
|
143
|
+
stroke_rect: CanvasGpuStrokeRect,
|
|
144
|
+
line: CanvasGpuLine,
|
|
145
|
+
path: []const PathElement,
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
pub const CanvasGpuPaint = union(enum) {
|
|
149
|
+
none,
|
|
150
|
+
color: Color,
|
|
151
|
+
linear_gradient: LinearGradient,
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
pub const CanvasGpuImage = struct {
|
|
155
|
+
image_id: ImageId = 0,
|
|
156
|
+
src: ?geometry.RectF = null,
|
|
157
|
+
dst: geometry.RectF = .{},
|
|
158
|
+
opacity: f32 = 1,
|
|
159
|
+
fit: ImageFit = .stretch,
|
|
160
|
+
sampling: ImageSampling = .linear,
|
|
161
|
+
/// Rounded-corner mask over `dst` (the avatar circle clip).
|
|
162
|
+
radius: Radius = .{},
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
pub const CanvasGpuText = struct {
|
|
166
|
+
font_id: FontId = 0,
|
|
167
|
+
size: f32 = 0,
|
|
168
|
+
origin: geometry.PointF = .{},
|
|
169
|
+
color: Color = .{},
|
|
170
|
+
text: []const u8 = "",
|
|
171
|
+
glyphs: []const Glyph = &.{},
|
|
172
|
+
text_layout: ?TextLayoutOptions = null,
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
pub const CanvasGpuShadow = struct {
|
|
176
|
+
rect: geometry.RectF = .{},
|
|
177
|
+
radius: Radius = .{},
|
|
178
|
+
offset: geometry.OffsetF = .{},
|
|
179
|
+
blur: f32 = 0,
|
|
180
|
+
spread: f32 = 0,
|
|
181
|
+
color: Color = .{},
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
pub const CanvasGpuBlur = struct {
|
|
185
|
+
rect: geometry.RectF = .{},
|
|
186
|
+
radius: f32 = 0,
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
pub const CanvasGpuEffect = union(enum) {
|
|
190
|
+
none,
|
|
191
|
+
shadow: CanvasGpuShadow,
|
|
192
|
+
blur: CanvasGpuBlur,
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
pub const CanvasGpuCommand = struct {
|
|
196
|
+
command_index: usize,
|
|
197
|
+
id: ?ObjectId = null,
|
|
198
|
+
kind: CanvasGpuCommandKind,
|
|
199
|
+
pipeline: ?RenderPipelineKind = null,
|
|
200
|
+
bounds: geometry.RectF = .{},
|
|
201
|
+
shape: CanvasGpuShape = .none,
|
|
202
|
+
paint: CanvasGpuPaint = .none,
|
|
203
|
+
stroke_width: f32 = 0,
|
|
204
|
+
image: ?CanvasGpuImage = null,
|
|
205
|
+
text: ?CanvasGpuText = null,
|
|
206
|
+
effect: CanvasGpuEffect = .none,
|
|
207
|
+
clip: ?geometry.RectF = null,
|
|
208
|
+
opacity: f32 = 1,
|
|
209
|
+
transform: Affine = .{},
|
|
210
|
+
uses_path_geometry: bool = false,
|
|
211
|
+
uses_image: bool = false,
|
|
212
|
+
uses_resource: bool = false,
|
|
213
|
+
uses_visual_effect: bool = false,
|
|
214
|
+
uses_glyph_atlas: bool = false,
|
|
215
|
+
uses_text_layout: bool = false,
|
|
216
|
+
|
|
217
|
+
pub fn supported(self: CanvasGpuCommand) bool {
|
|
218
|
+
return self.kind != .unsupported;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
pub fn usesCachedResource(self: CanvasGpuCommand) bool {
|
|
222
|
+
return self.uses_path_geometry or
|
|
223
|
+
self.uses_image or
|
|
224
|
+
self.uses_resource or
|
|
225
|
+
self.uses_visual_effect or
|
|
226
|
+
self.uses_glyph_atlas or
|
|
227
|
+
self.uses_text_layout;
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
pub const CanvasGpuPacket = struct {
|
|
232
|
+
frame_index: u64 = 0,
|
|
233
|
+
timestamp_ns: u64 = 0,
|
|
234
|
+
/// Retained-command-state generation stamped into the binary wire
|
|
235
|
+
/// header (v2): a keyed full present under generation G is the
|
|
236
|
+
/// baseline later `patch` presents edit. Generation 0 means "do not
|
|
237
|
+
/// retain" — the host draws the frame but never answers a patch from
|
|
238
|
+
/// it (packets built outside the runtime's retained bookkeeping stay
|
|
239
|
+
/// at 0).
|
|
240
|
+
generation: u64 = 0,
|
|
241
|
+
load_action: CanvasRenderPassLoadAction = .skip,
|
|
242
|
+
surface_size: geometry.SizeF = .{},
|
|
243
|
+
scale: f32 = 1,
|
|
244
|
+
scissor: ?geometry.RectF = null,
|
|
245
|
+
images: []const RenderImage = &.{},
|
|
246
|
+
image_actions: []const RenderImageCacheAction = &.{},
|
|
247
|
+
commands: []const CanvasGpuCommand = &.{},
|
|
248
|
+
batch_count: usize = 0,
|
|
249
|
+
pipeline_action_count: usize = 0,
|
|
250
|
+
path_geometry_count: usize = 0,
|
|
251
|
+
path_geometry_action_count: usize = 0,
|
|
252
|
+
image_count: usize = 0,
|
|
253
|
+
image_action_count: usize = 0,
|
|
254
|
+
layer_count: usize = 0,
|
|
255
|
+
layer_action_count: usize = 0,
|
|
256
|
+
resource_count: usize = 0,
|
|
257
|
+
resource_action_count: usize = 0,
|
|
258
|
+
visual_effect_count: usize = 0,
|
|
259
|
+
visual_effect_action_count: usize = 0,
|
|
260
|
+
glyph_atlas_entry_count: usize = 0,
|
|
261
|
+
glyph_atlas_action_count: usize = 0,
|
|
262
|
+
text_layout_count: usize = 0,
|
|
263
|
+
text_layout_line_count: usize = 0,
|
|
264
|
+
text_layout_action_count: usize = 0,
|
|
265
|
+
unsupported_command_count: usize = 0,
|
|
266
|
+
|
|
267
|
+
pub fn requiresRender(self: CanvasGpuPacket) bool {
|
|
268
|
+
return self.load_action != .skip;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
pub fn commandCount(self: CanvasGpuPacket) usize {
|
|
272
|
+
return self.commands.len;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
pub fn cacheActionCount(self: CanvasGpuPacket) usize {
|
|
276
|
+
return self.pipeline_action_count +
|
|
277
|
+
self.path_geometry_action_count +
|
|
278
|
+
self.image_action_count +
|
|
279
|
+
self.layer_action_count +
|
|
280
|
+
self.resource_action_count +
|
|
281
|
+
self.visual_effect_action_count +
|
|
282
|
+
self.glyph_atlas_action_count +
|
|
283
|
+
self.text_layout_action_count;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
pub fn cachedResourceCommandCount(self: CanvasGpuPacket) usize {
|
|
287
|
+
var count: usize = 0;
|
|
288
|
+
for (self.commands) |command| {
|
|
289
|
+
if (command.usesCachedResource()) count += 1;
|
|
290
|
+
}
|
|
291
|
+
return count;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
pub fn fullyRepresentable(self: CanvasGpuPacket) bool {
|
|
295
|
+
return self.unsupported_command_count == 0;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
pub fn writeJson(self: CanvasGpuPacket, writer: anytype) !void {
|
|
299
|
+
try canvas.writeCanvasGpuPacketJson(self, writer);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/// Compact binary wire encoding (see serialization.zig's binary
|
|
303
|
+
/// section for the layout): ~5-10x denser than `writeJson` on
|
|
304
|
+
/// text-heavy frames, so long rich views stay under the packet
|
|
305
|
+
/// transport bound instead of falling back to the software pixel
|
|
306
|
+
/// path.
|
|
307
|
+
pub fn writeBinary(self: CanvasGpuPacket, writer: anytype) !void {
|
|
308
|
+
try canvas.writeCanvasGpuPacketBinary(self, writer);
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
pub const CanvasGpuPacketSummary = struct {
|
|
313
|
+
load_action: CanvasRenderPassLoadAction = .skip,
|
|
314
|
+
command_count: usize = 0,
|
|
315
|
+
cache_action_count: usize = 0,
|
|
316
|
+
cached_resource_command_count: usize = 0,
|
|
317
|
+
unsupported_command_count: usize = 0,
|
|
318
|
+
|
|
319
|
+
pub fn requiresRender(self: CanvasGpuPacketSummary) bool {
|
|
320
|
+
return self.load_action != .skip;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
pub fn fullyRepresentable(self: CanvasGpuPacketSummary) bool {
|
|
324
|
+
return self.unsupported_command_count == 0;
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
pub const RenderEncoderPlanner = struct {
|
|
329
|
+
commands: []RenderEncoderCommand,
|
|
330
|
+
len: usize = 0,
|
|
331
|
+
|
|
332
|
+
pub fn init(commands: []RenderEncoderCommand) RenderEncoderPlanner {
|
|
333
|
+
return .{ .commands = commands };
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
pub fn reset(self: *RenderEncoderPlanner) void {
|
|
337
|
+
self.len = 0;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
pub fn build(self: *RenderEncoderPlanner, pass: canvas.CanvasRenderPass) Error!RenderEncoderPlan {
|
|
341
|
+
self.reset();
|
|
342
|
+
if (!pass.requiresRender()) return .{ .commands = self.commands[0..0] };
|
|
343
|
+
|
|
344
|
+
try self.append(.{ .begin_pass = .{
|
|
345
|
+
.load_action = pass.loadAction(),
|
|
346
|
+
.surface_size = pass.surface_size,
|
|
347
|
+
.scale = pass.scale,
|
|
348
|
+
.dirty_bounds = pass.dirty_bounds,
|
|
349
|
+
} });
|
|
350
|
+
if (pass.scissorBounds()) |bounds| try self.append(.{ .set_scissor = bounds });
|
|
351
|
+
|
|
352
|
+
for (pass.pipeline_actions) |action| try self.append(.{ .pipeline_cache = action });
|
|
353
|
+
for (pass.path_geometry_actions) |action| try self.append(.{ .path_geometry_cache = action });
|
|
354
|
+
for (pass.image_actions) |action| try self.append(.{ .image_cache = action });
|
|
355
|
+
for (pass.layer_actions) |action| try self.append(.{ .layer_cache = action });
|
|
356
|
+
for (pass.resource_actions) |action| try self.append(.{ .resource_cache = action });
|
|
357
|
+
for (pass.visual_effect_actions) |action| try self.append(.{ .visual_effect_cache = action });
|
|
358
|
+
for (pass.glyph_atlas_actions) |action| try self.append(.{ .glyph_atlas_cache = action });
|
|
359
|
+
for (pass.text_layout_actions) |action| try self.append(.{ .text_layout_cache = action });
|
|
360
|
+
|
|
361
|
+
var bound_pipeline: ?RenderPipelineKind = null;
|
|
362
|
+
for (pass.batches) |batch| {
|
|
363
|
+
if (bound_pipeline == null or bound_pipeline.? != batch.pipeline) {
|
|
364
|
+
try self.append(.{ .bind_pipeline = batch.pipeline });
|
|
365
|
+
bound_pipeline = batch.pipeline;
|
|
366
|
+
}
|
|
367
|
+
try self.append(.{ .draw_batch = batch });
|
|
368
|
+
}
|
|
369
|
+
try self.append(.end_pass);
|
|
370
|
+
|
|
371
|
+
return .{ .commands = self.commands[0..self.len] };
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
fn append(self: *RenderEncoderPlanner, command: RenderEncoderCommand) Error!void {
|
|
375
|
+
if (self.len >= self.commands.len) return error.RenderEncoderListFull;
|
|
376
|
+
self.commands[self.len] = command;
|
|
377
|
+
self.len += 1;
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
pub const CanvasGpuPacketPlanner = struct {
|
|
382
|
+
commands: []CanvasGpuCommand,
|
|
383
|
+
len: usize = 0,
|
|
384
|
+
unsupported_count: usize = 0,
|
|
385
|
+
|
|
386
|
+
pub fn init(commands: []CanvasGpuCommand) CanvasGpuPacketPlanner {
|
|
387
|
+
return .{ .commands = commands };
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
pub fn reset(self: *CanvasGpuPacketPlanner) void {
|
|
391
|
+
self.len = 0;
|
|
392
|
+
self.unsupported_count = 0;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
pub fn build(self: *CanvasGpuPacketPlanner, pass: canvas.CanvasRenderPass) Error!CanvasGpuPacket {
|
|
396
|
+
self.reset();
|
|
397
|
+
if (!pass.requiresRender()) {
|
|
398
|
+
return .{
|
|
399
|
+
.frame_index = pass.frame_index,
|
|
400
|
+
.timestamp_ns = pass.timestamp_ns,
|
|
401
|
+
.load_action = .skip,
|
|
402
|
+
.surface_size = pass.surface_size,
|
|
403
|
+
.scale = pass.scale,
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
const scissor_bounds = pass.scissorBounds();
|
|
408
|
+
for (pass.commands, 0..) |command, index| {
|
|
409
|
+
if (scissor_bounds) |scissor| {
|
|
410
|
+
if (!renderCommandIntersectsDirtyBounds(command, scissor)) continue;
|
|
411
|
+
}
|
|
412
|
+
try self.append(canvasGpuCommandFromRenderCommand(command, index));
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
return .{
|
|
416
|
+
.frame_index = pass.frame_index,
|
|
417
|
+
.timestamp_ns = pass.timestamp_ns,
|
|
418
|
+
.load_action = pass.loadAction(),
|
|
419
|
+
.surface_size = pass.surface_size,
|
|
420
|
+
.scale = pass.scale,
|
|
421
|
+
.scissor = pass.scissorBounds(),
|
|
422
|
+
.images = pass.images,
|
|
423
|
+
.image_actions = pass.image_actions,
|
|
424
|
+
.commands = self.commands[0..self.len],
|
|
425
|
+
.batch_count = pass.batchCount(),
|
|
426
|
+
.pipeline_action_count = pass.pipelineActionCount(),
|
|
427
|
+
.path_geometry_count = pass.pathGeometryCount(),
|
|
428
|
+
.path_geometry_action_count = pass.pathGeometryActionCount(),
|
|
429
|
+
.image_count = pass.imageCount(),
|
|
430
|
+
.image_action_count = pass.imageActionCount(),
|
|
431
|
+
.layer_count = pass.layerCount(),
|
|
432
|
+
.layer_action_count = pass.layerActionCount(),
|
|
433
|
+
.resource_count = pass.resourceCount(),
|
|
434
|
+
.resource_action_count = pass.resourceActionCount(),
|
|
435
|
+
.visual_effect_count = pass.visualEffectCount(),
|
|
436
|
+
.visual_effect_action_count = pass.visualEffectActionCount(),
|
|
437
|
+
.glyph_atlas_entry_count = pass.glyphAtlasEntryCount(),
|
|
438
|
+
.glyph_atlas_action_count = pass.glyphAtlasActionCount(),
|
|
439
|
+
.text_layout_count = pass.textLayoutCount(),
|
|
440
|
+
.text_layout_line_count = pass.textLayoutLineCount(),
|
|
441
|
+
.text_layout_action_count = pass.textLayoutActionCount(),
|
|
442
|
+
.unsupported_command_count = self.unsupported_count,
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
fn append(self: *CanvasGpuPacketPlanner, command: CanvasGpuCommand) Error!void {
|
|
447
|
+
if (self.len >= self.commands.len) return error.CanvasGpuCommandListFull;
|
|
448
|
+
if (!command.supported()) self.unsupported_count += 1;
|
|
449
|
+
self.commands[self.len] = command;
|
|
450
|
+
self.len += 1;
|
|
451
|
+
}
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
pub fn renderCommandIntersectsDirtyBounds(command: RenderCommand, dirty_bounds: geometry.RectF) bool {
|
|
455
|
+
const command_bounds = command.bounds.normalized();
|
|
456
|
+
const dirty = dirty_bounds.normalized();
|
|
457
|
+
if (command_bounds.isEmpty() or dirty.isEmpty()) return false;
|
|
458
|
+
return command_bounds.intersects(dirty);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
pub fn canvasGpuCommandFromRenderCommand(command: RenderCommand, command_index: usize) CanvasGpuCommand {
|
|
462
|
+
var packet_command = CanvasGpuCommand{
|
|
463
|
+
.command_index = command_index,
|
|
464
|
+
.id = command.id,
|
|
465
|
+
.kind = .unsupported,
|
|
466
|
+
.bounds = command.bounds,
|
|
467
|
+
.clip = command.clip,
|
|
468
|
+
.opacity = command.opacity,
|
|
469
|
+
.transform = command.transform,
|
|
470
|
+
};
|
|
471
|
+
|
|
472
|
+
switch (command.command) {
|
|
473
|
+
.fill_rect => |value| {
|
|
474
|
+
packet_command.kind = canvasGpuFillRectKind(value.fill);
|
|
475
|
+
packet_command.pipeline = canvasGpuFillPipeline(value.fill);
|
|
476
|
+
packet_command.shape = .{ .rect = value.rect.normalized() };
|
|
477
|
+
packet_command.paint = canvasGpuPaint(value.fill);
|
|
478
|
+
packet_command.uses_resource = canvasGpuFillUsesResource(value.fill);
|
|
479
|
+
},
|
|
480
|
+
.fill_rounded_rect => |value| {
|
|
481
|
+
packet_command.kind = canvasGpuRoundedRectKind(value.fill);
|
|
482
|
+
packet_command.pipeline = canvasGpuFillPipeline(value.fill);
|
|
483
|
+
packet_command.shape = .{ .rounded_rect = .{
|
|
484
|
+
.rect = value.rect.normalized(),
|
|
485
|
+
.radius = value.radius,
|
|
486
|
+
} };
|
|
487
|
+
packet_command.paint = canvasGpuPaint(value.fill);
|
|
488
|
+
packet_command.uses_resource = canvasGpuFillUsesResource(value.fill);
|
|
489
|
+
},
|
|
490
|
+
.stroke_rect => |value| {
|
|
491
|
+
packet_command.kind = canvasGpuStrokeRectKind(value.stroke.fill);
|
|
492
|
+
packet_command.pipeline = canvasGpuFillPipeline(value.stroke.fill);
|
|
493
|
+
packet_command.shape = .{ .stroke_rect = .{
|
|
494
|
+
.rect = value.rect.normalized(),
|
|
495
|
+
.radius = value.radius,
|
|
496
|
+
.width = value.stroke.width,
|
|
497
|
+
} };
|
|
498
|
+
packet_command.paint = canvasGpuPaint(value.stroke.fill);
|
|
499
|
+
packet_command.stroke_width = value.stroke.width;
|
|
500
|
+
packet_command.uses_resource = canvasGpuFillUsesResource(value.stroke.fill);
|
|
501
|
+
},
|
|
502
|
+
.draw_line => |value| {
|
|
503
|
+
packet_command.kind = canvasGpuLineKind(value.stroke.fill);
|
|
504
|
+
packet_command.pipeline = canvasGpuFillPipeline(value.stroke.fill);
|
|
505
|
+
packet_command.shape = .{ .line = .{
|
|
506
|
+
.from = value.from,
|
|
507
|
+
.to = value.to,
|
|
508
|
+
.width = value.stroke.width,
|
|
509
|
+
} };
|
|
510
|
+
packet_command.paint = canvasGpuPaint(value.stroke.fill);
|
|
511
|
+
packet_command.stroke_width = value.stroke.width;
|
|
512
|
+
packet_command.uses_resource = canvasGpuFillUsesResource(value.stroke.fill);
|
|
513
|
+
},
|
|
514
|
+
.fill_path => |value| {
|
|
515
|
+
packet_command.kind = .fill_path;
|
|
516
|
+
packet_command.pipeline = .path;
|
|
517
|
+
packet_command.shape = .{ .path = value.elements };
|
|
518
|
+
packet_command.paint = canvasGpuPaint(value.fill);
|
|
519
|
+
packet_command.uses_path_geometry = true;
|
|
520
|
+
packet_command.uses_resource = canvasGpuFillUsesResource(value.fill);
|
|
521
|
+
},
|
|
522
|
+
.stroke_path => |value| {
|
|
523
|
+
packet_command.kind = .stroke_path;
|
|
524
|
+
packet_command.pipeline = .path;
|
|
525
|
+
packet_command.shape = .{ .path = value.elements };
|
|
526
|
+
packet_command.paint = canvasGpuPaint(value.stroke.fill);
|
|
527
|
+
packet_command.stroke_width = value.stroke.width;
|
|
528
|
+
packet_command.uses_path_geometry = true;
|
|
529
|
+
packet_command.uses_resource = canvasGpuFillUsesResource(value.stroke.fill);
|
|
530
|
+
},
|
|
531
|
+
.draw_image => |value| {
|
|
532
|
+
packet_command.kind = .draw_image;
|
|
533
|
+
packet_command.pipeline = .image;
|
|
534
|
+
packet_command.image = .{
|
|
535
|
+
.image_id = value.image_id,
|
|
536
|
+
.src = value.src,
|
|
537
|
+
.dst = value.dst.normalized(),
|
|
538
|
+
.opacity = value.opacity,
|
|
539
|
+
.fit = value.fit,
|
|
540
|
+
.sampling = value.sampling,
|
|
541
|
+
.radius = value.radius,
|
|
542
|
+
};
|
|
543
|
+
packet_command.uses_image = true;
|
|
544
|
+
packet_command.uses_resource = true;
|
|
545
|
+
},
|
|
546
|
+
.draw_text => |value| {
|
|
547
|
+
packet_command.kind = .draw_text;
|
|
548
|
+
packet_command.pipeline = .glyph_run;
|
|
549
|
+
packet_command.paint = .{ .color = value.color };
|
|
550
|
+
packet_command.text = .{
|
|
551
|
+
.font_id = value.font_id,
|
|
552
|
+
.size = value.size,
|
|
553
|
+
.origin = value.origin,
|
|
554
|
+
.color = value.color,
|
|
555
|
+
.text = value.text,
|
|
556
|
+
.glyphs = value.glyphs,
|
|
557
|
+
.text_layout = value.text_layout,
|
|
558
|
+
};
|
|
559
|
+
packet_command.uses_resource = true;
|
|
560
|
+
packet_command.uses_glyph_atlas = true;
|
|
561
|
+
packet_command.uses_text_layout = value.text_layout != null;
|
|
562
|
+
},
|
|
563
|
+
.shadow => |value| {
|
|
564
|
+
packet_command.kind = .shadow;
|
|
565
|
+
packet_command.pipeline = .shadow;
|
|
566
|
+
packet_command.effect = .{ .shadow = .{
|
|
567
|
+
.rect = value.rect.normalized(),
|
|
568
|
+
.radius = value.radius,
|
|
569
|
+
.offset = value.offset,
|
|
570
|
+
.blur = value.blur,
|
|
571
|
+
.spread = value.spread,
|
|
572
|
+
.color = value.color,
|
|
573
|
+
} };
|
|
574
|
+
packet_command.uses_resource = true;
|
|
575
|
+
packet_command.uses_visual_effect = true;
|
|
576
|
+
},
|
|
577
|
+
.blur => |value| {
|
|
578
|
+
packet_command.kind = .blur;
|
|
579
|
+
packet_command.pipeline = .blur;
|
|
580
|
+
packet_command.effect = .{ .blur = .{
|
|
581
|
+
.rect = value.rect.normalized(),
|
|
582
|
+
.radius = value.radius,
|
|
583
|
+
} };
|
|
584
|
+
packet_command.uses_resource = true;
|
|
585
|
+
packet_command.uses_visual_effect = true;
|
|
586
|
+
},
|
|
587
|
+
.push_clip, .pop_clip, .push_opacity, .pop_opacity, .transform => {},
|
|
588
|
+
}
|
|
589
|
+
return packet_command;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
fn canvasGpuPaint(fill: Fill) CanvasGpuPaint {
|
|
593
|
+
return switch (fill) {
|
|
594
|
+
.color => |color| .{ .color = color },
|
|
595
|
+
.linear_gradient => |gradient| .{ .linear_gradient = gradient },
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
fn canvasGpuFillPipeline(fill: Fill) RenderPipelineKind {
|
|
600
|
+
return switch (fill) {
|
|
601
|
+
.color => .solid,
|
|
602
|
+
.linear_gradient => .linear_gradient,
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
fn canvasGpuFillUsesResource(fill: Fill) bool {
|
|
607
|
+
return switch (fill) {
|
|
608
|
+
.color => false,
|
|
609
|
+
.linear_gradient => true,
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
fn canvasGpuFillRectKind(fill: Fill) CanvasGpuCommandKind {
|
|
614
|
+
return switch (fill) {
|
|
615
|
+
.color => .fill_rect_solid,
|
|
616
|
+
.linear_gradient => .fill_rect_gradient,
|
|
617
|
+
};
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
fn canvasGpuRoundedRectKind(fill: Fill) CanvasGpuCommandKind {
|
|
621
|
+
return switch (fill) {
|
|
622
|
+
.color => .fill_rounded_rect_solid,
|
|
623
|
+
.linear_gradient => .fill_rounded_rect_gradient,
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
fn canvasGpuStrokeRectKind(fill: Fill) CanvasGpuCommandKind {
|
|
628
|
+
return switch (fill) {
|
|
629
|
+
.color => .stroke_rect_solid,
|
|
630
|
+
.linear_gradient => .stroke_rect_gradient,
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
fn canvasGpuLineKind(fill: Fill) CanvasGpuCommandKind {
|
|
635
|
+
return switch (fill) {
|
|
636
|
+
.color => .draw_line_solid,
|
|
637
|
+
.linear_gradient => .draw_line_gradient,
|
|
638
|
+
};
|
|
639
|
+
}
|