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
9
10#include <QtGui/private/qeglpbuffer_p.h>
11
12#include <QSurface>
13#include <QtGui/private/qopenglcontext_p.h>
14#include <QtGui/QOffscreenSurface>
15
17
18QAndroidPlatformOpenGLContext::QAndroidPlatformOpenGLContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share, EGLDisplay display)
19 : QEGLPlatformContext(format, share, display, nullptr)
20{
21}
22
23void QAndroidPlatformOpenGLContext::swapBuffers(QPlatformSurface *surface)
24{
25 if (surface->surface()->surfaceClass() != QSurface::Window) {
26 QEGLPlatformContext::swapBuffers(surface);
27 return;
28 }
29
30 QAndroidPlatformOpenGLWindow *window = static_cast<QAndroidPlatformOpenGLWindow *>(surface);
31 // Since QEGLPlatformContext::makeCurrent() and QEGLPlatformContext::swapBuffers()
32 // will be using the eglSurface of the window, which wraps the Android Surface, we
33 // need to lock here to make sure we don't end up using a Surface already destroyed
34 // by Android
35 window->lockSurface();
36
37 if (window->ensureEglSurfaceCreated(eglConfig())) {
38 // Call base class implementation directly since we are already locked
39 QEGLPlatformContext::makeCurrent(surface);
40 }
41 QEGLPlatformContext::swapBuffers(surface);
42
43 window->unlockSurface();
44}
45
46bool QAndroidPlatformOpenGLContext::makeCurrent(QPlatformSurface *surface)
47{
48 if (surface->surface()->surfaceClass() != QSurface::Window)
49 return QEGLPlatformContext::makeCurrent(surface);
50
51 QAndroidPlatformOpenGLWindow *window = static_cast<QAndroidPlatformOpenGLWindow *>(surface);
52 window->lockSurface();
53 // Has the Surface been destroyed?
54 if (window->eglSurface(eglConfig()) == EGL_NO_SURFACE) {
55 qWarning() << "makeCurrent(): no EGLSurface, likely Surface destroyed by Android.";
56 window->unlockSurface();
57 return false;
58 }
59 const bool ok = QEGLPlatformContext::makeCurrent(surface);
60 window->unlockSurface();
61 return ok;
62}
63
64// Called from inside QEGLPlatformContext::swapBuffers() and QEGLPlatformContext::makeCurrent(),
65// already locked
66EGLSurface QAndroidPlatformOpenGLContext::eglSurfaceForPlatformSurface(QPlatformSurface *surface)
67{
68 if (surface->surface()->surfaceClass() == QSurface::Window) {
69 return static_cast<QAndroidPlatformOpenGLWindow *>(surface)->eglSurface(eglConfig());
70 } else {
71 if (auto *platformOffscreenSurface = dynamic_cast<QAndroidPlatformOffscreenSurface *>(surface))
72 return platformOffscreenSurface->surface();
73 else
74 return static_cast<QEGLPbuffer *>(surface)->pbuffer();
75 }
76}
77
78QT_END_NAMESPACE