@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.
Files changed (367) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +50 -1
  3. package/app.zon +30 -0
  4. package/bin/native.js +156 -0
  5. package/build/app.zig +716 -0
  6. package/build.zig +2593 -0
  7. package/build.zig.zon +24 -0
  8. package/native-sdk.d.ts +615 -0
  9. package/package.json +44 -8
  10. package/skill-data/automation/SKILL.md +248 -0
  11. package/skill-data/core/SKILL.md +249 -0
  12. package/skill-data/core/references/app-model-runtime.md +141 -0
  13. package/skill-data/core/references/bridge-security-native-capabilities.md +230 -0
  14. package/skill-data/core/references/frontend-assets.md +124 -0
  15. package/skill-data/core/references/project-anatomy.md +108 -0
  16. package/skill-data/core/references/web-engines-packaging-debugging.md +199 -0
  17. package/skill-data/native-ui/SKILL.md +1080 -0
  18. package/skills/native-sdk/SKILL.md +33 -0
  19. package/src/app_runner/root.zig +740 -0
  20. package/src/assets/root.zig +20 -0
  21. package/src/automation/protocol.zig +285 -0
  22. package/src/automation/root.zig +13 -0
  23. package/src/automation/server.zig +506 -0
  24. package/src/automation/snapshot.zig +1202 -0
  25. package/src/automation/watcher.zig +165 -0
  26. package/src/bridge/root.zig +507 -0
  27. package/src/debug/root.zig +246 -0
  28. package/src/embed/app_exports.zig +11 -0
  29. package/src/embed/c_api.zig +793 -0
  30. package/src/embed/c_exports.zig +10 -0
  31. package/src/embed/chrome.zig +168 -0
  32. package/src/embed/conversions.zig +359 -0
  33. package/src/embed/host.zig +960 -0
  34. package/src/embed/root.zig +81 -0
  35. package/src/embed/tests.zig +2552 -0
  36. package/src/embed/types.zig +382 -0
  37. package/src/embed/ui_host.zig +289 -0
  38. package/src/extensions/root.zig +197 -0
  39. package/src/frontend/root.zig +48 -0
  40. package/src/js/root.zig +65 -0
  41. package/src/platform/android/NativeSdkActivity.java +1370 -0
  42. package/src/platform/android/android_host.c +696 -0
  43. package/src/platform/android/files.zig +9 -0
  44. package/src/platform/android/native_sdk_app.h +237 -0
  45. package/src/platform/ios/files.zig +8 -0
  46. package/src/platform/ios/native_sdk_app.h +289 -0
  47. package/src/platform/ios/uikit_host.m +2739 -0
  48. package/src/platform/linux/cef_host.cpp +599 -0
  49. package/src/platform/linux/gtk_host.c +5362 -0
  50. package/src/platform/linux/gtk_host.h +265 -0
  51. package/src/platform/linux/root.zig +1519 -0
  52. package/src/platform/macos/appkit_host.h +604 -0
  53. package/src/platform/macos/appkit_host.m +10392 -0
  54. package/src/platform/macos/automation_host.h +14 -0
  55. package/src/platform/macos/automation_host.m +12 -0
  56. package/src/platform/macos/cef_host.mm +3028 -0
  57. package/src/platform/macos/root.zig +2260 -0
  58. package/src/platform/null_platform.zig +2232 -0
  59. package/src/platform/null_platform_tests.zig +670 -0
  60. package/src/platform/policy_values.zig +14 -0
  61. package/src/platform/root.zig +181 -0
  62. package/src/platform/types.zig +2681 -0
  63. package/src/platform/windows/cef_host.cpp +3 -0
  64. package/src/platform/windows/root.zig +1521 -0
  65. package/src/platform/windows/webview2_host.cpp +6230 -0
  66. package/src/primitives/app_dirs/root.zig +440 -0
  67. package/src/primitives/app_manifest/root.zig +109 -0
  68. package/src/primitives/app_manifest/tests.zig +758 -0
  69. package/src/primitives/app_manifest/types.zig +587 -0
  70. package/src/primitives/app_manifest/validation.zig +828 -0
  71. package/src/primitives/assets/root.zig +520 -0
  72. package/src/primitives/canvas/a11y_audit.zig +390 -0
  73. package/src/primitives/canvas/a11y_audit_tests.zig +225 -0
  74. package/src/primitives/canvas/app_icon.zig +1590 -0
  75. package/src/primitives/canvas/chart.zig +392 -0
  76. package/src/primitives/canvas/chart_tests.zig +751 -0
  77. package/src/primitives/canvas/commands.zig +446 -0
  78. package/src/primitives/canvas/drawing.zig +309 -0
  79. package/src/primitives/canvas/equality.zig +316 -0
  80. package/src/primitives/canvas/events.zig +696 -0
  81. package/src/primitives/canvas/font_coverage.zig +118 -0
  82. package/src/primitives/canvas/font_ttf.zig +510 -0
  83. package/src/primitives/canvas/font_ttf_tests.zig +280 -0
  84. package/src/primitives/canvas/fonts/Geist-Regular.ttf +0 -0
  85. package/src/primitives/canvas/fonts/GeistMono-Regular.ttf +0 -0
  86. package/src/primitives/canvas/frame.zig +679 -0
  87. package/src/primitives/canvas/frame_metrics.zig +462 -0
  88. package/src/primitives/canvas/gpu.zig +639 -0
  89. package/src/primitives/canvas/hash.zig +112 -0
  90. package/src/primitives/canvas/icons/alert.svg +1 -0
  91. package/src/primitives/canvas/icons/archive.svg +1 -0
  92. package/src/primitives/canvas/icons/arrow-down.svg +1 -0
  93. package/src/primitives/canvas/icons/arrow-right.svg +1 -0
  94. package/src/primitives/canvas/icons/arrow-up.svg +1 -0
  95. package/src/primitives/canvas/icons/check-circle.svg +1 -0
  96. package/src/primitives/canvas/icons/check.svg +1 -0
  97. package/src/primitives/canvas/icons/chevron-down.svg +1 -0
  98. package/src/primitives/canvas/icons/chevron-left.svg +1 -0
  99. package/src/primitives/canvas/icons/chevron-right.svg +1 -0
  100. package/src/primitives/canvas/icons/chevron-up.svg +1 -0
  101. package/src/primitives/canvas/icons/circle-dot.svg +1 -0
  102. package/src/primitives/canvas/icons/clock.svg +1 -0
  103. package/src/primitives/canvas/icons/copy.svg +1 -0
  104. package/src/primitives/canvas/icons/download.svg +1 -0
  105. package/src/primitives/canvas/icons/edit.svg +1 -0
  106. package/src/primitives/canvas/icons/ellipsis.svg +1 -0
  107. package/src/primitives/canvas/icons/external-link.svg +1 -0
  108. package/src/primitives/canvas/icons/eye.svg +1 -0
  109. package/src/primitives/canvas/icons/file-text.svg +1 -0
  110. package/src/primitives/canvas/icons/folder-open.svg +1 -0
  111. package/src/primitives/canvas/icons/folder.svg +1 -0
  112. package/src/primitives/canvas/icons/git-branch.svg +1 -0
  113. package/src/primitives/canvas/icons/git-merge.svg +1 -0
  114. package/src/primitives/canvas/icons/git-pull-request.svg +1 -0
  115. package/src/primitives/canvas/icons/info.svg +1 -0
  116. package/src/primitives/canvas/icons/menu.svg +1 -0
  117. package/src/primitives/canvas/icons/missing.svg +1 -0
  118. package/src/primitives/canvas/icons/moon.svg +1 -0
  119. package/src/primitives/canvas/icons/music.svg +1 -0
  120. package/src/primitives/canvas/icons/panel-left.svg +1 -0
  121. package/src/primitives/canvas/icons/panel-right.svg +1 -0
  122. package/src/primitives/canvas/icons/pause.svg +1 -0
  123. package/src/primitives/canvas/icons/play.svg +1 -0
  124. package/src/primitives/canvas/icons/plus.svg +1 -0
  125. package/src/primitives/canvas/icons/refresh-cw.svg +1 -0
  126. package/src/primitives/canvas/icons/repeat.svg +1 -0
  127. package/src/primitives/canvas/icons/save.svg +1 -0
  128. package/src/primitives/canvas/icons/search.svg +1 -0
  129. package/src/primitives/canvas/icons/send.svg +1 -0
  130. package/src/primitives/canvas/icons/settings.svg +1 -0
  131. package/src/primitives/canvas/icons/shuffle.svg +1 -0
  132. package/src/primitives/canvas/icons/skip-back.svg +1 -0
  133. package/src/primitives/canvas/icons/skip-forward.svg +1 -0
  134. package/src/primitives/canvas/icons/sun.svg +1 -0
  135. package/src/primitives/canvas/icons/terminal.svg +1 -0
  136. package/src/primitives/canvas/icons/trash.svg +1 -0
  137. package/src/primitives/canvas/icons/volume.svg +1 -0
  138. package/src/primitives/canvas/icons/wrench.svg +1 -0
  139. package/src/primitives/canvas/icons/x-circle.svg +1 -0
  140. package/src/primitives/canvas/icons/x.svg +1 -0
  141. package/src/primitives/canvas/icons.zig +249 -0
  142. package/src/primitives/canvas/layout_audit.zig +744 -0
  143. package/src/primitives/canvas/layout_audit_tests.zig +426 -0
  144. package/src/primitives/canvas/markdown.zig +1031 -0
  145. package/src/primitives/canvas/markdown_hostile_tests.zig +471 -0
  146. package/src/primitives/canvas/markdown_tests.zig +538 -0
  147. package/src/primitives/canvas/plan_key_index.zig +120 -0
  148. package/src/primitives/canvas/png.zig +355 -0
  149. package/src/primitives/canvas/reference.zig +1457 -0
  150. package/src/primitives/canvas/reference_blur.zig +104 -0
  151. package/src/primitives/canvas/reference_memo.zig +322 -0
  152. package/src/primitives/canvas/reference_paths.zig +184 -0
  153. package/src/primitives/canvas/reference_tests.zig +1650 -0
  154. package/src/primitives/canvas/render.zig +747 -0
  155. package/src/primitives/canvas/render_effects.zig +255 -0
  156. package/src/primitives/canvas/render_fingerprints.zig +256 -0
  157. package/src/primitives/canvas/render_generic_resources.zig +376 -0
  158. package/src/primitives/canvas/render_images.zig +247 -0
  159. package/src/primitives/canvas/render_layers.zig +260 -0
  160. package/src/primitives/canvas/render_paths.zig +347 -0
  161. package/src/primitives/canvas/render_resources.zig +51 -0
  162. package/src/primitives/canvas/render_tests.zig +3186 -0
  163. package/src/primitives/canvas/root.zig +744 -0
  164. package/src/primitives/canvas/serialization.zig +1528 -0
  165. package/src/primitives/canvas/svg_icon.zig +636 -0
  166. package/src/primitives/canvas/svg_icon_tests.zig +312 -0
  167. package/src/primitives/canvas/test_support.zig +422 -0
  168. package/src/primitives/canvas/testdata/markdown_document.md +83 -0
  169. package/src/primitives/canvas/tests.zig +30 -0
  170. package/src/primitives/canvas/text.zig +82 -0
  171. package/src/primitives/canvas/text_atlas.zig +408 -0
  172. package/src/primitives/canvas/text_batch_tests.zig +431 -0
  173. package/src/primitives/canvas/text_interaction.zig +615 -0
  174. package/src/primitives/canvas/text_layout.zig +1069 -0
  175. package/src/primitives/canvas/text_layout_cache.zig +281 -0
  176. package/src/primitives/canvas/text_layout_hash.zig +113 -0
  177. package/src/primitives/canvas/text_layout_types.zig +128 -0
  178. package/src/primitives/canvas/text_measure_cache.zig +279 -0
  179. package/src/primitives/canvas/text_metrics.zig +309 -0
  180. package/src/primitives/canvas/text_metrics_tests.zig +262 -0
  181. package/src/primitives/canvas/text_span_tests.zig +608 -0
  182. package/src/primitives/canvas/text_spans.zig +1010 -0
  183. package/src/primitives/canvas/text_tests.zig +1949 -0
  184. package/src/primitives/canvas/themes/geist.zig +470 -0
  185. package/src/primitives/canvas/tokens.zig +1522 -0
  186. package/src/primitives/canvas/ui.zig +2686 -0
  187. package/src/primitives/canvas/ui_markup.zig +3791 -0
  188. package/src/primitives/canvas/ui_markup_binary.zig +522 -0
  189. package/src/primitives/canvas/ui_markup_binary_tests.zig +591 -0
  190. package/src/primitives/canvas/ui_markup_compiled.zig +2565 -0
  191. package/src/primitives/canvas/ui_markup_compiled_tests.zig +1669 -0
  192. package/src/primitives/canvas/ui_markup_contract.zig +1620 -0
  193. package/src/primitives/canvas/ui_markup_contract_tests.zig +953 -0
  194. package/src/primitives/canvas/ui_markup_edit.zig +416 -0
  195. package/src/primitives/canvas/ui_markup_edit_tests.zig +341 -0
  196. package/src/primitives/canvas/ui_markup_expr.zig +1152 -0
  197. package/src/primitives/canvas/ui_markup_expr_tests.zig +779 -0
  198. package/src/primitives/canvas/ui_markup_huge_model_tests.zig +505 -0
  199. package/src/primitives/canvas/ui_markup_reflect.zig +127 -0
  200. package/src/primitives/canvas/ui_markup_tests.zig +1545 -0
  201. package/src/primitives/canvas/ui_markup_view.zig +2352 -0
  202. package/src/primitives/canvas/ui_markup_view_tests.zig +3709 -0
  203. package/src/primitives/canvas/ui_provenance.zig +96 -0
  204. package/src/primitives/canvas/ui_provenance_tests.zig +186 -0
  205. package/src/primitives/canvas/ui_schema.zig +825 -0
  206. package/src/primitives/canvas/ui_schema_tests.zig +128 -0
  207. package/src/primitives/canvas/ui_tests.zig +1432 -0
  208. package/src/primitives/canvas/vector.zig +919 -0
  209. package/src/primitives/canvas/vector_tests.zig +547 -0
  210. package/src/primitives/canvas/virtual_extent_tests.zig +317 -0
  211. package/src/primitives/canvas/virtual_extents.zig +540 -0
  212. package/src/primitives/canvas/widget_access.zig +208 -0
  213. package/src/primitives/canvas/widget_anchored_tests.zig +264 -0
  214. package/src/primitives/canvas/widget_builtin_tests.zig +3160 -0
  215. package/src/primitives/canvas/widget_invalidation.zig +748 -0
  216. package/src/primitives/canvas/widget_layout.zig +2055 -0
  217. package/src/primitives/canvas/widget_layout_tests.zig +2691 -0
  218. package/src/primitives/canvas/widget_metrics.zig +228 -0
  219. package/src/primitives/canvas/widget_render.zig +2534 -0
  220. package/src/primitives/canvas/widget_render_controls.zig +1563 -0
  221. package/src/primitives/canvas/widget_render_scroll.zig +136 -0
  222. package/src/primitives/canvas/widget_render_style.zig +626 -0
  223. package/src/primitives/canvas/widget_render_surfaces.zig +794 -0
  224. package/src/primitives/canvas/widget_routing.zig +475 -0
  225. package/src/primitives/canvas/widget_runtime.zig +307 -0
  226. package/src/primitives/canvas/widget_runtime_tests.zig +3015 -0
  227. package/src/primitives/canvas/widget_semantics.zig +480 -0
  228. package/src/primitives/canvas/widget_semantics_tests.zig +2129 -0
  229. package/src/primitives/canvas/widget_tests.zig +8 -0
  230. package/src/primitives/canvas/widget_text_input.zig +351 -0
  231. package/src/primitives/canvas/widget_text_select.zig +147 -0
  232. package/src/primitives/canvas/widget_tree.zig +232 -0
  233. package/src/primitives/canvas/widgets.zig +1319 -0
  234. package/src/primitives/diagnostics/root.zig +445 -0
  235. package/src/primitives/geometry/root.zig +889 -0
  236. package/src/primitives/json/root.zig +272 -0
  237. package/src/primitives/platform_info/root.zig +450 -0
  238. package/src/primitives/trace/root.zig +569 -0
  239. package/src/root.zig +165 -0
  240. package/src/runtime/api.zig +431 -0
  241. package/src/runtime/async_bridge.zig +49 -0
  242. package/src/runtime/automation_commands.zig +686 -0
  243. package/src/runtime/automation_liveness_tests.zig +140 -0
  244. package/src/runtime/automation_snapshot.zig +246 -0
  245. package/src/runtime/automation_widget_dispatch.zig +617 -0
  246. package/src/runtime/bridge_dispatch_tests.zig +202 -0
  247. package/src/runtime/bridge_payload.zig +194 -0
  248. package/src/runtime/bridge_permission_tests.zig +551 -0
  249. package/src/runtime/bridge_responses.zig +414 -0
  250. package/src/runtime/builtin_bridge.zig +554 -0
  251. package/src/runtime/canvas_budget_edge_tests.zig +415 -0
  252. package/src/runtime/canvas_font_tests.zig +410 -0
  253. package/src/runtime/canvas_fonts.zig +229 -0
  254. package/src/runtime/canvas_frame.zig +1734 -0
  255. package/src/runtime/canvas_frame_animation_tests.zig +609 -0
  256. package/src/runtime/canvas_frame_cache_tests.zig +333 -0
  257. package/src/runtime/canvas_frame_helpers.zig +414 -0
  258. package/src/runtime/canvas_frame_invalidation_tests.zig +544 -0
  259. package/src/runtime/canvas_frame_packet_tests.zig +1353 -0
  260. package/src/runtime/canvas_frame_patch_tests.zig +1051 -0
  261. package/src/runtime/canvas_frame_retained_tests.zig +753 -0
  262. package/src/runtime/canvas_frame_tests.zig +9 -0
  263. package/src/runtime/canvas_frame_text_layout_budget_tests.zig +149 -0
  264. package/src/runtime/canvas_image_tests.zig +362 -0
  265. package/src/runtime/canvas_images.zig +224 -0
  266. package/src/runtime/canvas_limits.zig +317 -0
  267. package/src/runtime/canvas_screenshot_tests.zig +289 -0
  268. package/src/runtime/canvas_widget_accessibility_tests.zig +1494 -0
  269. package/src/runtime/canvas_widget_anchored_tests.zig +678 -0
  270. package/src/runtime/canvas_widget_chart_tests.zig +249 -0
  271. package/src/runtime/canvas_widget_clipboard_tests.zig +399 -0
  272. package/src/runtime/canvas_widget_context_menu.zig +318 -0
  273. package/src/runtime/canvas_widget_context_menu_tests.zig +462 -0
  274. package/src/runtime/canvas_widget_control_tests.zig +2164 -0
  275. package/src/runtime/canvas_widget_disclosure_tests.zig +440 -0
  276. package/src/runtime/canvas_widget_display.zig +677 -0
  277. package/src/runtime/canvas_widget_event_tests.zig +1779 -0
  278. package/src/runtime/canvas_widget_events.zig +1098 -0
  279. package/src/runtime/canvas_widget_floating_tests.zig +695 -0
  280. package/src/runtime/canvas_widget_layout_tests.zig +26 -0
  281. package/src/runtime/canvas_widget_runtime.zig +1335 -0
  282. package/src/runtime/canvas_widget_scroll_driver_tests.zig +582 -0
  283. package/src/runtime/canvas_widget_scroll_drivers.zig +202 -0
  284. package/src/runtime/canvas_widget_scroll_tests.zig +1549 -0
  285. package/src/runtime/canvas_widget_semantics_tests.zig +810 -0
  286. package/src/runtime/canvas_widget_split_tree_tests.zig +1031 -0
  287. package/src/runtime/canvas_widget_state.zig +798 -0
  288. package/src/runtime/canvas_widget_text_tests.zig +2104 -0
  289. package/src/runtime/canvas_widget_window_drag_tests.zig +284 -0
  290. package/src/runtime/clock.zig +231 -0
  291. package/src/runtime/core.zig +927 -0
  292. package/src/runtime/effects.zig +4197 -0
  293. package/src/runtime/effects_audio_tests.zig +690 -0
  294. package/src/runtime/effects_clipboard_tests.zig +317 -0
  295. package/src/runtime/effects_fetch_tests.zig +1031 -0
  296. package/src/runtime/effects_file_tests.zig +407 -0
  297. package/src/runtime/effects_tests.zig +1251 -0
  298. package/src/runtime/flow.zig +1175 -0
  299. package/src/runtime/frame_profile.zig +221 -0
  300. package/src/runtime/gpu_surface_events.zig +639 -0
  301. package/src/runtime/launch_timing.zig +59 -0
  302. package/src/runtime/markdown_app_tests.zig +224 -0
  303. package/src/runtime/native_command_event_tests.zig +431 -0
  304. package/src/runtime/platform_bridge_tests.zig +8 -0
  305. package/src/runtime/platform_config_tests.zig +392 -0
  306. package/src/runtime/root.zig +150 -0
  307. package/src/runtime/runtime_event_tests.zig +1079 -0
  308. package/src/runtime/session_journal.zig +1522 -0
  309. package/src/runtime/session_record.zig +332 -0
  310. package/src/runtime/session_replay.zig +274 -0
  311. package/src/runtime/session_state.zig +30 -0
  312. package/src/runtime/session_tests.zig +399 -0
  313. package/src/runtime/shell_layout.zig +472 -0
  314. package/src/runtime/shell_layout_tests.zig +1246 -0
  315. package/src/runtime/shell_view_tests.zig +604 -0
  316. package/src/runtime/state.zig +110 -0
  317. package/src/runtime/system_services.zig +392 -0
  318. package/src/runtime/test_support.zig +79 -0
  319. package/src/runtime/tests.zig +30 -0
  320. package/src/runtime/ui_app.zig +3290 -0
  321. package/src/runtime/ui_app_huge_model_tests.zig +351 -0
  322. package/src/runtime/ui_app_provenance.zig +370 -0
  323. package/src/runtime/ui_app_tests.zig +3254 -0
  324. package/src/runtime/ui_app_virtual_variable_tests.zig +485 -0
  325. package/src/runtime/ui_app_window_tests.zig +442 -0
  326. package/src/runtime/validation.zig +206 -0
  327. package/src/runtime/view.zig +908 -0
  328. package/src/runtime/view_canvas.zig +850 -0
  329. package/src/runtime/view_widget_control.zig +433 -0
  330. package/src/runtime/view_widget_scroll.zig +360 -0
  331. package/src/runtime/view_widget_text.zig +275 -0
  332. package/src/runtime/view_widget_tree.zig +843 -0
  333. package/src/runtime/webview_view_bridge_tests.zig +664 -0
  334. package/src/runtime/widget_bridge.zig +231 -0
  335. package/src/runtime/window_command_bridge_tests.zig +403 -0
  336. package/src/runtime/window_storage.zig +255 -0
  337. package/src/runtime/window_view_runtime.zig +727 -0
  338. package/src/runtime/window_views.zig +334 -0
  339. package/src/security/root.zig +118 -0
  340. package/src/tooling/android.zig +1172 -0
  341. package/src/tooling/assets.zig +128 -0
  342. package/src/tooling/buildgraph.zig +379 -0
  343. package/src/tooling/cef.zig +671 -0
  344. package/src/tooling/codesign.zig +172 -0
  345. package/src/tooling/components/identity_tests.zig +185 -0
  346. package/src/tooling/components/stepper.zig +113 -0
  347. package/src/tooling/components/timeline.native +27 -0
  348. package/src/tooling/components/timeline_item.zig +131 -0
  349. package/src/tooling/default_icon.icns +0 -0
  350. package/src/tooling/default_icon.png +0 -0
  351. package/src/tooling/dev.zig +172 -0
  352. package/src/tooling/doctor.zig +349 -0
  353. package/src/tooling/eject_components.zig +170 -0
  354. package/src/tooling/embedlib.zig +290 -0
  355. package/src/tooling/ios.zig +528 -0
  356. package/src/tooling/manifest.zig +1939 -0
  357. package/src/tooling/package.zig +2388 -0
  358. package/src/tooling/process_tree.zig +114 -0
  359. package/src/tooling/raw_manifest.zig +193 -0
  360. package/src/tooling/root.zig +22 -0
  361. package/src/tooling/templates.zig +3191 -0
  362. package/src/tooling/toolchain.zig +371 -0
  363. package/src/tooling/verbs.zig +204 -0
  364. package/src/tooling/web_engine.zig +135 -0
  365. package/src/tooling/xcodeproj.zig +462 -0
  366. package/src/window_state/root.zig +507 -0
  367. package/index.js +0 -2
