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
4#include "qeglfsoffscreenwindow_p.h"
5#include "qeglfshooks_p.h"
6#include <QtGui/QOffscreenSurface>
7#include <QtGui/private/qeglconvenience_p.h>
8
9QT_BEGIN_NAMESPACE
10
11/*
12 In some cases pbuffers are not available. Triggering QtGui's built-in
13 fallback for a hidden QWindow is not suitable for eglfs since this would be
14 treated as an attempt to create multiple top-level, native windows.
15
16 Therefore this class is provided as an alternative to QEGLPbuffer.
17
18 This class requires the hooks to implement createNativeOffscreenWindow().
19*/
20
21QEglFSOffscreenWindow::QEglFSOffscreenWindow(EGLDisplay display, const QSurfaceFormat &format, QOffscreenSurface *offscreenSurface)
22 : QPlatformOffscreenSurface(offscreenSurface)
23 , m_format(format)
24 , m_display(display)
25 , m_surface(EGL_NO_SURFACE)
26 , m_window(0)
27{
28 m_window = qt_egl_device_integration()->createNativeOffscreenWindow(format);
29 if (!m_window) {
30 qWarning(msg: "QEglFSOffscreenWindow: Failed to create native window");
31 return;
32 }
33 EGLConfig config = q_configFromGLFormat(display: m_display, format: m_format);
34 m_surface = eglCreateWindowSurface(dpy: m_display, config, win: m_window, attrib_list: nullptr);
35 if (m_surface != EGL_NO_SURFACE)
36 m_format = q_glFormatFromConfig(display: m_display, config);
37}
38
39QEglFSOffscreenWindow::~QEglFSOffscreenWindow()
40{
41 if (m_surface != EGL_NO_SURFACE)
42 eglDestroySurface(dpy: m_display, surface: m_surface);
43 if (m_window)
44 qt_egl_device_integration()->destroyNativeWindow(window: m_window);
45}
46
47QT_END_NAMESPACE
48

source code of qtbase/src/plugins/platforms/eglfs/api/qeglfsoffscreenwindow.cpp