graphicstest/uibench/src/tredrawstoreperf.cpp
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 2008-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 #include "tredrawstoreperf.h"
       
    23 
       
    24 const TInt KIterationsToTest = 100; // Number of iterations to run tests
       
    25 TRect seg1;
       
    26 TRect seg2;
       
    27 TRect seg3;
       
    28 TRect seg4;
       
    29 TRect seg5;
       
    30 TRect seg6;
       
    31 
       
    32 CTRedrawstorePerf::CTRedrawstorePerf()
       
    33 	{
       
    34 	SetTestStepName(KTRedrawstorePerf);
       
    35 	}
       
    36 
       
    37 CTRedrawstorePerf::~CTRedrawstorePerf()
       
    38 	{
       
    39 	delete iGc;
       
    40 	delete iScreenDevice;
       
    41 	iWin.Close();
       
    42 	iWinGroup.Close();
       
    43 	iWs.Close();
       
    44 	}
       
    45 
       
    46 void CTRedrawstorePerf::CreateRWindowL()
       
    47 	{
       
    48 	iWin = RWindow(iWs);
       
    49 	User::LeaveIfError(iWin.Construct(iWinGroup, 2));
       
    50 	User::LeaveIfError(iWin.SetTransparencyAlphaChannel());	
       
    51 	iWin.SetBackgroundColor(TRgb(255,255,255,128 ));
       
    52 	iWin.Activate();
       
    53 	Init();
       
    54 	}
       
    55 
       
    56 void CTRedrawstorePerf::Init()
       
    57 	{
       
    58 	// Create RedrawStore segments
       
    59 	seg1=TRect( TSize( iWin.Size() ) );	
       
    60 	seg2=TRect( TPoint(50,0), seg1.Center()-TPoint(20,20) );
       
    61 	seg3=TRect( TPoint(seg1.Width()/2 + 20, 0), TPoint(seg1.Width()-50, seg1.Height()/2 -20 ) );
       
    62 	seg4=TRect( TPoint(50, seg1.Height()/2 + 20 ), TPoint(seg1.Width()/2 - 20, seg1.Height() ) );
       
    63 	seg5=TRect( seg1.Center()+TPoint(20,20), TPoint( seg1.Width()-50, seg1.Height()) );
       
    64 	seg6=TRect( seg1.Center()-TPoint(75,75), TSize(150,150) );
       
    65 	}
       
    66 
       
    67 /**
       
    68 Override of base class virtual
       
    69 
       
    70 @return - TVerdict code
       
    71 */
       
    72 TVerdict CTRedrawstorePerf::doTestStepPreambleL()
       
    73 	{
       
    74 	CTe_graphicsperformanceSuiteStepBase::doTestStepPreambleL();
       
    75 	return TestStepResult();
       
    76 	}
       
    77 
       
    78 /**
       
    79 Override of base class pure virtual
       
    80 Our implementation only gets called if the base class doTestStepPreambleL() did
       
    81 not leave. That being the case, the current test result value will be EPass.
       
    82 
       
    83 @return TVerdict code
       
    84 */
       
    85 TVerdict CTRedrawstorePerf::doTestStepL()
       
    86 	{
       
    87 	User::LeaveIfError(iWs.Connect());	
       
    88 	iScreenDevice = new(ELeave) CWsScreenDevice(iWs);
       
    89 	User::LeaveIfError(iScreenDevice->Construct(0)); // screen number (0 is first screen)
       
    90 	iGc = new(ELeave) CWindowGc(iScreenDevice);
       
    91 	User::LeaveIfError(iGc->Construct());
       
    92 	iWinGroup = RWindowGroup(iWs);
       
    93 	User::LeaveIfError(iWinGroup.Construct(1, EFalse));
       
    94 
       
    95 	SetTestStepID(_L("GRAPHICS-UI-BENCH-0137"));
       
    96 	TestStoreWithFewRectsL();
       
    97 	RecordTestResultL();
       
    98 	SetTestStepID(_L("GRAPHICS-UI-BENCH-0167"));
       
    99 	TestStoreWithManyRectsL();
       
   100 	RecordTestResultL();
       
   101 	SetTestStepID(_L("GRAPHICS-UI-BENCH-0139"));
       
   102 	TestPlaybackWithFewRectsL();
       
   103 	RecordTestResultL();
       
   104 	SetTestStepID(_L("GRAPHICS-UI-BENCH-0168"));
       
   105 	TestPlaybackWithManyRectsL();
       
   106 	RecordTestResultL();
       
   107 	SetTestStepID(_L("GRAPHICS-UI-BENCH-0141"));
       
   108 	TestStoreAndPlaybackWithFewRectsL();
       
   109 	RecordTestResultL();
       
   110 	SetTestStepID(_L("GRAPHICS-UI-BENCH-0142"));
       
   111 	TestStoreAndPlaybackWithManyRectsL();
       
   112 	RecordTestResultL();
       
   113 	
       
   114 	return TestStepResult();
       
   115 	}
       
   116 
       
   117 void CTRedrawstorePerf::TestStoringL(const TDesC& aTestName, TRedrawstoreTestCase aTestCase)
       
   118 	{
       
   119 	iProfiler->InitResults();
       
   120 	for (TInt count=0; count<KIterationsToTest; count++)
       
   121 		{
       
   122 		CreateRWindowL();
       
   123 		iWin.SetVisible(EFalse); // To make sure no playing back occurs
       
   124 		iWs.Finish();		
       
   125 		iGc->Activate(iWin);
       
   126 		iProfiler->StartTimer();		
       
   127 		if (aTestCase==EFragmentStore)
       
   128 			{
       
   129 			PopulateRedrawStore();
       
   130 			}
       
   131 		else if (aTestCase==EFragmentStoreWithManyRects)
       
   132 			{
       
   133 			PopulateRedrawStoreWithManyRects();
       
   134 			}			
       
   135 		iProfiler->MarkResultSetL();		
       
   136 		iGc->Deactivate();	
       
   137 		iWin.Close();
       
   138 		}
       
   139 	iProfiler->ResultsAnalysis(aTestName, 0, 0, iScreenDevice->DisplayMode(), KIterationsToTest);
       
   140 	}
       
   141 
       
   142 void CTRedrawstorePerf::TestPlayingbackL(const TDesC& aTestName, TRedrawstoreTestCase aTestCase)
       
   143 	{
       
   144 	iProfiler->InitResults();
       
   145 	for (TInt count=0; count<KIterationsToTest; count++)
       
   146 		{
       
   147 		CreateRWindowL();
       
   148 		iGc->Activate(iWin);
       
   149 		if (aTestCase==EFragmentStore)
       
   150 			{
       
   151 			PopulateRedrawStore();
       
   152 			}
       
   153 		else if (aTestCase==EFragmentStoreWithManyRects)
       
   154 			{
       
   155 			PopulateRedrawStoreWithManyRects();
       
   156 			}			
       
   157 		iWin.SetVisible( EFalse );
       
   158 		iWs.Finish();		
       
   159 		iProfiler->StartTimer();
       
   160 		iWin.SetVisible( ETrue );	// Make iWin visible to trigger playing back of redraw cmds
       
   161 		iWs.Finish();
       
   162 		iProfiler->MarkResultSetL();
       
   163 		iGc->Deactivate();	
       
   164 		iWin.Close();
       
   165 		}
       
   166 	iProfiler->ResultsAnalysis(aTestName, 0, 0, iScreenDevice->DisplayMode(), KIterationsToTest);
       
   167 	}
       
   168 
       
   169 void CTRedrawstorePerf::TestStoringAndPlayingbackL(const TDesC& aTestName, TRedrawstoreTestCase aTestCase)
       
   170 	{
       
   171 	iProfiler->InitResults();
       
   172 	for (TInt count=0; count<KIterationsToTest; count++)
       
   173 		{
       
   174 		CreateRWindowL();
       
   175 		iGc->Activate(iWin);
       
   176 		iProfiler->StartTimer();		
       
   177 		if (aTestCase==EFragmentStore)
       
   178 			{
       
   179 			PopulateRedrawStore();
       
   180 			}
       
   181 		else if (aTestCase==EFragmentStoreWithManyRects)
       
   182 			{
       
   183 			PopulateRedrawStoreWithManyRects();
       
   184 			}				
       
   185 		iWs.Finish();
       
   186 		iProfiler->MarkResultSetL();
       
   187 		iGc->Deactivate();	
       
   188 		iWin.Close();
       
   189 		}
       
   190 	iProfiler->ResultsAnalysis(aTestName, 0, 0, iScreenDevice->DisplayMode(), KIterationsToTest);
       
   191 	}
       
   192 
       
   193 
       
   194 // Fragments the fullscreen window by creating segments and drawing overlaping rects across the whole window 
       
   195 void CTRedrawstorePerf::PopulateRedrawStoreWithManyRects()
       
   196 	{
       
   197 	iWin.Invalidate();
       
   198 	iWin.BeginRedraw();
       
   199 	iGc->SetBrushColor(KRgbCyan);
       
   200 	iGc->Clear();
       
   201 	iWin.EndRedraw();
       
   202 
       
   203 	TInt x=0;
       
   204 	TBool offset=EFalse;
       
   205 	for(TInt y=0; y<=seg1.Height(); y+=20)
       
   206 		{
       
   207 		if (offset)
       
   208 			{
       
   209 			x=x+20;
       
   210 			offset=EFalse;
       
   211 			}
       
   212 		else
       
   213 			{
       
   214 			offset=ETrue;
       
   215 			}
       
   216 		
       
   217 		for(; x<=seg1.Width(); x+=40)
       
   218 			{
       
   219 			TRect seg(TPoint(x,y),TSize(30,30));
       
   220 			iWin.Invalidate(seg);
       
   221 			iWin.BeginRedraw(seg);
       
   222 			iGc->SetPenColor(KRgbRed);
       
   223 			iGc->DrawRect(seg);
       
   224 			iWin.EndRedraw();
       
   225 			}
       
   226 		x=0;
       
   227 		}
       
   228 	}
       
   229 
       
   230 void CTRedrawstorePerf::PopulateRedrawStore()
       
   231 	{
       
   232 	iWin.Invalidate(seg1);
       
   233 	iWin.BeginRedraw();
       
   234 	iGc->SetPenColor(KRgbBlack);
       
   235 	iGc->Reset();
       
   236 	iGc->DrawRect(seg1);	
       
   237 	iWin.EndRedraw();
       
   238 	
       
   239 	iWin.Invalidate(seg2);
       
   240 	iWin.BeginRedraw(seg2);
       
   241 	iGc->SetPenColor(KRgbBlack);
       
   242 	iGc->DrawRect(seg2);
       
   243 	iWin.EndRedraw();	
       
   244 	
       
   245 	iWin.Invalidate(seg3);
       
   246 	iWin.BeginRedraw(seg3);
       
   247 	iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   248 	iGc->SetBrushColor(KRgbBlue);
       
   249 	iGc->DrawRect(seg3);
       
   250 	iWin.EndRedraw();
       
   251 	
       
   252 	iWin.Invalidate(seg4);
       
   253 	iWin.BeginRedraw(seg4);
       
   254 	iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   255 	iGc->SetBrushColor(KRgbGreen);
       
   256 	iGc->DrawRect(seg4);
       
   257 	iWin.EndRedraw();
       
   258 		
       
   259 	iWin.Invalidate(seg5);
       
   260 	iWin.BeginRedraw(seg5);
       
   261 	iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   262 	iGc->SetBrushColor(KRgbRed);
       
   263 	iGc->DrawRect(seg5);
       
   264 	iWin.EndRedraw();	
       
   265 		
       
   266 	iWin.Invalidate(seg6);
       
   267 	iWin.BeginRedraw(seg6);
       
   268 	iGc->Reset();
       
   269 	iGc->DrawRect(seg6);
       
   270 	iWin.EndRedraw();
       
   271 	}
       
   272 	
       
   273 /**
       
   274 	@SYMTestCaseID
       
   275 	GRAPHICS-UI-BENCH-0137
       
   276 
       
   277 	@SYMTestCaseDesc
       
   278 	The test case mesures the time it takes to store redraw commands  
       
   279 
       
   280 	@SYMTestActions
       
   281 	A fullscreen window(RWindow) is created and made invisible. The window is then segmented
       
   282  	6 times, drawn to storing the corresponding Redraw Commands and destroyed.
       
   283 
       
   284 	@SYMTestExpectedResults
       
   285 	Test should pass and display average test time per iteration
       
   286 */
       
   287 void CTRedrawstorePerf::TestStoreWithFewRectsL()
       
   288 	{
       
   289 	_LIT(KTestName, "TestStoreWithFewRectsL");
       
   290 	TestStoringL(KTestName,EFragmentStore);
       
   291 	}
       
   292 
       
   293 /**
       
   294 	@SYMTestCaseID
       
   295 	GRAPHICS-UI-BENCH-0167
       
   296 
       
   297 	@SYMTestCaseDesc
       
   298 	A pathological test case. It measures the time it takes to store Redraw commands corresponding to 
       
   299 	hundereds of overlapping segments
       
   300 
       
   301 	@SYMTestActions
       
   302 	A fullscreen window(RWindow) is created and made invisible. The window is then segmented
       
   303  	a few hundered times, drawn to storing the corresponding Redraw Commands and destroyed.
       
   304 
       
   305 	@SYMTestExpectedResults
       
   306 	Test should pass and display average test time per iteration
       
   307 */
       
   308 void CTRedrawstorePerf::TestStoreWithManyRectsL()
       
   309 	{
       
   310 	_LIT(KTestName, "TestStoreWithManyRectsL");
       
   311 	TestStoringL(KTestName,EFragmentStoreWithManyRects);
       
   312 	}
       
   313 
       
   314 /**
       
   315 	@SYMTestCaseID
       
   316 	GRAPHICS-UI-BENCH-0139
       
   317 
       
   318 	@SYMTestCaseDesc
       
   319 	This test case measures the time it takes to play back the commands from the RedrawStore
       
   320 
       
   321 	@SYMTestActions
       
   322 	A fullscreen window(RWindow) is created, segmented 6 times and drawn to storing the corresponding
       
   323 	Redraw Commands. It is made invisible and then visible again which triggers the playing back of 
       
   324 	commands.The time is measured between when the window is made visible and the screen has been rendered.
       
   325 	The time is logged and window is destroyed.
       
   326 	
       
   327 	@SYMTestExpectedResults
       
   328 	Test should pass and display average test time per iteration
       
   329 */
       
   330 void CTRedrawstorePerf::TestPlaybackWithFewRectsL()
       
   331 	{
       
   332 	_LIT(KTestName, "TestPlaybackWithFewRectsL");
       
   333 	TestPlayingbackL(KTestName,EFragmentStore);
       
   334 	}
       
   335 
       
   336 /**
       
   337 	@SYMTestCaseID
       
   338 	GRAPHICS-UI-BENCH-0168
       
   339 
       
   340 	@SYMTestCaseDesc
       
   341 	A pathological test case. It measures the time it takes to play back the commands corresponding to 
       
   342 	hundereds of overlapping segments, from the RedrawStore
       
   343 
       
   344 	@SYMTestActions
       
   345 	A fullscreen window(RWindow) is created, segmented a few hundered times and drawn to storing the
       
   346 	corresponding Redraw Commands. It is made invisible and then visible again which triggers the playing
       
   347 	back of commands.The time is measured between when the window is made visible and the screen has been
       
   348 	rendered. The time is logged and window is destroyed.
       
   349 
       
   350 	@SYMTestExpectedResults
       
   351 	Test should pass and display average test time per iteration
       
   352 */
       
   353 void CTRedrawstorePerf::TestPlaybackWithManyRectsL()
       
   354 	{
       
   355 	_LIT(KTestName, "TestPlaybackWithManyRectsL");
       
   356 	TestPlayingbackL(KTestName,EFragmentStoreWithManyRects);
       
   357 	}
       
   358 
       
   359 /**
       
   360 	@SYMTestCaseID
       
   361 	GRAPHICS-UI-BENCH-0141
       
   362 
       
   363 	@SYMTestCaseDesc
       
   364 	This test cases measures the time it takes to store and play back redraw commands from the RedrawStore
       
   365 
       
   366 	@SYMTestActions
       
   367 	A fullscreen window(RWindow) is created, segmented 6 times and drawn to storing the corresponding
       
   368 	Redraw Commands. Finish() is called then to trigger the playing back from RedrawStore. The time it takes
       
   369 	to store and play back commands is logged and window is destroyed. 
       
   370 
       
   371 	@SYMTestExpectedResults
       
   372 	Test should pass and display average test time per iteration
       
   373 */
       
   374 void CTRedrawstorePerf::TestStoreAndPlaybackWithFewRectsL()
       
   375 	{
       
   376 	_LIT(KTestName, "TestStoreAndPlaybackWithFewRectsL");
       
   377 	TestStoringAndPlayingbackL(KTestName,EFragmentStore);
       
   378 	}
       
   379 
       
   380 /**
       
   381 	@SYMTestCaseID
       
   382 	GRAPHICS-UI-BENCH-0142
       
   383 
       
   384 	@SYMTestCaseDesc
       
   385 	A pathological test case. It measures the time it takes to store and playback commands corresponding to 
       
   386 	hundereds of overlapping segments, from RedrawStore
       
   387 
       
   388 	@SYMTestActions
       
   389 	A fullscreen window(RWindow) is created, segmented a few hundered times and drawn to storing the
       
   390 	corresponding Redraw Commands. Finish() is called then to render the screen by playing back the
       
   391 	commands from the RedrawStore. The time it takes to store and play back commands is logged and window
       
   392 	is destroyed. 
       
   393 
       
   394 	@SYMTestExpectedResults
       
   395 	Test should pass and display average test time per iteration
       
   396 */	
       
   397 void CTRedrawstorePerf::TestStoreAndPlaybackWithManyRectsL()
       
   398 	{
       
   399 	_LIT(KTestName, "TestStoreAndPlaybackWithManyRectsL");
       
   400 	TestStoringAndPlayingbackL(KTestName,EFragmentStoreWithManyRects);
       
   401 	}