1 | // Copyright (C) 2016 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 | |
4 | #include "qeglfsemulatorintegration.h" |
5 | #include "qeglfsemulatorscreen.h" |
6 | #include "private/qeglfsintegration_p.h" |
7 | |
8 | #include <private/qguiapplication_p.h> |
9 | #include <QtGui/private/qeglconvenience_p.h> |
10 | #include <QtGui/private/qeglplatformcontext_p.h> |
11 | |
12 | #include <qpa/qwindowsysteminterface.h> |
13 | |
14 | #include <QtCore/QJsonDocument> |
15 | #include <QtCore/QJsonArray> |
16 | #include <QtCore/QJsonParseError> |
17 | |
18 | QT_BEGIN_NAMESPACE |
19 | |
20 | QEglFSEmulatorIntegration::QEglFSEmulatorIntegration() |
21 | { |
22 | // The Qt Emulator provides the ability to render to multiple displays |
23 | // In addition to the usual EGL and OpenGLESv2 API's, there are also a |
24 | // few additional API's that enable the client (this plugin) to query |
25 | // the available screens and their properties, as well as the ability |
26 | // to select which screen is the active render target (as this is |
27 | // usually handled in a platform specific way and not by EGL itself). |
28 | |
29 | getDisplays = reinterpret_cast<PFNQGSGETDISPLAYSPROC>(eglGetProcAddress(procname: "qgsGetDisplays")); |
30 | setDisplay = reinterpret_cast<PFNQGSSETDISPLAYPROC>(eglGetProcAddress(procname: "qgsSetDisplay")); |
31 | } |
32 | |
33 | void QEglFSEmulatorIntegration::platformInit() |
34 | { |
35 | } |
36 | |
37 | void QEglFSEmulatorIntegration::platformDestroy() |
38 | { |
39 | } |
40 | |
41 | bool QEglFSEmulatorIntegration::usesDefaultScreen() |
42 | { |
43 | // This makes it possible to remotely query and then register our own set of screens |
44 | return false; |
45 | } |
46 | |
47 | void QEglFSEmulatorIntegration::screenInit() |
48 | { |
49 | // Use qgsGetDisplays() call to retrieve the available screens from the Emulator |
50 | if (getDisplays) { |
51 | QByteArray displaysInfo = getDisplays(); |
52 | QJsonParseError error; |
53 | QJsonDocument displaysDocument = QJsonDocument::fromJson(json: displaysInfo, error: &error); |
54 | if (error.error == QJsonParseError::NoError) { |
55 | // Document should be an array of screen objects |
56 | if (displaysDocument.isArray()){ |
57 | QJsonArray screenArray = displaysDocument.array(); |
58 | for (auto screenValue : screenArray) { |
59 | if (screenValue.isObject()) |
60 | QWindowSystemInterface::handleScreenAdded(screen: new QEglFSEmulatorScreen(screenValue.toObject())); |
61 | } |
62 | } |
63 | } else { |
64 | qWarning() << "eglfs_emu: Failed to parse display info JSON with error: "<< error.errorString() |
65 | << " at offset "<< error.offset << " : "<< displaysInfo; |
66 | |
67 | } |
68 | } else { |
69 | qFatal(msg: "EGL library doesn't support Emulator extensions"); |
70 | } |
71 | } |
72 | |
73 | bool QEglFSEmulatorIntegration::hasCapability(QPlatformIntegration::Capability cap) const |
74 | { |
75 | switch (cap) { |
76 | case QPlatformIntegration::ThreadedPixmaps: |
77 | case QPlatformIntegration::OpenGL: |
78 | case QPlatformIntegration::ThreadedOpenGL: |
79 | return true; |
80 | default: |
81 | return false; |
82 | } |
83 | } |
84 | |
85 | EGLNativeWindowType QEglFSEmulatorIntegration::createNativeWindow(QPlatformWindow *platformWindow, |
86 | const QSize &size, |
87 | const QSurfaceFormat &format) |
88 | { |
89 | Q_UNUSED(size); |
90 | Q_UNUSED(format); |
91 | QEglFSEmulatorScreen *screen = static_cast<QEglFSEmulatorScreen *>(platformWindow->screen()); |
92 | if (screen && setDisplay) { |
93 | // Let the emulator know which screen the window surface is attached to |
94 | setDisplay(screen->id()); |
95 | } |
96 | Q_CONSTINIT static QBasicAtomicInt uniqueWindowId = Q_BASIC_ATOMIC_INITIALIZER(0); |
97 | return EGLNativeWindowType(qintptr(1 + uniqueWindowId.fetchAndAddRelaxed(valueToAdd: 1))); |
98 | } |
99 | |
100 | QT_END_NAMESPACE |
101 |