os/graphics/fbs/fontandbitmapserver/tfbs/glyphatlastestwrapper.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/fbs/fontandbitmapserver/tfbs/glyphatlastestwrapper.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,167 @@
     1.4 +// Copyright (c) 2009-2010 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 +/**
    1.20 + @file
    1.21 + @internalComponent - Internal Symbian test code
    1.22 +*/
    1.23 +
    1.24 +#include "glyphatlastestwrapper.h"
    1.25 +
    1.26 +/**
    1.27 +Panic function required for glyphatlas.cpp to compile in the test project.
    1.28 +*/
    1.29 +GLDEF_C void Panic(TFbsPanic aPanic)
    1.30 +	{
    1.31 +	_LIT(KFBSERVClientPanicCategory,"FBSCLI");
    1.32 +	User::Panic(KFBSERVClientPanicCategory,aPanic);
    1.33 +	}
    1.34 +
    1.35 +
    1.36 +/**
    1.37 +Glyph Atlas test wrapper constructor.
    1.38 +*/
    1.39 +CGlyphAtlasTestWrapper::CGlyphAtlasTestWrapper()
    1.40 +	{
    1.41 +	}
    1.42 +
    1.43 +/**
    1.44 +Two-phase constructor.
    1.45 +@leave A system wide error code if RSgDriver failed to open.
    1.46 +*/
    1.47 +void CGlyphAtlasTestWrapper::ConstructL(TInt aMaxCacheSizeInBytes)
    1.48 +	{
    1.49 +	iAtlas = CGlyphAtlas::NewL(aMaxCacheSizeInBytes);
    1.50 +	}
    1.51 +
    1.52 +/**
    1.53 +Factory constructor method. Creates a new glyph atlas test wrapper.
    1.54 +
    1.55 +@param aMaxCacheSizeInBytes The size in bytes, to use as the upper limit
    1.56 +	for the size of memory used by the glyph images in the atlas. If this
    1.57 +	value is KGlyphAtlasNoCacheLimit, then there is no limit and the atlas
    1.58 +	will use as much memory as is available in the system.
    1.59 +
    1.60 +@return A pointer to the newly-constructed atlas test wrapper
    1.61 +
    1.62 +@leave KErrNoMemory if there was insufficient memory to create the atlas, 
    1.63 +	or a system wide error code if its RSgDriver failed to open.
    1.64 +*/
    1.65 +CGlyphAtlasTestWrapper* CGlyphAtlasTestWrapper::NewL(TInt aMaxCacheSizeInBytes)
    1.66 +    {
    1.67 +    CGlyphAtlasTestWrapper* self = CGlyphAtlasTestWrapper::NewLC( aMaxCacheSizeInBytes );
    1.68 +    CleanupStack::Pop(); // self;
    1.69 +
    1.70 +    return self;
    1.71 +    }
    1.72 +
    1.73 +CGlyphAtlasTestWrapper* CGlyphAtlasTestWrapper::NewLC(TInt aMaxCacheSizeInBytes)
    1.74 +    {
    1.75 +    CGlyphAtlasTestWrapper* self = new (ELeave) CGlyphAtlasTestWrapper();
    1.76 +    CleanupStack::PushL(self);
    1.77 +    self->ConstructL(aMaxCacheSizeInBytes);
    1.78 +
    1.79 +    return self;
    1.80 +    }
    1.81 +
    1.82 +TInt CGlyphAtlasTestWrapper::GetGlyph(const CBitmapFont& aFont, TUint aGlyphCode, TGlyphImageInfo& aGlyphImageInfo)
    1.83 +	{
    1.84 +	return iAtlas->GetGlyph(aFont, aGlyphCode, aGlyphImageInfo);
    1.85 +	}
    1.86 +
    1.87 +TInt CGlyphAtlasTestWrapper::AddGlyph(const CBitmapFont& aFont, const CGlyphAtlas::TAddGlyphArgs& aArgs, TGlyphImageInfo& aGlyphImageInfo)
    1.88 +	{
    1.89 +	return iAtlas->AddGlyph(aFont, aArgs, aGlyphImageInfo);
    1.90 +	}
    1.91 +
    1.92 +void CGlyphAtlasTestWrapper::FontReleased(const CBitmapFont& aFont)
    1.93 +	{
    1.94 +	iAtlas->FontReleased(aFont);
    1.95 +	}
    1.96 +
    1.97 +/**
    1.98 +Returns the current size of the glyph image memory used by the atlas in bytes.
    1.99 +*/
   1.100 +TInt CGlyphAtlasTestWrapper::SizeInBytes() const
   1.101 +	{
   1.102 +	return iAtlas->iCacheSizeInBytes;
   1.103 +	}
   1.104 +
   1.105 +/**
   1.106 +Tests whether the least recently used page contains the given glyph.
   1.107 +@param aGlyphCode The glyph code to match.
   1.108 +@return ETrue if the lru page contains the given glyph, EFalse if not.
   1.109 +*/
   1.110 +TBool CGlyphAtlasTestWrapper::LruPageContainsGlyph(TUint aGlyphCode) const
   1.111 +	{
   1.112 +	CGlyphAtlasPage* page = iAtlas->iLruPageList.Last();
   1.113 +	TInt numGlyphsInPage = page->GlyphCount();
   1.114 +	TBool glyphFound = EFalse;
   1.115 +	for (TInt ii = 0; ii < numGlyphsInPage && !glyphFound; ++ii)
   1.116 +		{
   1.117 +		glyphFound = (aGlyphCode == page->GlyphCodeAt(ii));
   1.118 +		}
   1.119 +	return glyphFound;
   1.120 +	}
   1.121 +
   1.122 +/**
   1.123 +Returns the number of glyphs associated to the given font in the atlas.
   1.124 +*/
   1.125 +TInt CGlyphAtlasTestWrapper::GlyphCountByFont(const CBitmapFont* aFont)
   1.126 +	{
   1.127 +	TInt glyphCount = 0;
   1.128 +	TDblQueIter<CGlyphAtlasPage> iter(iAtlas->iLruPageList);
   1.129 +	CGlyphAtlasPage* page;
   1.130 +	while((page=iter++) != NULL)
   1.131 +		{
   1.132 +		if (&page->FontEntry().Font() == aFont)
   1.133 +			{
   1.134 +			glyphCount += page->GlyphCount();
   1.135 +			}
   1.136 +		}
   1.137 +	return glyphCount;
   1.138 +	}
   1.139 +
   1.140 +/**
   1.141 +Returns the number of glyphs in the atlas.
   1.142 +*/
   1.143 +TInt CGlyphAtlasTestWrapper::GlyphCount()
   1.144 +	{
   1.145 +	TInt glyphCount = 0;
   1.146 +	TDblQueIter<CGlyphAtlasPage> iter(iAtlas->iLruPageList);
   1.147 +	CGlyphAtlasPage* page;
   1.148 +	while((page=iter++) != NULL)
   1.149 +		{
   1.150 +		glyphCount += page->GlyphCount();
   1.151 +		}
   1.152 +	return glyphCount;
   1.153 +	}
   1.154 +
   1.155 +/**
   1.156 +Returns the number of fonts in the atlas.
   1.157 +*/
   1.158 +TInt CGlyphAtlasTestWrapper::FontCount() const
   1.159 +	{
   1.160 +	return iAtlas->iFontEntryArray.Count();
   1.161 +	}
   1.162 +
   1.163 +/**
   1.164 +Glyph Atlas test wrapper destructor.
   1.165 +*/
   1.166 +CGlyphAtlasTestWrapper::~CGlyphAtlasTestWrapper()
   1.167 +	{
   1.168 +	delete iAtlas;
   1.169 +	}
   1.170 +