sl@0: // Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: // All rights reserved.
sl@0: // This component and the accompanying materials are made available
sl@0: // under the terms of "Eclipse Public License v1.0"
sl@0: // which accompanies this distribution, and is available
sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: //
sl@0: // Initial Contributors:
sl@0: // Nokia Corporation - initial contribution.
sl@0: //
sl@0: // Contributors:
sl@0: //
sl@0: // Description:
sl@0: // Screen device test code
sl@0: // 
sl@0: //
sl@0: 
sl@0: /**
sl@0:  @file
sl@0:  @test
sl@0:  @internalComponent - Internal Symbian test code
sl@0: */
sl@0: 
sl@0: #include "TSCRDEVRESSWITCH.H"
sl@0: 
sl@0: //Define this to get visible pauses (in test 6: DeviceResSwitchL)
sl@0: //#define VISIBLE_PAUSES
sl@0: 
sl@0: //Define this to get extra logging which may be useful in tracking down a fail
sl@0: //#define EXTRA_LOGGING
sl@0: 
sl@0: CTScreenDeviceResSwitch::CTScreenDeviceResSwitch(CTestStep* aStep) : CTWsGraphicsBase(aStep)
sl@0: 	{}
sl@0: 
sl@0: CTScreenDeviceResSwitch::~CTScreenDeviceResSwitch()
sl@0: 	{}
sl@0: 
sl@0: void CTScreenDeviceResSwitch::ConstructL()
sl@0: 	{
sl@0: 	//The following is just another test... it doesn't leave any resources for use by the test class AFAICT...
sl@0: 	RWsSession aSession;
sl@0: 	CWsScreenDevice *device1;
sl@0: 	CWsScreenDevice *device2;
sl@0: 	CWsScreenDevice *device3;
sl@0: 
sl@0: 	aSession.Connect();
sl@0: 	device1=new(ELeave) CWsScreenDevice(aSession);
sl@0: 	device1->Construct(iTest->iScreenNumber);
sl@0: 	delete device1;
sl@0: 	device1=new(ELeave) CWsScreenDevice(aSession);
sl@0: 	device1->Construct(iTest->iScreenNumber);
sl@0: 	device2=new(ELeave) CWsScreenDevice(aSession);
sl@0: 	device2->Construct(iTest->iScreenNumber);
sl@0: 	device3=new(ELeave) CWsScreenDevice(aSession);
sl@0: 	device3->Construct(iTest->iScreenNumber);
sl@0: 	delete device3;
sl@0: 	CFbsFont *font;
sl@0: 	User::LeaveIfError(device1->GetNearestFontToDesignHeightInTwips((CFont *&)font,TFontSpec()));
sl@0: 	RWindowGroup group(aSession);
sl@0: 	group.Construct(777);
sl@0: 	group.SetOwningWindowGroup(TheClient->iGroup->GroupWin()->Identifier());
sl@0: 	RWindow win(aSession);
sl@0: 	win.Construct(group,77);
sl@0: 	CWindowGc *gc=new(ELeave) CWindowGc(device1);
sl@0: 	gc->Construct();
sl@0: 	gc->Activate(win);
sl@0: 	gc->UseFont(font);
sl@0: 	device1->ReleaseFont(font);
sl@0: 	aSession.Flush();
sl@0: 	delete gc;
sl@0: 	win.Close();
sl@0: 	group.Close();
sl@0: 	delete device1;
sl@0: 	delete device2;
sl@0: 	aSession.Close();
sl@0: 	}
sl@0: 
sl@0: 	
sl@0: class CPrimaryColoursWin : public CTWin
sl@0: 	{
sl@0: public:
sl@0: 	enum	//various size factors	
sl@0: 		{  	
sl@0: 			kShrinkFactor=5,
sl@0: 			kPlotSize=16,
sl@0: 			kPlotMargin=4,
sl@0: 			kPlotWithMargin=kPlotSize+kPlotMargin,
sl@0: 			kPlotsAccross=3,
sl@0: 			kPlotsDown=1,
sl@0: 			kMinWidth=kPlotWithMargin*kPlotsAccross+kPlotMargin,
sl@0: 			kMinHeight=kPlotWithMargin*kPlotsDown+kPlotMargin,
sl@0: 		    KNumChannels=3,
sl@0: 		    KNumColours=256
sl@0: 		};
sl@0: 		
sl@0: 	CPrimaryColoursWin();
sl@0: 	~CPrimaryColoursWin();
sl@0: 	//Virtual Function from CTBaseWin
sl@0: 	void Draw();
sl@0: 	TInt CountUniquePlottedColours();
sl@0: 	TInt iDrawn;
sl@0: 	TInt iNumColours;
sl@0: 	TBool iBadPixels[KNumChannels][KNumColours];
sl@0: 	TBuf<0x40> iDisplayText;
sl@0: 	};
sl@0: 	
sl@0: CPrimaryColoursWin::CPrimaryColoursWin()
sl@0: 	{
sl@0: 	for (TInt channelnum=0;channelnum<KNumChannels;channelnum++)
sl@0: 		{
sl@0: 		for (TInt colour=0;colour<KNumColours;colour++)
sl@0: 			{
sl@0: 			iBadPixels[channelnum][colour]=EFalse;
sl@0: 			}
sl@0: 		}
sl@0: 		
sl@0: 	iDisplayText.Zero();
sl@0: 	iDisplayText.Format(_L("Test text"));
sl@0: 	}
sl@0: 	
sl@0: CPrimaryColoursWin::~CPrimaryColoursWin()
sl@0: 	{
sl@0: 
sl@0: 	}
sl@0: 	
sl@0: void CPrimaryColoursWin::Draw()
sl@0: 	{
sl@0: 	iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
sl@0: 	iGc->SetPenStyle(CGraphicsContext::ESolidPen);
sl@0: 	iGc->SetPenColor(TRgb(255, 255, 255));
sl@0: 	iGc->SetBrushColor(TRgb(0, 0, 0));
sl@0: 	TSize winSize = Size();
sl@0: 	iGc->DrawRect(TRect(winSize));
sl@0: 	
sl@0: 	CFont* font;
sl@0: 	TFontSpec fontSpec(_L(""), 300);
sl@0: 	TheClient->iScreen->GetNearestFontInTwips(font, fontSpec);
sl@0: 	
sl@0: 	if (font)
sl@0: 		{
sl@0: 		iGc->UseFont(font);
sl@0: 		TRect r(TPoint(0, 0), Size());
sl@0: 		r.Shrink(kMinHeight, kMinHeight);
sl@0: 		iGc->DrawText(iDisplayText, r, font->AscentInPixels(), iGc->ECenter, 0);
sl@0: 		iGc->DiscardFont();
sl@0: 		TheClient->iScreen->ReleaseFont(font);
sl@0: 		}
sl@0: 	
sl@0: 	iNumColours = 0;
sl@0: 	TPoint lhsAbs = Win()->AbsPosition();
sl@0: 	
sl@0: 	for(TInt channelnum = 0, channelmul = 1, xoordinate = kPlotMargin; channelnum < KNumChannels; channelnum++, channelmul <<= 8, xoordinate += kPlotWithMargin)
sl@0: 		{
sl@0: 		TRgb lastPixel(255, 255, 255, 255);
sl@0: 		
sl@0: 		for(TInt colour = 0; colour < KNumColours; colour++)
sl@0: 			{
sl@0: 			if(!iBadPixels[channelnum][colour])
sl@0: 				{
sl@0: 				iGc->SetPenColor(TRgb(colour * channelmul));				
sl@0: 				}
sl@0: 			else
sl@0: 				{
sl@0: 				iGc->SetPenColor(TRgb(255, 255, 255));			
sl@0: 				}
sl@0: 
sl@0: 			TPoint point = TPoint(xoordinate + (colour & 0x0f), kPlotMargin + (colour >> 4));
sl@0: 			iGc->Plot(point);
sl@0: 			}
sl@0: 		}
sl@0: 		
sl@0: 	iDrawn=ETrue;
sl@0: 	}
sl@0: 	
sl@0: TInt CPrimaryColoursWin::CountUniquePlottedColours()
sl@0: 	{
sl@0: 	iNumColours = 0;
sl@0: 	TPoint lhsAbs = Win()->AbsPosition();
sl@0: 	
sl@0: 	for(TInt channelnum = 0, channelmul = 1, xoordinate = kPlotMargin; channelnum < 3; channelnum++, channelmul <<=8 , xoordinate += kPlotWithMargin)
sl@0: 		{
sl@0: 		TRgb lastPixel(255, 255, 255, 255);
sl@0: 		
sl@0: 		for(TInt colour = 0; colour < 256; colour++)
sl@0: 			{
sl@0: 			TRgb readPixel;
sl@0:  			TPoint point = TPoint(xoordinate + (colour & 0x0f), kPlotMargin + (colour >> 4));
sl@0: 			TheClient->iScreen->GetPixel(readPixel, lhsAbs + point);
sl@0: 			
sl@0: 			if(readPixel != lastPixel)
sl@0: 				{
sl@0: 				lastPixel = readPixel;
sl@0: 				iNumColours++;
sl@0: 				iBadPixels[channelnum][colour] = EFalse;
sl@0: 				}
sl@0: 			else
sl@0: 				{
sl@0: 				iBadPixels[channelnum][colour] = ETrue;
sl@0: 				}
sl@0: 			} // for loop 
sl@0: 		} // for loop
sl@0: 		
sl@0: 	return iNumColours;
sl@0: 	}
sl@0: 	
sl@0: /**
sl@0: 	Intended primarily as a visual check that the mode is displayed correctly,
sl@0: 	for each rotated mode.
sl@0: **/
sl@0: void    CTScreenDeviceResSwitch::DeviceResSwitchWithRotationsL()
sl@0: 	{
sl@0: 	CWsScreenDevice *screen=TheClient->iScreen;
sl@0: 	TInt originalScreenMode = screen->CurrentScreenMode();
sl@0: 	TPixelsTwipsAndRotation originalModeSettings;
sl@0: 	screen->GetScreenModeSizeAndRotation(originalScreenMode,originalModeSettings);
sl@0: 	CArrayFixFlat<TInt> *rotations=new(ELeave) CArrayFixFlat<TInt>(1);
sl@0: 	CleanupStack::PushL(rotations);
sl@0: 	INFO_PRINTF2(_L("ScreenMode and rotation with colour depth. ScreenModes=%i"),TheClient->iScreenModes.Count());
sl@0: 	
sl@0: 	for (TInt rr=0,maxrr=3;rr<maxrr;++rr)
sl@0: 	for (TInt ii=0,maxii=TheClient->iScreenModes.Count();ii<maxii;++ii)
sl@0: 		{
sl@0: 		TInt newMode=TheClient->iScreenModes[ii];
sl@0: 		if (	screen->GetScreenModeOrigin(ii)!=TPoint(0,0)	||	screen->GetScreenModeScale(ii)!=TSize(1,1)	)
sl@0: 			{
sl@0: 			INFO_PRINTF2(_L("ScreenMode %i skipped: has scalind and/ or rotation"),ii);
sl@0: 			INFO_PRINTF1(_L("This scaling code is known to be broken if all modes do not support scaling"));
sl@0: 			INFO_PRINTF1(_L("See defect DEF111847 and break request 2226"));
sl@0: 			INFO_PRINTF5(_L("Origin: %i %i Scale %i %i"),
sl@0: 					screen->GetScreenModeOrigin(ii).iX,screen->GetScreenModeOrigin(ii).iY,
sl@0: 					screen->GetScreenModeScale(ii).iWidth,screen->GetScreenModeScale(ii).iHeight
sl@0: 				);
sl@0: 			continue;
sl@0: 			}
sl@0: 			
sl@0: 		screen->SetAppScreenMode(newMode);
sl@0: 		screen->SetScreenMode(newMode);
sl@0: 		TInt currentScreenMode = screen->CurrentScreenMode();
sl@0: 		TEST(currentScreenMode == newMode);
sl@0: 
sl@0: 		User::LeaveIfError(screen->GetRotationsList(newMode,rotations));
sl@0: 		INFO_PRINTF4(_L("ScreenMode and rotation with colour depth. Mode#%i=%i. Rotations=%i"),ii,newMode,rotations->Count());
sl@0: 		TPixelsTwipsAndRotation currentModeSettings;
sl@0: 		screen->GetDefaultScreenSizeAndRotation(currentModeSettings);
sl@0: 		screen->SetScreenSizeAndRotation(currentModeSettings);
sl@0: 		for (TInt jj=0,maxjj=rotations->Count();jj<maxjj;jj++)
sl@0: 			{
sl@0: 			CFbsBitGc::TGraphicsOrientation newOrientation=STATIC_CAST(CFbsBitGc::TGraphicsOrientation,rotations[0][jj]);
sl@0: 			INFO_PRINTF3(_L("ScreenMode and rotation with colour depth. Rotation#%i=%i(0..3)"),jj,newOrientation);
sl@0: 			screen->SetCurrentRotations(newMode,newOrientation);
sl@0: 			TheClient->iWs.Flush();
sl@0: 			
sl@0: 			TPixelsAndRotation modeSettings;
sl@0: 			TheClient->iScreen->GetDefaultScreenSizeAndRotation(modeSettings);
sl@0: 			TRect screenRect(TPoint(0,0),modeSettings.iPixelSize);
sl@0: 
sl@0: 			//move the debug windows to inside the area 
sl@0: 			//actually don't bother yet!
sl@0: 			if (screenRect.Width()>screenRect.Height())
sl@0: 				{
sl@0: 				}
sl@0: 			else
sl@0: 				{
sl@0: 				}
sl@0: 			DeviceResSwitchL();
sl@0: 			}
sl@0: 		screen->SetCurrentRotations(newMode,currentModeSettings.iRotation);
sl@0: 		screen->SetScreenSizeAndRotation(currentModeSettings);
sl@0: 		}
sl@0: 	
sl@0: 	CleanupStack::PopAndDestroy();
sl@0: 	screen->SetScreenMode(originalScreenMode);
sl@0: 	screen->SetCurrentRotations(originalScreenMode,originalModeSettings.iRotation);
sl@0: 	screen->SetScreenSizeAndRotation(originalModeSettings);
sl@0: 	}
sl@0: 	
sl@0: /**
sl@0: 	Intended primarily as a visual check that the mode is displayed correctly, 
sl@0: 	this code also verifies that the number of physical colours matches the reported mode.
sl@0: 	Note that although written to test GCE, this test is general and applies to all display versions.
sl@0: **/	
sl@0: void CTScreenDeviceResSwitch::DeviceResSwitchL()
sl@0: 	{		
sl@0: 	INFO_PRINTF1(_L("DeviceResSwitchL: Entering function"));
sl@0: 	TInt error = KErrNone;
sl@0: 	TInt isTransparencySupportedResult = KErrNone;
sl@0: 		
sl@0: 	TRAP(error, isTransparencySupportedResult = IsTransparencySupportedL());
sl@0: 	
sl@0: 	if(error != KErrNone)
sl@0: 		{
sl@0: 		INFO_PRINTF1(_L("DeviceResSwitchL: Transparency is not supported. Exits."));
sl@0: 		return;
sl@0: 		}	
sl@0: 	
sl@0: 	TRAP(error, CalculateDisplayPropertiesL());
sl@0: 	
sl@0: 	if(error != KErrNone)
sl@0: 		{
sl@0: 		INFO_PRINTF1(_L("DeviceResSwitchL: Could not calculate display properties. Test not supported. Exits."));
sl@0: 		return;		
sl@0: 		}	
sl@0: 
sl@0: 	TDisplayMode startDisplayMode = TheClient->iScreen->DisplayMode();
sl@0: 	TInt startColoursPixel = TDisplayModeUtils::NumDisplayModeColors(startDisplayMode);
sl@0: 		
sl@0: 	TPixelsAndRotation modeSettings;
sl@0: 	TheClient->iScreen->GetDefaultScreenSizeAndRotation(modeSettings);
sl@0: 	TRect r(TPoint(0, 0), modeSettings.iPixelSize);
sl@0: 
sl@0: 	// Starts off full-screen. Only shrink it if it will still be large enough to run the test
sl@0: 	// It should be... the test only needs 60x20 pixels
sl@0: 	
sl@0: 	if(r.Width() > r.Height())
sl@0: 		{
sl@0: 		if(r.Width() > (CPrimaryColoursWin::kMinWidth) * (CPrimaryColoursWin::kShrinkFactor-2) * 3 / (CPrimaryColoursWin::kShrinkFactor * 2))
sl@0: 			{
sl@0: 			r.iTl.iX = r.iBr.iX / 3;				
sl@0: 			}
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 		if (r.Height() > (CPrimaryColoursWin::kMinHeight) * (CPrimaryColoursWin::kShrinkFactor - 2) * 3/ (CPrimaryColoursWin::kShrinkFactor * 2))
sl@0: 			{
sl@0: 			r.iTl.iY = r.iBr.iY / 3;				
sl@0: 			}
sl@0: 		}
sl@0: 	if(r.Width() > (CPrimaryColoursWin::kMinWidth) * (CPrimaryColoursWin::kShrinkFactor - 2) / CPrimaryColoursWin::kShrinkFactor)
sl@0: 		{
sl@0: 		if(r.Height() > (CPrimaryColoursWin::kMinHeight) * (CPrimaryColoursWin::kShrinkFactor - 2) / CPrimaryColoursWin::kShrinkFactor)
sl@0: 			{
sl@0: 			r.Shrink(r.Width() / CPrimaryColoursWin::kShrinkFactor, r.Height() / CPrimaryColoursWin::kShrinkFactor);
sl@0: 			}
sl@0: 		}
sl@0: 		
sl@0: 	for(TInt i = 0; i < EColorLast; i++)
sl@0: 		{
sl@0: 		TDisplayMode tryMode = TDisplayMode(i);
sl@0: 		TInt tryColoursPixel = NumDisplayModeColors(tryMode);		
sl@0: 		
sl@0: 		INFO_PRINTF3(_L("DeviceResSwitchL: tryColoursPixel = %d, tryMode = %d"), tryColoursPixel, tryMode);
sl@0: 		
sl@0: 		if(TDisplayModeUtils::IsDisplayModeColor(tryMode) && startColoursPixel <= tryColoursPixel)
sl@0: 			{
sl@0: 				  //Create a test window at this mode, and see if it changes the screen mode
sl@0: 				{ // The braces define the lifetime of testWin. It must be destroyed before we check if mode changed back successfully.
sl@0: 				
sl@0: 				CPrimaryColoursWin* testWin1 = new (ELeave) CPrimaryColoursWin;
sl@0: 				CleanupStack::PushL(testWin1);
sl@0: 				
sl@0: 				TInt expectedColoursPerChannel = 1;
sl@0: 				TInt tt;
sl@0: 				
sl@0: 				testWin1->SetUpL(r.iTl, r.Size(), TheClient->iGroup, *TheClient->iGc, &tryMode);
sl@0: 				TheClient->iWs.Flush();
sl@0: 				TDisplayMode newDisplayMode = TheClient->iScreen->DisplayMode();
sl@0: 				
sl@0: 				TEST(TDisplayModeUtils::NumDisplayModeColors(newDisplayMode) >= tryColoursPixel);	
sl@0: 				
sl@0: 				if(!(TDisplayModeUtils::NumDisplayModeColors(newDisplayMode) >= tryColoursPixel))
sl@0: 					{
sl@0: 					ERR_PRINTF3(_L("testWin1: newDisplayMode = %d, tryColoursPixel = %d"), newDisplayMode, tryColoursPixel);
sl@0: 					}
sl@0: 				
sl@0: 				// Estimate the minimum number of shades of primary colours given the bits per pixel.
sl@0: 				// The maximum is twice this. Very appoximate but seems to work OK for 256 colours. Probably not good for grey modes. 
sl@0: 				for(tt = tryColoursPixel; tt >= 8; tt >>= 3)
sl@0: 					{
sl@0: 					expectedColoursPerChannel <<= 1;
sl@0: 					}
sl@0: 					
sl@0: 				// Draw some test data on the test window.
sl@0: 			    testWin1->DrawNow();
sl@0: 				TheClient->iWs.Flush();
sl@0: 				 
sl@0: #ifdef VISIBLE_PAUSES
sl@0: 			    TheClient->StdLogWindow().LogMessage(EFalse, _L("Mode: "), tryMode);
sl@0: 				User::After(1000000);
sl@0: #endif 
sl@0: 				TInt numUniqueColours = testWin1->CountUniquePlottedColours();
sl@0: 				INFO_PRINTF2(_L("testWin1: numUniqueColours = %d"), numUniqueColours);
sl@0: 			    testWin1->DrawNow();
sl@0: 			    TheClient->StdLogWindow().LogMessage(EFalse, _L("Channel Colours: "), numUniqueColours);
sl@0: 				TheClient->iWs.Flush();
sl@0: 				
sl@0: #ifdef VISIBLE_PAUSES
sl@0: 				User::After(1000000); 
sl@0: #endif
sl@0: 				// Read it back and see if it has the expected quality
sl@0: 				TEST(numUniqueColours >= (expectedColoursPerChannel * 3));
sl@0: 				
sl@0: 				if(!(numUniqueColours >= (expectedColoursPerChannel * 3)))
sl@0: 					{
sl@0: 					ERR_PRINTF3(_L("testWin1: numUniqueColours = %d, (expectedColoursPerChannel * 3) = %d"), numUniqueColours, (expectedColoursPerChannel * 3));
sl@0: 					}				
sl@0: 		
sl@0: 				/*
sl@0: 				 * Defect 107176 was rejected. This test for transparency is therefore removed.
sl@0: 				 * 
sl@0: 				 */
sl@0: 				if (false) //newDisplayMode != startDisplayMode)	 // Hide the window under a startmode window and see if we switch back?
sl@0: 				if (isTransparencySupportedResult==KErrNone && newDisplayMode != startDisplayMode)	 // Hide the window under a startmode window and see if we switch back?
sl@0: 				/*
sl@0: 				 * Defect 107176 was rejected. This test for transparency is therefore removed.
sl@0: 				 * The crash demonstrated by this code is related to the inconsistant support for origin and scale
sl@0: 				 * See defect DEF111847 and break request 2226
sl@0: 				 */
sl@0: 				if (false) //newDisplayMode != startDisplayMode)	 // Hide the window under a startmode window and see if we switch back?
sl@0: 					{
sl@0: 					// Demonstration of defect 107176
sl@0: 					// Create a translucent window which obscures the high-colour window
sl@0: 					// The existing code reduces the display colour depth because it thinks the obscured window is not visible any more
sl@0: 					// However, the obscured window is actually visible trough the transparency
sl@0: 					CPrimaryColoursWin* testWin2 = new (ELeave) CPrimaryColoursWin;
sl@0: 					CleanupStack::PushL(testWin2);
sl@0: 	
sl@0: 					testWin2->SetUpL(r.iTl - TPoint(20,20), r.Size() + TSize(40,40), TheClient->iGroup, *TheClient->iGc, &startDisplayMode, ETrue, 0x80);
sl@0: 					TheClient->iWs.Flush();
sl@0: 				    testWin2->DrawNow();
sl@0: 					TheClient->iWs.Flush();
sl@0: 					
sl@0: 					TDisplayMode newnewDisplayMode = TheClient->iScreen->DisplayMode();
sl@0: 					TInt newNumUniqueColours = testWin2->CountUniquePlottedColours();	
sl@0: 					INFO_PRINTF2(_L("testWin2: newNumUniqueColours = %d"), newNumUniqueColours);		
sl@0: 					
sl@0: 					TEST(newnewDisplayMode == newDisplayMode);				
sl@0: 				  
sl@0: 					if(!(newnewDisplayMode == newDisplayMode))
sl@0: 						{
sl@0: 						ERR_PRINTF3(_L("testWin2: newnewDisplayMode = %d, newDisplayMode = %d"), newnewDisplayMode, newDisplayMode);
sl@0: 						}
sl@0: 					  
sl@0: 				    testWin2->DrawNow();
sl@0: 					TheClient->iWs.Flush();
sl@0: 					
sl@0: #ifdef VISIBLE_PAUSES
sl@0: 					User::After(1000000); 
sl@0: #endif
sl@0: 					TheClient->iWs.Flush();
sl@0: 					
sl@0: 					CleanupStack::PopAndDestroy(testWin2);
sl@0: 					testWin2 = NULL;						
sl@0: 					}
sl@0: 					
sl@0: 					CleanupStack::PopAndDestroy(testWin1);
sl@0: 					testWin1 = NULL;
sl@0: 				}
sl@0: 			 
sl@0: 				TDisplayMode afterDisplayMode = TheClient->iScreen->DisplayMode();
sl@0: 				TEST(afterDisplayMode == startDisplayMode);
sl@0: 				
sl@0: 				if(afterDisplayMode != startDisplayMode)
sl@0: 					{
sl@0: 					ERR_PRINTF3(_L("DeviceResSwitchL: Original colour depth not restored. Was %i, now %i (TDisplayMode)"), startDisplayMode, afterDisplayMode);						
sl@0: 					}
sl@0: 
sl@0: #ifdef VISIBLE_PAUSES
sl@0: 				User::After(1000000); 
sl@0: #endif			
sl@0: 			} // context 
sl@0: 		} // for loop ends
sl@0: 		
sl@0: 	INFO_PRINTF1(_L("DeviceResSwitchL: Returning from function"));		
sl@0: 	}
sl@0: 	
sl@0: void CTScreenDeviceResSwitch::CalculateDisplayPropertiesL()
sl@0: 	{
sl@0: 	INFO_PRINTF1(_L("CalculateDisplayPropertiesL: Entering function"));
sl@0: 	
sl@0: 	TDisplayMode tryMode = (TDisplayMode) (EColorLast - 1);
sl@0: 	TPixelsAndRotation modeSettings;
sl@0: 	TheClient->iScreen->GetDefaultScreenSizeAndRotation(modeSettings);
sl@0: 	TRect r(TPoint(0, 0), modeSettings.iPixelSize);
sl@0: 
sl@0: 	CPrimaryColoursWin* tempWin = new (ELeave) CPrimaryColoursWin;
sl@0: 	CleanupStack::PushL(tempWin);
sl@0: 	
sl@0: 	tempWin->SetUpL(r.iTl, r.Size(), TheClient->iGroup, *TheClient->iGc, &tryMode);
sl@0: 	TheClient->iWs.Flush();
sl@0: 	
sl@0: 	iMaxDisplayMode = TheClient->iScreen->DisplayMode();
sl@0: 	INFO_PRINTF2(_L("CalculateDisplayPropertiesL: iMaxDisplayMode %d"), iMaxDisplayMode);
sl@0: 	iMaxDisplayModeColors = TDisplayModeUtils::NumDisplayModeColors(iMaxDisplayMode);
sl@0: 	INFO_PRINTF2(_L("CalculateDisplayPropertiesL: iMaxDisplayModeColors %d"), iMaxDisplayModeColors);	
sl@0: 	
sl@0: 	CleanupStack::PopAndDestroy(tempWin);
sl@0: 	INFO_PRINTF1(_L("CalculateDisplayPropertiesL: Returning from function"));
sl@0: 	}
sl@0: 	
sl@0: TInt CTScreenDeviceResSwitch::NumDisplayModeColors(TDisplayMode aDispMode)
sl@0: 	{
sl@0: 	TInt dispModeColors = TDisplayModeUtils::NumDisplayModeColors(aDispMode);
sl@0: 	
sl@0: 	if(dispModeColors > iMaxDisplayModeColors)
sl@0: 		{
sl@0: 		return iMaxDisplayModeColors;
sl@0: 		}
sl@0: 		
sl@0: 	return dispModeColors;
sl@0: 	}
sl@0: 	
sl@0: TInt CTScreenDeviceResSwitch::IsTransparencySupportedL()
sl@0: 	{
sl@0: 	INFO_PRINTF1(_L("IsTransparencySupportedL: Entering function"));
sl@0: 	// Creates a window and sets the transparency, if this feature
sl@0: 	// is not enabled, KErrNotSupported will be returned
sl@0: 	const TRgb KTransparencyColor(85,85,85);		
sl@0: 	RWindow win(TheClient->iWs);
sl@0: 	win.Construct(*TheClient->iGroup->GroupWin(), ENullWsHandle);	
sl@0: 	win.SetExtent(TPoint(0,0), TSize(50,50));	
sl@0: 	win.SetRequiredDisplayMode(EColor256);
sl@0: 	TInt ret = win.SetTransparencyFactor(KTransparencyColor);
sl@0: 	win.Close();
sl@0: 	
sl@0: 	if(!ret)
sl@0: 		{
sl@0: 		INFO_PRINTF1(_L("IsTransparencySupportedL: Transparency is supported"));
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 		INFO_PRINTF1(_L("IsTransparencySupportedL: Transparency is not supported"));
sl@0: 		}
sl@0: 	
sl@0: 	INFO_PRINTF1(_L("IsTransparencySupportedL: Returning from function"));
sl@0: 	return ret;
sl@0: 	}
sl@0: 
sl@0: void CTScreenDeviceResSwitch::RunTestCaseL(TInt /*aCurTestCase*/)
sl@0: 	{
sl@0: 	((CTScreenDeviceResSwitchStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
sl@0: 	switch(++iTest->iState)
sl@0: 		{
sl@0: /**
sl@0: @SYMTestCaseID		GRAPHICS-WSERV-0440
sl@0: 
sl@0: @SYMDEF             DEF107176
sl@0: 
sl@0: @SYMTestCaseDesc    Intended primarily as a visual check that the mode is displayed correctly. Checks correct display mode is set.
sl@0:                     The test also verifies that the number of physical colours matches the reported mode.
sl@0:                     Note that although written to test GCE, this test is general and applies to all display versions.               
sl@0: 
sl@0: @SYMTestPriority    High
sl@0: 
sl@0: @SYMTestStatus      Implemented
sl@0: 
sl@0: @SYMTestActions     Creates a windows with a higher display mode. Then creates a transparent
sl@0:                     window with lower display mode that completely covers the first window.
sl@0:                     Checks the display mode is not changed to the lower diplay mode when 
sl@0:                     the higher display mode window is visible through transparency.
sl@0: 
sl@0: @SYMTestExpectedResults The higher display mode should still be set after the second window is drawn.
sl@0: */
sl@0: 		case 1:
sl@0: 			((CTScreenDeviceResSwitchStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0440"));
sl@0: 			iTest->LogSubTest(_L("Device resolution switching"));
sl@0: 			DeviceResSwitchL();		
sl@0: 			break;			
sl@0: /**
sl@0: @SYMTestCaseID		GRAPHICS-WSERV-0520
sl@0: 
sl@0: @SYMTestCaseDesc	Test for device switching when mode increased.
sl@0: 
sl@0: @SYMTestActions     Windows are created in increasing modes and pixel colours written and read back.
sl@0: 					This code verifies that the mode change actually takes place.
sl@0: 					I am using this visually to verify that the new GCE is actually changing the mode.
sl@0: 
sl@0: **/
sl@0: 		case 2:
sl@0: 			((CTScreenDeviceResSwitchStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0520"));
sl@0: 			iTest->LogSubTest(_L("More device resolution switching"));
sl@0: 			DeviceResSwitchWithRotationsL();
sl@0: 			break;
sl@0: 		default:
sl@0: 			((CTScreenDeviceResSwitchStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
sl@0: 			((CTScreenDeviceResSwitchStep*)iStep)->CloseTMSGraphicsStep();
sl@0: 			TestComplete();
sl@0: 		}
sl@0: 	((CTScreenDeviceResSwitchStep*)iStep)->RecordTestResultL();
sl@0: 	}
sl@0: 
sl@0: __WS_CONSTRUCT_STEP__(ScreenDeviceResSwitch)