os/graphics/fbs/fontandbitmapserver/sfbs/glyphatlas.h
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
// Font & Bitmap Server Glyph Atlas
sl@0
    15
//
sl@0
    16
sl@0
    17
#ifndef GLYPHATLAS_H
sl@0
    18
#define GLYPHATLAS_H
sl@0
    19
sl@0
    20
#include <e32base.h>
sl@0
    21
#include <sgresource/sgimage.h>
sl@0
    22
#include <fbs.h>
sl@0
    23
#include "UTILS.H"
sl@0
    24
sl@0
    25
class CGlyphAtlasFontEntry;
sl@0
    26
class CGlyphAtlasPage;
sl@0
    27
class TGlyphCacheMetrics;
sl@0
    28
sl@0
    29
/**
sl@0
    30
The Glyph Atlas manages the storing and retrieval of glyphs stored in GPU 
sl@0
    31
memory as RSgImages.
sl@0
    32
sl@0
    33
CGlyphAtlas is the main class which processes requests to add and retrieve
sl@0
    34
glyphs. Only one instance of this class will exist throughout the lifetime of 
sl@0
    35
the Font and Bitmap Server.
sl@0
    36
@internalComponent
sl@0
    37
*/
sl@0
    38
NONSHARABLE_CLASS(CGlyphAtlas) : public CBase
sl@0
    39
	{
sl@0
    40
friend class CGlyphAtlasTestWrapper;
sl@0
    41
public:
sl@0
    42
	/**
sl@0
    43
	Structure used to pass information required to create a new glyph so that it can 
sl@0
    44
	be added to the glyph atlas.
sl@0
    45
	@internalComponent 
sl@0
    46
	*/
sl@0
    47
	class TAddGlyphArgs
sl@0
    48
		{
sl@0
    49
	public:
sl@0
    50
		inline TAddGlyphArgs(const TUint8* aBitmapPointer, TUint aGlyphCode, const TOpenFontCharMetrics& aMetrics)
sl@0
    51
			: iBitmapPointer(aBitmapPointer), iGlyphCode(aGlyphCode), iMetrics(&aMetrics) {}
sl@0
    52
	public:
sl@0
    53
		const TUint8* iBitmapPointer;	/**< The address of the bitmap glyph. No ownership.*/
sl@0
    54
		TUint iGlyphCode;	/**< The glyph code for the glyph being added. No ownership.*/
sl@0
    55
		const TOpenFontCharMetrics* iMetrics;	/**< The metrics for the glyph being added. No ownership.*/
sl@0
    56
		};
sl@0
    57
sl@0
    58
public:
sl@0
    59
	~CGlyphAtlas();
sl@0
    60
	static CGlyphAtlas* NewL(TInt aMaxCacheSizeInBytes);
sl@0
    61
	TInt GetGlyph(const CBitmapFont& aFont, TUint aGlyphCode, TGlyphImageInfo& aGlyphImageInfo);
sl@0
    62
	TInt AddGlyph(const CBitmapFont& aFont, const TAddGlyphArgs& aArgs, TGlyphImageInfo& aGlyphImageInfo);
sl@0
    63
	void FontReleased(const CBitmapFont& aFont);
sl@0
    64
	void MovePageToFront(CGlyphAtlasPage& aPage);
sl@0
    65
	TBool DeleteLeastRecentlyUsedPage(TBool aAllowMruPageDeletion);
sl@0
    66
	TInt FontCount() const;
sl@0
    67
	TInt GlyphCount() const;
sl@0
    68
	TInt GlyphCount(const CBitmapFont& aFont) const;
sl@0
    69
	void GlyphCacheMetrics(TInt& aSizeInBytes, TInt& aMaxSizeInBytes, TBool& aGpuCacheSizeLimitIsMax);
sl@0
    70
	void ReleaseGpuMemory( TInt /*aBytes*/, TInt /*aFlags*/ );
sl@0
    71
	void InstateGpuMemory( TInt /*aFlags*/ );
sl@0
    72
	void GetGlyphCacheMetrics( TGlyphCacheMetrics& aGlyphCacheMetrics );
sl@0
    73
sl@0
    74
private:
sl@0
    75
	CGlyphAtlas(TInt aMaxCacheSizeInBytes);
sl@0
    76
	void ConstructL();
sl@0
    77
	CGlyphAtlasFontEntry* CreateFontEntry(const CBitmapFont& aFont);
sl@0
    78
	CGlyphAtlasFontEntry* FindFontEntry(const CBitmapFont& aFont) const;
sl@0
    79
	void DeleteFontEntry(CGlyphAtlasFontEntry* aFontEntry);
sl@0
    80
    void SwitchGpuCacheSizeLimit();
sl@0
    81
    TBool GpuCacheSizeLimitIsMax() const;
sl@0
    82
sl@0
    83
private:
sl@0
    84
	class TFontEntryMap
sl@0
    85
		{
sl@0
    86
	public:
sl@0
    87
		inline TFontEntryMap(const CBitmapFont* aFont, CGlyphAtlasFontEntry* aEntry)
sl@0
    88
				: iFont(aFont),iEntry(aEntry) {}
sl@0
    89
	public:			
sl@0
    90
		const CBitmapFont* iFont;
sl@0
    91
		CGlyphAtlasFontEntry* iEntry;
sl@0
    92
		};
sl@0
    93
private:
sl@0
    94
	RSgDriver iSgDriver;
sl@0
    95
	TDblQue<CGlyphAtlasPage> iLruPageList; /**< Least-recently used ordered queue (most-recently used at head).*/
sl@0
    96
	RArray<TFontEntryMap> iFontEntryArray; /**< Array of font entries maintained in unsigned ordered by font pointer.*/
sl@0
    97
	TUint iMaxCacheSizeInBytes;	/**< Maximum specialised graphics memory the cache should use. If zero, there is no limit.*/
sl@0
    98
	TInt iMaxCacheSizeHigh;                /**< The high cach-size threshold.*/
sl@0
    99
	TInt iMaxCacheSizeLow;                 /**< The low cach-size threshold.*/
sl@0
   100
	TUint iCacheSizeInBytes; 	/**< Actual amount of specialised graphics memory used by the entire atlas.*/
sl@0
   101
	TBool iGpuCacheSizeLimitIsMax;         /**< Is the cache-size limit set to it's maximum value? */
sl@0
   102
	};
