os/graphics/windowing/windowserver/test/tdynamicres/src/wsdynamicresbase.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) 2008-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 #include <w32std.h>
    17 #include "wsdynamicresbase.h"
    18 #include "teflogextensions.h"
    19 #include "globalsettings.h"
    20 #include <bitdraw.h>
    21 #include <bitdrawinterfaceid.h>
    22 #include <bitdrawsurface.h>
    23 #include <graphics/surfaceconfiguration.h>
    24 #include "regionextend.h"
    25 
    26 
    27 #if defined(__X86GCC__)
    28 extern "C" TInt atexit(void (*function)(void))
    29 	{
    30 	return KErrNone;
    31 	}
    32 #endif
    33 
    34 CWsDynamicResBase::CWsDynamicResBase():
    35 	iUtility(this)
    36 	{
    37 	}
    38 
    39 CWsDynamicResBase::~CWsDynamicResBase()
    40 	{
    41 	}
    42 
    43 /**
    44 Common set up code for all tests.
    45 
    46 Creates the session and window group for further windows, plus a simple white
    47 background to obscure any unwanted stuff behind the test. Sets up the surface
    48 update session and surface manager, to work with surfaces. Creates a screen
    49 device for use in the tests.
    50 */
    51 void CWsDynamicResBase::SetupL()
    52 	{
    53 	SetupL(EFalse);
    54 	}
    55 void CWsDynamicResBase::SetupL(TBool aUseOtherScreenForInfo)
    56 	{
    57 	CWsDynamicResWinBase::SetupL(aUseOtherScreenForInfo);
    58 	
    59 	
    60 //clean-up if previous test abended
    61 	if (PostTestCleanupInstance().iSharedUtility)
    62 	{
    63 //Temp removed - may be causing ONB fails!
    64 //	if (PostTestCleanupInstance().iSharedUtility->DestroyAll())
    65 //		{
    66 //		INFO_PRINTF1(_L("Destroyed some surfaces from previous test."));
    67 //
    68 //		}
    69 	}
    70 	if (!PostTestCleanupInstance().iCleanedUpOnExit)
    71 	PostTestCleanupInstance().iCleanedUpOnExit=EFalse;
    72 	
    73 	if (!GCEIsSupported())
    74 		{
    75 		INFO_PRINTF1(_L("Some Setup skipped: GCE support is not loaded"));
    76 		return;
    77 		}
    78 
    79 	TRAPD(err_FailedToCreateSurfaceUtility, iUtility = CSurfaceUtility::NewL( PostTestCleanupInstance().iSharedUtility));
    80 	ASSERT_EQUALS(err_FailedToCreateSurfaceUtility,KErrNone);
    81 
    82 	
    83 	}
    84 
    85 /**
    86 Common tear down code for all tests.
    87 
    88 Windows, group and session created are closed. Screen device is destroyed.
    89 Surfaces, manager and update session are closed.
    90 */
    91 void CWsDynamicResBase::TearDownL()
    92 	{
    93 	CWsDynamicResWinBase::TearDownL();
    94 	delete iUtility();
    95 	PostTestCleanupInstance().iCleanedUpOnExit=ETrue;
    96 	//Pause(1000);
    97 	}
    98 /**
    99  * Note that this is not the ideal mechanism.
   100  * A derived class may thinks its TearDown is safe to do from delete, but in the class it is derived from it may not be safe
   101  **/
   102 void CWsDynamicResBase::TearDownFromDeleteL()	
   103 	{
   104 	CWsDynamicResBase::TearDownL();	
   105 	}
   106 
   107 //Allocating an instance of surface utility here means all test code instances will share the same instance of the utility class.
   108 // Owns the singleton
   109 /*static*/ const CWsDynamicResBase::TPostTestCleanup& CWsDynamicResBase::PostTestCleanupInstance()
   110 	{
   111 	static 
   112 	class RPostTestCleanup:public TPostTestCleanup
   113 		{
   114 		public:
   115 		RPostTestCleanup()
   116 			{
   117 			iSharedUtility=NULL;
   118 			iCleanedUpOnExit=ETrue;
   119 			}
   120 		~RPostTestCleanup()
   121 			{
   122 	// I want to cleanly release the surface utility, but at this point the threads have already been pulled down!
   123 	//		if (iSharedUtility)
   124 	//			delete iSharedUtility;
   125 			iSharedUtility=NULL;	//avoid phoenix behaviour
   126 			}
   127 		}	staticInstance;
   128 		return staticInstance;
   129 	}
   130 
   131 void	CWsDynamicResBase::TPostTestCleanup::CreateSharedUtilityL()const
   132 	{
   133 	if (iSharedUtility==NULL)
   134 		iSharedUtility=CSurfaceUtility::NewL();
   135 	}
   136 
   137 /**
   138 Pause for the given number of milliseconds.
   139 
   140 @param aMilliseconds	Time to wait in milliseconds.
   141 */
   142 void CWsDynamicResBase::Pause(TInt aMilliseconds)
   143 	{
   144 	User::After(TTimeIntervalMicroSeconds32(aMilliseconds * 1000));
   145 	}
   146 
   147 void CWsDynamicResBase::LargerTestWindow(TInt aPercentOfBack)
   148 	{
   149 	TRect newPos=iTestPos;
   150 	TSize backSize=iTestPos.Size();
   151 	newPos.Grow((aPercentOfBack-100)*backSize.iWidth/200,(aPercentOfBack-100)*backSize.iHeight/200);
   152 	iCenteredFrontWinRect=newPos;
   153 	if (iTestFront.WsHandle())
   154 		{
   155 		iTestFront.SetExtent(newPos.iTl,newPos.Size());
   156 		}
   157 	
   158 	}
   159 
   160 
   161 void CWsDynamicResBase::MakeExtraChildWindowL(const RWindowBase& aFromParent,TRect aChildRect,TRgb aChildColor)
   162 	{
   163 	ASSERT(aFromParent.WsHandle());
   164 	if (!iTestSecondChild.WsHandle())
   165 		{
   166 		iTestSecondChild=RWindow(iSession);
   167 		ASSERT_EQUALS_X(iTestSecondChild.Construct(aFromParent, ++iWindowHandle), KErrNone);
   168 		iTestSecondChild.SetRequiredDisplayMode(iDisplayMode);
   169 		}
   170 	iTestSecondChild.SetBackgroundColor(aChildColor);
   171 	iTestSecondChild.SetExtent(aChildRect.iTl,aChildRect.Size());
   172 	iTestSecondChild.Activate();
   173 	iTestSecondChild.BeginRedraw();
   174 	iGc->Activate(iCompare);
   175 	iGc->SetBrushColor(iBlue);
   176 	iGc->Clear();
   177 	iGc->Deactivate();
   178 	iTestSecondChild.EndRedraw();
   179 	iTestSecondChild.SetVisible(ETrue);
   180 	}
   181 
   182 CWsDynamicResBase::LoopingGcPtr  CWsDynamicResBase::LoopBeginActivateWithWipe(const TRegion& aRegion,RWindow& aWin,TRgb aColor)
   183 	{
   184 	InvalidateRegion(aRegion,aWin);
   185 	return LoopingGcPtr(aRegion,aWin,aColor,GcForWindow(aWin));
   186 	}
   187 
   188 //This gets called each itteration of the while loop, and is used to step the rectangle count!
   189 void CWsDynamicResBase::LoopingGcPtr::operator ++()
   190 	{
   191 	iPass++;
   192 	if (iPass<iRegion.Count())
   193 		{	//Invalidate all the rectangles in the region
   194 		iWin.BeginRedraw(iRegion[iPass]);
   195 		CWsDynamicResWinBase::ActivateWithWipe(iGc,iWin,iColor);
   196 //		return true;
   197 		}
   198 	else
   199 		{
   200 		iGc=NULL;
   201 //		return false;
   202 		}
   203 	}
   204 
   205 CWindowGc*	CWsDynamicResBase::BeginActivateWithWipe(TBool aInvalidate,RWindow& aWin,TRgb aColor)
   206 	{
   207 	return CWsDynamicResWinBase::BeginActivateWithWipe(aInvalidate,aWin,aColor);
   208 	}
   209 
   210 CWindowGc*	CWsDynamicResBase::BeginActivateWithWipe(TBool aInvalidate,TRect aRect,RWindow& aWin,TRgb aColor)
   211 	{
   212 	return CWsDynamicResWinBase::BeginActivateWithWipe(aInvalidate,aRect,aWin,aColor);
   213 	}
   214 
   215 CWindowGc*	CWsDynamicResBase::BeginActivateWithWipe(const TRegion& aRegion,RWindow& aWin,TRgb aColor)
   216 	{
   217 	return CWsDynamicResWinBase::BeginActivateWithWipe(aRegion,aWin,aColor);
   218 	}
   219 
   220 /**	
   221  * 	Generates a valid surfaceID for the current display mode.
   222  * 	This is then used in negative testing.
   223  * 
   224  * 
   225  **/
   226 void CWsDynamicResBase::UISurfaceL(TSurfaceId& aSurfaceId) const
   227 	{
   228 	CFbsDrawDevice* screenDevice=NULL;
   229 	TDisplayMode displayMode=iScreenDevice->DisplayMode();
   230 	screenDevice = CFbsDrawDevice::NewScreenDeviceL(TGlobalSettings::Instance().iScreen, displayMode);
   231 	CleanupStack::PushL(screenDevice);
   232 	TAny* p=NULL;
   233 	User::LeaveIfError(screenDevice->GetInterface(KSurfaceInterfaceID, p));
   234 	MSurfaceId* uiSurface = static_cast<MSurfaceId*>(p);
   235 	uiSurface->GetSurface(aSurfaceId);
   236 	CleanupStack::PopAndDestroy(screenDevice);
   237 	}
   238 
   239 /**
   240 Common set up code for creating a surface based window.
   241 
   242 Given window and surface objects and a color: creates the window and surface,
   243 sets the window to a default size (the same as the surface), sets the background
   244 to the bitwise inverse of the given color, sets the surface as the background,
   245 fills the surface with the color and completes a redraw to prevent an event.
   246 
   247 @param aWindow	The window object, connected to a session.
   248 @param aSurface	The surface object, to be initialized.
   249 @param aColor	The color to fill the surface with.
   250 */
   251 void CWsDynamicResBase::CommonSurfaceWindowSetupL(RWindow& aWindow, TSurfaceId& aSurface, const TRgb& aColor)
   252 	{
   253 	TInt err = KErrNone;
   254 
   255 	TRAP(err, aSurface = iUtility->CreateSurfaceL(TSize(KSurfaceWidth, KSurfaceHeight), 
   256 			KSurfaceFormat, KSurfaceWidth * KBytesPerPixel));
   257 	PRINT_ON_ERROR2_L(err, _L("Failed to create surface: %d"), err);
   258 	ASSERT_EQUALS_X(aWindow.Construct(iGroup, ++iWindowHandle), KErrNone);
   259 
   260 	aWindow.SetRequiredDisplayMode(iDisplayMode);
   261 	aWindow.SetExtent(TPoint(0, 0), TSize(KSurfaceWidth, KSurfaceHeight));
   262 	aWindow.SetBackgroundColor(TRgb(aColor.Value() ^ 0xFFFFFF));
   263 
   264 	ASSERT_EQUALS_X(aWindow.SetBackgroundSurface(aSurface), KErrNone);
   265 
   266 	TRAP(err, iUtility->FillSurfaceL(aSurface, aColor));
   267 	PRINT_ON_ERROR2_L(err, _L("Failed to fill surface: %d"), err);
   268 	DrawUIContent(aWindow);
   269 	}
   270 
   271 /**
   272 Common set up code for resizing tests.
   273 
   274 Similar to the common surface window code, but filling the surface with a grid
   275 instead of a solid color. The grid lines are always black. Also, the background
   276 color is always blue.
   277 */
   278 void CWsDynamicResBase::ResizeTestCommonSetupL(RWindow& aWindow, const TRgb& aColor)
   279 	{
   280 	// Session and group created in SetUpL()
   281 
   282 	TSurfaceId surface;
   283 	TInt err = KErrNone;
   284 
   285 	TRAP(err, surface = iUtility->CreateSurfaceL(TSize(KSurfaceWidth, KSurfaceHeight), 
   286 			KSurfaceFormat, KSurfaceWidth * KBytesPerPixel));
   287 	PRINT_ON_ERROR2_L(err, _L("Failed to create surface: %d"), err);
   288 
   289 	ASSERT_EQUALS_X(aWindow.Construct(iGroup, ++iWindowHandle), KErrNone);
   290 
   291 	aWindow.SetRequiredDisplayMode(iDisplayMode);
   292 	aWindow.SetExtent(TPoint(0, 0), TSize(KSurfaceWidth, KSurfaceHeight));
   293 	aWindow.SetBackgroundColor(iBlue);
   294 	ASSERT_EQUALS_X(aWindow.SetBackgroundSurface(surface), KErrNone);
   295 
   296 	TRAP(err, iUtility->GridFillSurfaceL(surface, aColor, TRgb(0)));
   297 	PRINT_ON_ERROR2_L(err, _L("Failed to grid fill surface: %d"), err);
   298 	DrawUIContent(aWindow);
   299 	}
   300 
   301 CFbsBitmap* CWsDynamicResBase::RotateBitmapLC(const CFbsBitmap* aSrcBitmap)
   302 	{
   303 	CFbsBitmap* rv=new CFbsBitmap;
   304 	CleanupStack::PushL(rv);
   305 	TSize srcSize=aSrcBitmap->SizeInPixels();
   306 	rv->Create(TSize(srcSize.iHeight,srcSize.iWidth),EColor16MA);
   307 	TRgb* linestore=new TRgb[srcSize.iHeight];
   308 	TPtr8 buff((unsigned char*)linestore,srcSize.iHeight*sizeof(TRgb),srcSize.iHeight*sizeof(TRgb));
   309 	for (TInt col=0;col<aSrcBitmap->SizeInPixels().iWidth;col++)
   310 		{
   311 		for (TInt row=0,brow=srcSize.iHeight-1;row<srcSize.iHeight;row++,brow--)
   312 			{
   313 			aSrcBitmap->GetPixel(linestore[row],TPoint(col,brow));
   314 			}
   315 		rv->SetScanLine(buff,col);
   316 		}
   317 	delete[] linestore;
   318 	return rv;
   319 	}
   320 
   321 
   322 //
   323 //
   324 //
   325 // Pattern checking. Is a given pattern still present?
   326 // To make life interesting, the pattern is stored backwards!
   327 // The pattern is fibonnacci sequence masked to byte:
   328 //	1	2	3	5	8	13	21	34	55	89	144	233	121
   329 //	98	219	61	24	85	109	194	47	241	32	17	49	66
   330 //	115	181	40	221	5	226	231	201	176	121	41	162
   331 //
   332 //
   333 void Pattern::Fill(void* aTrg,TInt aOffset,TInt aLength)
   334 	{
   335 	unsigned char* ptr=(unsigned char*)aTrg;
   336 	TInt a=0;
   337 	TInt b=1;
   338 	while (--aLength)
   339 		{
   340 			TInt c=a+b;
   341 			*(ptr+aOffset+aLength)=c&0xff;
   342 			a=b;
   343 			b=c;
   344 		}
   345 	}
   346 TBool Pattern::Check(void* aTrg,TInt aOffset,TInt aLength)
   347 	{
   348 	unsigned char* ptr=(unsigned char*)aTrg;
   349 	TInt a=0;
   350 	TInt b=1;
   351 	while (--aLength)
   352 		{
   353 			TInt c=a+b;
   354 			if (*(ptr+aOffset+aLength)!=c&0xff)
   355 				return EFalse;
   356 			a=b;
   357 			b=c;
   358 		}
   359 	return ETrue;
   360 	}
   361 TBool Pattern::CheckVal(void* aTrg,TInt aOffset,TInt aLength,char val)
   362 	{
   363 	unsigned char* ptr=(unsigned char*)aTrg;
   364 	while (--aLength)
   365 		{
   366 			if (*(ptr+aOffset+aLength)!=val&0xff)
   367 				return EFalse;
   368 		}
   369 	return ETrue;
   370 	}
   371 
   372 //I have removed these only because they use TRegionExtend
   373 //
   374 //TInt	CWsDynamicResBase::RegionDiffForUiLayer(TInt aUiLayer)
   375 //	{
   376 //	EWsDebugGetUILayerConfig,		//return: TSurfaceConfig		//Index UI layer via EWsDebugArgLayerMask
   377 //	EWsDebugGetUILayerBase,			//return: TRect[]
   378 //	
   379 //	RRegion 	layerRegion;
   380 //	TInt layerRegionLen=iSession.DebugInfo(EWsDebugGetUILayerBase,iSession.ObjInd(0,aUiLayer),layerRegion);
   381 //	if (layerRegionLen==KErrCancel)
   382 //		return TRegionExtend::EExact;
   383 //	ASSERT_TRUE(layerRegionLen>=0);
   384 //	TBuf8<sizeof(TSurfaceConfiguration)> configBuf(sizeof(TSurfaceConfiguration));
   385 //	const TSurfaceConfiguration* config;
   386 //	TInt configLen=iSession.DebugInfo(EWsDebugGetUILayerConfig,iSession.ObjInd(0,aUiLayer),configBuf,config);
   387 //	ASSERT_TRUE(configLen>=0);
   388 //	TRect layerExtent;
   389 //	config->GetExtent(layerExtent);
   390 //	TInt retVal=TRegionExtend::Cast(layerRegion).TestDifference(layerExtent.Size());
   391 //	layerRegion.Close();
   392 //	return retVal;
   393 //	}
   394 //CWsDynamicResBase::FastPathMode	CWsDynamicResBase::DeduceUiFastPathMode()
   395 //	{
   396 //	TInt blendedRegionState=RegionDiffForUiLayer(0);
   397 //	TInt opaqueRegionState=RegionDiffForUiLayer(1);
   398 //	if (blendedRegionState&TRegionExtend::ENoIntersect)
   399 //		{
   400 //		if (opaqueRegionState&TRegionExtend::ENoIntersect)
   401 //			{
   402 //			return EFpExternalOpaque;			//fullscreen fast-path external surface
   403 //			}
   404 //		else
   405 //			if (opaqueRegionState&TRegionExtend::EAdd)
   406 //				{
   407 //				return (FastPathMode)(EFpUiOpaque|EFpUiRegions);	//windowed max-opt no blending
   408 //				}
   409 //			else
   410 //				{
   411 //				return EFpUiOpaque;		//full-screen fastpath
   412 //				}
   413 //		}
   414 //	else
   415 //		{
   416 //		if (opaqueRegionState&TRegionExtend::ENoIntersect)
   417 //			{
   418 //			if (blendedRegionState&TRegionExtend::EAdd)
   419 //				{
   420 //				return (FastPathMode)(EFpUiBlended|EFpUiRegions);	//windowed max-opt no opaque
   421 //				}
   422 //			else
   423 //				{
   424 //				return (EFpUiBlended);	//full-screen blended
   425 //				}
   426 //			}
   427 //		else
   428 //			{
   429 //			if ((blendedRegionState|opaqueRegionState)&TRegionExtend::EAdd)
   430 //				{
   431 //				return (FastPathMode)(EFpUiComplex|EFpUiRegions);	//moxed blending, opaque and external max optimisation
   432 //				}
   433 //			else
   434 //				{
   435 //				return EFpUiComplex;	//Error! blend and opaque both enabled and full-screen!
   436 //				}
   437 //			}
   438 //		
   439 //		}
   440 //	}