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
4#include "qxcbvulkanwindow.h"
5
6QT_BEGIN_NAMESPACE
7
8QXcbVulkanWindow::QXcbVulkanWindow(QWindow *window)
9 : QXcbWindow(window),
10 m_surface(VK_NULL_HANDLE)
11{
12}
13
14QXcbVulkanWindow::~QXcbVulkanWindow()
15{
16 if (m_surface) {
17 QVulkanInstance *inst = window()->vulkanInstance();
18 if (inst)
19 static_cast<QXcbVulkanInstance *>(inst->handle())->destroySurface(surface: m_surface);
20 }
21}
22
23void QXcbVulkanWindow::resolveFormat(const QSurfaceFormat &format)
24{
25 m_format = format;
26 if (m_format.redBufferSize() <= 0)
27 m_format.setRedBufferSize(8);
28 if (m_format.greenBufferSize() <= 0)
29 m_format.setGreenBufferSize(8);
30 if (m_format.blueBufferSize() <= 0)
31 m_format.setBlueBufferSize(8);
32}
33
34// No createVisual() needed, use the default that picks one based on the R/G/B/A size.
35
36VkSurfaceKHR *QXcbVulkanWindow::surface()
37{
38 if (m_surface)
39 return &m_surface;
40
41 QVulkanInstance *inst = window()->vulkanInstance();
42 if (!inst) {
43 qWarning(msg: "Attempted to create Vulkan surface without an instance; was QWindow::setVulkanInstance() called?");
44 return nullptr;
45 }
46 QXcbVulkanInstance *xcbinst = static_cast<QXcbVulkanInstance *>(inst->handle());
47 m_surface = xcbinst->createSurface(window: this);
48
49 return &m_surface;
50}
51
52QT_END_NAMESPACE
53

source code of qtbase/src/plugins/platforms/xcb/qxcbvulkanwindow.cpp