Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qandroidplatformopenglwindow.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
6
8#include "androidjnimain.h"
11
12#include <QSurfaceFormat>
13#include <QtGui/private/qwindow_p.h>
14#include <QtGui/qguiapplication.h>
15
16#include <QtGui/private/qeglconvenience_p.h>
17#include <android/native_window.h>
18#include <android/native_window_jni.h>
19#include <qpa/qplatformscreen.h>
20#include <qpa/qwindowsysteminterface.h>
21
23
30
39
41{
42 if (rect == geometry())
43 return;
44
45 m_oldGeometry = geometry();
46
48
49
51
52 QRect availableGeometry = screen()->availableGeometry();
53 if (rect.width() > 0
54 && rect.height() > 0
55 && availableGeometry.width() > 0
56 && availableGeometry.height() > 0) {
58 }
59}
60
62{
65 return m_eglSurface;
66 }
67
69
70 if (!m_surfaceCreated) {
72 if (!protector.acquire())
73 return m_eglSurface;
74
77 }
78
79 if (m_eglSurface == EGL_NO_SURFACE) {
83 }
84 return m_eglSurface;
85}
86
88{
91 return false; // makeCurrent is NOT needed.
92
94
95 // we've create another surface, the window should be repainted
96 QRect availableGeometry = screen()->availableGeometry();
97 if (geometry().width() > 0 && geometry().height() > 0 && availableGeometry.width() > 0 && availableGeometry.height() > 0)
99 return true; // makeCurrent is needed!
100}
101
112
114{
115 clearEgl();
116 QJniEnvironment env;
117 m_nativeWindow = ANativeWindow_fromSurface(env.jniEnv(), m_androidSurfaceObject.object());
119 m_eglSurface = eglCreateWindowSurface(m_eglDisplay, config, m_nativeWindow, NULL);
120 m_format = q_glFormatFromConfig(m_eglDisplay, config, window()->requestedFormat());
121 if (Q_UNLIKELY(m_eglSurface == EGL_NO_SURFACE)) {
122 EGLint error = eglGetError();
123 eglTerminate(m_eglDisplay);
124 qFatal("EGL Error : Could not create the egl surface: error = 0x%x\n", error);
125 }
126}
127
129{
130 if (m_nativeWindow == 0)
131 return window()->requestedFormat();
132
133 return m_format;
134}
135
137{
138 if (m_eglSurface != EGL_NO_SURFACE) {
139 eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
140 eglDestroySurface(m_eglDisplay, m_eglSurface);
141 m_eglSurface = EGL_NO_SURFACE;
142 }
143
144 if (m_nativeWindow) {
145 ANativeWindow_release(m_nativeWindow);
146 m_nativeWindow = 0;
147 }
148}
149
void applicationStateChanged(Qt::ApplicationState) override
EGLSurface eglSurface(EGLConfig config)
void setGeometry(const QRect &rect) override
This function is called by Qt whenever a window is moved or resized using the QWindow API.
QAndroidPlatformOpenGLWindow(QWindow *window, EGLDisplay display)
QSurfaceFormat format() const override
Returns the actual surface format of the window.
void setNativeGeometry(const QRect &geometry)
virtual void applicationStateChanged(Qt::ApplicationState)
QtJniTypes::Surface m_androidSurfaceObject
void setGeometry(const QRect &rect) override
This function is called by Qt whenever a window is moved or resized using the QWindow API.
static Qt::ApplicationState applicationState()
\inmodule QtCore
\inmodule QtCore
\inmodule QtCore
Definition qmutex.h:313
void unlock() noexcept
Unlocks the mutex.
Definition qmutex.h:289
void lock() noexcept
Locks the mutex.
Definition qmutex.h:286
virtual QRect availableGeometry() const
Reimplement in subclass to return the pixel geometry of the available space This normally is the desk...
QWindow * window() const
Returns the window which belongs to the QPlatformWindow.
QPlatformScreen * screen() const override
Returns the platform screen handle corresponding to this platform window, or null if the window is no...
virtual QRect geometry() const
Returns the current geometry of a window.
\inmodule QtCore\reentrant
Definition qpoint.h:25
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr int height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:239
constexpr int width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:236
The QRegion class specifies a clip region for a painter.
Definition qregion.h:27
The QSurfaceFormat class represents the format of a QSurface. \inmodule QtGui.
@ RasterSurface
Definition qsurface.h:31
@ OpenGLSurface
Definition qsurface.h:32
bool wait(QMutex *, QDeadlineTimer=QDeadlineTimer(QDeadlineTimer::Forever))
static bool handleExposeEvent(QWindow *window, const QRegion &region)
\inmodule QtGui
Definition qwindow.h:63
SurfaceType surfaceType() const override
Returns the surface type of the window.
Definition qwindow.cpp:665
rect
[4]
else opt state
[0]
struct wl_display * display
Definition linuxdmabuf.h:41
Combined button and popup list for selecting options.
ApplicationState
Definition qnamespace.h:262
@ ApplicationHidden
Definition qnamespace.h:264
@ ApplicationSuspended
Definition qnamespace.h:263
#define Q_UNLIKELY(x)
DBusConnection const char DBusError * error
QSurfaceFormat q_glFormatFromConfig(EGLDisplay display, const EGLConfig config, const QSurfaceFormat &referenceFormat)
EGLConfig config
typedef EGLSurface(EGLAPIENTRYP PFNEGLCREATESTREAMPRODUCERSURFACEKHRPROC)(EGLDisplay dpy
typedef EGLDisplay(EGLAPIENTRYP PFNEGLGETPLATFORMDISPLAYEXTPROC)(EGLenum platform
#define qFatal
Definition qlogging.h:168
GLint GLsizei GLsizei height
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei width
QReadWriteLock lock
[0]
aWidget window() -> setWindowTitle("New Window Title")
[2]