Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qandroidplatformopenglcontext.cpp
Go to the documentation of this file.
1// Copyright (C) 2014 BogDan Vatra <bogdan@kde.org>
2// Copyright (C) 2016 The Qt Company Ltd.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4// Qt-Security score:significant reason:default
5
10
11#include <QtGui/private/qeglpbuffer_p.h>
12
13#include <QSurface>
14#include <QtGui/private/qopenglcontext_p.h>
15#include <QtGui/QOffscreenSurface>
16
18
19QAndroidPlatformOpenGLContext::QAndroidPlatformOpenGLContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share, EGLDisplay display)
20 : QEGLPlatformContext(format, share, display, nullptr)
21{
22}
23
24void QAndroidPlatformOpenGLContext::swapBuffers(QPlatformSurface *surface)
25{
26 if (surface->surface()->surfaceClass() != QSurface::Window) {
27 QEGLPlatformContext::swapBuffers(surface);
28 return;
29 }
30
31 QAndroidPlatformOpenGLWindow *window = static_cast<QAndroidPlatformOpenGLWindow *>(surface);
32 // Since QEGLPlatformContext::makeCurrent() and QEGLPlatformContext::swapBuffers()
33 // will be using the eglSurface of the window, which wraps the Android Surface, we
34 // need to lock here to make sure we don't end up using a Surface already destroyed
35 // by Android
36 window->lockSurface();
37
38 if (window->ensureEglSurfaceCreated(eglConfig())) {
39 // Call base class implementation directly since we are already locked
40 QEGLPlatformContext::makeCurrent(surface);
41 }
42 QEGLPlatformContext::swapBuffers(surface);
43
44 window->unlockSurface();
45}
46
47bool QAndroidPlatformOpenGLContext::makeCurrent(QPlatformSurface *surface)
48{
49 if (surface->surface()->surfaceClass() != QSurface::Window)
50 return QEGLPlatformContext::makeCurrent(surface);
51
52 QAndroidPlatformOpenGLWindow *window = static_cast<QAndroidPlatformOpenGLWindow *>(surface);
53 window->lockSurface();
54 // Has the Surface been destroyed?
55 if (window->eglSurface(eglConfig()) == EGL_NO_SURFACE) {
56 qWarning() << "makeCurrent(): no EGLSurface, likely Surface destroyed by Android.";
57 window->unlockSurface();
58 return false;
59 }
60 const bool ok = QEGLPlatformContext::makeCurrent(surface);
61 window->unlockSurface();
62 return ok;
63}
64
65// Called from inside QEGLPlatformContext::swapBuffers() and QEGLPlatformContext::makeCurrent(),
66// already locked
67EGLSurface QAndroidPlatformOpenGLContext::eglSurfaceForPlatformSurface(QPlatformSurface *surface)
68{
69 if (surface->surface()->surfaceClass() == QSurface::Window) {
70 return static_cast<QAndroidPlatformOpenGLWindow *>(surface)->eglSurface(eglConfig());
71 } else {
72 if (auto *platformOffscreenSurface = dynamic_cast<QAndroidPlatformOffscreenSurface *>(surface))
73 return platformOffscreenSurface->surface();
74 else
75 return static_cast<QEGLPbuffer *>(surface)->pbuffer();
76 }
77}
78
79QT_END_NAMESPACE
Combined button and popup list for selecting options.