sl@0: // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @test sl@0: @internalComponent - Internal Symbian test code sl@0: */ sl@0: sl@0: sl@0: #include "tfullscreentext.h" sl@0: #include "fontdefs.h" sl@0: #include "twindow.h" sl@0: sl@0: #include sl@0: #include sl@0: sl@0: sl@0: const TInt KIterationsToTest = 25; // number of iterations sl@0: sl@0: _LIT(KSemaphore, "SemFullScreenTextSync"); // Name of the global semaphore sl@0: _LIT(KTestStep0009,"GRAPHICS-UI-BENCH-S60-0009"); sl@0: sl@0: // Literals for the ini file sl@0: _LIT(KSectNameOpenGLVGTest, "FullScreenFontTest"); sl@0: _LIT(KKeyNameVertical, "Vertical"); sl@0: _LIT(KKeyNameRightToLeft, "RightToLeft"); sl@0: sl@0: sl@0: CTFullScreenText::CTFullScreenText() sl@0: { sl@0: SetTestStepName(KFullScreenText); sl@0: } sl@0: sl@0: void CTFullScreenText::InitUIL(CCoeEnv* aCoeEnv) sl@0: { sl@0: CFullScreenTextAppUi* appUi = new(ELeave) CFullScreenTextAppUi(); sl@0: CleanupStack::PushL(appUi); sl@0: appUi->ConstructL(iDrawVertically, iRightToLeft); sl@0: aCoeEnv->SetAppUi(appUi); // CCoeEnv takes ownership sl@0: CleanupStack::Pop(appUi); sl@0: } sl@0: sl@0: /** sl@0: * Generates events to communicate with the control. Each time the control receives an event sl@0: * it redraws itself. That's necessary because the draw method can't be called directly from sl@0: * a different thread. sl@0: */ sl@0: void CTFullScreenText::GenerateEventL(TRawEvent::TType aEventType) sl@0: { sl@0: TRawEvent rawEvent; sl@0: rawEvent.Set(aEventType, 0, 0); sl@0: User::LeaveIfError(UserSvr::AddEvent(rawEvent)); sl@0: } sl@0: sl@0: TVerdict CTFullScreenText::doTestStepPreambleL() sl@0: { sl@0: // The semaphore has to be created before, otherwise the control can't open it. sl@0: TESTNOERRORL(iSemaphore.CreateGlobal(KSemaphore, 0)); sl@0: // read values from ini file, if keys not found default values apply sl@0: iDrawVertically = EFalse; sl@0: GetBoolFromConfig(KSectNameOpenGLVGTest, KKeyNameVertical, iDrawVertically); sl@0: iRightToLeft = EFalse; sl@0: GetBoolFromConfig(KSectNameOpenGLVGTest, KKeyNameRightToLeft, iRightToLeft); sl@0: // baseclass function needs to be called at the end, otherwise sl@0: // the values from the ini file would be read after InitUIL() sl@0: return CTe_ConeStepBase::doTestStepPreambleL();; sl@0: } sl@0: sl@0: TVerdict CTFullScreenText::doTestStepPostambleL() sl@0: { sl@0: iSemaphore.Close(); sl@0: // undo the button state change sl@0: GenerateEventL(TRawEvent::EButton1Up); sl@0: return CTe_ConeStepBase::doTestStepPostambleL(); sl@0: } sl@0: sl@0: TVerdict CTFullScreenText::doTestStepL() sl@0: { sl@0: SetTestStepID(KTestStep0009); sl@0: TRAPD(err, FullScreenTextL()); sl@0: if (err != KErrNone) sl@0: { sl@0: SetTestStepResult(EAbort); sl@0: } sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID sl@0: GRAPHICS-UI-BENCH-S60-0009 sl@0: sl@0: @SYMTestCaseDesc sl@0: Tests how long it takes to draw text on the full screen. The font is requested sl@0: for every redraw. sl@0: sl@0: @SYMTestActions sl@0: The control redraws itself everytime it receives a left button down event. sl@0: A semaphore is used to synchronise cone thread and test step thread. Depending on the sl@0: ini file the text is drawn from left to right, vertically or normal. sl@0: sl@0: @SYMTestExpectedResults sl@0: Test should pass and log the framerate. sl@0: */ sl@0: void CTFullScreenText::FullScreenTextL() sl@0: { sl@0: iProfiler->InitResults(); sl@0: for(TInt i = KIterationsToTest; i > 0; --i) sl@0: { sl@0: GenerateEventL(TRawEvent::EButton1Down); sl@0: iSemaphore.Wait(); sl@0: } sl@0: iProfiler->MarkResultSetL(); sl@0: TSize screenSize = CTWindow::GetDisplaySizeInPixels(); sl@0: // todo: Define how to distinguish between tests with different ini files sl@0: iProfiler->ResultsAnalysisFrameRate(KTestStep0009, 0, 0, 0, KIterationsToTest, sl@0: screenSize.iWidth * screenSize.iHeight); sl@0: } sl@0: sl@0: sl@0: CGlobalTextControl* CGlobalTextControl::NewLC(const CCoeControl* aParent, TBool aDrawVertically, TBool aRightToLeft) sl@0: { sl@0: CGlobalTextControl* self; sl@0: self = new(ELeave) CGlobalTextControl(aDrawVertically, aRightToLeft); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aParent); sl@0: return self; sl@0: } sl@0: sl@0: CGlobalTextControl* CGlobalTextControl::NewL(const CCoeControl* aParent, TBool aDrawVertically, TBool aRightToLeft) sl@0: { sl@0: CGlobalTextControl* self; sl@0: self = CGlobalTextControl::NewLC(aParent, aDrawVertically, aRightToLeft); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CGlobalTextControl::CGlobalTextControl(TBool aDrawVertically, TBool aRightToLeft) : sl@0: iDrawVertically(aDrawVertically), iRightToLeft(aRightToLeft), sl@0: iWsSession(CCoeEnv::Static()->WsSession()) sl@0: { sl@0: iMargin.SetAllValuesTo(EInsetMargin); sl@0: } sl@0: sl@0: void CGlobalTextControl::ConstructL(const CCoeControl* aParent) sl@0: { sl@0: User::LeaveIfError(iSemaphore.OpenGlobal(KSemaphore)); sl@0: iScreen = new(ELeave) CWsScreenDevice(ControlEnv()->WsSession()); sl@0: iScreen->Construct(); // default screen used sl@0: if (iRightToLeft) sl@0: { sl@0: iBidiText = TBidiText::NewL(KRightToLeftText, EMaximumTextLines, TBidiText::ERightToLeft); sl@0: } sl@0: else sl@0: { sl@0: iBidiText = TBidiText::NewL(KFullScreenSampleText, EMaximumTextLines, TBidiText::ELeftToRight); sl@0: } sl@0: if (aParent) sl@0: { sl@0: SetContainerWindowL(*aParent); sl@0: } sl@0: else sl@0: { sl@0: CreateWindowL(); sl@0: ActivateL(); sl@0: } sl@0: SetRect(TRect(TPoint(0,0), CTWindow::GetDisplaySizeInPixels())); sl@0: } sl@0: sl@0: CGlobalTextControl::~CGlobalTextControl() sl@0: { sl@0: delete iBidiText; sl@0: delete iScreen; sl@0: iSemaphore.Close(); sl@0: } sl@0: sl@0: void CGlobalTextControl::Draw(const TRect& aRect) const sl@0: { sl@0: CWindowGc& gc = SystemGc(); sl@0: gc.SetBrushColor(TRgb(EBackgroundColor)); sl@0: gc.Clear(Rect()); sl@0: sl@0: // it's recommended to create XCoeTextDrawer on the stack sl@0: XCoeTextDrawer textDrawer(TextDrawer()); sl@0: textDrawer->SetAlignment(TGulAlignment(EHCenterVCenter)); sl@0: textDrawer->SetTextColor(KRgbBlack); sl@0: textDrawer->SetMargins(iMargin); sl@0: textDrawer->SetLineGapInPixels(EGapBetweenTextLines); sl@0: textDrawer.SetClipRect(aRect); sl@0: sl@0: // request the font, could also be done during construction sl@0: CFont* font; sl@0: TFontSpec fontSpec; sl@0: fontSpec.iTypeface.iName = KNokiaSeries60Font; sl@0: fontSpec.iHeight=EDesiredFontHeight; sl@0: iScreen->GetNearestFontToDesignHeightInPixels((CFont*&)font, fontSpec); sl@0: sl@0: if (iDrawVertically) sl@0: { sl@0: iBidiText->WrapText(aRect.Height() - ESideBearingsAllowance, *font, NULL, EMaximumTextLines); sl@0: textDrawer.DrawTextVertical(gc, *iBidiText, aRect, *font); sl@0: } sl@0: else sl@0: { sl@0: // If you don't explicitly set the alignment for RightToLeft text, sl@0: // DrawText's default is to left align regardless of the text direction. sl@0: // Setting it explicitly to Left alignment tells DrawText to right align. sl@0: if (iRightToLeft) sl@0: { sl@0: TGulAlignment alignment(EHLeftVTop); sl@0: textDrawer.SetAlignment(alignment); sl@0: } sl@0: iBidiText->WrapText(aRect.Width() - ESideBearingsAllowance, *font, NULL, EMaximumTextLines); sl@0: textDrawer.DrawText(gc, *iBidiText, aRect, *font); sl@0: } sl@0: iScreen->ReleaseFont(font); // should be done every time the font is not needed anymore sl@0: } sl@0: sl@0: void CGlobalTextControl::HandlePointerEventL(const TPointerEvent& aPointerEvent) sl@0: { sl@0: // Process event generated from test step, forces a redraw. sl@0: if(aPointerEvent.iType == TPointerEvent::EButton1Down) sl@0: { sl@0: DrawNow(); sl@0: iWsSession.Flush(); sl@0: iWsSession.Finish(); sl@0: iSemaphore.Signal(); sl@0: } sl@0: } sl@0: sl@0: sl@0: CFullScreenTextAppUi::CFullScreenTextAppUi() sl@0: { sl@0: // empty sl@0: } sl@0: sl@0: void CFullScreenTextAppUi::ConstructL(TBool aDrawVertically, TBool aRightToLeft) sl@0: { sl@0: BaseConstructL(ENoAppResourceFile); sl@0: iGlobalTextControl = CGlobalTextControl::NewL(NULL, aDrawVertically, aRightToLeft); sl@0: AddToStackL(iGlobalTextControl); sl@0: } sl@0: sl@0: CFullScreenTextAppUi::~CFullScreenTextAppUi() sl@0: { sl@0: RemoveFromStack(iGlobalTextControl); sl@0: delete iGlobalTextControl; sl@0: }