mirror of
https://github.com/doitsujin/dxvk.git
synced 2024-11-30 13:24:10 +01:00
[util] Add support for private references in Com<...> wrapper
This commit is contained in:
parent
54d3103b04
commit
61b97e5dd1
@ -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<typename T>
|
||||
T* ref(T* object) {
|
||||
if (object != nullptr)
|
||||
object->AddRef();
|
||||
return object;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief COM pointer
|
||||
*
|
||||
* Implements automatic reference
|
||||
* counting for COM objects.
|
||||
*/
|
||||
template<typename T>
|
||||
template<typename T, bool Public = true>
|
||||
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)
|
||||
if (m_ptr != nullptr) {
|
||||
if constexpr (Public)
|
||||
m_ptr->AddRef();
|
||||
else
|
||||
m_ptr->AddRefPrivate();
|
||||
}
|
||||
}
|
||||
|
||||
void decRef() const {
|
||||
if (m_ptr != nullptr)
|
||||
if (m_ptr != nullptr) {
|
||||
if constexpr (Public)
|
||||
m_ptr->Release();
|
||||
else
|
||||
m_ptr->ReleasePrivate();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
T* ref(T* object) {
|
||||
if (object != nullptr)
|
||||
object->AddRef();
|
||||
return object;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user