@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,3186 @@
1
+ const support = @import("test_support.zig");
2
+ const std = support.std;
3
+ const geometry = support.geometry;
4
+ const canvas = support.canvas;
5
+ const drawing_model = support.drawing_model;
6
+ const text_model = support.text_model;
7
+ const render_model = support.render_model;
8
+ const event_model = support.event_model;
9
+ const equality_model = support.equality_model;
10
+ const widget_runtime = support.widget_runtime;
11
+ const Error = support.Error;
12
+ const ObjectId = support.ObjectId;
13
+ const ImageId = support.ImageId;
14
+ const FontId = support.FontId;
15
+ const default_sans_font_id = support.default_sans_font_id;
16
+ const default_mono_font_id = support.default_mono_font_id;
17
+ const default_sans_font_family = support.default_sans_font_family;
18
+ const default_mono_font_family = support.default_mono_font_family;
19
+ const default_glyph_atlas_cache_retention_frames = support.default_glyph_atlas_cache_retention_frames;
20
+ const default_text_layout_cache_retention_frames = support.default_text_layout_cache_retention_frames;
21
+ const Color = support.Color;
22
+ const Affine = support.Affine;
23
+ const Radius = support.Radius;
24
+ const GradientStop = support.GradientStop;
25
+ const LinearGradient = support.LinearGradient;
26
+ const Fill = support.Fill;
27
+ const Stroke = support.Stroke;
28
+ const Clip = support.Clip;
29
+ const FillRect = support.FillRect;
30
+ const StrokeRect = support.StrokeRect;
31
+ const FillRoundedRect = support.FillRoundedRect;
32
+ const Line = support.Line;
33
+ const PathVerb = support.PathVerb;
34
+ const PathElement = support.PathElement;
35
+ const FillPath = support.FillPath;
36
+ const StrokePath = support.StrokePath;
37
+ const ImageFit = support.ImageFit;
38
+ const ImageSampling = support.ImageSampling;
39
+ const DrawImage = support.DrawImage;
40
+ const Shadow = support.Shadow;
41
+ const Blur = support.Blur;
42
+ const Glyph = support.Glyph;
43
+ const GlyphAtlasKey = support.GlyphAtlasKey;
44
+ const GlyphAtlasEntry = support.GlyphAtlasEntry;
45
+ const GlyphAtlasPlan = support.GlyphAtlasPlan;
46
+ const GlyphAtlasPlanner = support.GlyphAtlasPlanner;
47
+ const GlyphAtlasCacheEntry = support.GlyphAtlasCacheEntry;
48
+ const GlyphAtlasCacheActionKind = support.GlyphAtlasCacheActionKind;
49
+ const GlyphAtlasCacheAction = support.GlyphAtlasCacheAction;
50
+ const GlyphAtlasCachePlan = support.GlyphAtlasCachePlan;
51
+ const GlyphAtlasCachePlanner = support.GlyphAtlasCachePlanner;
52
+ const DrawText = support.DrawText;
53
+ const TextWrap = support.TextWrap;
54
+ const TextAlign = support.TextAlign;
55
+ const TextLayoutOptions = support.TextLayoutOptions;
56
+ const TextLine = support.TextLine;
57
+ const TextLayout = support.TextLayout;
58
+ const TextLayoutKey = support.TextLayoutKey;
59
+ const TextLayoutPlan = support.TextLayoutPlan;
60
+ const TextLayoutPlanSet = support.TextLayoutPlanSet;
61
+ const TextLayoutPlanner = support.TextLayoutPlanner;
62
+ const TextLayoutCacheEntry = support.TextLayoutCacheEntry;
63
+ const TextLayoutCacheActionKind = support.TextLayoutCacheActionKind;
64
+ const TextLayoutCacheAction = support.TextLayoutCacheAction;
65
+ const TextLayoutCachePlan = support.TextLayoutCachePlan;
66
+ const TextLayoutCachePlanner = support.TextLayoutCachePlanner;
67
+ const TextRange = support.TextRange;
68
+ const TextSelectionRect = support.TextSelectionRect;
69
+ const TextSelection = support.TextSelection;
70
+ const TextCaretDirection = support.TextCaretDirection;
71
+ const TextCaretMove = support.TextCaretMove;
72
+ const TextCompositionUpdate = support.TextCompositionUpdate;
73
+ const TextInputEvent = support.TextInputEvent;
74
+ const TextEditState = support.TextEditState;
75
+ const CanvasCommand = support.CanvasCommand;
76
+ const CommandRef = support.CommandRef;
77
+ const DiffKind = support.DiffKind;
78
+ const DiffChange = support.DiffChange;
79
+ const Builder = support.Builder;
80
+ const max_render_state_stack = support.max_render_state_stack;
81
+ const RenderState = support.RenderState;
82
+ const RenderCommand = support.RenderCommand;
83
+ const CanvasRenderOverride = support.CanvasRenderOverride;
84
+ const CanvasRenderAnimation = support.CanvasRenderAnimation;
85
+ const applyRenderOverrides = support.applyRenderOverrides;
86
+ const renderOverrideDirtyBounds = support.renderOverrideDirtyBounds;
87
+ const RenderPlan = support.RenderPlan;
88
+ const RenderPlanner = support.RenderPlanner;
89
+ const RenderPipelineKind = support.RenderPipelineKind;
90
+ const RenderBatch = support.RenderBatch;
91
+ const RenderBatchPlanner = support.RenderBatchPlanner;
92
+ const RenderBatchPlan = support.RenderBatchPlan;
93
+ const RenderPipelineCacheEntry = support.RenderPipelineCacheEntry;
94
+ const RenderPipelineCacheActionKind = support.RenderPipelineCacheActionKind;
95
+ const RenderPipelineCacheAction = support.RenderPipelineCacheAction;
96
+ const RenderPipelineCachePlanner = support.RenderPipelineCachePlanner;
97
+ const RenderPipelineCachePlan = support.RenderPipelineCachePlan;
98
+ const RenderPathGeometryKind = support.RenderPathGeometryKind;
99
+ const RenderPathGeometry = support.RenderPathGeometry;
100
+ const RenderPathGeometryPlan = support.RenderPathGeometryPlan;
101
+ const RenderPathGeometryPlanner = support.RenderPathGeometryPlanner;
102
+ const RenderPathGeometryKey = support.RenderPathGeometryKey;
103
+ const RenderPathGeometryCacheEntry = support.RenderPathGeometryCacheEntry;
104
+ const RenderPathGeometryCacheActionKind = support.RenderPathGeometryCacheActionKind;
105
+ const RenderPathGeometryCacheAction = support.RenderPathGeometryCacheAction;
106
+ const RenderPathGeometryCachePlan = support.RenderPathGeometryCachePlan;
107
+ const RenderPathGeometryCachePlanner = support.RenderPathGeometryCachePlanner;
108
+ const RenderImage = support.RenderImage;
109
+ const RenderImagePlan = support.RenderImagePlan;
110
+ const RenderImagePlanner = support.RenderImagePlanner;
111
+ const RenderImageKey = support.RenderImageKey;
112
+ const RenderImageCacheEntry = support.RenderImageCacheEntry;
113
+ const RenderImageCacheActionKind = support.RenderImageCacheActionKind;
114
+ const RenderImageCacheAction = support.RenderImageCacheAction;
115
+ const RenderImageCachePlan = support.RenderImageCachePlan;
116
+ const RenderImageCachePlanner = support.RenderImageCachePlanner;
117
+ const RenderResourceKind = support.RenderResourceKind;
118
+ const RenderResource = support.RenderResource;
119
+ const RenderResourcePlan = support.RenderResourcePlan;
120
+ const RenderResourcePlanner = support.RenderResourcePlanner;
121
+ const RenderResourceKey = support.RenderResourceKey;
122
+ const RenderResourceCacheEntry = support.RenderResourceCacheEntry;
123
+ const RenderResourceCacheActionKind = support.RenderResourceCacheActionKind;
124
+ const RenderResourceCacheAction = support.RenderResourceCacheAction;
125
+ const RenderResourceCachePlan = support.RenderResourceCachePlan;
126
+ const RenderResourceCachePlanner = support.RenderResourceCachePlanner;
127
+ const RenderLayer = support.RenderLayer;
128
+ const RenderLayerPlan = support.RenderLayerPlan;
129
+ const RenderLayerPlanner = support.RenderLayerPlanner;
130
+ const RenderLayerKey = support.RenderLayerKey;
131
+ const RenderLayerCacheEntry = support.RenderLayerCacheEntry;
132
+ const RenderLayerCacheActionKind = support.RenderLayerCacheActionKind;
133
+ const RenderLayerCacheAction = support.RenderLayerCacheAction;
134
+ const RenderLayerCachePlan = support.RenderLayerCachePlan;
135
+ const RenderLayerCachePlanner = support.RenderLayerCachePlanner;
136
+ const VisualEffectKind = support.VisualEffectKind;
137
+ const VisualEffect = support.VisualEffect;
138
+ const VisualEffectPlan = support.VisualEffectPlan;
139
+ const VisualEffectPlanner = support.VisualEffectPlanner;
140
+ const VisualEffectKey = support.VisualEffectKey;
141
+ const VisualEffectCacheEntry = support.VisualEffectCacheEntry;
142
+ const VisualEffectCacheActionKind = support.VisualEffectCacheActionKind;
143
+ const VisualEffectCacheAction = support.VisualEffectCacheAction;
144
+ const VisualEffectCachePlan = support.VisualEffectCachePlan;
145
+ const VisualEffectCachePlanner = support.VisualEffectCachePlanner;
146
+ const CanvasFrameOptions = support.CanvasFrameOptions;
147
+ const CanvasFrameStorage = support.CanvasFrameStorage;
148
+ const CanvasFrameBudget = support.CanvasFrameBudget;
149
+ const CanvasFrameBudgetStatus = support.CanvasFrameBudgetStatus;
150
+ const CanvasFrameDiagnostics = support.CanvasFrameDiagnostics;
151
+ const CanvasFrameProfileRisk = support.CanvasFrameProfileRisk;
152
+ const CanvasFrameProfile = support.CanvasFrameProfile;
153
+ const CanvasRenderPass = support.CanvasRenderPass;
154
+ const CanvasFrame = support.CanvasFrame;
155
+ const buildCanvasFrame = support.buildCanvasFrame;
156
+ const CanvasRenderPassLoadAction = support.CanvasRenderPassLoadAction;
157
+ const RenderEncoderBeginPass = support.RenderEncoderBeginPass;
158
+ const RenderEncoderCommand = support.RenderEncoderCommand;
159
+ const RenderEncoderPlan = support.RenderEncoderPlan;
160
+ const RenderEncoderPlanner = support.RenderEncoderPlanner;
161
+ const CanvasGpuCommandKind = support.CanvasGpuCommandKind;
162
+ const CanvasGpuRoundedRect = support.CanvasGpuRoundedRect;
163
+ const CanvasGpuStrokeRect = support.CanvasGpuStrokeRect;
164
+ const CanvasGpuLine = support.CanvasGpuLine;
165
+ const CanvasGpuShape = support.CanvasGpuShape;
166
+ const CanvasGpuPaint = support.CanvasGpuPaint;
167
+ const CanvasGpuImage = support.CanvasGpuImage;
168
+ const CanvasGpuText = support.CanvasGpuText;
169
+ const CanvasGpuShadow = support.CanvasGpuShadow;
170
+ const CanvasGpuBlur = support.CanvasGpuBlur;
171
+ const CanvasGpuEffect = support.CanvasGpuEffect;
172
+ const CanvasGpuCommand = support.CanvasGpuCommand;
173
+ const CanvasGpuPacket = support.CanvasGpuPacket;
174
+ const CanvasGpuPacketSummary = support.CanvasGpuPacketSummary;
175
+ const CanvasGpuPacketPlanner = support.CanvasGpuPacketPlanner;
176
+ const ReferenceImage = support.ReferenceImage;
177
+ const ReferenceRenderSurface = support.ReferenceRenderSurface;
178
+ const Density = support.Density;
179
+ const Easing = support.Easing;
180
+ const ColorScheme = support.ColorScheme;
181
+ const ColorContrast = support.ColorContrast;
182
+ const ThemeOptions = support.ThemeOptions;
183
+ const ColorTokens = support.ColorTokens;
184
+ const FontFamily = support.FontFamily;
185
+ const TypographyTokens = support.TypographyTokens;
186
+ const SpacingTokens = support.SpacingTokens;
187
+ const RadiusTokens = support.RadiusTokens;
188
+ const StrokeTokens = support.StrokeTokens;
189
+ const ShadowToken = support.ShadowToken;
190
+ const ShadowTokens = support.ShadowTokens;
191
+ const BlurTokens = support.BlurTokens;
192
+ const MotionDuration = support.MotionDuration;
193
+ const MotionAnimationOptions = support.MotionAnimationOptions;
194
+ const MotionTokens = support.MotionTokens;
195
+ const SpringToken = support.SpringToken;
196
+ const BlurTokenRef = support.BlurTokenRef;
197
+ const ScrollPhysics = support.ScrollPhysics;
198
+ const ScrollState = support.ScrollState;
199
+ const VirtualListOptions = support.VirtualListOptions;
200
+ const VirtualListRange = support.VirtualListRange;
201
+ const virtualListRange = support.virtualListRange;
202
+ const LayerTokens = support.LayerTokens;
203
+ const PixelSnapTokens = support.PixelSnapTokens;
204
+ const ControlVisualTokens = support.ControlVisualTokens;
205
+ const ControlTokens = support.ControlTokens;
206
+ const ColorTokenOverrides = support.ColorTokenOverrides;
207
+ const TypographyTokenOverrides = support.TypographyTokenOverrides;
208
+ const SpacingTokenOverrides = support.SpacingTokenOverrides;
209
+ const RadiusTokenOverrides = support.RadiusTokenOverrides;
210
+ const StrokeTokenOverrides = support.StrokeTokenOverrides;
211
+ const ShadowTokenOverrides = support.ShadowTokenOverrides;
212
+ const ShadowTokensOverrides = support.ShadowTokensOverrides;
213
+ const BlurTokenOverrides = support.BlurTokenOverrides;
214
+ const SpringTokenOverrides = support.SpringTokenOverrides;
215
+ const MotionTokenOverrides = support.MotionTokenOverrides;
216
+ const ScrollPhysicsOverrides = support.ScrollPhysicsOverrides;
217
+ const LayerTokenOverrides = support.LayerTokenOverrides;
218
+ const PixelSnapTokenOverrides = support.PixelSnapTokenOverrides;
219
+ const ControlVisualTokenOverrides = support.ControlVisualTokenOverrides;
220
+ const ControlTokenOverrides = support.ControlTokenOverrides;
221
+ const DesignTokenOverrides = support.DesignTokenOverrides;
222
+ const DesignTokens = support.DesignTokens;
223
+ const WidgetKind = support.WidgetKind;
224
+ const WidgetCursor = support.WidgetCursor;
225
+ const WidgetState = support.WidgetState;
226
+ const WidgetRenderState = support.WidgetRenderState;
227
+ const WidgetMainAlignment = support.WidgetMainAlignment;
228
+ const WidgetCrossAlignment = support.WidgetCrossAlignment;
229
+ const WidgetLayoutStyle = support.WidgetLayoutStyle;
230
+ const WidgetStyle = support.WidgetStyle;
231
+ const WidgetVariant = support.WidgetVariant;
232
+ const WidgetSize = support.WidgetSize;
233
+ const WidgetRole = support.WidgetRole;
234
+ const BuiltinComponentStyle = support.BuiltinComponentStyle;
235
+ const BuiltinComponentKind = support.BuiltinComponentKind;
236
+ const builtin_component_kinds = support.builtin_component_kinds;
237
+ const builtin_component_names = support.builtin_component_names;
238
+ const BuiltinComponentDescriptor = support.BuiltinComponentDescriptor;
239
+ const builtinComponentCount = support.builtinComponentCount;
240
+ const builtinComponentName = support.builtinComponentName;
241
+ const builtinComponentDescriptor = support.builtinComponentDescriptor;
242
+ const WidgetActions = support.WidgetActions;
243
+ const WidgetSemantics = support.WidgetSemantics;
244
+ const Widget = support.Widget;
245
+ const BuiltinComponentOptions = support.BuiltinComponentOptions;
246
+ const WidgetCommandPart = support.WidgetCommandPart;
247
+ const BuiltinSurfacePlacementOptions = support.BuiltinSurfacePlacementOptions;
248
+ const BuiltinSurfaceBackdropOptions = support.BuiltinSurfaceBackdropOptions;
249
+ const BuiltinStatusBarOptions = support.BuiltinStatusBarOptions;
250
+ const BuiltinSurfaceEnterAnimationOptions = support.BuiltinSurfaceEnterAnimationOptions;
251
+ const builtinComponentWidget = support.builtinComponentWidget;
252
+ const widgetCommandPartId = support.widgetCommandPartId;
253
+ const builtinSurfaceBackdropWidget = support.builtinSurfaceBackdropWidget;
254
+ const builtinStatusBarWidget = support.builtinStatusBarWidget;
255
+ const builtinSurfaceFrame = support.builtinSurfaceFrame;
256
+ const appendBuiltinSurfaceEnterAnimations = support.appendBuiltinSurfaceEnterAnimations;
257
+ const builtinSurfaceEnterOffset = support.builtinSurfaceEnterOffset;
258
+ const max_widget_depth = support.max_widget_depth;
259
+ const max_widget_text_range_rects = support.max_widget_text_range_rects;
260
+ const WidgetLayoutNode = support.WidgetLayoutNode;
261
+ const WidgetHit = support.WidgetHit;
262
+ const WidgetPointerPhase = support.WidgetPointerPhase;
263
+ const WidgetPointerEvent = support.WidgetPointerEvent;
264
+ const WidgetKeyboardPhase = support.WidgetKeyboardPhase;
265
+ const WidgetKeyboardModifiers = support.WidgetKeyboardModifiers;
266
+ const WidgetKeyboardEvent = support.WidgetKeyboardEvent;
267
+ const WidgetControlIntentKind = support.WidgetControlIntentKind;
268
+ const WidgetControlIntent = support.WidgetControlIntent;
269
+ const WidgetSemanticAction = support.WidgetSemanticAction;
270
+ const WidgetFileDropEvent = support.WidgetFileDropEvent;
271
+ const WidgetDragEvent = support.WidgetDragEvent;
272
+ const WidgetEventPhase = support.WidgetEventPhase;
273
+ const WidgetEventRouteEntry = support.WidgetEventRouteEntry;
274
+ const WidgetEventRoute = support.WidgetEventRoute;
275
+ const WidgetKeyboardRoute = support.WidgetKeyboardRoute;
276
+ const WidgetFocusDirection = support.WidgetFocusDirection;
277
+ const WidgetFocusTarget = support.WidgetFocusTarget;
278
+ const WidgetScrollMetrics = support.WidgetScrollMetrics;
279
+ const WidgetListMetrics = support.WidgetListMetrics;
280
+ const WidgetSemanticsNode = support.WidgetSemanticsNode;
281
+ const WidgetInvalidationKind = support.WidgetInvalidationKind;
282
+ const WidgetInvalidation = support.WidgetInvalidation;
283
+ const widgetKeyboardControlIntent = support.widgetKeyboardControlIntent;
284
+ const widgetSemanticControlIntent = support.widgetSemanticControlIntent;
285
+ const widgetSemanticControlIntentWithActions = support.widgetSemanticControlIntentWithActions;
286
+ const isWidgetActivationKey = support.isWidgetActivationKey;
287
+ const widgetSliderKeyboardValue = support.widgetSliderKeyboardValue;
288
+ const widgetScrollKeyboardIntent = support.widgetScrollKeyboardIntent;
289
+ const widgetScrollKeyboardDelta = support.widgetScrollKeyboardDelta;
290
+ const WidgetLayoutTree = support.WidgetLayoutTree;
291
+ const DisplayList = support.DisplayList;
292
+ const emitWidgetTree = support.emitWidgetTree;
293
+ const layoutWidgetTree = support.layoutWidgetTree;
294
+ const layoutWidgetTreeWithTokens = support.layoutWidgetTreeWithTokens;
295
+ const layoutTextRun = support.layoutTextRun;
296
+ const layoutTextRunPlan = support.layoutTextRunPlan;
297
+ const layoutTextCaretRect = support.layoutTextCaretRect;
298
+ const textCaretRectForLayout = support.textCaretRectForLayout;
299
+ const layoutTextSelectionRects = support.layoutTextSelectionRects;
300
+ const textSelectionRectsForLayout = support.textSelectionRectsForLayout;
301
+ const layoutTextOffsetForPoint = support.layoutTextOffsetForPoint;
302
+ const textOffsetForLayoutPoint = support.textOffsetForLayoutPoint;
303
+ const applyTextInputEvent = support.applyTextInputEvent;
304
+ const sampleCanvasRenderAnimations = support.sampleCanvasRenderAnimations;
305
+ const emitWidgetLayout = support.emitWidgetLayout;
306
+ const toggleWidgetKnobCommandId = support.toggleWidgetKnobCommandId;
307
+ const toggleWidgetKnobTravel = support.toggleWidgetKnobTravel;
308
+ const textSelectionForWidgetPoint = support.textSelectionForWidgetPoint;
309
+ const textOffsetForWidgetPoint = support.textOffsetForWidgetPoint;
310
+ const textInputViewportForWidget = support.textInputViewportForWidget;
311
+ const textInputContentExtentForWidget = support.textInputContentExtentForWidget;
312
+ const textInputMaxScrollOffsetForWidget = support.textInputMaxScrollOffsetForWidget;
313
+ const clampedTextInputScrollOffsetForWidget = support.clampedTextInputScrollOffsetForWidget;
314
+ const intrinsicWidgetSize = support.intrinsicWidgetSize;
315
+ const cursorForWidgetHit = support.cursorForWidgetHit;
316
+ const cursorForWidgetTarget = support.cursorForWidgetTarget;
317
+ const WidgetTextGeometry = support.WidgetTextGeometry;
318
+ const textGeometryForWidget = support.textGeometryForWidget;
319
+ const virtualWidgetScrollContentExtent = support.virtualWidgetScrollContentExtent;
320
+ const virtualWidgetScrollContentExtentWithTokens = support.virtualWidgetScrollContentExtentWithTokens;
321
+ const writeCanvasGpuPacketJson = support.writeCanvasGpuPacketJson;
322
+ const strokeBounds = support.strokeBounds;
323
+ const shadowBounds = support.shadowBounds;
324
+ const semanticActions = support.semanticActions;
325
+ const defaultSemanticActions = support.defaultSemanticActions;
326
+ const defaultFocusable = support.defaultFocusable;
327
+ const textLineBounds = support.textLineBounds;
328
+ const textBounds = support.textBounds;
329
+ const estimateTextWidth = support.estimateTextWidth;
330
+ const estimateTextWidthForFont = support.estimateTextWidthForFont;
331
+ const estimateTextAdvanceForBytes = support.estimateTextAdvanceForBytes;
332
+ const estimatedGlyphAdvance = support.estimatedGlyphAdvance;
333
+ const snapTextSelection = support.snapTextSelection;
334
+ const snapTextRange = support.snapTextRange;
335
+ const nextTextOffset = support.nextTextOffset;
336
+ const nextTextLineEnd = support.nextTextLineEnd;
337
+ const isTextBreakByte = support.isTextBreakByte;
338
+ const textLineRange = support.textLineRange;
339
+ const textLineCaretX = support.textLineCaretX;
340
+ const motionProgress = support.motionProgress;
341
+ const renderImageFingerprint = support.renderImageFingerprint;
342
+ const renderImageFingerprintForResource = support.renderImageFingerprintForResource;
343
+ const commandsEqual = support.commandsEqual;
344
+ const rectsEqual = support.rectsEqual;
345
+ const optionalRectsEqual = support.optionalRectsEqual;
346
+ const sizesEqual = support.sizesEqual;
347
+ const insetsEqual = support.insetsEqual;
348
+ const optionalColorsEqual = support.optionalColorsEqual;
349
+ const radiiEqual = support.radiiEqual;
350
+ const affinesEqual = support.affinesEqual;
351
+ const optionalF32Equal = support.optionalF32Equal;
352
+ const optionalTextSelectionsEqual = support.optionalTextSelectionsEqual;
353
+ const optionalTextRangesEqual = support.optionalTextRangesEqual;
354
+ const widgetPartId = support.widgetPartId;
355
+ const colorWithAlpha = support.colorWithAlpha;
356
+ const widgetControlHeight = support.widgetControlHeight;
357
+ const textSelectionFillColor = support.textSelectionFillColor;
358
+ const transparentColor = support.transparentColor;
359
+ const expectRect = support.expectRect;
360
+ const expectRectApprox = support.expectRectApprox;
361
+ const expectPixelRgba8 = support.expectPixelRgba8;
362
+ const expectVisiblePixel = support.expectVisiblePixel;
363
+ const referenceSurfaceSignature = support.referenceSurfaceSignature;
364
+ const expectLayoutFrame = support.expectLayoutFrame;
365
+ const expectRouteEntry = support.expectRouteEntry;
366
+ const expectFillColor = support.expectFillColor;
367
+ const expectGpuPaintColor = support.expectGpuPaintColor;
368
+
369
+ test "builder records replayable commands" {
370
+ var commands: [8]CanvasCommand = undefined;
371
+ var builder = Builder.init(&commands);
372
+
373
+ try builder.pushClip(.{ .id = 1, .rect = geometry.RectF.init(0, 0, 320, 240), .radius = Radius.all(8) });
374
+ try builder.pushOpacity(0.75);
375
+ try builder.fillRoundedRect(.{
376
+ .id = 2,
377
+ .rect = geometry.RectF.init(12, 16, 180, 96),
378
+ .radius = Radius.all(12),
379
+ .fill = .{ .color = Color.rgb8(17, 24, 39) },
380
+ });
381
+ try builder.popOpacity();
382
+ try builder.popClip();
383
+
384
+ const display_list = builder.displayList();
385
+ try std.testing.expectEqual(@as(usize, 5), display_list.commandCount());
386
+ try std.testing.expect(display_list.commands[0] == .push_clip);
387
+ try std.testing.expect(display_list.commands[2] == .fill_rounded_rect);
388
+ }
389
+
390
+ test "builder reports fixed buffer overflow" {
391
+ var commands: [1]CanvasCommand = undefined;
392
+ var builder = Builder.init(&commands);
393
+
394
+ try builder.pushOpacity(1);
395
+ try std.testing.expectError(error.DisplayListFull, builder.popOpacity());
396
+ }
397
+
398
+ test "display list finds commands and computes conservative bounds" {
399
+ const path = [_]PathElement{
400
+ .{ .verb = .move_to, .points = .{ geometry.PointF.init(5, 5), geometry.PointF.zero(), geometry.PointF.zero() } },
401
+ .{ .verb = .cubic_to, .points = .{ geometry.PointF.init(15, 30), geometry.PointF.init(20, 0), geometry.PointF.init(35, 35) } },
402
+ .{ .verb = .close },
403
+ };
404
+
405
+ var commands: [3]CanvasCommand = undefined;
406
+ var builder = Builder.init(&commands);
407
+ try builder.strokeRect(.{
408
+ .id = 1,
409
+ .rect = geometry.RectF.init(10, 10, 100, 40),
410
+ .stroke = .{ .fill = .{ .color = Color.rgb8(0, 0, 0) }, .width = 4 },
411
+ });
412
+ try builder.fillPath(.{
413
+ .id = 2,
414
+ .elements = &path,
415
+ .fill = .{ .color = Color.rgb8(255, 255, 255) },
416
+ });
417
+ try builder.shadow(.{
418
+ .id = 3,
419
+ .rect = geometry.RectF.init(20, 20, 40, 20),
420
+ .offset = .{ .dx = 0, .dy = 8 },
421
+ .blur = 12,
422
+ .spread = -4,
423
+ .color = Color.rgba8(0, 0, 0, 64),
424
+ });
425
+
426
+ const display_list = builder.displayList();
427
+ const path_ref = display_list.findCommandById(2).?;
428
+ try std.testing.expectEqual(@as(usize, 1), path_ref.index);
429
+ try std.testing.expectEqual(@as(?ObjectId, 2), path_ref.command.objectId());
430
+ try std.testing.expect(display_list.findCommandById(99) == null);
431
+
432
+ try expectRect(geometry.RectF.init(8, 8, 104, 44), display_list.commands[0].bounds());
433
+ try expectRect(geometry.RectF.init(5, 0, 30, 35), display_list.commands[1].bounds());
434
+ try expectRect(geometry.RectF.init(4, 12, 72, 52), display_list.commands[2].bounds());
435
+ try expectRect(geometry.RectF.init(4, 0, 108, 64), display_list.bounds());
436
+ }
437
+
438
+ test "display list diffs changed added removed and unkeyed scene commands" {
439
+ const previous_commands = [_]CanvasCommand{
440
+ .{ .push_opacity = 1 },
441
+ .{ .fill_rect = .{ .id = 1, .rect = geometry.RectF.init(0, 0, 100, 100), .fill = .{ .color = Color.rgb8(255, 255, 255) } } },
442
+ .{ .fill_rect = .{ .id = 2, .rect = geometry.RectF.init(120, 0, 40, 40), .fill = .{ .color = Color.rgb8(17, 24, 39) } } },
443
+ .{ .draw_image = .{ .id = 3, .image_id = 8, .dst = geometry.RectF.init(180, 0, 32, 32) } },
444
+ };
445
+ const next_commands = [_]CanvasCommand{
446
+ .{ .push_opacity = 0.5 },
447
+ .{ .fill_rect = .{ .id = 1, .rect = geometry.RectF.init(10, 0, 100, 100), .fill = .{ .color = Color.rgb8(255, 255, 255) } } },
448
+ .{ .fill_rect = .{ .id = 2, .rect = geometry.RectF.init(120, 0, 40, 40), .fill = .{ .color = Color.rgb8(17, 24, 39) } } },
449
+ .{ .blur = .{ .id = 4, .rect = geometry.RectF.init(220, 0, 24, 24), .radius = 6 } },
450
+ };
451
+
452
+ var changes: [8]DiffChange = undefined;
453
+ const diff = try DisplayList.diff(.{ .commands = &previous_commands }, .{ .commands = &next_commands }, &changes);
454
+ try std.testing.expectEqual(@as(usize, 4), diff.len);
455
+ try std.testing.expectEqual(DiffKind.scene_changed, diff[0].kind);
456
+ try std.testing.expectEqual(@as(?ObjectId, null), diff[0].id);
457
+ try std.testing.expect(diff[0].dirty_bounds != null);
458
+ try std.testing.expectEqual(DiffKind.changed, diff[1].kind);
459
+ try std.testing.expectEqual(@as(?ObjectId, 1), diff[1].id);
460
+ try std.testing.expectEqual(@as(?usize, 1), diff[1].previous_index);
461
+ try std.testing.expectEqual(@as(?usize, 1), diff[1].next_index);
462
+ try expectRect(geometry.RectF.init(0, 0, 110, 100), diff[1].dirty_bounds);
463
+ try std.testing.expectEqual(DiffKind.removed, diff[2].kind);
464
+ try std.testing.expectEqual(@as(?ObjectId, 3), diff[2].id);
465
+ try expectRect(geometry.RectF.init(180, 0, 32, 32), diff[2].dirty_bounds);
466
+ try std.testing.expectEqual(DiffKind.added, diff[3].kind);
467
+ try std.testing.expectEqual(@as(?ObjectId, 4), diff[3].id);
468
+ try expectRect(geometry.RectF.init(214, -6, 36, 36), diff[3].dirty_bounds);
469
+ }
470
+
471
+ test "display list diff treats empty transitions as full scene changes" {
472
+ const commands = [_]CanvasCommand{.{ .draw_text = .{
473
+ .id = 1,
474
+ .origin = geometry.PointF.init(0, 16),
475
+ .size = 13,
476
+ .color = Color.rgb8(255, 255, 255),
477
+ .text = "Initial retained canvas install",
478
+ .text_layout = .{ .max_width = 140, .line_height = 18, .wrap = .word },
479
+ } }};
480
+
481
+ var changes: [2]DiffChange = undefined;
482
+ const added = try DisplayList.diff(.{}, .{ .commands = &commands }, &changes);
483
+ try std.testing.expectEqual(@as(usize, 1), added.len);
484
+ try std.testing.expectEqual(DiffKind.scene_changed, added[0].kind);
485
+ try std.testing.expectEqual(@as(?ObjectId, null), added[0].id);
486
+ try std.testing.expectEqual(@as(?geometry.RectF, null), added[0].dirty_bounds);
487
+
488
+ const removed = try DisplayList.diff(.{ .commands = &commands }, .{}, &changes);
489
+ try std.testing.expectEqual(@as(usize, 1), removed.len);
490
+ try std.testing.expectEqual(DiffKind.scene_changed, removed[0].kind);
491
+ try std.testing.expectEqual(@as(?ObjectId, null), removed[0].id);
492
+ try std.testing.expectEqual(@as(?geometry.RectF, null), removed[0].dirty_bounds);
493
+ }
494
+
495
+ test "display list diff ignores unchanged keyed commands" {
496
+ const commands = [_]CanvasCommand{
497
+ .{ .fill_rounded_rect = .{
498
+ .id = 1,
499
+ .rect = geometry.RectF.init(8, 8, 120, 40),
500
+ .radius = Radius.all(10),
501
+ .fill = .{ .color = Color.rgb8(15, 23, 42) },
502
+ } },
503
+ };
504
+
505
+ var changes: [1]DiffChange = undefined;
506
+ const diff = try DisplayList.diff(.{ .commands = &commands }, .{ .commands = &commands }, &changes);
507
+ try std.testing.expectEqual(@as(usize, 0), diff.len);
508
+ }
509
+
510
+ test "display list diff rejects duplicate object ids" {
511
+ const commands = [_]CanvasCommand{
512
+ .{ .fill_rect = .{ .id = 1, .rect = geometry.RectF.init(0, 0, 10, 10), .fill = .{ .color = Color.rgb8(255, 255, 255) } } },
513
+ .{ .blur = .{ .id = 1, .rect = geometry.RectF.init(0, 0, 10, 10), .radius = 4 } },
514
+ };
515
+
516
+ var changes: [2]DiffChange = undefined;
517
+ try std.testing.expectError(error.DuplicateObjectId, DisplayList.diff(.{ .commands = &commands }, .{}, &changes));
518
+ }
519
+
520
+ test "affine transforms points and conservative rect bounds" {
521
+ const transform = Affine.translate(10, 5).multiply(Affine.scale(2, 3));
522
+ try std.testing.expectEqualDeep(geometry.PointF.init(14, 14), transform.transformPoint(geometry.PointF.init(2, 3)));
523
+ try std.testing.expectEqualDeep(geometry.RectF.init(10, 5, 20, 15), transform.transformRect(geometry.RectF.init(0, 0, 10, 5)));
524
+ const inverse = transform.inverse().?;
525
+ const restored = inverse.transformPoint(geometry.PointF.init(14, 14));
526
+ try std.testing.expectApproxEqAbs(@as(f32, 2), restored.x, 0.00001);
527
+ try std.testing.expectApproxEqAbs(@as(f32, 3), restored.y, 0.00001);
528
+ try std.testing.expect(Affine.scale(0, 1).inverse() == null);
529
+ }
530
+
531
+ test "render plan resolves transform clip and opacity state" {
532
+ const commands = [_]CanvasCommand{
533
+ .{ .push_clip = .{ .id = 90, .rect = geometry.RectF.init(10, 10, 50, 50) } },
534
+ .{ .push_opacity = 0.5 },
535
+ .{ .transform = Affine.translate(10, 0) },
536
+ .{ .fill_rect = .{ .id = 1, .rect = geometry.RectF.init(0, 0, 30, 30), .fill = .{ .color = Color.rgb8(255, 255, 255) } } },
537
+ .pop_opacity,
538
+ .{ .fill_rect = .{ .id = 2, .rect = geometry.RectF.init(0, 0, 4, 4), .fill = .{ .color = Color.rgb8(0, 0, 0) } } },
539
+ .pop_clip,
540
+ .{ .fill_rect = .{ .id = 3, .rect = geometry.RectF.init(0, 0, 4, 4), .fill = .{ .color = Color.rgb8(17, 24, 39) } } },
541
+ };
542
+
543
+ var render_commands: [4]RenderCommand = undefined;
544
+ const plan = try (DisplayList{ .commands = &commands }).renderPlan(&render_commands);
545
+ try std.testing.expectEqual(@as(usize, 2), plan.commandCount());
546
+
547
+ try std.testing.expectEqual(@as(?ObjectId, 1), plan.commands[0].id);
548
+ try std.testing.expectEqual(@as(f32, 0.5), plan.commands[0].opacity);
549
+ try expectRect(geometry.RectF.init(10, 10, 50, 50), plan.commands[0].clip);
550
+ try std.testing.expectEqualDeep(Affine.translate(10, 0), plan.commands[0].transform);
551
+ try expectRect(geometry.RectF.init(0, 0, 30, 30), plan.commands[0].local_bounds);
552
+ try std.testing.expectEqualDeep(geometry.RectF.init(10, 10, 30, 20), plan.commands[0].bounds);
553
+
554
+ try std.testing.expectEqual(@as(?ObjectId, 3), plan.commands[1].id);
555
+ try std.testing.expectEqual(@as(f32, 1), plan.commands[1].opacity);
556
+ try std.testing.expect(plan.commands[1].clip == null);
557
+ try std.testing.expectEqualDeep(Affine.translate(10, 0), plan.commands[1].transform);
558
+ try expectRect(geometry.RectF.init(0, 0, 4, 4), plan.commands[1].local_bounds);
559
+ try std.testing.expectEqualDeep(geometry.RectF.init(10, 0, 4, 4), plan.commands[1].bounds);
560
+ try expectRect(geometry.RectF.init(10, 0, 30, 30), plan.bounds);
561
+ }
562
+
563
+ test "render plan reports output and stack errors" {
564
+ const draw_commands = [_]CanvasCommand{
565
+ .{ .fill_rect = .{ .id = 1, .rect = geometry.RectF.init(0, 0, 10, 10), .fill = .{ .color = Color.rgb8(255, 255, 255) } } },
566
+ };
567
+ var empty_render_commands: [0]RenderCommand = .{};
568
+ try std.testing.expectError(error.RenderListFull, (DisplayList{ .commands = &draw_commands }).renderPlan(&empty_render_commands));
569
+
570
+ const bad_clip_commands = [_]CanvasCommand{.pop_clip};
571
+ var render_commands: [1]RenderCommand = undefined;
572
+ try std.testing.expectError(error.RenderStackUnderflow, (DisplayList{ .commands = &bad_clip_commands }).renderPlan(&render_commands));
573
+
574
+ const bad_opacity_commands = [_]CanvasCommand{.pop_opacity};
575
+ try std.testing.expectError(error.RenderStackUnderflow, (DisplayList{ .commands = &bad_opacity_commands }).renderPlan(&render_commands));
576
+ }
577
+
578
+ test "render batch plan groups adjacent commands by pipeline and state" {
579
+ const stops = [_]GradientStop{
580
+ .{ .offset = 0, .color = Color.rgb8(255, 255, 255) },
581
+ .{ .offset = 1, .color = Color.rgb8(24, 24, 27) },
582
+ };
583
+ const commands = [_]CanvasCommand{
584
+ .{ .fill_rect = .{ .id = 1, .rect = geometry.RectF.init(0, 0, 20, 20), .fill = .{ .color = Color.rgb8(255, 255, 255) } } },
585
+ .{ .fill_rounded_rect = .{ .id = 2, .rect = geometry.RectF.init(24, 0, 20, 20), .radius = Radius.all(4), .fill = .{ .color = Color.rgb8(24, 24, 27) } } },
586
+ .{ .fill_rect = .{ .id = 3, .rect = geometry.RectF.init(48, 0, 20, 20), .fill = .{ .linear_gradient = .{
587
+ .start = geometry.PointF.init(48, 0),
588
+ .end = geometry.PointF.init(68, 20),
589
+ .stops = &stops,
590
+ } } } },
591
+ .{ .draw_text = .{
592
+ .id = 4,
593
+ .font_id = 1,
594
+ .size = 12,
595
+ .origin = geometry.PointF.init(72, 18),
596
+ .color = Color.rgb8(15, 23, 42),
597
+ .text = "Hi",
598
+ } },
599
+ };
600
+
601
+ var render_commands: [4]RenderCommand = undefined;
602
+ const render_plan = try (DisplayList{ .commands = &commands }).renderPlan(&render_commands);
603
+ var batches: [4]RenderBatch = undefined;
604
+ const batch_plan = try render_plan.batchPlan(&batches);
605
+
606
+ try std.testing.expectEqual(@as(usize, 3), batch_plan.batchCount());
607
+ try std.testing.expectEqual(RenderPipelineKind.solid, batch_plan.batches[0].pipeline);
608
+ try std.testing.expectEqual(@as(usize, 0), batch_plan.batches[0].command_start);
609
+ try std.testing.expectEqual(@as(usize, 2), batch_plan.batches[0].command_count);
610
+ try expectRect(geometry.RectF.init(0, 0, 44, 20), batch_plan.batches[0].bounds);
611
+ try std.testing.expectEqual(RenderPipelineKind.linear_gradient, batch_plan.batches[1].pipeline);
612
+ try std.testing.expectEqual(@as(usize, 2), batch_plan.batches[1].command_start);
613
+ try std.testing.expectEqual(RenderPipelineKind.glyph_run, batch_plan.batches[2].pipeline);
614
+ try std.testing.expectEqual(@as(usize, 3), batch_plan.batches[2].command_start);
615
+ // Text command bounds carry the ink allowance (right 0.35em,
616
+ // bottom/left 0.1em) past the metric box.
617
+ try expectRectApprox(geometry.RectF.init(0, 0, 87.684, 22.2), batch_plan.bounds);
618
+ }
619
+
620
+ test "render batch plan respects clip opacity and output limits" {
621
+ const commands = [_]CanvasCommand{
622
+ .{ .push_opacity = 0.5 },
623
+ .{ .fill_rect = .{ .id = 1, .rect = geometry.RectF.init(0, 0, 20, 20), .fill = .{ .color = Color.rgb8(255, 255, 255) } } },
624
+ .pop_opacity,
625
+ .{ .fill_rect = .{ .id = 2, .rect = geometry.RectF.init(24, 0, 20, 20), .fill = .{ .color = Color.rgb8(24, 24, 27) } } },
626
+ .{ .push_clip = .{ .rect = geometry.RectF.init(48, 0, 20, 20) } },
627
+ .{ .fill_rect = .{ .id = 3, .rect = geometry.RectF.init(48, 0, 20, 20), .fill = .{ .color = Color.rgb8(15, 23, 42) } } },
628
+ .pop_clip,
629
+ };
630
+
631
+ var render_commands: [3]RenderCommand = undefined;
632
+ const render_plan = try (DisplayList{ .commands = &commands }).renderPlan(&render_commands);
633
+ var batches: [3]RenderBatch = undefined;
634
+ const batch_plan = try render_plan.batchPlan(&batches);
635
+
636
+ try std.testing.expectEqual(@as(usize, 3), batch_plan.batchCount());
637
+ try std.testing.expectEqual(@as(f32, 0.5), batch_plan.batches[0].opacity);
638
+ try std.testing.expect(batch_plan.batches[0].clip == null);
639
+ try std.testing.expectEqual(@as(f32, 1), batch_plan.batches[1].opacity);
640
+ try std.testing.expect(batch_plan.batches[1].clip == null);
641
+ try expectRect(geometry.RectF.init(48, 0, 20, 20), batch_plan.batches[2].clip);
642
+
643
+ var empty_batches: [0]RenderBatch = .{};
644
+ try std.testing.expectError(error.RenderBatchListFull, render_plan.batchPlan(&empty_batches));
645
+ }
646
+
647
+ test "render path geometry plan estimates fill and stroke tessellation" {
648
+ const path = [_]PathElement{
649
+ .{ .verb = .move_to, .points = .{ geometry.PointF.init(0, 0), geometry.PointF.zero(), geometry.PointF.zero() } },
650
+ .{ .verb = .line_to, .points = .{ geometry.PointF.init(20, 0), geometry.PointF.zero(), geometry.PointF.zero() } },
651
+ .{ .verb = .quad_to, .points = .{ geometry.PointF.init(24, 16), geometry.PointF.init(12, 22), geometry.PointF.zero() } },
652
+ .{ .verb = .cubic_to, .points = .{ geometry.PointF.init(8, 26), geometry.PointF.init(-4, 18), geometry.PointF.init(0, 0) } },
653
+ .{ .verb = .close },
654
+ };
655
+ const commands = [_]CanvasCommand{
656
+ .{ .fill_path = .{
657
+ .id = 1,
658
+ .elements = &path,
659
+ .fill = .{ .color = Color.rgb8(255, 255, 255) },
660
+ } },
661
+ .{ .transform = Affine.scale(2, 2) },
662
+ .{ .stroke_path = .{
663
+ .id = 2,
664
+ .elements = &path,
665
+ .stroke = .{ .fill = .{ .color = Color.rgb8(24, 24, 27) }, .width = 2 },
666
+ } },
667
+ };
668
+
669
+ var render_commands: [2]RenderCommand = undefined;
670
+ const render_plan = try (DisplayList{ .commands = &commands }).renderPlan(&render_commands);
671
+ var geometries: [2]RenderPathGeometry = undefined;
672
+ const geometry_plan = try render_plan.pathGeometryPlan(&geometries);
673
+
674
+ try std.testing.expectEqual(@as(usize, 2), geometry_plan.geometryCount());
675
+ try std.testing.expectEqual(@as(usize, 130), geometry_plan.vertexCount());
676
+ try std.testing.expectEqual(@as(usize, 228), geometry_plan.indexCount());
677
+
678
+ try std.testing.expectEqual(RenderPathGeometryKind.fill, geometry_plan.geometries[0].kind);
679
+ try std.testing.expectEqual(@as(?ObjectId, 1), geometry_plan.geometries[0].id);
680
+ try std.testing.expectEqual(@as(usize, 0), geometry_plan.geometries[0].command_index);
681
+ try std.testing.expectEqual(@as(usize, 5), geometry_plan.geometries[0].element_count);
682
+ try std.testing.expectEqual(@as(usize, 1), geometry_plan.geometries[0].contour_count);
683
+ try std.testing.expectEqual(@as(usize, 2), geometry_plan.geometries[0].line_segment_count);
684
+ try std.testing.expectEqual(@as(usize, 1), geometry_plan.geometries[0].quadratic_segment_count);
685
+ try std.testing.expectEqual(@as(usize, 1), geometry_plan.geometries[0].cubic_segment_count);
686
+ try std.testing.expectEqual(@as(usize, 26), geometry_plan.geometries[0].flattened_segment_count);
687
+ try std.testing.expectEqual(@as(usize, 26), geometry_plan.geometries[0].vertex_count);
688
+ try std.testing.expectEqual(@as(usize, 72), geometry_plan.geometries[0].index_count);
689
+ try std.testing.expectEqual(@as(f32, 0), geometry_plan.geometries[0].stroke_width);
690
+
691
+ try std.testing.expectEqual(RenderPathGeometryKind.stroke, geometry_plan.geometries[1].kind);
692
+ try std.testing.expectEqual(@as(?ObjectId, 2), geometry_plan.geometries[1].id);
693
+ try std.testing.expectEqual(@as(usize, 1), geometry_plan.geometries[1].command_index);
694
+ try std.testing.expectEqual(@as(usize, 26), geometry_plan.geometries[1].flattened_segment_count);
695
+ try std.testing.expectEqual(@as(usize, 104), geometry_plan.geometries[1].vertex_count);
696
+ try std.testing.expectEqual(@as(usize, 156), geometry_plan.geometries[1].index_count);
697
+ try std.testing.expectEqual(@as(f32, 4), geometry_plan.geometries[1].stroke_width);
698
+ try expectRect(geometry.RectF.init(-4, 0, 28, 26), geometry_plan.geometries[0].bounds);
699
+ try expectRect(geometry.RectF.init(-10, -2, 60, 56), geometry_plan.geometries[1].bounds);
700
+ }
701
+
702
+ test "render path geometry fingerprint tracks geometry not paint" {
703
+ const path = [_]PathElement{
704
+ .{ .verb = .move_to, .points = .{ geometry.PointF.init(0, 0), geometry.PointF.zero(), geometry.PointF.zero() } },
705
+ .{ .verb = .line_to, .points = .{ geometry.PointF.init(20, 0), geometry.PointF.zero(), geometry.PointF.zero() } },
706
+ .{ .verb = .line_to, .points = .{ geometry.PointF.init(0, 20), geometry.PointF.zero(), geometry.PointF.zero() } },
707
+ .{ .verb = .close },
708
+ };
709
+ const changed_path = [_]PathElement{
710
+ .{ .verb = .move_to, .points = .{ geometry.PointF.init(0, 0), geometry.PointF.zero(), geometry.PointF.zero() } },
711
+ .{ .verb = .line_to, .points = .{ geometry.PointF.init(24, 0), geometry.PointF.zero(), geometry.PointF.zero() } },
712
+ .{ .verb = .line_to, .points = .{ geometry.PointF.init(0, 20), geometry.PointF.zero(), geometry.PointF.zero() } },
713
+ .{ .verb = .close },
714
+ };
715
+ const commands = [_]CanvasCommand{.{ .fill_path = .{
716
+ .id = 9,
717
+ .elements = &path,
718
+ .fill = .{ .color = Color.rgb8(255, 255, 255) },
719
+ } }};
720
+ const recolored_commands = [_]CanvasCommand{.{ .fill_path = .{
721
+ .id = 9,
722
+ .elements = &path,
723
+ .fill = .{ .color = Color.rgb8(255, 0, 0) },
724
+ } }};
725
+ const reshaped_commands = [_]CanvasCommand{.{ .fill_path = .{
726
+ .id = 9,
727
+ .elements = &changed_path,
728
+ .fill = .{ .color = Color.rgb8(255, 255, 255) },
729
+ } }};
730
+
731
+ var render_commands: [1]RenderCommand = undefined;
732
+ const render_plan = try (DisplayList{ .commands = &commands }).renderPlan(&render_commands);
733
+ var geometries: [1]RenderPathGeometry = undefined;
734
+ const geometry_plan = try render_plan.pathGeometryPlan(&geometries);
735
+
736
+ var recolored_render_commands: [1]RenderCommand = undefined;
737
+ const recolored_render_plan = try (DisplayList{ .commands = &recolored_commands }).renderPlan(&recolored_render_commands);
738
+ var recolored_geometries: [1]RenderPathGeometry = undefined;
739
+ const recolored_geometry_plan = try recolored_render_plan.pathGeometryPlan(&recolored_geometries);
740
+
741
+ var reshaped_render_commands: [1]RenderCommand = undefined;
742
+ const reshaped_render_plan = try (DisplayList{ .commands = &reshaped_commands }).renderPlan(&reshaped_render_commands);
743
+ var reshaped_geometries: [1]RenderPathGeometry = undefined;
744
+ const reshaped_geometry_plan = try reshaped_render_plan.pathGeometryPlan(&reshaped_geometries);
745
+
746
+ try std.testing.expectEqual(geometry_plan.geometries[0].fingerprint, recolored_geometry_plan.geometries[0].fingerprint);
747
+ try std.testing.expect(geometry_plan.geometries[0].fingerprint != reshaped_geometry_plan.geometries[0].fingerprint);
748
+ }
749
+
750
+ test "render path geometry cache plan uploads retains and evicts geometries" {
751
+ const previous_geometries = [_]RenderPathGeometry{
752
+ .{ .kind = .fill, .command_index = 0, .id = 1, .bounds = geometry.RectF.init(0, 0, 20, 20), .vertex_count = 3, .index_count = 3, .fingerprint = 11 },
753
+ .{ .kind = .stroke, .command_index = 1, .id = 2, .bounds = geometry.RectF.init(24, 0, 20, 20), .vertex_count = 4, .index_count = 6, .stroke_width = 2, .fingerprint = 22 },
754
+ };
755
+ var previous_entries: [2]RenderPathGeometryCacheEntry = undefined;
756
+ var previous_actions: [2]RenderPathGeometryCacheAction = undefined;
757
+ const previous_cache = try (RenderPathGeometryPlan{ .geometries = &previous_geometries }).cachePlan(&.{}, 1, &previous_entries, &previous_actions);
758
+ try std.testing.expectEqual(@as(usize, 2), previous_cache.entryCount());
759
+ try std.testing.expectEqual(@as(usize, 2), previous_cache.uploadCount());
760
+
761
+ const next_geometries = [_]RenderPathGeometry{
762
+ .{ .kind = .fill, .command_index = 0, .id = 1, .bounds = geometry.RectF.init(0, 0, 20, 20), .vertex_count = 3, .index_count = 3, .fingerprint = 11 },
763
+ .{ .kind = .stroke, .command_index = 1, .id = 3, .bounds = geometry.RectF.init(48, 0, 20, 20), .vertex_count = 8, .index_count = 12, .stroke_width = 4, .fingerprint = 33 },
764
+ };
765
+ var next_entries: [2]RenderPathGeometryCacheEntry = undefined;
766
+ var next_actions: [3]RenderPathGeometryCacheAction = undefined;
767
+ const next_cache = try (RenderPathGeometryPlan{ .geometries = &next_geometries }).cachePlan(previous_cache.entries, 2, &next_entries, &next_actions);
768
+ try std.testing.expectEqual(@as(usize, 2), next_cache.entryCount());
769
+ try std.testing.expectEqual(@as(usize, 1), next_cache.retainCount());
770
+ try std.testing.expectEqual(@as(usize, 1), next_cache.uploadCount());
771
+ try std.testing.expectEqual(@as(usize, 1), next_cache.evictCount());
772
+ try std.testing.expectEqual(RenderPathGeometryCacheActionKind.retain, next_cache.actions[0].kind);
773
+ try std.testing.expectEqual(@as(?ObjectId, 1), next_cache.actions[0].key.id);
774
+ try std.testing.expectEqual(RenderPathGeometryCacheActionKind.upload, next_cache.actions[1].kind);
775
+ try std.testing.expectEqual(@as(?ObjectId, 3), next_cache.actions[1].key.id);
776
+ try std.testing.expectEqual(RenderPathGeometryCacheActionKind.evict, next_cache.actions[2].kind);
777
+ try std.testing.expectEqual(@as(?ObjectId, 2), next_cache.actions[2].key.id);
778
+ }
779
+
780
+ test "render path geometry plans report output overflow" {
781
+ const path = [_]PathElement{
782
+ .{ .verb = .move_to, .points = .{ geometry.PointF.init(0, 0), geometry.PointF.zero(), geometry.PointF.zero() } },
783
+ .{ .verb = .line_to, .points = .{ geometry.PointF.init(20, 0), geometry.PointF.zero(), geometry.PointF.zero() } },
784
+ .{ .verb = .line_to, .points = .{ geometry.PointF.init(0, 20), geometry.PointF.zero(), geometry.PointF.zero() } },
785
+ .{ .verb = .close },
786
+ };
787
+ const commands = [_]CanvasCommand{.{ .fill_path = .{
788
+ .id = 1,
789
+ .elements = &path,
790
+ .fill = .{ .color = Color.rgb8(255, 255, 255) },
791
+ } }};
792
+
793
+ var render_commands: [1]RenderCommand = undefined;
794
+ const render_plan = try (DisplayList{ .commands = &commands }).renderPlan(&render_commands);
795
+ var no_geometries: [0]RenderPathGeometry = .{};
796
+ try std.testing.expectError(error.PathGeometryListFull, render_plan.pathGeometryPlan(&no_geometries));
797
+
798
+ const geometries = [_]RenderPathGeometry{.{ .kind = .fill, .command_index = 0, .id = 1, .bounds = geometry.RectF.init(0, 0, 20, 20), .vertex_count = 3, .index_count = 3, .fingerprint = 11 }};
799
+ var no_entries: [0]RenderPathGeometryCacheEntry = .{};
800
+ var actions: [1]RenderPathGeometryCacheAction = undefined;
801
+ try std.testing.expectError(error.PathGeometryCacheListFull, (RenderPathGeometryPlan{ .geometries = &geometries }).cachePlan(&.{}, 1, &no_entries, &actions));
802
+
803
+ var entries: [1]RenderPathGeometryCacheEntry = undefined;
804
+ var no_actions: [0]RenderPathGeometryCacheAction = .{};
805
+ try std.testing.expectError(error.PathGeometryCacheListFull, (RenderPathGeometryPlan{ .geometries = &geometries }).cachePlan(&.{}, 1, &entries, &no_actions));
806
+ }
807
+
808
+ test "render layer plan groups composited commands by state" {
809
+ const commands = [_]CanvasCommand{
810
+ .{ .push_opacity = 0.5 },
811
+ .{ .fill_rect = .{ .id = 1, .rect = geometry.RectF.init(0, 0, 20, 20), .fill = .{ .color = Color.rgb8(255, 255, 255) } } },
812
+ .{ .fill_rect = .{ .id = 2, .rect = geometry.RectF.init(24, 0, 20, 20), .fill = .{ .color = Color.rgb8(24, 24, 27) } } },
813
+ .pop_opacity,
814
+ .{ .push_clip = .{ .rect = geometry.RectF.init(48, 0, 20, 20) } },
815
+ .{ .fill_rect = .{ .id = 3, .rect = geometry.RectF.init(48, 0, 20, 20), .fill = .{ .color = Color.rgb8(15, 23, 42) } } },
816
+ .pop_clip,
817
+ .{ .transform = Affine.translate(10, 0) },
818
+ .{ .fill_rect = .{ .id = 4, .rect = geometry.RectF.init(72, 0, 20, 20), .fill = .{ .color = Color.rgb8(37, 99, 235) } } },
819
+ };
820
+
821
+ var render_commands: [4]RenderCommand = undefined;
822
+ const render_plan = try (DisplayList{ .commands = &commands }).renderPlan(&render_commands);
823
+ var layers: [3]RenderLayer = undefined;
824
+ const layer_plan = try render_plan.layerPlan(&layers);
825
+
826
+ try std.testing.expectEqual(@as(usize, 3), layer_plan.layerCount());
827
+ try std.testing.expectEqual(@as(usize, 1), layer_plan.opacityLayerCount());
828
+ try std.testing.expectEqual(@as(usize, 1), layer_plan.clipLayerCount());
829
+ try std.testing.expectEqual(@as(usize, 1), layer_plan.transformLayerCount());
830
+ try std.testing.expectEqual(@as(usize, 0), layer_plan.layers[0].command_start);
831
+ try std.testing.expectEqual(@as(usize, 2), layer_plan.layers[0].command_count);
832
+ try std.testing.expect(layer_plan.layers[0].id == null);
833
+ try std.testing.expectEqual(@as(f32, 0.5), layer_plan.layers[0].opacity);
834
+ try expectRect(geometry.RectF.init(0, 0, 44, 20), layer_plan.layers[0].bounds);
835
+ try std.testing.expectEqual(@as(?ObjectId, 3), layer_plan.layers[1].id);
836
+ try expectRect(geometry.RectF.init(48, 0, 20, 20), layer_plan.layers[1].clip);
837
+ try std.testing.expectEqual(@as(?ObjectId, 4), layer_plan.layers[2].id);
838
+ try std.testing.expectEqualDeep(Affine.translate(10, 0), layer_plan.layers[2].transform);
839
+ try expectRect(geometry.RectF.init(82, 0, 20, 20), layer_plan.layers[2].bounds);
840
+
841
+ const changed_commands = [_]CanvasCommand{
842
+ .{ .push_opacity = 0.5 },
843
+ .{ .fill_rect = .{ .id = 1, .rect = geometry.RectF.init(0, 0, 20, 20), .fill = .{ .color = Color.rgb8(255, 0, 0) } } },
844
+ .{ .fill_rect = .{ .id = 2, .rect = geometry.RectF.init(24, 0, 20, 20), .fill = .{ .color = Color.rgb8(24, 24, 27) } } },
845
+ .pop_opacity,
846
+ };
847
+ var changed_render_commands: [2]RenderCommand = undefined;
848
+ const changed_render_plan = try (DisplayList{ .commands = &changed_commands }).renderPlan(&changed_render_commands);
849
+ var changed_layers: [1]RenderLayer = undefined;
850
+ const changed_layer_plan = try changed_render_plan.layerPlan(&changed_layers);
851
+ try std.testing.expect(layer_plan.layers[0].fingerprint != changed_layer_plan.layers[0].fingerprint);
852
+ }
853
+
854
+ test "render layer cache plan uploads retains and evicts layers" {
855
+ const previous_layers = [_]RenderLayer{
856
+ .{ .command_start = 0, .command_count = 1, .id = 1, .bounds = geometry.RectF.init(0, 0, 20, 20), .opacity = 0.5, .fingerprint = 11 },
857
+ .{ .command_start = 1, .command_count = 1, .id = 2, .bounds = geometry.RectF.init(24, 0, 20, 20), .clip = geometry.RectF.init(24, 0, 20, 20), .fingerprint = 22 },
858
+ };
859
+ var previous_entries: [2]RenderLayerCacheEntry = undefined;
860
+ var previous_actions: [2]RenderLayerCacheAction = undefined;
861
+ const previous_cache = try (RenderLayerPlan{ .layers = &previous_layers }).cachePlan(&.{}, 1, &previous_entries, &previous_actions);
862
+ try std.testing.expectEqual(@as(usize, 2), previous_cache.entryCount());
863
+ try std.testing.expectEqual(@as(usize, 2), previous_cache.uploadCount());
864
+
865
+ const next_layers = [_]RenderLayer{
866
+ .{ .command_start = 0, .command_count = 1, .id = 1, .bounds = geometry.RectF.init(0, 0, 20, 20), .opacity = 0.5, .fingerprint = 11 },
867
+ .{ .command_start = 1, .command_count = 1, .id = 3, .bounds = geometry.RectF.init(48, 0, 20, 20), .transform = Affine.translate(10, 0), .fingerprint = 33 },
868
+ };
869
+ var next_entries: [2]RenderLayerCacheEntry = undefined;
870
+ var next_actions: [3]RenderLayerCacheAction = undefined;
871
+ const next_cache = try (RenderLayerPlan{ .layers = &next_layers }).cachePlan(previous_cache.entries, 2, &next_entries, &next_actions);
872
+ try std.testing.expectEqual(@as(usize, 2), next_cache.entryCount());
873
+ try std.testing.expectEqual(@as(usize, 1), next_cache.retainCount());
874
+ try std.testing.expectEqual(@as(usize, 1), next_cache.uploadCount());
875
+ try std.testing.expectEqual(@as(usize, 1), next_cache.evictCount());
876
+ try std.testing.expectEqual(RenderLayerCacheActionKind.retain, next_cache.actions[0].kind);
877
+ try std.testing.expectEqual(@as(?ObjectId, 1), next_cache.actions[0].key.id);
878
+ try std.testing.expectEqual(RenderLayerCacheActionKind.upload, next_cache.actions[1].kind);
879
+ try std.testing.expectEqual(@as(?ObjectId, 3), next_cache.actions[1].key.id);
880
+ try std.testing.expectEqual(RenderLayerCacheActionKind.evict, next_cache.actions[2].kind);
881
+ try std.testing.expectEqual(@as(?ObjectId, 2), next_cache.actions[2].key.id);
882
+ }
883
+
884
+ test "render layer plans report output overflow" {
885
+ const commands = [_]CanvasCommand{
886
+ .{ .push_opacity = 0.5 },
887
+ .{ .fill_rect = .{ .id = 1, .rect = geometry.RectF.init(0, 0, 20, 20), .fill = .{ .color = Color.rgb8(255, 255, 255) } } },
888
+ .pop_opacity,
889
+ };
890
+ var render_commands: [1]RenderCommand = undefined;
891
+ const render_plan = try (DisplayList{ .commands = &commands }).renderPlan(&render_commands);
892
+ var no_layers: [0]RenderLayer = .{};
893
+ try std.testing.expectError(error.LayerListFull, render_plan.layerPlan(&no_layers));
894
+
895
+ const layers = [_]RenderLayer{.{ .command_start = 0, .command_count = 1, .id = 1, .bounds = geometry.RectF.init(0, 0, 20, 20), .opacity = 0.5, .fingerprint = 11 }};
896
+ var no_entries: [0]RenderLayerCacheEntry = .{};
897
+ var actions: [1]RenderLayerCacheAction = undefined;
898
+ try std.testing.expectError(error.LayerCacheListFull, (RenderLayerPlan{ .layers = &layers }).cachePlan(&.{}, 1, &no_entries, &actions));
899
+
900
+ var entries: [1]RenderLayerCacheEntry = undefined;
901
+ var no_actions: [0]RenderLayerCacheAction = .{};
902
+ try std.testing.expectError(error.LayerCacheListFull, (RenderLayerPlan{ .layers = &layers }).cachePlan(&.{}, 1, &entries, &no_actions));
903
+ }
904
+
905
+ test "render pipeline cache plan uploads retains and evicts pipelines" {
906
+ const first_batches = [_]RenderBatch{
907
+ .{ .pipeline = .solid, .command_start = 0, .command_count = 1 },
908
+ .{ .pipeline = .linear_gradient, .command_start = 1, .command_count = 1 },
909
+ .{ .pipeline = .solid, .command_start = 2, .command_count = 1 },
910
+ };
911
+ var first_entries: [2]RenderPipelineCacheEntry = undefined;
912
+ var first_actions: [2]RenderPipelineCacheAction = undefined;
913
+ const first_cache = try (RenderBatchPlan{ .batches = &first_batches }).cachePlan(&.{}, 1, &first_entries, &first_actions);
914
+
915
+ try std.testing.expectEqual(@as(usize, 2), first_cache.entryCount());
916
+ try std.testing.expectEqual(@as(usize, 2), first_cache.actionCount());
917
+ try std.testing.expectEqual(@as(usize, 2), first_cache.uploadCount());
918
+ try std.testing.expectEqual(RenderPipelineKind.solid, first_cache.entries[0].pipeline);
919
+ try std.testing.expectEqual(RenderPipelineKind.linear_gradient, first_cache.entries[1].pipeline);
920
+ try std.testing.expectEqual(@as(u64, 1), first_cache.entries[0].last_used_frame);
921
+
922
+ const second_batches = [_]RenderBatch{
923
+ .{ .pipeline = .linear_gradient, .command_start = 0, .command_count = 1 },
924
+ .{ .pipeline = .glyph_run, .command_start = 1, .command_count = 1 },
925
+ };
926
+ var second_entries: [2]RenderPipelineCacheEntry = undefined;
927
+ var second_actions: [3]RenderPipelineCacheAction = undefined;
928
+ const second_cache = try (RenderBatchPlan{ .batches = &second_batches }).cachePlan(first_cache.entries, 2, &second_entries, &second_actions);
929
+
930
+ try std.testing.expectEqual(@as(usize, 2), second_cache.entryCount());
931
+ try std.testing.expectEqual(@as(usize, 3), second_cache.actionCount());
932
+ try std.testing.expectEqual(@as(usize, 1), second_cache.uploadCount());
933
+ try std.testing.expectEqual(@as(usize, 1), second_cache.retainCount());
934
+ try std.testing.expectEqual(@as(usize, 1), second_cache.evictCount());
935
+ try std.testing.expectEqual(RenderPipelineCacheActionKind.retain, second_cache.actions[0].kind);
936
+ try std.testing.expectEqual(RenderPipelineKind.linear_gradient, second_cache.actions[0].pipeline);
937
+ try std.testing.expectEqual(@as(usize, 0), second_cache.actions[0].batch_index.?);
938
+ try std.testing.expectEqual(@as(usize, 1), second_cache.actions[0].cache_index.?);
939
+ try std.testing.expectEqual(RenderPipelineCacheActionKind.upload, second_cache.actions[1].kind);
940
+ try std.testing.expectEqual(RenderPipelineKind.glyph_run, second_cache.actions[1].pipeline);
941
+ try std.testing.expectEqual(RenderPipelineCacheActionKind.evict, second_cache.actions[2].kind);
942
+ try std.testing.expectEqual(RenderPipelineKind.solid, second_cache.actions[2].pipeline);
943
+ }
944
+
945
+ test "render pipeline cache plan reports output overflow" {
946
+ const batches = [_]RenderBatch{.{ .pipeline = .solid, .command_start = 0, .command_count = 1 }};
947
+ var no_entries: [0]RenderPipelineCacheEntry = .{};
948
+ var actions: [1]RenderPipelineCacheAction = undefined;
949
+ try std.testing.expectError(error.RenderPipelineCacheListFull, (RenderBatchPlan{ .batches = &batches }).cachePlan(&.{}, 1, &no_entries, &actions));
950
+
951
+ var entries: [1]RenderPipelineCacheEntry = undefined;
952
+ var no_actions: [0]RenderPipelineCacheAction = .{};
953
+ try std.testing.expectError(error.RenderPipelineCacheListFull, (RenderBatchPlan{ .batches = &batches }).cachePlan(&.{}, 1, &entries, &no_actions));
954
+ }
955
+
956
+ test "render image plan deduplicates texture cache inputs" {
957
+ const commands = [_]CanvasCommand{
958
+ .{ .draw_image = .{
959
+ .id = 1,
960
+ .image_id = 42,
961
+ .dst = geometry.RectF.init(0, 0, 20, 20),
962
+ } },
963
+ .{ .draw_image = .{
964
+ .id = 2,
965
+ .image_id = 42,
966
+ .src = geometry.RectF.init(4, 4, 12, 12),
967
+ .dst = geometry.RectF.init(48, 0, 20, 20),
968
+ .opacity = 0.5,
969
+ .fit = .cover,
970
+ } },
971
+ .{ .draw_image = .{
972
+ .id = 3,
973
+ .image_id = 77,
974
+ .dst = geometry.RectF.init(80, 0, 16, 16),
975
+ } },
976
+ };
977
+
978
+ var render_commands: [3]RenderCommand = undefined;
979
+ const render_plan = try (DisplayList{ .commands = &commands }).renderPlan(&render_commands);
980
+ var images: [2]RenderImage = undefined;
981
+ const image_plan = try render_plan.imagePlan(&images);
982
+
983
+ try std.testing.expectEqual(@as(usize, 2), image_plan.imageCount());
984
+ try std.testing.expectEqual(@as(usize, 3), image_plan.drawCount());
985
+ try std.testing.expectEqual(@as(ImageId, 42), image_plan.images[0].image_id);
986
+ try std.testing.expect(image_plan.images[0].id == null);
987
+ try std.testing.expectEqual(@as(usize, 2), image_plan.images[0].draw_count);
988
+ try expectRect(geometry.RectF.init(0, 0, 68, 20), image_plan.images[0].bounds);
989
+ try std.testing.expectEqual(renderImageFingerprint(42), image_plan.images[0].fingerprint);
990
+ try std.testing.expectEqual(@as(ImageId, 77), image_plan.images[1].image_id);
991
+ try std.testing.expectEqual(@as(?ObjectId, 3), image_plan.images[1].id);
992
+ }
993
+
994
+ test "render image plan carries provided image resources" {
995
+ const image_pixels = [_]u8{
996
+ 255, 0, 0, 255,
997
+ 0, 255, 0, 255,
998
+ 0, 0, 255, 255,
999
+ 255, 255, 255, 255,
1000
+ };
1001
+ const image_resources = [_]ReferenceImage{.{
1002
+ .id = 42,
1003
+ .width = 2,
1004
+ .height = 2,
1005
+ .pixels = &image_pixels,
1006
+ }};
1007
+ const commands = [_]CanvasCommand{.{ .draw_image = .{
1008
+ .id = 1,
1009
+ .image_id = 42,
1010
+ .dst = geometry.RectF.init(0, 0, 20, 20),
1011
+ } }};
1012
+
1013
+ var render_commands: [1]RenderCommand = undefined;
1014
+ const render_plan = try (DisplayList{ .commands = &commands }).renderPlan(&render_commands);
1015
+ var images: [1]RenderImage = undefined;
1016
+ const image_plan = try render_plan.imagePlanWithResources(&image_resources, &images);
1017
+
1018
+ try std.testing.expectEqual(@as(usize, 1), image_plan.imageCount());
1019
+ try std.testing.expectEqual(@as(ImageId, 42), image_plan.images[0].image_id);
1020
+ try std.testing.expectEqual(@as(usize, 2), image_plan.images[0].width);
1021
+ try std.testing.expectEqual(@as(usize, 2), image_plan.images[0].height);
1022
+ try std.testing.expectEqualSlices(u8, &image_pixels, image_plan.images[0].pixels);
1023
+ try std.testing.expect(image_plan.images[0].fingerprint != renderImageFingerprint(42));
1024
+ try std.testing.expectEqual(renderImageFingerprintForResource(42, image_resources[0]), image_plan.images[0].fingerprint);
1025
+ }
1026
+
1027
+ test "render image cache plan uploads retains and evicts textures" {
1028
+ const previous_images = [_]RenderImage{
1029
+ .{ .image_id = 8, .command_index = 0, .id = 1, .draw_count = 1, .bounds = geometry.RectF.init(0, 0, 20, 20), .fingerprint = renderImageFingerprint(8) },
1030
+ .{ .image_id = 9, .command_index = 1, .id = 2, .draw_count = 1, .bounds = geometry.RectF.init(24, 0, 20, 20), .fingerprint = renderImageFingerprint(9) },
1031
+ };
1032
+ var previous_entries: [2]RenderImageCacheEntry = undefined;
1033
+ var previous_actions: [2]RenderImageCacheAction = undefined;
1034
+ const previous_cache = try (RenderImagePlan{ .images = &previous_images }).cachePlan(&.{}, 1, &previous_entries, &previous_actions);
1035
+ try std.testing.expectEqual(@as(usize, 2), previous_cache.entryCount());
1036
+ try std.testing.expectEqual(@as(usize, 2), previous_cache.uploadCount());
1037
+ try std.testing.expectEqual(@as(u64, 1), previous_cache.entries[0].last_used_frame);
1038
+
1039
+ const next_images = [_]RenderImage{
1040
+ .{ .image_id = 8, .command_index = 0, .id = 1, .draw_count = 1, .bounds = geometry.RectF.init(0, 0, 20, 20), .fingerprint = renderImageFingerprint(8) },
1041
+ .{ .image_id = 10, .command_index = 1, .id = 3, .draw_count = 1, .bounds = geometry.RectF.init(48, 0, 20, 20), .fingerprint = renderImageFingerprint(10) },
1042
+ };
1043
+ var next_entries: [2]RenderImageCacheEntry = undefined;
1044
+ var next_actions: [3]RenderImageCacheAction = undefined;
1045
+ const next_cache = try (RenderImagePlan{ .images = &next_images }).cachePlan(previous_cache.entries, 2, &next_entries, &next_actions);
1046
+
1047
+ try std.testing.expectEqual(@as(usize, 2), next_cache.entryCount());
1048
+ try std.testing.expectEqual(@as(usize, 3), next_cache.actionCount());
1049
+ try std.testing.expectEqual(@as(usize, 1), next_cache.retainCount());
1050
+ try std.testing.expectEqual(@as(usize, 1), next_cache.uploadCount());
1051
+ try std.testing.expectEqual(@as(usize, 1), next_cache.evictCount());
1052
+ try std.testing.expectEqual(RenderImageCacheActionKind.retain, next_cache.actions[0].kind);
1053
+ try std.testing.expectEqual(@as(ImageId, 8), next_cache.actions[0].key.image_id);
1054
+ try std.testing.expectEqual(@as(?usize, 0), next_cache.actions[0].image_index);
1055
+ try std.testing.expectEqual(@as(?usize, 0), next_cache.actions[0].cache_index);
1056
+ try std.testing.expectEqual(RenderImageCacheActionKind.upload, next_cache.actions[1].kind);
1057
+ try std.testing.expectEqual(@as(ImageId, 10), next_cache.actions[1].key.image_id);
1058
+ try std.testing.expectEqual(RenderImageCacheActionKind.evict, next_cache.actions[2].kind);
1059
+ try std.testing.expectEqual(@as(ImageId, 9), next_cache.actions[2].key.image_id);
1060
+ try std.testing.expectEqual(@as(u64, 2), next_cache.entries[0].last_used_frame);
1061
+ }
1062
+
1063
+ test "render image plans report output overflow" {
1064
+ const commands = [_]CanvasCommand{.{ .draw_image = .{
1065
+ .id = 1,
1066
+ .image_id = 1,
1067
+ .dst = geometry.RectF.init(0, 0, 10, 10),
1068
+ } }};
1069
+
1070
+ var render_commands: [1]RenderCommand = undefined;
1071
+ const render_plan = try (DisplayList{ .commands = &commands }).renderPlan(&render_commands);
1072
+ var no_images: [0]RenderImage = .{};
1073
+ try std.testing.expectError(error.ImageListFull, render_plan.imagePlan(&no_images));
1074
+
1075
+ const images = [_]RenderImage{.{ .image_id = 1, .command_index = 0, .id = 1, .draw_count = 1, .bounds = geometry.RectF.init(0, 0, 10, 10), .fingerprint = renderImageFingerprint(1) }};
1076
+ var no_entries: [0]RenderImageCacheEntry = .{};
1077
+ var actions: [1]RenderImageCacheAction = undefined;
1078
+ try std.testing.expectError(error.ImageCacheListFull, (RenderImagePlan{ .images = &images }).cachePlan(&.{}, 1, &no_entries, &actions));
1079
+
1080
+ var entries: [1]RenderImageCacheEntry = undefined;
1081
+ var no_actions: [0]RenderImageCacheAction = .{};
1082
+ try std.testing.expectError(error.ImageCacheListFull, (RenderImagePlan{ .images = &images }).cachePlan(&.{}, 1, &entries, &no_actions));
1083
+ }
1084
+
1085
+ test "resource plan collects renderer cache inputs" {
1086
+ const stops = [_]GradientStop{
1087
+ .{ .offset = 0, .color = Color.rgb8(255, 255, 255) },
1088
+ .{ .offset = 1, .color = Color.rgb8(59, 130, 246) },
1089
+ };
1090
+ const glyphs = [_]Glyph{.{ .id = 7, .x = 0, .y = 0, .advance = 9 }};
1091
+ const commands = [_]CanvasCommand{
1092
+ .{ .fill_rounded_rect = .{
1093
+ .id = 1,
1094
+ .rect = geometry.RectF.init(0, 0, 100, 40),
1095
+ .radius = Radius.all(8),
1096
+ .fill = .{ .linear_gradient = .{
1097
+ .start = geometry.PointF.init(0, 0),
1098
+ .end = geometry.PointF.init(100, 40),
1099
+ .stops = &stops,
1100
+ } },
1101
+ } },
1102
+ .{ .draw_image = .{ .id = 2, .image_id = 99, .dst = geometry.RectF.init(8, 8, 32, 32) } },
1103
+ .{ .draw_text = .{
1104
+ .id = 3,
1105
+ .font_id = 5,
1106
+ .size = 14,
1107
+ .origin = geometry.PointF.init(48, 24),
1108
+ .color = Color.rgb8(15, 23, 42),
1109
+ .text = "Hi",
1110
+ .glyphs = &glyphs,
1111
+ } },
1112
+ .{ .shadow = .{
1113
+ .id = 4,
1114
+ .rect = geometry.RectF.init(0, 0, 100, 40),
1115
+ .offset = geometry.OffsetF.init(0, 8),
1116
+ .blur = 16,
1117
+ .spread = -4,
1118
+ .color = Color.rgba8(0, 0, 0, 64),
1119
+ } },
1120
+ .{ .blur = .{ .id = 5, .rect = geometry.RectF.init(0, 0, 20, 20), .radius = 6 } },
1121
+ };
1122
+
1123
+ var resources: [5]RenderResource = undefined;
1124
+ const plan = try (DisplayList{ .commands = &commands }).resourcePlan(&resources);
1125
+ try std.testing.expectEqual(@as(usize, 5), plan.resourceCount());
1126
+ try std.testing.expectEqual(RenderResourceKind.linear_gradient, plan.resources[0].kind);
1127
+ try std.testing.expectEqual(@as(?ObjectId, 1), plan.resources[0].id);
1128
+ try std.testing.expectEqual(@as(usize, 2), plan.resources[0].gradient_stop_count);
1129
+ try expectRect(geometry.RectF.init(0, 0, 100, 40), plan.resources[0].bounds);
1130
+
1131
+ try std.testing.expectEqual(RenderResourceKind.image, plan.resources[1].kind);
1132
+ try std.testing.expectEqual(@as(ImageId, 99), plan.resources[1].image_id);
1133
+ try expectRect(geometry.RectF.init(8, 8, 32, 32), plan.resources[1].bounds);
1134
+
1135
+ try std.testing.expectEqual(RenderResourceKind.glyph_run, plan.resources[2].kind);
1136
+ try std.testing.expectEqual(@as(FontId, 5), plan.resources[2].font_id);
1137
+ try std.testing.expectEqual(@as(usize, 1), plan.resources[2].glyph_count);
1138
+ try std.testing.expectEqual(@as(usize, 2), plan.resources[2].text_len);
1139
+
1140
+ try std.testing.expectEqual(RenderResourceKind.shadow, plan.resources[3].kind);
1141
+ try expectRect(geometry.RectF.init(-20, -12, 140, 80), plan.resources[3].bounds);
1142
+
1143
+ try std.testing.expectEqual(RenderResourceKind.blur, plan.resources[4].kind);
1144
+ try expectRect(geometry.RectF.init(-6, -6, 32, 32), plan.resources[4].bounds);
1145
+ }
1146
+
1147
+ test "resource plan collects gradient resources for lines and paths" {
1148
+ const stops = [_]GradientStop{
1149
+ .{ .offset = 0, .color = Color.rgb8(255, 255, 255) },
1150
+ .{ .offset = 1, .color = Color.rgb8(24, 24, 27) },
1151
+ };
1152
+ const path = [_]PathElement{
1153
+ .{ .verb = .move_to, .points = .{ geometry.PointF.init(4, 4), geometry.PointF.zero(), geometry.PointF.zero() } },
1154
+ .{ .verb = .line_to, .points = .{ geometry.PointF.init(20, 20), geometry.PointF.zero(), geometry.PointF.zero() } },
1155
+ };
1156
+ const gradient_fill = Fill{ .linear_gradient = .{
1157
+ .start = geometry.PointF.init(0, 0),
1158
+ .end = geometry.PointF.init(20, 20),
1159
+ .stops = &stops,
1160
+ } };
1161
+ const commands = [_]CanvasCommand{
1162
+ .{ .draw_line = .{
1163
+ .id = 1,
1164
+ .from = geometry.PointF.init(0, 0),
1165
+ .to = geometry.PointF.init(20, 20),
1166
+ .stroke = .{ .fill = gradient_fill, .width = 2 },
1167
+ } },
1168
+ .{ .fill_path = .{
1169
+ .id = 2,
1170
+ .elements = &path,
1171
+ .fill = gradient_fill,
1172
+ } },
1173
+ };
1174
+
1175
+ var resources: [2]RenderResource = undefined;
1176
+ const plan = try (DisplayList{ .commands = &commands }).resourcePlan(&resources);
1177
+ try std.testing.expectEqual(@as(usize, 2), plan.resourceCount());
1178
+ try std.testing.expectEqual(RenderResourceKind.linear_gradient, plan.resources[0].kind);
1179
+ try std.testing.expectEqual(@as(usize, 0), plan.resources[0].command_index);
1180
+ try std.testing.expectEqual(@as(?ObjectId, 1), plan.resources[0].id);
1181
+ try std.testing.expectEqual(@as(usize, 2), plan.resources[0].gradient_stop_count);
1182
+ try expectRect(geometry.RectF.init(-1, -1, 22, 22), plan.resources[0].bounds);
1183
+ try std.testing.expectEqual(RenderResourceKind.linear_gradient, plan.resources[1].kind);
1184
+ try std.testing.expectEqual(@as(usize, 1), plan.resources[1].command_index);
1185
+ try std.testing.expectEqual(@as(?ObjectId, 2), plan.resources[1].id);
1186
+ try expectRect(geometry.RectF.init(4, 4, 16, 16), plan.resources[1].bounds);
1187
+ }
1188
+
1189
+ test "resource cache plan uploads retains and evicts resources" {
1190
+ const stops = [_]GradientStop{
1191
+ .{ .offset = 0, .color = Color.rgb8(255, 255, 255) },
1192
+ .{ .offset = 1, .color = Color.rgb8(24, 24, 27) },
1193
+ };
1194
+ const first_commands = [_]CanvasCommand{
1195
+ .{ .fill_rect = .{ .id = 1, .rect = geometry.RectF.init(0, 0, 20, 20), .fill = .{ .linear_gradient = .{
1196
+ .start = geometry.PointF.init(0, 0),
1197
+ .end = geometry.PointF.init(20, 20),
1198
+ .stops = &stops,
1199
+ } } } },
1200
+ .{ .draw_image = .{ .id = 2, .image_id = 8, .dst = geometry.RectF.init(24, 0, 20, 20) } },
1201
+ };
1202
+ const second_commands = [_]CanvasCommand{
1203
+ .{ .fill_rect = .{ .id = 1, .rect = geometry.RectF.init(0, 0, 20, 20), .fill = .{ .linear_gradient = .{
1204
+ .start = geometry.PointF.init(0, 0),
1205
+ .end = geometry.PointF.init(20, 20),
1206
+ .stops = &stops,
1207
+ } } } },
1208
+ .{ .draw_text = .{
1209
+ .id = 3,
1210
+ .font_id = 7,
1211
+ .size = 12,
1212
+ .origin = geometry.PointF.init(24, 16),
1213
+ .color = Color.rgb8(15, 23, 42),
1214
+ .text = "Hi",
1215
+ } },
1216
+ };
1217
+
1218
+ var first_resources: [2]RenderResource = undefined;
1219
+ const first_plan = try (DisplayList{ .commands = &first_commands }).resourcePlan(&first_resources);
1220
+ var first_entries: [2]RenderResourceCacheEntry = undefined;
1221
+ var first_actions: [2]RenderResourceCacheAction = undefined;
1222
+ const first_cache = try first_plan.cachePlan(&.{}, 1, &first_entries, &first_actions);
1223
+ try std.testing.expectEqual(@as(usize, 2), first_cache.entryCount());
1224
+ try std.testing.expectEqual(@as(usize, 2), first_cache.actionCount());
1225
+ try std.testing.expectEqual(RenderResourceCacheActionKind.upload, first_cache.actions[0].kind);
1226
+ try std.testing.expectEqual(RenderResourceCacheActionKind.upload, first_cache.actions[1].kind);
1227
+ try std.testing.expectEqual(@as(u64, 1), first_cache.entries[0].last_used_frame);
1228
+
1229
+ var second_resources: [2]RenderResource = undefined;
1230
+ const second_plan = try (DisplayList{ .commands = &second_commands }).resourcePlan(&second_resources);
1231
+ var second_entries: [2]RenderResourceCacheEntry = undefined;
1232
+ var second_actions: [3]RenderResourceCacheAction = undefined;
1233
+ const second_cache = try second_plan.cachePlan(first_cache.entries, 2, &second_entries, &second_actions);
1234
+
1235
+ try std.testing.expectEqual(@as(usize, 2), second_cache.entryCount());
1236
+ try std.testing.expectEqual(@as(usize, 3), second_cache.actionCount());
1237
+ try std.testing.expectEqual(RenderResourceCacheActionKind.retain, second_cache.actions[0].kind);
1238
+ try std.testing.expectEqual(@as(?usize, 0), second_cache.actions[0].cache_index);
1239
+ try std.testing.expectEqual(RenderResourceCacheActionKind.upload, second_cache.actions[1].kind);
1240
+ try std.testing.expectEqual(RenderResourceKind.glyph_run, second_cache.actions[1].key.kind);
1241
+ try std.testing.expectEqual(RenderResourceCacheActionKind.evict, second_cache.actions[2].kind);
1242
+ try std.testing.expectEqual(RenderResourceKind.image, second_cache.actions[2].key.kind);
1243
+ try std.testing.expectEqual(@as(u64, 2), second_cache.entries[0].last_used_frame);
1244
+ }
1245
+
1246
+ test "resource cache plan treats changed fingerprints as uploads" {
1247
+ const first_stops = [_]GradientStop{
1248
+ .{ .offset = 0, .color = Color.rgb8(255, 255, 255) },
1249
+ .{ .offset = 1, .color = Color.rgb8(24, 24, 27) },
1250
+ };
1251
+ const second_stops = [_]GradientStop{
1252
+ .{ .offset = 0, .color = Color.rgb8(255, 255, 255) },
1253
+ .{ .offset = 1, .color = Color.rgb8(37, 99, 235) },
1254
+ };
1255
+ const first_commands = [_]CanvasCommand{.{ .fill_rect = .{ .id = 1, .rect = geometry.RectF.init(0, 0, 20, 20), .fill = .{ .linear_gradient = .{
1256
+ .start = geometry.PointF.init(0, 0),
1257
+ .end = geometry.PointF.init(20, 20),
1258
+ .stops = &first_stops,
1259
+ } } } }};
1260
+ const second_commands = [_]CanvasCommand{.{ .fill_rect = .{ .id = 1, .rect = geometry.RectF.init(0, 0, 20, 20), .fill = .{ .linear_gradient = .{
1261
+ .start = geometry.PointF.init(0, 0),
1262
+ .end = geometry.PointF.init(20, 20),
1263
+ .stops = &second_stops,
1264
+ } } } }};
1265
+
1266
+ var first_resources: [1]RenderResource = undefined;
1267
+ const first_plan = try (DisplayList{ .commands = &first_commands }).resourcePlan(&first_resources);
1268
+ var first_entries: [1]RenderResourceCacheEntry = undefined;
1269
+ var first_actions: [1]RenderResourceCacheAction = undefined;
1270
+ const first_cache = try first_plan.cachePlan(&.{}, 1, &first_entries, &first_actions);
1271
+
1272
+ var second_resources: [1]RenderResource = undefined;
1273
+ const second_plan = try (DisplayList{ .commands = &second_commands }).resourcePlan(&second_resources);
1274
+ try std.testing.expect(first_plan.resources[0].fingerprint != second_plan.resources[0].fingerprint);
1275
+
1276
+ var second_entries: [1]RenderResourceCacheEntry = undefined;
1277
+ var second_actions: [2]RenderResourceCacheAction = undefined;
1278
+ const second_cache = try second_plan.cachePlan(first_cache.entries, 2, &second_entries, &second_actions);
1279
+ try std.testing.expectEqual(@as(usize, 2), second_cache.actionCount());
1280
+ try std.testing.expectEqual(RenderResourceCacheActionKind.upload, second_cache.actions[0].kind);
1281
+ try std.testing.expectEqual(RenderResourceCacheActionKind.evict, second_cache.actions[1].kind);
1282
+ }
1283
+
1284
+ test "resource cache plan reports output overflow" {
1285
+ const commands = [_]CanvasCommand{
1286
+ .{ .draw_image = .{ .id = 1, .image_id = 1, .dst = geometry.RectF.init(0, 0, 10, 10) } },
1287
+ };
1288
+ var resources: [1]RenderResource = undefined;
1289
+ const plan = try (DisplayList{ .commands = &commands }).resourcePlan(&resources);
1290
+
1291
+ var no_entries: [0]RenderResourceCacheEntry = .{};
1292
+ var actions: [1]RenderResourceCacheAction = undefined;
1293
+ try std.testing.expectError(error.RenderResourceCacheListFull, plan.cachePlan(&.{}, 1, &no_entries, &actions));
1294
+
1295
+ var entries: [1]RenderResourceCacheEntry = undefined;
1296
+ var no_actions: [0]RenderResourceCacheAction = .{};
1297
+ try std.testing.expectError(error.RenderResourceCacheListFull, plan.cachePlan(&.{}, 1, &entries, &no_actions));
1298
+ }
1299
+
1300
+ test "resource plan reports output overflow" {
1301
+ const commands = [_]CanvasCommand{
1302
+ .{ .draw_image = .{ .id = 1, .image_id = 1, .dst = geometry.RectF.init(0, 0, 10, 10) } },
1303
+ };
1304
+ var resources: [0]RenderResource = .{};
1305
+ try std.testing.expectError(error.RenderResourceListFull, (DisplayList{ .commands = &commands }).resourcePlan(&resources));
1306
+ }
1307
+
1308
+ test "visual effect plan collects shadow and blur cache inputs" {
1309
+ const commands = [_]CanvasCommand{
1310
+ .{ .shadow = .{
1311
+ .id = 7,
1312
+ .rect = geometry.RectF.init(10, 20, 30, 40),
1313
+ .radius = Radius.all(5),
1314
+ .offset = .{ .dx = 3, .dy = 4 },
1315
+ .blur = 12,
1316
+ .spread = -2,
1317
+ .color = Color.rgba8(0, 0, 0, 96),
1318
+ } },
1319
+ .{ .blur = .{
1320
+ .id = 0,
1321
+ .rect = geometry.RectF.init(80, 90, 20, 10),
1322
+ .radius = 6,
1323
+ } },
1324
+ };
1325
+
1326
+ var effects: [2]VisualEffect = undefined;
1327
+ const plan = try (DisplayList{ .commands = &commands }).visualEffectPlan(&effects);
1328
+ try std.testing.expectEqual(@as(usize, 2), plan.effectCount());
1329
+ try std.testing.expectEqual(@as(usize, 1), plan.shadowCount());
1330
+ try std.testing.expectEqual(@as(usize, 1), plan.blurCount());
1331
+ try std.testing.expectEqual(VisualEffectKind.shadow, plan.effects[0].kind);
1332
+ try std.testing.expectEqual(@as(?ObjectId, 7), plan.effects[0].id);
1333
+ try expectRect(geometry.RectF.init(-1, 10, 58, 68), plan.effects[0].bounds);
1334
+ try std.testing.expect(radiiEqual(Radius.all(5), plan.effects[0].radius));
1335
+ try std.testing.expectEqual(@as(f32, 12), plan.effects[0].blur);
1336
+ try std.testing.expectEqual(@as(f32, -2), plan.effects[0].spread);
1337
+ try std.testing.expectEqual(VisualEffectKind.blur, plan.effects[1].kind);
1338
+ try std.testing.expect(plan.effects[1].id == null);
1339
+ try expectRect(geometry.RectF.init(74, 84, 32, 22), plan.effects[1].bounds);
1340
+ try std.testing.expectEqual(@as(f32, 6), plan.effects[1].blur);
1341
+
1342
+ var cache_entries: [2]VisualEffectCacheEntry = undefined;
1343
+ var cache_actions: [2]VisualEffectCacheAction = undefined;
1344
+ const cache_plan = try plan.cachePlan(&.{}, 1, &cache_entries, &cache_actions);
1345
+ try std.testing.expectEqual(@as(usize, 2), cache_plan.actionCount());
1346
+ const key = cache_plan.actions[1].key;
1347
+ try std.testing.expectEqual(VisualEffectKind.blur, key.kind);
1348
+ try std.testing.expect(key.id == null);
1349
+ try std.testing.expectEqual(@as(usize, 1), key.command_index);
1350
+ }
1351
+
1352
+ test "visual effect cache plan uploads retains and evicts effects" {
1353
+ const first_commands = [_]CanvasCommand{
1354
+ .{ .shadow = .{
1355
+ .id = 1,
1356
+ .rect = geometry.RectF.init(0, 0, 20, 20),
1357
+ .blur = 8,
1358
+ .color = Color.rgba8(0, 0, 0, 64),
1359
+ } },
1360
+ .{ .blur = .{
1361
+ .id = 2,
1362
+ .rect = geometry.RectF.init(30, 0, 20, 20),
1363
+ .radius = 4,
1364
+ } },
1365
+ };
1366
+ const second_commands = [_]CanvasCommand{
1367
+ .{ .shadow = .{
1368
+ .id = 1,
1369
+ .rect = geometry.RectF.init(0, 0, 20, 20),
1370
+ .blur = 8,
1371
+ .color = Color.rgba8(0, 0, 0, 64),
1372
+ } },
1373
+ .{ .blur = .{
1374
+ .id = 2,
1375
+ .rect = geometry.RectF.init(30, 0, 20, 20),
1376
+ .radius = 10,
1377
+ } },
1378
+ };
1379
+
1380
+ var first_effects: [2]VisualEffect = undefined;
1381
+ const first_plan = try (DisplayList{ .commands = &first_commands }).visualEffectPlan(&first_effects);
1382
+ var first_entries: [2]VisualEffectCacheEntry = undefined;
1383
+ var first_actions: [2]VisualEffectCacheAction = undefined;
1384
+ const first_cache = try first_plan.cachePlan(&.{}, 1, &first_entries, &first_actions);
1385
+ try std.testing.expectEqual(@as(usize, 2), first_cache.entryCount());
1386
+ try std.testing.expectEqual(@as(usize, 2), first_cache.uploadCount());
1387
+ try std.testing.expectEqual(@as(u64, 1), first_cache.entries[0].last_used_frame);
1388
+
1389
+ var second_effects: [2]VisualEffect = undefined;
1390
+ const second_plan = try (DisplayList{ .commands = &second_commands }).visualEffectPlan(&second_effects);
1391
+ var second_entries: [2]VisualEffectCacheEntry = undefined;
1392
+ var second_actions: [3]VisualEffectCacheAction = undefined;
1393
+ const second_cache = try second_plan.cachePlan(first_cache.entries, 2, &second_entries, &second_actions);
1394
+ try std.testing.expectEqual(@as(usize, 2), second_cache.entryCount());
1395
+ try std.testing.expectEqual(@as(usize, 1), second_cache.retainCount());
1396
+ try std.testing.expectEqual(@as(usize, 1), second_cache.uploadCount());
1397
+ try std.testing.expectEqual(@as(usize, 1), second_cache.evictCount());
1398
+ try std.testing.expectEqual(VisualEffectCacheActionKind.retain, second_cache.actions[0].kind);
1399
+ try std.testing.expectEqual(VisualEffectKind.shadow, second_cache.actions[0].key.kind);
1400
+ try std.testing.expectEqual(VisualEffectCacheActionKind.upload, second_cache.actions[1].kind);
1401
+ try std.testing.expectEqual(VisualEffectKind.blur, second_cache.actions[1].key.kind);
1402
+ try std.testing.expectEqual(VisualEffectCacheActionKind.evict, second_cache.actions[2].kind);
1403
+ try std.testing.expectEqual(VisualEffectKind.blur, second_cache.actions[2].key.kind);
1404
+ try std.testing.expectEqual(@as(u64, 2), second_cache.entries[0].last_used_frame);
1405
+ }
1406
+
1407
+ test "visual effect plans report output overflow" {
1408
+ const commands = [_]CanvasCommand{.{ .shadow = .{
1409
+ .id = 1,
1410
+ .rect = geometry.RectF.init(0, 0, 10, 10),
1411
+ .blur = 4,
1412
+ .color = Color.rgba8(0, 0, 0, 64),
1413
+ } }};
1414
+ var no_effects: [0]VisualEffect = .{};
1415
+ try std.testing.expectError(error.VisualEffectListFull, (DisplayList{ .commands = &commands }).visualEffectPlan(&no_effects));
1416
+
1417
+ var effects: [1]VisualEffect = undefined;
1418
+ const plan = try (DisplayList{ .commands = &commands }).visualEffectPlan(&effects);
1419
+ var no_entries: [0]VisualEffectCacheEntry = .{};
1420
+ var actions: [1]VisualEffectCacheAction = undefined;
1421
+ try std.testing.expectError(error.VisualEffectCacheListFull, plan.cachePlan(&.{}, 1, &no_entries, &actions));
1422
+
1423
+ var entries: [1]VisualEffectCacheEntry = undefined;
1424
+ var no_actions: [0]VisualEffectCacheAction = .{};
1425
+ try std.testing.expectError(error.VisualEffectCacheListFull, plan.cachePlan(&.{}, 1, &entries, &no_actions));
1426
+ }
1427
+
1428
+ test "glyph atlas plan deduplicates shaped glyph keys" {
1429
+ const first_glyphs = [_]Glyph{
1430
+ .{ .id = 10, .x = 0.10, .y = 0, .advance = 8 },
1431
+ .{ .id = 11, .x = 8.25, .y = 0, .advance = 8 },
1432
+ };
1433
+ const second_glyphs = [_]Glyph{
1434
+ .{ .id = 10, .x = 0.20, .y = 0, .advance = 8 },
1435
+ .{ .id = 10, .x = 0.55, .y = 0, .advance = 8 },
1436
+ };
1437
+ const commands = [_]CanvasCommand{
1438
+ .{ .draw_text = .{
1439
+ .id = 1,
1440
+ .font_id = 7,
1441
+ .size = 16,
1442
+ .origin = geometry.PointF.init(12, 24),
1443
+ .color = Color.rgb8(15, 23, 42),
1444
+ .glyphs = &first_glyphs,
1445
+ } },
1446
+ .{ .draw_text = .{
1447
+ .id = 2,
1448
+ .font_id = 7,
1449
+ .size = 16,
1450
+ .origin = geometry.PointF.init(12, 24),
1451
+ .color = Color.rgb8(15, 23, 42),
1452
+ .glyphs = &second_glyphs,
1453
+ } },
1454
+ };
1455
+
1456
+ var entries: [4]GlyphAtlasEntry = undefined;
1457
+ const plan = try (DisplayList{ .commands = &commands }).glyphAtlasPlan(&entries);
1458
+ try std.testing.expectEqual(@as(usize, 3), plan.entryCount());
1459
+ try std.testing.expectEqual(@as(FontId, 7), plan.entries[0].key.font_id);
1460
+ try std.testing.expectEqual(@as(u32, 10), plan.entries[0].key.glyph_id);
1461
+ try std.testing.expectEqual(@as(u8, 0), plan.entries[0].key.subpixel_x);
1462
+ try std.testing.expectEqual(@as(u32, 11), plan.entries[1].key.glyph_id);
1463
+ try std.testing.expectEqual(@as(u8, 1), plan.entries[1].key.subpixel_x);
1464
+ try std.testing.expectEqual(@as(u32, 10), plan.entries[2].key.glyph_id);
1465
+ try std.testing.expectEqual(@as(u8, 2), plan.entries[2].key.subpixel_x);
1466
+ }
1467
+
1468
+ test "glyph atlas keys and fingerprints keep fonts sharing glyph indices apart" {
1469
+ // Two faces routinely share raw glyph INDICES (index 10 in face A is
1470
+ // a different outline than index 10 in face B), so every cache seam
1471
+ // that stores rasterized glyphs or diffing fingerprints must key the
1472
+ // font id alongside the glyph id — a registered font id colliding
1473
+ // with a built-in's glyph indices must never share cache entries.
1474
+ const fingerprints = @import("render_fingerprints.zig");
1475
+ const glyphs = [_]Glyph{
1476
+ .{ .id = 10, .x = 0, .y = 0, .advance = 8 },
1477
+ .{ .id = 11, .x = 8, .y = 0, .advance = 8 },
1478
+ };
1479
+ const sans_text = text_model.DrawText{
1480
+ .id = 1,
1481
+ .font_id = default_sans_font_id,
1482
+ .size = 16,
1483
+ .origin = geometry.PointF.init(12, 24),
1484
+ .color = Color.rgb8(15, 23, 42),
1485
+ .glyphs = &glyphs,
1486
+ };
1487
+ var registered_text = sans_text;
1488
+ registered_text.font_id = canvas.min_registered_font_id;
1489
+
1490
+ // Same glyph ids, same size, same subpixel buckets — the plan still
1491
+ // carries one atlas entry per (font id, glyph id) pair.
1492
+ const commands = [_]CanvasCommand{
1493
+ .{ .draw_text = sans_text },
1494
+ .{ .draw_text = registered_text },
1495
+ };
1496
+ var entries: [4]GlyphAtlasEntry = undefined;
1497
+ const plan = try (DisplayList{ .commands = &commands }).glyphAtlasPlan(&entries);
1498
+ try std.testing.expectEqual(@as(usize, 4), plan.entryCount());
1499
+ try std.testing.expectEqual(default_sans_font_id, plan.entries[0].key.font_id);
1500
+ try std.testing.expectEqual(canvas.min_registered_font_id, plan.entries[2].key.font_id);
1501
+ try std.testing.expectEqual(plan.entries[0].key.glyph_id, plan.entries[2].key.glyph_id);
1502
+
1503
+ // Retained-diff fingerprints split on font id too, so a font swap on
1504
+ // an otherwise identical run repaints instead of skipping.
1505
+ try std.testing.expect(fingerprints.drawTextFingerprint(sans_text) != fingerprints.drawTextFingerprint(registered_text));
1506
+ }
1507
+
1508
+ test "glyph atlas plan honors shaped fallback font overrides" {
1509
+ const glyphs = [_]Glyph{
1510
+ .{ .id = 41, .x = 0, .y = 0, .advance = 8 },
1511
+ .{ .id = 9001, .font_id = 11, .x = 8, .y = 0, .advance = 14 },
1512
+ .{ .id = 42, .x = 22, .y = 0, .advance = 8 },
1513
+ };
1514
+ const commands = [_]CanvasCommand{.{ .draw_text = .{
1515
+ .id = 1,
1516
+ .font_id = 7,
1517
+ .size = 16,
1518
+ .origin = geometry.PointF.init(12, 24),
1519
+ .color = Color.rgb8(15, 23, 42),
1520
+ .text = "A🙂B",
1521
+ .glyphs = &glyphs,
1522
+ } }};
1523
+
1524
+ var entries: [3]GlyphAtlasEntry = undefined;
1525
+ const plan = try (DisplayList{ .commands = &commands }).glyphAtlasPlan(&entries);
1526
+ try std.testing.expectEqual(@as(usize, 3), plan.entryCount());
1527
+ try std.testing.expectEqual(@as(FontId, 7), plan.entries[0].key.font_id);
1528
+ try std.testing.expectEqual(@as(FontId, 11), plan.entries[1].key.font_id);
1529
+ try std.testing.expectEqual(@as(u32, 9001), plan.entries[1].key.glyph_id);
1530
+ try std.testing.expectEqual(@as(FontId, 7), plan.entries[2].key.font_id);
1531
+
1532
+ const primary_only = [_]Glyph{
1533
+ .{ .id = 41, .x = 0, .y = 0, .advance = 8 },
1534
+ .{ .id = 9001, .x = 8, .y = 0, .advance = 14 },
1535
+ .{ .id = 42, .x = 22, .y = 0, .advance = 8 },
1536
+ };
1537
+ const primary_commands = [_]CanvasCommand{.{ .draw_text = .{
1538
+ .id = 1,
1539
+ .font_id = 7,
1540
+ .size = 16,
1541
+ .origin = geometry.PointF.init(12, 24),
1542
+ .color = Color.rgb8(15, 23, 42),
1543
+ .text = "A🙂B",
1544
+ .glyphs = &primary_only,
1545
+ } }};
1546
+
1547
+ var changes: [1]DiffChange = undefined;
1548
+ const diff = try DisplayList.diff(.{ .commands = &primary_commands }, .{ .commands = &commands }, &changes);
1549
+ try std.testing.expectEqual(@as(usize, 1), diff.len);
1550
+ try std.testing.expectEqual(DiffKind.changed, diff[0].kind);
1551
+
1552
+ var buffer: [512]u8 = undefined;
1553
+ var writer = std.Io.Writer.fixed(&buffer);
1554
+ try (DisplayList{ .commands = &commands }).writeJson(&writer);
1555
+ try std.testing.expect(std.mem.indexOf(u8, writer.buffered(), "\"font\":11") != null);
1556
+ }
1557
+
1558
+ test "glyph atlas plan falls back to utf8 scalar glyph keys" {
1559
+ const commands = [_]CanvasCommand{.{ .draw_text = .{
1560
+ .id = 1,
1561
+ .font_id = 3,
1562
+ .size = 12,
1563
+ .origin = geometry.PointF.init(0.5, 8.75),
1564
+ .color = Color.rgb8(15, 23, 42),
1565
+ .text = "A é",
1566
+ } }};
1567
+
1568
+ var entries: [2]GlyphAtlasEntry = undefined;
1569
+ const plan = try (DisplayList{ .commands = &commands }).glyphAtlasPlan(&entries);
1570
+ try std.testing.expectEqual(@as(usize, 2), plan.entryCount());
1571
+ try std.testing.expectEqual(@as(u32, 'A'), plan.entries[0].key.glyph_id);
1572
+ try std.testing.expectEqual(@as(u8, 2), plan.entries[0].key.subpixel_x);
1573
+ try std.testing.expectEqual(@as(u8, 3), plan.entries[0].key.subpixel_y);
1574
+ try std.testing.expectEqual(@as(usize, 0), plan.entries[0].glyph_index);
1575
+ try std.testing.expectEqual(@as(u32, 0x00e9), plan.entries[1].key.glyph_id);
1576
+ try std.testing.expectEqual(@as(u8, 2), plan.entries[1].key.subpixel_x);
1577
+ try std.testing.expectEqual(@as(usize, 2), plan.entries[1].glyph_index);
1578
+ }
1579
+
1580
+ test "glyph atlas plan reports output overflow" {
1581
+ const glyphs = [_]Glyph{.{ .id = 10, .x = 0, .y = 0 }};
1582
+ const commands = [_]CanvasCommand{.{ .draw_text = .{
1583
+ .id = 1,
1584
+ .font_id = 1,
1585
+ .size = 14,
1586
+ .origin = geometry.PointF.init(0, 0),
1587
+ .color = Color.rgb8(0, 0, 0),
1588
+ .glyphs = &glyphs,
1589
+ } }};
1590
+ var entries: [0]GlyphAtlasEntry = .{};
1591
+ try std.testing.expectError(error.GlyphAtlasListFull, (DisplayList{ .commands = &commands }).glyphAtlasPlan(&entries));
1592
+ }
1593
+
1594
+ test "glyph atlas cache plan uploads retains and evicts glyphs" {
1595
+ const previous = [_]GlyphAtlasCacheEntry{
1596
+ .{
1597
+ .key = .{ .font_id = 1, .glyph_id = 65, .size = 14, .subpixel_x = 0, .subpixel_y = 0 },
1598
+ .last_used_frame = 3,
1599
+ },
1600
+ .{
1601
+ .key = .{ .font_id = 1, .glyph_id = 66, .size = 14, .subpixel_x = 0, .subpixel_y = 0 },
1602
+ .last_used_frame = 3,
1603
+ },
1604
+ };
1605
+ const atlas_entries = [_]GlyphAtlasEntry{
1606
+ .{
1607
+ .key = .{ .font_id = 1, .glyph_id = 65, .size = 14, .subpixel_x = 0, .subpixel_y = 0 },
1608
+ .command_index = 0,
1609
+ .glyph_index = 0,
1610
+ },
1611
+ .{
1612
+ .key = .{ .font_id = 1, .glyph_id = 67, .size = 14, .subpixel_x = 0, .subpixel_y = 0 },
1613
+ .command_index = 0,
1614
+ .glyph_index = 1,
1615
+ },
1616
+ };
1617
+
1618
+ var cache_entries: [2]GlyphAtlasCacheEntry = undefined;
1619
+ var cache_actions: [3]GlyphAtlasCacheAction = undefined;
1620
+ const cache = try (GlyphAtlasPlan{ .entries = &atlas_entries }).cachePlan(&previous, 4, &cache_entries, &cache_actions);
1621
+
1622
+ try std.testing.expectEqual(@as(usize, 2), cache.entryCount());
1623
+ try std.testing.expectEqual(@as(usize, 3), cache.actionCount());
1624
+ try std.testing.expectEqual(@as(usize, 1), cache.uploadCount());
1625
+ try std.testing.expectEqual(@as(usize, 1), cache.retainCount());
1626
+ try std.testing.expectEqual(@as(usize, 1), cache.evictCount());
1627
+ try std.testing.expectEqual(@as(u64, 4), cache.entries[0].last_used_frame);
1628
+ try std.testing.expectEqual(GlyphAtlasCacheActionKind.retain, cache.actions[0].kind);
1629
+ try std.testing.expectEqual(@as(u32, 65), cache.actions[0].key.glyph_id);
1630
+ try std.testing.expectEqual(@as(usize, 0), cache.actions[0].atlas_index.?);
1631
+ try std.testing.expectEqual(@as(usize, 0), cache.actions[0].cache_index.?);
1632
+ try std.testing.expectEqual(GlyphAtlasCacheActionKind.upload, cache.actions[1].kind);
1633
+ try std.testing.expectEqual(@as(u32, 67), cache.actions[1].key.glyph_id);
1634
+ try std.testing.expectEqual(@as(usize, 1), cache.actions[1].atlas_index.?);
1635
+ try std.testing.expect(cache.actions[1].cache_index == null);
1636
+ try std.testing.expectEqual(GlyphAtlasCacheActionKind.evict, cache.actions[2].kind);
1637
+ try std.testing.expectEqual(@as(u32, 66), cache.actions[2].key.glyph_id);
1638
+ try std.testing.expect(cache.actions[2].atlas_index == null);
1639
+ try std.testing.expectEqual(@as(usize, 1), cache.actions[2].cache_index.?);
1640
+ }
1641
+
1642
+ test "glyph atlas cache plan keeps recent unused glyphs warm" {
1643
+ const previous = [_]GlyphAtlasCacheEntry{
1644
+ .{
1645
+ .key = .{ .font_id = 1, .glyph_id = 65, .size = 14 },
1646
+ .last_used_frame = 3,
1647
+ },
1648
+ .{
1649
+ .key = .{ .font_id = 1, .glyph_id = 66, .size = 14 },
1650
+ .last_used_frame = 3,
1651
+ },
1652
+ };
1653
+ const atlas_entries = [_]GlyphAtlasEntry{.{
1654
+ .key = .{ .font_id = 1, .glyph_id = 65, .size = 14 },
1655
+ .command_index = 0,
1656
+ .glyph_index = 0,
1657
+ }};
1658
+
1659
+ var warm_entries: [2]GlyphAtlasCacheEntry = undefined;
1660
+ var warm_actions: [2]GlyphAtlasCacheAction = undefined;
1661
+ const warm = try (GlyphAtlasPlan{ .entries = &atlas_entries }).cachePlanWithRetention(&previous, 4, 2, &warm_entries, &warm_actions);
1662
+ try std.testing.expectEqual(@as(usize, 2), warm.entryCount());
1663
+ try std.testing.expectEqual(@as(usize, 0), warm.uploadCount());
1664
+ try std.testing.expectEqual(@as(usize, 2), warm.retainCount());
1665
+ try std.testing.expectEqual(@as(usize, 0), warm.evictCount());
1666
+ try std.testing.expectEqual(@as(u64, 4), warm.entries[0].last_used_frame);
1667
+ try std.testing.expectEqual(@as(u64, 3), warm.entries[1].last_used_frame);
1668
+ try std.testing.expectEqual(@as(?usize, 0), warm.actions[0].atlas_index);
1669
+ try std.testing.expectEqual(@as(?usize, 0), warm.actions[0].cache_index);
1670
+ try std.testing.expect(warm.actions[1].atlas_index == null);
1671
+ try std.testing.expectEqual(@as(?usize, 1), warm.actions[1].cache_index);
1672
+
1673
+ var stale_entries: [2]GlyphAtlasCacheEntry = undefined;
1674
+ var stale_actions: [2]GlyphAtlasCacheAction = undefined;
1675
+ const stale = try (GlyphAtlasPlan{ .entries = &atlas_entries }).cachePlanWithRetention(&previous, 6, 2, &stale_entries, &stale_actions);
1676
+ try std.testing.expectEqual(@as(usize, 1), stale.entryCount());
1677
+ try std.testing.expectEqual(@as(usize, 1), stale.retainCount());
1678
+ try std.testing.expectEqual(@as(usize, 1), stale.evictCount());
1679
+ try std.testing.expectEqual(GlyphAtlasCacheActionKind.evict, stale.actions[1].kind);
1680
+ try std.testing.expectEqual(@as(u32, 66), stale.actions[1].key.glyph_id);
1681
+ try std.testing.expectEqual(@as(?usize, 1), stale.actions[1].cache_index);
1682
+ }
1683
+
1684
+ test "glyph atlas cache plan reports output overflow" {
1685
+ const atlas_entries = [_]GlyphAtlasEntry{.{
1686
+ .key = .{ .font_id = 1, .glyph_id = 65, .size = 14 },
1687
+ .command_index = 0,
1688
+ .glyph_index = 0,
1689
+ }};
1690
+ var no_cache_entries: [0]GlyphAtlasCacheEntry = .{};
1691
+ var cache_actions: [1]GlyphAtlasCacheAction = undefined;
1692
+ try std.testing.expectError(error.GlyphAtlasCacheListFull, (GlyphAtlasPlan{ .entries = &atlas_entries }).cachePlan(&.{}, 1, &no_cache_entries, &cache_actions));
1693
+
1694
+ var cache_entries: [1]GlyphAtlasCacheEntry = undefined;
1695
+ var no_cache_actions: [0]GlyphAtlasCacheAction = .{};
1696
+ try std.testing.expectError(error.GlyphAtlasCacheListFull, (GlyphAtlasPlan{ .entries = &atlas_entries }).cachePlan(&.{}, 1, &cache_entries, &no_cache_actions));
1697
+ }
1698
+
1699
+ test "canvas frame budget tracks glyph and text cache churn" {
1700
+ const status = (CanvasFrameBudget{
1701
+ .max_glyph_atlas_entries = 8,
1702
+ .max_glyph_atlas_uploads = 1,
1703
+ .max_glyph_atlas_evicts = 1,
1704
+ .max_text_layouts = 8,
1705
+ .max_text_layout_lines = 8,
1706
+ .max_text_layout_uploads = 1,
1707
+ .max_text_layout_evicts = 1,
1708
+ }).status(.{
1709
+ .glyph_atlas_entry_count = 4,
1710
+ .glyph_atlas_upload_count = 2,
1711
+ .glyph_atlas_evict_count = 2,
1712
+ .text_layout_count = 3,
1713
+ .text_layout_line_count = 3,
1714
+ .text_layout_upload_count = 2,
1715
+ .text_layout_evict_count = 2,
1716
+ });
1717
+
1718
+ try std.testing.expect(status.ok() == false);
1719
+ try std.testing.expect(!status.glyph_atlas_entries_over);
1720
+ try std.testing.expect(status.glyph_atlas_uploads_over);
1721
+ try std.testing.expect(status.glyph_atlas_evicts_over);
1722
+ try std.testing.expect(!status.text_layouts_over);
1723
+ try std.testing.expect(!status.text_layout_lines_over);
1724
+ try std.testing.expect(status.text_layout_uploads_over);
1725
+ try std.testing.expect(status.text_layout_evicts_over);
1726
+ try std.testing.expectEqual(@as(usize, 4), status.exceededCount());
1727
+ }
1728
+
1729
+ test "canvas frame plan builds first frame renderer packet" {
1730
+ const stops = [_]GradientStop{
1731
+ .{ .offset = 0, .color = Color.rgb8(255, 255, 255) },
1732
+ .{ .offset = 1, .color = Color.rgb8(24, 24, 27) },
1733
+ };
1734
+ const commands = [_]CanvasCommand{
1735
+ .{ .fill_rounded_rect = .{
1736
+ .id = 1,
1737
+ .rect = geometry.RectF.init(16, 16, 160, 72),
1738
+ .radius = Radius.all(12),
1739
+ .fill = .{ .linear_gradient = .{
1740
+ .start = geometry.PointF.init(16, 16),
1741
+ .end = geometry.PointF.init(176, 88),
1742
+ .stops = &stops,
1743
+ } },
1744
+ } },
1745
+ .{ .draw_text = .{
1746
+ .id = 2,
1747
+ .font_id = 5,
1748
+ .size = 14,
1749
+ .origin = geometry.PointF.init(28, 48),
1750
+ .color = Color.rgb8(15, 23, 42),
1751
+ .text = "OK",
1752
+ } },
1753
+ };
1754
+
1755
+ var render_commands: [2]RenderCommand = undefined;
1756
+ var render_batches: [2]RenderBatch = undefined;
1757
+ var pipeline_cache_entries: [2]RenderPipelineCacheEntry = undefined;
1758
+ var pipeline_cache_actions: [2]RenderPipelineCacheAction = undefined;
1759
+ var resources: [2]RenderResource = undefined;
1760
+ var resource_cache_entries: [2]RenderResourceCacheEntry = undefined;
1761
+ var resource_cache_actions: [2]RenderResourceCacheAction = undefined;
1762
+ var glyphs: [2]GlyphAtlasEntry = undefined;
1763
+ var glyph_cache_entries: [2]GlyphAtlasCacheEntry = undefined;
1764
+ var glyph_cache_actions: [2]GlyphAtlasCacheAction = undefined;
1765
+ var text_layout_plans: [1]TextLayoutPlan = undefined;
1766
+ var text_layout_lines: [1]TextLine = undefined;
1767
+ var text_layout_cache_entries: [1]TextLayoutCacheEntry = undefined;
1768
+ var text_layout_cache_actions: [1]TextLayoutCacheAction = undefined;
1769
+ var changes: [2]DiffChange = undefined;
1770
+ const frame = try (DisplayList{ .commands = &commands }).framePlan(null, .{
1771
+ .frame_index = 7,
1772
+ .timestamp_ns = 88,
1773
+ .surface_size = geometry.SizeF.init(320, 200),
1774
+ .scale = 2,
1775
+ .budget = .{
1776
+ .max_commands = 1,
1777
+ .max_batches = 2,
1778
+ .max_encoder_commands = 13,
1779
+ .max_pipelines = 2,
1780
+ .max_pipeline_uploads = 1,
1781
+ .max_resources = 2,
1782
+ .max_resource_uploads = 1,
1783
+ .max_glyph_atlas_entries = 2,
1784
+ },
1785
+ }, .{
1786
+ .render_commands = &render_commands,
1787
+ .render_batches = &render_batches,
1788
+ .pipeline_cache_entries = &pipeline_cache_entries,
1789
+ .pipeline_cache_actions = &pipeline_cache_actions,
1790
+ .resources = &resources,
1791
+ .resource_cache_entries = &resource_cache_entries,
1792
+ .resource_cache_actions = &resource_cache_actions,
1793
+ .glyph_atlas_entries = &glyphs,
1794
+ .glyph_atlas_cache_entries = &glyph_cache_entries,
1795
+ .glyph_atlas_cache_actions = &glyph_cache_actions,
1796
+ .text_layout_plans = &text_layout_plans,
1797
+ .text_layout_lines = &text_layout_lines,
1798
+ .text_layout_cache_entries = &text_layout_cache_entries,
1799
+ .text_layout_cache_actions = &text_layout_cache_actions,
1800
+ .changes = &changes,
1801
+ });
1802
+
1803
+ try std.testing.expectEqual(@as(u64, 7), frame.frame_index);
1804
+ try std.testing.expectEqual(@as(u64, 88), frame.timestamp_ns);
1805
+ try std.testing.expectEqualDeep(geometry.SizeF.init(320, 200), frame.surface_size);
1806
+ try std.testing.expectEqual(@as(f32, 2), frame.scale);
1807
+ try std.testing.expect(frame.full_repaint);
1808
+ try std.testing.expect(frame.requiresRender());
1809
+ try std.testing.expectEqual(@as(usize, 2), frame.render_plan.commandCount());
1810
+ try std.testing.expectEqual(@as(usize, 2), frame.batch_plan.batchCount());
1811
+ try std.testing.expectEqual(RenderPipelineKind.linear_gradient, frame.batch_plan.batches[0].pipeline);
1812
+ try std.testing.expectEqual(RenderPipelineKind.glyph_run, frame.batch_plan.batches[1].pipeline);
1813
+ try std.testing.expectEqual(@as(usize, 2), frame.pipeline_cache_plan.entryCount());
1814
+ try std.testing.expectEqual(@as(usize, 2), frame.pipeline_cache_plan.actionCount());
1815
+ try std.testing.expectEqual(@as(usize, 2), frame.pipeline_cache_plan.uploadCount());
1816
+ try std.testing.expectEqual(RenderPipelineCacheActionKind.upload, frame.pipeline_cache_plan.actions[0].kind);
1817
+ try std.testing.expectEqual(RenderPipelineKind.linear_gradient, frame.pipeline_cache_plan.actions[0].pipeline);
1818
+ try std.testing.expectEqual(RenderPipelineKind.glyph_run, frame.pipeline_cache_plan.actions[1].pipeline);
1819
+ try std.testing.expectEqual(@as(usize, 2), frame.resource_plan.resourceCount());
1820
+ try std.testing.expectEqual(@as(usize, 2), frame.resource_cache_plan.entryCount());
1821
+ try std.testing.expectEqual(@as(usize, 2), frame.resource_cache_plan.actionCount());
1822
+ try std.testing.expectEqual(RenderResourceCacheActionKind.upload, frame.resource_cache_plan.actions[0].kind);
1823
+ try std.testing.expectEqual(RenderResourceCacheActionKind.upload, frame.resource_cache_plan.actions[1].kind);
1824
+ try std.testing.expectEqual(@as(usize, 2), frame.resource_cache_plan.uploadCount());
1825
+ try std.testing.expectEqual(@as(usize, 2), frame.glyph_atlas_plan.entryCount());
1826
+ try std.testing.expectEqual(@as(usize, 2), frame.glyph_atlas_cache_plan.entryCount());
1827
+ try std.testing.expectEqual(@as(usize, 2), frame.glyph_atlas_cache_plan.uploadCount());
1828
+ try std.testing.expectEqual(@as(usize, 1), frame.text_layout_plan.planCount());
1829
+ try std.testing.expectEqual(@as(usize, 1), frame.text_layout_plan.lineCount());
1830
+ try std.testing.expectEqual(@as(usize, 1), frame.text_layout_cache_plan.entryCount());
1831
+ try std.testing.expectEqual(@as(usize, 1), frame.text_layout_cache_plan.uploadCount());
1832
+ try std.testing.expectEqual(@as(usize, 0), frame.changes.len);
1833
+ try expectRect(geometry.RectF.init(0, 0, 320, 200), frame.dirty_bounds);
1834
+
1835
+ const render_pass = frame.renderPass();
1836
+ try std.testing.expect(render_pass.requiresRender());
1837
+ try std.testing.expectEqual(CanvasRenderPassLoadAction.clear, render_pass.loadAction());
1838
+ try std.testing.expectEqual(@as(u64, 7), render_pass.frame_index);
1839
+ try std.testing.expectEqual(@as(u64, 88), render_pass.timestamp_ns);
1840
+ try std.testing.expectEqualDeep(geometry.SizeF.init(320, 200), render_pass.surface_size);
1841
+ try std.testing.expectEqual(@as(f32, 2), render_pass.scale);
1842
+ try std.testing.expectEqual(@as(usize, 2), render_pass.commandCount());
1843
+ try std.testing.expectEqual(@as(usize, 2), render_pass.batchCount());
1844
+ try std.testing.expectEqual(@as(usize, 2), render_pass.pipelineActionCount());
1845
+ try std.testing.expectEqual(@as(usize, 0), render_pass.pathGeometryCount());
1846
+ try std.testing.expectEqual(@as(usize, 0), render_pass.pathGeometryActionCount());
1847
+ try std.testing.expectEqual(@as(usize, 0), render_pass.pathGeometryVertexCount());
1848
+ try std.testing.expectEqual(@as(usize, 0), render_pass.pathGeometryIndexCount());
1849
+ try std.testing.expectEqual(@as(usize, 0), render_pass.imageCount());
1850
+ try std.testing.expectEqual(@as(usize, 0), render_pass.imageActionCount());
1851
+ try std.testing.expectEqual(@as(usize, 0), render_pass.layerCount());
1852
+ try std.testing.expectEqual(@as(usize, 0), render_pass.layerActionCount());
1853
+ try std.testing.expectEqual(@as(usize, 14), render_pass.encoderCommandCount());
1854
+ try std.testing.expectEqual(@as(usize, 7), render_pass.encoderCacheActionCount());
1855
+ try std.testing.expectEqual(@as(usize, 2), render_pass.encoderBindPipelineCount());
1856
+ try std.testing.expectEqual(@as(usize, 2), render_pass.encoderDrawBatchCount());
1857
+ try std.testing.expectEqual(@as(usize, 2), render_pass.resourceCount());
1858
+ try std.testing.expectEqual(@as(usize, 2), render_pass.resourceActionCount());
1859
+ try std.testing.expectEqual(@as(usize, 2), render_pass.glyphAtlasEntryCount());
1860
+ try std.testing.expectEqual(@as(usize, 2), render_pass.glyphAtlasActionCount());
1861
+ try std.testing.expectEqual(@as(usize, 1), render_pass.textLayoutCount());
1862
+ try std.testing.expectEqual(@as(usize, 1), render_pass.textLayoutLineCount());
1863
+ try std.testing.expectEqual(@as(usize, 1), render_pass.textLayoutActionCount());
1864
+ try std.testing.expectEqual(RenderPipelineCacheActionKind.upload, render_pass.pipeline_actions[0].kind);
1865
+ try std.testing.expectEqual(RenderResourceCacheActionKind.upload, render_pass.resource_actions[0].kind);
1866
+ try std.testing.expectEqual(GlyphAtlasCacheActionKind.upload, render_pass.glyph_atlas_actions[0].kind);
1867
+ try std.testing.expectEqual(TextLayoutCacheActionKind.upload, render_pass.text_layout_actions[0].kind);
1868
+ try expectRect(geometry.RectF.init(0, 0, 320, 200), render_pass.scissorBounds());
1869
+
1870
+ var encoder_commands: [16]RenderEncoderCommand = undefined;
1871
+ const encoder_plan = try render_pass.encoderPlan(&encoder_commands);
1872
+ try std.testing.expectEqual(@as(usize, 14), encoder_plan.commandCount());
1873
+ try std.testing.expectEqual(@as(usize, 7), encoder_plan.cacheActionCount());
1874
+ try std.testing.expectEqual(@as(usize, 2), encoder_plan.bindPipelineCount());
1875
+ try std.testing.expectEqual(@as(usize, 2), encoder_plan.drawBatchCount());
1876
+ switch (encoder_plan.commands[0]) {
1877
+ .begin_pass => |begin| {
1878
+ try std.testing.expectEqual(CanvasRenderPassLoadAction.clear, begin.load_action);
1879
+ try std.testing.expectEqualDeep(geometry.SizeF.init(320, 200), begin.surface_size);
1880
+ },
1881
+ else => return error.TestExpectedEqual,
1882
+ }
1883
+ switch (encoder_plan.commands[1]) {
1884
+ .set_scissor => |bounds| try expectRect(geometry.RectF.init(0, 0, 320, 200), bounds),
1885
+ else => return error.TestExpectedEqual,
1886
+ }
1887
+ switch (encoder_plan.commands[encoder_plan.commands.len - 1]) {
1888
+ .end_pass => {},
1889
+ else => return error.TestExpectedEqual,
1890
+ }
1891
+
1892
+ var render_pass_json_buffer: [8192]u8 = undefined;
1893
+ var render_pass_json_writer = std.Io.Writer.fixed(&render_pass_json_buffer);
1894
+ try render_pass.writeJson(&render_pass_json_writer);
1895
+ const render_pass_json = render_pass_json_writer.buffered();
1896
+ try std.testing.expect(std.mem.indexOf(u8, render_pass_json, "\"loadAction\":\"clear\"") != null);
1897
+ try std.testing.expect(std.mem.indexOf(u8, render_pass_json, "\"scissorBounds\":[0,0,320,200]") != null);
1898
+ try std.testing.expect(std.mem.indexOf(u8, render_pass_json, "\"commands\":[{\"index\":0,\"id\":1,\"opacity\":1,\"clip\":null,\"transform\":[1,0,0,1,0,0],\"localBounds\":[16,16,160,72],\"bounds\":[16,16,160,72],\"command\":{\"op\":\"fill_rounded_rect\"") != null);
1899
+ try std.testing.expect(std.mem.indexOf(u8, render_pass_json, "\"batches\":[{\"pipeline\":\"linear_gradient\",\"commandStart\":0,\"commandCount\":1") != null);
1900
+ try std.testing.expect(std.mem.indexOf(u8, render_pass_json, "\"pipelineActions\":[{\"kind\":\"upload\",\"pipeline\":\"linear_gradient\",\"batchIndex\":0,\"cacheIndex\":null") != null);
1901
+ try std.testing.expect(std.mem.indexOf(u8, render_pass_json, "\"pathGeometries\":[],\"pathGeometryActions\":[]") != null);
1902
+ try std.testing.expect(std.mem.indexOf(u8, render_pass_json, "\"images\":[],\"imageActions\":[]") != null);
1903
+ try std.testing.expect(std.mem.indexOf(u8, render_pass_json, "\"layers\":[],\"layerActions\":[]") != null);
1904
+ try std.testing.expect(std.mem.indexOf(u8, render_pass_json, "\"resources\":[{\"kind\":\"linear_gradient\",\"commandIndex\":0,\"id\":1") != null);
1905
+ try std.testing.expect(std.mem.indexOf(u8, render_pass_json, "\"resourceActions\":[{\"kind\":\"upload\",\"key\":{\"kind\":\"linear_gradient\"") != null);
1906
+ try std.testing.expect(std.mem.indexOf(u8, render_pass_json, "\"glyphAtlasEntries\":[{\"key\":{\"fontId\":5,\"glyphId\":79") != null);
1907
+ try std.testing.expect(std.mem.indexOf(u8, render_pass_json, "\"glyphAtlasActions\":[{\"kind\":\"upload\",\"key\":{\"fontId\":5,\"glyphId\":79") != null);
1908
+ try std.testing.expect(std.mem.indexOf(u8, render_pass_json, "\"textLayouts\":[{\"key\":{\"fontId\":5,\"size\":14") != null);
1909
+ try std.testing.expect(std.mem.indexOf(u8, render_pass_json, "\"textLayoutActions\":[{\"kind\":\"upload\",\"key\":{\"fontId\":5,\"size\":14") != null);
1910
+
1911
+ const diagnostics = frame.diagnostics();
1912
+ try std.testing.expectEqual(@as(u64, 7), diagnostics.frame_index);
1913
+ try std.testing.expectEqual(@as(usize, 2), diagnostics.command_count);
1914
+ try std.testing.expectEqual(@as(usize, 2), diagnostics.batch_count);
1915
+ try std.testing.expectEqual(@as(usize, 14), diagnostics.encoder_command_count);
1916
+ try std.testing.expectEqual(@as(usize, 7), diagnostics.encoder_cache_action_count);
1917
+ try std.testing.expectEqual(@as(usize, 2), diagnostics.encoder_bind_pipeline_count);
1918
+ try std.testing.expectEqual(@as(usize, 2), diagnostics.encoder_draw_batch_count);
1919
+ try std.testing.expectEqual(@as(usize, 2), diagnostics.pipeline_count);
1920
+ try std.testing.expectEqual(@as(usize, 2), diagnostics.pipeline_upload_count);
1921
+ try std.testing.expectEqual(@as(usize, 0), diagnostics.pipeline_retain_count);
1922
+ try std.testing.expectEqual(@as(usize, 0), diagnostics.pipeline_evict_count);
1923
+ try std.testing.expectEqual(@as(usize, 0), diagnostics.path_geometry_count);
1924
+ try std.testing.expectEqual(@as(usize, 0), diagnostics.path_geometry_vertex_count);
1925
+ try std.testing.expectEqual(@as(usize, 0), diagnostics.path_geometry_index_count);
1926
+ try std.testing.expectEqual(@as(usize, 0), diagnostics.path_geometry_upload_count);
1927
+ try std.testing.expectEqual(@as(usize, 0), diagnostics.path_geometry_retain_count);
1928
+ try std.testing.expectEqual(@as(usize, 0), diagnostics.path_geometry_evict_count);
1929
+ try std.testing.expectEqual(@as(usize, 0), diagnostics.image_count);
1930
+ try std.testing.expectEqual(@as(usize, 0), diagnostics.image_upload_count);
1931
+ try std.testing.expectEqual(@as(usize, 0), diagnostics.image_retain_count);
1932
+ try std.testing.expectEqual(@as(usize, 0), diagnostics.image_evict_count);
1933
+ try std.testing.expectEqual(@as(usize, 0), diagnostics.layer_count);
1934
+ try std.testing.expectEqual(@as(usize, 0), diagnostics.layer_opacity_count);
1935
+ try std.testing.expectEqual(@as(usize, 0), diagnostics.layer_clip_count);
1936
+ try std.testing.expectEqual(@as(usize, 0), diagnostics.layer_transform_count);
1937
+ try std.testing.expectEqual(@as(usize, 0), diagnostics.layer_upload_count);
1938
+ try std.testing.expectEqual(@as(usize, 0), diagnostics.layer_retain_count);
1939
+ try std.testing.expectEqual(@as(usize, 0), diagnostics.layer_evict_count);
1940
+ try std.testing.expectEqual(@as(usize, 2), diagnostics.resource_count);
1941
+ try std.testing.expectEqual(@as(usize, 2), diagnostics.resource_upload_count);
1942
+ try std.testing.expectEqual(@as(usize, 0), diagnostics.resource_retain_count);
1943
+ try std.testing.expectEqual(@as(usize, 0), diagnostics.resource_evict_count);
1944
+ try std.testing.expectEqual(@as(usize, 2), diagnostics.glyph_atlas_entry_count);
1945
+ try std.testing.expectEqual(@as(usize, 2), diagnostics.glyph_atlas_upload_count);
1946
+ try std.testing.expectEqual(@as(usize, 0), diagnostics.glyph_atlas_retain_count);
1947
+ try std.testing.expectEqual(@as(usize, 0), diagnostics.glyph_atlas_evict_count);
1948
+ try std.testing.expectEqual(@as(usize, 1), diagnostics.text_layout_count);
1949
+ try std.testing.expectEqual(@as(usize, 1), diagnostics.text_layout_line_count);
1950
+ try std.testing.expectEqual(@as(usize, 1), diagnostics.text_layout_upload_count);
1951
+ try std.testing.expectEqual(@as(usize, 0), diagnostics.text_layout_retain_count);
1952
+ try std.testing.expectEqual(@as(usize, 0), diagnostics.text_layout_evict_count);
1953
+ try std.testing.expectEqual(@as(usize, 0), diagnostics.change_count);
1954
+ try std.testing.expect(diagnostics.full_repaint);
1955
+ try std.testing.expect(diagnostics.requires_render);
1956
+ try expectRect(geometry.RectF.init(0, 0, 320, 200), diagnostics.dirty_bounds);
1957
+ try std.testing.expect(!diagnostics.budgetOk());
1958
+ try std.testing.expect(diagnostics.budget_status.commands_over);
1959
+ try std.testing.expect(!diagnostics.budget_status.batches_over);
1960
+ try std.testing.expect(diagnostics.budget_status.encoder_commands_over);
1961
+ try std.testing.expect(!diagnostics.budget_status.pipelines_over);
1962
+ try std.testing.expect(diagnostics.budget_status.pipeline_uploads_over);
1963
+ try std.testing.expect(!diagnostics.budget_status.path_geometries_over);
1964
+ try std.testing.expect(!diagnostics.budget_status.path_geometry_uploads_over);
1965
+ try std.testing.expect(!diagnostics.budget_status.images_over);
1966
+ try std.testing.expect(!diagnostics.budget_status.image_uploads_over);
1967
+ try std.testing.expect(!diagnostics.budget_status.layers_over);
1968
+ try std.testing.expect(!diagnostics.budget_status.layer_uploads_over);
1969
+ try std.testing.expect(!diagnostics.budget_status.resources_over);
1970
+ try std.testing.expect(diagnostics.budget_status.resource_uploads_over);
1971
+ try std.testing.expect(!diagnostics.budget_status.glyph_atlas_entries_over);
1972
+ try std.testing.expect(!diagnostics.budget_status.text_layouts_over);
1973
+ try std.testing.expect(!diagnostics.budget_status.text_layout_lines_over);
1974
+ try std.testing.expect(!diagnostics.budget_status.changes_over);
1975
+ try std.testing.expectEqual(@as(usize, 2), diagnostics.gpu_packet_command_count);
1976
+ try std.testing.expectEqual(@as(usize, 7), diagnostics.gpu_packet_cache_action_count);
1977
+ try std.testing.expectEqual(@as(usize, 2), diagnostics.gpu_packet_cached_resource_command_count);
1978
+ try std.testing.expectEqual(@as(usize, 0), diagnostics.gpu_packet_unsupported_command_count);
1979
+ try std.testing.expect(diagnostics.gpu_packet_representable);
1980
+ try std.testing.expectEqual(@as(usize, 4), diagnostics.budget_status.exceededCount());
1981
+ try std.testing.expectEqual(@as(usize, 4), frame.budgetStatus().exceededCount());
1982
+
1983
+ var diagnostics_json_buffer: [2048]u8 = undefined;
1984
+ var diagnostics_json_writer = std.Io.Writer.fixed(&diagnostics_json_buffer);
1985
+ try frame.writeDiagnosticsJson(&diagnostics_json_writer);
1986
+ try std.testing.expectEqualStrings(
1987
+ "{\"frameIndex\":7,\"commandCount\":2,\"batchCount\":2,\"encoderCommandCount\":14,\"encoderCacheActionCount\":7,\"encoderBindPipelineCount\":2,\"encoderDrawBatchCount\":2,\"pipelineCount\":2,\"pipelineUploadCount\":2,\"pipelineRetainCount\":0,\"pipelineEvictCount\":0,\"pathGeometryCount\":0,\"pathGeometryVertexCount\":0,\"pathGeometryIndexCount\":0,\"pathGeometryUploadCount\":0,\"pathGeometryRetainCount\":0,\"pathGeometryEvictCount\":0,\"layerCount\":0,\"layerOpacityCount\":0,\"layerClipCount\":0,\"layerTransformCount\":0,\"layerUploadCount\":0,\"layerRetainCount\":0,\"layerEvictCount\":0,\"imageCount\":0,\"imageUploadCount\":0,\"imageRetainCount\":0,\"imageEvictCount\":0,\"resourceCount\":2,\"resourceUploadCount\":2,\"resourceRetainCount\":0,\"resourceEvictCount\":0,\"visualEffectCount\":0,\"visualEffectShadowCount\":0,\"visualEffectBlurCount\":0,\"visualEffectUploadCount\":0,\"visualEffectRetainCount\":0,\"visualEffectEvictCount\":0,\"glyphAtlasEntryCount\":2,\"glyphAtlasUploadCount\":2,\"glyphAtlasRetainCount\":0,\"glyphAtlasEvictCount\":0,\"textLayoutCount\":1,\"textLayoutLineCount\":1,\"textLayoutUploadCount\":1,\"textLayoutRetainCount\":0,\"textLayoutEvictCount\":0,\"gpuPacketCommandCount\":2,\"gpuPacketCacheActionCount\":7,\"gpuPacketCachedResourceCommandCount\":2,\"gpuPacketUnsupportedCommandCount\":0,\"gpuPacketRepresentable\":true,\"changeCount\":0,\"budgetExceededCount\":4,\"budgetOk\":false,\"fullRepaint\":true,\"requiresRender\":true,\"dirtyBounds\":[0,0,320,200]}",
1988
+ diagnostics_json_writer.buffered(),
1989
+ );
1990
+
1991
+ var clean_json_buffer: [2048]u8 = undefined;
1992
+ var clean_json_writer = std.Io.Writer.fixed(&clean_json_buffer);
1993
+ try (CanvasFrameDiagnostics{ .frame_index = 8 }).writeJson(&clean_json_writer);
1994
+ try std.testing.expectEqualStrings(
1995
+ "{\"frameIndex\":8,\"commandCount\":0,\"batchCount\":0,\"encoderCommandCount\":0,\"encoderCacheActionCount\":0,\"encoderBindPipelineCount\":0,\"encoderDrawBatchCount\":0,\"pipelineCount\":0,\"pipelineUploadCount\":0,\"pipelineRetainCount\":0,\"pipelineEvictCount\":0,\"pathGeometryCount\":0,\"pathGeometryVertexCount\":0,\"pathGeometryIndexCount\":0,\"pathGeometryUploadCount\":0,\"pathGeometryRetainCount\":0,\"pathGeometryEvictCount\":0,\"layerCount\":0,\"layerOpacityCount\":0,\"layerClipCount\":0,\"layerTransformCount\":0,\"layerUploadCount\":0,\"layerRetainCount\":0,\"layerEvictCount\":0,\"imageCount\":0,\"imageUploadCount\":0,\"imageRetainCount\":0,\"imageEvictCount\":0,\"resourceCount\":0,\"resourceUploadCount\":0,\"resourceRetainCount\":0,\"resourceEvictCount\":0,\"visualEffectCount\":0,\"visualEffectShadowCount\":0,\"visualEffectBlurCount\":0,\"visualEffectUploadCount\":0,\"visualEffectRetainCount\":0,\"visualEffectEvictCount\":0,\"glyphAtlasEntryCount\":0,\"glyphAtlasUploadCount\":0,\"glyphAtlasRetainCount\":0,\"glyphAtlasEvictCount\":0,\"textLayoutCount\":0,\"textLayoutLineCount\":0,\"textLayoutUploadCount\":0,\"textLayoutRetainCount\":0,\"textLayoutEvictCount\":0,\"gpuPacketCommandCount\":0,\"gpuPacketCacheActionCount\":0,\"gpuPacketCachedResourceCommandCount\":0,\"gpuPacketUnsupportedCommandCount\":0,\"gpuPacketRepresentable\":true,\"changeCount\":0,\"budgetExceededCount\":0,\"budgetOk\":true,\"fullRepaint\":false,\"requiresRender\":false,\"dirtyBounds\":null}",
1996
+ clean_json_writer.buffered(),
1997
+ );
1998
+ }
1999
+
2000
+ test "render encoder plan skips clean passes and reports output overflow" {
2001
+ var clean_encoder_commands: [1]RenderEncoderCommand = undefined;
2002
+ const clean_plan = try (CanvasRenderPass{}).encoderPlan(&clean_encoder_commands);
2003
+ try std.testing.expectEqual(@as(usize, 0), clean_plan.commandCount());
2004
+
2005
+ const batches = [_]RenderBatch{.{ .pipeline = .solid, .command_start = 0, .command_count = 1 }};
2006
+ const pass = CanvasRenderPass{
2007
+ .full_repaint = true,
2008
+ .batches = &batches,
2009
+ };
2010
+ var encoder_commands: [4]RenderEncoderCommand = undefined;
2011
+ const plan = try pass.encoderPlan(&encoder_commands);
2012
+ try std.testing.expectEqual(@as(usize, 4), plan.commandCount());
2013
+ try std.testing.expectEqual(@as(usize, 1), plan.bindPipelineCount());
2014
+ try std.testing.expectEqual(@as(usize, 1), plan.drawBatchCount());
2015
+
2016
+ var too_small: [3]RenderEncoderCommand = undefined;
2017
+ try std.testing.expectError(error.RenderEncoderListFull, pass.encoderPlan(&too_small));
2018
+ }
2019
+
2020
+ test "canvas render pass builds gpu packet for backend handoff" {
2021
+ const stops = [_]GradientStop{
2022
+ .{ .offset = 0, .color = Color.rgb8(255, 255, 255) },
2023
+ .{ .offset = 1, .color = Color.rgb8(37, 99, 235) },
2024
+ };
2025
+ const path = [_]PathElement{
2026
+ .{ .verb = .move_to, .points = .{ geometry.PointF.init(0, 0), geometry.PointF.zero(), geometry.PointF.zero() } },
2027
+ .{ .verb = .line_to, .points = .{ geometry.PointF.init(12, 0), geometry.PointF.zero(), geometry.PointF.zero() } },
2028
+ .{ .verb = .line_to, .points = .{ geometry.PointF.init(0, 12), geometry.PointF.zero(), geometry.PointF.zero() } },
2029
+ .{ .verb = .close },
2030
+ };
2031
+ const commands = [_]CanvasCommand{
2032
+ .{ .fill_rect = .{ .id = 1, .rect = geometry.RectF.init(0, 0, 12, 12), .fill = .{ .color = Color.rgb8(255, 255, 255) } } },
2033
+ .{ .fill_rounded_rect = .{ .id = 2, .rect = geometry.RectF.init(16, 0, 24, 12), .radius = .{ .top_left = 3, .top_right = 5, .bottom_right = 6, .bottom_left = 2 }, .fill = .{ .linear_gradient = .{
2034
+ .start = geometry.PointF.init(16, 0),
2035
+ .end = geometry.PointF.init(40, 12),
2036
+ .stops = &stops,
2037
+ } } } },
2038
+ .{ .stroke_rect = .{ .id = 8, .rect = geometry.RectF.init(42, 0, 12, 12), .radius = Radius.all(3), .stroke = .{
2039
+ .fill = .{ .color = Color.rgb8(203, 213, 225) },
2040
+ .width = 2,
2041
+ } } },
2042
+ .{ .draw_line = .{ .id = 9, .from = geometry.PointF.init(58, 2), .to = geometry.PointF.init(70, 14), .stroke = .{
2043
+ .fill = .{ .linear_gradient = .{
2044
+ .start = geometry.PointF.init(58, 2),
2045
+ .end = geometry.PointF.init(70, 14),
2046
+ .stops = &stops,
2047
+ } },
2048
+ .width = 3,
2049
+ } } },
2050
+ .{ .fill_path = .{ .id = 3, .elements = &path, .fill = .{ .color = Color.rgb8(15, 23, 42) } } },
2051
+ .{ .draw_image = .{
2052
+ .id = 4,
2053
+ .image_id = 42,
2054
+ .src = geometry.RectF.init(4, 8, 32, 24),
2055
+ .dst = geometry.RectF.init(44, 0, 16, 16),
2056
+ .opacity = 0.75,
2057
+ .fit = .cover,
2058
+ .sampling = .nearest,
2059
+ } },
2060
+ .{ .draw_text = .{
2061
+ .id = 5,
2062
+ .font_id = 7,
2063
+ .size = 12,
2064
+ .origin = geometry.PointF.init(0, 32),
2065
+ .color = Color.rgb8(15, 23, 42),
2066
+ .text = "Hi",
2067
+ .text_layout = .{ .max_width = 80, .line_height = 16 },
2068
+ } },
2069
+ .{ .shadow = .{
2070
+ .id = 6,
2071
+ .rect = geometry.RectF.init(0, 36, 40, 20),
2072
+ .radius = Radius.all(6),
2073
+ .offset = geometry.OffsetF.init(2, 3),
2074
+ .blur = 8,
2075
+ .spread = 1,
2076
+ .color = Color.rgba8(15, 23, 42, 60),
2077
+ } },
2078
+ .{ .blur = .{ .id = 7, .rect = geometry.RectF.init(44, 36, 20, 20), .radius = 4 } },
2079
+ };
2080
+
2081
+ var render_commands: [commands.len]RenderCommand = undefined;
2082
+ var render_batches: [commands.len]RenderBatch = undefined;
2083
+ var pipeline_cache_entries: [commands.len]RenderPipelineCacheEntry = undefined;
2084
+ var pipeline_cache_actions: [commands.len]RenderPipelineCacheAction = undefined;
2085
+ var path_geometries: [1]RenderPathGeometry = undefined;
2086
+ var path_geometry_cache_entries: [1]RenderPathGeometryCacheEntry = undefined;
2087
+ var path_geometry_cache_actions: [1]RenderPathGeometryCacheAction = undefined;
2088
+ var images: [1]RenderImage = undefined;
2089
+ var image_cache_entries: [1]RenderImageCacheEntry = undefined;
2090
+ var image_cache_actions: [1]RenderImageCacheAction = undefined;
2091
+ var resources: [6]RenderResource = undefined;
2092
+ var resource_cache_entries: [6]RenderResourceCacheEntry = undefined;
2093
+ var resource_cache_actions: [6]RenderResourceCacheAction = undefined;
2094
+ var visual_effects: [2]VisualEffect = undefined;
2095
+ var visual_effect_cache_entries: [2]VisualEffectCacheEntry = undefined;
2096
+ var visual_effect_cache_actions: [2]VisualEffectCacheAction = undefined;
2097
+ var glyphs: [2]GlyphAtlasEntry = undefined;
2098
+ var glyph_cache_entries: [2]GlyphAtlasCacheEntry = undefined;
2099
+ var glyph_cache_actions: [2]GlyphAtlasCacheAction = undefined;
2100
+ var text_layouts: [1]TextLayoutPlan = undefined;
2101
+ var text_layout_lines: [1]TextLine = undefined;
2102
+ var text_layout_cache_entries: [1]TextLayoutCacheEntry = undefined;
2103
+ var text_layout_cache_actions: [1]TextLayoutCacheAction = undefined;
2104
+ var changes: [commands.len]DiffChange = undefined;
2105
+ const frame = try (DisplayList{ .commands = &commands }).framePlan(null, .{
2106
+ .frame_index = 11,
2107
+ .timestamp_ns = 1234,
2108
+ .surface_size = geometry.SizeF.init(96, 72),
2109
+ }, .{
2110
+ .render_commands = &render_commands,
2111
+ .render_batches = &render_batches,
2112
+ .pipeline_cache_entries = &pipeline_cache_entries,
2113
+ .pipeline_cache_actions = &pipeline_cache_actions,
2114
+ .path_geometries = &path_geometries,
2115
+ .path_geometry_cache_entries = &path_geometry_cache_entries,
2116
+ .path_geometry_cache_actions = &path_geometry_cache_actions,
2117
+ .images = &images,
2118
+ .image_cache_entries = &image_cache_entries,
2119
+ .image_cache_actions = &image_cache_actions,
2120
+ .resources = &resources,
2121
+ .resource_cache_entries = &resource_cache_entries,
2122
+ .resource_cache_actions = &resource_cache_actions,
2123
+ .visual_effects = &visual_effects,
2124
+ .visual_effect_cache_entries = &visual_effect_cache_entries,
2125
+ .visual_effect_cache_actions = &visual_effect_cache_actions,
2126
+ .glyph_atlas_entries = &glyphs,
2127
+ .glyph_atlas_cache_entries = &glyph_cache_entries,
2128
+ .glyph_atlas_cache_actions = &glyph_cache_actions,
2129
+ .text_layout_plans = &text_layouts,
2130
+ .text_layout_lines = &text_layout_lines,
2131
+ .text_layout_cache_entries = &text_layout_cache_entries,
2132
+ .text_layout_cache_actions = &text_layout_cache_actions,
2133
+ .changes = &changes,
2134
+ });
2135
+
2136
+ var gpu_commands: [commands.len]CanvasGpuCommand = undefined;
2137
+ const packet = try frame.gpuPacket(&gpu_commands);
2138
+ try std.testing.expect(packet.requiresRender());
2139
+ try std.testing.expect(packet.fullyRepresentable());
2140
+ try std.testing.expectEqual(@as(u64, 11), packet.frame_index);
2141
+ try std.testing.expectEqual(@as(u64, 1234), packet.timestamp_ns);
2142
+ try std.testing.expectEqual(CanvasRenderPassLoadAction.clear, packet.load_action);
2143
+ try expectRect(geometry.RectF.init(0, 0, 96, 72), packet.scissor.?);
2144
+ try std.testing.expectEqual(@as(usize, commands.len), packet.commandCount());
2145
+ try std.testing.expectEqual(frame.renderPass().batchCount(), packet.batch_count);
2146
+ try std.testing.expectEqual(frame.renderPass().encoderCacheActionCount(), packet.cacheActionCount());
2147
+ try std.testing.expectEqual(@as(usize, 7), packet.cachedResourceCommandCount());
2148
+ try std.testing.expectEqual(@as(usize, 0), packet.unsupported_command_count);
2149
+
2150
+ try std.testing.expectEqual(CanvasGpuCommandKind.fill_rect_solid, packet.commands[0].kind);
2151
+ try std.testing.expectEqual(@as(?RenderPipelineKind, .solid), packet.commands[0].pipeline);
2152
+ switch (packet.commands[0].shape) {
2153
+ .rect => |rect_value| try std.testing.expectEqualDeep(geometry.RectF.init(0, 0, 12, 12), rect_value),
2154
+ else => return error.TestExpectedEqual,
2155
+ }
2156
+ try expectGpuPaintColor(Color.rgb8(255, 255, 255), packet.commands[0].paint);
2157
+ try std.testing.expect(!packet.commands[0].usesCachedResource());
2158
+ try std.testing.expectEqual(CanvasGpuCommandKind.fill_rounded_rect_gradient, packet.commands[1].kind);
2159
+ try std.testing.expectEqual(@as(?RenderPipelineKind, .linear_gradient), packet.commands[1].pipeline);
2160
+ switch (packet.commands[1].shape) {
2161
+ .rounded_rect => |rounded_rect| {
2162
+ try std.testing.expectEqualDeep(geometry.RectF.init(16, 0, 24, 12), rounded_rect.rect);
2163
+ try std.testing.expectEqualDeep(Radius{ .top_left = 3, .top_right = 5, .bottom_right = 6, .bottom_left = 2 }, rounded_rect.radius);
2164
+ },
2165
+ else => return error.TestExpectedEqual,
2166
+ }
2167
+ switch (packet.commands[1].paint) {
2168
+ .linear_gradient => |gradient| {
2169
+ try std.testing.expectEqualDeep(geometry.PointF.init(16, 0), gradient.start);
2170
+ try std.testing.expectEqualDeep(geometry.PointF.init(40, 12), gradient.end);
2171
+ try std.testing.expectEqual(@as(usize, 2), gradient.stops.len);
2172
+ },
2173
+ else => return error.TestExpectedEqual,
2174
+ }
2175
+ try std.testing.expect(packet.commands[1].uses_resource);
2176
+ try std.testing.expectEqual(CanvasGpuCommandKind.stroke_rect_solid, packet.commands[2].kind);
2177
+ switch (packet.commands[2].shape) {
2178
+ .stroke_rect => |stroke_rect| {
2179
+ try std.testing.expectEqualDeep(geometry.RectF.init(42, 0, 12, 12), stroke_rect.rect);
2180
+ try std.testing.expectEqualDeep(Radius.all(3), stroke_rect.radius);
2181
+ try std.testing.expectEqual(@as(f32, 2), stroke_rect.width);
2182
+ },
2183
+ else => return error.TestExpectedEqual,
2184
+ }
2185
+ try expectGpuPaintColor(Color.rgb8(203, 213, 225), packet.commands[2].paint);
2186
+ try std.testing.expectEqual(@as(f32, 2), packet.commands[2].stroke_width);
2187
+ try std.testing.expectEqual(CanvasGpuCommandKind.draw_line_gradient, packet.commands[3].kind);
2188
+ switch (packet.commands[3].shape) {
2189
+ .line => |line| {
2190
+ try std.testing.expectEqualDeep(geometry.PointF.init(58, 2), line.from);
2191
+ try std.testing.expectEqualDeep(geometry.PointF.init(70, 14), line.to);
2192
+ try std.testing.expectEqual(@as(f32, 3), line.width);
2193
+ },
2194
+ else => return error.TestExpectedEqual,
2195
+ }
2196
+ switch (packet.commands[3].paint) {
2197
+ .linear_gradient => |gradient| {
2198
+ try std.testing.expectEqualDeep(geometry.PointF.init(58, 2), gradient.start);
2199
+ try std.testing.expectEqualDeep(geometry.PointF.init(70, 14), gradient.end);
2200
+ },
2201
+ else => return error.TestExpectedEqual,
2202
+ }
2203
+ try std.testing.expectEqual(CanvasGpuCommandKind.fill_path, packet.commands[4].kind);
2204
+ try std.testing.expect(packet.commands[4].uses_path_geometry);
2205
+ switch (packet.commands[4].shape) {
2206
+ .path => |elements| {
2207
+ try std.testing.expectEqual(@as(usize, 4), elements.len);
2208
+ try std.testing.expectEqual(PathVerb.move_to, elements[0].verb);
2209
+ try std.testing.expectEqual(PathVerb.line_to, elements[1].verb);
2210
+ try std.testing.expectEqual(PathVerb.close, elements[3].verb);
2211
+ },
2212
+ else => return error.TestExpectedEqual,
2213
+ }
2214
+ try expectGpuPaintColor(Color.rgb8(15, 23, 42), packet.commands[4].paint);
2215
+ try std.testing.expectEqual(CanvasGpuCommandKind.draw_image, packet.commands[5].kind);
2216
+ try std.testing.expect(packet.commands[5].uses_image);
2217
+ try std.testing.expect(packet.commands[5].image != null);
2218
+ try std.testing.expectEqual(@as(ImageId, 42), packet.commands[5].image.?.image_id);
2219
+ try std.testing.expectEqualDeep(geometry.RectF.init(4, 8, 32, 24), packet.commands[5].image.?.src.?);
2220
+ try std.testing.expectEqualDeep(geometry.RectF.init(44, 0, 16, 16), packet.commands[5].image.?.dst);
2221
+ try std.testing.expectEqual(@as(f32, 0.75), packet.commands[5].image.?.opacity);
2222
+ try std.testing.expectEqual(ImageFit.cover, packet.commands[5].image.?.fit);
2223
+ try std.testing.expectEqual(ImageSampling.nearest, packet.commands[5].image.?.sampling);
2224
+ try std.testing.expectEqual(CanvasGpuCommandKind.draw_text, packet.commands[6].kind);
2225
+ try std.testing.expect(packet.commands[6].uses_glyph_atlas);
2226
+ try std.testing.expect(packet.commands[6].uses_text_layout);
2227
+ try expectGpuPaintColor(Color.rgb8(15, 23, 42), packet.commands[6].paint);
2228
+ try std.testing.expect(packet.commands[6].text != null);
2229
+ try std.testing.expectEqual(@as(FontId, 7), packet.commands[6].text.?.font_id);
2230
+ try std.testing.expectEqual(@as(f32, 12), packet.commands[6].text.?.size);
2231
+ try std.testing.expectEqualDeep(geometry.PointF.init(0, 32), packet.commands[6].text.?.origin);
2232
+ try std.testing.expectEqualDeep(Color.rgb8(15, 23, 42), packet.commands[6].text.?.color);
2233
+ try std.testing.expectEqualStrings("Hi", packet.commands[6].text.?.text);
2234
+ try std.testing.expect(packet.commands[6].text.?.text_layout != null);
2235
+ try std.testing.expectEqual(@as(f32, 80), packet.commands[6].text.?.text_layout.?.max_width);
2236
+ try std.testing.expectEqual(@as(f32, 16), packet.commands[6].text.?.text_layout.?.line_height);
2237
+ try std.testing.expectEqual(CanvasGpuCommandKind.shadow, packet.commands[7].kind);
2238
+ try std.testing.expect(packet.commands[7].uses_visual_effect);
2239
+ switch (packet.commands[7].effect) {
2240
+ .shadow => |shadow| {
2241
+ try std.testing.expectEqualDeep(geometry.RectF.init(0, 36, 40, 20), shadow.rect);
2242
+ try std.testing.expectEqualDeep(Radius.all(6), shadow.radius);
2243
+ try std.testing.expectEqualDeep(geometry.OffsetF.init(2, 3), shadow.offset);
2244
+ try std.testing.expectEqual(@as(f32, 8), shadow.blur);
2245
+ try std.testing.expectEqual(@as(f32, 1), shadow.spread);
2246
+ try std.testing.expectEqualDeep(Color.rgba8(15, 23, 42, 60), shadow.color);
2247
+ },
2248
+ else => return error.TestExpectedEqual,
2249
+ }
2250
+ try std.testing.expectEqual(CanvasGpuCommandKind.blur, packet.commands[8].kind);
2251
+ try std.testing.expect(packet.commands[8].uses_visual_effect);
2252
+ switch (packet.commands[8].effect) {
2253
+ .blur => |blur| {
2254
+ try std.testing.expectEqualDeep(geometry.RectF.init(44, 36, 20, 20), blur.rect);
2255
+ try std.testing.expectEqual(@as(f32, 4), blur.radius);
2256
+ },
2257
+ else => return error.TestExpectedEqual,
2258
+ }
2259
+
2260
+ var packet_json_buffer: [16384]u8 = undefined;
2261
+ var packet_json_writer = std.Io.Writer.fixed(&packet_json_buffer);
2262
+ try packet.writeJson(&packet_json_writer);
2263
+ const packet_json = packet_json_writer.buffered();
2264
+ try std.testing.expect(std.mem.indexOf(u8, packet_json, "\"loadAction\":\"clear\"") != null);
2265
+ try std.testing.expect(std.mem.indexOf(u8, packet_json, "\"commandCount\":9") != null);
2266
+ try std.testing.expect(std.mem.indexOf(u8, packet_json, "\"kind\":\"fill_rounded_rect_gradient\"") != null);
2267
+ try std.testing.expect(std.mem.indexOf(u8, packet_json, "\"shape\":{\"kind\":\"rounded_rect\",\"rect\":[16,0,24,12],\"radius\":[3,5,6,2]}") != null);
2268
+ try std.testing.expect(std.mem.indexOf(u8, packet_json, "\"paint\":{\"kind\":\"linear_gradient\",\"start\":[16,0],\"end\":[40,12]") != null);
2269
+ try std.testing.expect(std.mem.indexOf(u8, packet_json, "\"shape\":{\"kind\":\"path\",\"path\":[{\"verb\":\"move_to\",\"points\":[[0,0]]},{\"verb\":\"line_to\"") != null);
2270
+ try std.testing.expect(std.mem.indexOf(u8, packet_json, "\"image\":{\"image\":42,\"src\":[4,8,32,24],\"dst\":[44,0,16,16],\"opacity\":0.75,\"fit\":\"cover\",\"sampling\":\"nearest\"}") != null);
2271
+ try std.testing.expect(std.mem.indexOf(u8, packet_json, "\"text\":{\"font\":7,\"size\":12,\"origin\":[0,32]") != null);
2272
+ try std.testing.expect(std.mem.indexOf(u8, packet_json, "\"effect\":{\"kind\":\"shadow\",\"rect\":[0,36,40,20],\"radius\":[6,6,6,6],\"offset\":[2,3],\"blur\":8,\"spread\":1") != null);
2273
+ try std.testing.expect(std.mem.indexOf(u8, packet_json, "\"effect\":{\"kind\":\"blur\",\"rect\":[44,36,20,20],\"radius\":4}") != null);
2274
+ }
2275
+
2276
+ test "canvas gpu packet skips clean passes and reports output overflow" {
2277
+ var clean_gpu_commands: [1]CanvasGpuCommand = undefined;
2278
+ const clean_packet = try (CanvasRenderPass{}).gpuPacket(&clean_gpu_commands);
2279
+ try std.testing.expect(!clean_packet.requiresRender());
2280
+ try std.testing.expect(clean_packet.fullyRepresentable());
2281
+ try std.testing.expectEqual(@as(usize, 0), clean_packet.commandCount());
2282
+ var clean_packet_json_buffer: [512]u8 = undefined;
2283
+ var clean_packet_json_writer = std.Io.Writer.fixed(&clean_packet_json_buffer);
2284
+ try clean_packet.writeJson(&clean_packet_json_writer);
2285
+ try std.testing.expectEqualStrings(
2286
+ "{\"frameIndex\":0,\"timestampNs\":0,\"surfaceWidth\":0,\"surfaceHeight\":0,\"scale\":1,\"loadAction\":\"skip\",\"requiresRender\":false,\"scissorBounds\":null,\"commandCount\":0,\"cacheActionCount\":0,\"cachedResourceCommandCount\":0,\"unsupportedCommandCount\":0,\"representable\":true,\"images\":[],\"imageActions\":[],\"commands\":[]}",
2287
+ clean_packet_json_writer.buffered(),
2288
+ );
2289
+
2290
+ const render_commands = [_]RenderCommand{.{
2291
+ .command = .{ .fill_rect = .{
2292
+ .id = 1,
2293
+ .rect = geometry.RectF.init(0, 0, 10, 10),
2294
+ .fill = .{ .color = Color.rgb8(255, 255, 255) },
2295
+ } },
2296
+ .id = 1,
2297
+ .local_bounds = geometry.RectF.init(0, 0, 10, 10),
2298
+ .bounds = geometry.RectF.init(0, 0, 10, 10),
2299
+ }};
2300
+ const pass = CanvasRenderPass{
2301
+ .full_repaint = true,
2302
+ .commands = &render_commands,
2303
+ };
2304
+ var no_gpu_commands: [0]CanvasGpuCommand = .{};
2305
+ try std.testing.expectError(error.CanvasGpuCommandListFull, pass.gpuPacket(&no_gpu_commands));
2306
+ }
2307
+
2308
+ test "canvas gpu packet text serializes engine measured line breaks" {
2309
+ // Tight intrinsic box: max_width equals the engine-measured width, so
2310
+ // the engine keeps one line and the packet must carry it unbroken —
2311
+ // the host draws these lines verbatim instead of re-wrapping with its
2312
+ // own line breaker.
2313
+ const tight_width = estimateTextWidth("Songs", 12);
2314
+ // 70 explicit lines exceed the packet line budget (64): the serializer
2315
+ // must fall back to `null` so the host keeps its wrapping fallback.
2316
+ const overflow_text = "a\n" ** 70;
2317
+ const commands = [_]CanvasGpuCommand{
2318
+ .{
2319
+ .command_index = 0,
2320
+ .kind = .draw_text,
2321
+ .pipeline = .glyph_run,
2322
+ .text = .{
2323
+ .font_id = 1,
2324
+ .size = 12,
2325
+ .origin = geometry.PointF.init(4, 40),
2326
+ .color = Color.rgb8(0, 0, 0),
2327
+ .text = "Songs",
2328
+ .text_layout = .{ .max_width = tight_width, .line_height = 16 },
2329
+ },
2330
+ .uses_glyph_atlas = true,
2331
+ .uses_text_layout = true,
2332
+ },
2333
+ .{
2334
+ .command_index = 1,
2335
+ .kind = .draw_text,
2336
+ .pipeline = .glyph_run,
2337
+ .text = .{
2338
+ .font_id = 1,
2339
+ .size = 12,
2340
+ .origin = geometry.PointF.init(4, 40),
2341
+ .color = Color.rgb8(0, 0, 0),
2342
+ .text = "Song s",
2343
+ .text_layout = .{ .max_width = estimateTextWidth("Song", 12) + 1, .line_height = 16 },
2344
+ },
2345
+ .uses_glyph_atlas = true,
2346
+ .uses_text_layout = true,
2347
+ },
2348
+ .{
2349
+ .command_index = 2,
2350
+ .kind = .draw_text,
2351
+ .pipeline = .glyph_run,
2352
+ .text = .{
2353
+ .font_id = 1,
2354
+ .size = 12,
2355
+ .origin = geometry.PointF.init(4, 40),
2356
+ .color = Color.rgb8(0, 0, 0),
2357
+ .text = overflow_text,
2358
+ .text_layout = .{ .line_height = 16 },
2359
+ },
2360
+ .uses_glyph_atlas = true,
2361
+ .uses_text_layout = true,
2362
+ },
2363
+ .{
2364
+ .command_index = 3,
2365
+ .kind = .draw_text,
2366
+ .pipeline = .glyph_run,
2367
+ .text = .{
2368
+ .font_id = 1,
2369
+ .size = 12,
2370
+ .origin = geometry.PointF.init(4, 40),
2371
+ .color = Color.rgb8(0, 0, 0),
2372
+ .text = "Free",
2373
+ },
2374
+ .uses_glyph_atlas = true,
2375
+ },
2376
+ // Multibyte exact fit: every byte of a UTF-8-heavy string rides one
2377
+ // unbroken line — the live-window shape of the system-monitor
2378
+ // "drops one trailing glyph per multibyte codepoint" finding, whose
2379
+ // packet leg was the host re-wrapping tight boxes.
2380
+ .{
2381
+ .command_index = 4,
2382
+ .kind = .draw_text,
2383
+ .pipeline = .glyph_run,
2384
+ .text = .{
2385
+ .font_id = 1,
2386
+ .size = 12,
2387
+ .origin = geometry.PointF.init(4, 40),
2388
+ .color = Color.rgb8(0, 0, 0),
2389
+ .text = "Live \xc2\xb7 every 2 s",
2390
+ .text_layout = .{ .max_width = estimateTextWidth("Live \xc2\xb7 every 2 s", 12), .line_height = 16 },
2391
+ },
2392
+ .uses_glyph_atlas = true,
2393
+ .uses_text_layout = true,
2394
+ },
2395
+ };
2396
+ const packet = CanvasGpuPacket{ .load_action = .clear, .commands = &commands };
2397
+
2398
+ var packet_json_buffer: [16384]u8 = undefined;
2399
+ var packet_json_writer = std.Io.Writer.fixed(&packet_json_buffer);
2400
+ try packet.writeJson(&packet_json_writer);
2401
+ const packet_json = packet_json_writer.buffered();
2402
+
2403
+ // Exact-fit box: exactly one line, the full text, at the pen origin.
2404
+ try std.testing.expect(std.mem.indexOf(u8, packet_json, "\"lines\":[{\"x\":4,\"baseline\":40,\"text\":\"Songs\"}]") != null);
2405
+ // Engine word wrap carries through: the trailing break is trimmed and
2406
+ // the second line advances one line height.
2407
+ try std.testing.expect(std.mem.indexOf(u8, packet_json, "\"lines\":[{\"x\":4,\"baseline\":40,\"text\":\"Song\"},{\"x\":4,\"baseline\":56,\"text\":\"s\"}]") != null);
2408
+ // Line-budget overflow degrades to null (host wrapping fallback).
2409
+ try std.testing.expect(std.mem.indexOf(u8, packet_json, "\"lines\":null") != null);
2410
+ // Multibyte exact fit: one line, all bytes present, tail intact.
2411
+ try std.testing.expect(std.mem.indexOf(u8, packet_json, "\"lines\":[{\"x\":4,\"baseline\":40,\"text\":\"Live \xc2\xb7 every 2 s\"}]") != null);
2412
+ // No layout options -> no lines key at all.
2413
+ try std.testing.expectEqual(@as(usize, 4), std.mem.count(u8, packet_json, "\"lines\":"));
2414
+ }
2415
+
2416
+ test "canvas gpu packet lines carry elided text with the trailing ellipsis" {
2417
+ const content = "Quarterly revenue report";
2418
+ const full_width = estimateTextWidth(content, 12);
2419
+ const commands = [_]CanvasGpuCommand{.{
2420
+ .command_index = 0,
2421
+ .kind = .draw_text,
2422
+ .pipeline = .glyph_run,
2423
+ .text = .{
2424
+ .font_id = 1,
2425
+ .size = 12,
2426
+ .origin = geometry.PointF.init(4, 40),
2427
+ .color = Color.rgb8(0, 0, 0),
2428
+ .text = content,
2429
+ .text_layout = .{ .max_width = full_width * 0.5, .line_height = 16, .wrap = .none },
2430
+ },
2431
+ .uses_glyph_atlas = true,
2432
+ .uses_text_layout = true,
2433
+ }};
2434
+ const packet = CanvasGpuPacket{ .load_action = .clear, .commands = &commands };
2435
+
2436
+ var json_buffer: [8192]u8 = undefined;
2437
+ var json_writer = std.Io.Writer.fixed(&json_buffer);
2438
+ try packet.writeJson(&json_writer);
2439
+ const packet_json = json_writer.buffered();
2440
+ // The line text is the kept prefix plus the marker — the host draws
2441
+ // the measured extent verbatim, never the full overflowing string.
2442
+ try std.testing.expect(std.mem.indexOf(u8, packet_json, "\xe2\x80\xa6\"}]") != null);
2443
+ try std.testing.expect(std.mem.indexOf(u8, packet_json, "\"text\":\"Quarterly revenue report\"}]") == null);
2444
+ // The full source text still rides the command (selection source).
2445
+ try std.testing.expect(std.mem.indexOf(u8, packet_json, "\"text\":\"Quarterly revenue report\",\"glyphs\"") != null);
2446
+
2447
+ // The binary encoding mirrors the JSON lines byte-for-byte.
2448
+ var binary_buffer: [8192]u8 = undefined;
2449
+ var binary_writer = std.Io.Writer.fixed(&binary_buffer);
2450
+ try packet.writeBinary(&binary_writer);
2451
+ const packet_binary = binary_writer.buffered();
2452
+ try std.testing.expect(std.mem.indexOf(u8, packet_binary, "\xe2\x80\xa6") != null);
2453
+ }
2454
+
2455
+ test "canvas gpu packet serializes image upload payloads" {
2456
+ const image_pixels = [_]u8{ 11, 22, 33, 255 };
2457
+ const image_resources = [_]ReferenceImage{.{
2458
+ .id = 42,
2459
+ .width = 1,
2460
+ .height = 1,
2461
+ .pixels = &image_pixels,
2462
+ }};
2463
+ const commands = [_]CanvasCommand{.{ .draw_image = .{
2464
+ .id = 7,
2465
+ .image_id = 42,
2466
+ .dst = geometry.RectF.init(0, 0, 8, 8),
2467
+ .sampling = .nearest,
2468
+ } }};
2469
+
2470
+ var render_commands: [1]RenderCommand = undefined;
2471
+ var render_batches: [1]RenderBatch = undefined;
2472
+ var images: [1]RenderImage = undefined;
2473
+ var image_cache_entries: [1]RenderImageCacheEntry = undefined;
2474
+ var image_cache_actions: [1]RenderImageCacheAction = undefined;
2475
+ var resources: [1]RenderResource = undefined;
2476
+ var resource_cache_entries: [1]RenderResourceCacheEntry = undefined;
2477
+ var resource_cache_actions: [1]RenderResourceCacheAction = undefined;
2478
+ var glyph_atlas_entries: [0]GlyphAtlasEntry = .{};
2479
+ var changes: [1]DiffChange = undefined;
2480
+ const frame = try (DisplayList{ .commands = &commands }).framePlan(null, .{
2481
+ .frame_index = 12,
2482
+ .surface_size = geometry.SizeF.init(8, 8),
2483
+ .image_resources = &image_resources,
2484
+ }, .{
2485
+ .render_commands = &render_commands,
2486
+ .render_batches = &render_batches,
2487
+ .images = &images,
2488
+ .image_cache_entries = &image_cache_entries,
2489
+ .image_cache_actions = &image_cache_actions,
2490
+ .resources = &resources,
2491
+ .resource_cache_entries = &resource_cache_entries,
2492
+ .resource_cache_actions = &resource_cache_actions,
2493
+ .glyph_atlas_entries = &glyph_atlas_entries,
2494
+ .changes = &changes,
2495
+ });
2496
+
2497
+ var gpu_commands: [1]CanvasGpuCommand = undefined;
2498
+ const packet = try frame.gpuPacket(&gpu_commands);
2499
+ try std.testing.expectEqual(@as(usize, 1), packet.images.len);
2500
+ try std.testing.expectEqual(@as(usize, 1), packet.image_actions.len);
2501
+ try std.testing.expectEqualSlices(u8, &image_pixels, packet.images[0].pixels);
2502
+
2503
+ var packet_json_buffer: [2048]u8 = undefined;
2504
+ var packet_json_writer = std.Io.Writer.fixed(&packet_json_buffer);
2505
+ try packet.writeJson(&packet_json_writer);
2506
+ const packet_json = packet_json_writer.buffered();
2507
+ try std.testing.expect(std.mem.indexOf(u8, packet_json, "\"images\":[{\"imageId\":42") != null);
2508
+ // Pixels never ride packet JSON — uploads travel the binary
2509
+ // side-channel; the packet carries the id + fingerprint reference.
2510
+ try std.testing.expect(std.mem.indexOf(u8, packet_json, "\"width\":1,\"height\":1,\"fingerprint\"") != null);
2511
+ try std.testing.expect(std.mem.indexOf(u8, packet_json, "\"pixels\"") == null);
2512
+ try std.testing.expect(std.mem.indexOf(u8, packet_json, "\"imageActions\":[{\"kind\":\"upload\"") != null);
2513
+ try std.testing.expect(std.mem.indexOf(u8, packet_json, "\"image\":{\"image\":42") != null);
2514
+
2515
+ var retained_render_commands: [1]RenderCommand = undefined;
2516
+ var retained_render_batches: [1]RenderBatch = undefined;
2517
+ var retained_images: [1]RenderImage = undefined;
2518
+ var retained_image_cache_entries: [1]RenderImageCacheEntry = undefined;
2519
+ var retained_image_cache_actions: [1]RenderImageCacheAction = undefined;
2520
+ var retained_resources: [1]RenderResource = undefined;
2521
+ var retained_resource_cache_entries: [1]RenderResourceCacheEntry = undefined;
2522
+ var retained_resource_cache_actions: [1]RenderResourceCacheAction = undefined;
2523
+ var retained_glyph_atlas_entries: [0]GlyphAtlasEntry = .{};
2524
+ var retained_changes: [1]DiffChange = undefined;
2525
+ const retained_frame = try (DisplayList{ .commands = &commands }).framePlan(null, .{
2526
+ .frame_index = 13,
2527
+ .surface_size = geometry.SizeF.init(8, 8),
2528
+ .full_repaint = true,
2529
+ .previous_image_cache = frame.image_cache_plan.entries,
2530
+ .image_resources = &image_resources,
2531
+ }, .{
2532
+ .render_commands = &retained_render_commands,
2533
+ .render_batches = &retained_render_batches,
2534
+ .images = &retained_images,
2535
+ .image_cache_entries = &retained_image_cache_entries,
2536
+ .image_cache_actions = &retained_image_cache_actions,
2537
+ .resources = &retained_resources,
2538
+ .resource_cache_entries = &retained_resource_cache_entries,
2539
+ .resource_cache_actions = &retained_resource_cache_actions,
2540
+ .glyph_atlas_entries = &retained_glyph_atlas_entries,
2541
+ .changes = &retained_changes,
2542
+ });
2543
+ try std.testing.expectEqual(@as(usize, 0), retained_frame.image_cache_plan.uploadCount());
2544
+ try std.testing.expectEqual(@as(usize, 1), retained_frame.image_cache_plan.retainCount());
2545
+
2546
+ var retained_gpu_commands: [1]CanvasGpuCommand = undefined;
2547
+ const retained_packet = try retained_frame.gpuPacket(&retained_gpu_commands);
2548
+ var retained_packet_json_buffer: [2048]u8 = undefined;
2549
+ var retained_packet_json_writer = std.Io.Writer.fixed(&retained_packet_json_buffer);
2550
+ try retained_packet.writeJson(&retained_packet_json_writer);
2551
+ const retained_packet_json = retained_packet_json_writer.buffered();
2552
+ try std.testing.expect(std.mem.indexOf(u8, retained_packet_json, "\"imageActions\":[{\"kind\":\"retain\"") != null);
2553
+ try std.testing.expect(std.mem.indexOf(u8, retained_packet_json, "\"width\":1,\"height\":1,\"fingerprint\"") != null);
2554
+ try std.testing.expect(std.mem.indexOf(u8, retained_packet_json, "\"pixels\"") == null);
2555
+ }
2556
+
2557
+ test "canvas frame plan carries path geometry cache actions" {
2558
+ const path = [_]PathElement{
2559
+ .{ .verb = .move_to, .points = .{ geometry.PointF.init(0, 0), geometry.PointF.zero(), geometry.PointF.zero() } },
2560
+ .{ .verb = .line_to, .points = .{ geometry.PointF.init(20, 0), geometry.PointF.zero(), geometry.PointF.zero() } },
2561
+ .{ .verb = .line_to, .points = .{ geometry.PointF.init(0, 20), geometry.PointF.zero(), geometry.PointF.zero() } },
2562
+ .{ .verb = .close },
2563
+ };
2564
+ const commands = [_]CanvasCommand{.{ .fill_path = .{
2565
+ .id = 1,
2566
+ .elements = &path,
2567
+ .fill = .{ .color = Color.rgb8(255, 255, 255) },
2568
+ } }};
2569
+
2570
+ var render_commands: [1]RenderCommand = undefined;
2571
+ var render_batches: [1]RenderBatch = undefined;
2572
+ var pipeline_cache_entries: [1]RenderPipelineCacheEntry = undefined;
2573
+ var pipeline_cache_actions: [1]RenderPipelineCacheAction = undefined;
2574
+ var path_geometries: [1]RenderPathGeometry = undefined;
2575
+ var path_geometry_cache_entries: [1]RenderPathGeometryCacheEntry = undefined;
2576
+ var path_geometry_cache_actions: [1]RenderPathGeometryCacheAction = undefined;
2577
+ var resources: [0]RenderResource = .{};
2578
+ var resource_cache_entries: [0]RenderResourceCacheEntry = .{};
2579
+ var resource_cache_actions: [0]RenderResourceCacheAction = .{};
2580
+ var glyphs: [0]GlyphAtlasEntry = .{};
2581
+ var changes: [1]DiffChange = undefined;
2582
+ const frame = try (DisplayList{ .commands = &commands }).framePlan(null, .{
2583
+ .frame_index = 4,
2584
+ .surface_size = geometry.SizeF.init(64, 64),
2585
+ }, .{
2586
+ .render_commands = &render_commands,
2587
+ .render_batches = &render_batches,
2588
+ .pipeline_cache_entries = &pipeline_cache_entries,
2589
+ .pipeline_cache_actions = &pipeline_cache_actions,
2590
+ .path_geometries = &path_geometries,
2591
+ .path_geometry_cache_entries = &path_geometry_cache_entries,
2592
+ .path_geometry_cache_actions = &path_geometry_cache_actions,
2593
+ .resources = &resources,
2594
+ .resource_cache_entries = &resource_cache_entries,
2595
+ .resource_cache_actions = &resource_cache_actions,
2596
+ .glyph_atlas_entries = &glyphs,
2597
+ .changes = &changes,
2598
+ });
2599
+
2600
+ try std.testing.expectEqual(@as(usize, 1), frame.path_geometry_plan.geometryCount());
2601
+ try std.testing.expectEqual(@as(usize, 3), frame.path_geometry_plan.vertexCount());
2602
+ try std.testing.expectEqual(@as(usize, 3), frame.path_geometry_plan.indexCount());
2603
+ try std.testing.expectEqual(@as(usize, 1), frame.path_geometry_cache_plan.entryCount());
2604
+ try std.testing.expectEqual(@as(usize, 1), frame.path_geometry_cache_plan.uploadCount());
2605
+ try std.testing.expectEqual(RenderPathGeometryCacheActionKind.upload, frame.path_geometry_cache_plan.actions[0].kind);
2606
+
2607
+ const render_pass = frame.renderPass();
2608
+ try std.testing.expectEqual(@as(usize, 1), render_pass.pathGeometryCount());
2609
+ try std.testing.expectEqual(@as(usize, 1), render_pass.pathGeometryActionCount());
2610
+ try std.testing.expectEqual(@as(usize, 3), render_pass.pathGeometryVertexCount());
2611
+ try std.testing.expectEqual(@as(usize, 3), render_pass.pathGeometryIndexCount());
2612
+ try std.testing.expectEqual(@as(usize, 2), render_pass.encoderCacheActionCount());
2613
+
2614
+ var encoder_commands: [8]RenderEncoderCommand = undefined;
2615
+ const encoder_plan = try render_pass.encoderPlan(&encoder_commands);
2616
+ try std.testing.expectEqual(@as(usize, 7), encoder_plan.commandCount());
2617
+ try std.testing.expectEqual(@as(usize, 2), encoder_plan.cacheActionCount());
2618
+ switch (encoder_plan.commands[2]) {
2619
+ .pipeline_cache => |action| try std.testing.expectEqual(RenderPipelineKind.path, action.pipeline),
2620
+ else => return error.TestExpectedEqual,
2621
+ }
2622
+ switch (encoder_plan.commands[3]) {
2623
+ .path_geometry_cache => |action| {
2624
+ try std.testing.expectEqual(RenderPathGeometryCacheActionKind.upload, action.kind);
2625
+ try std.testing.expectEqual(RenderPathGeometryKind.fill, action.key.kind);
2626
+ try std.testing.expectEqual(@as(?ObjectId, 1), action.key.id);
2627
+ },
2628
+ else => return error.TestExpectedEqual,
2629
+ }
2630
+
2631
+ const diagnostics = frame.diagnostics();
2632
+ try std.testing.expectEqual(@as(usize, 1), diagnostics.path_geometry_count);
2633
+ try std.testing.expectEqual(@as(usize, 3), diagnostics.path_geometry_vertex_count);
2634
+ try std.testing.expectEqual(@as(usize, 3), diagnostics.path_geometry_index_count);
2635
+ try std.testing.expectEqual(@as(usize, 1), diagnostics.path_geometry_upload_count);
2636
+ }
2637
+
2638
+ test "canvas frame plan carries image cache actions" {
2639
+ const commands = [_]CanvasCommand{.{ .draw_image = .{
2640
+ .id = 1,
2641
+ .image_id = 42,
2642
+ .dst = geometry.RectF.init(8, 8, 24, 24),
2643
+ } }};
2644
+
2645
+ var render_commands: [1]RenderCommand = undefined;
2646
+ var render_batches: [1]RenderBatch = undefined;
2647
+ var pipeline_cache_entries: [1]RenderPipelineCacheEntry = undefined;
2648
+ var pipeline_cache_actions: [1]RenderPipelineCacheAction = undefined;
2649
+ var images: [1]RenderImage = undefined;
2650
+ var image_cache_entries: [1]RenderImageCacheEntry = undefined;
2651
+ var image_cache_actions: [1]RenderImageCacheAction = undefined;
2652
+ var resources: [1]RenderResource = undefined;
2653
+ var resource_cache_entries: [1]RenderResourceCacheEntry = undefined;
2654
+ var resource_cache_actions: [1]RenderResourceCacheAction = undefined;
2655
+ var glyphs: [0]GlyphAtlasEntry = .{};
2656
+ var changes: [1]DiffChange = undefined;
2657
+ const frame = try (DisplayList{ .commands = &commands }).framePlan(null, .{
2658
+ .frame_index = 6,
2659
+ .surface_size = geometry.SizeF.init(64, 64),
2660
+ }, .{
2661
+ .render_commands = &render_commands,
2662
+ .render_batches = &render_batches,
2663
+ .pipeline_cache_entries = &pipeline_cache_entries,
2664
+ .pipeline_cache_actions = &pipeline_cache_actions,
2665
+ .images = &images,
2666
+ .image_cache_entries = &image_cache_entries,
2667
+ .image_cache_actions = &image_cache_actions,
2668
+ .resources = &resources,
2669
+ .resource_cache_entries = &resource_cache_entries,
2670
+ .resource_cache_actions = &resource_cache_actions,
2671
+ .glyph_atlas_entries = &glyphs,
2672
+ .changes = &changes,
2673
+ });
2674
+
2675
+ try std.testing.expectEqual(@as(usize, 1), frame.image_plan.imageCount());
2676
+ try std.testing.expectEqual(@as(usize, 1), frame.image_plan.drawCount());
2677
+ try std.testing.expectEqual(@as(ImageId, 42), frame.image_plan.images[0].image_id);
2678
+ try std.testing.expectEqual(@as(usize, 1), frame.image_cache_plan.entryCount());
2679
+ try std.testing.expectEqual(@as(usize, 1), frame.image_cache_plan.uploadCount());
2680
+ try std.testing.expectEqual(RenderImageCacheActionKind.upload, frame.image_cache_plan.actions[0].kind);
2681
+
2682
+ const render_pass = frame.renderPass();
2683
+ try std.testing.expectEqual(@as(usize, 1), render_pass.imageCount());
2684
+ try std.testing.expectEqual(@as(usize, 1), render_pass.imageActionCount());
2685
+ try std.testing.expectEqual(@as(usize, 3), render_pass.encoderCacheActionCount());
2686
+
2687
+ var encoder_commands: [8]RenderEncoderCommand = undefined;
2688
+ const encoder_plan = try render_pass.encoderPlan(&encoder_commands);
2689
+ try std.testing.expectEqual(@as(usize, 8), encoder_plan.commandCount());
2690
+ try std.testing.expectEqual(@as(usize, 3), encoder_plan.cacheActionCount());
2691
+ switch (encoder_plan.commands[2]) {
2692
+ .pipeline_cache => |action| try std.testing.expectEqual(RenderPipelineKind.image, action.pipeline),
2693
+ else => return error.TestExpectedEqual,
2694
+ }
2695
+ switch (encoder_plan.commands[3]) {
2696
+ .image_cache => |action| {
2697
+ try std.testing.expectEqual(RenderImageCacheActionKind.upload, action.kind);
2698
+ try std.testing.expectEqual(@as(ImageId, 42), action.key.image_id);
2699
+ },
2700
+ else => return error.TestExpectedEqual,
2701
+ }
2702
+
2703
+ const diagnostics = frame.diagnostics();
2704
+ try std.testing.expectEqual(@as(usize, 1), diagnostics.image_count);
2705
+ try std.testing.expectEqual(@as(usize, 1), diagnostics.image_upload_count);
2706
+ try std.testing.expectEqual(@as(usize, 0), diagnostics.image_retain_count);
2707
+ try std.testing.expectEqual(@as(usize, 0), diagnostics.image_evict_count);
2708
+
2709
+ const profile = frame.profile();
2710
+ try std.testing.expectEqual(@as(u64, 6), profile.frame_index);
2711
+ try std.testing.expect(profile.requires_render);
2712
+ try std.testing.expect(profile.full_repaint);
2713
+ try std.testing.expectEqual(@as(usize, 3), profile.cache_action_count);
2714
+ try std.testing.expectEqual(@as(usize, 3), profile.cache_upload_count);
2715
+ try std.testing.expectEqual(@as(usize, 1), profile.image_count);
2716
+ try std.testing.expectEqual(CanvasFrameProfileRisk.high, profile.risk);
2717
+ }
2718
+
2719
+ test "canvas frame plan carries resource cache retain upload and evict actions" {
2720
+ const stops = [_]GradientStop{
2721
+ .{ .offset = 0, .color = Color.rgb8(255, 255, 255) },
2722
+ .{ .offset = 1, .color = Color.rgb8(24, 24, 27) },
2723
+ };
2724
+ const previous_commands = [_]CanvasCommand{
2725
+ .{ .fill_rect = .{ .id = 1, .rect = geometry.RectF.init(0, 0, 20, 20), .fill = .{ .linear_gradient = .{
2726
+ .start = geometry.PointF.init(0, 0),
2727
+ .end = geometry.PointF.init(20, 20),
2728
+ .stops = &stops,
2729
+ } } } },
2730
+ .{ .draw_image = .{ .id = 2, .image_id = 8, .dst = geometry.RectF.init(24, 0, 20, 20) } },
2731
+ };
2732
+ const next_commands = [_]CanvasCommand{
2733
+ .{ .fill_rect = .{ .id = 1, .rect = geometry.RectF.init(0, 0, 20, 20), .fill = .{ .linear_gradient = .{
2734
+ .start = geometry.PointF.init(0, 0),
2735
+ .end = geometry.PointF.init(20, 20),
2736
+ .stops = &stops,
2737
+ } } } },
2738
+ .{ .draw_text = .{
2739
+ .id = 3,
2740
+ .font_id = 7,
2741
+ .size = 12,
2742
+ .origin = geometry.PointF.init(24, 16),
2743
+ .color = Color.rgb8(15, 23, 42),
2744
+ .text = "Hi",
2745
+ } },
2746
+ };
2747
+
2748
+ var previous_render_commands: [2]RenderCommand = undefined;
2749
+ var previous_render_batches: [2]RenderBatch = undefined;
2750
+ var previous_resources: [2]RenderResource = undefined;
2751
+ var previous_cache_entries: [2]RenderResourceCacheEntry = undefined;
2752
+ var previous_cache_actions: [2]RenderResourceCacheAction = undefined;
2753
+ var previous_glyphs: [0]GlyphAtlasEntry = .{};
2754
+ var previous_changes: [0]DiffChange = .{};
2755
+ const previous_frame = try (DisplayList{ .commands = &previous_commands }).framePlan(null, .{
2756
+ .frame_index = 1,
2757
+ }, .{
2758
+ .render_commands = &previous_render_commands,
2759
+ .render_batches = &previous_render_batches,
2760
+ .resources = &previous_resources,
2761
+ .resource_cache_entries = &previous_cache_entries,
2762
+ .resource_cache_actions = &previous_cache_actions,
2763
+ .glyph_atlas_entries = &previous_glyphs,
2764
+ .changes = &previous_changes,
2765
+ });
2766
+
2767
+ var next_render_commands: [2]RenderCommand = undefined;
2768
+ var next_render_batches: [2]RenderBatch = undefined;
2769
+ var next_resources: [2]RenderResource = undefined;
2770
+ var next_cache_entries: [2]RenderResourceCacheEntry = undefined;
2771
+ var next_cache_actions: [3]RenderResourceCacheAction = undefined;
2772
+ var next_glyphs: [2]GlyphAtlasEntry = undefined;
2773
+ var next_glyph_cache_entries: [2]GlyphAtlasCacheEntry = undefined;
2774
+ var next_glyph_cache_actions: [2]GlyphAtlasCacheAction = undefined;
2775
+ var next_changes: [2]DiffChange = undefined;
2776
+ const next_frame = try (DisplayList{ .commands = &next_commands }).framePlan(.{ .commands = &previous_commands }, .{
2777
+ .frame_index = 2,
2778
+ .previous_resource_cache = previous_frame.resource_cache_plan.entries,
2779
+ }, .{
2780
+ .render_commands = &next_render_commands,
2781
+ .render_batches = &next_render_batches,
2782
+ .resources = &next_resources,
2783
+ .resource_cache_entries = &next_cache_entries,
2784
+ .resource_cache_actions = &next_cache_actions,
2785
+ .glyph_atlas_entries = &next_glyphs,
2786
+ .glyph_atlas_cache_entries = &next_glyph_cache_entries,
2787
+ .glyph_atlas_cache_actions = &next_glyph_cache_actions,
2788
+ .changes = &next_changes,
2789
+ });
2790
+
2791
+ try std.testing.expectEqual(@as(usize, 2), next_frame.resource_cache_plan.entryCount());
2792
+ try std.testing.expectEqual(@as(usize, 3), next_frame.resource_cache_plan.actionCount());
2793
+ try std.testing.expectEqual(@as(usize, 1), next_frame.resource_cache_plan.retainCount());
2794
+ try std.testing.expectEqual(@as(usize, 1), next_frame.resource_cache_plan.uploadCount());
2795
+ try std.testing.expectEqual(@as(usize, 1), next_frame.resource_cache_plan.evictCount());
2796
+ try std.testing.expectEqual(RenderResourceCacheActionKind.retain, next_frame.resource_cache_plan.actions[0].kind);
2797
+ try std.testing.expectEqual(RenderResourceKind.linear_gradient, next_frame.resource_cache_plan.actions[0].key.kind);
2798
+ try std.testing.expectEqual(RenderResourceCacheActionKind.upload, next_frame.resource_cache_plan.actions[1].kind);
2799
+ try std.testing.expectEqual(RenderResourceKind.glyph_run, next_frame.resource_cache_plan.actions[1].key.kind);
2800
+ try std.testing.expectEqual(RenderResourceCacheActionKind.evict, next_frame.resource_cache_plan.actions[2].kind);
2801
+ try std.testing.expectEqual(RenderResourceKind.image, next_frame.resource_cache_plan.actions[2].key.kind);
2802
+ try std.testing.expectEqual(@as(u64, 2), next_frame.resource_cache_plan.entries[0].last_used_frame);
2803
+ try std.testing.expectEqual(@as(usize, 2), next_frame.glyph_atlas_cache_plan.uploadCount());
2804
+
2805
+ const diagnostics = next_frame.diagnostics();
2806
+ try std.testing.expectEqual(@as(usize, 1), diagnostics.resource_retain_count);
2807
+ try std.testing.expectEqual(@as(usize, 1), diagnostics.resource_upload_count);
2808
+ try std.testing.expectEqual(@as(usize, 1), diagnostics.resource_evict_count);
2809
+ try std.testing.expectEqual(@as(usize, 2), diagnostics.glyph_atlas_upload_count);
2810
+ try std.testing.expectEqual(@as(usize, 0), diagnostics.glyph_atlas_retain_count);
2811
+ try std.testing.expectEqual(@as(usize, 0), diagnostics.glyph_atlas_evict_count);
2812
+ try std.testing.expectEqual(@as(usize, 2), diagnostics.change_count);
2813
+ }
2814
+
2815
+ test "canvas frame plan clips incremental dirty bounds to surface" {
2816
+ const previous_commands = [_]CanvasCommand{
2817
+ .{ .fill_rect = .{ .id = 1, .rect = geometry.RectF.init(0, 0, 40, 40), .fill = .{ .color = Color.rgb8(255, 255, 255) } } },
2818
+ .{ .fill_rect = .{ .id = 2, .rect = geometry.RectF.init(70, 0, 20, 20), .fill = .{ .color = Color.rgb8(0, 0, 0) } } },
2819
+ };
2820
+ const next_commands = [_]CanvasCommand{
2821
+ .{ .fill_rect = .{ .id = 1, .rect = geometry.RectF.init(20, 0, 40, 40), .fill = .{ .color = Color.rgb8(255, 255, 255) } } },
2822
+ .{ .fill_rect = .{ .id = 2, .rect = geometry.RectF.init(70, 0, 20, 20), .fill = .{ .color = Color.rgb8(0, 0, 0) } } },
2823
+ };
2824
+
2825
+ var render_commands: [2]RenderCommand = undefined;
2826
+ var render_batches: [1]RenderBatch = undefined;
2827
+ var resources: [0]RenderResource = .{};
2828
+ var resource_cache_entries: [0]RenderResourceCacheEntry = .{};
2829
+ var resource_cache_actions: [0]RenderResourceCacheAction = .{};
2830
+ var glyphs: [0]GlyphAtlasEntry = .{};
2831
+ var changes: [2]DiffChange = undefined;
2832
+ const frame = try (DisplayList{ .commands = &next_commands }).framePlan(.{ .commands = &previous_commands }, .{
2833
+ .surface_size = geometry.SizeF.init(50, 50),
2834
+ }, .{
2835
+ .render_commands = &render_commands,
2836
+ .render_batches = &render_batches,
2837
+ .resources = &resources,
2838
+ .resource_cache_entries = &resource_cache_entries,
2839
+ .resource_cache_actions = &resource_cache_actions,
2840
+ .glyph_atlas_entries = &glyphs,
2841
+ .changes = &changes,
2842
+ });
2843
+
2844
+ try std.testing.expect(!frame.full_repaint);
2845
+ try std.testing.expect(frame.requiresRender());
2846
+ try std.testing.expectEqual(@as(usize, 1), frame.batch_plan.batchCount());
2847
+ try std.testing.expectEqual(@as(usize, 1), frame.changes.len);
2848
+ try std.testing.expectEqual(DiffKind.changed, frame.changes[0].kind);
2849
+ try std.testing.expectEqual(@as(?ObjectId, 1), frame.changes[0].id);
2850
+ try expectRect(geometry.RectF.init(0, 0, 50, 40), frame.dirty_bounds);
2851
+
2852
+ const render_pass = frame.renderPass();
2853
+ try std.testing.expect(render_pass.requiresRender());
2854
+ try std.testing.expectEqual(CanvasRenderPassLoadAction.load, render_pass.loadAction());
2855
+ try std.testing.expectEqual(@as(usize, 2), render_pass.commandCount());
2856
+ try std.testing.expectEqual(@as(usize, 1), render_pass.batchCount());
2857
+ try expectRect(geometry.RectF.init(0, 0, 50, 40), render_pass.scissorBounds());
2858
+
2859
+ var gpu_commands: [2]CanvasGpuCommand = undefined;
2860
+ const packet = try frame.gpuPacket(&gpu_commands);
2861
+ try std.testing.expect(packet.requiresRender());
2862
+ try std.testing.expect(packet.fullyRepresentable());
2863
+ try std.testing.expectEqual(CanvasRenderPassLoadAction.load, packet.load_action);
2864
+ try std.testing.expectEqual(@as(usize, 1), packet.commandCount());
2865
+ try std.testing.expectEqual(@as(?ObjectId, 1), packet.commands[0].id);
2866
+ const packet_summary = frame.gpuPacketSummary();
2867
+ try std.testing.expectEqual(packet.commandCount(), packet_summary.command_count);
2868
+ try std.testing.expectEqual(packet.cachedResourceCommandCount(), packet_summary.cached_resource_command_count);
2869
+ try std.testing.expectEqual(packet.unsupported_command_count, packet_summary.unsupported_command_count);
2870
+ try expectRect(geometry.RectF.init(0, 0, 50, 40), packet.scissor.?);
2871
+ var packet_json_buffer: [2048]u8 = undefined;
2872
+ var packet_json_writer = std.Io.Writer.fixed(&packet_json_buffer);
2873
+ try packet.writeJson(&packet_json_writer);
2874
+ const packet_json = packet_json_writer.buffered();
2875
+ try std.testing.expect(std.mem.indexOf(u8, packet_json, "\"loadAction\":\"load\"") != null);
2876
+ try std.testing.expect(std.mem.indexOf(u8, packet_json, "\"scissorBounds\":[0,0,50,40]") != null);
2877
+
2878
+ const profile = frame.profile();
2879
+ try std.testing.expect(profile.requires_render);
2880
+ try std.testing.expect(!profile.full_repaint);
2881
+ try std.testing.expectEqual(@as(f32, 2500), profile.surface_area);
2882
+ try std.testing.expectEqual(@as(f32, 2000), profile.dirty_area);
2883
+ try std.testing.expectEqual(@as(f32, 0.8), profile.dirty_ratio);
2884
+ try std.testing.expectEqual(CanvasFrameProfileRisk.high, profile.risk);
2885
+
2886
+ var profile_json_buffer: [1024]u8 = undefined;
2887
+ var profile_json_writer = std.Io.Writer.fixed(&profile_json_buffer);
2888
+ try frame.writeProfileJson(&profile_json_writer);
2889
+ const profile_json = profile_json_writer.buffered();
2890
+ try std.testing.expect(std.mem.indexOf(u8, profile_json, "\"dirtyArea\":2000") != null);
2891
+ try std.testing.expect(std.mem.indexOf(u8, profile_json, "\"risk\":\"high\"") != null);
2892
+ }
2893
+
2894
+ test "canvas frame plan leaves unchanged retained frame clean" {
2895
+ const commands = [_]CanvasCommand{
2896
+ .{ .fill_rect = .{ .id = 1, .rect = geometry.RectF.init(0, 0, 40, 40), .fill = .{ .color = Color.rgb8(255, 255, 255) } } },
2897
+ };
2898
+
2899
+ var render_commands: [1]RenderCommand = undefined;
2900
+ var render_batches: [1]RenderBatch = undefined;
2901
+ var resources: [0]RenderResource = .{};
2902
+ var resource_cache_entries: [0]RenderResourceCacheEntry = .{};
2903
+ var resource_cache_actions: [0]RenderResourceCacheAction = .{};
2904
+ var glyphs: [0]GlyphAtlasEntry = .{};
2905
+ var changes: [1]DiffChange = undefined;
2906
+ const frame = try (DisplayList{ .commands = &commands }).framePlan(.{ .commands = &commands }, .{}, .{
2907
+ .render_commands = &render_commands,
2908
+ .render_batches = &render_batches,
2909
+ .resources = &resources,
2910
+ .resource_cache_entries = &resource_cache_entries,
2911
+ .resource_cache_actions = &resource_cache_actions,
2912
+ .glyph_atlas_entries = &glyphs,
2913
+ .changes = &changes,
2914
+ });
2915
+
2916
+ try std.testing.expect(!frame.full_repaint);
2917
+ try std.testing.expect(!frame.requiresRender());
2918
+ try std.testing.expectEqual(@as(usize, 1), frame.render_plan.commandCount());
2919
+ try std.testing.expectEqual(@as(usize, 1), frame.batch_plan.batchCount());
2920
+ try std.testing.expectEqual(@as(usize, 0), frame.changes.len);
2921
+ try std.testing.expect(frame.dirty_bounds == null);
2922
+
2923
+ const render_pass = frame.renderPass();
2924
+ try std.testing.expect(!render_pass.requiresRender());
2925
+ try std.testing.expectEqual(CanvasRenderPassLoadAction.skip, render_pass.loadAction());
2926
+ try std.testing.expect(render_pass.scissorBounds() == null);
2927
+ try std.testing.expectEqual(@as(usize, 1), render_pass.commandCount());
2928
+ try std.testing.expectEqual(@as(usize, 1), render_pass.batchCount());
2929
+
2930
+ const profile = frame.profile();
2931
+ try std.testing.expect(!profile.requires_render);
2932
+ try std.testing.expectEqual(CanvasFrameProfileRisk.idle, profile.risk);
2933
+ try std.testing.expectEqual(@as(usize, 0), profile.encoder_command_count);
2934
+ try std.testing.expectEqual(@as(usize, 0), profile.work_units);
2935
+ }
2936
+
2937
+ test "canvas frame plan applies render overrides without display list changes" {
2938
+ const commands = [_]CanvasCommand{.{ .fill_rect = .{
2939
+ .id = 1,
2940
+ .rect = geometry.RectF.init(0, 0, 10, 10),
2941
+ .fill = .{ .color = Color.rgb8(255, 0, 0) },
2942
+ } }};
2943
+ const overrides = [_]CanvasRenderOverride{.{
2944
+ .id = 1,
2945
+ .opacity = 0.5,
2946
+ .transform = Affine.translate(10, 0),
2947
+ }};
2948
+
2949
+ var render_commands: [1]RenderCommand = undefined;
2950
+ var render_batches: [1]RenderBatch = undefined;
2951
+ var resources: [0]RenderResource = .{};
2952
+ var resource_cache_entries: [0]RenderResourceCacheEntry = .{};
2953
+ var resource_cache_actions: [0]RenderResourceCacheAction = .{};
2954
+ var glyphs: [0]GlyphAtlasEntry = .{};
2955
+ var changes: [1]DiffChange = undefined;
2956
+ const frame = try (DisplayList{ .commands = &commands }).framePlan(.{ .commands = &commands }, .{
2957
+ .surface_size = geometry.SizeF.init(40, 20),
2958
+ .render_overrides = &overrides,
2959
+ }, .{
2960
+ .render_commands = &render_commands,
2961
+ .render_batches = &render_batches,
2962
+ .resources = &resources,
2963
+ .resource_cache_entries = &resource_cache_entries,
2964
+ .resource_cache_actions = &resource_cache_actions,
2965
+ .glyph_atlas_entries = &glyphs,
2966
+ .changes = &changes,
2967
+ });
2968
+
2969
+ try std.testing.expect(!frame.full_repaint);
2970
+ try std.testing.expect(frame.requiresRender());
2971
+ try std.testing.expectEqual(@as(usize, 0), frame.changes.len);
2972
+ try expectRect(geometry.RectF.init(0, 0, 20, 10), frame.dirty_bounds);
2973
+ try std.testing.expectEqual(@as(usize, 1), frame.render_plan.commandCount());
2974
+ try std.testing.expectEqual(@as(f32, 0.5), frame.render_plan.commands[0].opacity);
2975
+ try std.testing.expectEqualDeep(Affine.translate(10, 0), frame.render_plan.commands[0].transform);
2976
+ try std.testing.expectEqualDeep(geometry.RectF.init(10, 0, 10, 10), frame.render_plan.commands[0].bounds);
2977
+
2978
+ const render_pass = frame.renderPass();
2979
+ try std.testing.expectEqual(CanvasRenderPassLoadAction.load, render_pass.loadAction());
2980
+ try expectRect(geometry.RectF.init(0, 0, 20, 10), render_pass.scissorBounds());
2981
+
2982
+ var pixels: [40 * 20 * 4]u8 = undefined;
2983
+ const surface = try ReferenceRenderSurface.init(40, 20, &pixels);
2984
+ surface.clear(Color.rgb8(0, 0, 0));
2985
+ try surface.renderPass(render_pass, Color.rgb8(0, 0, 0));
2986
+ try expectPixelRgba8(.{ 0, 0, 0, 255 }, surface, 5, 5);
2987
+ try expectPixelRgba8(.{ 128, 0, 0, 255 }, surface, 15, 5);
2988
+
2989
+ var clean_render_commands: [1]RenderCommand = undefined;
2990
+ var clean_render_batches: [1]RenderBatch = undefined;
2991
+ var clean_changes: [1]DiffChange = undefined;
2992
+ const clean_frame = try (DisplayList{ .commands = &commands }).framePlan(.{ .commands = &commands }, .{
2993
+ .surface_size = geometry.SizeF.init(40, 20),
2994
+ .previous_render_overrides = &overrides,
2995
+ .render_overrides = &overrides,
2996
+ }, .{
2997
+ .render_commands = &clean_render_commands,
2998
+ .render_batches = &clean_render_batches,
2999
+ .resources = &resources,
3000
+ .resource_cache_entries = &resource_cache_entries,
3001
+ .resource_cache_actions = &resource_cache_actions,
3002
+ .glyph_atlas_entries = &glyphs,
3003
+ .changes = &clean_changes,
3004
+ });
3005
+
3006
+ try std.testing.expect(!clean_frame.requiresRender());
3007
+ try std.testing.expect(clean_frame.dirty_bounds == null);
3008
+ try std.testing.expectEqualDeep(geometry.RectF.init(10, 0, 10, 10), clean_frame.render_plan.commands[0].bounds);
3009
+ }
3010
+
3011
+ test "canvas render animations sample overrides for frame planning" {
3012
+ const animations = [_]CanvasRenderAnimation{.{
3013
+ .id = 1,
3014
+ .start_ns = 1_000,
3015
+ .duration_ms = 1000,
3016
+ .easing = .linear,
3017
+ .from_opacity = 0,
3018
+ .to_opacity = 1,
3019
+ .from_transform = Affine.translate(0, 0),
3020
+ .to_transform = Affine.translate(20, 0),
3021
+ }};
3022
+
3023
+ var overrides: [1]CanvasRenderOverride = undefined;
3024
+ const sampled = try sampleCanvasRenderAnimations(&animations, 500_001_000, &overrides);
3025
+ try std.testing.expectEqual(@as(usize, 1), sampled.len);
3026
+ try std.testing.expectEqual(@as(ObjectId, 1), sampled[0].id);
3027
+ try std.testing.expectEqual(@as(f32, 0.5), sampled[0].opacity.?);
3028
+ try std.testing.expectEqualDeep(Affine.translate(10, 0), sampled[0].transform.?);
3029
+
3030
+ const commands = [_]CanvasCommand{.{ .fill_rect = .{
3031
+ .id = 1,
3032
+ .rect = geometry.RectF.init(0, 0, 10, 10),
3033
+ .fill = .{ .color = Color.rgb8(255, 0, 0) },
3034
+ } }};
3035
+ var render_commands: [1]RenderCommand = undefined;
3036
+ var render_batches: [1]RenderBatch = undefined;
3037
+ var resources: [0]RenderResource = .{};
3038
+ var resource_cache_entries: [0]RenderResourceCacheEntry = .{};
3039
+ var resource_cache_actions: [0]RenderResourceCacheAction = .{};
3040
+ var glyphs: [0]GlyphAtlasEntry = .{};
3041
+ var changes: [1]DiffChange = undefined;
3042
+ const frame = try (DisplayList{ .commands = &commands }).framePlan(.{ .commands = &commands }, .{
3043
+ .surface_size = geometry.SizeF.init(40, 20),
3044
+ .render_overrides = sampled,
3045
+ }, .{
3046
+ .render_commands = &render_commands,
3047
+ .render_batches = &render_batches,
3048
+ .resources = &resources,
3049
+ .resource_cache_entries = &resource_cache_entries,
3050
+ .resource_cache_actions = &resource_cache_actions,
3051
+ .glyph_atlas_entries = &glyphs,
3052
+ .changes = &changes,
3053
+ });
3054
+
3055
+ try std.testing.expectEqual(@as(usize, 0), frame.changes.len);
3056
+ try expectRect(geometry.RectF.init(0, 0, 20, 10), frame.dirty_bounds);
3057
+ try std.testing.expectEqual(@as(f32, 0.5), frame.render_plan.commands[0].opacity);
3058
+ try std.testing.expectEqualDeep(Affine.translate(10, 0), frame.render_plan.commands[0].transform);
3059
+
3060
+ var empty_overrides: [0]CanvasRenderOverride = .{};
3061
+ try std.testing.expectError(error.RenderOverrideListFull, sampleCanvasRenderAnimations(&animations, 500_001_000, &empty_overrides));
3062
+ }
3063
+
3064
+ test "canvas render animations sample wrap-looping rotation about a center" {
3065
+ // The spinner shape: a `.wrap` loop restarts the 0→1 sweep each
3066
+ // cycle, and rotation samples by ANGLE about `rotation_center`
3067
+ // (matrix lerp would collapse a full turn to a point).
3068
+ const animations = [_]CanvasRenderAnimation{.{
3069
+ .id = 5,
3070
+ .start_ns = 0,
3071
+ .duration_ms = 1000,
3072
+ .easing = .linear,
3073
+ .from_rotation = 0,
3074
+ .to_rotation = 360,
3075
+ .rotation_center = geometry.PointF.init(10, 10),
3076
+ .loop = .wrap,
3077
+ }};
3078
+
3079
+ // Quarter cycle: 90 degrees clockwise (y-down) about (10, 10).
3080
+ var overrides: [1]CanvasRenderOverride = undefined;
3081
+ const quarter = try sampleCanvasRenderAnimations(&animations, 250 * std.time.ns_per_ms, &overrides);
3082
+ try std.testing.expectEqual(@as(usize, 1), quarter.len);
3083
+ const rotated = quarter[0].transform.?.transformPoint(geometry.PointF.init(20, 10));
3084
+ try std.testing.expectApproxEqAbs(@as(f32, 10), rotated.x, 0.001);
3085
+ try std.testing.expectApproxEqAbs(@as(f32, 20), rotated.y, 0.001);
3086
+
3087
+ // One-and-a-quarter cycles wraps to the same quarter-turn pose —
3088
+ // the seam between turns is invisible.
3089
+ var wrap_overrides: [1]CanvasRenderOverride = undefined;
3090
+ const wrapped = try sampleCanvasRenderAnimations(&animations, 1250 * std.time.ns_per_ms, &wrap_overrides);
3091
+ try std.testing.expectEqual(@as(usize, 1), wrapped.len);
3092
+ const wrapped_point = wrapped[0].transform.?.transformPoint(geometry.PointF.init(20, 10));
3093
+ try std.testing.expectApproxEqAbs(rotated.x, wrapped_point.x, 0.001);
3094
+ try std.testing.expectApproxEqAbs(rotated.y, wrapped_point.y, 0.001);
3095
+
3096
+ // The rotation center itself is a fixed point of the override.
3097
+ const center = quarter[0].transform.?.transformPoint(geometry.PointF.init(10, 10));
3098
+ try std.testing.expectApproxEqAbs(@as(f32, 10), center.x, 0.001);
3099
+ try std.testing.expectApproxEqAbs(@as(f32, 10), center.y, 0.001);
3100
+ }
3101
+
3102
+ test "motion tokens build render animations" {
3103
+ const tokens = MotionTokens{
3104
+ .fast_ms = 90,
3105
+ .normal_ms = 160,
3106
+ .slow_ms = 320,
3107
+ .easing = .linear,
3108
+ .spring = .{ .mass = 2, .stiffness = 180, .damping = 22 },
3109
+ };
3110
+
3111
+ try std.testing.expectEqual(@as(u32, 90), tokens.durationMs(.fast));
3112
+ try std.testing.expectEqual(@as(u32, 160), tokens.durationMs(.normal));
3113
+ try std.testing.expectEqual(@as(u32, 320), tokens.durationMs(.slow));
3114
+
3115
+ const animation = tokens.animation(.{
3116
+ .id = 7,
3117
+ .start_ns = 10_000,
3118
+ .duration = .slow,
3119
+ .from_opacity = 0,
3120
+ .to_opacity = 1,
3121
+ .from_transform = Affine.translate(0, 0),
3122
+ .to_transform = Affine.translate(16, 0),
3123
+ });
3124
+
3125
+ try std.testing.expectEqual(@as(ObjectId, 7), animation.id);
3126
+ try std.testing.expectEqual(@as(u64, 10_000), animation.start_ns);
3127
+ try std.testing.expectEqual(@as(u32, 320), animation.duration_ms);
3128
+ try std.testing.expectEqual(Easing.linear, animation.easing);
3129
+ try std.testing.expectEqual(@as(f32, 2), animation.spring.mass);
3130
+ try std.testing.expectEqual(@as(f32, 180), animation.spring.stiffness);
3131
+ try std.testing.expectEqual(@as(f32, 22), animation.spring.damping);
3132
+
3133
+ var overrides: [1]CanvasRenderOverride = undefined;
3134
+ const sampled = try sampleCanvasRenderAnimations(&.{animation}, animation.start_ns + 160_000_000, &overrides);
3135
+ try std.testing.expectEqual(@as(usize, 1), sampled.len);
3136
+ try std.testing.expectEqual(@as(ObjectId, 7), sampled[0].id);
3137
+ try std.testing.expectEqual(@as(f32, 0.5), sampled[0].opacity.?);
3138
+ try std.testing.expectEqualDeep(Affine.translate(8, 0), sampled[0].transform.?);
3139
+
3140
+ const override_animation = tokens.animation(.{
3141
+ .id = 8,
3142
+ .easing = .emphasized,
3143
+ .spring = .{ .mass = 3, .stiffness = 140, .damping = 18 },
3144
+ });
3145
+ try std.testing.expectEqual(Easing.emphasized, override_animation.easing);
3146
+ try std.testing.expectEqual(@as(f32, 3), override_animation.spring.mass);
3147
+ try std.testing.expectEqual(@as(f32, 140), override_animation.spring.stiffness);
3148
+ try std.testing.expectEqual(@as(f32, 18), override_animation.spring.damping);
3149
+
3150
+ const reduced = MotionTokens.reduced();
3151
+ try std.testing.expectEqual(@as(u32, 0), reduced.durationMs(.fast));
3152
+ try std.testing.expectEqual(@as(u32, 0), reduced.durationMs(.normal));
3153
+ try std.testing.expectEqual(@as(u32, 0), reduced.durationMs(.slow));
3154
+ const reduced_animation = reduced.animation(.{
3155
+ .id = 9,
3156
+ .duration = .slow,
3157
+ .from_opacity = 0,
3158
+ .to_opacity = 1,
3159
+ });
3160
+ try std.testing.expectEqual(@as(u32, 0), reduced_animation.duration_ms);
3161
+ try std.testing.expectEqual(Easing.linear, reduced_animation.easing);
3162
+ try std.testing.expectEqual(@as(f32, 1), motionProgress(reduced_animation, reduced_animation.start_ns));
3163
+ }
3164
+
3165
+ test "canvas frame plan reports diff storage overflow" {
3166
+ const next_commands = [_]CanvasCommand{
3167
+ .{ .fill_rect = .{ .id = 1, .rect = geometry.RectF.init(0, 0, 40, 40), .fill = .{ .color = Color.rgb8(255, 255, 255) } } },
3168
+ };
3169
+
3170
+ var render_commands: [1]RenderCommand = undefined;
3171
+ var render_batches: [1]RenderBatch = undefined;
3172
+ var resources: [0]RenderResource = .{};
3173
+ var resource_cache_entries: [0]RenderResourceCacheEntry = .{};
3174
+ var resource_cache_actions: [0]RenderResourceCacheAction = .{};
3175
+ var glyphs: [0]GlyphAtlasEntry = .{};
3176
+ var changes: [0]DiffChange = .{};
3177
+ try std.testing.expectError(error.DiffListFull, (DisplayList{ .commands = &next_commands }).framePlan(.{}, .{}, .{
3178
+ .render_commands = &render_commands,
3179
+ .render_batches = &render_batches,
3180
+ .resources = &resources,
3181
+ .resource_cache_entries = &resource_cache_entries,
3182
+ .resource_cache_actions = &resource_cache_actions,
3183
+ .glyph_atlas_entries = &glyphs,
3184
+ .changes = &changes,
3185
+ }));
3186
+ }