1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the plugins of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "qeglfsglobal_p.h"
41#include <QtGui/QSurface>
42#include <QtEglSupport/private/qeglconvenience_p.h>
43#include <QtEglSupport/private/qeglpbuffer_p.h>
44
45#include "qeglfscontext_p.h"
46#include "qeglfswindow_p.h"
47#include "qeglfshooks_p.h"
48#include "qeglfscursor_p.h"
49
50QT_BEGIN_NAMESPACE
51
52QEglFSContext::QEglFSContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share, EGLDisplay display,
53 EGLConfig *config, const QVariant &nativeHandle)
54 : QEGLPlatformContext(format, share, display, config, nativeHandle,
55 qt_egl_device_integration()->supportsSurfacelessContexts() ? Flags() : QEGLPlatformContext::NoSurfaceless),
56 m_tempWindow(0)
57{
58}
59
60EGLSurface QEglFSContext::eglSurfaceForPlatformSurface(QPlatformSurface *surface)
61{
62 if (surface->surface()->surfaceClass() == QSurface::Window)
63 return static_cast<QEglFSWindow *>(surface)->surface();
64 else
65 return static_cast<QEGLPbuffer *>(surface)->pbuffer();
66}
67
68EGLSurface QEglFSContext::createTemporaryOffscreenSurface()
69{
70 if (qt_egl_device_integration()->supportsPBuffers())
71 return QEGLPlatformContext::createTemporaryOffscreenSurface();
72
73 if (!m_tempWindow) {
74 m_tempWindow = qt_egl_device_integration()->createNativeOffscreenWindow(format: format());
75 if (!m_tempWindow) {
76 qWarning(msg: "QEglFSContext: Failed to create temporary native window");
77 return EGL_NO_SURFACE;
78 }
79 }
80 EGLConfig config = q_configFromGLFormat(display: eglDisplay(), format: format());
81 return eglCreateWindowSurface(dpy: eglDisplay(), config, win: m_tempWindow, attrib_list: nullptr);
82}
83
84void QEglFSContext::destroyTemporaryOffscreenSurface(EGLSurface surface)
85{
86 if (qt_egl_device_integration()->supportsPBuffers()) {
87 QEGLPlatformContext::destroyTemporaryOffscreenSurface(surface);
88 } else {
89 eglDestroySurface(dpy: eglDisplay(), surface);
90 qt_egl_device_integration()->destroyNativeWindow(window: m_tempWindow);
91 m_tempWindow = 0;
92 }
93}
94
95void QEglFSContext::runGLChecks()
96{
97 // Note that even though there is an EGL context current here,
98 // QOpenGLContext and QOpenGLFunctions are not yet usable at this stage.
99 const char *renderer = reinterpret_cast<const char *>(glGetString(GL_RENDERER));
100 // Be nice and warn about a common source of confusion.
101 if (renderer && strstr(haystack: renderer, needle: "llvmpipe"))
102 qWarning(msg: "Running on a software rasterizer (LLVMpipe), expect limited performance.");
103}
104
105void QEglFSContext::swapBuffers(QPlatformSurface *surface)
106{
107 // draw the cursor
108 if (surface->surface()->surfaceClass() == QSurface::Window) {
109 QPlatformWindow *window = static_cast<QPlatformWindow *>(surface);
110 if (QEglFSCursor *cursor = qobject_cast<QEglFSCursor *>(object: window->screen()->cursor()))
111 cursor->paintOnScreen();
112 }
113
114 qt_egl_device_integration()->waitForVSync(surface);
115 QEGLPlatformContext::swapBuffers(surface);
116 qt_egl_device_integration()->presentBuffer(surface);
117}
118
119QT_END_NAMESPACE
120

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