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 <QtGui/private/qeglconvenience_p.h>
43#include <QtGui/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)
54 : QEGLPlatformContext(format, share, display, config,
55 qt_egl_device_integration()->supportsSurfacelessContexts() ? Flags() : QEGLPlatformContext::NoSurfaceless)
56{
57}
58
59EGLSurface QEglFSContext::eglSurfaceForPlatformSurface(QPlatformSurface *surface)
60{
61 if (surface->surface()->surfaceClass() == QSurface::Window)
62 return static_cast<QEglFSWindow *>(surface)->surface();
63 else
64 return static_cast<QEGLPbuffer *>(surface)->pbuffer();
65}
66
67EGLSurface QEglFSContext::createTemporaryOffscreenSurface()
68{
69 if (qt_egl_device_integration()->supportsPBuffers())
70 return QEGLPlatformContext::createTemporaryOffscreenSurface();
71
72 if (!m_tempWindow) {
73 m_tempWindow = qt_egl_device_integration()->createNativeOffscreenWindow(format());
74 if (!m_tempWindow) {
75 qWarning("QEglFSContext: Failed to create temporary native window");
76 return EGL_NO_SURFACE;
77 }
78 }
79 EGLConfig config = q_configFromGLFormat(eglDisplay(), format());
80 return eglCreateWindowSurface(eglDisplay(), config, m_tempWindow, nullptr);
81}
82
83void QEglFSContext::destroyTemporaryOffscreenSurface(EGLSurface surface)
84{
85 if (qt_egl_device_integration()->supportsPBuffers()) {
86 QEGLPlatformContext::destroyTemporaryOffscreenSurface(surface);
87 } else {
88 eglDestroySurface(eglDisplay(), surface);
89 qt_egl_device_integration()->destroyNativeWindow(m_tempWindow);
90 m_tempWindow = 0;
91 }
92}
93
94void QEglFSContext::runGLChecks()
95{
96 // Note that even though there is an EGL context current here,
97 // QOpenGLContext and QOpenGLFunctions are not yet usable at this stage.
98 const char *renderer = reinterpret_cast<const char *>(glGetString(GL_RENDERER));
99 // Be nice and warn about a common source of confusion.
100 if (renderer && strstr(renderer, "llvmpipe"))
101 qWarning("Running on a software rasterizer (LLVMpipe), expect limited performance.");
102}
103
104void QEglFSContext::swapBuffers(QPlatformSurface *surface)
105{
106 // draw the cursor
107 if (surface->surface()->surfaceClass() == QSurface::Window) {
108 QPlatformWindow *window = static_cast<QPlatformWindow *>(surface);
109 if (QEglFSCursor *cursor = qobject_cast<QEglFSCursor *>(window->screen()->cursor()))
110 cursor->paintOnScreen();
111 }
112
113 qt_egl_device_integration()->waitForVSync(surface);
114 QEGLPlatformContext::swapBuffers(surface);
115 qt_egl_device_integration()->presentBuffer(surface);
116}
117
118QT_END_NAMESPACE
119