1/****************************************************************************
2**
3** Copyright (C) 2020 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtGui module 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 <QtGui/private/qtguiglobal_p.h>
41
42#include <QtGui/private/qopenglcontext_p.h>
43#include <QtGui/private/qguiapplication_p.h>
44
45#include <qpa/qplatformopenglcontext.h>
46#include <qpa/qplatformintegration.h>
47#include <qpa/qplatformscreen_p.h>
48#include <qpa/qplatformwindow_p.h>
49
50#include <QtGui/private/qkeymapper_p.h>
51
52QT_BEGIN_NAMESPACE
53
54using namespace QNativeInterface::Private;
55
56#ifndef QT_NO_OPENGL
57
58#if defined(Q_OS_LINUX)
59
60/*!
61 \class QNativeInterface::QGLXContext
62 \since 6.0
63 \brief Native interface to a GLX context.
64
65 Accessed through QOpenGLContext::nativeInterface().
66
67 \inmodule QtGui
68 \ingroup native-interfaces
69 \ingroup native-interfaces-qopenglcontext
70*/
71
72/*!
73 \fn QOpenGLContext *QNativeInterface::QGLXContext::fromNative(GLXContext configBasedContext, QOpenGLContext *shareContext = nullptr)
74
75 \brief Adopts a GLXContext created from an FBConfig.
76
77 The context must be created from a framebuffer configuration, using the \c glXCreateNewContext function.
78
79 Ownership of the created QOpenGLContext is transferred to the caller.
80*/
81
82/*!
83 \fn QOpenGLContext *QNativeInterface::QGLXContext::fromNative(GLXContext visualBasedContext, void *visualInfo, QOpenGLContext *shareContext = nullptr)
84
85 \brief Adopts a GLXContext created from an X visual.
86
87 The context must be created from a visual, using the \c glXCreateContext function.
88 The same visual must be passed as a pointer to an \c XVisualInfo struct, in the \a visualInfo argument.
89
90 Ownership of the created QOpenGLContext is transferred to the caller.
91*/
92
93/*!
94 \fn GLXContext QNativeInterface::QGLXContext::nativeContext() const
95
96 \return the underlying GLXContext.
97*/
98
99QT_DEFINE_NATIVE_INTERFACE(QGLXContext, QOpenGLContext);
100QT_DEFINE_PRIVATE_NATIVE_INTERFACE(QGLXIntegration);
101
102QOpenGLContext *QNativeInterface::QGLXContext::fromNative(GLXContext configBasedContext, QOpenGLContext *shareContext)
103{
104 return QGuiApplicationPrivate::platformIntegration()->call<
105 &QGLXIntegration::createOpenGLContext>(configBasedContext, nullptr, shareContext);
106}
107
108QOpenGLContext *QNativeInterface::QGLXContext::fromNative(GLXContext visualBasedContext, void *visualInfo, QOpenGLContext *shareContext)
109{
110 return QGuiApplicationPrivate::platformIntegration()->call<
111 &QGLXIntegration::createOpenGLContext>(visualBasedContext, visualInfo, shareContext);
112}
113#endif // defined(Q_OS_LINUX)
114
115#if QT_CONFIG(egl)
116
117/*!
118 \class QNativeInterface::QEGLContext
119 \since 6.0
120 \brief Native interface to an EGL context.
121
122 Accessed through QOpenGLContext::nativeInterface().
123
124 \inmodule QtGui
125 \ingroup native-interfaces
126 \ingroup native-interfaces-qopenglcontext
127*/
128
129/*!
130 \fn QOpenGLContext *QNativeInterface::QEGLContext::fromNative(EGLContext context, EGLDisplay display, QOpenGLContext *shareContext = nullptr)
131
132 \brief Adopts an EGLContext.
133
134 The same \c EGLDisplay passed to \c eglCreateContext must be passed as the \a display argument.
135
136 Ownership of the created QOpenGLContext is transferred to the caller.
137*/
138
139/*!
140 \fn EGLContext QNativeInterface::QEGLContext::nativeContext() const
141
142 \return the underlying EGLContext.
143*/
144
145QT_DEFINE_NATIVE_INTERFACE(QEGLContext, QOpenGLContext);
146QT_DEFINE_PRIVATE_NATIVE_INTERFACE(QEGLIntegration);
147
148QOpenGLContext *QNativeInterface::QEGLContext::fromNative(EGLContext context, EGLDisplay display, QOpenGLContext *shareContext)
149{
150 return QGuiApplicationPrivate::platformIntegration()->call<
151 &QEGLIntegration::createOpenGLContext>(context, display, shareContext);
152}
153#endif // QT_CONFIG(egl)
154
155#endif // QT_NO_OPENGL
156
157#if QT_CONFIG(xcb)
158
159/*!
160 \class QNativeInterface::Private::QXcbScreen
161 \since 6.0
162 \internal
163 \brief Native interface to QPlatformScreen.
164 \inmodule QtGui
165 \ingroup native-interfaces
166*/
167
168QT_DEFINE_PRIVATE_NATIVE_INTERFACE(QXcbScreen);
169
170/*!
171 \class QNativeInterface::Private::QXcbWindow
172 \since 6.0
173 \internal
174 \brief Native interface to QPlatformWindow.
175 \inmodule QtGui
176 \ingroup native-interfaces
177*/
178
179QT_DEFINE_PRIVATE_NATIVE_INTERFACE(QXcbWindow);
180
181#endif // QT_CONFIG(xcb)
182
183#if QT_CONFIG(vsp2)
184QT_DEFINE_PRIVATE_NATIVE_INTERFACE(QVsp2Screen);
185#endif
186
187#if QT_CONFIG(evdev)
188
189/*!
190 \class QNativeInterface::Private::QEvdevKeyMapper
191 \since 6.0
192 \internal
193 \brief Native interface to QKeyMapper.
194 \inmodule QtGui
195 \ingroup native-interfaces
196*/
197
198QT_DEFINE_PRIVATE_NATIVE_INTERFACE(QEvdevKeyMapper);
199
200template <>
201QEvdevKeyMapper *QKeyMapper::nativeInterface<QEvdevKeyMapper>() const
202{
203 return dynamic_cast<QEvdevKeyMapper*>(QGuiApplicationPrivate::platformIntegration());
204}
205#endif // QT_CONFIG(evdev)
206
207QT_END_NAMESPACE
208