|
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 <swtfunctor.h> |
|
23 #include "M2GUtils.h" |
|
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 TInt M2GBitmapUtils::BitBlt(CBitmapContext& aTargetContext, |
|
97 const CFbsBitmap& aSource, |
|
98 const TPoint& aPoint, |
|
99 const TRect* aRect, |
|
100 const CFbsBitmap* aSourceMask, |
|
101 MSwtClient* /*aClientHandle*/, |
|
102 TBool aUseNativeClear /*= EFalse*/) |
|
103 { |
|
104 M2G_DEBUG_2("M2G_DEBUG: M2GBitmapUtils::BitBlt() - Point(x=%d, y=%d)", aPoint.iX, aPoint.iY); |
|
105 TInt err = KM2GOk; |
|
106 TSWTBitBlt bitBlitter(aTargetContext, aPoint, |
|
107 &aSource, aRect, aSourceMask, aUseNativeClear); |
|
108 bitBlitter(); |
|
109 M2G_DEBUG_1("M2G_DEBUG: M2GBitmapUtils::BitBlt() - end: %d", err); |
|
110 return err; |
|
111 } |
|
112 |
|
113 // ----------------------------------------------------------------------------- |
|
114 // TM2GRenderRect::TM2GRenderRect |
|
115 // ----------------------------------------------------------------------------- |
|
116 TM2GRenderRect::TM2GRenderRect( |
|
117 TInt aAnchorX, TInt aAnchorY, |
|
118 TInt aClipX, TInt aClipY, |
|
119 TInt aClipW, TInt aClipH) |
|
120 : TRect( |
|
121 TPoint(aClipX, aClipY), |
|
122 TSize(aClipW, aClipH)), |
|
123 iAnchorX(aAnchorX), |
|
124 iAnchorY(aAnchorY) |
|
125 { |
|
126 } |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // TM2GRenderRect::TM2GRenderRect |
|
130 // ----------------------------------------------------------------------------- |
|
131 TM2GRenderRect::TM2GRenderRect(TInt* aDimensions, TInt /*aLength*/) |
|
132 : TRect( |
|
133 TPoint(aDimensions[EClipX], aDimensions[EClipY]), |
|
134 TSize(aDimensions[EClipW], aDimensions[EClipH])), |
|
135 iAnchorX(aDimensions[EAnchorX]), |
|
136 iAnchorY(aDimensions[EAnchorY]) |
|
137 { |
|
138 } |
|
139 |
|
140 // ----------------------------------------------------------------------------- |
|
141 // TM2GRenderRect::~TM2GRenderRect |
|
142 // ----------------------------------------------------------------------------- |
|
143 TM2GRenderRect::~TM2GRenderRect() |
|
144 { |
|
145 } |
|
146 |
|
147 // ----------------------------------------------------------------------------- |
|
148 // TM2GRenderRect::TM2GRenderRect |
|
149 // ----------------------------------------------------------------------------- |
|
150 TM2GRenderRect::TM2GRenderRect(const TM2GRenderRect& aRd) |
|
151 { |
|
152 (*this = aRd); |
|
153 } |
|
154 |
|
155 // ----------------------------------------------------------------------------- |
|
156 // TM2GRenderRect::operator= |
|
157 // ----------------------------------------------------------------------------- |
|
158 TM2GRenderRect& TM2GRenderRect::operator=(const TM2GRenderRect& aRd) |
|
159 { |
|
160 if (this != &aRd) |
|
161 { |
|
162 iAnchorX = aRd.iAnchorX; |
|
163 iAnchorY = aRd.iAnchorY; |
|
164 SetRect(aRd.iTl.iX, aRd.iTl.iY, aRd.iBr.iX, aRd.iBr.iY); |
|
165 } |
|
166 return *this; |
|
167 } |
|
168 |
|
169 // ----------------------------------------------------------------------------- |
|
170 // TM2GRenderRect::GetRegionSizeInPixels |
|
171 // ----------------------------------------------------------------------------- |
|
172 TSize TM2GRenderRect::GetRegionSizeInPixels( |
|
173 TM2GRenderRect& aRect, |
|
174 const TSize& aSz) |
|
175 { |
|
176 return TSize( |
|
177 // determine the width of the region to be paint |
|
178 M2GGeneral::Min< TInt >(aRect.GetAnchorX() + aSz.iWidth, aRect.GetClipX() + aRect.GetClipW()) - |
|
179 M2GGeneral::Max< TInt >(aRect.GetAnchorX(), aRect.GetClipX()), |
|
180 // determine the height of the region to be paint |
|
181 M2GGeneral::Min< TInt >(aRect.GetAnchorY() + aSz.iHeight, aRect.GetClipY() + aRect.GetClipH()) - |
|
182 M2GGeneral::Max< TInt >(aRect.GetAnchorY(), aRect.GetClipY())); |
|
183 } |
|
184 |
|
185 |
|
186 // ----------------------------------------------------------------------------- |
|
187 // TM2GBitmapLock::TM2GBitmapLock |
|
188 // ----------------------------------------------------------------------------- |
|
189 TM2GBitmapLock::TM2GBitmapLock(const CFbsBitmap* aBitmap, TBool aLock) |
|
190 : iBitmap(aBitmap), iIsLocked(EFalse) |
|
191 { |
|
192 if (aLock) |
|
193 { |
|
194 Lock(); |
|
195 } |
|
196 } |
|
197 |
|
198 // ----------------------------------------------------------------------------- |
|
199 // TM2GBitmapLock::~TM2GBitmapLock |
|
200 // ----------------------------------------------------------------------------- |
|
201 TM2GBitmapLock::~TM2GBitmapLock() |
|
202 { |
|
203 Unlock(); |
|
204 } |
|
205 |
|
206 // ----------------------------------------------------------------------------- |
|
207 // TM2GBitmapLock::Lock() |
|
208 // ----------------------------------------------------------------------------- |
|
209 void TM2GBitmapLock::Lock() |
|
210 { |
|
211 if (iBitmap && !iIsLocked) |
|
212 { |
|
213 iBitmap->LockHeap(); |
|
214 iIsLocked = ETrue; |
|
215 } |
|
216 } |
|
217 |
|
218 // ----------------------------------------------------------------------------- |
|
219 // TM2GBitmapLock::Unlock() |
|
220 // ----------------------------------------------------------------------------- |
|
221 void TM2GBitmapLock::Unlock() |
|
222 { |
|
223 if (iBitmap && iIsLocked) |
|
224 { |
|
225 iBitmap->UnlockHeap(); |
|
226 iIsLocked = EFalse; |
|
227 } |
|
228 } |
|
229 |
|
230 TSWTBitBlt::TSWTBitBlt(CBitmapContext& aTargetContext, |
|
231 const TPoint& aPoint, |
|
232 const CFbsBitmap* aBitmap, |
|
233 const TRect* aSourceRect, |
|
234 const CFbsBitmap* aMaskBitmap, |
|
235 TBool aUseNativeClear) |
|
236 : iTargetContext(aTargetContext), |
|
237 iPoint(aPoint), |
|
238 iUseNativeClear(aUseNativeClear) |
|
239 { |
|
240 iBitmap = aBitmap; |
|
241 iRect = aSourceRect; |
|
242 iMaskBitmap = aMaskBitmap; |
|
243 } |
|
244 void TSWTBitBlt::operator()() const |
|
245 { |
|
246 M2G_DEBUG_0("TSWTBitBlt()+"); |
|
247 CFbsBitmap* tempBitmap = new(ELeave) CFbsBitmap; |
|
248 CleanupStack::PushL(tempBitmap); |
|
249 User::LeaveIfError(tempBitmap->Duplicate(iBitmap->Handle())); |
|
250 if (iRect) |
|
251 { |
|
252 if (iUseNativeClear) |
|
253 { |
|
254 iTargetContext.SetBrushColor(KRgbWhite); |
|
255 iTargetContext.Clear(*iRect); |
|
256 } |
|
257 if (iMaskBitmap) |
|
258 { |
|
259 CFbsBitmap* tempMask = new(ELeave) CFbsBitmap; |
|
260 CleanupStack::PushL(tempMask); |
|
261 User::LeaveIfError(tempMask->Duplicate(iMaskBitmap->Handle())); |
|
262 iTargetContext.BitBltMasked( |
|
263 iPoint, tempBitmap, *iRect, tempMask, ETrue); |
|
264 CleanupStack::PopAndDestroy(tempMask); |
|
265 } |
|
266 else |
|
267 { |
|
268 iTargetContext.BitBlt(iPoint, tempBitmap, *iRect); |
|
269 } |
|
270 } |
|
271 else |
|
272 { |
|
273 if (iUseNativeClear) |
|
274 { |
|
275 iTargetContext.SetBrushColor(KRgbWhite); |
|
276 iTargetContext.Clear(); |
|
277 } |
|
278 iTargetContext.BitBlt(iPoint, tempBitmap); |
|
279 } |
|
280 CleanupStack::PopAndDestroy(tempBitmap); |
|
281 M2G_DEBUG_0("TSWTBitBlt()-"); |
|
282 } |
|
283 M2G_NS_END |