| 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 | #pragma qt_sync_skip_header_check | 
|---|
| 48 | #endif | 
|---|
| 49 |  | 
|---|
| 50 | #if QT_CONFIG(vulkan) || defined(Q_CLANG_QDOC) | 
|---|
| 51 |  | 
|---|
| 52 | #include <QtGui/qvulkaninstance.h> | 
|---|
| 53 | #include <QtGui/qwindow.h> | 
|---|
| 54 | #include <QtGui/qimage.h> | 
|---|
| 55 | #include <QtGui/qmatrix4x4.h> | 
|---|
| 56 | #include <QtCore/qset.h> | 
|---|
| 57 |  | 
|---|
| 58 | #ifdef Q_CLANG_QDOC | 
|---|
| 59 | typedef void* VkQueue; | 
|---|
| 60 | typedef void* VkCommandPool; | 
|---|
| 61 | typedef void* VkRenderPass; | 
|---|
| 62 | typedef void* VkCommandBuffer; | 
|---|
| 63 | typedef void* VkFramebuffer; | 
|---|
| 64 | typedef int VkPhysicalDeviceProperties; | 
|---|
| 65 | typedef int VkFormat; | 
|---|
| 66 | typedef int VkQueueFamilyProperties; | 
|---|
| 67 | typedef int VkDeviceQueueCreateInfo; | 
|---|
| 68 | typedef int VkFormat; | 
|---|
| 69 | typedef int VkSampleCountFlagBits; | 
|---|
| 70 | #endif | 
|---|
| 71 |  | 
|---|
| 72 | QT_BEGIN_NAMESPACE | 
|---|
| 73 |  | 
|---|
| 74 | class QVulkanWindowPrivate; | 
|---|
| 75 |  | 
|---|
| 76 | class Q_GUI_EXPORT QVulkanWindowRenderer | 
|---|
| 77 | { | 
|---|
| 78 | public: | 
|---|
| 79 | virtual ~QVulkanWindowRenderer(); | 
|---|
| 80 |  | 
|---|
| 81 | virtual void preInitResources(); | 
|---|
| 82 | virtual void initResources(); | 
|---|
| 83 | virtual void initSwapChainResources(); | 
|---|
| 84 | virtual void releaseSwapChainResources(); | 
|---|
| 85 | virtual void releaseResources(); | 
|---|
| 86 |  | 
|---|
| 87 | virtual void startNextFrame() = 0; | 
|---|
| 88 |  | 
|---|
| 89 | virtual void physicalDeviceLost(); | 
|---|
| 90 | virtual void logicalDeviceLost(); | 
|---|
| 91 | }; | 
|---|
| 92 |  | 
|---|
| 93 | class Q_GUI_EXPORT QVulkanWindow : public QWindow | 
|---|
| 94 | { | 
|---|
| 95 | Q_OBJECT | 
|---|
| 96 | Q_DECLARE_PRIVATE(QVulkanWindow) | 
|---|
| 97 |  | 
|---|
| 98 | public: | 
|---|
| 99 | enum Flag { | 
|---|
| 100 | PersistentResources = 0x01 | 
|---|
| 101 | }; | 
|---|
| 102 | Q_DECLARE_FLAGS(Flags, Flag) | 
|---|
| 103 |  | 
|---|
| 104 | explicit QVulkanWindow(QWindow *parent = nullptr); | 
|---|
| 105 | ~QVulkanWindow(); | 
|---|
| 106 |  | 
|---|
| 107 | void setFlags(Flags flags); | 
|---|
| 108 | Flags flags() const; | 
|---|
| 109 |  | 
|---|
| 110 | QList<VkPhysicalDeviceProperties> availablePhysicalDevices(); | 
|---|
| 111 | void setPhysicalDeviceIndex(int idx); | 
|---|
| 112 |  | 
|---|
| 113 | QVulkanInfoVector<QVulkanExtension> supportedDeviceExtensions(); | 
|---|
| 114 | void setDeviceExtensions(const QByteArrayList &extensions); | 
|---|
| 115 |  | 
|---|
| 116 | void setPreferredColorFormats(const QList<VkFormat> &formats); | 
|---|
| 117 |  | 
|---|
| 118 | QList<int> supportedSampleCounts(); | 
|---|
| 119 | void setSampleCount(int sampleCount); | 
|---|
| 120 |  | 
|---|
| 121 | typedef std::function<void(const VkQueueFamilyProperties *, uint32_t, | 
|---|
| 122 | QList<VkDeviceQueueCreateInfo> &)> | 
|---|
| 123 | QueueCreateInfoModifier; | 
|---|
| 124 | void setQueueCreateInfoModifier(const QueueCreateInfoModifier &modifier); | 
|---|
| 125 |  | 
|---|
| 126 | bool isValid() const; | 
|---|
| 127 |  | 
|---|
| 128 | virtual QVulkanWindowRenderer *createRenderer(); | 
|---|
| 129 | void frameReady(); | 
|---|
| 130 |  | 
|---|
| 131 | VkPhysicalDevice physicalDevice() const; | 
|---|
| 132 | const VkPhysicalDeviceProperties *physicalDeviceProperties() const; | 
|---|
| 133 | VkDevice device() const; | 
|---|
| 134 | VkQueue graphicsQueue() const; | 
|---|
| 135 | uint32_t graphicsQueueFamilyIndex() const; | 
|---|
| 136 | VkCommandPool graphicsCommandPool() const; | 
|---|
| 137 | uint32_t hostVisibleMemoryIndex() const; | 
|---|
| 138 | uint32_t deviceLocalMemoryIndex() const; | 
|---|
| 139 | VkRenderPass defaultRenderPass() const; | 
|---|
| 140 |  | 
|---|
| 141 | VkFormat colorFormat() const; | 
|---|
| 142 | VkFormat depthStencilFormat() const; | 
|---|
| 143 | QSize swapChainImageSize() const; | 
|---|
| 144 |  | 
|---|
| 145 | VkCommandBuffer currentCommandBuffer() const; | 
|---|
| 146 | VkFramebuffer currentFramebuffer() const; | 
|---|
| 147 | int currentFrame() const; | 
|---|
| 148 |  | 
|---|
| 149 | static const int MAX_CONCURRENT_FRAME_COUNT = 3; | 
|---|
| 150 | int concurrentFrameCount() const; | 
|---|
| 151 |  | 
|---|
| 152 | int swapChainImageCount() const; | 
|---|
| 153 | int currentSwapChainImageIndex() const; | 
|---|
| 154 | VkImage swapChainImage(int idx) const; | 
|---|
| 155 | VkImageView swapChainImageView(int idx) const; | 
|---|
| 156 | VkImage depthStencilImage() const; | 
|---|
| 157 | VkImageView depthStencilImageView() const; | 
|---|
| 158 |  | 
|---|
| 159 | VkSampleCountFlagBits sampleCountFlagBits() const; | 
|---|
| 160 | VkImage msaaColorImage(int idx) const; | 
|---|
| 161 | VkImageView msaaColorImageView(int idx) const; | 
|---|
| 162 |  | 
|---|
| 163 | bool supportsGrab() const; | 
|---|
| 164 | QImage grab(); | 
|---|
| 165 |  | 
|---|
| 166 | QMatrix4x4 clipCorrectionMatrix(); | 
|---|
| 167 |  | 
|---|
| 168 | Q_SIGNALS: | 
|---|
| 169 | void frameGrabbed(const QImage &image); | 
|---|
| 170 |  | 
|---|
| 171 | protected: | 
|---|
| 172 | void exposeEvent(QExposeEvent *) override; | 
|---|
| 173 | void resizeEvent(QResizeEvent *) override; | 
|---|
| 174 | bool event(QEvent *) override; | 
|---|
| 175 |  | 
|---|
| 176 | private: | 
|---|
| 177 | Q_DISABLE_COPY(QVulkanWindow) | 
|---|
| 178 | }; | 
|---|
| 179 |  | 
|---|
| 180 | Q_DECLARE_OPERATORS_FOR_FLAGS(QVulkanWindow::Flags) | 
|---|
| 181 |  | 
|---|
| 182 | QT_END_NAMESPACE | 
|---|
| 183 |  | 
|---|
| 184 | #endif // QT_CONFIG(vulkan) | 
|---|
| 185 |  | 
|---|
| 186 | #endif | 
|---|
| 187 |  | 
|---|