~linaro-graphics-wg/+junk/spandex-package

« back to all changes in this revision

Viewing changes to sct/common/modules/opengles2/sct_opengles2decodeaction.c

  • Committer: Alexandros Frantzis
  • Date: 2011-05-04 08:50:52 UTC
  • Revision ID: alexandros.frantzis@linaro.org-20110504085052-88gps4jrg317s6lc
Tags: upstream-1.1.3~git20110502.0ae20368
ImportĀ upstreamĀ versionĀ 1.1.3~git20110502.0ae20368

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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_opengles2decodeaction.h"
 
23
#include "sct_sicommon.h"
 
24
#include "sct_sifile.h"
 
25
#include "sct_utils.h"
 
26
#include "sct_gl2.h"
 
27
 
 
28
#include <stdio.h>
 
29
#include <string.h>
 
30
 
 
31
#define SCT_PVRTEXTOOL3_HEADER_LENGTH   52
 
32
 
 
33
/*!
 
34
 *
 
35
 *
 
36
 */
 
37
void* sctiCreateOpenGLES2DecodeActionContext( void* moduleContext, SCTAttributeList* attributes )
 
38
{
 
39
    SCTOpenGLES2DecodeActionContext*    context;
 
40
 
 
41
    SCT_ASSERT_ALWAYS( moduleContext != NULL );
 
42
    SCT_ASSERT_ALWAYS( attributes != NULL );
 
43
 
 
44
    context = ( SCTOpenGLES2DecodeActionContext* )( siCommonMemoryAlloc( NULL, sizeof( SCTOpenGLES2DecodeActionContext ) ) );
 
45
    if( context == NULL )
 
46
    {
 
47
        SCT_LOG_ERROR( "Allocation failed in Decode@OpenGLES2 action context creation." );
 
48
        return NULL;
 
49
    }
 
50
    memset( context, 0, sizeof( SCTOpenGLES2DecodeActionContext ) );
 
51
 
 
52
    context->moduleContext = ( SCTOpenGLES2ModuleContext* )( moduleContext );
 
53
 
 
54
    if( sctiParseOpenGLES2DecodeActionAttributes( &( context->data ), attributes ) == SCT_FALSE )
 
55
    {
 
56
        sctiDestroyOpenGLES2DecodeActionContext( context );
 
57
        return NULL;
 
58
    }
 
59
 
 
60
    if( sctiOpenGLES2ModuleIsValidDataIndex( context->moduleContext, context->data.srcDataIndex ) == SCT_FALSE )
 
61
    {
 
62
        sctiDestroyOpenGLES2DecodeActionContext( context );
 
63
        SCT_LOG_ERROR( "Invalid source data index in Decode@OpenGLES2 context creation." );
 
64
        return NULL;
 
65
    }
 
66
 
 
67
    if( sctiOpenGLES2ModuleIsValidDataIndex( context->moduleContext, context->data.dstDataIndex ) == SCT_FALSE )
 
68
    {
 
69
        sctiDestroyOpenGLES2DecodeActionContext( context );
 
70
        SCT_LOG_ERROR( "Invalid destination data index in Decode@OpenGLES2 context creation." );
 
71
        return NULL;
 
72
    }
 
73
 
 
74
    return context;
 
75
}
 
76
 
 
77
/*!
 
78
 *
 
79
 *
 
80
 */
 
81
void sctiDestroyOpenGLES2DecodeActionContext( void* context )
 
82
{
 
83
    if( context == NULL )
 
84
    {
 
85
        return;
 
86
    }
 
87
   
 
88
    siCommonMemoryFree( NULL, context );
 
89
}
 
90
 
 
91
/*!
 
92
 *
 
93
 *
 
94
 */
 
95
SCTBoolean sctiOpenGLES2DecodeActionInit( SCTAction* action, SCTBenchmark* benchmark )
 
96
{
 
97
    SCT_ASSERT_ALWAYS( action != NULL );
 
98
    SCT_ASSERT_ALWAYS( action->context != NULL );
 
99
    SCT_ASSERT_ALWAYS( benchmark != NULL );
 
100
 
 
101
    return SCT_TRUE;
 
102
}
 
103
 
 
104
/*!
 
105
 *
 
106
 *
 
107
 */
 
108
SCTBoolean sctiOpenGLES2DecodeActionExecute( SCTAction* action, int frameNumber )
 
