os/graphics/graphicstest/uibench/src/ttranslucent.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
/**
sl@0
    17
 @file
sl@0
    18
 @test
sl@0
    19
 @internalComponent - Internal Symbian test code 
sl@0
    20
*/
sl@0
    21
sl@0
    22
#include "ttranslucent.h"
sl@0
    23
sl@0
    24
const TInt KIterationsToTest = 100;
sl@0
    25
sl@0
    26
//
sl@0
    27
// CTTranslucent
sl@0
    28
//
sl@0
    29
CTTranslucent::CTTranslucent()
sl@0
    30
	{
sl@0
    31
	SetTestStepName(KTTranslucent);
sl@0
    32
	}
sl@0
    33
sl@0
    34
CTTranslucent::~CTTranslucent()
sl@0
    35
	{
sl@0
    36
	iWindowArray.ResetAndDestroy();
sl@0
    37
	iWindowArray.Close();
sl@0
    38
    delete iTopWindow;
sl@0
    39
    delete iBottomWindow;
sl@0
    40
    delete iBitmap; 
sl@0
    41
sl@0
    42
    delete iGc;
sl@0
    43
    delete iScreen;
sl@0
    44
	iWindowGroup.Close();
sl@0
    45
	iWsSession.Close();
sl@0
    46
	}	
sl@0
    47
sl@0
    48
/**
sl@0
    49
Override of base class virtual
sl@0
    50
sl@0
    51
@return - TVerdict code
sl@0
    52
*/
sl@0
    53
TVerdict CTTranslucent::doTestStepPreambleL()
sl@0
    54
	{	
sl@0
    55
	CTe_graphicsperformanceSuiteStepBase::doTestStepPreambleL();	
sl@0
    56
	SetScreenModeL(EColor16MU);
sl@0
    57
	return TestStepResult();
sl@0
    58
	}
sl@0
    59
	
sl@0
    60
