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
qandroidplatformvulkanwindow.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 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
5#include "androidjnimain.h"
9
10#include <QSurfaceFormat>
11#include <qpa/qplatformscreen.h>
12#include <qpa/qwindowsysteminterface.h>
13
14#include <android/native_window.h>
15#include <android/native_window_jni.h>
16
18
21 m_nativeWindow(nullptr),
22 m_vkSurface(0),
23 m_createVkSurface(nullptr),
24 m_destroyVkSurface(nullptr)
25{
26}
27
33
35{
36 if (rect == geometry())
37 return;
38
39 m_oldGeometry = geometry();
40
44
45 QRect availableGeometry = screen()->availableGeometry();
46 if (rect.width() > 0
47 && rect.height() > 0
48 && availableGeometry.width() > 0
49 && availableGeometry.height() > 0) {
51 }
52}
53
61
63{
64 return window()->requestedFormat();
65}
66
67void QAndroidPlatformVulkanWindow::clearSurface()
68{
69 if (m_vkSurface && m_destroyVkSurface) {
70 m_destroyVkSurface(window()->vulkanInstance()->vkInstance(), m_vkSurface, nullptr);
71 m_vkSurface = 0;
72 }
73
74 if (m_nativeWindow) {
75 ANativeWindow_release(m_nativeWindow);
76 m_nativeWindow = nullptr;
77 }
78}
79
80void QAndroidPlatformVulkanWindow::destroyAndClearSurface()
81{
84 clearSurface();
86}
87
89{
91 return &m_vkSurface;
92
93 bool needsExpose = false;
94 if (!m_vkSurface) {
95 clearSurface();
96
98 if (!m_surfaceCreated) {
100 if (!protector.acquire())
101 return &m_vkSurface;
104 }
105
106 if (!m_surfaceCreated || !m_androidSurfaceObject.isValid())
107 return &m_vkSurface;
108
109 QJniEnvironment env;
110 m_nativeWindow = ANativeWindow_fromSurface(env.jniEnv(), m_androidSurfaceObject.object());
111
112 VkAndroidSurfaceCreateInfoKHR surfaceInfo;
113 memset(&surfaceInfo, 0, sizeof(surfaceInfo));
114 surfaceInfo.sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR;
115 surfaceInfo.window = m_nativeWindow;
116 QVulkanInstance *inst = window()->vulkanInstance();
117 if (!inst) {
118 qWarning("Attempted to create Vulkan surface without an instance; was QWindow::setVulkanInstance() called?");
119 return &m_vkSurface;
120 }
121 if (!m_createVkSurface) {
122 m_createVkSurface = reinterpret_cast<PFN_vkCreateAndroidSurfaceKHR>(
123 inst->getInstanceProcAddr("vkCreateAndroidSurfaceKHR"));
124 }
125 if (!m_destroyVkSurface) {
126 m_destroyVkSurface = reinterpret_cast<PFN_vkDestroySurfaceKHR>(
127 inst->getInstanceProcAddr("vkDestroySurfaceKHR"));
128 }
129 VkResult err = m_createVkSurface(inst->vkInstance(), &surfaceInfo, nullptr, &m_vkSurface);
130 if (err != VK_SUCCESS)
131 qWarning("Failed to create Android VkSurface: %d", err);
132
133 needsExpose = true;
134 }
135
136 if (needsExpose)
137 sendExpose();
138
139 return &m_vkSurface;
140}
141
void applicationStateChanged(Qt::ApplicationState) override
void setGeometry(const QRect &rect) override
This function is called by Qt whenever a window is moved or resized using the QWindow API.
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.
\inmodule QtCore
\inmodule QtCore
Definition qmutex.h:313
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 QSurfaceFormat class represents the format of a QSurface. \inmodule QtGui.
The QVulkanInstance class represents a native Vulkan instance, enabling Vulkan rendering onto a QSurf...
bool wait(QMutex *, QDeadlineTimer=QDeadlineTimer(QDeadlineTimer::Forever))
static bool handleExposeEvent(QWindow *window, const QRegion &region)
\inmodule QtGui
Definition qwindow.h:63
rect
[4]
else opt state
[0]
Combined button and popup list for selecting options.
ApplicationState
Definition qnamespace.h:262
@ ApplicationHidden
Definition qnamespace.h:264
#define qWarning
Definition qlogging.h:166
QObject::connect nullptr
QReadWriteLock lock
[0]
aWidget window() -> setWindowTitle("New Window Title")
[2]