1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/angle/src/common/RefCountObject.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,65 @@ 1.4 +// 1.5 +// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved. 1.6 +// Use of this source code is governed by a BSD-style license that can be 1.7 +// found in the LICENSE file. 1.8 +// 1.9 + 1.10 +// RefCountObject.h: Defines the gl::RefCountObject base class that provides 1.11 +// lifecycle support for GL objects using the traditional BindObject scheme, but 1.12 +// that need to be reference counted for correct cross-context deletion. 1.13 +// (Concretely, textures, buffers and renderbuffers.) 1.14 + 1.15 +#ifndef COMMON_REFCOUNTOBJECT_H_ 1.16 +#define COMMON_REFCOUNTOBJECT_H_ 1.17 + 1.18 +#include <cstddef> 1.19 + 1.20 +#define GL_APICALL 1.21 +#include <GLES2/gl2.h> 1.22 + 1.23 +#include "common/debug.h" 1.24 + 1.25 +class RefCountObject 1.26 +{ 1.27 + public: 1.28 + explicit RefCountObject(GLuint id); 1.29 + virtual ~RefCountObject(); 1.30 + 1.31 + virtual void addRef() const; 1.32 + virtual void release() const; 1.33 + 1.34 + GLuint id() const { return mId; } 1.35 + 1.36 + private: 1.37 + GLuint mId; 1.38 + 1.39 + mutable std::size_t mRefCount; 1.40 +}; 1.41 + 1.42 +class RefCountObjectBindingPointer 1.43 +{ 1.44 + protected: 1.45 + RefCountObjectBindingPointer() : mObject(NULL) { } 1.46 + ~RefCountObjectBindingPointer() { ASSERT(mObject == NULL); } // Objects have to be released before the resource manager is destroyed, so they must be explicitly cleaned up. 1.47 + 1.48 + void set(RefCountObject *newObject); 1.49 + RefCountObject *get() const { return mObject; } 1.50 + 1.51 + public: 1.52 + GLuint id() const { return (mObject != NULL) ? mObject->id() : 0; } 1.53 + bool operator ! () const { return (get() == NULL); } 1.54 + 1.55 + private: 1.56 + RefCountObject *mObject; 1.57 +}; 1.58 + 1.59 +template <class ObjectType> 1.60 +class BindingPointer : public RefCountObjectBindingPointer 1.61 +{ 1.62 + public: 1.63 + void set(ObjectType *newObject) { RefCountObjectBindingPointer::set(newObject); } 1.64 + ObjectType *get() const { return static_cast<ObjectType*>(RefCountObjectBindingPointer::get()); } 1.65 + ObjectType *operator -> () const { return get(); } 1.66 +}; 1.67 + 1.68 +#endif // COMMON_REFCOUNTOBJECT_H_