os/graphics/graphicsdeviceinterface/screendriver/tsrc/tscdvdevorientation.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2004-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 <e32math.h>
    17 #include <hal.h>
    18 #include <bitdraw.h>
    19 #include <bitdrawinterfaceid.h>
    20 #include <graphics/gdi/gdiconsts.h>
    21 #include "tscdvdevorientation.h"
    22 
    23 void AutoPanic(TInt aPanic)
    24 	{
    25 	User::Panic(_L("Auto"),aPanic);
    26 	}
    27 
    28 LOCAL_C TInt PanicThreadFunc(TAny *aPointerToAny)
    29 	{
    30 	CTrapCleanup* CleanUpStack=CTrapCleanup::New();
    31 	SPanicParams *pointerPanicParams=(SPanicParams *)aPointerToAny;
    32 	TInt ret;
    33 	TRAP(ret,(*pointerPanicParams->functionName)(*pointerPanicParams->pointerDeviceOrientation,*pointerPanicParams->pointerDisplayMode,*pointerPanicParams->pointerScreenNo));
    34 	delete CleanUpStack;
    35 	if (ret==EWsExitReasonBad)
    36 		AutoPanic(EAutoPanicPanicFailed);
    37 	return(ret);
    38 	}
    39 
    40 CPanicTest::CPanicTest()
    41 	{
    42 	
    43 	}
    44 	
    45 CPanicTest::~CPanicTest()
    46 	{
    47 	
    48 	}
    49 TInt CPanicTest::LaunchPanicThread(RThread &aThread, SPanicParams *aPointerPanicParams)
    50 	{
    51 	TBuf<32> threadName;
    52 	threadName.Format(TRefByValue<const TDesC>(_L("AutoPanicThread%d")),iThreadNumber++);
    53 	return(aThread.Create(threadName,PanicThreadFunc,KDefaultStackSize,KPanicThreadHeapSize,KPanicThreadHeapSize,aPointerPanicParams,EOwnerThread));
    54 	}
    55 
    56 TInt CPanicTest::TestPanicL(SPanicParams *aPointerPanicParams, TInt aExitReason, const TDesC &aCategory, TBool* aTestFinished)
    57 	{
    58 	RThread thread;
    59 	TRequestStatus stat;
    60 	TInt err=LaunchPanicThread(thread, aPointerPanicParams);
    61 	if (err==KErrAlreadyExists)
    62 		{
    63 		// wait for kernel to clear up old threads
    64 		// and have several attempts at starting the thread
    65 		// if unsuccessful the first time
    66 		for (TInt i=0;i<3;i++)
    67 			{
    68 			User::After(TTimeIntervalMicroSeconds32(100000));		//0.1 secs
    69 			err=LaunchPanicThread(thread, aPointerPanicParams);
    70 			if (err!=KErrAlreadyExists)
    71 				break;
    72 			}
    73 		}
    74 	User::LeaveIfError(err);
    75 	thread.Logon(stat);
    76 	User::SetJustInTime(EFalse);
    77 	thread.Resume();
    78 	User::WaitForRequest(stat);
    79 	User::SetJustInTime(ETrue);
    80 
    81 	TBool testFinished=EFalse;
    82 	TBool testPassed=EFalse;
    83 	if (thread.ExitType()==EExitPanic)	   // the function is panicked
    84 		{
    85 		// ignore code for transparency
    86 		if(aExitReason == thread.ExitReason())  // panic reason is equal to the scdv EScreenDriverPanicInvalidParameter
    87 			{
    88 			testPassed=ETrue;
    89   			}
    90 		iActualPanicCode=thread.ExitReason();
    91 		testFinished=ETrue;	// Finish tests
    92 		}
    93 	else
    94 		{
    95 		if((thread.ExitCategory().Compare(aCategory)!=0)
    96 		|| (thread.ExitReason()!=aExitReason)
    97 		|| (thread.ExitType()!=EExitPanic)		//This last condition is always true!!!!!!
    98 			)
    99 			{
   100 			testPassed=EFalse;
   101 			}			
   102 		iActualPanicCode=0;
   103 		}
   104 
   105 	if(aTestFinished)
   106 		*aTestFinished=testFinished;
   107 	thread.Close();
   108 	return(testPassed);
   109 	}
   110 
   111 TInt CPanicTest::TestInvalidModePanicL(TPanicFunction aFunction, TScreenDriverPanic aExitReason,TDisplayMode* aPointerDispMode, TDeviceOrientation* aPointerDevOrientation,TInt* aPtrScreenNo, TBool* aTestFinished)
   112 	{
   113 	// function name, exit reason, and parameters
   114 	return TestPanicL(aFunction,aExitReason,KSCDVPanicCategory, aPointerDispMode, aPointerDevOrientation, aPtrScreenNo, aTestFinished);
   115 	}
   116 	
   117 TInt CPanicTest::TestPanicL(TPanicFunction aFunction, TInt aExitReason, const TDesC &aCategory, TDisplayMode* aPointerDispMode, TDeviceOrientation* aPointerDevOrientation,TInt* aPtrScreenNo, TBool* aTestFinished)
   118 	{
   119 	SPanicParams params;
   120 	params.functionName=aFunction;
   121 	params.pointerDeviceOrientation = aPointerDevOrientation;
   122 	params.pointerDisplayMode = aPointerDispMode;
   123 	params.pointerScreenNo = aPtrScreenNo;
   124 	return TestPanicL(&params, aExitReason, aCategory, aTestFinished);
   125 	}
   126 
   127 
   128 //
   129 //Test code
   130 //
   131 
   132 CTDevOrientation::CTDevOrientation(CTestStep *aTest, RArray<TInt> aArrayDispModes) :
   133 				CTGraphicsBase(aTest),iArrayDispModesPerScreen(aArrayDispModes)
   134 	{
   135 	INFO_PRINTF1(_L("Screen Device Orientation tests"));
   136 	}
   137 
   138 CTDevOrientation::CTDevOrientation(CTestStep *aTest) :
   139 				CTGraphicsBase(aTest)
   140 	{
   141 	INFO_PRINTF1(_L("Screen Device Orientation tests"));
   142 	}
   143 
   144 void CTDevOrientation::ConstructL()	
   145 	{
   146 	iPanicTest = new (ELeave) CPanicTest();
   147 	}
   148 	
   149 CTDevOrientation::~CTDevOrientation()
   150 	{
   151 	iArrayOrientation.Close();
   152 	iArrayDispModesPerScreen.Close();
   153 	delete iPanicTest;
   154 	}
   155 
   156 /**
   157 Create the screen device and surface interface objects for the specific screen and display mode
   158 @internalAll
   159 @return ETrue means valid screen device and surface interface objects are created, EFalse means a leave or an error
   160 @param aScreenNo the screen no
   161 @param aDisplayMode the specified display mode
   162 @param aDrawScreenDevice 
   163 @param aSurfaceIdInterface
   164 */
   165 TBool CTDevOrientation::GetSurfaceIdInterfaceL(const TInt& aScreenNo,const TDisplayMode& aDisplayMode, CFbsDrawDevice*& aDrawScreenDevice, MSurfaceId*& aSurfaceIdInterface )
   166 	{
   167 	
   168 	TInt address = NULL;
   169 	User::LeaveIfError(HAL::Get(aScreenNo, HALData::EDisplayMemoryAddress,address));
   170 	User::LeaveIfError(HAL::Get(aScreenNo, HALData::EDisplayXPixels, iPhysSize.iWidth));
   171 	User::LeaveIfError(HAL::Get(aScreenNo, HALData::EDisplayYPixels, iPhysSize.iHeight));
   172 	__ASSERT_DEBUG(iPhysSize.iWidth > 0 && iPhysSize.iHeight > 0 && address != NULL, User::Invariant());
   173 
   174    	aDrawScreenDevice = NULL;
   175 	TRAPD(err, aDrawScreenDevice = CFbsDrawDevice::NewScreenDeviceL(aScreenNo, aDisplayMode));
   176 
   177 	if(err == KErrNone)	  // as aDisplayMode is verified to be supported so this should be the case
   178 		{  
   179 		__ASSERT_ALWAYS(aDrawScreenDevice != NULL, User::Invariant());
   180 		//Set other properties
   181     	aDrawScreenDevice->SetUserDisplayMode(aDisplayMode);
   182 		aDrawScreenDevice->SetAutoUpdate(EFalse);
   183 		if(!aSurfaceIdInterface)
   184 			{
   185 			err = aDrawScreenDevice->GetInterface(KSurfaceInterfaceID, reinterpret_cast <TAny*&> (aSurfaceIdInterface));
   186 			}
   187 		if (err == KErrNone && aSurfaceIdInterface != NULL)
   188 			{
   189 			return ETrue;
   190 			}
   191 		else 
   192 			{
   193 			delete aDrawScreenDevice;
   194 			return EFalse;
   195 			}
   196 		}
   197 	else 
   198 	 	{
   199 	 	// Leave with error codes
   200 	 	INFO_PRINTF2(_L("CFbsDrawDevice::NewScreenDeviceL leaves with code =%d"), err);
   201 	 	return EFalse;
   202 	 	}
   203 	}
   204 
   205 /**
   206 Retrive the required bpp value and pixel format based on the specified display mode
   207 @internalAll
   208 @return ETrue means the display mode is supported
   209 @param aDisplayMode the specified display mode
   210 @param aBpp the required bpp value
   211 @param aPixelFormat the required pixel format 
   212 */
   213 TBool CTDevOrientation::ReqBppAndPixelFormat(TDisplayMode aDisplayMode, TInt& aBpp, TUint32& aPixelFormat)	
   214 	{
   215 //	aBpp = TDisplayModeUtils::NumDisplayModeBitsPerPixel(aDisplayMode);
   216 
   217 	switch(aDisplayMode)
   218 		{
   219 	case EGray2:
   220 		aPixelFormat = 0;
   221         aBpp = 1;
   222         break;
   223     case EGray4:
   224 		aPixelFormat = 0;
   225         aBpp = 2;
   226         break;
   227     case EGray16:
   228     case EColor16:
   229 		aPixelFormat = 0;
   230         aBpp = 4;
   231         break;
   232     case EGray256:
   233     case EColor256: // 8 Bpp color mode
   234 		aPixelFormat = 0;
   235 		aBpp = 8;
   236 		break;
   237 	case EColor4K:
   238 		aPixelFormat = EUidPixelFormatXRGB_4444; //12 Bpp color mode
   239 		aBpp = 12;
   240 		break;
   241 	case EColor64K: // 16 Bpp color mode
   242 		aPixelFormat = EUidPixelFormatRGB_565;
   243 		aBpp = 16;
   244 		break;
   245 	case EColor16MU:   //24 Bpp color mode
   246 		aPixelFormat = EUidPixelFormatXRGB_8888;
   247 		aBpp = 24;
   248 		break;
   249 	case EColor16MA:   // 32 Bpp color mode
   250 		aPixelFormat = EUidPixelFormatARGB_8888;
   251 		aBpp = 32;
   252 		break;
   253 	case EColor16MAP:
   254 		aPixelFormat = EUidPixelFormatARGB_8888_PRE;
   255 		aBpp = 32;
   256 		break;
   257 		default:
   258 		return EFalse;	
   259 		}  
   260 	return ETrue;
   261 	}
   262 	
   263 void CTDevOrientation::TestGetSurfaceWithValidDispModeL(const MSurfaceId* aSurfaceIdInterface, const TDisplayMode& aDisplayMode, TInt aScreenNo)
   264 	{
   265 	// Sanity check
   266 	__ASSERT_ALWAYS(aSurfaceIdInterface != NULL, User::Invariant());
   267 	TSurfaceId surfaceId;
   268 	aSurfaceIdInterface->GetSurface(surfaceId);
   269 	INFO_PRINTF1(_L("Test GetSurface() returns valid surface Id with the specified display modes"));		
   270 	//Check the screen no
   271 	TEST(surfaceId.iInternal[0] == aScreenNo);
   272 	// Hal mode
   273 	TInt halMode = surfaceId.iInternal[1];	 // 24bpp and 32bpp are currently considered the same by HAL
   274 	User::LeaveIfError(HAL::Get(surfaceId.iInternal[0], HALData::EDisplayBitsPerPixel, halMode));
   275     TUint32 pixelFormat = 0;
   276     TInt bpp = 0;
   277     if (ReqBppAndPixelFormat(aDisplayMode,bpp, pixelFormat))
   278     	{
   279     	// Check the color depth 
   280    		TEST(bpp == halMode || bpp == 24 && halMode == 32 || bpp == 32 && halMode == 24);
   281 		// Check the pixel format
   282 		TEST(surfaceId.iInternal[2] == pixelFormat);//Need to test the type as well
   283 		// Check the surface type
   284 		TEST(surfaceId.iInternal[3]>>24 == TSurfaceId::EScreenSurface );
   285 		}
   286 	else
   287 		INFO_PRINTF1(_L("Unsupported display modes"));			
   288 	}
   289 
   290 /**
   291 Retrive all the availably supported device orientation modes by the hardware.
   292 @internalAll
   293 @return ETrue means there are valid device orientation modes supported, EFalse means no good mode supported
   294 @param aSurfaceIdInterface MSurfaceId* 
   295 */
   296 TBool CTDevOrientation::ChooseOrientationMode( MSurfaceId* aSurfaceIdInterface)
   297 	{
   298 	__ASSERT_ALWAYS(aSurfaceIdInterface != NULL, User::Invariant());
   299 	TUint orAvailable = aSurfaceIdInterface->DeviceOrientationsAvailable();
   300 	iArrayOrientation.Reset();
   301 	if ( orAvailable <= 15 || orAvailable > 0)
   302 		{
   303 		if (iArrayOrientation.Count() == 0)	   // Only fills the array once
   304 			{
   305 			// there is at least one mode available
   306 			// Find one availabe device orientation mode
   307 			for (TUint32 mode = (TUint32)EDeviceOrientationNormal; mode <= (TUint)EDeviceOrientation270CW; mode*=2)
   308 				{
   309 				if ( orAvailable & (TDeviceOrientation)mode)
   310 					{
   311 					iArrayOrientation.Append((TDeviceOrientation)mode);
   312 					}
   313 				}
   314 			} 
   315 		return ETrue;
   316 		}
   317 	else 
   318 		{
   319 		// No available mode supported
   320 		return EFalse;
   321 		}
   322 	}
   323 
   324 void CTDevOrientation::TestGetDeviceOrientation( MSurfaceId* aSurfaceIdInterface)
   325 	{
   326     if (ChooseOrientationMode(aSurfaceIdInterface) && iArrayOrientation.Count() != 0)
   327     	{
   328        	INFO_PRINTF1(_L("Test DeviceOrientationAvailabe() returns one or a combination of valid modes"));		
   329     	}
   330     else
   331        	INFO_PRINTF1(_L("Test DeviceOrientationAvailabe() gives no valid returns"));		
   332 	}
   333 
   334 	
   335 void CTDevOrientation::TestDeviceOrientationSettingandGetting( MSurfaceId* aSurfaceIdInterface)
   336 	{
   337 	__ASSERT_ALWAYS(aSurfaceIdInterface != NULL, User::Invariant());
   338     if (ChooseOrientationMode(aSurfaceIdInterface) && iArrayOrientation.Count() != 0)
   339     	{
   340        	for (TInt i = 0; i < iArrayOrientation.Count(); i++)
   341        		{
   342 	       	// Set the orientation
   343 			aSurfaceIdInterface->SetDeviceOrientation(iArrayOrientation[i]);
   344 			INFO_PRINTF2(_L("Test SetDeviceOrientation() and GetDeviceOrientation() for DeviceOrientation Mode %d"), i);
   345 			//Get the orientation
   346 			TEST(iArrayOrientation[i] == aSurfaceIdInterface->DeviceOrientation());		
   347        		}
   348     	}
   349 	else
   350 		{
   351 		// No avaialbe orientation modes
   352 		INFO_PRINTF1(_L("No availabe device orientation modes supported by the device"));
   353 		}
   354 	}
   355 
   356 void CTDevOrientation::TestHorizontalVerticalTwips(const CFbsDrawDevice* aDrawScreenDevice,  MSurfaceId* aSurfaceIdInterface, TDisplayMode aDisplayMode, TInt aScreenNo)
   357 	{
   358     __ASSERT_ALWAYS(aSurfaceIdInterface != NULL, User::Invariant());
   359 	TInt horTwipsRef = aDrawScreenDevice->HorzTwipsPerThousandPixels();
   360 	TInt verTwipsRef = aDrawScreenDevice->VertTwipsPerThousandPixels();
   361 
   362 	TUint32 pixelFormat = 0;
   363     TInt bpp = 0;
   364     // Find the required color depth and pixel format based on the aDisplayMode
   365     TEST(ReqBppAndPixelFormat(aDisplayMode,bpp, pixelFormat));
   366     
   367     TSurfaceId surfaceId;	
   368    	
   369    	if (ChooseOrientationMode(aSurfaceIdInterface) && iArrayOrientation.Count() != 0 )
   370     	{
   371 	   	for (TInt i = 0; i < iArrayOrientation.Count(); i++)
   372     		{
   373  			// Set the orientation
   374 			if (aSurfaceIdInterface->SetDeviceOrientation(iArrayOrientation[i]))
   375 				{
   376 				// Retrieve SurfaceId to test the second bit
   377 				aSurfaceIdInterface->GetSurface(surfaceId);
   378 				INFO_PRINTF1(_L("CFbsDrawDevice, Retrieve the surfaceId to test whether the second bit has been modified accordingly and other bits left unchanged"));		
   379 				//Check the values
   380 				TEST(surfaceId.iInternal[0] == aScreenNo);
   381 				TInt halMode = surfaceId.iInternal[1] &~TSurfaceId::TScreenSurfaceUsage::EHalFlippedFlag;
   382 				HAL::Get(surfaceId.iInternal[0], HALData::EDisplayBitsPerPixel, halMode);
   383 		   	
   384 				TInt horTwipsRotated = aDrawScreenDevice->HorzTwipsPerThousandPixels();
   385 				TInt verTwipsRotated = aDrawScreenDevice->VertTwipsPerThousandPixels();
   386 		   	
   387 				if (iArrayOrientation[i] & (EDeviceOrientation90CW | EDeviceOrientation270CW))
   388 					{  
   389 					INFO_PRINTF2(_L("Test DeviceOrientation Mode %d returns swapped horizontal and vertical twip values"), i);
   390 					TEST(horTwipsRef == verTwipsRotated);
   391 					TEST(verTwipsRef == horTwipsRotated);
   392 					TEST((surfaceId.iInternal[1] & TSurfaceId::TScreenSurfaceUsage::EHalFlippedFlag) != 0); //flipped
   393 					}
   394 				else 
   395 					{
   396 					INFO_PRINTF2(_L("Test DeviceOrientation Mode %d returns no swapped horizontal and vertical twip values"), i);
   397 					TEST(verTwipsRef == verTwipsRotated);
   398 					TEST(horTwipsRef == horTwipsRotated);
   399 					TEST((surfaceId.iInternal[1] & TSurfaceId::TScreenSurfaceUsage::EHalFlippedFlag) == 0); //no flipped
   400 					}
   401 				// Check the color depth unchanged
   402  	  			TEST(bpp == halMode || bpp == 24 && halMode == 32 || bpp == 32 && halMode == 24);
   403 				TEST(surfaceId.iInternal[2] == pixelFormat);//Need to test the type as well
   404 				TEST(surfaceId.iInternal[3]>>24 == TSurfaceId::EScreenSurface );
   405  				}
   406  			else
   407 	    		INFO_PRINTF1(_L("No attributes have been changed after calling SetDeviceOrientation()"));
   408     		}
   409     	}
   410     else 
   411     	{
   412 		INFO_PRINTF1(_L("No availabe device orientation modes supported by the device"));
   413     	}
   414 
   415 	}
   416 	
   417 void CTDevOrientation::TestSetDeviceOrientationWithValidMode(const CFbsDrawDevice* aDrawScreenDevice,  MSurfaceId* aSurfaceIdInterface, TDisplayMode aDisplayMode, TInt aScreenNo)
   418 	{
   419 	__ASSERT_ALWAYS(aSurfaceIdInterface != NULL, User::Invariant());
   420 	TSize sizeRef = aDrawScreenDevice->SizeInPixels();
   421 	TSize sizeRotated;
   422 	TUint32 pixelFormat = 0;
   423     TInt bpp = 0;
   424     // Find the required color depth and pixel format based on the aDisplayMode
   425     TEST(ReqBppAndPixelFormat(aDisplayMode,bpp, pixelFormat));
   426     
   427     TSurfaceId surfaceId;	
   428    	
   429    	if (ChooseOrientationMode(aSurfaceIdInterface) && iArrayOrientation.Count() != 0 )
   430     	{
   431 	   	for (TInt i = 0; i < iArrayOrientation.Count(); i++)
   432     		{
   433  			// Set the orientation
   434 			if (aSurfaceIdInterface->SetDeviceOrientation(iArrayOrientation[i]))
   435 				{
   436 				// Retrieve SurfaceId to test the second bit
   437 				aSurfaceIdInterface->GetSurface(surfaceId);
   438 				INFO_PRINTF1(_L("CFbsDrawDevice, Retrieve the surfaceId to test whether the second bit has been modified accordingly and other bits left unchanged"));		
   439 				//Check the values
   440 				TEST(surfaceId.iInternal[0] == aScreenNo);
   441 				TInt halMode = surfaceId.iInternal[1] &~TSurfaceId::TScreenSurfaceUsage::EHalFlippedFlag;
   442 				HAL::Get(surfaceId.iInternal[0], HALData::EDisplayBitsPerPixel, halMode);
   443 				// Retrieve the size in pixel after setting the device rotation
   444 	  			sizeRotated = aDrawScreenDevice->SizeInPixels();
   445 		   	
   446 				if (iArrayOrientation[i] & (EDeviceOrientation90CW | EDeviceOrientation270CW))
   447 					{  
   448 					INFO_PRINTF2(_L("Test DeviceOrientation Mode %d returns swapped screen Height and Width"), i);
   449 					TEST(sizeRef.iHeight == sizeRotated.iWidth);
   450 					TEST(sizeRef.iWidth == sizeRotated.iHeight);
   451 					TEST((surfaceId.iInternal[1] & TSurfaceId::TScreenSurfaceUsage::EHalFlippedFlag) != 0); //has set to 8 ---  flipped
   452 					}
   453 				else 
   454 					{
   455 					INFO_PRINTF2(_L("Test DeviceOrientation Mode %d returns no swapped screen Height and Width"), i);
   456 					TEST(sizeRef.iWidth == sizeRotated.iWidth);
   457 					TEST(sizeRef.iHeight == sizeRotated.iHeight);
   458 					TEST((surfaceId.iInternal[1] & TSurfaceId::TScreenSurfaceUsage::EHalFlippedFlag) == 0); //has set to 0  --- no flipped
   459 					}
   460 				// Check the color depth unchanged
   461  	  			TEST(bpp == halMode || bpp == 24 && halMode == 32 || bpp == 32 && halMode == 24);
   462 				TEST(surfaceId.iInternal[2] == pixelFormat);//Need to test the type as well
   463 				TEST(surfaceId.iInternal[3]>>24 == TSurfaceId::EScreenSurface );
   464 				}
   465 			else
   466 	    		INFO_PRINTF1(_L("No attributes have been changed after calling SetDeviceOrientation()"));
   467     		}
   468     	}
   469     else 
   470     	{
   471 		INFO_PRINTF1(_L("No availabe device orientation modes supported by the device"));
   472     	}
   473 	}
   474 
   475 
   476 // THIS METHOD IS EXPECTED TO PANIC
   477 LOCAL_C TInt DoSetDeviceOrientationWithInvalidModeL(TDeviceOrientation aOrientation, TDisplayMode aDisplayMode, TInt aScreenNo)
   478 	{
   479 	CFbsDrawDevice* drawScreenDevice =  NULL;
   480 	TRAPD(err, drawScreenDevice = CFbsDrawDevice::NewScreenDeviceL(aScreenNo, aDisplayMode));
   481     CleanupStack::PushL(drawScreenDevice);
   482     if(err == KErrNone)
   483 		{  
   484 		__ASSERT_ALWAYS(drawScreenDevice != NULL, User::Invariant());
   485 		//Set other properties
   486     	drawScreenDevice->SetUserDisplayMode(EColor16MA);
   487 		drawScreenDevice->SetAutoUpdate(EFalse);
   488 		MSurfaceId* surfaceIdInterface = NULL;
   489 		err = drawScreenDevice->GetInterface(KSurfaceInterfaceID, reinterpret_cast <TAny*&> (surfaceIdInterface));
   490 		if (err == KErrNone)
   491 			{
   492 			// Currently Panics the secondary thread
   493 			surfaceIdInterface->SetDeviceOrientation(aOrientation);
   494 			}
   495 		}
   496 	else
   497 		{
   498 		User::LeaveIfError(err);
   499 		}
   500 	CleanupStack::PopAndDestroy();
   501 	return(EWsExitReasonBad);
   502 	}
   503 
   504 
   505 void CTDevOrientation::TestSetDeviceOrientationWithInvalidModeL(TDisplayMode aDisplayMode)
   506 	{
   507 	INFO_PRINTF1(_L("Test SetDeviceOrientation() with invalid device orientation modes -1"));
   508 	// Invalid bit is set
   509     TDeviceOrientation aInvalidMode = (TDeviceOrientation)-1;
   510     // Check the test results in the secondary thread
   511 	TEST(iPanicTest->TestInvalidModePanicL(&(DoSetDeviceOrientationWithInvalidModeL),EScreenDriverPanicInvalidParameter, (TDisplayMode*)&aDisplayMode, &aInvalidMode,&iCurrScreen));
   512 
   513    	INFO_PRINTF1(_L("Test SetDeviceOrientation() with invalid device orientation modes 0"));
   514     aInvalidMode = (TDeviceOrientation)0;
   515     // Check the test results in the secondary thread
   516 	TEST(iPanicTest->TestInvalidModePanicL(&(DoSetDeviceOrientationWithInvalidModeL),EScreenDriverPanicInvalidParameter, &aDisplayMode,&aInvalidMode,&iCurrScreen));
   517 
   518 	INFO_PRINTF1(_L("Test SetDeviceOrientation() with invalid device orientation modes 3"));
   519     aInvalidMode = (TDeviceOrientation)3;
   520     // Check the test results in the secondary thread
   521 	TEST(iPanicTest->TestInvalidModePanicL(&(DoSetDeviceOrientationWithInvalidModeL),EScreenDriverPanicInvalidParameter,&aDisplayMode, &aInvalidMode,&iCurrScreen));
   522 
   523    	INFO_PRINTF1(_L("Test SetDeviceOrientation() with invalid device orientation modes 5"));
   524     aInvalidMode = (TDeviceOrientation)5;
   525     // Check the test results in the secondary thread
   526 	TEST(iPanicTest->TestInvalidModePanicL(&(DoSetDeviceOrientationWithInvalidModeL),EScreenDriverPanicInvalidParameter, &aDisplayMode,&aInvalidMode,&iCurrScreen));
   527 
   528 	INFO_PRINTF1(_L("Test SetDeviceOrientation() with invalid device orientation modes 7"));
   529     aInvalidMode = (TDeviceOrientation)7;
   530     // Check the test results in the secondary thread
   531 	TEST(iPanicTest->TestInvalidModePanicL(&(DoSetDeviceOrientationWithInvalidModeL),EScreenDriverPanicInvalidParameter, &aDisplayMode,&aInvalidMode,&iCurrScreen));
   532 
   533 	INFO_PRINTF1(_L("Test SetDeviceOrientation() with invalid device orientation modes 9"));
   534     aInvalidMode = (TDeviceOrientation)9;
   535     // Check the test results in the secondary thread
   536 	TEST(iPanicTest->TestInvalidModePanicL(&(DoSetDeviceOrientationWithInvalidModeL),EScreenDriverPanicInvalidParameter, &aDisplayMode,&aInvalidMode,&iCurrScreen));
   537     
   538    	INFO_PRINTF1(_L("Test SetDeviceOrientation() with invalid device orientation modes 15"));
   539     aInvalidMode = (TDeviceOrientation)15;
   540     // Check the test results in the secondary thread
   541 	TEST(iPanicTest->TestInvalidModePanicL(&(DoSetDeviceOrientationWithInvalidModeL),EScreenDriverPanicInvalidParameter, &aDisplayMode,&aInvalidMode,&iCurrScreen));
   542 
   543    	INFO_PRINTF1(_L("Test SetDeviceOrientation() with invalid device orientation modes 16"));
   544     aInvalidMode = (TDeviceOrientation)16;
   545     // Check the test results in the secondary thread
   546 	TEST(iPanicTest->TestInvalidModePanicL(&(DoSetDeviceOrientationWithInvalidModeL),EScreenDriverPanicInvalidParameter,&aDisplayMode, &aInvalidMode,&iCurrScreen));
   547 
   548 	INFO_PRINTF1(_L("Test SetDeviceOrientation() with invalid device orientation modes 17"));
   549   	aInvalidMode = (TDeviceOrientation)17;
   550     // Check the test results in the secondary thread
   551 	TEST(iPanicTest->TestInvalidModePanicL(&(DoSetDeviceOrientationWithInvalidModeL),EScreenDriverPanicInvalidParameter, &aDisplayMode,&aInvalidMode,&iCurrScreen));
   552 
   553    	INFO_PRINTF1(_L("Test SetDeviceOrientation() with invalid device orientation modes 32"));
   554   	aInvalidMode = (TDeviceOrientation)32;
   555     // Check the test results in the secondary thread
   556 	TEST(iPanicTest->TestInvalidModePanicL(&(DoSetDeviceOrientationWithInvalidModeL),EScreenDriverPanicInvalidParameter, &aDisplayMode,&aInvalidMode,&iCurrScreen));
   557 
   558 	}
   559 
   560 void CTDevOrientation::TestValidButUnavailableOrientationL(MSurfaceId* aSurfaceIdInterface, TDisplayMode aDisplayMode)
   561 	{
   562 
   563 	__ASSERT_ALWAYS(aSurfaceIdInterface != NULL, User::Invariant());
   564     if (ChooseOrientationMode(aSurfaceIdInterface) && iArrayOrientation.Count() != 0)
   565     	{// Find a valid but unavailable device orientation
   566     	if (iArrayOrientation.Count() ==4)
   567     		{
   568 			INFO_PRINTF1(_L("All four possible device orientation modes are supported"));
   569     		}
   570     	else
   571     		{ // There must be one valid but unsupported display  modes
   572     		RArray<TDeviceOrientation> arrayValidUnsupOrientation;
   573     		CleanupClosePushL(arrayValidUnsupOrientation); 
   574     		
   575     		for (TUint32 mode = (TUint32)EDeviceOrientationNormal; mode <= (TUint32)EDeviceOrientation270CW; mode *= 2)
   576     			{
   577     			// Insert into the arry arrayValidUnsupOrientation
   578     			if (iArrayOrientation.Find((TDeviceOrientation)mode) == KErrNotFound)
   579 	    		    {
   580 	    			arrayValidUnsupOrientation.Append((TDeviceOrientation)mode);
   581 	    			}
   582     			}
   583 
   584     		for (TInt i = 0; i < arrayValidUnsupOrientation.Count(); i++)
   585  				{
   586  				INFO_PRINTF2(_L("Test SetDeviceOrientation() with valid but unsupported display modes %d"), i);
   587    				// Also retrieve the current device orientation for reference
   588    				TDeviceOrientation devOrientationRef = aSurfaceIdInterface->DeviceOrientation();
   589    				TBool panicTestPass=iPanicTest->TestInvalidModePanicL(&(DoSetDeviceOrientationWithInvalidModeL),EScreenDriverPanicInvalidParameter, &aDisplayMode, &arrayValidUnsupOrientation[i],&iCurrScreen);
   590    				if (!panicTestPass)
   591    					if (iPanicTest->iActualPanicCode==0)
   592    						{
   593    						INFO_PRINTF1(_L("Panic test failed to panic!?"));
   594    						}
   595    					else
   596    						{
   597    						INFO_PRINTF2(_L("Panic test: wrong code %i"),iPanicTest->iActualPanicCode);
   598    						}
   599    				TEST(panicTestPass);
   600 				// Call GetDeviceOrientation() again to check the orientation mode hasnt been changed
   601 				INFO_PRINTF1(_L("Test the current device orientation mode has not been changed when the second thread panics"));
   602 				TEST(devOrientationRef == aSurfaceIdInterface->DeviceOrientation());	
   603 				}
   604 			CleanupStack::PopAndDestroy();
   605       		}
   606     	}
   607     else 
   608     	{
   609 		// No avaialbe orientation modes
   610 		INFO_PRINTF1(_L("No availabe device orientation modes supported by the device"));
   611     	}
   612 	}
   613 /**	Copies the given screendevice to a new screendevice
   614  *  Assertion is that if the old screen device is different rotation then the updated screen device gets the rotation of the old device.
   615  *  Try to force the devices to have different rotations before we start in order to detect that the update does occur.
   616  * 
   617  **/
   618 void CTDevOrientation::TestSetDisplayMode(CFbsDrawDevice* aDrawScreenDevice,MSurfaceId* aSurfaceIdInterface)
   619 	{
   620 	// Create a new screendevice and surfaceId
   621 	CFbsDrawDevice* inputScreenDevice = NULL;
   622 	MSurfaceId* inputSurfaceIdInterface = NULL;
   623 	
   624 	TRAPD(err, inputScreenDevice = CFbsDrawDevice::NewScreenDeviceL(iCurrScreen, aDrawScreenDevice->DisplayMode()));
   625 	if(err == KErrNone && !inputSurfaceIdInterface)
   626 		{
   627 		err = inputScreenDevice->GetInterface(KSurfaceInterfaceID, reinterpret_cast <TAny*&> (inputSurfaceIdInterface));
   628 		}
   629 	TInt beforeOrientation=aSurfaceIdInterface->DeviceOrientation();
   630 	TInt inputOrientation=inputSurfaceIdInterface->DeviceOrientation();
   631 	TInt alternateOrientation=(inputOrientation>1)?(inputOrientation>>1):(inputOrientation<<1);
   632 
   633 	if (err == KErrNone)
   634 		{
   635 		if (beforeOrientation==inputOrientation)
   636 			{
   637 			// Set orientation on aDrawScreenDevice
   638 			// (deviceOrientation*2) mod 8 
   639 		  	INFO_PRINTF1(_L("Test SetDisplayMode() copys "));
   640 		  	if (aSurfaceIdInterface->DeviceOrientationsAvailable()&alternateOrientation)
   641 		  		{
   642 				TBool didIt=aSurfaceIdInterface->SetDeviceOrientation(TDeviceOrientation(alternateOrientation));
   643 			  	INFO_PRINTF1(_L("[done SetDeviceOrientation] SetDisplayMode() copys "));
   644 			  	TEST(!didIt|| aSurfaceIdInterface->DeviceOrientation() == alternateOrientation);
   645 		  		}
   646 		  	else
   647 		  		{
   648 		  		INFO_PRINTF1(_L("*** source device couldn't change orientation ***"));
   649 		  		}
   650 			}
   651 	  	INFO_PRINTF1(_L("Test SetDisplayMode() copys "));
   652 		aDrawScreenDevice->SetDisplayMode(inputScreenDevice);
   653 	  	INFO_PRINTF1(_L("[done SetDisplayMode] SetDisplayMode() copys "));
   654 	  	
   655 		// Compare the orientation if they are the same... right...
   656 		if (inputSurfaceIdInterface->DeviceOrientationsAvailable()&inputOrientation)
   657 			{
   658 			TEST(aSurfaceIdInterface->DeviceOrientation() == inputOrientation);
   659 			}
   660 		else
   661 			{	//target device doesn't support this orientation
   662 	  		INFO_PRINTF1(_L("*** target device couldn't change orientation to honour copied source device ***"));
   663 			TEST(aSurfaceIdInterface->DeviceOrientation() == beforeOrientation);
   664 			}
   665 	  	INFO_PRINTF1(_L("[done DeviceOrientation] SetDisplayMode() copys "));
   666 		}	
   667 	else
   668 		{
   669 	  	INFO_PRINTF1(_L("Error in GetInterface()"));
   670 		}
   671 	delete inputScreenDevice;
   672 	}
   673 
   674 void CTDevOrientation::RunTestCaseL(TInt aCurTestCase)
   675 	{
   676 	if (aCurTestCase < 9)
   677    		{
   678 		//All screens
   679 		for (TInt count = 0; count < iArrayDispModesPerScreen.Count(); count++)
   680 			{
   681 			iCurrScreen=count;
   682 	    	for (TInt ind = 0;iArrayDispModesPerScreen[count]>=(1<<ind); ind++)
   683 	    		{
   684 	    		TDisplayMode mode= (TDisplayMode)ind;
   685 	    		if (iArrayDispModesPerScreen[count]&(1<<ind))
   686 	    			{
   687 				  	INFO_PRINTF3(_L("The current screen number =%d The current display mode =%d"), count, ind);
   688 					CFbsDrawDevice* drawScreenDevice = NULL;
   689 					MSurfaceId* surfaceIdInterface = NULL;
   690 					if (!GetSurfaceIdInterfaceL(count,mode, drawScreenDevice, surfaceIdInterface))
   691 	    				{
   692 	   		  			INFO_PRINTF1(_L("** GCE INTERFACE NOT SUPPORTED ***"));
   693 	    				}
   694 					else
   695 	    				{
   696 		
   697 	    				CleanupStack::PushL(drawScreenDevice);
   698 	    				((CTDevOrientationStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
   699 	    				switch(aCurTestCase)
   700 							{
   701 /**
   702 @SYMTestCaseID			GRAPHICS-SCDV-0010
   703 @SYMPREQ			PREQ1019
   704 @SYMREQ				REQ8228,REQ8223,REQ8227		
   705 @SYMTestPriority		High 
   706 @SYMTestCaseDesc		This test gets a screen surface and checks the expected values of the surfaceID
   707 @SYMTestStatus			Implemented
   708 
   709 @SYMTestActions			Call CFbsDrawDevice::CreateScreenDeviceL(), CFbsDrawDevice::GetInterface(), MSurfaceId::GetSurface() 
   710 @SYMTestExpectedResults This test passes with surfaceId has the expected values in each field.  				
   711 */
   712 		case 1:
   713 			((CTDevOrientationStep*)iStep)->SetTestStepID(_L("GRAPHICS-SCDV-0010"));
   714 			TestGetSurfaceWithValidDispModeL(surfaceIdInterface,mode, count);
   715 			break;
   716 /**
   717 @SYMTestCaseID			GRAPHICS-SCDV-0011
   718 @SYMPREQ			PREQ1019
   719 @SYMREQ				REQ8228,REQ8223,REQ8227	
   720 @SYMTestPriority		High 
   721 @SYMTestCaseDesc		This test checks DeviceOrientationAvailable() returns a valid orientation mode or a combination of them
   722 SYMTestStatus			Implemented
   723 
   724 @SYMTestActions			Call CFbsDrawDevice::CreateScreenDeviceL(), CFbsDrawDevice::GetInterface(), MSurfaceId::DeviceOrientationAvailable() 
   725 @SYMTestExpectedResults This test passes after checking the return values of DeviceOrientationAvailable()  
   726 */
   727 		case 2:
   728 			((CTDevOrientationStep*)iStep)->SetTestStepID(_L("GRAPHICS-SCDV-0011"));
   729 			TestGetDeviceOrientation(surfaceIdInterface);
   730 			break;
   731 /**
   732 @SYMTestCaseID			GRAPHICS-SCDV-0012
   733 @SYMPREQ			PREQ1019	
   734 @SYMREQ				REQ8228,REQ8223,REQ8227
   735 @SYMTestPriority		High 
   736 @SYMTestCaseDesc		This test checks the change of screen size before and after calling SetDeviceOrientation with a valid orientation mode
   737 @SYMTestStatus			Implemented
   738 
   739 @SYMTestActions			Call CFbsDrawDevice::CreateScreenDeviceL(), CFbsDrawDevice::GetInterface(), MSurfaceId::SetDeviceOrientation(), CFbsDrawDevice::SizeInPixel() 
   740 @SYMTestExpectedResults In the case of EDeviceOrientation90CW and EDeviceOrientation270CW the size width and height are swapped after calling SetDeviceOrientation, while in other cases, the values remained the same before and after the rotation setting.  
   741 */
   742 		case 3:
   743 			((CTDevOrientationStep*)iStep)->SetTestStepID(_L("GRAPHICS-SCDV-0012"));
   744 			TestSetDeviceOrientationWithValidMode(drawScreenDevice, surfaceIdInterface,mode,count);
   745 
   746 			break;
   747 /**
   748 @SYMTestCaseID			GRAPHICS-SCDV-0013
   749 @SYMPREQ			PREQ1019
   750 @SYMREQ				REQ8228,REQ8223,REQ8227	
   751 @SYMTestPriority		High 
   752 @SYMTestCaseDesc		This test checks the change of horizontal and vertical twips before and after calling SetDeviceOrientation with a valid orientation mode
   753 @SYMTestStatus			Implemented
   754 
   755 @SYMTestActions			Call CFbsDrawDevice::CreateScreenDeviceL(), CFbsDrawDevice::GetInterface(), MSurfaceId::SetDeviceOrientation(), CFbsDrawDevice::HorzTwipsPerThousandPixels() and CFbsDrawDevice:: VertTwipsPerThousandPixels() 
   756 @SYMTestExpectedResults In the case of EDeviceOrientation90CW and EDeviceOrientation270CW the horizontal and vertical twips are swapped after calling SetDeviceOrientation, while in other cases, the values remained the same before and after the rotation setting.  
   757 */
   758 		case 4:
   759 			((CTDevOrientationStep*)iStep)->SetTestStepID(_L("GRAPHICS-SCDV-0013"));
   760 			TestHorizontalVerticalTwips(drawScreenDevice, surfaceIdInterface,mode, count);
   761 			break;
   762 /**
   763 @SYMTestCaseID			GRAPHICS-SCDV-0014
   764 @SYMPREQ			PREQ1019
   765 @SYMREQ				REQ8228,REQ8223,REQ8227	
   766 @SYMTestPriority		High 
   767 @SYMTestCaseDesc		This test checks the functionality of SetDeviceOrientation() and DeviceOrientation()
   768 @SYMTestStatus			Implemented
   769 
   770 @SYMTestActions			Call CFbsDrawDevice::CreateScreenDeviceL(), CFbsDrawDevice::GetInterface(), MSurfaceId::SetDeviceOrientation(), MSurfaceId::DeviceOrientation() 
   771 @SYMTestExpectedResults The orientation mode value passed into SetDeviceOrientation is identical to that returned from calling DeviceOrientation().  
   772 */
   773 		case 5:
   774 			((CTDevOrientationStep*)iStep)->SetTestStepID(_L("GRAPHICS-SCDV-0014"));
   775 			TestDeviceOrientationSettingandGetting(surfaceIdInterface);
   776 			break;
   777 /**
   778 @SYMTestCaseID			GRAPHICS-SCDV-0015
   779 @SYMPREQ			PREQ1019
   780 @SYMREQ				REQ8228,REQ8223,REQ8227	
   781 @SYMTestPriority		High 
   782 @SYMTestCaseDesc		This test checks SetDeviceOrientation does not accept an invalid device orientation mode
   783 @SYMTestStatus			Implemented
   784 
   785 @SYMTestActions			Call CFbsDrawDevice::CreateScreenDeviceL(), CFbsDrawDevice::GetInterface(), MSurfaceId::SetDeviceOrientation() 
   786 @SYMTestExpectedResults This test panic with code EScreenDriverPanicInvalidParameter.  
   787 */
   788 		case 6:
   789 			((CTDevOrientationStep*)iStep)->SetTestStepID(_L("GRAPHICS-SCDV-0015"));
   790 			TestSetDeviceOrientationWithInvalidModeL(mode);
   791 			break;
   792 /**
   793 @SYMTestCaseID			GRAPHICS-SCDV-0016
   794 @SYMPREQ			PREQ1019
   795 @SYMREQ				REQ8228,REQ8223,REQ8227	
   796 @SYMTestPriority		High 
   797 @SYMTestCaseDesc		This test checks SetDeviceOrientation does not accept a valid but unsupported device orientation mode
   798 @SYMTestStatus			Implemented
   799 
   800 @SYMTestActions			Call CFbsDrawDevice::CreateScreenDeviceL(), CFbsDrawDevice::GetInterface(), MSurfaceId::SetDeviceOrientation() 
   801 @SYMTestExpectedResults This test panic with code EScreenDriverPanicInvalidParameter.  
   802 */		
   803 		case 7:
   804 			((CTDevOrientationStep*)iStep)->SetTestStepID(_L("GRAPHICS-SCDV-0016"));
   805 			TestValidButUnavailableOrientationL(surfaceIdInterface,mode);
   806 			break;
   807 /**
   808 @SYMTestCaseID			GRAPHICS-SCDV-0017
   809 @SYMPREQ			PREQ1019
   810 @SYMREQ				REQ8228,REQ8223,REQ8227	
   811 @SYMTestPriority		High 
   812 @SYMTestCaseDesc		This test compares the two draw devices after copying one to the other
   813 @SYMTestStatus			Implemented
   814 
   815 @SYMTestActions			Call CFbsDrawDevice::CreateScreenDeviceL(), CFbsDrawDevice::GetInterface(), CFbsDrawDevice::SetDisplayMode(), MSurfaceId::SetDeviceOrientation() 
   816 @SYMTestExpectedResults This test should pass all the device orientation checking.  
   817 */
   818 		case 8:
   819 			((CTDevOrientationStep*)iStep)->SetTestStepID(_L("GRAPHICS-SCDV-0017"));
   820 			TestSetDisplayMode(drawScreenDevice,surfaceIdInterface);
   821 			break;
   822 							}
   823 	    				((CTDevOrientationStep*)iStep)->RecordTestResultL();
   824 	    				CleanupStack::PopAndDestroy();
   825 				   		}
   826 					}
   827 
   828 				}
   829 			}
   830 		}
   831     else
   832     	{
   833         ((CTDevOrientationStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
   834         ((CTDevOrientationStep*)iStep)->CloseTMSGraphicsStep();
   835     	TestComplete();
   836     	}
   837 		((CTDevOrientationStep*)iStep)->RecordTestResultL();
   838 	}
   839 
   840 
   841 //--------------------------------------------------------------
   842 
   843 CTDevOrientationStep::CTDevOrientationStep() 
   844 	{ 
   845 	SetTestStepName(KTDevOrientationStep); 
   846 	} 
   847 	 
   848 CTGraphicsBase* CTDevOrientationStep::CreateTestL()
   849 	{ 
   850 	CTGraphicsBase* theTest = NULL;
   851 	CFbsDrawDevice* device = NULL;
   852 	TInt numOfScreens = 0;
   853 	TInt err = HAL::Get(HALData::EDisplayNumberOfScreens, numOfScreens);
   854 	RArray<TInt> arrayDispModesPerScreen;
   855 	
   856 	CleanupClosePushL(arrayDispModesPerScreen);
   857 	for (TUint scr=0;scr<numOfScreens;scr++)
   858 		{
   859 		TUint modeBits=0;
   860 		// go through all the display modes and find out the supported ones by hardware/emulator
   861 	    for (TUint32 ind = 0; ind <= (TUint32)EColorLast; ind++)
   862 	    	{
   863 	   	    TDisplayMode mode2 = (TDisplayMode)ind;
   864 
   865 	    	TRAPD(err, device = CFbsDrawDevice::NewScreenDeviceL(scr, mode2));
   866 	   		if (err==KErrNone)  //support this mode
   867 				{
   868 				modeBits+=1<<ind;
   869 				}// otherwise, unsupport this mode does nothing
   870 	    	delete device;
   871 	    
   872 			device = NULL;
   873 	     	}
   874 	    arrayDispModesPerScreen.Append(modeBits);
   875 		}
   876 	
   877     // Create the test class 	
   878 	if (arrayDispModesPerScreen.Count() > 0)
   879 		{
   880 		// there is at least one supported display modes
   881 		theTest = new (ELeave) CTDevOrientation(this, arrayDispModesPerScreen);
   882  		}
   883  	else
   884  		{
   885 		User::Leave(KErrNotSupported);
   886  		}
   887 	 	
   888     CleanupStack::Pop(&arrayDispModesPerScreen);
   889 	return 	theTest;		
   890 	} 
   891 
   892 
   893 void CTDevOrientationStep::TestSetupL()
   894 	{
   895 	TInt temp = 0;
   896 	HAL::Get(KDefaultScreenNo, HALData::EDisplayColors, temp);//force HAL memory allocation
   897 	
   898 	}