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
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
19
20QEglFSEmulatorIntegration::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("qgsGetDisplays"));
30 setDisplay = reinterpret_cast<PFNQGSSETDISPLAYPROC>(eglGetProcAddress("qgsSetDisplay"));
31}
32
36
40
42{
43 // This makes it possible to remotely query and then register our own set of screens
44 return false;
45}
46
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(displaysInfo, &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(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("EGL library doesn't support Emulator extensions");
70 }
71}
72
73bool 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
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(1)));
98}
99
100QT_END_NAMESPACE
bool hasCapability(QPlatformIntegration::Capability cap) const override
EGLNativeWindowType createNativeWindow(QPlatformWindow *platformWindow, const QSize &size, const QSurfaceFormat &format) override
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()