• 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 
14 namespace gl
15 {
16 
RefCountObject(GLuint id)17 RefCountObject::RefCountObject(GLuint id)
18 {
19     mId = id;
20     mRefCount = 0;
21 }
22 
~RefCountObject()23 RefCountObject::~RefCountObject()
24 {
25     ASSERT(mRefCount == 0);
26 }
27 
addRef() const28 void RefCountObject::addRef() const
29 {
30     mRefCount++;
31 }
32 
release() const33 void RefCountObject::release() const
34 {
35     ASSERT(mRefCount > 0);
36 
37     if (--mRefCount == 0)
38     {
39         delete this;
40     }
41 }
42 
set(RefCountObject * newObject)43 void RefCountObjectBindingPointer::set(RefCountObject *newObject)
44 {
45     // addRef first in case newObject == mObject and this is the last reference to it.
46     if (newObject != NULL) newObject->addRef();
47     if (mObject != NULL) mObject->release();
48 
49     mObject = newObject;
50 }
51 
52 }
53