QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
GstQgcRenderTarget.cc
Go to the documentation of this file.
2
3#include <atomic>
4#ifdef QGC_UNITTEST_BUILD
5#include <optional>
6#endif
7
8#include <QtCore/QThread>
9#include <QtQuick/QQuickWindow>
10#include <QtQuick/QSGRendererInterface>
11
12#if defined(QGC_HAS_ANY_GPU_PATH)
13#include <rhi/qrhi.h>
14
16#endif
17#ifdef QGC_UNITTEST_BUILD
18#include "GstQgcCaps.h"
19#endif
20
21namespace GstQgc {
22
23namespace {
24
25constinit std::atomic<int> s_requestedBackend{static_cast<int>(RenderBackend::Unknown)};
26
27RenderBackend fromGraphicsApi(QSGRendererInterface::GraphicsApi api) noexcept
28{
29 switch (api) {
30 case QSGRendererInterface::Unknown:
32 case QSGRendererInterface::OpenGL:
34 case QSGRendererInterface::Direct3D11:
36 case QSGRendererInterface::Direct3D12:
38 case QSGRendererInterface::Metal:
40 case QSGRendererInterface::Vulkan:
42 default:
44 }
45}
46
47#if defined(QGC_HAS_ANY_GPU_PATH)
48RenderBackend fromRhiImplementation(int implementation) noexcept
49{
50 switch (static_cast<QRhi::Implementation>(implementation)) {
51 case QRhi::Null:
53 case QRhi::OpenGLES2:
55 case QRhi::D3D11:
57 case QRhi::D3D12:
59 case QRhi::Metal:
61 case QRhi::Vulkan:
63 }
65}
66#endif
67
68} // namespace
69
71{
72#ifdef QGC_UNITTEST_BUILD
73 if (const std::optional<SinkEnvironment> environment = sinkEnvironmentForTest()) {
74 return environment->target;
75 }
76#endif
77 // QQuickWindow::graphicsApi() may apply Qt Quick's settings on first use, so only the GUI thread asks it.
78 if (QThread::isMainThread()) {
79 s_requestedBackend.store(static_cast<int>(fromGraphicsApi(QQuickWindow::graphicsApi())),
80 std::memory_order_relaxed);
81 }
82 RenderTarget target{.backend = static_cast<RenderBackend>(s_requestedBackend.load(std::memory_order_relaxed))};
83#if defined(QGC_HAS_ANY_GPU_PATH)
84 if (const int live = QGCRhiCapture::deviceSnapshot().backend.load(std::memory_order_acquire); live >= 0) {
85 target.backend = fromRhiImplementation(live);
86 }
88#endif
89 return target;
90}
91
92bool RenderTarget::sharesGlContext() const noexcept
93{
94#if defined(Q_OS_LINUX)
96#else
97 // WGL and CGL contexts aren't wrapped.
98 return isOpenGlOnEgl();
99#endif
100}
101
102const char* toString(RenderBackend backend) noexcept
103{
104 switch (backend) {
106 return "unknown";
108 return "null";
110 return "OpenGL";
112 return "Direct3D11";
114 return "Direct3D12";
116 return "Metal";
118 return "Vulkan";
119 }
120 return "unknown";
121}
122
123const char* zeroCopyPathName(RenderBackend backend) noexcept
124{
125 // A backend has a case only in a build with its zero-copy path.
126 switch (backend) {
127#if defined(QGC_HAS_GST_GLMEMORY_GPU_PATH) || defined(QGC_HAS_GST_DMABUF_GPU_PATH)
129 return "GLMemory/DMABuf";
130#endif
131#if defined(QGC_HAS_GST_D3D11_GPU_PATH)
133 return "D3D11";
134#endif
135#if defined(QGC_HAS_GST_D3D12_GPU_PATH)
137 // A D3D12 device is a per-adapter singleton, so GStreamer's device on Qt's adapter is Qt's device.
138 return "D3D12 (d3d12convert to RGBA)";
139#endif
140#if defined(QGC_HAS_GST_IOSURFACE_GPU_PATH)
142 return "IOSurface/VideoToolbox";
143#endif
144#if defined(QGC_HAS_GST_DMABUF_VULKAN_IMPORT)
146 return "DMABuf";
147#endif
148 default:
149 return "CPU";
150 }
151}
152
153} // namespace GstQgc
GstVideoSink that pushes decoded frames into a Qt QVideoSink; sole sink in qgcvideosinkbin....
RenderTarget currentRenderTarget()
const char * toString(RenderBackend backend) noexcept
RenderBackend
Graphics API Qt Quick renders the video with, which decides the GPU memory qgcqvideosink can import.
@ Unknown
No scene graph yet, and the GUI thread hasn't recorded the requested API either.
@ Null
QRhi's Null backend or the software renderer: no GPU import.
const char * zeroCopyPathName(RenderBackend backend) noexcept
void * qtEglDisplay()
DeviceSnapshot & deviceSnapshot() noexcept
Returns the global snapshot. Atomic fields make individual reads thread-safe.
bool sharesGlContext() const noexcept