Integrate dialog export and Apple service teams

This commit is contained in:
2026-06-12 20:18:20 +02:00
parent 90f5fb29a6
commit 46fb8efec4
21 changed files with 1271 additions and 122 deletions

View File

@@ -928,7 +928,7 @@ if(TARGET pano_cli)
COMMAND pano_cli plan-export-snapshot-route --kind depth)
set_tests_properties(pano_cli_plan_export_snapshot_route_depth_smoke PROPERTIES
LABELS "app;integration;desktop-fast"
PASS_REGULAR_EXPRESSION "\"command\":\"plan-export-snapshot-route\".*\"kind\":\"depth\".*\"targetSupported\":false.*\"platformSupported\":true.*\"action\":\"use-legacy-export\".*\"fallbackReason\":\"document snapshot export does not support this target\"")
PASS_REGULAR_EXPRESSION "\"command\":\"plan-export-snapshot-route\".*\"kind\":\"depth\".*\"targetSupported\":true.*\"platformSupported\":true.*\"action\":\"use-document-snapshot-writer\".*\"usesDocumentSnapshotWriter\":true.*\"fallbackReason\":\"\"")
add_test(NAME pano_cli_plan_export_menu_rejects_unknown
COMMAND pano_cli plan-export-menu --kind unknown)

View File

@@ -3,6 +3,51 @@
namespace {
class TestProgressDialog final : public pp::app::AppProgressDialog {
public:
[[nodiscard]] pp::app::AppDialogKind kind() const noexcept override
{
return pp::app::AppDialogKind::progress;
}
};
class TestMessageDialog final : public pp::app::AppMessageDialog {
public:
[[nodiscard]] pp::app::AppDialogKind kind() const noexcept override
{
return pp::app::AppDialogKind::message;
}
};
class TestInputDialog final : public pp::app::AppInputDialog {
public:
[[nodiscard]] pp::app::AppDialogKind kind() const noexcept override
{
return pp::app::AppDialogKind::input;
}
};
class TestDialogFactory final : public pp::app::AppDialogFactory {
public:
std::shared_ptr<pp::app::AppProgressDialog> show_progress_dialog(
const pp::app::AppProgressDialogPlan&) override
{
return std::make_shared<TestProgressDialog>();
}
std::shared_ptr<pp::app::AppMessageDialog> show_message_dialog(
const pp::app::AppMessageDialogPlan&) override
{
return std::make_shared<TestMessageDialog>();
}
std::shared_ptr<pp::app::AppInputDialog> show_input_dialog(
const pp::app::AppInputDialogPlan&) override
{
return std::make_shared<TestInputDialog>();
}
};
void progress_dialog_initializes_progress_state(pp::tests::Harness& harness)
{
const auto plan = pp::app::plan_app_progress_dialog("Saving", 12);
@@ -62,6 +107,14 @@ void input_dialog_rejects_empty_ok_caption(pp::tests::Harness& harness)
PP_EXPECT(harness, plan.status().code == pp::foundation::StatusCode::invalid_argument);
}
void dialog_factory_uses_pure_app_core_dialog_types(pp::tests::Harness& harness)
{
TestDialogFactory factory;
PP_EXPECT(harness, factory.show_progress_dialog({})->kind() == pp::app::AppDialogKind::progress);
PP_EXPECT(harness, factory.show_message_dialog({})->kind() == pp::app::AppDialogKind::message);
PP_EXPECT(harness, factory.show_input_dialog({})->kind() == pp::app::AppDialogKind::input);
}
}
int main()
@@ -74,5 +127,6 @@ int main()
harness.run("message dialog allows custom button captions", message_dialog_allows_custom_button_captions);
harness.run("input dialog preserves ok caption", input_dialog_preserves_ok_caption);
harness.run("input dialog rejects empty ok caption", input_dialog_rejects_empty_ok_caption);
harness.run("dialog factory uses pure app-core dialog types", dialog_factory_uses_pure_app_core_dialog_types);
return harness.finish();
}

View File

