Loading...
Searching...
No Matches
ScreenNode.hpp
1#pragma once
2#include <atomic>
3#include <Gfx/Graph/OutputNode.hpp>
4#include <Gfx/Window/WindowSettings.hpp>
5
6class QScreen;
7class QTabletEvent;
8namespace score::gfx
9{
13struct SCORE_PLUGIN_GFX_EXPORT ScreenNode : OutputNode
14{
15 explicit ScreenNode(Configuration conf, bool embedded = false, bool startFullScreen = false);
16 virtual ~ScreenNode();
17
18 void startRendering() override;
19 void render() override;
20 void onRendererChange() override;
21 bool canRender() const override;
22 void stopRendering() override;
23
24 void setRenderer(std::shared_ptr<RenderList> r) override;
25 RenderList* renderer() const override;
26
27 void setScreen(QScreen*);
28 void setPosition(QPoint pos);
29 void setSize(QSize sz);
30 void setRenderSize(QSize sz);
31 void setFullScreen(bool);
32 void setCursor(bool);
33 void setTitle(QString);
34 void setConfiguration(Configuration);
35 void setSwapchainFlag(Gfx::SwapchainFlag flag);
36 void setSwapchainFormat(Gfx::SwapchainFormat format);
37
38 void createOutput(score::gfx::OutputConfiguration) override;
39 void destroyOutput() override;
40 void updateGraphicsAPI(GraphicsApi) override;
41 void setVSyncCallback(std::function<void()>) override;
42
43 std::shared_ptr<RenderState> renderState() const override;
44 score::gfx::OutputNodeRenderer* createRenderer(RenderList& r) const noexcept override;
45 Configuration configuration() const noexcept override;
46
47 const std::shared_ptr<Window>& window() const noexcept { return m_window; }
48
49 // Readback of the on-screen frame. QScreen::grabWindow reads the desktop at
50 // the window's geometry, so it captures whatever is in front of the window;
51 // this reads the swapchain's own backbuffer instead. It costs a full-frame
52 // copy, so the renderer only issues it when requestReadback() has armed it.
53 void requestReadback() const noexcept { m_readbackRequested.store(true); }
54 bool takeReadbackRequest() const noexcept
55 {
56 return m_readbackRequested.exchange(false);
57 }
58 const std::shared_ptr<QRhiReadbackResult>& readback() const noexcept
59 {
60 return m_readback;
61 }
62
63 std::function<void(QPointF)> onWindowMove;
64 std::function<void(QPointF, QPointF)> onMouseMove;
65 std::function<void(QTabletEvent*)> onTabletMove;
66 std::function<void(int, const QString&)> onKey;
67 std::function<void(int, const QString&)> onKeyRelease;
68 std::function<void(float)> onFps;
69
70private:
71 Configuration m_conf;
72 mutable std::atomic_bool m_readbackRequested{false};
73 std::shared_ptr<QRhiReadbackResult> m_readback
74 = std::make_shared<QRhiReadbackResult>();
75 std::shared_ptr<Window> m_window{};
76 QRhiSwapChain* m_swapChain{};
77 QRhiRenderBuffer* m_depthStencil{};
78 QScreen* m_screen{};
79 QString m_title;
80 std::optional<QPoint> m_pos{};
81 std::optional<QSize> m_sz{};
82 std::optional<QSize> m_renderSz{};
83 std::function<void()> m_vsyncCallback;
84
85 Gfx::SwapchainFlag m_swapchainFlag{};
86 Gfx::SwapchainFormat m_swapchainFormat{};
87 bool m_embedded{};
88 bool m_fullScreen{};
89 bool m_ownsWindow{};
90};
91}
Base class for sink nodes (QWindow, spout, syphon, NDI output, ...)
Definition OutputNode.hpp:54
Definition OutputNode.hpp:36
List of nodes to be rendered to an output.
Definition RenderList.hpp:30
Graphics rendering pipeline for ossia score.
Definition Filter/PreviewWidget.hpp:11
GraphicsApi
Available graphics APIs to use.
Definition RenderState.hpp:22
void setCursor(Qt::CursorShape c)
setCursor sets the cursor safely.
Definition ClearLayout.cpp:8
Definition OutputNode.hpp:15
Definition OutputNode.hpp:84
This node is used for rendering to a score::gfx::Window.
Definition ScreenNode.hpp:14