diff --git a/src/libANGLE/RefCountObject.cpp b/src/libANGLE/RefCountObject.cpp index c1ef90cdc..401feb646 100644 --- a/src/libANGLE/RefCountObject.cpp +++ b/src/libANGLE/RefCountObject.cpp @@ -37,11 +37,3 @@ void RefCountObject::release() const } } -void RefCountObjectBindingPointer::set(RefCountObject *newObject) -{ - // addRef first in case newObject == mObject and this is the last reference to it. - if (newObject != NULL) newObject->addRef(); - if (mObject != NULL) mObject->release(); - - mObject = newObject; -} diff --git a/src/libANGLE/RefCountObject.h b/src/libANGLE/RefCountObject.h index 39c0e229c..835df4cc8 100644 --- a/src/libANGLE/RefCountObject.h +++ b/src/libANGLE/RefCountObject.h @@ -28,55 +28,73 @@ class RefCountObject virtual void release() const; GLuint id() const { return mId; } - + private: GLuint mId; mutable std::size_t mRefCount; }; -class RefCountObjectBindingPointer +template +class BindingPointer { - protected: - RefCountObjectBindingPointer() : mObject(NULL) { } - ~RefCountObjectBindingPointer() { ASSERT(mObject == NULL); } // Objects have to be released before the resource manager is destroyed, so they must be explicitly cleaned up. +public: + BindingPointer() + : mObject(nullptr) + { + } - void set(RefCountObject *newObject); - RefCountObject *get() const { return mObject; } + BindingPointer(const BindingPointer &other) + : mObject(nullptr) + { + set(other.mObject); + } - public: - GLuint id() const { return (mObject != NULL) ? mObject->id() : 0; } - bool operator!() const { return (get() == NULL); } + void operator=(const BindingPointer &other) + { + set(other.mObject); + } + + virtual ~BindingPointer() + { + // Objects have to be released before the resource manager is destroyed, so they must be explicitly cleaned up. + ASSERT(mObject == nullptr); + } + + virtual void set(ObjectType *newObject) + { + // addRef first in case newObject == mObject and this is the last reference to it. + if (newObject != nullptr) reinterpret_cast(newObject)->addRef(); + if (mObject != nullptr) reinterpret_cast(mObject)->release(); + mObject = newObject; + } + + ObjectType *get() const { return mObject; } + ObjectType *operator->() const { return mObject; } + + GLuint id() const { return (mObject != nullptr) ? mObject->id() : 0; } + bool operator!() const { return (mObject == nullptr); } private: - RefCountObject *mObject; + ObjectType *mObject; }; template -class BindingPointer : public RefCountObjectBindingPointer -{ - public: - void set(ObjectType *newObject) { RefCountObjectBindingPointer::set(newObject); } - ObjectType *get() const { return static_cast(RefCountObjectBindingPointer::get()); } - ObjectType *operator->() const { return get(); } -}; - -template -class OffsetBindingPointer : public RefCountObjectBindingPointer +class OffsetBindingPointer : public BindingPointer { public: OffsetBindingPointer() : mOffset(0), mSize(0) { } - void set(ObjectType *newObject) + void set(ObjectType *newObject) override { - RefCountObjectBindingPointer::set(newObject); + BindingPointer::set(newObject); mOffset = 0; mSize = 0; } void set(ObjectType *newObject, GLintptr offset, GLsizeiptr size) { - RefCountObjectBindingPointer::set(newObject); + BindingPointer::set(newObject); mOffset = offset; mSize = size; } @@ -84,9 +102,6 @@ class OffsetBindingPointer : public RefCountObjectBindingPointer GLintptr getOffset() const { return mOffset; } GLsizeiptr getSize() const { return mSize; } - ObjectType *get() const { return static_cast(RefCountObjectBindingPointer::get()); } - ObjectType *operator->() const { return get(); } - private: GLintptr mOffset; GLsizeiptr mSize;