sl@0
   103
sl@0
   104
sl@0
   105
/**
sl@0
   106
Each font entry manages the storing and retrieval of glyphs belonging to a font.
sl@0
   107
@internalComponent
sl@0
   108
*/
sl@0
   109
NONSHARABLE_CLASS(CGlyphAtlasFontEntry): public CBase
sl@0
   110
	{
sl@0
   111
public:
sl@0
   112
	CGlyphAtlasFontEntry(const CBitmapFont& aFont, CGlyphAtlas& aGlyphAtlas);
sl@0
   113
	~CGlyphAtlasFontEntry();
sl@0
   114
	const CBitmapFont& Font() const;
sl@0
   115
	void DeletePage(CGlyphAtlasPage* aPage);
sl@0
   116
	TInt GetGlyph(TUint aGlyphCode, TGlyphImageInfo& aGlyphImageInfo);
sl@0
   117
	TInt AddGlyph(const CGlyphAtlas::TAddGlyphArgs& aArgs, TGlyphImageInfo& aGlyphImageInfo, TInt& aSizeInBytes);
sl@0
   118
	TInt SizeInBytes() const;
sl@0
   119
	TBool IsEmpty() const;
sl@0
   120
	CGlyphAtlas& GlyphAtlas() const;
sl@0
   121
	TInt GlyphCount() const;
sl@0
   122
sl@0
   123
private:
sl@0
   124
	// Class that handles association between glyph code and page the 
sl@0
   125
	// image that glyph code resides on. Used in pointer arrays.
sl@0
   126
	class TPageMap
sl@0
   127
		{
sl@0
   128
	public:
sl@0
   129
		inline TPageMap(TUint aGlyphCode, CGlyphAtlasPage* aPage)
sl@0
   130
				: iGlyphCode(aGlyphCode),iPage(aPage) {}
sl@0
   131
	public:			
sl@0
   132
		TUint iGlyphCode;
sl@0
   133
		CGlyphAtlasPage* iPage;
sl@0
   134
		};
sl@0
   135
private:
sl@0
   136
	const CBitmapFont& iFont;	/**< The font which the stored glyph belongs to.*/
sl@0
   137
	RArray<TPageMap> iPageArray;	/**< Array of pages maintained in unsigned ordered by glyph code.*/
sl@0
   138
	CGlyphAtlas& iAtlas;		/**< The glyph atlas the font entry belongs to.*/
sl@0
   139
	TInt iSizeInBytes;			/**< The amount of specialised graphics memory used by all owned pages.*/
sl@0
   140
	};
