From 84491e555134ee7a5ae0d8cfec4b2e7a0cfe56cc Mon Sep 17 00:00:00 2001 From: JiDe Zhang Date: Sun, 1 May 2022 22:55:58 +0800 Subject: [PATCH] Export the QVulkanInstancePrivate class When needs by the QVulkanInstance::setVkInstance to use a existing VkInstance to a QQuickWindow, the VkInstance maybe is from a non Qt render system, in the case, the QPlatformVulkanInstance object of QVulkanInstance is can't create from the QPA, the all vulkan information is need get from the VkInstance owner(eg, getInstanceProcAddr). But providing it with a public interface is not a good idea, so by exporting a private class, you can use a private interface where needed to achieve the above purpose. Task-number: QTBUG-103021 Change-Id: I0312adcf55cfd7d49889ed112ab237c0b3ab3ef6 Reviewed-by: Laszlo Agocs --- src/gui/CMakeLists.txt | 2 +- src/gui/vulkan/qvulkaninstance.cpp | 29 +-------- src/gui/vulkan/qvulkaninstance.h | 1 + src/gui/vulkan/qvulkaninstance_p.h | 95 ++++++++++++++++++++++++++++++ 4 files changed, 98 insertions(+), 29 deletions(-) create mode 100644 src/gui/vulkan/qvulkaninstance_p.h diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index e9a07f124ef..b1795842f43 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -880,7 +880,7 @@ qt_internal_extend_target(Gui CONDITION QT_FEATURE_vulkan vulkan/qplatformvulkaninstance.cpp vulkan/qplatformvulkaninstance.h vulkan/qvulkandefaultinstance.cpp vulkan/qvulkandefaultinstance_p.h vulkan/qvulkanfunctions.cpp - vulkan/qvulkaninstance.cpp vulkan/qvulkaninstance.h + vulkan/qvulkaninstance.cpp vulkan/qvulkaninstance.h vulkan/qvulkaninstance_p.h vulkan/qvulkanwindow.cpp vulkan/qvulkanwindow.h vulkan/qvulkanwindow_p.h ) if(QT_FEATURE_vulkan) diff --git a/src/gui/vulkan/qvulkaninstance.cpp b/src/gui/vulkan/qvulkaninstance.cpp index aaa86912733..05353e36c24 100644 --- a/src/gui/vulkan/qvulkaninstance.cpp +++ b/src/gui/vulkan/qvulkaninstance.cpp @@ -37,8 +37,7 @@ ** ****************************************************************************/ -#include "qvulkaninstance.h" -#include +#include "qvulkaninstance_p.h" #include #include #include @@ -245,32 +244,6 @@ QT_BEGIN_NAMESPACE \value NoDebugOutputRedirect Disables Vulkan debug output (\c{VK_EXT_debug_report}) redirection to qDebug. */ -class QVulkanInstancePrivate -{ -public: - QVulkanInstancePrivate(QVulkanInstance *q) - : q_ptr(q), - vkInst(VK_NULL_HANDLE), - errorCode(VK_SUCCESS) - { } - ~QVulkanInstancePrivate() { reset(); } - - bool ensureVulkan(); - void reset(); - - QVulkanInstance *q_ptr; - QScopedPointer platformInst; - VkInstance vkInst; - QVulkanInstance::Flags flags; - QByteArrayList layers; - QByteArrayList extensions; - QVersionNumber apiVersion; - VkResult errorCode; - QScopedPointer funcs; - QHash deviceFuncs; - QList debugFilters; -}; - bool QVulkanInstancePrivate::ensureVulkan() { if (!platformInst) { diff --git a/src/gui/vulkan/qvulkaninstance.h b/src/gui/vulkan/qvulkaninstance.h index bfdaf1ab691..156d6cebfcc 100644 --- a/src/gui/vulkan/qvulkaninstance.h +++ b/src/gui/vulkan/qvulkaninstance.h @@ -223,6 +223,7 @@ public: void removeDebugOutputFilter(DebugFilter filter); private: + friend class QVulkanInstancePrivate; QScopedPointer d_ptr; Q_DISABLE_COPY(QVulkanInstance) }; diff --git a/src/gui/vulkan/qvulkaninstance_p.h b/src/gui/vulkan/qvulkaninstance_p.h new file mode 100644 index 00000000000..c52677da370 --- /dev/null +++ b/src/gui/vulkan/qvulkaninstance_p.h @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2022 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QVULKANINSTANCE_P_H +#define QVULKANINSTANCE_P_H + +#include + +#if QT_CONFIG(vulkan) || defined(Q_CLANG_QDOC) + +#include "qvulkaninstance.h" +#include +#include + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of a number of Qt sources files. This header file may change from +// version to version without notice, or even be removed. +// +// We mean it. +// + +QT_BEGIN_NAMESPACE + +class Q_GUI_EXPORT QVulkanInstancePrivate +{ +public: + QVulkanInstancePrivate(QVulkanInstance *q) + : q_ptr(q), + vkInst(VK_NULL_HANDLE), + errorCode(VK_SUCCESS) + { } + ~QVulkanInstancePrivate() { reset(); } + static QVulkanInstancePrivate *get(QVulkanInstance *q) { return q->d_ptr.data(); } + + bool ensureVulkan(); + void reset(); + + QVulkanInstance *q_ptr; + QScopedPointer platformInst; + VkInstance vkInst; + QVulkanInstance::Flags flags; + QByteArrayList layers; + QByteArrayList extensions; + QVersionNumber apiVersion; + VkResult errorCode; + QScopedPointer funcs; + QHash deviceFuncs; + QList debugFilters; +}; + +QT_END_NAMESPACE + +#endif // QT_CONFIG(vulkan) + +#endif // QVULKANINSTANCE_P_H