|
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: Util methods |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include <bitdev.h> // CFbsBitmapDevice |
|
20 #include <bitstd.h> // CFbsBitGc |
|
21 #include <e32math.h> // FRand |
|
22 #include "M2GUtils.h" |
|
23 |
|
24 |
|
25 M2G_NS_START |
|
26 |
|
27 // EXTERNAL DATA STRUCTURES |
|
28 |
|
29 // EXTERNAL FUNCTION PROTOTYPES |
|
30 |
|
31 // CONSTANTS |
|
32 |
|
33 // MACROS |
|
34 |
|
35 // LOCAL CONSTANTS AND MACROS |
|
36 |
|
37 // MODULE DATA STRUCTURES |
|
38 |
|
39 // LOCAL FUNCTION PROTOTYPES |
|
40 |
|
41 // FORWARD DECLARATIONS |
|
42 class TSWTBitBlt; |
|
43 class TM2GBitmapLock; |
|
44 // ----------------------------------------------------------------------------- |
|
45 // M2GBitmapUtils::BitBlt |
|
46 // ----------------------------------------------------------------------------- |
|
47 TInt M2GBitmapUtils::BitBlt(CFbsBitmap& aTarget, |
|
48 const CFbsBitmap& aSource, |
|
49 const TPoint& aPoint, |
|
50 const TRect* aRect, |
|
51 const CFbsBitmap* aSourceMask) |
|
52 { |
|
53 M2G_DEBUG_2("M2G_DEBUG: M2GBitmapUtils::BitBlt() - Point(x=%d, y=%d)", aPoint.iX, aPoint.iY); |
|
54 CFbsBitGc* context = NULL; |
|
55 CFbsBitmapDevice* device = NULL; |
|
56 TInt err = KM2GOk; |
|
57 TRAP(err, (device = CFbsBitmapDevice::NewL(&aTarget))); |
|
58 if ((err == KM2GOk) && (device != NULL)) |
|
59 { |
|
60 err = device->CreateContext(context); |
|
61 if ((err == KM2GOk) && (context != NULL)) |
|
62 { |
|
63 M2G_DEBUG_0("M2G_DEBUG: M2GBitmapUtils::BitBlt() - CFbsBitGc::BitBlt()"); |
|
64 if (aRect) |
|
65 { |
|
66 // Check if mask |
|
67 if (aSourceMask) |
|
68 { |
|
69 M2G_DEBUG_4("M2G_DEBUG: M2GBitmapUtils::BitBlt() - mask rect(x1=%d, y1=%d, x2=%d, y2=%d)", aRect->iTl.iX, aRect->iTl.iY, aRect->iBr.iX, aRect->iBr.iY); |
|
70 // A pixel that is masked by a BLACK is NOT transferred to a destination rectangle. |
|
71 context->BitBltMasked(aPoint, &aSource, *aRect, aSourceMask, ETrue); |
|
72 err = KM2GOk; |
|
73 } |
|
74 else |
|
75 { |
|
76 M2G_DEBUG_4("M2G_DEBUG: M2GBitmapUtils::BitBlt() - rect(x1=%d, y1=%d, x2=%d, y2=%d)", aRect->iTl.iX, aRect->iTl.iY, aRect->iBr.iX, aRect->iBr.iY); |
|
77 context->BitBlt(aPoint, &aSource, *aRect); |
|
78 err = KM2GOk; |
|
79 } |
|
80 } |
|
81 else |
|
82 { |
|
83 M2G_DEBUG_0("M2G_DEBUG: M2GBitmapUtils::BitBlt() - no rect"); |
|
84 context->BitBlt(aPoint, &aSource); |
|
85 err = KM2GOk; |
|
86 } |
|
87 } |
|
88 } |
|
89 delete context; |
|
90 delete device; |
|
91 context = NULL; |
|
92 device = NULL; |
|
93 M2G_DEBUG_1("M2G_DEBUG: M2GBitmapUtils::BitBlt() - end: %d", err); |
|
94 return err; |
|
95 } |
|
96 |
|
97 |
|
98 TInt M2GBitmapUtils::BitQBlt(QImage& aTargetQimage, |
|
99 const QImage& aSourceQimage, |
|
100 const TPoint& aPoint, |
|
101 const TRect* aRect, |
|
102 const CFbsBitmap* aSourceMask) |
|
103 { |
|
104 M2G_DEBUG_2("M2G_DEBUG: M2GBitmapUtils::BitQBlt() - Point(x=%d, y=%d)", aPoint.iX, aPoint.iY); |
|
105 |
|
106 QPixmap pixmapTarget = QPixmap::fromImage(aTargetQimage); |
|
107 CFbsBitmap* aTarget = pixmapTarget.toSymbianCFbsBitmap(); |
|
108 |
|
109 QPixmap pixmapSource = QPixmap::fromImage(aSourceQimage); |
|
110 CFbsBitmap* aSource = pixmapSource.toSymbianCFbsBitmap(); |
|
111 |
|
112 CFbsBitGc* context = NULL; |
|
113 CFbsBitmapDevice* device = NULL; |
|
114 TInt err = KM2GOk; |
|
115 TRAP(err, (device = CFbsBitmapDevice::NewL(aTarget))); |
|
116 if ((err == KM2GOk) && (device != NULL)) |
|
117 { |
|
118 err = device->CreateContext(context); |
|
119 if ((err == KM2GOk) && (context != NULL)) |
|
120 { |
|
121 M2G_DEBUG_0("M2G_DEBUG: M2GBitmapUtils::BitBlt() - CFbsBitGc::BitBlt()"); |
|
122 if (aRect) |
|
123 { |
|
124 // Check if mask |
|
125 if (aSourceMask) |
|
126 { |
|
127 M2G_DEBUG_4("M2G_DEBUG: M2GBitmapUtils::BitBlt() - mask rect(x1=%d, y1=%d, x2=%d, y2=%d)", aRect->iTl.iX, aRect->iTl.iY, aRect->iBr.iX, aRect->iBr.iY); |
|
128 // A pixel that is masked by a BLACK is NOT transferred to a destination rectangle. |
|
129 context->BitBltMasked(aPoint, aSource, *aRect, aSourceMask, ETrue); |
|
130 err = KM2GOk; |
|
131 } |
|
132 else |
|
133 { |
|
134 M2G_DEBUG_4("M2G_DEBUG: M2GBitmapUtils::BitBlt() - rect(x1=%d, y1=%d, x2=%d, y2=%d)", aRect->iTl.iX, aRect->iTl.iY, aRect->iBr.iX, aRect->iBr.iY); |
|
135 context->BitBlt(aPoint, aSource, *aRect); |
|
136 err = KM2GOk; |
|
137 } |
|
138 } |
|
139 else |
|
140 { |
|
141 M2G_DEBUG_0("M2G_DEBUG: M2GBitmapUtils::BitBlt() - no rect"); |
|
142 context->BitBlt(aPoint, aSource); |
|
143 err = KM2GOk; |
|
144 } |
|
145 } |
|
146 } |
|
147 delete context; |
|
148 delete device; |
|
149 context = NULL; |
|
150 device = NULL; |
|
151 M2G_DEBUG_1("M2G_DEBUG: M2GBitmapUtils::BitBlt() - end: %d", err); |
|
152 return err; |
|
153 } |
|
154 |
|
155 |
|
156 |
|
157 TInt M2GBitmapUtils::BitBlt(CBitmapContext& aTargetContext, |
|
158 const CFbsBitmap& aSource, |
|
159 const TPoint& aPoint, |
|
160 const TRect* aRect, |
|
161 const CFbsBitmap* aSourceMask, |
|
162 /*MSwtClient* aClientHandle,*/ |
|
163 TBool aUseNativeClear /*= EFalse*/) |
|
164 { |
|
165 M2G_DEBUG_2("M2G_DEBUG: M2GBitmapUtils::BitBlt() - Point(x=%d, y=%d)", aPoint.iX, aPoint.iY); |
|
166 TInt err = KM2GOk; |
|
167 TSWTBitBlt bitBlitter(aTargetContext, aPoint, |
|
168 &aSource, aRect, aSourceMask, aUseNativeClear); |
|
169 bitBlitter(); |
|
170 M2G_DEBUG_1("M2G_DEBUG: M2GBitmapUtils::BitBlt() - end: %d", err); |
|
171 return err; |
|
172 } |
|
173 |
|
174 // ----------------------------------------------------------------------------- |
|
175 // TM2GRenderRect::TM2GRenderRect |
|
176 // ----------------------------------------------------------------------------- |
|
177 TM2GRenderRect::TM2GRenderRect( |
|
178 TInt aAnchorX, TInt aAnchorY, |
|
179 TInt aClipX, TInt aClipY, |
|
180 TInt aClipW, TInt aClipH) |
|
181 : TRect( |
|
182 TPoint(aClipX, aClipY), |
|
183 TSize(aClipW, aClipH)), |
|
184 iAnchorX(aAnchorX), |
|
185 iAnchorY(aAnchorY) |
|
186 { |
|
187 } |
|
188 |
|
189 // ----------------------------------------------------------------------------- |
|
190 // TM2GRenderRect::TM2GRenderRect |
|
191 // ----------------------------------------------------------------------------- |
|
192 TM2GRenderRect::TM2GRenderRect(TInt* aDimensions, TInt /*aLength*/) |
|
193 : TRect( |
|
194 TPoint(aDimensions[EClipX], aDimensions[EClipY]), |
|
195 TSize(aDimensions[EClipW], aDimensions[EClipH])), |
|
196 iAnchorX(aDimensions[EAnchorX]), |
|
197 iAnchorY(aDimensions[EAnchorY]) |
|
198 { |
|
199 } |
|
200 |
|
201 // ----------------------------------------------------------------------------- |
|
202 // TM2GRenderRect::~TM2GRenderRect |
|
203 // ----------------------------------------------------------------------------- |
|
204 TM2GRenderRect::~TM2GRenderRect() |
|
205 { |
|
206 } |
|
207 |
|
208 // ----------------------------------------------------------------------------- |
|
209 // TM2GRenderRect::TM2GRenderRect |
|
210 // ----------------------------------------------------------------------------- |
|
211 TM2GRenderRect::TM2GRenderRect(const TM2GRenderRect& aRd) |
|
212 { |
|
213 (*this = aRd); |
|
214 } |
|
215 |
|
216 // ----------------------------------------------------------------------------- |
|
217 // TM2GRenderRect::operator= |
|
218 // ----------------------------------------------------------------------------- |
|
219 TM2GRenderRect& TM2GRenderRect::operator=(const TM2GRenderRect& aRd) |
|
220 { |
|
221 if (this != &aRd) |
|
222 { |
|
223 iAnchorX = aRd.iAnchorX; |
|
224 iAnchorY = aRd.iAnchorY; |
|
225 SetRect(aRd.iTl.iX, aRd.iTl.iY, aRd.iBr.iX, aRd.iBr.iY); |
|
226 } |
|
227 return *this; |
|
228 } |
|
229 |
|
230 // ----------------------------------------------------------------------------- |
|
231 // TM2GRenderRect::GetRegionSizeInPixels |
|
232 // ----------------------------------------------------------------------------- |
|
233 TSize TM2GRenderRect::GetRegionSizeInPixels( |
|
234 TM2GRenderRect& aRect, |
|
235 const TSize& aSz) |
|
236 { |
|
237 return TSize( |
|
238 // determine the width of the region to be paint |
|
239 M2GGeneral::Min< TInt >(aRect.GetAnchorX() + aSz.iWidth, aRect.GetClipX() + aRect.GetClipW()) - |
|
240 M2GGeneral::Max< TInt >(aRect.GetAnchorX(), aRect.GetClipX()), |
|
241 // determine the height of the region to be paint |
|
242 M2GGeneral::Min< TInt >(aRect.GetAnchorY() + aSz.iHeight, aRect.GetClipY() + aRect.GetClipH()) - |
|
243 M2GGeneral::Max< TInt >(aRect.GetAnchorY(), aRect.GetClipY())); |
|
244 } |
|
245 |
|
246 |
|
247 // ----------------------------------------------------------------------------- |
|
248 // TM2GBitmapLock::TM2GBitmapLock |
|
249 // ----------------------------------------------------------------------------- |
|
250 TM2GBitmapLock::TM2GBitmapLock(const CFbsBitmap* aBitmap, TBool aLock) |
|
251 : iBitmap(aBitmap), iIsLocked(EFalse) |
|
252 { |
|
253 if (aLock) |
|
254 { |
|
255 Lock(); |
|
256 } |
|
257 } |
|
258 |
|
259 // ----------------------------------------------------------------------------- |
|
260 // TM2GBitmapLock::~TM2GBitmapLock |
|
261 // ----------------------------------------------------------------------------- |
|
262 TM2GBitmapLock::~TM2GBitmapLock() |
|
263 { |
|
264 Unlock(); |
|
265 } |
|
266 |
|
267 // ----------------------------------------------------------------------------- |
|
268 // TM2GBitmapLock::Lock() |
|
269 // ----------------------------------------------------------------------------- |
|
270 void TM2GBitmapLock::Lock() |
|
271 { |
|
272 if (iBitmap && !iIsLocked) |
|
273 { |
|
274 iBitmap->LockHeap(); |
|
275 iIsLocked = ETrue; |
|
276 } |
|
277 } |
|
278 |
|
279 // ----------------------------------------------------------------------------- |
|
280 // TM2GBitmapLock::Unlock() |
|
281 // ----------------------------------------------------------------------------- |
|
282 void TM2GBitmapLock::Unlock() |
|
283 { |
|
284 if (iBitmap && iIsLocked) |
|
285 { |
|
286 iBitmap->UnlockHeap(); |
|
287 iIsLocked = EFalse; |
|
288 } |
|
289 } |
|
290 |
|
291 TSWTBitBlt::TSWTBitBlt(CBitmapContext& aTargetContext, |
|
292 const TPoint& aPoint, |
|
293 const CFbsBitmap* aBitmap, |
|
294 const TRect* aSourceRect, |
|
295 const CFbsBitmap* aMaskBitmap, |
|
296 TBool aUseNativeClear) |
|
297 : iTargetContext(aTargetContext), |
|
298 iPoint(aPoint), |
|
299 iUseNativeClear(aUseNativeClear) |
|
300 { |
|
301 iBitmap = aBitmap; |
|
302 iRect = aSourceRect; |
|
303 iMaskBitmap = aMaskBitmap; |
|
304 } |
|
305 void TSWTBitBlt::operator()() const |
|
306 { |
|
307 M2G_DEBUG_0("TSWTBitBlt()+"); |
|
308 CFbsBitmap* tempBitmap = new(ELeave) CFbsBitmap; |
|
309 CleanupStack::PushL(tempBitmap); |
|
310 User::LeaveIfError(tempBitmap->Duplicate(iBitmap->Handle())); |
|
311 if (iRect) |
|
312 { |
|
313 if (iUseNativeClear) |
|
314 { |
|
315 iTargetContext.SetBrushColor(KRgbWhite); |
|
316 iTargetContext.Clear(*iRect); |
|
317 } |
|
318 if (iMaskBitmap) |
|
319 { |
|
320 CFbsBitmap* tempMask = new(ELeave) CFbsBitmap; |
|
321 CleanupStack::PushL(tempMask); |
|
322 User::LeaveIfError(tempMask->Duplicate(iMaskBitmap->Handle())); |
|
323 iTargetContext.BitBltMasked( |
|
324 iPoint, tempBitmap, *iRect, tempMask, ETrue); |
|
325 CleanupStack::PopAndDestroy(tempMask); |
|
326 } |
|
327 else |
|
328 { |
|
329 iTargetContext.BitBlt(iPoint, tempBitmap, *iRect); |
|
330 } |
|
331 } |
|
332 else |
|
333 { |
|
334 if (iUseNativeClear) |
|
335 { |
|
336 iTargetContext.SetBrushColor(KRgbWhite); |
|
337 iTargetContext.Clear(); |
|
338 } |
|
339 iTargetContext.BitBlt(iPoint, tempBitmap); |
|
340 } |
|
341 CleanupStack::PopAndDestroy(tempBitmap); |
|
342 M2G_DEBUG_0("TSWTBitBlt()-"); |
|
343 } |
|
344 //TODO Check for M2G_DO_LOCK M2G_DO_UNLOCK |
|
345 //TODO Put Check for aSvgProxyHandle in all the functions. |
|
346 M2G_NS_END |