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