os/graphics/windowing/windowserver/nga/remotegc/BitmapCache.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
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".
     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 		// coverity[extend_simple_error]
    50 		return err;
    51 		}
    52 	
    53 	entry.iIsUsed = ETrue;		
    54 	CleanupStack::PushL(entry.iCachedItem);
    55 	iCachedItems.InsertInUnsignedKeyOrderL(entry);
    56 	CleanupStack::Pop(entry.iCachedItem);	
    57 	return KErrNone;
    58 	}
    59 
    60 /**
    61 Returns a bitmap from the cache corresponding to a specific handle.
    62 
    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.
    65 */
    66 const CFbsBitmap* CBitmapCache::Resolve(TInt aHandle)
    67 	{	
    68 	const CBase* item = CCacheBase::Resolve(aHandle);
    69 	if(item != NULL)
    70 		return static_cast<const CFbsBitmap*>(item);
    71 	else
    72 		return NULL;
    73 	}
    74 	
    75