diff options
Diffstat (limited to 'src/3rdparty/angle/src/libANGLE/RefCountObject.h')
-rw-r--r-- | src/3rdparty/angle/src/libANGLE/RefCountObject.h | 88 |
1 files changed, 68 insertions, 20 deletions
diff --git a/src/3rdparty/angle/src/libANGLE/RefCountObject.h b/src/3rdparty/angle/src/libANGLE/RefCountObject.h index 86e6d788b5..cb41cc27f4 100644 --- a/src/3rdparty/angle/src/libANGLE/RefCountObject.h +++ b/src/3rdparty/angle/src/libANGLE/RefCountObject.h @@ -12,16 +12,21 @@ #ifndef LIBANGLE_REFCOUNTOBJECT_H_ #define LIBANGLE_REFCOUNTOBJECT_H_ -#include "common/debug.h" - #include "angle_gl.h" +#include "common/debug.h" +#include "libANGLE/Error.h" #include <cstddef> -class RefCountObject : angle::NonCopyable +namespace gl +{ +class Context; + +class RefCountObjectNoID : angle::NonCopyable { public: - explicit RefCountObject(GLuint id) : mId(id), mRefCount(0) {} + RefCountObjectNoID() : mRefCount(0) {} + virtual Error onDestroy(const Context *context); void addRef() const { ++mRefCount; } @@ -35,17 +40,56 @@ class RefCountObject : angle::NonCopyable } } + size_t getRefCount() const { return mRefCount; } + + protected: + virtual ~RefCountObjectNoID(); + + // A specialized release method for objects which need a destroy context. + void release(const gl::Context *context) + { + ASSERT(mRefCount > 0); + if (--mRefCount == 0) + { + ANGLE_SWALLOW_ERR(onDestroy(context)); + delete this; + } + } + + template <class ObjectType> + friend class BindingPointer; + mutable std::size_t mRefCount; +}; + +inline RefCountObjectNoID::~RefCountObjectNoID() +{ + ASSERT(mRefCount == 0); +} + +inline Error RefCountObjectNoID::onDestroy(const Context *context) +{ + return NoError(); +} + +template <class ObjectType> +class BindingPointer; + +class RefCountObject : RefCountObjectNoID +{ + public: + explicit RefCountObject(GLuint id) : mId(id) {} + GLuint id() const { return mId; } - size_t getRefCount() const { return mRefCount; } + using RefCountObjectNoID::release; + using RefCountObjectNoID::addRef; + using RefCountObjectNoID::getRefCount; protected: - virtual ~RefCountObject() { ASSERT(mRefCount == 0); } + ~RefCountObject() override {} private: GLuint mId; - - mutable std::size_t mRefCount; }; template <class ObjectType> @@ -57,15 +101,17 @@ class BindingPointer { } - BindingPointer(const BindingPointer<ObjectType> &other) - : mObject(nullptr) + BindingPointer(ObjectType *object) : mObject(object) { mObject->addRef(); } + + BindingPointer(const BindingPointer<ObjectType> &other) : mObject(other.mObject) { - set(other.mObject); + mObject->addRef(); } - void operator=(const BindingPointer<ObjectType> &other) + BindingPointer &operator=(BindingPointer<ObjectType> &&other) { - set(other.mObject); + std::swap(mObject, other.mObject); + return *this; } virtual ~BindingPointer() @@ -74,11 +120,12 @@ class BindingPointer ASSERT(mObject == nullptr); } - virtual void set(ObjectType *newObject) + virtual void set(const Context *context, ObjectType *newObject) { // addRef first in case newObject == mObject and this is the last reference to it. - if (newObject != nullptr) reinterpret_cast<const RefCountObject*>(newObject)->addRef(); - if (mObject != nullptr) reinterpret_cast<const RefCountObject*>(mObject)->release(); + if (newObject != nullptr) reinterpret_cast<const RefCountObjectNoID*>(newObject)->addRef(); + if (mObject != nullptr) + reinterpret_cast<RefCountObjectNoID *>(mObject)->release(context); mObject = newObject; } @@ -104,16 +151,16 @@ class OffsetBindingPointer : public BindingPointer<ObjectType> public: OffsetBindingPointer() : mOffset(0), mSize(0) { } - void set(ObjectType *newObject) override + void set(const Context *context, ObjectType *newObject) override { - BindingPointer<ObjectType>::set(newObject); + BindingPointer<ObjectType>::set(context, newObject); mOffset = 0; mSize = 0; } - void set(ObjectType *newObject, GLintptr offset, GLsizeiptr size) + void set(const Context *context, ObjectType *newObject, GLintptr offset, GLsizeiptr size) { - BindingPointer<ObjectType>::set(newObject); + BindingPointer<ObjectType>::set(context, newObject); mOffset = offset; mSize = size; } @@ -135,5 +182,6 @@ class OffsetBindingPointer : public BindingPointer<ObjectType> GLintptr mOffset; GLsizeiptr mSize; }; +} // namespace gl #endif // LIBANGLE_REFCOUNTOBJECT_H_ |