|
1 // Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #ifdef WIN32 |
|
17 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers |
|
18 #include <windows.h> |
|
19 #endif |
|
20 #include <stdio.h> |
|
21 #include <stdlib.h> |
|
22 |
|
23 #include <EGL/egl.h> |
|
24 #include <vg/openvg.h> |
|
25 #include "GLES/gl.h" |
|
26 |
|
27 #include "KhronosAPIWrapper.h" |
|
28 #include "serializedfunctioncall.h" |
|
29 #include "remotefunctioncall.h" |
|
30 #include "openvgrfc.h" |
|
31 #include "eglrfc.h" |
|
32 #include "driverrfc.h" |
|
33 #include "apiwrapper.h" |
|
34 #include "driverapiwrapper.h" |
|
35 #include "eglapiwrapper.h" |
|
36 #include "openvgapiwrapper.h" |
|
37 #include "opengles11apiwrapper.h" |
|
38 |
|
39 #include "graphicsvhwcallback.h" //callback interface Wrapper=>Virtual HW |
|
40 |
|
41 #include "platformthreading.h" |
|
42 #include "serialisedapiuids.h" |
|
43 #include "khronosapiwrapperdefs.h" |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 Psu::PLATFORM_THREADFUNC_RETTYPE WINAPI WorkerThreadFunction(void* aParam) |
|
49 { |
|
50 TRACE("KhronosAPIWrapper WorkerThreadFunction ->\n"); |
|
51 KhronosAPIWrapper* impl=(KhronosAPIWrapper*) aParam; |
|
52 impl->WorkerThread(); |
|
53 TRACE("KhronosAPIWrapper WorkerThreadFunction <-\n"); |
|
54 return 0; |
|
55 } |
|
56 |
|
57 int KhronosAPIWrapper::HandleNextRequest() |
|
58 { |
|
59 TRACE("KhronosAPIWrapper::HandleNextRequest() ->\n"); |
|
60 int ret(0); |
|
61 uint32_t inputBufferTail = m_InputRequestBuffer->GetReadIndex(); |
|
62 RemoteFunctionCallData& rfc( *iRFCData ); |
|
63 SerializedFunctionCall remotefcall(rfc); |
|
64 TRACE("KhronosAPIWrapper::HandleNextRequest ParseBuffer from %u\n", inputBufferTail); |
|
65 TInt len = remotefcall.ParseBuffer( ((TUint8*)(m_currentInput))+inputBufferTail, |
|
66 VVI_PARAMETERS_INPUT_MEMORY_SIZE - inputBufferTail ); |
|
67 ASSERT( len != -1 ); |
|
68 m_InputRequestBuffer->FreeBytes( len ); |
|
69 |
|
70 //TRACE("KhronosAPIWrapper::WorkerThread DispatchRequest -> %u\n", m_currentFunctionCall.Data().Header().iTransactionId); |
|
71 TRACE("KhronosAPIWrapper::HandleNextRequest DispatchRequest opCode -> %u / retval initially:%d\n", rfc.Header().iOpCode, rfc.Header().iReturnValue ); |
|
72 |
|
73 const TUint32 processId(rfc.Header().iProcessId); |
|
74 const TUint32 threadId(rfc.Header().iThreadId); |
|
75 |
|
76 if ( processId != m_lastProcessId || threadId != m_lastThreadId ) |
|
77 { |
|
78 m_lastProcessId = processId; |
|
79 m_lastThreadId = threadId; |
|
80 TRACE("KhronosAPIWrapper::HandleNextRequest Set process info for %u / %u \n", processId, threadId ); |
|
81 m_EGLWrapper->SetProcessInformation( processId, threadId ); |
|
82 } |
|
83 |
|
84 switch ( rfc.Header().iApiUid ) |
|
85 { |
|
86 case SERIALISED_DRIVER_API_UID: |
|
87 { |
|
88 TRACE("KhronosAPIWrapper::HandleNextRequest SERIALISED_DRIVER_API_UID \n" ); |
|
89 if ( DriverRFC::EDrvClientShutdown == rfc.Header().iOpCode ) |
|
90 { |
|
91 m_OpenVGWrapper->Cleanup( processId, threadId ); |
|
92 m_EGLWrapper->Cleanup( processId, threadId ); |
|
93 m_OGLESWrapper->Cleanup( processId, threadId ); |
|
94 } |
|
95 else |
|
96 { |
|
97 m_DriverAPIWrapper->DispatchRequest( rfc.Header().iOpCode ); |
|
98 } |
|
99 break; |
|
100 } |
|
101 case SERIALISED_OPENVG_API_UID: |
|
102 { |
|
103 ret = m_OpenVGWrapper->DispatchRequest( rfc.Header().iOpCode ); |
|
104 break; |
|
105 } |
|
106 case SERIALISED_EGL_API_UID: |
|
107 { |
|
108 ret = m_EGLWrapper->DispatchRequest( rfc.Header().iOpCode ); |
|
109 break; |
|
110 } |
|
111 case SERIALISED_OPENGLES_1_1_API_UID: |
|
112 { |
|
113 m_OGLESWrapper->SetProcessInformation( processId, threadId ); |
|
114 ret = m_OGLESWrapper->DispatchRequest( rfc.Header().iOpCode ); |
|
115 break; |
|
116 } |
|
117 default: |
|
118 break; |
|
119 } |
|
120 |
|
121 TRACE("KhronosAPIWrapper::HandleNextRequest DispatchRequest <-\n"); |
|
122 |
|
123 if ( RemoteFunctionCallData::EOpReply == rfc.Header().iOpType ) |
|
124 { |
|
125 TRACE("KhronosAPIWrapper::HandleNextRequest ProsessingDone ->\n"); |
|
126 iServiceIf->ProcessingDone( rfc.Header().iTransactionId ); |
|
127 TRACE("KhronosAPIWrapper::HandleNextRequest ProsessingDone <-\n"); |
|
128 } |
|
129 else if ( !m_InputRequestBuffer->IsDataAvailable() ) |
|
130 { |
|
131 iServiceIf->LockOutputBuffer(); //We need to use the lock buffer so that the request id register is protected |
|
132 iServiceIf->ProcessingDone( 0 ); //Signal driver that buffer is empty |
|
133 } |
|
134 TRACE("ret = %d\n", ret); |
|
135 TRACE("KhronosAPIWrapper::HandleNextRequest() <-\n"); |
|
136 return ret; |
|
137 } |
|
138 |
|
139 |
|
140 void KhronosAPIWrapper::WorkerThread() |
|
141 { |
|
142 TRACE("KhronosAPIWrapper::WorkerThread ->\n"); |
|
143 while(1) |
|
144 { |
|
145 int ret; |
|
146 |
|
147 while ( !m_exit && !m_InputRequestBuffer->IsDataAvailable() ) |
|
148 { |
|
149 TRACE("KhronosAPIWrapper::WorkerThread Waiting\n"); |
|
150 //No more data, wait for some more |
|
151 Psu::platform_wait_for_signal(m_SemapHandle); |
|
152 TRACE("KhronosAPIWrapper::WorkerThread Signaled\n"); |
|
153 } |
|
154 |
|
155 TRACE("KhronosAPIWrapper::WorkerThread Process request\n"); |
|
156 |
|
157 if ( m_exit ) |
|
158 { |
|
159 TRACE("KhronosAPIWrapper::WorkerThread m_exit\n"); |
|
160 return; |
|
161 } |
|
162 ret = HandleNextRequest(); |
|
163 TRACE("KhronosAPIWrapper::WorkerThread <-\n"); |
|
164 } |
|
165 } |
|
166 |
|
167 |
|
168 TUint32 KhronosAPIWrapper::GetWriteCount() |
|
169 { |
|
170 TRACE("KhronosAPIWrapper::GetWriteCount()\n"); |
|
171 return InputBufferWriteCount(); |
|
172 } |
|
173 |
|
174 |
|
175 void KhronosAPIWrapper::IncrementReadCount( TUint32 aReadCount ) |
|
176 { |
|
177 TRACE("KhronosAPIWrapper::IncrementReadCount()\n"); |
|
178 IncrementInputBufferReadCount( aReadCount ); |
|
179 } |
|
180 |
|
181 |
|
182 TUint32 KhronosAPIWrapper::GetReadCount() |
|
183 { |
|
184 TRACE("KhronosAPIWrapper::GetReadCount()\n"); |
|
185 return InputBufferReadCount(); |
|
186 } |
|
187 |
|
188 |
|
189 TUint32 KhronosAPIWrapper::BufferTail() |
|
190 { |
|
191 TRACE("KhronosAPIWrapper::BufferTail()\n"); |
|
192 return InputBufferTail(); |
|
193 } |
|
194 |
|
195 |
|
196 void KhronosAPIWrapper::SetBufferTail( TUint32 aIndex ) |
|
197 { |
|
198 TRACE("KhronosAPIWrapper::SetBufferTail()\n"); |
|
199 SetInputBufferTail( aIndex ); |
|
200 } |
|
201 |
|
202 |
|
203 TUint32 KhronosAPIWrapper::BufferHead() |
|
204 { |
|
205 TRACE("KhronosAPIWrapper::BufferHead()\n"); |
|
206 return InputBufferHead(); |
|
207 } |
|
208 |
|
209 |
|
210 TUint32 KhronosAPIWrapper::MaxTailIndex() |
|
211 { |
|
212 TRACE("KhronosAPIWrapper::MaxTailIndex()\n"); |
|
213 return InputMaxTailIndex(); |
|
214 } |
|
215 |
|
216 |
|
217 void KhronosAPIWrapper::SetMaxTailIndex( TUint32 aIndex ) |
|
218 { |
|
219 TRACE("KhronosAPIWrapper::SetMaxTailIndex()\n"); |
|
220 SetInputMaxTailIndex( aIndex ); |
|
221 } |
|
222 |
|
223 |
|
224 TUint32 KhronosAPIWrapper::InputMaxTailIndex() |
|
225 { |
|
226 TRACE("KhronosAPIWrapper::InputMaxTailIndex()\n"); |
|
227 TUint32 ret = m_InputBufferMaxTailIndex; |
|
228 return ret; |
|
229 } |
|
230 |
|
231 |
|
232 void KhronosAPIWrapper::SetInputMaxTailIndex( TUint32 aIndex ) |
|
233 { |
|
234 TRACE("KhronosAPIWrapper::SetInputMaxTailIndex aIndex %u\n", aIndex ); |
|
235 m_InputBufferMaxTailIndex = aIndex; |
|
236 } |
|
237 |
|
238 |
|
239 void KhronosAPIWrapper::SetInputBufferTail(uint32_t p_val) |
|
240 { |
|
241 TRACE("KhronosAPIWrapper::SetInputBufferTail aIndex %u\n", p_val ); |
|
242 m_InputBufferTail = p_val; |
|
243 } |
|
244 |
|
245 |
|
246 uint32_t KhronosAPIWrapper::InputBufferTail() |
|
247 { |
|
248 uint32_t val = m_InputBufferTail; |
|
249 TRACE("KhronosAPIWrapper::InputBufferTail %u\n", val ); |
|
250 return val; |
|
251 } |
|
252 |
|
253 |
|
254 void KhronosAPIWrapper::SetInputBufferHead(uint32_t p_val) |
|
255 { |
|
256 TRACE("KhronosAPIWrapper::SetInputBufferHead aIndex %u\n", p_val ); |
|
257 m_InputBufferHead = p_val; |
|
258 } |
|
259 |
|
260 |
|
261 uint32_t KhronosAPIWrapper::InputBufferHead() |
|
262 { |
|
263 uint32_t val = m_InputBufferHead; |
|
264 TRACE("KhronosAPIWrapper::InputBufferHead %u\n", val ); |
|
265 return val; |
|
266 } |
|
267 |
|
268 |
|
269 void KhronosAPIWrapper::SetInputBufferReadCount(uint32_t p_val) |
|
270 { |
|
271 TRACE("KhronosAPIWrapper::SetInputBufferReadCount aIndex %u\n", p_val ); |
|
272 m_InputBufferReadCount = p_val; |
|
273 } |
|
274 |
|
275 |
|
276 void KhronosAPIWrapper::IncrementInputBufferReadCount( TUint32 aReadCount ) |
|
277 { |
|
278 TRACE("KhronosAPIWrapper::IncrementInputBufferReadCount m_InputBufferReadCount++ %u\n", m_InputBufferReadCount ); |
|
279 m_InputBufferReadCount += aReadCount; |
|
280 } |
|
281 |
|
282 |
|
283 uint32_t KhronosAPIWrapper::InputBufferReadCount() |
|
284 { |
|
285 uint32_t val = m_InputBufferReadCount; |
|
286 TRACE("KhronosAPIWrapper::InputBufferReadCount %u\n", val ); |
|
287 return val; |
|
288 } |
|
289 |
|
290 |
|
291 void KhronosAPIWrapper::SetInputBufferWriteCount(uint32_t p_val) |
|
292 { |
|
293 TRACE("KhronosAPIWrapper::SetInputBufferWriteCount %u\n", p_val ); |
|
294 m_InputbufferWriteCount = p_val; |
|
295 } |
|
296 |
|
297 |
|
298 uint32_t KhronosAPIWrapper::InputBufferWriteCount() |
|
299 { |
|
300 uint32_t val = m_InputbufferWriteCount; |
|
301 TRACE("KhronosAPIWrapper::InputBufferWriteCount %u\n", val ); |
|
302 return val; |
|
303 } |
|
304 |
|
305 |
|
306 KhronosAPIWrapper::KhronosAPIWrapper( MGraphicsVHWCallback* aServiceIf, void* surfacebuffer, void* inputdata, void* outputdata ) |
|
307 { |
|
308 TRACE("KhronosAPIWrapper::KhronosAPIWrapper()\n"); |
|
309 m_lastVgError = VG_NO_ERROR; |
|
310 m_lastEglError = EGL_SUCCESS; |
|
311 |
|
312 m_lastProcessId = 0; |
|
313 m_lastThreadId = 0; |
|
314 m_currentInput = inputdata; |
|
315 m_currentResult = outputdata; |
|
316 m_surfaceBuffer = surfacebuffer; |
|
317 m_exit = false; |
|
318 iServiceIf = aServiceIf; |
|
319 m_initDone = false; |
|
320 iRFCData = new RemoteFunctionCallData; |
|
321 m_InputRequestBuffer = new RequestBufferReader( *this, VVI_PARAMETERS_INPUT_MEMORY_SIZE ); |
|
322 |
|
323 Psu::platform_create_semaphore(m_SemapHandle, 0, 1000000); |
|
324 |
|
325 Psu::platform_mutex_init( &m_InputBufferMutex ); |
|
326 m_InputBufferTail = 0; |
|
327 m_InputBufferHead = 0; |
|
328 m_InputBufferReadCount = 0; |
|
329 m_InputbufferWriteCount = 0; |
|
330 |
|
331 iStack = new APIWrapperStack(); |
|
332 iStack->InitStack( KMaxStackSize ); |
|
333 |
|
334 m_OpenVGWrapper = new OpenVGAPIWrapper( *iRFCData, iStack, m_currentResult, iServiceIf, this ); |
|
335 m_OGLESWrapper = new OGLES11Wrapper(*iRFCData, iStack, m_currentResult, iServiceIf); |
|
336 m_EGLWrapper = new EGLAPIWrapper( *iRFCData, iStack, m_currentResult, iServiceIf, m_surfaceBuffer, this ); |
|
337 m_DriverAPIWrapper = new DriverAPIWrapper( *iRFCData, iStack, m_currentResult, iServiceIf, this ); |
|
338 |
|
339 #ifdef KHRONOS_API_W_MULTITHREAD |
|
340 int result = Psu::platform_create_simple_thread(&m_threadHandle, |
|
341 &WorkerThreadFunction, this); |
|
342 if (result) |
|
343 { |
|
344 //Error |
|
345 } |
|
346 #endif |
|
347 } |
|
348 |
|
349 KhronosAPIWrapper::~KhronosAPIWrapper() |
|
350 { |
|
351 TRACE("KhronosAPIWrapper::~KhronosAPIWrapper\n"); |
|
352 m_exit = true; |
|
353 Psu::platform_signal_semaphore(m_SemapHandle); |
|
354 Psu::platform_join_thread(m_threadHandle); |
|
355 Psu::platform_release_semaphore(m_SemapHandle); |
|
356 Psu::platform_mutex_destroy( &m_InputBufferMutex ); |
|
357 delete iStack; iStack = NULL; |
|
358 delete m_InputRequestBuffer; m_InputRequestBuffer = NULL; |
|
359 delete m_OpenVGWrapper; m_OpenVGWrapper = NULL; |
|
360 delete m_EGLWrapper; m_EGLWrapper = NULL; |
|
361 delete m_DriverAPIWrapper; m_DriverAPIWrapper = NULL; |
|
362 delete m_OGLESWrapper; m_OGLESWrapper = NULL; |
|
363 delete iRFCData; iRFCData = NULL; |
|
364 } |
|
365 |
|
366 |
|
367 unsigned long KhronosAPIWrapper::InputParameterOffset() |
|
368 { |
|
369 TRACE("KhronosAPIWrapper::InputParameterOffset()\n"); |
|
370 return 0; |
|
371 } |
|
372 |
|
373 |
|
374 unsigned long KhronosAPIWrapper::Execute() |
|
375 { |
|
376 TRACE("KhronosAPIWrapper::Execute\n"); |
|
377 TInt ret(0); |
|
378 |
|
379 #ifdef KHRONOS_API_W_MULTITHREAD |
|
380 Psu::platform_signal_semaphore(m_SemapHandle); |
|
381 #else |
|
382 while ( m_InputRequestBuffer->IsDataAvailable() ) |
|
383 { |
|
384 HandleNextRequest(); |
|
385 } |
|
386 #endif |
|
387 |
|
388 return ret; |
|
389 } |
|
390 |
|
391 |
|
392 #ifdef WIN32 |
|
393 |
|
394 BOOL APIENTRY DllMain( HMODULE hModule, |
|
395 DWORD ul_reason_for_call, |
|
396 LPVOID lpReserved |
|
397 ) |
|
398 { |
|
399 switch (ul_reason_for_call) |
|
400 { |
|
401 case DLL_PROCESS_ATTACH: |
|
402 case DLL_THREAD_ATTACH: |
|
403 case DLL_THREAD_DETACH: |
|
404 case DLL_PROCESS_DETACH: |
|
405 break; |
|
406 } |
|
407 return true; |
|
408 } |
|
409 #endif |
|
410 |