graphicstest/uibench/src/tnonredrawdrawing.cpp
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 2007-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 "tnonredrawdrawing.h"
       
    23 #include <gdi.h>
       
    24 #include <hal.h>
       
    25 
       
    26 
       
    27 const TInt KIterationsToTest = 100; // Number of iterations to run tests
       
    28 
       
    29 
       
    30 CTNonRedrawDrawing::CTNonRedrawDrawing()
       
    31 	{
       
    32 	SetTestStepName(KTNonRedrawDrawing);
       
    33 	}
       
    34 
       
    35 CTNonRedrawDrawing::~CTNonRedrawDrawing()
       
    36 	{
       
    37 	delete iWindowGc;
       
    38 	delete iScreenDevice;
       
    39 	iBackgroundWindow.Close();
       
    40 	iWinGroup.Close();
       
    41 	iWsSession.Close();
       
    42 	RFbsSession::Disconnect();
       
    43 	}
       
    44 
       
    45 /**
       
    46 @SYMTestCaseID GRAPHICS-UI-BENCH-0075
       
    47 @SYMTestType UT
       
    48 @SYMTestPriority Critical
       
    49 @SYMDEF PDEF102791
       
    50 
       
    51 @SYMTestCaseDesc
       
    52 The test determines how long it takes to do non-redraw drawing on a transparent window
       
    53 compared to non-redraw drawing on an opaque window.
       
    54 
       
    55 @SYMTestActions
       
    56 The test creates a background window that takes a relatively long time to render from its
       
    57 redraw store by issuing a number of ellipse drawing commands. After that it creates a
       
    58 foreground window, opaque then transparent, and does some non-redraw drawing on it for a
       
    59 number of iterations.
       
    60 
       
    61 @SYMTestExpectedResults
       
    62 The test should pass and display test time both using an opaque window and a transparent one.
       
    63 */
       
    64 void CTNonRedrawDrawing::NonRedrawDrawingL(TTestCase aTestCase)
       
    65 	{
       
    66 	iProfiler->InitResults();
       
    67 	// Create foreground window
       
    68 	RWindow foregroundWindow = RWindow(iWsSession);
       
    69 	User::LeaveIfError(foregroundWindow.Construct(iWinGroup, 3));
       
    70 	CleanupClosePushL(foregroundWindow);
       
    71 	if (aTestCase == EUseTransparencyFactor)
       
    72 		User::LeaveIfError(foregroundWindow.SetTransparencyFactor(TRgb(0xAA, 0xAA, 0xAA)));
       
    73 	foregroundWindow.Activate();
       
    74 	for (TInt i = KIterationsToTest; i > 0; --i)
       
    75 		{
       
    76 		// Initialize its redraw store
       
    77 		foregroundWindow.BeginRedraw();
       
    78 		iWindowGc->Activate(foregroundWindow);
       
    79 		iWindowGc->SetBrushColor(KRgbYellow);
       
    80 		iWindowGc->Clear();
       
    81 		iWindowGc->Deactivate();
       
    82 		foregroundWindow.EndRedraw();
       
    83 		iWsSession.Flush();
       
    84 		iProfiler->StartTimer();
       
    85 		// Now do some non-redraw drawing
       
    86 		iWindowGc->Activate(foregroundWindow);
       
    87 		iWindowGc->SetBrushColor(KRgbRed);
       
    88 		for (TInt x = 0; x < 200; x += 4)
       
    89 			iWindowGc->Clear(TRect(x, x, x + 4, x + 4));
       
    90 		iWindowGc->Deactivate();
       
    91 		iWsSession.Flush();
       
    92 		iProfiler->MarkResultSetL();
       
    93 		// Empty redraw store to avoid OOM
       
    94 		foregroundWindow.Invalidate();
       
    95 		}
       
    96 	CleanupStack::PopAndDestroy(&foregroundWindow);
       
    97 	}
       
    98 
       
    99 /**
       
   100 Override of base class virtual
       
   101 
       
   102 @return - TVerdict code
       
   103 */
       
   104 TVerdict CTNonRedrawDrawing::doTestStepPreambleL()
       
   105 	{
       
   106 	CTe_graphicsperformanceSuiteStepBase::doTestStepPreambleL();
       
   107 	User::LeaveIfError(RFbsSession::Connect());
       
   108 	User::LeaveIfError(iWsSession.Connect());
       
   109 	iScreenDevice = new(ELeave) CWsScreenDevice(iWsSession);
       
   110 	User::LeaveIfError(iScreenDevice->Construct(0)); // screen number (0 is first screen)
       
   111 	iWindowGc = new(ELeave) CWindowGc(iScreenDevice);
       
   112 	User::LeaveIfError(iWindowGc->Construct());
       
   113 	iWinGroup = RWindowGroup(iWsSession);
       
   114 	User::LeaveIfError(iWinGroup.Construct(1, EFalse));
       
   115 	// Create background window
       
   116 	iBackgroundWindow = RWindow(iWsSession);
       
   117 	User::LeaveIfError(iBackgroundWindow.Construct(iWinGroup, 2));
       
   118 	iBackgroundWindow.SetRequiredDisplayMode(EColor64K);
       
   119 	iBackgroundWindow.Activate();
       
   120 	// Initialize its redraw store with time-consuming ellipse drawing commands
       
   121 	iBackgroundWindow.BeginRedraw();
       
   122 	iWindowGc->Activate(iBackgroundWindow);
       
   123 	TSize size = iBackgroundWindow.Size();
       
   124 	for (TInt x = 0; x < 80; x += 4)
       
   125 		{
       
   126 		iWindowGc->SetPenColor(TRgb(0, x << 1, 0xFF));
       
   127 		iWindowGc->DrawEllipse(TRect(x, x, size.iWidth - x, size.iHeight - x));
       
   128 		}
       
   129 	iWindowGc->Deactivate();
       
   130 	iBackgroundWindow.EndRedraw();
       
   131 	iWsSession.Flush();
       
   132 	return TestStepResult();
       
   133 	}
       
   134 
       
   135 /**
       
   136 Override of base class pure virtual
       
   137 Our implementation only gets called if the base class doTestStepPreambleL() did
       
   138 not leave. That being the case, the current test result value will be EPass.
       
   139 
       
   140 @return TVerdict code
       
   141 */
       
   142 TVerdict CTNonRedrawDrawing::doTestStepL()
       
   143 	{
       
   144 	SetTestStepID(_L("GRAPHICS-UI-BENCH-0075"));
       
   145 	NonRedrawDrawingL(EUseOpaqueDraw);
       
   146 	iProfiler->ResultsAnalysis(_L("Opaque Non-Redraw Drawing"), 0, 0, EColor64K, KIterationsToTest);
       
   147 	NonRedrawDrawingL(EUseTransparencyFactor);
       
   148 	iProfiler->ResultsAnalysis(_L("Transparent Non-Redraw Drawing"), 0, 0, EColor64K, KIterationsToTest);
       
   149 	RecordTestResultL();
       
   150 	return TestStepResult();
       
   151 	}