@native-sdk/cli 0.0.0 → 0.4.1
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/assets/icon.icns +0 -0
- package/assets/icon.ico +0 -0
- package/assets/icon.png +0 -0
- package/assets/icon.svg +15 -0
- package/assets/native-sdk.entitlements +10 -0
- package/assets/native-sdk.manifest +12 -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 +45 -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,260 @@
|
|
|
1
|
+
const geometry = @import("geometry");
|
|
2
|
+
const canvas = @import("root.zig");
|
|
3
|
+
const drawing_model = @import("drawing.zig");
|
|
4
|
+
const equality_model = @import("equality.zig");
|
|
5
|
+
const fingerprints = @import("render_fingerprints.zig");
|
|
6
|
+
|
|
7
|
+
const Error = canvas.Error;
|
|
8
|
+
const ObjectId = canvas.ObjectId;
|
|
9
|
+
const Affine = drawing_model.Affine;
|
|
10
|
+
const optionalRectsEqual = equality_model.optionalRectsEqual;
|
|
11
|
+
|
|
12
|
+
const affinesEqual = fingerprints.affinesEqual;
|
|
13
|
+
const renderLayerFingerprint = fingerprints.renderLayerFingerprint;
|
|
14
|
+
const renderLayerFingerprintAppend = fingerprints.renderLayerFingerprintAppend;
|
|
15
|
+
|
|
16
|
+
pub const RenderLayer = struct {
|
|
17
|
+
command_start: usize = 0,
|
|
18
|
+
command_count: usize = 0,
|
|
19
|
+
id: ?ObjectId = null,
|
|
20
|
+
bounds: geometry.RectF = .{},
|
|
21
|
+
opacity: f32 = 1,
|
|
22
|
+
clip: ?geometry.RectF = null,
|
|
23
|
+
transform: Affine = .{},
|
|
24
|
+
fingerprint: u64 = 0,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
pub const RenderLayerPlan = struct {
|
|
28
|
+
layers: []const RenderLayer = &.{},
|
|
29
|
+
|
|
30
|
+
pub fn layerCount(self: RenderLayerPlan) usize {
|
|
31
|
+
return self.layers.len;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
pub fn opacityLayerCount(self: RenderLayerPlan) usize {
|
|
35
|
+
var count: usize = 0;
|
|
36
|
+
for (self.layers) |layer| {
|
|
37
|
+
if (layer.opacity != 1) count += 1;
|
|
38
|
+
}
|
|
39
|
+
return count;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
pub fn clipLayerCount(self: RenderLayerPlan) usize {
|
|
43
|
+
var count: usize = 0;
|
|
44
|
+
for (self.layers) |layer| {
|
|
45
|
+
if (layer.clip != null) count += 1;
|
|
46
|
+
}
|
|
47
|
+
return count;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
pub fn transformLayerCount(self: RenderLayerPlan) usize {
|
|
51
|
+
var count: usize = 0;
|
|
52
|
+
for (self.layers) |layer| {
|
|
53
|
+
if (!affinesEqual(layer.transform, Affine.identity())) count += 1;
|
|
54
|
+
}
|
|
55
|
+
return count;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
pub fn cachePlan(self: RenderLayerPlan, previous: []const RenderLayerCacheEntry, frame_index: u64, entries: []RenderLayerCacheEntry, actions: []RenderLayerCacheAction) Error!RenderLayerCachePlan {
|
|
59
|
+
var planner = RenderLayerCachePlanner.init(entries, actions);
|
|
60
|
+
return planner.build(self, previous, frame_index);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
pub const RenderLayerPlanner = struct {
|
|
65
|
+
layers: []RenderLayer,
|
|
66
|
+
len: usize = 0,
|
|
67
|
+
|
|
68
|
+
pub fn init(layers: []RenderLayer) RenderLayerPlanner {
|
|
69
|
+
return .{ .layers = layers };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
pub fn reset(self: *RenderLayerPlanner) void {
|
|
73
|
+
self.len = 0;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
pub fn build(self: *RenderLayerPlanner, render_plan: anytype) Error!RenderLayerPlan {
|
|
77
|
+
self.reset();
|
|
78
|
+
for (render_plan.commands, 0..) |command, index| {
|
|
79
|
+
try self.consume(command, index);
|
|
80
|
+
}
|
|
81
|
+
return .{ .layers = self.layers[0..self.len] };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
fn consume(self: *RenderLayerPlanner, command: anytype, index: usize) Error!void {
|
|
85
|
+
if (!renderCommandNeedsLayer(command)) return;
|
|
86
|
+
|
|
87
|
+
if (self.len > 0 and renderLayerCanExtend(self.layers[self.len - 1], command, index)) {
|
|
88
|
+
const layer = &self.layers[self.len - 1];
|
|
89
|
+
layer.command_count += 1;
|
|
90
|
+
layer.id = if (layer.id == command.id) layer.id else null;
|
|
91
|
+
layer.bounds = geometry.RectF.unionWith(layer.bounds.normalized(), command.bounds.normalized());
|
|
92
|
+
layer.fingerprint = renderLayerFingerprintAppend(layer.fingerprint, command);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (self.len >= self.layers.len) return error.LayerListFull;
|
|
97
|
+
self.layers[self.len] = .{
|
|
98
|
+
.command_start = index,
|
|
99
|
+
.command_count = 1,
|
|
100
|
+
.id = command.id,
|
|
101
|
+
.bounds = command.bounds,
|
|
102
|
+
.opacity = command.opacity,
|
|
103
|
+
.clip = command.clip,
|
|
104
|
+
.transform = command.transform,
|
|
105
|
+
.fingerprint = renderLayerFingerprint(command),
|
|
106
|
+
};
|
|
107
|
+
self.len += 1;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
pub const RenderLayerKey = struct {
|
|
112
|
+
id: ?ObjectId = null,
|
|
113
|
+
command_start: usize = 0,
|
|
114
|
+
fingerprint: u64 = 0,
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
pub const RenderLayerCacheEntry = struct {
|
|
118
|
+
key: RenderLayerKey,
|
|
119
|
+
last_used_frame: u64 = 0,
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
pub const RenderLayerCacheActionKind = enum {
|
|
123
|
+
upload,
|
|
124
|
+
retain,
|
|
125
|
+
evict,
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
pub const RenderLayerCacheAction = struct {
|
|
129
|
+
kind: RenderLayerCacheActionKind,
|
|
130
|
+
key: RenderLayerKey,
|
|
131
|
+
layer_index: ?usize = null,
|
|
132
|
+
cache_index: ?usize = null,
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
pub const RenderLayerCachePlan = struct {
|
|
136
|
+
entries: []const RenderLayerCacheEntry = &.{},
|
|
137
|
+
actions: []const RenderLayerCacheAction = &.{},
|
|
138
|
+
|
|
139
|
+
pub fn entryCount(self: RenderLayerCachePlan) usize {
|
|
140
|
+
return self.entries.len;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
pub fn actionCount(self: RenderLayerCachePlan) usize {
|
|
144
|
+
return self.actions.len;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
pub fn uploadCount(self: RenderLayerCachePlan) usize {
|
|
148
|
+
return self.actionCountByKind(.upload);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
pub fn retainCount(self: RenderLayerCachePlan) usize {
|
|
152
|
+
return self.actionCountByKind(.retain);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
pub fn evictCount(self: RenderLayerCachePlan) usize {
|
|
156
|
+
return self.actionCountByKind(.evict);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
fn actionCountByKind(self: RenderLayerCachePlan, kind: RenderLayerCacheActionKind) usize {
|
|
160
|
+
var count: usize = 0;
|
|
161
|
+
for (self.actions) |action| {
|
|
162
|
+
if (action.kind == kind) count += 1;
|
|
163
|
+
}
|
|
164
|
+
return count;
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
pub const RenderLayerCachePlanner = struct {
|
|
169
|
+
entries: []RenderLayerCacheEntry,
|
|
170
|
+
actions: []RenderLayerCacheAction,
|
|
171
|
+
entry_len: usize = 0,
|
|
172
|
+
action_len: usize = 0,
|
|
173
|
+
|
|
174
|
+
pub fn init(entries: []RenderLayerCacheEntry, actions: []RenderLayerCacheAction) RenderLayerCachePlanner {
|
|
175
|
+
return .{ .entries = entries, .actions = actions };
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
pub fn reset(self: *RenderLayerCachePlanner) void {
|
|
179
|
+
self.entry_len = 0;
|
|
180
|
+
self.action_len = 0;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
pub fn build(self: *RenderLayerCachePlanner, layer_plan: RenderLayerPlan, previous: []const RenderLayerCacheEntry, frame_index: u64) Error!RenderLayerCachePlan {
|
|
184
|
+
self.reset();
|
|
185
|
+
for (layer_plan.layers, 0..) |layer, layer_index| {
|
|
186
|
+
const key = renderLayerKey(layer);
|
|
187
|
+
if (findRenderLayerCacheEntry(self.entries[0..self.entry_len], key) != null) continue;
|
|
188
|
+
|
|
189
|
+
const previous_index = findRenderLayerCacheEntry(previous, key);
|
|
190
|
+
try self.appendAction(.{
|
|
191
|
+
.kind = if (previous_index == null) .upload else .retain,
|
|
192
|
+
.key = key,
|
|
193
|
+
.layer_index = layer_index,
|
|
194
|
+
.cache_index = previous_index,
|
|
195
|
+
});
|
|
196
|
+
try self.appendEntry(.{
|
|
197
|
+
.key = key,
|
|
198
|
+
.last_used_frame = frame_index,
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
for (previous, 0..) |entry, cache_index| {
|
|
203
|
+
if (findRenderLayerCacheEntry(self.entries[0..self.entry_len], entry.key) != null) continue;
|
|
204
|
+
try self.appendAction(.{
|
|
205
|
+
.kind = .evict,
|
|
206
|
+
.key = entry.key,
|
|
207
|
+
.cache_index = cache_index,
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return .{
|
|
212
|
+
.entries = self.entries[0..self.entry_len],
|
|
213
|
+
.actions = self.actions[0..self.action_len],
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
fn appendEntry(self: *RenderLayerCachePlanner, entry: RenderLayerCacheEntry) Error!void {
|
|
218
|
+
if (self.entry_len >= self.entries.len) return error.LayerCacheListFull;
|
|
219
|
+
self.entries[self.entry_len] = entry;
|
|
220
|
+
self.entry_len += 1;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
fn appendAction(self: *RenderLayerCachePlanner, action: RenderLayerCacheAction) Error!void {
|
|
224
|
+
if (self.action_len >= self.actions.len) return error.LayerCacheListFull;
|
|
225
|
+
self.actions[self.action_len] = action;
|
|
226
|
+
self.action_len += 1;
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
fn renderCommandNeedsLayer(command: anytype) bool {
|
|
231
|
+
return command.opacity != 1 or command.clip != null or !affinesEqual(command.transform, Affine.identity());
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
fn renderLayerCanExtend(layer: RenderLayer, command: anytype, index: usize) bool {
|
|
235
|
+
return layer.command_start + layer.command_count == index and
|
|
236
|
+
layer.opacity == command.opacity and
|
|
237
|
+
optionalRectsEqual(layer.clip, command.clip) and
|
|
238
|
+
affinesEqual(layer.transform, command.transform);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
fn renderLayerKey(layer: RenderLayer) RenderLayerKey {
|
|
242
|
+
return .{
|
|
243
|
+
.id = layer.id,
|
|
244
|
+
.command_start = if (layer.id == null) layer.command_start else 0,
|
|
245
|
+
.fingerprint = layer.fingerprint,
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
fn findRenderLayerCacheEntry(entries: []const RenderLayerCacheEntry, key: RenderLayerKey) ?usize {
|
|
250
|
+
for (entries, 0..) |entry, index| {
|
|
251
|
+
if (renderLayerKeysEqual(entry.key, key)) return index;
|
|
252
|
+
}
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
fn renderLayerKeysEqual(a: RenderLayerKey, b: RenderLayerKey) bool {
|
|
257
|
+
return a.id == b.id and
|
|
258
|
+
a.command_start == b.command_start and
|
|
259
|
+
a.fingerprint == b.fingerprint;
|
|
260
|
+
}
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
const geometry = @import("geometry");
|
|
2
|
+
const canvas = @import("root.zig");
|
|
3
|
+
const drawing_model = @import("drawing.zig");
|
|
4
|
+
const hash_model = @import("hash.zig");
|
|
5
|
+
|
|
6
|
+
const Error = canvas.Error;
|
|
7
|
+
const ObjectId = canvas.ObjectId;
|
|
8
|
+
const Affine = drawing_model.Affine;
|
|
9
|
+
const PathElement = drawing_model.PathElement;
|
|
10
|
+
|
|
11
|
+
const path_geometry_curve_segments: usize = 12;
|
|
12
|
+
const resourceHashTag = hash_model.resourceHashTag;
|
|
13
|
+
const resourceHashBytes = hash_model.resourceHashBytes;
|
|
14
|
+
const resourceHashF32 = hash_model.resourceHashF32;
|
|
15
|
+
const resourceHashAffine = hash_model.resourceHashAffine;
|
|
16
|
+
const resourceHashOptionalObjectId = hash_model.resourceHashOptionalObjectId;
|
|
17
|
+
const resourceHashPath = hash_model.resourceHashPath;
|
|
18
|
+
|
|
19
|
+
pub const RenderPathGeometryKind = enum {
|
|
20
|
+
fill,
|
|
21
|
+
stroke,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
pub const RenderPathGeometry = struct {
|
|
25
|
+
kind: RenderPathGeometryKind,
|
|
26
|
+
command_index: usize = 0,
|
|
27
|
+
id: ?ObjectId = null,
|
|
28
|
+
bounds: geometry.RectF = .{},
|
|
29
|
+
element_count: usize = 0,
|
|
30
|
+
contour_count: usize = 0,
|
|
31
|
+
line_segment_count: usize = 0,
|
|
32
|
+
quadratic_segment_count: usize = 0,
|
|
33
|
+
cubic_segment_count: usize = 0,
|
|
34
|
+
flattened_segment_count: usize = 0,
|
|
35
|
+
vertex_count: usize = 0,
|
|
36
|
+
index_count: usize = 0,
|
|
37
|
+
stroke_width: f32 = 0,
|
|
38
|
+
fingerprint: u64 = 0,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
pub const RenderPathGeometryPlan = struct {
|
|
42
|
+
geometries: []const RenderPathGeometry = &.{},
|
|
43
|
+
|
|
44
|
+
pub fn geometryCount(self: RenderPathGeometryPlan) usize {
|
|
45
|
+
return self.geometries.len;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
pub fn vertexCount(self: RenderPathGeometryPlan) usize {
|
|
49
|
+
var count: usize = 0;
|
|
50
|
+
for (self.geometries) |geometry_plan| count += geometry_plan.vertex_count;
|
|
51
|
+
return count;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
pub fn indexCount(self: RenderPathGeometryPlan) usize {
|
|
55
|
+
var count: usize = 0;
|
|
56
|
+
for (self.geometries) |geometry_plan| count += geometry_plan.index_count;
|
|
57
|
+
return count;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
pub fn cachePlan(self: RenderPathGeometryPlan, previous: []const RenderPathGeometryCacheEntry, frame_index: u64, entries: []RenderPathGeometryCacheEntry, actions: []RenderPathGeometryCacheAction) Error!RenderPathGeometryCachePlan {
|
|
61
|
+
var planner = RenderPathGeometryCachePlanner.init(entries, actions);
|
|
62
|
+
return planner.build(self, previous, frame_index);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
pub const RenderPathGeometryPlanner = struct {
|
|
67
|
+
geometries: []RenderPathGeometry,
|
|
68
|
+
len: usize = 0,
|
|
69
|
+
|
|
70
|
+
pub fn init(geometries: []RenderPathGeometry) RenderPathGeometryPlanner {
|
|
71
|
+
return .{ .geometries = geometries };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
pub fn reset(self: *RenderPathGeometryPlanner) void {
|
|
75
|
+
self.len = 0;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
pub fn build(self: *RenderPathGeometryPlanner, render_plan: anytype) Error!RenderPathGeometryPlan {
|
|
79
|
+
self.reset();
|
|
80
|
+
for (render_plan.commands, 0..) |command, index| {
|
|
81
|
+
try self.consume(command, index);
|
|
82
|
+
}
|
|
83
|
+
return .{ .geometries = self.geometries[0..self.len] };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
fn consume(self: *RenderPathGeometryPlanner, command: anytype, index: usize) Error!void {
|
|
87
|
+
switch (command.command) {
|
|
88
|
+
.fill_path => |value| try self.consumePath(.fill, command, index, value.elements, 0),
|
|
89
|
+
.stroke_path => |value| {
|
|
90
|
+
const stroke_width = nonNegative(value.stroke.width) * referenceTransformScale(command.transform);
|
|
91
|
+
if (stroke_width <= 0) return;
|
|
92
|
+
try self.consumePath(.stroke, command, index, value.elements, stroke_width);
|
|
93
|
+
},
|
|
94
|
+
else => {},
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
fn consumePath(self: *RenderPathGeometryPlanner, kind: RenderPathGeometryKind, command: anytype, index: usize, elements: []const PathElement, stroke_width: f32) Error!void {
|
|
99
|
+
const counts = analyzePathGeometry(elements, kind);
|
|
100
|
+
if (counts.vertex_count == 0 or counts.index_count == 0) return;
|
|
101
|
+
if (self.len >= self.geometries.len) return error.PathGeometryListFull;
|
|
102
|
+
self.geometries[self.len] = .{
|
|
103
|
+
.kind = kind,
|
|
104
|
+
.command_index = index,
|
|
105
|
+
.id = command.id,
|
|
106
|
+
.bounds = command.bounds,
|
|
107
|
+
.element_count = elements.len,
|
|
108
|
+
.contour_count = counts.contour_count,
|
|
109
|
+
.line_segment_count = counts.line_segment_count,
|
|
110
|
+
.quadratic_segment_count = counts.quadratic_segment_count,
|
|
111
|
+
.cubic_segment_count = counts.cubic_segment_count,
|
|
112
|
+
.flattened_segment_count = counts.flattened_segment_count,
|
|
113
|
+
.vertex_count = counts.vertex_count,
|
|
114
|
+
.index_count = counts.index_count,
|
|
115
|
+
.stroke_width = stroke_width,
|
|
116
|
+
.fingerprint = renderPathGeometryFingerprint(command, kind, elements, stroke_width),
|
|
117
|
+
};
|
|
118
|
+
self.len += 1;
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
pub const PathGeometryCounts = struct {
|
|
123
|
+
contour_count: usize = 0,
|
|
124
|
+
line_segment_count: usize = 0,
|
|
125
|
+
quadratic_segment_count: usize = 0,
|
|
126
|
+
cubic_segment_count: usize = 0,
|
|
127
|
+
flattened_segment_count: usize = 0,
|
|
128
|
+
vertex_count: usize = 0,
|
|
129
|
+
index_count: usize = 0,
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
pub fn analyzePathGeometry(elements: []const PathElement, kind: RenderPathGeometryKind) PathGeometryCounts {
|
|
133
|
+
var counts = PathGeometryCounts{};
|
|
134
|
+
var has_current = false;
|
|
135
|
+
|
|
136
|
+
for (elements) |element| {
|
|
137
|
+
switch (element.verb) {
|
|
138
|
+
.move_to => {
|
|
139
|
+
counts.contour_count += 1;
|
|
140
|
+
counts.vertex_count += 1;
|
|
141
|
+
has_current = true;
|
|
142
|
+
},
|
|
143
|
+
.line_to => {
|
|
144
|
+
if (!has_current) {
|
|
145
|
+
counts.contour_count += 1;
|
|
146
|
+
counts.vertex_count += 1;
|
|
147
|
+
has_current = true;
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
counts.line_segment_count += 1;
|
|
151
|
+
counts.flattened_segment_count += 1;
|
|
152
|
+
counts.vertex_count += 1;
|
|
153
|
+
},
|
|
154
|
+
.quad_to => {
|
|
155
|
+
if (!has_current) continue;
|
|
156
|
+
counts.quadratic_segment_count += 1;
|
|
157
|
+
counts.flattened_segment_count += path_geometry_curve_segments;
|
|
158
|
+
counts.vertex_count += path_geometry_curve_segments;
|
|
159
|
+
},
|
|
160
|
+
.cubic_to => {
|
|
161
|
+
if (!has_current) continue;
|
|
162
|
+
counts.cubic_segment_count += 1;
|
|
163
|
+
counts.flattened_segment_count += path_geometry_curve_segments;
|
|
164
|
+
counts.vertex_count += path_geometry_curve_segments;
|
|
165
|
+
},
|
|
166
|
+
.close => {
|
|
167
|
+
if (!has_current) continue;
|
|
168
|
+
counts.line_segment_count += 1;
|
|
169
|
+
counts.flattened_segment_count += 1;
|
|
170
|
+
},
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
switch (kind) {
|
|
175
|
+
.fill => {
|
|
176
|
+
counts.index_count = if (counts.vertex_count >= 3) (counts.vertex_count - 2) * 3 else 0;
|
|
177
|
+
},
|
|
178
|
+
.stroke => {
|
|
179
|
+
counts.vertex_count = counts.flattened_segment_count * 4;
|
|
180
|
+
counts.index_count = counts.flattened_segment_count * 6;
|
|
181
|
+
},
|
|
182
|
+
}
|
|
183
|
+
return counts;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
fn renderPathGeometryKey(geometry_plan: RenderPathGeometry) RenderPathGeometryKey {
|
|
187
|
+
return .{
|
|
188
|
+
.kind = geometry_plan.kind,
|
|
189
|
+
.id = geometry_plan.id,
|
|
190
|
+
.command_index = if (geometry_plan.id == null) geometry_plan.command_index else 0,
|
|
191
|
+
.fingerprint = geometry_plan.fingerprint,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
fn findRenderPathGeometryCacheEntry(entries: []const RenderPathGeometryCacheEntry, key: RenderPathGeometryKey) ?usize {
|
|
196
|
+
for (entries, 0..) |entry, index| {
|
|
197
|
+
if (renderPathGeometryKeysEqual(entry.key, key)) return index;
|
|
198
|
+
}
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
fn renderPathGeometryKeysEqual(a: RenderPathGeometryKey, b: RenderPathGeometryKey) bool {
|
|
203
|
+
return a.kind == b.kind and
|
|
204
|
+
a.id == b.id and
|
|
205
|
+
a.command_index == b.command_index and
|
|
206
|
+
a.fingerprint == b.fingerprint;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
fn renderPathGeometryFingerprint(command: anytype, kind: RenderPathGeometryKind, elements: []const PathElement, stroke_width: f32) u64 {
|
|
210
|
+
var hash = resourceHashTag("path_geometry");
|
|
211
|
+
hash = resourceHashBytes(hash, @tagName(kind));
|
|
212
|
+
hash = resourceHashOptionalObjectId(hash, command.id);
|
|
213
|
+
hash = resourceHashAffine(hash, command.transform);
|
|
214
|
+
hash = resourceHashPath(hash, elements);
|
|
215
|
+
hash = resourceHashF32(hash, stroke_width);
|
|
216
|
+
return hash;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
pub const RenderPathGeometryKey = struct {
|
|
220
|
+
kind: RenderPathGeometryKind,
|
|
221
|
+
id: ?ObjectId = null,
|
|
222
|
+
command_index: usize = 0,
|
|
223
|
+
fingerprint: u64 = 0,
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
pub const RenderPathGeometryCacheEntry = struct {
|
|
227
|
+
key: RenderPathGeometryKey,
|
|
228
|
+
last_used_frame: u64 = 0,
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
pub const RenderPathGeometryCacheActionKind = enum {
|
|
232
|
+
upload,
|
|
233
|
+
retain,
|
|
234
|
+
evict,
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
pub const RenderPathGeometryCacheAction = struct {
|
|
238
|
+
kind: RenderPathGeometryCacheActionKind,
|
|
239
|
+
key: RenderPathGeometryKey,
|
|
240
|
+
geometry_index: ?usize = null,
|
|
241
|
+
cache_index: ?usize = null,
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
pub const RenderPathGeometryCachePlan = struct {
|
|
245
|
+
entries: []const RenderPathGeometryCacheEntry = &.{},
|
|
246
|
+
actions: []const RenderPathGeometryCacheAction = &.{},
|
|
247
|
+
|
|
248
|
+
pub fn entryCount(self: RenderPathGeometryCachePlan) usize {
|
|
249
|
+
return self.entries.len;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
pub fn actionCount(self: RenderPathGeometryCachePlan) usize {
|
|
253
|
+
return self.actions.len;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
pub fn uploadCount(self: RenderPathGeometryCachePlan) usize {
|
|
257
|
+
return self.actionCountByKind(.upload);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
pub fn retainCount(self: RenderPathGeometryCachePlan) usize {
|
|
261
|
+
return self.actionCountByKind(.retain);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
pub fn evictCount(self: RenderPathGeometryCachePlan) usize {
|
|
265
|
+
return self.actionCountByKind(.evict);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
fn actionCountByKind(self: RenderPathGeometryCachePlan, kind: RenderPathGeometryCacheActionKind) usize {
|
|
269
|
+
var count: usize = 0;
|
|
270
|
+
for (self.actions) |action| {
|
|
271
|
+
if (action.kind == kind) count += 1;
|
|
272
|
+
}
|
|
273
|
+
return count;
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
pub const RenderPathGeometryCachePlanner = struct {
|
|
278
|
+
entries: []RenderPathGeometryCacheEntry,
|
|
279
|
+
actions: []RenderPathGeometryCacheAction,
|
|
280
|
+
entry_len: usize = 0,
|
|
281
|
+
action_len: usize = 0,
|
|
282
|
+
|
|
283
|
+
pub fn init(entries: []RenderPathGeometryCacheEntry, actions: []RenderPathGeometryCacheAction) RenderPathGeometryCachePlanner {
|
|
284
|
+
return .{ .entries = entries, .actions = actions };
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
pub fn reset(self: *RenderPathGeometryCachePlanner) void {
|
|
288
|
+
self.entry_len = 0;
|
|
289
|
+
self.action_len = 0;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
pub fn build(self: *RenderPathGeometryCachePlanner, geometry_plan: RenderPathGeometryPlan, previous: []const RenderPathGeometryCacheEntry, frame_index: u64) Error!RenderPathGeometryCachePlan {
|
|
293
|
+
self.reset();
|
|
294
|
+
for (geometry_plan.geometries, 0..) |geometry_plan_item, geometry_index| {
|
|
295
|
+
const key = renderPathGeometryKey(geometry_plan_item);
|
|
296
|
+
if (findRenderPathGeometryCacheEntry(self.entries[0..self.entry_len], key) != null) continue;
|
|
297
|
+
|
|
298
|
+
const previous_index = findRenderPathGeometryCacheEntry(previous, key);
|
|
299
|
+
try self.appendAction(.{
|
|
300
|
+
.kind = if (previous_index == null) .upload else .retain,
|
|
301
|
+
.key = key,
|
|
302
|
+
.geometry_index = geometry_index,
|
|
303
|
+
.cache_index = previous_index,
|
|
304
|
+
});
|
|
305
|
+
try self.appendEntry(.{
|
|
306
|
+
.key = key,
|
|
307
|
+
.last_used_frame = frame_index,
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
for (previous, 0..) |entry, cache_index| {
|
|
312
|
+
if (findRenderPathGeometryCacheEntry(self.entries[0..self.entry_len], entry.key) != null) continue;
|
|
313
|
+
try self.appendAction(.{
|
|
314
|
+
.kind = .evict,
|
|
315
|
+
.key = entry.key,
|
|
316
|
+
.cache_index = cache_index,
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
return .{
|
|
321
|
+
.entries = self.entries[0..self.entry_len],
|
|
322
|
+
.actions = self.actions[0..self.action_len],
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
fn appendEntry(self: *RenderPathGeometryCachePlanner, entry: RenderPathGeometryCacheEntry) Error!void {
|
|
327
|
+
if (self.entry_len >= self.entries.len) return error.PathGeometryCacheListFull;
|
|
328
|
+
self.entries[self.entry_len] = entry;
|
|
329
|
+
self.entry_len += 1;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
fn appendAction(self: *RenderPathGeometryCachePlanner, action: RenderPathGeometryCacheAction) Error!void {
|
|
333
|
+
if (self.action_len >= self.actions.len) return error.PathGeometryCacheListFull;
|
|
334
|
+
self.actions[self.action_len] = action;
|
|
335
|
+
self.action_len += 1;
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
fn referenceTransformScale(transform: Affine) f32 {
|
|
340
|
+
const x_scale = @sqrt(transform.a * transform.a + transform.b * transform.b);
|
|
341
|
+
const y_scale = @sqrt(transform.c * transform.c + transform.d * transform.d);
|
|
342
|
+
return @max(0.0001, @max(x_scale, y_scale));
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
fn nonNegative(value: f32) f32 {
|
|
346
|
+
return @max(0, value);
|
|
347
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
const render_images = @import("render_images.zig");
|
|
2
|
+
const render_generic_resources = @import("render_generic_resources.zig");
|
|
3
|
+
const render_layers = @import("render_layers.zig");
|
|
4
|
+
const render_effects = @import("render_effects.zig");
|
|
5
|
+
const render_fingerprints = @import("render_fingerprints.zig");
|
|
6
|
+
|
|
7
|
+
pub const RenderImage = render_images.RenderImage;
|
|
8
|
+
pub const RenderImagePlan = render_images.RenderImagePlan;
|
|
9
|
+
pub const RenderImagePlanner = render_images.RenderImagePlanner;
|
|
10
|
+
pub const RenderImageKey = render_images.RenderImageKey;
|
|
11
|
+
pub const RenderImageCacheEntry = render_images.RenderImageCacheEntry;
|
|
12
|
+
pub const RenderImageCacheActionKind = render_images.RenderImageCacheActionKind;
|
|
13
|
+
pub const RenderImageCacheAction = render_images.RenderImageCacheAction;
|
|
14
|
+
pub const RenderImageCachePlan = render_images.RenderImageCachePlan;
|
|
15
|
+
pub const RenderImageCachePlanner = render_images.RenderImageCachePlanner;
|
|
16
|
+
|
|
17
|
+
pub const RenderResourceKind = render_generic_resources.RenderResourceKind;
|
|
18
|
+
pub const RenderResource = render_generic_resources.RenderResource;
|
|
19
|
+
pub const RenderResourcePlan = render_generic_resources.RenderResourcePlan;
|
|
20
|
+
pub const RenderResourcePlanner = render_generic_resources.RenderResourcePlanner;
|
|
21
|
+
pub const RenderResourceKey = render_generic_resources.RenderResourceKey;
|
|
22
|
+
pub const RenderResourceCacheEntry = render_generic_resources.RenderResourceCacheEntry;
|
|
23
|
+
pub const RenderResourceCacheActionKind = render_generic_resources.RenderResourceCacheActionKind;
|
|
24
|
+
pub const RenderResourceCacheAction = render_generic_resources.RenderResourceCacheAction;
|
|
25
|
+
pub const RenderResourceCachePlan = render_generic_resources.RenderResourceCachePlan;
|
|
26
|
+
pub const RenderResourceCachePlanner = render_generic_resources.RenderResourceCachePlanner;
|
|
27
|
+
|
|
28
|
+
pub const RenderLayer = render_layers.RenderLayer;
|
|
29
|
+
pub const RenderLayerPlan = render_layers.RenderLayerPlan;
|
|
30
|
+
pub const RenderLayerPlanner = render_layers.RenderLayerPlanner;
|
|
31
|
+
pub const RenderLayerKey = render_layers.RenderLayerKey;
|
|
32
|
+
pub const RenderLayerCacheEntry = render_layers.RenderLayerCacheEntry;
|
|
33
|
+
pub const RenderLayerCacheActionKind = render_layers.RenderLayerCacheActionKind;
|
|
34
|
+
pub const RenderLayerCacheAction = render_layers.RenderLayerCacheAction;
|
|
35
|
+
pub const RenderLayerCachePlan = render_layers.RenderLayerCachePlan;
|
|
36
|
+
pub const RenderLayerCachePlanner = render_layers.RenderLayerCachePlanner;
|
|
37
|
+
|
|
38
|
+
pub const VisualEffectKind = render_effects.VisualEffectKind;
|
|
39
|
+
pub const VisualEffect = render_effects.VisualEffect;
|
|
40
|
+
pub const VisualEffectPlan = render_effects.VisualEffectPlan;
|
|
41
|
+
pub const VisualEffectPlanner = render_effects.VisualEffectPlanner;
|
|
42
|
+
pub const VisualEffectKey = render_effects.VisualEffectKey;
|
|
43
|
+
pub const VisualEffectCacheEntry = render_effects.VisualEffectCacheEntry;
|
|
44
|
+
pub const VisualEffectCacheActionKind = render_effects.VisualEffectCacheActionKind;
|
|
45
|
+
pub const VisualEffectCacheAction = render_effects.VisualEffectCacheAction;
|
|
46
|
+
pub const VisualEffectCachePlan = render_effects.VisualEffectCachePlan;
|
|
47
|
+
pub const VisualEffectCachePlanner = render_effects.VisualEffectCachePlanner;
|
|
48
|
+
|
|
49
|
+
pub const drawImageFingerprint = render_fingerprints.drawImageFingerprint;
|
|
50
|
+
pub const renderImageFingerprint = render_fingerprints.renderImageFingerprint;
|
|
51
|
+
pub const renderImageFingerprintForResource = render_fingerprints.renderImageFingerprintForResource;
|