Bug 704839 - [9/9] - Refactor mutual ownership of WebGL objects - r=jgilbert

This patch removes the old helper classes which we no longer use.
This commit is contained in:
Benoit Jacob 2011-12-04 14:15:43 -05:00
parent a31862a997
commit 1cbd18259d

View File

@ -97,7 +97,6 @@ class WebGLUniformLocation;
class WebGLExtension;
class WebGLVertexAttribData;
template<int PreallocatedOwnersCapacity> class WebGLZeroingObject;
class WebGLContextBoundObject;
enum FakeBlackStatus { DoNotNeedFakeBlack, DoNeedFakeBlack, DontKnowIfNeedFakeBlack };
@ -366,141 +365,6 @@ protected:
T *mRawPtr;
};
class WebGLObjectBaseRefPtr
{
protected:
template<int PreallocatedOwnersCapacity>
friend class WebGLZeroingObject;
WebGLObjectBaseRefPtr()
: mRawPtr(0)
{
}
WebGLObjectBaseRefPtr(nsISupports *rawPtr)
: mRawPtr(rawPtr)
{
}
void Zero() {
if (mRawPtr) {
// Note: RemoveRefOwner isn't called here, because
// the entire owner array will be cleared.
mRawPtr->Release();
mRawPtr = 0;
}
}
protected:
nsISupports *mRawPtr;
};
template <class T>
class WebGLObjectRefPtr
: public WebGLObjectBaseRefPtr
{
public:
typedef T element_type;
WebGLObjectRefPtr()
{ }
WebGLObjectRefPtr(const WebGLObjectRefPtr<T>& aSmartPtr)
: WebGLObjectBaseRefPtr(aSmartPtr.mRawPtr)
{
if (mRawPtr) {
RawPtr()->AddRef();
RawPtr()->AddRefOwner(this);
}
}
WebGLObjectRefPtr(T *aRawPtr)
: WebGLObjectBaseRefPtr(aRawPtr)
{
if (mRawPtr) {
RawPtr()->AddRef();
RawPtr()->AddRefOwner(this);
}
}
WebGLObjectRefPtr(const already_AddRefed<T>& aSmartPtr)
: WebGLObjectBaseRefPtr(aSmartPtr.mRawPtr)
// construct from |dont_AddRef(expr)|
{
if (mRawPtr) {
RawPtr()->AddRef();
RawPtr()->AddRefOwner(this);
}
}
~WebGLObjectRefPtr() {
if (mRawPtr) {
RawPtr()->RemoveRefOwner(this);
RawPtr()->Release();
}
}
WebGLObjectRefPtr<T>&
operator=(const WebGLObjectRefPtr<T>& rhs)
{
assign_with_AddRef(static_cast<T*>(rhs.mRawPtr));
return *this;
}
WebGLObjectRefPtr<T>&
operator=(T* rhs)
{
assign_with_AddRef(rhs);
return *this;
}
WebGLObjectRefPtr<T>&
operator=(const already_AddRefed<T>& rhs)
{
assign_assuming_AddRef(static_cast<T*>(rhs.mRawPtr));
return *this;
}
T* get() const {
return const_cast<T*>(static_cast<T*>(mRawPtr));
}
operator T*() const {
return get();
}
T* operator->() const {
NS_PRECONDITION(mRawPtr != 0, "You can't dereference a NULL WebGLObjectRefPtr with operator->()!");
return get();
}
T& operator*() const {
NS_PRECONDITION(mRawPtr != 0, "You can't dereference a NULL WebGLObjectRefPtr with operator*()!");
return *get();
}
private:
T* RawPtr() { return static_cast<T*>(mRawPtr); }
void assign_with_AddRef(T* rawPtr) {
if (rawPtr) {
rawPtr->AddRef();
rawPtr->AddRefOwner(this);
}
assign_assuming_AddRef(rawPtr);
}
void assign_assuming_AddRef(T* newPtr) {
T* oldPtr = RawPtr();
mRawPtr = newPtr;
if (oldPtr) {
oldPtr->RemoveRefOwner(this);
oldPtr->Release();
}
}
};
struct WebGLContextOptions {
// these are defaults
WebGLContextOptions()
@ -944,46 +808,6 @@ public:
friend class WebGLShader;
};
// this class is a mixin for the named type wrappers, and is used
// by WebGLObjectRefPtr to tell the object who holds references, so that
// we can zero them out appropriately when the object is deleted, because
// it will be unbound in the GL.
//
// PreallocatedOwnersCapacity is the preallocated capacity for the array of refptrs to owners.
// Having some minimal preallocated capacity is an important optimization, see bug 522193. In this
// bug, a benchmark was using WebGLBuffer with a number of owners oscillating between 0 and 2.
// At this time mRefOwners was a nsTArray, and the too frequent reallocations were slowing us down.
template<int PreallocatedOwnersCapacity>
class WebGLZeroingObject
{
public:
WebGLZeroingObject()
{ }
void AddRefOwner(WebGLObjectBaseRefPtr *owner) {
mRefOwners.AppendElement(owner);
}
void RemoveRefOwner(WebGLObjectBaseRefPtr *owner) {
mRefOwners.RemoveElement(owner);
}
void ZeroOwners() {
WebGLObjectBaseRefPtr **owners = mRefOwners.Elements();
for (PRUint32 i = 0; i < mRefOwners.Length(); i++) {
owners[i]->Zero();
}
mRefOwners.Clear();
}
protected:
nsAutoTArray<WebGLObjectBaseRefPtr *, PreallocatedOwnersCapacity> mRefOwners;
friend class WebGLShader;
friend class WebGLBuffer;
};
// this class is a mixin for GL objects that have dimensions
// that we need to track.
class WebGLRectangleObject