Files
Aethera/mcp/core/runtime/Gallery_Runtime.hpp
T
2026-09-03 15:31:39 +08:00

77 lines
4.2 KiB
C++

#pragma once
#include <nlohmann/json_fwd.hpp>
#include <render_2D/module/scene/Render_Scene_2D.hpp>
#include <render_3D/scene/Render_Scene_3D.hpp>
#include <chrono>
#include <cstddef>
#include <cstdint>
#include <functional>
#include <memory>
#include <string>
#include <string_view>
#include <utility>
#include <variant>
#include <vector>
namespace aethera::web {
enum struct Gallery_Pixel_Layout : std::uint8_t {
bgra8, /* Blend2D native premultiplied BGRA8 bytes. */
rgba8 /* Datoviz native RGBA8 bytes. */
};
struct Gallery_Frame_Request {
std::chrono::steady_clock::time_point issued_at{}; /* Monotonic time at which the external request entered the control service. */
double time_milliseconds{}; /* Plot animation time supplied by the caller or derived from the runtime clock. */
std::uint64_t sequence{}; /* Runtime-assigned monotonic render request sequence. */
std::uint64_t correlation_id{}; /* Optional caller sequence carried through the rendered frame. */
std::uint32_t width{720}; /* Requested physical pixel width. */
std::uint32_t height{420}; /* Requested physical pixel height. */
};
struct Gallery_Pixel_Frame {
std::shared_ptr<const std::vector<std::byte>> pixels{}; /* Shared immutable bytes; asynchronous publishers retain this owner until feedback. */
Gallery_Pixel_Layout layout{Gallery_Pixel_Layout::rgba8}; /* Byte channel order. */
std::chrono::microseconds presentation_time{}; /* Plot animation timestamp. */
std::uint64_t sequence{}; /* Runtime-assigned monotonic rendered-frame sequence. */
std::uint64_t correlation_id{}; /* Caller request correlation. */
std::uint64_t rendered_sequence{}; /* Physical 3D frame actually read back; equals sequence for 2D. */
std::uint64_t rendered_correlation_id{}; /* Correlation carried by the physical rendered frame. */
std::uint32_t width{}; /* Pixel width. */
std::uint32_t height{}; /* Pixel height. */
};
struct Gallery_Frame {
std::shared_ptr<const Gallery_Pixel_Frame> pixels{}; /* Shared immutable publication payload. */
};
enum struct Gallery_Frame_Publication : std::uint8_t {
ignored, /* No consumer accepted the frame; the Sink may release it immediately. */
completed, /* Publication completed before the publisher returned. */
asynchronous /* Publication retained the frame and will return Gallery_Publication_Feedback. */
};
struct Gallery_Publication_Feedback {
std::chrono::steady_clock::time_point completed_at{}; /* Monotonic completion time reported by the asynchronous publisher. */
std::uint64_t sequence{}; /* Gallery frame sequence whose Sink borrow is released. */
bool succeeded{}; /* Whether the asynchronous publisher completed successfully. */
};
using Gallery_Frame_Publisher = std::function<Gallery_Frame_Publication(std::string_view, std::shared_ptr<const Gallery_Frame>)>;
struct Gallery_Component {
virtual ~Gallery_Component() = default;
[[nodiscard]] virtual nlohmann::json schema() const = 0;
[[nodiscard]] virtual nlohmann::json write_prop(std::string_view component, std::string_view key, const nlohmann::json& value) = 0;
[[nodiscard]] virtual nlohmann::json component_state(std::string_view component) const = 0;
[[nodiscard]] virtual nlohmann::json capture_components(const std::vector<std::string>& components) const = 0;
[[nodiscard]] virtual nlohmann::json data_generator_schema() const = 0;
[[nodiscard]] virtual nlohmann::json generate_data(const nlohmann::json& input) = 0;
virtual void update(const Gallery_Frame_Request& request) = 0;
};
using Gallery_Scene = std::variant<std::unique_ptr<render_2d::Render_Scene_2D>, std::unique_ptr<render_3d::Render_Scene_3D>>;
using Gallery_Build = std::pair<std::unique_ptr<Gallery_Component>, Gallery_Scene>;
} // namespace aethera::web