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
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// Qt-Security score:significant reason:default
4
6
7#include "wfd.h"
8#include "wfdext2.h"
9
11
12#define MAX_NUM_OF_WFD_BUFFERS 3
13#define MAX_NUM_OF_WFD_DEVICES 4
14#define MAX_NUM_OF_WFD_PIPELINES 16
15#define MAX_NUM_OF_WFD_PORT_MODES 64
16#define MAX_NUM_OF_WFD_PORTS 4
17
18typedef struct wfd_buffer {
21} wfd_buffer_t;
22
30
31void QEglFSOpenWFDIntegration::platformInit()
32{
33 QEglFSDeviceIntegration::platformInit();
34
35 mNativeDisplay = EGL_DEFAULT_DISPLAY;
36
37 // Get device list
38 WFDint numDevs = wfdEnumerateDevices(nullptr, 0, nullptr);
39 WFDint devIds[MAX_NUM_OF_WFD_DEVICES];
40
41 if (numDevs > 0)
42 wfdEnumerateDevices(devIds, numDevs, nullptr);
43
44 // Create device
45 WFDint dev_attribs[3] = {WFD_DEVICE_CLIENT_TYPE,
46 WFD_CLIENT_ID_CLUSTER,
47 WFD_NONE};
48
49 bool ok;
50 WFDint clientType = qgetenv("QT_OPENWFD_CLIENT_ID").toInt(&ok, 16);
51
52 if (ok)
53 dev_attribs[1] = clientType;
54
55 mDevice = wfdCreateDevice(WFD_DEFAULT_DEVICE_ID, dev_attribs);
56
57 if (WFD_INVALID_HANDLE == mDevice)
58 qFatal( "Failed to create wfd device");
59
60 // Get port list
61 WFDint portIds[MAX_NUM_OF_WFD_PORTS];
62 WFDint numPorts = wfdEnumeratePorts(mDevice, nullptr, 0, nullptr);
63 wfdEnumeratePorts(mDevice, portIds, numPorts, nullptr);
64
65 // Create port
66 mPort = wfdCreatePort(mDevice, portIds[0], nullptr);
67
68 if (WFD_INVALID_HANDLE == mPort)
69 qFatal("Failed to create wfd port");
70
71 // Get port modes
72 WFDint numPortModes = wfdGetPortModes(mDevice, mPort, nullptr, 0);
73 WFDPortMode portModes[MAX_NUM_OF_WFD_PORT_MODES];
74 wfdGetPortModes(mDevice, mPort, portModes, numPortModes);
75
76 // Get width and height
77 mScreenSize.setWidth(wfdGetPortModeAttribi(mDevice, mPort, portModes[0], WFD_PORT_MODE_WIDTH));
78 mScreenSize.setHeight(wfdGetPortModeAttribi(mDevice, mPort, portModes[0], WFD_PORT_MODE_HEIGHT));
79
80 // Set port mode
81 wfdSetPortMode(mDevice, mPort, portModes[0]);
82 WFDErrorCode eError = wfdGetError(mDevice);
83 if (WFD_ERROR_NONE != eError)
84 qFatal("Failed to set wfd port mode");
85
86 // Power on
87 wfdSetPortAttribi(mDevice, mPort, WFD_PORT_POWER_MODE, WFD_POWER_MODE_ON);
88 eError = wfdGetError(mDevice);
89 if (WFD_ERROR_NONE != eError)
90 qFatal("Failed to power on wfd port");
91}
92
93QSize QEglFSOpenWFDIntegration::screenSize() const
94{
95 return mScreenSize;
96}
97
98EGLNativeDisplayType QEglFSOpenWFDIntegration::platformDisplay() const
99{
100 return mNativeDisplay;
101}
102
103EGLNativeWindowType QEglFSOpenWFDIntegration::createNativeWindow(QPlatformWindow *window,
104 const QSize &size,
105 const QSurfaceFormat &format)
106{
107 Q_UNUSED(window);
108 Q_UNUSED(format);
109
110 // Get list of pipelines
111 WFDint numPipelines = wfdEnumeratePipelines(mDevice, nullptr, 0, nullptr);
112
113 WFDint pipelineIds[MAX_NUM_OF_WFD_PIPELINES];
114 wfdEnumeratePipelines(mDevice, pipelineIds, numPipelines, nullptr);
115
116 bool ok;
117 WFDint pipelineId = qgetenv("QT_OPENWFD_PIPELINE_ID").toInt(&ok);
118
119 if (!ok)
120 pipelineId = pipelineIds[0];
121
122 mPipeline = wfdCreatePipeline(mDevice, pipelineId, nullptr);
123 if (WFD_INVALID_HANDLE == mPipeline)
124 qFatal("Failed to create wfd pipeline");
125
126 wfdSetPipelineAttribi(mDevice, mPipeline, WFD_PIPELINE_TRANSPARENCY_ENABLE,
127 (WFD_TRANSPARENCY_SOURCE_ALPHA|WFD_TRANSPARENCY_GLOBAL_ALPHA));
128
129 WFDErrorCode eError = wfdGetError(mDevice);
130 if (WFD_ERROR_NONE != eError)
131 qFatal("Failed to set WFD_PIPELINE_TRANSPARENCY_ENABLE");
132
133 wfdSetPipelineAttribi(mDevice, mPipeline, WFD_PIPELINE_GLOBAL_ALPHA, 255);
134 eError = wfdGetError(mDevice);
135 if (WFD_ERROR_NONE != eError)
136 qFatal("Failed to set WFD_PIPELINE_GLOBAL_ALPHA");
137
138 wfdBindPipelineToPort(mDevice, mPort, mPipeline);
139 eError = wfdGetError(mDevice);
140 if (WFD_ERROR_NONE != eError)
141 qFatal("Failed to bind port to pipeline");
142
143 // Create buffers
144 WFDSource source[MAX_NUM_OF_WFD_BUFFERS] = {WFD_INVALID_HANDLE, WFD_INVALID_HANDLE,
145 WFD_INVALID_HANDLE};
146 WFDEGLImage eglImageHandles[MAX_NUM_OF_WFD_BUFFERS];
147 WFD_EGLImageType* wfdEglImages[MAX_NUM_OF_WFD_BUFFERS];
148
149 for (int i = 0; i < MAX_NUM_OF_WFD_BUFFERS; i++) {
150 wfdCreateWFDEGLImages(mDevice, mScreenSize.width(), mScreenSize.height(),
151 WFD_FORMAT_RGBA8888, WFD_USAGE_OPENGL_ES2 | WFD_USAGE_DISPLAY,
152 1, &(eglImageHandles[i]), 0);
153
154 wfdEglImages[i] = (WFD_EGLImageType *)(eglImageHandles[i]);
155 if (WFD_INVALID_HANDLE == wfdEglImages[i])
156 qFatal("Failed to create WDFEGLImages");
157
158 source[i] = wfdCreateSourceFromImage(mDevice, mPipeline, eglImageHandles[i], nullptr);
159 if (WFD_INVALID_HANDLE == source[i])
160 qFatal("Failed to create source from EGLImage");
161 }
162
163 // Commit port
164 wfdDeviceCommit(mDevice, WFD_COMMIT_ENTIRE_PORT, mPort);
165 eError = wfdGetError(mDevice);
166 if (WFD_ERROR_NONE != eError)
167 qFatal("Failed to commit port");
168
169 // Create native window
170 wfd_window_t* nativeWindow = (wfd_window_t*)malloc(sizeof(wfd_window_t));
171 if (nullptr == nativeWindow)
172 qFatal("Failed to allocate memory for native window");
173
174 nativeWindow->dev = mDevice;
175 nativeWindow->port = mPort;
176 nativeWindow->pipeline = mPipeline;
178
179 for (int i = 0; i < MAX_NUM_OF_WFD_BUFFERS; i++) {
180 nativeWindow->buffers[i].image = wfdEglImages[i];
181 nativeWindow->buffers[i].source = source[i];
182 }
183 return (EGLNativeWindowType)nativeWindow;
184}
185
186QSurfaceFormat QEglFSOpenWFDIntegration::surfaceFormatFor(const QSurfaceFormat &inputFormat) const
187{
188 QSurfaceFormat format = inputFormat;
189 format.setRedBufferSize(8);
190 format.setGreenBufferSize(8);
191 format.setBlueBufferSize(8);
192 format.setAlphaBufferSize(8);
193 return format;
194}
195
196void QEglFSOpenWFDIntegration::destroyNativeWindow(EGLNativeWindowType window)
197{
198 wfdDestroyPipeline(mDevice, mPipeline);
199 free((void*)window);
200}
201
202void QEglFSOpenWFDIntegration::platformDestroy()
203{
204 wfdDestroyPort(mDevice, mPort);
205 WFDErrorCode error = wfdDestroyDevice(mDevice);
206 if (error != WFD_ERROR_NONE)
207 qWarning() << "Failed to release wfd device! Error = " << error;
208}
209
210QT_END_NAMESPACE
Combined button and popup list for selecting options.
#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
WFD_EGLImageType * image
wfd_buffer_t buffers[MAX_NUM_OF_WFD_BUFFERS]