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 "EGLDisplay.h"
|
|
32 |
#include "EGLContext.h"
|
|
33 |
#include "EGLConfig.h"
|
|
34 |
#include "EGLSurface.h"
|
|
35 |
#include "EGLImage.h"
|
|
36 |
#include "EGLWindowSurface.h"
|
|
37 |
#include "EGLPbufferSurface.h"
|
|
38 |
#include "ColorDescriptor.h"
|
|
39 |
#include "EGLOs.h"
|
|
40 |
#include "EGLUtils.h"
|
|
41 |
#include "EGLState.h"
|
|
42 |
#include "EGLProcess.h"
|
|
43 |
#include "EGLThread.h"
|
|
44 |
|
|
45 |
|
|
46 |
CEGLDisplay::CEGLDisplay( EGLINativeDisplayType nativeType, EGLint processId ) :
|
|
47 |
m_nativeType( nativeType ),
|
|
48 |
m_initialized( EGL_FALSE ),
|
|
49 |
m_processId( processId )
|
|
50 |
{
|
|
51 |
}
|
|
52 |
|
|
53 |
CEGLDisplay::~CEGLDisplay(void)
|
|
54 |
{
|
|
55 |
DestroyPointerVector<CEGLContext>( m_contexts );
|
|
56 |
DestroyPointerVector<CEGLSurface>( m_surfaces );
|
|
57 |
DestroyPointerVector<CEGLImage>( m_images );
|
|
58 |
}
|
|
59 |
|
|
60 |
CEGLContext* CEGLDisplay::AddContext( CEGLContext* context )
|
|
61 |
{
|
|
62 |
if( context )
|
|
63 |
{
|
|
64 |
AddObject<CEGLContext>( m_contexts, context );
|
|
65 |
}
|
|
66 |
return context;
|
|
67 |
}
|
|
68 |
|
|
69 |
void CEGLDisplay::RemoveContext( EGLContext context )
|
|
70 |
{
|
|
71 |
DeleteObjectByPointer<CEGLContext>( m_contexts, context );
|
|
72 |
}
|
|
73 |
|
|
74 |
CEGLContext* CEGLDisplay::GetContext( EGLContext context ) const
|
|
75 |
{
|
|
76 |
CEGLContext* ret = FindObjectByPointer<CEGLContext>( m_contexts, context, NULL );
|
|
77 |
if( ret && ret->IsTerminated() ) ret = NULL;
|
|
78 |
return ret;
|
|
79 |
}
|
|
80 |
|
|
81 |
CEGLSurface* CEGLDisplay::AddSurface( CEGLSurface* surface )
|
|
82 |
{
|
|
83 |
if( surface )
|
|
84 |
{
|
|
85 |
AddObject<CEGLSurface>( m_surfaces, surface );
|
|
86 |
}
|
|
87 |
return surface;
|
|
88 |
}
|
|
89 |
|
|
90 |
void CEGLDisplay::RemoveSurface( EGLSurface surfaceId )
|
|
91 |
{
|
|
92 |
DeleteObjectByPointer<CEGLSurface>( m_surfaces, surfaceId );
|
|
93 |
}
|
|
94 |
|
|
95 |
CEGLSurface* CEGLDisplay::GetSurface( EGLSurface surfaceId ) const
|
|
96 |
{
|
|
97 |
CEGLSurface* ret = FindObjectByPointer<CEGLSurface>( m_surfaces, surfaceId, NULL );
|
|
98 |
if( ret && ret->IsTerminated() ) ret = NULL;
|
|
99 |
return ret;
|
|
100 |
}
|
|
101 |
|
|
102 |
CEGLSurface* CEGLDisplay::GetSurfaceByNativeType( EGLINativeWindowType nativeType ) const
|
|
103 |
{
|
|
104 |
CEGLSurface* ret = NULL;
|
|
105 |
std::vector<CEGLSurface*>::const_iterator iter = m_surfaces.begin();
|
|
106 |
while( iter != m_surfaces.end() )
|
|
107 |
{
|
|
108 |
if( (*iter)->Type() == CEGLSurface::WINDOW_SURFACE )
|
|
109 |
{
|
|
110 |
if( ((CEGLWindowSurface*)(*iter))->NativeType() == nativeType && !((*iter)->IsTerminated()) )
|
|
111 |
{
|
|
112 |
ret = (*iter);
|
|
113 |
break;
|
|
114 |
}
|
|
115 |
}
|
|
116 |
iter++;
|
|
117 |
}
|
|
118 |
return ret;
|
|
119 |
}
|
|
120 |
|
|
121 |
CEGLSurface* CEGLDisplay::FindSurfaceByClientSurface( void* clientSurface, EGLenum api, EGLint apiVersion ) const
|
|
122 |
{
|
|
123 |
CEGLSurface* ret = NULL;
|
|
124 |
std::vector<CEGLSurface*>::const_iterator iter = m_surfaces.begin();
|
|
125 |
while( iter != m_surfaces.end() )
|
|
126 |
{
|
|
127 |
switch( api )
|
|
128 |
{
|
|
129 |
case EGL_OPENVG_API:
|
|
130 |
{
|
|
131 |
if( (*iter)->VGClientSurface() == clientSurface )
|
|
132 |
{
|
|
133 |
ret = (*iter);
|
|
134 |
break;
|
|
135 |
}
|
|
136 |
}
|
|
137 |
case EGL_OPENGL_ES_API:
|
|
138 |
{
|
|
139 |
if( (*iter)->GLESClientSurface() == clientSurface )
|
|
140 |
{
|
|
141 |
ret = (*iter);
|
|
142 |
break;
|
|
143 |
}
|
|
144 |
}
|
|
145 |
}
|
|
146 |
iter++;
|
|
147 |
}
|
|
148 |
return ret;
|
|
149 |
}
|
|
150 |
|
|
151 |
CEGLSurface* CEGLDisplay::FindSurfaceByClientBuffer( void* clientBuffer ) const
|
|
152 |
{
|
|
153 |
CEGLSurface* ret = NULL;
|
|
154 |
std::vector<CEGLSurface*>::const_iterator iter = m_surfaces.begin();
|
|
155 |
while( iter != m_surfaces.end() )
|
|
156 |
{
|
|
157 |
if( (*iter)->Type() == CEGLSurface::PBUFFER_SURFACE &&
|
|
158 |
((CEGLPbufferSurface*)(*iter))->ClientBuffer() == clientBuffer )
|
|
159 |
{
|
|
160 |
ret = (*iter);
|
|
161 |
break;
|
|
162 |
}
|
|
163 |
iter++;
|
|
164 |
}
|
|
165 |
return ret;
|
|
166 |
}
|
|
167 |
|
|
168 |
EGLINativeDisplayType CEGLDisplay::NativeType() const
|
|
169 |
{
|
|
170 |
#if defined(EGLI_USE_PLATSIM_EXTENSIONS)
|
|
171 |
return m_nativeType;
|
|
172 |
#else
|
|
173 |
return m_nativeType;
|
|
174 |
#endif
|
|
175 |
}
|
|
176 |
|
|
177 |
EGLBoolean CEGLDisplay::Initialize()
|
|
178 |
{
|
|
179 |
m_initialized = EGL_TRUE;
|
|
180 |
return m_initialized;
|
|
181 |
}
|
|
182 |
|
|
183 |
bool CEGLDisplay::TerminateDisplay()
|
|
184 |
{
|
|
185 |
//m_initialized = EGL_FALSE;
|
|
186 |
bool ret = true;
|
|
187 |
std::vector<CEGLSurface*> boundSurfaces;
|
|
188 |
std::vector<CEGLSurface*>::iterator sIter = m_surfaces.begin();
|
|
189 |
CEGLState* state = getState();
|
|
190 |
CEGLThread* thread = state->GetCurrentProcess()->CurrentThread();
|
|
191 |
while( sIter != m_surfaces.end() )
|
|
192 |
{
|
|
193 |
if( (*sIter)->IsTerminated() || !((*sIter)->RemoveRef()) )
|
|
194 |
{
|
|
195 |
(*sIter)->Terminate();
|
|
196 |
boundSurfaces.push_back( (*sIter) );
|
|
197 |
sIter = m_surfaces.erase( sIter );
|
|
198 |
}
|
|
199 |
else
|
|
200 |
{
|
|
201 |
sIter++;
|
|
202 |
}
|
|
203 |
}
|
|
204 |
DestroyPointerVector<CEGLSurface>(m_surfaces);
|
|
205 |
m_surfaces.swap( boundSurfaces );
|
|
206 |
boundSurfaces.clear();
|
|
207 |
|
|
208 |
std::vector<CEGLContext*> boundContexts;
|
|
209 |
std::vector<CEGLContext*>::iterator cIter = m_contexts.begin();
|
|
210 |
while( cIter != m_contexts.end() )
|
|
211 |
{
|
|
212 |
if( (*cIter)->IsTerminated() || !((*cIter)->RemoveRef()) )
|
|
213 |
{
|
|
214 |
(*cIter)->Terminate();
|
|
215 |
boundContexts.push_back( (*cIter) );
|
|
216 |
cIter = m_contexts.erase( cIter );
|
|
217 |
}
|
|
218 |
else
|
|
219 |
{
|
|
220 |
cIter++;
|
|
221 |
}
|
|
222 |
}
|
|
223 |
DestroyPointerVector<CEGLContext>(m_contexts);
|
|
224 |
m_contexts.swap( boundContexts );
|
|
225 |
ret = (m_contexts.size() <= 0 && m_surfaces.size() <= 0);
|
|
226 |
Terminate();
|
|
227 |
return ret;
|
|
228 |
//TODO
|
|
229 |
//EGLI_ASSERT( false );
|
|
230 |
}
|
|
231 |
|
|
232 |
CEGLImage* CEGLDisplay::AddEGLImage( CEGLImage* image )
|
|
233 |
{
|
|
234 |
if( image )
|
|
235 |
{
|
|
236 |
AddObject<CEGLImage>( m_images, image );
|
|
237 |
}
|
|
238 |
return image;
|
|
239 |
}
|
|
240 |
|
|
241 |
void CEGLDisplay::RemoveEGLImage( EGLImageKHR image )
|
|
242 |
{
|
|
243 |
DeleteObjectByPointer<CEGLImage>( m_images, image );
|
|
244 |
}
|
|
245 |
|
|
246 |
CEGLImage* CEGLDisplay::GetImage( EGLImageKHR image ) const
|
|
247 |
{
|
|
248 |
CEGLImage* ret = FindObjectByPointer<CEGLImage>( m_images, image, NULL );
|
|
249 |
return ret;
|
|
250 |
}
|