24
|
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 |
#include "EGLUtils.h"
|
|
32 |
#include "EGLSurface.h"
|
|
33 |
#include "EGLContext.h"
|
|
34 |
#include "EGLImage.h"
|
|
35 |
#include "EGLThread.h"
|
|
36 |
#include "EGLProcess.h"
|
|
37 |
#include "EGLConfig.h"
|
|
38 |
#include "EGLDisplay.h"
|
|
39 |
|
|
40 |
template<class T>
|
|
41 |
void AddObject( std::vector<T*>& vector, T*& object )
|
|
42 |
{
|
|
43 |
if( !object ) return;
|
|
44 |
try
|
|
45 |
{
|
|
46 |
vector.push_back(object);
|
|
47 |
}
|
|
48 |
catch( std::bad_alloc )
|
|
49 |
{
|
|
50 |
delete object;
|
|
51 |
object = NULL;
|
|
52 |
}
|
|
53 |
}
|
|
54 |
|
|
55 |
template<class T>
|
|
56 |
T* FindObjectByPointer( const std::vector<T*>& vector, void* item, int* index )
|
|
57 |
{
|
|
58 |
T* ret = NULL;
|
|
59 |
for( typename std::vector<T*>::size_type i = 0; i < vector.size(); i++ )
|
|
60 |
{
|
|
61 |
if( vector[i] == item )
|
|
62 |
{
|
|
63 |
ret = vector[i];
|
|
64 |
if( index ) *index = i;
|
|
65 |
break;
|
|
66 |
}
|
|
67 |
}
|
|
68 |
return ret;
|
|
69 |
}
|
|
70 |
|
|
71 |
template<class T>
|
|
72 |
T* FindObjectById( const std::vector<T*>& vector, EGLint id, int* index )
|
|
73 |
{
|
|
74 |
T* ret = NULL;
|
|
75 |
for( typename std::vector<T*>::size_type i = 0; i < vector.size(); i++ )
|
|
76 |
{
|
|
77 |
if( vector[i]->Id() == id )
|
|
78 |
{
|
|
79 |
ret = vector[i];
|
|
80 |
if( index ) *index = i;
|
|
81 |
break;
|
|
82 |
}
|
|
83 |
}
|
|
84 |
return ret;
|
|
85 |
}
|
|
86 |
|
|
87 |
template<class T>
|
|
88 |
void DeleteObjectByPointer( std::vector<T*>& vector, void* item )
|
|
89 |
{
|
|
90 |
int index;
|
|
91 |
T* object = FindObjectByPointer<T>( vector, item, &index );
|
|
92 |
if( object )
|
|
93 |
{
|
|
94 |
delete object;
|
|
95 |
vector.erase( vector.begin() + index );
|
|
96 |
}
|
|
97 |
}
|
|
98 |
|
|
99 |
template<class T>
|
|
100 |
void DeleteObjectById( std::vector<T*>& vector, EGLint id )
|
|
101 |
{
|
|
102 |
int index;
|
|
103 |
T* object = FindObjectById<T>(vector, id, &index );
|
|
104 |
if( object && object->Id() == id )
|
|
105 |
{
|
|
106 |
delete object;
|
|
107 |
vector.erase( vector.begin() + index );
|
|
108 |
}
|
|
109 |
}
|
|
110 |
|
|
111 |
template<class T>
|
|
112 |
void DestroyPointerVector( std::vector<T*>& vector )
|
|
113 |
{
|
|
114 |
for(typename std::vector<T*>::iterator iter = vector.begin(); iter != vector.end(); iter++)
|
|
115 |
{
|
|
116 |
delete (*iter);
|
|
117 |
}
|
|
118 |
vector.clear();
|
|
119 |
}
|
|
120 |
|
|
121 |
// CEGLSurface
|
|
122 |
template void AddObject( std::vector<class CEGLSurface*>& vector, class CEGLSurface*& object );
|
|
123 |
template class CEGLSurface* FindObjectByPointer( const std::vector<class CEGLSurface*>& vector, void* item, int* index );
|
|
124 |
template void DeleteObjectByPointer( std::vector<class CEGLSurface*>& vector, void* item );
|
|
125 |
template void DestroyPointerVector( std::vector<class CEGLSurface*>& vector );
|
|
126 |
|
|
127 |
// CEGLContext
|
|
128 |
template void AddObject( std::vector<class CEGLContext*>& vector, class CEGLContext*& object );
|
|
129 |
template void DeleteObjectByPointer( std::vector<class CEGLContext*>& vector, void* item );
|
|
130 |
template void DestroyPointerVector( std::vector<class CEGLContext*>& vector );
|
|
131 |
|
|
132 |
// CEGLImage
|
|
133 |
template void AddObject( std::vector<class CEGLImage*>& vector, class CEGLImage*& object );
|
|
134 |
template void DeleteObjectByPointer( std::vector<class CEGLImage*>& vector, void* item );
|
|
135 |
template void DestroyPointerVector( std::vector<class CEGLImage*>& vector );
|
|
136 |
|
|
137 |
// CEGLThread
|
|
138 |
template void AddObject( std::vector<class CEGLThread*>& vector, class CEGLThread*& object );
|
|
139 |
template void DeleteObjectById( std::vector<class CEGLThread*>& vector, EGLint id );
|
|
140 |
template void DestroyPointerVector( std::vector<class CEGLThread*>& vector );
|
|
141 |
template class CEGLThread* FindObjectById( const std::vector<class CEGLThread*>& vector, EGLint id, int* index );
|
|
142 |
|
|
143 |
// CEGLProcess
|
|
144 |
template void AddObject( std::vector<class CEGLProcess*>& vector, class CEGLProcess*& object );
|
|
145 |
template void DestroyPointerVector( std::vector<class CEGLProcess*>& vector );
|
|
146 |
template void DeleteObjectById( std::vector<class CEGLProcess*>& vector, EGLint id );
|
|
147 |
|
|
148 |
// CEGLDisplay
|
|
149 |
template void AddObject( std::vector<class CEGLDisplay*>& vector, class CEGLDisplay*& object );
|
|
150 |
template class CEGLDisplay* FindObjectByPointer( const std::vector<class CEGLDisplay*>& vector, void* item, int* index );
|
|
151 |
template void DeleteObjectByPointer( std::vector<class CEGLDisplay*>& vector, void* item );
|
|
152 |
template void DestroyPointerVector( std::vector<class CEGLDisplay*>& vector );
|
|
153 |
|
|
154 |
// CEGLConfig
|
|
155 |
template void AddObject( std::vector<class CEGLConfig*>& vector, class CEGLConfig*& object );
|
|
156 |
template class CEGLConfig* FindObjectByPointer( const std::vector<class CEGLConfig*>& vector, void* item, int* index );
|
|
157 |
template class CEGLConfig* FindObjectById( const std::vector<class CEGLConfig*>& vector, EGLint id, int* index );
|
|
158 |
template void DestroyPointerVector( std::vector<class CEGLConfig*>& vector );
|