TVerdict CTTranslucent::doTestStepL()
sl@0
    61
	{
sl@0
    62
    User::LeaveIfError(iWsSession.Connect());
sl@0
    63
    
sl@0
    64
    iWindowGroup=RWindowGroup(iWsSession);
sl@0
    65
    User::LeaveIfError(iWindowGroup.Construct(2, ETrue)); // meaningless handle; enable focus
sl@0
    66
sl@0
    67
    // construct screen device and graphics context
sl@0
    68
    iScreen=new (ELeave) CWsScreenDevice(iWsSession); // make device for this session
sl@0
    69
    User::LeaveIfError(iScreen->Construct()); // and complete its construction
sl@0
    70
    User::LeaveIfError(iScreen->CreateContext(iGc)); // create graphics context
sl@0
    71
sl@0
    72
    iScreenRect = TRect(0,0,iScreen->SizeInPixels().iWidth, iScreen->SizeInPixels().iHeight);
sl@0
    73
sl@0
    74
    // Construct a gradient bitmap for use by bitmap test
sl@0
    75
	CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
sl@0
    76
	CleanupStack::PushL(bitmap);
sl@0
    77
	User::LeaveIfError(bitmap->Create(TSize(80,80), EColor16MA));
sl@0
    78
	CTe_graphicsperformanceSuiteStepBase::VerticalGradientAlphaL(bitmap, TRgb(0x000000ff), TRgb(0xff000000));
sl@0
    79
	delete iBitmap;
sl@0
    80
	iBitmap = bitmap;
sl@0
    81
	CleanupStack::Pop(bitmap);
sl@0
    82
sl@0
    83
	/**
sl@0
    84
	@SYMTestCaseID GRAPHICS-UI-BENCH-0132
sl@0
    85
	@SYMPREQ PREQ1841
sl@0
    86
	@SYMTestCaseDesc Measures time taken to redraw 2, 8, 32 and 144 blank translucent
sl@0
    87
					 partially overlapping windows.
sl@0
    88
	@SYMTestActions
sl@0
    89
	1. Create blank translucent partially overlapping windows.
sl@0
    90
	2. Cover them all with an "ontop" window.
sl@0
    91
	3. Hide the "ontop" window and measure time taken to redraw all overlapping windows underneath.
sl@0
    92
	4. Repeat KIterationsToTest times and calculate average time per iteration.
sl@0
    93
sl@0
    94
	@SYMTestExpectedResults
sl@0
    95
	As the number of windows increases, so should the time taken to redraw them.
sl@0
    96
	*/	
sl@0
    97
	SetTestStepID(_L("GRAPHICS-UI-BENCH-0132"));
sl@0
    98
	RunTestCaseL(_L("Redraw-BlankWindows2"), EBlankWindows, 2, 1);
sl@0
    99
	RunTestCaseL(_L("Redraw-BlankWindows8"), EBlankWindows, 2, 4);
sl@0
   100
	RunTestCaseL(_L("Redraw-BlankWindows32"), EBlankWindows, 4, 8);
sl@0
   101
	RunTestCaseL(_L("Redraw-BlankWindows144"), EBlankWindows, 12, 12);
sl@0
   102
	RecordTestResultL();
sl@0
   103
sl@0
   104
	/**
sl@0
   105
	@SYMTestCaseID GRAPHICS-UI-BENCH-0133
sl@0
   106
	@SYMPREQ PREQ1841
sl@0
   107
	@SYMTestCaseDesc Measures time taken to redraw 2, 8, 32 and 144 translucent
sl@0
   108
					 partially overlapping windows containing drawn text.
sl@0
   109
	@SYMTestActions
sl@0
   110
	1. Create translucent partially overlapping windows.
sl@0
   111
	2. Cover them all with an "ontop" window.
sl@0
   112
	3. Hide the "ontop" window and measure time taken to redraw all overlapping windows underneath.
sl@0
   113
	4. Repeat KIterationsToTest times and calculate average time per iteration.
sl@0
   114
sl@0
   115
	@SYMTestExpectedResults
sl@0
   116
	As the number of windows increases, so should the time taken to redraw them.
sl@0
   117
	*/	
sl@0
   118
	SetTestStepID(_L("GRAPHICS-UI-BENCH-0133"));
sl@0
   119
	RunTestCaseL(_L("Redraw-TextWindows2"), ETextWindows, 2, 1);
sl@0
   120
	RunTestCaseL(_L("Redraw-TextWindows8"), ETextWindows, 2, 4);
sl@0
   121
	RunTestCaseL(_L("Redraw-TextWindows32"), ETextWindows, 4, 8);
sl@0
   122
	RunTestCaseL(_L("Redraw-TextWindows144"), ETextWindows, 12, 12);
sl@0
   123
	RecordTestResultL();
sl@0
   124
sl@0
   125
	/**
sl@0
   126
	@SYMTestCaseID GRAPHICS-UI-BENCH-0134
sl@0
   127
	@SYMPREQ PREQ1841
sl@0
   128
	@SYMTestCaseDesc Measures time taken to redraw 2, 8, 32 and 144 translucent
sl@0
   129
					 partially overlapping windows containing drawn ellipsis.
sl@0
   130
	@SYMTestActions
sl@0
   131
	1. Create translucent partially overlapping windows.
sl@0
   132
	2. Cover them all with an "ontop" window.
sl@0
   133
	3. Hide the "ontop" window and measure time taken to redraw all overlapping windows underneath.
sl@0
   134
	4. Repeat KIterationsToTest times and calculate average time per iteration.
sl@0
   135
sl@0
   136
	@SYMTestExpectedResults
sl@0
   137
	As the number of windows increases, so should the time taken to redraw them.
sl@0
   138
	*/	
sl@0
   139
	SetTestStepID(_L("GRAPHICS-UI-BENCH-0134"));
sl@0
   140
	RunTestCaseL(_L("Redraw-EllipseWindows2"), EEllipseWindows, 2, 1);
sl@0
   141
	RunTestCaseL(_L("Redraw-EllipseWindows8"), EEllipseWindows, 2, 4);
sl@0
   142
	RunTestCaseL(_L("Redraw-EllipseWindows32"), EEllipseWindows, 4, 8);
sl@0
   143
	RunTestCaseL(_L("Redraw-EllipseWindows144"), EEllipseWindows, 12, 12);
sl@0
   144
	RecordTestResultL();
sl@0
   145
sl@0
   146
	/**
sl@0
   147
	@SYMTestCaseID GRAPHICS-UI-BENCH-0135
sl@0
   148
	@SYMPREQ PREQ1841
sl@0
   149
	@SYMTestCaseDesc Measures time taken to redraw 2, 8, 32 and 144 translucent
sl@0
   150
					 partially overlapping windows containing bitmaps.
sl@0
   151
	@SYMTestActions
sl@0
   152
	1. Create translucent partially overlapping windows.
sl@0
   153
	2. Cover them all with an "ontop" window.
sl@0
   154
	3. Hide the "ontop" window and measure time taken to redraw all overlapping windows underneath.
sl@0
   155
	4. Repeat KIterationsToTest times and calculate average time per iteration.
sl@0
   156
sl@0
   157
	@SYMTestExpectedResults
sl@0
   158
	As the number of windows increases, so should the time taken to redraw them.
sl@0
   159
	*/	
sl@0
   160
	SetTestStepID(_L("GRAPHICS-UI-BENCH-0135"));
sl@0
   161
	RunTestCaseL(_L("Redraw-BitmapWindows2"), EBitmapWindows, 2, 1);
sl@0
   162
	RunTestCaseL(_L("Redraw-BitmapWindows8"), EBitmapWindows, 2, 4);
sl@0
   163
	RunTestCaseL(_L("Redraw-BitmapWindows32"), EBitmapWindows, 4, 8);
sl@0
   164
	RunTestCaseL(_L("Redraw-BitmapWindows144"), EBitmapWindows, 12, 12);
sl@0
   165
	RecordTestResultL();
sl@0
   166
		
sl@0
   167
	return TestStepResult();
sl@0
   168
	}
