Commit 1f40291c by Geoff Lang

Remove the non-templated RefCountObjectBindingPointer class.

This allows the regular BindingPointer class to template on const types. Also added assignment and copy operators that don't leak the resources. BUG=angleproject:880 Change-Id: If3efa26a7fa89306d783c3e8a5fb92b16861d77a Reviewed-on: https://chromium-review.googlesource.com/257670Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 6341939f
...@@ -37,11 +37,3 @@ void RefCountObject::release() const ...@@ -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;
}
...@@ -28,55 +28,73 @@ class RefCountObject ...@@ -28,55 +28,73 @@ class RefCountObject
virtual void release() const; virtual void release() const;
GLuint id() const { return mId; } GLuint id() const { return mId; }
private: private:
GLuint mId; GLuint mId;
mutable std::size_t mRefCount; mutable std::size_t mRefCount;
}; };
class RefCountObjectBindingPointer template <class ObjectType>
class BindingPointer
{ {
protected: public:
RefCountObjectBindingPointer() : mObject(NULL) { } BindingPointer()
~RefCountObjectBindingPointer() { ASSERT(mObject == NULL); } // Objects have to be released before the resource manager is destroyed, so they must be explicitly cleaned up. : mObject(nullptr)
{
}
void set(RefCountObject *newObject); BindingPointer(const BindingPointer<ObjectType> &other)
RefCountObject *get() const { return mObject; } : mObject(nullptr)
{
set(other.mObject);
}
public: void operator=(const BindingPointer<ObjectType> &other)
GLuint id() const { return (mObject != NULL) ? mObject->id() : 0; } {
bool operator!() const { return (get() == NULL); } set(other.mObject);
}
private: virtual ~BindingPointer()
RefCountObject *mObject; {
}; // Objects have to be released before the resource manager is destroyed, so they must be explicitly cleaned up.
ASSERT(mObject == nullptr);
}
template <class ObjectType> virtual void set(ObjectType *newObject)
class BindingPointer : public RefCountObjectBindingPointer {
{ // addRef first in case newObject == mObject and this is the last reference to it.
public: if (newObject != nullptr) reinterpret_cast<const RefCountObject*>(newObject)->addRef();
void set(ObjectType *newObject) { RefCountObjectBindingPointer::set(newObject); } if (mObject != nullptr) reinterpret_cast<const RefCountObject*>(mObject)->release();
ObjectType *get() const { return static_cast<ObjectType*>(RefCountObjectBindingPointer::get()); } mObject = newObject;
ObjectType *operator->() const { return get(); } }
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:
ObjectType *mObject;
}; };
template <class ObjectType> template <class ObjectType>
class OffsetBindingPointer : public RefCountObjectBindingPointer class OffsetBindingPointer : public BindingPointer<ObjectType>
{ {
public: public:
OffsetBindingPointer() : mOffset(0), mSize(0) { } OffsetBindingPointer() : mOffset(0), mSize(0) { }
void set(ObjectType *newObject) void set(ObjectType *newObject) override
{ {
RefCountObjectBindingPointer::set(newObject); BindingPointer<ObjectType>::set(newObject);
mOffset = 0; mOffset = 0;
mSize = 0; mSize = 0;
} }
void set(ObjectType *newObject, GLintptr offset, GLsizeiptr size) void set(ObjectType *newObject, GLintptr offset, GLsizeiptr size)
{ {
RefCountObjectBindingPointer::set(newObject); BindingPointer<ObjectType>::set(newObject);
mOffset = offset; mOffset = offset;
mSize = size; mSize = size;
} }
...@@ -84,9 +102,6 @@ class OffsetBindingPointer : public RefCountObjectBindingPointer ...@@ -84,9 +102,6 @@ class OffsetBindingPointer : public RefCountObjectBindingPointer
GLintptr getOffset() const { return mOffset; } GLintptr getOffset() const { return mOffset; }
GLsizeiptr getSize() const { return mSize; } GLsizeiptr getSize() const { return mSize; }
ObjectType *get() const { return static_cast<ObjectType*>(RefCountObjectBindingPointer::get()); }
ObjectType *operator->() const { return get(); }
private: private:
GLintptr mOffset; GLintptr mOffset;
GLsizeiptr mSize; GLsizeiptr mSize;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment