1/****************************************************************************
2**
3** Copyright (C) 2017 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QVULKANWINDOW_H
41#define QVULKANWINDOW_H
42
43#include <QtGui/qtguiglobal.h>
44
45#if 0
46#pragma qt_no_master_include
47#endif
48
49#if QT_CONFIG(vulkan) || defined(Q_CLANG_QDOC)
50
51#include <QtGui/qvulkaninstance.h>
52#include <QtGui/qwindow.h>
53#include <QtGui/qimage.h>
54#include <QtGui/qmatrix4x4.h>
55#include <QtCore/qset.h>
56
57#ifdef Q_CLANG_QDOC
58typedef void* VkQueue;
59typedef void* VkCommandPool;
60typedef void* VkRenderPass;
61typedef void* VkCommandBuffer;
62typedef void* VkFramebuffer;
63typedef int VkPhysicalDeviceProperties;
64typedef int VkFormat;
65typedef int VkQueueFamilyProperties;
66typedef int VkDeviceQueueCreateInfo;
67typedef int VkFormat;
68typedef int VkSampleCountFlagBits;
69#endif
70
71QT_BEGIN_NAMESPACE
72
73class QVulkanWindowPrivate;
74
75class Q_GUI_EXPORT QVulkanWindowRenderer
76{
77public:
78 virtual ~QVulkanWindowRenderer();
79
80 virtual void preInitResources();
81 virtual void initResources();
82 virtual void initSwapChainResources();
83 virtual void releaseSwapChainResources();
84 virtual void releaseResources();
85
86 virtual void startNextFrame() = 0;
87
88 virtual void physicalDeviceLost();
89 virtual void logicalDeviceLost();
90};
91
92class Q_GUI_EXPORT QVulkanWindow : public QWindow
93{
94 Q_OBJECT
95 Q_DECLARE_PRIVATE(QVulkanWindow)
96
97public:
98 enum Flag {
99 PersistentResources = 0x01
100 };
101 Q_DECLARE_FLAGS(Flags, Flag)
102
103 explicit QVulkanWindow(QWindow *parent = nullptr);
104 ~QVulkanWindow();
105
106 void setFlags(Flags flags);
107 Flags flags() const;
108
109 QVector<VkPhysicalDeviceProperties> availablePhysicalDevices();
110 void setPhysicalDeviceIndex(int idx);
111
112 QVulkanInfoVector<QVulkanExtension> supportedDeviceExtensions();
113 void setDeviceExtensions(const QByteArrayList &extensions);
114
115 void setPreferredColorFormats(const QVector<VkFormat> &formats);
116
117 QVector<int> supportedSampleCounts();
118 void setSampleCount(int sampleCount);
119
120 typedef std::function<void(const VkQueueFamilyProperties *,
121 uint32_t,
122 QVector<VkDeviceQueueCreateInfo> &)> QueueCreateInfoModifier;
123 void setQueueCreateInfoModifier(const QueueCreateInfoModifier &modifier);
124
125 bool isValid() const;
126
127 virtual QVulkanWindowRenderer *createRenderer();
128 void frameReady();
129
130 VkPhysicalDevice physicalDevice() const;
131 const VkPhysicalDeviceProperties *physicalDeviceProperties() const;
132 VkDevice device() const;
133 VkQueue graphicsQueue() const;
134 uint32_t graphicsQueueFamilyIndex() const;
135 VkCommandPool graphicsCommandPool() const;
136 uint32_t hostVisibleMemoryIndex() const;
137 uint32_t deviceLocalMemoryIndex() const;
138 VkRenderPass defaultRenderPass() const;
139
140 VkFormat colorFormat() const;
141 VkFormat depthStencilFormat() const;
142 QSize swapChainImageSize() const;
143
144 VkCommandBuffer currentCommandBuffer() const;
145 VkFramebuffer currentFramebuffer() const;
146 int currentFrame() const;
147
148 static const int MAX_CONCURRENT_FRAME_COUNT = 3;
149 int concurrentFrameCount() const;
150
151 int swapChainImageCount() const;
152 int currentSwapChainImageIndex() const;
153 VkImage swapChainImage(int idx) const;
154 VkImageView swapChainImageView(int idx) const;
155 VkImage depthStencilImage() const;
156 VkImageView depthStencilImageView() const;
157
158 VkSampleCountFlagBits sampleCountFlagBits() const;
159 VkImage msaaColorImage(int idx) const;
160 VkImageView msaaColorImageView(int idx) const;
161
162 bool supportsGrab() const;
163 QImage grab();
164
165 QMatrix4x4 clipCorrectionMatrix();
166
167Q_SIGNALS:
168 void frameGrabbed(const QImage &image);
169
170protected:
171 void exposeEvent(QExposeEvent *) override;
172 void resizeEvent(QResizeEvent *) override;
173 bool event(QEvent *) override;
174
175private:
176 Q_DISABLE_COPY(QVulkanWindow)
177};
178
179Q_DECLARE_OPERATORS_FOR_FLAGS(QVulkanWindow::Flags)
180
181QT_END_NAMESPACE
182
183#endif // QT_CONFIG(vulkan)
184
185#endif
186

source code of qtbase/src/gui/vulkan/qvulkanwindow.h