Line | Source | Count |
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | QEglFSWindow::QEglFSWindow(QWindow *w) | - |
6 | : QPlatformWindow(w), | - |
7 | m_backingStore(0), | - |
8 | m_raster(false), | - |
9 | m_winId(0), | - |
10 | m_surface(((EGLSurface)0)), | - |
11 | m_window(0), | - |
12 | m_flags(0) | - |
13 | { | - |
14 | } | - |
15 | | - |
16 | QEglFSWindow::~QEglFSWindow() | - |
17 | { | - |
18 | destroy(); | - |
19 | } | - |
20 | | - |
21 | static WId newWId() | - |
22 | { | - |
23 | static WId id = 0; | - |
24 | | - |
25 | if (id == std::numeric_limits<WId>::max()) | - |
26 | QMessageLogger(__FILE__, 7076, __PRETTY_FUNCTION__).warning("QEGLPlatformWindow: Out of window IDs"); | - |
27 | | - |
28 | return ++id; | - |
29 | } | - |
30 | | - |
31 | void QEglFSWindow::create() | - |
32 | { | - |
33 | if (m_flags.testFlag(Created)TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
34 | return; never executed: return; | 0 |
35 | | - |
36 | m_winId = newWId(); | - |
37 | | - |
38 | | - |
39 | m_raster = (window()->surfaceType() == QSurface::RasterSurface); | - |
40 | if (m_rasterTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
41 | window()->setSurfaceType(QSurface::OpenGLSurface); never executed: window()->setSurfaceType(QSurface::OpenGLSurface); | 0 |
42 | | - |
43 | if (window()->type() == Qt::DesktopTRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
44 | QRect fullscreenRect(QPoint(), screen()->availableGeometry().size()); | - |
45 | QPlatformWindow::setGeometry(fullscreenRect); | - |
46 | QWindowSystemInterface::handleGeometryChange(window(), fullscreenRect); | - |
47 | return; never executed: return; | 0 |
48 | } | - |
49 | | - |
50 | m_flags = Created; | - |
51 | | - |
52 | if (window()->type() == Qt::DesktopTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
53 | return; never executed: return; | 0 |
54 | | - |
55 | | - |
56 | | - |
57 | | - |
58 | QEglFSScreen *screen = this->screen(); | - |
59 | QOpenGLCompositor *compositor = QOpenGLCompositor::instance(); | - |
60 | if (screen->primarySurface() != ((EGLSurface)0)TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
61 | if (__builtin_expect(!!(!TRUE | never evaluated | FALSE | never evaluated |
isRaster() &&|| !compositor->targetWindow())()), false)TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
62 | | - |
63 | | - |
64 | | - |
65 | m_format = compositor->targetWindow()->format(); | - |
| return; | |
| }QMessageLogger(__FILE__, 113115, __PRETTY_FUNCTION__).fatal("EGLFS: OpenGL windows cannot be mixed with others."); | |
66 | | - |
67 | return; never executed: return; | 0 |
68 | } | - |
69 | m_format = compositor->targetWindow()->format(); | - |
70 | return; never executed: return; | 0 |
71 | } | - |
72 | | - |
73 | m_flags |= HasNativeWindow; | - |
74 | setGeometry(QRect()); | - |
75 | QWindowSystemInterface::handleExposeEvent(window(), QRect(QPoint(0, 0), geometry().size())); | - |
76 | | - |
77 | resetSurface(); | - |
78 | | - |
79 | if (__builtin_expect(!!(TRUE | never evaluated | FALSE | never evaluated |
m_surface == ((EGLSurface)0)), false)TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
80 | EGLint error = eglGetError(); | - |
81 | eglTerminate(screen->display()); | - |
82 | QMessageLogger(__FILE__, 128132, __PRETTY_FUNCTION__).fatal("EGL Error : Could not create the egl surface: error = 0x%x\n", error); | - |
83 | } never executed: end of block | 0 |
84 | | - |
85 | screen->setPrimarySurface(m_surface); | - |
86 | | - |
87 | if (isRaster()TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
88 | QOpenGLContext *context = new QOpenGLContext(QGuiApplication::instance()); | - |
89 | context->setShareContext(qt_gl_global_share_context()); | - |
90 | context->setFormat(m_format); | - |
91 | context->setScreen(window()->screen()); | - |
92 | if (!(__builtin_expect(!!(!TRUE | never evaluated | FALSE | never evaluated |
context->create())()), false)TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
93 | QMessageLogger(__FILE__, 139143, __PRETTY_FUNCTION__).fatal("EGLFS: Failed to create compositing context"); never executed: QMessageLogger(__FILE__, 143, __PRETTY_FUNCTION__).fatal("EGLFS: Failed to create compositing context"); | 0 |
94 | compositor->setTarget(context, window()); | - |
95 | | - |
96 | | - |
97 | if (!qt_gl_global_share_context()TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
98 | qt_gl_set_global_share_context(context); | - |
99 | | - |
100 | | - |
101 | QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts); | - |
102 | } never executed: end of block | 0 |
103 | } never executed: end of block | 0 |
104 | } never executed: end of block | 0 |
105 | | - |
106 | void QEglFSWindow::destroy() | - |
107 | { | - |
108 | QEglFSScreen *screen = this->screen(); | - |
109 | if (m_flags.testFlag(HasNativeWindow)) { | - |
110 | QEglFSCursor *cursor = qobject_cast<QEglFSCursor *>(screen->cursor()); | - |
111 | if (cursor) | - |
112 | cursor->resetResources(); | - |
113 | | - |
114 | if (screen->primarySurface() == m_surface) | - |
115 | screen->setPrimarySurface(((EGLSurface)0)); | - |
116 | | - |
117 | invalidateSurface(); | - |
118 | } | - |
119 | | - |
120 | m_flags = 0; | - |
121 | QOpenGLCompositor::instance()->removeWindow(this); | - |
122 | } | - |
123 | | - |
124 | void QEglFSWindow::invalidateSurface() | - |
125 | { | - |
126 | if (m_surface != ((EGLSurface)0)) { | - |
127 | eglDestroySurface(screen()->display(), m_surface); | - |
128 | m_surface = ((EGLSurface)0); | - |
129 | } | - |
130 | qt_egl_device_integration()->destroyNativeWindow(m_window); | - |
131 | m_window = 0; | - |
132 | } | - |
133 | | - |
134 | void QEglFSWindow::resetSurface() | - |
135 | { | - |
136 | EGLDisplay display = screen()->display(); | - |
137 | QSurfaceFormat platformFormat = qt_egl_device_integration()->surfaceFormatFor(window()->requestedFormat()); | - |
138 | | - |
139 | m_config = QEglFSIntegration::chooseConfig(display, platformFormat); | - |
140 | m_format = q_glFormatFromConfig(display, m_config, platformFormat); | - |
141 | m_window = qt_egl_device_integration()->createNativeWindow(this, screen()->geometry().size(), m_format); | - |
142 | m_surface = eglCreateWindowSurface(display, m_config, m_window, __null); | - |
143 | } | - |
144 | | - |
145 | void QEglFSWindow::setVisible(bool visible) | - |
146 | { | - |
147 | QOpenGLCompositor *compositor = QOpenGLCompositor::instance(); | - |
148 | QList<QOpenGLCompositorWindow *> windows = compositor->windows(); | - |
149 | QWindow *wnd = window(); | - |
150 | | - |
151 | if (wnd->type() != Qt::Desktop) { | - |
152 | if (visible) { | - |
153 | compositor->addWindow(this); | - |
154 | } else { | - |
155 | compositor->removeWindow(this); | - |
156 | windows = compositor->windows(); | - |
157 | if (windows.size()) | - |
158 | windows.last()->sourceWindow()->requestActivate(); | - |
159 | } | - |
160 | } | - |
161 | | - |
162 | QWindowSystemInterface::handleExposeEvent(wnd, QRect(QPoint(0, 0), wnd->geometry().size())); | - |
163 | | - |
164 | if (visible) | - |
165 | QWindowSystemInterface::flushWindowSystemEvents(QEventLoop::ExcludeUserInputEvents); | - |
166 | } | - |
167 | | - |
168 | void QEglFSWindow::setGeometry(const QRect &r) | - |
169 | { | - |
170 | QRect rect; | - |
171 | bool forceFullscreen = m_flags.testFlag(HasNativeWindow); | - |
172 | if (forceFullscreen) | - |
173 | rect = screen()->availableGeometry(); | - |
174 | else | - |
175 | rect = r; | - |
176 | | - |
177 | QPlatformWindow::setGeometry(rect); | - |
178 | | - |
179 | | - |
180 | if (rect != r) | - |
181 | QWindowSystemInterface::handleGeometryChange(window(), rect, r); | - |
182 | } | - |
183 | | - |
184 | QRect QEglFSWindow::geometry() const | - |
185 | { | - |
186 | | - |
187 | | - |
188 | | - |
189 | if (!m_flags.testFlag(Created) && screen()->primarySurface() == ((EGLSurface)0)) | - |
190 | return screen()->availableGeometry(); | - |
191 | | - |
192 | return QPlatformWindow::geometry(); | - |
193 | } | - |
194 | | - |
195 | void QEglFSWindow::requestActivateWindow() | - |
196 | { | - |
197 | if (window()->type() != Qt::Desktop) | - |
198 | QOpenGLCompositor::instance()->moveToTop(this); | - |
199 | | - |
200 | QWindow *wnd = window(); | - |
201 | QWindowSystemInterface::handleWindowActivated(wnd); | - |
202 | QWindowSystemInterface::handleExposeEvent(wnd, QRect(QPoint(0, 0), wnd->geometry().size())); | - |
203 | } | - |
204 | | - |
205 | void QEglFSWindow::raise() | - |
206 | { | - |
207 | QWindow *wnd = window(); | - |
208 | if (wnd->type() != Qt::Desktop) { | - |
209 | QOpenGLCompositor::instance()->moveToTop(this); | - |
210 | QWindowSystemInterface::handleExposeEvent(wnd, QRect(QPoint(0, 0), wnd->geometry().size())); | - |
211 | } | - |
212 | } | - |
213 | | - |
214 | void QEglFSWindow::lower() | - |
215 | { | - |
216 | QOpenGLCompositor *compositor = QOpenGLCompositor::instance(); | - |
217 | QList<QOpenGLCompositorWindow *> windows = compositor->windows(); | - |
218 | if (window()->type() != Qt::Desktop && windows.count() > 1) { | - |
219 | int idx = windows.indexOf(this); | - |
220 | if (idx > 0) { | - |
221 | compositor->changeWindowIndex(this, idx - 1); | - |
222 | QWindowSystemInterface::handleExposeEvent(windows.last()->sourceWindow(), | - |
223 | QRect(QPoint(0, 0), windows.last()->sourceWindow()->geometry().size())); | - |
224 | } | - |
225 | } | - |
226 | } | - |
227 | | - |
228 | EGLSurface QEglFSWindow::surface() const | - |
229 | { | - |
230 | return m_surface != ((EGLSurface)0) ? m_surface : screen()->primarySurface(); | - |
231 | } | - |
232 | | - |
233 | QSurfaceFormat QEglFSWindow::format() const | - |
234 | { | - |
235 | return m_format; | - |
236 | } | - |
237 | | - |
238 | EGLNativeWindowType QEglFSWindow::eglWindow() const | - |
239 | { | - |
240 | return m_window; | - |
241 | } | - |
242 | | - |
243 | QEglFSScreen *QEglFSWindow::screen() const | - |
244 | { | - |
245 | return static_cast<QEglFSScreen *>(QPlatformWindow::screen()); | - |
246 | } | - |
247 | | - |
248 | bool QEglFSWindow::isRaster() const | - |
249 | { | - |
250 | return m_raster || window()->surfaceType() == QSurface::RasterGLSurface; | - |
251 | } | - |
252 | | - |
253 | QWindow *QEglFSWindow::sourceWindow() const | - |
254 | { | - |
255 | return window(); | - |
256 | } | - |
257 | | - |
258 | const QPlatformTextureList *QEglFSWindow::textures() const | - |
259 | { | - |
260 | if (m_backingStore) | - |
261 | return m_backingStore->textures(); | - |
262 | | - |
263 | return 0; | - |
264 | } | - |
265 | | - |
266 | void QEglFSWindow::endCompositing() | - |
267 | { | - |
268 | if (m_backingStore) | - |
269 | m_backingStore->notifyComposited(); | - |
270 | } | - |
271 | | - |
272 | WId QEglFSWindow::winId() const | - |
273 | { | - |
274 | return m_winId; | - |
275 | } | - |
276 | | - |
277 | void QEglFSWindow::setOpacity(qreal) | - |
278 | { | - |
279 | if (!isRaster()) | - |
280 | QMessageLogger(__FILE__, 326330, __PRETTY_FUNCTION__).warning("QEglFSWindow: Cannot set opacity for non-raster windows"); | - |
281 | | - |
282 | | - |
283 | } | - |
284 | | - |
285 | | - |
| | |