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
qeglfsopenwfdintegration.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 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
5
6#include "wfd.h"
7#include "wfdext2.h"
8
10
11#define MAX_NUM_OF_WFD_BUFFERS 3
12#define MAX_NUM_OF_WFD_DEVICES 4
13#define MAX_NUM_OF_WFD_PIPELINES 16
14#define MAX_NUM_OF_WFD_PORT_MODES 64
15#define MAX_NUM_OF_WFD_PORTS 4
16
17typedef struct wfd_buffer {
18 WFD_EGLImageType* image;
19 WFDSource source;
21
29
31{
33
34 mNativeDisplay = EGL_DEFAULT_DISPLAY;
35
36 // Get device list
37 WFDint numDevs = wfdEnumerateDevices(nullptr, 0, nullptr);
38 WFDint devIds[MAX_NUM_OF_WFD_DEVICES];
39
40 if (numDevs > 0)
41 wfdEnumerateDevices(devIds, numDevs, nullptr);
42
43 // Create device
44 WFDint dev_attribs[3] = {WFD_DEVICE_CLIENT_TYPE,
45 WFD_CLIENT_ID_CLUSTER,
46 WFD_NONE};
47
48 bool ok;
49 WFDint clientType = qgetenv("QT_OPENWFD_CLIENT_ID").toInt(&ok, 16);
50
51 if (ok)
52 dev_attribs[1] = clientType;
53
54 mDevice = wfdCreateDevice(WFD_DEFAULT_DEVICE_ID, dev_attribs);
55
56 if (WFD_INVALID_HANDLE == mDevice)
57 qFatal( "Failed to create wfd device");
58
59 // Get port list
60 WFDint portIds[MAX_NUM_OF_WFD_PORTS];
61 WFDint numPorts = wfdEnumeratePorts(mDevice, nullptr, 0, nullptr);
62 wfdEnumeratePorts(mDevice, portIds, numPorts, nullptr);
63
64 // Create port
65 mPort = wfdCreatePort(mDevice, portIds[0], nullptr);
66
67 if (WFD_INVALID_HANDLE == mPort)
68 qFatal("Failed to create wfd port");
69
70 // Get port modes
71 WFDint numPortModes = wfdGetPortModes(mDevice, mPort, nullptr, 0);
72 WFDPortMode portModes[MAX_NUM_OF_WFD_PORT_MODES];
73 wfdGetPortModes(mDevice, mPort, portModes, numPortModes);
74
75 // Get width and height
76 mScreenSize.setWidth(wfdGetPortModeAttribi(mDevice, mPort, portModes[0], WFD_PORT_MODE_WIDTH));
77 mScreenSize.setHeight(wfdGetPortModeAttribi(mDevice, mPort, portModes[0], WFD_PORT_MODE_HEIGHT));
78
79 // Set port mode
80 wfdSetPortMode(mDevice, mPort, portModes[0]);
81 WFDErrorCode eError = wfdGetError(mDevice);
82 if (WFD_ERROR_NONE != eError)
83 qFatal("Failed to set wfd port mode");
84
85 // Power on
86 wfdSetPortAttribi(mDevice, mPort, WFD_PORT_POWER_MODE, WFD_POWER_MODE_ON);
87 eError = wfdGetError(mDevice);
88 if (WFD_ERROR_NONE != eError)
89 qFatal("Failed to power on wfd port");
90}
91
93{
94 return mScreenSize;
95}
96
98{
99 return mNativeDisplay;
100}
101
103 const QSize &size,
104 const QSurfaceFormat &format)
105{
108
109 // Get list of pipelines
110 WFDint numPipelines = wfdEnumeratePipelines(mDevice, nullptr, 0, nullptr);
111
112 WFDint pipelineIds[MAX_NUM_OF_WFD_PIPELINES];
113 wfdEnumeratePipelines(mDevice, pipelineIds, numPipelines, nullptr);
114
115 bool ok;
116 WFDint pipelineId = qgetenv("QT_OPENWFD_PIPELINE_ID").toInt(&ok);
117
118 if (!ok)
119 pipelineId = pipelineIds[0];
120
121 mPipeline = wfdCreatePipeline(mDevice, pipelineId, nullptr);
122 if (WFD_INVALID_HANDLE == mPipeline)
123 qFatal("Failed to create wfd pipeline");
124
125 wfdSetPipelineAttribi(mDevice, mPipeline, WFD_PIPELINE_TRANSPARENCY_ENABLE,
126 (WFD_TRANSPARENCY_SOURCE_ALPHA|WFD_TRANSPARENCY_GLOBAL_ALPHA));
127
128 WFDErrorCode eError = wfdGetError(mDevice);
129 if (WFD_ERROR_NONE != eError)
130 qFatal("Failed to set WFD_PIPELINE_TRANSPARENCY_ENABLE");
131
132 wfdSetPipelineAttribi(mDevice, mPipeline, WFD_PIPELINE_GLOBAL_ALPHA, 255);
133 eError = wfdGetError(mDevice);
134 if (WFD_ERROR_NONE != eError)
135 qFatal("Failed to set WFD_PIPELINE_GLOBAL_ALPHA");
136
137 wfdBindPipelineToPort(mDevice, mPort, mPipeline);
138 eError = wfdGetError(mDevice);
139 if (WFD_ERROR_NONE != eError)
140 qFatal("Failed to bind port to pipeline");
141
142 // Create buffers
143 WFDSource source[MAX_NUM_OF_WFD_BUFFERS] = {WFD_INVALID_HANDLE, WFD_INVALID_HANDLE,
144 WFD_INVALID_HANDLE};
145 WFDEGLImage eglImageHandles[MAX_NUM_OF_WFD_BUFFERS];
146 WFD_EGLImageType* wfdEglImages[MAX_NUM_OF_WFD_BUFFERS];
147
148 for (int i = 0; i < MAX_NUM_OF_WFD_BUFFERS; i++) {
149 wfdCreateWFDEGLImages(mDevice, mScreenSize.width(), mScreenSize.height(),
150 WFD_FORMAT_RGBA8888, WFD_USAGE_OPENGL_ES2 | WFD_USAGE_DISPLAY,
151 1, &(eglImageHandles[i]), 0);
152
153 wfdEglImages[i] = (WFD_EGLImageType *)(eglImageHandles[i]);
154 if (WFD_INVALID_HANDLE == wfdEglImages[i])
155 qFatal("Failed to create WDFEGLImages");
156
157 source[i] = wfdCreateSourceFromImage(mDevice, mPipeline, eglImageHandles[i], nullptr);
158 if (WFD_INVALID_HANDLE == source[i])
159 qFatal("Failed to create source from EGLImage");
160 }
161
162 // Commit port
163 wfdDeviceCommit(mDevice, WFD_COMMIT_ENTIRE_PORT, mPort);
164 eError = wfdGetError(mDevice);
165 if (WFD_ERROR_NONE != eError)
166 qFatal("Failed to commit port");
167
168 // Create native window
170 if (nullptr == nativeWindow)
171 qFatal("Failed to allocate memory for native window");
172
173 nativeWindow->dev = mDevice;
174 nativeWindow->port = mPort;
175 nativeWindow->pipeline = mPipeline;
177
178 for (int i = 0; i < MAX_NUM_OF_WFD_BUFFERS; i++) {
179 nativeWindow->buffers[i].image = wfdEglImages[i];
180 nativeWindow->buffers[i].source = source[i];
181 }
182 return (EGLNativeWindowType)nativeWindow;
183}
184
186{
187 QSurfaceFormat format = inputFormat;
189 format.setGreenBufferSize(8);
190 format.setBlueBufferSize(8);
191 format.setAlphaBufferSize(8);
192 return format;
193}
194
196{
197 wfdDestroyPipeline(mDevice, mPipeline);
198 free((void*)window);
199}
200
202{
203 wfdDestroyPort(mDevice, mPort);
204 WFDErrorCode error = wfdDestroyDevice(mDevice);
205 if (error != WFD_ERROR_NONE)
206 qWarning() << "Failed to release wfd device! Error = " << error;
207}
208
virtual QSurfaceFormat surfaceFormatFor(const QSurfaceFormat &inputFormat) const
EGLNativeWindowType createNativeWindow(QPlatformWindow *window, const QSize &size, const QSurfaceFormat &format) override
EGLNativeDisplayType platformDisplay() const override
void destroyNativeWindow(EGLNativeWindowType window) override
The QPlatformWindow class provides an abstraction for top-level windows.
\inmodule QtCore
Definition qsize.h:25
constexpr int height() const noexcept
Returns the height.
Definition qsize.h:133
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:130
constexpr void setWidth(int w) noexcept
Sets the width to the given width.
Definition qsize.h:136
constexpr void setHeight(int h) noexcept
Sets the height to the given height.
Definition qsize.h:139
The QSurfaceFormat class represents the format of a QSurface. \inmodule QtGui.
void setRedBufferSize(int size)
Set the desired size in bits of the red channel of the color buffer.
Combined button and popup list for selecting options.
DBusConnection const char DBusError * error
#define MAX_NUM_OF_WFD_DEVICES
#define MAX_NUM_OF_WFD_PORT_MODES
#define MAX_NUM_OF_WFD_PORTS
#define MAX_NUM_OF_WFD_PIPELINES
#define MAX_NUM_OF_WFD_BUFFERS
struct wfd_buffer wfd_buffer_t
struct wfd_window wfd_window_t
#define qWarning
Definition qlogging.h:166
#define qFatal
Definition qlogging.h:168
GLuint const GLuint * buffers
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum format
GLsizei GLsizei GLchar * source
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
#define Q_UNUSED(x)
static QWindowsDirect2DWindow * nativeWindow(QWindow *window)
aWidget window() -> setWindowTitle("New Window Title")
[2]
WFD_EGLImageType * image