os/graphics/windowing/windowserver/test/t_integ/src/t_fpsappeng.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     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
    20 */
    21 
    22 #include <libc/limits.h> //UINT_MAX
    23 #include "t_fpsappeng.h"
    24 #include "t_pseudoapputils.h"
    25 
    26 const TInt KSurfaceWidth = 640;
    27 const TInt KSurfaceHeight = 240;
    28 const TUidPixelFormat KSurfaceFormat = EUidPixelFormatXRGB_8888;
    29 const TInt KBytesPerPixel = 4;	// Four bytes per pixel for the format above.
    30 
    31 CFpsAppEng::CFpsAppEng(RWsSession& aClient, CWsScreenDevice& aScreenDevice, RWindow& aWindow)
    32 : CTimer(CActive::EPriorityStandard),
    33 	iClient(aClient),
    34 	iWindow(aWindow),
    35 	iScreenDevice(aScreenDevice)
    36 	{
    37 	}
    38 
    39 CFpsAppEng* CFpsAppEng::NewL(RWsSession& aClient, CWsScreenDevice& aScreenDevice, RWindow& aWindow)
    40     {
    41     CFpsAppEng* self = new (ELeave) CFpsAppEng(aClient, aScreenDevice, aWindow);
    42     CleanupStack::PushL(self);
    43     self->ConstructL();
    44     CleanupStack::Pop(); // self;
    45     return self;
    46     }
    47 
    48 CFpsAppEng::~CFpsAppEng()
    49 	{
    50     if(IsActive())
    51     	{
    52 	    Cancel();
    53     	}
    54 	
    55 	User::Free(iBufPtr1);
    56 	DestroySurface();
    57 	    	
    58 	//Pause to allow the test step to kill the app
    59 	User::After(1000000);
    60 	}
    61 
    62 void CFpsAppEng::ConstructL()
    63 	{
    64 	CTimer::ConstructL();
    65 
    66 	iNoOfPixels = KSurfaceHeight*KSurfaceWidth;
    67 	iNoOfBytes = iNoOfPixels*KBytesPerPixel;
    68 
    69 	// Allocate a memory block
    70 	iBufPtr1 = reinterpret_cast<TUint32*>(User::AllocL(iNoOfBytes));
    71 	
    72 	RDebug::Print(_L("Creating Surface manager..."));
    73 	CreateSurfaceManager();
    74 	RDebug::Print(_L("Creating Surface..."));
    75 	CreateSurface(iSurfaceId);
    76 	RDebug::Print(_L("Create Surface update session..."));
    77 	CreateSurfaceUpdateSessionL();
    78 	
    79 	CActiveScheduler::Add(this);
    80 	}
    81 
    82 void CFpsAppEng::StartDrawing()
    83 	{	
    84 	//A value of 0 will provoke a E32User-Cbase 46 panic
    85 	After(TTimeIntervalMicroSeconds32(100000));
    86 	}
    87 
    88 void CFpsAppEng::CreateSurfaceManager()
    89 	{
    90 	TInt ret = iSurfaceManager.Open();
    91 	if(ret==KErrNone)
    92 		{
    93 		RDebug::Print(_L("Creating surface manager OK"));
    94 		}
    95 	}
    96 
    97 
    98 void CFpsAppEng::CreateSurface(TSurfaceId& aSurfaceId)
    99 	{
   100 	RSurfaceManager::TSurfaceCreationAttributesBuf attribs;
   101 	RSurfaceManager::TSurfaceCreationAttributes& surfaceCreationAtribs=attribs();
   102 	surfaceCreationAtribs.iSize.iWidth = KSurfaceWidth;
   103 	surfaceCreationAtribs.iSize.iHeight = KSurfaceHeight;
   104 	surfaceCreationAtribs.iBuffers = 2;
   105 	surfaceCreationAtribs.iPixelFormat = KSurfaceFormat;
   106 	surfaceCreationAtribs.iStride = KBytesPerPixel*KSurfaceWidth;
   107 	surfaceCreationAtribs.iOffsetToFirstBuffer = 0;
   108 	surfaceCreationAtribs.iAlignment = 4;
   109 	surfaceCreationAtribs.iContiguous = EFalse;
   110 	surfaceCreationAtribs.iMappable = ETrue;
   111 	
   112 	TInt err = iSurfaceManager.CreateSurface(attribs, aSurfaceId);
   113 	if (err == KErrNone)
   114 		{
   115 		err = iSurfaceManager.MapSurface(aSurfaceId, iChunk);
   116 		}		
   117 	if (err == KErrNone)
   118 		{
   119 		RDebug::Print(_L("Surface created: OK"));
   120 		}
   121 		
   122 	iSurfacePtr = reinterpret_cast<TUint32*>(iChunk.Base());		
   123 	err=iWindow.SetBackgroundSurface(aSurfaceId);
   124 	if ( err!=KErrNone)
   125 		{
   126 		RDebug::Print(_L("ERROR: %d - Setting window background to the surface failed!"), err);
   127 		User::Panic(_L("Fps panic"), err);
   128 		}
   129 	}
   130 
   131 void CFpsAppEng::CreateSurfaceUpdateSessionL()
   132 	{
   133 	TInt ret = iSurfaceUpdateSession.Connect();
   134 
   135 	if (ret==KErrAlreadyExists)
   136 		{
   137 		RDebug::Print(_L("Device driver already loaded"));
   138 		}
   139 	else if (ret==KErrNone)
   140 		{
   141 		RDebug::Print(_L("Connected to surface update server"));
   142 		}
   143 	else
   144 		{
   145 		RDebug::Print(_L("Fatal error connecting to surface update server"));
   146 		User::LeaveIfError(ret);
   147 		}
   148 	}
   149 
   150 void CFpsAppEng::DestroySurface()
   151 	{
   152 	RDebug::Print(_L("Destroy Surface update session"));
   153 	iSurfaceUpdateSession.Close();
   154 
   155 	RDebug::Print(_L("Closing chunk"));
   156 	iChunk.Close();
   157 
   158 	RDebug::Print(_L("Closing surface"));
   159 	TInt ret = iSurfaceManager.CloseSurface(iSurfaceId);
   160 	if(ret!=KErrNone)
   161 		{
   162 		RDebug::Print(_L("Surface manager failed to close"));
   163 		}
   164 
   165 	RDebug::Print(_L("Close Surface Manager"));
   166 	iSurfaceManager.Close();
   167 	}
   168 
   169 
   170 // Timer's RunL()
   171 void CFpsAppEng::RunL()
   172 	{
   173 	TInt j;
   174 	if (iCol1)
   175 		{
   176 		for (j=0; j<iNoOfPixels; j++)
   177 			{		
   178 			iBufPtr1[j]=0xFF00FF00;
   179 			}		
   180 		iCol1=EFalse;
   181 		iCol2=ETrue;		
   182 		}
   183 	else
   184 		{
   185 		for (j=0; j<iNoOfPixels; j++)
   186 			{		
   187 			iBufPtr1[j]=0xFF0000FF;
   188 			}		
   189 		iCol2=EFalse;
   190 		iCol1=ETrue;		
   191 		}
   192 
   193 	Mem::Move(iSurfacePtr, iBufPtr1, iNoOfBytes);
   194 	__ASSERT_ALWAYS( KErrNone==iSurfaceUpdateSession.SubmitUpdate(KAllScreens, iSurfaceId, 0, NULL),User::Panic(_L("Fps App"), -1));
   195 	iClient.Flush();
   196 
   197 //	After(TTimeIntervalMicroSeconds32(10000));	// 0.002sec, 100fps	
   198 //	After(TTimeIntervalMicroSeconds32(20000));	// 0.02sec,  50fps
   199 //	After(TTimeIntervalMicroSeconds32(25000));	// 0.025sec, 40fps
   200 	After(TTimeIntervalMicroSeconds32(33333));	// 0.033sec, 30fps	
   201 //	After(TTimeIntervalMicroSeconds32(50000));  // 0.050sec, 20fps
   202 //	After(TTimeIntervalMicroSeconds32(100000));  //0.01sec,  10fps
   203 	}
   204 
   205 
   206 // Timer's DoCancel()
   207 void CFpsAppEng::DoCancel()
   208 	{
   209 	// Cancel timer
   210 	CTimer::DoCancel();
   211 	}