os/graphics/windowing/windowserver/nga/SERVER/openwfc/screen.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/windowing/windowserver/nga/SERVER/openwfc/screen.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,2372 @@
     1.4 +// Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include "screen.h"
    1.20 +
    1.21 +#include <hal.h>
    1.22 +#include <graphics/wsscreendevice.h>
    1.23 +#include <graphics/wsscene.h>
    1.24 +#include <graphics/wselement.h>
    1.25 +#include "server.h"
    1.26 +#include "wstop.h"
    1.27 +#include "rootwin.h"
    1.28 +#include "walkwindowtree.h"
    1.29 +#include "EVENT.H"
    1.30 +#include "windowgroup.h"
    1.31 +#include "inifile.h"
    1.32 +#include "pointer.h"
    1.33 +#include "windowelementset.h"
    1.34 +#include "registeredsurfacemap.h"
    1.35 +#include "debugbar.h"
    1.36 +#include "ScreenRedraw.h"
    1.37 +#include "wspluginmanager.h"
    1.38 +#include "devicemap.h"
    1.39 +#include <graphics/wsdisplaymapping.h>
    1.40 +#if defined(__WINS__) && defined(_DEBUG)
    1.41 +#include "../../debuglog/osbwin.h"
    1.42 +#endif
    1.43 +#include <graphics/wsdisplaycontrol.h>
    1.44 +
    1.45 +GLREF_D CDebugLogBase *wsDebugLog;
    1.46 +
    1.47 +LOCAL_C inline MWsScene::TSceneRotation GcToScreen(CFbsBitGc::TGraphicsOrientation aGcOrientation)
    1.48 +	{
    1.49 +	MWsScene::TSceneRotation screenRotation = MWsScene::ESceneAntiClockwise0;
    1.50 +
    1.51 +	switch (aGcOrientation)
    1.52 +		{
    1.53 +		case CFbsBitGc::EGraphicsOrientationRotated90:
    1.54 +			screenRotation = MWsScene::ESceneAntiClockwise90;
    1.55 +			break;
    1.56 +		case CFbsBitGc::EGraphicsOrientationRotated180:
    1.57 +			screenRotation = MWsScene::ESceneAntiClockwise180;
    1.58 +			break;
    1.59 +		case CFbsBitGc::EGraphicsOrientationRotated270:
    1.60 +			screenRotation = MWsScene::ESceneAntiClockwise270;
    1.61 +			break;
    1.62 +		}
    1.63 +
    1.64 +	return screenRotation;
    1.65 +	}
    1.66 +
    1.67 +LOCAL_C inline TDeviceOrientation GcToDevice(CFbsBitGc::TGraphicsOrientation aGcOrientation)
    1.68 +	{
    1.69 +	// Each device orientation is defined to be the value where just the bit
    1.70 +	// corresponding to the GDI orientation value is set.
    1.71 +	return (TDeviceOrientation)(1 << aGcOrientation);
    1.72 +	}
    1.73 +
    1.74 +LOCAL_D TBool FindNextValue(TLex& aLex, TInt& aValue) // assumes the list cannot contain *negative* integers
    1.75 +	{
    1.76 +	while (!aLex.Eos())
    1.77 +		{
    1.78 +		const TUint character=aLex.Peek();
    1.79 +		if (Rng(TUint('0'), character, TUint('9')) || (character=='-'))
    1.80 +			{
    1.81 +			break;
    1.82 +			}
    1.83 +		aLex.Inc();
    1.84 +		}
    1.85 +
    1.86 +	return (aLex.Val(aValue)==KErrNone);
    1.87 +	}
    1.88 +
    1.89 +CScreen::CFallbackMap * CScreen::CFallbackMap::NewL(CScreen* aScreen)
    1.90 +	{
    1.91 +	CFallbackMap * self = new (ELeave) CFallbackMap(aScreen);
    1.92 +	CleanupStack::PushL(self);
    1.93 +	self->ConstructL();
    1.94 +	CleanupStack::Pop(self);
    1.95 +	return self;
    1.96 +	}
    1.97 +	
    1.98 +CScreen::CFallbackMap::CFallbackMap(CScreen* aScreen) :
    1.99 +	iScreen(aScreen),
   1.100 +	iRegion(TRect(TPoint(0,0), TSize(1,1))),
   1.101 +	iCount(0)
   1.102 +	{
   1.103 +	}
   1.104 +	
   1.105 +CScreen::CFallbackMap::~CFallbackMap()
   1.106 +	{
   1.107 +	delete []iMap;
   1.108 +	}
   1.109 +	
   1.110 +void CScreen::CFallbackMap::ConstructL()
   1.111 +	{
   1.112 +	iMapSize = 0;
   1.113 +	
   1.114 +	for (TInt num = 0; num < iScreen->NumScreenSizeModes(); ++num)
   1.115 +		{
   1.116 +		if (iScreen->IsValidScreenSizeMode(num))
   1.117 +			{
   1.118 +			const TSizeMode & mode = iScreen->ScreenSizeModeData(num);
   1.119 +			TInt width = mode.iScreenSize.iWidth / 32;
   1.120 +			if (mode.iScreenSize.iWidth & (32 - 1))
   1.121 +				++width;
   1.122 +			TInt size = width * mode.iScreenSize.iHeight;
   1.123 +			if (size > iMapSize)
   1.124 +				iMapSize = size;
   1.125 +			}
   1.126 +		}
   1.127 +		
   1.128 +	iMap = new (ELeave) TInt [iMapSize];
   1.129 +	}
   1.130 +
   1.131 +void CScreen::CFallbackMap::Prepare()
   1.132 +	{
   1.133 +	const TSizeMode & mode = iScreen->ScreenSizeModeData();
   1.134 +	Mem::FillZ(iMap, iMapSize * sizeof(TInt));
   1.135 +	iCount = mode.iScreenSize.iHeight * mode.iScreenSize.iWidth;
   1.136 +	WS_ASSERT_DEBUG(iRegion.Count() == 1, EWsPanicScreenFallback);
   1.137 +	iRegion.Clear();
   1.138 +	iRegion.AddRect(TRect(mode.iOrigin, mode.iScreenSize));
   1.139 +	}
   1.140 +
   1.141 +TBool CScreen::CFallbackMap::FillRegion(const TRegion& aRegion)
   1.142 +	{
   1.143 +	WS_ASSERT_DEBUG(!aRegion.CheckError(), EWsPanicScreenFallback);
   1.144 +	if (aRegion.Count() > 20 || aRegion.CheckError())
   1.145 +		return ETrue;
   1.146 +	TBool hit = EFalse;
   1.147 +	if (iCount > 0)
   1.148 +		{
   1.149 +		const TRect * rect = aRegion.RectangleList();
   1.150 +		for (TInt num = 0; num < aRegion.Count(); ++num)
   1.151 +			{
   1.152 +			hit = FillRect(*rect) || hit;
   1.153 +			if (iCount < 1)
   1.154 +				break;
   1.155 +			++rect;
   1.156 +			}
   1.157 +		}
   1.158 +	return hit;
   1.159 +	}
   1.160 +	
   1.161 +// x >> 5 is equivalent to x / 32
   1.162 +// 0x1F is the rounding error when dividing by 32
   1.163 +// 0x20 is 32.
   1.164 +// The compiler might do all the optimizations for us - not checked.
   1.165 +TBool CScreen::CFallbackMap::FillRect(const TRect& aRect)
   1.166 +	{
   1.167 +	TBool hit = EFalse;
   1.168 +	const TSizeMode & mode = iScreen->ScreenSizeModeData();
   1.169 +	TRect scrrect(mode.iOrigin, mode.iScreenSize);
   1.170 +	TRect rect = aRect;
   1.171 +	rect.Intersection(scrrect);
   1.172 +	TInt rowWidthInInts = mode.iScreenSize.iWidth;
   1.173 +	if (rowWidthInInts & 0x1F)
   1.174 +		rowWidthInInts += 0x20;
   1.175 +	rowWidthInInts >>= 5;
   1.176 +
   1.177 +	TInt colStartInInts = rect.iTl.iX >> 5;
   1.178 +	TInt firstOffsetInBits = rect.iTl.iX & 0x1F;
   1.179 +
   1.180 +	for(TInt row = rect.iTl.iY; row < rect.iBr.iY; ++row)
   1.181 +		{
   1.182 +		TInt * map = iMap + row * rowWidthInInts + colStartInInts;
   1.183 +		TInt offsetShift = 31 - firstOffsetInBits;
   1.184 +		for (TInt col = rect.iTl.iX; col < rect.iBr.iX; ++col)
   1.185 +			{
   1.186 +			WS_ASSERT_DEBUG(map - iMap < iMapSize, EWsPanicScreenFallback);
   1.187 +			if (!(*map & 1 << offsetShift))
   1.188 +				{
   1.189 +				--iCount;
   1.190 +				hit = ETrue;
   1.191 +				if (iCount < 1)
   1.192 +					break;
   1.193 +				(*map) |= (1 << offsetShift);
   1.194 +				}
   1.195 +			--offsetShift;
   1.196 +			if (offsetShift < 0)
   1.197 +				{
   1.198 +				offsetShift = 31;
   1.199 +				++map;
   1.200 +				}
   1.201 +			}
   1.202 +		}
   1.203 +	return hit;
   1.204 +	}
   1.205 +
   1.206 +TInt CScreen::CFallbackMap::Count() const
   1.207 +	{
   1.208 +	return iCount;
   1.209 +	}
   1.210 +
   1.211 +const TRect * CScreen::CFallbackMap::Rect() const
   1.212 +	{
   1.213 +	return iRegion.RectangleList();
   1.214 +	}
   1.215 +	
   1.216 +const RRegion * CScreen::CFallbackMap::Region() const
   1.217 +	{
   1.218 +	return &iRegion;
   1.219 +	}
   1.220 +
   1.221 +TInt CScreen::CFallbackMap::Resize(const TSize& aSize)
   1.222 +	{
   1.223 +	TInt err = KErrNone;
   1.224 +	TInt width = (aSize.iWidth+31) >> 5;	// divide by 32
   1.225 +	TInt invertedWidth = (aSize.iHeight+31) >> 5;	// divide by 32
   1.226 +		
   1.227 +	TInt maxSize = Max(width * aSize.iHeight,invertedWidth * aSize.iWidth);
   1.228 +	if (maxSize > iMapSize)
   1.229 +		{
   1.230 +		TInt* newMap=NULL;
   1.231 +		newMap = new  TInt [maxSize];
   1.232 +		if (newMap)
   1.233 +			{
   1.234 +			delete []iMap;
   1.235 +			iMap = newMap;
   1.236 +			iMapSize = maxSize;
   1.237 +			}
   1.238 +		else
   1.239 +			{
   1.240 +			err = KErrNoMemory;
   1.241 +			}
   1.242 +		}
   1.243 +	return err;
   1.244 +	}
   1.245 +	
   1.246 +//
   1.247 +// CScreen
   1.248 +//
   1.249 +CScreen::CScreen(): iDirects(_FOFF(CWsDirectScreenAccess,iLink)), iMaxContrast(-1), iMaxBrightness(-1)
   1.250 +, iDisplayChangeSpinner(0), iConfigChangeSpinner(0)
   1.251 +	{
   1.252 +	}
   1.253 +
   1.254 +CScreen::~CScreen()
   1.255 +	{
   1.256 +	delete iDebugBar;
   1.257 +	TInt ii;
   1.258 +	if(iModes)
   1.259 +		{
   1.260 +		for(ii=iNumScreenSizeModes-1;ii>=0;--ii)
   1.261 +			{
   1.262 +			delete (*iModes)[ii];
   1.263 +			}
   1.264 +		iModes->Close();
   1.265 +		delete iModes;
   1.266 +		}
   1.267 +	delete iRootWindow;
   1.268 +	iScreenDevice = NULL;
   1.269 +	delete iDsaDevice;
   1.270 +	delete iDeviceMap;
   1.271 +	delete iFallbackMap;
   1.272 +	delete iSpriteManager;
   1.273 +	delete iWindowElementSet;
   1.274 +	if (!iDsaSurface.IsNull())
   1.275 +	    {
   1.276 +	    TInt err = iScene->UnregisterSurface(iDsaSurface);
   1.277 +		WS_ASSERT_DEBUG(KErrNone == err, EWsPanicDirectScreenAccess);
   1.278 +	    }
   1.279 +
   1.280 +	delete iSurfaceMap;
   1.281 +	delete iRedraw;
   1.282 +#if defined(__WINS__) && defined(_DEBUG)
   1.283 +	delete iDebugWin;
   1.284 +#endif
   1.285 +	
   1.286 +	if(iDisplayChangeNotifier)
   1.287 +		delete iDisplayChangeNotifier;
   1.288 +	if(iConfigChangeNotifier)
   1.289 +		delete iConfigChangeNotifier;
   1.290 +	iWsClientList.Close();
   1.291 +	}
   1.292 +
   1.293 +void CScreen::ConstructL(const TRect& aDigitiserArea, TInt aScreenNumber)
   1.294 +	{
   1.295 +	iScreenNumber = aScreenNumber ;
   1.296 +
   1.297 +	if (wsDebugLog)
   1.298 +		{
   1.299 +		_LIT(KWSERVInitScreen,"Initialising for Screen %d");
   1.300 +		wsDebugLog->MiscMessage(CDebugLogBase::ELogImportant, KWSERVInitScreen, aScreenNumber);
   1.301 +		}
   1.302 +
   1.303 +	// create screen redraw with render stages
   1.304 +	iRedraw = CScreenRedraw::NewL(*this);
   1.305 +	iScreenDevice = iRedraw->ObjectInterface<MWsScreenDevice>();
   1.306 +	WS_ASSERT_ALWAYS(iScreenDevice, EWsPanicScreenDeviceMissing);
   1.307 +	iScene = iRedraw->ObjectInterface<MWsScene>();
   1.308 +	WS_ASSERT_ALWAYS(iScene, EWsPanicSceneMissing);
   1.309 +	
   1.310 +	iDeviceMap = CGraphicsDeviceMap::NewL(*iScreenDevice);
   1.311 +
   1.312 +	iDisplayControl = MWsScreen::ObjectInterface<MWsDisplayControl>();
   1.313 +	iDisplayMapping = MWsScreen::ObjectInterface<MWsDisplayMapping>();
   1.314 +	iDisplayPolicy = MWsScreen::ObjectInterface<MWsDisplayPolicy>();
   1.315 +
   1.316 +
   1.317 +	// initialize screen size mode data
   1.318 +	LoadScreenSizesL(iScreenDevice->SizeInPixels());
   1.319 +	iFallbackMap = CFallbackMap::NewL(this);
   1.320 +
   1.321 +	LoadScreenSizeProperties(iScreenDevice->DisplayMode());
   1.322 +
   1.323 +	if (iDisplayPolicy)
   1.324 +		{
   1.325 +		iDisplayPolicy->NewAppModesAvailable();
   1.326 +		}
   1.327 +	
   1.328 +	iDigitiserArea = aDigitiserArea;
   1.329 +	SetInitialScreenSizeModeAndRotation(); //get the first/lowest valid mode.  Also calls SetDigitiserAreas
   1.330 +	
   1.331 +	ApplyRemainingWsiniSettingsL();
   1.332 +	
   1.333 +	iRootWindow = new (ELeave) CWsRootWindow(NULL, this);
   1.334 +	iRootWindow->ConstructL();
   1.335 +	
   1.336 +	// Default fading parameters
   1.337 +	iBlackMap=128;
   1.338 +	iWhiteMap=255;
   1.339 +	
   1.340 +	iSpriteManager = CWsSpriteManager::NewL();
   1.341 +
   1.342 +	InitializeSceneL();
   1.343 +	InitializeUiElementsL();
   1.344 +	iSurfaceMap = new (ELeave) CRegisteredSurfaceMap(*iScene);
   1.345 +	
   1.346 +	//if the interface for notification is available. start notification AO.
   1.347 +	if (iDisplayControl)
   1.348 +		{
   1.349 +		iDisplayChangeNotifier = CWsDisplayChangeNotifier::NewL(iDisplayControl, this);
   1.350 +		iDisplayChangeNotifier->IssueNotificationRequest();
   1.351 +		iConfigChangeNotifier = CWsConfigChangeNotifier::NewL(iDisplayControl, this);
   1.352 +		iConfigChangeNotifier->IssueNotificationRequest();
   1.353 +		}
   1.354 +	doSetScreenMode(iScreenSizeMode,ETrue);
   1.355 +	}
   1.356 +
   1.357 +void CScreen::ApplyRemainingWsiniSettingsL()
   1.358 +	{
   1.359 +#if defined(__WINS__) && defined(_DEBUG)
   1.360 +	_LIT(KDebugOsb,"DEBUGOSB");
   1.361 +	if(WsIniFile->FindVar(iScreenNumber, KDebugOsb))
   1.362 +		{
   1.363 +		_LIT(KDebugWinTitleFormat, "Screen %d, DSA surface");
   1.364 +		TBuf<32> title;
   1.365 +		title.Format(KDebugWinTitleFormat, iScreenNumber);
   1.366 +		iDebugWin = CDebugOsbWin::NewL(title, iScreenDevice->SizeInPixels());
   1.367 +		}
   1.368 +#endif
   1.369 +	
   1.370 +   	TInt autoClear = 1;
   1.371 +   	_LIT(KWSERVIniFileVarAutoClear,"AUTOCLEAR");
   1.372 +   	WsIniFile->FindVar(iScreenNumber,KWSERVIniFileVarAutoClear,autoClear);
   1.373 +   	if (autoClear != 0)
   1.374 +   		{
   1.375 +   		iFlags|=EAutoClear;
   1.376 +   		}
   1.377 +		
   1.378 +	_LIT(KBackLight,"BACKLIGHTCONTROL");
   1.379 +	iBackLightFlag=WsIniFile->FindVar( iScreenNumber, KBackLight);
   1.380 +
   1.381 +	_LIT(KWSERVIniFileVarBlankScreen, "BLANKSCREENONROTATION");
   1.382 +	if (WsIniFile->FindVar(iScreenNumber, KWSERVIniFileVarBlankScreen))
   1.383 +		{
   1.384 +		iFlags|=EBlankScreenOnRotation;
   1.385 +		}
   1.386 +
   1.387 +	//Cache pointers to renderstage APIs required in CHANGETRACKING mode
   1.388 +	iWindowTreeObserver = iRedraw->ObjectInterface<MWsWindowTreeObserver>(); 
   1.389 +	iDrawAnnotationObserver = iRedraw->ObjectInterface<MWsDrawAnnotationObserver>();
   1.390 +	iWindowVisibilityNotifier = iRedraw->ObjectInterface<MWsWindowVisibilityNotifier>();
   1.391 +	if(iWindowVisibilityNotifier)
   1.392 +		{
   1.393 +		iWindowVisibilityNotifier->RegisterWindowVisibilityObserver(iRedraw);
   1.394 +		}
   1.395 +	if (WsIniFile->FindVar(iScreenNumber, KWSERVIniFileVarChangeTracking))
   1.396 +		{
   1.397 +		iFlags|=EChangeTracking;
   1.398 +		}
   1.399 +
   1.400 +	//coverity[const]
   1.401 +	TInt refreshRate = 1000000;
   1.402 +	_LIT(KDebugBar, "DEBUGBAR");
   1.403 +	if (WsIniFile->FindVar(KDebugBar, refreshRate))
   1.404 +		{
   1.405 +		if (refreshRate < 100000)
   1.406 +			// coverity [dead_error_line]
   1.407 +			refreshRate = 50000;
   1.408 +		iDebugBar = CDebugBar::NewL(this, refreshRate);
   1.409 +		}
   1.410 +	}
   1.411 +
   1.412 +void CScreen::AcquireDsaScreenDeviceL()
   1.413 +	{
   1.414 +	//creates WSERV's DSA buffer handle
   1.415 +	//registers the DSA surface into the scene accordingly to the value of aRegisterSurface
   1.416 +	if(!iDsaDevice)
   1.417 +		{
   1.418 +		TDisplayMode screenMode = ENone;
   1.419 +		screenMode = iScreenDevice->DisplayMode();
   1.420 +		if(screenMode != ENone)
   1.421 +			{
   1.422 +			CreateDsaScreenDeviceIfSupportedL(screenMode);
   1.423 +			// initialize DSA
   1.424 +			iDsaDevice->SetAutoUpdate(EFalse);
   1.425 +			iDsaDevice->SetDeviceOrientation(GcToDevice(ScreenSizeModeData().iRotation));
   1.426 +			iDsaDevice->ChangeScreenDevice(NULL);    //This is necessary to initialise the screen
   1.427 +			// register DSA Surface
   1.428 +			TInt err = InitializeDsaSurface();
   1.429 +			// create a graphics context to clear the DSA surface
   1.430 +			if (!err)
   1.431 +				err = iDsaDevice->CreateContext(iDsaGc);
   1.432 +			if (!err)
   1.433 +				iDsaGc->Activate(iDsaDevice);
   1.434 +			if (err != KErrNone)
   1.435 +				{
   1.436 +				//Creation of the DSA surface failed
   1.437 +				//Cleanup the DSA Surface ID
   1.438 +				iDsaSurface = TSurfaceId::CreateNullId();
   1.439 +				//and the iDsaDevice
   1.440 +				delete iDsaDevice;
   1.441 +				iDsaDevice = NULL;
   1.442 +				User::Leave(err);
   1.443 +				}
   1.444 +			}
   1.445 +		else
   1.446 +			{
   1.447 +			User::Leave(KErrNotSupported);
   1.448 +			}
   1.449 +		}
   1.450 +	iNumberDrawingDsa++;
   1.451 +	}
   1.452 +
   1.453 +void CScreen::CreateDsaScreenDeviceIfSupportedL(TDisplayMode aScreenMode)
   1.454 +	{
   1.455 +	if(DoCreateDsaScreenDevice(aScreenMode))
   1.456 +		return;
   1.457 +	// Try creating the screen device with all available display modes, going from best to worst
   1.458 +	__ASSERT_COMPILE(EColorLast == 14); // if any display mode is added to TDisplayMode we must update the list below
   1.459 +	// (the list below contains all enums in TDisplayMode except ENone, ERgb, EColorLast)
   1.460 +	if(DoCreateDsaScreenDevice(EColor16MAP))
   1.461 +		return;
   1.462 +	if(DoCreateDsaScreenDevice(EColor16MA))
   1.463 +		return;
   1.464 +	if(DoCreateDsaScreenDevice(EColor16MU))
   1.465 +		return;
   1.466 +	if(DoCreateDsaScreenDevice(EColor16M))
   1.467 +		return;
   1.468 +	if(DoCreateDsaScreenDevice(EColor64K))
   1.469 +		return;
   1.470 +	if(DoCreateDsaScreenDevice(EColor4K))
   1.471 +		return;
   1.472 +	if(DoCreateDsaScreenDevice(EColor256))
   1.473 +		return;
   1.474 +	if(DoCreateDsaScreenDevice(EColor16))
   1.475 +		return;
   1.476 +	if(DoCreateDsaScreenDevice(EGray256))
   1.477 +		return;
   1.478 +	if(DoCreateDsaScreenDevice(EGray16))
   1.479 +		return;
   1.480 +	if(DoCreateDsaScreenDevice(EGray4))
   1.481 +		return;
   1.482 +	if(DoCreateDsaScreenDevice(EGray2))
   1.483 +		return;
   1.484 +	User::Leave(KErrNotSupported);
   1.485 +	}
   1.486 +
   1.487 +TBool CScreen::DoCreateDsaScreenDevice(TDisplayMode aScreenMode)
   1.488 +	{
   1.489 +	TRAPD(err, iDsaDevice = CFbsScreenDevice::NewL(iScreenNumber, aScreenMode));
   1.490 +	if(err == KErrNone)
   1.491 +		{
   1.492 +		TUint supportedDsaRotationModes = iDsaDevice->DeviceOrientationsAvailable();
   1.493 +		MWsScene::TSceneRotation currenTSceneRotation = iScene->SceneRotation();
   1.494 +		TBool doesDsaSupportThisMode = EFalse;
   1.495 +		switch(currenTSceneRotation)
   1.496 +			{
   1.497 +			case MWsScene::ESceneAntiClockwise0:
   1.498 +				if(supportedDsaRotationModes & EDeviceOrientationNormal)
   1.499 +					{
   1.500 +					doesDsaSupportThisMode = ETrue;
   1.501 +					}
   1.502 +				break;
   1.503 +			case MWsScene::ESceneAntiClockwise90:
   1.504 +				if(supportedDsaRotationModes & EDeviceOrientation90CW)
   1.505 +					{
   1.506 +					doesDsaSupportThisMode = ETrue;
   1.507 +					}
   1.508 +				break;				
   1.509 +			case MWsScene::ESceneAntiClockwise180:
   1.510 +				if(supportedDsaRotationModes & EDeviceOrientation180)
   1.511 +					{
   1.512 +					doesDsaSupportThisMode = ETrue;
   1.513 +					}
   1.514 +				break;				
   1.515 +			case MWsScene::ESceneAntiClockwise270:
   1.516 +				if(supportedDsaRotationModes & EDeviceOrientation270CW)
   1.517 +					{
   1.518 +					doesDsaSupportThisMode = ETrue;
   1.519 +					}
   1.520 +				break;				
   1.521 +			default:
   1.522 +				RDebug::Print(_L("** CScreen::DoCreateDsaScreenDevice Panic, non existing rotation mode"));
   1.523 +				WS_PANIC_ALWAYS(EWsPanicInvalidOperation);
   1.524 +				break;
   1.525 +			}
   1.526 +		if(!doesDsaSupportThisMode)
   1.527 +			{
   1.528 +			delete iDsaDevice;
   1.529 +			iDsaDevice = NULL;
   1.530 +			RDebug::Print(_L("** Current Rotation Mode not supported by the DSA device"));
   1.531 +			err = KErrNotSupported;
   1.532 +			}
   1.533 +		}
   1.534 +	return (err == KErrNone);
   1.535 +	}
   1.536 +
   1.537 +void CScreen::AbortDSAs(RDirectScreenAccess::TTerminationReasons aReason, TSglQue<CWsDirectScreenAccess>& aDirects)
   1.538 +	{
   1.539 +	if (aDirects.IsEmpty())
   1.540 +		return;
   1.541 +
   1.542 +	TInt nofDSAs = 0;
   1.543 +	CWsDirectScreenAccess* direct= NULL;
   1.544 +	TSglQueIter<CWsDirectScreenAccess> iter(aDirects);
   1.545 +	while ((direct=iter++)!=NULL)
   1.546 +		{
   1.547 +		nofDSAs++;
   1.548 +		direct->SignalAbort(aReason);
   1.549 +		}
   1.550 +
   1.551 +	TRequestStatus timerStatus;
   1.552 +	RTimer& timer=CWsTop::Timer();
   1.553 +	timer.Cancel();
   1.554 +
   1.555 +	TRequestStatus** cancelReqList = (TRequestStatus**) User::AllocZ(sizeof(TRequestStatus*) * (nofDSAs + 1));
   1.556 +	if (NULL != cancelReqList)
   1.557 +		{
   1.558 +		TInt dsaNo = 1;
   1.559 +		timer.After(timerStatus, KDSAAbortingImmediateRespAwaitFrameMicrosec);
   1.560 +		iter.SetToFirst();
   1.561 +		while ((direct=iter++)!=NULL)
   1.562 +			{
   1.563 +			WS_ASSERT_DEBUG((dsaNo<=(nofDSAs)),EWsPanicDirectScreenAccess);
   1.564 +			cancelReqList[ dsaNo ] = &direct->AbortStatus();
   1.565 +			dsaNo++;
   1.566 +			}
   1.567 +		cancelReqList[ 0 ] = &timerStatus;
   1.568 +
   1.569 +		//wait for response or timeout
   1.570 +		User::WaitForNRequest(cancelReqList, nofDSAs + 1);
   1.571 +
   1.572 +		iter.SetToFirst();
   1.573 +		while ((direct=iter++)!=NULL)
   1.574 +			{
   1.575 +			if (direct->AbortStatus() != KRequestPending)
   1.576 +				direct->CancelAbortObject(); // responded
   1.577 +			else
   1.578 +				direct->Abort();
   1.579 +			}
   1.580 +
   1.581 +		if (timerStatus == KRequestPending)
   1.582 +			{
   1.583 +			timer.Cancel();
   1.584 +			User::WaitForRequest(timerStatus);
   1.585 +			}
   1.586 +
   1.587 +		User::Free(cancelReqList);
   1.588 +		}
   1.589 +	else
   1.590 +		{
   1.591 +		iter.SetToFirst();
   1.592 +		while ((direct=iter++) != NULL)
   1.593 +			{
   1.594 +			TRequestStatus timerStatus;
   1.595 +			RTimer& timer=CWsTop::Timer();
   1.596 +			timer.Cancel();
   1.597 +			timer.After(timerStatus, KDSAAbortingImmediateRespAwaitFrameMicrosec);
   1.598 +			
   1.599 +			//wait for response or timeout
   1.600 +			User::WaitForRequest(direct->AbortStatus(), timerStatus);
   1.601 +			
   1.602 +			if (direct->AbortStatus() != KRequestPending)
   1.603 +				direct->CancelAbortObject(); //responded
   1.604 +			else
   1.605 +				direct->Abort(); //timed out
   1.606 +
   1.607 +			if (timerStatus == KRequestPending)
   1.608 +				{
   1.609 +				timer.Cancel();
   1.610 +				User::WaitForRequest(timerStatus);
   1.611 +				}
   1.612 +			}
   1.613 +		}
   1.614 +	}
   1.615 +
   1.616 +void CScreen::AbortAllDirectDrawing(RDirectScreenAccess::TTerminationReasons aReason)
   1.617 +	{
   1.618 +	AbortDSAs(aReason,iDirects);
   1.619 +	}
   1.620 +
   1.621 +void CScreen::AddDirect(CWsDirectScreenAccess& aDirect)
   1.622 +	{
   1.623 +	TBool emptyBefore = iDirects.IsEmpty();
   1.624 +	iDirects.AddLast(aDirect);
   1.625 +	TBool emptyAfter = iDirects.IsEmpty();
   1.626 +	if (emptyBefore && ! emptyAfter)
   1.627 +		{
   1.628 +		TWsEvent wsevent;
   1.629 +		wsevent.SetType(EEventDirectScreenAccessBegin);
   1.630 +		*(wsevent.Int()) = iScreenNumber;
   1.631 +		TWindowServerEvent::PublishNotification(wsevent);
   1.632 +		}
   1.633 +
   1.634 +	if (iDsaDrawState==EDsaDrawStateIdle && aDirect.IsVisible())
   1.635 +		{
   1.636 +		iDsaDrawState = EDsaDrawStateDrawing;
   1.637 +		TWindowServerEvent::NotifyDrawer(TWservCrEvent(TWservCrEvent::EDsaDrawingBegin, iScreenNumber));
   1.638 +		}
   1.639 +	}
   1.640 +
   1.641 +void CScreen::RemoveDirect(CWsDirectScreenAccess& aDirect)
   1.642 +	{
   1.643 +	TBool emptyBefore = iDirects.IsEmpty();
   1.644 +	iDirects.Remove(aDirect);
   1.645 +	TBool emptyAfter = iDirects.IsEmpty();
   1.646 +	if (emptyAfter && ! emptyBefore)
   1.647 +		{
   1.648 +		TWsEvent wsevent;
   1.649 +		wsevent.SetType(EEventDirectScreenAccessEnd);
   1.650 +		*(wsevent.Int()) = iScreenNumber;
   1.651 +		TWindowServerEvent::PublishNotification(wsevent);
   1.652 +		}
   1.653 +
   1.654 +	if (iDsaDrawState==EDsaDrawStateDrawing && aDirect.IsVisible() && !HasVisibleDirectOnQueue())
   1.655 +		{
   1.656 +		iDsaDrawState = EDsaDrawStateIdle;
   1.657 +		TWindowServerEvent::NotifyDrawer(TWservCrEvent(TWservCrEvent::EDsaDrawingEnd, iScreenNumber));
   1.658 +		}
   1.659 +	}
   1.660 +
   1.661 +TBool CScreen::HasVisibleDirectOnQueue()
   1.662 +	{
   1.663 +	if (iDirects.IsEmpty())
   1.664 +		return EFalse;
   1.665 +
   1.666 +	TSglQueIter<CWsDirectScreenAccess> iter(iDirects);
   1.667 +	CWsDirectScreenAccess* dsa;
   1.668 +	while ((dsa=iter++)!=NULL)
   1.669 +		{
   1.670 +		if (dsa->IsVisible())
   1.671 +			return ETrue;
   1.672 +		}
   1.673 +
   1.674 +	return EFalse;
   1.675 +	}
   1.676 +
   1.677 +#if defined(_DEBUG)
   1.678 +TBool CScreen::IsDirectOnQueue(const CWsDirectScreenAccess* aDirect)
   1.679 +	{
   1.680 +	TSglQueIter<CWsDirectScreenAccess> iter(iDirects);
   1.681 +	CWsDirectScreenAccess* direct;
   1.682 +	while ((direct=iter++)!=NULL)
   1.683 +		{
   1.684 +		if (direct==aDirect)
   1.685 +			return ETrue;
   1.686 +		}
   1.687 +	return EFalse;
   1.688 +	}
   1.689 +#endif
   1.690 +
   1.691 +void CScreen::KillForegroundSession()
   1.692 +	{
   1.693 +	if (iCurrentFocus)
   1.694 +		{
   1.695 +		_LIT(KWSERVKillWinGp,"Killing Session owning Window Group with Id=%d");
   1.696 +		if (wsDebugLog)
   1.697 +			wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything,KWSERVKillWinGp,iCurrentFocus->Identifier());
   1.698 +		iCurrentFocus->WsOwner()->SessionTerminate();
   1.699 +		}
   1.700 +	}
   1.701 +
   1.702 +CWsWindowGroup* CScreen::FindNewFocus(CWsRootWindow* aRootWindow)
   1.703 +	{
   1.704 +	CWsWindowGroup* newFocus;
   1.705 +	for(newFocus=aRootWindow->Child();newFocus && newFocus->CanReceiveFocus()==EFalse;newFocus=newFocus->NextSibling()) {}
   1.706 +
   1.707 +	return newFocus;
   1.708 +	}
   1.709 +
   1.710 +void CScreen::ResetFocus(CWsWindowGroup* aClosingWindow)
   1.711 +	{
   1.712 +	CWsWindowGroup* oldFocus=iCurrentFocus;
   1.713 +	CWsWindowGroup* newFocus=NULL;
   1.714 +	CScreen* newFocusedScreen=NULL;
   1.715 +	iCurrentFocus=FindNewFocus(iRootWindow);
   1.716 +	TBool focusedScreen= EFalse;
   1.717 +	/*Focus policy is specified in the wsini.ini file using the keyword 'MULTIFOCUSPOLICY'.
   1.718 +	If the keyword is not specified, then the default policy is run.
   1.719 +	*/
   1.720 +	if(!CWsTop::MultiFocusPolicy())
   1.721 +		{
   1.722 +		focusedScreen=(this==CWsTop::CurrentFocusScreen()); //check if this screen is the focus screen
   1.723 +		if (!iCurrentFocus && focusedScreen)
   1.724 +			{
   1.725 +			/*If this screen is the focused screen but does not have a focusable window group, then search for the
   1.726 +			next screen that has a focusable window group and set that screen as the focused screen.
   1.727 +			*/
   1.728 +			CScreen* screen=NULL;
   1.729 +			TInt screenNo;
   1.730 +			for (screenNo=0; screenNo<CWsTop::NumberOfScreens() && !newFocus; ++screenNo)
   1.731 +				{
   1.732 +				if (screenNo!=iScreenNumber)
   1.733 +					{
   1.734 +					screen=CWsTop::Screen(screenNo);
   1.735 +					newFocus=FindNewFocus(screen->RootWindow());
   1.736 +					}
   1.737 +				}
   1.738 +			if (newFocus)
   1.739 +				newFocusedScreen=screen;
   1.740 +			}
   1.741 +		}
   1.742 +	/*Scenario A: multi-focus policy
   1.743 +			newFocusedScreen is NULL
   1.744 +			focusedScreen is EFalse
   1.745 +			CWsTop::MultiFocusPolicy() returns ETrue
   1.746 +			Check if the new focusable window group is not the same, send focus lost message to window group
   1.747 +			that has just lost focus and send focus gain message to window group that can receive focus.
   1.748 +	  Scenario B: single-focus policy (default)
   1.749 +			CWsTop::MultiFocusPolicy() returns EFalse
   1.750 +			Check if the new focusable window group is not the same or if there is a new focused screen, send focus lost
   1.751 +			message to window group that has just lost focus and send focus gain message to window group that can receive focus.
   1.752 +	*/
   1.753 +	if (iCurrentFocus!=oldFocus || newFocusedScreen)
   1.754 +		{
   1.755 +		if (oldFocus && (focusedScreen || CWsTop::MultiFocusPolicy()) && oldFocus!=aClosingWindow)
   1.756 +			{
   1.757 +			oldFocus->LostFocus();
   1.758 +			}
   1.759 +		if (newFocusedScreen)
   1.760 +			{
   1.761 +			CWsTop::SetCurrentFocusScreen(newFocusedScreen);
   1.762 +			newFocus->ReceivedFocus();
   1.763 +			}
   1.764 +		else if (iCurrentFocus && (focusedScreen || CWsTop::MultiFocusPolicy()))
   1.765 +			{
   1.766 +			iCurrentFocus->ReceivedFocus();
   1.767 +			}
   1.768 +		TWsPointer::UpdatePointerCursor();
   1.769 +		TWindowServerEvent::SendFocusChangedEvents();
   1.770 +		}
   1.771 +	TWindowServerEvent::SendGroupListChangedEvents();
   1.772 +	}
   1.773 +
   1.774 +void CScreen::RemoveFromDefaultOwningList(CWsWindowGroup *aDestroyedGroup)
   1.775 +	{
   1.776 +	for (CWsWindowGroup **group=&iDefaultOwningWindow;*group;group=(*group)->NextDefaultOwningWindowPtr())
   1.777 +		{
   1.778 +		if (*group==aDestroyedGroup)
   1.779 +			{
   1.780 +			*group=*aDestroyedGroup->NextDefaultOwningWindowPtr();
   1.781 +			break;
   1.782 +			}
   1.783 +		}
   1.784 +	}
   1.785 +
   1.786 +void CScreen::SetDefaultOwningWindow(CWsWindowGroup *aGroup)
   1.787 +	{
   1.788 +	RemoveFromDefaultOwningList(aGroup);
   1.789 +	aGroup->SetNextDefaultOwningWindow(iDefaultOwningWindow);
   1.790 +	iDefaultOwningWindow=aGroup;
   1.791 +	}
   1.792 +
   1.793 +void CScreen::GetScanLine(const TWsSdCmdGetScanLine *aGetScanLine)
   1.794 +	{
   1.795 +	TRgb buf[EGetScanLineBufLen];
   1.796 +	TPtr8 des((TUint8 *)&buf[0],EGetScanLineBufLen*sizeof(TRgb));
   1.797 +	TPoint pos(aGetScanLine->pos);
   1.798 +	TInt read=0;
   1.799 +	TInt len=(des.MaxLength()*EGetScanLineBufLen)/CFbsBitmap::ScanLineLength(EGetScanLineBufLen,aGetScanLine->dispMode);
   1.800 +	if (aGetScanLine->len < 0 || (CFbsBitmap::ScanLineLength(aGetScanLine->len, aGetScanLine->dispMode) >
   1.801 +									CWsClient::CurrentClient()->ClientMessage().GetDesMaxLength(1)))
   1.802 +		{
   1.803 +		CWsClient::PanicCurrentClient(EWservPanicInvalidParameter);
   1.804 +		}
   1.805 +	FOREVER
   1.806 +		{
   1.807 +		if ((aGetScanLine->len-read)<len)
   1.808 +			len=aGetScanLine->len-read;
   1.809 +		iScreenDevice->GetScanLine(des,pos,len,aGetScanLine->dispMode);
   1.810 +		CWsClient::ReplyBuf(des);
   1.811 +		read+=len;
   1.812 +		if (read==aGetScanLine->len)
   1.813 +			break;
   1.814 +		pos.iX+=len;
   1.815 +		}
   1.816 +	}
   1.817 +
   1.818 +void CScreen::MaxNumColors(TInt& aColors,TInt& aGrays)
   1.819 +	{
   1.820 +	aGrays=0;
   1.821 +	aColors=TDisplayModeUtils::NumDisplayModeColors(DisplayMode());
   1.822 +	if (!TDisplayModeUtils::IsDisplayModeColor(DisplayMode()))
   1.823 +		{
   1.824 +		aGrays=aColors;
   1.825 +		aColors=0;
   1.826 +		}
   1.827 +	}
   1.828 +
   1.829 +#define MODE_TO_FLAG(x) 1<<(x-1)
   1.830 +#define ROTATION_TO_FLAG(x) 1<<x
   1.831 +const TUint allRotationsMask = ROTATION_TO_FLAG(CFbsBitGc::EGraphicsOrientationNormal)
   1.832 +						| ROTATION_TO_FLAG(CFbsBitGc::EGraphicsOrientationRotated90)
   1.833 +						| ROTATION_TO_FLAG(CFbsBitGc::EGraphicsOrientationRotated180)
   1.834 +						| ROTATION_TO_FLAG(CFbsBitGc::EGraphicsOrientationRotated270);
   1.835 +const TUint KRotation0_180Mask = ROTATION_TO_FLAG(CFbsBitGc::EGraphicsOrientationNormal)
   1.836 +						| ROTATION_TO_FLAG(CFbsBitGc::EGraphicsOrientationRotated180);
   1.837 +const TUint KRotation90_270Mask = ROTATION_TO_FLAG(CFbsBitGc::EGraphicsOrientationRotated90)
   1.838 +						| ROTATION_TO_FLAG(CFbsBitGc::EGraphicsOrientationRotated270);
   1.839 +TInt CScreen::ColorModesFlag()
   1.840 +	{
   1.841 +	return MODE_TO_FLAG(DisplayMode());
   1.842 +	}
   1.843 +
   1.844 +void CScreen::UpdateDsa()
   1.845 +	{
   1.846 +	if(iDsaDevice)
   1.847 +		{
   1.848 +		#if defined(__WINS__) && defined(_DEBUG)
   1.849 +			if (iDebugWin)
   1.850 +				iDebugWin->Refresh(iDsaDevice->SizeInPixels(), iDsaDevice->DisplayMode(), iDsaDevice->Bits());
   1.851 +		#endif
   1.852 +		
   1.853 +		iDsaDevice->Update();
   1.854 +		}
   1.855 +	}
   1.856 +
   1.857 +const CGraphicsDeviceMap& CScreen::DeviceMap() const
   1.858 +	{
   1.859 +	return *iDeviceMap;
   1.860 +	}
   1.861 +
   1.862 +const MWsScreenDevice& CScreen::ScreenDevice() const
   1.863 +	{
   1.864 +	return *iScreenDevice; 
   1.865 +	}
   1.866 +
   1.867 +void CScreen::SetPointerCursorArea(TInt aMode,const TRect& aRect)
   1.868 +	{
   1.869 +	(*iModes)[aMode]->iPointerCursorArea=aRect;
   1.870 +	(*iModes)[aMode]->iFlags |= EClientDefinedDigitiserArea;
   1.871 +	TWsPointer::SetPointerCursorPos(TWsPointer::PointerCursorPos());
   1.872 +	}
   1.873 +
   1.874 +CFbsBitGc::TGraphicsOrientation CScreen::Orientation() const
   1.875 +	{
   1.876 +  	WS_ASSERT_DEBUG(IsValidScreenSizeMode(iScreenSizeMode),EWsPanicInvalidScreenSizeMode);
   1.877 +	return (*iModes)[iScreenSizeMode]->iRotation;
   1.878 +	}
   1.879 +
   1.880 +TRect CScreen::DrawableArea() const
   1.881 +	{
   1.882 +	TRect drawRect=iScreenDevice->SizeInPixels();
   1.883 +	if (iDisplayMapping)
   1.884 +		{
   1.885 +		iDisplayMapping->MapCoordinates(EFullScreenSpace,drawRect,EApplicationSpace,drawRect);                   
   1.886 +		}
   1.887 +	return drawRect;
   1.888 +	}
   1.889 +
   1.890 +TClientPanic CScreen::SetModeRotation(TInt aMode,CFbsBitGc::TGraphicsOrientation aRotation)
   1.891 +	{
   1.892 +	if (!IsValidScreenSizeMode(aMode))
   1.893 +		return EWservPanicScreenModeNumber;
   1.894 +	TSizeMode& mode=*(*iModes)[aMode];
   1.895 +	if (!(ROTATION_TO_FLAG(aRotation)&mode.iAlternativeRotations))
   1.896 +		return EWservPanicRotation;
   1.897 +	CFbsBitGc::TGraphicsOrientation oldRotation=mode.iRotation;
   1.898 +	mode.iRotation=aRotation;
   1.899 +	CWsWindowGroup::NewOrientation(aMode,aRotation, iRootWindow);
   1.900 +	if (aMode==ScreenSizeMode())
   1.901 +		{
   1.902 +		if(iDisplayPolicy && iDisplayControl && (mode.iAlternativeRotations == allRotationsMask))
   1.903 +			{
   1.904 +			//square mode supports all 4 rotations. We'd better do a complete Setconfiguration
   1.905 +			//all parameters are recalculated for 90 degree rotation
   1.906 +			//The most important one is the offset, since we need to re-center the appmode and it's a policy behaviour
   1.907 +			TDisplayConfiguration config;
   1.908 +			iDisplayControl->GetConfiguration(config);
   1.909 +			//update rotation
   1.910 +			config.SetRotation((TDisplayConfiguration::TRotation)aRotation);
   1.911 +			SetConfiguration(config);
   1.912 +			}
   1.913 +		else if (!UpdateOrientation())
   1.914 +			{
   1.915 +			// Roll back earlier change
   1.916 +			mode.iRotation=oldRotation;
   1.917 +			CWsWindowGroup::NewOrientation(aMode, oldRotation, iRootWindow);
   1.918 +			}
   1.919 +		}
   1.920 +	return EWservNoPanic;
   1.921 +	}
   1.922 +
   1.923 +void CScreen::CycleDisplaySize()
   1.924 +	{
   1.925 +	TInt newMode = iScreenSizeMode;
   1.926 +	TSizeMode* sizeMode = NULL;
   1.927 +	do
   1.928 +		{
   1.929 +		newMode = (newMode+1)%iModes->Count();
   1.930 +		sizeMode = (*iModes)[newMode];
   1.931 +		}
   1.932 +	while (sizeMode==NULL);
   1.933 +	doSetScreenMode(newMode);
   1.934 +	}
   1.935 +
   1.936 +void CScreen::doSetScreenMode(TInt aMode,TBool aInsideStartup)
   1.937 +	{
   1.938 +  	WS_ASSERT_DEBUG(IsValidScreenSizeMode(aMode),EWsPanicInvalidScreenSizeMode);
   1.939 + 	TWindowServerEvent::NotifyDrawer(TWservCrEvent(TWservCrEvent::EScreenSizeModeAboutToChange, aMode));
   1.940 +	
   1.941 +	if (iDisplayControl && iDisplayPolicy)
   1.942 +		{
   1.943 +		TDisplayConfiguration config;
   1.944 +		TRect sizeModePosition;
   1.945 +		TInt error;
   1.946 +		TSizeMode& mode=*(*iModes)[aMode];
   1.947 +		config.SetRotation((TDisplayConfiguration::TRotation)mode.iRotation);
   1.948 +		//This will return suitable config when display is connected
   1.949 +		//and UI size equal to smallest appmode when disconnected
   1.950 +		error = iDisplayPolicy->GetSizeModeConfiguration(aMode,config,sizeModePosition);
   1.951 +		//set appmode in policy
   1.952 +		if (iDisplayMapping)
   1.953 +			{
   1.954 +			iDisplayMapping->SetSizeModeExtent(sizeModePosition,MWsDisplayMapping::KOffsetAll);
   1.955 +			}
   1.956 +		MWsScene::TSceneRotation oldRotation;
   1.957 +		TSize newUiSize;
   1.958 +		config.GetResolution(newUiSize);
   1.959 +		if (error == KErrNone)
   1.960 +			{
   1.961 +			oldRotation = iScene->SceneRotation();
   1.962 +			//The config info will always be set in policy. If display is connected, policy will have
   1.963 +			//correct composition, Ui and app res. otherwise Ui and appmode will be both set to smallest
   1.964 +			//app mode, composition will be set to zero
   1.965 +			if (iFlags&EHasDynamicSizeModes)
   1.966 +				{
   1.967 +				error = iFallbackMap->Resize(newUiSize);
   1.968 +				}
   1.969 +			if (error == KErrNone)
   1.970 +				{
   1.971 +				error = iDisplayControl->SetConfiguration(config);
   1.972 +				}
   1.973 +			}
   1.974 +		if (error == KErrNone)
   1.975 +			{
   1.976 +			UpdateDynamicScreenModes();
   1.977 +			AbortAllDirectDrawing(RDirectScreenAccess::ETerminateScreenMode);
   1.978 +
   1.979 +			if(iDsaDevice && iDsaDevice->GraphicsAccelerator())
   1.980 +				{
   1.981 +				iDsaDevice->ChangeScreenDevice(iDsaDevice); // orientation has changed, therefore we need to re-initialise the screen device's graphics accelerator
   1.982 +				}
   1.983 +
   1.984 +			iScreenSizeMode=aMode;
   1.985 +			//This could fail (to set orientation on the context, or to register the rotated DSA).
   1.986 +			//Previously, the update rotation was deferred, leaving the size mode out of step with the actual rotation
   1.987 +			//It also returns false if the orientation is "intentionally" not modified.
   1.988 +			(void) UpdateOrientation(&oldRotation);	
   1.989 +			
   1.990 +			//SetDigitiserAreas needs revisiting if/when we support dynamic resolutions
   1.991 +            //on a screen with touch input.
   1.992 +            //SetDigitiserAreas(newUiSize);
   1.993 +			
   1.994 +			CWsWindowGroup::SetScreenDeviceValidStates(this);
   1.995 +			
   1.996 +			if (!aInsideStartup)
   1.997 +				{
   1.998 +				iWindowElementSet->ResubmitAllElementExtents();
   1.999 +				//TODO jonas: we'd like to not have to clear at all... make the actual change to compositor etc lazily!
  1.1000 +				if(BlankScreenOnRotation())
  1.1001 +					{
  1.1002 +					iRootWindow->ClearDisplay();
  1.1003 +					}
  1.1004 +	
  1.1005 +				CWsTop::ClearAllRedrawStores();
  1.1006 +				DiscardAllSchedules();
  1.1007 +				iRootWindow->InvalidateWholeScreen();
  1.1008 +				}
  1.1009 +			}
  1.1010 +		}
  1.1011 +	else
  1.1012 +		{
  1.1013 +		if (iDisplayMapping)
  1.1014 +			{
  1.1015 +			TRect sizeModePosition;
  1.1016 +			TRAPD(err,sizeModePosition=TRect(OriginL(aMode),ScreenModeSizeInPixelsL(aMode)));
  1.1017 +			if (err==KErrNone)
  1.1018 +				{
  1.1019 +				iDisplayMapping->SetSizeModeExtent(sizeModePosition,MWsDisplayMapping::KOffsetAll);
  1.1020 +				}
  1.1021 +			}
  1.1022 +		if (!aInsideStartup && (*iModes)[aMode]->iOrigin != (*iModes)[iScreenSizeMode]->iOrigin)
  1.1023 +			{
  1.1024 +			iWindowElementSet->ResubmitAllElementExtents();
  1.1025 +			if ((*iModes)[aMode]->iRotation == (*iModes)[iScreenSizeMode]->iRotation)
  1.1026 +				{
  1.1027 +				//TODO jonas: we'd like to not have to clear at all... make the actual change to compositor etc lazily!
  1.1028 +				if(BlankScreenOnRotation())
  1.1029 +					{
  1.1030 +					iRootWindow->ClearDisplay();
  1.1031 +					}
  1.1032 +	
  1.1033 +				CWsTop::ClearAllRedrawStores();
  1.1034 +				DiscardAllSchedules();
  1.1035 +				iRootWindow->InvalidateWholeScreen();
  1.1036 +				}
  1.1037 +			}
  1.1038 +		iScreenSizeMode=aMode;
  1.1039 +		//This could fail (to set orientation on the context, or to register the rotated DSA).
  1.1040 +		//Previously, the update rotation was deferred, leaving the size mode out of step with the actual rotation
  1.1041 +		//It also returns false if the orientation is not modified.
  1.1042 +		(void)UpdateOrientation();
  1.1043 +		CWsWindowGroup::SetScreenDeviceValidStates(this);
  1.1044 +		}
  1.1045 +	TWindowServerEvent::SendScreenDeviceChangedEvents(this);
  1.1046 +	ResetFocus(NULL);
  1.1047 +	}
  1.1048 +
  1.1049 +void CScreen::CycleOrientation()
  1.1050 +	{
  1.1051 +  	WS_ASSERT_DEBUG(IsValidScreenSizeMode(iScreenSizeMode),EWsPanicInvalidScreenSizeMode);
  1.1052 +	TSizeMode& currentSizeMode=*(*iModes)[iScreenSizeMode];
  1.1053 +	TUint rotations=currentSizeMode.iAlternativeRotations;
  1.1054 +	TInt currentRotation=currentSizeMode.iRotation;
  1.1055 +	TInt rotation=currentRotation+1;
  1.1056 +	while (rotation!=currentRotation)
  1.1057 +		{
  1.1058 +		if (rotation>CFbsBitGc::EGraphicsOrientationRotated270)
  1.1059 +			rotation=CFbsBitGc::EGraphicsOrientationNormal;
  1.1060 +		if (ROTATION_TO_FLAG(rotation)&rotations)
  1.1061 +			break;
  1.1062 +		++rotation;
  1.1063 +		}
  1.1064 +	if (rotation==currentRotation)
  1.1065 +		{
  1.1066 +		if (rotation>CFbsBitGc::EGraphicsOrientationRotated90)
  1.1067 +			rotation-=2;
  1.1068 +		else
  1.1069 +			rotation+=2;
  1.1070 +		}
  1.1071 +	currentSizeMode.iRotation=REINTERPRET_CAST(CFbsBitGc::TGraphicsOrientation&,rotation);
  1.1072 +	CWsWindowGroup::NewOrientation(iScreenSizeMode,currentSizeMode.iRotation, iRootWindow);
  1.1073 +
  1.1074 +	if (!UpdateOrientation())
  1.1075 +		{
  1.1076 +		// Roll back earlier changes
  1.1077 +		currentSizeMode.iRotation=REINTERPRET_CAST(CFbsBitGc::TGraphicsOrientation&,currentRotation);
  1.1078 +		CWsWindowGroup::NewOrientation(iScreenSizeMode, currentSizeMode.iRotation, iRootWindow);
  1.1079 +		}
  1.1080 +	}
  1.1081 +
  1.1082 +/**
  1.1083 + * This method is called either when switching screen size mode, or when the 
  1.1084 + * orientation of the currently active screen size mode is changed.
  1.1085 + */
  1.1086 +TBool CScreen::UpdateOrientation(MWsScene::TSceneRotation* aOldRotation)
  1.1087 +	{
  1.1088 +	CFbsBitGc::TGraphicsOrientation gcOrientation = Orientation();
  1.1089 +
  1.1090 +	MWsScene::TSceneRotation oldRotation = aOldRotation? (*aOldRotation):(iScene->SceneRotation());
  1.1091 +	MWsScene::TSceneRotation newRotation = GcToScreen(gcOrientation);
  1.1092 +	TDeviceOrientation newDeviceOrientation = GcToDevice(gcOrientation);
  1.1093 +
  1.1094 +	// We have to disable the text cursor here while we are still in the
  1.1095 +	// same orientation or offset as we drew it.
  1.1096 +	RWsTextCursor* cursor = CWsTop::CurrentTextCursor();
  1.1097 +	if (cursor)
  1.1098 +		{
  1.1099 +		cursor->Disable();
  1.1100 +		}
  1.1101 +	
  1.1102 +// Some of this method has to be done when changing mode even if not changing rotation
  1.1103 +	TBool rotating=(oldRotation != newRotation);
  1.1104 +	if (rotating)
  1.1105 +		{
  1.1106 +	
  1.1107 +		// Set the new screen rotation and update the UI element extent
  1.1108 +		if (iScene->SetSceneRotation(newRotation) != KErrNone)
  1.1109 +			return EFalse;
  1.1110 +		// Set the new orientation for the DSA device and update the DSA surface
  1.1111 +		if(iDsaDevice)
  1.1112 +			{
  1.1113 +			iDsaDevice->SetDeviceOrientation(newDeviceOrientation);
  1.1114 +	
  1.1115 +			TSurfaceId newSurface;
  1.1116 +			iDsaDevice->GetSurface(newSurface);
  1.1117 +			TInt errRegister = iScene->RegisterSurface(newSurface);
  1.1118 +			WS_ASSERT_DEBUG(KErrNone == errRegister, EWsPanicDirectScreenAccess);
  1.1119 +			// This will remove all the DSA elements from the scene
  1.1120 +            AbortAllDirectDrawing(RDirectScreenAccess::ETerminateRotation);
  1.1121 +	
  1.1122 +			TInt errUnregister = iScene->UnregisterSurface(iDsaSurface);
  1.1123 +			WS_ASSERT_DEBUG(KErrNone == errUnregister, EWsPanicDirectScreenAccess);
  1.1124 +			iDsaSurface = newSurface;
  1.1125 +			}
  1.1126 +		
  1.1127 +		//updaterotation should not fail after this point (no cleanup)
  1.1128 +			
  1.1129 +        //update the last set config with the new rotation change so we don't incorrectly
  1.1130 +        //change the layer extents
  1.1131 +        if (iDisplayControl)
  1.1132 +            {
  1.1133 +            TDisplayConfiguration config;
  1.1134 +            config.SetRotation(static_cast<TDisplayConfiguration::TRotation>(newRotation));           
  1.1135 +            iConfigChangeNotifier->UpdateLastSetConfiguration(config);
  1.1136 +            }		
  1.1137 +		
  1.1138 +		TWservCrEvent crEvent(TWservCrEvent::EDeviceOrientationChanged,iScreenNumber,&gcOrientation);
  1.1139 +		TWindowServerEvent::NotifyDrawer(crEvent);
  1.1140 +		
  1.1141 +		if(iDsaDevice && iDsaDevice->GraphicsAccelerator())
  1.1142 +			{
  1.1143 +			iDsaDevice->ChangeScreenDevice(iDsaDevice); // orientation has changed, therefore we need to re-initialise the screen device's graphics accelerator
  1.1144 +			}
  1.1145 +		
  1.1146 +		}
  1.1147 +	
  1.1148 +	iRootWindow->AdjustCoordsDueToRotation();
  1.1149 +	if (rotating)
  1.1150 +		{
  1.1151 +		if(BlankScreenOnRotation())
  1.1152 +			{
  1.1153 +			iRootWindow->ClearDisplay();
  1.1154 +			}
  1.1155 +		
  1.1156 +		CWsTop::ClearAllRedrawStores();	
  1.1157 +		DiscardAllSchedules();
  1.1158 +		iRootWindow->InvalidateWholeScreen();
  1.1159 +		}
  1.1160 +	return ETrue;
  1.1161 +	}
  1.1162 +
  1.1163 +TPoint CScreen::PhysicalToLogical(TPoint aPhysicalPt)
  1.1164 +	{
  1.1165 +	const TSizeMode& mode=ScreenSizeModeData();
  1.1166 +	TPoint logicalPt;
  1.1167 +	if(!iDisplayMapping)
  1.1168 +		{
  1.1169 +		//old behaviour
  1.1170 +		logicalPt=aPhysicalPt-mode.iOrigin;
  1.1171 +		if (mode.iScreenScale.iWidth!=1)
  1.1172 +			logicalPt.iX=(logicalPt.iX>=0 ? logicalPt.iX/mode.iScreenScale.iWidth : (logicalPt.iX-(mode.iScreenScale.iWidth-1))/mode.iScreenScale.iWidth);
  1.1173 +		if (mode.iScreenScale.iHeight!=1)
  1.1174 +			logicalPt.iY=(logicalPt.iY>=0 ? logicalPt.iY/mode.iScreenScale.iHeight : (logicalPt.iY-(mode.iScreenScale.iHeight-1))/mode.iScreenScale.iHeight);
  1.1175 +		}
  1.1176 +	else
  1.1177 +		{
  1.1178 +		//rect with dummy size for coordinates mapping purpose
  1.1179 +		TRect rectInComp(aPhysicalPt, TSize(1,1));
  1.1180 +		TRect rectInApp;
  1.1181 +		iDisplayMapping->MapCoordinates(ECompositionSpace, rectInComp, EApplicationSpace,rectInApp);
  1.1182 +		logicalPt = rectInApp.iTl;
  1.1183 +		}
  1.1184 +	
  1.1185 +	return logicalPt;
  1.1186 +	}
  1.1187 +
  1.1188 +void CScreen::LoadScreenSizesL(TSize aScreenSize)
  1.1189 +	{
  1.1190 +	_LIT(KWSERVNumScrSizeMode, "NUMSCREENMODES");
  1.1191 +	TBool allowScrGap=WsIniFile->FindVar(iScreenNumber, KWSERVNumScrSizeMode, iNumScreenSizeModes);
  1.1192 +	iModes=new(ELeave) RPointerArray<TInternalSizeMode>(1);
  1.1193 +	WS_ASSERT_DEBUG(!allowScrGap || (allowScrGap && iNumScreenSizeModes>0), EWsPanicInvalidScreenSizeMode);
  1.1194 +	TInt screenNum=0;
  1.1195 +	FOREVER
  1.1196 +		{
  1.1197 +		++screenNum;
  1.1198 +		TBuf<32> varNameWidth;
  1.1199 +		TBuf<32> varNameHeight;
  1.1200 +		_LIT(KWSERVScreenWidthPattern,"SCR_WIDTH%d");
  1.1201 +		varNameWidth.Format(KWSERVScreenWidthPattern,screenNum);
  1.1202 +		_LIT(KWSERVScreenHeightPattern,"SCR_HEIGHT%d");
  1.1203 +		varNameHeight.Format(KWSERVScreenHeightPattern,screenNum);
  1.1204 +		TSize screenSize;
  1.1205 +		if (!WsIniFile->FindVar(iScreenNumber, varNameWidth, screenSize.iWidth) ||
  1.1206 +			!WsIniFile->FindVar(iScreenNumber, varNameHeight, screenSize.iHeight))
  1.1207 +			{
  1.1208 +			if (allowScrGap && screenNum<=iNumScreenSizeModes)
  1.1209 +				{
  1.1210 +				iModes->AppendL(NULL);
  1.1211 +				continue;
  1.1212 +				}
  1.1213 +			else
  1.1214 +				break;
  1.1215 +			}
  1.1216 +		TInt flags=0;
  1.1217 +		if (screenSize.iWidth==0 && screenSize.iHeight==0)
  1.1218 +			{
  1.1219 +			screenSize=aScreenSize;
  1.1220 +			flags|=EHalDefault;
  1.1221 +			}
  1.1222 +		if (screenSize.iWidth==-1 && screenSize.iHeight==-1)
  1.1223 +			{
  1.1224 +			screenSize=aScreenSize;
  1.1225 +			flags|=EDynamic;
  1.1226 +			iFlags|=EHasDynamicSizeModes;
  1.1227 +			}
  1.1228 +		TInternalSizeMode* newSizeMode=new(ELeave) TInternalSizeMode(screenSize);
  1.1229 +		newSizeMode->iFlags|=flags;
  1.1230 +		CleanupStack::PushL(newSizeMode);
  1.1231 +		iModes->AppendL(newSizeMode);
  1.1232 +		CleanupStack::Pop(newSizeMode);
  1.1233 +		++iNumSupportedScreenSizeModes;
  1.1234 +		}
  1.1235 +	// If sparse index is enabled and no screen size mode defined, all iModes entries will be NULL
  1.1236 +	// Otherwise iModes will be empty
  1.1237 +	if (iModes->Count()==0 || iNumSupportedScreenSizeModes==0)
  1.1238 +		{
  1.1239 +		TInternalSizeMode* defaultSizeMode=new(ELeave) TInternalSizeMode(aScreenSize);
  1.1240 +		defaultSizeMode->iFlags|=EHalDefault;
  1.1241 +		if (iModes->Count()>0)
  1.1242 +			(*iModes)[0]=defaultSizeMode;
  1.1243 +		else
  1.1244 +			{
  1.1245 +			CleanupStack::PushL(defaultSizeMode);
  1.1246 +			iModes->AppendL(defaultSizeMode);
  1.1247 +			CleanupStack::Pop(defaultSizeMode);
  1.1248 +			}
  1.1249 +		++iNumSupportedScreenSizeModes;
  1.1250 +		}
  1.1251 +	if (!allowScrGap)
  1.1252 +		iNumScreenSizeModes=iNumSupportedScreenSizeModes;
  1.1253 +	}
  1.1254 +
  1.1255 +void CScreen::LoadScreenRotationProperties(TInternalSizeMode& aMode, const TInt aModeIndex)
  1.1256 +	{
  1.1257 +	TBuf<32> varRotation;
  1.1258 +	_LIT(KWSERVScreenRotationPattern,"SCR_ROTATION%d");
  1.1259 +	varRotation.Format(KWSERVScreenRotationPattern,aModeIndex+1);		
  1.1260 +	TInt rotation=CFbsBitGc::EGraphicsOrientationNormal;
  1.1261 +	TUint allRotations=0;
  1.1262 +	TPtrC rotList(NULL,0);
  1.1263 +	if (WsIniFile->FindVar( iScreenNumber, varRotation,rotList))
  1.1264 +		{
  1.1265 +		TLex lex(rotList);
  1.1266 +		TBool foundOne=EFalse;
  1.1267 +		TInt rot;
  1.1268 +
  1.1269 +		while (!lex.Eos())
  1.1270 +			{
  1.1271 +			if (!FindNextValue(lex, rot))
  1.1272 +				{
  1.1273 +				break;
  1.1274 +				}
  1.1275 +			if (rot<0 || rot>360)
  1.1276 +				{
  1.1277 +				continue;
  1.1278 +				}
  1.1279 +			if (rot>4)
  1.1280 +				{
  1.1281 +				rot/=90;
  1.1282 +				}
  1.1283 +			if (!foundOne)
  1.1284 +				{
  1.1285 +				rotation=rot;
  1.1286 +				foundOne=ETrue;
  1.1287 +				}
  1.1288 +			if (rot<=CFbsBitGc::EGraphicsOrientationRotated270)
  1.1289 +				{
  1.1290 +				allRotations|=ROTATION_TO_FLAG(rot);
  1.1291 +				}
  1.1292 +			}
  1.1293 +		}
  1.1294 +	if (allRotations==0)
  1.1295 +		allRotations=ROTATION_TO_FLAG(rotation);
  1.1296 +	const TInt KAllRotationsMask = 0xF;	//Used to keep the old behaviour
  1.1297 +	WS_ASSERT_ALWAYS((ROTATION_TO_FLAG(rotation)&KAllRotationsMask)>0, EWsPanicFailedToInitialise);
  1.1298 +	aMode.iRotation=reinterpret_cast<CFbsBitGc::TGraphicsOrientation&>(rotation);
  1.1299 +	aMode.iAlternativeRotations=allRotations&KAllRotationsMask;
  1.1300 +	}
  1.1301 +
  1.1302 +void CScreen::LoadScreenTwipsProperties(TInternalSizeMode& aMode, const TInt aModeIndex)
  1.1303 +	{
  1.1304 +	TBuf<32> varNameWidth;
  1.1305 +	_LIT(KWSERVScreenTwipWidthPattern,"SCR_TWIP_WIDTH%d");
  1.1306 +	varNameWidth.Format(KWSERVScreenTwipWidthPattern,aModeIndex+1);
  1.1307 +	TBuf<32> varNameHeight;
  1.1308 +	_LIT(KWSERVScreenTwipHeightPattern,"SCR_TWIP_HEIGHT%d");
  1.1309 +	varNameHeight.Format(KWSERVScreenTwipHeightPattern,aModeIndex+1);
  1.1310 +
  1.1311 +	TSize twipsSize;
  1.1312 +	TBool widthFound = WsIniFile->FindVar(iScreenNumber,varNameWidth,twipsSize.iWidth);
  1.1313 +	TBool heightFound = WsIniFile->FindVar(iScreenNumber,varNameHeight,twipsSize.iHeight);	
  1.1314 +	
  1.1315 +	// if either of the width or height wsini reads has failed we need to generate default values
  1.1316 +	switch(aMode.iRotation)
  1.1317 +		{
  1.1318 +		// CFbsBitGc::TGraphicsOrientation
  1.1319 +		case CFbsBitGc::EGraphicsOrientationRotated90:	// deliberate drop-through
  1.1320 +		case CFbsBitGc::EGraphicsOrientationRotated270:
  1.1321 +			{
  1.1322 +			// CFbsScreenDevice knows nothing about rotation, so we can't use it's PixelsTo Twips methods
  1.1323 +			// So swap the axis here to use the correct twips per pixel ratio
  1.1324 +			if (!widthFound)
  1.1325 +				twipsSize.iWidth = DeviceMap().VerticalPixelsToTwips(aMode.iScreenSize.iWidth);
  1.1326 +			if (!heightFound)
  1.1327 +				twipsSize.iHeight = DeviceMap().HorizontalPixelsToTwips(aMode.iScreenSize.iHeight);	
  1.1328 +			break;
  1.1329 +			}
  1.1330 +		case CFbsBitGc::EGraphicsOrientationNormal:		// deliberate drop-through
  1.1331 +		case CFbsBitGc::EGraphicsOrientationRotated180:
  1.1332 +			if (!widthFound)
  1.1333 +				twipsSize.iWidth = DeviceMap().HorizontalPixelsToTwips(aMode.iScreenSize.iWidth);
  1.1334 +			if (!heightFound)
  1.1335 +				twipsSize.iHeight = DeviceMap().VerticalPixelsToTwips(aMode.iScreenSize.iHeight);
  1.1336 +			break;
  1.1337 +		default:
  1.1338 +			RDebug::Print(_L("** CScreen::LoadScreenTwipsProperties Panic"));
  1.1339 +			WS_PANIC_ALWAYS(EWsPanicFailedToInitialise);
  1.1340 +			break;			
  1.1341 +		}
  1.1342 +	if (widthFound&&heightFound)
  1.1343 +		{
  1.1344 +		aMode.iFlags|=this->ETwipsSpecified;
  1.1345 +		}
  1.1346 +	aMode.iScreenTwipsSize=twipsSize;
  1.1347 +	}
  1.1348 +
  1.1349 +
  1.1350 +void CScreen::LoadScreenSizeProperties(TDisplayMode aDefaultDisplayMode)
  1.1351 +	{
  1.1352 +	for(TInt sizeLoop=0;sizeLoop<iModes->Count();sizeLoop++)
  1.1353 +		{
  1.1354 +		TInternalSizeMode* modePtr=(*iModes)[sizeLoop];
  1.1355 +		if (!modePtr)
  1.1356 +			continue;
  1.1357 +		TInternalSizeMode& mode=*modePtr;
  1.1358 +		TBuf<32> varDisplayMode;
  1.1359 +		_LIT(KWSERVScreenDisplayModePattern,"SCR_WINDOWMODE%d");
  1.1360 +		
  1.1361 +		varDisplayMode.Format(KWSERVScreenDisplayModePattern,sizeLoop+1);
  1.1362 +		mode.iScreenScale.iWidth=1;
  1.1363 +		mode.iScreenScale.iHeight=1;
  1.1364 +
  1.1365 +		TBuf<32> varLeft;
  1.1366 +		TBuf<32> varTop;
  1.1367 +		_LIT(KWSERVScreenLeftPattern,"SCR_LEFT%d");
  1.1368 +		_LIT(KWSERVScreenTopPattern,"SCR_TOP%d");
  1.1369 +		varLeft.Format(KWSERVScreenLeftPattern,sizeLoop+1);
  1.1370 +		varTop.Format(KWSERVScreenTopPattern,sizeLoop+1);
  1.1371 +		if (!WsIniFile->FindVar( iScreenNumber, varLeft,mode.iOrigin.iX))
  1.1372 +			mode.iOrigin.iX=0;
  1.1373 +		if (!WsIniFile->FindVar( iScreenNumber, varTop,mode.iOrigin.iY))
  1.1374 +			mode.iOrigin.iY=0;
  1.1375 +			
  1.1376 +		TPtrC displayModeName(NULL,0);
  1.1377 +		mode.iDefaultDisplayMode = aDefaultDisplayMode;
  1.1378 +		// must know rotation before parsing twips
  1.1379 +		LoadScreenRotationProperties(mode, sizeLoop);
  1.1380 +		LoadScreenTwipsProperties(mode, sizeLoop);
  1.1381 +		
  1.1382 +		
  1.1383 +		if(mode.iScreenSize.iWidth == mode.iScreenSize.iHeight && mode.iAlternativeRotations == allRotationsMask)
  1.1384 +			{
  1.1385 +			//square appmode with all four rotations allowed must have square twipsize
  1.1386 +			if((mode.iFlags&ETwipsSpecified) && mode.iScreenTwipsSize.iWidth != mode.iScreenTwipsSize.iHeight)
  1.1387 +				{
  1.1388 +				RDebug::Print(_L("**Panic: Square appmode with all four rotations must have square twip size"));
  1.1389 +				WS_PANIC_ALWAYS(EWsPanicFailedToInitialise);
  1.1390 +				}
  1.1391 +			//square appmode with all four rotations allowed must have square offset
  1.1392 +			if(mode.iOrigin.iX != mode.iOrigin.iY)
  1.1393 +				{
  1.1394 +				RDebug::Print(_L("**Panic: Square appmode with all four rotations must have square offset"));
  1.1395 +				WS_PANIC_ALWAYS(EWsPanicFailedToInitialise);
  1.1396 +				}
  1.1397 +			}
  1.1398 +		else
  1.1399 +			{
  1.1400 +			//Everything else is treated as rectangle appmode. Square appmode not supporting all 4 rotations is considered
  1.1401 +			//as rectangle appmode as well. Rectangle appmode suports 2 rotations at most (0 and 180, or 90 and 270)
  1.1402 +			//first rotation of the appmode is taken to apply the corresponding rotation mask
  1.1403 +			if(!((mode.iAlternativeRotations&KRotation0_180Mask) == mode.iAlternativeRotations
  1.1404 +					|| (mode.iAlternativeRotations&KRotation90_270Mask) == mode.iAlternativeRotations))
  1.1405 +				{
  1.1406 +				RDebug::Print(_L("**Panic_DEBUG: non square appmode can only define (0,180) or (90,270) rotations"));
  1.1407 +				WS_PANIC_DEBUG(EWsPanicFailedToInitialise);
  1.1408 +				//in relase build, no panic, just correct the rotations set
  1.1409 +
  1.1410 +				}
  1.1411 +			//correct the rotations set
  1.1412 +			mode.iAlternativeRotations &= ((ROTATION_TO_FLAG(mode.iRotation) & KRotation0_180Mask)? KRotation0_180Mask:
  1.1413 +												KRotation90_270Mask);
  1.1414 +			}
  1.1415 +			
  1.1416 +		}
  1.1417 +//
  1.1418 +	TInt intForFindVar=0;
  1.1419 +	_LIT(KWSERVIniFileVarSizeMode,"SIZE_MODE");
  1.1420 +	WsIniFile->FindVar( iScreenNumber, KWSERVIniFileVarSizeMode,intForFindVar);
  1.1421 +	iSizeEnforcementMode=(TScreenModeEnforcement)intForFindVar;
  1.1422 +	}
  1.1423 +
  1.1424 +void CScreen::SetDigitiserAreas(const TSize& aUiSize)
  1.1425 +	{  //aUiSize should be the unrotated current ui size
  1.1426 +	//SetDigitiserAreas needs revisiting if/when we support dynamic resolutions on a screen 
  1.1427 +    //with touch input. It is not known how digitiser coordinates will be represented if the 
  1.1428 +    //physical display resolution changes. Currently digitisers are only supported on screen 0, 
  1.1429 +    //and dynamic resolution only applies to higher screen numbers on real hardware.
  1.1430 +	for(TInt sizeLoop=0;sizeLoop<iModes->Count();sizeLoop++)
  1.1431 +		{
  1.1432 +		TInternalSizeMode* modePtr=(*iModes)[sizeLoop];
  1.1433 +		if (!modePtr)
  1.1434 +			continue;
  1.1435 +		TInternalSizeMode& mode=*modePtr;
  1.1436 +		if(mode.iFlags & EClientDefinedDigitiserArea)
  1.1437 +			{
  1.1438 +			//if it's client set, keep it unchanged.
  1.1439 +			continue;
  1.1440 +			}
  1.1441 +		switch (mode.iRotation)
  1.1442 +			{
  1.1443 +			case CFbsBitGc::EGraphicsOrientationNormal:
  1.1444 +				mode.iPointerCursorArea=iDigitiserArea;
  1.1445 +				continue;
  1.1446 +			case CFbsBitGc::EGraphicsOrientationRotated90:
  1.1447 +				mode.iPointerCursorArea.SetRect(iDigitiserArea.iTl.iY,aUiSize.iWidth-iDigitiserArea.iBr.iX,
  1.1448 +																iDigitiserArea.iBr.iY,aUiSize.iWidth-iDigitiserArea.iTl.iX);
  1.1449 +				break;
  1.1450 +			case CFbsBitGc::EGraphicsOrientationRotated180:
  1.1451 +				mode.iPointerCursorArea.SetRect(-(iDigitiserArea.iBr-aUiSize),-(iDigitiserArea.iTl-aUiSize));
  1.1452 +				break;
  1.1453 +			case CFbsBitGc::EGraphicsOrientationRotated270:
  1.1454 +				mode.iPointerCursorArea.SetRect(aUiSize.iHeight-iDigitiserArea.iBr.iY,iDigitiserArea.iTl.iX,
  1.1455 +				        aUiSize.iHeight-iDigitiserArea.iTl.iY,iDigitiserArea.iBr.iX);
  1.1456 +				break;
  1.1457 +			default:
  1.1458 +			    WS_PANIC_ALWAYS(EWsPanicInvalidRotation);
  1.1459 +			}
  1.1460 +		}
  1.1461 +	}
  1.1462 +
  1.1463 +void CScreen::GetScreenSizeAndRotation(TPixelsTwipsAndRotation &aSar, TInt aScreenMode)
  1.1464 +	{
  1.1465 +	TSizeMode& mode=*(*iModes)[aScreenMode];
  1.1466 +	aSar.iRotation=mode.iRotation;
  1.1467 +	aSar.iPixelSize=mode.iScreenSize;
  1.1468 +	aSar.iTwipsSize=mode.iScreenTwipsSize;
  1.1469 +	if (aSar.iTwipsSize.iWidth==0)
  1.1470 +		{
  1.1471 +		aSar.iTwipsSize.iWidth  = iDeviceMap->HorizontalPixelsToTwips(aSar.iPixelSize.iWidth);
  1.1472 +		aSar.iTwipsSize.iHeight = iDeviceMap->VerticalPixelsToTwips(aSar.iPixelSize.iHeight);
  1.1473 +		}
  1.1474 +	}
  1.1475 +
  1.1476 +void CScreen::GetScreenSizeAndRotation(TPixelsAndRotation &aSar, TInt aScreenMode)
  1.1477 +	{
  1.1478 +	TSizeMode& mode=*(*iModes)[aScreenMode];
  1.1479 +	aSar.iRotation=mode.iRotation;
  1.1480 +	aSar.iPixelSize=mode.iScreenSize;
  1.1481 +	}
  1.1482 +
  1.1483 +TBool CScreen::SetScreenModeEnforcement(TInt aMode)
  1.1484 +	{
  1.1485 +	if (aMode<0 || aMode>ESizeEnforcementPixelsTwipsAndRotation)
  1.1486 +		return EFalse;
  1.1487 +	TScreenModeEnforcement newMode=(TScreenModeEnforcement)aMode;
  1.1488 +	if (newMode!=iSizeEnforcementMode)
  1.1489 +		{
  1.1490 +		iSizeEnforcementMode=newMode;
  1.1491 +		CWsWindowGroup::SetScreenDeviceValidStates(this);
  1.1492 +		ResetFocus(NULL);
  1.1493 +		}
  1.1494 +	return ETrue;
  1.1495 +	}
  1.1496 +
  1.1497 +void CScreen::IncContrast()
  1.1498 +	{
  1.1499 +	TInt contrast;
  1.1500 +	if (iMaxContrast<0)			//If failed to get it sofar get it again
  1.1501 +		TWindowServerEvent::ProcessErrorMessages(TWsErrorMessage::EContrast, HAL::Get(iScreenNumber,HALData::EDisplayContrastMax,iMaxContrast));
  1.1502 +	if (TWindowServerEvent::ProcessErrorMessages(TWsErrorMessage::EContrast, HAL::Get(iScreenNumber,HALData::EDisplayContrast,contrast)))
  1.1503 +		return;
  1.1504 +	if (contrast==iMaxContrast)
  1.1505 +		contrast=-1;
  1.1506 +	TWindowServerEvent::ProcessErrorMessages(TWsErrorMessage::EContrast, HAL::Set(iScreenNumber,HALData::EDisplayContrast,++contrast));
  1.1507 +	}
  1.1508 +
  1.1509 +void CScreen::DecContrast()
  1.1510 +	{
  1.1511 +	TInt contrast;
  1.1512 +	if (TWindowServerEvent::ProcessErrorMessages(TWsErrorMessage::EContrast, HAL::Get(iScreenNumber,HALData::EDisplayContrast,contrast)))
  1.1513 +		return;
  1.1514 +	if (contrast==0)
  1.1515 +		{
  1.1516 +		if (iMaxContrast<0 && TWindowServerEvent::ProcessErrorMessages(TWsErrorMessage::EContrast,
  1.1517 +															HAL::Get(iScreenNumber,HALData::EDisplayContrastMax,iMaxContrast)))
  1.1518 +			return;
  1.1519 +		contrast=iMaxContrast+1;
  1.1520 +		}
  1.1521 +	TWindowServerEvent::ProcessErrorMessages(TWsErrorMessage::EContrast, HAL::Set(iScreenNumber,HALData::EDisplayContrast,--contrast));
  1.1522 +	}
  1.1523 +
  1.1524 +void CScreen::IncBrightness()
  1.1525 +	{
  1.1526 +	TInt brightness;
  1.1527 +	if (iMaxBrightness<0)			//If failed to get it sofar get it again
  1.1528 +		TWindowServerEvent::ProcessErrorMessages(TWsErrorMessage::EBackLight, HAL::Get(iScreenNumber,HALData::EDisplayBrightnessMax,iMaxBrightness));
  1.1529 +	if (TWindowServerEvent::ProcessErrorMessages(TWsErrorMessage::EBackLight, HAL::Get(iScreenNumber,HALData::EDisplayBrightness,brightness)))
  1.1530 +		return;
  1.1531 +	if (brightness==iMaxBrightness)
  1.1532 +		brightness=-1;
  1.1533 +	TWindowServerEvent::ProcessErrorMessages(TWsErrorMessage::EBackLight, HAL::Set(iScreenNumber,HALData::EDisplayBrightness,++brightness));
  1.1534 +	}
  1.1535 +
  1.1536 +void CScreen::DecBrightness()
  1.1537 +	{
  1.1538 +	TInt brightness;
  1.1539 +	if (TWindowServerEvent::ProcessErrorMessages(TWsErrorMessage::EBackLight, HAL::Get(iScreenNumber,HALData::EDisplayBrightness,brightness)))
  1.1540 +		return;
  1.1541 +	if (brightness==0)
  1.1542 +		{
  1.1543 +		if (iMaxBrightness<0 && TWindowServerEvent::ProcessErrorMessages(TWsErrorMessage::EBackLight,
  1.1544 +													HAL::Get(iScreenNumber,HALData::EDisplayBrightnessMax,iMaxBrightness)))
  1.1545 +			return;
  1.1546 +		brightness=iMaxBrightness+1;
  1.1547 +		}
  1.1548 +	TWindowServerEvent::ProcessErrorMessages(TWsErrorMessage::EBackLight, HAL::Set(iScreenNumber,HALData::EDisplayBrightness,--brightness));
  1.1549 +	}
  1.1550 +TInt CScreen::GetScreenSizeModeList(RArray<TInt>& aList) const
  1.1551 +	{
  1.1552 +	aList.Reset();
  1.1553 +	TInt numModes=iNumScreenSizeModes;
  1.1554 +	TInt err=aList.Reserve(numModes);
  1.1555 +	if (err!=KErrNone)
  1.1556 +		return err;
  1.1557 +	TInt index;
  1.1558 +	for (index=0; index<numModes; ++index)
  1.1559 +		{
  1.1560 +		TSizeMode* modePtr=(*iModes)[index];
  1.1561 +		if (modePtr)
  1.1562 +			aList.Append(index);	//Can't fail due to reserve
  1.1563 +		}
  1.1564 +	TInt count=aList.Count();
  1.1565 +	return count;
  1.1566 +	}
  1.1567 +
  1.1568 +TInt CScreen::GetScreenSizeModeListL()
  1.1569 +	{
  1.1570 +	RArray<TInt> list;
  1.1571 +	CleanupClosePushL(list);
  1.1572 +	TInt count=GetScreenSizeModeList(list);
  1.1573 +		User::LeaveIfError(count);
  1.1574 +	CWsClient::ReplyBuf(&list[0], count*sizeof(TInt));
  1.1575 +	CleanupStack::PopAndDestroy(&list);
  1.1576 +	return count;
  1.1577 +	}
  1.1578 +
  1.1579 +void CScreen::SetInitialScreenSizeModeAndRotation()
  1.1580 +	{	//Set first app mode that supports current supported rotations if available
  1.1581 +	TInt index;
  1.1582 +	TInt firstMode = -1;
  1.1583 +	TInt bestMode = -1;
  1.1584 +	// Since all screen rotation modes are supported.
  1.1585 +	TBitFlags32 rotationFlags = CFbsBitGc::EGraphicsOrientationNormal|CFbsBitGc::EGraphicsOrientationRotated90|CFbsBitGc::EGraphicsOrientationRotated180|CFbsBitGc::EGraphicsOrientationRotated270;
  1.1586 +	for (index=0; index<iModes->Count(); ++index)
  1.1587 +		{
  1.1588 +		TSizeMode* modePtr=(*iModes)[index];
  1.1589 +		if (modePtr)
  1.1590 +			{
  1.1591 +			if (firstMode == -1)
  1.1592 +				{
  1.1593 +				firstMode = index;
  1.1594 +				}
  1.1595 +			if (rotationFlags.IsSet((TInt)modePtr->iRotation))
  1.1596 +				{
  1.1597 +				bestMode = index;
  1.1598 +				break;
  1.1599 +				}
  1.1600 +			}
  1.1601 +		}
  1.1602 +
  1.1603 +	if (bestMode != -1)	//found a mode that supports current supported rotations
  1.1604 +		{
  1.1605 +		iScreenSizeMode = bestMode;
  1.1606 +		}
  1.1607 +	else
  1.1608 +		{
  1.1609 +		if (firstMode != -1)	//could only find a mode that doesnt support current supported rotations
  1.1610 +			{
  1.1611 +			iScreenSizeMode = firstMode;
  1.1612 +			}
  1.1613 +		else
  1.1614 +			{
  1.1615 +			return;	//couldn't find a mode at all
  1.1616 +			}
  1.1617 +		}
  1.1618 +	if(iDisplayPolicy)
  1.1619 +		{
  1.1620 +		iDisplayPolicy->SetLastAppMode(iScreenSizeMode);
  1.1621 +		}
  1.1622 +
  1.1623 +    SetDigitiserAreas(iScreenDevice->SizeInPixels()); //unrotated size in pixels
  1.1624 +    
  1.1625 +    // Here we are mixing CFbsBitGc::TGraphicsOrientation with MWsScene::TSceneRotation
  1.1626 +    // As they both have same values it is fine for now
  1.1627 +    iScene->SetSceneRotation(GcToScreen(ScreenSizeModeData().iRotation)); //set rotation
  1.1628 +	}
  1.1629 +
  1.1630 +
  1.1631 +TDisplayMode CScreen::FirstDefaultDisplayMode() const
  1.1632 +	{
  1.1633 +	TInt mode=-1;
  1.1634 +	while ((*iModes)[++mode]==NULL)
  1.1635 +		{
  1.1636 +		WS_ASSERT_DEBUG(mode<iModes->Count()-1,EWsPanicInvalidScreenSizeMode);
  1.1637 +		}
  1.1638 +	return((*iModes)[mode]->iDefaultDisplayMode);
  1.1639 +	}
  1.1640 +
  1.1641 +void CScreen::AddRedrawRegion(const TRegion& aRegion, TBool aSchedule, TRedrawDepth aDepth)
  1.1642 +	{
  1.1643 +	iRedraw->AddRedrawRegion(aRegion, aSchedule, aDepth);
  1.1644 +	}
  1.1645 +
  1.1646 +void CScreen::ScheduleRender(const TTimeIntervalMicroSeconds& aFromNow)
  1.1647 +	{
  1.1648 +	iRedraw->ScheduleRender(aFromNow);
  1.1649 +	}
  1.1650 +
  1.1651 +void CScreen::DoRedrawNow()
  1.1652 +	{
  1.1653 +	iRedraw->DoRedrawNow();
  1.1654 +	}
  1.1655 +
  1.1656 +// See CScreenRedraw::IsUpdatePending() for important notes on usage.
  1.1657 +void CScreen::RedrawNowIfPending()
  1.1658 +	{
  1.1659 +	if(iRedraw->IsUpdatePending())
  1.1660 +		DoRedrawNow();
  1.1661 +	}
  1.1662 +
  1.1663 +TBool CScreen::IsQuickFadeScheduled( CWsWindow* aWin ) const
  1.1664 +	{
  1.1665 +	return iRedraw->IsQuickFadeScheduled( aWin );
  1.1666 +	}
  1.1667 +
  1.1668 +void CScreen::RemoveFromQuickFadeList( CWsWindow* aWin )
  1.1669 +	{
  1.1670 +	iRedraw->RemoveFromQuickFadeList( aWin );
  1.1671 +	}
  1.1672 +
  1.1673 +void CScreen::AcceptFadeRequest( CWsWindow* aWin, TBool aIsFaded )
  1.1674 +	{
  1.1675 +	iRedraw->AcceptFadeRequest( aWin, aIsFaded );
  1.1676 +	}
  1.1677 +
  1.1678 +// implementing MWsScreen
  1.1679 +
  1.1680 +const TTime& CScreen::Now() const
  1.1681 +	{
  1.1682 +	return iRedraw->Now();
  1.1683 +	}
  1.1684 +
  1.1685 +void CScreen::ScheduleAnimation(TAnimType aType, const TRect& aRect,const TTimeIntervalMicroSeconds& aFromNow,const TTimeIntervalMicroSeconds& aFreq,const TTimeIntervalMicroSeconds& aStop, CWsWindow* aWindow)
  1.1686 +	{
  1.1687 +	iRedraw->ScheduleAnimation(aType, aRect,aFromNow,aFreq,aStop, aWindow);
  1.1688 +	}
  1.1689 +
  1.1690 +TBool CScreen::IsScheduled(TAnimType aType, const TRect& aRect, CWsWindow* aWindow) const
  1.1691 +	{
  1.1692 +	return iRedraw->IsScheduled(aType, aRect, aWindow);
  1.1693 +	}
  1.1694 +
  1.1695 +void CScreen::OnAnimation(TRequestStatus* aFinished)
  1.1696 +	{
  1.1697 +	iRedraw->OnAnimation(aFinished);
  1.1698 +	}
  1.1699 +	
  1.1700 +void CScreen::Redraw()
  1.1701 +	{
  1.1702 +	STACK_REGION bounds;
  1.1703 +	bounds.AddRect(DrawableArea());
  1.1704 +	AddRedrawRegion(bounds);
  1.1705 +	bounds.Close();
  1.1706 +	}
  1.1707 +
  1.1708 +TBool CScreen::RedrawInvalid(const TArray<TGraphicDrawerId>& aInvalid)
  1.1709 +	{
  1.1710 +	TBool wasDirty = EFalse;
  1.1711 +	STACK_REGION bounds;
  1.1712 +	bounds.AddRect(DrawableArea());
  1.1713 +	STACK_REGION dirty;
  1.1714 +	TWalkWindowTreeCalcInvalidGraphics calc(&bounds,dirty,aInvalid);
  1.1715 +	if(calc.CreateSubRegion())
  1.1716 +		{
  1.1717 +		calc.CalcInvalid(*this);
  1.1718 +		if(dirty.CheckError() || dirty.Count())
  1.1719 +			{
  1.1720 +			Redraw();
  1.1721 +			wasDirty = ETrue;
  1.1722 +			}
  1.1723 +		calc.DestroyRegions();
  1.1724 +		}
  1.1725 +	dirty.Close();
  1.1726 +	bounds.Close();
  1.1727 +	return wasDirty;
  1.1728 +	}
  1.1729 +
  1.1730 +/**
  1.1731 + Overidding MWsObjectProvider
  1.1732 +*/
  1.1733 +TAny* CScreen::ResolveObjectInterface(TUint aTypeId)
  1.1734 +	{
  1.1735 +	TAny* interface = NULL;
  1.1736 +
  1.1737 +	switch (aTypeId)
  1.1738 +		{
  1.1739 +		case MWsWindow::EWsObjectInterfaceId:
  1.1740 +			interface = static_cast<MWsWindow*>(RootWindow());
  1.1741 +			break;
  1.1742 +		case MWsScreenConfigList::EWsObjectInterfaceId:
  1.1743 +			interface = static_cast<MWsScreenConfigList*>(this);
  1.1744 +			break;
  1.1745 +		case MWsScreenConfig::EWsObjectInterfaceId:
  1.1746 +			interface = static_cast<MWsScreenConfig*>(this);
  1.1747 +			break;
  1.1748 +		case MWsWindowTree::EWsObjectInterfaceId:
  1.1749 +			interface = static_cast<MWsWindowTree*>(this);
  1.1750 +		}
  1.1751 +
  1.1752 +	if (!interface)
  1.1753 +		interface = iRedraw->ResolveObjectInterface(aTypeId);
  1.1754 +
  1.1755 +	return interface;
  1.1756 +	}
  1.1757 +
  1.1758 +void CScreen::SendTree() const
  1.1759 +	{
  1.1760 +	if(!iWindowTreeObserver)
  1.1761 +		return;
  1.1762 +	
  1.1763 +	TWalkWindowTreeSendState wtw(*iWindowTreeObserver);
  1.1764 +	RootWindow()->WalkWindowTreeBackToFront(wtw, EVisitParentNodesFirst);
  1.1765 +
  1.1766 +	//Standard text cursors
  1.1767 +	RWsTextCursor* cursor = CWsTop::CurrentTextCursor();
  1.1768 +	if(cursor)
  1.1769 +		cursor->SendState(*iWindowTreeObserver);
  1.1770 +	
  1.1771 +	//Floating Sprites	
  1.1772 +	SpriteManager()->SendState(*iWindowTreeObserver);
  1.1773 +	
  1.1774 +	//Window Group Chains
  1.1775 +	for(CWsWindowGroup *group=RootWindow()->Child(); group!=NULL; group=group->NextSibling())
  1.1776 +		{
  1.1777 +		group->SendStateWindowGroupChain(*iWindowTreeObserver);
  1.1778 +		}
  1.1779 +	}
  1.1780 +
  1.1781 +TDisplayMode CScreen::DisplayMode() const
  1.1782 +	{
  1.1783 +	return iScreenDevice->DisplayMode();
  1.1784 +	}
  1.1785 +
  1.1786 +TSize CScreen::SizeInPixels() const
  1.1787 +	{
  1.1788 +	return iScreenDevice->SizeInPixels();
  1.1789 +	}
  1.1790 +
  1.1791 +TSize CScreen::SizeInTwips() const
  1.1792 +	{
  1.1793 +	return iScreenDevice->SizeInTwips();
  1.1794 +	}
  1.1795 +
  1.1796 +void CScreen::DiscardAllSchedules()
  1.1797 +	{
  1.1798 +	iRedraw->DiscardAllSchedules();
  1.1799 +	}
  1.1800 +
  1.1801 +void CScreen::ScheduleRegionUpdate(const TRegion* aDefinitelyDirty)
  1.1802 +	{
  1.1803 +	iRedraw->ScheduleRegionUpdate(aDefinitelyDirty);
  1.1804 +	}
  1.1805 +
  1.1806 +TBool CScreen::IsDSAClientWindow( const CWsClientWindow* aWin ) const
  1.1807 +	{
  1.1808 +	TBool res = EFalse; 
  1.1809 +	if ( ! iDirects.IsEmpty() )
  1.1810 +		{
  1.1811 +		TSglQueIter<CWsDirectScreenAccess> iter( (TSglQueBase&)iDirects );
  1.1812 +		iter.SetToFirst();
  1.1813 +		CWsDirectScreenAccess* dsa;
  1.1814 +		while ( (dsa = iter++) != NULL && !res )
  1.1815 +			{
  1.1816 +			res =  (dsa->ClientWindow() == aWin) && (dsa->IsVisible());
  1.1817 +			}
  1.1818 +		}
  1.1819 +	return res;	
  1.1820 +	}
  1.1821 +
  1.1822 +/**
  1.1823 +Update the UI element composition method based on whether
  1.1824 +there are any externals surfaces present and the current display mode. 
  1.1825 +If the method changes, recomposition is triggered.
  1.1826 +*/
  1.1827 +void CScreen::UpdateCompositionMode()
  1.1828 +	{
  1.1829 +	// do nothing
  1.1830 +	}
  1.1831 +
  1.1832 +void CScreen::ElementAdded()
  1.1833 +	{
  1.1834 +	UpdateCompositionMode();
  1.1835 +	}
  1.1836 +
  1.1837 +void CScreen::ElementRemoved()
  1.1838 +	{
  1.1839 +	UpdateCompositionMode();
  1.1840 +	}
  1.1841 +
  1.1842 +CRegisteredSurfaceMap* CScreen::SurfaceMap()
  1.1843 +	{
  1.1844 +	return iSurfaceMap;
  1.1845 +	}
  1.1846 +
  1.1847 +void CScreen::InitializeSceneL()
  1.1848 +	{
  1.1849 +	// Ensure the surface is not valid to start with.
  1.1850 +	iDsaSurface = TSurfaceId::CreateNullId();
  1.1851 +	iWindowElementSet = CWindowElementSet::NewL(*iScene);
  1.1852 +	}
  1.1853 +
  1.1854 +MWsElement* CScreen::CreateUiElementL(const TRect& aExtent)
  1.1855 +	{
  1.1856 +	MWsElement* pElement = iScene->CreateSceneElementL();
  1.1857 +	
  1.1858 +	TUint32 flags = 0;
  1.1859 +	pElement->GetRenderStageFlags(flags);
  1.1860 +	flags |= MWsElement::EElementIsIndirectlyRenderedUserInterface;
  1.1861 +	pElement->SetRenderStageFlags(flags);
  1.1862 +	    
  1.1863 +    iScene->InsertSceneElement(pElement, NULL);
  1.1864 +
  1.1865 +	pElement->SetDestinationRectangle(aExtent);
  1.1866 +	pElement->SetSourceRectangle(aExtent);	//initial guess... updated by PositionUiElements
  1.1867 +
  1.1868 +	return pElement;
  1.1869 +	}
  1.1870 +
  1.1871 +void CScreen::InitializeUiElementsL()
  1.1872 +	{
  1.1873 +	const TRect screenRect(iScreenDevice->SizeInPixels());
  1.1874 +	MWsElement* pElement = CreateUiElementL(screenRect);
  1.1875 +	
  1.1876 +	if(HasAlpha())
  1.1877 +		{
  1.1878 +		TUint32 flags = 0;
  1.1879 +		pElement->GetTargetRendererFlags(flags);
  1.1880 +		flags |= MWsElement::EElementTransparencySource;
  1.1881 +		pElement->SetTargetRendererFlags(flags);
  1.1882 +		}
  1.1883 +	}
  1.1884 +
  1.1885 +TInt CScreen::InitializeDsaSurface()
  1.1886 +	{
  1.1887 +	WS_ASSERT_DEBUG(iDsaSurface.IsNull(),EWsPanicInvalidOperation);
  1.1888 +	iDsaDevice->GetSurface(iDsaSurface);
  1.1889 +	// Currently Surface Manager does not recognise DSA surface IDs originating
  1.1890 +	// from the Screen Driver.  This causes it to fail to register such
  1.1891 +	// surfaces.  OpenWF should be amended to properly register DSA surfaces.
  1.1892 +	iScene->RegisterSurface(iDsaSurface);
  1.1893 +
  1.1894 +	return KErrNone;
  1.1895 +	}
  1.1896 +
  1.1897 +TSize CScreen::DSASizeInPixels() const
  1.1898 +	{
  1.1899 +	if(iDsaDevice)
  1.1900 +		{
  1.1901 +		return iDsaDevice->SizeInPixels();
  1.1902 +		}
  1.1903 +	else
  1.1904 +		{
  1.1905 +		return TSize(0,0);
  1.1906 +		}
  1.1907 +	}
  1.1908 +
  1.1909 +MWsTextCursor* CScreen::RenderStageTextCursor() const
  1.1910 +	{
  1.1911 +	return iRedraw->RenderStageTextCursor();
  1.1912 +	}
  1.1913 +
  1.1914 +void CScreen::ClearDsaSurface(const TRect& area, const TRgb& color)
  1.1915 +	{
  1.1916 +	WS_ASSERT_DEBUG(iDsaGc, EWsPanicInvalidOperation);
  1.1917 +	iDsaGc->SetBrushStyle(CFbsBitGc::ESolidBrush);
  1.1918 +	iDsaGc->SetPenStyle(CFbsBitGc::ENullPen);
  1.1919 +	iDsaGc->SetBrushColor(color);
  1.1920 +	iDsaGc->DrawRect(area);
  1.1921 +	iDsaDevice->Update();
  1.1922 +	}
  1.1923 +
  1.1924 +void CScreen::ReleaseDsaScreenDevice()
  1.1925 +	{
  1.1926 +	//This function checks if any of the DSA currently active on the screen is actually used to draw
  1.1927 +	//If not it unregister the DSA surface and destroys the iDsaDevice.
  1.1928 +	//This function should be called only by a drawing DSA so a surface should be in place.
  1.1929 +	iNumberDrawingDsa--;
  1.1930 +	if(iNumberDrawingDsa == 0)
  1.1931 +		{
  1.1932 +		WS_ASSERT_DEBUG(!iDsaSurface.IsNull(),EWsPanicInvalidOperation);
  1.1933 +		delete iDsaGc;
  1.1934 +		iDsaGc = NULL;
  1.1935 +		// Currently Surface Manager does not recognise DSA surface IDs originating
  1.1936 +		// from the Screen Driver.  This causes it to fail to unregister such
  1.1937 +		// surfaces.  OpenWF should be amended to properly register DSA surfaces.
  1.1938 +		iScene->UnregisterSurface(iDsaSurface);
  1.1939 +
  1.1940 +		delete iDsaDevice;
  1.1941 +		iDsaDevice = NULL;
  1.1942 +		//the old surface Id is now meaningless
  1.1943 +		iDsaSurface = TSurfaceId::CreateNullId();
  1.1944 +		}
  1.1945 +	}
  1.1946 +
  1.1947 +TInt CScreen::SetConfiguration(const TDisplayConfiguration& aConfigInput)
  1.1948 +	{
  1.1949 +	TInt reply = KErrNone;
  1.1950 +	if(iDisplayControl)
  1.1951 +		{
  1.1952 +		TDisplayConfiguration config(aConfigInput);
  1.1953 +		TRect sizeModePosition;
  1.1954 +		if (iDisplayPolicy)
  1.1955 +			{	//validate config and update to a valid hardware config
  1.1956 +			reply = iDisplayPolicy->GetSizeModeConfiguration(iScreenSizeMode,config,sizeModePosition);
  1.1957 +			if (reply >= KErrNone)
  1.1958 +				{//set appmode in policy
  1.1959 +				if (iDisplayMapping)
  1.1960 +					{
  1.1961 +					iDisplayMapping->SetSizeModeExtent(sizeModePosition,MWsDisplayMapping::KOffsetAll);
  1.1962 +					}
  1.1963 +				}
  1.1964 +			}
  1.1965 +		else
  1.1966 +			{	//exessive strategy: limit rotation agains curr app mode.
  1.1967 +				//really we want the system to accept the rotation change regardless of the app mode.
  1.1968 +			TDisplayConfiguration::TRotation newRot;
  1.1969 +			if (aConfigInput.GetRotation(newRot))
  1.1970 +				{	//This should cast between rotation enumertaions "properly"
  1.1971 +				if (!(iModes[0][iScreenSizeMode]->iAlternativeRotations&(1<<newRot)))
  1.1972 +					{
  1.1973 +					reply=KErrArgument;
  1.1974 +					}
  1.1975 +				}
  1.1976 +			}
  1.1977 +		if (reply < KErrNone)
  1.1978 +			{
  1.1979 +			return reply;
  1.1980 +			}
  1.1981 +		MWsScene::TSceneRotation oldRotation;
  1.1982 +		oldRotation = iScene->SceneRotation();
  1.1983 +		TSize newUiSize;
  1.1984 +		config.GetResolution(newUiSize);
  1.1985 +		TDisplayConfiguration oldConfig;
  1.1986 +		iDisplayControl->GetConfiguration(oldConfig);
  1.1987 +		if(iFlags&EHasDynamicSizeModes)
  1.1988 +			{
  1.1989 +			reply = iFallbackMap->Resize(newUiSize);
  1.1990 +			}
  1.1991 +		if (reply >= KErrNone)
  1.1992 +			{
  1.1993 +			reply=iDisplayControl->SetConfiguration(config);
  1.1994 +			}	
  1.1995 +		if (reply==KErrNone)
  1.1996 +			{
  1.1997 +			TSize oldConfigRes;
  1.1998 +			oldConfig.GetResolution(oldConfigRes);
  1.1999 +            TDisplayConfiguration newConfig;
  1.2000 +			if (oldConfigRes.iWidth == 0 || oldConfigRes.iHeight == 0)
  1.2001 +				{
  1.2002 +				iDisplayControl->GetConfiguration(newConfig);
  1.2003 +				RecalculateModeTwips(&newConfig);	//needs res and twips information
  1.2004 +				}
  1.2005 +			UpdateDynamicScreenModes();
  1.2006 +			
  1.2007 +			//update the last set config in the config change notifier to 
  1.2008 +			//prevent SetConfiguration() from being called again!
  1.2009 +			newConfig.ClearAll();
  1.2010 +			iDisplayControl->GetConfiguration(newConfig);
  1.2011 +			iConfigChangeNotifier->UpdateLastSetConfiguration(newConfig); 			
  1.2012 +			
  1.2013 +			TWindowServerEvent::NotifyDrawer(TWservCrEvent(TWservCrEvent::EScreenSizeModeAboutToChange, iScreenSizeMode));
  1.2014 +			// This will remove all the DSA elements from the scene
  1.2015 +			AbortAllDirectDrawing(RDirectScreenAccess::ETerminateRotation);
  1.2016 +			
  1.2017 +			//SetDigitiserAreas needs revisiting if/when we support dynamic resolutions
  1.2018 +			//on a screen with touch input.
  1.2019 +			//SetDigitiserAreas(newUiSize);
  1.2020 +			
  1.2021 +			//failure here should only be because of DSA orientation change failure, which shouldn't happen, either.
  1.2022 +			//Or there may be no change to do.
  1.2023 +			(void)UpdateOrientation(&oldRotation);
  1.2024 +			
  1.2025 +			iWindowElementSet->ResubmitAllElementExtents();
  1.2026 +			if(iDsaDevice && iDsaDevice->GraphicsAccelerator())
  1.2027 +				{
  1.2028 +				iDsaDevice->ChangeScreenDevice(iDsaDevice); // orientation has changed, therefore we need to re-initialise the screen device's graphics accelerator
  1.2029 +				}
  1.2030 +			
  1.2031 +			iRootWindow->AdjustCoordsDueToRotation();
  1.2032 +
  1.2033 +			//TODO jonas: we'd like to not have to clear at all... make the actual change to compositor etc lazily!
  1.2034 +			if(BlankScreenOnRotation())
  1.2035 +				{
  1.2036 +				iRootWindow->ClearDisplay();
  1.2037 +				}
  1.2038 +
  1.2039 +			CWsTop::ClearAllRedrawStores();
  1.2040 +			DiscardAllSchedules();
  1.2041 +			iRootWindow->InvalidateWholeScreen();
  1.2042 +			CWsWindowGroup::SetScreenDeviceValidStates(this);
  1.2043 +			TWindowServerEvent::SendScreenDeviceChangedEvents(this);
  1.2044 +			}
  1.2045 +		else
  1.2046 +			{
  1.2047 +			return reply;
  1.2048 +			}
  1.2049 +		}
  1.2050 +	else
  1.2051 +		{
  1.2052 +		reply = KErrNotSupported;
  1.2053 +		}
  1.2054 +	return reply;
  1.2055 +	}
  1.2056 +
  1.2057 +/**
  1.2058 + * Updates the screen device display properties. This is to ensure the screen device is 
  1.2059 + * consistent with any configuration changes not made using CScreen::SetConfiguration.
  1.2060 + * 
  1.2061 + * @param aConfigInput a fully populated display configuration
  1.2062 + **/
  1.2063 +TInt CScreen::UpdateConfiguration(const TDisplayConfiguration& aConfigInput)
  1.2064 +    {
  1.2065 +    TInt reply = KErrNone;
  1.2066 +    if(iDisplayControl)
  1.2067 +        {
  1.2068 +        TDisplayConfiguration config(aConfigInput);
  1.2069 +        TRect sizeModePosition;
  1.2070 +        if (iDisplayPolicy)
  1.2071 +            {   //validate config and update to a valid hardware config
  1.2072 +            reply = iDisplayPolicy->GetSizeModeConfiguration(iScreenSizeMode,config,sizeModePosition);
  1.2073 +            if (reply >= KErrNone)
  1.2074 +                {//set appmode in policy
  1.2075 +                if (iDisplayMapping)
  1.2076 +                    {
  1.2077 +                    iDisplayMapping->SetSizeModeExtent(sizeModePosition,MWsDisplayMapping::KOffsetAll);
  1.2078 +                    }
  1.2079 +                }
  1.2080 +            }
  1.2081 +        else
  1.2082 +            {   //exessive strategy: limit rotation agains curr app mode.
  1.2083 +                //really we want the system to accept the rotation change regardless of the app mode.
  1.2084 +            TDisplayConfiguration::TRotation newRot;
  1.2085 +            if (aConfigInput.GetRotation(newRot))
  1.2086 +                {   //This should cast between rotation enumertaions "properly"
  1.2087 +                if (!(iModes[0][iScreenSizeMode]->iAlternativeRotations&(1<<newRot)))
  1.2088 +                    {
  1.2089 +                    reply=KErrArgument;
  1.2090 +                    }
  1.2091 +                }
  1.2092 +            }
  1.2093 +
  1.2094 +        MWsScene::TSceneRotation oldRotation;
  1.2095 +        oldRotation = iScene->SceneRotation();
  1.2096 +        TSize newUiSize;
  1.2097 +        config.GetResolution(newUiSize);
  1.2098 +        if(iFlags&EHasDynamicSizeModes)
  1.2099 +            {
  1.2100 +            reply = iFallbackMap->Resize(newUiSize);
  1.2101 +            }
  1.2102 +
  1.2103 +        RecalculateModeTwips(&config);   //needs res and twips information
  1.2104 +        UpdateDynamicScreenModes();        
  1.2105 +        
  1.2106 +        TWindowServerEvent::NotifyDrawer(TWservCrEvent(TWservCrEvent::EScreenSizeModeAboutToChange, iScreenSizeMode));
  1.2107 +        // This will remove all the DSA elements from the scene
  1.2108 +        AbortAllDirectDrawing(RDirectScreenAccess::ETerminateRotation);
  1.2109 +        
  1.2110 +        //SetDigitiserAreas needs revisiting if/when we support dynamic resolutions
  1.2111 +        //on a screen with touch input.
  1.2112 +        //SetDigitiserAreas(newUiSize);
  1.2113 +        
  1.2114 +        //failure here should only be because of DSA orientation change failure, which shouldn't happen, either.
  1.2115 +        //Or there may be no change to do.
  1.2116 +        (void)UpdateOrientation(&oldRotation);
  1.2117 +        
  1.2118 +        iWindowElementSet->ResubmitAllElementExtents();
  1.2119 +        if(iDsaDevice && iDsaDevice->GraphicsAccelerator())
  1.2120 +            {
  1.2121 +            iDsaDevice->ChangeScreenDevice(iDsaDevice); // orientation has changed, therefore we need to re-initialise the screen device's graphics accelerator
  1.2122 +            }
  1.2123 +        
  1.2124 +        iRootWindow->AdjustCoordsDueToRotation();
  1.2125 +
  1.2126 +        //TODO jonas: we'd like to not have to clear at all... make the actual change to compositor etc lazily!
  1.2127 +        if(BlankScreenOnRotation())
  1.2128 +            {
  1.2129 +            iRootWindow->ClearDisplay();
  1.2130 +            }
  1.2131 +
  1.2132 +        CWsTop::ClearAllRedrawStores();
  1.2133 +        DiscardAllSchedules();
  1.2134 +        iRootWindow->InvalidateWholeScreen();
  1.2135 +        CWsWindowGroup::SetScreenDeviceValidStates(this);
  1.2136 +        TWindowServerEvent::SendScreenDeviceChangedEvents(this);
  1.2137 +        }
  1.2138 +    else
  1.2139 +        {
  1.2140 +        reply = KErrNotSupported;
  1.2141 +        }
  1.2142 +    return reply;  
  1.2143 +    }
  1.2144 +
  1.2145 +void CScreen::UpdateDynamicScreenModes()
  1.2146 +	{
  1.2147 +	WS_ASSERT_DEBUG(iDisplayControl,EWsPanicNoDisplayControl);
  1.2148 +	TDisplayConfiguration newConfig;
  1.2149 +	iDisplayControl->GetConfiguration(newConfig);
  1.2150 +	TSize res;
  1.2151 +	TSize twips;
  1.2152 +	newConfig.GetResolution(res);
  1.2153 +	newConfig.GetResolutionTwips(twips);
  1.2154 +	for (TInt i=0; i<iModes->Count(); i++)
  1.2155 +		{
  1.2156 +		if ((*iModes)[i] && ((*iModes)[i]->iFlags & EDynamic))
  1.2157 +			{
  1.2158 +			(*iModes)[i]->iScreenSize = res;
  1.2159 +			(*iModes)[i]->iScreenTwipsSize = twips;
  1.2160 +			}
  1.2161 +		}
  1.2162 +	}
  1.2163 +
  1.2164 +void CScreen::RecalculateModeTwips(const TDisplayConfiguration* aConfig)
  1.2165 +	{
  1.2166 +	TDisplayConfiguration config;
  1.2167 +	iDisplayControl->GetConfiguration(config);
  1.2168 +	TSize res;
  1.2169 +	TSize twips;
  1.2170 +	if (aConfig)	//called from SetConfiguration
  1.2171 +		{
  1.2172 +		aConfig->GetResolution(res);
  1.2173 +		if (res.iWidth == 0 || res.iHeight == 0)
  1.2174 +			{
  1.2175 +			return;
  1.2176 +			}
  1.2177 +		aConfig->GetResolutionTwips(twips);
  1.2178 +		}
  1.2179 +	else	//called from DisplayChangeNotifier during attach
  1.2180 +		{
  1.2181 +		config.GetResolution(res);
  1.2182 +		if ((res.iWidth == 0 || res.iHeight == 0) && !iDisplayPolicy)
  1.2183 +			{
  1.2184 +			return;
  1.2185 +			}
  1.2186 +		config.GetResolutionTwips(twips);
  1.2187 +		}
  1.2188 +	TInt err=KErrNone;
  1.2189 +	TInt flags=0;
  1.2190 +	for (TInt ii=0; ii<iModes->Count(); ii++)
  1.2191 +		{	//for every mode
  1.2192 +		TRAP(err, flags = ModePtrL(ii)->iFlags);
  1.2193 +		if (err != KErrNone || flags&(ETwipsSpecified|EDynamic))
  1.2194 +			{	//continue if mode doesnt exist,twips specified or dynamic mode specified
  1.2195 +			continue;
  1.2196 +			}
  1.2197 +
  1.2198 +		if (iDisplayPolicy)
  1.2199 +			{	//get ideal config for app mode from policy
  1.2200 +			TRect modePosition;
  1.2201 +			config.ClearAll();
  1.2202 +			TInt err = iDisplayPolicy->GetSizeModeConfiguration(ii,config,modePosition);
  1.2203 +			if (err != KErrNone)
  1.2204 +				{	//nothing we can do, the twips will not be calculated correctly
  1.2205 +				continue;
  1.2206 +				}
  1.2207 +			config.GetResolution(res);
  1.2208 +			config.GetResolutionTwips(twips);
  1.2209 +			}
  1.2210 +		TSizeMode* modePtr=(*iModes)[ii];
  1.2211 +		modePtr->iScreenTwipsSize.iWidth = (twips.iWidth * modePtr->iScreenSize.iWidth)/
  1.2212 +				res.iWidth;
  1.2213 +		modePtr->iScreenTwipsSize.iHeight = (twips.iHeight * modePtr->iScreenSize.iHeight)/
  1.2214 +				res.iHeight;
  1.2215 +		}
  1.2216 +	
  1.2217 +	}
  1.2218 +
  1.2219 +TInt CScreen::AddNotificationClient(CWsClient *aClient)
  1.2220 +	{
  1.2221 +	TInt err = iWsClientList.InsertInAddressOrder(aClient);
  1.2222 +	if(!(err == KErrNone || err == KErrAlreadyExists))
  1.2223 +		{
  1.2224 +		return err;
  1.2225 +		}
  1.2226 +	return KErrNone;
  1.2227 +	}
  1.2228 +void CScreen::RemoveNotificationClient(CWsClient *aClient)
  1.2229 +	{
  1.2230 +	TInt index = iWsClientList.FindInAddressOrder(aClient);
  1.2231 +	if(index != KErrNotFound)
  1.2232 +		{
  1.2233 +		iWsClientList.Remove(index);
  1.2234 +		}
  1.2235 +	}
  1.2236 +TInt CScreen::GetNotificationClients(RPointerArray<CWsClient>& aClientsArray)
  1.2237 +	{
  1.2238 +	TInt err = aClientsArray.Reserve(iWsClientList.Count());
  1.2239 +	if(err != KErrNone)
  1.2240 +		return err;
  1.2241 +	
  1.2242 +	for(TInt i = 0; i < iWsClientList.Count(); i++)
  1.2243 +		{
  1.2244 +		aClientsArray.Append(iWsClientList[i]);
  1.2245 +		}
  1.2246 +	return KErrNone;
  1.2247 +	}
  1.2248 +
  1.2249 +TInt CScreen::FindNotificationClient (CWsClient *aClient)
  1.2250 +	{
  1.2251 +	return iWsClientList.FindInAddressOrder(aClient);
  1.2252 +	}
  1.2253 +
  1.2254 +// implementing MWsScreenConfig... this might be better as RS interface
  1.2255 +TSize CScreen::ScreenModeSizeInPixels() const
  1.2256 +	{
  1.2257 +	return (*iModes)[iScreenSizeMode]->iScreenSize;
  1.2258 +	}
  1.2259 +TInt CScreen::Stride() const
  1.2260 +	{
  1.2261 +	return 0;
  1.2262 +	}
  1.2263 +TInt CScreen::SizeMode() const
  1.2264 +	{
  1.2265 +	return iScreenSizeMode;
  1.2266 +
  1.2267 +	}
  1.2268 +TSize CScreen::ScalingFactor() const
  1.2269 +	{
  1.2270 +	return (*iModes)[iScreenSizeMode]->iScreenScale;
  1.2271 +	}
  1.2272 +TPoint CScreen::Origin() const
  1.2273 +	{
  1.2274 +	return (*iModes)[iScreenSizeMode]->iOrigin;
  1.2275 +	}
  1.2276 +TPoint CScreen::ScaledOrigin() const
  1.2277 +	{
  1.2278 +	return (*iModes)[iScreenSizeMode]->ScaledOrigin();
  1.2279 +	}
  1.2280 +
  1.2281 +const CScreen::TInternalSizeMode* CScreen::ModePtrL(TInt aIndex) const
  1.2282 +	{
  1.2283 +	if (aIndex>=iModes->Count() || aIndex<0)
  1.2284 +		{
  1.2285 +		User::Leave(KErrArgument);
  1.2286 +		}
  1.2287 +	if (iModes==NULL)
  1.2288 +		{
  1.2289 +		User::Leave(KErrNotReady);
  1.2290 +		}
  1.2291 +	TInternalSizeMode* modePtr=(*iModes)[aIndex];
  1.2292 +	if (modePtr==NULL)
  1.2293 +		{
  1.2294 +		User::Leave(KErrArgument);
  1.2295 +		}
  1.2296 +	return modePtr;
  1.2297 +	}
  1.2298 +
  1.2299 +TDisplayMode CScreen::DisplayModeL(TInt aIndex) const
  1.2300 +	{
  1.2301 +	return ModePtrL(aIndex)->iDefaultDisplayMode;
  1.2302 +	}
  1.2303 +TSize CScreen::ScreenModeSizeInPixelsL(TInt aIndex) const
  1.2304 +	{
  1.2305 +	return ModePtrL(aIndex)->iScreenSize;
  1.2306 +	}
  1.2307 +TSize CScreen::ScreenModeSizeInTwipsL(TInt aIndex) const 
  1.2308 +	{
  1.2309 +	return ModePtrL(aIndex)->iScreenTwipsSize;
  1.2310 +	}
  1.2311 +
  1.2312 +CFbsBitGc::TGraphicsOrientation CScreen::OrientationL(TInt aIndex) const
  1.2313 +	{
  1.2314 +	return ModePtrL(aIndex)->iRotation;
  1.2315 +	}
  1.2316 +TInt CScreen::AvailableOrientationsL(TInt aIndex) const
  1.2317 +	{
  1.2318 +	return ModePtrL(aIndex)->iAlternativeRotations;
  1.2319 +	}
  1.2320 +TSize CScreen::ScalingFactorL(TInt aIndex) const
  1.2321 +	{
  1.2322 +	return ModePtrL(aIndex)->iScreenScale;
  1.2323 +	}
  1.2324 +TPoint CScreen::OriginL(TInt aIndex) const
  1.2325 +	{
  1.2326 +	return ModePtrL(aIndex)->iOrigin;
  1.2327 +	}
  1.2328 +TPoint CScreen::ScaledOriginL(TInt aIndex) const
  1.2329 +	{
  1.2330 +	return ModePtrL(aIndex)->ScaledOrigin();
  1.2331 +	}
  1.2332 +TInt CScreen::ModeFlagsL(TInt aIndex) const
  1.2333 +	{
  1.2334 +	return ModePtrL(aIndex)->iFlags;
  1.2335 +	}
  1.2336 +void CScreen::SetCurrentScreenModeAttributes(const TSizeMode &aModeData)
  1.2337 +	{	
  1.2338 +	TSizeMode* modeToOverwrite=(*iModes)[iScreenSizeMode];
  1.2339 +	*modeToOverwrite=aModeData;
  1.2340 +	}
  1.2341 +
  1.2342 +void CScreen::ScheduleWindow(CWsWindow* aWindow)
  1.2343 +	{
  1.2344 +	iRedraw->ScheduleWindow(aWindow);
  1.2345 +	}
  1.2346 +
  1.2347 +void CScreen::RemoveFromScheduledList(CWsWindow* aWindow)
  1.2348 +	{
  1.2349 +	iRedraw->RemoveFromScheduledList(aWindow);
  1.2350 +	}
  1.2351 +
  1.2352 +void CScreen::RemoveFromTimedDrawList(CWsWindow* aWindow)
  1.2353 +	{
  1.2354 +	iRedraw->RemoveFromTimedDrawList(aWindow);
  1.2355 +	}
  1.2356 +
  1.2357 +void CScreen::SetupVisibleRegionTracking(CWsWindow& aWindow, TBool aRegister) const
  1.2358 +	{
  1.2359 +	if(ChangeTracking() && iWindowVisibilityNotifier)
  1.2360 +		{
  1.2361 +		if(aRegister)
  1.2362 +			{
  1.2363 +			iWindowVisibilityNotifier->RegisterWindow(aWindow);
  1.2364 +			}
  1.2365 +		else
  1.2366 +			{
  1.2367 +			iWindowVisibilityNotifier->UnregisterWindow(aWindow);
  1.2368 +			}
  1.2369 +		}
  1.2370 +	}
  1.2371 +
  1.2372 +TBool CScreen::IsAnimating() const
  1.2373 +    {
  1.2374 +    return iRedraw->IsAnimating();
  1.2375 +    }