summaryrefslogtreecommitdiffstats
path: root/pica-client/vaapi.h
diff options
context:
space:
mode:
authorAnton <anton@picapica.im>2026-08-16 03:28:51 +0400
committerAnton <anton@picapica.im>2026-08-16 03:28:51 +0400
commit1b7b9d46c84c38cbf2df293113a687481e205585 (patch)
tree59f95bc2900e5e12141d40777e332ce4e2ee91d6 /pica-client/vaapi.h
parentad95ec8759777c4b8df0dcd66fd8200d24e912b1 (diff)
downloadpica-pica-1b7b9d46c84c38cbf2df293113a687481e205585.tar.gz
pica-pica-1b7b9d46c84c38cbf2df293113a687481e205585.zip
pica-client: VAAPI on X11, two codepaths
Diffstat (limited to 'pica-client/vaapi.h')
-rw-r--r--pica-client/vaapi.h73
1 files changed, 73 insertions, 0 deletions
diff --git a/pica-client/vaapi.h b/pica-client/vaapi.h
index c422a88..888a9d6 100644
--- a/pica-client/vaapi.h
+++ b/pica-client/vaapi.h
@@ -58,9 +58,82 @@ public:
// back to software rather than each probing for themselves.
static bool isAvailable();
+ // Whether the display was opened on an X11 connection rather than a DRM
+ // render node. That is decided once, when the device is created, and
+ // decides how a decoded surface can be drawn: only an X11 display can be
+ // drawn with vaPutSurface(), which is the only option left when Qt's
+ // OpenGL contexts come from GLX. Always false in a build without X11
+ // rendering support.
+ static bool usesX11();
+
+ // The X connection the display was opened on, as a Display*, or null when
+ // it was not opened on one. Untyped to keep the Xlib headers, and the
+ // names they take over, out of everything that includes this.
+ static void *x11Display();
+
// Registers the metatype for AVFramePtr, so hardware frames can be passed
// through queued signal connections. Call once at startup.
static void registerMetaTypes();
+
+ // Tells Xlib that its connection will be used from more than one thread,
+ // which it only accepts before that connection is opened - so this has to
+ // run before QApplication is constructed. Does nothing in a build without
+ // X11 rendering support.
+ static void initX11Threading();
+
+ // Works out whether this session needs the X11 drawing path - that is,
+ // whether Qt's OpenGL contexts come from GLX, leaving no way to import a
+ // surface as an EGL image - and if so remembers Qt's X connection to open
+ // the VAAPI display on. Call once at startup, after QApplication exists
+ // and before any video starts. Does nothing outside an X11 session, or
+ // when Qt is using EGL there.
+ static void detectX11Display();
+};
+
+class QWidget;
+
+// The common face of the two widgets that can draw a decoded surface: the
+// OpenGL one, which imports it as EGL images, and the X11 one, which has the
+// driver put it on screen. Which of them a session can use is not known until
+// it runs, and nothing outside create() should care which it got.
+class VaapiRenderWidget
+{
+public:
+ virtual ~VaapiRenderWidget() {}
+
+ // The widget to lay out, show and hide, and to connect to: both carry a
+ // renderingFailed(QString) signal.
+ virtual QWidget *widget() = 0;
+
+ // Takes the frame to draw next, replacing any previous one not yet drawn -
+ // for live video the newest frame is the one that matters.
+ virtual void setFrame(AVFramePtr frame) = 0;
+
+ // Drops the current frame and clears the widget.
+ virtual void clearFrame() = 0;
+
+ // Whether frames are still being drawn. False once drawing has failed, so
+ // a caller can fall back to the software path rather than leave a blank
+ // widget.
+ virtual bool isWorking() const = 0;
+
+ // The renderer this session can use. Never null - it falls back to the
+ // OpenGL one, which reports the reason it cannot draw if it cannot.
+ static VaapiRenderWidget *create(QWidget *parent);
+
+ // Whether drawing GPU frames has already been found not to work in this
+ // session. Nothing about that changes while the client runs - it follows
+ // from the kind of OpenGL context Qt provides and what the driver can do
+ // with it - so once one widget has failed, the next will fail the same
+ // way. Callers use this to stop asking for GPU frames at all rather than
+ // to fail again for every window they open.
+ static bool renderingKnownBroken() { return s_renderingBroken; }
+
+protected:
+ static void markRenderingBroken() { s_renderingBroken = true; }
+
+private:
+ static bool s_renderingBroken;
};
Q_DECLARE_METATYPE(AVFramePtr)