Update contrib.
1 // Copyright (c) 2006-2009 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.
19 @internalComponent - Internal Symbian test code
23 #include "tfullscreentext.h"
28 #include <coefontprovider.h>
31 const TInt KIterationsToTest = 25; // number of iterations
33 _LIT(KSemaphore, "SemFullScreenTextSync"); // Name of the global semaphore
34 _LIT(KTestStep0009,"GRAPHICS-UI-BENCH-S60-0009");
36 // Literals for the ini file
37 _LIT(KSectNameOpenGLVGTest, "FullScreenFontTest");
38 _LIT(KKeyNameVertical, "Vertical");
39 _LIT(KKeyNameRightToLeft, "RightToLeft");
42 CTFullScreenText::CTFullScreenText()
44 SetTestStepName(KFullScreenText);
47 void CTFullScreenText::InitUIL(CCoeEnv* aCoeEnv)
49 CFullScreenTextAppUi* appUi = new(ELeave) CFullScreenTextAppUi();
50 CleanupStack::PushL(appUi);
51 appUi->ConstructL(iDrawVertically, iRightToLeft);
52 aCoeEnv->SetAppUi(appUi); // CCoeEnv takes ownership
53 CleanupStack::Pop(appUi);
57 * Generates events to communicate with the control. Each time the control receives an event
58 * it redraws itself. That's necessary because the draw method can't be called directly from
61 void CTFullScreenText::GenerateEventL(TRawEvent::TType aEventType)
64 rawEvent.Set(aEventType, 0, 0);
65 User::LeaveIfError(UserSvr::AddEvent(rawEvent));
68 TVerdict CTFullScreenText::doTestStepPreambleL()
70 // The semaphore has to be created before, otherwise the control can't open it.
71 TESTNOERRORL(iSemaphore.CreateGlobal(KSemaphore, 0));
72 // read values from ini file, if keys not found default values apply
73 iDrawVertically = EFalse;
74 GetBoolFromConfig(KSectNameOpenGLVGTest, KKeyNameVertical, iDrawVertically);
75 iRightToLeft = EFalse;
76 GetBoolFromConfig(KSectNameOpenGLVGTest, KKeyNameRightToLeft, iRightToLeft);
77 // baseclass function needs to be called at the end, otherwise
78 // the values from the ini file would be read after InitUIL()
79 return CTe_ConeStepBase::doTestStepPreambleL();;
82 TVerdict CTFullScreenText::doTestStepPostambleL()
85 // undo the button state change
86 GenerateEventL(TRawEvent::EButton1Up);
87 return CTe_ConeStepBase::doTestStepPostambleL();
90 TVerdict CTFullScreenText::doTestStepL()
92 SetTestStepID(KTestStep0009);
93 TRAPD(err, FullScreenTextL());
96 SetTestStepResult(EAbort);
98 return TestStepResult();
103 GRAPHICS-UI-BENCH-S60-0009
106 Tests how long it takes to draw text on the full screen. The font is requested
110 The control redraws itself everytime it receives a left button down event.
111 A semaphore is used to synchronise cone thread and test step thread. Depending on the
112 ini file the text is drawn from left to right, vertically or normal.
114 @SYMTestExpectedResults
115 Test should pass and log the framerate.
117 void CTFullScreenText::FullScreenTextL()
119 iProfiler->InitResults();
120 for(TInt i = KIterationsToTest; i > 0; --i)
122 GenerateEventL(TRawEvent::EButton1Down);
125 iProfiler->MarkResultSetL();
126 TSize screenSize = CTWindow::GetDisplaySizeInPixels();
127 // todo: Define how to distinguish between tests with different ini files
128 iProfiler->ResultsAnalysisFrameRate(KTestStep0009, 0, 0, 0, KIterationsToTest,
129 screenSize.iWidth * screenSize.iHeight);
133 CGlobalTextControl* CGlobalTextControl::NewLC(const CCoeControl* aParent, TBool aDrawVertically, TBool aRightToLeft)
135 CGlobalTextControl* self;
136 self = new(ELeave) CGlobalTextControl(aDrawVertically, aRightToLeft);
137 CleanupStack::PushL(self);
138 self->ConstructL(aParent);
142 CGlobalTextControl* CGlobalTextControl::NewL(const CCoeControl* aParent, TBool aDrawVertically, TBool aRightToLeft)
144 CGlobalTextControl* self;
145 self = CGlobalTextControl::NewLC(aParent, aDrawVertically, aRightToLeft);
146 CleanupStack::Pop(self);
150 CGlobalTextControl::CGlobalTextControl(TBool aDrawVertically, TBool aRightToLeft) :
151 iDrawVertically(aDrawVertically), iRightToLeft(aRightToLeft),
152 iWsSession(CCoeEnv::Static()->WsSession())
154 iMargin.SetAllValuesTo(EInsetMargin);
157 void CGlobalTextControl::ConstructL(const CCoeControl* aParent)
159 User::LeaveIfError(iSemaphore.OpenGlobal(KSemaphore));
160 iScreen = new(ELeave) CWsScreenDevice(ControlEnv()->WsSession());
161 iScreen->Construct(); // default screen used
164 iBidiText = TBidiText::NewL(KRightToLeftText, EMaximumTextLines, TBidiText::ERightToLeft);
168 iBidiText = TBidiText::NewL(KFullScreenSampleText, EMaximumTextLines, TBidiText::ELeftToRight);
172 SetContainerWindowL(*aParent);
179 SetRect(TRect(TPoint(0,0), CTWindow::GetDisplaySizeInPixels()));
182 CGlobalTextControl::~CGlobalTextControl()
189 void CGlobalTextControl::Draw(const TRect& aRect) const
191 CWindowGc& gc = SystemGc();
192 gc.SetBrushColor(TRgb(EBackgroundColor));
195 // it's recommended to create XCoeTextDrawer on the stack
196 XCoeTextDrawer textDrawer(TextDrawer());
197 textDrawer->SetAlignment(TGulAlignment(EHCenterVCenter));
198 textDrawer->SetTextColor(KRgbBlack);
199 textDrawer->SetMargins(iMargin);
200 textDrawer->SetLineGapInPixels(EGapBetweenTextLines);
201 textDrawer.SetClipRect(aRect);
203 // request the font, could also be done during construction
206 fontSpec.iTypeface.iName = KNokiaSeries60Font;
207 fontSpec.iHeight=EDesiredFontHeight;
208 iScreen->GetNearestFontToDesignHeightInPixels((CFont*&)font, fontSpec);
212 iBidiText->WrapText(aRect.Height() - ESideBearingsAllowance, *font, NULL, EMaximumTextLines);
213 textDrawer.DrawTextVertical(gc, *iBidiText, aRect, *font);
217 // If you don't explicitly set the alignment for RightToLeft text,
218 // DrawText's default is to left align regardless of the text direction.
219 // Setting it explicitly to Left alignment tells DrawText to right align.
222 TGulAlignment alignment(EHLeftVTop);
223 textDrawer.SetAlignment(alignment);
225 iBidiText->WrapText(aRect.Width() - ESideBearingsAllowance, *font, NULL, EMaximumTextLines);
226 textDrawer.DrawText(gc, *iBidiText, aRect, *font);
228 iScreen->ReleaseFont(font); // should be done every time the font is not needed anymore
231 void CGlobalTextControl::HandlePointerEventL(const TPointerEvent& aPointerEvent)
233 // Process event generated from test step, forces a redraw.
234 if(aPointerEvent.iType == TPointerEvent::EButton1Down)
244 CFullScreenTextAppUi::CFullScreenTextAppUi()
249 void CFullScreenTextAppUi::ConstructL(TBool aDrawVertically, TBool aRightToLeft)
251 BaseConstructL(ENoAppResourceFile);
252 iGlobalTextControl = CGlobalTextControl::NewL(NULL, aDrawVertically, aRightToLeft);
253 AddToStackL(iGlobalTextControl);
256 CFullScreenTextAppUi::~CFullScreenTextAppUi()
258 RemoveFromStack(iGlobalTextControl);
259 delete iGlobalTextControl;