sl@0
   169
sl@0
   170
void CTTranslucent::RunTestCaseL(const TDesC& aTestName, TTestCase aTestCase, TInt aHorizontalWindows, TInt aVerticalWindows)
sl@0
   171
	{
sl@0
   172
	iTestCase = aTestCase;
sl@0
   173
sl@0
   174
	ConstructWindowsL(aHorizontalWindows, aVerticalWindows);
sl@0
   175
	iWsSession.Finish(); // Make sure all windows are drawn in their initial state/positions
sl@0
   176
sl@0
   177
	iProfiler->InitResults();
sl@0
   178
sl@0
   179
	// Measure time taken to redraw all overlapping translucent windows
sl@0
   180
	// and repeat KIterationsToTest times
sl@0
   181
	for (int i = 0; i < KIterationsToTest; i++)
sl@0
   182
		{
sl@0
   183
		iProfiler->StartTimer();
sl@0
   184
		iTopWindow->Window().SetVisible(EFalse); // hide ontop window to cause overlapping translucent windows to be redrawn
sl@0
   185
		iWsSession.Finish();
sl@0
   186
		iProfiler->MarkResultSetL();
sl@0
   187
sl@0
   188
		iTopWindow->Window().SetVisible(ETrue); // show ontop window
sl@0
   189
		iWsSession.Finish();
sl@0
   190
		}
sl@0
   191
sl@0
   192
	iProfiler->ResultsAnalysis(aTestName, 0, 0, ScreenDevice()->BitmapDevice().DisplayMode(), KIterationsToTest);
sl@0
   193
	
sl@0
   194
	DestroyWindows();
sl@0
   195
	}
sl@0
   196
sl@0
   197
