First public contribution.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include "BitmapCache.h"
18 CBitmapCache::CBitmapCache() : CCacheBase()
23 CBitmapCache::~CBitmapCache()
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.
32 @return KErrNone if no problem occured, otherwise a systemwide error.
34 TInt CBitmapCache::UseL(TInt aHandle)
36 TCacheEntry entry(aHandle);
37 TInt index = iCachedItems.FindInUnsignedKeyOrder(entry);
38 if(index != KErrNotFound)
40 iCachedItems[index].iIsUsed = ETrue;
44 entry.iCachedItem = new (ELeave) CFbsBitmap;
45 TInt err = static_cast<CFbsBitmap*>(entry.iCachedItem)->Duplicate(aHandle);
48 delete entry.iCachedItem;
49 // coverity[extend_simple_error]
53 entry.iIsUsed = ETrue;
54 CleanupStack::PushL(entry.iCachedItem);
55 iCachedItems.InsertInUnsignedKeyOrderL(entry);
56 CleanupStack::Pop(entry.iCachedItem);
61 Returns a bitmap from the cache corresponding to a specific handle.
63 @param aHandle A handle to match against a bitmap in the cache.
64 @return The bitmap that matches the handle provided as a parameter.
66 const CFbsBitmap* CBitmapCache::Resolve(TInt aHandle)
68 const CBase* item = CCacheBase::Resolve(aHandle);
70 return static_cast<const CFbsBitmap*>(item);