80
|
1 |
/*
|
87
|
2 |
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
|
80
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: General definitions
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#ifndef M2GGENERAL_H
|
|
19 |
#define M2GGENERAL_H
|
|
20 |
|
|
21 |
#include <e32base.h>
|
|
22 |
#include "jstringutils.h"
|
|
23 |
#include "jni.h"
|
87
|
24 |
|
80
|
25 |
|
|
26 |
#if defined ( _DEBUG )
|
|
27 |
#if defined ( __WINSCW__ )
|
|
28 |
// #define M2G_DEBUG
|
|
29 |
#endif // __WINSCW__
|
|
30 |
#endif // _DEBUG
|
|
31 |
|
|
32 |
#ifdef M2G_DEBUG
|
|
33 |
// #define M2G_INFO_POPUP
|
|
34 |
#define M2G_STATISTIC_DEBUG
|
|
35 |
#include <flogger.h>
|
|
36 |
#include <jdebug.h>
|
|
37 |
#ifdef M2G_STATISTIC_DEBUG
|
|
38 |
#include <HAL.h>
|
|
39 |
#include <hal_data.h>
|
|
40 |
#endif // M2G_STATISTIC_DEBUG
|
|
41 |
#endif // M2G_DEBUG
|
|
42 |
|
|
43 |
#include "JcfAutoPtr.h"// cfcommon::auto_ptr<>
|
|
44 |
#include "M2GNamespace.h"
|
|
45 |
|
|
46 |
//#if defined( __cplusplus )
|
|
47 |
//extern "C" {
|
|
48 |
//#endif
|
|
49 |
|
|
50 |
M2G_NS_START
|
|
51 |
|
|
52 |
// CONSTANTS
|
|
53 |
// == ALPHA BLEND CONSTANTS ==
|
|
54 |
const TUint8 KFullOpaque = 0xFF;
|
|
55 |
const TUint8 KFullTransparent = 0x00;
|
|
56 |
|
|
57 |
// == ERROR TEXT CONSTANTS ==
|
|
58 |
_LIT8(KM2GEmptyString8, "");
|
|
59 |
_LIT(KM2GEmptyString, "");
|
|
60 |
_LIT(KGraphicsContextErrText, "Invalid M2G graphics context");
|
|
61 |
_LIT(KOffscreenErrText, "Invalid M2G offscreen bitmap");
|
|
62 |
_LIT(KSvgProxyPointerErrText, "Invalid SVG proxy pointer");
|
|
63 |
_LIT(KSvgEnginePointerErrText, "Invalid SVG engine pointer");
|
|
64 |
_LIT(KSvgTargetGraphicsPointerErrText, "Invalid target graphics pointer");
|
|
65 |
_LIT(KNotSupportedErrText, "Not supported");
|
|
66 |
|
|
67 |
// == ERROR CODE CONSTANTS ==
|
|
68 |
const TInt KM2GOk = KErrNone;
|
|
69 |
const TInt KM2GNotOk = KErrGeneral;
|
|
70 |
const TInt KM2GHandleNotOk = KErrBadHandle;
|
|
71 |
const TInt KM2GArgNotOk = KErrArgument;
|
|
72 |
const TInt KM2GSupportedNotOk = KErrNotSupported;
|
|
73 |
const TInt KM2GMemoryNotOk = KErrNoMemory;
|
|
74 |
|
|
75 |
// Own error codes
|
|
76 |
const TInt KM2GIOException = -10;
|
|
77 |
|
|
78 |
// Java exception class names
|
|
79 |
_LIT8(KJavaExceptionClass, "java/lang/Exception");
|
|
80 |
_LIT8(KJavaIOExceptionClass, "java/io/IOException");
|
|
81 |
_LIT8(KJavaOutOfMemoryErrorClass, "java/lang/OutOfMemoryError");
|
|
82 |
_LIT8(KJavaNullPointerException, "java/lang/NullPointerException");
|
|
83 |
|
|
84 |
// == SVG CONSTANTS ==
|
|
85 |
const TInt KM2GRestartAttribute = 114; // M2GSVGConstants.AT_RESTART
|
|
86 |
const TInt KM2GRestartNever = 471; // M2GSVGConstants.RESTART_NEVER
|
|
87 |
const TInt KM2GRestartWhenNotActive = 472; // M2GSVGConstants.RESTART_WHENNOTACTIVE
|
|
88 |
|
|
89 |
// == HANDLE MACROS ==
|
|
90 |
#define M2G_INVALID_HANDLE /**/ 0
|
|
91 |
|
|
92 |
// FORWARD DECLARATIONS
|
|
93 |
class RWriteStream;
|
|
94 |
|
|
95 |
// FUNCTION PROTOTYPES
|
|
96 |
|
|
97 |
// CLASS DECLARATION
|
|
98 |
/**
|
|
99 |
* General static methods
|
|
100 |
* @lib -
|
|
101 |
* @series Series S60 3.0
|
|
102 |
*/
|
|
103 |
class M2GGeneral
|
|
104 |
{
|
|
105 |
public: // STATIC METHODS
|
|
106 |
/**
|
|
107 |
* Check if a handle is valid
|
|
108 |
* @since Series S60 3.0
|
|
109 |
* @param aHandle
|
|
110 |
* @return ETrue if a handle is valid.
|
|
111 |
*/
|
|
112 |
template<typename T>
|
|
113 |
inline static TBool IsHandleValid(const T& aHandle)
|
|
114 |
{
|
|
115 |
return ((aHandle == M2G_INVALID_HANDLE) ? EFalse : ETrue);
|
|
116 |
}
|
|
117 |
|
|
118 |
/**
|
|
119 |
* Returns min
|
|
120 |
* @since Series S60 3.0
|
|
121 |
* @param a Left parameter
|
|
122 |
* @param b Right parameter
|
|
123 |
* @return Returns min
|
|
124 |
*/
|
|
125 |
template<typename T>
|
|
126 |
inline static T Min(const T& a, const T& b)
|
|
127 |
{
|
|
128 |
return ((a) <= (b) ? (a) : (b));
|
|
129 |
}
|
|
130 |
|
|
131 |
|
|
132 |
/**
|
|
133 |
* Returns max
|
|
134 |
* @since Series S60 3.0
|
|
135 |
* @param a Left parameter
|
|
136 |
* @param b Right parameter
|
|
137 |
* @return Returns max
|
|
138 |
*/
|
|
139 |
template<typename T>
|
|
140 |
inline static T Max(const T& a, const T& b)
|
|
141 |
{
|
|
142 |
return ((a) >= (b) ? (a) : (b));
|
|
143 |
}
|
|
144 |
/**
|
|
145 |
* Instantiates an Java exception object with the message specified by
|
|
146 |
* message, and causes that exception to be thrown in Java side. A thrown
|
|
147 |
* exception will be pending in the current thread, but does not
|
|
148 |
* immediately disrupt native code execution.
|
|
149 |
* @param aEnv pointer to JNI environment
|
|
150 |
* @param aName The name of a java.lang.Throwable class.
|
|
151 |
* @param aMsg The message used to construct the java.lang.Throwable object.
|
|
152 |
*/
|
|
153 |
static void RaiseException(
|
|
154 |
JNIEnv* aEnv,
|
|
155 |
const TDesC8& aName,
|
|
156 |
const TUint8* aMsg = (STATIC_CAST(const TDesC8&, KM2GEmptyString8)).Ptr());
|
|
157 |
|
|
158 |
/**
|
|
159 |
* Instantiates an Java exception object specified by error code,
|
|
160 |
* and causes that exception to be thrown in Java side.
|
|
161 |
* @param aEnv pointer to JNI environment
|
|
162 |
* @param aErrorCode Error code.
|
|
163 |
* @return Value passed in is returned if not an error.
|
|
164 |
*/
|
|
165 |
static TInt CheckErrorCode(JNIEnv* aEnv, TInt aErrorCode);
|
|
166 |
|
|
167 |
/**
|
|
168 |
* If handle is invalid instantiates an Java exception object,
|
|
169 |
* and causes that exception to be thrown in Java side.
|
|
170 |
* @param aEnv pointer to JNI environment
|
|
171 |
* @param aHandle Handle.
|
|
172 |
* @return Handle passed in is returned if it is not invalid.
|
|
173 |
*/
|
|
174 |
static TInt CheckHandle(JNIEnv* aEnv, TInt aHandle);
|
|
175 |
|
|
176 |
/**
|
|
177 |
* If handle is invalid or error code matches instantiates an
|
|
178 |
* Java exception object, and causes that exception to be thrown in Java side.
|
|
179 |
* @param aEnv pointer to JNI environment
|
|
180 |
* @param aErrorCode
|
|
181 |
* @param aHandle Handle.
|
|
182 |
* @param aErrorResult Result that is returned if error.
|
|
183 |
* @return Handle passed in is returned if no error otherwise the
|
|
184 |
* .aErrorResult is returned.
|
|
185 |
*/
|
|
186 |
static TInt CheckErrorCodeAndHandle(
|
|
187 |
JNIEnv* aEnv, TInt aErrorCode, TInt aHandle, TInt aErrorResult);
|
|
188 |
|
|
189 |
/**
|
|
190 |
* Shows pop up dialog on the emulator
|
|
191 |
* @since Series S60 3.1
|
|
192 |
* @param aLine1
|
|
193 |
* @param aLine2
|
|
194 |
*/
|
|
195 |
#ifdef M2G_INFO_POPUP
|
|
196 |
static void PopupInfo(
|
|
197 |
const TDesC& aLine1,
|
|
198 |
const TDesC& aLine2);
|
|
199 |
#endif // M2G_INFO_POPUP
|
|
200 |
|
|
201 |
|
|
202 |
/**
|
|
203 |
* Data array wrapper.
|
|
204 |
* @series Series S60 3.1
|
|
205 |
*/
|
|
206 |
template <typename T>
|
|
207 |
class TDataArrayPtr
|
|
208 |
{
|
|
209 |
|
|
210 |
public: // METHODS
|
|
211 |
/**
|
|
212 |
* Ctor
|
|
213 |
*/
|
|
214 |
TDataArrayPtr(T* aData = 0, TInt aSize = 0) : iData(aData), iSize(aSize) {}
|
|
215 |
|
|
216 |
/**
|
|
217 |
* Return pointer to a data
|
|
218 |
* @return Pointer
|
|
219 |
*/
|
|
220 |
inline T* Begin()
|
|
221 |
{
|
|
222 |
return iData;
|
|
223 |
}
|
|
224 |
|
|
225 |
/**
|
|
226 |
* Check if data is valid
|
|
227 |
* @return ETrue if ok
|
|
228 |
*/
|
|
229 |
inline TBool IsValid()
|
|
230 |
{
|
|
231 |
return (((iData != NULL) && (iSize > 0)) ? ETrue : EFalse);
|
|
232 |
}
|
|
233 |
|
|
234 |
/**
|
|
235 |
* Return data size
|
|
236 |
* @return Length
|
|
237 |
*/
|
|
238 |
inline TInt Length()
|
|
239 |
{
|
|
240 |
return iSize;
|
|
241 |
}
|
|
242 |
|
|
243 |
/**
|
|
244 |
* Operator [] const
|
|
245 |
*/
|
|
246 |
inline const T& operator[](TInt aIndex) const
|
|
247 |
{
|
|
248 |
return iData[ aIndex ];
|
|
249 |
}
|
|
250 |
|
|
251 |
/**
|
|
252 |
* Operator []
|
|
253 |
*/
|
|
254 |
inline T& operator[](TInt aIndex)
|
|
255 |
{
|
|
256 |
return iData[ aIndex ];
|
|
257 |
}
|
|
258 |
|
|
259 |
private: // METHODS
|
|
260 |
|
|
261 |
/**
|
|
262 |
* Copy ctor
|
|
263 |
* @param aRhs Right side array
|
|
264 |
*/
|
|
265 |
TDataArrayPtr(const TDataArrayPtr& aRhs);
|
|
266 |
|
|
267 |
/**
|
|
268 |
* Assignment operator
|
|
269 |
* @param aRhs Right side array
|
|
270 |
* @return Array object
|
|
271 |
*/
|
|
272 |
TDataArrayPtr& operator=(const TDataArrayPtr& aRhs);
|
|
273 |
|
|
274 |
public: // VARIABLES
|
|
275 |
T* iData;
|
|
276 |
TInt iSize;
|
|
277 |
};
|
|
278 |
|
|
279 |
|
|
280 |
/**
|
|
281 |
* Statistic info
|
|
282 |
* @series Series S60 3.1
|
|
283 |
*/
|
|
284 |
#ifdef M2G_STATISTIC_DEBUG
|
|
285 |
class TM2GStatistic
|
|
286 |
{
|
|
287 |
public: // METHODS
|
|
288 |
/**
|
|
289 |
* Ctor
|
|
290 |
*/
|
|
291 |
TM2GStatistic();
|
|
292 |
|
|
293 |
/**
|
|
294 |
* Reset
|
|
295 |
*/
|
|
296 |
void Reset();
|
|
297 |
|
|
298 |
/**
|
|
299 |
* Print
|
|
300 |
* @param aPrintElapsedTime Print also en elapsed time
|
|
301 |
*/
|
|
302 |
void Print(TBool aPrintElapsedTime = EFalse);
|
|
303 |
|
|
304 |
/**
|
|
305 |
* Print
|
|
306 |
* @param aStream
|
|
307 |
*/
|
|
308 |
void Print(RWriteStream& aStream);
|
|
309 |
|
|
310 |
public: // STATIC METHODS
|
|
311 |
static void Log();
|
|
312 |
|
|
313 |
private: // METHODS
|
|
314 |
/**
|
|
315 |
* Copy ctor
|
|
316 |
*/
|
|
317 |
TM2GStatistic(const TM2GStatistic&);
|
|
318 |
|
|
319 |
/**
|
|
320 |
* Assignment operator
|
|
321 |
*/
|
|
322 |
TM2GStatistic& operator=(const TM2GStatistic&);
|
|
323 |
|
|
324 |
private: // VARIABLES
|
|
325 |
TTime iStartTime;
|
|
326 |
TTime iEndTime;
|
|
327 |
TThreadId iId;
|
|
328 |
TName iThreadName;
|
|
329 |
};
|
|
330 |
#endif // M2G_STATISTIC_DEBUG
|
|
331 |
|
|
332 |
private: // METHODS
|
|
333 |
/**
|
|
334 |
* Default constructor
|
|
335 |
*/
|
|
336 |
M2GGeneral() {};
|
|
337 |
|
|
338 |
/**
|
|
339 |
* Copy constructor
|
|
340 |
*/
|
|
341 |
M2GGeneral(const M2GGeneral&);
|
|
342 |
|
|
343 |
/**
|
|
344 |
* Assignment operator
|
|
345 |
*/
|
|
346 |
M2GGeneral& operator=(const M2GGeneral&);
|
|
347 |
};
|
|
348 |
|
|
349 |
// MACROS
|
|
350 |
// == TOOL MACROS ==
|
|
351 |
#define M2G_MIN( a, b ) ( ( a ) <= ( b ) ? ( a ) : ( b ) )
|
|
352 |
#define M2G_MAX( a, b ) ( ( a ) >= ( b ) ? ( a ) : ( b ) )
|
|
353 |
|
|
354 |
// == SWITCHES ==
|
|
355 |
#define M2G_NO_EXCEPTION_SWITCH
|
|
356 |
// #define M2G_NO_NULL_POINTER_EXCEPTION_SWITCH
|
|
357 |
|
|
358 |
#if defined( M2G_DEBUG )
|
|
359 |
#define M2G_TRACE
|
|
360 |
#endif
|
|
361 |
|
|
362 |
// == EXCEPTION MACROS ==
|
|
363 |
// Common exception handling
|
|
364 |
#ifndef M2G_NO_EXCEPTION_SWITCH
|
|
365 |
#define M2G_THROW( ERR_CODE ) /**/ User::Leave( ( ERR_CODE ) )
|
|
366 |
#define M2G_THROW2( ERR_TEXT, ERR_CODE ) /**/ M2G_DEBUG_0( ERR_TEXT ); User::Leave( ( ERR_CODE ) )
|
|
367 |
#else
|
|
368 |
#define M2G_THROW( ERR_CODE ) /**/
|
|
369 |
#define M2G_THROW2( ERR_TEXT, ERR_CODE ) /**/
|
|
370 |
#endif // !M2G_NO_EXCEPTION_SWITCH
|
|
371 |
|
|
372 |
// Null pointer exception handling
|
|
373 |
#ifndef M2G_NO_NULL_POINTER_EXCEPTION_SWITCH
|
|
374 |
#define M2G_CHECK_NULL_POINTER( JNI, POINTER ) /**/ M2GGeneral::CheckHandle( ( JNI, POINTER ) )
|
|
375 |
#else
|
|
376 |
#define M2G_CHECK_NULL_POINTER( JNI, POINTER ) /**/
|
|
377 |
#endif // !M2G_NO_NULL_POINTER_EXCEPTION_SWITCH
|
|
378 |
|
|
379 |
|
|
380 |
// == STATIC LOG MACROS ==
|
|
381 |
#if defined( M2G_STATISTIC_DEBUG )
|
|
382 |
#define M2G_STATISTIC_LOG /**/ M2GGeneral::TM2GStatistic::Log()
|
|
383 |
#else // M2G_STATISTIC_DEBUG
|
|
384 |
#define M2G_STATISTIC_LOG /**/
|
|
385 |
#endif // !M2G_STATISTIC_DEBUG
|
|
386 |
|
|
387 |
// == POPUP MACROS ==
|
|
388 |
#if defined( M2G_INFO_POPUP )
|
|
389 |
#define M2G_POPUP( LINE1, LINE2 ) /**/ M2GGeneral::PopupInfo( LINE1, LINE2 );
|
|
390 |
#else // !M2G_INFO_POPUP
|
|
391 |
#define M2G_POPUP( LINE1, LINE2 ) /**/
|
|
392 |
#endif // M2G_INFO_POPUP
|
|
393 |
|
|
394 |
// == TRACE MACROS ==
|
|
395 |
#if defined( M2G_TRACE )
|
|
396 |
#define M2G_DEBUG_0( TEXT ) /**/ \
|
|
397 |
RFileLogger::Write( KLogDirectory, KLogFileName, EFileLoggingModeAppend, _L( TEXT ) )
|
|
398 |
|
|
399 |
#define M2G_DEBUG_1( TEXT, VAL1 ) /**/ \
|
|
400 |
RFileLogger::WriteFormat( KLogDirectory, KLogFileName, EFileLoggingModeAppend, /**/ \
|
|
401 |
_L( TEXT ), VAL1 )
|
|
402 |
|
|
403 |
#define M2G_DEBUG_2( TEXT, VAL1, VAL2 ) /**/ \
|
|
404 |
RFileLogger::WriteFormat( KLogDirectory, KLogFileName, EFileLoggingModeAppend, /**/ \
|
|
405 |
_L( TEXT ), VAL1, VAL2 )
|
|
406 |
|
|
407 |
#define M2G_DEBUG_3( TEXT, VAL1, VAL2, VAL3 ) /**/ \
|
|
408 |
RFileLogger::WriteFormat( KLogDirectory, KLogFileName, EFileLoggingModeAppend, /**/ \
|
|
409 |
_L( TEXT ), VAL1, VAL2, VAL3 )
|
|
410 |
|
|
411 |
#define M2G_DEBUG_4( TEXT, VAL1, VAL2, VAL3, VAL4 ) /**/ \
|
|
412 |
RFileLogger::WriteFormat( KLogDirectory, KLogFileName, EFileLoggingModeAppend, /**/ \
|
|
413 |
_L( TEXT ), VAL1, VAL2, VAL3, VAL4 )
|
|
414 |
|
|
415 |
#define M2G_DEBUG_5( TEXT, VAL1, VAL2, VAL3, VAL4, VAL5 ) /**/ \
|
|
416 |
RFileLogger::WriteFormat( KLogDirectory, KLogFileName, EFileLoggingModeAppend, /**/ \
|
|
417 |
_L( TEXT ), VAL1, VAL2, VAL3, VAL4, VAL5 )
|
|
418 |
|
|
419 |
#define M2G_DEBUG_6( TEXT, VAL1, VAL2, VAL3, VAL4, VAL5, VAL6 ) /**/ \
|
|
420 |
RFileLogger::WriteFormat( KLogDirectory, KLogFileName, EFileLoggingModeAppend, /**/ \
|
|
421 |
_L( TEXT ), VAL1, VAL2, VAL3, VAL4, VAL5, VAL6 )
|
|
422 |
|
|
423 |
#define M2G_DEBUG_7( TEXT, VAL1, VAL2, VAL3, VAL4, VAL5, VAL6, VAL7 ) /**/ \
|
|
424 |
RFileLogger::WriteFormat( KLogDirectory, KLogFileName, EFileLoggingModeAppend, /**/ \
|
|
425 |
_L( TEXT ), VAL1, VAL2, VAL3, VAL4, VAL5, VAL6, VAL7 )
|
|
426 |
#else // !M2G_TRACE
|
|
427 |
#define M2G_POPUP( LINE1, LINE2 ) /**/
|
|
428 |
|
|
429 |
#define M2G_DEBUG_0( TEXT ) /**/
|
|
430 |
#define M2G_DEBUG_1( TEXT, VAL1 ) /**/
|
|
431 |
#define M2G_DEBUG_2( TEXT, VAL1, VAL2 ) /**/
|
|
432 |
#define M2G_DEBUG_3( TEXT, VAL1, VAL2, VAL3 ) /**/
|
|
433 |
#define M2G_DEBUG_4( TEXT, VAL1, VAL2, VAL3, VAL4 ) /**/
|
|
434 |
#define M2G_DEBUG_5( TEXT, VAL1, VAL2, VAL3, VAL4, VAL5 ) /**/
|
|
435 |
#define M2G_DEBUG_6( TEXT, VAL1, VAL2, VAL3, VAL4, VAL5, VAL6 ) /**/
|
|
436 |
#define M2G_DEBUG_7( TEXT, VAL1, VAL2, VAL3, VAL4, VAL5, VAL6, VAL7 ) /**/
|
|
437 |
#endif // M2G_TRACE
|
|
438 |
|
|
439 |
// DATA TYPES
|
|
440 |
typedef TInt TM2GSvgEngineHandle;
|
|
441 |
typedef TInt TM2GSvgDocumentHandle;
|
|
442 |
typedef TInt TM2GSvgElementHandle;
|
|
443 |
typedef TInt TM2GBitmapHandle;
|
|
444 |
typedef TInt TM2GSvgPathHandle;
|
|
445 |
typedef TInt16 TM2GSvgAttrType;
|
|
446 |
typedef TUint8 TM2GPixelComponent;
|
|
447 |
|
|
448 |
//For Qimage related changes
|
|
449 |
typedef TUint TM2GSvgBitmapHandle;
|
|
450 |
|
|
451 |
typedef TFixedArray<TInt, 3> TM2GColorData;
|
|
452 |
typedef TFixedArray<TReal32, 6> TM2GMatrixData;
|
|
453 |
typedef M2GGeneral::TDataArrayPtr<TReal32> TM2GMatrixData2;
|
|
454 |
typedef TFixedArray<TReal32, 4> TM2GRectData;
|
|
455 |
typedef TFixedArray<TReal32, 4> TM2GScreenBBoxData;
|
|
456 |
typedef TFixedArray<TReal32, 6> TM2GPathCurveData;
|
|
457 |
|
|
458 |
|
|
459 |
M2G_NS_END
|
|
460 |
|
|
461 |
//#if defined( __cplusplus )
|
|
462 |
//} // extern "C"
|
|
463 |
//#endif
|
|
464 |
|
|
465 |
#endif // M2GGENERAL_H
|