|
1 // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <s32file.h> |
|
17 #include <bitmap.h> |
|
18 #include <graphicsaccelerator.h> |
|
19 #include <fbs.h> |
|
20 #include <graphics/bitmapuid.h> |
|
21 #include "fbsdefs.h" |
|
22 #include "UTILS.H" |
|
23 #include "fbshelper.h" |
|
24 #include "fbsrasterizer.h" |
|
25 #include "BitwiseBitmap.inl" |
|
26 #include "fbsmessage.h" |
|
27 #include "bitmapconst.h" |
|
28 |
|
29 const TInt KMaxPixelSize = KMaxTInt / 4; // Maximum pixel size to avoid some overflow problems |
|
30 const TInt KMaxBitmapHandleBufferSize = KNumBytesPerBitmapHandle * 2000; // Maximum size of buffer to store all bitmap handles. |
|
31 |
|
32 GLREF_C void Panic(TFbsPanic aPanic); |
|
33 |
|
34 //If we have to handle RAM located file with an embedded ROM mbm file section - |
|
35 //KRomMBMInRamRSC should be ETrue. |
|
36 //If it is not allowed to do that - KRomMBMInRamRSC should be EFalse. |
|
37 //The same constant is defined into TDefect test app. It should be changed too. |
|
38 #pragma warning(disable : 4127) //conditional expression is constant |
|
39 LOCAL_D const TBool KRomMBMInRamRSC = EFalse; |
|
40 |
|
41 //Cleanup function used by CFbsBitmap::LoadShiftedRomBmpL(...) |
|
42 LOCAL_D void FreeMem(TAny* aMem) |
|
43 { |
|
44 delete[] static_cast<TUint8*>(aMem); |
|
45 } |
|
46 |
|
47 // Fbs style bitmap client class for font bitmap server |
|
48 /** @publishedAll */ |
|
49 EXPORT_C CFbsBitmap::CFbsBitmap(): |
|
50 CBase(), |
|
51 iFbs(RFbsSession::GetSession()), |
|
52 iAddressPointer(NULL), |
|
53 iFlags(0), |
|
54 iUseCount(0), |
|
55 iHandle(0), |
|
56 iServerHandle(0) |
|
57 { |
|
58 } |
|
59 |
|
60 /** Destructor. Calls Reset(). |
|
61 @see Reset() |
|
62 @publishedAll |
|
63 @released |
|
64 */ |
|
65 EXPORT_C CFbsBitmap::~CFbsBitmap() |
|
66 { |
|
67 Reset(); |
|
68 } |
|
69 |
|
70 /** Gets the physical length in bytes of a scanline in memory. |
|
71 This is aligned to a 4 byte (DWORD) boundary for performance reasons. |
|
72 |
|
73 @param aLength The length of a scanline in pixels. |
|
74 @param aDispMode The display mode of the bitmap. |
|
75 @return Number of bytes in the scanline in memory. |
|
76 @publishedAll |
|
77 @released |
|
78 */ |
|
79 EXPORT_C TInt CFbsBitmap::ScanLineLength(TInt aLength,TDisplayMode aDispMode) |
|
80 { |
|
81 if (aDispMode == ERgb) |
|
82 return aLength * 4; |
|
83 else if (aDispMode == ENone) |
|
84 return 0; |
|
85 |
|
86 return CBitwiseBitmap::ByteWidth(aLength,aDispMode); |
|
87 } |
|
88 |
|
89 /** Releases the bitmap's handle from the font and bitmap server and decrements |
|
90 its access count. |
|
91 The server-side bitmap is only deleted when the access count for the bitmap |
|
92 decrements to zero. |
|
93 @publishedAll |
|
94 @released |
|
95 */ |
|
96 EXPORT_C void CFbsBitmap::Reset() |
|
97 { |
|
98 if (iHandle && !(iFlags & EIsRomBitmap)) |
|
99 { |
|
100 iFbs->SendCommand(EFbsMessClose, iHandle, Handle()); |
|
101 iFbs->iHelper->RemoveBitmap(*this); |
|
102 } |
|
103 if (KRomMBMInRamRSC && (iFlags & EIsRomBitmap)) |
|
104 { |
|
105 // If it is a ROM bitmap, we have to check, is it a ROM bitmap located |
|
106 // in RAM? If yes, then we have to deallocate the bitmap memory. |
|
107 TBool isInRom = EFalse; |
|
108 TInt ret = User::IsRomAddress(isInRom, iAddressPointer); |
|
109 if (ret == KErrNone && !isInRom) |
|
110 delete[] reinterpret_cast<TUint8*>(iAddressPointer); |
|
111 } |
|
112 iAddressPointer = NULL; |
|
113 iFlags = 0; |
|
114 iUseCount = 0; |
|
115 iHandle = 0; |
|
116 iServerHandle = 0; |
|
117 } |
|
118 |
|
119 /** Tests whether or not the bitmap is read-only. |
|
120 @return ETrue if the bitmap is read-only, EFalse otherwise. |
|
121 @publishedAll |
|
122 @released |
|
123 */ |
|
124 EXPORT_C TBool CFbsBitmap::IsRomBitmap() const |
|
125 { |
|
126 return (iFlags & EIsReadOnlyBitmapMask) > 0; |
|
127 } |
|
128 |
|
129 /** Sets the bitmap to use a bitmap image stored in ROM. |
|
130 @param aRomBitmapPointer Pointer to a bitmap stored in ROM. |
|
131 @param aBitmapSizeInBytes On return, indicates the size of |
|
132 the bitmap in bytes. |
|
133 @leave KErrUnknown aRomBitmapPointer is not in ROM, or has an invalid UID. |
|
134 @publishedAll |
|
135 @released |
|
136 */ |
|
137 EXPORT_C void CFbsBitmap::SetRomBitmapL(CBitwiseBitmap* aRomBitmapPointer,TInt& aBitmapSizeInBytes) |
|
138 { |
|
139 TBool isInRom = EFalse; |
|
140 TInt ret = User::IsRomAddress(isInRom,(TAny*)aRomBitmapPointer); |
|
141 if (ret != KErrNone || !isInRom || aRomBitmapPointer->Uid() != KCBitwiseBitmapUid) |
|
142 User::Leave(KErrUnknown); |
|
143 |
|
144 Reset(); |
|
145 iAddressPointer = aRomBitmapPointer; |
|
146 iFlags = EIsRomBitmap; |
|
147 iHandle = 1; |
|
148 |
|
149 User::LeaveIfError(iFbs->AllocScanLineBuffer(aRomBitmapPointer->iByteWidth + 4)); |
|
150 aBitmapSizeInBytes = Align4(aRomBitmapPointer->iHeader.iBitmapSize + 28); |
|
151 } |
|
152 |
|
153 CBitwiseBitmap* CFbsBitmap::Address() const |
|
154 { |
|
155 if (!iHandle) |
|
156 return NULL; |
|
157 return iAddressPointer; |
|
158 } |
|
159 |
|
160 EXPORT_C CBitwiseBitmap* CFbsBitmap::CleanAddress() const |
|
161 { |
|
162 if (!iHandle) |
|
163 return NULL; |
|
164 // Don't try to clean a dirty bitmap between calls to BeginDataAccess() and EndDataAccess(), i.e. iUseCount > 0 |
|
165 // ROM bitmaps can never be dirty |
|
166 if (!(iFlags & EIsReadOnlyBitmapMask) && iUseCount == 0 && iAddressPointer->iSettings.IsDirtyBitmap()) |
|
167 { |
|
168 TPckgBuf<TBmpHandles> handlebuf; |
|
169 TIpcArgs args(iHandle, &handlebuf); |
|
170 if (iFbs->SendCommand(EFbsMessBitmapClean, args) == KErrNone) |
|
171 { |
|
172 const_cast<CFbsBitmap*>(this)->iHandle = handlebuf().iHandle; |
|
173 const_cast<CFbsBitmap*>(this)->iServerHandle = handlebuf().iServerHandle; |
|
174 const_cast<CFbsBitmap*>(this)->iAddressPointer = (CBitwiseBitmap*)(iFbs->HeapBase() + handlebuf().iAddressOffset); |
|
175 } |
|
176 } |
|
177 return iAddressPointer; |
|
178 } |
|
179 |
|
180 inline CBitwiseBitmap* CFbsBitmap::BeginDataAccessAndGetCleanAddress(TUint32*& aDataAddress) const |
|
181 { |
|
182 BeginDataAccess(); |
|
183 CBitwiseBitmap* bmp = Address(); |
|
184 // aDataAddress should be consistent with bmp since after the call to BeginDataAccess() |
|
185 // the call to DataAddress() will not clean the bitmap again |
|
186 aDataAddress = DataAddress(); |
|
187 return bmp; |
|
188 } |
|
189 |
|
190 /** Gets the address of the first pixel in the bitmap. |
|
191 The first pixel is at the top-left. Access to the pixel data of a bitmap |
|
192 should be surrounded by calls to BeginDataAccess() and EndDataAccess(), |
|
193 otherwise performance may be degraded on certain platforms. |
|
194 |
|
195 Note: Performing a Resize() or Compress() operation changes the value returned by this function. |
|
196 @return The address of the first pixel of the bitmap. |
|
197 @publishedAll |
|
198 @released |
|
199 @see CFbsBitmap::BeginDataAccess() |
|
200 @see CFbsBitmap::EndDataAccess() |
|
201 */ |
|
202 EXPORT_C TUint32* CFbsBitmap::DataAddress() const |
|
203 { |
|
204 if(!iHandle) return(NULL); |
|
205 CBitwiseBitmap* bmp = CleanAddress(); |
|
206 |
|
207 if (!(iFlags & EIsReadOnlyBitmapMask) && (iUseCount == 0)) |
|
208 bmp->iSettings.SetVolatileBitmap(); |
|
209 |
|
210 if(bmp->iUid.iUid==KCBitwiseBitmapHardwareUid.iUid) // RHardwareBitmap |
|
211 { |
|
212 RHardwareBitmap hwb(bmp->iDataOffset); // iDataOffset = handle for hardware bitmap |
|
213 TAcceleratedBitmapInfo info; |
|
214 const TInt ret = hwb.GetInfo(info); |
|
215 return ret!=KErrNone ? NULL : (reinterpret_cast<TUint32*>(info.iAddress)); |
|
216 } |
|
217 |
|
218 if (bmp->iHeap == NULL) |
|
219 return(reinterpret_cast<TUint32*>((TUint8*)bmp+bmp->iDataOffset)); |
|
220 return(reinterpret_cast<TUint32*>(iFbs->iLargeBitmapChunk.Base()+bmp->iDataOffset)); |
|
221 } |
|
222 |
|
223 /** Gets the length in bytes between scanlines in memory. |
|
224 @return The length in bytes between scanlines in memory. |
|
225 @internalAll |
|
226 @released |
|
227 */ |
|
228 EXPORT_C TInt CFbsBitmap::DataStride() const |
|
229 { |
|
230 if (!iHandle) |
|
231 { |
|
232 return 0; |
|
233 } |
|
234 |
|
235 CBitwiseBitmap* bmp = CleanAddress(); |
|
236 if (bmp==NULL) |
|
237 { |
|
238 return 0; |
|
239 } |
|
240 |
|
241 return bmp->DataStride(); |
|
242 } |
|
243 |
|
244 /** Creates a bitmap with the specified size and display mode. The bitmap is |
|
245 created on the font and bitmap server's shared heap. |
|
246 @param aSizeInPixels The size of the bitmap to be created. |
|
247 @param aDispMode The display mode of the bitmap to be created. |
|
248 @return KErrNone if successful; KErrCouldNotConnect if no connection to the |
|
249 font and bitmap server could be made; KErrArgument if either the width or height specified |
|
250 in aSizeInPixels are negative or if the requested display mode is invalid; KErrTooBig |
|
251 if the requested size is too big. |
|
252 @publishedAll |
|
253 @released |
|
254 */ |
|
255 EXPORT_C TInt CFbsBitmap::Create(const TSize& aSizeInPixels,TDisplayMode aDispMode) |
|
256 { |
|
257 return DoCreate(aSizeInPixels,aDispMode,KUidCFbsBitmapCreation); |
|
258 } |
|
259 |
|
260 TInt CFbsBitmap::DoCreate(const TSize& aSizeInPixels, TDisplayMode aDispMode, TUid aUid, TInt aDataSize) |
|
261 { |
|
262 if(!iFbs) return(KErrCouldNotConnect); |
|
263 if (aDispMode <= ENone || aDispMode == ERgb || aDispMode >= EColorLast) return KErrArgument; |
|
264 if(aSizeInPixels.iWidth<0 || aSizeInPixels.iHeight<0) return(KErrArgument); |
|
265 if (aDataSize < 0) return KErrArgument; |
|
266 Reset(); |
|
267 TBmpSpec bmpspec; |
|
268 bmpspec.iSizeInPixels=aSizeInPixels; |
|
269 bmpspec.iDispMode=aDispMode; |
|
270 bmpspec.iHandle = aUid.iUid; // Use iHandle to pass UID |
|
271 bmpspec.iServerHandle = aDataSize; // Use iServerHandle to pass data size |
|
272 TPckgBuf<TBmpSpec> b; |
|
273 b=bmpspec; |
|
274 TIpcArgs args(&b); |
|
275 TInt ret=iFbs->SendCommand(EFbsMessBitmapCreate,args); |
|
276 if(ret!=KErrNone) return(ret); |
|
277 iHandle=b().iHandle; |
|
278 iServerHandle=b().iServerHandle; |
|
279 iAddressPointer=(CBitwiseBitmap*)(iFbs->HeapBase()+b().iAddressOffset); |
|
280 if (aDataSize > 0) // explicitly specified data size means extended bitmap |
|
281 { |
|
282 iFlags = EIsExtendedBitmap; |
|
283 } |
|
284 ret = iFbs->iHelper->AddBitmap(*this); |
|
285 if (ret != KErrNone) |
|
286 return ret; |
|
287 return iFbs->AllocScanLineBuffer(CBitwiseBitmap::ByteWidth(aSizeInPixels.iWidth, aDispMode)+4); |
|
288 } |
|
289 |
|
290 /** Creates a hardware bitmap with a size and display mode. |
|
291 @param aSizeInPixels The bitmap's width and height in pixels. |
|
292 @param aDispMode The bitmap's display mode. |
|
293 @param aCreatorUid The UID of the application calling this function. This is |
|
294 used to allow segregation of the memory used for hardware bitmaps. For instance, |
|
295 if a device has video memory attached to display and graphics accelerator |
|
296 hardware, this UID is used to determine whether any video memory is pre-allocated |
|
297 for that application's use. |
|
298 @return KErrNone if successful, otherwise one of the system wide error codes. |
|
299 These include KErrCouldNotConnect if no connection has been made to the font |
|
300 and bitmap server, KErrArgument if either the width or height specified in |
|
301 aSizeInPixels are negative or if the requested display mode is invalid, or KErrNotSupported |
|
302 if hardware bitmaps are not supported on the device. |
|
303 @publishedAll |
|
304 @released |
|
305 */ |
|
306 EXPORT_C TInt CFbsBitmap::CreateHardwareBitmap(const TSize& aSizeInPixels,TDisplayMode aDispMode,TUid aCreatorUid) |
|
307 { |
|
308 return DoCreate(aSizeInPixels,aDispMode,aCreatorUid); |
|
309 } |
|
310 |
|
311 /** Resets the pixel-size of the bitmap. |
|
312 If the new size is bigger than the old, the original bitmap is still situated |
|
313 at (0,0), but pixels outside the range of the old pixel-size are set to zero. |
|
314 @param aSizeInPixels The new size of the bitmap. |
|
315 @return KErrNone if successful; KErrArgument if the new size is illegal; |
|
316 KErrGeneral if the bitmap has not yet been created; KErrAccessDenied if the |
|
317 bitmap is in ROM or is an extended bitmap; otherwise another of the system-wide error codes. |
|
318 @publishedAll |
|
319 @released |
|
320 */ |
|
321 EXPORT_C TInt CFbsBitmap::Resize(const TSize& aSizeInPixels) |
|
322 { |
|
323 if(aSizeInPixels.iWidth<0 || aSizeInPixels.iHeight<0) |
|
324 return(KErrArgument); |
|
325 if(aSizeInPixels.iWidth>KMaxPixelSize || aSizeInPixels.iHeight>KMaxPixelSize) |
|
326 return(KErrTooBig); |
|
327 if(!iHandle) |
|
328 return(KErrGeneral); |
|
329 if (iFlags & EIsReadOnlyBitmapMask) |
|
330 return(KErrAccessDenied); |
|
331 TPckgBuf<TBmpHandles> handlebuf; |
|
332 TIpcArgs args(iHandle, aSizeInPixels.iWidth, aSizeInPixels.iHeight, &handlebuf); |
|
333 TInt err = iFbs->SendCommand(EFbsMessBitmapResize, args); |
|
334 if (err != KErrNone) |
|
335 return (err); |
|
336 iHandle = handlebuf().iHandle; |
|
337 iServerHandle = handlebuf().iServerHandle; |
|
338 iAddressPointer = (CBitwiseBitmap*)(iFbs->HeapBase() + handlebuf().iAddressOffset); |
|
339 return iFbs->AllocScanLineBuffer(CBitwiseBitmap::ByteWidth(aSizeInPixels.iWidth, DisplayMode())+4); |
|
340 } |
|
341 |
|
342 /** Gets the display mode of the bitmap. |
|
343 @return The display mode of the bitmap. |
|
344 @publishedAll |
|
345 @released |
|
346 */ |
|
347 EXPORT_C TDisplayMode CFbsBitmap::DisplayMode() const |
|
348 { |
|
349 if(iHandle==NULL) return(ENone); |
|
350 return CleanAddress()->DisplayMode(); |
|
351 } |
|
352 |
|
353 /** Returns the display mode that was used to create the bitmap. |
|
354 @return The display mode used to create the bitmap. |
|
355 @publishedAll |
|
356 @released |
|
357 */ |
|
358 EXPORT_C TDisplayMode CFbsBitmap::InitialDisplayMode() const |
|
359 { |
|
360 if(iHandle == NULL) |
|
361 { |
|
362 return ENone; |
|
363 } |
|
364 return CleanAddress()->InitialDisplayMode(); |
|
365 } |
|
366 |
|
367 /** |
|
368 Changes the display mode of the bitmap. |
|
369 The requested display mode cannot be greater (in bpp value) than the initial display mode. |
|
370 This method cannot leave, for instance because of an out of memory condition. No |
|
371 additional memory is allocated or leaving methods called. |
|
372 The bitmap's content is preserved when converting it to the requested display mode, |
|
373 but there may be some loss of quality. |
|
374 @publishedAll |
|
375 @released |
|
376 @param aDisplayMode The requested display mode. |
|
377 @return KErrArgument if the requested mode is invalid, or has a greater bpp value |
|
378 than the initial mode. KErrNotSupported if the bitmap is compressed, or is a |
|
379 ROM bitmap, an extended bitmap or a hardware bitmap. KErrGeneral if the bitmap |
|
380 handle is NULL. KErrNone if the method call is successful. |
|
381 @see CFbsBitmap::InitialDisplayMode() |
|
382 */ |
|
383 EXPORT_C TInt CFbsBitmap::SetDisplayMode(TDisplayMode aDisplayMode) |
|
384 { |
|
385 if(!iHandle) |
|
386 { |
|
387 return KErrGeneral; |
|
388 } |
|
389 TUint32* data; |
|
390 CBitwiseBitmap* bmp = BeginDataAccessAndGetCleanAddress(data); |
|
391 TInt err = bmp->SetDisplayMode(aDisplayMode, data); |
|
392 EndDataAccess(EFalse); |
|
393 return err; |
|
394 } |
|
395 |
|
396 /** Duplicates a bitmap. |
|
397 This function does not create a copy of the bitmap. It just assigns another |
|
398 handle to the bitmap in the font and bitmap server, and sets this object's |
|
399 handle to that. If the specified bitmap is in the ROM, it just assigns a pointer |
|
400 to it. |
|
401 @param aHandle The handle to an existing bitmap. |
|
402 @return KErrNone if successful; KErrCouldNotConnect if no connection to the |
|
403 font and bitmap server could be made; KErrUnknown if no bitmap could be found |
|
404 with the specified handle number. |
|
405 @publishedAll |
|
406 @released |
|
407 @see CFbsBitmap::Handle() |
|
408 */ |
|
409 EXPORT_C TInt CFbsBitmap::Duplicate(TInt aBitmapHandle) |
|
410 { |
|
411 if(!iFbs) |
|
412 { |
|
413 return(KErrCouldNotConnect); |
|
414 } |
|
415 if(!aBitmapHandle) |
|
416 { |
|
417 return(KErrUnknown); |
|
418 } |
|
419 Reset(); |
|
420 TBool isinrom=EFalse; |
|
421 TInt ret=User::IsRomAddress(isinrom,(TAny*)aBitmapHandle); |
|
422 if(ret!=KErrNone) |
|
423 { |
|
424 return(KErrUnknown); |
|
425 } |
|
426 if(isinrom) |
|
427 { |
|
428 if (((CBitwiseBitmap*)aBitmapHandle)->Uid() != KCBitwiseBitmapUid) |
|
429 return(KErrUnknown); |
|
430 iAddressPointer = (CBitwiseBitmap*)aBitmapHandle; |
|
431 iFlags = EIsRomBitmap; |
|
432 iHandle=1; |
|
433 return iFbs->AllocScanLineBuffer(iAddressPointer->iByteWidth + 4); |
|
434 } |
|
435 TPckgBuf<TBmpHandles> b; |
|
436 TIpcArgs args(aBitmapHandle,&b); |
|
437 ret=iFbs->SendCommand(EFbsMessBitmapDuplicate,args); |
|
438 if(ret!=KErrNone) |
|
439 { |
|
440 return(ret); |
|
441 } |
|
442 iHandle=b().iHandle; |
|
443 iServerHandle=b().iServerHandle; |
|
444 iAddressPointer=(CBitwiseBitmap*)(iFbs->HeapBase()+b().iAddressOffset); |
|
445 if (iAddressPointer->iUid.iUid != KCBitwiseBitmapUid.iUid && iAddressPointer->iUid.iUid != KCBitwiseBitmapHardwareUid.iUid) |
|
446 { |
|
447 iFlags = EIsExtendedBitmap; |
|
448 } |
|
449 ret = iFbs->iHelper->AddBitmap(*this); |
|
450 if (ret != KErrNone) |
|
451 { |
|
452 return ret; |
|
453 } |
|
454 return iFbs->AllocScanLineBuffer(iAddressPointer->iByteWidth+4); |
|
455 } |
|
456 |
|
457 /** Loads a specific bitmap from a multi-bitmap file. |
|
458 The bitmap may be shared by other font and bitmap server clients. |
|
459 @param aFileName The filename of the multi-bitmap (.mbm) file. |
|
460 @param aId The bitmap identifier. |
|
461 @param aShareIfLoaded Specifies whether or not the loaded bitmap will be made |
|
462 available for sharing between font and bitmap server clients. |
|
463 @return KErrNone if successful, otherwise another of the system error |
|
464 codes. |
|
465 @publishedAll |
|
466 @released |
|
467 */ |
|
468 EXPORT_C TInt CFbsBitmap::Load(const TDesC& aFileName,TInt32 aId,TBool aShareIfLoaded) |
|
469 { |
|
470 return Load(aFileName,aId,aShareIfLoaded,0); |
|
471 } |
|
472 |
|
473 /** Loads a specific bitmap from a multi-bitmap file. |
|
474 The bitmap may be shared by other font and bitmap server clients. |
|
475 @param aFileName The filename of the multi-bitmap (.mbm) file. |
|
476 @param aId The bitmap identifier. |
|
477 @param aShareIfLoaded Specifies whether or not the loaded bitmap will be made |
|
478 available for sharing between FBSERV clients. |
|
479 @param aFileOffset Bitmap file section offset within the file. |
|
480 @return KErrNone if successful, otherwise another of the system error codes. |
|
481 @publishedAll |
|
482 @released |
|
483 */ |
|
484 EXPORT_C TInt CFbsBitmap::Load(const TDesC& aFileName,TInt32 aId,TBool aShareIfLoaded,TUint aFileOffset) |
|
485 { |
|
486 if(!iFbs) |
|
487 { |
|
488 return(KErrCouldNotConnect); |
|
489 } |
|
490 Reset(); |
|
491 TUint32* rompointer = NULL; |
|
492 //access using filename has the advantage of using rom address lookup cache |
|
493 IsFileInRom(aFileName, rompointer); |
|
494 TBool romPointerValid; |
|
495 TInt err = DoLoadFromRom(rompointer, aId, aFileOffset, romPointerValid); |
|
496 if(romPointerValid) |
|
497 { |
|
498 return err; |
|
499 } |
|
500 _LIT(KResourcePath, "?:\\Resource\\*"); |
|
501 TInt match = aFileName.MatchF(KResourcePath); |
|
502 //if the file is in the resource directory we don't need to check capabilities and the file can just be opened on the server side. |
|
503 if (match == 0) |
|
504 { |
|
505 err = DoLoad(aFileName,aId,aShareIfLoaded,aFileOffset); |
|
506 } |
|
507 else |
|
508 { |
|
509 RFile file; |
|
510 err = file.Open(iFbs->FileServer(),aFileName,EFileShareReadersOnly); |
|
511 if (err!=KErrNone) |
|
512 { |
|
513 return err; |
|
514 } |
|
515 err = DoLoad(file,aId,aShareIfLoaded,aFileOffset); |
|
516 file.Close(); |
|
517 } |
|
518 return err; |
|
519 } |
|
520 |
|
521 /** Loads and compresses a specific bitmap from a multi-bitmap file. |
|
522 The bitmap may be shared by other font and bitmap server clients. |
|
523 If the bitmap is loaded from ROM then compression is not allowed. |
|
524 @param aFileName The filename of the multi-bitmap (.mbm) file. |
|
525 @param aId The bitmap identifier. |
|
526 @param aShareIfLoaded Specifies whether or not the loaded bitmap will be |
|
527 made available for sharing between FBSERV clients. |
|
528 @return KErrNone if successful, otherwise another of the system-wide error |
|
529 codes. |
|
530 @publishedAll |
|
531 @released |
|
532 */ |
|
533 EXPORT_C TInt CFbsBitmap::LoadAndCompress(const TDesC& aFileName,TInt32 aId,TBool aShareIfLoaded) |
|
534 { |
|
535 return LoadAndCompress(aFileName, aId, aShareIfLoaded, 0); |
|
536 } |
|
537 |
|
538 /** Loads and compresses a specific bitmap from a multi-bitmap file. |
|
539 The bitmap may be shared by other font and bitmap server clients. If the |
|
540 bitmap is loaded from ROM then compression is not allowed. |
|
541 @param aFileName The filename of the multi-bitmap (.mbm) file. |
|
542 @param aId The bitmap identifier. |
|
543 @param aShareIfLoaded Specifies whether or not the loaded bitmap will be made |
|
544 available for sharing between FBSERV clients. |
|
545 @param aFileOffset Bitmap file section offset within the file. |
|
546 @return KErrNone if successful, otherwise another of the system-wide error |
|
547 codes. |
|
548 @publishedAll |
|
549 @released |
|
550 */ |
|
551 EXPORT_C TInt CFbsBitmap::LoadAndCompress(const TDesC& aFileName,TInt32 aId,TBool aShareIfLoaded,TUint aFileOffset) |
|
552 { |
|
553 TInt err = Load(aFileName,aId,aShareIfLoaded,aFileOffset); |
|
554 if (err == KErrNone) |
|
555 { |
|
556 err = !(iFlags & EIsRomBitmap) ? Compress() : KErrAccessDenied; |
|
557 } |
|
558 return err; |
|
559 } |
|
560 |
|
561 /** Saves the bitmap as a direct file store. |
|
562 The file store overwrites any existing file with the same name. |
|
563 @param aFilename The name of the file. |
|
564 @return KErrNone if successful, KErrNotSupported if this CFbsBitmap is an |
|
565 extended bitmap, otherwise another of the system-wide error codes. |
|
566 @publishedAll |
|
567 @released |
|
568 */ |
|
569 EXPORT_C TInt CFbsBitmap::Save(const TDesC& aFilename) |
|
570 { |
|
571 if (!iHandle) |
|
572 { |
|
573 return(KErrGeneral); |
|
574 } |
|
575 RFile file; |
|
576 TInt ret=file.Replace(iFbs->FileServer(),aFilename,EFileWrite); |
|
577 if(ret!=KErrNone) return(ret); |
|
578 TRAP(ret,DoSaveL(file)); |
|
579 file.Close(); |
|
580 return(ret); |
|
581 } |
|
582 |
|
583 /** Saves the bitmap as a direct file store using an opened file handle. |
|
584 The file store overwrites any existing file with the same name. |
|
585 @param aFile The opened file handle |
|
586 @return KErrNone if successful, KErrNotSupported if this CFbsBitmap is an |
|
587 extended bitmap, otherwise another of the system-wide error codes. |
|
588 @publishedAll |
|
589 @released |
|
590 */ |
|
591 EXPORT_C TInt CFbsBitmap::Save(RFile& aFile) |
|
592 { |
|
593 if (!iHandle) |
|
594 { |
|
595 return KErrGeneral; |
|
596 } |
|
597 TRAPD(ret,DoSaveL(aFile)); |
|
598 return ret; |
|
599 } |
|
600 |
|
601 void CFbsBitmap::DoSaveL(RFile& aFile) |
|
602 { |
|
603 CDirectFileStore* filestore=CDirectFileStore::NewLC(aFile); // create from open file |
|
604 TUidType uidtype(KDirectFileStoreLayoutUid,KMultiBitmapFileImageUid); |
|
605 filestore->SetTypeL(uidtype); |
|
606 RStoreWriteStream bmpstream; |
|
607 TStreamId bmpstreamid=bmpstream.CreateLC(*filestore); // create bitmap stream |
|
608 ExternalizeL(bmpstream); |
|
609 bmpstream.CommitL(); |
|
610 CleanupStack::PopAndDestroy(); // bitmap stream |
|
611 RStoreWriteStream rootstream; |
|
612 TStreamId rootstreamid=rootstream.CreateLC(*filestore); // create root stream |
|
613 rootstream.WriteInt32L(1); // number of bitmaps |
|
614 rootstream<<bmpstreamid; // stream id of bitmap |
|
615 rootstream.CommitL(); |
|
616 CleanupStack::PopAndDestroy(); // root stream |
|
617 filestore->SetRootL(rootstreamid); |
|
618 filestore->CommitL(); |
|
619 CleanupStack::PopAndDestroy(); // file store |
|
620 } |
|
621 |
|
622 /** Constructs a multi-bitmap file. |
|
623 @param aFilename The name of the multi-bitmap file to be created. |
|
624 @param aNumSources The number of bitmaps to store in the file. |
|
625 @param aSources An array of pointers to bitmaps to be stored. |
|
626 @param aSourceIds An array of identifiers for the bitmaps to be stored. |
|
627 @publishedAll |
|
628 @released |
|
629 */ |
|
630 EXPORT_C void CFbsBitmap::StoreL(const TDesC& aFilename,TInt aNumSources,const TDesC* aSources[],TInt32 aSourceIds[]) |
|
631 { |
|
632 CFbsBitmap* bitmap = new(ELeave) CFbsBitmap; |
|
633 CleanupStack::PushL(bitmap); |
|
634 CDirectFileStore* filestore = CDirectFileStore::ReplaceLC(bitmap->iFbs->FileServer(),aFilename,EFileWrite); |
|
635 DoStoreL(filestore,bitmap,aNumSources,aSources,aSourceIds); |
|
636 CleanupStack::PopAndDestroy(2,bitmap); |
|
637 } |
|
638 |
|
639 /** Constructs a multi-bitmap file using an opened file handle. |
|
640 @param aFile The opened file handle of multi-bitmap file |
|
641 @param aNumSources The number of bitmaps to store in the file. |
|
642 @param aSources An array of pointers to bitmaps to be stored. |
|
643 @param aSourceIds An array of identifiers for the bitmaps to be stored. |
|
644 @publishedAll |
|
645 @released |
|
646 */ |
|
647 EXPORT_C void CFbsBitmap::StoreL(RFile& aFile,TInt aNumSources,const TDesC* aSources[],TInt32 aSourceIds[]) |
|
648 { |
|
649 CDirectFileStore* filestore = CDirectFileStore::NewLC(aFile); |
|
650 DoStoreL(filestore,NULL,aNumSources,aSources,aSourceIds); |
|
651 CleanupStack::PopAndDestroy(filestore); |
|
652 } |
|
653 |
|
654 /** |
|
655 @internalComponent |
|
656 */ |
|
657 void CFbsBitmap::DoStoreL(CDirectFileStore* aFileStore,CFbsBitmap* aBitmap,TInt aNumSources,const TDesC* aSources[],TInt32 aSourceIds[]) |
|
658 { |
|
659 if(aNumSources<1 || aSources==NULL) User::Leave(KErrArgument); |
|
660 TInt count=0; |
|
661 for(;count<aNumSources;count++) |
|
662 if(aSources[count]==NULL) User::Leave(KErrArgument); |
|
663 TStreamId* ids=new(ELeave) TStreamId[aNumSources]; |
|
664 CleanupArrayDeletePushL(ids); |
|
665 TInt nPushed=1; |
|
666 if (!aBitmap) |
|
667 { |
|
668 aBitmap=new(ELeave) CFbsBitmap; |
|
669 CleanupStack::PushL(aBitmap); |
|
670 ++nPushed; |
|
671 } |
|
672 TUidType uidtype(KDirectFileStoreLayoutUid,KMultiBitmapFileImageUid); |
|
673 aFileStore->SetTypeL(uidtype); |
|
674 for(count=0;count<aNumSources;count++) |
|
675 { |
|
676 User::LeaveIfError(aBitmap->Load(*aSources[count],aSourceIds[count])); |
|
677 RStoreWriteStream bmpstream; |
|
678 ids[count]=bmpstream.CreateLC(*aFileStore); // create bitmap stream |
|
679 aBitmap->ExternalizeL(bmpstream); |
|
680 bmpstream.Close(); |
|
681 CleanupStack::Pop(); // bitmap stream |
|
682 } |
|
683 RStoreWriteStream rootstream; |
|
684 TStreamId rootstreamid=rootstream.CreateLC(*aFileStore); // create root stream |
|
685 rootstream.WriteInt32L(aNumSources); // number of bitmaps |
|
686 for(count=0;count<aNumSources;count++) |
|
687 rootstream<<ids[count]; // stream ids of bitmaps |
|
688 rootstream.Close(); |
|
689 CleanupStack::Pop(); // root stream |
|
690 aFileStore->SetRootL(rootstreamid); |
|
691 CleanupStack::PopAndDestroy(nPushed); // ids [and bitmap] |
|
692 } |
|
693 |
|
694 /** Gets the bitmap's scanline for the specified line starting from the |
|
695 specified point. |
|
696 The dither offset of the bitmap is taken to be TPoint(0,0). |
|
697 @param aBuf The buffer in which the scanline is returned. |
|
698 @param aPoint The start pixel. |
|
699 @param aLength The number of pixels to get. |
|
700 @param aDispMode Format to be used to write the data to the buffer. |
|
701 @publishedAll |
|
702 @released |
|
703 */ |
|
704 EXPORT_C void CFbsBitmap::GetScanLine(TDes8& aBuf,const TPoint& aPoint,TInt aLength,TDisplayMode aDispMode) const |
|
705 { |
|
706 GetScanLine(aBuf,aPoint,aLength,TPoint(0,0),aDispMode); |
|
707 } |
|
708 |
|
709 /** Gets the bitmap's scanline for the specified line starting from the specified |
|
710 point and using the specified dither offset. |
|
711 @param aBuf The buffer in which the scanline is returned. |
|
712 @param aPixel The start pixel. |
|
713 @param aLength The number of pixels to get. |
|
714 @param aDitherOffset The dither offset of the bitmap. |
|
715 @param aDispMode Format to be used to write the data to the buffer. |
|
716 @publishedAll |
|
717 @released |
|
718 */ |
|
719 EXPORT_C void CFbsBitmap::GetScanLine(TDes8& aBuf,const TPoint& aPoint,TInt aLength,const TPoint& aDitherOffset,TDisplayMode aDispMode) const |
|
720 { |
|
721 if(!iHandle) return; |
|
722 TUint32* data; |
|
723 CBitwiseBitmap* bmp = BeginDataAccessAndGetCleanAddress(data); |
|
724 CFbsRasterizer* rasterizer = NULL; |
|
725 if ((iFlags & EIsExtendedBitmap) && iFbs) |
|
726 { |
|
727 rasterizer = iFbs->iHelper->Rasterizer(); |
|
728 if (rasterizer) |
|
729 { |
|
730 CFbsRasterizer::TBitmapDesc desc; |
|
731 desc.iSizeInPixels = bmp->SizeInPixels(); |
|
732 desc.iDispMode = bmp->DisplayMode(); |
|
733 desc.iDataType = bmp->iUid; |
|
734 desc.iData = data; |
|
735 desc.iDataSize = bmp->iHeader.iBitmapSize - bmp->iHeader.iStructSize; |
|
736 rasterizer->BeginBitmap(bmp->Extra()->iSerialNumber, desc, NULL); |
|
737 } |
|
738 } |
|
739 bmp->GetScanLine(aBuf, aPoint, aLength, ETrue, aDitherOffset, aDispMode, data); |
|
740 if (rasterizer) |
|
741 { |
|
742 rasterizer->EndBitmap(bmp->Extra()->iSerialNumber); |
|
743 } |
|
744 EndDataAccess(ETrue); |
|
745 } |
|
746 |
|
747 /** Sets the bitmap's horizontal scanline at the specified y co-ordinate to the |
|
748 scanline contained in the buffer. |
|
749 @param aBuf The new scanline to be written to the bitmap. |
|
750 @param aY The y co-ordinate of the scanline. |
|
751 @panic FBSCLI 11 in debug builds if this is a compressed bitmap. |
|
752 @panic FBSCLI 28 in debug builds if this is a read-only bitmap. |
|
753 @publishedAll |
|
754 @released |
|
755 */ |
|
756 EXPORT_C void CFbsBitmap::SetScanLine(TDes8& aBuf,TInt aY) const |
|
757 { |
|
758 if (!iHandle) |
|
759 return; |
|
760 if (iFlags & EIsReadOnlyBitmapMask) |
|
761 { |
|
762 __ASSERT_DEBUG(EFalse, ::Panic(EFbsPanicBitmapReadOnly)); |
|
763 return; |
|
764 } |
|
765 TUint32* data; |
|
766 CBitwiseBitmap* bmp = BeginDataAccessAndGetCleanAddress(data); |
|
767 if (bmp->IsCompressed()) |
|
768 { |
|
769 EndDataAccess(ETrue); |
|
770 __ASSERT_DEBUG(EFalse, ::Panic(EFbsBitmapInvalidCompression)); |
|
771 return; |
|
772 } |
|
773 data = bmp->ScanLineAddress(data, aY); |
|
774 TInt bytewidth = bmp->iByteWidth; |
|
775 TInt bytelen=aBuf.Length(); |
|
776 if(bytelen<bytewidth) bytewidth=bytelen; |
|
777 TInt wordlen=bytewidth>>2; |
|
778 TUint32* ptr=(TUint32*)aBuf.Ptr(); |
|
779 TUint32* ptrlim=ptr+wordlen; |
|
780 while(ptr<ptrlim) |
|
781 *data++=*ptr++; |
|
782 TInt limit=wordlen<<2; |
|
783 if(limit<bytewidth) |
|
784 { |
|
785 TUint8* byteptr=(TUint8*)ptrlim; |
|
786 TUint8* databyte=(TUint8*)data; |
|
787 while(limit<bytewidth) |
|
788 { |
|
789 *databyte++=*byteptr++; |
|
790 limit++; |
|
791 } |
|
792 } |
|
793 EndDataAccess(EFalse); |
|
794 } |
|
795 |
|
796 /** Gets the bitmap's vertical scanline starting at the specified x co-ordinate. |
|
797 Note: The method only works for uncompressed bitmaps. |
|
798 Note: The dither offset of the bitmap is taken to be TPoint(0,0). |
|
799 @param aBuf The buffer in which the vertical scanline is returned. |
|
800 @param aX The x co-ordinate of the vertical scanline. |
|
801 @param aDispMode Format to be used to write the data to the buffer. |
|
802 @panic FBSCLI 11 in debug builds if this is not an ucompressed bitmap or an extended bitmap. |
|
803 @publishedAll |
|
804 @released |
|
805 */ |
|
806 EXPORT_C void CFbsBitmap::GetVerticalScanLine(TDes8& aBuf,TInt aX,TDisplayMode aDispMode) const |
|
807 { |
|
808 GetVerticalScanLine(aBuf,aX,TPoint(0,0),aDispMode); |
|
809 } |
|
810 |
|
811 /** Gets the bitmap's vertical scanline starting at the specified x co-ordinate |
|
812 and using the specified dither offset. |
|
813 Note: The method only works for uncompressed bitmaps. |
|
814 @param aBuf The buffer in which the vertical scanline will be returned. |
|
815 @param aX The x co-ordinate of the vertical scanline to get. |
|
816 @param aDitherOffset The dither offset of the bitmap. |
|
817 @param aDispMode Format to be used to write the data to the buffer. |
|
818 @panic FBSCLI 11 in debug builds if this is not an ucompressed bitmap or an extended bitmap. |
|
819 @publishedAll |
|
820 @released |
|
821 */ |
|
822 EXPORT_C void CFbsBitmap::GetVerticalScanLine(TDes8& aBuf,TInt aX,const TPoint& aDitherOffset,TDisplayMode aDispMode) const |
|
823 { |
|
824 if(!iHandle) return; |
|
825 TUint32* data; |
|
826 CBitwiseBitmap* bmp = BeginDataAccessAndGetCleanAddress(data); |
|
827 CFbsRasterizer* rasterizer = NULL; |
|
828 if ((iFlags & EIsExtendedBitmap) && iFbs) |
|
829 { |
|
830 rasterizer = iFbs->iHelper->Rasterizer(); |
|
831 if (rasterizer) |
|
832 { |
|
833 CFbsRasterizer::TBitmapDesc desc; |
|
834 desc.iSizeInPixels = bmp->SizeInPixels(); |
|
835 desc.iDispMode = bmp->DisplayMode(); |
|
836 desc.iDataType = bmp->iUid; |
|
837 desc.iData = data; |
|
838 desc.iDataSize = bmp->iHeader.iBitmapSize - bmp->iHeader.iStructSize; |
|
839 rasterizer->BeginBitmap(bmp->Extra()->iSerialNumber, desc, NULL); |
|
840 } |
|
841 } |
|
842 bmp->GetVerticalScanLine(aBuf, aX, ETrue, aDitherOffset, aDispMode, data, rasterizer); |
|
843 if (rasterizer) |
|
844 { |
|
845 rasterizer->EndBitmap(bmp->Extra()->iSerialNumber); |
|
846 } |
|
847 EndDataAccess(ETrue); |
|
848 } |
|
849 |
|
850 /** Gets the handle number of the bitmap. |
|
851 The returned value can be used to give another thread access to the bitmap. |
|
852 @return The handle number of the bitmap. |
|
853 @publishedAll |
|
854 @released |
|
855 @see CFbsBitmap::Duplicate() |
|
856 */ |
|
857 EXPORT_C TInt CFbsBitmap::Handle() const |
|
858 { |
|
859 if(!iHandle) |
|
860 return(0); |
|
861 if (iFlags & EIsRomBitmap) |
|
862 return TInt(iAddressPointer); |
|
863 else |
|
864 return(iServerHandle); |
|
865 } |
|
866 |
|
867 /** Creates a bitmap header. |
|
868 This is used when streaming bitmaps to stores. |
|
869 @return The bitmap header for the bitmap. |
|
870 @publishedAll |
|
871 @released |
|
872 */ |
|
873 EXPORT_C SEpocBitmapHeader CFbsBitmap::Header() const |
|
874 { |
|
875 if (iHandle) |
|
876 return CleanAddress()->iHeader; |
|
877 SEpocBitmapHeader header; |
|
878 return(header); |
|
879 } |
|
880 |
|
881 /** Converts a horizontal dimension on the graphics device from pixels to twips. |
|
882 @param aPixels A horizontal dimension on the graphics device in pixels. |
|
883 @return A horizontal dimension on the graphics device in twips. |
|
884 @publishedAll |
|
885 @released |
|
886 */ |
|
887 EXPORT_C TInt CFbsBitmap::HorizontalPixelsToTwips(TInt aPixels) const |
|
888 { |
|
889 if(iHandle==NULL) return(0); |
|
890 return CleanAddress()->HorizontalPixelsToTwips(aPixels); |
|
891 } |
|
892 |
|
893 /** Converts a horizontal dimension on the graphics device from twips to pixels. |
|
894 @param aTwips A horizontal dimension on the graphics device in twips. |
|
895 @return A horizontal dimension on the graphics device in pixels. |
|
896 @publishedAll |
|
897 @released |
|
898 */ |
|
899 EXPORT_C TInt CFbsBitmap::HorizontalTwipsToPixels(TInt aTwips) const |
|
900 { |
|
901 if(iHandle==NULL) return(0); |
|
902 return CleanAddress()->HorizontalTwipsToPixels(aTwips); |
|
903 } |
|
904 |
|
905 /** Gets the RGB value of the specified pixel. |
|
906 Note: The method only works for uncompressed bitmaps and extended bitmaps. |
|
907 @param aColor On return, the RGB value of the specified pixel. |
|
908 @param aPixel The pixel whose colour is to be determined. |
|
909 @panic FBSCLI 11 in debug builds if this is a compressed bitmap. |
|
910 @publishedAll |
|
911 @released |
|
912 */ |
|
913 EXPORT_C void CFbsBitmap::GetPixel(TRgb& aColor,const TPoint& aPoint) const |
|
914 { |
|
915 if(!iHandle) |
|
916 { |
|
917 return; |
|
918 } |
|
919 |
|
920 TUint32* data; |
|
921 CBitwiseBitmap* bmp = BeginDataAccessAndGetCleanAddress(data); |
|
922 CFbsRasterizer* rasterizer = NULL; |
|
923 if ((iFlags & EIsExtendedBitmap) && iFbs) |
|
924 { |
|
925 rasterizer = iFbs->iHelper->Rasterizer(); |
|
926 if (rasterizer) |
|
927 { |
|
928 CFbsRasterizer::TBitmapDesc desc; |
|
929 desc.iSizeInPixels = bmp->SizeInPixels(); |
|
930 desc.iDispMode = bmp->DisplayMode(); |
|
931 desc.iDataType = bmp->iUid; |
|
932 desc.iData = data; |
|
933 desc.iDataSize = bmp->iHeader.iBitmapSize - bmp->iHeader.iStructSize; |
|
934 rasterizer->BeginBitmap(bmp->Extra()->iSerialNumber, desc, NULL); |
|
935 } |
|
936 } |
|
937 bmp->GetPixel(aColor, aPoint, data, rasterizer); |
|
938 if (rasterizer) |
|
939 { |
|
940 rasterizer->EndBitmap(bmp->Extra()->iSerialNumber); |
|
941 } |
|
942 EndDataAccess(ETrue); |
|
943 } |
|
944 |
|
945 /** Gets the pixel-size of the bitmap. |
|
946 @return The size of the bitmap, in pixels. |
|
947 @publishedAll |
|
948 @released |
|
949 */ |
|
950 EXPORT_C TSize CFbsBitmap::SizeInPixels() const |
|
951 { |
|
952 TSize zero; |
|
953 if(!iHandle) return(zero); |
|
954 return CleanAddress()->SizeInPixels(); |
|
955 } |
|
956 |
|
957 /** Sets the twip-size of the bitmap by converting the bitmaps pixel-size from |
|
958 pixels to twips, using the conversion functions in the specified graphics |
|
959 device map. |
|
960 @param aMap The graphics device map to be used for providing pixel to twip |
|
961 conversion. |
|
962 @publishedAll |
|
963 @released |
|
964 */ |
|
965 EXPORT_C void CFbsBitmap::SetSizeInTwips(const MGraphicsDeviceMap* aMap) |
|
966 { |
|
967 if (!iHandle || (iFlags & EIsRomBitmap) || aMap == NULL) |
|
968 return; |
|
969 TSize size=SizeInPixels(); |
|
970 size.iWidth=aMap->HorizontalPixelsToTwips(size.iWidth); |
|
971 size.iHeight=aMap->VerticalPixelsToTwips(size.iHeight); |
|
972 iFbs->SetCallBackPtr(&iServerHandle); |
|
973 iFbs->CallBack(); |
|
974 // SizeInPixels() called CleanAddress() so call Address() now to make sure we don't clean the bitmap twice |
|
975 Address()->iHeader.iSizeInTwips=size; |
|
976 } |
|
977 |
|
978 /** Sets the twip-size of the bitmap directly to the specified size. |
|
979 @param aSizeInTwips The new size of the bitmap, in twips. |
|
980 @publishedAll |
|
981 @released |
|
982 */ |
|
983 EXPORT_C void CFbsBitmap::SetSizeInTwips(const TSize& aSizeInTwips) |
|
984 { |
|
985 if (!iHandle || (iFlags & EIsRomBitmap)) |
|
986 return; |
|
987 iFbs->SetCallBackPtr(&iServerHandle); |
|
988 iFbs->CallBack(); |
|
989 CleanAddress()->iHeader.iSizeInTwips = aSizeInTwips; |
|
990 } |
|
991 |
|
992 /** Externalises the bitmap to the specified stream. Not supported for extended bitmaps. |
|
993 @param aStream The write stream. |
|
994 @publishedAll |
|
995 @released |
|
996 */ |
|
997 EXPORT_C void CFbsBitmap::ExternalizeL(RWriteStream& aStream) const |
|
998 { |
|
999 if (!iHandle) |
|
1000 User::Leave(KErrGeneral); |
|
1001 BeginDataAccess(); |
|
1002 Address()->ExternalizeL(aStream, *this); |
|
1003 EndDataAccess(ETrue); |
|
1004 } |
|
1005 |
|
1006 /** Externalises that area of the bitmap contained within a specified |
|
1007 rectangular area. Not supported for extended bitmaps. |
|
1008 @param aStream The write stream |
|
1009 @param aRect The rectangular area of the bitmap to externalise. The bitmap |
|
1010 that is externalized will be of this size. |
|
1011 @publishedAll |
|
1012 @released |
|
1013 */ |
|
1014 EXPORT_C void CFbsBitmap::ExternalizeRectangleL(RWriteStream& aStream,const TRect& aRect) const |
|
1015 { |
|
1016 if (!iHandle) |
|
1017 User::Leave(KErrGeneral); |
|
1018 BeginDataAccess(); |
|
1019 Address()->ExternalizeRectangleL(aStream, aRect, *this); |
|
1020 EndDataAccess(ETrue); |
|
1021 } |
|
1022 |
|
1023 /** Internalises a CFbsBitmap from a stream. |
|
1024 @param aStream The read stream. |
|
1025 @publishedAll |
|
1026 @released |
|
1027 */ |
|
1028 EXPORT_C void CFbsBitmap::InternalizeL(RReadStream& aStream) |
|
1029 { |
|
1030 if(!iFbs) User::Leave(KErrCouldNotConnect); |
|
1031 Reset(); |
|
1032 SEpocBitmapHeader header; |
|
1033 CBitwiseBitmap::InternalizeHeaderL(aStream,header); |
|
1034 |
|
1035 TDisplayMode dispmode = CBitwiseBitmap::DisplayMode(header.iBitsPerPixel,header.iColor); |
|
1036 User::LeaveIfError(Create(header.iSizeInPixels,dispmode)); |
|
1037 |
|
1038 TUint32* data; |
|
1039 CBitwiseBitmap* bmp=BeginDataAccessAndGetCleanAddress(data); |
|
1040 bmp->iHeader=header; |
|
1041 TInt bytesize = header.iBitmapSize - header.iStructSize; |
|
1042 if (bytesize > 0) |
|
1043 { |
|
1044 bmp->DoInternalizeL(aStream, bytesize, data); |
|
1045 EndDataAccess(EFalse); |
|
1046 } |
|
1047 else |
|
1048 { |
|
1049 EndDataAccess(ETrue); |
|
1050 } |
|
1051 } |
|
1052 |
|
1053 EXPORT_C TInt CFbsBitmap::Compress() |
|
1054 { |
|
1055 return Compress(ERLECompression); |
|
1056 } |
|
1057 |
|
1058 /** Compresses bitmap in RAM. |
|
1059 @param aScheme specifies preferred compression type ERLECompression or EPaletteCompression |
|
1060 @return KErrNone on success, KErrGeneral if the bitmap handle is NULL, KErrAccessDenied if |
|
1061 the bitmap is in ROM or it is an extended bitmap, otherwise one of the system wide error codes. |
|
1062 @publishedAll |
|
1063 @released |
|
1064 */ |
|
1065 EXPORT_C TInt CFbsBitmap::Compress(TBitmapfileCompressionScheme aScheme) |
|
1066 { |
|
1067 if (!iHandle) |
|
1068 return KErrGeneral; |
|
1069 if (iFlags & EIsReadOnlyBitmapMask) |
|
1070 return KErrAccessDenied; |
|
1071 TPckgBuf<TBmpHandles> handlebuf; |
|
1072 TIpcArgs args(iHandle, aScheme, &handlebuf); |
|
1073 TInt err = iFbs->SendCommand(EFbsMessBitmapCompress, args); |
|
1074 if (err != KErrNone) |
|
1075 return err; |
|
1076 iHandle = handlebuf().iHandle; |
|
1077 iServerHandle = handlebuf().iServerHandle; |
|
1078 iAddressPointer = (CBitwiseBitmap*)(iFbs->HeapBase() + handlebuf().iAddressOffset); |
|
1079 return KErrNone; |
|
1080 } |
|
1081 |
|
1082 /** Submits the bitmap for asynchronous background compression. |
|
1083 @param aRequestStatus The request status which will be completed with the appropriate error code after the compression has finished |
|
1084 The error code will be KErrNone on success, KErrGeneral if the bitmap handle is NULL, KErrAccessDenied if the |
|
1085 bitmap is in ROM or it is an extended bitmap, otherwise one of the system wide error codes. |
|
1086 @publishedAll |
|
1087 @released |
|
1088 */ |
|
1089 EXPORT_C void CFbsBitmap::CompressInBackground(TRequestStatus& aRequestStatus) |
|
1090 { |
|
1091 CompressInBackground(aRequestStatus, ERLECompression); |
|
1092 } |
|
1093 |
|
1094 /** Submits the bitmap for asynchronous background compression. No notification will be provided when the compression has completed. |
|
1095 @return KErrNone if the bitmap was successfully submitted to the background compression queue, KErrGeneral if the bitmap handle is NULL, |
|
1096 KErrAccessDenied if the bitmap is in ROM or it is an extended bitmap, otherwise another of the system-wide error codes. |
|
1097 @publishedAll |
|
1098 @released |
|
1099 */ |
|
1100 EXPORT_C TInt CFbsBitmap::CompressInBackground() |
|
1101 { |
|
1102 return CompressInBackground(ERLECompression); |
|
1103 } |
|
1104 |
|
1105 /** Submits the bitmap for asynchronous background compression. |
|
1106 @param aRequestStatus The request status which will be completed with the appropriate error code after the compression has finished. |
|
1107 The error code will be KErrNone on success, KErrGeneral if the bitmap handle is NULL, KErrAccessDenied if the |
|
1108 bitmap is in ROM or it is an extended bitmap, otherwise one of the system wide error codes. |
|
1109 @param aScheme Specifies preferred compression type: ERLECompression or EPaletteCompression |
|
1110 @publishedAll |
|
1111 @released |
|
1112 */ |
|
1113 EXPORT_C void CFbsBitmap::CompressInBackground(TRequestStatus& aRequestStatus, TBitmapfileCompressionScheme aScheme) |
|
1114 { |
|
1115 TRequestStatus* reqStat = &aRequestStatus; |
|
1116 aRequestStatus = KRequestPending; |
|
1117 if (!iHandle) |
|
1118 User::RequestComplete(reqStat, KErrGeneral); |
|
1119 else if (iFlags & EIsReadOnlyBitmapMask) |
|
1120 User::RequestComplete(reqStat, KErrAccessDenied); |
|
1121 else |
|
1122 { |
|
1123 TIpcArgs args(iHandle, aScheme, ETrue); |
|
1124 iFbs->SendCommand(EFbsMessBitmapBgCompress, args, aRequestStatus); |
|
1125 } |
|
1126 } |
|
1127 |
|
1128 /** Submits the bitmap for asynchronous background compression. No notification will be provided when the compression has completed. |
|
1129 @return KErrNone if the bitmap was successfully submitted to the background compression queue, KErrGeneral if the bitmap handle is NULL, |
|
1130 KErrAccessDenied if the bitmap is in ROM or it is an extended bitmap, otherwise another of the system-wide error codes. |
|
1131 @publishedAll |
|
1132 @released |
|
1133 */ |
|
1134 EXPORT_C TInt CFbsBitmap::CompressInBackground(TBitmapfileCompressionScheme aScheme) |
|
1135 { |
|
1136 if (!iHandle) |
|
1137 return KErrGeneral; |
|
1138 if (iFlags & EIsReadOnlyBitmapMask) |
|
1139 return KErrAccessDenied; |
|
1140 TIpcArgs args(iHandle, aScheme, EFalse); |
|
1141 return iFbs->SendCommand(EFbsMessBitmapBgCompress, args); |
|
1142 } |
|
1143 |
|
1144 /**Tests whether the bitmap located in RAM has been compressed. |
|
1145 @return ETrue if the bitmap is compressed, EFalse otherwise. |
|
1146 @publishedAll |
|
1147 @released |
|
1148 */ |
|
1149 EXPORT_C TBool CFbsBitmap::IsCompressedInRAM() const |
|
1150 { |
|
1151 CBitwiseBitmap* bitmap = CleanAddress(); |
|
1152 if (bitmap==NULL) |
|
1153 { |
|
1154 return EFalse; |
|
1155 } |
|
1156 return bitmap->IsCompressedInRAM(); |
|
1157 } |
|
1158 |
|
1159 /** Gets the twip-size of the bitmap. |
|
1160 @return The size of the bitmap, in twips. |
|
1161 @publishedAll |
|
1162 @released |
|
1163 */ |
|
1164 EXPORT_C TSize CFbsBitmap::SizeInTwips() const |
|
1165 { |
|
1166 TSize zero; |
|
1167 if(iHandle==NULL) return(zero); |
|
1168 return CleanAddress()->SizeInTwips(); |
|
1169 } |
|
1170 |
|
1171 /** Converts a vertical dimension on the graphics device from pixels to twips. |
|
1172 @param aPixels A vertical dimension on the graphics device in pixels. |
|
1173 @return A vertical dimension on the graphics device in twips. |
|
1174 @publishedAll |
|
1175 @released |
|
1176 */ |
|
1177 EXPORT_C TInt CFbsBitmap::VerticalPixelsToTwips(TInt aPixels) const |
|
1178 { |
|
1179 if(iHandle==NULL) return(0); |
|
1180 return CleanAddress()->VerticalPixelsToTwips(aPixels); |
|
1181 } |
|
1182 |
|
1183 /** Converts a vertical dimension on the graphics device from twips to pixels. |
|
1184 @param aTwips A vertical dimension on the graphics device in twips. |
|
1185 @return A vertical dimension on the graphics device in pixels. |
|
1186 @publishedAll |
|
1187 @released |
|
1188 */ |
|
1189 EXPORT_C TInt CFbsBitmap::VerticalTwipsToPixels(TInt aTwips) const |
|
1190 { |
|
1191 if(iHandle==NULL) return(0); |
|
1192 return CleanAddress()->VerticalTwipsToPixels(aTwips); |
|
1193 } |
|
1194 |
|
1195 /** Tests whether or not the specified file is in ROM. |
|
1196 @param aFilename The name of the file. |
|
1197 @param aWord On return, contains the address of the file in ROM. |
|
1198 @return ETrue if the file is in the ROM; EFalse otherwise. |
|
1199 @publishedAll |
|
1200 @released |
|
1201 */ |
|
1202 EXPORT_C TBool CFbsBitmap::IsFileInRom(const TDesC& aFilename,TUint32*& aWord) |
|
1203 { |
|
1204 RFbsSession* fbs=RFbsSession::GetSession(); |
|
1205 __ASSERT_ALWAYS(fbs,Panic(EFbsPanicNoConnection)); |
|
1206 return fbs->LookupBitmapInROM (aFilename, (TAny*&)aWord); |
|
1207 } |
|
1208 |
|
1209 /** Tests whether or not the specified file is in ROM. |
|
1210 @param aFile The file handle |
|
1211 @param aWord On return, contains the address of the file in ROM. |
|
1212 @return ETrue if the file is in the ROM; EFalse otherwise. |
|
1213 @publishedAll |
|
1214 @released |
|
1215 */ |
|
1216 EXPORT_C TBool CFbsBitmap::IsFileInRom(RFile& aFile,TUint32*& aWord) |
|
1217 { |
|
1218 // cannot use rom lookup cache as filename is not available |
|
1219 // offset must be initialised to zero to indicate beginning of the file |
|
1220 aWord = 0; |
|
1221 return aFile.Seek(ESeekAddress,(TInt&)aWord)==KErrNone; |
|
1222 } |
|
1223 |
|
1224 /** Tests whether or not the bitmap is monochrome. |
|
1225 Monochrome bitmaps have a display-mode of 1 bit-per-pixel. |
|
1226 @return ETrue if the bitmap is monochrome; EFalse otherwise. |
|
1227 @publishedAll |
|
1228 @released |
|
1229 */ |
|
1230 EXPORT_C TBool CFbsBitmap::IsMonochrome() const |
|
1231 { |
|
1232 if(!iHandle) return(EFalse); |
|
1233 TUint32* data; |
|
1234 CBitwiseBitmap* bmp = BeginDataAccessAndGetCleanAddress(data); |
|
1235 TBool isMonochrome = bmp->IsMonochrome(data); |
|
1236 EndDataAccess(ETrue); |
|
1237 return isMonochrome; |
|
1238 } |
|
1239 |
|
1240 /** Marks the beginning of direct access to the bitmap data. |
|
1241 This function prepares the bitmap for direct access to its pixel data |
|
1242 and should be used before calling DataAddress(), otherwise performance |
|
1243 may be degraded on certain platforms. |
|
1244 Calls to BeginDataAccess() must be coupled with subsequent calls to EndDataAccess(). |
|
1245 |
|
1246 @publishedAll |
|
1247 @released |
|
1248 @see CFbsBitmap::DataAddress() |
|
1249 @see CFbsBitmap::EndDataAccess() |
|
1250 */ |
|
1251 EXPORT_C void CFbsBitmap::BeginDataAccess() const |
|
1252 { |
|
1253 if (!iHandle) |
|
1254 return; |
|
1255 (void)CleanAddress(); //called for side-effect to make sure bitmap reference is current. Should be low overhead. |
|
1256 const_cast<CFbsBitmap*>(this)->iUseCount++; |
|
1257 } |
|
1258 |
|
1259 /** Marks the end of direct access to the bitmap data. |
|
1260 Use this function after ending direct access to the bitmap data. |
|
1261 Calls to EndDataAccess() must correspond to prior calls to BeginDataAccess(). |
|
1262 See BeginDataAccess() for more details. |
|
1263 |
|
1264 @param aReadOnly Whether or not the bitmap data has only been read since |
|
1265 the corresponding call to BeginDataAccess(). |
|
1266 |
|
1267 @publishedAll |
|
1268 @released |
|
1269 @param aReadOnly True if the bitmap data had only been read. False if the data has been modified. |
|
1270 @see CFbsBitmap::BeginDataAccess() |
|
1271 */ |
|
1272 EXPORT_C void CFbsBitmap::EndDataAccess(TBool aReadOnly) const |
|
1273 { |
|
1274 if (!iHandle) |
|
1275 return; |
|
1276 const_cast<CFbsBitmap*>(this)->iUseCount--; |
|
1277 if (!aReadOnly && !(iFlags & EIsReadOnlyBitmapMask)) |
|
1278 User::LockedInc(iAddressPointer->Extra()->iTouchCount); |
|
1279 } |
|
1280 |
|
1281 /** Locks the global bitmap heap. |
|
1282 This function is deprecated, since it is no longer necessary to lock the global |
|
1283 bitmap heap to prevent the pixel data from being moved in memory asynchronously, |
|
1284 as the value returned by DataAddress() can now only change as a result of bitmap |
|
1285 operations explicitly requested by clients of the Font and Bitmap Server. |
|
1286 Calls to LockHeap() should be replaced by calls to BeginDataAccess(). |
|
1287 |
|
1288 Calls to LockHeap() must be coupled with subsequent calls to CFbsBitmap::UnlockHeap(). |
|
1289 Code called between a LockHeap() - UnlockHeap() pair must not include any other calls to |
|
1290 CFbsBitmap methods, which internally may call CFbsBitmap::LockHeap(). Also, code must |
|
1291 not leave between a LockHeap() - UnlockHeap() pair. |
|
1292 @note IMPORTANT: CFbsBitmap::LockHeap() cannot be used as a means of synchronization between |
|
1293 threads concurrently accessing bitmap data. |
|
1294 |
|
1295 @publishedAll |
|
1296 @deprecated |
|
1297 @see CFbsBitmap::UnlockHeap() |
|
1298 @see CFbsBitmap::BeginDataAccess() |
|
1299 */ |
|
1300 EXPORT_C void CFbsBitmap::LockHeap(TBool /*aAlways*/) const |
|
1301 { |
|
1302 BeginDataAccess(); |
|
1303 #ifdef SYMBIAN_DEBUG_FBS_LOCKHEAP |
|
1304 //These debug checks now refer to the cleaned data address |
|
1305 if (!iHandle) |
|
1306 return; |
|
1307 if (!(iFlags & EIsRomBitmap)) // can't do anything with ROM bitmaps |
|
1308 { |
|
1309 TThreadId threadId = RThread().Id(); |
|
1310 iFbs->iHelper->iDebugMutex.Wait(); |
|
1311 if (iAddressPointer->Extra()->iLockCount++ == 0) |
|
1312 { |
|
1313 __ASSERT_ALWAYS(iAddressPointer->Extra()->iThreadId == TThreadId(KNullThreadId), Panic(EFbsPanicBadHeapLock)); |
|
1314 iAddressPointer->Extra()->iThreadId = threadId; |
|
1315 } |
|
1316 else |
|
1317 __ASSERT_ALWAYS(iAddressPointer->Extra()->iThreadId == threadId, Panic(EFbsPanicBadHeapLock)); |
|
1318 iFbs->iHelper->iDebugMutex.Signal(); |
|
1319 } |
|
1320 #endif |
|
1321 } |
|
1322 |
|
1323 /** Unlocks the global heap. |
|
1324 This function is deprecated. See LockHeap() for more details. |
|
1325 Calls to UnlockHeap() should be replaced by calls to EndDataAccess(). |
|
1326 Calls to UnlockHeap() must correspond to prior calls to LockHeap() or LockHeapLC(). |
|
1327 |
|
1328 @publishedAll |
|
1329 @deprecated |
|
1330 @see CFbsBitmap::LockHeap() |
|
1331 @see CFbsBitmap::EndDataAccess() |
|
1332 */ |
|
1333 EXPORT_C void CFbsBitmap::UnlockHeap(TBool /*aAlways*/) const |
|
1334 { |
|
1335 #ifdef SYMBIAN_DEBUG_FBS_LOCKHEAP |
|
1336 if (!iHandle) |
|
1337 return; |
|
1338 if (!(iFlags & EIsRomBitmap)) // can't do anything with ROM bitmaps |
|
1339 { |
|
1340 TThreadId threadId = RThread().Id(); |
|
1341 iFbs->iHelper->iDebugMutex.Wait(); |
|
1342 __ASSERT_ALWAYS(iAddressPointer->Extra()->iLockCount > 0, Panic(EFbsPanicBadHeapLock)); |
|
1343 __ASSERT_ALWAYS(iAddressPointer->Extra()->iThreadId == threadId, Panic(EFbsPanicBadHeapLock)); |
|
1344 if (--iAddressPointer->Extra()->iLockCount == 0) |
|
1345 iAddressPointer->Extra()->iThreadId = TThreadId(KNullThreadId); |
|
1346 iFbs->iHelper->iDebugMutex.Signal(); |
|
1347 } |
|
1348 #endif |
|
1349 EndDataAccess(); |
|
1350 } |
|
1351 |
|
1352 /** Locks the global bitmap heap, leaving on the clean-up stack a pointer |
|
1353 to a TCleanupItem that unlocks the heap on deletion. |
|
1354 Use this function instead of LockHeap() if code may leave between the |
|
1355 LockHeap() - UnlockHeap() pair. Calls to LockHeapLC() must be coupled with |
|
1356 subsequent calls to CFbsBitmap::UnlockHeap() or CleanupStack::PopAndDestroy(). |
|
1357 This function is deprecated. See CFbsBitmap::LockHeap() for more details. |
|
1358 |
|
1359 @publishedAll |
|
1360 @deprecated |
|
1361 @see CFbsBitmap::LockHeap() |
|
1362 */ |
|
1363 EXPORT_C void CFbsBitmap::LockHeapLC(TBool /*aAlways*/) const |
|
1364 { |
|
1365 LockHeap(); |
|
1366 TCleanupItem cleanitem(CFbsBitmap::UnlockHeap, (TAny*)this); |
|
1367 CleanupStack::PushL(cleanitem); |
|
1368 } |
|
1369 |
|
1370 EXPORT_C void CFbsBitmap::UnlockHeap(TAny* aFbsBitmap) |
|
1371 { |
|
1372 ((CFbsBitmap*)aFbsBitmap)->UnlockHeap(); |
|
1373 } |
|
1374 |
|
1375 /** Tests whether the bitmap is volatile. |
|
1376 A bitmap becomes volatile if CFbsBitmap::DataAdress() is called without |
|
1377 CFbsBitmap::BeginDataAccess() having been called before and it can become non-volatile |
|
1378 again if a resizing or compression is performed. |
|
1379 |
|
1380 @internalTechnology |
|
1381 @prototype |
|
1382 */ |
|
1383 EXPORT_C TBool CFbsBitmap::IsVolatile() const |
|
1384 { |
|
1385 if (!iHandle) |
|
1386 return EFalse; |
|
1387 return CleanAddress()->iSettings.IsVolatileBitmap(); |
|
1388 } |
|
1389 |
|
1390 /** Tests how many times the bitmap has been touched. |
|
1391 A bitmap is touched whenever CFbsBitmap::EndDataAccess() is called with the parameter |
|
1392 aReadOnly set to EFalse and also whenever a resizing or compression is performed. |
|
1393 |
|
1394 @internalTechnology |
|
1395 @prototype |
|
1396 @return The number of times the bitmap has been touched. |
|
1397 */ |
|
1398 EXPORT_C TInt CFbsBitmap::TouchCount() const |
|
1399 { |
|
1400 if (!iHandle || (iFlags & EIsReadOnlyBitmapMask)) |
|
1401 return 0; // A read-only bitmap can never be touched. |
|
1402 return CleanAddress()->Extra()->iTouchCount; |
|
1403 } |
|
1404 |
|
1405 /** Returns the serial number of the bitmap |
|
1406 The serial number is unique to this bitmap. |
|
1407 The serial number is a signed 64-bit integer, with only the positive values being assigned. |
|
1408 As ROM bitmaps do not have serial numbers, the serial number will use the negative range |
|
1409 of values so that ROM bitmap's serial number cannot be the same as a RAM bitmap's. |
|
1410 ROM bitmap's address pointers are unique to the ROM bitmap, so the serial number will just |
|
1411 be negative value of the address pointer. |
|
1412 |
|
1413 @internalTechnology |
|
1414 @prototype |
|
1415 @return The unique serial number for the bitmap |
|
1416 */ |
|
1417 EXPORT_C TInt64 CFbsBitmap::SerialNumber() const |
|
1418 { |
|
1419 if (!iHandle) |
|
1420 return 0; |
|
1421 if (iFlags & EIsRomBitmap) |
|
1422 return -TInt64(reinterpret_cast<TUint32>(iAddressPointer)); |
|
1423 return CleanAddress()->Extra()->iSerialNumber; |
|
1424 } |
|
1425 |
|
1426 /** Tests whether the bitmap is large. |
|
1427 @return ETrue if the bitmap is large, EFalse if not. |
|
1428 @publishedAll |
|
1429 @released |
|
1430 */ |
|
1431 EXPORT_C TBool CFbsBitmap::IsLargeBitmap() const |
|
1432 { |
|
1433 CBitwiseBitmap* bitmap = CleanAddress(); |
|
1434 if (!bitmap) |
|
1435 { |
|
1436 return EFalse; |
|
1437 } |
|
1438 return bitmap->IsLargeBitmap(); |
|
1439 } |
|
1440 |
|
1441 /** Returns the handle for the hardware bitmap which this CFbsBitmap is using. |
|
1442 @return The handle to the hardware bitmap. The handle is NULL if it is not |
|
1443 a hardware bitmap. |
|
1444 @publishedAll |
|
1445 @released |
|
1446 */ |
|
1447 EXPORT_C TInt CFbsBitmap::HardwareBitmapHandle() const |
|
1448 { |
|
1449 CBitwiseBitmap* bitmap = CleanAddress(); |
|
1450 if (!bitmap) |
|
1451 { |
|
1452 return 0; |
|
1453 } |
|
1454 return bitmap->HardwareBitmapHandle(); |
|
1455 } |
|
1456 |
|
1457 /** Gets the attributes of the bitmap's palette. |
|
1458 This is not currently supported. |
|
1459 @param aModifiable On return, whether or not the palette is modifiable. |
|
1460 @param aNumEntries On return, the number of entries in the palette. |
|
1461 @publishedAll |
|
1462 @released |
|
1463 */ |
|
1464 EXPORT_C void CFbsBitmap::PaletteAttributes(TBool& aModifiable,TInt& aNumEntries) const |
|
1465 { |
|
1466 aModifiable=EFalse; |
|
1467 aNumEntries=0; |
|
1468 } |
|
1469 |
|
1470 /** Sets the bitmap's palette. |
|
1471 This is not currently supported. |
|
1472 @param aPalette Not used. |
|
1473 @publishedAll |
|
1474 @released |
|
1475 */ |
|
1476 EXPORT_C void CFbsBitmap::SetPalette(CPalette* /*aPalette*/) |
|
1477 { |
|
1478 } |
|
1479 |
|
1480 /** Gets the bitmap's palette. |
|
1481 This is not currently supported. |
|
1482 @param aPalette Not used. |
|
1483 @return KErrNotSupported. |
|
1484 @publishedAll |
|
1485 @released |
|
1486 */ |
|
1487 EXPORT_C TInt CFbsBitmap::GetPalette(CPalette*& /*aPalette*/) const |
|
1488 { |
|
1489 return(KErrNotSupported); |
|
1490 } |
|
1491 |
|
1492 /** |
|
1493 @internalComponent |
|
1494 This method loads a bitmap from an opened file handle. |
|
1495 |
|
1496 @param aFile mbm or rsc file handle (rsc file format: header + rsc |
|
1497 data section + mbm file section). |
|
1498 @param aId Bitmap ID - should be less than mbm file bitmaps count. |
|
1499 @param aShareIfLoaded Specifies whether or not the loaded bitmap will be |
|
1500 made available for sharing between FBSERV clients. |
|
1501 @param aFileOffset mbm file section offset into rsc file. |
|
1502 @return KErrNone if successful, otherwise another |
|
1503 of the system-wide error codes. |
|
1504 */ |
|
1505 TInt CFbsBitmap::DoLoad(RFile& aFile,TInt32 aId,TBool aShareIfLoaded,TUint aFileOffset) |
|
1506 { |
|
1507 TInt ret=KErrNone; |
|
1508 TPckgBuf<TBmpHandles> handlebuf; |
|
1509 TPckgBuf<TLoadBitmapArg> loadBitmapArg; |
|
1510 loadBitmapArg().iBitmapId = aId; |
|
1511 loadBitmapArg().iShareIfLoaded = TInt(aShareIfLoaded); |
|
1512 loadBitmapArg().iFileOffset = aFileOffset; |
|
1513 //Getting the RFs Handle(2) and RFile handle(3) into a TIpcArgs into 2nd and 3rd argument |
|
1514 TIpcArgs fileargs; |
|
1515 ret=aFile.TransferToServer(fileargs,2,3); |
|
1516 if (ret!=KErrNone) |
|
1517 return ret; |
|
1518 fileargs.Set(0,&handlebuf); |
|
1519 fileargs.Set(1,&loadBitmapArg); |
|
1520 ret=iFbs->SendCommand(EFbsMessBitmapLoad,fileargs); |
|
1521 if(ret!=KErrNone) return(ret); |
|
1522 iHandle=handlebuf().iHandle; |
|
1523 iServerHandle=handlebuf().iServerHandle; |
|
1524 iAddressPointer=(CBitwiseBitmap*)(iFbs->HeapBase()+handlebuf().iAddressOffset); |
|
1525 ret = iFbs->iHelper->AddBitmap(*this); |
|
1526 if (ret != KErrNone) |
|
1527 return ret; |
|
1528 return iFbs->AllocScanLineBuffer(iAddressPointer->iByteWidth+4); |
|
1529 } |
|
1530 |
|
1531 /** |
|
1532 @internalComponent |
|
1533 This method loads a bitmap from the mbm or rsc file specified by the filename. |
|
1534 |
|
1535 @param aFileName mbm or rsc file name (rsc file format: header + rsc |
|
1536 data section + mbm file section). |
|
1537 @param aId Bitmap ID - should be less than mbm file bitmaps count. |
|
1538 @param aShareIfLoaded Specifies whether or not the loaded bitmap will be |
|
1539 made available for sharing between FBSERV clients. |
|
1540 @param aFileOffset mbm file section offset into rsc file. |
|
1541 @return KErrNone if successful, otherwise another |
|
1542 of the system-wide error codes. |
|
1543 */ |
|
1544 TInt CFbsBitmap::DoLoad(const TDesC& aFileName,TInt32 aId,TBool aShareIfLoaded,TUint aFileOffset) |
|
1545 { |
|
1546 TInt ret=KErrNone; |
|
1547 TPckgBuf<TBmpHandles> handlebuf; |
|
1548 TPckgBuf<TLoadBitmapArg> loadBitmapArg; |
|
1549 loadBitmapArg().iBitmapId = aId; |
|
1550 loadBitmapArg().iShareIfLoaded = TInt(aShareIfLoaded); |
|
1551 loadBitmapArg().iFileOffset = aFileOffset; |
|
1552 TIpcArgs fileargs; |
|
1553 fileargs.Set(0,&handlebuf); |
|
1554 fileargs.Set(1,&loadBitmapArg); |
|
1555 fileargs.Set(2,&aFileName); |
|
1556 ret=iFbs->SendCommand(EFbsMessBitmapLoadFast,fileargs); |
|
1557 if(ret!=KErrNone) return(ret); |
|
1558 iHandle=handlebuf().iHandle; |
|
1559 iServerHandle=handlebuf().iServerHandle; |
|
1560 iAddressPointer=(CBitwiseBitmap*)(iFbs->HeapBase()+handlebuf().iAddressOffset); |
|
1561 ret = iFbs->iHelper->AddBitmap(*this); |
|
1562 if (ret != KErrNone) |
|
1563 return ret; |
|
1564 return iFbs->AllocScanLineBuffer(iAddressPointer->iByteWidth+4); |
|
1565 } |
|
1566 |
|
1567 /** |
|
1568 @internalComponent |
|
1569 This method handles very special case when the rsc file is in RAM, but it |
|
1570 contains ROM mbm file. ROM mbm file format is different than RAM mbm file |
|
1571 format and ROM mbm file cannot be loaded into RAM using standard techniques |
|
1572 (used by CFbsBitmap::DoLoad()). We have to check it is really a ROM mbm file. |
|
1573 If it is - we have to allocate the right amount of RAM, read and copy |
|
1574 requested ROM bitmap to the allocated RAM. |
|
1575 |
|
1576 @leave KErrNotSupported if this is a RAM rsc file with ROM mbm file section, |
|
1577 or any of the RFile related error codes. |
|
1578 @param aFileName rsc file name (rsc file format: header + rsc data section + |
|
1579 mbm file section). |
|
1580 @param aId Bitmap ID - should be less than mbm file bitmaps count. |
|
1581 @param aFileOffset mbm file section offset into rsc file. |
|
1582 @return EFalse - this is not a ROM mbm file. ETrue - this is a ROM mbm file |
|
1583 and requested by aId bitmmap is loaded. |
|
1584 */ |
|
1585 TBool CFbsBitmap::LoadShiftedRomBmpL(const TDesC& aFileName, TInt32 aId, TUint aFileOffset) |
|
1586 { |
|
1587 RFile mbm_file; |
|
1588 ::CleanupClosePushL(mbm_file); |
|
1589 User::LeaveIfError(mbm_file.Open(iFbs->FileServer(), aFileName, EFileRead | EFileShareReadersOnly)); |
|
1590 TInt pos = static_cast <TInt> (aFileOffset); |
|
1591 User::LeaveIfError(mbm_file.Seek(ESeekStart, pos));//move to the beginning of the mbm file section |
|
1592 TBuf8<sizeof(CBitwiseBitmap)> buf; |
|
1593 //Check if it is a ROM mbm file |
|
1594 User::LeaveIfError(mbm_file.Read(buf, sizeof(KMultiBitmapRomImageUid.iUid)));//Bitmap file UID - ROM or RAM |
|
1595 TInt32 mbm_uid = *(reinterpret_cast <const TInt32*> (buf.Ptr())); |
|
1596 TBool loaded = EFalse; |
|
1597 if(mbm_uid == KMultiBitmapRomImageUid.iUid) |
|
1598 { |
|
1599 if(!KRomMBMInRamRSC) |
|
1600 { |
|
1601 User::Leave(KErrNotSupported); |
|
1602 } |
|
1603 else |
|
1604 { |
|
1605 User::LeaveIfError(mbm_file.Read(buf, sizeof(TInt32)));//Number of bitmaps |
|
1606 TInt32 bmp_cnt = *(reinterpret_cast <const TInt32*> (buf.Ptr())); |
|
1607 if(aId >= bmp_cnt) |
|
1608 { |
|
1609 User::Leave(KErrNotFound); |
|
1610 } |
|
1611 for(TInt i=0;i<aId;i++) //Read bitmap UIDs located before aId. |
|
1612 { |
|
1613 User::LeaveIfError(mbm_file.Read(buf, sizeof(aId))); |
|
1614 } |
|
1615 User::LeaveIfError(mbm_file.Read(buf, sizeof(TInt32)));//Read the offset of aId bitmap. |
|
1616 TInt bmp_offset = *(reinterpret_cast <const TInt32*> (buf.Ptr())) + TInt(aFileOffset); |
|
1617 pos = static_cast <TInt> (bmp_offset); |
|
1618 User::LeaveIfError(mbm_file.Seek(ESeekStart, pos));//move the file pointer to the bitmap |
|
1619 User::LeaveIfError(mbm_file.Read(buf, sizeof(CBitwiseBitmap)));//Read CBitwiseBitmap data (without the bitmap data) |
|
1620 const CBitwiseBitmap* bmp = reinterpret_cast <const CBitwiseBitmap*> (buf.Ptr()); |
|
1621 //Calculate bitmap data size, alocate enough memory for the bitmap, copy CBitwiseBitmap |
|
1622 //members first, read the bitmap data from the file, copy the data to the allocated memory, |
|
1623 //initialize iRomPointer. |
|
1624 //If sizeof(CBitwiseBitmap) != real size of CBitwiseBitmap then we could have problems, |
|
1625 //because bitmap data won't be copied at the right position. |
|
1626 TInt size = bmp->iHeader.iBitmapSize - sizeof(SEpocBitmapHeader) + sizeof(CBitwiseBitmap); |
|
1627 TUint8* bmp_mem = new (ELeave) TUint8[size]; |
|
1628 //There is no need bmp_mem to be aligned, because it is a pointer to a RAM block of memory. |
|
1629 TCleanupItem cleanitem(FreeMem, bmp_mem); |
|
1630 CleanupStack::PushL(cleanitem); |
|
1631 Mem::Copy(bmp_mem, bmp, sizeof(CBitwiseBitmap)); |
|
1632 TPtr8 pbmp(bmp_mem + sizeof(CBitwiseBitmap), size - sizeof(CBitwiseBitmap)); |
|
1633 User::LeaveIfError(mbm_file.Read(pbmp, size - sizeof(CBitwiseBitmap)));//read the bitmap data. We've already read the CBitwiseBitmap data. |
|
1634 CleanupStack::Pop(bmp_mem); |
|
1635 iAddressPointer = reinterpret_cast<CBitwiseBitmap*>(bmp_mem); |
|
1636 iFlags = EIsRomBitmap; |
|
1637 iHandle = 1; |
|
1638 loaded = ETrue; |
|
1639 }//end of - if(!KRomMBMInRamRSC) - "else" part |
|
1640 }//end of - if(mbm_uid == KMultiBitmapRomImageUid.iUid) |
|
1641 CleanupStack::PopAndDestroy();//mbm_file |
|
1642 return loaded; |
|
1643 } |
|
1644 |
|
1645 /** |
|
1646 Swaps the bitmap's width and height. |
|
1647 For example, if the bitmap's size is (40, 20), the new size will be (20, 40). |
|
1648 Bitmap content is not preserved. |
|
1649 @publishedAll |
|
1650 @released |
|
1651 @return KErrNone if the call was successful, KErrGeneral if the bitmap handle is |
|
1652 invalid, KErrAccessDenied if the bitmap is in ROM, KErrNotSupported if the bitmap |
|
1653 is a hardware bitmap or an extended bitmap. |
|
1654 */ |
|
1655 EXPORT_C TInt CFbsBitmap::SwapWidthAndHeight() |
|
1656 { |
|
1657 if(!iHandle) |
|
1658 { |
|
1659 return KErrGeneral; |
|
1660 } |
|
1661 TUint32* data; |
|
1662 CBitwiseBitmap* bmp = BeginDataAccessAndGetCleanAddress(data); |
|
1663 |
|
1664 // Check the new bitmap size here then decide whether to swap the bitmap on the |
|
1665 // client side or send it to be done on the server and reallocate memory for it. |
|
1666 TInt newWidthInBytes = CBitwiseBitmap::ByteWidth(bmp->iHeader.iSizeInPixels.iHeight, bmp->iSettings.CurrentDisplayMode()); |
|
1667 TInt64 hugeDataSize = TInt64(bmp->iHeader.iSizeInPixels.iWidth) * TInt64(newWidthInBytes); |
|
1668 |
|
1669 TInt err = KErrNone; |
|
1670 // If the size of the new swapped bitmap is less than or equal its original size before the swap, |
|
1671 // then we do not need to reallocate memory. The swapping is straight forward. |
|
1672 if( I64HIGH(hugeDataSize) == 0 && I64LOW(hugeDataSize) <= TUint(bmp->iHeader.iBitmapSize - bmp->iHeader.iStructSize) ) |
|
1673 { |
|
1674 err = bmp->SwapWidthAndHeight(data); |
|
1675 // Even though used DataAddress() as read-only, need to increment touch count, so indicate that data has been written |
|
1676 EndDataAccess(EFalse); |
|
1677 } |
|
1678 // Otherwise we need to reallocate memory. We do this by using the already exisitng |
|
1679 // Resize() function as a work around- Code Reusability!! |
|
1680 else |
|
1681 { |
|
1682 EndDataAccess(ETrue); // Used DataAddress() to read only. |
|
1683 // Resize will increase touch counter |
|
1684 err = Resize(TSize(bmp->iHeader.iSizeInPixels.iHeight, bmp->iHeader.iSizeInPixels.iWidth)); |
|
1685 } |
|
1686 return err; |
|
1687 } |
|
1688 |
|
1689 /** Gets a pointer to the decompression buffer owned by this thread's FBServ session. |
|
1690 @param aSize The size in bytes of the scan lines to decompress. |
|
1691 @return A pointer to the decompression buffer or NULL if there is no FBServ session. |
|
1692 @internalTechnology |
|
1693 @released |
|
1694 */ |
|
1695 EXPORT_C HBufC8* CFbsBitmap::GetDecompressionBuffer(TInt aSize) |
|
1696 { |
|
1697 RFbsSession* ses=RFbsSession::GetSession(); |
|
1698 return ses? ses->GetDecompressionBuffer(aSize) : NULL; |
|
1699 } |
|
1700 |
|
1701 /** Gets a pointer to the rasterizer for extended bitmaps if present. |
|
1702 @return A pointer to the rasterizer owned by this thread's FBServ session. |
|
1703 @return NULL if the rasterizer is not present. |
|
1704 @internalTechnology |
|
1705 @prototype |
|
1706 */ |
|
1707 EXPORT_C CFbsRasterizer* CFbsBitmap::Rasterizer() |
|
1708 { |
|
1709 RFbsSession* session = RFbsSession::GetSession(); |
|
1710 return session ? session->iHelper->Rasterizer() : NULL; |
|
1711 } |
|
1712 |
|
1713 /** Loads a specific bitmap from an opened multi-bitmap file handle. |
|
1714 The bitmap may be shared by other font and bitmap server clients. |
|
1715 @param aFile The handle of the multi-bitmap (.mbm) file. |
|
1716 @param aId The bitmap identifier. |
|
1717 @param aShareIfLoaded Specifies whether or not the loaded bitmap will be made |
|
1718 available for sharing between font and bitmap server clients. |
|
1719 @return KErrNone if successful, otherwise another of the system error |
|
1720 codes. |
|
1721 @publishedAll |
|
1722 @released |
|
1723 */ |
|
1724 EXPORT_C TInt CFbsBitmap::Load(RFile& aFile,TInt32 aId/*=0*/,TBool aShareIfLoaded/*=ETrue*/) |
|
1725 { |
|
1726 return Load(aFile,aId,aShareIfLoaded,0); |
|
1727 } |
|
1728 |
|
1729 /** Loads a specific bitmap from an opened multi-bitmap file handle. |
|
1730 The bitmap may be shared by other font and bitmap server clients. |
|
1731 @param aFile The handle of the multi-bitmap (.mbm) file. |
|
1732 @param aId The bitmap identifier. |
|
1733 @param aShareIfLoaded Specifies whether or not the loaded bitmap will be made |
|
1734 available for sharing between FBSERV clients. |
|
1735 @param aFileOffset Bitmap file section offset within the file. |
|
1736 @return KErrNone if successful, otherwise another of the system error codes. |
|
1737 @publishedAll |
|
1738 @released |
|
1739 */ |
|
1740 EXPORT_C TInt CFbsBitmap::Load(RFile& aFile,TInt32 aId,TBool aShareIfLoaded,TUint aFileOffset) |
|
1741 { |
|
1742 if (!iFbs) |
|
1743 { |
|
1744 return(KErrCouldNotConnect); |
|
1745 } |
|
1746 Reset(); |
|
1747 TUint32* rompointer; |
|
1748 IsFileInRom(aFile,rompointer); |
|
1749 TBool romPointerValid; |
|
1750 TInt err = DoLoadFromRom(rompointer, aId, aFileOffset, romPointerValid); |
|
1751 if (!romPointerValid) |
|
1752 { |
|
1753 err = DoLoad(aFile,aId,aShareIfLoaded,aFileOffset); |
|
1754 } |
|
1755 return err; |
|
1756 } |
|
1757 |
|
1758 /** Loads and compresses a specific bitmap from an opened multi-bitmap file handle. |
|
1759 The bitmap may be shared by other font and bitmap server clients. |
|
1760 If the bitmap is loaded from ROM then compression is not allowed. |
|
1761 @param aFile The handle of the multi-bitmap (.mbm) file. |
|
1762 @param aId The bitmap identifier. |
|
1763 @param aShareIfLoaded Specifies whether or not the loaded bitmap will be |
|
1764 made available for sharing between FBSERV clients. |
|
1765 @return KErrNone if successful, otherwise another of the system-wide error |
|
1766 codes. |
|
1767 @publishedAll |
|
1768 @released |
|
1769 */ |
|
1770 EXPORT_C TInt CFbsBitmap::LoadAndCompress(RFile& aFile,TInt32 aId/*=0*/,TBool aShareIfLoaded/*=ETrue*/) |
|
1771 { |
|
1772 return LoadAndCompress(aFile,aId,aShareIfLoaded,0); |
|
1773 } |
|
1774 |
|
1775 /** Loads and compresses a specific bitmap from an opened multi-bitmap file handle. |
|
1776 The bitmap may be shared by other font and bitmap server clients. If the |
|
1777 bitmap is loaded from ROM then compression is not allowed. |
|
1778 @param aFile The handle of the multi-bitmap (.mbm) file. |
|
1779 @param aId The bitmap identifier. |
|
1780 @param aShareIfLoaded Specifies whether or not the loaded bitmap will be made |
|
1781 available for sharing between FBSERV clients. |
|
1782 @param aFileOffset Bitmap file section offset within the file. |
|
1783 @return KErrNone if successful, otherwise another of the system-wide error |
|
1784 codes. |
|
1785 @publishedAll |
|
1786 @released |
|
1787 */ |
|
1788 EXPORT_C TInt CFbsBitmap::LoadAndCompress(RFile& aFile,TInt32 aId,TBool aShareIfLoaded,TUint aFileOffset) |
|
1789 { |
|
1790 TInt err = Load(aFile,aId,aShareIfLoaded,aFileOffset); |
|
1791 if (err == KErrNone) |
|
1792 { |
|
1793 err = !(iFlags & EIsRomBitmap) ? Compress() : KErrAccessDenied; |
|
1794 } |
|
1795 return err; |
|
1796 } |
|
1797 |
|
1798 /** Gets all the bitmap handles for all the bitmaps stored in the Font Bitmap Server. There is a limit of |
|
1799 the number of bitmaps that can be retrieved defined by KMaxBitmapHandleBufferSize. If this limit has been |
|
1800 reached then KErrOverflow will be returned. |
|
1801 @param aBitmapIdArray returns an array of all the bitmap handles |
|
1802 @return KErrNone if successful, KErrOverflow if the bitmapBuffer is not large enough to store |
|
1803 all the bitmap handles, otherwise another of the system-wide error codes. |
|
1804 @capability ReadDeviceData |
|
1805 @internalComponent |
|
1806 @released |
|
1807 */ |
|
1808 EXPORT_C TInt CFbsBitmap::GetAllBitmapHandles(RArray<TInt>& aBitmapIdArray) const |
|
1809 { |
|
1810 RBuf8 bitmapBuffer; |
|
1811 TInt ret = bitmapBuffer.Create(KMaxBitmapHandleBufferSize); |
|
1812 if (ret==KErrNone) |
|
1813 { |
|
1814 TIpcArgs args(&bitmapBuffer); |
|
1815 ret=iFbs->SendCommand(EFbsGetAllBitmapHandles, args); |
|
1816 if (ret==KErrNone) |
|
1817 { |
|
1818 // Convert data returned from server and place into the RArray (aBitmapIdArray) |
|
1819 aBitmapIdArray.Reset(); |
|
1820 TInt* bitmapIdPtr = (TInt*)bitmapBuffer.Ptr(); |
|
1821 const TInt numBitmapIds = bitmapBuffer.Size() / KNumBytesPerBitmapHandle; // Divide by number of bytes per bitmap handle to get total number of bitmap IDs |
|
1822 for (TInt count=0; count<numBitmapIds; ++count) |
|
1823 { |
|
1824 TInt bitmapId = *bitmapIdPtr++; |
|
1825 ret = aBitmapIdArray.Append(bitmapId); |
|
1826 if (ret!=KErrNone) |
|
1827 break; |
|
1828 } |
|
1829 } |
|
1830 } |
|
1831 bitmapBuffer.Close(); |
|
1832 return ret; |
|
1833 } |
|
1834 |
|
1835 /** |
|
1836 @internalComponent |
|
1837 This method tries to load a bitmap if mbm or rsc file is in ROM. |
|
1838 |
|
1839 @param aRomPointer the address of the file in ROM |
|
1840 @param aId a Bitmap ID which should be less than mbm file bitmaps count. |
|
1841 @param aFileOffset mbm file section offset into rsc file. |
|
1842 @param aRomPointerValid on output it is set to ETrue if aRomPointer points to a valid ROM file or EFalse otherwise. |
|
1843 @return KErrNone if successful, otherwise another of the system-wide error codes. |
|
1844 */ |
|
1845 TInt CFbsBitmap::DoLoadFromRom(TUint32* aRomPointer, TInt32 aId, TUint aFileOffset, TBool& aRomPointerValid) |
|
1846 { |
|
1847 aRomPointerValid = ETrue; |
|
1848 if(aRomPointer) |
|
1849 { |
|
1850 TUint8* temp = reinterpret_cast <TUint8*> (aRomPointer); |
|
1851 __ASSERT_DEBUG(!(TUint(temp) & 0x00000003),Panic(EFbsBitmapAlignment)); |
|
1852 temp += aFileOffset; |
|
1853 aRomPointer = reinterpret_cast <TUint32*> (temp); |
|
1854 if(TInt32(*aRomPointer)==KMultiBitmapRomImageUid.iUid) |
|
1855 { |
|
1856 TInt numbitmaps = (TInt)*(aRomPointer+1); |
|
1857 if(aId>=numbitmaps) |
|
1858 { |
|
1859 return(KErrEof); |
|
1860 } |
|
1861 TInt offset = *(aRomPointer+aId+2); |
|
1862 iAddressPointer = (CBitwiseBitmap*)(((TUint8*)aRomPointer) + offset); |
|
1863 iFlags = EIsRomBitmap; |
|
1864 iHandle = 1; |
|
1865 return iFbs->AllocScanLineBuffer(iAddressPointer->iByteWidth + 4); |
|
1866 } |
|
1867 } |
|
1868 aRomPointerValid = EFalse; |
|
1869 return KErrNone; |
|
1870 } |
|
1871 |
|
1872 |
|
1873 /** |
|
1874 Creates an extended bitmap. Extended bitmaps are used to store immutable |
|
1875 data in a platform-specific format. They cannot be used as targets of |
|
1876 graphics contexts, and modification of their data via DataAddress() or |
|
1877 TBitmapUtil is not supported and results in undefined behaviour up to |
|
1878 and including process termination. |
|
1879 |
|
1880 Initialisation of the raw data of the new bitmap is carried out by copying |
|
1881 the data pointed to by the parameter aData. |
|
1882 |
|
1883 Read-only access to the raw data of an extended bitmap is provided by |
|
1884 DataAddress() and DataSize() in conjunction with BeginDataAccess() and |
|
1885 EndDataAccess(). |
|
1886 |
|
1887 Extended bitmaps have a conceptual size in pixels and a conceptual |
|
1888 display mode for compatibility purposes. The raw data can be independent |
|
1889 of these properties. |
|
1890 |
|
1891 @param aSizeInPixels The conceptual width and height of the new bitmap in pixels. |
|
1892 @param aDispMode The conceptual display mode of the new bitmap. |
|
1893 @param aType The UID identifying the data format of the new bitmap. Used by the |
|
1894 extended bitmap rasterizer to distinguish between different data types. |
|
1895 @param aData A pointer to the raw data to be stored in the new bitmap. |
|
1896 @param aDataSize The size in bytes of the raw data to be stored in the new bitmap. |
|
1897 @return KErrNone if successful; KErrArgument if the width or height specified in |
|
1898 aSizeInPixels is negative, aDispMode is an invalid display mode, aData is NULL, |
|
1899 aDataSize is negative or zero, or aDataType is a UID reserved for OS use; KErrTooBig |
|
1900 if the width or height specified in aSizeInPixels exceeds KMaxTInt/4, or aDataSize |
|
1901 exceeds KMaxTInt/2; otherwise another of the system-wide error codes. |
|
1902 @publishedPartner |
|
1903 @prototype |
|
1904 @see CFbsBitmap::DataAddress() |
|
1905 @see CFbsBitmap::DataSize() |
|
1906 @see CFbsBitmap::BeginDataAccess() |
|
1907 @see CFbsBitmap::EndDataAccess() |
|
1908 */ |
|
1909 EXPORT_C TInt CFbsBitmap::CreateExtendedBitmap(const TSize& aSizeInPixels, TDisplayMode aDispMode, TUid aType, const TAny* aData, TInt aDataSize) |
|
1910 { |
|
1911 if (!aData || aDataSize == 0) |
|
1912 { |
|
1913 return KErrArgument; |
|
1914 } |
|
1915 TInt err = DoCreate(aSizeInPixels, aDispMode, aType, aDataSize); |
|
1916 if (err == KErrNone) |
|
1917 { |
|
1918 Mem::Copy(iFbs->iLargeBitmapChunk.Base() + iAddressPointer->iDataOffset, aData, aDataSize); |
|
1919 } |
|
1920 return err; |
|
1921 } |
|
1922 |
|
1923 /** |
|
1924 Creates an extended bitmap. Extended bitmaps are used to store immutable |
|
1925 data in a platform-specific format. They cannot be used as targets of |
|
1926 graphics contexts, and modification of their data via DataAddress() or |
|
1927 TBitmapUtil is not supported and results in undefined behaviour up to |
|
1928 and including process termination. |
|
1929 |
|
1930 Initialisation of the raw data of the new bitmap is carried out by a |
|
1931 callback to the MFbsExtendedBitmapInitializer::InitExtendedBitmap() |
|
1932 function passed through the parameter aInitializer. |
|
1933 |
|
1934 Read-only access to the raw data of an extended bitmap is provided by |
|
1935 DataAddress() and DataSize() in conjunction with BeginDataAccess() and |
|
1936 EndDataAccess(). |
|
1937 |
|
1938 Extended bitmaps have a conceptual size in pixels and a conceptual |
|
1939 display mode for compatibility purposes. The raw data can be independent |
|
1940 of these properties. |
|
1941 |
|
1942 @param aSizeInPixels The conceptual width and height of the new bitmap in pixels. |
|
1943 @param aDispMode The conceptual display mode of the new bitmap. |
|
1944 @param aType The UID identifying the data format of the new bitmap. Used by the |
|
1945 extended bitmap rasterizer to distinguish between different data types. |
|
1946 @param aDataSize The size in bytes of the raw data to be stored in the new bitmap. |
|
1947 @param aInitializer A reference to the initializer of the raw data to be stored in the new bitmap. |
|
1948 @return KErrNone if successful; KErrArgument if the width or height specified in |
|
1949 aSizeInPixels is negative, aDispMode is an invalid display mode, aData is NULL, |
|
1950 aDataSize is negative or zero, or aDataType is a UID reserved for OS use; KErrTooBig |
|
1951 if the width or height specified in aSizeInPixels exceeds KMaxTInt/4, or aDataSize |
|
1952 exceeds KMaxTInt/2; otherwise another of the system-wide error codes. |
|
1953 @publishedPartner |
|
1954 @prototype |
|
1955 @see CFbsBitmap::DataAddress() |
|
1956 @see CFbsBitmap::DataSize() |
|
1957 @see CFbsBitmap::BeginDataAccess() |
|
1958 @see CFbsBitmap::EndDataAccess() |
|
1959 @see MFbsExtendedBitmapInitializer |
|
1960 */ |
|
1961 EXPORT_C TInt CFbsBitmap::CreateExtendedBitmap(const TSize& aSizeInPixels, TDisplayMode aDispMode, TUid aType, TInt aDataSize, MFbsExtendedBitmapInitializer& aInitializer) |
|
1962 { |
|
1963 if (aDataSize == 0) |
|
1964 { |
|
1965 return KErrArgument; |
|
1966 } |
|
1967 TInt err = DoCreate(aSizeInPixels, aDispMode, aType, aDataSize); |
|
1968 if (err == KErrNone) |
|
1969 { |
|
1970 err = aInitializer.InitExtendedBitmap(iFbs->iLargeBitmapChunk.Base() + iAddressPointer->iDataOffset, aDataSize); |
|
1971 if (err != KErrNone) |
|
1972 { |
|
1973 Reset(); |
|
1974 } |
|
1975 } |
|
1976 return err; |
|
1977 } |
|
1978 |
|
1979 /** |
|
1980 Gets the UID identifying the data format of an extended bitmap. |
|
1981 @return The UID identifying the data format of the bitmap or |
|
1982 KNullUid if the bitmap is not an extended bitmap. |
|
1983 @publishedPartner |
|
1984 @prototype |
|
1985 */ |
|
1986 EXPORT_C TUid CFbsBitmap::ExtendedBitmapType() const |
|
1987 { |
|
1988 if (iHandle == 0) |
|
1989 { |
|
1990 return KNullUid; |
|
1991 } |
|
1992 TUid type = CleanAddress()->iUid; |
|
1993 if (type.iUid == KCBitwiseBitmapUid.iUid || type.iUid == KCBitwiseBitmapHardwareUid.iUid) |
|
1994 { |
|
1995 return KNullUid; |
|
1996 } |
|
1997 return type; |
|
1998 } |
|
1999 |
|
2000 /** |
|
2001 Gets the size in bytes of the bitmap data. |
|
2002 @return The size in bytes of the bitmap data. |
|
2003 @publishedPartner |
|
2004 @prototype |
|
2005 */ |
|
2006 EXPORT_C TInt CFbsBitmap::DataSize() const |
|
2007 { |
|
2008 if (iHandle == 0) |
|
2009 { |
|
2010 return 0; |
|
2011 } |
|
2012 CBitwiseBitmap* bmp = CleanAddress(); |
|
2013 return bmp->iHeader.iBitmapSize - bmp->iHeader.iStructSize; |
|
2014 } |
|
2015 |
|
2016 /** |
|
2017 Gets a pointer to an extra buffer for general use owned by this thread's FBServ session. |
|
2018 @param aSize The size of the buffer in bytes |
|
2019 @return A pointer to the extra buffer if successful or NULL if there is no FBServ session |
|
2020 @internalTechnology |
|
2021 @released |
|
2022 */ |
|
2023 EXPORT_C HBufC8* CFbsBitmap::GetExtraBuffer(TInt aSize) |
|
2024 { |
|
2025 RFbsSession* ses=RFbsSession::GetSession(); |
|
2026 return ses? ses->GetExtraBuffer(aSize) : NULL; |
|
2027 } |