hostsupport/hostegl/inc/EGLUtils.h
branchbug235_bringup_0
changeset 53 c2ef9095503a
child 67 ca7e6949bf7a
equal deleted inserted replaced
52:39e5f73667ba 53:c2ef9095503a
       
     1 /* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     2  *
       
     3  * Permission is hereby granted, free of charge, to any person obtaining a
       
     4  * copy of this software and /or associated documentation files
       
     5  * (the "Materials "), to deal in the Materials without restriction,
       
     6  * including without limitation the rights to use, copy, modify, merge,
       
     7  * publish, distribute, sublicense, and/or sell copies of the Materials,
       
     8  * and to permit persons to whom the Materials are furnished to do so,
       
     9  * subject to the following conditions:
       
    10  *
       
    11  * The above copyright notice and this permission notice shall be included
       
    12  * in all copies or substantial portions of the Materials.
       
    13  *
       
    14  * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
       
    15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
       
    16  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
       
    17  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
       
    18  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
       
    19  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
       
    20  * THE USE OR OTHER DEALINGS IN THE MATERIALS.
       
    21  *
       
    22  * Initial Contributors:
       
    23  * Nokia Corporation - initial contribution.
       
    24  *
       
    25  * Contributors:
       
    26  *
       
    27  * Description:
       
    28  *
       
    29  */
       
    30 
       
    31 #ifndef _EGLUTILS_H_
       
    32 #define _EGLUTILS_H_
       
    33 
       
    34 #include <vector>
       
    35 #include <EGL/egl.h>
       
    36 #include "eglDefinitions.h"
       
    37 
       
    38 class RefCountingObject
       
    39     {
       
    40 public:
       
    41     RefCountingObject() : m_refCount( 0 ), m_terminated( false ) {}
       
    42     virtual ~RefCountingObject() { EGLI_ASSERT( m_refCount == 0); }
       
    43 
       
    44 public:
       
    45     virtual void AddRef() { m_refCount++; }
       
    46     virtual int RefCount() const { return m_refCount; }
       
    47     //returns true if object should be destroyed
       
    48     virtual bool RemoveRef() { m_refCount--; EGLI_ASSERT(m_refCount >= 0); return (m_refCount == 0); }
       
    49     virtual void Terminate() { m_terminated = true; }
       
    50     virtual bool IsTerminated() const { return m_terminated; }
       
    51 
       
    52 protected:
       
    53     int     m_refCount;
       
    54     bool    m_terminated;
       
    55     };
       
    56 
       
    57 template<class T> 
       
    58 extern void AddObject( std::vector<T*>& vector, T*& object );
       
    59 
       
    60 template<class T>
       
    61 extern T* FindObjectByPointer( const std::vector<T*>& vector, void* id, int* index );
       
    62 
       
    63 template<class T>
       
    64 extern  T* FindObjectById( const std::vector<T*>& vector, EGLint id, int* index );
       
    65 
       
    66 template<class T>
       
    67 extern  void DeleteObjectByPointer( std::vector<T*>& vector, void* item );
       
    68 
       
    69 template<class T>
       
    70 extern  void DeleteObjectById( std::vector<T*>& vector, EGLint id );
       
    71 
       
    72 template<class T>
       
    73 extern  void DestroyPointerVector( std::vector<T*>& vector );
       
    74 
       
    75 
       
    76 #endif //_EGLUTILS_H_