Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qvkkhrdisplayintegration.cpp
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
6
7#include <qpa/qplatformwindow.h>
8#include <qpa/qplatformbackingstore.h>
9#include <qpa/qplatforminputcontextfactory_p.h>
10#include <qpa/qwindowsysteminterface.h>
11
12#include <QtGui/private/qguiapplication_p.h>
13#include <QtGui/private/qwindow_p.h>
14#include <QtGui/private/qgenericunixeventdispatcher_p.h>
15#include <QtGui/private/qgenericunixfontdatabase_p.h>
16#include <QtGui/private/qgenericunixthemes_p.h>
17#include <QtGui/private/qgenericunixservices_p.h>
18
19#include <QtFbSupport/private/qfbvthandler_p.h>
20
21#if QT_CONFIG(libinput)
22#include <QtInputSupport/private/qlibinputhandler_p.h>
23#endif
24
25#if QT_CONFIG(evdev)
26#include <QtInputSupport/private/qevdevmousemanager_p.h>
27#include <QtInputSupport/private/qevdevkeyboardmanager_p.h>
28#include <QtInputSupport/private/qevdevtouchmanager_p.h>
29#endif
30
31#if QT_CONFIG(tslib)
32#include <QtInputSupport/private/qtslib_p.h>
33#endif
34
36
37using namespace Qt::StringLiterals;
38
40{
41public:
42 QRect geometry() const override { return m_geometry; }
43 int depth() const override { return m_depth; }
44 QImage::Format format() const override { return m_format; }
46
47private:
48 QVkKhrDisplayVulkanInstance *m_vk = nullptr;
49 QRect m_geometry;
50 int m_depth = 32;
53};
54
56{
57 m_vk = inst;
58 m_geometry = QRect(QPoint(0, 0), m_vk->displaySize());
60 qDebug() << "Screen will report geometry" << m_geometry;
61
62 // Thanks to this deferred screen setup, a QWindow with a size based on the
63 // dummy screen size may already exist. Try to resize it.
64 QScreen *thisScreen = screen();
66 if (window->isTopLevel() && window->screen() == thisScreen)
67 window->handle()->setGeometry(QRect()); // set fullscreen geometry
68 }
69}
70
72{
73public:
76
77 void *vulkanSurfacePtr();
78
79 void setGeometry(const QRect &r) override;
80
81private:
82 VkSurfaceKHR m_surface = VK_NULL_HANDLE;
83};
84
86{
87 if (m_surface) {
88 QVulkanInstance *inst = window()->vulkanInstance();
89 if (inst)
90 static_cast<QVkKhrDisplayVulkanInstance *>(inst->handle())->destroySurface(m_surface);
91 }
92}
93
95{
96 if (m_surface)
97 return &m_surface;
98
99 QVulkanInstance *inst = window()->vulkanInstance();
100 if (!inst) {
101 qWarning("Attempted to create Vulkan surface without an instance; was QWindow::setVulkanInstance() called?");
102 return nullptr;
103 }
104 QVkKhrDisplayVulkanInstance *vkdinst = static_cast<QVkKhrDisplayVulkanInstance *>(inst->handle());
105 m_surface = vkdinst->createSurface(window());
106
107 return &m_surface;
108}
109
111{
112 // We only support full-screen windows
113 QRect rect(screen()->availableGeometry());
116
117 const QRect lastReportedGeometry = qt_window_private(window())->geometry;
118 if (rect != lastReportedGeometry)
120}
121
122// does not actually support raster content, just paint into a QImage and that's it for now
124{
125public:
127
128 QPaintDevice *paintDevice() override { return &m_image; }
129 void flush(QWindow *window, const QRegion &region, const QPoint &offset) override {
131 Q_UNUSED(region);
133 }
134 void resize(const QSize &size, const QRegion &staticContents) override {
135 Q_UNUSED(staticContents);
137 if (m_image.size() != size)
138 m_image = QImage(size, format);
139 }
140
141private:
142 QImage m_image;
143};
144
146{
147 Q_UNUSED(parameters);
148}
149
151{
153 delete m_services;
154 delete m_fontDatabase;
155 delete m_vtHandler;
156}
157
159{
160 switch (cap) {
161 case ThreadedPixmaps: return true;
162 case WindowManagement: return false;
164 }
165}
166
168{
169 m_primaryScreen = new QVkKhrDisplayScreen;
170
171 // The real values are only known when the QVulkanInstance initializes, use
172 // dummy values until then.
173 m_primaryScreen->m_geometry = QRect(0, 0, 1920, 1080);
174 m_primaryScreen->m_depth = 32;
175 m_primaryScreen->m_format = QImage::Format_ARGB32_Premultiplied;
176
178
179 m_inputContext = QPlatformInputContextFactory::create();
180
181 m_vtHandler = new QFbVtHandler;
182
183 if (!qEnvironmentVariableIntValue("QT_QPA_DISABLE_INPUT"))
184 createInputHandlers();
185}
186
188{
189 if (!m_fontDatabase)
190 m_fontDatabase = new QGenericUnixFontDatabase;
191
192 return m_fontDatabase;
193}
194
196{
197 if (!m_services)
198 m_services = new QGenericUnixServices;
199
200 return m_services;
201}
202
204{
205 return m_inputContext;
206}
207
212
217
219{
220 if (window->surfaceType() != QSurface::VulkanSurface) {
221 qWarning("vkkhrdisplay platform plugin only supports QWindow with surfaceType == VulkanSurface");
222 // Assume VulkanSurface, better than crashing. Consider e.g. an autotest
223 // creating a default QWindow just to have something to be used with
224 // QRhi's Null backend. Continuing to set up a Vulkan window (even
225 // though the request was Raster or something) is better than failing to
226 // create a platform window, and may even be sufficient in some cases.
227 }
228
230 w->setGeometry(QRect()); // set fullscreen geometry
231 w->requestActivateWindow();
232 return w;
233}
234
239
241{
242 return createUnixEventDispatcher();
243}
244
245void QVkKhrDisplayIntegration::handleInstanceCreated(QVkKhrDisplayVulkanInstance *inst, void *userData)
246{
247 QVkKhrDisplayIntegration *self = static_cast<QVkKhrDisplayIntegration *>(userData);
248 self->m_primaryScreen->setVk(inst);
249}
250
252{
254 inst->setCreatedCallback(handleInstanceCreated, const_cast<QVkKhrDisplayIntegration *>(this));
255 return inst;
256}
257
261
262static int resourceType(const QByteArray &key)
263{
264 static const QByteArray names[] = { // match ResourceType
265 QByteArrayLiteral("vksurface")
266 };
267 const QByteArray *end = names + sizeof(names) / sizeof(names[0]);
268 const QByteArray *result = std::find(names, end, key);
269 if (result == end)
270 result = std::find(names, end, key.toLower());
271 return int(result - names);
272}
273
275{
276 void *result = nullptr;
277
278 switch (resourceType(resource)) {
279 case VkSurface:
280 if (window && window->handle() && window->surfaceType() == QSurface::VulkanSurface)
281 result = static_cast<QVkKhrDisplayWindow *>(window->handle())->vulkanSurfacePtr();
282 break;
283 default:
284 break;
285 }
286
287 return result;
288}
289
290void QVkKhrDisplayIntegration::createInputHandlers()
291{
292#if QT_CONFIG(libinput)
293 if (!qEnvironmentVariableIntValue("QT_QPA_NO_LIBINPUT")) {
294 new QLibInputHandler("libinput"_L1, QString());
295 return;
296 }
297#endif
298
299#if QT_CONFIG(tslib)
300 bool useTslib = qEnvironmentVariableIntValue("QT_QPA_TSLIB");
301 if (useTslib)
302 new QTsLibMouseHandler("TsLib"_L1, QString());
303#endif
304
305#if QT_CONFIG(evdev)
306 new QEvdevKeyboardManager("EvdevKeyboard"_L1, QString(), this);
307 new QEvdevMouseManager("EvdevMouse"_L1, QString(), this);
308#if QT_CONFIG(tslib)
309 if (!useTslib)
310#endif
311 new QEvdevTouchManager("EvdevTouch"_L1, QString() /* spec */, this);
312#endif
313}
314
\inmodule QtCore
Definition qbytearray.h:57
static QPlatformTheme * createUnixTheme(const QString &name)
Creates a UNIX theme according to the detected desktop environment.
static QWindowList allWindows()
Returns a list of all the windows in the application.
QScreen * primaryScreen
the primary (or default) screen of the application.
\inmodule QtGui
Definition qimage.h:37
QSize size() const
Returns the size of the image, i.e.
Format
The following image formats are available in Qt.
Definition qimage.h:41
@ Format_ARGB32_Premultiplied
Definition qimage.h:48
The QPlatformBackingStore class provides the drawing area for top-level windows.
QWindow * window() const
Returns a pointer to the top-level window associated with this surface.
The QPlatformFontDatabase class makes it possible to customize how fonts are discovered and how they ...
static QPlatformInputContext * create()
The QPlatformInputContext class abstracts the input method dependent data and composing state.
virtual bool hasCapability(Capability cap) const
Capability
Capabilities are used to determine specific features of a platform integration.
The QPlatformNativeInterface class provides an abstraction for retrieving native resource handles.
The QPlatformScreen class provides an abstraction for visual displays.
QScreen * screen() const
virtual QImage::Format format() const =0
Reimplement in subclass to return the image format which corresponds to the screen format.
The QPlatformServices provides the backend for desktop-related functionality.
The QPlatformTheme class allows customizing the UI based on themes.
The QPlatformVulkanInstance class provides an abstraction for Vulkan instances.
The QPlatformWindow class provides an abstraction for top-level windows.
QWindow * window() const
Returns the window which belongs to the QPlatformWindow.
QPlatformScreen * screen() const override
Returns the platform screen handle corresponding to this platform window, or null if the window is no...
virtual void setGeometry(const QRect &rect)
This function is called by Qt whenever a window is moved or resized using the QWindow API.
\inmodule QtCore\reentrant
Definition qpoint.h:25
\inmodule QtCore\reentrant
Definition qrect.h:30
The QRegion class specifies a clip region for a painter.
Definition qregion.h:27
The QScreen class is used to query screen properties. \inmodule QtGui.
Definition qscreen.h:32
QPlatformScreen * handle() const
Get the platform screen handle.
Definition qscreen.cpp:83
\inmodule QtCore
Definition qsize.h:25
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
@ VulkanSurface
Definition qsurface.h:35
void flush(QWindow *window, const QRegion &region, const QPoint &offset) override
Flushes the given region from the specified window.
QPaintDevice * paintDevice() override
Implement this function to return the appropriate paint device.
void resize(const QSize &size, const QRegion &staticContents) override
bool hasCapability(QPlatformIntegration::Capability cap) const override
QPlatformBackingStore * createPlatformBackingStore(QWindow *window) const override
Factory function for QPlatformBackingStore.
QPlatformTheme * createPlatformTheme(const QString &name) const override
QVkKhrDisplayIntegration(const QStringList &parameters)
QPlatformVulkanInstance * createPlatformVulkanInstance(QVulkanInstance *instance) const override
QPlatformServices * services() const override
QPlatformInputContext * inputContext() const override
Returns the platforms input context.
QPlatformNativeInterface * nativeInterface() const override
QPlatformFontDatabase * fontDatabase() const override
Accessor for the platform integration's fontdatabase.
QAbstractEventDispatcher * createEventDispatcher() const override
Factory function for the GUI event dispatcher.
void initialize() override
Performs initialization steps that depend on having an event dispatcher available.
void * nativeResourceForWindow(const QByteArray &resource, QWindow *window) override
QPlatformWindow * createPlatformWindow(QWindow *window) const override
Factory function for QPlatformWindow.
QRect geometry() const override
Reimplement in subclass to return the pixel geometry of the screen.
QImage::Format format() const override
Reimplement in subclass to return the image format which corresponds to the screen format.
void setVk(QVkKhrDisplayVulkanInstance *inst)
int depth() const override
Reimplement in subclass to return current depth of the screen.
void setCreatedCallback(CreatedCallback callback, void *userData)
void setGeometry(const QRect &r) override
This function is called by Qt whenever a window is moved or resized using the QWindow API.
The QVulkanInstance class represents a native Vulkan instance, enabling Vulkan rendering onto a QSurf...
static void handleScreenGeometryChange(QScreen *screen, const QRect &newGeometry, const QRect &newAvailableGeometry)
static void handleGeometryChange(QWindow *window, const QRect &newRect)
static void handleScreenAdded(QPlatformScreen *screen, bool isPrimary=false)
Should be called by the implementation whenever a new screen is added.
static void handleScreenRemoved(QPlatformScreen *screen)
Should be called by the implementation whenever a screen is removed.
static bool handleExposeEvent(QWindow *window, const QRegion &region)
\inmodule QtGui
Definition qwindow.h:63
rect
[4]
Combined button and popup list for selecting options.
#define QByteArrayLiteral(str)
Definition qbytearray.h:52
static int resourceType(const QByteArray &key)
QPlatformFontDatabase QGenericUnixFontDatabase
#define qDebug
[1]
Definition qlogging.h:164
#define qWarning
Definition qlogging.h:166
GLuint64 key
GLfloat GLfloat GLfloat w
[0]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLboolean r
[2]
GLuint GLuint end
GLenum GLuint GLintptr offset
GLuint name
GLint GLsizei GLsizei GLenum format
GLuint GLuint * names
GLuint64EXT * result
[6]
GLenum cap
Q_CORE_EXPORT int qEnvironmentVariableIntValue(const char *varName, bool *ok=nullptr) noexcept
#define Q_UNUSED(x)
static int resourceType(const QByteArray &key)
Q_GUI_EXPORT QWindowPrivate * qt_window_private(QWindow *window)
Definition qwindow.cpp:2950
aWidget window() -> setWindowTitle("New Window Title")
[2]