author | Matt Plumtree <matt.plumtree@nokia.com> |
Fri, 12 Nov 2010 17:56:05 +0000 | |
branch | bug235_bringup_0 |
changeset 76 | 24381b61de5c |
parent 71 | 243bbc1d70db |
permissions | -rw-r--r-- |
24 | 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 |
#include <stdio.h> |
|
17 |
#include <stdlib.h> |
|
18 |
#include <EGL/egl.h>//EGL operations will be called a lot from here |
|
19 |
#include <vg/openvg.h> |
|
20 |
||
21 |
#include "driverapiwrapper.h" |
|
22 |
#include "KhronosAPIWrapper.h" |
|
23 |
||
24 |
||
25 |
bool DriverAPIWrapper::IsSgBackingVGImage( VGImage aImage ) |
|
26 |
{ |
|
27 |
for( std::list<VGImage>::iterator cur = m_SgImageVGImages.begin(); |
|
28 |
cur != m_SgImageVGImages.end(); |
|
29 |
++cur ) |
|
30 |
{ |
|
31 |
if( (*cur) == aImage ) |
|
32 |
{ |
|
33 |
return true; |
|
34 |
} |
|
35 |
} |
|
36 |
return false; |
|
37 |
} |
|
38 |
||
39 |
bool DriverAPIWrapper::IsSgBackingPBuffer( EGLSurface aSurface ) |
|
40 |
{ |
|
41 |
for( std::list<EGLSurface>::iterator cur = m_SgImagePbuffers.begin(); |
|
42 |
cur != m_SgImagePbuffers.end(); |
|
43 |
++cur ) |
|
44 |
{ |
|
45 |
if( (*cur) == aSurface ) |
|
46 |
{ |
|
47 |
return true; |
|
48 |
} |
|
49 |
} |
|
50 |
return false; |
|
51 |
} |
|
52 |
||
53 |
int DriverAPIWrapper::CreatePoolContext() |
|
54 |
{ |
|
55 |
//Initialize EGL on the first run, as per 5.1 in the "Implementing SgImage" design doc |
|
56 |
if( m_initialized ){ return 0; } |
|
57 |
TRACE("DriverAPIWrapper::CreatePoolContext() ->\n"); |
|
58 |
EGLDisplay display(0); |
|
59 |
||
60 |
EGLConfig config(0); |
|
61 |
EGLint num_config; |
|
62 |
||
63 |
EGLContext PoolContext(0);//for sharing |
|
64 |
EGLContext ContextWithFormatARGB_8888_PRE(0);//for sharing |
|
65 |
EGLContext ContextWithFormatARGB_8888(0); |
|
66 |
EGLContext ContextWithFormatXRGB_8888(0); |
|
67 |
EGLContext ContextWithFormatRGB_565(0); |
|
68 |
EGLContext ContextWithFormatA_8(0); |
|
69 |
EGLSurface DudSurface(0); |
|
70 |
||
71 |
int red(0); |
|
72 |
int green(0); |
|
73 |
int blue(0); |
|
74 |
int alpha(0); |
|
75 |
||
76 |
display = ::eglGetDisplay( EGL_DEFAULT_DISPLAY );//Notice: there is no support for multiple displays here |
|
77 |
||
78 |
if( !::eglInitialize(display, NULL, NULL) ) |
|
79 |
{ |
|
80 |
TRACE("DriverAPIWrapper::CreatePoolContext() <- (eglInitialize failed)\n"); |
|
81 |
return 0; |
|
82 |
} |
|
83 |
||
84 |
m_Dpy = display; |
|
85 |
//Pool Context |
|
86 |
//get a Configuration, then get the context |
|
87 |
if( ::eglChooseConfig( display, |
|
88 |
getColorAttributes( EUidPixelFormatARGB_8888, red, green, blue, alpha ), |
|
89 |
&config, |
|
90 |
1, |
|
91 |
&num_config ) == EGL_TRUE ) |
|
92 |
{ |
|
93 |
/* create an EGL rendering context */ |
|
94 |
PoolContext = ContextWithFormatARGB_8888 = eglCreateContext(display, config, EGL_NO_CONTEXT, NULL); |
|
95 |
m_PoolConfig = config; |
|
96 |
} |
|
97 |
||
98 |
||
30
f204b762818d
Rename use of "frame" buffer to "surface" buffer, to reduce confusion.
Matt Plumtree <matt.plumtree@nokia.com>
parents:
24
diff
changeset
|
99 |
/* get an appropriate EGL surface buffer configuration */ |
24 | 100 |
if( ::eglChooseConfig( display, |
101 |
getColorAttributes( EUidPixelFormatXRGB_8888, red, green, blue, alpha ), |
|
102 |
&config, |
|
103 |
1, |
|
104 |
&num_config ) == EGL_TRUE ) |
|
105 |
{ |
|
106 |
/* create an EGL rendering context */ |
|
107 |
PoolContext = ContextWithFormatXRGB_8888 = eglCreateContext(display, config, EGL_NO_CONTEXT, NULL); |
|
108 |
} |
|
109 |
||
110 |
||
111 |
//get a Configuration, then get the context |
|
112 |
if( ::eglChooseConfig( display, |
|
113 |
getColorAttributes( EUidPixelFormatARGB_8888_PRE, red, green, blue, alpha ), |
|
114 |
&config, |
|
115 |
1, |
|
116 |
&num_config ) == EGL_TRUE ) |
|
117 |
{ |
|
118 |
/* create an EGL rendering context */ |
|
119 |
ContextWithFormatARGB_8888_PRE = eglCreateContext(display, config, EGL_NO_CONTEXT, NULL); |
|
120 |
} |
|
121 |
||
122 |
||
123 |
//get a Configuration, then get the context |
|
124 |
if( ::eglChooseConfig( display, |
|
125 |
getColorAttributes( EUidPixelFormatRGB_565, red, green, blue, alpha ), |
|
126 |
&config, |
|
127 |
1, |
|
128 |
&num_config ) == EGL_TRUE ) |
|
129 |
{ |
|
130 |
/* create an EGL rendering context */ |
|
131 |
ContextWithFormatRGB_565 = eglCreateContext(display, config, EGL_NO_CONTEXT, NULL); |
|
132 |
} |
|
133 |
||
134 |
||
135 |
//get a Configuration, then get the context |
|
136 |
if( ::eglChooseConfig( display, |
|
137 |
getColorAttributes( EUidPixelFormatA_8, red, green, blue, alpha ), |
|
138 |
&config, |
|
139 |
1, |
|
140 |
&num_config ) == EGL_TRUE ) |
|
141 |
{ |
|
142 |
/* create an EGL rendering context */ |
|
143 |
ContextWithFormatA_8 = eglCreateContext(display, config, EGL_NO_CONTEXT, NULL); |
|
144 |
} |
|
145 |
||
146 |
||
147 |
EGLint attribs[] = { EGL_NONE }; |
|
148 |
DudSurface = ::eglCreatePbufferSurface( display, PoolContext, attribs ); |
|
149 |
||
150 |
||
151 |
TRACE( "PoolContext = %u\n", PoolContext ); |
|
152 |
TRACE( "ContextWithFormatARGB_8888_PRE = %u\n", ContextWithFormatARGB_8888_PRE ); |
|
153 |
TRACE( "ContextWithFormatARGB_8888 = %u\n", ContextWithFormatARGB_8888 ); |
|
154 |
TRACE( "ContextWithFormatXRGB_8888 = %u\n", ContextWithFormatXRGB_8888 ); |
|
155 |
TRACE( "ContextWithFormatRGB_565 = %u\n", ContextWithFormatRGB_565 ); |
|
156 |
TRACE( "ContextWithFormatA_8 = %u\n", ContextWithFormatA_8 ); |
|
157 |
TRACE( "DummySurface = %u\n", DudSurface ); |
|
158 |
||
159 |
m_Dpy = display; |
|
160 |
m_PoolContext = PoolContext; |
|
161 |
m_ContextWithFormatARGB_8888_PRE = ContextWithFormatARGB_8888_PRE; |
|
162 |
m_ContextWithFormatARGB_8888 = ContextWithFormatARGB_8888; |
|
163 |
m_ContextWithFormatXRGB_8888 = ContextWithFormatXRGB_8888; |
|
164 |
m_ContextWithFormatRGB_565 = ContextWithFormatRGB_565; |
|
165 |
m_ContextWithFormatA_8 = ContextWithFormatA_8; |
|
166 |
m_DudSurface = DudSurface; |
|
167 |
||
168 |
//m_currentFunctionCall.AppendEGLContext( PoolContext );//for sharing |
|
169 |
//m_currentFunctionCall.AppendEGLContext( ContextWithFormatARGB_8888_PRE );//for sharing |
|
170 |
//m_currentFunctionCall.AppendEGLContext( ContextWithFormatARGB_8888 ); |
|
171 |
//m_currentFunctionCall.AppendEGLContext( ContextWithFormatXRGB_8888 ); |
|
172 |
//m_currentFunctionCall.AppendEGLContext( ContextWithFormatRGB_565 ); |
|
173 |
//m_currentFunctionCall.AppendEGLContext( ContextWithFormatA_8 ); |
|
174 |
//m_currentFunctionCall.AppendEGLSurface( DudSurface ); |
|
175 |
||
176 |
TRACE("DriverAPIWrapper::CreatePoolContext() <-\n"); |
|
177 |
m_initialized = true; |
|
178 |
return 1; |
|
179 |
} |
|
180 |
||
181 |
||
182 |
||
183 |
||
184 |
/** |
|
185 |
* This code is supposed to create a pbuffer to back an sgImage |
|
186 |
* TODO: not tested at all |
|
187 |
*/ |
|
188 |
int DriverAPIWrapper::CreatePbufferSg( ) |
|
189 |
{ |
|
190 |
TRACE("DriverAPIWrapper::CreatePbufferSg ->\n"); |
|
191 |
EGLint w; |
|
192 |
EGLint h; |
|
193 |
||
194 |
if( !m_initialized ) |
|
195 |
{ |
|
196 |
CreatePoolContext(); |
|
197 |
} |
|
198 |
||
199 |
m_currentFunctionCall.GetEGLint( w, 0 ); |
|
200 |
m_currentFunctionCall.GetEGLint( h, 1 ); |
|
201 |
||
202 |
//eglCreatePbufferSurface |
|
203 |
EGLint pbuffer_surface_attribs[] = |
|
204 |
{ |
|
205 |
EGL_WIDTH, w, |
|
206 |
EGL_HEIGHT, h, |
|
207 |
EGL_NONE |
|
208 |
}; |
|
209 |
||
210 |
EGLSurface surface = ::eglCreatePbufferSurface( m_Dpy, m_PoolConfig, pbuffer_surface_attribs ); |
|
211 |
if( surface != EGL_NO_SURFACE ) |
|
212 |
{ |
|
213 |
m_SgImagePbuffers.push_back( surface ); |
|
214 |
} |
|
215 |
TRACE("DriverAPIWrapper::CreatePbufferSg surface=%u \n", surface ); |
|
216 |
m_currentFunctionCall.SetReturnValue( (TUint32)surface ); |
|
217 |
TRACE("DriverAPIWrapper::CreatePbufferSg <-\n"); |
|
218 |
return WriteReply(); |
|
219 |
} |
|
220 |
||
221 |
||
222 |
/** |
|
223 |
* This code is supposed to create a pbuffer to back an sgImage |
|
224 |
* TODO: not tested at all |
|
225 |
*/ |
|
226 |
int DriverAPIWrapper::CreateVGImageSg( ) |
|
227 |
{ |
|
228 |
TRACE("DriverAPIWrapper::CreateVGImageSg ->\n"); |
|
229 |
EGLint w; |
|
230 |
EGLint h; |
|
231 |
EGLint pixelformat; |
|
232 |
VGImage img; |
|
233 |
||
234 |
if( !m_initialized ) |
|
235 |
{ |
|
236 |
CreatePoolContext(); |
|
237 |
} |
|
238 |
||
239 |
EGLenum previousApi = ::eglQueryAPI(); |
|
240 |
::eglBindAPI( EGL_OPENVG_API ); |
|
241 |
||
242 |
m_currentFunctionCall.GetEGLint( w, 0 ); |
|
243 |
m_currentFunctionCall.GetEGLint( h, 1 ); |
|
244 |
m_currentFunctionCall.GetEGLint( pixelformat, 2 ); |
|
245 |
||
246 |
::eglMakeCurrent( m_Dpy, m_DudSurface, m_DudSurface, m_PoolContext ); |
|
247 |
||
248 |
VGImageFormat format = getVGColorFormat( pixelformat ); |
|
249 |
img = ::vgCreateImage(format, w, h, VG_IMAGE_QUALITY_NONANTIALIASED);//todo: quality; how to decide (TSgImageInfo only provides w,h, pixelformat)? |
|
250 |
if( img != VG_INVALID_HANDLE ) |
|
251 |
{ |
|
252 |
m_SgImageVGImages.push_back( img ); |
|
253 |
} |
|
254 |
||
255 |
m_currentFunctionCall.SetReturnValue( (TUint32)img ); |
|
256 |
::eglBindAPI( previousApi ); |
|
257 |
TRACE("DriverAPIWrapper::CreateVGImageSg <-\n"); |
|
258 |
return WriteReply(); |
|
259 |
} |
|
260 |
||
261 |
int DriverAPIWrapper::DeleteSgImage() |
|
262 |
{ |
|
263 |
EGLSurface surface; |
|
264 |
VGImage image; |
|
265 |
m_currentFunctionCall.GetEGLSurface( surface, 0 ); |
|
266 |
m_currentFunctionCall.GetVGParamValue( image, 1 ); |
|
267 |
||
268 |
eglDestroySurface( m_Dpy, surface ); |
|
269 |
vgDestroyImage( image ); |
|
270 |
||
271 |
return WriteReply(); |
|
272 |
} |
|
273 |
||
274 |
void DriverAPIWrapper::SyncVGImageFromPBuffer( EGLSurface aPbuffer, VGImage aVGImage ) |
|
275 |
{ |
|
276 |
TRACE("DriverAPIWrapper::SyncVGImageFromPBuffer ->\n"); |
|
277 |
//Store the previous current |
|
278 |
EGLDisplay disp = ::eglGetCurrentDisplay(); |
|
279 |
EGLSurface draw = ::eglGetCurrentSurface( EGL_DRAW ); |
|
280 |
EGLSurface read = ::eglGetCurrentSurface( EGL_READ ); |
|
281 |
EGLContext ctx = ::eglGetCurrentContext(); |
|
282 |
||
283 |
EGLint width(0); |
|
284 |
EGLint height(0); |
|
285 |
eglSurfaceAttrib( disp, aPbuffer, EGL_WIDTH, width ); |
|
286 |
eglSurfaceAttrib( disp, aPbuffer, EGL_HEIGHT, height ); |
|
287 |
||
288 |
::eglMakeCurrent( m_Dpy, aPbuffer, aPbuffer, m_PoolContext ); |
|
289 |
::vgGetPixels( aVGImage, 0, 0, 0, 0, width, height ); |
|
290 |
//Set the previous current |
|
291 |
::eglMakeCurrent( disp, draw, read, ctx ); |
|
292 |
TRACE("DriverAPIWrapper::SyncVGImageFromPBuffer <-\n"); |
|
293 |
} |
|
294 |
||
295 |
||
296 |
int DriverAPIWrapper::SyncPBufferFromVGImage( VGImage aSrc, VGint aWidth, VGint aHeight ) |
|
297 |
{ |
|
298 |
TRACE("DriverAPIWrapper::SyncPBufferFromVGImage ->\n"); |
|
299 |
if( ((VGboolean)vgGeti( VG_SCISSORING )) == VG_TRUE ) |
|
300 |
{ |
|
301 |
::vgSeti( VG_SCISSORING, VG_FALSE ); |
|
302 |
//The surface is the same size, as the vgimage |
|
303 |
::vgSetPixels( 0, 0, aSrc, 0, 0, aWidth, aHeight ); |
|
304 |
::vgSeti( VG_SCISSORING, VG_TRUE ); |
|
305 |
} |
|
306 |
else |
|
307 |
{ |
|
308 |
::vgSetPixels( 0, 0, aSrc, 0, 0, aWidth, aHeight ); |
|
309 |
} |
|
310 |
TRACE("DriverAPIWrapper::SyncPBufferFromVGImage <-\n"); |
|
311 |
return 0; |
|
312 |
} |
|
313 |
||
314 |
||
315 |
VGImageFormat DriverAPIWrapper::getVGColorFormat( int aPixelFormat ) |
|
316 |
{ |
|
317 |
switch( aPixelFormat ) |
|
318 |
{ |
|
319 |
case EUidPixelFormatXRGB_8888: |
|
320 |
{ |
|
321 |
return VG_sXRGB_8888; |
|
322 |
} |
|
323 |
case EUidPixelFormatARGB_8888: |
|
324 |
{ |
|
325 |
return VG_sARGB_8888; |
|
326 |
} |
|
327 |
case EUidPixelFormatARGB_8888_PRE: |
|
328 |
{ |
|
329 |
return VG_sARGB_8888_PRE; |
|
330 |
} |
|
331 |
case EUidPixelFormatRGB_565: |
|
332 |
{ |
|
333 |
return VG_sRGB_565; |
|
334 |
} |
|
335 |
case EUidPixelFormatA_8: |
|
336 |
{ |
|
337 |
return VG_A_8; |
|
338 |
} |
|
339 |
default: |
|
340 |
{ |
|
341 |
return VG_sARGB_8888; |
|
342 |
} |
|
343 |
} |
|
344 |
} |
|
345 |
||
346 |
EGLint* DriverAPIWrapper::getColorAttributes( int aPixelFormat, int& aRed, int& aGreen, int& aBlue, int& aAlpha ) |
|
347 |
{ |
|
348 |
switch( aPixelFormat ) |
|
349 |
{ |
|
350 |
case EUidPixelFormatXRGB_8888: |
|
351 |
{ |
|
352 |
aRed = aGreen = aBlue = aAlpha = 8; |
|
353 |
break; |
|
354 |
} |
|
355 |
case EUidPixelFormatARGB_8888: |
|
356 |
{ |
|
357 |
aRed = aGreen = aBlue = aAlpha = 8; |
|
358 |
break; |
|
359 |
} |
|
360 |
case EUidPixelFormatARGB_8888_PRE: |
|
361 |
{ |
|
362 |
aRed = aGreen = aBlue = aAlpha = 8; |
|
363 |
break; |
|
364 |
} |
|
365 |
case EUidPixelFormatRGB_565: |
|
366 |
{ |
|
367 |
aRed = 5; aGreen = 6; aBlue = 5; aAlpha = 0; |
|
368 |
break; |
|
369 |
} |
|
370 |
case EUidPixelFormatA_8: |
|
371 |
{ |
|
372 |
aRed = aGreen = aBlue = 0; aAlpha = 8; |
|
373 |
break; |
|
374 |
} |
|
375 |
default: |
|
376 |
{ |
|
377 |
aRed = aGreen = aBlue = aAlpha = 0; |
|
378 |
break; |
|
379 |
} |
|
380 |
} |
|
381 |
static EGLint attribs[] = |
|
382 |
{ |
|
383 |
EGL_RED_SIZE, aRed, |
|
384 |
EGL_GREEN_SIZE, aGreen, |
|
385 |
EGL_BLUE_SIZE, aBlue, |
|
386 |
EGL_ALPHA_SIZE, aAlpha, |
|
387 |
EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT, |
|
388 |
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, |
|
389 |
EGL_NONE |
|
390 |
}; |
|
391 |
return attribs; |
|
392 |
} |
|
393 |