sl@0
|
1 |
// Copyright (c) 2006-2009 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 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
/**
|
sl@0
|
17 |
@file
|
sl@0
|
18 |
@test
|
sl@0
|
19 |
@internalComponent - Internal Symbian test code
|
sl@0
|
20 |
*/
|
sl@0
|
21 |
|
sl@0
|
22 |
|
sl@0
|
23 |
#include "tfullscreentext.h"
|
sl@0
|
24 |
#include "fontdefs.h"
|
sl@0
|
25 |
#include "twindow.h"
|
sl@0
|
26 |
|
sl@0
|
27 |
#include <w32std.h>
|
sl@0
|
28 |
#include <coefontprovider.h>
|
sl@0
|
29 |
|
sl@0
|
30 |
|
sl@0
|
31 |
const TInt KIterationsToTest = 25; // number of iterations
|
sl@0
|
32 |
|
sl@0
|
33 |
_LIT(KSemaphore, "SemFullScreenTextSync"); // Name of the global semaphore
|
sl@0
|
34 |
_LIT(KTestStep0009,"GRAPHICS-UI-BENCH-S60-0009");
|
sl@0
|
35 |
|
sl@0
|
36 |
// Literals for the ini file
|
sl@0
|
37 |
_LIT(KSectNameOpenGLVGTest, "FullScreenFontTest");
|
sl@0
|
38 |
_LIT(KKeyNameVertical, "Vertical");
|
sl@0
|
39 |
_LIT(KKeyNameRightToLeft, "RightToLeft");
|
sl@0
|
40 |
|
sl@0
|
41 |
|
sl@0
|
42 |
CTFullScreenText::CTFullScreenText()
|
sl@0
|
43 |
{
|
sl@0
|
44 |
SetTestStepName(KFullScreenText);
|
sl@0
|
45 |
}
|
sl@0
|
46 |
|
sl@0
|
47 |
void CTFullScreenText::InitUIL(CCoeEnv* aCoeEnv)
|
sl@0
|
48 |
{
|
sl@0
|
49 |
CFullScreenTextAppUi* appUi = new(ELeave) CFullScreenTextAppUi();
|
sl@0
|
50 |
CleanupStack::PushL(appUi);
|
sl@0
|
51 |
appUi->ConstructL(iDrawVertically, iRightToLeft);
|
sl@0
|
52 |
aCoeEnv->SetAppUi(appUi); // CCoeEnv takes ownership
|
sl@0
|
53 |
CleanupStack::Pop(appUi);
|
sl@0
|
54 |
}
|
sl@0
|
55 |
|
sl@0
|
56 |
/**
|
sl@0
|
57 |
* Generates events to communicate with the control. Each time the control receives an event
|
sl@0
|
58 |
* it redraws itself. That's necessary because the draw method can't be called directly from
|
sl@0
|
59 |
* a different thread.
|
sl@0
|
60 |
*/
|
sl@0
|
61 |
void CTFullScreenText::GenerateEventL(TRawEvent::TType aEventType)
|
sl@0
|
62 |
{
|
sl@0
|
63 |
TRawEvent rawEvent;
|
sl@0
|
64 |
rawEvent.Set(aEventType, 0, 0);
|
sl@0
|
65 |
User::LeaveIfError(UserSvr::AddEvent(rawEvent));
|
sl@0
|
66 |
}
|
sl@0
|
67 |
|
sl@0
|
68 |
TVerdict CTFullScreenText::doTestStepPreambleL()
|
sl@0
|
69 |
{
|
sl@0
|
70 |
// The semaphore has to be created before, otherwise the control can't open it.
|
sl@0
|
71 |
TESTNOERRORL(iSemaphore.CreateGlobal(KSemaphore, 0));
|
sl@0
|
72 |
// read values from ini file, if keys not found default values apply
|
sl@0
|
73 |
iDrawVertically = EFalse;
|
sl@0
|
74 |
GetBoolFromConfig(KSectNameOpenGLVGTest, KKeyNameVertical, iDrawVertically);
|
sl@0
|
75 |
iRightToLeft = EFalse;
|
sl@0
|
76 |
GetBoolFromConfig(KSectNameOpenGLVGTest, KKeyNameRightToLeft, iRightToLeft);
|
sl@0
|
77 |
// baseclass function needs to be called at the end, otherwise
|
sl@0
|
78 |
// the values from the ini file would be read after InitUIL()
|
sl@0
|
79 |
return CTe_ConeStepBase::doTestStepPreambleL();;
|
sl@0
|
80 |
}
|
sl@0
|
81 |
|
sl@0
|
82 |
TVerdict CTFullScreenText::doTestStepPostambleL()
|
sl@0
|
83 |
{
|
sl@0
|
84 |
iSemaphore.Close();
|
sl@0
|
85 |
// undo the button state change
|
sl@0
|
86 |
GenerateEventL(TRawEvent::EButton1Up);
|
sl@0
|
87 |
return CTe_ConeStepBase::doTestStepPostambleL();
|
sl@0
|
88 |
}
|
sl@0
|
89 |
|
sl@0
|
90 |
TVerdict CTFullScreenText::doTestStepL()
|
sl@0
|
91 |
{
|
sl@0
|
92 |
SetTestStepID(KTestStep0009);
|
sl@0
|
93 |
TRAPD(err, FullScreenTextL());
|
sl@0
|
94 |
if (err != KErrNone)
|
sl@0
|
95 |
{
|
sl@0
|
96 |
SetTestStepResult(EAbort);
|
sl@0
|
97 |
}
|
sl@0
|
98 |
return TestStepResult();
|
sl@0
|
99 |
}
|
sl@0
|
100 |
|
sl@0
|
101 |
/**
|
sl@0
|
102 |
@SYMTestCaseID
|
sl@0
|
103 |
GRAPHICS-UI-BENCH-S60-0009
|
sl@0
|
104 |
|
sl@0
|
105 |
@SYMTestCaseDesc
|
sl@0
|
106 |
Tests how long it takes to draw text on the full screen. The font is requested
|
sl@0
|
107 |
for every redraw.
|
sl@0
|
108 |
|
sl@0
|
109 |
@SYMTestActions
|
sl@0
|
110 |
The control redraws itself everytime it receives a left button down event.
|
sl@0
|
111 |
A semaphore is used to synchronise cone thread and test step thread. Depending on the
|
sl@0
|
112 |
ini file the text is drawn from left to right, vertically or normal.
|
sl@0
|
113 |
|
sl@0
|
114 |
@SYMTestExpectedResults
|
sl@0
|
115 |
Test should pass and log the framerate.
|
sl@0
|
116 |
*/
|
sl@0
|
117 |
void CTFullScreenText::FullScreenTextL()
|
sl@0
|
118 |
{
|
sl@0
|
119 |
iProfiler->InitResults();
|
sl@0
|
120 |
for(TInt i = KIterationsToTest; i > 0; --i)
|
sl@0
|
121 |
{
|
sl@0
|
122 |
GenerateEventL(TRawEvent::EButton1Down);
|
sl@0
|
123 |
iSemaphore.Wait();
|
sl@0
|
124 |
}
|
sl@0
|
125 |
iProfiler->MarkResultSetL();
|
sl@0
|
126 |
TSize screenSize = CTWindow::GetDisplaySizeInPixels();
|
sl@0
|
127 |
// todo: Define how to distinguish between tests with different ini files
|
sl@0
|
128 |
iProfiler->ResultsAnalysisFrameRate(KTestStep0009, 0, 0, 0, KIterationsToTest,
|
sl@0
|
129 |
screenSize.iWidth * screenSize.iHeight);
|
sl@0
|
130 |
}
|
sl@0
|
131 |
|
sl@0
|
132 |
|
sl@0
|
133 |
CGlobalTextControl* CGlobalTextControl::NewLC(const CCoeControl* aParent, TBool aDrawVertically, TBool aRightToLeft)
|
sl@0
|
134 |
{
|
sl@0
|
135 |
CGlobalTextControl* self;
|
sl@0
|
136 |
self = new(ELeave) CGlobalTextControl(aDrawVertically, aRightToLeft);
|
sl@0
|
137 |
CleanupStack::PushL(self);
|
sl@0
|
138 |
self->ConstructL(aParent);
|
sl@0
|
139 |
return self;
|
sl@0
|
140 |
}
|
sl@0
|
141 |
|
sl@0
|
142 |
CGlobalTextControl* CGlobalTextControl::NewL(const CCoeControl* aParent, TBool aDrawVertically, TBool aRightToLeft)
|
sl@0
|
143 |
{
|
sl@0
|
144 |
CGlobalTextControl* self;
|
sl@0
|
145 |
self = CGlobalTextControl::NewLC(aParent, aDrawVertically, aRightToLeft);
|
sl@0
|
146 |
CleanupStack::Pop(self);
|
sl@0
|
147 |
return self;
|
sl@0
|
148 |
}
|
sl@0
|
149 |
|
sl@0
|
150 |
CGlobalTextControl::CGlobalTextControl(TBool aDrawVertically, TBool aRightToLeft) :
|
sl@0
|
151 |
iDrawVertically(aDrawVertically), iRightToLeft(aRightToLeft),
|
sl@0
|
152 |
iWsSession(CCoeEnv::Static()->WsSession())
|
sl@0
|
153 |
{
|
sl@0
|
154 |
iMargin.SetAllValuesTo(EInsetMargin);
|
sl@0
|
155 |
}
|
sl@0
|
156 |
|
sl@0
|
157 |
void CGlobalTextControl::ConstructL(const CCoeControl* aParent)
|
sl@0
|
158 |
{
|
sl@0
|
159 |
User::LeaveIfError(iSemaphore.OpenGlobal(KSemaphore));
|
sl@0
|
160 |
iScreen = new(ELeave) CWsScreenDevice(ControlEnv()->WsSession());
|
sl@0
|
161 |
iScreen->Construct(); // default screen used
|
sl@0
|
162 |
if (iRightToLeft)
|
sl@0
|
163 |
{
|
sl@0
|
164 |
iBidiText = TBidiText::NewL(KRightToLeftText, EMaximumTextLines, TBidiText::ERightToLeft);
|
sl@0
|
165 |
}
|
sl@0
|
166 |
else
|
sl@0
|
167 |
{
|
sl@0
|
168 |
iBidiText = TBidiText::NewL(KFullScreenSampleText, EMaximumTextLines, TBidiText::ELeftToRight);
|
sl@0
|
169 |
}
|
sl@0
|
170 |
if (aParent)
|
sl@0
|
171 |
{
|
sl@0
|
172 |
SetContainerWindowL(*aParent);
|
sl@0
|
173 |
}
|
sl@0
|
174 |
else
|
sl@0
|
175 |
{
|
sl@0
|
176 |
CreateWindowL();
|
sl@0
|
177 |
ActivateL();
|
sl@0
|
178 |
}
|
sl@0
|
179 |
SetRect(TRect(TPoint(0,0), CTWindow::GetDisplaySizeInPixels()));
|
sl@0
|
180 |
}
|
sl@0
|
181 |
|
sl@0
|
182 |
CGlobalTextControl::~CGlobalTextControl()
|
sl@0
|
183 |
{
|
sl@0
|
184 |
delete iBidiText;
|
sl@0
|
185 |
delete iScreen;
|
sl@0
|
186 |
iSemaphore.Close();
|
sl@0
|
187 |
}
|
sl@0
|
188 |
|
sl@0
|
189 |
void CGlobalTextControl::Draw(const TRect& aRect) const
|
sl@0
|
190 |
{
|
sl@0
|
191 |
CWindowGc& gc = SystemGc();
|
sl@0
|
192 |
gc.SetBrushColor(TRgb(EBackgroundColor));
|
sl@0
|
193 |
gc.Clear(Rect());
|
sl@0
|
194 |
|
sl@0
|
195 |
// it's recommended to create XCoeTextDrawer on the stack
|
sl@0
|
196 |
XCoeTextDrawer textDrawer(TextDrawer());
|
sl@0
|
197 |
textDrawer->SetAlignment(TGulAlignment(EHCenterVCenter));
|
sl@0
|
198 |
textDrawer->SetTextColor(KRgbBlack);
|
sl@0
|
199 |
textDrawer->SetMargins(iMargin);
|
sl@0
|
200 |
textDrawer->SetLineGapInPixels(EGapBetweenTextLines);
|
sl@0
|
201 |
textDrawer.SetClipRect(aRect);
|
sl@0
|
202 |
|
sl@0
|
203 |
// request the font, could also be done during construction
|
sl@0
|
204 |
CFont* font;
|
sl@0
|
205 |
TFontSpec fontSpec;
|
sl@0
|
206 |
fontSpec.iTypeface.iName = KNokiaSeries60Font;
|
sl@0
|
207 |
fontSpec.iHeight=EDesiredFontHeight;
|
sl@0
|
208 |
iScreen->GetNearestFontToDesignHeightInPixels((CFont*&)font, fontSpec);
|
sl@0
|
209 |
|
sl@0
|
210 |
if (iDrawVertically)
|
sl@0
|
211 |
{
|
sl@0
|
212 |
iBidiText->WrapText(aRect.Height() - ESideBearingsAllowance, *font, NULL, EMaximumTextLines);
|
sl@0
|
213 |
textDrawer.DrawTextVertical(gc, *iBidiText, aRect, *font);
|
sl@0
|
214 |
}
|
sl@0
|
215 |
else
|
sl@0
|
216 |
{
|
sl@0
|
217 |
// If you don't explicitly set the alignment for RightToLeft text,
|
sl@0
|
218 |
// DrawText's default is to left align regardless of the text direction.
|
sl@0
|
219 |
// Setting it explicitly to Left alignment tells DrawText to right align.
|
sl@0
|
220 |
if (iRightToLeft)
|
sl@0
|
221 |
{
|
sl@0
|
222 |
TGulAlignment alignment(EHLeftVTop);
|
sl@0
|
223 |
textDrawer.SetAlignment(alignment);
|
sl@0
|
224 |
}
|
sl@0
|
225 |
iBidiText->WrapText(aRect.Width() - ESideBearingsAllowance, *font, NULL, EMaximumTextLines);
|
sl@0
|
226 |
textDrawer.DrawText(gc, *iBidiText, aRect, *font);
|
sl@0
|
227 |
}
|
sl@0
|
228 |
iScreen->ReleaseFont(font); // should be done every time the font is not needed anymore
|
sl@0
|
229 |
}
|
sl@0
|
230 |
|
sl@0
|
231 |
void CGlobalTextControl::HandlePointerEventL(const TPointerEvent& aPointerEvent)
|
sl@0
|
232 |
{
|
sl@0
|
233 |
// Process event generated from test step, forces a redraw.
|
sl@0
|
234 |
if(aPointerEvent.iType == TPointerEvent::EButton1Down)
|
sl@0
|
235 |
{
|
sl@0
|
236 |
DrawNow();
|
sl@0
|
237 |
iWsSession.Flush();
|
sl@0
|
238 |
iWsSession.Finish();
|
sl@0
|
239 |
iSemaphore.Signal();
|
sl@0
|
240 |
}
|
sl@0
|
241 |
}
|
sl@0
|
242 |
|
sl@0
|
243 |
|
sl@0
|
244 |
CFullScreenTextAppUi::CFullScreenTextAppUi()
|
sl@0
|
245 |
{
|
sl@0
|
246 |
// empty
|
sl@0
|
247 |
}
|
sl@0
|
248 |
|
sl@0
|
249 |
void CFullScreenTextAppUi::ConstructL(TBool aDrawVertically, TBool aRightToLeft)
|
sl@0
|
250 |
{
|
sl@0
|
251 |
BaseConstructL(ENoAppResourceFile);
|
sl@0
|
252 |
iGlobalTextControl = CGlobalTextControl::NewL(NULL, aDrawVertically, aRightToLeft);
|
sl@0
|
253 |
AddToStackL(iGlobalTextControl);
|
sl@0
|
254 |
}
|
sl@0
|
255 |
|
sl@0
|
256 |
CFullScreenTextAppUi::~CFullScreenTextAppUi()
|
sl@0
|
257 |
{
|
sl@0
|
258 |
RemoveFromStack(iGlobalTextControl);
|
sl@0
|
259 |
delete iGlobalTextControl;
|
sl@0
|
260 |
}
|