Add document face compositor bridge
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
#include "test_harness.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <span>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
@@ -9,11 +11,13 @@ using pp::foundation::StatusCode;
|
||||
using pp::paint::BlendMode;
|
||||
using pp::paint::Rgba;
|
||||
using pp::paint::StrokeBlendMode;
|
||||
using pp::paint_renderer::LayerCompositeView;
|
||||
using pp::paint_renderer::CanvasBlendGateRequest;
|
||||
using pp::paint_renderer::DocumentFaceCompositeRequest;
|
||||
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::plan_canvas_blend_gate;
|
||||
using pp::paint_renderer::plan_canvas_stroke_feedback;
|
||||
using pp::paint_renderer::plan_stroke_composite;
|
||||
@@ -23,6 +27,11 @@ using pp::renderer::Extent2D;
|
||||
using pp::renderer::RenderDeviceFeatures;
|
||||
using pp::renderer::TextureFormat;
|
||||
using pp::renderer::TextureUsage;
|
||||
using pp::document::AnimationFrame;
|
||||
using pp::document::CanvasDocument;
|
||||
using pp::document::DocumentLayerConfig;
|
||||
using pp::document::DocumentSnapshotConfig;
|
||||
using pp::document::LayerFacePixels;
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -110,6 +119,218 @@ void rejects_invalid_sizes_and_opacity(pp::tests::Harness& h)
|
||||
PP_EXPECT(h, bad_extent.code == StatusCode::invalid_argument);
|
||||
}
|
||||
|
||||
void composites_document_face_payloads_in_layer_order(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 = 2,
|
||||
.height = 1,
|
||||
.rgba8 = { 255, 0, 0, 255, 0, 255, 0, 255 },
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const AnimationFrame paint_frames[] {
|
||||
{
|
||||
.duration_ms = 100,
|
||||
.face_pixels = {
|
||||
LayerFacePixels {
|
||||
.face_index = 0,
|
||||
.x = 1,
|
||||
.y = 0,
|
||||
.width = 1,
|
||||
.height = 1,
|
||||
.rgba8 = { 0, 0, 255, 255 },
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const AnimationFrame hidden_frames[] {
|
||||
{
|
||||
.duration_ms = 100,
|
||||
.face_pixels = {
|
||||
LayerFacePixels {
|
||||
.face_index = 0,
|
||||
.x = 0,
|
||||
.y = 0,
|
||||
.width = 1,
|
||||
.height = 1,
|
||||
.rgba8 = { 255, 255, 255, 255 },
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const DocumentLayerConfig layers[] {
|
||||
{
|
||||
.name = "Base",
|
||||
.frames = std::span<const AnimationFrame>(base_frames, 1),
|
||||
},
|
||||
{
|
||||
.name = "Paint",
|
||||
.opacity = 0.5F,
|
||||
.frames = std::span<const AnimationFrame>(paint_frames, 1),
|
||||
},
|
||||
{
|
||||
.name = "Hidden",
|
||||
.visible = false,
|
||||
.frames = std::span<const AnimationFrame>(hidden_frames, 1),
|
||||
},
|
||||
};
|
||||
|
||||
const auto document = CanvasDocument::create_from_snapshot(DocumentSnapshotConfig {
|
||||
.width = 2,
|
||||
.height = 1,
|
||||
.layers = std::span<const DocumentLayerConfig>(layers, 3),
|
||||
.frames = std::span<const AnimationFrame>(root_frames, 1),
|
||||
.selection_masks = {},
|
||||
});
|
||||
PP_EXPECT(h, document);
|
||||
const auto result = composite_document_face(DocumentFaceCompositeRequest {
|
||||
.document = &document.value(),
|
||||
.frame_index = 0,
|
||||
.face_index = 0,
|
||||
});
|
||||
|
||||
PP_EXPECT(h, result);
|
||||
if (result) {
|
||||
PP_EXPECT(h, result.value().extent.width == 2U);
|
||||
PP_EXPECT(h, result.value().extent.height == 1U);
|
||||
PP_EXPECT(h, result.value().visited_layer_count == 3U);
|
||||
PP_EXPECT(h, result.value().composited_layer_count == 2U);
|
||||
PP_EXPECT(h, result.value().face_payload_count == 2U);
|
||||
PP_EXPECT(h, result.value().pixels.size() == 2U);
|
||||
PP_EXPECT(h, near(result.value().pixels[0].r, 1.0F));
|
||||
PP_EXPECT(h, near(result.value().pixels[0].g, 0.0F));
|
||||
PP_EXPECT(h, near(result.value().pixels[0].b, 0.0F));
|
||||
PP_EXPECT(h, near(result.value().pixels[0].a, 1.0F));
|
||||
PP_EXPECT(h, near(result.value().pixels[1].r, 0.0F));
|
||||
PP_EXPECT(h, near(result.value().pixels[1].g, 0.5F));
|
||||
PP_EXPECT(h, near(result.value().pixels[1].b, 0.5F));
|
||||
PP_EXPECT(h, near(result.value().pixels[1].a, 1.0F));
|
||||
}
|
||||
}
|
||||
|
||||
void document_face_composite_skips_layers_without_requested_frame(pp::tests::Harness& h)
|
||||
{
|
||||
const AnimationFrame root_frames[] {
|
||||
{ .duration_ms = 100, .face_pixels = {} },
|
||||
{ .duration_ms = 100, .face_pixels = {} },
|
||||
};
|
||||
const AnimationFrame short_layer_frames[] {
|
||||
{
|
||||
.duration_ms = 100,
|
||||
.face_pixels = {
|
||||
LayerFacePixels {
|
||||
.face_index = 0,
|
||||
.x = 0,
|
||||
.y = 0,
|
||||
.width = 1,
|
||||
.height = 1,
|
||||
.rgba8 = { 255, 0, 0, 255 },
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const AnimationFrame animated_layer_frames[] {
|
||||
{ .duration_ms = 100, .face_pixels = {} },
|
||||
{
|
||||
.duration_ms = 100,
|
||||
.face_pixels = {
|
||||
LayerFacePixels {
|
||||
.face_index = 0,
|
||||
.x = 0,
|
||||
.y = 0,
|
||||
.width = 1,
|
||||
.height = 1,
|
||||
.rgba8 = { 0, 0, 255, 255 },
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const DocumentLayerConfig layers[] {
|
||||
{
|
||||
.name = "Short",
|
||||
.frames = std::span<const AnimationFrame>(short_layer_frames, 1),
|
||||
},
|
||||
{
|
||||
.name = "Animated",
|
||||
.frames = std::span<const AnimationFrame>(animated_layer_frames, 2),
|
||||
},
|
||||
};
|
||||
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, 2),
|
||||
.selection_masks = {},
|
||||
});
|
||||
PP_EXPECT(h, document);
|
||||
|
||||
const auto result = composite_document_face(DocumentFaceCompositeRequest {
|
||||
.document = &document.value(),
|
||||
.frame_index = 1,
|
||||
.face_index = 0,
|
||||
});
|
||||
|
||||
PP_EXPECT(h, result);
|
||||
if (result) {
|
||||
PP_EXPECT(h, result.value().visited_layer_count == 2U);
|
||||
PP_EXPECT(h, result.value().composited_layer_count == 1U);
|
||||
PP_EXPECT(h, result.value().face_payload_count == 1U);
|
||||
PP_EXPECT(h, near(result.value().pixels[0].r, 0.0F));
|
||||
PP_EXPECT(h, near(result.value().pixels[0].g, 0.0F));
|
||||
PP_EXPECT(h, near(result.value().pixels[0].b, 1.0F));
|
||||
PP_EXPECT(h, near(result.value().pixels[0].a, 1.0F));
|
||||
}
|
||||
}
|
||||
|
||||
void document_face_composite_rejects_invalid_requests(pp::tests::Harness& h)
|
||||
{
|
||||
const auto no_document = composite_document_face(DocumentFaceCompositeRequest {});
|
||||
|
||||
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 = composite_document_face(DocumentFaceCompositeRequest {
|
||||
.document = &document.value(),
|
||||
.frame_index = 1,
|
||||
.face_index = 0,
|
||||
});
|
||||
const auto bad_face = composite_document_face(DocumentFaceCompositeRequest {
|
||||
.document = &document.value(),
|
||||
.frame_index = 0,
|
||||
.face_index = 6,
|
||||
});
|
||||
|
||||
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, !bad_face.ok());
|
||||
PP_EXPECT(h, bad_face.status().code == StatusCode::out_of_range);
|
||||
}
|
||||
|
||||
void detects_feedback_requirements(pp::tests::Harness& h)
|
||||
{
|
||||
PP_EXPECT(h, !stroke_composite_requires_feedback(
|
||||
@@ -449,6 +670,9 @@ int main()
|
||||
harness.run("composites_visible_layer_with_opacity", composites_visible_layer_with_opacity);
|
||||
harness.run("invisible_and_zero_opacity_layers_are_noops", invisible_and_zero_opacity_layers_are_noops);
|
||||
harness.run("rejects_invalid_sizes_and_opacity", rejects_invalid_sizes_and_opacity);
|
||||
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("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);
|
||||
|
||||
Reference in New Issue
Block a user