daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 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 | |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 14 | RefCountObject::RefCountObject(GLuint id) |
| 15 | { |
| 16 | mId = id; |
| 17 | mRefCount = 0; |
| 18 | } |
| 19 | |
| 20 | RefCountObject::~RefCountObject() |
| 21 | { |
apatrick@chromium.org | 8d012df | 2010-09-15 18:26:44 +0000 | [diff] [blame] | 22 | ASSERT(mRefCount == 0); |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | void RefCountObject::addRef() const |
| 26 | { |
| 27 | mRefCount++; |
| 28 | } |
| 29 | |
| 30 | void RefCountObject::release() const |
| 31 | { |
| 32 | ASSERT(mRefCount > 0); |
| 33 | |
| 34 | if (--mRefCount == 0) |
| 35 | { |
| 36 | delete this; |
| 37 | } |
| 38 | } |
| 39 | |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 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 | } |