Bug 994081 - [1/3] Make VolatileBufferPtrs more flexible, r=glandium

This commit is contained in:
Michael Wu 2014-04-18 12:26:49 -04:00
parent aff06146d3
commit 46a592e4f4

View File

@ -79,18 +79,11 @@ private:
class VolatileBufferPtr_base {
public:
explicit VolatileBufferPtr_base(VolatileBuffer* vbuf) : mVBuf(vbuf) {
if (vbuf) {
mPurged = !vbuf->Lock(&mMapping);
} else {
mMapping = nullptr;
mPurged = false;
}
Lock();
}
~VolatileBufferPtr_base() {
if (mVBuf) {
mVBuf->Unlock();
}
Unlock();
}
bool WasBufferPurged() const {
@ -100,9 +93,30 @@ public:
protected:
void* mMapping;
void Set(VolatileBuffer* vbuf) {
Unlock();
mVBuf = vbuf;
Lock();
}
private:
RefPtr<VolatileBuffer> mVBuf;
bool mPurged;
void Lock() {
if (mVBuf) {
mPurged = !mVBuf->Lock(&mMapping);
} else {
mMapping = nullptr;
mPurged = false;
}
}
void Unlock() {
if (mVBuf) {
mVBuf->Unlock();
}
}
};
template <class T>
@ -110,10 +124,17 @@ class VolatileBufferPtr : public VolatileBufferPtr_base
{
public:
explicit VolatileBufferPtr(VolatileBuffer* vbuf) : VolatileBufferPtr_base(vbuf) {}
VolatileBufferPtr() : VolatileBufferPtr_base(nullptr) {}
operator T*() const {
return (T*) mMapping;
}
void operator =(VolatileBuffer* vbuf) {
Set(vbuf);
}
private:
VolatileBufferPtr(VolatileBufferPtr const& vbufptr) MOZ_DELETE;
};
}; /* namespace mozilla */