1// Copyright (C) 2019 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
4#include "qwaylandvulkanwindow_p.h"
5
6QT_BEGIN_NAMESPACE
7
8namespace QtWaylandClient {
9
10QWaylandVulkanWindow::QWaylandVulkanWindow(QWindow *window, QWaylandDisplay *display)
11 : QWaylandWindow(window, display)
12{
13}
14
15QWaylandVulkanWindow::~QWaylandVulkanWindow()
16{
17 invalidateSurface();
18}
19
20QWaylandWindow::WindowType QWaylandVulkanWindow::windowType() const
21{
22 return QWaylandWindow::Vulkan;
23}
24
25void QWaylandVulkanWindow::invalidateSurface()
26{
27 if (m_surface) {
28 QVulkanInstance *inst = window()->vulkanInstance();
29 if (inst)
30 static_cast<QWaylandVulkanInstance *>(inst->handle())->destroySurface(surface: m_surface);
31 }
32 m_surface = VK_NULL_HANDLE;
33 QWaylandWindow::invalidateSurface();
34}
35
36VkSurfaceKHR *QWaylandVulkanWindow::vkSurface()
37{
38 if (m_surface)
39 return &m_surface;
40
41 QVulkanInstance *vulkanInstance = window()->vulkanInstance();
42 if (!vulkanInstance) {
43 qWarning() << "Attempted to create Vulkan surface without an instance; was QWindow::setVulkanInstance() called?";
44 return nullptr;
45 }
46
47 auto *waylandVulkanInstance = static_cast<QWaylandVulkanInstance *>(vulkanInstance->handle());
48 m_surface = waylandVulkanInstance->createSurface(this);
49
50 return &m_surface;
51}
52
53} // namespace QtWaylandClient
54
55QT_END_NAMESPACE
56

source code of qtwayland/src/client/qwaylandvulkanwindow.cpp