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