From 61b97e5dd1118bcad10c94748162fb9c564e5ebc Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Tue, 14 May 2019 14:52:22 +0200 Subject: [PATCH] [util] Add support for private references in Com<...> wrapper --- src/util/com/com_pointer.h | 43 +++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/src/util/com/com_pointer.h b/src/util/com/com_pointer.h index 254f05bc..2c91c03a 100644 --- a/src/util/com/com_pointer.h +++ b/src/util/com/com_pointer.h @@ -4,13 +4,28 @@ namespace dxvk { + /** + * \brief Increment public ref count + * + * If the pointer is not \c nullptr, this + * calls \c AddRef for the given object. + * \returns Pointer to the object + */ + template + T* ref(T* object) { + if (object != nullptr) + object->AddRef(); + return object; + } + + /** * \brief COM pointer * * Implements automatic reference * counting for COM objects. */ - template + template class Com { public: @@ -80,8 +95,7 @@ namespace dxvk { bool operator != (std::nullptr_t) const { return m_ptr != nullptr; } T* ref() const { - this->incRef(); - return m_ptr; + return dxvk::ref(m_ptr); } T* ptr() const { @@ -93,22 +107,23 @@ namespace dxvk { T* m_ptr = nullptr; void incRef() const { - if (m_ptr != nullptr) - m_ptr->AddRef(); + if (m_ptr != nullptr) { + if constexpr (Public) + m_ptr->AddRef(); + else + m_ptr->AddRefPrivate(); + } } void decRef() const { - if (m_ptr != nullptr) - m_ptr->Release(); + if (m_ptr != nullptr) { + if constexpr (Public) + m_ptr->Release(); + else + m_ptr->ReleasePrivate(); + } } }; - template - T* ref(T* object) { - if (object != nullptr) - object->AddRef(); - return object; - } - }