• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 // RefCountObject.cpp: Defines the gl::RefCountObject base class that provides
8 // lifecycle support for GL objects using the traditional BindObject scheme, but
9 // that need to be reference counted for correct cross-context deletion.
10 // (Concretely, textures, buffers and renderbuffers.)
11 
12 #include "RefCountObject.h"
13 
RefCountObject(GLuint id)14 RefCountObject::RefCountObject(GLuint id)
15 {
16     mId = id;
17     mRefCount = 0;
18 }
19 
~RefCountObject()20 RefCountObject::~RefCountObject()
21 {
22     ASSERT(mRefCount == 0);
23 }
24 
addRef() const25 void RefCountObject::addRef() const
26 {
27     mRefCount++;
28 }
29 
release() const30 void RefCountObject::release() const
31 {
32     ASSERT(mRefCount > 0);
33 
34     if (--mRefCount == 0)
35     {
36         delete this;
37     }
38 }
39 
set(RefCountObject * newObject)40 void RefCountObjectBindingPointer::set(RefCountObject *newObject)
41 {
42     // addRef first in case newObject == mObject and this is the last reference to it.
43     if (newObject != NULL) newObject->addRef();
44     if (mObject != NULL) mObject->release();
45 
46     mObject = newObject;
47 }
48