@@ -880,7 +880,7 @@ void export_snapshot_target_support_covers_document_writer_formats(pp::tests::Ha
pp::app::DocumentExportExecutionKind::cube_faces));
PP_EXPECT(
harness,
!pp::app::document_export_snapshot_target_supported(
pp::app::document_export_snapshot_target_supported(
pp::app::DocumentExportExecutionKind::depth));
}
@@ -930,7 +930,7 @@ void export_snapshot_route_for_current_platform_uses_platform_policy(pp::tests::
#endif
}
void export_snapshot_route_for_current_platform_reports_depth_fallback(pp::tests::Harness& harness)
void export_snapshot_route_for_current_platform_supports_depth_writer(pp::tests::Harness& harness)
{
pp::app::DocumentCanvasSaveSnapshotReport report;
report.payload_complete = true;
@@ -940,18 +940,17 @@ void export_snapshot_route_for_current_platform_reports_depth_fallback(pp::tests
pp::app::DocumentExportExecutionKind::depth,
report);
PP_EXPECT(harness, !plan.uses_document_snapshot_writer);
#if __WEB__
PP_EXPECT(harness, !plan.uses_document_snapshot_writer);
PP_EXPECT(harness, !plan.platform_supported);
PP_EXPECT(
harness,
plan.fallback_reason == "document snapshot export is disabled on this platform");
#else
PP_EXPECT(harness, plan.uses_document_snapshot_writer);
PP_EXPECT(harness, plan.platform_supported);
PP_EXPECT(harness, !plan.target_supported);
PP_EXPECT(
harness,
plan.fallback_reason == "document snapshot export does not support this target");
PP_EXPECT(harness, plan.target_supported);
PP_EXPECT(harness, plan.fallback_reason.empty());
#endif
}
@@ -1382,8 +1381,8 @@ int main()
"export snapshot route for current platform uses platform policy",
export_snapshot_route_for_current_platform_uses_platform_policy);
harness.run(
"export snapshot route for current platform reports depth fallback",
export_snapshot_route_for_current_platform_reports_depth_fallback);
"export snapshot route for current platform supports depth writer",
export_snapshot_route_for_current_platform_supports_depth_writer);
harness.run(
"export snapshot route falls back for pending renderer payloads",
export_snapshot_route_falls_back_for_pending_renderer_payloads);

View File

