151 lines
5.2 KiB
C++
151 lines
5.2 KiB
C++
#pragma once
|
|
|
|
#include "../base/Types.h"
|
|
#include "../event/Event.h"
|
|
#include <renderive/frame_control/Frame_Consumer_Feedback.hpp>
|
|
|
|
#include <atomic>
|
|
#include <concepts>
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <string>
|
|
|
|
class Scene_Base;
|
|
|
|
namespace renderive {
|
|
|
|
class Performance_Overlay;
|
|
struct Performance_Overlay_Options;
|
|
class Renderable;
|
|
|
|
enum class Frame_Control_Mode : std::uint8_t {
|
|
Manual,
|
|
Low_Latency,
|
|
Playback
|
|
};
|
|
|
|
struct Refresh_Control_Snapshot {
|
|
double frequency_hz{};
|
|
std::uint64_t frame_count{};
|
|
std::uint64_t next_refresh_interval_ns{};
|
|
};
|
|
|
|
struct Low_Latency_Diagnostics {
|
|
bool active{};
|
|
Refresh_Control_Snapshot refresh;
|
|
};
|
|
|
|
struct Frame_Observer_Snapshot {
|
|
Frame_Control_Mode mode = Frame_Control_Mode::Low_Latency;
|
|
std::string last_event;
|
|
std::string limit_state;
|
|
double frequency_hz{};
|
|
std::uint64_t observation_count{};
|
|
std::uint64_t produced_frame_count{};
|
|
std::uint64_t consumed_frame_count{};
|
|
std::uint64_t dropped_frame_count{};
|
|
std::uint64_t failed_operation_count{};
|
|
std::uint64_t pending_frame_count{};
|
|
std::uint64_t latest_sequence{};
|
|
std::uint64_t paint_duration_ns{};
|
|
std::uint64_t render_duration_ns{};
|
|
std::uint64_t target_interval_ns{};
|
|
bool frequency_limit_enabled{};
|
|
bool consumer_feedback_enabled{};
|
|
std::uint64_t bottleneck_duration_ns{};
|
|
std::uint64_t consumer_sample_interval_ns{};
|
|
std::uint64_t consumer_smoothed_interval_ns{};
|
|
std::uint64_t consumer_variation_ns{};
|
|
std::uint64_t consumer_safety_interval_ns{};
|
|
std::uint64_t consumer_interval_ns{};
|
|
std::uint64_t next_refresh_interval_ns{};
|
|
std::uint64_t paint_lease_wait_ns{};
|
|
std::uint64_t paint_state_wait_ns{};
|
|
std::uint64_t publish_state_wait_ns{};
|
|
std::uint64_t ready_wait_ns{};
|
|
std::uint64_t frame_age_at_render_ns{};
|
|
std::uint64_t render_lease_wait_ns{};
|
|
std::uint64_t render_state_wait_ns{};
|
|
std::uint64_t render_finish_state_wait_ns{};
|
|
std::uint64_t queue_wait_ns{};
|
|
std::uint64_t end_to_end_ns{};
|
|
};
|
|
|
|
class Presentation_Sink {
|
|
public:
|
|
virtual ~Presentation_Sink() = default;
|
|
virtual void request_present(Rect dirty_rect) = 0;
|
|
};
|
|
|
|
class LIB_DECL Plot_Core {
|
|
public:
|
|
Plot_Core();
|
|
explicit Plot_Core(Frame_Control_Mode mode);
|
|
~Plot_Core();
|
|
Plot_Core(const Plot_Core&) = delete;
|
|
Plot_Core& operator=(const Plot_Core&) = delete;
|
|
|
|
void init();
|
|
[[nodiscard]] std::shared_ptr<Renderable> root_renderable() const;
|
|
[[nodiscard]] std::shared_ptr<Renderable> create_renderable_node(
|
|
const std::shared_ptr<Renderable>& parent,
|
|
std::string object_name = {});
|
|
|
|
template <class T, class... Args>
|
|
requires std::derived_from<T, Renderable> && std::constructible_from<T, Plot_Core&, Args&&...>
|
|
std::shared_ptr<T> make_renderable(const std::shared_ptr<Renderable>& parent, Args&&... args) {
|
|
auto renderable = renderive::make_shared<T>(Memory_Domain::Renderable, *this,
|
|
std::forward<Args>(args)...);
|
|
attach_renderable(renderable, parent);
|
|
return renderable;
|
|
}
|
|
|
|
void remove_renderable(const std::shared_ptr<Renderable>& renderable);
|
|
void set_background_color(Color color);
|
|
[[nodiscard]] Color background_color() const noexcept;
|
|
void set_viewport_size(Size size);
|
|
[[nodiscard]] Size viewport_size() const noexcept;
|
|
|
|
void dispatch_event(const Event& event);
|
|
void notify_model_dirty() noexcept;
|
|
[[nodiscard]] bool prepare_frame();
|
|
[[nodiscard]] bool refresh_manual_frame();
|
|
[[nodiscard]] bool render_prepared_frame();
|
|
[[nodiscard]] bool discard_pending_frame();
|
|
[[nodiscard]] bool render_frame(bool force = false);
|
|
void with_frame(const std::function<void(Image_View)>& consumer);
|
|
|
|
void activate_view() noexcept;
|
|
void deactivate_view() noexcept;
|
|
[[nodiscard]] bool view_active() const noexcept;
|
|
|
|
void set_max_render_fps(double fps);
|
|
void clear_max_render_fps();
|
|
void set_consumer_feedback(Frame_Consumer_Feedback feedback);
|
|
void clear_consumer_feedback();
|
|
[[nodiscard]] double max_render_fps() const noexcept;
|
|
[[nodiscard]] Low_Latency_Diagnostics diagnostics() const;
|
|
[[nodiscard]] Refresh_Control_Snapshot refresh_feedback_snapshot() const;
|
|
[[nodiscard]] Frame_Control_Mode frame_control_mode() const noexcept;
|
|
[[nodiscard]] Frame_Observer_Snapshot frame_observer_snapshot() const;
|
|
|
|
void set_presentation_sink(std::weak_ptr<Presentation_Sink> sink);
|
|
[[nodiscard]] std::shared_ptr<Performance_Overlay> performance_overlay() const;
|
|
|
|
private:
|
|
friend class Renderable;
|
|
friend std::shared_ptr<Performance_Overlay> attach_performance_overlay(Plot_Core&);
|
|
friend std::shared_ptr<Performance_Overlay> attach_performance_overlay(
|
|
Plot_Core&, const Performance_Overlay_Options&);
|
|
struct Impl;
|
|
std::unique_ptr<Impl> impl_;
|
|
|
|
[[nodiscard]] ::Scene_Base& kernel_scene() const noexcept;
|
|
void attach_renderable(const std::shared_ptr<Renderable>& renderable,
|
|
const std::shared_ptr<Renderable>& parent);
|
|
void set_renderable_cache(Renderable& renderable, Renderable_Cache_Mode mode);
|
|
void set_performance_overlay(std::shared_ptr<Performance_Overlay> overlay);
|
|
};
|
|
|
|
} // namespace renderive
|