os/graphics/fbs/fontandbitmapserver/tfbs/glyphatlastestwrapper.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.
sl@0
     1
// Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
/**
sl@0
    17
 @file
sl@0
    18
 @internalComponent - Internal Symbian test code
sl@0
    19
*/
sl@0
    20
sl@0
    21
#include "glyphatlastestwrapper.h"
sl@0
    22
sl@0
    23
/**
sl@0
    24
Panic function required for glyphatlas.cpp to compile in the test project.
sl@0
    25
*/
sl@0
    26
GLDEF_C void Panic(TFbsPanic aPanic)
sl@0
    27
	{
sl@0
    28
	_LIT(KFBSERVClientPanicCategory,"FBSCLI");
sl@0
    29
	User::Panic(KFBSERVClientPanicCategory,aPanic);
sl@0
    30
	}
sl@0
    31
sl@0
    32
sl@0
    33
/**
sl@0
    34
Glyph Atlas test wrapper constructor.
sl@0
    35
*/
sl@0
    36
CGlyphAtlasTestWrapper::CGlyphAtlasTestWrapper()
sl@0
    37
	{
sl@0
    38
	}
sl@0
    39
sl@0
    40
/**
sl@0
    41
Two-phase constructor.
sl@0
    42
@leave A system wide error code if RSgDriver failed to open.
sl@0
    43
*/
sl@0
    44
void CGlyphAtlasTestWrapper::ConstructL(TInt aMaxCacheSizeInBytes)
sl@0
    45
	{
sl@0
    46
	iAtlas = CGlyphAtlas::NewL(aMaxCacheSizeInBytes);
sl@0
    47
	}
sl@0
    48
sl@0
    49
/**
sl@0
    50
Factory constructor method. Creates a new glyph atlas test wrapper.
sl@0
    51
sl@0
    52
@param aMaxCacheSizeInBytes The size in bytes, to use as the upper limit
sl@0
    53
	for the size of memory used by the glyph images in the atlas. If this
sl@0
    54
	value is KGlyphAtlasNoCacheLimit, then there is no limit and the atlas
sl@0
    55
	will use as much memory as is available in the system.
sl@0
    56
sl@0
    57
@return A pointer to the newly-constructed atlas test wrapper
sl@0
    58
sl@0
    59
@leave KErrNoMemory if there was insufficient memory to create the atlas, 
sl@0
    60
	or a system wide error code if its RSgDriver failed to open.
sl@0
    61
*/
sl@0
    62
CGlyphAtlasTestWrapper* CGlyphAtlasTestWrapper::NewL(TInt aMaxCacheSizeInBytes)
sl@0
    63
    {
sl@0
    64
    CGlyphAtlasTestWrapper* self = CGlyphAtlasTestWrapper::NewLC( aMaxCacheSizeInBytes );
sl@0
    65
    CleanupStack::Pop(); // self;
sl@0
    66
sl@0
    67
    return self;
sl@0
    68
    }
sl@0
    69
sl@0
    70
CGlyphAtlasTestWrapper* CGlyphAtlasTestWrapper::NewLC(TInt aMaxCacheSizeInBytes)
sl@0
    71
    {
sl@0
    72
    CGlyphAtlasTestWrapper* self = new (ELeave) CGlyphAtlasTestWrapper();
sl@0
    73
    CleanupStack::PushL(self);
sl@0
    74
    self->ConstructL(aMaxCacheSizeInBytes);
sl@0
    75
sl@0
    76
    return self;
sl@0
    77
    }
sl@0
    78
sl@0
    79
TInt CGlyphAtlasTestWrapper::GetGlyph(const CBitmapFont& aFont, TUint aGlyphCode, TGlyphImageInfo& aGlyphImageInfo)
sl@0
    80
	{
sl@0
    81
	return iAtlas->GetGlyph(aFont, aGlyphCode, aGlyphImageInfo);
sl@0
    82
	}
sl@0
    83
sl@0
    84
TInt CGlyphAtlasTestWrapper::AddGlyph(const CBitmapFont& aFont, const CGlyphAtlas::TAddGlyphArgs& aArgs, TGlyphImageInfo& aGlyphImageInfo)
sl@0
    85
	{
sl@0
    86
	return iAtlas->AddGlyph(aFont, aArgs, aGlyphImageInfo);
sl@0
    87
	}
