sl@0: // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include "BitmapCache.h" sl@0: sl@0: CBitmapCache::CBitmapCache() : CCacheBase() sl@0: { sl@0: sl@0: } sl@0: sl@0: CBitmapCache::~CBitmapCache() sl@0: { sl@0: sl@0: } sl@0: sl@0: /** sl@0: Enables the use of a cached bitmap with a specified handle. sl@0: If no bitmap with this handle is cached, the bitmap is created and cached. sl@0: sl@0: @return KErrNone if no problem occured, otherwise a systemwide error. sl@0: */ sl@0: TInt CBitmapCache::UseL(TInt aHandle) sl@0: { sl@0: TCacheEntry entry(aHandle); sl@0: TInt index = iCachedItems.FindInUnsignedKeyOrder(entry); sl@0: if(index != KErrNotFound) sl@0: { sl@0: iCachedItems[index].iIsUsed = ETrue; sl@0: return KErrNone; sl@0: } sl@0: sl@0: entry.iCachedItem = new (ELeave) CFbsBitmap; sl@0: TInt err = static_cast<CFbsBitmap*>(entry.iCachedItem)->Duplicate(aHandle); sl@0: if(err) sl@0: { sl@0: delete entry.iCachedItem; sl@0: return err; sl@0: } sl@0: sl@0: entry.iIsUsed = ETrue; sl@0: CleanupStack::PushL(entry.iCachedItem); sl@0: iCachedItems.InsertInUnsignedKeyOrderL(entry); sl@0: CleanupStack::Pop(entry.iCachedItem); sl@0: return KErrNone; sl@0: } sl@0: sl@0: /** sl@0: Returns a bitmap from the cache corresponding to a specific handle. sl@0: sl@0: @param aHandle A handle to match against a bitmap in the cache. sl@0: @return The bitmap that matches the handle provided as a parameter. sl@0: */ sl@0: const CFbsBitmap* CBitmapCache::Resolve(TInt aHandle) sl@0: { sl@0: const CBase* item = CCacheBase::Resolve(aHandle); sl@0: if(item != NULL) sl@0: return static_cast<const CFbsBitmap*>(item); sl@0: else sl@0: return NULL; sl@0: } sl@0: sl@0: