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
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 {
20} wfd_buffer_t;
21
29
30void QEglFSOpenWFDIntegration::platformInit()
31{
32 QEglFSDeviceIntegration::platformInit();
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
92QSize QEglFSOpenWFDIntegration::screenSize() const
93{
94 return mScreenSize;
95}
96
97EGLNativeDisplayType QEglFSOpenWFDIntegration::platformDisplay() const
98{
99 return mNativeDisplay;
100}
101
102EGLNativeWindowType QEglFSOpenWFDIntegration::createNativeWindow(QPlatformWindow *window,
103 const QSize &size,
104 const QSurfaceFormat &format)
105{
106 Q_UNUSED(window);
107 Q_UNUSED(format);
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
169 wfd_window_t* nativeWindow = (wfd_window_t*)malloc(sizeof(wfd_window_t));
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
185QSurfaceFormat QEglFSOpenWFDIntegration::surfaceFormatFor(const QSurfaceFormat &inputFormat) const
186{
187 QSurfaceFormat format = inputFormat;
188 format.setRedBufferSize(8);
189 format.setGreenBufferSize(8);
190 format.setBlueBufferSize(8);
191 format.setAlphaBufferSize(8);
192 return format;
193}
194
195void QEglFSOpenWFDIntegration::destroyNativeWindow(EGLNativeWindowType window)
196{
197 wfdDestroyPipeline(mDevice, mPipeline);
198 free((void*)window);
199}
200
201void QEglFSOpenWFDIntegration::platformDestroy()
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
209QT_END_NAMESPACE
#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]