109
{
 
110
    SCTOpenGLES2DecodeActionContext*    context;
 
111
    OpenGLES2DecodeActionData*          data;
 
112
    SCTOpenGLES2Data*                   srcData;
 
113
    SCTOpenGLES2Data*                   dstData;
 
114
    unsigned char*                      ptr          = NULL;
 
115
    int                                 length       = 0;
 
116
 
 
117
    SCT_ASSERT( action != NULL );
 
118
    SCT_ASSERT( action->context != NULL );
 
119
    SCT_USE_VARIABLE( frameNumber );
 
120
 
 
121
    context = ( SCTOpenGLES2DecodeActionContext* )( action->context );
 
122
    data    = &( context->data );
 
123
 
 
124
    srcData = sctiOpenGLES2ModuleGetData( context->moduleContext, data->srcDataIndex );
 
125
    if( srcData == NULL )
 
126
    {
 
127
        SCT_LOG_ERROR( "Invalid source data index in Decode@OpenGLES2 action execute." );
 
128
        return SCT_FALSE;
 
129
    }
 
130
 
 
131
    if( data->encoder == DECODE_ENCODER_PVRTEXTOOL3 )
 
132
    {
 
133
        if( srcData->length <= SCT_PVRTEXTOOL3_HEADER_LENGTH )
 
134
        {
 
135
            SCT_LOG_ERROR( "Invalid PVRTEXTOOL3 data in Decode@OpenGLES2 action execute." );
 
136
            return SCT_FALSE;
 
137
        }
 
138
 
 
139
        ptr    = &( ( unsigned char* )( srcData->data ) )[ SCT_PVRTEXTOOL3_HEADER_LENGTH ];
 
140
        length = srcData->length - SCT_PVRTEXTOOL3_HEADER_LENGTH;
 
141
    }
 
142
    else
 
143
    {
 
144
        SCT_LOG_ERROR( "Unexpected encoder in Decode@OpenGLES2 action execute." );
 
145
        return SCT_FALSE;
 
146
    }
 
147
    
 
148
    dstData = sctiOpenGLES2ModuleGetData( context->moduleContext, data->dstDataIndex );
 
149
    if( dstData != NULL )
 
150
    {
 
151
        if( dstData->length != length )
 
152
        {
 
153
            SCT_LOG_ERROR( "Destination data index already in use in Decode@OpenGLES2 action execute." );
 
154
            return SCT_FALSE;
 
155
        }
 
156
 
 
157
        memcpy( dstData->data, ptr, length );
 
158
    }
 
159
    else
 
160
    {
 
161
        dstData = sctOpenGLES2CreateData( ptr, length, SCT_TRUE );
 
162
        if( dstData == NULL )
 
163
        {
 
164
            SCT_LOG_ERROR( "Destination data allocation failed in Decode@OpenGLES2 action execute." );
 
165
            return SCT_FALSE;
 
166
        }
 
167
 
 
168
        sctiOpenGLES2ModuleSetData( context->moduleContext, data->dstDataIndex, dstData );
 
169
    }
 
170
 
 
171
    return SCT_TRUE;
 
172
}
 
173
 
 
174
/*!
 
175
 *
 
176
 *
 
177
 */
 
178
void sctiOpenGLES2DecodeActionTerminate( SCTAction* action )
 
179
{
 
180
    SCTOpenGLES2DecodeActionContext*    context;
 
181
 
 
182
    SCT_ASSERT_ALWAYS( action != NULL );
 
183
    SCT_ASSERT_ALWAYS( action->context != NULL );
 
184
 
 
185
    context = ( SCTOpenGLES2DecodeActionContext* )( action->context );
 
186
 
 
187
    sctiOpenGLES2ModuleDeleteData( context->moduleContext, context->data.dstDataIndex );
 
188
}
 
189
 
 
190
/*!
 
191
 *
 
192
 *
 
193
 */
 
194
void sctiOpenGLES2DecodeActionDestroy( SCTAction* action )
 
195
{
 
196
    SCTOpenGLES2DecodeActionContext*    context;
 
197
 
 
198
    SCT_ASSERT_ALWAYS( action != NULL );
 
199
 
 
200
    context = ( SCTOpenGLES2DecodeActionContext* )( action->context );
 
201
 
 
202
    action->context = NULL;
 
203
    sctiDestroyOpenGLES2DecodeActionContext( context );
 
204
}