windowing/windowserver/ttime/TTGRAPH.CPP
changeset 110 7f25ef56562d
parent 98 bf7481649c98
child 111 29ddb8a72f0e
equal deleted inserted replaced
98:bf7481649c98 110:7f25ef56562d
     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_BITMAP_NAME _L("Z:\\WSTEST\\TEST.MBM")
       
    21 
       
    22 GLREF_C void Panic(TInt aPanic);
       
    23 
       
    24 enum TFuncType
       
    25 	{
       
    26 	EBitmapTest,
       
    27 	EXorTest,
       
    28 	ESmallClearTest,
       
    29 	ERectCompareTest,
       
    30 	EUseFontTest,
       
    31 	EBitBltTest,
       
    32 	EFullScreenBitBltTest,
       
    33 	EMaskedBitBltTest,
       
    34 	EFillPatternTest,
       
    35 	EBackupWindowDrawingTest,
       
    36 	};
       
    37 
       
    38 class TGraphicsTest : public CBase
       
    39 	{
       
    40 public:
       
    41 	void DoTestL(TInt aOwningGroup, TFuncType aFunc, TInt aParam1, TAny *aParam2);
       
    42 	void DrawBitmapTestL(TInt aParam1, TAny *aParam2);
       
    43 	void XorTest(TInt aParam1, TAny *aParam2);
       
    44 	void SmallClearTest(TInt , TAny *);
       
    45 	void RectCompareTest(TInt , TAny *);
       
    46 	void UseFontTestL(TInt , TAny *);
       
    47 	void BitBltTestL(TInt , TAny *);
       
    48 	void FullScreenBitBltTestL(TInt , TAny *);
       
    49 	void MaskedBitBltTestL(TInt , TAny *);
       
    50 	void FillPatternTestL(TInt , TAny *);
       
    51 	void BackedUpWindowDrawingL(TInt aMode, TAny *);
       
    52 private:
       
    53 	RWsSession iWs;
       
    54 	CWsScreenDevice *iDevice;
       
    55 	RWindowGroup iGroup;
       
    56 	RWindow iWindow;
       
    57 	RBackedUpWindow iBackedUpWindow;
       
    58 	RDrawableWindow *iWindowPtr;
       
    59 	CWindowGc *iGc;
       
    60 	};
       
    61 	
       
    62 TInt CreateGraphicsTest(TInt aOwningGroup, TFuncType aFunc, TInt aParam1, TAny *aParam2)
       
    63 	{
       
    64 	TGraphicsTest *iTest=NULL;
       
    65 	TRAPD(err,iTest=new(ELeave) TGraphicsTest());
       
    66 	if (err==KErrNone)
       
    67 		{
       
    68 		TRAP(err,iTest->DoTestL(aOwningGroup, aFunc, aParam1, aParam2));
       
    69 		delete iTest;
       
    70 		}
       
    71 	return(err);
       
    72 	}
       
    73 
       
    74 void TGraphicsTest::DoTestL(TInt aOwningGroup, TFuncType aFunc, TInt aParam1, TAny *aParam2)
       
    75 	{
       
    76 	iWs.Connect();
       
    77 	iDevice=new(ELeave) CWsScreenDevice(iWs);
       
    78 	iDevice->Construct();
       
    79 	iGroup=RWindowGroup(iWs);
       
    80 	iGroup.Construct(ENullWsHandle);
       
    81 	iGroup.SetOwningWindowGroup(aOwningGroup);
       
    82 //
       
    83 	if (aFunc==EBackupWindowDrawingTest)
       
    84 		{
       
    85 		iBackedUpWindow=RBackedUpWindow(iWs);
       
    86 		iWindowPtr=&iBackedUpWindow;
       
    87 		iBackedUpWindow.Construct(iGroup,EGray4,ENullWsHandle);
       
    88 		}
       
    89 	else
       
    90 		{
       
    91 		iWindow=RWindow(iWs);
       
    92 		iWindowPtr=&iWindow;
       
    93 		iWindow.Construct(iGroup,ENullWsHandle);
       
    94 		}
       
    95 	User::LeaveIfError(iWindowPtr->SetExtentErr(TPoint(), iDevice->SizeInPixels()));
       
    96 	iWindowPtr->Activate();
       
    97 	//
       
    98 	iDevice->CreateContext(iGc);
       
    99 	iGc->Activate(*iWindowPtr);
       
   100 	if (iWindowPtr==&iWindow)
       
   101 		{
       
   102 		iWindow.BeginRedraw();
       
   103 		iGc->Clear();
       
   104 		iWindow.EndRedraw();
       
   105 		}
       
   106 	switch(aFunc)
       
   107 		{
       
   108 		case EBitmapTest:
       
   109 			DrawBitmapTestL(aParam1, aParam2);
       
   110 			break;
       
   111 		case EXorTest:
       
   112 			XorTest(aParam1, aParam2);
       
   113 			break;
       
   114 		case ESmallClearTest:
       
   115 			SmallClearTest(aParam1, aParam2);
       
   116 			break;
       
   117 		case ERectCompareTest:
       
   118 			RectCompareTest(aParam1, aParam2);
       
   119 			break;
       
   120 		case EUseFontTest:
       
   121 			UseFontTestL(aParam1, aParam2);
       
   122 			break;
       
   123 		case EBitBltTest:
       
   124 			BitBltTestL(aParam1, aParam2);
       
   125 			break;
       
   126 		case EFullScreenBitBltTest:
       
   127 			FullScreenBitBltTestL(aParam1, aParam2);
       
   128 			break;
       
   129 		case EMaskedBitBltTest:
       
   130 			MaskedBitBltTestL(aParam1, aParam2);
       
   131 			break;
       
   132 		case EFillPatternTest:
       
   133 			FillPatternTestL(aParam1, aParam2);
       
   134 			break;
       
   135 		case EBackupWindowDrawingTest:
       
   136 			BackedUpWindowDrawingL(aParam1, aParam2);
       
   137 			break;
       
   138 		default:;
       
   139 		}
       
   140 //
       
   141 	delete iGc;
       
   142 	iWindowPtr->Close();
       
   143 	iGroup.Close();
       
   144 	delete iDevice;
       
   145 	iWs.Close();
       
   146 	}
       
   147 
       
   148 // Draw bitmap //
       
   149 
       
   150 void TGraphicsTest::DrawBitmapTestL(TInt , TAny *)
       
   151 	{
       
   152 	CFbsBitmap *bitmap=new(ELeave) CFbsBitmap;
       
   153 	User::LeaveIfError(bitmap->Load(TEST_BITMAP_NAME,0));
       
   154 	for(TInt nTimes=0;nTimes<10;nTimes++)
       
   155 		{
       
   156 		iGc->Clear();
       
   157 		TSize size(iDevice->SizeInPixels());
       
   158 		iGc->DrawBitmap(TRect(-size.iWidth,-size.iHeight,size.iWidth<<1,size.iHeight<<1),bitmap);
       
   159 		iWs.Flush();
       
   160 		}
       
   161 	delete bitmap;
       
   162 	}
       
   163 
       
   164 TInt DrawBitmapTestFunc(TInt aOwningGroup)
       
   165 	{
       
   166 	return(CreateGraphicsTest(aOwningGroup, EBitmapTest, 0, NULL));
       
   167 	}
       
   168 
       
   169 GLDEF_D TTimeTestHeader DrawBitmapTest={_S("Draw bitmap"),DrawBitmapTestFunc};
       
   170 
       
   171 // XOR Test //
       
   172 
       
   173 void TGraphicsTest::XorTest(TInt , TAny *)
       
   174 	{
       
   175 	iGc->SetDrawMode(CGraphicsContext::EDrawModeXOR);
       
   176 	iGc->SetBrushColor(TRgb::Gray256(255));
       
   177 	iGc->SetPenStyle(CGraphicsContext::ENullPen);
       
   178 	iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   179 	for(TInt count=0;count<10;count++)
       
   180 		{
       
   181 		for(TInt wid=1;wid<320;wid+=3)
       
   182 			{
       
   183 			iGc->DrawRect(TRect(10,10,10+wid,150));
       
   184 	//		iWs.Flush();
       
   185 			}
       
   186 		}
       
   187 	}
       
   188 
       
   189 TInt XorIngTestFunc(TInt aOwningGroup)
       
   190 	{
       
   191 	return(CreateGraphicsTest(aOwningGroup, EXorTest, 0, NULL));
       
   192 	}
       
   193 
       
   194 GLDEF_D TTimeTestHeader XorIngTest={_S("Xor'ing"),XorIngTestFunc};
       
   195 
       
   196 // XOR Test //
       
   197 
       
   198 void TGraphicsTest::SmallClearTest(TInt , TAny *)
       
   199 	{
       
   200 	iGc->SetBrushColor(TRgb::Gray256(255));
       
   201 	iGc->SetPenStyle(CGraphicsContext::ENullPen);
       
   202 	iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   203 	for(TInt count=0;count<500;count++)
       
   204 		{
       
   205 		for(TInt wid=1;wid<30;wid++)
       
   206 			{
       
   207 			iGc->DrawRect(TRect(1,0,10+wid,100));
       
   208 //			iWs.Flush();
       
   209 			}
       
   210 		}
       
   211 	}
       
   212 
       
   213 TInt SmallClearTestFunc(TInt aOwningGroup)
       
   214 	{
       
   215 	return(CreateGraphicsTest(aOwningGroup, ESmallClearTest, 0, NULL));
       
   216 	}
       
   217 
       
   218 GLDEF_D TTimeTestHeader SmallClearTest={_S("Small clear rect"),SmallClearTestFunc};
       
   219 
       
   220 // XOR Test //
       
   221 
       
   222 enum {EMaxWidth=100};
       
   223 
       
   224 void TGraphicsTest::RectCompareTest(TInt , TAny *)
       
   225 	{
       
   226 	TSize size(iDevice->SizeInPixels());
       
   227 	for(TInt count=0;count<10;count++)
       
   228 		iDevice->RectCompare(TRect(0,0,size.iWidth>>1,size.iHeight),TRect(size.iWidth>>1,0,size.iWidth,size.iHeight));
       
   229 	}
       
   230 
       
   231 TInt RectCompareTestFunc(TInt aOwningGroup)
       
   232 	{
       
   233 	return(CreateGraphicsTest(aOwningGroup, ERectCompareTest, 0, NULL));
       
   234 	}
       
   235 
       
   236 GLDEF_D TTimeTestHeader RectCompareTest={_S("RectCompare"),RectCompareTestFunc};
       
   237 
       
   238 // Use Font //
       
   239 
       
   240 void TGraphicsTest::UseFontTestL(TInt , TAny *)
       
   241 	{
       
   242 	CFbsFont *font;
       
   243 	TFontSpec fspec(KTestFontTypefaceName,200);
       
   244 	User::LeaveIfError(iDevice->GetNearestFontToDesignHeightInTwips((CFont *&)font, fspec));
       
   245 	for(TInt count=0;count<1000;count++)
       
   246 		iGc->UseFont(font);
       
   247 	iDevice->ReleaseFont(font);
       
   248 	}
       
   249 
       
   250 TInt UseFontTestFunc(TInt aOwningGroup)
       
   251 	{
       
   252 	return(CreateGraphicsTest(aOwningGroup, EUseFontTest, 0, NULL));
       
   253 	}
       
   254 
       
   255 GLDEF_D TTimeTestHeader UseFontTest={_S("UseFont(x1000)"),UseFontTestFunc};
       
   256 
       
   257 // Small BitBlt //
       
   258 
       
   259 void TGraphicsTest::BitBltTestL(TInt , TAny *)
       
   260 	{
       
   261 	CWsBitmap *bitmap=new(ELeave) CWsBitmap(iWs);
       
   262 	TSize size(25,50);
       
   263 	bitmap->Create(size,EGray4);
       
   264 	CFbsDevice *bitmapDevice=CFbsBitmapDevice::NewL(bitmap);
       
   265 	CFbsBitGc *gc=CFbsBitGc::NewL();
       
   266 	gc->Activate(bitmapDevice);
       
   267 	gc->DrawEllipse(TRect(size));
       
   268 	delete gc;
       
   269 	delete bitmapDevice;
       
   270 	for(TInt count=0;count<10;count++)
       
   271 		{
       
   272 		iGc->Clear();
       
   273 		TPoint pos(0,0);
       
   274 		for(TInt xcount=0;xcount<25;xcount++,pos.iX+=size.iWidth)
       
   275 			{
       
   276 			pos.iY=0;
       
   277 			for(TInt ycount=0;ycount<4;ycount++,pos.iY+=size.iHeight)
       
   278 				iGc->BitBlt(pos,bitmap);
       
   279 			}
       
   280 		}
       
   281 	delete bitmap;
       
   282 	}
       
   283 
       
   284 TInt BitBltTestFunc(TInt aOwningGroup)
       
   285 	{
       
   286 	return(CreateGraphicsTest(aOwningGroup, EBitBltTest, 0, NULL));
       
   287 	}
       
   288 
       
   289 GLDEF_D TTimeTestHeader BitBltTest={_S("BitBlt"),BitBltTestFunc};
       
   290 
       
   291 // Full Screen BitBlt //
       
   292 
       
   293 void TGraphicsTest::FullScreenBitBltTestL(TInt , TAny *)
       
   294 	{
       
   295 	CWsBitmap *bitmap=new(ELeave) CWsBitmap(iWs);
       
   296 	TSize size(640,240);
       
   297 	User::LeaveIfError(bitmap->Create(size,EGray4));
       
   298 	CFbsDevice *bitmapDevice=CFbsBitmapDevice::NewL(bitmap);
       
   299 	CFbsBitGc *gc=CFbsBitGc::NewL();
       
   300 	gc->Activate(bitmapDevice);
       
   301 	for(TInt pos=0;pos<size.iWidth;pos+=8)
       
   302 		{
       
   303 		gc->DrawRect(TRect(pos,0,pos+16,size.iHeight));
       
   304 		iGc->BitBlt(TPoint(0,0),bitmap);
       
   305 		iWs.Flush();
       
   306 		}
       
   307 	delete gc;
       
   308 	delete bitmapDevice;
       
   309 	delete bitmap;
       
   310 	}
       
   311 
       
   312 TInt FullScreenBitBltTestFunc(TInt aOwningGroup)
       
   313 	{
       
   314 	return(CreateGraphicsTest(aOwningGroup, EFullScreenBitBltTest, 0, NULL));
       
   315 	}
       
   316 
       
   317 GLDEF_D TTimeTestHeader FullScreenBitBltTest={_S("FullScreenBitBlt"),FullScreenBitBltTestFunc};
       
   318 
       
   319 // Masked BitBlt //
       
   320 
       
   321 void TGraphicsTest::MaskedBitBltTestL(TInt , TAny *)
       
   322 	{
       
   323 	TSize size(24,48);
       
   324 	CWsBitmap *bitmap=new(ELeave) CWsBitmap(iWs);
       
   325 	bitmap->Create(size,EGray4);
       
   326 	CFbsDevice *bitmapDevice=CFbsBitmapDevice::NewL(bitmap);
       
   327 	CFbsBitGc *gc=CFbsBitGc::NewL();
       
   328 	gc->Activate(bitmapDevice);
       
   329 	gc->DrawEllipse(TRect(size));
       
   330 	delete bitmapDevice;
       
   331 // Now do the mask
       
   332 	CWsBitmap *mask=new(ELeave) CWsBitmap(iWs);
       
   333 	mask->Create(size,EGray4);
       
   334 	bitmapDevice=CFbsBitmapDevice::NewL(mask);
       
   335 	gc->Activate(bitmapDevice);
       
   336 	gc->SetPenColor(TRgb::Gray4(3));
       
   337 	gc->DrawEllipse(TRect(size));
       
   338 	delete bitmapDevice;
       
   339 //
       
   340 	delete gc;
       
   341 	for(TInt count=0;count<10;count++)
       
   342 		{
       
   343 		iGc->Clear();
       
   344 		TPoint pos(0,0);
       
   345 		for(TInt xcount=0;xcount<25;xcount++,pos.iX+=size.iWidth+1)
       
   346 			{
       
   347 			pos.iY=0;
       
   348 			for(TInt ycount=0;ycount<4;ycount++,pos.iY+=size.iHeight)
       
   349 				iGc->BitBltMasked(pos,bitmap,TRect(size),mask,EFalse);
       
   350 			}
       
   351 		}
       
   352 	delete bitmap;
       
   353 	delete mask;
       
   354 	}
       
   355 
       
   356 TInt MaskedBitBltTestFunc(TInt aOwningGroup)
       
   357 	{
       
   358 	return(CreateGraphicsTest(aOwningGroup, EMaskedBitBltTest, 0, NULL));
       
   359 	}
       
   360 
       
   361 GLDEF_D TTimeTestHeader MaskedBitBltTest={_S("MaskedBitBlt"),MaskedBitBltTestFunc};
       
   362 
       
   363 // Fill Pattern //
       
   364 
       
   365 void TGraphicsTest::FillPatternTestL(TInt , TAny *)
       
   366 	{
       
   367 	TSize scrSize(iDevice->SizeInPixels());
       
   368 	TSize rectSize(scrSize.iWidth/5-1,scrSize.iHeight/2);
       
   369 
       
   370 	CWsBitmap *bitmap=new(ELeave) CWsBitmap(iWs);
       
   371 
       
   372 	TSize bitmapSize(50,40);
       
   373 	bitmap->Create(bitmapSize,EGray4);
       
   374 	CFbsDevice *bitmapDevice=CFbsBitmapDevice::NewL(bitmap);
       
   375 	CFbsBitGc *gc=CFbsBitGc::NewL();
       
   376 	gc->Activate(bitmapDevice);
       
   377 	gc->SetBrushColor(TRgb::Gray4(2));
       
   378 	gc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   379 	gc->DrawEllipse(TRect(bitmapSize));
       
   380 	delete bitmapDevice;
       
   381 	delete gc;
       
   382 //
       
   383 	iGc->UseBrushPattern(bitmap);
       
   384 	iGc->SetBrushStyle(CGraphicsContext::EPatternedBrush);
       
   385 	iGc->SetPenStyle(CGraphicsContext::ESolidPen);
       
   386 	for(TInt count=0;count<50;count++)
       
   387 		{
       
   388 		iGc->Clear();
       
   389 		TPoint pos(0,0);
       
   390 		for(TInt xcount=0;xcount<5;xcount++,pos.iX+=rectSize.iWidth)
       
   391 			{
       
   392 			pos.iY=0;
       
   393 			for(TInt ycount=0;ycount<2;ycount++,pos.iY+=rectSize.iHeight)
       
   394 				iGc->DrawRect(TRect(pos,rectSize));
       
   395 			}
       
   396 		}
       
   397 	delete bitmap;
       
   398 	}
       
   399 
       
   400 TInt FillPatternTestFunc(TInt aOwningGroup)
       
   401 	{
       
   402 	return(CreateGraphicsTest(aOwningGroup, EFillPatternTest, 0, NULL));
       
   403 	}
       
   404 
       
   405 GLDEF_D TTimeTestHeader FillPatternTest={_S("FillPattern"),FillPatternTestFunc};
       
   406 
       
   407 // Backup Window Drawing //
       
   408 
       
   409 void TGraphicsTest::BackedUpWindowDrawingL(TInt aMode, TAny *)
       
   410 	{
       
   411 	TSize scrSize(iDevice->SizeInPixels());
       
   412 	CFbsFont *font=NULL;
       
   413 	if (aMode==1)
       
   414 		{
       
   415 		TFontSpec fspec(KTestFontTypefaceName,200);
       
   416 		User::LeaveIfError(iDevice->GetNearestFontToDesignHeightInTwips((CFont *&)font, fspec));
       
   417 		iGc->UseFont(font);
       
   418 		}
       
   419 	iGc->SetPenStyle(CGraphicsContext::ESolidPen);
       
   420 	TPoint pos;
       
   421 	for(TInt count=0;count<10;count++)
       
   422 		{
       
   423 		iGc->Clear();
       
   424 		for(pos.iY=0;pos.iY<scrSize.iHeight;pos.iY++)
       
   425 			iGc->DrawLine(pos,pos+TSize(scrSize.iWidth,0));
       
   426 		}
       
   427 	if (aMode==1)
       
   428 		iDevice->ReleaseFont(font);
       
   429 	}
       
   430 
       
   431 TInt BackupWindowDrawingFunc1(TInt aOwningGroup)
       
   432 	{
       
   433 	return(CreateGraphicsTest(aOwningGroup, EBackupWindowDrawingTest, 0, NULL));
       
   434 	}
       
   435 
       
   436 GLDEF_D TTimeTestHeader BackupWindowDrawingCreate1={_S("BackupWindowDrawing 1"),BackupWindowDrawingFunc1};
       
   437 
       
   438 TInt BackupWindowDrawingFunc2(TInt aOwningGroup)
       
   439 	{
       
   440 	return(CreateGraphicsTest(aOwningGroup, EBackupWindowDrawingTest, 1, NULL));
       
   441 	}
       
   442 
       
   443 GLDEF_D TTimeTestHeader BackupWindowDrawingCreate2={_S("BackupWindowDrawing 2"),BackupWindowDrawingFunc2};