blob: c1ef90cdccc26095ffe51830316a182df126fe76 [file] [log] [blame]
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +00001//
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.com9ecb9f92010-07-28 19:21:12 +000014RefCountObject::RefCountObject(GLuint id)
15{
16 mId = id;
17 mRefCount = 0;
18}
19
20RefCountObject::~RefCountObject()
21{
apatrick@chromium.org8d012df2010-09-15 18:26:44 +000022 ASSERT(mRefCount == 0);
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000023}
24
25void RefCountObject::addRef() const
26{
27 mRefCount++;
28}
29
30void RefCountObject::release() const
31{
32 ASSERT(mRefCount > 0);
33
34 if (--mRefCount == 0)
35 {
36 delete this;
37 }
38}
39
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000040void 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}