Home | History | Annotate | Download | only in libGLESv2
      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 
     14 namespace gl
     15 {
     16 
     17 RefCountObject::RefCountObject(GLuint id)
     18 {
     19     mId = id;
     20     mRefCount = 0;
     21 }
     22 
     23 RefCountObject::~RefCountObject()
     24 {
     25     ASSERT(mRefCount == 0);
     26 }
     27 
     28 void RefCountObject::addRef() const
     29 {
     30     mRefCount++;
     31 }
     32 
     33 void RefCountObject::release() const
     34 {
     35     ASSERT(mRefCount > 0);
     36 
     37     if (--mRefCount == 0)
     38     {
     39         delete this;
     40     }
     41 }
     42 
     43 void 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 }
     53