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 functions
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#ifndef M2GUTILS_H
|
|
19 |
#define M2GUTILS_H
|
|
20 |
|
|
21 |
// INCLUDE FILES
|
|
22 |
#include <gdi.h> // DisplayMode, Draw, BitBlt
|
|
23 |
#include <fbs.h> // CFbsBitmap
|
|
24 |
#include "M2GGeneral.h"
|
|
25 |
#include <QPixmap>
|
|
26 |
#include <jni.h>
|
87
|
27 |
#include "CSynchronization.h" //For UI Thread Execution.
|
80
|
28 |
M2G_NS_START
|
|
29 |
|
|
30 |
// CONSTANTS
|
|
31 |
|
|
32 |
// DATA TYPES
|
|
33 |
|
|
34 |
// MACROS
|
|
35 |
|
87
|
36 |
|
|
37 |
/*!
|
|
38 |
* \brief Macros for serializing m2gcore function calls
|
|
39 |
* in native threading environment.
|
|
40 |
*/
|
|
41 |
|
|
42 |
#define M2G_DO_LOCK CSynchronization::InstanceL()->Lock();
|
|
43 |
|
|
44 |
#define M2G_DO_UNLOCK(aEnv) {\
|
|
45 |
TInt errorCode = CSynchronization::InstanceL()->GetErrorCode();\
|
|
46 |
if ( errorCode != 0){\
|
|
47 |
M2GGeneral::CheckErrorCode(aEnv,errorCode);\
|
|
48 |
}\
|
|
49 |
CSynchronization::InstanceL()->Unlock();\
|
|
50 |
}\
|
|
51 |
|
80
|
52 |
// FORWARD DECLARATIONS
|
|
53 |
class CFbsBitmapDevice;
|
|
54 |
class CFbsBitGc;
|
|
55 |
|
|
56 |
// FUNCTION PROTOTYPES
|
|
57 |
|
|
58 |
// CLASS DECLARATION
|
|
59 |
|
|
60 |
/**
|
|
61 |
* @class M2GBitmapUtils
|
|
62 |
* @brief Static methods for alpha blending and bitmaps
|
|
63 |
*/
|
|
64 |
|
|
65 |
class M2GBitmapUtils
|
|
66 |
{
|
|
67 |
public: // STATIC METHODS
|
|
68 |
/**
|
|
69 |
* Blits two bitmap
|
|
70 |
* @since Series S60 3.0
|
|
71 |
* @param aTarget Target bitmap.
|
|
72 |
* @param aSource Source bitmap.
|
|
73 |
* @param aPoint Position for the top left corner of the bitmap.
|
|
74 |
* @param aRect Rectangle defining the piece of the bitmap to be drawn.
|
|
75 |
* @param aSourceMask Mask.
|
|
76 |
* @return M2G_OK if ok
|
|
77 |
*/
|
|
78 |
static TInt BitBlt(CFbsBitmap& aTarget,
|
|
79 |
const CFbsBitmap& aSource,
|
|
80 |
const TPoint& aPoint,
|
|
81 |
const TRect* aRect = NULL,
|
|
82 |
const CFbsBitmap* aSourceMask = NULL);
|
|
83 |
|
|
84 |
static TInt BitBlt(CBitmapContext& aTargetContext,
|
|
85 |
const CFbsBitmap& aSource,
|
|
86 |
const TPoint& aPoint,
|
|
87 |
const TRect* aRect,
|
|
88 |
const CFbsBitmap* aSourceMask,
|
|
89 |
/*MSwtClient* aClientHandle,*/
|
|
90 |
TBool aUseNativeClear = EFalse);
|
87
|
91 |
|
80
|
92 |
static TInt BitQBlt(QImage& aTargetQimage,
|
87
|
93 |
const QImage& aSourceQimage,
|
|
94 |
const TPoint& aPoint,
|
|
95 |
const TRect* aRect,
|
|
96 |
const CFbsBitmap* aSourceMask);
|
|
97 |
|
80
|
98 |
/**
|
|
99 |
* Checks if two bitmap are equal.
|
|
100 |
* @since Series S60 3.0
|
|
101 |
* @param aLhs Left side bitmap
|
|
102 |
* @param aRhs Right side bitmap
|
|
103 |
* @return ETrue if bitmaps are equal.
|
|
104 |
*/
|
|
105 |
inline static TBool Equals(const CFbsBitmap& aLhs, const CFbsBitmap& aRhs)
|
|
106 |
{
|
|
107 |
return (aLhs.SizeInPixels() == aRhs.SizeInPixels());
|
|
108 |
}
|
|
109 |
|
|
110 |
/**
|
|
111 |
* Checks if a bitmap has same values as given values.
|
|
112 |
* @since Series S60 3.0
|
|
113 |
* @param aBitmap Bitmap
|
|
114 |
* @param aSz Size in pixels.
|
|
115 |
* @param aMode Display mode.
|
|
116 |
* @return ETrue if bitmaps are equal.
|
|
117 |
*/
|
|
118 |
inline static TBool Equals(
|
|
119 |
const CFbsBitmap& aBitmap,
|
|
120 |
const TSize& aSz,
|
|
121 |
const TDisplayMode* aMode)
|
|
122 |
{
|
|
123 |
return (((aBitmap.SizeInPixels() == aSz) &&
|
|
124 |
((aMode == NULL) || (aBitmap.DisplayMode() == *aMode))
|
|
125 |
) ? ETrue : EFalse);
|
|
126 |
}
|
|
127 |
|
|
128 |
/**
|
|
129 |
* Return byte per pixel
|
|
130 |
* @since Series S60 3.1
|
|
131 |
* @param aBitmap
|
|
132 |
* @param aRhs Right side bitmap
|
|
133 |
* @return ETrue if bitmaps are equal.
|
|
134 |
*/
|
|
135 |
inline static TInt BytesPerPixel(const CFbsBitmap& aBitmap)
|
|
136 |
{
|
|
137 |
switch (aBitmap.DisplayMode())
|
|
138 |
{
|
|
139 |
case EGray256 :
|
|
140 |
case EColor256 :
|
|
141 |
return 1;
|
|
142 |
case EColor64K :
|
|
143 |
return 2;
|
|
144 |
case EColor16M :
|
|
145 |
case EColor16MU :
|
|
146 |
case EColor16MA :
|
|
147 |
return 4;
|
|
148 |
default :
|
|
149 |
return 0;
|
|
150 |
}
|
|
151 |
}
|
|
152 |
|
|
153 |
};
|
|
154 |
|
|
155 |
|
|
156 |
//-----------------------------------------------------------------------------
|
|
157 |
// Creating integer 'handles' from C++ objects for referencing them inside Java
|
|
158 |
// The shift garauntees a positive integer, so object creation native methods
|
|
159 |
// can overload the return value to be a handle or an error code
|
|
160 |
//
|
|
161 |
// Unhanding the integer requires the destination type to be known, so is
|
|
162 |
// implemented as a template function, it should be invoked as
|
|
163 |
//
|
|
164 |
// CXyz* xyz=JavaUnhand(aHandle);
|
|
165 |
//
|
|
166 |
const TInt KJavaHandleShift=2;
|
|
167 |
|
|
168 |
inline TInt JavaMakeHandle(const TAny* aObject)
|
|
169 |
{
|
|
170 |
return reinterpret_cast<TUint>(aObject)>>KJavaHandleShift;
|
|
171 |
}
|
|
172 |
|
|
173 |
template <typename T>
|
|
174 |
inline T* JavaUnhand(TInt aHandle)
|
|
175 |
{
|
|
176 |
return reinterpret_cast<T*>(aHandle<<KJavaHandleShift);
|
|
177 |
}
|
|
178 |
|
|
179 |
//----------------------------------------------------------------------------
|
|
180 |
/* Takes an EPOC string and returns a Java JNI string */
|
|
181 |
inline jstring CreateJavaString(JNIEnv& aJni, const TDesC16& aString)
|
|
182 |
{
|
|
183 |
const jchar* stringPtr = aString.Ptr();
|
|
184 |
const jsize stringLength = aString.Length();
|
|
185 |
jstring jniString = aJni.NewString(stringPtr, stringLength);
|
|
186 |
return jniString;
|
|
187 |
}
|
|
188 |
|
|
189 |
|
|
190 |
|
|
191 |
/**
|
|
192 |
* @class TM2GRenderRect
|
|
193 |
* @brief Class for handling rendering rectangle
|
|
194 |
*/
|
|
195 |
class TM2GRenderRect : public TRect
|
|
196 |
{
|
|
197 |
private:
|
|
198 |
// NOTE ELength should be always the last one and indexing
|
|
199 |
// should start from 0
|
|
200 |
enum TArrayIndexes
|
|
201 |
{
|
|
202 |
EAnchorX = 0,
|
|
203 |
EAnchorY = 1,
|
|
204 |
EClipX = 2,
|
|
205 |
EClipY = 3,
|
|
206 |
EClipW = 4,
|
|
207 |
EClipH = 5,
|
|
208 |
ELength
|
|
209 |
};
|
|
210 |
|
|
211 |
public: // METHODS
|
|
212 |
/**
|
|
213 |
* Ctor
|
|
214 |
* @since Series S60 3.0
|
|
215 |
* @param aAnchorX X anchor
|
|
216 |
* @param aAnchorY Y anchor
|
|
217 |
* @param aClipX Clip x
|
|
218 |
* @param aClipY Clip y
|
|
219 |
* @param aClipWidth Clip width
|
|
220 |
* @param aClipHeight Clip height
|
|
221 |
*/
|
|
222 |
TM2GRenderRect(
|
|
223 |
TInt aAnchorX, TInt aAnchorY,
|
|
224 |
TInt aClipX, TInt aClipY,
|
|
225 |
TInt aClipW, TInt aClipH);
|
|
226 |
|
|
227 |
/**
|
|
228 |
* Ctor
|
|
229 |
* @since Series S60 3.0
|
|
230 |
* @param aDimensions Dimensions. @see TArrayIndexes.
|
|
231 |
* @param aLength Array length
|
|
232 |
*/
|
|
233 |
TM2GRenderRect(TInt* aDimensions, TInt aLength);
|
|
234 |
|
|
235 |
/**
|
|
236 |
* Copy ctor
|
|
237 |
* @since Series S60 3.0
|
|
238 |
* @param aRd
|
|
239 |
*/
|
|
240 |
TM2GRenderRect(const TM2GRenderRect& aRd);
|
|
241 |
|
|
242 |
/**
|
|
243 |
* Assignment operator
|
|
244 |
* @since Series S60 3.0
|
|
245 |
* @param aRd
|
|
246 |
* @return TM2GRenderRect
|
|
247 |
*/
|
|
248 |
TM2GRenderRect& operator=(const TM2GRenderRect& aRd);
|
|
249 |
|
|
250 |
/**
|
|
251 |
* Dtor
|
|
252 |
* @since Series S60 3.0
|
|
253 |
*/
|
|
254 |
virtual ~TM2GRenderRect();
|
|
255 |
|
|
256 |
/**
|
|
257 |
* Returns x anchor
|
|
258 |
* @since Series S60 3.0
|
|
259 |
* @return X anchor
|
|
260 |
*/
|
|
261 |
inline TInt GetAnchorX()
|
|
262 |
{
|
|
263 |
return iAnchorX;
|
|
264 |
}
|
|
265 |
|
|
266 |
/**
|
|
267 |
* Returns y anchor
|
|
268 |
* @since Series S60 3.0
|
|
269 |
* @return Y anchor
|
|
270 |
*/
|
|
271 |
inline TInt GetAnchorY()
|
|
272 |
{
|
|
273 |
return iAnchorY;
|
|
274 |
}
|
|
275 |
|
|
276 |
/**
|
|
277 |
* Returns clip height
|
|
278 |
* @since Series S60 3.0
|
|
279 |
* @return Clip height
|
|
280 |
*/
|
|
281 |
inline TInt GetClipH()
|
|
282 |
{
|
|
283 |
return Height();
|
|
284 |
}
|
|
285 |
|
|
286 |
/**
|
|
287 |
* Returns x clip
|
|
288 |
* @since Series S60 3.0
|
|
289 |
* @return X clip
|
|
290 |
*/
|
|
291 |
inline TInt GetClipX()
|
|
292 |
{
|
|
293 |
return iTl.iX;
|
|
294 |
}
|
|
295 |
|
|
296 |
/**
|
|
297 |
* Returns y clip
|
|
298 |
* @since Series S60 3.0
|
|
299 |
* @return Y clip
|
|
300 |
*/
|
|
301 |
inline TInt GetClipY()
|
|
302 |
{
|
|
303 |
return iTl.iY;
|
|
304 |
}
|
|
305 |
|
|
306 |
/**
|
|
307 |
* Returns clip width
|
|
308 |
* @since Series S60 3.0
|
|
309 |
* @return Clip width
|
|
310 |
*/
|
|
311 |
inline TInt GetClipW()
|
|
312 |
{
|
|
313 |
return Width();
|
|
314 |
}
|
|
315 |
|
|
316 |
/**
|
|
317 |
* Sets x anchor
|
|
318 |
* @since Series S60 3.0
|
|
319 |
* @param aX X anchor
|
|
320 |
*/
|
|
321 |
inline void SetAnchorX(TInt aX)
|
|
322 |
{
|
|
323 |
iAnchorX = aX;
|
|
324 |
}
|
|
325 |
|
|
326 |
/**
|
|
327 |
* Sets y anchor
|
|
328 |
* @since Series S60 3.0
|
|
329 |
* @param aY Y anchor
|
|
330 |
*/
|
|
331 |
inline void SetAnchorY(TInt aY)
|
|
332 |
{
|
|
333 |
iAnchorY = aY;
|
|
334 |
}
|
|
335 |
|
|
336 |
/**
|
|
337 |
* Sets clip height
|
|
338 |
* @since Series S60 3.0
|
|
339 |
* @param aH Clip height
|
|
340 |
*/
|
|
341 |
inline void SetClipH(TInt aH)
|
|
342 |
{
|
|
343 |
SetHeight(aH);
|
|
344 |
}
|
|
345 |
|
|
346 |
/**
|
|
347 |
* Sets x clip
|
|
348 |
* @since Series S60 3.0
|
|
349 |
* @param aX X clip
|
|
350 |
*/
|
|
351 |
inline void SetClipX(TInt aX)
|
|
352 |
{
|
|
353 |
iTl.iX = aX;
|
|
354 |
}
|
|
355 |
|
|
356 |
/**
|
|
357 |
* Sets y clip
|
|
358 |
* @since Series S60 3.0
|
|
359 |
* @param aY Y clip
|
|
360 |
*/
|
|
361 |
inline void SetClipY(TInt aY)
|
|
362 |
{
|
|
363 |
iTl.iY = aY;
|
|
364 |
}
|
|
365 |
|
|
366 |
/**
|
|
367 |
* Sets clip width
|
|
368 |
* @since Series S60 3.0
|
|
369 |
* @param aW Clip width
|
|
370 |
*/
|
|
371 |
inline void SetClipW(TInt aW)
|
|
372 |
{
|
|
373 |
SetWidth(aW);
|
|
374 |
}
|
|
375 |
|
|
376 |
public: // STATIC METHODS
|
|
377 |
/**
|
|
378 |
* Gets region size
|
|
379 |
* @since Series S60 3.0
|
|
380 |
* @param aRect Render dimensions
|
|
381 |
* @param aSz Source surface size
|
|
382 |
* @return Region size to be paint
|
|
383 |
*/
|
|
384 |
static TSize GetRegionSizeInPixels(
|
|
385 |
TM2GRenderRect& aRect,
|
|
386 |
const TSize& aSz);
|
|
387 |
|
|
388 |
public: // VARIABLES
|
|
389 |
TInt iAnchorX;
|
|
390 |
TInt iAnchorY;
|
|
391 |
};
|
|
392 |
|
|
393 |
|
|
394 |
/**
|
|
395 |
* @class TM2GBitmapLock
|
|
396 |
* @brief Bitmap autolocker
|
|
397 |
*/
|
|
398 |
class TM2GBitmapLock
|
|
399 |
{
|
|
400 |
public: // METHODS
|
|
401 |
/**
|
|
402 |
* Ctor
|
|
403 |
* @param aBitmap Bitmap
|
|
404 |
* @param aLock If ETrue then bitmap is locked by ctor.
|
|
405 |
*/
|
|
406 |
TM2GBitmapLock(const CFbsBitmap* aBitmap, TBool aLock = ETrue);
|
|
407 |
|
|
408 |
/**
|
|
409 |
* Dtor
|
|
410 |
* @since Series S60 3.0
|
|
411 |
*/
|
|
412 |
virtual ~TM2GBitmapLock();
|
|
413 |
|
|
414 |
/**
|
|
415 |
* Locks bitmap heap
|
|
416 |
* @since Series S60 3.0
|
|
417 |
*/
|
|
418 |
void Lock();
|
|
419 |
|
|
420 |
/**
|
|
421 |
* Unlocks bitmap heap
|
|
422 |
* @since Series S60 3.0
|
|
423 |
*/
|
|
424 |
void Unlock();
|
|
425 |
|
|
426 |
protected: // METHODS
|
|
427 |
/**
|
|
428 |
* Copy ctor
|
|
429 |
* @since Series S60 3.0
|
|
430 |
* @param aRd
|
|
431 |
*/
|
|
432 |
TM2GBitmapLock(const TM2GBitmapLock& aRd);
|
|
433 |
|
|
434 |
/**
|
|
435 |
* Assignment operator
|
|
436 |
* @since Series S60 3.0
|
|
437 |
* @param aRd
|
|
438 |
* @return TM2GBitmapLock
|
|
439 |
*/
|
|
440 |
TM2GBitmapLock& operator=(const TM2GBitmapLock& aRd);
|
|
441 |
|
|
442 |
public: // VARIABLES
|
|
443 |
const CFbsBitmap* iBitmap;
|
|
444 |
TBool iIsLocked;
|
|
445 |
};
|
|
446 |
class TSWTBitBlt/*: public MSwtFunctor*/
|
|
447 |
{
|
|
448 |
public:
|
|
449 |
TSWTBitBlt(CBitmapContext& aTargetContext,
|
|
450 |
const TPoint& aPoint,
|
|
451 |
const CFbsBitmap* aBitmap,
|
|
452 |
const TRect* aSourceRect,
|
|
453 |
const CFbsBitmap* aMaskBitmap,
|
|
454 |
TBool aUseNativeClear);
|
|
455 |
|
|
456 |
void operator()() const;
|
|
457 |
CBitmapContext& iTargetContext;
|
|
458 |
const TPoint iPoint;
|
|
459 |
const CFbsBitmap* iBitmap;
|
|
460 |
const TRect* iRect;
|
|
461 |
const CFbsBitmap* iMaskBitmap;
|
|
462 |
TBool iUseNativeClear;
|
|
463 |
};
|
|
464 |
M2G_NS_END
|
|
465 |
|
|
466 |
|
|
467 |
#endif // M2GUTILS_H
|