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
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// Qt-Security score:significant reason:default
4
8
9#include <QSurfaceFormat>
10#include <qpa/qplatformscreen.h>
11#include <qpa/qwindowsysteminterface.h>
12
13#include <android/native_window.h>
14#include <android/native_window_jni.h>
15
17
18using namespace Qt::StringLiterals;
19
24
26{
27 // The base class destructor can't reach destroyWindowSurface().
29}
30
32{
34
35 // Like the OpenGL window, programmatic resizes need an expose to
36 // re-layout widget-embedded scenes.
37 if (!rect.isEmpty() && !screen()->availableGeometry().isEmpty())
38 QWindowSystemInterface::handleExposeEvent(window(), QRegion(QRect(QPoint(), rect.size())));
39}
40
42{
43 return window()->requestedFormat();
44}
45
47{
48 if (Q_LIKELY(m_vkSurface != VK_NULL_HANDLE))
49 return &m_vkSurface;
51 if (!m_nativeWindow)
52 return &m_vkSurface;
53
54 QVulkanInstance *inst = window()->vulkanInstance();
55 if (!inst) {
56 qWarning("Attempted to create Vulkan surface without an instance; "
57 "was QWindow::setVulkanInstance() called?");
58 return &m_vkSurface;
59 }
60 if (!m_createVkSurface) {
61 m_createVkSurface = reinterpret_cast<PFN_vkCreateAndroidSurfaceKHR>(
62 inst->getInstanceProcAddr("vkCreateAndroidSurfaceKHR"));
63 }
64 if (!m_destroyVkSurface) {
65 m_destroyVkSurface = reinterpret_cast<PFN_vkDestroySurfaceKHR>(
66 inst->getInstanceProcAddr("vkDestroySurfaceKHR"));
67 }
68 VkAndroidSurfaceCreateInfoKHR surfaceInfo {};
69 surfaceInfo.sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR;
70 surfaceInfo.window = m_nativeWindow;
71 const VkResult err = m_createVkSurface(inst->vkInstance(), &surfaceInfo, nullptr, &m_vkSurface);
72 if (err != VK_SUCCESS)
73 qWarning("Failed to create Android VkSurface: %d", err);
74 return &m_vkSurface;
75}
76
78{
79 if (m_vkSurface && m_destroyVkSurface) {
80 m_destroyVkSurface(window()->vulkanInstance()->vkInstance(), m_vkSurface, nullptr);
81 m_vkSurface = VK_NULL_HANDLE;
82 }
83}
84
85QT_END_NAMESPACE
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.
QAndroidPlatformWindow(QWindow *window)
void setGeometry(const QRect &rect) override
This function is called by Qt whenever a window is moved or resized using the QWindow API.
Combined button and popup list for selecting options.