1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicstest/uibench/s60/src/tests_fonts/tfullscreentext.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,260 @@
1.4 + // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 + // All rights reserved.
1.6 + // This component and the accompanying materials are made available
1.7 + // under the terms of "Eclipse Public License v1.0"
1.8 + // which accompanies this distribution, and is available
1.9 + // at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 + //
1.11 + // Initial Contributors:
1.12 + // Nokia Corporation - initial contribution.
1.13 + //
1.14 + // Contributors:
1.15 + //
1.16 + // Description:
1.17 + //
1.18 +
1.19 +/**
1.20 + @file
1.21 + @test
1.22 + @internalComponent - Internal Symbian test code
1.23 +*/
1.24 +
1.25 +
1.26 +#include "tfullscreentext.h"
1.27 +#include "fontdefs.h"
1.28 +#include "twindow.h"
1.29 +
1.30 +#include <w32std.h>
1.31 +#include <coefontprovider.h>
1.32 +
1.33 +
1.34 +const TInt KIterationsToTest = 25; // number of iterations
1.35 +
1.36 +_LIT(KSemaphore, "SemFullScreenTextSync"); // Name of the global semaphore
1.37 +_LIT(KTestStep0009,"GRAPHICS-UI-BENCH-S60-0009");
1.38 +
1.39 +// Literals for the ini file
1.40 +_LIT(KSectNameOpenGLVGTest, "FullScreenFontTest");
1.41 +_LIT(KKeyNameVertical, "Vertical");
1.42 +_LIT(KKeyNameRightToLeft, "RightToLeft");
1.43 +
1.44 +
1.45 +CTFullScreenText::CTFullScreenText()
1.46 + {
1.47 + SetTestStepName(KFullScreenText);
1.48 + }
1.49 +
1.50 +void CTFullScreenText::InitUIL(CCoeEnv* aCoeEnv)
1.51 + {
1.52 + CFullScreenTextAppUi* appUi = new(ELeave) CFullScreenTextAppUi();
1.53 + CleanupStack::PushL(appUi);
1.54 + appUi->ConstructL(iDrawVertically, iRightToLeft);
1.55 + aCoeEnv->SetAppUi(appUi); // CCoeEnv takes ownership
1.56 + CleanupStack::Pop(appUi);
1.57 + }
1.58 +
1.59 +/**
1.60 + * Generates events to communicate with the control. Each time the control receives an event
1.61 + * it redraws itself. That's necessary because the draw method can't be called directly from
1.62 + * a different thread.
1.63 + */
1.64 +void CTFullScreenText::GenerateEventL(TRawEvent::TType aEventType)
1.65 + {
1.66 + TRawEvent rawEvent;
1.67 + rawEvent.Set(aEventType, 0, 0);
1.68 + User::LeaveIfError(UserSvr::AddEvent(rawEvent));
1.69 + }
1.70 +
1.71 +TVerdict CTFullScreenText::doTestStepPreambleL()
1.72 + {
1.73 + // The semaphore has to be created before, otherwise the control can't open it.
1.74 + TESTNOERRORL(iSemaphore.CreateGlobal(KSemaphore, 0));
1.75 + // read values from ini file, if keys not found default values apply
1.76 + iDrawVertically = EFalse;
1.77 + GetBoolFromConfig(KSectNameOpenGLVGTest, KKeyNameVertical, iDrawVertically);
1.78 + iRightToLeft = EFalse;
1.79 + GetBoolFromConfig(KSectNameOpenGLVGTest, KKeyNameRightToLeft, iRightToLeft);
1.80 + // baseclass function needs to be called at the end, otherwise
1.81 + // the values from the ini file would be read after InitUIL()
1.82 + return CTe_ConeStepBase::doTestStepPreambleL();;
1.83 + }
1.84 +
1.85 +TVerdict CTFullScreenText::doTestStepPostambleL()
1.86 + {
1.87 + iSemaphore.Close();
1.88 + // undo the button state change
1.89 + GenerateEventL(TRawEvent::EButton1Up);
1.90 + return CTe_ConeStepBase::doTestStepPostambleL();
1.91 + }
1.92 +
1.93 +TVerdict CTFullScreenText::doTestStepL()
1.94 + {
1.95 + SetTestStepID(KTestStep0009);
1.96 + TRAPD(err, FullScreenTextL());
1.97 + if (err != KErrNone)
1.98 + {
1.99 + SetTestStepResult(EAbort);
1.100 + }
1.101 + return TestStepResult();
1.102 + }
1.103 +
1.104 +/**
1.105 +@SYMTestCaseID
1.106 +GRAPHICS-UI-BENCH-S60-0009
1.107 +
1.108 +@SYMTestCaseDesc
1.109 +Tests how long it takes to draw text on the full screen. The font is requested
1.110 +for every redraw.
1.111 +
1.112 +@SYMTestActions
1.113 +The control redraws itself everytime it receives a left button down event.
1.114 +A semaphore is used to synchronise cone thread and test step thread. Depending on the
1.115 +ini file the text is drawn from left to right, vertically or normal.
1.116 +
1.117 +@SYMTestExpectedResults
1.118 +Test should pass and log the framerate.
1.119 +*/
1.120 +void CTFullScreenText::FullScreenTextL()
1.121 + {
1.122 + iProfiler->InitResults();
1.123 + for(TInt i = KIterationsToTest; i > 0; --i)
1.124 + {
1.125 + GenerateEventL(TRawEvent::EButton1Down);
1.126 + iSemaphore.Wait();
1.127 + }
1.128 + iProfiler->MarkResultSetL();
1.129 + TSize screenSize = CTWindow::GetDisplaySizeInPixels();
1.130 + // todo: Define how to distinguish between tests with different ini files
1.131 + iProfiler->ResultsAnalysisFrameRate(KTestStep0009, 0, 0, 0, KIterationsToTest,
1.132 + screenSize.iWidth * screenSize.iHeight);
1.133 + }
1.134 +
1.135 +
1.136 +CGlobalTextControl* CGlobalTextControl::NewLC(const CCoeControl* aParent, TBool aDrawVertically, TBool aRightToLeft)
1.137 + {
1.138 + CGlobalTextControl* self;
1.139 + self = new(ELeave) CGlobalTextControl(aDrawVertically, aRightToLeft);
1.140 + CleanupStack::PushL(self);
1.141 + self->ConstructL(aParent);
1.142 + return self;
1.143 + }
1.144 +
1.145 +CGlobalTextControl* CGlobalTextControl::NewL(const CCoeControl* aParent, TBool aDrawVertically, TBool aRightToLeft)
1.146 + {
1.147 + CGlobalTextControl* self;
1.148 + self = CGlobalTextControl::NewLC(aParent, aDrawVertically, aRightToLeft);
1.149 + CleanupStack::Pop(self);
1.150 + return self;
1.151 + }
1.152 +
1.153 +CGlobalTextControl::CGlobalTextControl(TBool aDrawVertically, TBool aRightToLeft) :
1.154 + iDrawVertically(aDrawVertically), iRightToLeft(aRightToLeft),
1.155 + iWsSession(CCoeEnv::Static()->WsSession())
1.156 + {
1.157 + iMargin.SetAllValuesTo(EInsetMargin);
1.158 + }
1.159 +
1.160 +void CGlobalTextControl::ConstructL(const CCoeControl* aParent)
1.161 + {
1.162 + User::LeaveIfError(iSemaphore.OpenGlobal(KSemaphore));
1.163 + iScreen = new(ELeave) CWsScreenDevice(ControlEnv()->WsSession());
1.164 + iScreen->Construct(); // default screen used
1.165 + if (iRightToLeft)
1.166 + {
1.167 + iBidiText = TBidiText::NewL(KRightToLeftText, EMaximumTextLines, TBidiText::ERightToLeft);
1.168 + }
1.169 + else
1.170 + {
1.171 + iBidiText = TBidiText::NewL(KFullScreenSampleText, EMaximumTextLines, TBidiText::ELeftToRight);
1.172 + }
1.173 + if (aParent)
1.174 + {
1.175 + SetContainerWindowL(*aParent);
1.176 + }
1.177 + else
1.178 + {
1.179 + CreateWindowL();
1.180 + ActivateL();
1.181 + }
1.182 + SetRect(TRect(TPoint(0,0), CTWindow::GetDisplaySizeInPixels()));
1.183 + }
1.184 +
1.185 +CGlobalTextControl::~CGlobalTextControl()
1.186 + {
1.187 + delete iBidiText;
1.188 + delete iScreen;
1.189 + iSemaphore.Close();
1.190 + }
1.191 +
1.192 +void CGlobalTextControl::Draw(const TRect& aRect) const
1.193 + {
1.194 + CWindowGc& gc = SystemGc();
1.195 + gc.SetBrushColor(TRgb(EBackgroundColor));
1.196 + gc.Clear(Rect());
1.197 +
1.198 + // it's recommended to create XCoeTextDrawer on the stack
1.199 + XCoeTextDrawer textDrawer(TextDrawer());
1.200 + textDrawer->SetAlignment(TGulAlignment(EHCenterVCenter));
1.201 + textDrawer->SetTextColor(KRgbBlack);
1.202 + textDrawer->SetMargins(iMargin);
1.203 + textDrawer->SetLineGapInPixels(EGapBetweenTextLines);
1.204 + textDrawer.SetClipRect(aRect);
1.205 +
1.206 + // request the font, could also be done during construction
1.207 + CFont* font;
1.208 + TFontSpec fontSpec;
1.209 + fontSpec.iTypeface.iName = KNokiaSeries60Font;
1.210 + fontSpec.iHeight=EDesiredFontHeight;
1.211 + iScreen->GetNearestFontToDesignHeightInPixels((CFont*&)font, fontSpec);
1.212 +
1.213 + if (iDrawVertically)
1.214 + {
1.215 + iBidiText->WrapText(aRect.Height() - ESideBearingsAllowance, *font, NULL, EMaximumTextLines);
1.216 + textDrawer.DrawTextVertical(gc, *iBidiText, aRect, *font);
1.217 + }
1.218 + else
1.219 + {
1.220 + // If you don't explicitly set the alignment for RightToLeft text,
1.221 + // DrawText's default is to left align regardless of the text direction.
1.222 + // Setting it explicitly to Left alignment tells DrawText to right align.
1.223 + if (iRightToLeft)
1.224 + {
1.225 + TGulAlignment alignment(EHLeftVTop);
1.226 + textDrawer.SetAlignment(alignment);
1.227 + }
1.228 + iBidiText->WrapText(aRect.Width() - ESideBearingsAllowance, *font, NULL, EMaximumTextLines);
1.229 + textDrawer.DrawText(gc, *iBidiText, aRect, *font);
1.230 + }
1.231 + iScreen->ReleaseFont(font); // should be done every time the font is not needed anymore
1.232 + }
1.233 +
1.234 +void CGlobalTextControl::HandlePointerEventL(const TPointerEvent& aPointerEvent)
1.235 + {
1.236 + // Process event generated from test step, forces a redraw.
1.237 + if(aPointerEvent.iType == TPointerEvent::EButton1Down)
1.238 + {
1.239 + DrawNow();
1.240 + iWsSession.Flush();
1.241 + iWsSession.Finish();
1.242 + iSemaphore.Signal();
1.243 + }
1.244 + }
1.245 +
1.246 +
1.247 +CFullScreenTextAppUi::CFullScreenTextAppUi()
1.248 + {
1.249 + // empty
1.250 + }
1.251 +
1.252 +void CFullScreenTextAppUi::ConstructL(TBool aDrawVertically, TBool aRightToLeft)
1.253 + {
1.254 + BaseConstructL(ENoAppResourceFile);
1.255 + iGlobalTextControl = CGlobalTextControl::NewL(NULL, aDrawVertically, aRightToLeft);
1.256 + AddToStackL(iGlobalTextControl);
1.257 + }
1.258 +
1.259 +CFullScreenTextAppUi::~CFullScreenTextAppUi()
1.260 + {
1.261 + RemoveFromStack(iGlobalTextControl);
1.262 + delete iGlobalTextControl;
1.263 + }