|
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 <fntstore.h> |
|
17 #include <bitmap.h> |
|
18 #include "FBSVER.H" |
|
19 #include "SERVER.H" |
|
20 #include "BackGroundCompression.h" |
|
21 #include "linkedfonts.h" |
|
22 #include "BitwiseBitmap.inl" |
|
23 |
|
24 const TInt KFbsPriority = 0; |
|
25 |
|
26 // Setup security policies |
|
27 const TInt KRanges[] = |
|
28 { |
|
29 0, |
|
30 EFbsMessShutdown, |
|
31 EFbsMessClose, |
|
32 EFbsSetSystemDefaultTypefaceName, |
|
33 EFbsGetAllBitmapHandles, |
|
34 EFbsMessUnused1, |
|
35 EFbsMessUnused2, |
|
36 EFbsMessRegisterLinkedTypeface, |
|
37 EFbsMessFetchLinkedTypeface, |
|
38 EFbsMessUpdateLinkedTypeface, |
|
39 }; |
|
40 const TUint KRangeCount = sizeof(KRanges)/sizeof(TInt); |
|
41 const TUint8 KElementsIndex[KRangeCount] = |
|
42 { |
|
43 0, |
|
44 3, // For EFbsMessShutdown |
|
45 0, |
|
46 1, // For EFbsSetSystemDefaultTypefaceName |
|
47 2, // For EFbsGetAllBitmapHandles |
|
48 0, // ECapability_None for EFbsMessUnused1 |
|
49 0, // ECapability_None for EFbsMessUnused2 and beyond |
|
50 1, // ECapabilityWriteDeviceData for EFbsMessRegisterLinkedTypeface |
|
51 2, // ECapabilityReadDeviceData for EFbsMessFetchLinkedTypeface |
|
52 1, // ECapabilityWriteDeviceData for EFbsMessUpdateLinkedTypeface |
|
53 }; |
|
54 const CPolicyServer::TPolicyElement KElements[] = |
|
55 { |
|
56 {_INIT_SECURITY_POLICY_C1(ECapability_None), CPolicyServer::EFailClient}, |
|
57 {_INIT_SECURITY_POLICY_C1(ECapabilityWriteDeviceData), CPolicyServer::EFailClient}, |
|
58 {_INIT_SECURITY_POLICY_C1(ECapabilityReadDeviceData), CPolicyServer::EFailClient}, |
|
59 {_INIT_SECURITY_POLICY_C1(ECapabilityPowerMgmt), CPolicyServer::EFailClient}, |
|
60 }; |
|
61 const CPolicyServer::TPolicy KFbsPolicy = |
|
62 { |
|
63 CPolicyServer::EAlwaysPass, //specifies all connect attempts should pass |
|
64 KRangeCount, |
|
65 KRanges, |
|
66 KElementsIndex, |
|
67 KElements, |
|
68 }; |
|
69 |
|
70 CFontBitmapServer::CFontBitmapServer(): |
|
71 CPolicyServer(KFbsPriority, KFbsPolicy), |
|
72 iConnectionId(0), |
|
73 iTopLevelStore(NULL) |
|
74 { |
|
75 } |
|
76 |
|
77 CFontBitmapServer::~CFontBitmapServer() |
|
78 { |
|
79 delete iTopLevelStore; |
|
80 iTopLevelStore = NULL; // so that CFBClient::~CFbClient can avoid using this pointer; |
|
81 // it may be called inside CFontBitmapServer::~CFontBitmapServer |
|
82 } |
|
83 |
|
84 CFontBitmapServer* CFontBitmapServer::NewL() |
|
85 { |
|
86 CFontBitmapServer* fbs=new(ELeave) CFontBitmapServer; |
|
87 CleanupStack::PushL(fbs); |
|
88 fbs->iTopLevelStore=CFbTop::NewL(); |
|
89 |
|
90 // If fbserv data paging is configured as unpaged, automatically pin client descriptors |
|
91 if(!RProcess().DefaultDataPaged()) |
|
92 { |
|
93 fbs->SetPinClientDescriptors(ETrue); |
|
94 } |
|
95 |
|
96 fbs->StartL(KFBSERVGlobalThreadName); |
|
97 CleanupStack::Pop(); |
|
98 return(fbs); |
|
99 } |
|
100 |
|
101 CFbTop* CFontBitmapServer::TopLevelStore() |
|
102 { |
|
103 return(iTopLevelStore); |
|
104 } |
|
105 CSession2* CFontBitmapServer::NewSessionL(const TVersion& aVersion,const RMessage2& /*aMessage*/ ) const |
|
106 { |
|
107 TVersion v(KFbsMajorVersionNumber,KFbsMinorVersionNumber,KFbsBuildVersionNumber); |
|
108 if(!User::QueryVersionSupported(v,aVersion)) |
|
109 User::Leave(KErrNotSupported); |
|
110 |
|
111 CSession2* pSession2 = CFbClient::NewL(iTopLevelStore->Heap()); |
|
112 return pSession2; |
|
113 } |
|
114 |
|
115 TInt CFontBitmapServer::Init() |
|
116 { |
|
117 return(iConnectionId++); |
|
118 } |
|
119 |
|
120 |
|
121 TInt CFontBitmapServer::HandleMesgTypefaceSupport(const RMessage2& aMessage, TBool& aClientPanicRequired) |
|
122 { |
|
123 TTypefaceSupport tfi; |
|
124 TPckgBuf<TTypefaceSupport> ttipckg(tfi); |
|
125 TPckgBuf<TSize> pixelSize; |
|
126 TInt index=aMessage.Int0(); |
|
127 TInt limit=iTopLevelStore->FontStore()->NumTypefaces(); |
|
128 if(index<0 || index>limit) |
|
129 { |
|
130 return KErrArgument; |
|
131 } |
|
132 TInt ret = aMessage.Read(2, pixelSize); |
|
133 if (ret != KErrNone) |
|
134 { |
|
135 return ret; |
|
136 } |
|
137 iTopLevelStore->FontStore()->iKPixelHeightInTwips = pixelSize().iHeight; |
|
138 iTopLevelStore->FontStore()->iKPixelWidthInTwips = pixelSize().iWidth; |
|
139 iTopLevelStore->FontStore()->TypefaceSupport(ttipckg(),index); |
|
140 ret = aMessage.Write(1,ttipckg); |
|
141 if(ret!=KErrNone) |
|
142 { |
|
143 aClientPanicRequired = ETrue; |
|
144 } |
|
145 return ret; |
|
146 } |
|
147 |
|
148 |
|
149 TInt CFontBitmapServer::HandleMesgFontHeight(const RMessage2& aMessage, TBool aInTwips) |
|
150 { |
|
151 TInt typefaceindex = aMessage.Int0(); |
|
152 TInt fontsize = aMessage.Int1(); |
|
153 |
|
154 if(typefaceindex < 0) |
|
155 { |
|
156 aMessage.Panic(KFBSERVPanicCategory,KErrArgument); |
|
157 return KErrArgument; |
|
158 } |
|
159 |
|
160 // pixel size (used to be set in a separate call) |
|
161 TPckgBuf<TSize> size; |
|
162 TInt ret = aMessage.Read(2, size); |
|
163 if (ret != KErrNone) |
|
164 { |
|
165 return ret; |
|
166 } |
|
167 |
|
168 if(size().iHeight <= 0 || size().iWidth < 0) |
|
169 { |
|
170 aMessage.Panic(KFBSERVPanicCategory,KErrArgument); |
|
171 return KErrArgument; |
|
172 } |
|
173 |
|
174 iTopLevelStore->FontStore()->iKPixelHeightInTwips = size().iHeight; |
|
175 iTopLevelStore->FontStore()->iKPixelWidthInTwips = size().iWidth; |
|
176 if (aInTwips) |
|
177 { |
|
178 return iTopLevelStore->FontStore()->FontHeightInTwips(typefaceindex,fontsize); |
|
179 } |
|
180 else |
|
181 { |
|
182 return iTopLevelStore->FontStore()->FontHeightInPixels(typefaceindex,fontsize); |
|
183 } |
|
184 } |
|
185 |
|
186 |
|
187 #ifdef _DEBUG |
|
188 //aRet is used in debug builds to allow the server to know if the call was successful. |
|
189 //On success there should be no panics from out of memory testing, since memory |
|
190 //may have been genuinely allocated. |
|
191 void CFontBitmapServer::ProcMessage(const RMessage2& aMessage, TInt aSession, TInt& aRet) |
|
192 #else |
|
193 void CFontBitmapServer::ProcMessage(const RMessage2& aMessage, TInt aSession) |
|
194 #endif |
|
195 { |
|
196 TInt ret=KErrNone; |
|
197 TBool clientPanicRequired = EFalse; |
|
198 #ifdef _DEBUG |
|
199 TInt num=0; |
|
200 #endif |
|
201 switch (aMessage.Function()) |
|
202 { |
|
203 case EFbsMessShutdown: |
|
204 CActiveScheduler::Stop(); |
|
205 break; |
|
206 case EFbsMessNumTypefaces: |
|
207 ret=iTopLevelStore->FontStore()->NumTypefaces(); |
|
208 break; |
|
209 case EFbsMessTypefaceSupport: |
|
210 ret = HandleMesgTypefaceSupport(aMessage, clientPanicRequired); |
|
211 break; |
|
212 |
|
213 case EFbsMessFontHeightInTwips: |
|
214 ret = HandleMesgFontHeight(aMessage, ETrue); |
|
215 break; |
|
216 |
|
217 case EFbsMessFontHeightInPixels: |
|
218 ret = HandleMesgFontHeight(aMessage, EFalse); |
|
219 break; |
|
220 |
|
221 case EFbsMessSetPixelHeight: |
|
222 iTopLevelStore->FontStore()->iKPixelWidthInTwips=aMessage.Int0(); |
|
223 iTopLevelStore->FontStore()->iKPixelHeightInTwips=aMessage.Int1(); |
|
224 break; |
|
225 #ifdef _DEBUG |
|
226 case EFbsMessDefaultAllocFail: |
|
227 num=aMessage.Int0(); |
|
228 if(num) __UHEAP_FAILNEXT(num); |
|
229 else __UHEAP_RESET; |
|
230 break; |
|
231 case EFbsMessDefaultMark: |
|
232 __UHEAP_MARK; |
|
233 break; |
|
234 case EFbsMessDefaultMarkEnd: |
|
235 num=aMessage.Int0(); |
|
236 if(num) __UHEAP_MARKENDC(num); |
|
237 else __UHEAP_MARKEND; |
|
238 break; |
|
239 case EFbsMessUserAllocFail: |
|
240 num=aMessage.Int0(); |
|
241 if(num) __RHEAP_FAILNEXT(iTopLevelStore->Heap(),num); |
|
242 else __RHEAP_RESET(iTopLevelStore->Heap()); |
|
243 break; |
|
244 case EFbsMessUserMark: |
|
245 __RHEAP_MARK(iTopLevelStore->Heap()); |
|
246 break; |
|
247 case EFbsMessUserMarkEnd: |
|
248 num=aMessage.Int0(); |
|
249 if(num) __RHEAP_MARKENDC(iTopLevelStore->Heap(),num); |
|
250 else __RHEAP_MARKEND(iTopLevelStore->Heap()); |
|
251 break; |
|
252 #endif |
|
253 case EFbsMessHeapCheck: |
|
254 iTopLevelStore->Heap()->Check(); |
|
255 User::Heap().Check(); |
|
256 break; |
|
257 case EFbsMessSetDefaultGlyphBitmapType: |
|
258 iTopLevelStore->FontStore()->SetDefaultBitmapType((TGlyphBitmapType)aMessage.Int0()); |
|
259 break; |
|
260 case EFbsMessGetDefaultGlyphBitmapType: |
|
261 ret = iTopLevelStore->FontStore()->DefaultBitmapType(); |
|
262 break; |
|
263 case EFbsMessFontNameAlias: |
|
264 TRAP(ret, iTopLevelStore->SetFontNameAliasL(aMessage)); |
|
265 break; |
|
266 case EFbsMessGetHeapSizes: |
|
267 TRAP(ret, GetHeapSizesL(aMessage)); |
|
268 break; |
|
269 case EFbsMessDefaultLanguageForMetrics: |
|
270 iTopLevelStore->SetDefaultLanguageForMetrics(aMessage); |
|
271 break; |
|
272 case EFbsCompress: |
|
273 iTopLevelStore->BackgroundCompression()->CompressAll(); |
|
274 break; |
|
275 case EFbsMessRegisterLinkedTypeface: |
|
276 { |
|
277 TPckgBuf<TLinkedTypefaceSpecificationArgs> buf; |
|
278 ret=aMessage.Read(0,buf); |
|
279 if (ret==KErrNone) |
|
280 { |
|
281 //Id used by original font linking; now unused. |
|
282 TInt id; |
|
283 ret=iTopLevelStore->FontStore()->CreateLinkedTypeface(buf(),aSession,id); |
|
284 } |
|
285 } |
|
286 break; |
|
287 case EFbsMessFetchLinkedTypeface: |
|
288 { |
|
289 TBuf<KMaxTypefaceNameLength> name; |
|
290 ret = aMessage.GetDesLength(0); |
|
291 |
|
292 if (ret < 0) |
|
293 break; |
|
294 |
|
295 if (ret > KMaxTypefaceNameLength) |
|
296 { |
|
297 clientPanicRequired = ETrue; |
|
298 ret = KErrTooBig; |
|
299 break; |
|
300 } |
|
301 |
|
302 ret = aMessage.Read(0,name); |
|
303 |
|
304 TLinkedTypefaceSpecificationArgs spec; |
|
305 |
|
306 spec.iName = name; |
|
307 |
|
308 if (ret==KErrNone) |
|
309 { |
|
310 TRAP(ret, iTopLevelStore->FontStore()->GetLinkedTypefaceL(spec)); |
|
311 |
|
312 if (ret == KErrNone) |
|
313 { |
|
314 TPckgBuf<TLinkedTypefaceSpecificationArgs> specArgs = spec; |
|
315 ret = aMessage.Write(2,specArgs); |
|
316 } |
|
317 } |
|
318 } |
|
319 break; |
|
320 case EFbsMessUpdateLinkedTypeface: |
|
321 { |
|
322 TPckgBuf<TLinkedTypefaceSpecificationArgs> buf; |
|
323 ret=aMessage.Read(0,buf); |
|
324 if (ret==KErrNone) |
|
325 { |
|
326 TRAP(ret, iTopLevelStore->FontStore()->UpdateLinkedTypefaceL(buf())); |
|
327 } |
|
328 } |
|
329 break; |
|
330 } |
|
331 |
|
332 if (clientPanicRequired) |
|
333 { |
|
334 aMessage.Panic(KFBSERVPanicCategory,ret); |
|
335 } |
|
336 else |
|
337 { |
|
338 if(!aMessage.IsNull()) |
|
339 { |
|
340 aMessage.Complete(ret); |
|
341 } |
|
342 } |
|
343 |
|
344 #ifdef _DEBUG |
|
345 aRet=ret; |
|
346 #endif |
|
347 } |
|
348 |
|
349 /** |
|
350 Returns the current sizes of the FBServ default heap, the heap for large bitmaps, |
|
351 and the heap for small bitmaps. |
|
352 |
|
353 Not supported in release builds. |
|
354 |
|
355 @internalComponent |
|
356 @test |
|
357 @param aMessage Encapsulates references to integers supplied by the caller, which will on return contain the sizes of the default heap, heap for small bitmaps, and heap for large bitmaps. |
|
358 @leave KErrNotSupported when used in release mode. |
|
359 */ |
|
360 #ifdef _DEBUG |
|
361 void CFontBitmapServer::GetHeapSizesL(const RMessage2& aMessage) |
|
362 { |
|
363 TPckgBuf<THeapSizes> data; |
|
364 TInt defaultHeapSize; |
|
365 TInt smallBmpHeapSize; |
|
366 TInt bigBmpHeapSize; |
|
367 |
|
368 User::Heap().AllocSize(defaultHeapSize); |
|
369 bigBmpHeapSize = iTopLevelStore->iLargeBitmapChunk.Size(); |
|
370 iTopLevelStore->Heap()->AllocSize(smallBmpHeapSize); |
|
371 |
|
372 data().iDefault = defaultHeapSize; |
|
373 data().iBig = bigBmpHeapSize; |
|
374 data().iSmall = smallBmpHeapSize; |
|
375 |
|
376 aMessage.WriteL(0, data); |
|
377 } |
|
378 #else |
|
379 void CFontBitmapServer::GetHeapSizesL(const RMessage2&) |
|
380 { |
|
381 User::Leave(KErrNotSupported); |
|
382 } |
|
383 #endif |
|
384 |
|
385 |
|
386 CFontObject::CFontObject(CFontStore* aFontStore): |
|
387 CObject(), |
|
388 iAddressPointer(NULL), |
|
389 iFontStore(aFontStore) |
|
390 { |
|
391 } |
|
392 |
|
393 CFontObject::~CFontObject() |
|
394 { |
|
395 if (AccessCount()==1) |
|
396 Dec(); |
|
397 iFontStore->ReleaseFont(iAddressPointer); |
|
398 } |
|
399 |
|
400 // CBitmapObject constructor - takes ownership of aBmp |
|
401 CBitmapObject::CBitmapObject(CFbTop& aFbTop, CBitwiseBitmap* aBmp): |
|
402 CObject(), |
|
403 iFbTop(&aFbTop), |
|
404 iAddressPointer(aBmp) |
|
405 { |
|
406 __ASSERT_DEBUG(iAddressPointer, User::Invariant()); |
|
407 } |
|
408 |
|
409 /** Second-phase constructor of reference counting objects for bitmaps. |
|
410 Adds the CBitmapObject to the bitmap object container and, if it is not a |
|
411 replacement for a dirty bitmap, assigns a server-wide handle to it and adds |
|
412 it to the server's bitmap index. When a replacement bitmap is attached to |
|
413 the corresponding dirty bitmap with a call to SetCleanBitmap(), then it is |
|
414 assigned the same server-wide handle as the bitmap to be replaced. |
|
415 |
|
416 @param aReplacement If ETrue the bitmap is being created as a replacement |
|
417 for a bitmap being made dirty by a resize or compress operation. |
|
418 @internalComponent |
|
419 */ |
|
420 void CBitmapObject::ConstructL(TBool aReplacement) |
|
421 { |
|
422 iFbTop->iBitmapCon->AddL(this); |
|
423 if (!aReplacement) |
|
424 { |
|
425 iHandle = reinterpret_cast<TInt>(this); |
|
426 while (iFbTop->iBitmapObjectIndex.FindInOrder(this, Compare) != KErrNotFound) |
|
427 ++iHandle; |
|
428 User::LeaveIfError(iFbTop->iBitmapObjectIndex.InsertInOrder(this, Compare)); |
|
429 } |
|
430 } |
|
431 |
|
432 void CleanupBitmapObject(TAny* aPtr) |
|
433 { |
|
434 CBitmapObject* ptr = static_cast<CBitmapObject*>(aPtr); |
|
435 ptr->Close(); |
|
436 } |
|
437 |
|
438 /** Create a reference counting object for a new bitmap. |
|
439 |
|
440 @param aFbTop Reference to the CFbTop singleton. |
|
441 @param aBmp Bitmap to be attached to the new reference counting object. |
|
442 The bitmap must have been pushed on the clean-up stack and it will be |
|
443 popped out of the stack by this function. Ownership will be transferred |
|
444 to the reference counting object. |
|
445 @param aReplacement If ETrue the bitmap is being created as a replacement |
|
446 for a bitmap being made dirty by a resize or compress operation. |
|
447 @internalComponent |
|
448 */ |
|
449 CBitmapObject* CBitmapObject::NewL(CFbTop& aFbTop, CBitwiseBitmap* aBmp, TBool aReplacement) |
|
450 { |
|
451 CBitmapObject* bmpObj = new(ELeave) CBitmapObject(aFbTop, aBmp); |
|
452 CleanupStack::Pop(aBmp); // aBmp is owned now by bmpObj |
|
453 TCleanupItem bitmapObjectCleanupItem(CleanupBitmapObject, bmpObj); |
|
454 CleanupStack::PushL(bitmapObjectCleanupItem); |
|
455 bmpObj->ConstructL(aReplacement); |
|
456 CleanupStack::Pop(bmpObj); |
|
457 return bmpObj; |
|
458 } |
|
459 |
|
460 CBitmapObject::~CBitmapObject() |
|
461 { |
|
462 iFbTop->BackgroundCompression()->RemoveFromCompressionQueue(this); |
|
463 // the associated clean bitmap object cannot possibly be now in the background compression queue |
|
464 if (iHandle) |
|
465 { |
|
466 if (Owner() == NULL) |
|
467 { |
|
468 TInt index = iFbTop->iBitmapObjectIndex.FindInOrder(this, Compare); |
|
469 if (index != KErrNotFound) |
|
470 { |
|
471 if (iCleanBitmap) |
|
472 iFbTop->iBitmapObjectIndex[index] = iCleanBitmap; |
|
473 else |
|
474 iFbTop->iBitmapObjectIndex.Remove(index); |
|
475 } |
|
476 } |
|
477 if (iCleanBitmap != NULL) |
|
478 { |
|
479 iCleanBitmap->SetOwner(NULL); |
|
480 iCleanBitmap->Close(); |
|
481 } |
|
482 } |
|
483 delete iAddressPointer; |
|
484 } |
|
485 |
|
486 void CBitmapObject::SetCleanBitmap(CBitmapObject* aNewBmpObj) |
|
487 { |
|
488 __ASSERT_DEBUG(iHandle, User::Invariant()); |
|
489 __ASSERT_DEBUG(iCleanBitmap == NULL, User::Invariant()); |
|
490 __ASSERT_DEBUG(aNewBmpObj->Owner() == NULL, User::Invariant()); |
|
491 __ASSERT_DEBUG(aNewBmpObj->iHandle == 0, User::Invariant()); |
|
492 __ASSERT_DEBUG(aNewBmpObj->iCleanBitmap == NULL, User::Invariant()); |
|
493 iCleanBitmap = aNewBmpObj; |
|
494 aNewBmpObj->SetOwner(this); |
|
495 aNewBmpObj->iHandle = iHandle; |
|
496 iAddressPointer->iSettings.SetDirtyBitmap(); |
|
497 aNewBmpObj->iAddressPointer->Extra()->iSerialNumber = iAddressPointer->Extra()->iSerialNumber; |
|
498 aNewBmpObj->iAddressPointer->Extra()->iTouchCount = iAddressPointer->Extra()->iTouchCount + 1; |
|
499 } |
|
500 |
|
501 void CBitmapObject::Close() |
|
502 { |
|
503 if (iCleanBitmap != NULL && Owner() != NULL && AccessCount() == 2) |
|
504 { |
|
505 static_cast<CBitmapObject*>(Owner())->iCleanBitmap = iCleanBitmap; |
|
506 iCleanBitmap->SetOwner(Owner()); |
|
507 iHandle = 0; |
|
508 Dec(); |
|
509 } |
|
510 CObject::Close(); |
|
511 } |
|
512 |
|
513 TInt CBitmapObject::Compare(const CBitmapObject& aBmpObj1, const CBitmapObject& aBmpObj2) |
|
514 { |
|
515 return aBmpObj1.iHandle - aBmpObj2.iHandle; |
|
516 } |
|
517 |
|
518 TInt CBitmapObject::Compare(const TInt* aHandle, const CBitmapObject& aBmpObj) |
|
519 { |
|
520 return *aHandle - aBmpObj.iHandle; |
|
521 } |
|
522 |
|
523 // CSharedBitmapObject constructor - takes ownership of aBmp and aKey |
|
524 CSharedBitmapObject::CSharedBitmapObject(CFbTop& aFbTop, CBitwiseBitmap* aBmp, TDesC* aKey): |
|
525 CBitmapObject(aFbTop, aBmp), |
|
526 iKey(aKey), |
|
527 iNext(NULL) |
|
528 { |
|
529 __ASSERT_DEBUG(iKey, User::Invariant()); |
|
530 } |
|
531 |
|
532 /** Second-phase constructor of reference counting objects for bitmaps |
|
533 loaded to share from a file. Adds the CSharedBitmapObject to the bitmap |
|
534 object container, assigns a server-wide handle to it and adds it to the |
|
535 server's bitmap index and to the server's shared bitmap hash map. |
|
536 |
|
537 @param aHash Hash value of the key associated with the bitmap. |
|
538 @internalComponent |
|
539 */ |
|
540 void CSharedBitmapObject::ConstructL(TUint aHash) |
|
541 { |
|
542 CBitmapObject::ConstructL(EFalse); |
|
543 iFbTop->iSharedBitmapObjectHashMap.Insert(*this, aHash); |
|
544 } |
|
545 |
|
546 /** Create a reference counting object for a bitmap loaded to share from a file. |
|
547 |
|
548 @param aFbTop Reference to the CFbTop singleton. |
|
549 @param aBmp Bitmap to be attached to the new reference counting object. |
|
550 The bitmap must have been pushed on the clean-up stack and it will be |
|
551 popped out of the stack by this function. Ownership will be transferred |
|
552 to the reference counting object. |
|
553 @param aKey Key associated with the bitmap. The key must have been pushed on |
|
554 the clean-up stack and it will be popped out of the stack by this function. |
|
555 Ownership will be transferred to the reference counting object. |
|
556 @param aHash Hash value of the key associated with the bitmap. |
|
557 @internalComponent |
|
558 */ |
|
559 CSharedBitmapObject* CSharedBitmapObject::NewL(CFbTop& aFbTop, CBitwiseBitmap* aBmp, TDesC* aKey, TUint aHash) |
|
560 { |
|
561 CSharedBitmapObject* bmpObj = new(ELeave) CSharedBitmapObject(aFbTop, aBmp, aKey); |
|
562 CleanupStack::Pop(2, aKey); // aBmp and aKey are owned now by bmpObj |
|
563 TCleanupItem bitmapObjectCleanupItem(CleanupBitmapObject, bmpObj); |
|
564 CleanupStack::PushL(bitmapObjectCleanupItem); |
|
565 bmpObj->ConstructL(aHash); |
|
566 CleanupStack::Pop(bmpObj); |
|
567 return bmpObj; |
|
568 } |
|
569 |
|
570 CSharedBitmapObject::~CSharedBitmapObject() |
|
571 { |
|
572 iFbTop->iSharedBitmapObjectHashMap.Remove(*this); |
|
573 delete iKey; |
|
574 } |
|
575 |
|
576 // Constructs a single key object from constituent parts that uniquely identify a bitmap |
|
577 HBufC* CSharedBitmapObject::KeyLC(const TDesC& aFileName, TInt aId, const TTime& aModTime) |
|
578 { |
|
579 static const TInt K16BitSizeOfTInt = sizeof(TInt) /sizeof(TUint16); |
|
580 static const TInt K16BitSizeOfTTime = sizeof(TTime)/sizeof(TUint16); |
|
581 |
|
582 HBufC* key = HBufC::NewLC(K16BitSizeOfTInt + K16BitSizeOfTTime + aFileName.Length()); |
|
583 |
|
584 TPtr keyPtr = key->Des(); |
|
585 |
|
586 keyPtr.Append(reinterpret_cast<const TUint16*>(&aId), K16BitSizeOfTInt); |
|
587 keyPtr.Append(reinterpret_cast<const TUint16*>(&aModTime), K16BitSizeOfTTime); |
|
588 keyPtr.Append(aFileName); |
|
589 |
|
590 return key; |
|
591 } |