Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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 //
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.)
13 #include "RefCountObject.h"
15 RefCountObject::RefCountObject(GLuint id)
16 {
17 mId = id;
18 mRefCount = 0;
19 }
21 RefCountObject::~RefCountObject()
22 {
23 ASSERT(mRefCount == 0);
24 }
26 void RefCountObject::addRef() const
27 {
28 mRefCount++;
29 }
31 void RefCountObject::release() const
32 {
33 ASSERT(mRefCount > 0);
35 if (--mRefCount == 0)
36 {
37 delete this;
38 }
39 }
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();
47 mObject = newObject;
48 }