void CTTranslucent::ConstructWindowsL(TInt aHorizontalWindows, TInt aVerticalWindows)
sl@0
   198
	{
sl@0
   199
	// Create a yellow opaque window to use as the background for the translucent windows
sl@0
   200
    iBottomWindow = new (ELeave) CWin(iWsSession, iWindowGroup);
sl@0
   201
    iBottomWindow->ConstructL(iScreenRect);
sl@0
   202
    iBottomWindow->Window().SetBackgroundColor(TRgb(255, 255, 0));
sl@0
   203
    iBottomWindow->Window().SetOrdinalPosition(-1);
sl@0
   204
    iBottomWindow->Window().Invalidate();
sl@0
   205
    iBottomWindow->Window().BeginRedraw();
sl@0
   206
    iBottomWindow->Window().EndRedraw();
sl@0
   207
    iBottomWindow->Window().Activate();
sl@0
   208
sl@0
   209
	// Create some green partially overlapping translucent windows.
sl@0
   210
	// Each window has roughly the same aspect ratio as the screen.
sl@0
   211
	// Each window is the same size for every test, regardless of how many windows are being created.
sl@0
   212
sl@0
   213
    // Maximum number of windows horizontally and vertically that we want to be able to fit onto
sl@0
   214
    // the screen. Window size is calculated based on screen width/height and number of windows we want
sl@0
   215
    // to fit in with the desired overlap.
sl@0
   216
    // KMaxWindows * KMaxWindows gives the total maximum number of windows that will fit on screen without
sl@0
   217
    // being clipped.
sl@0
   218
	const TInt KMaxWindows = 12;
sl@0
   219
	
sl@0
   220
	// Calculate 1/4 width of each window
sl@0
   221
	const TInt KQuarterWidth = iScreenRect.Width() / (KMaxWindows + 3);
sl@0
   222
	// Calculate 1/4 height of each window
sl@0
   223
	const TInt KQuarterHeight = iScreenRect.Height() / (KMaxWindows + 3);
sl@0
   224
sl@0
   225
	TRect rect(0, 0, 0, 0);
sl@0
   226
	TInt x = 0;
sl@0
   227
	TInt y = 0;
sl@0
   228
	// Calculate size used for all translucent windows
sl@0
   229
	TSize size(KQuarterWidth*4, KQuarterHeight*4);
sl@0
   230
	TInt hCount = 0;
sl@0
   231
	TInt vCount = 0;
sl@0
   232
	for (hCount = 0; hCount < aHorizontalWindows; hCount++)
sl@0
   233
		{
sl@0
   234
		y = 0;
sl@0
   235
		for (vCount = 0; vCount < aVerticalWindows; vCount++)
sl@0
   236
			{
sl@0
   237
			// Construct a vertical column of windows
sl@0
   238
			CWin* win = new(ELeave) CWin(iWsSession, iWindowGroup);
sl@0
   239
			CleanupStack::PushL(win);
sl@0
   240
			iWindowArray.AppendL(win);
sl@0
   241
			CleanupStack::Pop(win);
sl@0
   242
			rect.iTl = TPoint(x, y);
sl@0
   243
			rect.SetSize(size);
sl@0
   244
			win->ConstructL(rect);
sl@0
   245
			User::LeaveIfError(win->Window().SetTransparencyAlphaChannel());
sl@0
   246
			win->Window().SetBackgroundColor(TRgb(0, 255, 0, 16));
sl@0
   247
sl@0
   248
			TRect clipRect(size);
sl@0
   249
			DrawWindowL(win, clipRect);
sl@0
   250
			win->Window().Activate();
sl@0
   251
			y+=KQuarterHeight;
sl@0
   252
			}
sl@0
   253
		x+=KQuarterWidth;
sl@0
   254
		}
sl@0
   255
sl@0
   256
	// Create a red opaque window ontop of all the others
sl@0
   257
	iTopWindow = new (ELeave) CWin(iWsSession, iWindowGroup);
sl@0
   258
	iTopWindow->ConstructL(iScreenRect);
sl@0
   259
	iTopWindow->Window().SetBackgroundColor(TRgb(255, 0, 0));
sl@0
   260
	iTopWindow->Window().SetOrdinalPosition(0);
sl@0
   261
	iTopWindow->Window().Invalidate();
sl@0
   262
	iTopWindow->Window().BeginRedraw();
sl@0
   263
	iTopWindow->Window().EndRedraw();
sl@0
   264
	iTopWindow->Window().Activate();
sl@0
   265
	}
sl@0
   266
sl@0
   267
void CTTranslucent::DestroyWindows()
sl@0
   268
	{
sl@0
   269
	iWindowArray.ResetAndDestroy();
sl@0
   270
    delete iTopWindow;
sl@0
   271
    iTopWindow = NULL;
sl@0
   272
    delete iBottomWindow;
sl@0
   273
	iBottomWindow = NULL;
sl@0
   274
	}
sl@0
   275
