|
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 "LcdImage.h" |
|
19 #include <lcdgdrv.h> |
|
20 #include "fbslcdgraphics.h" |
|
21 #include "LcdFbsImage.h" |
|
22 |
|
23 /** |
|
24 * Copy bitmap data from (aColorBitmap,aAlphaBitmap) to aFbsImage. |
|
25 */ |
|
26 extern void CopyBitmapsL |
|
27 ( |
|
28 CLcdGraphicsDriver& aDriver, |
|
29 CLcdFbsImage& aFbsImage, |
|
30 CFbsBitmap* aColorBitmap, |
|
31 CFbsBitmap* aAlphaBitmap, |
|
32 TBool aInvertMask |
|
33 ); |
|
34 |
|
35 CLcdImage::CLcdImage(CLcdGraphicsDriver& aDriver, TBool aMutable) |
|
36 : iDriver(aDriver) |
|
37 , iFbsImage(NULL) |
|
38 , iMutable(aMutable) |
|
39 { |
|
40 } |
|
41 |
|
42 CLcdImage::~CLcdImage() |
|
43 { |
|
44 if (iFbsImage) |
|
45 { |
|
46 iFbsImage->RemoveRef(); |
|
47 } |
|
48 } |
|
49 |
|
50 void CLcdImage::ConstructL(const TSize& aSize, const TImageType& aImageType) |
|
51 { |
|
52 ASSERT(NULL == iFbsImage); |
|
53 ASSERT(aSize.iWidth > 0); |
|
54 ASSERT(aSize.iHeight > 0); |
|
55 |
|
56 iFbsImage = CLcdFbsImage::NewL(aSize, aImageType.iColorMode, aImageType.iAlphaMode); |
|
57 iFbsImage->AddRef(); |
|
58 iTransparency = aImageType.iTransparency; |
|
59 } |
|
60 |
|
61 /** |
|
62 * 2nd phase constructor from bitmap(s) |
|
63 * |
|
64 * Where possible, make a shallow copy (Duplicate) of aColorBitmap and optional aAlphaBitmap, |
|
65 * if that is not possible because the bitmaps do not match the desired image type, make a |
|
66 * deep copy. |
|
67 */ |
|
68 void CLcdImage::ConstructL(CFbsBitmap* aColorBitmap, CFbsBitmap* aAlphaBitmap, const TImageType& aImageType) |
|
69 { |
|
70 ASSERT(NULL == iFbsImage); |
|
71 |
|
72 TDisplayMode colorMode = aColorBitmap->DisplayMode(); |
|
73 TDisplayMode alphaMode = aAlphaBitmap ? aAlphaBitmap->DisplayMode() : ENone; |
|
74 |
|
75 if ((colorMode == aImageType.iColorMode) && (alphaMode == aImageType.iAlphaMode)) |
|
76 { |
|
77 // modes match - just duplicate. |
|
78 iFbsImage = CLcdFbsImage::NewL(aColorBitmap, aAlphaBitmap); |
|
79 iFbsImage->AddRef(); |
|
80 } |
|
81 else |
|
82 { |
|
83 iFbsImage = CLcdFbsImage::NewL(aColorBitmap->SizeInPixels(), aImageType.iColorMode, aImageType.iAlphaMode); |
|
84 iFbsImage->AddRef(); |
|
85 CopyBitmapsL(iDriver, *iFbsImage, aColorBitmap, aAlphaBitmap, EFalse); |
|
86 } |
|
87 |
|
88 iTransparency = aImageType.iTransparency; |
|
89 } |
|
90 |
|
91 TTransparency CLcdImage::Transparency() const |
|
92 { |
|
93 return iTransparency; |
|
94 } |
|
95 |
|
96 TSize CLcdImage::Size() const |
|
97 { |
|
98 return iFbsImage->Size(); |
|
99 } |
|
100 |
|
101 void CLcdImage::CopyRegion(CLcdImage& aSource, const TDrawRegion& aRegion, const TRect& aClipRect) |
|
102 { |
|
103 TTransparency dstTransparency = Transparency(); |
|
104 TTransparency srcTransparency = aSource.Transparency(); |
|
105 |
|
106 TInt error = TFbsLcdGraphics::CopyRegion |
|
107 ( |
|
108 iDriver, |
|
109 iFbsImage->ColorBitmap(), |
|
110 iFbsImage->AlphaBitmap(), |
|
111 dstTransparency, |
|
112 aSource.iFbsImage->ColorBitmap(), |
|
113 aSource.iFbsImage->AlphaBitmap(), |
|
114 srcTransparency, |
|
115 aRegion, |
|
116 aClipRect |
|
117 ); |
|
118 |
|
119 ASSERT(error==KErrNone); |
|
120 } |
|
121 |
|
122 void CLcdImage::SetPixels |
|
123 ( |
|
124 const TRect& aRect, |
|
125 const TUint32* aPixels, |
|
126 TInt aLength, |
|
127 TInt aOffset, |
|
128 TInt aScanLength, |
|
129 const TSize& aSize, |
|
130 TBool aProcessAlpha |
|
131 ) |
|
132 { |
|
133 TInt error = TFbsLcdGraphics::SetPixels |
|
134 ( |
|
135 iDriver, |
|
136 iFbsImage->ColorBitmap(), |
|
137 iFbsImage->AlphaBitmap(), |
|
138 iTransparency, |
|
139 aRect, |
|
140 aPixels, |
|
141 aLength, |
|
142 aOffset, |
|
143 aScanLength, |
|
144 aSize, |
|
145 aProcessAlpha |
|
146 ); |
|
147 |
|
148 ASSERT(error == KErrNone); |
|
149 } |
|
150 |
|
151 void CLcdImage::GetPixels |
|
152 ( |
|
153 const TRect& aRect, |
|
154 TUint32* aPixels, |
|
155 TInt aLength, |
|
156 TInt aOffset, |
|
157 TInt aScanLength, |
|
158 const TSize& aSize |
|
159 ) |
|
160 { |
|
161 TInt error = TFbsLcdGraphics::GetPixels |
|
162 ( |
|
163 iDriver, |
|
164 iFbsImage->ColorBitmap(), |
|
165 iFbsImage->AlphaBitmap(), |
|
166 iTransparency, |
|
167 aRect, |
|
168 aPixels, |
|
169 aLength, |
|
170 aOffset, |
|
171 aScanLength, |
|
172 aSize |
|
173 ); |
|
174 |
|
175 ASSERT(error == KErrNone); |
|
176 } |
|
177 |
|
178 TBool CLcdImage::DetectCollision |
|
179 ( |
|
180 const TRect& aRect1, |
|
181 TInt aTransform1, |
|
182 const TPoint& aPoint1, |
|
183 const CLcdImage& aImage2, |
|
184 const TRect& aRect2, |
|
185 TInt aTransform2, |
|
186 const TPoint& aPoint2 |
|
187 ) |
|
188 { |
|
189 TTransparency transparency1 = iTransparency; |
|
190 CFbsBitmap* alphaBitmap1 = iFbsImage->AlphaBitmap(); |
|
191 if (transparency1 == ETransparencyAlphaChannel || transparency1 == ETransparencyMaskChannel) |
|
192 { |
|
193 alphaBitmap1 = iFbsImage->ColorBitmap(); |
|
194 } |
|
195 |
|
196 TTransparency transparency2 = aImage2.iTransparency; |
|
197 CFbsBitmap* alphaBitmap2 = aImage2.iFbsImage->AlphaBitmap(); |
|
198 if (transparency2 == ETransparencyAlphaChannel || transparency2 == ETransparencyMaskChannel) |
|
199 { |
|
200 alphaBitmap2 = aImage2.iFbsImage->ColorBitmap(); |
|
201 } |
|
202 |
|
203 return TFbsLcdGraphics::DetectCollision |
|
204 ( |
|
205 iDriver, |
|
206 alphaBitmap1, |
|
207 iTransparency, |
|
208 Size(), |
|
209 aRect1, |
|
210 aTransform1, |
|
211 aPoint1, |
|
212 alphaBitmap2, |
|
213 aImage2.Transparency(), |
|
214 aImage2.Size(), |
|
215 aRect2, |
|
216 aTransform2, |
|
217 aPoint2 |
|
218 ); |
|
219 } |
|
220 |
|
221 |
|
222 void CLcdImage::Lock(TBitmapLockCount& aCount, TAcceleratedBitmapInfo& aColorBitmap, TAcceleratedBitmapInfo& aAlphaBitmap) const |
|
223 { |
|
224 CFbsBitmap* colorBitmap = iFbsImage->ColorBitmap(); |
|
225 CFbsBitmap* alphaBitmap = iFbsImage->AlphaBitmap(); |
|
226 |
|
227 TAcceleratedBitmapSpec color(colorBitmap); |
|
228 TAcceleratedBitmapSpec alpha; |
|
229 if (alphaBitmap) |
|
230 { |
|
231 alpha = TAcceleratedBitmapSpec(alphaBitmap); |
|
232 } |
|
233 |
|
234 color.Lock(aCount); |
|
235 color.GetInfo(aColorBitmap); |
|
236 if (alphaBitmap) |
|
237 { |
|
238 alpha.Lock(aCount); |
|
239 alpha.GetInfo(aAlphaBitmap); |
|
240 } |
|
241 else |
|
242 { |
|
243 Mem::FillZ(&aAlphaBitmap, sizeof(TAcceleratedBitmapInfo)); |
|
244 } |
|
245 } |
|
246 |
|
247 void CLcdImage::Unlock(TBitmapLockCount& aCount) const |
|
248 { |
|
249 CFbsBitmap* colorBitmap = iFbsImage->ColorBitmap(); |
|
250 CFbsBitmap* alphaBitmap = iFbsImage->AlphaBitmap(); |
|
251 |
|
252 if (alphaBitmap) |
|
253 { |
|
254 TAcceleratedBitmapSpec alpha(alphaBitmap); |
|
255 alpha.Unlock(aCount); |
|
256 } |
|
257 |
|
258 TAcceleratedBitmapSpec color(colorBitmap); |
|
259 color.Unlock(aCount); |
|
260 } |
|
261 |
|
262 TBool CLcdImage::Mutable() |
|
263 { |
|
264 return iMutable; |
|
265 } |
|
266 |
|
267 /** |
|
268 * Temporary |
|
269 */ |
|
270 CLcdFbsImage* CLcdImage::FbsImage() |
|
271 { |
|
272 return iFbsImage; |
|
273 } |
|
274 |
|
275 TInt CLcdImage::SetImageType(const TImageType& aType) |
|
276 { |
|
277 // |
|
278 // We only support changing from no-transparency images. |
|
279 // |
|
280 if (iTransparency != ETransparencyNone) |
|
281 { |
|
282 return KErrNotSupported; |
|
283 } |
|
284 |
|
285 ASSERT(NULL == iFbsImage->AlphaBitmap()); |
|
286 |
|
287 CFbsBitmap* colorBitmap = iFbsImage->ColorBitmap(); |
|
288 TDisplayMode colorMode = colorBitmap->DisplayMode(); |
|
289 |
|
290 TInt err = KErrNotSupported; |
|
291 if ((colorMode == aType.iColorMode) && (aType.iTransparency == ETransparencyAlphaBitmap)) |
|
292 { |
|
293 // |
|
294 // We are just adding an alpha bitmap. |
|
295 // |
|
296 TRAP(err, iFbsImage->CreateAlphaBitmapL()); |
|
297 } |
|
298 else if ((colorMode == EColor16MU) && (aType.iColorMode == EColor16MA) && (aType.iTransparency == ETransparencyAlphaChannel)) |
|
299 { |
|
300 // |
|
301 // Switch from EColor16MU to EColor16MA mode. |
|
302 // |
|
303 err = colorBitmap->SetDisplayMode(EColor16MA); |
|
304 } |
|
305 |
|
306 if (0 == err) |
|
307 { |
|
308 iTransparency = aType.iTransparency; |
|
309 } |
|
310 |
|
311 return err; |
|
312 } |