os/graphics/graphicstest/uibench/s60/src/tests_fonts/tfullscreentext.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
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".
     7  //
     8  // Initial Contributors:
     9  // Nokia Corporation - initial contribution.
    10  //
    11  // Contributors:
    12  //
    13  // Description:
    14  //
    15 
    16 /**
    17  @file
    18  @test
    19  @internalComponent - Internal Symbian test code 
    20 */
    21 
    22 
    23 #include "tfullscreentext.h"
    24 #include "fontdefs.h"
    25 #include "twindow.h"
    26 
    27 #include <w32std.h>
    28 #include <coefontprovider.h>
    29 
    30 
    31 const TInt KIterationsToTest = 25; // number of iterations
    32 
    33 _LIT(KSemaphore, "SemFullScreenTextSync"); // Name of the global semaphore
    34 _LIT(KTestStep0009,"GRAPHICS-UI-BENCH-S60-0009");
    35 
    36 // Literals for the ini file
    37 _LIT(KSectNameOpenGLVGTest, "FullScreenFontTest");
    38 _LIT(KKeyNameVertical, "Vertical");
    39 _LIT(KKeyNameRightToLeft, "RightToLeft");
    40 
    41 
    42 CTFullScreenText::CTFullScreenText()
    43 	{
    44 	SetTestStepName(KFullScreenText);
    45 	}
    46 
    47 void CTFullScreenText::InitUIL(CCoeEnv* aCoeEnv)
    48     {
    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);
    54     }
    55 
    56 /**
    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
    59  * a different thread.
    60  */
    61 void CTFullScreenText::GenerateEventL(TRawEvent::TType aEventType)
    62     {
    63     TRawEvent rawEvent;
    64     rawEvent.Set(aEventType, 0, 0);
    65     User::LeaveIfError(UserSvr::AddEvent(rawEvent));
    66     }
    67 
    68 TVerdict CTFullScreenText::doTestStepPreambleL()
    69 	{
    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();;
    80 	}
    81 
    82 TVerdict CTFullScreenText::doTestStepPostambleL()
    83     {
    84     iSemaphore.Close();
    85     // undo the button state change
    86     GenerateEventL(TRawEvent::EButton1Up);
    87     return CTe_ConeStepBase::doTestStepPostambleL();
    88     }
    89 
    90 TVerdict CTFullScreenText::doTestStepL()
    91     {
    92     SetTestStepID(KTestStep0009);
    93     TRAPD(err, FullScreenTextL());
    94     if (err != KErrNone)
    95         {
    96         SetTestStepResult(EAbort);
    97         }
    98     return TestStepResult();
    99     }
   100 
   101 /**
   102 @SYMTestCaseID
   103 GRAPHICS-UI-BENCH-S60-0009
   104 
   105 @SYMTestCaseDesc
   106 Tests how long it takes to draw text on the full screen. The font is requested
   107 for every redraw.
   108 
   109 @SYMTestActions
   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.
   113 
   114 @SYMTestExpectedResults
   115 Test should pass and log the framerate.
   116 */
   117 void CTFullScreenText::FullScreenTextL()
   118     {
   119     iProfiler->InitResults();
   120     for(TInt i = KIterationsToTest; i > 0; --i)
   121         {
   122         GenerateEventL(TRawEvent::EButton1Down);
   123         iSemaphore.Wait();
   124         }
   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);
   130     }
   131 
   132 
   133 CGlobalTextControl* CGlobalTextControl::NewLC(const CCoeControl* aParent, TBool aDrawVertically, TBool aRightToLeft)
   134 	{
   135 	CGlobalTextControl* self;
   136 	self = new(ELeave) CGlobalTextControl(aDrawVertically, aRightToLeft);
   137 	CleanupStack::PushL(self);
   138 	self->ConstructL(aParent);
   139 	return self;
   140 	}
   141 
   142 CGlobalTextControl* CGlobalTextControl::NewL(const CCoeControl* aParent, TBool aDrawVertically, TBool aRightToLeft)
   143 	{
   144 	CGlobalTextControl* self;
   145 	self = CGlobalTextControl::NewLC(aParent, aDrawVertically, aRightToLeft);
   146 	CleanupStack::Pop(self);
   147 	return self;
   148 	}
   149 
   150 CGlobalTextControl::CGlobalTextControl(TBool aDrawVertically, TBool aRightToLeft) : 
   151         iDrawVertically(aDrawVertically), iRightToLeft(aRightToLeft),
   152         iWsSession(CCoeEnv::Static()->WsSession())
   153     {
   154     iMargin.SetAllValuesTo(EInsetMargin);
   155     }
   156 
   157 void CGlobalTextControl::ConstructL(const CCoeControl* aParent)
   158     {
   159     User::LeaveIfError(iSemaphore.OpenGlobal(KSemaphore));
   160     iScreen = new(ELeave) CWsScreenDevice(ControlEnv()->WsSession());
   161     iScreen->Construct(); // default screen used
   162     if (iRightToLeft)
   163         {
   164         iBidiText = TBidiText::NewL(KRightToLeftText, EMaximumTextLines, TBidiText::ERightToLeft);
   165         }
   166     else
   167         {
   168         iBidiText = TBidiText::NewL(KFullScreenSampleText, EMaximumTextLines, TBidiText::ELeftToRight);
   169         }
   170     if (aParent)
   171         {
   172         SetContainerWindowL(*aParent);
   173         }
   174     else
   175         {
   176         CreateWindowL();
   177         ActivateL();
   178         }
   179     SetRect(TRect(TPoint(0,0), CTWindow::GetDisplaySizeInPixels()));
   180     }
   181 
   182 CGlobalTextControl::~CGlobalTextControl()
   183 	{
   184     delete iBidiText;
   185     delete iScreen;
   186     iSemaphore.Close();
   187 	}
   188 
   189 void CGlobalTextControl::Draw(const TRect& aRect) const
   190 	{
   191 	CWindowGc& gc = SystemGc();
   192 	gc.SetBrushColor(TRgb(EBackgroundColor));
   193 	gc.Clear(Rect());
   194 	
   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);
   202 
   203 	// request the font, could also be done during construction
   204 	CFont* font;
   205 	TFontSpec fontSpec;
   206 	fontSpec.iTypeface.iName = KNokiaSeries60Font;
   207 	fontSpec.iHeight=EDesiredFontHeight;
   208 	iScreen->GetNearestFontToDesignHeightInPixels((CFont*&)font, fontSpec);
   209 	
   210 	if (iDrawVertically)
   211 		{
   212 		iBidiText->WrapText(aRect.Height() - ESideBearingsAllowance, *font, NULL, EMaximumTextLines);
   213 		textDrawer.DrawTextVertical(gc, *iBidiText, aRect, *font);
   214 		}
   215 	else
   216 		{
   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.
   220 		if (iRightToLeft)
   221 			{
   222 			TGulAlignment alignment(EHLeftVTop);
   223 			textDrawer.SetAlignment(alignment);
   224 			}
   225 		iBidiText->WrapText(aRect.Width() - ESideBearingsAllowance, *font, NULL, EMaximumTextLines);
   226 		textDrawer.DrawText(gc, *iBidiText, aRect, *font);
   227 		}
   228 	iScreen->ReleaseFont(font);	// should be done every time the font is not needed anymore
   229 	}
   230 
   231 void CGlobalTextControl::HandlePointerEventL(const TPointerEvent& aPointerEvent)
   232     {
   233     // Process event generated from test step, forces a redraw.
   234     if(aPointerEvent.iType == TPointerEvent::EButton1Down)
   235         {
   236         DrawNow();
   237         iWsSession.Flush();
   238         iWsSession.Finish();
   239         iSemaphore.Signal();
   240         }    
   241     }
   242 
   243 
   244 CFullScreenTextAppUi::CFullScreenTextAppUi()
   245 	{
   246 	// empty
   247 	}
   248 
   249 void CFullScreenTextAppUi::ConstructL(TBool aDrawVertically, TBool aRightToLeft)
   250     {
   251     BaseConstructL(ENoAppResourceFile);
   252     iGlobalTextControl = CGlobalTextControl::NewL(NULL, aDrawVertically, aRightToLeft);
   253     AddToStackL(iGlobalTextControl);
   254     }
   255 
   256 CFullScreenTextAppUi::~CFullScreenTextAppUi()
   257 	{
   258 	RemoveFromStack(iGlobalTextControl);
   259 	delete iGlobalTextControl;
   260 	}