From 7c6c5f3e36e83e1ac6475350145f21767cee0d4f Mon Sep 17 00:00:00 2001 From: omigamedev Date: Fri, 5 Jun 2026 17:30:44 +0200 Subject: [PATCH] Add document frame render automation --- docs/modernization/build-inventory.md | 11 +- docs/modernization/capability-map.md | 6 +- docs/modernization/debt.md | 7 +- docs/modernization/roadmap.md | 15 ++- src/paint_renderer/compositor.cpp | 39 ++++++ src/paint_renderer/compositor.h | 18 +++ tests/CMakeLists.txt | 6 + tests/paint_renderer/compositor_tests.cpp | 127 ++++++++++++++++++++ tools/pano_cli/main.cpp | 137 ++++++++++++++++++++++ 9 files changed, 354 insertions(+), 12 deletions(-) diff --git a/docs/modernization/build-inventory.md b/docs/modernization/build-inventory.md index b4ea6fc..433ee88 100644 --- a/docs/modernization/build-inventory.md +++ b/docs/modernization/build-inventory.md @@ -247,13 +247,16 @@ powershell -ExecutionPolicy Bypass -File scripts\automation\apple-remote-build.p - `pp_document_ppi_export_tests` exports pure `pp_document` metadata, per-layer frame durations, and RGBA8 face payloads to PPI bytes through `pp_assets`, then decodes and reimports them for round-trip coverage. -- `pp_paint_renderer_compositor_tests` now covers pure `pp_document` frame/face - compositing by expanding per-layer dirty face payload rectangles into a full - renderer-sized RGBA buffer with layer visibility, opacity, and blend mode - applied in document order. +- `pp_paint_renderer_compositor_tests` now covers pure `pp_document` face and + six-face frame compositing by expanding per-layer dirty face payload + rectangles into full renderer-sized RGBA buffers with layer visibility, + opacity, and blend mode applied in document order. - `pano_cli simulate-document-export` exposes the same pure document-to-PPI export, asset-level decode, and document reimport path through JSON automation and is covered by `pano_cli_simulate_document_export_smoke`. +- `pano_cli simulate-document-render` exposes the pure document-to-renderer + frame compositor through JSON automation and is covered by + `pano_cli_simulate_document_render_smoke`. - `pano_cli save-document-project` writes that pure document export to a PPI file and is covered by `pano_cli_save_document_project_roundtrip_smoke`, which inspects and loads the generated file. diff --git a/docs/modernization/capability-map.md b/docs/modernization/capability-map.md index 44179f0..236f428 100644 --- a/docs/modernization/capability-map.md +++ b/docs/modernization/capability-map.md @@ -1,7 +1,7 @@ # PanoPainter Capability Map Status: live -Last updated: 2026-06-03 +Last updated: 2026-06-05 This map is the preservation checklist for the modernization. When a component is extracted, update the relevant rows with the owning component, test label, @@ -26,7 +26,7 @@ and validation command. | PNG/JPEG import | `Image`, `Canvas` import paths | `pp_assets`, `pp_document` | Fixture import, malformed file | | PNG/JPEG export | `Canvas`, `Image`, export dialogs | `pp_assets`, `pp_paint_renderer`, `pp_app_core` | Golden output tolerance, export start/target planning tests | | Equirectangular import/export | `Canvas`, shaders, RTT, export dialogs | `pp_paint_renderer`, `pp_app_core` | Tiny cube/equirect golden, app-core file target tests | -| Cube face export | `Canvas` | `pp_paint_renderer` | Six-face golden set | +| Cube face export | `Canvas` | `pp_paint_renderer` | Pure six-face document frame composite, six-face golden set | | Depth export | `Canvas`, grid tools | `pp_paint_renderer` | Float/readback validation | ## Brush And Painting @@ -38,7 +38,7 @@ and validation command. | PPBR import/export | brush panel/dialog | `pp_assets`, `pp_panopainter_ui` | Round-trip fixture | | Stroke sampling | `Stroke`, `Canvas` | `pp_paint` | Property tests for spacing, pressure, jitter | | Dual brush/pattern behavior | `Brush`, shaders | `pp_paint`, `pp_paint_renderer` | Stroke-alpha CPU reference, dual/pattern feedback planning, GPU golden | -| Blend modes | GLSL include files, layer rendering | `pp_paint`, `pp_paint_renderer` | Final RGBA and stroke-alpha CPU reference vectors, pure `pp_document` frame/face compositing, fixed-function/framebuffer-fetch/ping-pong stroke composite planning, live `Canvas`/`NodeCanvas` blend-gate coverage, live canvas stroke/thumbnail/brush-preview destination-copy coverage, and GPU parity | +| Blend modes | GLSL include files, layer rendering | `pp_paint`, `pp_paint_renderer` | Final RGBA and stroke-alpha CPU reference vectors, pure `pp_document` face and six-face frame compositing, fixed-function/framebuffer-fetch/ping-pong stroke composite planning, live `Canvas`/`NodeCanvas` blend-gate coverage, live canvas stroke/thumbnail/brush-preview destination-copy coverage, and GPU parity | | Erase/flood fill/masks | `Canvas`, modes, shaders | `pp_document`, `pp_paint_renderer` | Edge masks, alpha lock, dirty rects | ## Layers And Animation diff --git a/docs/modernization/debt.md b/docs/modernization/debt.md index 943c09e..49edada 100644 --- a/docs/modernization/debt.md +++ b/docs/modernization/debt.md @@ -444,6 +444,11 @@ agent or engineer to remove them without reconstructing context from chat. dirty face payload rectangles into a full renderer-sized RGBA buffer while preserving document layer visibility, opacity, blend mode, and uneven per-layer frame timelines. +- 2026-06-05: DEBT-0010 was narrowed again. The same compositor boundary now + exposes a pure six-face document frame composite plus + `pano_cli simulate-document-render` JSON automation, so headless tests can + validate document payloads moving toward renderer/export services without a + GL context. ## Open Debt @@ -457,7 +462,7 @@ agent or engineer to remove them without reconstructing context from chat. | DEBT-0007 | Open | Modernization | `vcpkg.json` and `windows-msvc-vcpkg-headless` are validated for the headless Windows component matrix, and root CMake now exposes a focused `panopainter_platform_build_vcpkg_ui_core` target for the vcpkg-backed `pp_ui_core`/tinyxml2 boundary, but app targets still use vendored libraries and Android/Apple triplets are not proven | Dependency migration must stay incremental while SDK/patched/vendor dependencies remain in use | `cmake --preset windows-msvc-vcpkg-headless`; `ctest --preset desktop-fast-vcpkg --build-config Debug`; `cmake --build --preset windows-msvc-default --config Debug --target panopainter_platform_build_vcpkg_ui_core` | Component targets consume vcpkg packages where reliable and desktop app, Android, and Apple triplets are validated or explicitly documented as permanent vendor exceptions | | DEBT-0008 | Open | Modernization | `windows-msvc-default` and `windows-msvc-vcpkg-headless` explicitly select Visual Studio 18 2026 for local validation, but non-VS2026 CMake executables on PATH may not know that generator | The local machine has VS 2026, but using an older CMake can still default to Ninja or reject the VS 2026 generator | `cmake --preset windows-msvc-default`; `cmake --build --preset windows-msvc-default --config Debug --target PanoPainter`; `ctest --preset desktop-fast --build-config Debug` | The repo automation invokes or locates a CMake executable that supports `Visual Studio 18 2026`, and VS 2026 generator validation is the normal Windows path without manual tool selection | | DEBT-0009 | Open | Modernization | Android root CMake validation currently builds headless targets only, while retained standard/Quest/Focus package CMake paths now have a refreshed CMake 3.10/C++23 baseline outside root CMake; automation queries `sdkmanager`, installs newer or missing SDK Manager NDK/CMake packages, selects the resulting pair before configure, and reports update decisions; root CMake exposes non-default platform-build and retained native package validation targets | Platform app entrypoints still live in legacy Gradle/CMake projects and need Phase 6 alignment | `powershell -ExecutionPolicy Bypass -File scripts\automation\platform-build.ps1 -Presets android-arm64`; `cmake --build --preset android-x64`; `cmake --build --preset android-quest-arm64`; `cmake --build --preset android-focus-arm64`; `cmake --build --preset windows-msvc-default --config Debug --target panopainter_platform_build_android_assets`; `powershell -ExecutionPolicy Bypass -File scripts\automation\android-legacy-package-build.ps1 -Packages standard`; `powershell -ExecutionPolicy Bypass -File scripts\automation\android-legacy-package-build.ps1 -Packages quest,focus -ConfigureOnly`; `powershell -ExecutionPolicy Bypass -File scripts\automation\package-smoke.ps1 -ReadinessOnly -AndroidNativeChecks -PackageKinds android-standard-apk,android-quest-apk,android-focus-apk`; `cmake --build --preset windows-msvc-default --config Debug --target panopainter_android_native_package_smoke` | Android standard, Quest, and Focus/Wave package targets consume shared component targets and have package smoke commands | -| DEBT-0010 | Open | Modernization | `pp_document` is a pure layer/frame/document/undo-history model with alpha-lock metadata, snapshot construction, per-layer frame metadata, renderer-free RGBA8 face payload storage, snapshot-embedded face-payload validation, renderer-free alpha8 selection-mask storage, PPI import/export helpers, stroke-script-to-face-payload CLI automation, and a `pp_paint_renderer` document frame/face compositor, but it is not yet wired to legacy `Canvas`, legacy save, or legacy action commands | Keep extraction incremental while preserving app behavior | `ctest --preset desktop-fast --build-config Debug`; `pano_cli create-document --width 64 --height 32 --layers 2`; `pano_cli load-project --path tests\data\projects\minimal-project.ppi`; `pp_document_tests`; `pp_document_ppi_import_tests`; `pp_document_ppi_export_tests`; `pp_paint_renderer_compositor_tests`; `pano_cli_simulate_document_edits_smoke`; `pano_cli_simulate_document_export_smoke`; `pano_cli_save_document_project_roundtrip_smoke`; `pano_cli_apply_stroke_script_roundtrip_smoke`; `pano_cli_apply_stroke_script_rejects_tiny_canvas` | Legacy document behavior is represented by `pp_document`/`pp_paint_renderer` tests and the app consumes it through a boundary/facade | +| DEBT-0010 | Open | Modernization | `pp_document` is a pure layer/frame/document/undo-history model with alpha-lock metadata, snapshot construction, per-layer frame metadata, renderer-free RGBA8 face payload storage, snapshot-embedded face-payload validation, renderer-free alpha8 selection-mask storage, PPI import/export helpers, stroke-script-to-face-payload CLI automation, and `pp_paint_renderer` document face/frame compositors with CLI render automation, but it is not yet wired to legacy `Canvas`, legacy save, or legacy action commands | Keep extraction incremental while preserving app behavior | `ctest --preset desktop-fast --build-config Debug`; `pano_cli create-document --width 64 --height 32 --layers 2`; `pano_cli load-project --path tests\data\projects\minimal-project.ppi`; `pano_cli simulate-document-render --width 64 --height 32`; `pp_document_tests`; `pp_document_ppi_import_tests`; `pp_document_ppi_export_tests`; `pp_paint_renderer_compositor_tests`; `pano_cli_simulate_document_edits_smoke`; `pano_cli_simulate_document_export_smoke`; `pano_cli_simulate_document_render_smoke`; `pano_cli_save_document_project_roundtrip_smoke`; `pano_cli_apply_stroke_script_roundtrip_smoke`; `pano_cli_apply_stroke_script_rejects_tiny_canvas` | Legacy document behavior is represented by `pp_document`/`pp_paint_renderer` tests and the app consumes it through a boundary/facade | | DEBT-0011 | Open | Modernization | `package-smoke` validates the Windows CMake app artifact and launch-folder DLL payload, and reports a structured package readiness matrix for Windows AppX, Android standard/Quest/Focus APKs, Apple bundles, Linux app output, and WebGL output; the Windows app smoke passes the configure-time CMake executable so VS 2026 generator validation does not depend on `cmake` from PATH, retained Android package native CMake paths, and retained Linux/WebGL CMake baseline metadata are reachable from package validation and root CMake package-readiness targets, but Windows AppX/APK/Linux/Apple/WebGL package outputs are still `blocked` because root CMake package targets do not exist yet | Platform package targets are not migrated to root CMake yet | `powershell -ExecutionPolicy Bypass -File scripts\automation\package-smoke.ps1 -Preset windows-msvc-default -Configuration Debug`; `cmake --build --preset windows-msvc-default --config Debug --target panopainter_windows_app_package_smoke`; `powershell -ExecutionPolicy Bypass -File scripts\automation\package-smoke.ps1 -ReadinessOnly -AndroidNativeChecks -PackageKinds android-standard-apk,android-quest-apk,android-focus-apk`; `cmake --build --preset windows-msvc-default --config Debug --target panopainter_android_native_package_smoke`; `cmake --build --preset windows-msvc-default --config Debug --target panopainter_linux_webgl_package_readiness`; `python scripts/dev/check_package_smoke_readiness.py`; `bash -n scripts/automation/package-smoke.sh` | Package-smoke builds and validates Windows AppX, Android APK variants, Linux app, Apple bundles, and WebGL output where local toolchains are present | | DEBT-0012 | Open | Modernization | `pp_ui_core` uses vcpkg tinyxml2 on `windows-msvc-vcpkg-headless`, but retains `pp_vendor_tinyxml2` for default and unproven platform presets | Mobile/AppX/Apple triplets and app packaging still need validation before removing the vendored fallback | `ctest --preset desktop-fast-vcpkg --build-config Debug`; `ctest --preset desktop-fast --build-config Debug`; `powershell -ExecutionPolicy Bypass -File scripts\automation\platform-build.ps1 -Presets android-arm64` | All supported presets consume vcpkg tinyxml2 or document a permanent vendored exception | | DEBT-0013 | Open | Modernization | `pp_assets`, `pp_document`, `pano_cli inspect-project`, `pano_cli load-project`, and `pano_cli save-project` validate the fixed PPI header, thumbnail/body byte layout, generated multi-layer/multi-frame PPI writing with explicit layer opacity/blend/alpha-lock/visibility metadata, per-layer frame durations, metadata-only and targeted dirty-face-payload save/load round-trips, layer/frame index, dirty-face descriptors, dirty-face PNG payload metadata, asset-level RGBA PNG payload decoding, pure document-to-PPI export, CLI document export automation, file-writing document export automation, stroke-script-generated document payload export, and decoded pixel attachment to `pp_document`, but full legacy PPI round-trip parity is not yet extracted | Full PPI save parity requires staged extraction of legacy `Canvas` serialization and image/layer payload handling | `ctest --preset desktop-fast --build-config Debug`; `pp_assets_image_pixels_tests`; `pp_assets_ppi_header_tests`; `pp_document_ppi_import_tests`; `pp_document_ppi_export_tests`; `pano_cli_inspect_project_layout_smoke`; `pano_cli_load_project_metadata_smoke`; `pano_cli_save_project_roundtrip_smoke`; `pano_cli_save_project_payload_roundtrip_smoke`; `pano_cli_simulate_document_export_smoke`; `pano_cli_save_document_project_roundtrip_smoke`; `pano_cli_apply_stroke_script_roundtrip_smoke`; `pano_cli_apply_stroke_script_rejects_tiny_canvas` | Full PPI load/save fixtures cover thumbnails, decoded layer face payloads attached to documents, frames, corrupt payloads, dirty-face payload saving, arbitrary legacy canvas payload/layout combinations, and legacy app round-trip compatibility | diff --git a/docs/modernization/roadmap.md b/docs/modernization/roadmap.md index 0c2d7ac..734ef7e 100644 --- a/docs/modernization/roadmap.md +++ b/docs/modernization/roadmap.md @@ -453,9 +453,10 @@ duplicate selection masks. `pp_renderer_api` has started with renderer-neutral texture/readback descriptors and validation tests. `pp_paint_renderer` has started with deterministic CPU layer compositing over renderer extents using -the paint blend reference, and now exposes a pure `pp_document` face -compositor that expands per-layer dirty face payload rectangles into a full -renderer-sized RGBA buffer for a requested frame/face. `pp_ui_core` has started with XML-layout-facing +the paint blend reference, and now exposes pure `pp_document` face and +six-face frame compositors that expand per-layer dirty face payload rectangles +into full renderer-sized RGBA buffers for a requested document frame. +`pp_ui_core` has started with XML-layout-facing length parsing, color parsing, tinyxml-backed layout XML parsing, and invalid input tests. `pano_cli inspect-image` exposes PNG IHDR metadata as JSON, @@ -481,6 +482,8 @@ bytes using that writer, including PNG-encoded layer/frame face payloads. `pano_cli simulate-document-export` exercises that pure document export path, decodes the generated PPI bytes, reimports them, and emits JSON round-trip metadata. +`pano_cli simulate-document-render` exercises the pure document-to-renderer +frame compositor and emits six-face render summaries for headless automation. `pano_cli save-document-project` writes the same pure document export to a PPI file for inspect/load round-trip automation. `pano_cli create-document` can create simple animation documents with explicit @@ -1703,7 +1706,8 @@ Results: no-feedback blends, invalid render-target usage, unsupported backends, and depth-target rejection. - `pp_paint_renderer_compositor_tests` passed, including pure - `pp_document` frame/face compositing over per-layer dirty face payloads. + `pp_document` face and six-face frame compositing over per-layer dirty face + payloads. The suite now covers fixed-function stroke composite planning, framebuffer-fetch planning, ping-pong texture-copy/blit fallback planning, dual/pattern blend feedback detection, invalid blend mode rejection, @@ -1722,6 +1726,9 @@ Results: - `pano_cli_simulate_document_export_smoke` passed and reports pure `pp_document` export to PPI bytes, asset-level decode, and document reimport round-trip state as JSON. +- `pano_cli_simulate_document_render_smoke` passed and reports pure + `pp_document` to `pp_paint_renderer` six-face frame compositing summaries as + JSON. - `pano_cli_simulate_image_import_smoke` passed and reports embedded PNG decode plus `pp_document` face-payload attachment state as JSON. - `pano_cli_inspect_image_rejects_unsupported` passed as an expected failure diff --git a/src/paint_renderer/compositor.cpp b/src/paint_renderer/compositor.cpp index 6de7a25..feb8be3 100644 --- a/src/paint_renderer/compositor.cpp +++ b/src/paint_renderer/compositor.cpp @@ -288,6 +288,45 @@ pp::foundation::Result composite_document_face( return pp::foundation::Result::success(std::move(result)); } +pp::foundation::Result composite_document_frame( + DocumentFrameCompositeRequest request) +{ + if (request.document == nullptr) { + return pp::foundation::Result::failure( + pp::foundation::Status::invalid_argument("document frame composite request requires a document")); + } + + if (request.frame_index >= request.document->frames().size()) { + return pp::foundation::Result::failure( + pp::foundation::Status::out_of_range("document frame composite index is outside the document")); + } + + DocumentFrameCompositeResult result; + result.extent = pp::renderer::Extent2D { + .width = request.document->width(), + .height = request.document->height(), + }; + result.visited_layer_count = request.document->layers().size(); + + for (std::uint32_t face_index = 0; face_index < pp::document::cube_face_count; ++face_index) { + auto face = composite_document_face(DocumentFaceCompositeRequest { + .document = request.document, + .frame_index = request.frame_index, + .face_index = face_index, + .clear_color = request.clear_color, + }); + if (!face) { + return pp::foundation::Result::failure(face.status()); + } + + result.composited_layer_face_count += face.value().composited_layer_count; + result.face_payload_count += face.value().face_payload_count; + result.faces[face_index] = std::move(face.value()); + } + + return pp::foundation::Result::success(std::move(result)); +} + bool stroke_composite_requires_feedback( pp::paint::BlendMode layer_blend_mode, pp::paint::StrokeBlendMode stroke_blend_mode, diff --git a/src/paint_renderer/compositor.h b/src/paint_renderer/compositor.h index d5dbe94..27f4abb 100644 --- a/src/paint_renderer/compositor.h +++ b/src/paint_renderer/compositor.h @@ -5,6 +5,7 @@ #include "paint/blend.h" #include "renderer_api/renderer_api.h" +#include #include #include #include @@ -101,6 +102,20 @@ struct DocumentFaceCompositeResult { std::size_t face_payload_count = 0; }; +struct DocumentFrameCompositeRequest { + const pp::document::CanvasDocument* document = nullptr; + std::size_t frame_index = 0; + pp::paint::Rgba clear_color {}; +}; + +struct DocumentFrameCompositeResult { + pp::renderer::Extent2D extent {}; + std::array faces {}; + std::size_t visited_layer_count = 0; + std::size_t composited_layer_face_count = 0; + std::size_t face_payload_count = 0; +}; + [[nodiscard]] pp::foundation::Status composite_layer( std::span destination, pp::renderer::Extent2D extent, @@ -109,6 +124,9 @@ struct DocumentFaceCompositeResult { [[nodiscard]] pp::foundation::Result composite_document_face( DocumentFaceCompositeRequest request); +[[nodiscard]] pp::foundation::Result composite_document_frame( + DocumentFrameCompositeRequest request); + [[nodiscard]] bool stroke_composite_requires_feedback( pp::paint::BlendMode layer_blend_mode, pp::paint::StrokeBlendMode stroke_blend_mode, diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d25f221..1d4741c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -2448,6 +2448,12 @@ if(TARGET pano_cli) LABELS "assets;document;integration;desktop-fast" PASS_REGULAR_EXPRESSION "\"command\":\"simulate-document-export\".*\"source\":\\{\"width\":64,\"height\":32,\"layers\":2,\"frames\":2,\"facePayloads\":2\\}.*\"export\":\\{\"bytes\":[0-9]+,\"dirtyFaces\":2,\"rgbaFacePayloads\":2,\"compressedBytes\":[0-9]+\\}.*\"roundtrip\":\\{\"layers\":2,\"frames\":2,\"facePayloads\":2,\"layerNames\":\\[\"Base\",\"Paint\"\\],\"layerFrameCounts\":\\[2,1\\],\"layerDurationsMs\":\\[350,333\\]\\}.*\"payloads\":\\[\\{\"layer\":0,\"frame\":0,\"face\":0,\"x\":2,\"y\":3,\"bytes\":4,\"alpha\":255\\},\\{\"layer\":1,\"frame\":0,\"face\":5,\"x\":4,\"y\":5,\"bytes\":4,\"alpha\":128\\}\\]") + add_test(NAME pano_cli_simulate_document_render_smoke + COMMAND pano_cli simulate-document-render --width 64 --height 32) + set_tests_properties(pano_cli_simulate_document_render_smoke PROPERTIES + LABELS "document;renderer;integration;desktop-fast" + PASS_REGULAR_EXPRESSION "\"command\":\"simulate-document-render\".*\"source\":\\{\"width\":64,\"height\":32,\"layers\":2,\"frames\":2,\"facePayloads\":2\\}.*\"render\":\\{\"frame\":0,\"width\":64,\"height\":32,\"faces\":6,\"visitedLayers\":2,\"compositedLayerFaces\":1,\"facePayloads\":1.*\\{\"face\":0,\"pixels\":2048,\"payloads\":1,\"nonClearPixels\":1,\"firstNonClear\":\\{\"index\":194,\"x\":2,\"y\":3,\"r\":1,\"g\":0,\"b\":0,\"a\":1\\}\\}.*\\{\"face\":5,\"pixels\":2048,\"payloads\":0,\"nonClearPixels\":0\\}") + add_test(NAME pano_cli_simulate_image_import_smoke COMMAND pano_cli simulate-image-import --width 64 --height 32) set_tests_properties(pano_cli_simulate_image_import_smoke PROPERTIES diff --git a/tests/paint_renderer/compositor_tests.cpp b/tests/paint_renderer/compositor_tests.cpp index 5c1d36e..2bdec9a 100644 --- a/tests/paint_renderer/compositor_tests.cpp +++ b/tests/paint_renderer/compositor_tests.cpp @@ -13,11 +13,13 @@ using pp::paint::Rgba; using pp::paint::StrokeBlendMode; using pp::paint_renderer::CanvasBlendGateRequest; using pp::paint_renderer::DocumentFaceCompositeRequest; +using pp::paint_renderer::DocumentFrameCompositeRequest; using pp::paint_renderer::LayerCompositeView; using pp::paint_renderer::StrokeCompositePath; using pp::paint_renderer::StrokeCompositeRequest; using pp::paint_renderer::composite_layer; using pp::paint_renderer::composite_document_face; +using pp::paint_renderer::composite_document_frame; using pp::paint_renderer::plan_canvas_blend_gate; using pp::paint_renderer::plan_canvas_stroke_feedback; using pp::paint_renderer::plan_stroke_composite; @@ -331,6 +333,129 @@ void document_face_composite_rejects_invalid_requests(pp::tests::Harness& h) PP_EXPECT(h, bad_face.status().code == StatusCode::out_of_range); } +void composites_document_frame_cube_faces(pp::tests::Harness& h) +{ + const AnimationFrame root_frames[] { + { .duration_ms = 100, .face_pixels = {} }, + }; + const AnimationFrame base_frames[] { + { + .duration_ms = 100, + .face_pixels = { + LayerFacePixels { + .face_index = 0, + .x = 0, + .y = 0, + .width = 1, + .height = 1, + .rgba8 = { 255, 0, 0, 255 }, + }, + LayerFacePixels { + .face_index = 5, + .x = 0, + .y = 0, + .width = 1, + .height = 1, + .rgba8 = { 0, 0, 255, 255 }, + }, + }, + }, + }; + const AnimationFrame paint_frames[] { + { + .duration_ms = 100, + .face_pixels = { + LayerFacePixels { + .face_index = 5, + .x = 0, + .y = 0, + .width = 1, + .height = 1, + .rgba8 = { 0, 255, 0, 255 }, + }, + }, + }, + }; + const DocumentLayerConfig layers[] { + { + .name = "Base", + .frames = std::span(base_frames, 1), + }, + { + .name = "Paint", + .opacity = 0.5F, + .frames = std::span(paint_frames, 1), + }, + }; + const auto document = CanvasDocument::create_from_snapshot(DocumentSnapshotConfig { + .width = 1, + .height = 1, + .layers = std::span(layers, 2), + .frames = std::span(root_frames, 1), + .selection_masks = {}, + }); + PP_EXPECT(h, document); + + const auto result = composite_document_frame(DocumentFrameCompositeRequest { + .document = &document.value(), + .frame_index = 0, + .clear_color = Rgba { .r = 0.25F, .g = 0.25F, .b = 0.25F, .a = 1.0F }, + }); + + PP_EXPECT(h, result); + if (result) { + PP_EXPECT(h, result.value().extent.width == 1U); + PP_EXPECT(h, result.value().extent.height == 1U); + PP_EXPECT(h, result.value().faces.size() == pp::document::cube_face_count); + PP_EXPECT(h, result.value().visited_layer_count == 2U); + PP_EXPECT(h, result.value().composited_layer_face_count == 3U); + PP_EXPECT(h, result.value().face_payload_count == 3U); + PP_EXPECT(h, result.value().faces[0].pixels.size() == 1U); + PP_EXPECT(h, near(result.value().faces[0].pixels[0].r, 1.0F)); + PP_EXPECT(h, near(result.value().faces[0].pixels[0].g, 0.0F)); + PP_EXPECT(h, near(result.value().faces[0].pixels[0].b, 0.0F)); + PP_EXPECT(h, result.value().faces[1].pixels.size() == 1U); + PP_EXPECT(h, near(result.value().faces[1].pixels[0].r, 0.25F)); + PP_EXPECT(h, near(result.value().faces[1].pixels[0].g, 0.25F)); + PP_EXPECT(h, near(result.value().faces[1].pixels[0].b, 0.25F)); + PP_EXPECT(h, result.value().faces[5].pixels.size() == 1U); + PP_EXPECT(h, near(result.value().faces[5].pixels[0].r, 0.0F)); + PP_EXPECT(h, near(result.value().faces[5].pixels[0].g, 0.5F)); + PP_EXPECT(h, near(result.value().faces[5].pixels[0].b, 0.5F)); + PP_EXPECT(h, near(result.value().faces[5].pixels[0].a, 1.0F)); + } +} + +void document_frame_composite_rejects_invalid_requests(pp::tests::Harness& h) +{ + const auto no_document = composite_document_frame(DocumentFrameCompositeRequest {}); + + const AnimationFrame root_frames[] { + { .duration_ms = 100, .face_pixels = {} }, + }; + const DocumentLayerConfig layers[] { + { .name = "Layer", .frames = {} }, + }; + const auto document = CanvasDocument::create_from_snapshot(DocumentSnapshotConfig { + .width = 1, + .height = 1, + .layers = std::span(layers, 1), + .frames = std::span(root_frames, 1), + .selection_masks = {}, + }); + PP_EXPECT(h, document); + + const auto bad_frame = composite_document_frame(DocumentFrameCompositeRequest { + .document = &document.value(), + .frame_index = 1, + }); + + PP_EXPECT(h, !no_document.ok()); + PP_EXPECT(h, no_document.status().code == StatusCode::invalid_argument); + PP_EXPECT(h, !bad_frame.ok()); + PP_EXPECT(h, bad_frame.status().code == StatusCode::out_of_range); +} + void detects_feedback_requirements(pp::tests::Harness& h) { PP_EXPECT(h, !stroke_composite_requires_feedback( @@ -673,6 +798,8 @@ int main() harness.run("composites_document_face_payloads_in_layer_order", composites_document_face_payloads_in_layer_order); harness.run("document_face_composite_skips_layers_without_requested_frame", document_face_composite_skips_layers_without_requested_frame); harness.run("document_face_composite_rejects_invalid_requests", document_face_composite_rejects_invalid_requests); + harness.run("composites_document_frame_cube_faces", composites_document_frame_cube_faces); + harness.run("document_frame_composite_rejects_invalid_requests", document_frame_composite_rejects_invalid_requests); harness.run("detects_feedback_requirements", detects_feedback_requirements); harness.run("plans_stroke_composite_paths", plans_stroke_composite_paths); harness.run("rejects_bad_stroke_composite_plans", rejects_bad_stroke_composite_plans); diff --git a/tools/pano_cli/main.cpp b/tools/pano_cli/main.cpp index 0cc5cde..6e7673a 100644 --- a/tools/pano_cli/main.cpp +++ b/tools/pano_cli/main.cpp @@ -727,6 +727,12 @@ struct SimulateDocumentExportArgs { std::uint32_t height = 32; }; +struct SimulateDocumentRenderArgs { + std::uint32_t width = 64; + std::uint32_t height = 32; + std::uint32_t frame = 0; +}; + struct SimulateDocumentHistoryArgs { std::uint32_t width = 64; std::uint32_t height = 32; @@ -2431,6 +2437,7 @@ void print_help() << " save-project --path FILE --width N --height N [--layer-name NAME] [--layer-opacity N] [--blend-mode N] [--alpha-locked] [--hidden] [--layers N] [--frames N] [--frame-duration-ms N] [--include-test-face-payload] [--payload-layer N] [--payload-frame N]\n" << " simulate-document-edits [--width N] [--height N]\n" << " simulate-document-export [--width N] [--height N]\n" + << " simulate-document-render [--width N] [--height N] [--frame N]\n" << " simulate-document-history [--width N] [--height N] [--history N]\n" << " simulate-app-session [--no-canvas] [--new-document] [--unsaved] [--close-prompt-open] [--save-intent save|save-as|save-version|save-dirty-version]\n" << " simulate-blend\n" @@ -10600,6 +10607,132 @@ int simulate_document_export(int argc, char** argv) return 0; } +pp::foundation::Status parse_simulate_document_render_args( + int argc, + char** argv, + SimulateDocumentRenderArgs& args) +{ + for (int i = 2; i < argc; ++i) { + const std::string_view key(argv[i]); + if (key == "--width" || key == "--height" || key == "--frame") { + if (i + 1 >= argc) { + return pp::foundation::Status::invalid_argument("missing value for option"); + } + + const auto value = pp::foundation::parse_u32(argv[++i]); + if (!value) { + return value.status(); + } + + if (key == "--width") { + args.width = value.value(); + } else if (key == "--height") { + args.height = value.value(); + } else { + args.frame = value.value(); + } + } else { + return pp::foundation::Status::invalid_argument("unknown option"); + } + } + + if (args.width == 0 || args.height == 0) { + return pp::foundation::Status::invalid_argument("width and height must be greater than zero"); + } + + if (args.width < 8 || args.height < 8) { + return pp::foundation::Status::out_of_range("width and height must be at least 8 for render simulation"); + } + + return pp::foundation::Status::success(); +} + +[[nodiscard]] bool pixel_differs_from_clear(pp::paint::Rgba pixel, pp::paint::Rgba clear) noexcept +{ + return pixel.r != clear.r || pixel.g != clear.g || pixel.b != clear.b || pixel.a != clear.a; +} + +int simulate_document_render(int argc, char** argv) +{ + SimulateDocumentRenderArgs args; + const auto status = parse_simulate_document_render_args(argc, argv, args); + if (!status.ok()) { + print_error("simulate-document-render", status.message); + return 2; + } + + const auto document_result = create_export_sample_document(args.width, args.height); + if (!document_result) { + print_error("simulate-document-render", document_result.status().message); + return 2; + } + + constexpr pp::paint::Rgba clear_color {}; + const auto composited = pp::paint_renderer::composite_document_frame( + pp::paint_renderer::DocumentFrameCompositeRequest { + .document = &document_result.value(), + .frame_index = args.frame, + .clear_color = clear_color, + }); + if (!composited) { + print_error("simulate-document-render", composited.status().message); + return 2; + } + + const auto& document = document_result.value(); + const auto& result = composited.value(); + std::cout << "{\"ok\":true,\"command\":\"simulate-document-render\"" + << ",\"source\":{\"width\":" << document.width() + << ",\"height\":" << document.height() + << ",\"layers\":" << document.layers().size() + << ",\"frames\":" << document.frames().size() + << ",\"facePayloads\":" << document.face_pixel_payload_count() + << "},\"render\":{\"frame\":" << args.frame + << ",\"width\":" << result.extent.width + << ",\"height\":" << result.extent.height + << ",\"faces\":" << result.faces.size() + << ",\"visitedLayers\":" << result.visited_layer_count + << ",\"compositedLayerFaces\":" << result.composited_layer_face_count + << ",\"facePayloads\":" << result.face_payload_count + << ",\"faceSummaries\":["; + for (std::size_t face_index = 0; face_index < result.faces.size(); ++face_index) { + const auto& face = result.faces[face_index]; + std::size_t non_clear_pixels = 0; + std::size_t first_non_clear = face.pixels.size(); + for (std::size_t pixel_index = 0; pixel_index < face.pixels.size(); ++pixel_index) { + if (!pixel_differs_from_clear(face.pixels[pixel_index], clear_color)) { + continue; + } + if (first_non_clear == face.pixels.size()) { + first_non_clear = pixel_index; + } + ++non_clear_pixels; + } + + if (face_index != 0U) { + std::cout << ","; + } + std::cout << "{\"face\":" << face_index + << ",\"pixels\":" << face.pixels.size() + << ",\"payloads\":" << face.face_payload_count + << ",\"nonClearPixels\":" << non_clear_pixels; + if (first_non_clear != face.pixels.size()) { + const auto& pixel = face.pixels[first_non_clear]; + std::cout << ",\"firstNonClear\":{\"index\":" << first_non_clear + << ",\"x\":" << (first_non_clear % result.extent.width) + << ",\"y\":" << (first_non_clear / result.extent.width) + << ",\"r\":" << pixel.r + << ",\"g\":" << pixel.g + << ",\"b\":" << pixel.b + << ",\"a\":" << pixel.a + << "}"; + } + std::cout << "}"; + } + std::cout << "]}}\n"; + return 0; +} + pp::foundation::Status parse_simulate_document_history_args( int argc, char** argv, @@ -11736,6 +11869,10 @@ int main(int argc, char** argv) return simulate_document_export(argc, argv); } + if (command == "simulate-document-render") { + return simulate_document_render(argc, argv); + } + if (command == "simulate-document-history") { return simulate_document_history(argc, argv); }