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#ifndef QXCBEGLCONTEXT_H
5#define QXCBEGLCONTEXT_H
6
7#include "qxcbeglwindow.h"
8#include <QtGui/private/qeglplatformcontext_p.h>
9#include <QtGui/private/qeglpbuffer_p.h>
10
11QT_BEGIN_NAMESPACE
12
13class QXcbEglContext : public QEGLPlatformContext
14{
15public:
16 using QEGLPlatformContext::QEGLPlatformContext;
17 QXcbEglContext(const QSurfaceFormat &glFormat, QPlatformOpenGLContext *share, EGLDisplay display)
18 : QEGLPlatformContext(glFormat, share, display, nullptr)
19 {
20 }
21
22 void swapBuffers(QPlatformSurface *surface) override
23 {
24 QEGLPlatformContext::swapBuffers(surface);
25 if (surface->surface()->surfaceClass() == QSurface::Window) {
26 QXcbWindow *platformWindow = static_cast<QXcbWindow *>(surface);
27 // OpenGL context might be bound to a non-gui thread use QueuedConnection to sync
28 // the window from the platformWindow's thread as QXcbWindow is no QObject, an
29 // event is sent to QXcbConnection. (this is faster than a metacall)
30 if (platformWindow->needsSync())
31 platformWindow->postSyncWindowRequest();
32 }
33 }
34
35 bool makeCurrent(QPlatformSurface *surface) override
36 {
37 return QEGLPlatformContext::makeCurrent(surface);
38 }
39
40 void doneCurrent() override
41 {
42 QEGLPlatformContext::doneCurrent();
43 }
44
45 EGLSurface eglSurfaceForPlatformSurface(QPlatformSurface *surface) override
46 {
47 if (surface->surface()->surfaceClass() == QSurface::Window)
48 return static_cast<QXcbEglWindow *>(surface)->eglSurface();
49 else
50 return static_cast<QEGLPbuffer *>(surface)->pbuffer();
51 }
52};
53
54QT_END_NAMESPACE
55#endif //QXCBEGLCONTEXT_H
56
57

source code of qtbase/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglcontext.h