1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/windowing/windowserver/nga/remotegc/FontsCache.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,94 @@
1.4 +// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include "FontsCache.h"
1.20 +
1.21 +NONSHARABLE_CLASS(CCachedFont) : public CFbsFont
1.22 + {
1.23 +public:
1.24 + CCachedFont();
1.25 + ~CCachedFont();
1.26 +
1.27 + TInt Duplicate(TInt aHandle); //lint !e1511
1.28 + };
1.29 +
1.30 +CCachedFont::CCachedFont()
1.31 + {
1.32 + }
1.33 +
1.34 +CCachedFont::~CCachedFont()
1.35 + {
1.36 + }
1.37 +
1.38 +TInt CCachedFont::Duplicate(TInt aHandle)
1.39 + {
1.40 + return CFbsFont::Duplicate(aHandle);
1.41 + }
1.42 +
1.43 +CFontsCache::CFontsCache() : CCacheBase()
1.44 + {
1.45 + }
1.46 +
1.47 +CFontsCache::~CFontsCache()
1.48 + {
1.49 + }
1.50 +
1.51 +/**
1.52 +Enables the use of a cached font with a specified handle.
1.53 +If no font with this handle is cached, the font is created and cached.
1.54 +
1.55 +@return KErrNone if no problem occured, otherwise a systemwide error.
1.56 +*/
1.57 +TInt CFontsCache::UseL(TInt aHandle)
1.58 + {
1.59 + TCacheEntry entry(aHandle);
1.60 + TInt index = iCachedItems.FindInUnsignedKeyOrder(entry);
1.61 + if(index != KErrNotFound)
1.62 + {
1.63 + iCachedItems[index].iIsUsed = ETrue;
1.64 + return KErrNone;
1.65 + }
1.66 +
1.67 + entry.iCachedItem = new (ELeave) CCachedFont;
1.68 + TInt err = static_cast<CCachedFont*>(entry.iCachedItem)->Duplicate(aHandle);
1.69 + if(err)
1.70 + {
1.71 + delete entry.iCachedItem;
1.72 + // coverity[extend_simple_error]
1.73 + return err;
1.74 + }
1.75 +
1.76 + entry.iIsUsed = ETrue;
1.77 + CleanupStack::PushL(entry.iCachedItem);
1.78 + iCachedItems.InsertInUnsignedKeyOrderL(entry);
1.79 + CleanupStack::Pop(entry.iCachedItem);
1.80 + return KErrNone;
1.81 + }
1.82 +
1.83 +/**
1.84 +Returns a font from the cache corresponding to a specific handle.
1.85 +
1.86 +@param aHandle A handle to match against a font in the cache.
1.87 +@return The font that matches the handle provided as a parameter.
1.88 +*/
1.89 +const CFont* CFontsCache::Resolve(TInt aHandle)
1.90 + {
1.91 + const CBase* item = CCacheBase::Resolve(aHandle);
1.92 + if(item != NULL)
1.93 + return static_cast<const CCachedFont*>(item);
1.94 + else
1.95 + return NULL;
1.96 + }
1.97 +