Loading...
Searching...
No Matches
GfxContext.hpp
1#pragma once
2#include <Process/Dataflow/CableData.hpp>
3
4#include <Gfx/Graph/Node.hpp>
5
6#include <score/tools/Timers.hpp>
7
8#include <ossia/dataflow/nodes/media.hpp>
9#include <ossia/dataflow/token_request.hpp>
10#include <ossia/detail/buffer_pool.hpp>
11#include <ossia/detail/flat_set.hpp>
12#include <ossia/detail/hash_map.hpp>
13#include <ossia/detail/mutex.hpp>
14#include <ossia/detail/small_flat_map.hpp>
15#include <ossia/detail/variant.hpp>
16#include <ossia/gfx/port_index.hpp>
17#include <ossia/network/value/value.hpp>
18
19#include <concurrentqueue.h>
20#include <score_plugin_gfx_export.h>
21namespace score {
22class HighResolutionTimer;
23class Timers;
24}
25namespace score::gfx
26{
27struct Graph;
28class OutputNode;
29}
30namespace score
31{
32struct DocumentContext;
33}
34namespace Gfx
35{
36using port_index = ossia::gfx::port_index;
38{
39 port_index first{};
40 port_index second{};
41 Process::CableType type{};
42
43 bool operator==(const EdgeSpec& other) const noexcept
44 {
45 return first == other.first && second == other.second;
46 }
47 bool operator!=(const EdgeSpec& other) const noexcept
48 {
49 return first != other.first || second != other.second;
50 }
51 bool operator<(const EdgeSpec& other) const noexcept
52 {
53 return first < other.first || (first == other.first && second < other.second);
54 }
55};
56
58class SCORE_PLUGIN_GFX_EXPORT GfxContext : public QObject
59{
60 friend class GfxExecutionAction;
61
62public:
63 using NodePtr = std::unique_ptr<score::gfx::Node>;
64
65 explicit GfxContext(const score::DocumentContext& ctx);
67
68 int32_t register_node(NodePtr node);
69 int32_t register_preview_node(NodePtr node);
70 void connect_preview_node(EdgeSpec e);
71 void disconnect_preview_node(EdgeSpec e);
72 void unregister_node(int32_t idx);
73 void unregister_preview_node(int32_t idx);
74
75 void recompute_edges();
76 void recompute_graph();
77 void recompute_connections();
78
79 void update_inputs();
80 void updateGraph();
81
82 void send_message(score::gfx::Message&& msg) noexcept
83 {
84 tick_messages.enqueue(std::move(msg));
85 }
86
87private:
88 void run_commands();
89 void add_preview_output(score::gfx::OutputNode& out);
90 void remove_preview_output();
91 void add_edge(EdgeSpec e);
92 void remove_edge(EdgeSpec e);
93 void remove_node(std::vector<std::unique_ptr<score::gfx::Node>>& nursery, int32_t id);
94
95 void on_no_vsync_timer(score::HighResolutionTimer* self);
96 void on_watchdog_timer(score::HighResolutionTimer* self);
97 void on_manual_timer(score::HighResolutionTimer* self);
98 const score::DocumentContext& m_context;
99 std::atomic_int32_t index{1};
100 ossia::hash_map<int32_t, NodePtr> nodes;
101
102 score::gfx::Graph* m_graph{};
103 QThread m_thread;
104
105 struct NodeCommand
106 {
107 enum
108 {
109 ADD_NODE,
110 ADD_PREVIEW_NODE,
111 REMOVE_NODE,
112 REMOVE_PREVIEW_NODE,
113 RELINK
114 } cmd{};
115 int32_t index{};
116 std::unique_ptr<score::gfx::Node> node;
117 };
118
119 struct EdgeCommand
120 {
121 enum
122 {
123 CONNECT_PREVIEW_NODE,
124 DISCONNECT_PREVIEW_NODE
125 } cmd{};
126 EdgeSpec edge;
127 };
128
129 using Command = ossia::variant<NodeCommand, EdgeCommand>;
130 moodycamel::ConcurrentQueue<Command> tick_commands;
131 moodycamel::ConcurrentQueue<score::gfx::Message> tick_messages;
132
133 std::mutex edges_lock;
134 ossia::flat_set<EdgeSpec> new_edges TS_GUARDED_BY(edges_lock);
135 ossia::flat_set<EdgeSpec> edges;
136 ossia::flat_set<EdgeSpec> preview_edges;
137 std::atomic_bool edges_changed{};
138
139 score::HighResolutionTimer* m_no_vsync_timer{};
140 score::HighResolutionTimer* m_watchdog_timer{};
141
142 ossia::small_flat_map<score::HighResolutionTimer*, ossia::flat_set<score::gfx::OutputNode*>, 8> m_manualTimers;
143
144 ossia::object_pool<std::vector<score::gfx::gfx_input>> m_buffers;
145
146 score::Timers m_timers;
147};
148
149}
Definition GfxContext.hpp:59
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:113
Definition GfxContext.hpp:38
Definition DocumentContext.hpp:18
Represents a graph of renderers.
Definition score-plugin-gfx/Gfx/Graph/Graph.hpp:18
Definition score-plugin-gfx/Gfx/Graph/Node.hpp:49