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