Update contrib.
1 // Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Font & Bitmap Server Glyph Atlas
21 #include <sgresource/sgimage.h>
25 class CGlyphAtlasFontEntry;
26 class CGlyphAtlasPage;
27 class TGlyphCacheMetrics;
30 The Glyph Atlas manages the storing and retrieval of glyphs stored in GPU
33 CGlyphAtlas is the main class which processes requests to add and retrieve
34 glyphs. Only one instance of this class will exist throughout the lifetime of
35 the Font and Bitmap Server.
38 NONSHARABLE_CLASS(CGlyphAtlas) : public CBase
40 friend class CGlyphAtlasTestWrapper;
43 Structure used to pass information required to create a new glyph so that it can
44 be added to the glyph atlas.
50 inline TAddGlyphArgs(const TUint8* aBitmapPointer, TUint aGlyphCode, const TOpenFontCharMetrics& aMetrics)
51 : iBitmapPointer(aBitmapPointer), iGlyphCode(aGlyphCode), iMetrics(&aMetrics) {}
53 const TUint8* iBitmapPointer; /**< The address of the bitmap glyph. No ownership.*/
54 TUint iGlyphCode; /**< The glyph code for the glyph being added. No ownership.*/
55 const TOpenFontCharMetrics* iMetrics; /**< The metrics for the glyph being added. No ownership.*/
60 static CGlyphAtlas* NewL(TInt aMaxCacheSizeInBytes);
61 TInt GetGlyph(const CBitmapFont& aFont, TUint aGlyphCode, TGlyphImageInfo& aGlyphImageInfo);
62 TInt AddGlyph(const CBitmapFont& aFont, const TAddGlyphArgs& aArgs, TGlyphImageInfo& aGlyphImageInfo);
63 void FontReleased(const CBitmapFont& aFont);
64 void MovePageToFront(CGlyphAtlasPage& aPage);
65 TBool DeleteLeastRecentlyUsedPage(TBool aAllowMruPageDeletion);
66 TInt FontCount() const;
67 TInt GlyphCount() const;
68 TInt GlyphCount(const CBitmapFont& aFont) const;
69 void GlyphCacheMetrics(TInt& aSizeInBytes, TInt& aMaxSizeInBytes, TBool& aGpuCacheSizeLimitIsMax);
70 void ReleaseGpuMemory( TInt /*aBytes*/, TInt /*aFlags*/ );
71 void InstateGpuMemory( TInt /*aFlags*/ );
72 void GetGlyphCacheMetrics( TGlyphCacheMetrics& aGlyphCacheMetrics );
75 CGlyphAtlas(TInt aMaxCacheSizeInBytes);
77 CGlyphAtlasFontEntry* CreateFontEntry(const CBitmapFont& aFont);
78 CGlyphAtlasFontEntry* FindFontEntry(const CBitmapFont& aFont) const;
79 void DeleteFontEntry(CGlyphAtlasFontEntry* aFontEntry);
80 void SwitchGpuCacheSizeLimit();
81 TBool GpuCacheSizeLimitIsMax() const;
87 inline TFontEntryMap(const CBitmapFont* aFont, CGlyphAtlasFontEntry* aEntry)
88 : iFont(aFont),iEntry(aEntry) {}
90 const CBitmapFont* iFont;
91 CGlyphAtlasFontEntry* iEntry;
95 TDblQue<CGlyphAtlasPage> iLruPageList; /**< Least-recently used ordered queue (most-recently used at head).*/
96 RArray<TFontEntryMap> iFontEntryArray; /**< Array of font entries maintained in unsigned ordered by font pointer.*/
97 TUint iMaxCacheSizeInBytes; /**< Maximum specialised graphics memory the cache should use. If zero, there is no limit.*/
98 TInt iMaxCacheSizeHigh; /**< The high cach-size threshold.*/
99 TInt iMaxCacheSizeLow; /**< The low cach-size threshold.*/
100 TUint iCacheSizeInBytes; /**< Actual amount of specialised graphics memory used by the entire atlas.*/
101 TBool iGpuCacheSizeLimitIsMax; /**< Is the cache-size limit set to it's maximum value? */
106 Each font entry manages the storing and retrieval of glyphs belonging to a font.
109 NONSHARABLE_CLASS(CGlyphAtlasFontEntry): public CBase
112 CGlyphAtlasFontEntry(const CBitmapFont& aFont, CGlyphAtlas& aGlyphAtlas);
113 ~CGlyphAtlasFontEntry();
114 const CBitmapFont& Font() const;
115 void DeletePage(CGlyphAtlasPage* aPage);
116 TInt GetGlyph(TUint aGlyphCode, TGlyphImageInfo& aGlyphImageInfo);
117 TInt AddGlyph(const CGlyphAtlas::TAddGlyphArgs& aArgs, TGlyphImageInfo& aGlyphImageInfo, TInt& aSizeInBytes);
118 TInt SizeInBytes() const;
119 TBool IsEmpty() const;
120 CGlyphAtlas& GlyphAtlas() const;
121 TInt GlyphCount() const;
124 // Class that handles association between glyph code and page the
125 // image that glyph code resides on. Used in pointer arrays.
129 inline TPageMap(TUint aGlyphCode, CGlyphAtlasPage* aPage)
130 : iGlyphCode(aGlyphCode),iPage(aPage) {}
133 CGlyphAtlasPage* iPage;
136 const CBitmapFont& iFont; /**< The font which the stored glyph belongs to.*/
137 RArray<TPageMap> iPageArray; /**< Array of pages maintained in unsigned ordered by glyph code.*/
138 CGlyphAtlas& iAtlas; /**< The glyph atlas the font entry belongs to.*/
139 TInt iSizeInBytes; /**< The amount of specialised graphics memory used by all owned pages.*/
144 Each page in the glyph atlas stores one glyph in one RSgImage.
147 NONSHARABLE_CLASS(CGlyphAtlasPage): public CBase
149 friend CGlyphAtlas::CGlyphAtlas(TInt);
151 CGlyphAtlasPage(CGlyphAtlasFontEntry& aFontEntry);
153 TInt AddGlyph(const CGlyphAtlas::TAddGlyphArgs& aArgs, TGlyphImageInfo& aGlyphImageInfo, TInt& aSizeInBytes);
154 void GetGlyph(TUint aGlyphCode, TGlyphImageInfo& aGlyphImageInfo) const;
155 TUint GlyphCodeAt(TInt aIndex) const;
156 TInt GlyphCount() const;
157 CGlyphAtlasFontEntry& FontEntry() const;
158 TInt SizeInBytes() const;
159 void MoveToFirstInQueue(TDblQue<CGlyphAtlasPage>& aList);
163 // Data for the stored glyph
164 CGlyphAtlasFontEntry& iFontEntry; /**< The font entry asssociated with the page.*/
165 RSgImage iGlyphImage; /**< The image which contains the stored glyph.*/
166 TInt16 iPosX; /**< The x-coord of the position of the stored glyph within the image.*/
167 TInt16 iPosY; /**< The y-coord of the position of the stored glyph within the image.*/
168 TOpenFontCharMetrics iMetrics; /**< The character metrics for the stored glyph.*/
169 TUint iGlyphCode; /**< The glyph code for the stored glyph.*/
170 TInt iSizeInBytes; /**< The amount of specialised graphics memory used by this page.*/
171 TInt iNumGlyphs; /**< The number of glyphs contained in the page.*/
175 // If no limit to the size of the glyph atlas cache is desired, this
176 // constant must be passed to CGlyphCache::NewL()
177 // In this case the cache lower maximum limit, deployed in response to GooM,
178 // will be set to KGlyphAtlasLowMemCacheLimitDefault
179 const TInt KGlyphAtlasNoCacheLimit = 0;
180 const TInt KGlyphAtlasLowMemCacheLimitDivisor = 2;
181 const TInt KGlyphAtlasLowMemCacheLimitDefault = 0x40000;
184 #endif // GLYPHATLAS_H