1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/windowing/windowserver/test/t_integ/src/t_fpsappeng.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,211 @@
1.4 +// Copyright (c) 2007-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 +//
1.18 +
1.19 +/**
1.20 + @file
1.21 + @test
1.22 + @internalComponent
1.23 +*/
1.24 +
1.25 +#include <libc/limits.h> //UINT_MAX
1.26 +#include "t_fpsappeng.h"
1.27 +#include "t_pseudoapputils.h"
1.28 +
1.29 +const TInt KSurfaceWidth = 640;
1.30 +const TInt KSurfaceHeight = 240;
1.31 +const TUidPixelFormat KSurfaceFormat = EUidPixelFormatXRGB_8888;
1.32 +const TInt KBytesPerPixel = 4; // Four bytes per pixel for the format above.
1.33 +
1.34 +CFpsAppEng::CFpsAppEng(RWsSession& aClient, CWsScreenDevice& aScreenDevice, RWindow& aWindow)
1.35 +: CTimer(CActive::EPriorityStandard),
1.36 + iClient(aClient),
1.37 + iWindow(aWindow),
1.38 + iScreenDevice(aScreenDevice)
1.39 + {
1.40 + }
1.41 +
1.42 +CFpsAppEng* CFpsAppEng::NewL(RWsSession& aClient, CWsScreenDevice& aScreenDevice, RWindow& aWindow)
1.43 + {
1.44 + CFpsAppEng* self = new (ELeave) CFpsAppEng(aClient, aScreenDevice, aWindow);
1.45 + CleanupStack::PushL(self);
1.46 + self->ConstructL();
1.47 + CleanupStack::Pop(); // self;
1.48 + return self;
1.49 + }
1.50 +
1.51 +CFpsAppEng::~CFpsAppEng()
1.52 + {
1.53 + if(IsActive())
1.54 + {
1.55 + Cancel();
1.56 + }
1.57 +
1.58 + User::Free(iBufPtr1);
1.59 + DestroySurface();
1.60 +
1.61 + //Pause to allow the test step to kill the app
1.62 + User::After(1000000);
1.63 + }
1.64 +
1.65 +void CFpsAppEng::ConstructL()
1.66 + {
1.67 + CTimer::ConstructL();
1.68 +
1.69 + iNoOfPixels = KSurfaceHeight*KSurfaceWidth;
1.70 + iNoOfBytes = iNoOfPixels*KBytesPerPixel;
1.71 +
1.72 + // Allocate a memory block
1.73 + iBufPtr1 = reinterpret_cast<TUint32*>(User::AllocL(iNoOfBytes));
1.74 +
1.75 + RDebug::Print(_L("Creating Surface manager..."));
1.76 + CreateSurfaceManager();
1.77 + RDebug::Print(_L("Creating Surface..."));
1.78 + CreateSurface(iSurfaceId);
1.79 + RDebug::Print(_L("Create Surface update session..."));
1.80 + CreateSurfaceUpdateSessionL();
1.81 +
1.82 + CActiveScheduler::Add(this);
1.83 + }
1.84 +
1.85 +void CFpsAppEng::StartDrawing()
1.86 + {
1.87 + //A value of 0 will provoke a E32User-Cbase 46 panic
1.88 + After(TTimeIntervalMicroSeconds32(100000));
1.89 + }
1.90 +
1.91 +void CFpsAppEng::CreateSurfaceManager()
1.92 + {
1.93 + TInt ret = iSurfaceManager.Open();
1.94 + if(ret==KErrNone)
1.95 + {
1.96 + RDebug::Print(_L("Creating surface manager OK"));
1.97 + }
1.98 + }
1.99 +
1.100 +
1.101 +void CFpsAppEng::CreateSurface(TSurfaceId& aSurfaceId)
1.102 + {
1.103 + RSurfaceManager::TSurfaceCreationAttributesBuf attribs;
1.104 + RSurfaceManager::TSurfaceCreationAttributes& surfaceCreationAtribs=attribs();
1.105 + surfaceCreationAtribs.iSize.iWidth = KSurfaceWidth;
1.106 + surfaceCreationAtribs.iSize.iHeight = KSurfaceHeight;
1.107 + surfaceCreationAtribs.iBuffers = 2;
1.108 + surfaceCreationAtribs.iPixelFormat = KSurfaceFormat;
1.109 + surfaceCreationAtribs.iStride = KBytesPerPixel*KSurfaceWidth;
1.110 + surfaceCreationAtribs.iOffsetToFirstBuffer = 0;
1.111 + surfaceCreationAtribs.iAlignment = 4;
1.112 + surfaceCreationAtribs.iContiguous = EFalse;
1.113 + surfaceCreationAtribs.iMappable = ETrue;
1.114 +
1.115 + TInt err = iSurfaceManager.CreateSurface(attribs, aSurfaceId);
1.116 + if (err == KErrNone)
1.117 + {
1.118 + err = iSurfaceManager.MapSurface(aSurfaceId, iChunk);
1.119 + }
1.120 + if (err == KErrNone)
1.121 + {
1.122 + RDebug::Print(_L("Surface created: OK"));
1.123 + }
1.124 +
1.125 + iSurfacePtr = reinterpret_cast<TUint32*>(iChunk.Base());
1.126 + err=iWindow.SetBackgroundSurface(aSurfaceId);
1.127 + if ( err!=KErrNone)
1.128 + {
1.129 + RDebug::Print(_L("ERROR: %d - Setting window background to the surface failed!"), err);
1.130 + User::Panic(_L("Fps panic"), err);
1.131 + }
1.132 + }
1.133 +
1.134 +void CFpsAppEng::CreateSurfaceUpdateSessionL()
1.135 + {
1.136 + TInt ret = iSurfaceUpdateSession.Connect();
1.137 +
1.138 + if (ret==KErrAlreadyExists)
1.139 + {
1.140 + RDebug::Print(_L("Device driver already loaded"));
1.141 + }
1.142 + else if (ret==KErrNone)
1.143 + {
1.144 + RDebug::Print(_L("Connected to surface update server"));
1.145 + }
1.146 + else
1.147 + {
1.148 + RDebug::Print(_L("Fatal error connecting to surface update server"));
1.149 + User::LeaveIfError(ret);
1.150 + }
1.151 + }
1.152 +
1.153 +void CFpsAppEng::DestroySurface()
1.154 + {
1.155 + RDebug::Print(_L("Destroy Surface update session"));
1.156 + iSurfaceUpdateSession.Close();
1.157 +
1.158 + RDebug::Print(_L("Closing chunk"));
1.159 + iChunk.Close();
1.160 +
1.161 + RDebug::Print(_L("Closing surface"));
1.162 + TInt ret = iSurfaceManager.CloseSurface(iSurfaceId);
1.163 + if(ret!=KErrNone)
1.164 + {
1.165 + RDebug::Print(_L("Surface manager failed to close"));
1.166 + }
1.167 +
1.168 + RDebug::Print(_L("Close Surface Manager"));
1.169 + iSurfaceManager.Close();
1.170 + }
1.171 +
1.172 +
1.173 +// Timer's RunL()
1.174 +void CFpsAppEng::RunL()
1.175 + {
1.176 + TInt j;
1.177 + if (iCol1)
1.178 + {
1.179 + for (j=0; j<iNoOfPixels; j++)
1.180 + {
1.181 + iBufPtr1[j]=0xFF00FF00;
1.182 + }
1.183 + iCol1=EFalse;
1.184 + iCol2=ETrue;
1.185 + }
1.186 + else
1.187 + {
1.188 + for (j=0; j<iNoOfPixels; j++)
1.189 + {
1.190 + iBufPtr1[j]=0xFF0000FF;
1.191 + }
1.192 + iCol2=EFalse;
1.193 + iCol1=ETrue;
1.194 + }
1.195 +
1.196 + Mem::Move(iSurfacePtr, iBufPtr1, iNoOfBytes);
1.197 + __ASSERT_ALWAYS( KErrNone==iSurfaceUpdateSession.SubmitUpdate(KAllScreens, iSurfaceId, 0, NULL),User::Panic(_L("Fps App"), -1));
1.198 + iClient.Flush();
1.199 +
1.200 +// After(TTimeIntervalMicroSeconds32(10000)); // 0.002sec, 100fps
1.201 +// After(TTimeIntervalMicroSeconds32(20000)); // 0.02sec, 50fps
1.202 +// After(TTimeIntervalMicroSeconds32(25000)); // 0.025sec, 40fps
1.203 + After(TTimeIntervalMicroSeconds32(33333)); // 0.033sec, 30fps
1.204 +// After(TTimeIntervalMicroSeconds32(50000)); // 0.050sec, 20fps
1.205 +// After(TTimeIntervalMicroSeconds32(100000)); //0.01sec, 10fps
1.206 + }
1.207 +
1.208 +
1.209 +// Timer's DoCancel()
1.210 +void CFpsAppEng::DoCancel()
1.211 + {
1.212 + // Cancel timer
1.213 + CTimer::DoCancel();
1.214 + }