sl@0
    88
sl@0
    89
void CGlyphAtlasTestWrapper::FontReleased(const CBitmapFont& aFont)
sl@0
    90
	{
sl@0
    91
	iAtlas->FontReleased(aFont);
sl@0
    92
	}
sl@0
    93
sl@0
    94
/**
sl@0
    95
Returns the current size of the glyph image memory used by the atlas in bytes.
sl@0
    96
*/
sl@0
    97
TInt CGlyphAtlasTestWrapper::SizeInBytes() const
sl@0
    98
	{
sl@0
    99
	return iAtlas->iCacheSizeInBytes;
sl@0
   100
	}
sl@0
   101
sl@0
   102
/**
sl@0
   103
Tests whether the least recently used page contains the given glyph.
sl@0
   104
@param aGlyphCode The glyph code to match.
sl@0
   105
@return ETrue if the lru page contains the given glyph, EFalse if not.
sl@0
   106
*/
sl@0
   107
TBool CGlyphAtlasTestWrapper::LruPageContainsGlyph(TUint aGlyphCode) const
sl@0
   108
	{
sl@0
   109
	CGlyphAtlasPage* page = iAtlas->iLruPageList.Last();
sl@0
   110
	TInt numGlyphsInPage = page->GlyphCount();
sl@0
   111
	TBool glyphFound = EFalse;
sl@0
   112
	for (TInt ii = 0; ii < numGlyphsInPage && !glyphFound; ++ii)
sl@0
   113
		{
sl@0
   114
		glyphFound = (aGlyphCode == page->GlyphCodeAt(ii));
sl@0
   115
		}
sl@0
   116
	return glyphFound;
sl@0
   117
	}
sl@0
   118
sl@0
   119
/**
sl@0
   120
Returns the number of glyphs associated to the given font in the atlas.
sl@0
   121
*/
sl@0
   122
TInt CGlyphAtlasTestWrapper::GlyphCountByFont(const CBitmapFont* aFont)
sl@0
   123
	{
sl@0
   124
	TInt glyphCount = 0;
sl@0
   125
	TDblQueIter<CGlyphAtlasPage> iter(iAtlas->iLruPageList);
sl@0
   126
	CGlyphAtlasPage* page;
sl@0
   127
	while((page=iter++) != NULL)
sl@0
   128
		{
sl@0
   129
		if (&page->FontEntry().Font() == aFont)
sl@0
   130
			{
sl@0
   131
			glyphCount += page->GlyphCount();
sl@0
   132
			}
sl@0
   133
		}
sl@0
   134
	return glyphCount;
sl@0
   135
	}
sl@0
   136
sl@0
   137
/**
sl@0
   138
Returns the number of glyphs in the atlas.
sl@0
   139
*/
sl@0
   140
TInt CGlyphAtlasTestWrapper::GlyphCount()
sl@0
   141
	{
sl@0
   142
	TInt glyphCount = 0;
sl@0
   143
	TDblQueIter<CGlyphAtlasPage> iter(iAtlas->iLruPageList);
sl@0
   144
	CGlyphAtlasPage* page;
sl@0
   145
	while((page=iter++) != NULL)
sl@0
   146
		{
sl@0
   147
		glyphCount += page->GlyphCount();
sl@0
   148
		}
sl@0
   149
	return glyphCount;
sl@0
   150
	}
sl@0
   151
sl@0
   152
/**
sl@0
   153
Returns the number of fonts in the atlas.
sl@0
   154
*/
sl@0
   155
TInt CGlyphAtlasTestWrapper::FontCount() const
sl@0
   156
	{
sl@0
   157
	return iAtlas->iFontEntryArray.Count();
sl@0
   158
	}
sl@0
   159
sl@0
   160
/**
sl@0
   161
Glyph Atlas test wrapper destructor.
sl@0
   162
*/
sl@0
   163
CGlyphAtlasTestWrapper::~CGlyphAtlasTestWrapper()
sl@0
   164
	{
sl@0
   165
	delete iAtlas;
sl@0
   166
	}
sl@0
   167