@@ -0,0 +1,376 @@
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 fingerprints = @import("render_fingerprints.zig");
6
+ const plan_key_index = @import("plan_key_index.zig");
7
+
8
+ const Error = canvas.Error;
9
+ const ObjectId = canvas.ObjectId;
10
+ const ImageId = canvas.ImageId;
11
+ const FontId = canvas.FontId;
12
+ const Fill = drawing_model.Fill;
13
+ const Stroke = drawing_model.Stroke;
14
+ const shadowBounds = drawing_model.shadowBounds;
15
+ const textBounds = text_model.textBounds;
16
+
17
+ const drawImageFingerprint = fingerprints.drawImageFingerprint;
18
+ const drawTextFingerprint = fingerprints.drawTextFingerprint;
19
+ const linearGradientFingerprint = fingerprints.linearGradientFingerprint;
20
+ const shadowFingerprint = fingerprints.shadowFingerprint;
21
+ const blurFingerprint = fingerprints.blurFingerprint;
22
+ const nonZeroObjectId = fingerprints.nonZeroObjectId;
23
+ const nonNegative = fingerprints.nonNegative;
24
+
25
+ pub const RenderResourceKind = enum {
26
+ linear_gradient,
27
+ image,
28
+ glyph_run,
29
+ shadow,
30
+ blur,
31
+ };
32
+
33
+ pub const RenderResource = struct {
34
+ kind: RenderResourceKind,
35
+ command_index: usize,
36
+ id: ?ObjectId = null,
37
+ bounds: ?geometry.RectF = null,
38
+ image_id: ImageId = 0,
39
+ font_id: FontId = 0,
40
+ gradient_stop_count: usize = 0,
41
+ glyph_count: usize = 0,
42
+ text_len: usize = 0,
43
+ fingerprint: u64 = 0,
44
+ };
45
+
46
+ pub const RenderResourcePlan = struct {
47
+ resources: []const RenderResource = &.{},
48
+
49
+ pub fn resourceCount(self: RenderResourcePlan) usize {
50
+ return self.resources.len;
51
+ }
52
+
53
+ pub fn cachePlan(self: RenderResourcePlan, previous: []const RenderResourceCacheEntry, frame_index: u64, entries: []RenderResourceCacheEntry, actions: []RenderResourceCacheAction) Error!RenderResourceCachePlan {
54
+ var planner = RenderResourceCachePlanner.init(entries, actions);
55
+ return planner.build(self, previous, frame_index);
56
+ }
57
+ };
58
+
59
+ pub const RenderResourcePlanner = struct {
60
+ resources: []RenderResource,
61
+ len: usize = 0,
62
+
63
+ pub fn init(resources: []RenderResource) RenderResourcePlanner {
64
+ return .{ .resources = resources };
65
+ }
66
+
67
+ pub fn reset(self: *RenderResourcePlanner) void {
68
+ self.len = 0;
69
+ }
70
+
71
+ pub fn build(self: *RenderResourcePlanner, display_list: anytype) Error!RenderResourcePlan {
72
+ self.reset();
73
+ for (display_list.commands, 0..) |command, index| {
74
+ try self.consume(command, index);
75
+ }
76
+ return .{ .resources = self.resources[0..self.len] };
77
+ }
78
+
79
+ fn consume(self: *RenderResourcePlanner, command: anytype, index: usize) Error!void {
80
+ switch (command) {
81
+ .push_clip, .pop_clip, .push_opacity, .pop_opacity, .transform => {},
82
+ .fill_rect => |value| try self.consumeFill(value.fill, index, value.id, command.bounds()),
83
+ .stroke_rect => |value| try self.consumeStroke(value.stroke, index, value.id, command.bounds()),
84
+ .fill_rounded_rect => |value| try self.consumeFill(value.fill, index, value.id, command.bounds()),
85
+ .draw_line => |value| try self.consumeStroke(value.stroke, index, value.id, command.bounds()),
86
+ .fill_path => |value| try self.consumeFill(value.fill, index, value.id, command.bounds()),
87
+ .stroke_path => |value| try self.consumeStroke(value.stroke, index, value.id, command.bounds()),
88
+ .draw_image => |value| try self.append(.{
89
+ .kind = .image,
90
+ .command_index = index,
91
+ .id = nonZeroObjectId(value.id),
92
+ .bounds = value.dst.normalized(),
93
+ .image_id = value.image_id,
94
+ .fingerprint = drawImageFingerprint(value),
95
+ }),
96
+ .draw_text => |value| try self.append(.{
97
+ .kind = .glyph_run,
98
+ .command_index = index,
99
+ .id = nonZeroObjectId(value.id),
100
+ .bounds = textBounds(value),
101
+ .font_id = value.font_id,
102
+ .glyph_count = value.glyphs.len,
103
+ .text_len = value.text.len,
104
+ .fingerprint = drawTextFingerprint(value),
105
+ }),
106
+ .shadow => |value| try self.append(.{
107
+ .kind = .shadow,
108
+ .command_index = index,
109
+ .id = nonZeroObjectId(value.id),
110
+ .bounds = shadowBounds(value),
111
+ .fingerprint = shadowFingerprint(value),
112
+ }),
113
+ .blur => |value| try self.append(.{
114
+ .kind = .blur,
115
+ .command_index = index,
116
+ .id = nonZeroObjectId(value.id),
117
+ .bounds = value.rect.normalized().inflate(geometry.InsetsF.all(nonNegative(value.radius))),
118
+ .fingerprint = blurFingerprint(value),
119
+ }),
120
+ }
121
+ }
122
+
123
+ fn consumeStroke(self: *RenderResourcePlanner, stroke: Stroke, index: usize, id: ObjectId, bounds: ?geometry.RectF) Error!void {
124
+ try self.consumeFill(stroke.fill, index, id, bounds);
125
+ }
126
+
127
+ fn consumeFill(self: *RenderResourcePlanner, fill: Fill, index: usize, id: ObjectId, bounds: ?geometry.RectF) Error!void {
128
+ switch (fill) {
129
+ .color => {},
130
+ .linear_gradient => |gradient| try self.append(.{
131
+ .kind = .linear_gradient,
132
+ .command_index = index,
133
+ .id = nonZeroObjectId(id),
134
+ .bounds = bounds,
135
+ .gradient_stop_count = gradient.stops.len,
136
+ .fingerprint = linearGradientFingerprint(gradient),
137
+ }),
138
+ }
139
+ }
140
+
141
+ fn append(self: *RenderResourcePlanner, resource: RenderResource) Error!void {
142
+ if (self.len >= self.resources.len) return error.RenderResourceListFull;
143
+ self.resources[self.len] = resource;
144
+ self.len += 1;
145
+ }
146
+ };
147
+
148
+ pub const RenderResourceKey = struct {
149
+ kind: RenderResourceKind,
150
+ id: ?ObjectId = null,
151
+ command_index: usize = 0,
152
+ image_id: ImageId = 0,
153
+ font_id: FontId = 0,
154
+ fingerprint: u64 = 0,
155
+ };
156
+
157
+ pub const RenderResourceCacheEntry = struct {
158
+ key: RenderResourceKey,
159
+ last_used_frame: u64 = 0,
160
+ };
161
+
162
+ pub const RenderResourceCacheActionKind = enum {
163
+ upload,
164
+ retain,
165
+ evict,
166
+ };
167
+
168
+ pub const RenderResourceCacheAction = struct {
169
+ kind: RenderResourceCacheActionKind,
170
+ key: RenderResourceKey,
171
+ resource_index: ?usize = null,
172
+ cache_index: ?usize = null,
173
+ };
174
+
175
+ pub const RenderResourceCachePlan = struct {
176
+ entries: []const RenderResourceCacheEntry = &.{},
177
+ actions: []const RenderResourceCacheAction = &.{},
178
+
179
+ pub fn entryCount(self: RenderResourceCachePlan) usize {
180
+ return self.entries.len;
181
+ }
182
+
183
+ pub fn actionCount(self: RenderResourceCachePlan) usize {
184
+ return self.actions.len;
185
+ }
186
+
187
+ pub fn uploadCount(self: RenderResourceCachePlan) usize {
188
+ return self.actionCountByKind(.upload);
189
+ }
190
+
191
+ pub fn retainCount(self: RenderResourceCachePlan) usize {
192
+ return self.actionCountByKind(.retain);
193
+ }
194
+
195
+ pub fn evictCount(self: RenderResourceCachePlan) usize {
196
+ return self.actionCountByKind(.evict);
197
+ }
198
+
199
+ fn actionCountByKind(self: RenderResourceCachePlan, kind: RenderResourceCacheActionKind) usize {
200
+ var count: usize = 0;
201
+ for (self.actions) |action| {
202
+ if (action.kind == kind) count += 1;
203
+ }
204
+ return count;
205
+ }
206
+ };
207
+
208
+ pub const RenderResourceCachePlanner = struct {
209
+ entries: []RenderResourceCacheEntry,
210
+ actions: []RenderResourceCacheAction,
211
+ entry_len: usize = 0,
212
+ action_len: usize = 0,
213
+
214
+ pub fn init(entries: []RenderResourceCacheEntry, actions: []RenderResourceCacheAction) RenderResourceCachePlanner {
215
+ return .{ .entries = entries, .actions = actions };
216
+ }
217
+
218
+ pub fn reset(self: *RenderResourceCachePlanner) void {
219
+ self.entry_len = 0;
220
+ self.action_len = 0;
221
+ }
222
+
223
+ pub fn build(self: *RenderResourceCachePlanner, resource_plan: RenderResourcePlan, previous: []const RenderResourceCacheEntry, frame_index: u64) Error!RenderResourceCachePlan {
224
+ self.reset();
225
+ // Keyed lookups ride the probe-table index whenever the inputs
226
+ // fit its half-full bound (the runtime budgets always do);
227
+ // oversized library inputs keep the linear scans. Same outputs
228
+ // either way — the index resolves to the lowest-index equal
229
+ // entry exactly like the scans it replaces.
230
+ const use_index = (resource_plan.resources.len >= plan_key_index.min_entries_for_index or
231
+ previous.len >= plan_key_index.min_entries_for_index) and
232
+ plan_key_index.fitsHashSlots(resource_cache_index_slots, previous.len) and
233
+ plan_key_index.fitsHashSlots(resource_cache_index_slots, resource_plan.resources.len);
234
+ if (use_index) {
235
+ resource_cache_previous_index.reset();
236
+ for (previous, 0..) |entry, index| {
237
+ var p = ResourceCacheIndex.probe(renderResourceKeyHash(entry.key));
238
+ while (resource_cache_previous_index.next(&p)) |_| {}
239
+ resource_cache_previous_index.insert(p, @intCast(index));
240
+ }
241
+ resource_cache_entry_index.reset();
242
+ }
243
+
244
+ for (resource_plan.resources, 0..) |resource, resource_index| {
245
+ const key = renderResourceKey(resource);
246
+ const key_hash = if (use_index) renderResourceKeyHash(key) else 0;
247
+ if (use_index) {
248
+ var p = ResourceCacheIndex.probe(key_hash);
249
+ var duplicate = false;
250
+ while (resource_cache_entry_index.next(&p)) |candidate| {
251
+ if (renderResourceKeysEqual(self.entries[candidate].key, key)) {
252
+ duplicate = true;
253
+ break;
254
+ }
255
+ }
256
+ if (duplicate) continue;
257
+ const previous_index = findRenderResourceCacheEntryIndexed(previous, key, key_hash);
258
+ try self.appendAction(.{
259
+ .kind = if (previous_index == null) .upload else .retain,
260
+ .key = key,
261
+ .resource_index = resource_index,
262
+ .cache_index = previous_index,
263
+ });
264
+ try self.appendEntry(.{
265
+ .key = key,
266
+ .last_used_frame = frame_index,
267
+ });
268
+ resource_cache_entry_index.insert(p, @intCast(self.entry_len - 1));
269
+ continue;
270
+ }
271
+ if (findRenderResourceCacheEntry(self.entries[0..self.entry_len], key) != null) continue;
272
+
273
+ const previous_index = findRenderResourceCacheEntry(previous, key);
274
+ try self.appendAction(.{
275
+ .kind = if (previous_index == null) .upload else .retain,
276
+ .key = key,
277
+ .resource_index = resource_index,
278
+ .cache_index = previous_index,
279
+ });
280
+ try self.appendEntry(.{
281
+ .key = key,
282
+ .last_used_frame = frame_index,
283
+ });
284
+ }
285
+
286
+ for (previous, 0..) |entry, cache_index| {
287
+ if (use_index) {
288
+ var p = ResourceCacheIndex.probe(renderResourceKeyHash(entry.key));
289
+ var kept = false;
290
+ while (resource_cache_entry_index.next(&p)) |candidate| {
291
+ if (renderResourceKeysEqual(self.entries[candidate].key, entry.key)) {
292
+ kept = true;
293
+ break;
294
+ }
295
+ }
296
+ if (kept) continue;
297
+ } else if (findRenderResourceCacheEntry(self.entries[0..self.entry_len], entry.key) != null) {
298
+ continue;
299
+ }
300
+ try self.appendAction(.{
301
+ .kind = .evict,
302
+ .key = entry.key,
303
+ .cache_index = cache_index,
304
+ });
305
+ }
306
+
307
+ return .{
308
+ .entries = self.entries[0..self.entry_len],
309
+ .actions = self.actions[0..self.action_len],
310
+ };
311
+ }
312
+
313
+ fn appendEntry(self: *RenderResourceCachePlanner, entry: RenderResourceCacheEntry) Error!void {
314
+ if (self.entry_len >= self.entries.len) return error.RenderResourceCacheListFull;
315
+ self.entries[self.entry_len] = entry;
316
+ self.entry_len += 1;
317
+ }
318
+
319
+ fn appendAction(self: *RenderResourceCachePlanner, action: RenderResourceCacheAction) Error!void {
320
+ if (self.action_len >= self.actions.len) return error.RenderResourceCacheListFull;
321
+ self.actions[self.action_len] = action;
322
+ self.action_len += 1;
323
+ }
324
+ };
325
+
326
+ fn renderResourceKey(resource: RenderResource) RenderResourceKey {
327
+ return .{
328
+ .kind = resource.kind,
329
+ .id = resource.id,
330
+ .command_index = if (resource.id == null and resource.kind != .image) resource.command_index else 0,
331
+ .image_id = resource.image_id,
332
+ .font_id = resource.font_id,
333
+ .fingerprint = resource.fingerprint,
334
+ };
335
+ }
336
+
337
+ fn findRenderResourceCacheEntry(entries: []const RenderResourceCacheEntry, key: RenderResourceKey) ?usize {
338
+ for (entries, 0..) |entry, index| {
339
+ if (renderResourceKeysEqual(entry.key, key)) return index;
340
+ }
341
+ return null;
342
+ }
343
+
344
+ /// Probe-table scratch for the cache planner (see plan_key_index.zig):
345
+ /// sized for the runtime's per-view resource budget (2048) at the
346
+ /// half-full bound; bigger inputs fall back to the linear scans.
347
+ const resource_cache_index_slots = 4096;
348
+ const ResourceCacheIndex = plan_key_index.HashSlots(resource_cache_index_slots);
349
+ threadlocal var resource_cache_previous_index: ResourceCacheIndex = .{};
350
+ threadlocal var resource_cache_entry_index: ResourceCacheIndex = .{};
351
+
352
+ /// The chain's first equal candidate is the lowest-index equal entry —
353
+ /// the exact value the linear scan returned.
354
+ fn findRenderResourceCacheEntryIndexed(previous: []const RenderResourceCacheEntry, key: RenderResourceKey, key_hash: u64) ?usize {
355
+ var p = ResourceCacheIndex.probe(key_hash);
356
+ while (resource_cache_previous_index.next(&p)) |candidate| {
357
+ if (renderResourceKeysEqual(previous[candidate].key, key)) return candidate;
358
+ }
359
+ return null;
360
+ }
361
+
362
+ fn renderResourceKeyHash(key: RenderResourceKey) u64 {
363
+ var hash = plan_key_index.mixHash(key.fingerprint ^ @as(u64, @intFromEnum(key.kind)));
364
+ hash = plan_key_index.mixHash(hash ^ @as(u64, key.id orelse 0) ^ @as(u64, @intCast(key.command_index)));
365
+ hash = plan_key_index.mixHash(hash ^ @as(u64, key.image_id) ^ @as(u64, key.font_id) ^ @as(u64, @intFromBool(key.id != null)));
366
+ return hash;
367
+ }
368
+
369
+ fn renderResourceKeysEqual(a: RenderResourceKey, b: RenderResourceKey) bool {
370
+ return a.kind == b.kind and
371
+ a.id == b.id and
372
+ a.command_index == b.command_index and
373
+ a.image_id == b.image_id and
374
+ a.font_id == b.font_id and
375
+ a.fingerprint == b.fingerprint;
376
+ }
@@ -0,0 +1,247 @@
1
+ const geometry = @import("geometry");
2
+ const canvas = @import("root.zig");
3
+ const drawing_model = @import("drawing.zig");
4
+ const fingerprints = @import("render_fingerprints.zig");
5
+
6
+ const Error = canvas.Error;
7
+ const ObjectId = canvas.ObjectId;
8
+ const ImageId = canvas.ImageId;
9
+ const ReferenceImage = canvas.ReferenceImage;
10
+ const DrawImage = drawing_model.DrawImage;
11
+
12
+ pub const RenderImage = struct {
13
+ image_id: ImageId,
14
+ command_index: usize = 0,
15
+ id: ?ObjectId = null,
16
+ draw_count: usize = 0,
17
+ bounds: geometry.RectF = .{},
18
+ width: usize = 0,
19
+ height: usize = 0,
20
+ pixels: []const u8 = &.{},
21
+ fingerprint: u64 = 0,
22
+ };
23
+
24
+ pub const RenderImagePlan = struct {
25
+ images: []const RenderImage = &.{},
26
+
27
+ pub fn imageCount(self: RenderImagePlan) usize {
28
+ return self.images.len;
29
+ }
30
+
31
+ pub fn drawCount(self: RenderImagePlan) usize {
32
+ var count: usize = 0;
33
+ for (self.images) |image| count += image.draw_count;
34
+ return count;
35
+ }
36
+
37
+ pub fn cachePlan(self: RenderImagePlan, previous: []const RenderImageCacheEntry, frame_index: u64, entries: []RenderImageCacheEntry, actions: []RenderImageCacheAction) Error!RenderImageCachePlan {
38
+ var planner = RenderImageCachePlanner.init(entries, actions);
39
+ return planner.build(self, previous, frame_index);
40
+ }
41
+ };
42
+
43
+ pub const RenderImageKey = struct {
44
+ image_id: ImageId,
45
+ fingerprint: u64 = 0,
46
+ };
47
+
48
+ pub const RenderImageCacheEntry = struct {
49
+ key: RenderImageKey,
50
+ last_used_frame: u64 = 0,
51
+ };
52
+
53
+ pub const RenderImageCacheActionKind = enum {
54
+ upload,
55
+ retain,
56
+ evict,
57
+ };
58
+
59
+ pub const RenderImageCacheAction = struct {
60
+ kind: RenderImageCacheActionKind,
61
+ key: RenderImageKey,
62
+ image_index: ?usize = null,
63
+ cache_index: ?usize = null,
64
+ };
65
+
66
+ pub const RenderImageCachePlan = struct {
67
+ entries: []const RenderImageCacheEntry = &.{},
68
+ actions: []const RenderImageCacheAction = &.{},
69
+
70
+ pub fn entryCount(self: RenderImageCachePlan) usize {
71
+ return self.entries.len;
72
+ }
73
+
74
+ pub fn actionCount(self: RenderImageCachePlan) usize {
75
+ return self.actions.len;
76
+ }
77
+
78
+ pub fn uploadCount(self: RenderImageCachePlan) usize {
79
+ return self.actionCountByKind(.upload);
80
+ }
81
+
82
+ pub fn retainCount(self: RenderImageCachePlan) usize {
83
+ return self.actionCountByKind(.retain);
84
+ }
85
+
86
+ pub fn evictCount(self: RenderImageCachePlan) usize {
87
+ return self.actionCountByKind(.evict);
88
+ }
89
+
90
+ fn actionCountByKind(self: RenderImageCachePlan, kind: RenderImageCacheActionKind) usize {
91
+ var count: usize = 0;
92
+ for (self.actions) |action| {
93
+ if (action.kind == kind) count += 1;
94
+ }
95
+ return count;
96
+ }
97
+ };
98
+
99
+ pub const RenderImagePlanner = struct {
100
+ images: []RenderImage,
101
+ image_resources: []const ReferenceImage = &.{},
102
+ len: usize = 0,
103
+
104
+ pub fn init(images: []RenderImage) RenderImagePlanner {
105
+ return .{ .images = images };
106
+ }
107
+
108
+ pub fn reset(self: *RenderImagePlanner) void {
109
+ self.len = 0;
110
+ }
111
+
112
+ pub fn build(self: *RenderImagePlanner, render_plan: anytype) Error!RenderImagePlan {
113
+ self.reset();
114
+ for (render_plan.commands, 0..) |command, index| {
115
+ try self.consume(command, index);
116
+ }
117
+ return .{ .images = self.images[0..self.len] };
118
+ }
119
+
120
+ fn consume(self: *RenderImagePlanner, command: anytype, index: usize) Error!void {
121
+ switch (command.command) {
122
+ .draw_image => |value| try self.appendOrExtend(value, command, index),
123
+ else => {},
124
+ }
125
+ }
126
+
127
+ fn appendOrExtend(self: *RenderImagePlanner, image: DrawImage, command: anytype, index: usize) Error!void {
128
+ const resource = findReferenceImage(self.image_resources, image.image_id);
129
+ const fingerprint = fingerprints.renderImageFingerprintForResource(image.image_id, resource);
130
+ if (findRenderImage(self.images[0..self.len], image.image_id, fingerprint)) |existing_index| {
131
+ const existing = &self.images[existing_index];
132
+ existing.draw_count += 1;
133
+ existing.id = if (existing.id == command.id) existing.id else null;
134
+ existing.bounds = geometry.RectF.unionWith(existing.bounds.normalized(), command.bounds.normalized());
135
+ return;
136
+ }
137
+
138
+ if (self.len >= self.images.len) return error.ImageListFull;
139
+ self.images[self.len] = .{
140
+ .image_id = image.image_id,
141
+ .command_index = index,
142
+ .id = command.id,
143
+ .draw_count = 1,
144
+ .bounds = command.bounds,
145
+ .width = if (resource) |value| value.width else 0,
146
+ .height = if (resource) |value| value.height else 0,
147
+ .pixels = if (resource) |value| value.pixels else &.{},
148
+ .fingerprint = fingerprint,
149
+ };
150
+ self.len += 1;
151
+ }
152
+ };
153
+
154
+ pub const RenderImageCachePlanner = struct {
155
+ entries: []RenderImageCacheEntry,
156
+ actions: []RenderImageCacheAction,
157
+ entry_len: usize = 0,
158
+ action_len: usize = 0,
159
+
160
+ pub fn init(entries: []RenderImageCacheEntry, actions: []RenderImageCacheAction) RenderImageCachePlanner {
161
+ return .{ .entries = entries, .actions = actions };
162
+ }
163
+
164
+ pub fn reset(self: *RenderImageCachePlanner) void {
165
+ self.entry_len = 0;
166
+ self.action_len = 0;
167
+ }
168
+
169
+ pub fn build(self: *RenderImageCachePlanner, image_plan: RenderImagePlan, previous: []const RenderImageCacheEntry, frame_index: u64) Error!RenderImageCachePlan {
170
+ self.reset();
171
+ for (image_plan.images, 0..) |image, image_index| {
172
+ const key = renderImageKey(image);
173
+ if (findRenderImageCacheEntry(self.entries[0..self.entry_len], key) != null) continue;
174
+
175
+ const previous_index = findRenderImageCacheEntry(previous, key);
176
+ try self.appendAction(.{
177
+ .kind = if (previous_index == null) .upload else .retain,
178
+ .key = key,
179
+ .image_index = image_index,
180
+ .cache_index = previous_index,
181
+ });
182
+ try self.appendEntry(.{
183
+ .key = key,
184
+ .last_used_frame = frame_index,
185
+ });
186
+ }
187
+
188
+ for (previous, 0..) |entry, cache_index| {
189
+ if (findRenderImageCacheEntry(self.entries[0..self.entry_len], entry.key) != null) continue;
190
+ try self.appendAction(.{
191
+ .kind = .evict,
192
+ .key = entry.key,
193
+ .cache_index = cache_index,
194
+ });
195
+ }
196
+
197
+ return .{
198
+ .entries = self.entries[0..self.entry_len],
199
+ .actions = self.actions[0..self.action_len],
200
+ };
201
+ }
202
+
203
+ fn appendEntry(self: *RenderImageCachePlanner, entry: RenderImageCacheEntry) Error!void {
204
+ if (self.entry_len >= self.entries.len) return error.ImageCacheListFull;
205
+ self.entries[self.entry_len] = entry;
206
+ self.entry_len += 1;
207
+ }
208
+
209
+ fn appendAction(self: *RenderImageCachePlanner, action: RenderImageCacheAction) Error!void {
210
+ if (self.action_len >= self.actions.len) return error.ImageCacheListFull;
211
+ self.actions[self.action_len] = action;
212
+ self.action_len += 1;
213
+ }
214
+ };
215
+
216
+ fn renderImageKey(image: RenderImage) RenderImageKey {
217
+ return .{
218
+ .image_id = image.image_id,
219
+ .fingerprint = image.fingerprint,
220
+ };
221
+ }
222
+
223
+ fn findRenderImage(images: []const RenderImage, image_id: ImageId, fingerprint: u64) ?usize {
224
+ for (images, 0..) |image, index| {
225
+ if (image.image_id == image_id and image.fingerprint == fingerprint) return index;
226
+ }
227
+ return null;
228
+ }
229
+
230
+ fn findRenderImageCacheEntry(entries: []const RenderImageCacheEntry, key: RenderImageKey) ?usize {
231
+ for (entries, 0..) |entry, index| {
232
+ if (renderImageKeysEqual(entry.key, key)) return index;
233
+ }
234
+ return null;
235
+ }
236
+
237
+ fn renderImageKeysEqual(a: RenderImageKey, b: RenderImageKey) bool {
238
+ return a.image_id == b.image_id and
239
+ a.fingerprint == b.fingerprint;
240
+ }
241
+
242
+ fn findReferenceImage(images: []const ReferenceImage, id: ImageId) ?ReferenceImage {
243
+ for (images) |image| {
244
+ if (image.id == id) return image;
245
+ }
246
+ return null;
247
+ }