|
1 // Copyright (c) 2006-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 "BitmapCache.h" |
|
17 |
|
18 CBitmapCache::CBitmapCache() : CCacheBase() |
|
19 { |
|
20 |
|
21 } |
|
22 |
|
23 CBitmapCache::~CBitmapCache() |
|
24 { |
|
25 |
|
26 } |
|
27 |
|
28 /** |
|
29 Enables the use of a cached bitmap with a specified handle. |
|
30 If no bitmap with this handle is cached, the bitmap is created and cached. |
|
31 |
|
32 @return KErrNone if no problem occured, otherwise a systemwide error. |
|
33 */ |
|
34 TInt CBitmapCache::UseL(TInt aHandle) |
|
35 { |
|
36 TCacheEntry entry(aHandle); |
|
37 TInt index = iCachedItems.FindInUnsignedKeyOrder(entry); |
|
38 if(index != KErrNotFound) |
|
39 { |
|
40 iCachedItems[index].iIsUsed = ETrue; |
|
41 return KErrNone; |
|
42 } |
|
43 |
|
44 entry.iCachedItem = new (ELeave) CFbsBitmap; |
|
45 TInt err = static_cast<CFbsBitmap*>(entry.iCachedItem)->Duplicate(aHandle); |
|
46 if(err) |
|
47 { |
|
48 delete entry.iCachedItem; |
|
49 return err; |
|
50 } |
|
51 |
|
52 entry.iIsUsed = ETrue; |
|
53 CleanupStack::PushL(entry.iCachedItem); |
|
54 iCachedItems.InsertInUnsignedKeyOrderL(entry); |
|
55 CleanupStack::Pop(entry.iCachedItem); |
|
56 return KErrNone; |
|
57 } |
|
58 |
|
59 /** |
|
60 Returns a bitmap from the cache corresponding to a specific handle. |
|
61 |
|
62 @param aHandle A handle to match against a bitmap in the cache. |
|
63 @return The bitmap that matches the handle provided as a parameter. |
|
64 */ |
|
65 const CFbsBitmap* CBitmapCache::Resolve(TInt aHandle) |
|
66 { |
|
67 const CBase* item = CCacheBase::Resolve(aHandle); |
|
68 if(item != NULL) |
|
69 return static_cast<const CFbsBitmap*>(item); |
|
70 else |
|
71 return NULL; |
|
72 } |
|
73 |
|
74 |