sl@0
   141
sl@0
   142
sl@0
   143
/**
sl@0
   144
Each page in the glyph atlas stores one glyph in one RSgImage.
sl@0
   145
@internalComponent
sl@0
   146
*/
sl@0
   147
NONSHARABLE_CLASS(CGlyphAtlasPage): public CBase
sl@0
   148
	{
sl@0
   149
friend CGlyphAtlas::CGlyphAtlas(TInt);
sl@0
   150
public:
sl@0
   151
	CGlyphAtlasPage(CGlyphAtlasFontEntry& aFontEntry);
sl@0
   152
	~CGlyphAtlasPage();
sl@0
   153
	TInt AddGlyph(const CGlyphAtlas::TAddGlyphArgs& aArgs, TGlyphImageInfo& aGlyphImageInfo, TInt& aSizeInBytes);
sl@0
   154
	void GetGlyph(TUint aGlyphCode, TGlyphImageInfo& aGlyphImageInfo) const;
sl@0
   155
	TUint GlyphCodeAt(TInt aIndex) const;
sl@0
   156
	TInt GlyphCount() const;
sl@0
   157
	CGlyphAtlasFontEntry& FontEntry() const;
sl@0
   158
	TInt SizeInBytes() const;
sl@0
   159
	void MoveToFirstInQueue(TDblQue<CGlyphAtlasPage>& aList);
sl@0
   160
sl@0
   161
private:
sl@0
   162
	TDblQueLink iLink;
sl@0
   163
	// Data for the stored glyph
sl@0
   164
	CGlyphAtlasFontEntry& iFontEntry;	/**< The font entry asssociated with the page.*/
sl@0
   165
	RSgImage iGlyphImage;		/**< The image which contains the stored glyph.*/
sl@0
   166
	TInt16 iPosX;				/**< The x-coord of the position of the stored glyph within the image.*/
sl@0
   167
	TInt16 iPosY;				/**< The y-coord of the position of the stored glyph within the image.*/
sl@0
   168
	TOpenFontCharMetrics iMetrics;	/**< The character metrics for the stored glyph.*/
sl@0
   169
	TUint iGlyphCode;			/**< The glyph code for the stored glyph.*/
sl@0
   170
	TInt iSizeInBytes;			/**< The amount of specialised graphics memory used by this page.*/
sl@0
   171
	TInt iNumGlyphs;			/**< The number of glyphs contained in the page.*/
sl@0
   172
	};
sl@0
   173
sl@0
   174
sl@0
   175
// If no limit to the size of the glyph atlas cache is desired, this
sl@0
   176
// constant must be passed to CGlyphCache::NewL()
sl@0
   177
// In this case the cache lower maximum limit, deployed in response to GooM,
sl@0
   178
// will be set to KGlyphAtlasLowMemCacheLimitDefault
sl@0
   179
const TInt KGlyphAtlasNoCacheLimit = 0;
sl@0
   180
const TInt KGlyphAtlasLowMemCacheLimitDivisor = 2;
sl@0
   181
const TInt KGlyphAtlasLowMemCacheLimitDefault = 0x40000;
sl@0
   182
sl@0
   183
sl@0
   184
#endif // GLYPHATLAS_H
sl@0
   185