Commit 986d09df by Tibor den Ouden Committed by Geoff Lang

Improved performance of RefCountObject

Drop virtual specifier on addRef() and release(). There are no derived classes which re-implement these functions. Inlined implementation of constructor and destructor. Destructor is still virtual, but empty implementation is now visible for derived classes. Destructor is now protected to make sure that object is destructed through release(). BUG=angleproject:1263 Change-Id: I744430c1d99b917f3d7b63d47305d937be323ee7 Reviewed-on: https://chromium-review.googlesource.com/320861 Tryjob-Request: Tibor Ouden, den <tibordenouden@gmail.com> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 67d81044
//
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// RefCountObject.cpp: Defines the gl::RefCountObject base class that provides
// lifecycle support for GL objects using the traditional BindObject scheme, but
// that need to be reference counted for correct cross-context deletion.
// (Concretely, textures, buffers and renderbuffers.)
#include "RefCountObject.h"
RefCountObject::RefCountObject(GLuint id)
: mId(id),
mRefCount(0)
{
}
RefCountObject::~RefCountObject()
{
ASSERT(mRefCount == 0);
}
void RefCountObject::addRef() const
{
mRefCount++;
}
void RefCountObject::release() const
{
ASSERT(mRefCount > 0);
if (--mRefCount == 0)
{
delete this;
}
}
...@@ -21,16 +21,27 @@ ...@@ -21,16 +21,27 @@
class RefCountObject : angle::NonCopyable class RefCountObject : angle::NonCopyable
{ {
public: public:
explicit RefCountObject(GLuint id); explicit RefCountObject(GLuint id) : mId(id), mRefCount(0) {}
virtual ~RefCountObject();
virtual void addRef() const; void addRef() const { ++mRefCount; }
virtual void release() const;
void release() const
{
ASSERT(mRefCount > 0);
if (--mRefCount == 0)
{
delete this;
}
}
GLuint id() const { return mId; } GLuint id() const { return mId; }
size_t getRefCount() const { return mRefCount; } size_t getRefCount() const { return mRefCount; }
protected:
virtual ~RefCountObject() { ASSERT(mRefCount == 0); }
private: private:
GLuint mId; GLuint mId;
......
...@@ -98,7 +98,6 @@ ...@@ -98,7 +98,6 @@
'libANGLE/Program.h', 'libANGLE/Program.h',
'libANGLE/Query.cpp', 'libANGLE/Query.cpp',
'libANGLE/Query.h', 'libANGLE/Query.h',
'libANGLE/RefCountObject.cpp',
'libANGLE/RefCountObject.h', 'libANGLE/RefCountObject.h',
'libANGLE/Renderbuffer.cpp', 'libANGLE/Renderbuffer.cpp',
'libANGLE/Renderbuffer.h', 'libANGLE/Renderbuffer.h',
......
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