sl@0
   276
void CTTranslucent::DrawWindowL(CWin* aWindow, const TRect& aRect)
sl@0
   277
	{
sl@0
   278
	iGc->Activate(aWindow->Window());
sl@0
   279
    iGc->SetClippingRect(aRect);
sl@0
   280
	aWindow->Window().Invalidate();
sl@0
   281
	aWindow->Window().BeginRedraw();
sl@0
   282
sl@0
   283
	// Draw the whole window
sl@0
   284
    switch(iTestCase)
sl@0
   285
    	{
sl@0
   286
    	case EBlankWindows:
sl@0
   287
    		break; // Don't draw anything on the blank windows
sl@0
   288
sl@0
   289
    	case ETextWindows:
sl@0
   290
    		{
sl@0
   291
    		CFont* font;
sl@0
   292
    		TFontSpec fontSpec;
sl@0
   293
    		fontSpec.iHeight = 300;
sl@0
   294
    		User::LeaveIfError(iGc->Device()->GetNearestFontToDesignHeightInTwips(font, fontSpec));
sl@0
   295
    		iGc->UseFont(font);
sl@0
   296
    		iGc->DrawText(_L("Text"), TPoint(0,20));
sl@0
   297
    		iGc->DrawText(_L("window"), TPoint(0,40));
sl@0
   298
    		iGc->DiscardFont();
sl@0
   299
    		iGc->Device()->ReleaseFont(font);
sl@0
   300
    		break;
sl@0
   301
    		}
sl@0
   302
sl@0
   303
    	case EEllipseWindows:
sl@0
   304
    		iGc->SetPenColor(TRgb(0, 0, 0, 255));
sl@0
   305
    		iGc->SetBrushColor(TRgb(128, 128, 255, 128));
sl@0
   306
    		iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
sl@0
   307
    		iGc->DrawEllipse(TRect(0,0,79,79));
sl@0
   308
    		iGc->DrawEllipse(TRect(10,10,69,69));
sl@0
   309
    		iGc->DrawEllipse(TRect(20,20,59,59));
sl@0
   310
    		iGc->DrawEllipse(TRect(30,30,49,49));
sl@0
   311
    		iGc->SetBrushColor(TRgb(255, 0, 0, 150));
sl@0
   312
    		iGc->SetBrushStyle(CGraphicsContext::EDiamondCrossHatchBrush);
sl@0
   313
    		iGc->DrawEllipse(TRect(0,0,20,15));
sl@0
   314
    		iGc->DrawEllipse(TRect(30,10,50,30));
sl@0
   315
    		break;
sl@0
   316
    	case EBitmapWindows:
sl@0
   317
    		iGc->BitBlt(TPoint(0,0), iBitmap);
sl@0
   318
    		break;
sl@0
   319
    	}
sl@0
   320
sl@0
   321
	aWindow->Window().EndRedraw();
sl@0
   322
	iGc->Deactivate();
sl@0
   323
	}
sl@0
   324
sl@0
   325
//
sl@0
   326
// CWin
sl@0
   327
//
sl@0
   328
CTTranslucent::CWin::CWin(RWsSession& aWsSession, RWindowGroup& aWindowGroup)
sl@0
   329
	:iWsSession(aWsSession), iWindowGroup(aWindowGroup)
sl@0
   330
    {
sl@0
   331
    }
sl@0
   332
sl@0
   333
CTTranslucent::CWin::~CWin()
sl@0
   334
    {
sl@0
   335
    iWindow.Close();
sl@0
   336
    }
sl@0
   337
sl@0
   338
void CTTranslucent::CWin::ConstructL (const TRect& aRect)
sl@0
   339
    {
sl@0
   340
    iWindow=RWindow(iWsSession);
sl@0
   341
    User::LeaveIfError(iWindow.Construct(iWindowGroup, (TUint32)this));
sl@0
   342
    iRect = aRect;
sl@0
   343
    iWindow.SetExtent(iRect.iTl, iRect.Size());
sl@0
   344
    }
sl@0
   345
sl@0
   346
RWindow& CTTranslucent::CWin::Window()
sl@0
   347
	{
sl@0
   348
	return iWindow;
sl@0
   349
	}