blob: 2de1e718db6346ec9a867b6037799e1ecb8d4a46 [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
14namespace gl
15{
16
17RefCountObject::RefCountObject(GLuint id)
18{
19 mId = id;
20 mRefCount = 0;
21}
22
23RefCountObject::~RefCountObject()
24{
apatrick@chromium.org8d012df2010-09-15 18:26:44 +000025 ASSERT(mRefCount == 0);
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000026}
27
28void RefCountObject::addRef() const
29{
30 mRefCount++;
31}
32
33void RefCountObject::release() const
34{
35 ASSERT(mRefCount > 0);
36
37 if (--mRefCount == 0)
38 {
39 delete this;
40 }
41}
42
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000043void 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}