windowing/windowserver/ttime/TTIME.CPP
changeset 116 171fae344dd4
parent 103 2717213c588a
equal deleted inserted replaced
103:2717213c588a 116:171fae344dd4
     1 // Copyright (c) 1995-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 // Functions to act as bench marks for various window server features
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "TTIME.H"
       
    19 #include <e32svr.h>
       
    20 #include <e32def_private.h>
       
    21 typedef TBuf<32> TestNameBuf;
       
    22 
       
    23 LOCAL_D const TUint KHeapSize=0x10000;
       
    24 
       
    25 class CTimeClient;
       
    26 
       
    27 class CResultDialog : public CTDialog
       
    28 	{		  
       
    29 public:
       
    30 	CResultDialog(CTWindowGroup *aGroupWin,CWindowGc *aGc);
       
    31 	void ButtonPressL(TInt aButton);
       
    32 	void ConstructLD();
       
    33 private:
       
    34 	CTWindowGroup *iGroupWin;
       
    35 	CWindowGc *iGc;
       
    36 	};
       
    37 
       
    38 class CListWindow : public CTTitledWindow
       
    39 	{
       
    40 public:
       
    41 	CListWindow();
       
    42 	void CloseWindow();
       
    43 	void ConstructL(CTWinBase &parent, TBool aExitOnEscape);
       
    44 	void Draw();
       
    45 	virtual void SelectedL(TInt aIndex)=0;
       
    46 	virtual void WinKeyL(const TKeyEvent &aKey,const TTime& aTime);
       
    47 	void SetExt(const TPoint &aPos, const TSize &aSize);
       
    48 	void SetSize(const TSize &);
       
    49 protected:
       
    50 	virtual TPtrC GetText(TInt aLine)=0;
       
    51 	virtual TInt ListCount()=0;
       
    52 	void SetSize();
       
    53 private:
       
    54 	void Resized(const TSize &aSize);
       
    55 	void SetListPos(TInt aNewPos);
       
    56 	TInt TextRowHeight() const;
       
    57 	void RowBox(TRect &aRect, TInt aRow) const;
       
    58 	void PointerL(const TPointerEvent &aPointer,const TTime& aTime);
       
    59 private:
       
    60 	TInt iListPos;
       
    61 	TTime iPrevTime;
       
    62 	TBool iExitOnEscape;
       
    63 	};
       
    64 
       
    65 class CTestList : public CListWindow
       
    66 	{
       
    67 public:
       
    68 	CTestList();
       
    69 	~CTestList();
       
    70 	void ConstructL(CTWinBase &parent);
       
    71 	static void AppendProfileNum(TDes &aDes, TInt aNum);
       
    72 	static void AppendProfileCount(TDes &aDes, TInt aNum);
       
    73 	void SelectedL(TInt aIndex);
       
    74 	virtual void WinKeyL(const TKeyEvent &aKey,const TTime& aTime);
       
    75 	void ForegroundAppDialog();
       
    76 	void AppendToListL(const TDesC &aDesc);
       
    77 private:
       
    78 	virtual TPtrC GetText(TInt aLine);
       
    79 	virtual TInt ListCount();
       
    80 private:
       
    81 	TInt iCount;
       
    82 	CArrayFixSeg<TestNameBuf> iTestNames;
       
    83 	RThread iTimeTest;
       
    84 	};
       
    85 
       
    86 class CTimeTestWindowGroup : public CTWindowGroup
       
    87 	{
       
    88 public:
       
    89 	CTimeTestWindowGroup(CTClient *aClient);
       
    90 	void KeyL(const TKeyEvent &aKey,const TTime &aTime);
       
    91 	};
       
    92 
       
    93 class CTimeClient : public CTClient
       
    94 	{
       
    95 public:
       
    96 	CTimeClient();
       
    97 	void ConstructL();
       
    98 	void KeyL(const TKeyEvent &aKey,const TTime &aTime);
       
    99 	void Exit();
       
   100 	CTWin *CreateTestWindowL(TPoint pos,CTWinBase *parent);
       
   101 private:
       
   102 	TInt iNum;
       
   103 	};
       
   104 
       
   105 const TInt Xmove=8;
       
   106 const TInt Ymove=6;
       
   107 
       
   108 GLREF_D TTimeTestHeader MovingWindowTest1;
       
   109 GLREF_D TTimeTestHeader MovingWindowTest2;
       
   110 GLREF_D TTimeTestHeader StackedWindowCreate;
       
   111 GLREF_D TTimeTestHeader WindowCreateDestroy;
       
   112 GLREF_D TTimeTestHeader LoadsaText;
       
   113 GLREF_D TTimeTestHeader DrawBitmapTest;
       
   114 GLREF_D TTimeTestHeader XorIngTest;
       
   115 GLREF_D TTimeTestHeader SmallClearTest;
       
   116 GLREF_D TTimeTestHeader RectCompareTest;
       
   117 GLREF_D TTimeTestHeader SimpleFlushTest;
       
   118 GLREF_D TTimeTestHeader SimpleFlushTest2;
       
   119 GLREF_D TTimeTestHeader UseFontTest;
       
   120 GLREF_D TTimeTestHeader BitBltTest;
       
   121 GLREF_D TTimeTestHeader FullScreenBitBltTest;
       
   122 GLREF_D TTimeTestHeader MaskedBitBltTest;
       
   123 GLREF_D TTimeTestHeader SpriteTest;
       
   124 GLREF_D TTimeTestHeader BitmapDeviceTest1;
       
   125 GLREF_D TTimeTestHeader BitmapDeviceTest2;
       
   126 GLREF_D TTimeTestHeader FillPatternTest;
       
   127 GLREF_D TTimeTestHeader BitmapLoadTest;
       
   128 GLREF_D TTimeTestHeader WsBitmapLoadTest;
       
   129 GLREF_D TTimeTestHeader RomFileTest;
       
   130 GLREF_D TTimeTestHeader TrivialFunctionsTest;
       
   131 GLREF_D TTimeTestHeader BackupWindowDrawingCreate1;
       
   132 GLREF_D TTimeTestHeader BackupWindowDrawingCreate2;
       
   133 GLREF_D TTimeTestHeader MenuEmulationCreate;
       
   134 GLREF_D TTimeTestHeader MenuEmulationCreate2;
       
   135 
       
   136 TTimeTestHeader *tests[]={
       
   137 	&MenuEmulationCreate,
       
   138 	&MenuEmulationCreate2,
       
   139 	&BitmapLoadTest,
       
   140 	&WsBitmapLoadTest,
       
   141 	&RomFileTest,
       
   142 	&TrivialFunctionsTest,
       
   143 	&BackupWindowDrawingCreate1,
       
   144 	&BackupWindowDrawingCreate2,
       
   145 	&MovingWindowTest1,
       
   146 	&MovingWindowTest2,
       
   147 	&StackedWindowCreate,
       
   148 //	&WindowCreateDestroy,
       
   149 	&LoadsaText,
       
   150 	&DrawBitmapTest,
       
   151 //	&BitmapDeviceTest1,
       
   152 //	&BitmapDeviceTest2,
       
   153 //	&XorIngTest,		List getting too big
       
   154 //	&SmallClearTest,	List getting too big
       
   155 //	&RectCompareTest,
       
   156 	&SpriteTest,
       
   157 //	&SimpleFlushTest,
       
   158 //	&SimpleFlushTest2,
       
   159 //	&UseFontTest,
       
   160 	&BitBltTest,
       
   161 //	&FullScreenBitBltTest,
       
   162 	&MaskedBitBltTest,
       
   163 //	&FillPatternTest,
       
   164 	};
       
   165 
       
   166 void Panic(TInt aPanic)
       
   167 	{
       
   168 	User::Panic(_L("TimeTest"),aPanic);
       
   169 	}
       
   170 
       
   171 struct TThreadParams
       
   172 	{
       
   173 	TInt iIndex;
       
   174 	TInt iGroupId;
       
   175 	};
       
   176 
       
   177 TInt TimeThread(TAny *aParams)
       
   178 	{
       
   179 	CTrapCleanup* CleanUpStack=CTrapCleanup::New();
       
   180 	//__PROFILE_START(0)
       
   181 	TInt ret=tests[((TThreadParams *)aParams)->iIndex]->function(((TThreadParams *)aParams)->iGroupId);
       
   182 	//__PROFILE_END(0)
       
   183 	delete CleanUpStack;
       
   184 	return ret;
       
   185 	}
       
   186 
       
   187 //
       
   188 // List Window //
       
   189 //
       
   190 
       
   191 CListWindow::CListWindow() : CTTitledWindow(), iPrevTime(0)
       
   192 	{
       
   193 	}
       
   194 
       
   195 void CListWindow::CloseWindow()
       
   196 	{
       
   197 	CTClient *client=((CTimeClient *)Client());
       
   198 	delete this;
       
   199 	client->ResetFocus();
       
   200 	}
       
   201 
       
   202 void CListWindow::SetExt(const TPoint &aPos, const TSize &)
       
   203 	{
       
   204 	SetPos(aPos);
       
   205 	}
       
   206 
       
   207 void CListWindow::SetSize(const TSize &)
       
   208 	{
       
   209 	}
       
   210 
       
   211 void CListWindow::SetSize()
       
   212 	{
       
   213 	iSize.iHeight=ListCount()*(iFont->HeightInPixels()+1)+iTitleHeight+2;
       
   214 	iSize.iWidth=iFont->TextWidthInPixels(*Client()->Title())+30;
       
   215 	for(TInt index=0;index<ListCount();index++)
       
   216 		{
       
   217 		TInt wid=iFont->TextWidthInPixels(GetText(index));
       
   218 		if (wid>iSize.iWidth)
       
   219 			iSize.iWidth=wid;
       
   220 		}
       
   221 	iSize.iWidth+=4;
       
   222 	iWin.SetSize(iSize);
       
   223 	Resized(iSize);
       
   224 	}
       
   225 
       
   226 void CListWindow::ConstructL(CTWinBase &parent, TBool aExitOnEscape)
       
   227 	{
       
   228 	iExitOnEscape=aExitOnEscape;
       
   229 	CTTitledWindow::ConstructL(parent);
       
   230 	}
       
   231 
       
   232 void CListWindow::SetListPos(TInt aNewPos)
       
   233 	{
       
   234 	if (aNewPos>=0 && aNewPos<ListCount())
       
   235 		{
       
   236 		iListPos=aNewPos;
       
   237 		Invalidate();
       
   238 		}
       
   239 	}
       
   240 
       
   241 void CListWindow::WinKeyL(const TKeyEvent &aKey, const TTime&)
       
   242 	{
       
   243 	switch(aKey.iCode)
       
   244 		{
       
   245 		case EKeyUpArrow:
       
   246 			SetListPos(iListPos-1);
       
   247 			break;
       
   248 		case EKeyDownArrow:
       
   249 			SetListPos(iListPos+1);
       
   250 			break;
       
   251 		case EKeyEnter:
       
   252 			SelectedL(iListPos);
       
   253 			break;
       
   254 		case EKeyEscape:		// Fall through from EKeyEnter
       
   255 			if (iExitOnEscape)
       
   256 				CloseWindow();
       
   257 			break;
       
   258 		}
       
   259 	}
       
   260 
       
   261 void CListWindow::PointerL(const TPointerEvent &aPointer,const TTime& aTime)
       
   262 	{
       
   263 	if (aPointer.iType==TPointerEvent::EButton1Down)
       
   264 		{
       
   265 		TRect rect;
       
   266 		for(TInt index=0;index<ListCount();index++)
       
   267 			{
       
   268 			RowBox(rect,index);
       
   269 			if (rect.Contains(aPointer.iPosition))
       
   270 				{
       
   271 				if (index==iListPos && aPointer.iModifiers&EModifierDoubleClick)
       
   272 					SelectedL(iListPos);
       
   273 				else
       
   274 					{
       
   275 					iPrevTime=aTime;
       
   276 					SetListPos(index);
       
   277 					}
       
   278 				return;
       
   279 				}
       
   280 			}
       
   281 		}
       
   282 	CTTitledWindow::PointerL(aPointer,aTime);
       
   283 	}
       
   284 
       
   285 TInt CListWindow::TextRowHeight() const
       
   286 	{
       
   287 	return(iFont->HeightInPixels()+1);
       
   288 	}
       
   289 
       
   290 void CListWindow::RowBox(TRect &aRect, TInt aRow) const
       
   291 	{
       
   292 	aRect.iTl.iX=2;
       
   293 	aRect.iTl.iY=iTitleHeight+TextRowHeight()*aRow;
       
   294 	aRect.iBr.iX=iSize.iWidth-2;
       
   295 	aRect.iBr.iY=aRect.iTl.iY+TextRowHeight();
       
   296 	}
       
   297 
       
   298 void CListWindow::Draw()
       
   299 	{
       
   300 	CTTitledWindow::Draw();
       
   301 	iGc->SetPenColor(TRgb::Gray16(0));
       
   302 	TPoint pos(2,iTitleHeight+iFont->AscentInPixels()+2);
       
   303 	TInt gap=TextRowHeight();
       
   304 	for(TInt index=0;index<ListCount();index++,pos.iY+=gap)
       
   305 		{
       
   306 		iGc->DrawText(GetText(index), pos);
       
   307 		if (index==iListPos)
       
   308 			{
       
   309 			iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   310 			iGc->SetBrushColor(TRgb::Gray256(255));
       
   311 			iGc->SetPenStyle(CGraphicsContext::ENullPen);
       
   312 			iGc->SetDrawMode(CGraphicsContext::EDrawModeXOR);
       
   313 			TRect rect;
       
   314 			RowBox(rect,index);
       
   315 			iGc->DrawRect(rect);
       
   316 			iGc->SetBrushStyle(CGraphicsContext::ENullBrush);
       
   317 			iGc->SetPenStyle(CGraphicsContext::ESolidPen);
       
   318 			iGc->SetDrawMode(CGraphicsContext::EDrawModePEN);
       
   319 			}
       
   320 		}
       
   321 	}
       
   322 
       
   323 void CListWindow::Resized(const TSize &aSize)
       
   324 	{
       
   325 	SetDragRect(TRect(0,0,aSize.iWidth,iTitleHeight));
       
   326 	}
       
   327 
       
   328 //
       
   329 // Test list window
       
   330 //
       
   331 
       
   332 CTestList::CTestList() : CListWindow(), iTestNames(4)
       
   333 	{
       
   334 	}
       
   335 
       
   336 CTestList::~CTestList()
       
   337 	{
       
   338 	}
       
   339 
       
   340 void CTestList::ConstructL(CTWinBase &parent)
       
   341 	{
       
   342 	CListWindow::ConstructL(parent, EFalse);
       
   343 	for(TUint index=0;index<(sizeof(tests)/sizeof(tests[0]));index++)
       
   344 		AppendToListL(TPtrC(tests[index]->title));
       
   345 	SetSize();
       
   346 	/*for(TUint index1=0;index1<(sizeof(tests)/sizeof(tests[0]));index1++)
       
   347 		Selected(index1);*/
       
   348 	}
       
   349 
       
   350 void CTestList::AppendProfileNum(TDes &aDes, TInt aNum)
       
   351 	{
       
   352 	aDes.AppendFormat(_L("%d.%02d, "),aNum/1000000,(aNum%1000000)/10000);
       
   353 	}
       
   354 
       
   355 void CTestList::AppendProfileCount(TDes &aDes, TInt aNum)
       
   356 	{
       
   357 	aDes.AppendFormat(_L("%d, "),aNum);
       
   358 	}
       
   359 
       
   360 #define USE_PROCESS 1
       
   361 
       
   362 void CTestList::SelectedL(TInt aIndex)
       
   363 	{
       
   364 #if USE_PROCESS
       
   365 	TThreadParams params;
       
   366 	params.iIndex=aIndex;
       
   367 	TName name;
       
   368 	name.Format(_L("TimeTest-%x"),iCount++);
       
   369 	params.iGroupId=Client()->iGroup->GroupWin()->Identifier();
       
   370 	User::LeaveIfError(iTimeTest.Create(name,TimeThread,KDefaultStackSize*2,KHeapSize,KHeapSize,&params,EOwnerThread));
       
   371 	TRequestStatus status;
       
   372 	iTimeTest.Logon(status);
       
   373 	__PROFILE_RESET(8);
       
   374 	iTimeTest.Resume();
       
   375 	User::WaitForRequest(status);
       
   376 #else
       
   377 	TThreadParams params;
       
   378 	params.iIndex=aIndex;
       
   379 	TimeThread(&params);
       
   380 #endif
       
   381 	TBuf<64> buf;
       
   382 	TBuf<64> buf2;
       
   383 	TBuf<64> buf3;
       
   384 	CResultDialog *dialog=new(ELeave) CResultDialog(Client()->iGroup, iGc);
       
   385 	dialog->ConstructLD();
       
   386 #if USE_PROCESS
       
   387 	if (status.Int()==KErrNone)
       
   388 		{
       
   389 #endif
       
   390 #if !defined(__PROFILING__)
       
   391 		buf=_L("Profiling information not available");
       
   392 #else
       
   393 		TProfile profile[6];
       
   394 		__PROFILE_DISPLAY(6);
       
   395 		for (TInt index=1;index<6;index++)
       
   396 			AppendProfileNum(buf2,profile[index].iTime);
       
   397 		for (TInt index2=1;index2<6;index2++)
       
   398 			AppendProfileCount(buf3,profile[index2].iCount);
       
   399 		buf.Format(_L("Time=%d.%2d"),profile[0].iTime/1000000,(profile[0].iTime%1000000)/10000);
       
   400 #endif
       
   401 		dialog->SetTitle(buf);
       
   402 #if USE_PROCESS
       
   403 		}
       
   404 	else
       
   405 		{
       
   406 		dialog->SetTitle(_L("Error in test"));
       
   407 		buf.Format(_L("Error=%d"),status.Int());
       
   408 		buf2=iTimeTest.ExitCategory();
       
   409 		}
       
   410 #endif
       
   411 	dialog->SetLine1(buf2);
       
   412 	dialog->SetLine2(buf3);
       
   413 	dialog->SetNumButtons(1);
       
   414 	dialog->SetButtonText(0,_L("Okay"));
       
   415 	if (dialog->Display()!=0)
       
   416 		Panic(0);
       
   417 	}
       
   418 
       
   419 TPtrC CTestList::GetText(TInt aLine)
       
   420 	{
       
   421 	return(TPtrC(iTestNames[aLine]));
       
   422 	}
       
   423 
       
   424 TInt CTestList::ListCount()
       
   425 	{
       
   426 	return(iTestNames.Count());
       
   427 	}
       
   428 
       
   429 void CTestList::WinKeyL(const TKeyEvent &aKey,const TTime& aTime)
       
   430 	{
       
   431 	if (aKey.iModifiers&EModifierFunc)
       
   432 		{
       
   433 		switch(aKey.iCode)
       
   434 			{
       
   435 			case EKeyLeftArrow:
       
   436 				AdjustSize(-Xmove,0,aKey.iModifiers);
       
   437 				break;
       
   438 			case EKeyRightArrow:
       
   439 				AdjustSize(Xmove,0,aKey.iModifiers);
       
   440 				break;
       
   441 			case EKeyUpArrow:
       
   442 				AdjustSize(0,-Ymove,aKey.iModifiers);
       
   443 				break;
       
   444 			case EKeyDownArrow:
       
   445 				AdjustSize(0,Ymove,aKey.iModifiers);
       
   446 				break;
       
   447 			default:
       
   448 				goto not_used;
       
   449 			}
       
   450 		}
       
   451 	else
       
   452 		goto not_used;
       
   453 	return;
       
   454 not_used:
       
   455 	CListWindow::WinKeyL(aKey,aTime);
       
   456 	}
       
   457 
       
   458 void CTestList::AppendToListL(const TDesC &aDesc)
       
   459 	{
       
   460 	TestNameBuf buf(aDesc);	
       
   461 	iTestNames.AppendL(buf);
       
   462 	}
       
   463 
       
   464 //
       
   465 
       
   466 CResultDialog::CResultDialog(CTWindowGroup *aGroupWin,CWindowGc *aGc) : CTDialog(),
       
   467 	iGroupWin(aGroupWin),
       
   468 	iGc(aGc)
       
   469 	{
       
   470 	}
       
   471 
       
   472 void CResultDialog::ButtonPressL(TInt aButton)
       
   473 	{
       
   474 	if (aButton==0)
       
   475 		CTDialog::ButtonPressL(aButton);
       
   476 	}
       
   477 
       
   478 void CResultDialog::ConstructLD()
       
   479 	{
       
   480 	CTDialog::ConstructLD(*iGroupWin, *iGc);
       
   481 	}
       
   482 
       
   483 //
       
   484 // CTimeTestWindowGroup class //
       
   485 //
       
   486 
       
   487 CTimeTestWindowGroup::CTimeTestWindowGroup(CTClient *aClient) : CTWindowGroup(aClient)
       
   488 	{
       
   489 	}
       
   490 
       
   491 void CTimeTestWindowGroup::KeyL(const TKeyEvent &aKey,const TTime &aTime)
       
   492 	{
       
   493 	if (aKey.iModifiers&EModifierFunc)
       
   494 		{
       
   495 		switch(aKey.iCode)
       
   496 			{
       
   497 			case 'x':
       
   498 				((CTimeClient *)Client())->Exit();
       
   499 				break;
       
   500 			}
       
   501 		}
       
   502 	else
       
   503 		iCurWin->WinKeyL(aKey,aTime);
       
   504 	}
       
   505 
       
   506 //
       
   507 
       
   508 CTimeClient::CTimeClient()
       
   509 	{
       
   510 	}
       
   511 
       
   512 CTWin *CTimeClient::CreateTestWindowL(TPoint pos,CTWinBase *parent)
       
   513 	{
       
   514 	CTWin *win=new(ELeave) CTestList();
       
   515 	TRAPD(err,win->ConstructL(*parent));
       
   516 	if (err!=KErrNone)
       
   517 		goto ctw_err;
       
   518 	TRAP(err,win->SetPos(pos));
       
   519 	if (err!=KErrNone)
       
   520 		{
       
   521 ctw_err:
       
   522 		delete win;
       
   523 		User::Leave(err);
       
   524 		}
       
   525 	win->Activate();
       
   526 	win->AssignGC(*iGc);
       
   527 	return(win);
       
   528 	}
       
   529 
       
   530 void CTimeClient::ConstructL()
       
   531 	{
       
   532 	CTClient::ConstructL();
       
   533 
       
   534 	iGroup=new(ELeave) CTimeTestWindowGroup(this);
       
   535 	iGroup->ConstructL();
       
   536 
       
   537 	CreateTestWindowL(TPoint(30,4),iGroup);
       
   538 	iGroup->SetCurrentWindow(iGroup->Child());
       
   539 	}
       
   540 
       
   541 void CTimeClient::Exit()
       
   542 	{
       
   543 	CActiveScheduler::Stop();
       
   544 	}
       
   545 
       
   546 GLDEF_C CTClient *CreateClientL()
       
   547 	{
       
   548 	return(new(ELeave) CTimeClient());
       
   549 	}
       
   550 
       
   551 GLDEF_C TInt E32Main()
       
   552 	{
       
   553 	return(TestLibStartUp(CreateClientL));
       
   554 	}