|
1 /* |
|
2 * Copyright (c) 2005 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <fbs.h> |
|
19 #include "fbslcdgraphics.h" |
|
20 #include <lcdgdrv.h> |
|
21 |
|
22 #include "DebugArg.h" |
|
23 |
|
24 #ifdef _LCDGDRV_FBSBITMAP_SUPPORT_ |
|
25 |
|
26 |
|
27 /** |
|
28 * Copy a region of a bitmap - used when creating immutable images from mutable ones, or when creating |
|
29 * transformed immutable images from other immutable images. |
|
30 */ |
|
31 TInt TFbsLcdGraphics::CopyRegion |
|
32 ( |
|
33 CLcdGraphicsDriver& aDriver, |
|
34 CFbsBitmap* aDstColorBitmap, |
|
35 CFbsBitmap* aDstAlphaBitmap, |
|
36 TTransparency aDstTransparency, |
|
37 CFbsBitmap* aSrcColorBitmap, |
|
38 CFbsBitmap* aSrcAlphaBitmap, |
|
39 TTransparency aSrcTransparency, |
|
40 const TDrawRegion& aRegion, |
|
41 const TRect& aClipRect |
|
42 ) |
|
43 { |
|
44 TAcceleratedBitmapSpec dstColorSpec(aDstColorBitmap); |
|
45 TAcceleratedBitmapSpec dstAlphaSpec; |
|
46 TAcceleratedBitmapSpec srcColorSpec(aSrcColorBitmap); |
|
47 TAcceleratedBitmapSpec srcAlphaSpec; |
|
48 TAcceleratedBitmapInfo dstColor; |
|
49 TAcceleratedBitmapInfo dstAlpha; |
|
50 TAcceleratedBitmapInfo srcColor; |
|
51 TAcceleratedBitmapInfo srcAlpha; |
|
52 TAcceleratedBitmapInfo* dstAlphaPtr = NULL; |
|
53 TAcceleratedBitmapInfo* srcAlphaPtr = NULL; |
|
54 TBitmapLockCount count; |
|
55 TInt err; |
|
56 |
|
57 if (aDstAlphaBitmap) |
|
58 { |
|
59 new(&dstAlphaSpec) TAcceleratedBitmapSpec(aDstAlphaBitmap); |
|
60 } |
|
61 |
|
62 if (aSrcAlphaBitmap) |
|
63 { |
|
64 new(&srcAlphaSpec) TAcceleratedBitmapSpec(aSrcAlphaBitmap); |
|
65 } |
|
66 |
|
67 // |
|
68 // Lock and copy color bitmaps. |
|
69 // |
|
70 dstColorSpec.Lock(count); |
|
71 srcColorSpec.Lock(count); |
|
72 |
|
73 if (aDstAlphaBitmap) |
|
74 { |
|
75 dstAlphaSpec.Lock(count); |
|
76 } |
|
77 |
|
78 if (aSrcAlphaBitmap) |
|
79 { |
|
80 srcAlphaSpec.Lock(count); |
|
81 } |
|
82 |
|
83 dstColorSpec.GetInfo(dstColor); |
|
84 srcColorSpec.GetInfo(srcColor); |
|
85 |
|
86 if (aDstAlphaBitmap) |
|
87 { |
|
88 dstAlphaSpec.GetInfo(dstAlpha); |
|
89 dstAlphaPtr = &dstAlpha; |
|
90 } |
|
91 |
|
92 if (aSrcAlphaBitmap) |
|
93 { |
|
94 srcAlphaSpec.GetInfo(srcAlpha); |
|
95 srcAlphaPtr = &srcAlpha; |
|
96 } |
|
97 |
|
98 TTransformType transform = (TTransformType)aRegion.iTransform; |
|
99 TAnchor anchor = (TAnchor)aRegion.iAnchor; |
|
100 |
|
101 TRect srcRect(aRegion.iSrcRect); |
|
102 TRect clipRect(dstColor.iSize); |
|
103 clipRect.Intersection(aClipRect); |
|
104 |
|
105 // |
|
106 // Compute destination rectangle with anchor point at aRegion.iDstPoint. |
|
107 // |
|
108 // Destination rectangle need not lie within destination image. |
|
109 // |
|
110 TRect dstRect = CalcDstRect(aRegion.iDstPoint, srcRect.Size(), transform, anchor); |
|
111 |
|
112 err = aDriver.CopyRegion( |
|
113 &dstColor, |
|
114 dstAlphaPtr, |
|
115 aDstTransparency, |
|
116 dstRect, |
|
117 &srcColor, |
|
118 srcAlphaPtr, |
|
119 aSrcTransparency, |
|
120 srcRect, |
|
121 transform, |
|
122 clipRect |
|
123 ); |
|
124 |
|
125 if (aSrcAlphaBitmap) |
|
126 { |
|
127 srcAlphaSpec.Unlock(count); |
|
128 } |
|
129 if (aDstAlphaBitmap) |
|
130 { |
|
131 dstAlphaSpec.Unlock(count); |
|
132 } |
|
133 |
|
134 srcColorSpec.Unlock(count); |
|
135 dstColorSpec.Unlock(count); |
|
136 |
|
137 return err; |
|
138 } |
|
139 |
|
140 TInt TFbsLcdGraphics::GetPixels |
|
141 ( |
|
142 CLcdGraphicsDriver& aDriver, |
|
143 CFbsBitmap* aSrcColorBitmap, |
|
144 CFbsBitmap* aSrcAlphaBitmap, |
|
145 TTransparency aSrcTransparency, |
|
146 const TRect& aSrcRect, |
|
147 TUint32* aARGB32Pixels, |
|
148 TInt DEBUG_ARG(aLength), |
|
149 TInt aOffset, |
|
150 TInt aLinePitch, |
|
151 const TSize& aSize |
|
152 ) |
|
153 { |
|
154 ASSERT((aOffset >= 0) && (aOffset < aLength)); |
|
155 ASSERT((aOffset + aLinePitch*(aSize.iHeight-1) + aSize.iWidth - 1) >= 0); |
|
156 ASSERT((aOffset + aLinePitch*(aSize.iHeight-1) + aSize.iWidth - 1) < aLength); |
|
157 |
|
158 TAcceleratedBitmapSpec srcColorSpec(aSrcColorBitmap); |
|
159 TAcceleratedBitmapSpec srcAlphaSpec; |
|
160 if (aSrcAlphaBitmap) |
|
161 { |
|
162 new(&srcAlphaSpec) TAcceleratedBitmapSpec(aSrcAlphaBitmap); |
|
163 } |
|
164 |
|
165 TAcceleratedBitmapInfo dstColor; |
|
166 TAcceleratedBitmapInfo srcColor; |
|
167 TAcceleratedBitmapInfo srcAlpha; |
|
168 TBitmapLockCount count; |
|
169 TAcceleratedBitmapInfo* srcAlphaPtr = NULL; |
|
170 |
|
171 TTransformType transform = ETransNone; |
|
172 TUint8* address = (TUint8*)(aARGB32Pixels) + aOffset*sizeof(TUint32); |
|
173 if (aLinePitch < 0) |
|
174 { |
|
175 // |
|
176 // compute address of first row of image. |
|
177 // |
|
178 address += aLinePitch * (aSize.iHeight - 1) * sizeof(TUint32); |
|
179 |
|
180 // |
|
181 // use vertical reflection blitter. |
|
182 // |
|
183 transform = ETransMirrorRot180; |
|
184 |
|
185 // |
|
186 // correct sign of linePitch |
|
187 // |
|
188 aLinePitch = - aLinePitch; |
|
189 } |
|
190 |
|
191 CLcdGraphicsDriver::TDriverInfo info; |
|
192 aDriver.GetDriverInfo(info); |
|
193 |
|
194 dstColor.iAddress = address; |
|
195 dstColor.iDisplayMode = info.iARGB8888Mode; |
|
196 dstColor.iPixelShift = 5; // or 32? |
|
197 dstColor.iLinePitch = aLinePitch*sizeof(TUint32); // bytes |
|
198 dstColor.iSize = aSize; // |
|
199 dstColor.iPhysicalAddress = NULL; // software bitmap |
|
200 |
|
201 srcColorSpec.Lock(count); |
|
202 srcColorSpec.GetInfo(srcColor); |
|
203 if (aSrcAlphaBitmap) |
|
204 { |
|
205 srcAlphaSpec.Lock(count); |
|
206 srcAlphaSpec.GetInfo(srcAlpha); |
|
207 srcAlphaPtr = &srcAlpha; |
|
208 } |
|
209 |
|
210 TRect dstRect(aSize); |
|
211 TRect clipRect(aSize); |
|
212 |
|
213 TInt err = aDriver.CopyRegion |
|
214 ( |
|
215 &dstColor, |
|
216 NULL, |
|
217 ETransparencyAlphaChannel, |
|
218 dstRect, |
|
219 &srcColor, |
|
220 srcAlphaPtr, |
|
221 aSrcTransparency, |
|
222 aSrcRect, |
|
223 transform, |
|
224 clipRect |
|
225 ); |
|
226 |
|
227 if (aSrcAlphaBitmap) |
|
228 { |
|
229 srcAlphaSpec.Unlock(count); |
|
230 } |
|
231 srcColorSpec.Unlock(count); |
|
232 |
|
233 return err; |
|
234 } |
|
235 |
|
236 /** |
|
237 * |
|
238 */ |
|
239 TInt TFbsLcdGraphics::SetPixels |
|
240 ( |
|
241 CLcdGraphicsDriver& aDriver, |
|
242 CFbsBitmap* aDstColorBitmap, |
|
243 CFbsBitmap* aDstAlphaBitmap, |
|
244 TTransparency aDstTransparency, |
|
245 const TRect& aDstRect, |
|
246 const TUint32* aARGB32Pixels, |
|
247 TInt DEBUG_ARG(aLength), |
|
248 TInt aOffset, |
|
249 TInt aLinePitch, |
|
250 const TSize& aSize, |
|
251 TBool aAlpha |
|
252 ) |
|
253 { |
|
254 ASSERT((aOffset >= 0) && (aOffset < aLength)); |
|
255 ASSERT((aOffset + aLinePitch*(aSize.iHeight-1) + aSize.iWidth - 1) >= 0); |
|
256 ASSERT((aOffset + aLinePitch*(aSize.iHeight-1) + aSize.iWidth - 1) < aLength); |
|
257 |
|
258 TAcceleratedBitmapSpec dstColorSpec(aDstColorBitmap); |
|
259 TAcceleratedBitmapSpec dstAlphaSpec; |
|
260 if (aDstAlphaBitmap) |
|
261 { |
|
262 new(&dstAlphaSpec) TAcceleratedBitmapSpec(aDstAlphaBitmap); |
|
263 } |
|
264 |
|
265 TAcceleratedBitmapInfo srcColor; |
|
266 TAcceleratedBitmapInfo dstColor; |
|
267 TAcceleratedBitmapInfo dstAlpha; |
|
268 TAcceleratedBitmapInfo* dstAlphaPtr = NULL; |
|
269 TBitmapLockCount count; |
|
270 |
|
271 |
|
272 TTransformType transform = ETransNone; |
|
273 TUint8* address = (TUint8*)(aARGB32Pixels) + aOffset*sizeof(TUint32); |
|
274 if (aLinePitch < 0) |
|
275 { |
|
276 // |
|
277 // compute address of first row of image. |
|
278 // |
|
279 address += aLinePitch * (aSize.iHeight - 1) * sizeof(TUint32); |
|
280 |
|
281 // |
|
282 // use vertical reflection blitter. |
|
283 // |
|
284 transform = ETransMirrorRot180; |
|
285 |
|
286 // |
|
287 // correct sign of linePitch |
|
288 // |
|
289 aLinePitch = - aLinePitch; |
|
290 } |
|
291 |
|
292 CLcdGraphicsDriver::TDriverInfo info; |
|
293 aDriver.GetDriverInfo(info); |
|
294 |
|
295 srcColor.iAddress = address; // address of top-left pixel in src |
|
296 srcColor.iDisplayMode = info.iARGB8888Mode; // how driver recognises ARGB8888 pixels |
|
297 srcColor.iPixelShift = 5; // |
|
298 srcColor.iLinePitch = aLinePitch*sizeof(TUint32); // bytes |
|
299 srcColor.iSize = aSize; // |
|
300 srcColor.iPhysicalAddress = NULL; // software bitmap |
|
301 |
|
302 TTransparency srcTransparency = (aAlpha ? ETransparencyAlphaChannel : ETransparencyIgnoreChannel); |
|
303 |
|
304 dstColorSpec.Lock(count); |
|
305 dstColorSpec.GetInfo(dstColor); |
|
306 if (aDstAlphaBitmap) |
|
307 { |
|
308 dstAlphaSpec.Lock(count); |
|
309 dstAlphaSpec.GetInfo(dstAlpha); |
|
310 dstAlphaPtr = &dstAlpha; |
|
311 } |
|
312 |
|
313 TRect srcRect(aSize); |
|
314 TRect clipRect(dstColor.iSize); |
|
315 |
|
316 TInt err = aDriver.CopyRegion |
|
317 ( |
|
318 &dstColor, |
|
319 dstAlphaPtr, |
|
320 aDstTransparency, |
|
321 aDstRect, |
|
322 &srcColor, |
|
323 NULL, |
|
324 srcTransparency, |
|
325 srcRect, |
|
326 transform, |
|
327 clipRect |
|
328 ); |
|
329 |
|
330 if (aDstAlphaBitmap) |
|
331 { |
|
332 dstAlphaSpec.Unlock(count); |
|
333 } |
|
334 dstColorSpec.Unlock(count); |
|
335 |
|
336 return err; |
|
337 } |
|
338 |
|
339 |
|
340 TBool TFbsLcdGraphics::DetectCollision |
|
341 ( |
|
342 CLcdGraphicsDriver& aDriver, |
|
343 |
|
344 CFbsBitmap* aMask1, |
|
345 TTransparency aTransparency1, |
|
346 const TSize& aSize1, |
|
347 const TRect& aRect1, |
|
348 TInt aTransform1, |
|
349 const TPoint& aPoint1, |
|
350 |
|
351 CFbsBitmap* aMask2, |
|
352 TTransparency aTransparency2, |
|
353 const TSize& aSize2, |
|
354 const TRect& aRect2, |
|
355 TInt aTransform2, |
|
356 const TPoint& aPoint2 |
|
357 ) |
|
358 { |
|
359 TAcceleratedBitmapSpec bitmapSpec1; |
|
360 TAcceleratedBitmapInfo bitmapInfo1; |
|
361 TAcceleratedBitmapInfo* bitmapPtr1 = NULL; |
|
362 TAcceleratedBitmapSpec bitmapSpec2; |
|
363 TAcceleratedBitmapInfo bitmapInfo2; |
|
364 TAcceleratedBitmapInfo* bitmapPtr2 = NULL; |
|
365 |
|
366 TBitmapLockCount count; |
|
367 |
|
368 if (aMask1) |
|
369 { |
|
370 bitmapSpec1 = TAcceleratedBitmapSpec(aMask1); |
|
371 } |
|
372 |
|
373 if (aMask2) |
|
374 { |
|
375 bitmapSpec2 = TAcceleratedBitmapSpec(aMask2); |
|
376 } |
|
377 |
|
378 if (aMask1) |
|
379 { |
|
380 bitmapSpec1.Lock(count); |
|
381 bitmapSpec1.GetInfo(bitmapInfo1); |
|
382 bitmapPtr1 = &bitmapInfo1; |
|
383 } |
|
384 |
|
385 if (aMask2) |
|
386 { |
|
387 bitmapSpec2.Lock(count); |
|
388 bitmapSpec2.GetInfo(bitmapInfo2); |
|
389 bitmapPtr2 = &bitmapInfo2; |
|
390 } |
|
391 |
|
392 TBool collision = aDriver.DetectCollision( |
|
393 bitmapPtr1, |
|
394 aTransparency1, |
|
395 aSize1, |
|
396 aRect1, |
|
397 aTransform1, |
|
398 aPoint1, |
|
399 |
|
400 bitmapPtr2, |
|
401 aTransparency2, |
|
402 aSize2, |
|
403 aRect2, |
|
404 aTransform2, |
|
405 aPoint2 |
|
406 ); |
|
407 |
|
408 if (aMask2) |
|
409 { |
|
410 bitmapSpec2.Unlock(count); |
|
411 } |
|
412 |
|
413 if (aMask1) |
|
414 { |
|
415 bitmapSpec1.Unlock(count); |
|
416 } |
|
417 |
|
418 return collision; |
|
419 } |
|
420 #endif |
|
421 |
|
422 /** |
|
423 * Compute destination rectangle of rectangle of size aSrcSize, transformed by aSrcTransform |
|
424 * and then positioned with a reference point specified by aSrcAnchor at aDstPoint. |
|
425 */ |
|
426 TRect CalcDstRect(const TPoint& aDstPoint, const TSize& aSrcSize, TTransformType aSrcTransform, TAnchor aSrcAnchor) |
|
427 { |
|
428 TPoint point = aDstPoint; |
|
429 TSize size = aSrcSize; |
|
430 |
|
431 if (aSrcTransform & EReflectDiag) |
|
432 { |
|
433 TInt tmp = size.iWidth; |
|
434 size.iWidth = size.iHeight; |
|
435 size.iHeight = tmp; |
|
436 } |
|
437 |
|
438 if (aSrcAnchor & EAnchorHCenter) |
|
439 { |
|
440 point.iX -= size.iWidth/2; |
|
441 } |
|
442 else if (aSrcAnchor & EAnchorRight) |
|
443 { |
|
444 point.iX -= size.iWidth; |
|
445 } |
|
446 |
|
447 if (aSrcAnchor & EAnchorVCenter) |
|
448 { |
|
449 point.iY -= size.iHeight/2; |
|
450 } |
|
451 else if (aSrcAnchor & EAnchorBottom) |
|
452 { |
|
453 point.iY -= size.iHeight; |
|
454 } |
|
455 |
|
456 return TRect(point, size); |
|
457 } |