1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/windowing/windowserver/test/ttime/TTIME.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,554 @@
1.4 +// Copyright (c) 1995-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 +// Functions to act as bench marks for various window server features
1.18 +//
1.19 +//
1.20 +
1.21 +#include "TTIME.H"
1.22 +#include <e32svr.h>
1.23 +#include <e32def_private.h>
1.24 +typedef TBuf<32> TestNameBuf;
1.25 +
1.26 +LOCAL_D const TUint KHeapSize=0x10000;
1.27 +
1.28 +class CTimeClient;
1.29 +
1.30 +class CResultDialog : public CTDialog
1.31 + {
1.32 +public:
1.33 + CResultDialog(CTWindowGroup *aGroupWin,CWindowGc *aGc);
1.34 + void ButtonPressL(TInt aButton);
1.35 + void ConstructLD();
1.36 +private:
1.37 + CTWindowGroup *iGroupWin;
1.38 + CWindowGc *iGc;
1.39 + };
1.40 +
1.41 +class CListWindow : public CTTitledWindow
1.42 + {
1.43 +public:
1.44 + CListWindow();
1.45 + void CloseWindow();
1.46 + void ConstructL(CTWinBase &parent, TBool aExitOnEscape);
1.47 + void Draw();
1.48 + virtual void SelectedL(TInt aIndex)=0;
1.49 + virtual void WinKeyL(const TKeyEvent &aKey,const TTime& aTime);
1.50 + void SetExt(const TPoint &aPos, const TSize &aSize);
1.51 + void SetSize(const TSize &);
1.52 +protected:
1.53 + virtual TPtrC GetText(TInt aLine)=0;
1.54 + virtual TInt ListCount()=0;
1.55 + void SetSize();
1.56 +private:
1.57 + void Resized(const TSize &aSize);
1.58 + void SetListPos(TInt aNewPos);
1.59 + TInt TextRowHeight() const;
1.60 + void RowBox(TRect &aRect, TInt aRow) const;
1.61 + void PointerL(const TPointerEvent &aPointer,const TTime& aTime);
1.62 +private:
1.63 + TInt iListPos;
1.64 + TTime iPrevTime;
1.65 + TBool iExitOnEscape;
1.66 + };
1.67 +
1.68 +class CTestList : public CListWindow
1.69 + {
1.70 +public:
1.71 + CTestList();
1.72 + ~CTestList();
1.73 + void ConstructL(CTWinBase &parent);
1.74 + static void AppendProfileNum(TDes &aDes, TInt aNum);
1.75 + static void AppendProfileCount(TDes &aDes, TInt aNum);
1.76 + void SelectedL(TInt aIndex);
1.77 + virtual void WinKeyL(const TKeyEvent &aKey,const TTime& aTime);
1.78 + void ForegroundAppDialog();
1.79 + void AppendToListL(const TDesC &aDesc);
1.80 +private:
1.81 + virtual TPtrC GetText(TInt aLine);
1.82 + virtual TInt ListCount();
1.83 +private:
1.84 + TInt iCount;
1.85 + CArrayFixSeg<TestNameBuf> iTestNames;
1.86 + RThread iTimeTest;
1.87 + };
1.88 +
1.89 +class CTimeTestWindowGroup : public CTWindowGroup
1.90 + {
1.91 +public:
1.92 + CTimeTestWindowGroup(CTClient *aClient);
1.93 + void KeyL(const TKeyEvent &aKey,const TTime &aTime);
1.94 + };
1.95 +
1.96 +class CTimeClient : public CTClient
1.97 + {
1.98 +public:
1.99 + CTimeClient();
1.100 + void ConstructL();
1.101 + void KeyL(const TKeyEvent &aKey,const TTime &aTime);
1.102 + void Exit();
1.103 + CTWin *CreateTestWindowL(TPoint pos,CTWinBase *parent);
1.104 +private:
1.105 + TInt iNum;
1.106 + };
1.107 +
1.108 +const TInt Xmove=8;
1.109 +const TInt Ymove=6;
1.110 +
1.111 +GLREF_D TTimeTestHeader MovingWindowTest1;
1.112 +GLREF_D TTimeTestHeader MovingWindowTest2;
1.113 +GLREF_D TTimeTestHeader StackedWindowCreate;
1.114 +GLREF_D TTimeTestHeader WindowCreateDestroy;
1.115 +GLREF_D TTimeTestHeader LoadsaText;
1.116 +GLREF_D TTimeTestHeader DrawBitmapTest;
1.117 +GLREF_D TTimeTestHeader XorIngTest;
1.118 +GLREF_D TTimeTestHeader SmallClearTest;
1.119 +GLREF_D TTimeTestHeader RectCompareTest;
1.120 +GLREF_D TTimeTestHeader SimpleFlushTest;
1.121 +GLREF_D TTimeTestHeader SimpleFlushTest2;
1.122 +GLREF_D TTimeTestHeader UseFontTest;
1.123 +GLREF_D TTimeTestHeader BitBltTest;
1.124 +GLREF_D TTimeTestHeader FullScreenBitBltTest;
1.125 +GLREF_D TTimeTestHeader MaskedBitBltTest;
1.126 +GLREF_D TTimeTestHeader SpriteTest;
1.127 +GLREF_D TTimeTestHeader BitmapDeviceTest1;
1.128 +GLREF_D TTimeTestHeader BitmapDeviceTest2;
1.129 +GLREF_D TTimeTestHeader FillPatternTest;
1.130 +GLREF_D TTimeTestHeader BitmapLoadTest;
1.131 +GLREF_D TTimeTestHeader WsBitmapLoadTest;
1.132 +GLREF_D TTimeTestHeader RomFileTest;
1.133 +GLREF_D TTimeTestHeader TrivialFunctionsTest;
1.134 +GLREF_D TTimeTestHeader BackupWindowDrawingCreate1;
1.135 +GLREF_D TTimeTestHeader BackupWindowDrawingCreate2;
1.136 +GLREF_D TTimeTestHeader MenuEmulationCreate;
1.137 +GLREF_D TTimeTestHeader MenuEmulationCreate2;
1.138 +
1.139 +TTimeTestHeader *tests[]={
1.140 + &MenuEmulationCreate,
1.141 + &MenuEmulationCreate2,
1.142 + &BitmapLoadTest,
1.143 + &WsBitmapLoadTest,
1.144 + &RomFileTest,
1.145 + &TrivialFunctionsTest,
1.146 + &BackupWindowDrawingCreate1,
1.147 + &BackupWindowDrawingCreate2,
1.148 + &MovingWindowTest1,
1.149 + &MovingWindowTest2,
1.150 + &StackedWindowCreate,
1.151 +// &WindowCreateDestroy,
1.152 + &LoadsaText,
1.153 + &DrawBitmapTest,
1.154 +// &BitmapDeviceTest1,
1.155 +// &BitmapDeviceTest2,
1.156 +// &XorIngTest, List getting too big
1.157 +// &SmallClearTest, List getting too big
1.158 +// &RectCompareTest,
1.159 + &SpriteTest,
1.160 +// &SimpleFlushTest,
1.161 +// &SimpleFlushTest2,
1.162 +// &UseFontTest,
1.163 + &BitBltTest,
1.164 +// &FullScreenBitBltTest,
1.165 + &MaskedBitBltTest,
1.166 +// &FillPatternTest,
1.167 + };
1.168 +
1.169 +void Panic(TInt aPanic)
1.170 + {
1.171 + User::Panic(_L("TimeTest"),aPanic);
1.172 + }
1.173 +
1.174 +struct TThreadParams
1.175 + {
1.176 + TInt iIndex;
1.177 + TInt iGroupId;
1.178 + };
1.179 +
1.180 +TInt TimeThread(TAny *aParams)
1.181 + {
1.182 + CTrapCleanup* CleanUpStack=CTrapCleanup::New();
1.183 + //__PROFILE_START(0)
1.184 + TInt ret=tests[((TThreadParams *)aParams)->iIndex]->function(((TThreadParams *)aParams)->iGroupId);
1.185 + //__PROFILE_END(0)
1.186 + delete CleanUpStack;
1.187 + return ret;
1.188 + }
1.189 +
1.190 +//
1.191 +// List Window //
1.192 +//
1.193 +
1.194 +CListWindow::CListWindow() : CTTitledWindow(), iPrevTime(0)
1.195 + {
1.196 + }
1.197 +
1.198 +void CListWindow::CloseWindow()
1.199 + {
1.200 + CTClient *client=((CTimeClient *)Client());
1.201 + delete this;
1.202 + client->ResetFocus();
1.203 + }
1.204 +
1.205 +void CListWindow::SetExt(const TPoint &aPos, const TSize &)
1.206 + {
1.207 + SetPos(aPos);
1.208 + }
1.209 +
1.210 +void CListWindow::SetSize(const TSize &)
1.211 + {
1.212 + }
1.213 +
1.214 +void CListWindow::SetSize()
1.215 + {
1.216 + iSize.iHeight=ListCount()*(iFont->HeightInPixels()+1)+iTitleHeight+2;
1.217 + iSize.iWidth=iFont->TextWidthInPixels(*Client()->Title())+30;
1.218 + for(TInt index=0;index<ListCount();index++)
1.219 + {
1.220 + TInt wid=iFont->TextWidthInPixels(GetText(index));
1.221 + if (wid>iSize.iWidth)
1.222 + iSize.iWidth=wid;
1.223 + }
1.224 + iSize.iWidth+=4;
1.225 + iWin.SetSize(iSize);
1.226 + Resized(iSize);
1.227 + }
1.228 +
1.229 +void CListWindow::ConstructL(CTWinBase &parent, TBool aExitOnEscape)
1.230 + {
1.231 + iExitOnEscape=aExitOnEscape;
1.232 + CTTitledWindow::ConstructL(parent);
1.233 + }
1.234 +
1.235 +void CListWindow::SetListPos(TInt aNewPos)
1.236 + {
1.237 + if (aNewPos>=0 && aNewPos<ListCount())
1.238 + {
1.239 + iListPos=aNewPos;
1.240 + Invalidate();
1.241 + }
1.242 + }
1.243 +
1.244 +void CListWindow::WinKeyL(const TKeyEvent &aKey, const TTime&)
1.245 + {
1.246 + switch(aKey.iCode)
1.247 + {
1.248 + case EKeyUpArrow:
1.249 + SetListPos(iListPos-1);
1.250 + break;
1.251 + case EKeyDownArrow:
1.252 + SetListPos(iListPos+1);
1.253 + break;
1.254 + case EKeyEnter:
1.255 + SelectedL(iListPos);
1.256 + break;
1.257 + case EKeyEscape: // Fall through from EKeyEnter
1.258 + if (iExitOnEscape)
1.259 + CloseWindow();
1.260 + break;
1.261 + }
1.262 + }
1.263 +
1.264 +void CListWindow::PointerL(const TPointerEvent &aPointer,const TTime& aTime)
1.265 + {
1.266 + if (aPointer.iType==TPointerEvent::EButton1Down)
1.267 + {
1.268 + TRect rect;
1.269 + for(TInt index=0;index<ListCount();index++)
1.270 + {
1.271 + RowBox(rect,index);
1.272 + if (rect.Contains(aPointer.iPosition))
1.273 + {
1.274 + if (index==iListPos && aPointer.iModifiers&EModifierDoubleClick)
1.275 + SelectedL(iListPos);
1.276 + else
1.277 + {
1.278 + iPrevTime=aTime;
1.279 + SetListPos(index);
1.280 + }
1.281 + return;
1.282 + }
1.283 + }
1.284 + }
1.285 + CTTitledWindow::PointerL(aPointer,aTime);
1.286 + }
1.287 +
1.288 +TInt CListWindow::TextRowHeight() const
1.289 + {
1.290 + return(iFont->HeightInPixels()+1);
1.291 + }
1.292 +
1.293 +void CListWindow::RowBox(TRect &aRect, TInt aRow) const
1.294 + {
1.295 + aRect.iTl.iX=2;
1.296 + aRect.iTl.iY=iTitleHeight+TextRowHeight()*aRow;
1.297 + aRect.iBr.iX=iSize.iWidth-2;
1.298 + aRect.iBr.iY=aRect.iTl.iY+TextRowHeight();
1.299 + }
1.300 +
1.301 +void CListWindow::Draw()
1.302 + {
1.303 + CTTitledWindow::Draw();
1.304 + iGc->SetPenColor(TRgb::Gray16(0));
1.305 + TPoint pos(2,iTitleHeight+iFont->AscentInPixels()+2);
1.306 + TInt gap=TextRowHeight();
1.307 + for(TInt index=0;index<ListCount();index++,pos.iY+=gap)
1.308 + {
1.309 + iGc->DrawText(GetText(index), pos);
1.310 + if (index==iListPos)
1.311 + {
1.312 + iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
1.313 + iGc->SetBrushColor(TRgb::Gray256(255));
1.314 + iGc->SetPenStyle(CGraphicsContext::ENullPen);
1.315 + iGc->SetDrawMode(CGraphicsContext::EDrawModeXOR);
1.316 + TRect rect;
1.317 + RowBox(rect,index);
1.318 + iGc->DrawRect(rect);
1.319 + iGc->SetBrushStyle(CGraphicsContext::ENullBrush);
1.320 + iGc->SetPenStyle(CGraphicsContext::ESolidPen);
1.321 + iGc->SetDrawMode(CGraphicsContext::EDrawModePEN);
1.322 + }
1.323 + }
1.324 + }
1.325 +
1.326 +void CListWindow::Resized(const TSize &aSize)
1.327 + {
1.328 + SetDragRect(TRect(0,0,aSize.iWidth,iTitleHeight));
1.329 + }
1.330 +
1.331 +//
1.332 +// Test list window
1.333 +//
1.334 +
1.335 +CTestList::CTestList() : CListWindow(), iTestNames(4)
1.336 + {
1.337 + }
1.338 +
1.339 +CTestList::~CTestList()
1.340 + {
1.341 + }
1.342 +
1.343 +void CTestList::ConstructL(CTWinBase &parent)
1.344 + {
1.345 + CListWindow::ConstructL(parent, EFalse);
1.346 + for(TUint index=0;index<(sizeof(tests)/sizeof(tests[0]));index++)
1.347 + AppendToListL(TPtrC(tests[index]->title));
1.348 + SetSize();
1.349 + /*for(TUint index1=0;index1<(sizeof(tests)/sizeof(tests[0]));index1++)
1.350 + Selected(index1);*/
1.351 + }
1.352 +
1.353 +void CTestList::AppendProfileNum(TDes &aDes, TInt aNum)
1.354 + {
1.355 + aDes.AppendFormat(_L("%d.%02d, "),aNum/1000000,(aNum%1000000)/10000);
1.356 + }
1.357 +
1.358 +void CTestList::AppendProfileCount(TDes &aDes, TInt aNum)
1.359 + {
1.360 + aDes.AppendFormat(_L("%d, "),aNum);
1.361 + }
1.362 +
1.363 +#define USE_PROCESS 1
1.364 +
1.365 +void CTestList::SelectedL(TInt aIndex)
1.366 + {
1.367 +#if USE_PROCESS
1.368 + TThreadParams params;
1.369 + params.iIndex=aIndex;
1.370 + TName name;
1.371 + name.Format(_L("TimeTest-%x"),iCount++);
1.372 + params.iGroupId=Client()->iGroup->GroupWin()->Identifier();
1.373 + User::LeaveIfError(iTimeTest.Create(name,TimeThread,KDefaultStackSize*2,KHeapSize,KHeapSize,¶ms,EOwnerThread));
1.374 + TRequestStatus status;
1.375 + iTimeTest.Logon(status);
1.376 + __PROFILE_RESET(8);
1.377 + iTimeTest.Resume();
1.378 + User::WaitForRequest(status);
1.379 +#else
1.380 + TThreadParams params;
1.381 + params.iIndex=aIndex;
1.382 + TimeThread(¶ms);
1.383 +#endif
1.384 + TBuf<64> buf;
1.385 + TBuf<64> buf2;
1.386 + TBuf<64> buf3;
1.387 + CResultDialog *dialog=new(ELeave) CResultDialog(Client()->iGroup, iGc);
1.388 + dialog->ConstructLD();
1.389 +#if USE_PROCESS
1.390 + if (status.Int()==KErrNone)
1.391 + {
1.392 +#endif
1.393 +#if !defined(__PROFILING__)
1.394 + buf=_L("Profiling information not available");
1.395 +#else
1.396 + TProfile profile[6];
1.397 + __PROFILE_DISPLAY(6);
1.398 + for (TInt index=1;index<6;index++)
1.399 + AppendProfileNum(buf2,profile[index].iTime);
1.400 + for (TInt index2=1;index2<6;index2++)
1.401 + AppendProfileCount(buf3,profile[index2].iCount);
1.402 + buf.Format(_L("Time=%d.%2d"),profile[0].iTime/1000000,(profile[0].iTime%1000000)/10000);
1.403 +#endif
1.404 + dialog->SetTitle(buf);
1.405 +#if USE_PROCESS
1.406 + }
1.407 + else
1.408 + {
1.409 + dialog->SetTitle(_L("Error in test"));
1.410 + buf.Format(_L("Error=%d"),status.Int());
1.411 + buf2=iTimeTest.ExitCategory();
1.412 + }
1.413 +#endif
1.414 + dialog->SetLine1(buf2);
1.415 + dialog->SetLine2(buf3);
1.416 + dialog->SetNumButtons(1);
1.417 + dialog->SetButtonText(0,_L("Okay"));
1.418 + if (dialog->Display()!=0)
1.419 + Panic(0);
1.420 + }
1.421 +
1.422 +TPtrC CTestList::GetText(TInt aLine)
1.423 + {
1.424 + return(TPtrC(iTestNames[aLine]));
1.425 + }
1.426 +
1.427 +TInt CTestList::ListCount()
1.428 + {
1.429 + return(iTestNames.Count());
1.430 + }
1.431 +
1.432 +void CTestList::WinKeyL(const TKeyEvent &aKey,const TTime& aTime)
1.433 + {
1.434 + if (aKey.iModifiers&EModifierFunc)
1.435 + {
1.436 + switch(aKey.iCode)
1.437 + {
1.438 + case EKeyLeftArrow:
1.439 + AdjustSize(-Xmove,0,aKey.iModifiers);
1.440 + break;
1.441 + case EKeyRightArrow:
1.442 + AdjustSize(Xmove,0,aKey.iModifiers);
1.443 + break;
1.444 + case EKeyUpArrow:
1.445 + AdjustSize(0,-Ymove,aKey.iModifiers);
1.446 + break;
1.447 + case EKeyDownArrow:
1.448 + AdjustSize(0,Ymove,aKey.iModifiers);
1.449 + break;
1.450 + default:
1.451 + goto not_used;
1.452 + }
1.453 + }
1.454 + else
1.455 + goto not_used;
1.456 + return;
1.457 +not_used:
1.458 + CListWindow::WinKeyL(aKey,aTime);
1.459 + }
1.460 +
1.461 +void CTestList::AppendToListL(const TDesC &aDesc)
1.462 + {
1.463 + TestNameBuf buf(aDesc);
1.464 + iTestNames.AppendL(buf);
1.465 + }
1.466 +
1.467 +//
1.468 +
1.469 +CResultDialog::CResultDialog(CTWindowGroup *aGroupWin,CWindowGc *aGc) : CTDialog(),
1.470 + iGroupWin(aGroupWin),
1.471 + iGc(aGc)
1.472 + {
1.473 + }
1.474 +
1.475 +void CResultDialog::ButtonPressL(TInt aButton)
1.476 + {
1.477 + if (aButton==0)
1.478 + CTDialog::ButtonPressL(aButton);
1.479 + }
1.480 +
1.481 +void CResultDialog::ConstructLD()
1.482 + {
1.483 + CTDialog::ConstructLD(*iGroupWin, *iGc);
1.484 + }
1.485 +
1.486 +//
1.487 +// CTimeTestWindowGroup class //
1.488 +//
1.489 +
1.490 +CTimeTestWindowGroup::CTimeTestWindowGroup(CTClient *aClient) : CTWindowGroup(aClient)
1.491 + {
1.492 + }
1.493 +
1.494 +void CTimeTestWindowGroup::KeyL(const TKeyEvent &aKey,const TTime &aTime)
1.495 + {
1.496 + if (aKey.iModifiers&EModifierFunc)
1.497 + {
1.498 + switch(aKey.iCode)
1.499 + {
1.500 + case 'x':
1.501 + ((CTimeClient *)Client())->Exit();
1.502 + break;
1.503 + }
1.504 + }
1.505 + else
1.506 + iCurWin->WinKeyL(aKey,aTime);
1.507 + }
1.508 +
1.509 +//
1.510 +
1.511 +CTimeClient::CTimeClient()
1.512 + {
1.513 + }
1.514 +
1.515 +CTWin *CTimeClient::CreateTestWindowL(TPoint pos,CTWinBase *parent)
1.516 + {
1.517 + CTWin *win=new(ELeave) CTestList();
1.518 + TRAPD(err,win->ConstructL(*parent));
1.519 + if (err!=KErrNone)
1.520 + goto ctw_err;
1.521 + TRAP(err,win->SetPos(pos));
1.522 + if (err!=KErrNone)
1.523 + {
1.524 +ctw_err:
1.525 + delete win;
1.526 + User::Leave(err);
1.527 + }
1.528 + win->Activate();
1.529 + win->AssignGC(*iGc);
1.530 + return(win);
1.531 + }
1.532 +
1.533 +void CTimeClient::ConstructL()
1.534 + {
1.535 + CTClient::ConstructL();
1.536 +
1.537 + iGroup=new(ELeave) CTimeTestWindowGroup(this);
1.538 + iGroup->ConstructL();
1.539 +
1.540 + CreateTestWindowL(TPoint(30,4),iGroup);
1.541 + iGroup->SetCurrentWindow(iGroup->Child());
1.542 + }
1.543 +
1.544 +void CTimeClient::Exit()
1.545 + {
1.546 + CActiveScheduler::Stop();
1.547 + }
1.548 +
1.549 +GLDEF_C CTClient *CreateClientL()
1.550 + {
1.551 + return(new(ELeave) CTimeClient());
1.552 + }
1.553 +
1.554 +GLDEF_C TInt E32Main()
1.555 + {
1.556 + return(TestLibStartUp(CreateClientL));
1.557 + }