os/graphics/fbs/fontandbitmapserver/sfbs/glyphatlas.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/fbs/fontandbitmapserver/sfbs/glyphatlas.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,185 @@
     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 +// Font & Bitmap Server Glyph Atlas
    1.18 +//
    1.19 +
    1.20 +#ifndef GLYPHATLAS_H
    1.21 +#define GLYPHATLAS_H
    1.22 +
    1.23 +#include <e32base.h>
    1.24 +#include <sgresource/sgimage.h>
    1.25 +#include <fbs.h>
    1.26 +#include "UTILS.H"
    1.27 +
    1.28 +class CGlyphAtlasFontEntry;
    1.29 +class CGlyphAtlasPage;
    1.30 +class TGlyphCacheMetrics;
    1.31 +
    1.32 +/**
    1.33 +The Glyph Atlas manages the storing and retrieval of glyphs stored in GPU 
    1.34 +memory as RSgImages.
    1.35 +
    1.36 +CGlyphAtlas is the main class which processes requests to add and retrieve
    1.37 +glyphs. Only one instance of this class will exist throughout the lifetime of 
    1.38 +the Font and Bitmap Server.
    1.39 +@internalComponent
    1.40 +*/
    1.41 +NONSHARABLE_CLASS(CGlyphAtlas) : public CBase
    1.42 +	{
    1.43 +friend class CGlyphAtlasTestWrapper;
    1.44 +public:
    1.45 +	/**
    1.46 +	Structure used to pass information required to create a new glyph so that it can 
    1.47 +	be added to the glyph atlas.
    1.48 +	@internalComponent 
    1.49 +	*/
    1.50 +	class TAddGlyphArgs
    1.51 +		{
    1.52 +	public:
    1.53 +		inline TAddGlyphArgs(const TUint8* aBitmapPointer, TUint aGlyphCode, const TOpenFontCharMetrics& aMetrics)
    1.54 +			: iBitmapPointer(aBitmapPointer), iGlyphCode(aGlyphCode), iMetrics(&aMetrics) {}
    1.55 +	public:
    1.56 +		const TUint8* iBitmapPointer;	/**< The address of the bitmap glyph. No ownership.*/
    1.57 +		TUint iGlyphCode;	/**< The glyph code for the glyph being added. No ownership.*/
    1.58 +		const TOpenFontCharMetrics* iMetrics;	/**< The metrics for the glyph being added. No ownership.*/
    1.59 +		};
    1.60 +
    1.61 +public:
    1.62 +	~CGlyphAtlas();
    1.63 +	static CGlyphAtlas* NewL(TInt aMaxCacheSizeInBytes);
    1.64 +	TInt GetGlyph(const CBitmapFont& aFont, TUint aGlyphCode, TGlyphImageInfo& aGlyphImageInfo);
    1.65 +	TInt AddGlyph(const CBitmapFont& aFont, const TAddGlyphArgs& aArgs, TGlyphImageInfo& aGlyphImageInfo);
    1.66 +	void FontReleased(const CBitmapFont& aFont);
    1.67 +	void MovePageToFront(CGlyphAtlasPage& aPage);
    1.68 +	TBool DeleteLeastRecentlyUsedPage(TBool aAllowMruPageDeletion);
    1.69 +	TInt FontCount() const;
    1.70 +	TInt GlyphCount() const;
    1.71 +	TInt GlyphCount(const CBitmapFont& aFont) const;
    1.72 +	void GlyphCacheMetrics(TInt& aSizeInBytes, TInt& aMaxSizeInBytes, TBool& aGpuCacheSizeLimitIsMax);
    1.73 +	void ReleaseGpuMemory( TInt /*aBytes*/, TInt /*aFlags*/ );
    1.74 +	void InstateGpuMemory( TInt /*aFlags*/ );
    1.75 +	void GetGlyphCacheMetrics( TGlyphCacheMetrics& aGlyphCacheMetrics );
    1.76 +
    1.77 +private:
    1.78 +	CGlyphAtlas(TInt aMaxCacheSizeInBytes);
    1.79 +	void ConstructL();
    1.80 +	CGlyphAtlasFontEntry* CreateFontEntry(const CBitmapFont& aFont);
    1.81 +	CGlyphAtlasFontEntry* FindFontEntry(const CBitmapFont& aFont) const;
    1.82 +	void DeleteFontEntry(CGlyphAtlasFontEntry* aFontEntry);
    1.83 +    void SwitchGpuCacheSizeLimit();
    1.84 +    TBool GpuCacheSizeLimitIsMax() const;
    1.85 +
    1.86 +private:
    1.87 +	class TFontEntryMap
    1.88 +		{
    1.89 +	public:
    1.90 +		inline TFontEntryMap(const CBitmapFont* aFont, CGlyphAtlasFontEntry* aEntry)
    1.91 +				: iFont(aFont),iEntry(aEntry) {}
    1.92 +	public:			
    1.93 +		const CBitmapFont* iFont;
    1.94 +		CGlyphAtlasFontEntry* iEntry;
    1.95 +		};
    1.96 +private:
    1.97 +	RSgDriver iSgDriver;
    1.98 +	TDblQue<CGlyphAtlasPage> iLruPageList; /**< Least-recently used ordered queue (most-recently used at head).*/
    1.99 +	RArray<TFontEntryMap> iFontEntryArray; /**< Array of font entries maintained in unsigned ordered by font pointer.*/
   1.100 +	TUint iMaxCacheSizeInBytes;	/**< Maximum specialised graphics memory the cache should use. If zero, there is no limit.*/
   1.101 +	TInt iMaxCacheSizeHigh;                /**< The high cach-size threshold.*/
   1.102 +	TInt iMaxCacheSizeLow;                 /**< The low cach-size threshold.*/
   1.103 +	TUint iCacheSizeInBytes; 	/**< Actual amount of specialised graphics memory used by the entire atlas.*/
   1.104 +	TBool iGpuCacheSizeLimitIsMax;         /**< Is the cache-size limit set to it's maximum value? */
   1.105 +	};
   1.106 +
   1.107 +
   1.108 +/**
   1.109 +Each font entry manages the storing and retrieval of glyphs belonging to a font.
   1.110 +@internalComponent
   1.111 +*/
   1.112 +NONSHARABLE_CLASS(CGlyphAtlasFontEntry): public CBase
   1.113 +	{
   1.114 +public:
   1.115 +	CGlyphAtlasFontEntry(const CBitmapFont& aFont, CGlyphAtlas& aGlyphAtlas);
   1.116 +	~CGlyphAtlasFontEntry();
   1.117 +	const CBitmapFont& Font() const;
   1.118 +	void DeletePage(CGlyphAtlasPage* aPage);
   1.119 +	TInt GetGlyph(TUint aGlyphCode, TGlyphImageInfo& aGlyphImageInfo);
   1.120 +	TInt AddGlyph(const CGlyphAtlas::TAddGlyphArgs& aArgs, TGlyphImageInfo& aGlyphImageInfo, TInt& aSizeInBytes);
   1.121 +	TInt SizeInBytes() const;
   1.122 +	TBool IsEmpty() const;
   1.123 +	CGlyphAtlas& GlyphAtlas() const;
   1.124 +	TInt GlyphCount() const;
   1.125 +
   1.126 +private:
   1.127 +	// Class that handles association between glyph code and page the 
   1.128 +	// image that glyph code resides on. Used in pointer arrays.
   1.129 +	class TPageMap
   1.130 +		{
   1.131 +	public:
   1.132 +		inline TPageMap(TUint aGlyphCode, CGlyphAtlasPage* aPage)
   1.133 +				: iGlyphCode(aGlyphCode),iPage(aPage) {}
   1.134 +	public:			
   1.135 +		TUint iGlyphCode;
   1.136 +		CGlyphAtlasPage* iPage;
   1.137 +		};
   1.138 +private:
   1.139 +	const CBitmapFont& iFont;	/**< The font which the stored glyph belongs to.*/
   1.140 +	RArray<TPageMap> iPageArray;	/**< Array of pages maintained in unsigned ordered by glyph code.*/
   1.141 +	CGlyphAtlas& iAtlas;		/**< The glyph atlas the font entry belongs to.*/
   1.142 +	TInt iSizeInBytes;			/**< The amount of specialised graphics memory used by all owned pages.*/
   1.143 +	};
   1.144 +
   1.145 +
   1.146 +/**
   1.147 +Each page in the glyph atlas stores one glyph in one RSgImage.
   1.148 +@internalComponent
   1.149 +*/
   1.150 +NONSHARABLE_CLASS(CGlyphAtlasPage): public CBase
   1.151 +	{
   1.152 +friend CGlyphAtlas::CGlyphAtlas(TInt);
   1.153 +public:
   1.154 +	CGlyphAtlasPage(CGlyphAtlasFontEntry& aFontEntry);
   1.155 +	~CGlyphAtlasPage();
   1.156 +	TInt AddGlyph(const CGlyphAtlas::TAddGlyphArgs& aArgs, TGlyphImageInfo& aGlyphImageInfo, TInt& aSizeInBytes);
   1.157 +	void GetGlyph(TUint aGlyphCode, TGlyphImageInfo& aGlyphImageInfo) const;
   1.158 +	TUint GlyphCodeAt(TInt aIndex) const;
   1.159 +	TInt GlyphCount() const;
   1.160 +	CGlyphAtlasFontEntry& FontEntry() const;
   1.161 +	TInt SizeInBytes() const;
   1.162 +	void MoveToFirstInQueue(TDblQue<CGlyphAtlasPage>& aList);
   1.163 +
   1.164 +private:
   1.165 +	TDblQueLink iLink;
   1.166 +	// Data for the stored glyph
   1.167 +	CGlyphAtlasFontEntry& iFontEntry;	/**< The font entry asssociated with the page.*/
   1.168 +	RSgImage iGlyphImage;		/**< The image which contains the stored glyph.*/
   1.169 +	TInt16 iPosX;				/**< The x-coord of the position of the stored glyph within the image.*/
   1.170 +	TInt16 iPosY;				/**< The y-coord of the position of the stored glyph within the image.*/
   1.171 +	TOpenFontCharMetrics iMetrics;	/**< The character metrics for the stored glyph.*/
   1.172 +	TUint iGlyphCode;			/**< The glyph code for the stored glyph.*/
   1.173 +	TInt iSizeInBytes;			/**< The amount of specialised graphics memory used by this page.*/
   1.174 +	TInt iNumGlyphs;			/**< The number of glyphs contained in the page.*/
   1.175 +	};
   1.176 +
   1.177 +
   1.178 +// If no limit to the size of the glyph atlas cache is desired, this
   1.179 +// constant must be passed to CGlyphCache::NewL()
   1.180 +// In this case the cache lower maximum limit, deployed in response to GooM,
   1.181 +// will be set to KGlyphAtlasLowMemCacheLimitDefault
   1.182 +const TInt KGlyphAtlasNoCacheLimit = 0;
   1.183 +const TInt KGlyphAtlasLowMemCacheLimitDivisor = 2;
   1.184 +const TInt KGlyphAtlasLowMemCacheLimitDefault = 0x40000;
   1.185 +
   1.186 +
   1.187 +#endif // GLYPHATLAS_H
   1.188 +