#pragma once #include #include #include #include #include #include #include #include #include #include #include namespace aethera::web { struct Gallery_Video_Stream; struct Plot_Input_Event { Event_Type type{Event_Type::pointer_move}; /* 输入事件业务类型。 */ double time_milliseconds{}; /* 输入生产者单调时间线上的事件发生时刻。 */ render_2d::Point_F position{}; /* Plot 像素坐标。 */ render_2d::Point_F global_position{}; /* 浏览器屏幕像素坐标。 */ Mouse_Button button{Mouse_Button::none}; /* 本次变化涉及的鼠标按键。 */ Mouse_Button_Mask buttons{}; /* 事件产生时保持按下的按键集合。 */ Keyboard_Modifier modifiers{Keyboard_Modifier::none}; /* 事件产生时的修饰键集合。 */ double pixel_delta_x{}; /* 水平高精度滚轮增量。 */ double pixel_delta_y{}; /* 垂直高精度滚轮增量。 */ double angle_delta_x{}; /* 水平离散滚轮增量。 */ double angle_delta_y{}; /* 垂直离散滚轮增量。 */ Key key{Key::unknown}; /* 标准化键盘按键。 */ std::uint32_t native_key{}; /* 浏览器原生按键码。 */ bool auto_repeat{}; /* 是否为系统重复按键。 */ }; struct Plot_Render_Tick { std::chrono::steady_clock::time_point issued_at{}; /* 页面帧时钟发布本 tick 的单调时刻;手动帧在提交时填写。 */ std::uint64_t sequence{}; /* Kernel 全局 Frame_Scheduler 时间轴上的关联序号。 */ double time_milliseconds{}; /* 页面级单调时间线,所有图共享同一个动画时刻。 */ std::uint32_t width{320}; /* 当前图在媒体图集中的固定像素宽度。 */ std::uint32_t height{192}; /* 当前图在媒体图集中的固定像素高度。 */ Frame_Request_Source source{Frame_Request_Source::immediate}; /* 本次请求来自周期时钟、手动操作或最大吞吐自驱动。 */ }; enum struct Plot_Pixel_Layout : std::uint8_t { bgra8, rgba8 }; struct Plot_Pixel_Frame { std::shared_ptr> pixels{}; /* 可选的不可变原生像素;停传输时为空但完成身份仍有效。 */ Plot_Pixel_Layout layout{Plot_Pixel_Layout::rgba8}; /* 像素真实通道布局,由产生帧的后端标注。 */ std::chrono::microseconds presentation_time{}; /* 页面媒体时钟上的显示时间戳。 */ std::uint64_t sequence{}; /* 对应 Plot 完成帧的局部单调序号。 */ std::uint64_t correlation_id{}; /* 触发本帧的页面级时钟序号;手动帧等于局部序号。 */ std::uint64_t rendered_sequence{}; /* 实际产生当前像素的 Scene/GPU 提交帧序号。 */ std::uint64_t rendered_correlation_id{}; /* 实际画面对应的页面级时钟序号。 */ std::uint32_t width{}; /* 原生像素宽度。 */ std::uint32_t height{}; /* 原生像素高度。 */ }; struct Plot_Stream_Frame { std::string notification{}; /* 仅用于终止错误等低频控制通知;正常帧为空。 */ std::shared_ptr pixels{}; /* 每帧完成进度及其可选图集像素。 */ }; struct Plot final : public std::enable_shared_from_this { public: using Stream_Id = std::uint64_t; using Stream_Handler = std::function)>; using Json_Handler = std::function; struct Scene_View { public: virtual ~Scene_View() = 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& 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 Plot_Render_Tick& tick) = 0; }; Plot(std::unique_ptr scene, std::unique_ptr view); Plot(std::unique_ptr scene, std::unique_ptr view); ~Plot(); Plot(const Plot&) = delete; Plot& operator=(const Plot&) = delete; [[nodiscard]] Stream_Id subscribe(Stream_Handler handler); void unsubscribe(Stream_Id stream); void configure_stream(Stream_Id stream, std::uint32_t width, std::uint32_t height); void schedule_render(Plot_Render_Tick tick); void render_once(); void submit_input(Plot_Input_Event event); [[nodiscard]] nlohmann::json schema(); [[nodiscard]] nlohmann::json write_prop(std::string_view component, std::string_view key, const nlohmann::json& value); [[nodiscard]] nlohmann::json component_state(std::string_view component) const; [[nodiscard]] nlohmann::json generate_data(const nlohmann::json& input); [[nodiscard]] nlohmann::json diagnostics() const; /* 清空旧捕获并请求接下来实际完成的 frame_count 帧 Task DAG。 */ void request_taskflow_trace(std::size_t frame_count); [[nodiscard]] nlohmann::json taskflow_trace() const; /* 仅捕获 publish 之后真实执行的外接 Task_Graph;不追踪另一张 Plot 的 Render DAG。 */ void request_post_publish_taskflow_trace(std::size_t frame_count); [[nodiscard]] nlohmann::json post_publish_taskflow_trace() const; void reset_diagnostics(); private: friend struct Gallery_Video_Stream; struct Private; void ensure_started(); void attach_scene_completion(std::unique_ptr completion); std::unique_ptr d; }; }