Upload document frame faces through renderer API

This commit is contained in:
2026-06-05 17:37:21 +02:00
parent 7c6c5f3e36
commit d0e023556b
9 changed files with 278 additions and 17 deletions

View File

@@ -1,4 +1,5 @@
#include "paint_renderer/compositor.h"
#include "renderer_api/recording_renderer.h"
#include "test_harness.h"
#include <cmath>
@@ -26,6 +27,8 @@ using pp::paint_renderer::plan_stroke_composite;
using pp::paint_renderer::stroke_composite_path_name;
using pp::paint_renderer::stroke_composite_requires_feedback;
using pp::renderer::Extent2D;
using pp::renderer::RecordedRenderCommandKind;
using pp::renderer::RecordingRenderDevice;
using pp::renderer::RenderDeviceFeatures;
using pp::renderer::TextureFormat;
using pp::renderer::TextureUsage;
@@ -456,6 +459,124 @@ void document_frame_composite_rejects_invalid_requests(pp::tests::Harness& h)
PP_EXPECT(h, bad_frame.status().code == StatusCode::out_of_range);
}
void uploads_document_frame_faces_to_renderer_api(pp::tests::Harness& h)
{
const AnimationFrame root_frames[] {
{ .duration_ms = 100, .face_pixels = {} },
};
const AnimationFrame layer_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 = 3,
.x = 0,
.y = 0,
.width = 1,
.height = 1,
.rgba8 = { 0, 255, 0, 128 },
},
},
},
};
const DocumentLayerConfig layers[] {
{
.name = "Paint",
.frames = std::span<const AnimationFrame>(layer_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);
RecordingRenderDevice device;
const auto result = pp::paint_renderer::upload_document_frame_faces(
device,
pp::paint_renderer::DocumentFrameUploadRequest {
.document = &document.value(),
.frame_index = 0,
});
PP_EXPECT(h, result);
if (result) {
PP_EXPECT(h, result.value().texture_count == pp::document::cube_face_count);
PP_EXPECT(h, result.value().transition_count == pp::document::cube_face_count);
PP_EXPECT(h, result.value().uploaded_bytes == 24U);
PP_EXPECT(h, result.value().composite.face_payload_count == 2U);
PP_EXPECT(h, result.value().face_textures[0] != nullptr);
PP_EXPECT(h, result.value().face_textures[0]->desc().extent.width == 1U);
PP_EXPECT(h, result.value().face_textures[0]->desc().format == TextureFormat::rgba8);
}
std::size_t upload_count = 0;
std::size_t transition_count = 0;
for (const auto& command : device.commands()) {
if (command.kind == RecordedRenderCommandKind::upload_texture) {
++upload_count;
PP_EXPECT(h, command.upload_bytes == 4U);
PP_EXPECT(h, command.readback_region.width == 1U);
PP_EXPECT(h, command.texture_desc.format == TextureFormat::rgba8);
}
if (command.kind == RecordedRenderCommandKind::transition_texture) {
++transition_count;
PP_EXPECT(h, command.before_state == pp::renderer::TextureState::upload_destination);
PP_EXPECT(h, command.after_state == pp::renderer::TextureState::shader_read);
}
}
PP_EXPECT(h, device.commands().size() == 12U);
PP_EXPECT(h, upload_count == pp::document::cube_face_count);
PP_EXPECT(h, transition_count == pp::document::cube_face_count);
}
void document_frame_upload_rejects_invalid_requests(pp::tests::Harness& h)
{
RecordingRenderDevice device;
const auto no_document = pp::paint_renderer::upload_document_frame_faces(
device,
pp::paint_renderer::DocumentFrameUploadRequest {});
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<const DocumentLayerConfig>(layers, 1),
.frames = std::span<const AnimationFrame>(root_frames, 1),
.selection_masks = {},
});
PP_EXPECT(h, document);
const auto bad_frame = pp::paint_renderer::upload_document_frame_faces(
device,
pp::paint_renderer::DocumentFrameUploadRequest {
.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);
PP_EXPECT(h, device.commands().empty());
}
void detects_feedback_requirements(pp::tests::Harness& h)
{
PP_EXPECT(h, !stroke_composite_requires_feedback(
@@ -800,6 +921,8 @@ int main()
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("uploads_document_frame_faces_to_renderer_api", uploads_document_frame_faces_to_renderer_api);
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);
harness.run("rejects_bad_stroke_composite_plans", rejects_bad_stroke_composite_plans);