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