1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/angle/src/common/RefCountObject.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,48 @@ 1.4 +#include "precompiled.h" 1.5 +// 1.6 +// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved. 1.7 +// Use of this source code is governed by a BSD-style license that can be 1.8 +// found in the LICENSE file. 1.9 +// 1.10 + 1.11 +// RefCountObject.cpp: Defines the gl::RefCountObject base class that provides 1.12 +// lifecycle support for GL objects using the traditional BindObject scheme, but 1.13 +// that need to be reference counted for correct cross-context deletion. 1.14 +// (Concretely, textures, buffers and renderbuffers.) 1.15 + 1.16 +#include "RefCountObject.h" 1.17 + 1.18 +RefCountObject::RefCountObject(GLuint id) 1.19 +{ 1.20 + mId = id; 1.21 + mRefCount = 0; 1.22 +} 1.23 + 1.24 +RefCountObject::~RefCountObject() 1.25 +{ 1.26 + ASSERT(mRefCount == 0); 1.27 +} 1.28 + 1.29 +void RefCountObject::addRef() const 1.30 +{ 1.31 + mRefCount++; 1.32 +} 1.33 + 1.34 +void RefCountObject::release() const 1.35 +{ 1.36 + ASSERT(mRefCount > 0); 1.37 + 1.38 + if (--mRefCount == 0) 1.39 + { 1.40 + delete this; 1.41 + } 1.42 +} 1.43 + 1.44 +void RefCountObjectBindingPointer::set(RefCountObject *newObject) 1.45 +{ 1.46 + // addRef first in case newObject == mObject and this is the last reference to it. 1.47 + if (newObject != NULL) newObject->addRef(); 1.48 + if (mObject != NULL) mObject->release(); 1.49 + 1.50 + mObject = newObject; 1.51 +}