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