WORK-IN-PROGRESS commit: threads working in symbian s60
[spandex:spandex.git] / sct / common / modules / openvg / sct_openvginfoaction.c
1 /*
2  * Spandex benchmark and test framework.
3  *
4  * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
5  *
6  * Contact: Kari J. Kangas <kari.j.kangas@nokia.com>
7  *
8  *   This framework is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU Lesser General Public License as published by the
10  * Free Software Foundation, version 2.1 of the License.
11  *
12  *   This framework is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  *   You should have received a copy of the GNU Lesser General Public License
18  * along with this framework; if not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21
22 #include "sct_openvginfoaction.h"
23 #include "sct_sicommon.h"
24 #include "sct_utils.h"
25 #include "sct_vg.h"
26
27 #include <stdio.h>
28 #include <string.h>
29
30 /*!
31  *
32  */
33 static SCTBoolean sctiReportHardwareCapabilities( SCTAttributeList* attributes );
34
35 /*!
36  *
37  *
38  */
39 void* sctiCreateOpenVGInfoActionContext( void* moduleContext, SCTAttributeList* attributes )
40 {
41     SCTOpenVGInfoActionContext* context;
42
43     SCT_ASSERT_ALWAYS( moduleContext != NULL );
44     SCT_ASSERT_ALWAYS( attributes != NULL );
45
46     context = ( SCTOpenVGInfoActionContext* )( siCommonMemoryAlloc( NULL, sizeof( SCTOpenVGInfoActionContext ) ) );
47     if( context == NULL )
48     {
49         SCT_LOG_ERROR( "Allocation failed in Info@OpenVG action context creation." );
50         return NULL;
51     }
52     memset( context, 0, sizeof( SCTOpenVGInfoActionContext ) );
53
54     context->reported = SCT_FALSE;
55
56     if( sctiParseOpenVGInfoActionAttributes( &( context->data ), attributes ) == SCT_FALSE )
57     {
58         sctiDestroyOpenVGInfoActionContext( context );
59         return NULL;
60     }
61
62     return context;
63 }
64
65 /*!
66  *
67  *
68  */
69 void sctiDestroyOpenVGInfoActionContext( void* context )
70 {
71     if( context == NULL )
72     {
73         return;
74     }
75     siCommonMemoryFree( NULL, context );
76 }
77
78 /*!
79  *
80  *
81  */
82 SCTBoolean sctiOpenVGInfoActionExecute( SCTAction* action, int frameNumber )
83 {
84     SCTOpenVGInfoActionContext* context;
85     SCTAttributeList*           attributes;
86     VGErrorCode                 err;    
87     SCTBoolean                  status          = SCT_TRUE;
88     const char*                 str;
89
90     SCT_ASSERT_ALWAYS( action != NULL );
91     SCT_ASSERT_ALWAYS( action->context != NULL );
92     SCT_USE_VARIABLE( frameNumber );
93
94     context = ( SCTOpenVGInfoActionContext* )( action->context );
95
96     if( context->reported == SCT_TRUE )
97     {
98         return SCT_TRUE;
99     }
100
101     attributes = sctCreateAttributeList();
102     if( attributes == NULL )
103     {
104         SCT_LOG_ERROR( "Allocation failed in Info@OpenVG action execute." );
105         return SCT_FALSE;
106     }
107     
108     /* Store VG vendor. */
109     str = ( const char* )( vgGetString( VG_VENDOR ) );
110     if( str == NULL || 
111         sctAddNameValueToList( attributes, "VG vendor", str ) == SCT_FALSE )
112     {
113         status = SCT_FALSE;
114     }
115     
116     /* Store VG renderer. */
117     str = ( const char* )( vgGetString( VG_RENDERER ) );
118     if( str == NULL ||
119         sctAddNameValueToList( attributes, "VG renderer", str ) == SCT_FALSE )
120     {
121         status = SCT_FALSE;
122     }
123
124     /* Store VG version. */
125     str = ( const char* )( vgGetString( VG_VERSION ) );
126     if( str == NULL ||
127         sctAddNameValueToList( attributes, "VG version", str ) == SCT_FALSE )
128     {
129         status = SCT_FALSE;
130     }
131
132     /* Store VG extensions string. */
133     str = ( const char* )( vgGetString( VG_EXTENSIONS ) );
134     if( str == NULL ||
135         sctAddNameValueToList( attributes, "VG extensions", str ) == SCT_FALSE )
136     {
137         status = SCT_FALSE;
138     }
139
140     if( status == SCT_FALSE )
141     {
142         SCT_LOG_ERROR( "List add failed in Info@OpenVG action execute." );
143     }
144
145     /* Report hardware capabilities. */
146     if( status == SCT_TRUE && sctiReportHardwareCapabilities( attributes ) == SCT_FALSE )
147     {
148         SCT_LOG_ERROR( "Reporting hardware capabilities failed in Info@OpenVG action execute." );
149         status = SCT_FALSE;
150     }
151
152     if( status == SCT_TRUE )
153     {
154         err = vgGetError();
155         if( err != VG_NO_ERROR )
156         {
157             char buf[ 256 ];
158             sprintf( buf, "VG error %s in Info@OpenVG action execute.", sctiOpenVGGetErrorString( err ) );
159             SCT_LOG_ERROR( buf );
160             sctiOpenVGClearVGError();
161             status = SCT_FALSE;
162         }
163     }
164
165     /* Write a section to output file. *SLIGHT HACK* */
166     if( status == SCT_TRUE && sctReportSection( "OpenVG", "MODULE", attributes ) == SCT_FALSE )
167     {
168         SCT_LOG_ERROR( "Report section failed in Info@OpenVG action execute." );
169         status = SCT_FALSE;
170     }
171
172     sctDestroyAttributeList( attributes );
173
174     context->reported = SCT_TRUE;
175
176     return status;
177 }
178
179 /*!
180  *
181  *
182  */
183 void sctiOpenVGInfoActionDestroy( SCTAction* action )
184 {
185     SCTOpenVGInfoActionContext* context;
186
187     SCT_ASSERT_ALWAYS( action != NULL );
188
189     context = ( SCTOpenVGInfoActionContext* )( action->context );
190
191     action->context = NULL;
192     sctiDestroyOpenVGInfoActionContext( context );
193 }
194
195 /*!
196  *
197  *
198  */
199 static const char* _OpenVGImageFormatStrings[] = { "VG_sRGBX_8888",
200                                                    "VG_sRGBA_8888",
201                                                    "VG_sRGBA_8888_PRE",
202                                                    "VG_sRGB_565",
203                                                    "VG_sRGBA_5551",
204                                                    "VG_sRGBA_4444",
205                                                    "VG_sL_8",
206                                                    "VG_lRGBX_8888",
207                                                    "VG_lRGBA_8888",
208                                                    "VG_lRGBA_8888_PRE",
209                                                    "VG_lL_8",
210                                                    "VG_A_8",
211                                                    "VG_BW_1",
212 #if defined( OPENVG_VERSION_1_1 )
213                                                    "VG_A_1",
214                                                    "VG_A_4",
215 #endif /* defined( OPENVG_VERSION_1_1 ) */
216                                                    "VG_sXRGB_8888",
217                                                    "VG_sARGB_8888",
218                                                    "VG_sARGB_8888_PRE",
219                                                    "VG_sARGB_1555",
220                                                    "VG_sARGB_4444",
221                                                    "VG_lXRGB_8888",
222                                                    "VG_lARGB_8888",
223                                                    "VG_lARGB_8888_PRE",
224                                                    "VG_sBGRX_8888",
225                                                    "VG_sBGRA_8888",
226                                                    "VG_sBGRA_8888_PRE",
227                                                    "VG_sBGR_565",
228                                                    "VG_sBGRA_5551",
229                                                    "VG_sBGRA_4444",
230                                                    "VG_lBGRX_8888",
231                                                    "VG_lBGRA_8888",
232                                                    "VG_lBGRA_8888_PRE",
233                                                    "VG_sXBGR_8888",
234                                                    "VG_sABGR_8888",
235                                                    "VG_sABGR_8888_PRE",
236                                                    "VG_sABGR_1555",
237                                                    "VG_sABGR_4444",
238                                                    "VG_lXBGR_8888",
239                                                    "VG_lABGR_8888",
240                                                    "VG_lABGR_8888_PRE" };
241
242 /*!
243  *
244  *
245  */
246 static const int _OpenVGImageFormatValues[] = { VG_sRGBX_8888,
247                                                 VG_sRGBA_8888,
248                                                 VG_sRGBA_8888_PRE,
249                                                 VG_sRGB_565,
250                                                 VG_sRGBA_5551,
251                                                 VG_sRGBA_4444,
252                                                 VG_sL_8,
253                                                 VG_lRGBX_8888,
254                                                 VG_lRGBA_8888,
255                                                 VG_lRGBA_8888_PRE,
256                                                 VG_lL_8,
257                                                 VG_A_8,
258                                                 VG_BW_1,
259 #if defined( OPENVG_VERSION_1_1 )
260                                                 VG_A_1,
261                                                 VG_A_4,
262 #endif /* defined( OPENVG_VERSION_1_1 ) */
263                                                 VG_sXRGB_8888,
264                                                 VG_sARGB_8888,
265                                                 VG_sARGB_8888_PRE,
266                                                 VG_sARGB_1555,
267                                                 VG_sARGB_4444,
268                                                 VG_lXRGB_8888,
269                                                 VG_lARGB_8888,
270                                                 VG_lARGB_8888_PRE,
271                                                 VG_sBGRX_8888,
272                                                 VG_sBGRA_8888,
273                                                 VG_sBGRA_8888_PRE,
274                                                 VG_sBGR_565,
275                                                 VG_sBGRA_5551,
276                                                 VG_sBGRA_4444,
277                                                 VG_lBGRX_8888,
278                                                 VG_lBGRA_8888,
279                                                 VG_lBGRA_8888_PRE,
280                                                 VG_sXBGR_8888,
281                                                 VG_sABGR_8888,
282                                                 VG_sABGR_8888_PRE,
283                                                 VG_sABGR_1555,
284                                                 VG_sABGR_4444,
285                                                 VG_lXBGR_8888,
286                                                 VG_lABGR_8888,
287                                                 VG_lABGR_8888_PRE };
288
289 /*!
290  *
291  *
292  */
293 static const char* _OpenVGPathDatatypeStrings[] = { "VG_PATH_DATATYPE_S_8",
294                                                     "VG_PATH_DATATYPE_S_16",
295                                                     "VG_PATH_DATATYPE_S_32",
296                                                     "VG_PATH_DATATYPE_F" };
297
298 /*!
299  *
300  *
301  */
302 static const int _OpenVGPathDatatypeValues[] = { VG_PATH_DATATYPE_S_8,
303                                                  VG_PATH_DATATYPE_S_16,
304                                                  VG_PATH_DATATYPE_S_32,
305                                                  VG_PATH_DATATYPE_F };
306
307 /*!
308  *
309  */
310 #define OPENVG_INFO_BUF1_LENGTH    128
311 #define OPENVG_INFO_BUF2_LENGTH    8
312 /*
313  *
314  *
315  */
316 static SCTBoolean sctiReportHardwareCapabilities( SCTAttributeList* attributes )
317 {
318     char                                buf1[ OPENVG_INFO_BUF1_LENGTH ];
319     char                                buf2[ OPENVG_INFO_BUF2_LENGTH ];
320     VGHardwareQueryResult               hwQueryResult;
321     int                                 i;
322     const char*                         imageFormatString       = "HWA image format %s";
323     const char*                         pathDatatypeString      = "HWA path datatype %s";
324
325     SCT_ASSERT( attributes != NULL );
326
327     for( i = 0; i < SCT_ARRAY_LENGTH( _OpenVGImageFormatValues ); ++i )
328     {
329         hwQueryResult = vgHardwareQuery( VG_IMAGE_FORMAT_QUERY, _OpenVGImageFormatValues[ i ] );
330
331         // Beware buffer overrun
332         SCT_ASSERT( ( strlen( _OpenVGImageFormatStrings[ i ] ) + strlen( imageFormatString ) ) < OPENVG_INFO_BUF1_LENGTH );
333
334         sprintf( buf1, imageFormatString, _OpenVGImageFormatStrings[ i ] );
335
336         if( hwQueryResult == VG_HARDWARE_ACCELERATED )
337         {
338             strcpy( buf2, "YES" );
339         }
340         else
341         {
342             strcpy( buf2, "NO" );
343         }
344
345         if( sctAddNameValueToList( attributes, buf1, buf2 ) == SCT_FALSE )
346         {
347             return SCT_FALSE;
348         }
349     }
350
351     for( i = 0; i < SCT_ARRAY_LENGTH( _OpenVGPathDatatypeValues ); ++i )
352     {
353         hwQueryResult = vgHardwareQuery( VG_PATH_DATATYPE_QUERY, _OpenVGPathDatatypeValues[ i ] );
354
355         // Beware buffer overrun
356         SCT_ASSERT( ( strlen( _OpenVGPathDatatypeStrings[ i ] ) + strlen( pathDatatypeString ) ) < OPENVG_INFO_BUF1_LENGTH );
357
358         sprintf( buf1, pathDatatypeString, _OpenVGPathDatatypeStrings[ i ] );
359
360         if( hwQueryResult == VG_HARDWARE_ACCELERATED )
361         {
362             strcpy( buf2, "YES" );
363         }
364         else
365         {
366             strcpy( buf2, "NO" );
367         }
368
369         if( sctAddNameValueToList( attributes, buf1, buf2 ) == SCT_FALSE )
370         {
371             return SCT_FALSE;
372         }
373     }
374
375     return SCT_TRUE;
376 }