gfx/angle/src/common/RefCountObject.cpp

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

mercurial