Loading...
Searching...
No Matches
GfxContext.hpp
1#pragma once
2#include <Gfx/Graph/Node.hpp>
3
4#include <ossia/dataflow/nodes/media.hpp>
5#include <ossia/dataflow/token_request.hpp>
6#include <ossia/detail/buffer_pool.hpp>
7#include <ossia/detail/flat_set.hpp>
8#include <ossia/detail/hash_map.hpp>
9#include <ossia/detail/mutex.hpp>
10#include <ossia/detail/variant.hpp>
11#include <ossia/detail/small_flat_map.hpp>
12#include <ossia/gfx/port_index.hpp>
13#include <ossia/network/value/value.hpp>
14#include <score/tools/Timers.hpp>
15#include <concurrentqueue.h>
16#include <score_plugin_gfx_export.h>
17namespace score {
18class HighResolutionTimer;
19class Timers;
20}
21namespace score::gfx
22{
23struct Graph;
24class OutputNode;
25}
26namespace score
27{
28struct DocumentContext;
29}
30namespace Gfx
31{
32using port_index = ossia::gfx::port_index;
33
34using EdgeSpec = std::pair<port_index, port_index>;
35class GfxExecutionAction;
36class SCORE_PLUGIN_GFX_EXPORT GfxContext : public QObject
37{
38 friend class GfxExecutionAction;
39
40public:
41 using NodePtr = std::unique_ptr<score::gfx::Node>;
42
43 explicit GfxContext(const score::DocumentContext& ctx);
45
46 int32_t register_node(NodePtr node);
47 int32_t register_preview_node(NodePtr node);
48 void connect_preview_node(EdgeSpec e);
49 void disconnect_preview_node(EdgeSpec e);
50 void unregister_node(int32_t idx);
51 void unregister_preview_node(int32_t idx);
52
53 void recompute_edges();
54 void recompute_graph();
55 void recompute_connections();
56
57 void update_inputs();
58 void updateGraph();
59
60 void send_message(score::gfx::Message&& msg) noexcept
61 {
62 tick_messages.enqueue(std::move(msg));
63 }
64
65private:
66 void run_commands();
67 void add_preview_output(score::gfx::OutputNode& out);
68 void remove_preview_output();
69 void add_edge(EdgeSpec e);
70 void remove_edge(EdgeSpec e);
71 void remove_node(std::vector<std::unique_ptr<score::gfx::Node>>& nursery, int32_t id);
72
73 void on_no_vsync_timer(score::HighResolutionTimer* self);
74 void on_watchdog_timer(score::HighResolutionTimer* self);
75 void on_manual_timer(score::HighResolutionTimer* self);
76 const score::DocumentContext& m_context;
77 std::atomic_int32_t index{1};
78 ossia::hash_map<int32_t, NodePtr> nodes;
79
80 score::gfx::Graph* m_graph{};
81 QThread m_thread;
82
83 struct NodeCommand
84 {
85 enum
86 {
87 ADD_NODE,
88 ADD_PREVIEW_NODE,
89 REMOVE_NODE,
90 REMOVE_PREVIEW_NODE,
91 RELINK
92 } cmd{};
93 int32_t index{};
94 std::unique_ptr<score::gfx::Node> node;
95 };
96
97 struct EdgeCommand
98 {
99 enum
100 {
101 CONNECT_PREVIEW_NODE,
102 DISCONNECT_PREVIEW_NODE
103 } cmd{};
104 EdgeSpec edge;
105 };
106
107 using Command = ossia::variant<NodeCommand, EdgeCommand>;
108 moodycamel::ConcurrentQueue<Command> tick_commands;
109 moodycamel::ConcurrentQueue<score::gfx::Message> tick_messages;
110
111 std::mutex edges_lock;
112 ossia::flat_set<EdgeSpec> new_edges TS_GUARDED_BY(edges_lock);
113 ossia::flat_set<EdgeSpec> edges;
114 ossia::flat_set<EdgeSpec> preview_edges;
115 std::atomic_bool edges_changed{};
116
117 score::HighResolutionTimer* m_no_vsync_timer{};
118 score::HighResolutionTimer* m_watchdog_timer{};
119
120 ossia::small_flat_map<score::HighResolutionTimer*, ossia::flat_set<score::gfx::OutputNode*>, 8> m_manualTimers;
121
122 ossia::object_pool<std::vector<score::gfx::gfx_input>> m_buffers;
123
124 score::Timers m_timers;
125};
126
127}
Definition GfxContext.hpp:37
Definition GfxExecContext.hpp:16
Definition Timers.hpp:14
Definition Timers.hpp:38
Base class for sink nodes (QWindow, spout, syphon, NDI output, ...)
Definition OutputNode.hpp:31
Binds the rendering pipeline to ossia processes.
Definition CameraDevice.cpp:30
Graphics rendering pipeline for ossia score.
Definition Filter/PreviewWidget.hpp:12
Base toolkit upon which the software is built.
Definition Application.cpp:111
Definition DocumentContext.hpp:18
Represents a graph of renderers.
Definition score-plugin-gfx/Gfx/Graph/Graph.hpp:16
Definition score-plugin-gfx/Gfx/Graph/Node.hpp:49