Plan depth export through document renderer
This commit is contained in:
@@ -154,6 +154,7 @@ public:
|
||||
|
||||
class FakeDocumentCubeFaceExportWriteServices final
|
||||
: public pp::app::DocumentCubeFaceExportWriteServices
|
||||
, public pp::app::DocumentDepthExportWriteServices
|
||||
, public pp::app::DocumentExportCollectionWriteServices {
|
||||
public:
|
||||
pp::foundation::Status write_binary_file(
|
||||
@@ -266,6 +267,26 @@ void cube_face_export_rejects_invalid_target_inputs(pp::tests::Harness& harness)
|
||||
PP_EXPECT(harness, missing_name.status().code == pp::foundation::StatusCode::invalid_argument);
|
||||
}
|
||||
|
||||
void depth_export_builds_legacy_work_paths(pp::tests::Harness& harness)
|
||||
{
|
||||
const auto target = pp::app::make_document_depth_export_target("D:/Paint", "demo");
|
||||
|
||||
PP_EXPECT(harness, target);
|
||||
PP_EXPECT(harness, target.value().image_path == "D:/Paint/demo.png");
|
||||
PP_EXPECT(harness, target.value().depth_path == "D:/Paint/demo_depth.png");
|
||||
}
|
||||
|
||||
void depth_export_rejects_invalid_target_inputs(pp::tests::Harness& harness)
|
||||
{
|
||||
const auto missing_work_directory = pp::app::make_document_depth_export_target("", "demo");
|
||||
const auto missing_name = pp::app::make_document_depth_export_target("D:/Paint", "");
|
||||
|
||||
PP_EXPECT(harness, !missing_work_directory);
|
||||
PP_EXPECT(harness, missing_work_directory.status().code == pp::foundation::StatusCode::invalid_argument);
|
||||
PP_EXPECT(harness, !missing_name);
|
||||
PP_EXPECT(harness, missing_name.status().code == pp::foundation::StatusCode::invalid_argument);
|
||||
}
|
||||
|
||||
void cube_face_export_writer_writes_and_publishes_faces_in_order(pp::tests::Harness& harness)
|
||||
{
|
||||
const auto target = pp::app::make_document_cube_face_export_target("D:/Paint", "demo");
|
||||
@@ -349,6 +370,97 @@ void cube_face_export_writer_rejects_malformed_inputs(pp::tests::Harness& harnes
|
||||
PP_EXPECT(harness, services.publish_calls == 0);
|
||||
}
|
||||
|
||||
void depth_export_writer_writes_and_publishes_image_then_depth(pp::tests::Harness& harness)
|
||||
{
|
||||
const auto target = pp::app::make_document_depth_export_target("D:/Paint", "demo");
|
||||
const std::array<std::byte, 2> image_bytes {};
|
||||
const std::array<std::byte, 3> depth_bytes {};
|
||||
FakeDocumentCubeFaceExportWriteServices services;
|
||||
|
||||
PP_EXPECT(harness, target);
|
||||
PP_EXPECT(
|
||||
harness,
|
||||
pp::app::execute_document_depth_export_write(
|
||||
target.value(),
|
||||
pp::app::DocumentDepthExportPayload {
|
||||
.image_bytes = std::span<const std::byte>(image_bytes),
|
||||
.depth_bytes = std::span<const std::byte>(depth_bytes),
|
||||
},
|
||||
services)
|
||||
.ok());
|
||||
PP_EXPECT(harness, services.write_calls == 2);
|
||||
PP_EXPECT(harness, services.publish_calls == 2);
|
||||
PP_EXPECT(harness, services.total_bytes == 5U);
|
||||
PP_EXPECT(harness, services.last_path == "D:/Paint/demo_depth.png");
|
||||
PP_EXPECT(
|
||||
harness,
|
||||
services.call_order
|
||||
== "write:D:/Paint/demo.png;publish:D:/Paint/demo.png;"
|
||||
"write:D:/Paint/demo_depth.png;publish:D:/Paint/demo_depth.png;");
|
||||
}
|
||||
|
||||
void depth_export_writer_stops_before_depth_publish_on_write_failure(pp::tests::Harness& harness)
|
||||
{
|
||||
const auto target = pp::app::make_document_depth_export_target("D:/Paint", "demo");
|
||||
const std::array<std::byte, 2> image_bytes {};
|
||||
const std::array<std::byte, 3> depth_bytes {};
|
||||
FakeDocumentCubeFaceExportWriteServices services;
|
||||
services.fail_on_write_call = 2;
|
||||
|
||||
PP_EXPECT(harness, target);
|
||||
const auto status = pp::app::execute_document_depth_export_write(
|
||||
target.value(),
|
||||
pp::app::DocumentDepthExportPayload {
|
||||
.image_bytes = std::span<const std::byte>(image_bytes),
|
||||
.depth_bytes = std::span<const std::byte>(depth_bytes),
|
||||
},
|
||||
services);
|
||||
PP_EXPECT(harness, !status.ok());
|
||||
PP_EXPECT(harness, services.write_calls == 2);
|
||||
PP_EXPECT(harness, services.publish_calls == 1);
|
||||
PP_EXPECT(
|
||||
harness,
|
||||
services.call_order
|
||||
== "write:D:/Paint/demo.png;publish:D:/Paint/demo.png;"
|
||||
"write:D:/Paint/demo_depth.png;");
|
||||
}
|
||||
|
||||
void depth_export_writer_rejects_malformed_inputs(pp::tests::Harness& harness)
|
||||
{
|
||||
const auto target = pp::app::make_document_depth_export_target("D:/Paint", "demo");
|
||||
const std::array<std::byte, 2> image_bytes {};
|
||||
const std::array<std::byte, 3> depth_bytes {};
|
||||
FakeDocumentCubeFaceExportWriteServices services;
|
||||
|
||||
PP_EXPECT(harness, target);
|
||||
auto empty_image_path = target.value();
|
||||
empty_image_path.image_path.clear();
|
||||
PP_EXPECT(
|
||||
harness,
|
||||
!pp::app::execute_document_depth_export_write(
|
||||
empty_image_path,
|
||||
pp::app::DocumentDepthExportPayload {
|
||||
.image_bytes = std::span<const std::byte>(image_bytes),
|
||||
.depth_bytes = std::span<const std::byte>(depth_bytes),
|
||||
},
|
||||
services)
|
||||
.ok());
|
||||
|
||||
PP_EXPECT(
|
||||
harness,
|
||||
!pp::app::execute_document_depth_export_write(
|
||||
target.value(),
|
||||
pp::app::DocumentDepthExportPayload {
|
||||
.image_bytes = {},
|
||||
.depth_bytes = std::span<const std::byte>(depth_bytes),
|
||||
},
|
||||
services)
|
||||
.ok());
|
||||
|
||||
PP_EXPECT(harness, services.write_calls == 0);
|
||||
PP_EXPECT(harness, services.publish_calls == 0);
|
||||
}
|
||||
|
||||
void collection_export_builds_legacy_path_suffixes(pp::tests::Harness& harness)
|
||||
{
|
||||
PP_EXPECT(
|
||||
@@ -976,6 +1088,8 @@ int main()
|
||||
harness.run("picked directory export builds stem", picked_directory_export_builds_stem);
|
||||
harness.run("cube face export builds legacy work paths", cube_face_export_builds_legacy_work_paths);
|
||||
harness.run("cube face export rejects invalid target inputs", cube_face_export_rejects_invalid_target_inputs);
|
||||
harness.run("depth export builds legacy work paths", depth_export_builds_legacy_work_paths);
|
||||
harness.run("depth export rejects invalid target inputs", depth_export_rejects_invalid_target_inputs);
|
||||
harness.run(
|
||||
"cube face export writer writes and publishes faces in order",
|
||||
cube_face_export_writer_writes_and_publishes_faces_in_order);
|
||||
@@ -983,6 +1097,13 @@ int main()
|
||||
"cube face export writer stops before publish on write failure",
|
||||
cube_face_export_writer_stops_before_publish_on_write_failure);
|
||||
harness.run("cube face export writer rejects malformed inputs", cube_face_export_writer_rejects_malformed_inputs);
|
||||
harness.run(
|
||||
"depth export writer writes and publishes image then depth",
|
||||
depth_export_writer_writes_and_publishes_image_then_depth);
|
||||
harness.run(
|
||||
"depth export writer stops before depth publish on write failure",
|
||||
depth_export_writer_stops_before_depth_publish_on_write_failure);
|
||||
harness.run("depth export writer rejects malformed inputs", depth_export_writer_rejects_malformed_inputs);
|
||||
harness.run("collection export builds legacy path suffixes", collection_export_builds_legacy_path_suffixes);
|
||||
harness.run(
|
||||
"collection export writer writes and publishes payloads in order",
|
||||
|
||||
@@ -24,6 +24,7 @@ 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_document_depth_export_render;
|
||||
using pp::paint_renderer::plan_stroke_composite;
|
||||
using pp::paint_renderer::stroke_composite_path_name;
|
||||
using pp::paint_renderer::stroke_composite_requires_feedback;
|
||||
@@ -1036,6 +1037,80 @@ void exports_document_animation_frames_as_equirectangular_pngs(pp::tests::Harnes
|
||||
PP_EXPECT(h, decoded.value().pixels[2] == 0U);
|
||||
}
|
||||
|
||||
void plans_document_depth_export_renderer_work(pp::tests::Harness& h)
|
||||
{
|
||||
std::vector<LayerFacePixels> visible_faces;
|
||||
visible_faces.push_back(solid_face_payload(0, 1, 1, 255, 0, 0, 255));
|
||||
visible_faces.push_back(solid_face_payload(2, 1, 1, 0, 0, 255, 255));
|
||||
|
||||
const AnimationFrame root_frames[] {
|
||||
{ .duration_ms = 100, .face_pixels = {} },
|
||||
};
|
||||
const AnimationFrame visible_layer_frames[] {
|
||||
{ .duration_ms = 100, .face_pixels = visible_faces },
|
||||
};
|
||||
const AnimationFrame hidden_layer_frames[] {
|
||||
{
|
||||
.duration_ms = 100,
|
||||
.face_pixels = solid_cube_faces(1, 1, 255, 255, 0, 255),
|
||||
},
|
||||
};
|
||||
const AnimationFrame empty_layer_frames[] {
|
||||
{ .duration_ms = 100, .face_pixels = {} },
|
||||
};
|
||||
const DocumentLayerConfig layers[] {
|
||||
{
|
||||
.name = "Visible",
|
||||
.frames = std::span<const AnimationFrame>(visible_layer_frames, 1),
|
||||
},
|
||||
{
|
||||
.name = "Hidden",
|
||||
.visible = false,
|
||||
.frames = std::span<const AnimationFrame>(hidden_layer_frames, 1),
|
||||
},
|
||||
{
|
||||
.name = "Transparent",
|
||||
.opacity = 0.0F,
|
||||
.frames = std::span<const AnimationFrame>(hidden_layer_frames, 1),
|
||||
},
|
||||
{
|
||||
.name = "EmptyVisible",
|
||||
.frames = std::span<const AnimationFrame>(empty_layer_frames, 1),
|
||||
},
|
||||
};
|
||||
const auto document = CanvasDocument::create_from_snapshot(DocumentSnapshotConfig {
|
||||
.width = 1,
|
||||
.height = 1,
|
||||
.layers = std::span<const DocumentLayerConfig>(layers, 4),
|
||||
.frames = std::span<const AnimationFrame>(root_frames, 1),
|
||||
.selection_masks = {},
|
||||
});
|
||||
PP_EXPECT(h, document);
|
||||
if (!document) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto plan = plan_document_depth_export_render(
|
||||
pp::paint_renderer::DocumentDepthExportRenderPlanRequest {
|
||||
.document = &document.value(),
|
||||
.frame_index = 0,
|
||||
});
|
||||
PP_EXPECT(h, plan);
|
||||
if (!plan) {
|
||||
return;
|
||||
}
|
||||
|
||||
PP_EXPECT(h, plan.value().output_extent.width == 1024U);
|
||||
PP_EXPECT(h, plan.value().output_extent.height == 1024U);
|
||||
PP_EXPECT(h, plan.value().merged_face_draw_count == pp::document::cube_face_count);
|
||||
PP_EXPECT(h, plan.value().visited_layer_count == 4U);
|
||||
PP_EXPECT(h, plan.value().visible_layer_count == 2U);
|
||||
PP_EXPECT(h, plan.value().face_payload_count == 2U);
|
||||
PP_EXPECT(h, plan.value().layer_depth_draw_count == 2U);
|
||||
PP_EXPECT(h, plan.value().uses_perspective_camera);
|
||||
PP_EXPECT(h, plan.value().requires_renderer_readback);
|
||||
}
|
||||
|
||||
void document_frame_upload_rejects_invalid_requests(pp::tests::Harness& h)
|
||||
{
|
||||
RecordingRenderDevice device;
|
||||
@@ -1050,6 +1125,8 @@ void document_frame_upload_rejects_invalid_requests(pp::tests::Harness& h)
|
||||
pp::paint_renderer::DocumentLayerEquirectangularPngExportRequest {});
|
||||
const auto no_document_frames = pp::paint_renderer::export_document_animation_frames_equirectangular_pngs(
|
||||
pp::paint_renderer::DocumentAnimationFrameEquirectangularPngExportRequest {});
|
||||
const auto no_document_depth = plan_document_depth_export_render(
|
||||
pp::paint_renderer::DocumentDepthExportRenderPlanRequest {});
|
||||
|
||||
const AnimationFrame root_frames[] {
|
||||
{ .duration_ms = 100, .face_pixels = {} },
|
||||
@@ -1077,6 +1154,17 @@ void document_frame_upload_rejects_invalid_requests(pp::tests::Harness& h)
|
||||
.document = &document.value(),
|
||||
.frame_index = 1,
|
||||
});
|
||||
const auto bad_frame_depth = plan_document_depth_export_render(
|
||||
pp::paint_renderer::DocumentDepthExportRenderPlanRequest {
|
||||
.document = &document.value(),
|
||||
.frame_index = 1,
|
||||
});
|
||||
const auto bad_extent_depth = plan_document_depth_export_render(
|
||||
pp::paint_renderer::DocumentDepthExportRenderPlanRequest {
|
||||
.document = &document.value(),
|
||||
.frame_index = 0,
|
||||
.output_extent = Extent2D {},
|
||||
});
|
||||
|
||||
PP_EXPECT(h, !no_document.ok());
|
||||
PP_EXPECT(h, no_document.status().code == StatusCode::invalid_argument);
|
||||
@@ -1088,10 +1176,16 @@ void document_frame_upload_rejects_invalid_requests(pp::tests::Harness& h)
|
||||
PP_EXPECT(h, no_document_layers.status().code == StatusCode::invalid_argument);
|
||||
PP_EXPECT(h, !no_document_frames.ok());
|
||||
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, !bad_frame.ok());
|
||||
PP_EXPECT(h, bad_frame.status().code == StatusCode::out_of_range);
|
||||
PP_EXPECT(h, !bad_frame_readiness.ok());
|
||||
PP_EXPECT(h, bad_frame_readiness.status().code == StatusCode::out_of_range);
|
||||
PP_EXPECT(h, !bad_frame_depth.ok());
|
||||
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, device.commands().empty());
|
||||
}
|
||||
|
||||
@@ -1448,6 +1542,7 @@ int main()
|
||||
harness.run(
|
||||
"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("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);
|
||||
|
||||
Reference in New Issue
Block a user