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
qandroidplatformwindow.h
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
6#ifndef ANDROIDPLATFORMWINDOW_H
7#define ANDROIDPLATFORMWINDOW_H
8#include <qobject.h>
9#include <qrect.h>
10#include <qpa/qplatformwindow.h>
11#include <QtCore/qjnienvironment.h>
12#include <QtCore/qjniobject.h>
13#include <QtCore/qjnitypes.h>
14#include <QtCore/qloggingcategory.h>
15
16#include <jni.h>
17
18struct ANativeWindow;
19
20QT_BEGIN_NAMESPACE
21
22Q_DECLARE_LOGGING_CATEGORY(lcQpaWindow)
23Q_DECLARE_JNI_CLASS(QtWindow, "org/qtproject/qt/android/QtWindow")
24Q_DECLARE_JNI_CLASS(Surface, "android/view/Surface")
25Q_DECLARE_JNI_CLASS(Insets, "android/graphics/Insets")
26Q_DECLARE_JNI_CLASS(Runnable, "java/lang/Runnable")
27
28class QAndroidPlatformScreen;
29
30// Surface lifecycle. The Qt GUI thread owns m_nativeWindow and the expose
31// state. JNI surface callbacks are queued unless Qt is parked.
32// When Qt destroys a window it releases the GPU surface itself first.
33// The render thread creates its EGL/Vk surface lazily from m_nativeWindow, and
34// isExposed() stays false until a Surface arrives.
35//
36// m_nativeWindow needs no atomics. The GUI thread writes it only while the
37// render thread is paused by SurfaceAboutToBeDestroyed, and the render thread
38// reads it only after the posted expose event, which orders the write.
39
41{
42public:
47
48 explicit QAndroidPlatformWindow(QWindow *window);
49 void initialize() override;
50
52 void lower() override;
53 void raise() override;
54
55 void setVisible(bool visible) override;
56
57 void setWindowState(Qt::WindowStates state) override;
58 void setWindowFlags(Qt::WindowFlags flags) override;
59 void setParent(const QPlatformWindow *window) override;
60
61 WId winId() const override;
62
63 bool setMouseGrabEnabled(bool grab) override { Q_UNUSED(grab); return false; }
64 bool setKeyboardGrabEnabled(bool grab) override { Q_UNUSED(grab); return false; }
65
67
68 QMargins safeAreaMargins() const override;
69 void setSafeAreaMargins(const QMargins safeMargins);
70
73 void applySystemUi(Qt::WindowStates states, Qt::WindowFlags flags);
75 inline bool isRaster() const { return m_isRaster; }
76 bool isExposed() const override;
77 QtJniTypes::QtWindow nativeWindow() const { return m_nativeQtWindow; }
78
80 void sendChildExposeEvents() const;
81 bool isChildOfQtWindow() const;
83 int nativeViewId() const { return m_nativeViewId; }
84
85 static bool registerNatives(QJniEnvironment &env);
86
87 // GUI-thread handlers for the queued JNI surface callbacks.
88 void onSurfaceCreated(QtJniTypes::Surface surface);
89 void onRedrawNeeded();
90 void onSurfaceDestroyed();
91
92protected:
93 void setGeometry(const QRect &rect) override;
94 void updateNativeWindow(bool visible);
95 bool blockedByModal() const;
96 bool isEmbeddingContainer() const;
97
98 // Ends Qt's use of the Surface. Runs on the GUI thread, or inline while
99 // Qt is parked.
100 void releaseSurface();
101
102 // Also removes the Surface from Java, which doesn't report that back.
103 void destroySurface();
104
105 // Fetches the Surface from Java without blocking, so makeCurrent() right
106 // after QWindow::create() works. GUI thread only.
107 void ensureNativeWindow();
108
109 // Written on the GUI thread, read on the render thread after the expose
110 // event that follows the write.
111 ANativeWindow *m_nativeWindow = nullptr;
112
113 // Between Android's surfaceCreated and surfaceDestroyed. Unlike
114 // m_nativeWindow, it drops before the GPU surface is torn down.
115 bool m_surfaceValid = false;
116
118
123
125
126private:
127 // The EGL or Vulkan surface, which has to go before the ANativeWindow.
128 virtual void destroyWindowSurface() {}
129
130 static void surfaceCreated(JNIEnv *env, jobject obj, jint windowId, QtJniTypes::Surface surface);
132 static void surfaceRedrawNeeded(JNIEnv *env, jobject obj, jint windowId,
133 QtJniTypes::Runnable drawingFinished);
135 static void surfaceDestroyed(JNIEnv *env, jobject obj, jint windowId,
136 QtJniTypes::Runnable surfaceReleased);
138 static void windowFocusChanged(JNIEnv *env, jobject object, jboolean focus, jint windowId);
140 static void safeAreaMarginsChanged(JNIEnv *env, jobject obj, QtJniTypes::Insets insets, jint id);
142 static void applySystemUiNative(JNIEnv *env, jobject obj);
144
145 static QAndroidPlatformWindow *findWindowById(jint windowId);
146};
147
148QT_END_NAMESPACE
149#endif // ANDROIDPLATFORMWINDOW_H
static const char m_qtTag[]
#define GET_AND_CHECK_STATIC_METHOD(VAR, CLASS, METHOD_NAME, METHOD_SIGNATURE)
#define CHECK_AND_INIT_STATIC_FIELD(TYPE, VAR, CLASS, FIELD_NAME)
void propagateSizeHints() override
Reimplement to propagate the size hints of the QWindow.
virtual void applicationStateChanged(Qt::ApplicationState)
QAndroidPlatformWindow(QWindow *window)
void setSafeAreaMargins(const QMargins safeMargins)
void setWindowFlags(Qt::WindowFlags flags) override
Requests setting the window flags of this surface to flags.
void setWindowState(Qt::WindowStates state) override
Requests setting the window state of this surface to type.
QtJniTypes::QtWindow nativeWindow() const
bool isExposed() const override
Returns if this window is exposed in the windowing system.
SurfaceContainer m_surfaceContainerType
QAndroidPlatformScreen * platformScreen() const
void requestActivateWindow() override
Reimplement to let Qt be able to request activation/focus for a window.
bool setKeyboardGrabEnabled(bool grab) override
void applySystemUi(Qt::WindowStates states, Qt::WindowFlags flags)
static bool registerNatives(QJniEnvironment &env)
void updateNativeWindow(bool visible)
QtJniTypes::QtWindow m_nativeParentQtWindow
QtJniTypes::QtWindow m_nativeQtWindow
void initialize() override
Called as part of QWindow::create(), after constructing the window.
void setVisible(bool visible) override
Reimplemented in subclasses to show the surface if visible is true, and hide it if visible is false.
void setParent(const QPlatformWindow *window) override
This function is called to enable native child window in QPA.
void lower() override
Reimplement to be able to let Qt lower windows to the bottom of the desktop.
bool setMouseGrabEnabled(bool grab) override
void onSurfaceCreated(QtJniTypes::Surface surface)
WId winId() const override
Reimplement in subclasses to return a handle to the native window.
void raise() override
Reimplement to be able to let Qt raise windows to the top of the desktop.
void setGeometry(const QRect &rect) override
This function is called by Qt whenever a window is moved or resized using the QWindow API.
QMargins safeAreaMargins() const override
The safe area margins of a window represent the area that is safe to place content within,...
\inmodule QtCore\reentrant
Definition qpoint.h:30
static jboolean showOnScreen(JNIEnv *, jobject, jint objectId)
void notifyDescriptionOrNameChanged(uint accessibilityObjectId)
void notifyObjectShow(uint accessibilityObjectId)
static bool clickAction_helper(int objectId)
static const JNINativeMethod methods[]
void notifyLocationChange(uint accessibilityObjectId)
void runInObjectContext(QObject *context, Func &&func, Ret *retVal)
static std::atomic< bool > m_accessibilityActivated
static jboolean scrollForward(JNIEnv *, jobject, jint objectId)
static ScrollEventInfo populateScrollEvent_helper(int objectId)
void notifyObjectFocus(uint accessibilityObjectId)
static jboolean scrollBackward(JNIEnv *, jobject, jint objectId)
static QString descriptionForInterface(QAccessibleInterface *iface)
static bool showOnScreen_helper(int objectId)
static int hitTest_helper(float x, float y)
static jboolean expand(JNIEnv *, jobject, jint objectId)
static jstring descriptionForAccessibleObject(JNIEnv *env, jobject, jint objectId)
void notifyObjectDestroyed(uint accessibilityObjectId)
static bool scroll_helper(int objectId, const QString &actionName)
static QString classNameForRole(QAccessible::Role role, QAccessible::State state)
static jmethodID m_setContentDescriptionMethodID
static QString textFromValue(QAccessibleInterface *iface)
void createAccessibilityContextObject(QObject *parent)
static QVarLengthArray< int, 8 > childIdListForAccessibleObject_helper(int objectId)
void notifyObjectCreated(uint accessibilityObjectId)
static NodeInfo populateNode_helper(int objectId)
void notifyObjectHide(uint accessibilityObjectId)
static jboolean focusAction(JNIEnv *, jobject, jint objectId)
static jmethodID m_setExpandedStateMethodID
static QList< QAccessible::Id > m_modalInterfaces
static QString languageTag_helper(int objectId)
static jmethodID m_setVisibleToUserMethodID
static jint hitTest(JNIEnv *, jobject, jfloat x, jfloat y)
static jstring languageTag(JNIEnv *env, jobject, jint objectId)
static bool focusAction_helper(int objectId)
static jboolean clickAction(JNIEnv *, jobject, jint objectId)
static bool childOfModalInterface(QAccessibleInterface *modalInterface, QAccessibleInterface *iface)
static void setActive(JNIEnv *, jobject, jboolean active)
static void invokeActionOnInterfaceInMainThread(QAccessibleActionInterface *actionInterface, const QString &action)
static jmethodID m_setTextSelectionMethodID
bool registerNatives(QJniEnvironment &env)
QAccessibleInterface * interfaceFromId(jint objectId)
void notifyValueChanged(uint accessibilityObjectId)
static jboolean populateScrollEvent(JNIEnv *env, jobject, jint objectId, jobject event)
static int expandedStateFromState(QAccessible::State state)
void notifyAnnouncementEvent(uint accessibilityObjectId, const QString &message)
static int parentId_helper(int objectId)
static QRect screenRect_helper(int objectId, bool clip=true)
static QString descriptionForAccessibleObject_helper(int objectId)
static jint parentId(JNIEnv *, jobject, jint objectId)
static jboolean collapse(JNIEnv *, jobject, jint objectId)
static jobject screenRect(JNIEnv *env, jobject, jint objectId)
static jintArray childIdListForAccessibleObject(JNIEnv *env, jobject, jint objectId)
static jboolean populateNode(JNIEnv *env, jobject, jint objectId, jobject node)
void notifyScrolledEvent(uint accessiblityObjectId)
#define qApp