os/graphics/windowing/windowserver/test/ttime/TTGENRAL.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) 1996-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 // used for timing graphics
    15 // 
    16 //
    17 
    18 #include "TTIME.H"
    19 
    20 #define TEST_ROM_BITMAP_NAME _L("Z:\\WSTEST\\TROM.MBM")
    21 
    22 enum TFuncType
    23 	{
    24 	ESimpleFlush,
    25 	ESpriteSetting,
    26 	EBitmapDevice,
    27 	ETrivialFunctions,
    28 	ELoadBitmap,
    29 	};
    30 
    31 class TWsTest : public CBase
    32 	{
    33 public:
    34 	void DoTestL(TInt aOwningGroup, TFuncType aFunc, TInt aParam1, TAny *aParam2);
    35 	void SimpleFlush(TInt aParam1, TAny *aParam2);
    36 	void SpriteSettingL(TInt aParam1, TAny *aParam2);
    37 	void BitmapDeviceL(TInt aParam, TAny *);
    38 	void TrivialFunctions(TInt aParam1, TAny *aParam2);
    39 	void LoadBitmapL(TInt aParam1, TAny *aParam2);
    40 private:
    41 	void createSpriteBitmapL(CFbsBitmap *aBitmap, CFbsBitmapDevice *&aBitmapDevice, const TSize &aSize, TBool aDoMask);
    42 private:
    43 	RWsSession iWs;
    44 	RWindowGroup iGroup;
    45 	RWindow iWindow;
    46 	CWsScreenDevice *iDevice;
    47 	CWindowGc *iGc;
    48 	};
    49 	
    50 TInt CreateWsTest(TInt aOwningGroup, TFuncType aFunc, TInt aParam1, TAny *aParam2)
    51 	{
    52 	TWsTest *iTest=NULL;
    53 	TRAPD(err,iTest=new(ELeave) TWsTest());
    54 	if (err==KErrNone)
    55 		{
    56 		TRAP(err,iTest->DoTestL(aOwningGroup, aFunc, aParam1, aParam2));
    57 		delete iTest;
    58 		}
    59 	return(err);
    60 	}
    61 
    62 void TWsTest::DoTestL(TInt aOwningGroup, TFuncType aFunc, TInt aParam1, TAny *aParam2)
    63 	{
    64 	iWs.Connect();
    65 	iDevice=new(ELeave) CWsScreenDevice(iWs);
    66 	iDevice->Construct();
    67 	iGroup=RWindowGroup(iWs);
    68 	iGroup.Construct(ENullWsHandle);
    69 	iGroup.SetOwningWindowGroup(aOwningGroup);
    70 //
    71 	iWindow=RWindow(iWs);
    72 	iWindow.Construct(iGroup,ENullWsHandle);
    73 	iWindow.SetExtent(TPoint(), iDevice->SizeInPixels());
    74 	iWindow.Activate();
    75 //
    76 	iDevice->CreateContext(iGc);
    77 	iWindow.BeginRedraw();
    78 	iGc->Activate(iWindow);
    79 	iGc->Clear();
    80 	iWindow.EndRedraw();
    81 //
    82 	switch(aFunc)
    83 		{
    84 		case ESimpleFlush:
    85 			SimpleFlush(aParam1, aParam2);
    86 			break;
    87 		case ESpriteSetting:
    88 			SpriteSettingL(aParam1, aParam2);
    89 			break;
    90 		case EBitmapDevice:
    91 			BitmapDeviceL(aParam1, aParam2);
    92 			break;
    93 		case ETrivialFunctions:
    94 			TrivialFunctions(aParam1, aParam2);
    95 			break;
    96 		case ELoadBitmap:
    97 			LoadBitmapL(aParam1, aParam2);
    98 			break;
    99 		default:;
   100 		}
   101 	delete iGc;
   102 	iWindow.Close();
   103 	iGroup.Close();
   104 	delete iDevice;
   105 	iWs.Close();
   106 	}
   107 
   108 // Flush //
   109 
   110 void TWsTest::SimpleFlush(TInt aParam, TAny *)
   111 	{
   112 	TTimeIntervalMicroSeconds32 interval(100000);
   113 	TInt distance=10;
   114 	if (aParam==0)
   115 		{
   116 		TTimeIntervalMicroSeconds32 origInterval;
   117 		TInt origDistance;
   118 		iWs.GetDoubleClickSettings(origInterval,origDistance);
   119 		for(TInt nTimes=0;nTimes<5000-1;nTimes++)
   120 			{
   121 			iWs.SetDoubleClick(interval,distance);
   122 			iWs.Flush();
   123 			}
   124 		iWs.SetDoubleClick(origInterval,origDistance);
   125 		}
   126 	else
   127 		{
   128 		for(TInt nTimes=0;nTimes<5000;nTimes++)
   129 			iWs.GetDoubleClickSettings(interval,distance);
   130 		}
   131 	}
   132 
   133 TInt SimpleFlushTestFunc(TInt aOwningGroup)
   134 	{
   135 	return(CreateWsTest(aOwningGroup, ESimpleFlush, 0, NULL));
   136 	}
   137 
   138 TInt SimpleFlushTestFunc2(TInt aOwningGroup)
   139 	{
   140 	return(CreateWsTest(aOwningGroup, ESimpleFlush, 1, NULL));
   141 	}
   142 
   143 GLDEF_D TTimeTestHeader SimpleFlushTest={_S("Simple Flush[1] x5000"),SimpleFlushTestFunc};
   144 GLDEF_D TTimeTestHeader SimpleFlushTest2={_S("Simple Flush[2] x5000"),SimpleFlushTestFunc2};
   145 
   146 // IP Read/Write //
   147 
   148 #if 0
   149 TInt ReadWriteThreadFunc(TAny *aParams)
   150 	{
   151 	TWinCommand command;
   152 	RProcess().CommandLine(command);
   153 	TDesC8 *cmd=&command;
   154 	RThread thread;
   155 	thread.Open(_L("TimeTest"));
   156 	TAny *remotePtr=*(TAny **)aCmd->Ptr();
   157 	TBuf<0x10> buf;
   158 	for(TInt count=0;count<100000;count++)
   159 		thread.ReadL(remotePtr,buf,0);
   160 	}
   161 
   162 void TWsTest::IPReadWriteL(TInt aParam, TAny *)
   163 	{
   164 	TBuf<0x10> srcData;
   165 	srcData.Append(_L("1234567890ABCDEF"));
   166 	RProcess process;
   167 	TWinCommand command;
   168 	*((TAny **)command.Ptr())=&srcData;
   169 	User::LeaveIfError(process.Create(_L("TimeThread1"),);
   170 	TRequestStatus status;
   171 	process.Logon(status);
   172 	process.Resume();
   173 	User::WaitForRequest(status);
   174 	process.Close();
   175 	}
   176 
   177 TInt SimpleFlushTestFunc(TInt aOwningGroup)
   178 	{
   179 	return(CreateWsTest(aOwningGroup, ESimpleFlush, 0, NULL));
   180 	}
   181 
   182 TInt SimpleFlushTestFunc2(TInt aOwningGroup)
   183 	{
   184 	return(CreateWsTest(aOwningGroup, ESimpleFlush, 1, NULL));
   185 	}
   186 
   187 GLDEF_D TTimeTestHeader SimpleFlushTest={_S("Simple Flush[1] x5000"),SimpleFlushTestFunc};
   188 GLDEF_D TTimeTestHeader SimpleFlushTest2={_S("Simple Flush[2] x5000"),SimpleFlushTestFunc2};
   189 #endif
   190 // Bitmap device //
   191 
   192 void TWsTest::BitmapDeviceL(TInt aParam, TAny *)
   193 	{
   194 	CFbsBitmap *bitmap=new(ELeave) CFbsBitmap();
   195 	User::LeaveIfError(bitmap->Create(TSize(10,10),EGray4));
   196 	CFbsBitmapDevice *bitmapDevicePerm=NULL;
   197 	if (aParam==1)
   198 		bitmapDevicePerm=CFbsBitmapDevice::NewL(bitmap);
   199 	for(TInt nTimes=0;nTimes<100;nTimes++)
   200 		{
   201 		CFbsBitmapDevice *bitmapDevice=CFbsBitmapDevice::NewL(bitmap);
   202 		delete bitmapDevice;
   203 		}
   204 	delete bitmapDevicePerm;
   205 	delete bitmap;
   206 	}
   207 
   208 TInt BitmapDeviceTestFunc1(TInt aOwningGroup)
   209 	{
   210 	return(CreateWsTest(aOwningGroup, EBitmapDevice, 0, NULL));
   211 	}
   212 
   213 TInt BitmapDeviceTestFunc2(TInt aOwningGroup)
   214 	{
   215 	return(CreateWsTest(aOwningGroup, EBitmapDevice, 1, NULL));
   216 	}
   217 
   218 GLDEF_D TTimeTestHeader BitmapDeviceTest1={_S("Bitmap Device (reload)"),BitmapDeviceTestFunc1};
   219 GLDEF_D TTimeTestHeader BitmapDeviceTest2={_S("Bitmap Device "),BitmapDeviceTestFunc2};
   220 
   221 // Sprite Setting //
   222 
   223 void TWsTest::createSpriteBitmapL(CFbsBitmap *aBitmap, CFbsBitmapDevice *&aBitmapDevice, const TSize &aSize, TBool aDoMask)
   224 	{
   225 	User::LeaveIfError(aBitmap->Create(aSize,EGray4));
   226 	aBitmapDevice=CFbsBitmapDevice::NewL(aBitmap);
   227 	CFbsBitGc *gc=CFbsBitGc::NewL();
   228 	gc->Activate(aBitmapDevice);
   229 	gc->SetBrushColor(TRgb::Gray4(aDoMask ? 0 : 2));
   230 	gc->SetBrushStyle(CGraphicsContext::ESolidBrush);
   231 	gc->SetPenStyle(CGraphicsContext::ENullPen);
   232 	gc->DrawRect(TRect(aSize));
   233 	gc->SetPenStyle(CGraphicsContext::ESolidPen);
   234 	gc->SetPenColor(TRgb::Gray4(aDoMask ? 3 : 0));
   235 	gc->SetBrushColor(TRgb::Gray4(aDoMask ? 3 : 1));
   236 	gc->DrawEllipse(TRect(aSize));
   237 	delete gc;
   238 	}
   239 
   240 void TWsTest::SpriteSettingL(TInt , TAny *)
   241 	{
   242 	RWsSprite sprite;
   243 	TSize size(32,32);
   244 	sprite=RWsSprite(iWs);
   245 	CFbsBitmap *bitmap=new(ELeave) CFbsBitmap();
   246 	CFbsBitmap *mask=new(ELeave) CFbsBitmap();
   247 	CFbsBitmapDevice *bitmapDevice=NULL;		//To stop warning
   248 	TRAPD(err,createSpriteBitmapL(bitmap,bitmapDevice,size,EFalse));
   249 	delete bitmapDevice;
   250 	TRAP(err,createSpriteBitmapL(mask,bitmapDevice,size,ETrue));
   251 	delete bitmapDevice;
   252 	TSpriteMember spriteData;
   253 	spriteData.iBitmap=bitmap;
   254 	spriteData.iMaskBitmap=mask;
   255 	spriteData.iInvertMask=EFalse;
   256 	spriteData.iInterval=TTimeIntervalMicroSeconds32(0);
   257 	User::LeaveIfError(sprite.Construct(iWindow,TPoint(0,0),0));
   258 	User::LeaveIfError(sprite.AppendMember(spriteData));
   259 	User::LeaveIfError(sprite.Activate());
   260 	for(TInt i=0;i<500;i++)
   261 		sprite.SetPosition(TPoint(i&0x7f,i&0x7f));
   262 	sprite.Close();
   263 	delete mask;
   264 	delete bitmap;
   265 	}
   266 
   267 TInt SpriteSettingTestFunc(TInt aOwningGroup)
   268 	{
   269 	return(CreateWsTest(aOwningGroup, ESpriteSetting, 0, NULL));
   270 	}
   271 
   272 GLDEF_D TTimeTestHeader SpriteTest={_S("Sprite Setting"),SpriteSettingTestFunc};
   273 
   274 void TWsTest::TrivialFunctions(TInt , TAny *)
   275 	{
   276 	for(TInt i=0;i<100000;i++)
   277 		iWs.FreeSystemPointerCursorList();
   278 	}
   279 
   280 TInt TrivialFunctionsTestFunc(TInt aOwningGroup)
   281 	{
   282 	return(CreateWsTest(aOwningGroup, ETrivialFunctions, 0, NULL));
   283 	}
   284 
   285 GLDEF_D TTimeTestHeader TrivialFunctionsTest={_S("TrivialFunctions"),TrivialFunctionsTestFunc};
   286 
   287 void TWsTest::LoadBitmapL(TInt aMode, TAny *)
   288 	{
   289 	if (aMode<2)
   290 		{
   291 		for(TInt count=0;count<10;count++)
   292 			{
   293 			if (aMode==0)
   294 				{
   295 				CFbsBitmap *bit=new(ELeave) CFbsBitmap();
   296 				User::LeaveIfError(bit->Load(TEST_ROM_BITMAP_NAME,0));
   297 				delete bit;
   298 				}
   299 			else
   300 				{
   301 				CWsBitmap *bit=new(ELeave) CWsBitmap(iWs);
   302 				User::LeaveIfError(bit->Load(TEST_ROM_BITMAP_NAME,0));
   303 				delete bit;
   304 				}
   305 			}
   306 		}
   307 	else for(TInt count=0;count<100;count++)
   308 		{
   309 	//__PROFILE_START(1)
   310 		RFs fs;
   311 		User::LeaveIfError(fs.Connect());
   312 		fs.SetNotifyUser(EFalse);
   313 	//__PROFILE_END(1)
   314 	//__PROFILE_START(2)
   315 		TParse parse;
   316 		User::LeaveIfError(fs.Parse(TEST_ROM_BITMAP_NAME,parse));
   317 	//__PROFILE_END(2)
   318 	//__PROFILE_START(3)
   319 		TInt drive;
   320 		User::LeaveIfError(RFs::CharToDrive(parse.Drive()[0],drive));
   321 		TDriveInfo driveinfo;
   322 		User::LeaveIfError(fs.Drive(driveinfo,drive));
   323 	//__PROFILE_END(3)
   324 	//__PROFILE_START(4)
   325 		RFile tempfile;
   326 		User::LeaveIfError(tempfile.Open(fs,TEST_ROM_BITMAP_NAME,EFileShareAny));
   327 		TInt aAddress;
   328 		tempfile.Seek(ESeekAddress,aAddress);
   329 	//__PROFILE_END(4)
   330 	//__PROFILE_START(5)
   331 		tempfile.Close();
   332 		fs.Close();
   333 	//__PROFILE_END(5)
   334 		}
   335 	}
   336 
   337 TInt LoadBitmapTestFunc(TInt aOwningGroup)
   338 	{
   339 	return(CreateWsTest(aOwningGroup, ELoadBitmap, 0, NULL));
   340 	}
   341 TInt LoadWsBitmapTestFunc(TInt aOwningGroup)
   342 	{
   343 	return(CreateWsTest(aOwningGroup, ELoadBitmap, 1, NULL));
   344 	}
   345 TInt LoadRomFileTestFunc(TInt aOwningGroup)
   346 	{
   347 	return(CreateWsTest(aOwningGroup, ELoadBitmap, 3, NULL));
   348 	}
   349 
   350 GLDEF_D TTimeTestHeader BitmapLoadTest={_S("Load Bitmap"),LoadBitmapTestFunc};
   351 GLDEF_D TTimeTestHeader WsBitmapLoadTest={_S("Load WsBitmap"),LoadWsBitmapTestFunc};
   352 GLDEF_D TTimeTestHeader RomFileTest={_S("Rom File"),LoadRomFileTestFunc};