@@ -13,6 +13,7 @@ using pp::foundation::StatusCode;
using pp::paint::BlendMode;
using pp::paint::Rgba;
using pp::paint::StrokeBlendMode;
using pp::assets::decode_png_rgba8;
using pp::paint_renderer::CanvasBlendGateRequest;
using pp::paint_renderer::DocumentFaceCompositeRequest;
using pp::paint_renderer::DocumentFrameCompositeRequest;
@@ -22,6 +23,7 @@ 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::export_document_depth_pngs;
using pp::paint_renderer::plan_canvas_blend_gate;
using pp::paint_renderer::plan_canvas_stroke_feedback;
using pp::paint_renderer::plan_document_depth_export_render;
@@ -1176,6 +1178,126 @@ void plans_document_depth_export_renderer_work(pp::tests::Harness& h)
PP_EXPECT(h, plan.value().requires_renderer_readback);
}
void exports_document_depth_as_png_payloads(pp::tests::Harness& h)
{
const AnimationFrame root_frames[] {
{ .duration_ms = 100, .face_pixels = {} },
};
const AnimationFrame base_frames[] {
{
.duration_ms = 100,
.face_pixels = {
solid_face_payload(0, 1, 1, 255, 0, 0, 255),
},
},
};
const AnimationFrame top_frames[] {
{
.duration_ms = 100,
.face_pixels = {
solid_face_payload(0, 1, 1, 0, 255, 0, 255),
},
},
};
const DocumentLayerConfig layers[] {
{
.name = "Base",
.frames = std::span<const AnimationFrame>(base_frames, 1),
},
{
.name = "Top",
.frames = std::span<const AnimationFrame>(top_frames, 1),
},
};
const auto document = CanvasDocument::create_from_snapshot(DocumentSnapshotConfig {
.width = 1,
.height = 1,
.layers = std::span<const DocumentLayerConfig>(layers, 2),
.frames = std::span<const AnimationFrame>(root_frames, 1),
.selection_masks = {},
});
PP_EXPECT(h, document);
if (!document) {
return;
}
const auto exported = export_document_depth_pngs(
pp::paint_renderer::DocumentDepthExportRenderPlanRequest {
.document = &document.value(),
.frame_index = 0,
.output_extent = Extent2D { .width = 1, .height = 1 },
});
PP_EXPECT(h, exported);
if (!exported) {
return;
}
PP_EXPECT(h, exported.value().output_extent.width == 1U);
PP_EXPECT(h, exported.value().output_extent.height == 1U);
PP_EXPECT(h, exported.value().image_encoded_bytes > 0U);
PP_EXPECT(h, exported.value().depth_encoded_bytes > 0U);
PP_EXPECT(h, exported.value().merged_face_draw_count == pp::document::cube_face_count);
PP_EXPECT(h, exported.value().layer_depth_draw_count == 2U);
PP_EXPECT(h, exported.value().visited_layer_count == 2U);
PP_EXPECT(h, exported.value().visible_layer_count == 2U);
PP_EXPECT(h, exported.value().face_payload_count == 2U);
PP_EXPECT(h, exported.value().uses_perspective_camera);
const auto image = decode_png_rgba8(exported.value().image_png);
const auto depth = decode_png_rgba8(exported.value().depth_png);
PP_EXPECT(h, image);
PP_EXPECT(h, depth);
if (!image || !depth) {
return;
}
PP_EXPECT(h, image.value().width == 1U);
PP_EXPECT(h, image.value().height == 1U);
PP_EXPECT(h, depth.value().width == 1U);
PP_EXPECT(h, depth.value().height == 1U);
const std::vector<std::uint8_t> expected_image { 0, 255, 0, 255 };
const std::vector<std::uint8_t> expected_depth { 170, 170, 170, 255 };
PP_EXPECT(h, image.value().pixels == expected_image);
PP_EXPECT(h, depth.value().pixels == expected_depth);
}
void depth_export_payload_boundary_rejects_malformed_face_bytes(pp::tests::Harness& h)
{
const AnimationFrame root_frames[] {
{ .duration_ms = 100, .face_pixels = {} },
};
const AnimationFrame bad_frames[] {
{
.duration_ms = 100,
.face_pixels = {
LayerFacePixels {
.face_index = 0,
.x = 0,
.y = 0,
.width = 1,
.height = 1,
.rgba8 = { 255, 0, 0 },
},
},
},
};
const DocumentLayerConfig layers[] {
{
.name = "Broken",
.frames = std::span<const AnimationFrame>(bad_frames, 1),
},
};
const auto document = CanvasDocument::create_from_snapshot(DocumentSnapshotConfig {
.width = 1,
.height = 1,
.layers = std::span<const DocumentLayerConfig>(layers, 1),
.frames = std::span<const AnimationFrame>(root_frames, 1),
.selection_masks = {},
});
PP_EXPECT(h, !document.ok());
PP_EXPECT(h, document.status().code == StatusCode::invalid_argument);
}
void document_frame_upload_rejects_invalid_requests(pp::tests::Harness& h)
{
RecordingRenderDevice device;
@@ -1194,6 +1316,8 @@ void document_frame_upload_rejects_invalid_requests(pp::tests::Harness& h)
pp::paint_renderer::DocumentAnimationFrameEquirectangularPngExportRequest {});
const auto no_document_depth = plan_document_depth_export_render(
pp::paint_renderer::DocumentDepthExportRenderPlanRequest {});
const auto no_document_depth_pngs = export_document_depth_pngs(
pp::paint_renderer::DocumentDepthExportRenderPlanRequest {});
const AnimationFrame root_frames[] {
{ .duration_ms = 100, .face_pixels = {} },
@@ -1232,6 +1356,17 @@ void document_frame_upload_rejects_invalid_requests(pp::tests::Harness& h)
.frame_index = 0,
.output_extent = Extent2D {},
});
const auto bad_frame_depth_pngs = export_document_depth_pngs(
pp::paint_renderer::DocumentDepthExportRenderPlanRequest {
.document = &document.value(),
.frame_index = 1,
});
const auto bad_extent_depth_pngs = export_document_depth_pngs(
pp::paint_renderer::DocumentDepthExportRenderPlanRequest {
.document = &document.value(),
.frame_index = 0,
.output_extent = Extent2D {},
});
const auto bad_jpeg_quality = pp::paint_renderer::export_document_frame_equirectangular_jpeg(
DocumentFrameCompositeRequest {
.document = &document.value(),
@@ -1253,6 +1388,8 @@ void document_frame_upload_rejects_invalid_requests(pp::tests::Harness& h)
PP_EXPECT(h, no_document_frames.status().code == StatusCode::invalid_argument);
PP_EXPECT(h, !no_document_depth.ok());
PP_EXPECT(h, no_document_depth.status().code == StatusCode::invalid_argument);
PP_EXPECT(h, !no_document_depth_pngs.ok());
PP_EXPECT(h, no_document_depth_pngs.status().code == StatusCode::invalid_argument);
PP_EXPECT(h, !bad_frame.ok());
PP_EXPECT(h, bad_frame.status().code == StatusCode::out_of_range);
PP_EXPECT(h, !bad_frame_readiness.ok());
@@ -1261,6 +1398,10 @@ void document_frame_upload_rejects_invalid_requests(pp::tests::Harness& h)
PP_EXPECT(h, bad_frame_depth.status().code == StatusCode::out_of_range);
PP_EXPECT(h, !bad_extent_depth.ok());
PP_EXPECT(h, bad_extent_depth.status().code == StatusCode::invalid_argument);
PP_EXPECT(h, !bad_frame_depth_pngs.ok());
PP_EXPECT(h, bad_frame_depth_pngs.status().code == StatusCode::out_of_range);
PP_EXPECT(h, !bad_extent_depth_pngs.ok());
PP_EXPECT(h, bad_extent_depth_pngs.status().code == StatusCode::invalid_argument);
PP_EXPECT(h, !bad_jpeg_quality.ok());
PP_EXPECT(h, bad_jpeg_quality.status().code == StatusCode::out_of_range);
PP_EXPECT(h, device.commands().empty());
@@ -1623,6 +1764,10 @@ int main()
"exports_document_animation_frames_as_equirectangular_pngs",
exports_document_animation_frames_as_equirectangular_pngs);
harness.run("plans_document_depth_export_renderer_work", plans_document_depth_export_renderer_work);
harness.run("exports_document_depth_as_png_payloads", exports_document_depth_as_png_payloads);
harness.run(
"depth export payload boundary rejects malformed face bytes",
depth_export_payload_boundary_rejects_malformed_face_bytes);
harness.run("document_frame_upload_rejects_invalid_requests", document_frame_upload_rejects_invalid_requests);
harness.run("detects_feedback_requirements", detects_feedback_requirements);
harness.run("plans_stroke_composite_paths", plans_stroke_composite_paths);

View File

@@ -4,6 +4,7 @@
#include "platform_api/network_tls_policy.h"
#include "platform_api/platform_policy.h"
#include "platform_api/platform_services.h"
#include "platform_apple/apple_platform_services.h"
#include <filesystem>
#include <fstream>
@@ -495,6 +496,56 @@ private:
std::string clipboard_value_;
};
class FakeAppleDocumentPickerBridge final {
public:
[[nodiscard]] pp::platform::apple::AppleDocumentPickerBridge bridge()
{
pp::platform::apple::AppleDocumentPickerBridge result;
result.pick_image = [this](pp::platform::PickedPathCallback callback) {
++pick_image_requests;
callback(image_path);
};
result.pick_file = [this](
std::vector<std::string> file_types,
pp::platform::PickedPathCallback callback) {
++pick_file_requests;
picked_file_types = std::move(file_types);
callback(file_path);
};
result.pick_save_file = [this](
std::vector<std::string> file_types,
pp::platform::PickedPathCallback callback) {
++pick_save_file_requests;
save_file_types = std::move(file_types);
callback(save_path);
};
result.pick_directory = [this](pp::platform::PickedPathCallback callback) {
++pick_directory_requests;
callback(directory_path);
};
result.format_working_directory_path = [this](std::string_view path) {
++format_requests;
last_format_path.assign(path);
return formatted_path;
};
return result;
}
int pick_image_requests = 0;
int pick_file_requests = 0;
int pick_save_file_requests = 0;
int pick_directory_requests = 0;
int format_requests = 0;
std::string image_path = "D:/Paint/import.png";
std::string file_path = "D:/Paint/demo.ppi";
std::string save_path = "D:/Paint/export.ppi";
std::string directory_path = "D:/Paint/work";
std::string formatted_path = "D:/Paint/Resolved";
std::string last_format_path;
std::vector<std::string> picked_file_types;
std::vector<std::string> save_file_types;
};
void platform_services_dispatch_clipboard_reads_and_writes(pp::tests::Harness& harness)
{
FakePlatformServices fake("#112233");
@@ -776,6 +827,117 @@ void platform_services_dispatch_prepared_file_save(pp::tests::Harness& harness)
PP_EXPECT(harness, saved);
}
void apple_document_platform_services_preserve_browse_root_policy(pp::tests::Harness& harness)
{
pp::platform::apple::AppleDocumentPlatformServices ios_services(pp::platform::PlatformFamily::ios);
pp::platform::apple::AppleDocumentPlatformServices macos_services(pp::platform::PlatformFamily::macos);
const auto ios_roots = ios_services.document_browse_roots("D:/Paint/work", "D:/Paint");
const auto macos_roots = macos_services.document_browse_roots("D:/Paint/work", "D:/Paint");
PP_EXPECT(harness, ios_roots.size() == 2);
PP_EXPECT(harness, ios_roots[0] == "D:/Paint/work");
PP_EXPECT(harness, ios_roots[1] == "D:/Paint/Inbox");
PP_EXPECT(harness, macos_roots.size() == 1);
PP_EXPECT(harness, macos_roots[0] == "D:/Paint/work");
}
void apple_document_platform_services_dispatch_ios_picker_callbacks(pp::tests::Harness& harness)
{
FakeAppleDocumentPickerBridge fake;
pp::platform::apple::AppleDocumentPlatformServices services(
pp::platform::PlatformFamily::ios,
fake.bridge());
std::string image_path;
std::string file_path;
std::string save_path = "unchanged";
std::string directory_path = "unchanged";
services.pick_image([&](std::string path) { image_path = std::move(path); });
services.pick_file({ "ppi", "ppbr" }, [&](std::string path) { file_path = std::move(path); });
services.pick_save_file({ "ppi" }, [&](std::string path) { save_path = std::move(path); });
services.pick_directory([&](std::string path) { directory_path = std::move(path); });
PP_EXPECT(harness, fake.pick_image_requests == 1);
PP_EXPECT(harness, fake.pick_file_requests == 1);
PP_EXPECT(harness, fake.pick_save_file_requests == 0);
PP_EXPECT(harness, fake.pick_directory_requests == 0);
PP_EXPECT(harness, image_path == "D:/Paint/import.png");
PP_EXPECT(harness, file_path == "D:/Paint/demo.ppi");
PP_EXPECT(harness, fake.picked_file_types.size() == 2);
PP_EXPECT(harness, fake.picked_file_types[0] == "ppi");
PP_EXPECT(harness, fake.picked_file_types[1] == "ppbr");
PP_EXPECT(harness, save_path == "unchanged");
PP_EXPECT(harness, directory_path == "unchanged");
}
void apple_document_platform_services_filter_macos_picker_paths(pp::tests::Harness& harness)
{
FakeAppleDocumentPickerBridge fake;
pp::platform::apple::AppleDocumentPlatformServices services(
pp::platform::PlatformFamily::macos,
fake.bridge());
std::string image_path = "unchanged";
std::string file_path = "unchanged";
std::string save_path = "unchanged";
std::string directory_path = "unchanged";
fake.file_path.clear();
services.pick_image([&](std::string path) { image_path = std::move(path); });
PP_EXPECT(harness, fake.pick_image_requests == 0);
PP_EXPECT(harness, fake.pick_file_requests == 1);
PP_EXPECT(harness, fake.picked_file_types.size() == 5);
PP_EXPECT(harness, fake.picked_file_types[0] == "png");
PP_EXPECT(harness, fake.picked_file_types[1] == "PNG");
PP_EXPECT(harness, fake.picked_file_types[2] == "jpg");
PP_EXPECT(harness, fake.picked_file_types[3] == "JPG");
PP_EXPECT(harness, fake.picked_file_types[4] == "jpeg");
PP_EXPECT(harness, image_path == "unchanged");
fake.file_path = "D:/Paint/demo.ppi";
services.pick_file({ "ppi" }, [&](std::string path) { file_path = std::move(path); });
PP_EXPECT(harness, fake.pick_file_requests == 2);
PP_EXPECT(harness, file_path == "D:/Paint/demo.ppi");
fake.save_path.clear();
services.pick_save_file({ "ppi" }, [&](std::string path) { save_path = std::move(path); });
PP_EXPECT(harness, fake.pick_save_file_requests == 1);
PP_EXPECT(harness, save_path == "unchanged");
fake.save_path = "D:/Paint/export.ppi";
services.pick_save_file({ "ppi" }, [&](std::string path) { save_path = std::move(path); });
PP_EXPECT(harness, fake.pick_save_file_requests == 2);
PP_EXPECT(harness, save_path == "D:/Paint/export.ppi");
fake.directory_path.clear();
services.pick_directory([&](std::string path) { directory_path = std::move(path); });
PP_EXPECT(harness, fake.pick_directory_requests == 1);
PP_EXPECT(harness, directory_path == "unchanged");
fake.directory_path = "D:/Paint/work";
services.pick_directory([&](std::string path) { directory_path = std::move(path); });
PP_EXPECT(harness, fake.pick_directory_requests == 2);
PP_EXPECT(harness, directory_path == "D:/Paint/work");
}
void apple_document_platform_services_preserve_working_directory_picker_policy(pp::tests::Harness& harness)
{
FakeAppleDocumentPickerBridge fake;
pp::platform::apple::AppleDocumentPlatformServices ios_services(
pp::platform::PlatformFamily::ios,
fake.bridge());
pp::platform::apple::AppleDocumentPlatformServices macos_services(
pp::platform::PlatformFamily::macos,
fake.bridge());
PP_EXPECT(harness, !ios_services.supports_working_directory_picker());
PP_EXPECT(harness, macos_services.supports_working_directory_picker());
PP_EXPECT(harness, ios_services.format_working_directory_path("D:/Paint/.") == "D:/Paint/.");
PP_EXPECT(harness, macos_services.format_working_directory_path("D:/Paint/.") == "D:/Paint/Resolved");
PP_EXPECT(harness, fake.format_requests == 1);
PP_EXPECT(harness, fake.last_format_path == "D:/Paint/.");
}
void web_platform_services_preserve_default_web_policy(pp::tests::Harness& harness)
{
ScopedInjectedWebPlatformServices scoped(nullptr);
@@ -1209,6 +1371,18 @@ int main()
"platform services dispatch working directory picker policy",
platform_services_dispatch_working_directory_picker_policy);
harness.run("platform services dispatch prepared file save", platform_services_dispatch_prepared_file_save);
harness.run(
"apple document platform services preserve browse root policy",
apple_document_platform_services_preserve_browse_root_policy);
harness.run(
"apple document platform services dispatch ios picker callbacks",
apple_document_platform_services_dispatch_ios_picker_callbacks);
harness.run(
"apple document platform services filter macos picker paths",
apple_document_platform_services_filter_macos_picker_paths);
harness.run(
"apple document platform services preserve working directory picker policy",
apple_document_platform_services_preserve_working_directory_picker_policy);
harness.run("web platform services preserve default web policy", web_platform_services_preserve_default_web_policy);
harness.run("web platform services resolve injected services", web_platform_services_resolve_injected_services);
harness.run("platform services dispatch writable file target", platform_services_dispatch_writable_file_target);