|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "appiconcache.h" |
|
20 |
|
21 CAppIconCache::~CAppIconCache() |
|
22 { |
|
23 Clear(); |
|
24 } |
|
25 |
|
26 CAppIconCache::CAppIconCache(TInt aCacheLimit) : iCache(32), iCacheLimit(aCacheLimit) |
|
27 { |
|
28 } |
|
29 |
|
30 CAppIconCache* CAppIconCache::NewL(TInt aCacheLimit) |
|
31 { |
|
32 CAppIconCache* self = new (ELeave) CAppIconCache(aCacheLimit); |
|
33 CleanupStack::PushL(self); |
|
34 self->ConstructL(); |
|
35 CleanupStack::Pop(); |
|
36 return self; |
|
37 } |
|
38 |
|
39 |
|
40 void CAppIconCache::ConstructL() |
|
41 { |
|
42 } |
|
43 |
|
44 EXPORT_C CFbsBitmap* CAppIconCache::Find(TInt64 aSerialNumber, TSize aSize) |
|
45 { |
|
46 TRasterizedBitmap rb; |
|
47 for (TInt index = 0; index < iCache.Count(); index++) |
|
48 { |
|
49 if (iCache[index].iBitmapSerial == aSerialNumber && iCache[index].iBitmap->SizeInPixels() == aSize) |
|
50 { |
|
51 // if we found a match, move the entry to the beginning of |
|
52 // the cache |
|
53 rb = iCache[index]; |
|
54 iCache.Remove(index); |
|
55 iCache.Insert(rb, 0); |
|
56 return rb.iBitmap; |
|
57 } |
|
58 } |
|
59 return NULL; |
|
60 } |
|
61 |
|
62 EXPORT_C TInt CAppIconCache::Insert(TRasterizedBitmap& aBitmap) |
|
63 { |
|
64 TSize bitmapsize = aBitmap.iBitmap->SizeInPixels(); |
|
65 // assume 32bpp for the icon |
|
66 TInt bitmapBytes = bitmapsize.iWidth*bitmapsize.iHeight*4; |
|
67 if (bitmapBytes > 128*128*4) |
|
68 { |
|
69 return KErrTooBig; |
|
70 } |
|
71 |
|
72 if (iCache.Count() > iCacheLimit) |
|
73 { |
|
74 // cache limit exceeded, remove |
|
75 // the least recently used entry |
|
76 delete iCache[iCache.Count()-1].iBitmap; |
|
77 iCache.Remove(iCache.Count()-1); |
|
78 } |
|
79 return iCache.Insert(aBitmap, 0); |
|
80 } |
|
81 |
|
82 EXPORT_C void CAppIconCache::Clear() |
|
83 { |
|
84 for (TInt index = 0; index < iCache.Count(); index++) |
|
85 { |
|
86 delete iCache[index].iBitmap; |
|
87 } |
|
88 iCache.Reset(); |
|
89 } |