os/graphics/windowing/windowserver/nonnga/SERVER/screen.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include "screen.h"
sl@0
    17
sl@0
    18
#include <hal.h>
sl@0
    19
sl@0
    20
#include "server.h"
sl@0
    21
#include "wstop.h"
sl@0
    22
#include "rootwin.h"
sl@0
    23
#include "walkwindowtree.h"
sl@0
    24
#include "offscreenbitmap.h"
sl@0
    25
#include "EVENT.H"
sl@0
    26
#include "windowgroup.h"
sl@0
    27
#include "gc.h"
sl@0
    28
#include "inifile.h"
sl@0
    29
#include "pointer.h"
sl@0
    30
sl@0
    31
#include "debugbar.h"
sl@0
    32
#include "ScreenRedraw.h"
sl@0
    33
#include "wspluginmanager.h"
sl@0
    34
sl@0
    35
GLREF_D CDebugLogBase *wsDebugLog;
sl@0
    36
GLREF_D TDisplayMode ParseDisplayMode(const TDesC& aModeName);
sl@0
    37
sl@0
    38
LOCAL_D TBool FindNextValue(TLex& aLex, TInt& aValue) // assumes the list cannot contain *negative* integers
sl@0
    39
	{
sl@0
    40
	while (!aLex.Eos())
sl@0
    41
		{
sl@0
    42
		const TUint character=aLex.Peek();
sl@0
    43
		if (Rng(TUint('0'), character, TUint('9')) || (character=='-'))
sl@0
    44
			{
sl@0
    45
			break;
sl@0
    46
			}
sl@0
    47
		aLex.Inc();
sl@0
    48
		}
sl@0
    49
sl@0
    50
	return (aLex.Val(aValue)==KErrNone);
sl@0
    51
	}
sl@0
    52
sl@0
    53
CScreen::CFallbackMap * CScreen::CFallbackMap::NewL(CScreen* aScreen)
sl@0
    54
	{
sl@0
    55
	CFallbackMap * self = new (ELeave) CFallbackMap(aScreen);
sl@0
    56
	CleanupStack::PushL(self);
sl@0
    57
	self->ConstructL();
sl@0
    58
	CleanupStack::Pop(self);
sl@0
    59
	return self;
sl@0
    60
	}
sl@0
    61
	
sl@0
    62
CScreen::CFallbackMap::CFallbackMap(CScreen* aScreen) :
sl@0
    63
	iScreen(aScreen),
sl@0
    64
	iRegion(TRect(TPoint(0,0), TSize(1,1))),
sl@0
    65
	iCount(0)
sl@0
    66
	{
sl@0
    67
	}
sl@0
    68
	
sl@0
    69
CScreen::CFallbackMap::~CFallbackMap()
sl@0
    70
	{
sl@0
    71
	delete iMap;
sl@0
    72
	}
sl@0
    73
	
sl@0
    74
void CScreen::CFallbackMap::ConstructL()
sl@0
    75
	{
sl@0
    76
	iMapSize = 0;
sl@0
    77
	
sl@0
    78
	for (TInt num = 0; num < iScreen->NumScreenSizeModes(); ++num)
sl@0
    79
		{
sl@0
    80
		if (iScreen->IsValidScreenSizeMode(num))
sl@0
    81
			{
sl@0
    82
			const TSizeMode & mode = iScreen->ScreenSizeModeData(num);
sl@0
    83
			TInt width = mode.iScreenSize.iWidth / 32;
sl@0
    84
			if (mode.iScreenSize.iWidth & (32 - 1))
sl@0
    85
				++width;
sl@0
    86
			TInt size = width * mode.iScreenSize.iHeight;
sl@0
    87
			if (size > iMapSize)
sl@0
    88
				iMapSize = size;
sl@0
    89
			}
sl@0
    90
		}
sl@0
    91
		
sl@0
    92
	iMap = new (ELeave) TInt [iMapSize];
sl@0
    93
	}
sl@0
    94
sl@0
    95
void CScreen::CFallbackMap::Prepare()
sl@0
    96
	{
sl@0
    97
	const TSizeMode & mode = iScreen->ScreenSizeModeData();
sl@0
    98
	Mem::FillZ(iMap, iMapSize * sizeof(TInt));
sl@0
    99
	iCount = mode.iScreenSize.iHeight * mode.iScreenSize.iWidth;
sl@0
   100
	WS_ASSERT_DEBUG(iRegion.Count() == 1, EWsPanicScreenFallback);
sl@0
   101
	iRegion.Clear();
sl@0
   102
	iRegion.AddRect(TRect(mode.iOrigin, mode.iScreenSize));
sl@0
   103
	}
sl@0
   104
sl@0
   105
TBool CScreen::CFallbackMap::FillRegion(const TRegion& aRegion)
sl@0
   106
	{
sl@0
   107
	WS_ASSERT_DEBUG(!aRegion.CheckError(), EWsPanicScreenFallback);
sl@0
   108
	if (aRegion.Count() > 20 || aRegion.CheckError())
sl@0
   109
		return ETrue;
sl@0
   110
	TBool hit = EFalse;
sl@0
   111
	if (iCount > 0)
sl@0
   112
		{
sl@0
   113
		const TRect * rect = aRegion.RectangleList();
sl@0
   114
		for (TInt num = 0; num < aRegion.Count(); ++num)
sl@0
   115
			{
sl@0
   116
			hit = FillRect(*rect) || hit;
sl@0
   117
			if (iCount < 1)
sl@0
   118
				break;
sl@0
   119
			++rect;
sl@0
   120
			}
sl@0
   121
		}
sl@0
   122
	return hit;
sl@0
   123
	}
sl@0
   124
	
sl@0
   125
// x >> 5 is equivalent to x / 32
sl@0
   126
// 0x1F is the rounding error when dividing by 32
sl@0
   127
// 0x20 is 32.
sl@0
   128
// The compiler might do all the optimizations for us - not checked.
sl@0
   129
TBool CScreen::CFallbackMap::FillRect(const TRect& aRect)
sl@0
   130
	{
sl@0
   131
	TBool hit = EFalse;
sl@0
   132
	const TSizeMode & mode = iScreen->ScreenSizeModeData();
sl@0
   133
	TRect scrrect(mode.iOrigin, mode.iScreenSize);
sl@0
   134
	TRect rect = aRect;
sl@0
   135
	rect.Intersection(scrrect);
sl@0
   136
	TInt rowWidthInInts = mode.iScreenSize.iWidth;
sl@0
   137
	if (rowWidthInInts & 0x1F)
sl@0
   138
		rowWidthInInts += 0x20;
sl@0
   139
	rowWidthInInts >>= 5;
sl@0
   140
sl@0
   141
	TInt colStartInInts = rect.iTl.iX >> 5;
sl@0
   142
	TInt firstOffsetInBits = rect.iTl.iX & 0x1F;
sl@0
   143
sl@0
   144
	for(TInt row = rect.iTl.iY; row < rect.iBr.iY; ++row)
sl@0
   145
		{
sl@0
   146
		TInt * map = iMap + row * rowWidthInInts + colStartInInts;
sl@0
   147
		TInt offsetShift = 31 - firstOffsetInBits;
sl@0
   148
		for (TInt col = rect.iTl.iX; col < rect.iBr.iX; ++col)
sl@0
   149
			{
sl@0
   150
			WS_ASSERT_DEBUG(map - iMap < iMapSize, EWsPanicScreenFallback);
sl@0
   151
			if (!(*map & 1 << offsetShift))
sl@0
   152
				{
sl@0
   153
				--iCount;
sl@0
   154
				hit = ETrue;
sl@0
   155
				if (iCount < 1)
sl@0
   156
					break;
sl@0
   157
				(*map) |= (1 << offsetShift);
sl@0
   158
				}
sl@0
   159
			--offsetShift;
sl@0
   160
			if (offsetShift < 0)
sl@0
   161
				{
sl@0
   162
				offsetShift = 31;
sl@0
   163
				++map;
sl@0
   164
				}
sl@0
   165
			}
sl@0
   166
		}
sl@0
   167
	return hit;
sl@0
   168
	}
sl@0
   169
sl@0
   170
TInt CScreen::CFallbackMap::Count() const
sl@0
   171
	{
sl@0
   172
	return iCount;
sl@0
   173
	}
sl@0
   174
sl@0
   175
const TRect * CScreen::CFallbackMap::Rect() const
sl@0
   176
	{
sl@0
   177
	return iRegion.RectangleList();
sl@0
   178
	}
sl@0
   179
	
sl@0
   180
const RRegion * CScreen::CFallbackMap::Region() const
sl@0
   181
	{
sl@0
   182
	return &iRegion;
sl@0
   183
	}
sl@0
   184
	
sl@0
   185
//
sl@0
   186
// CScreen
sl@0
   187
//
sl@0
   188
CScreen::CScreen(): iDirects(_FOFF(CWsDirectScreenAccess,iLink)), iMaxContrast(-1), iMaxBrightness(-1)
sl@0
   189
	{
sl@0
   190
	}
sl@0
   191
sl@0
   192
CScreen::~CScreen()
sl@0
   193
	{
sl@0
   194
	delete iDebugBar;
sl@0
   195
	delete iOffScreenBitmap;
sl@0
   196
	delete iScreenGdi;
sl@0
   197
	TInt ii;
sl@0
   198
	if(iModes)
sl@0
   199
		{
sl@0
   200
		for(ii=iNumScreenSizeModes-1;ii>=0;--ii)
sl@0
   201
			{
sl@0
   202
			delete (*iModes)[ii];
sl@0
   203
			}
sl@0
   204
		iModes->Close();
sl@0
   205
		delete iModes;
sl@0
   206
		}
sl@0
   207
	delete iRootWindow;
sl@0
   208
	delete iScreenDevice;
sl@0
   209
	delete iFallbackMap;
sl@0
   210
	delete iSpriteManager;
sl@0
   211
	delete iRedraw;
sl@0
   212
	}
sl@0
   213
sl@0
   214
void CScreen::ConstructL(const TRect& aDigitiserArea, TInt aScreenNumber )
sl@0
   215
	{
sl@0
   216
	iScreenNumber = aScreenNumber ;
sl@0
   217
sl@0
   218
	if (wsDebugLog)
sl@0
   219
		{
sl@0
   220
		_LIT(KWSERVInitScreen,"Initialising for Screen %d");
sl@0
   221
		wsDebugLog->MiscMessage(CDebugLogBase::ELogImportant, KWSERVInitScreen, aScreenNumber);
sl@0
   222
		}
sl@0
   223
sl@0
   224
	CreateScreenDeviceL();
sl@0
   225
	iScreenDevice->SetAutoUpdate(EFalse);
sl@0
   226
	iPhysicalScreenSize=iScreenDevice->SizeInPixels();
sl@0
   227
	LoadScreenSizesL(iPhysicalScreenSize);
sl@0
   228
	// mode 0 might not be available, get the first/lowest valid mode
sl@0
   229
	SetInitialScreenSizeMode();
sl@0
   230
	
sl@0
   231
	iFallbackMap = CFallbackMap::NewL(this);
sl@0
   232
//
sl@0
   233
	iScreenGdi=CFbsBitGc::NewL();
sl@0
   234
	iScreenGdi->Activate(iScreenDevice);
sl@0
   235
	LoadScreenSizeProperties();
sl@0
   236
	SetDigitiserAreas(iScreenDevice->SizeInPixels(),aDigitiserArea);
sl@0
   237
//
sl@0
   238
	iScreenGdi->SetOrientation(Orientation());
sl@0
   239
	const TSizeMode& sizeMode=ScreenSizeModeData(ScreenSizeMode());
sl@0
   240
	iScreenDevice->SetScalingFactor(sizeMode.iOrigin,sizeMode.iScreenScale.iWidth,sizeMode.iScreenScale.iHeight,1,1);
sl@0
   241
	iScreenDevice->ChangeScreenDevice(NULL);    //This is necessary to initialise the screen
sl@0
   242
//
sl@0
   243
	// Off Screen Bitmaps
sl@0
   244
	iOffScreenBitmap=CWsOffScreenBitmap::NewL(this);
sl@0
   245
	TSize osbSize(iOffScreenBitmap->Bitmap()->SizeInPixels());
sl@0
   246
	TSize osbTwips(sizeMode.iScreenTwipsSize);
sl@0
   247
	if (osbSize!=sizeMode.iScreenSize)
sl@0
   248
		{
sl@0
   249
		// The specified screen twips size is for the specified screen pixel size, however the OSB
sl@0
   250
		// is potentially larger as it needs to hold the maximum possible screen size, so we need
sl@0
   251
		// to scale the twips size up correspondingly.
sl@0
   252
		osbTwips.iWidth=sizeMode.iScreenTwipsSize.iWidth*osbSize.iWidth/sizeMode.iScreenSize.iWidth;
sl@0
   253
		osbTwips.iHeight=sizeMode.iScreenTwipsSize.iHeight*osbSize.iHeight/sizeMode.iScreenSize.iHeight;
sl@0
   254
		}
sl@0
   255
	iOffScreenBitmap->Bitmap()->SetSizeInTwips(osbTwips);		
sl@0
   256
sl@0
   257
	TInt autoClear = 1;
sl@0
   258
	_LIT(KWSERVIniFileVarAutoClear,"AUTOCLEAR");
sl@0
   259
	WsIniFile->FindVar(iScreenNumber,KWSERVIniFileVarAutoClear,autoClear);
sl@0
   260
	if (autoClear != 0)
sl@0
   261
		{
sl@0
   262
		iFlags|=EAutoClear;
sl@0
   263
		}
sl@0
   264
sl@0
   265
	_LIT(KBackLight,"BACKLIGHTCONTROL");
sl@0
   266
	iBackLightFlag=WsIniFile->FindVar( iScreenNumber, KBackLight);
sl@0
   267
sl@0
   268
	_LIT(KWSERVIniFileVarBlankScreen, "BLANKSCREENONROTATION");
sl@0
   269
	if (WsIniFile->FindVar(iScreenNumber, KWSERVIniFileVarBlankScreen))
sl@0
   270
		{
sl@0
   271
		iFlags|=EBlankScreenOnRotation;
sl@0
   272
		}
sl@0
   273
sl@0
   274
	SetShadowVector(TPoint(EDefaultShadowX,EDefaultShadowY));
sl@0
   275
sl@0
   276
	iRedraw = CScreenRedraw::NewL(*this);
sl@0
   277
sl@0
   278
	iRootWindow = new (ELeave) CWsRootWindow(NULL, this);
sl@0
   279
	iRootWindow->ConstructL();
sl@0
   280
sl@0
   281
	TInt refreshRate = 1000000;
sl@0
   282
	_LIT(KDebugBar, "DEBUGBAR");
sl@0
   283
	if (WsIniFile->FindVar(refreshRate, KDebugBar))
sl@0
   284
		{
sl@0
   285
		if (refreshRate < 100000)
sl@0
   286
			refreshRate = 50000;
sl@0
   287
		const TPoint origin = CurrentScreenModeOrigin();
sl@0
   288
		iDebugBar = CDebugBar::NewL(this, TRect(origin.iX,origin.iY,origin.iX+CurrentScreenSize().iWidth,origin.iY+16), refreshRate);
sl@0
   289
		}
sl@0
   290
	// Default fading parameters
sl@0
   291
	iBlackMap=128;
sl@0
   292
	iWhiteMap=255;
sl@0
   293
	
sl@0
   294
	iSpriteManager = CWsSpriteManager::NewL();
sl@0
   295
	//Look for fading plugins here.
sl@0
   296
	_LIT(KDefaultFaderPluginName, "wsfader");
sl@0
   297
  	_LIT(KFaderPluginIni,"FADER");
sl@0
   298
	CWsPluginManager* mgr = CWsTop::WindowServer()->PluginManager();
sl@0
   299
	if (mgr)
sl@0
   300
		{
sl@0
   301
	  	TPtrC faderName;
sl@0
   302
  		if (WsIniFile->FindVar(iScreenNumber, KFaderPluginIni, faderName))
sl@0
   303
      		iFader = mgr->FindNamedImplementation<MWsFader>(faderName);
sl@0
   304
    	else	
sl@0
   305
		  	iFader = mgr->FindNamedImplementation<MWsFader>(KDefaultFaderPluginName);
sl@0
   306
		}
sl@0
   307
	
sl@0
   308
	_LIT(KBltOffScreenBitmap,"BLTOFFSCREENBITMAP");
sl@0
   309
	if (WsIniFile->FindVar(iScreenNumber, KBltOffScreenBitmap))
sl@0
   310
		{
sl@0
   311
		iFlags|=EBltOffScreenBitmap;
sl@0
   312
		}	
sl@0
   313
	}
sl@0
   314
sl@0
   315
void CScreen::CreateScreenDeviceL()
sl@0
   316
	{
sl@0
   317
	_LIT(KScreenMode,"SCREENMODE");
sl@0
   318
	_LIT(KWindowMode,"WINDOWMODE");
sl@0
   319
	TPtrC screenModeName;
sl@0
   320
	TDisplayMode screenMode = ENone;
sl@0
   321
	if (WsIniFile->FindVar(iScreenNumber, KScreenMode, screenModeName))
sl@0
   322
		{
sl@0
   323
		screenMode = ParseDisplayMode(screenModeName);
sl@0
   324
		}
sl@0
   325
	else if (WsIniFile->FindVar(iScreenNumber, KWindowMode, screenModeName))
sl@0
   326
		{
sl@0
   327
		screenMode = ParseDisplayMode(screenModeName);
sl@0
   328
		}
sl@0
   329
sl@0
   330
	if (screenMode != ENone)
sl@0
   331
		{
sl@0
   332
		if(DoCreateScreenDevice(screenMode))
sl@0
   333
			return;
sl@0
   334
		}
sl@0
   335
sl@0
   336
	// No screen mode was specified, or we failed creating the specified screen
sl@0
   337
	// mode. Default to as high display mode as possible.
sl@0
   338
sl@0
   339
	// Check if the screen device supports 16M colors (it can only support one of
sl@0
   340
	// 16M, 16MU, 16MA, 16MAP, or none of them)
sl@0
   341
	screenMode = CFbsDevice::DisplayMode16M();
sl@0
   342
	if(screenMode != ENone)
sl@0
   343
		{
sl@0
   344
		if(DoCreateScreenDevice(screenMode))
sl@0
   345
			return;
sl@0
   346
		}
sl@0
   347
	
sl@0
   348
	// Try creating the screen device with all available display modes, going from best to worst
sl@0
   349
	__ASSERT_COMPILE(EColorLast == 14); // if any display mode is added to TDisplayMode we must update the list below
sl@0
   350
	// (the list below contains all enums in TDisplayMode except ENone, ERgb, EColorLast)
sl@0
   351
	if(DoCreateScreenDevice(EColor16MAP))
sl@0
   352
		return;
sl@0
   353
	if(DoCreateScreenDevice(EColor16MA))
sl@0
   354
		return;
sl@0
   355
	if(DoCreateScreenDevice(EColor16MU))
sl@0
   356
		return;
sl@0
   357
	if(DoCreateScreenDevice(EColor16M))
sl@0
   358
		return;
sl@0
   359
	if(DoCreateScreenDevice(EColor64K))
sl@0
   360
		return;
sl@0
   361
	if(DoCreateScreenDevice(EColor4K))
sl@0
   362
		return;
sl@0
   363
	if(DoCreateScreenDevice(EColor256))
sl@0
   364
		return;
sl@0
   365
	if(DoCreateScreenDevice(EColor16))
sl@0
   366
		return;
sl@0
   367
	if(DoCreateScreenDevice(EGray256))
sl@0
   368
		return;
sl@0
   369
	if(DoCreateScreenDevice(EGray16))
sl@0
   370
		return;
sl@0
   371
	if(DoCreateScreenDevice(EGray4))
sl@0
   372
		return;
sl@0
   373
	if(DoCreateScreenDevice(EGray2))
sl@0
   374
		return;
sl@0
   375
		
sl@0
   376
	User::Leave(KErrNotSupported);
sl@0
   377
	}
sl@0
   378
sl@0
   379
TBool CScreen::DoCreateScreenDevice(TDisplayMode aScreenMode)
sl@0
   380
	{
sl@0
   381
	TRAPD(err, iScreenDevice = CFbsScreenDevice::NewL(iScreenNumber, aScreenMode));
sl@0
   382
	return (err == KErrNone);
sl@0
   383
	}
sl@0
   384
sl@0
   385
void CScreen::AbortDSAs(RDirectScreenAccess::TTerminationReasons aReason,TSglQue<CWsDirectScreenAccess>& aDirects)
sl@0
   386
	{
sl@0
   387
	if (aDirects.IsEmpty())
sl@0
   388
		return;
sl@0
   389
	TInt nofDSAs = 0;
sl@0
   390
	TSglQueIter<CWsDirectScreenAccess> iter(aDirects);
sl@0
   391
	CWsDirectScreenAccess* direct;
sl@0
   392
	while (( direct=iter++)!=NULL )
sl@0
   393
		{
sl@0
   394
		nofDSAs++;
sl@0
   395
		direct->SignalAbort( aReason );
sl@0
   396
		}
sl@0
   397
sl@0
   398
	TRequestStatus timerStatus;
sl@0
   399
	RTimer& timer=CWsTop::Timer();
sl@0
   400
	timer.Cancel();
sl@0
   401
	
sl@0
   402
	TRequestStatus** cancelReqList = (TRequestStatus**) User::AllocZ( sizeof( TRequestStatus* ) * (nofDSAs + 1)  );  
sl@0
   403
	if ( NULL != cancelReqList  )
sl@0
   404
		{		
sl@0
   405
			TInt dsaNo = 1; 
sl@0
   406
		
sl@0
   407
			timer.After( timerStatus, KDSAAbortingImmediateRespAwaitFrameMicrosec );		
sl@0
   408
sl@0
   409
			iter.SetToFirst();
sl@0
   410
			while (( direct=iter++)!=NULL )
sl@0
   411
				{
sl@0
   412
					cancelReqList[ dsaNo ] =  &direct->AbortStatus();
sl@0
   413
					dsaNo++;
sl@0
   414
				}
sl@0
   415
			cancelReqList[ 0 ] = &timerStatus;
sl@0
   416
			
sl@0
   417
			User::WaitForNRequest( cancelReqList, nofDSAs + 1 );
sl@0
   418
			
sl@0
   419
			iter.SetToFirst();
sl@0
   420
			while (( direct=iter++)!=NULL )
sl@0
   421
				{
sl@0
   422
				if ( direct->AbortStatus() != KRequestPending )
sl@0
   423
					direct->CancelAbortObject(); // responded
sl@0
   424
				else
sl@0
   425
					direct->Abort();
sl@0
   426
				}
sl@0
   427
sl@0
   428
			if (timerStatus == KRequestPending)
sl@0
   429
				{
sl@0
   430
				timer.Cancel();
sl@0
   431
				User::WaitForRequest( timerStatus );
sl@0
   432
				}
sl@0
   433
			
sl@0
   434
			User::Free( cancelReqList );
sl@0
   435
		}
sl@0
   436
	else
sl@0
   437
		{
sl@0
   438
		iter.SetToFirst();
sl@0
   439
		while ((direct=iter++) != NULL)
sl@0
   440
			{
sl@0
   441
		
sl@0
   442
			TRequestStatus timerStatus;
sl@0
   443
			RTimer& timer=CWsTop::Timer();
sl@0
   444
			timer.Cancel();
sl@0
   445
			timer.After(timerStatus, KDSAAbortingImmediateRespAwaitFrameMicrosec);
sl@0
   446
			//wait for response or timeout
sl@0
   447
			User::WaitForRequest(direct->AbortStatus(), timerStatus);
sl@0
   448
		
sl@0
   449
			if (direct->AbortStatus() != KRequestPending)
sl@0
   450
				direct->CancelAbortObject(); //responded
sl@0
   451
			else
sl@0
   452
				direct->Abort(); //timed out
sl@0
   453
sl@0
   454
			if (timerStatus == KRequestPending)
sl@0
   455
				{
sl@0
   456
				timer.Cancel();
sl@0
   457
				User::WaitForRequest(timerStatus);
sl@0
   458
				}
sl@0
   459
			}
sl@0
   460
		}
sl@0
   461
	}
sl@0
   462
sl@0
   463
void CScreen::AbortAllDirectDrawing(RDirectScreenAccess::TTerminationReasons aReason)
sl@0
   464
	{
sl@0
   465
	AbortDSAs(aReason,iDirects);
sl@0
   466
	}
sl@0
   467
sl@0
   468
void CScreen::AddDirect(CWsDirectScreenAccess& aDirect)
sl@0
   469
	{
sl@0
   470
	TBool emptyBefore = iDirects.IsEmpty();
sl@0
   471
	iDirects.AddLast(aDirect);
sl@0
   472
	TBool emptyAfter = iDirects.IsEmpty();
sl@0
   473
	if (emptyBefore && ! emptyAfter)
sl@0
   474
		{
sl@0
   475
		TWsEvent wsevent;
sl@0
   476
		wsevent.SetType(EEventDirectScreenAccessBegin);
sl@0
   477
		*(wsevent.Int()) = iScreenNumber;
sl@0
   478
		TWindowServerEvent::PublishNotification(wsevent);
sl@0
   479
		}
sl@0
   480
sl@0
   481
	if (iDsaDrawState==EDsaDrawStateIdle && aDirect.IsVisible())
sl@0
   482
		{
sl@0
   483
		iDsaDrawState = EDsaDrawStateDrawing;
sl@0
   484
		TWindowServerEvent::NotifyDrawer(TWservCrEvent(TWservCrEvent::EDsaDrawingBegin, iScreenNumber));
sl@0
   485
		}
sl@0
   486
	}
sl@0
   487
sl@0
   488
void CScreen::RemoveDirect(CWsDirectScreenAccess& aDirect)
sl@0
   489
	{
sl@0
   490
	TBool emptyBefore = iDirects.IsEmpty();
sl@0
   491
	iDirects.Remove(aDirect);
sl@0
   492
	TBool emptyAfter = iDirects.IsEmpty();
sl@0
   493
	if (emptyAfter && ! emptyBefore)
sl@0
   494
		{
sl@0
   495
		TWsEvent wsevent;
sl@0
   496
		wsevent.SetType(EEventDirectScreenAccessEnd);
sl@0
   497
		*(wsevent.Int()) = iScreenNumber;
sl@0
   498
		TWindowServerEvent::PublishNotification(wsevent);
sl@0
   499
		}
sl@0
   500
sl@0
   501
	if (iDsaDrawState==EDsaDrawStateDrawing && aDirect.IsVisible() && !HasVisibleDirectOnQueue())
sl@0
   502
		{
sl@0
   503
		iDsaDrawState = EDsaDrawStateIdle;
sl@0
   504
		TWindowServerEvent::NotifyDrawer(TWservCrEvent(TWservCrEvent::EDsaDrawingEnd, iScreenNumber));
sl@0
   505
		}
sl@0
   506
	}
sl@0
   507
sl@0
   508
TBool CScreen::HasVisibleDirectOnQueue()
sl@0
   509
	{
sl@0
   510
	if (iDirects.IsEmpty())
sl@0
   511
		return EFalse;
sl@0
   512
sl@0
   513
	TSglQueIter<CWsDirectScreenAccess> iter(iDirects);
sl@0
   514
	CWsDirectScreenAccess* dsa;
sl@0
   515
	while ((dsa=iter++)!=NULL)
sl@0
   516
		{
sl@0
   517
		if (dsa->IsVisible())
sl@0
   518
			return ETrue;
sl@0
   519
		}
sl@0
   520
sl@0
   521
	return EFalse;
sl@0
   522
	}
sl@0
   523
sl@0
   524
#if defined(_DEBUG)
sl@0
   525
TBool CScreen::IsDirectOnQueue(const CWsDirectScreenAccess* aDirect)
sl@0
   526
	{
sl@0
   527
	TSglQueIter<CWsDirectScreenAccess> iter(iDirects);
sl@0
   528
	CWsDirectScreenAccess* direct;
sl@0
   529
	while ((direct=iter++)!=NULL)
sl@0
   530
		{
sl@0
   531
		if (direct==aDirect)
sl@0
   532
			return ETrue;
sl@0
   533
		}
sl@0
   534
	return EFalse;
sl@0
   535
	}
sl@0
   536
sl@0
   537
#if defined(__WINS__)
sl@0
   538
void CScreen::UpdateOffScreenBitmap()
sl@0
   539
	{
sl@0
   540
	if (iOffScreenBitmap)
sl@0
   541
		iOffScreenBitmap->Update();
sl@0
   542
	}
sl@0
   543
#endif
sl@0
   544
#endif
sl@0
   545
sl@0
   546
void CScreen::KillForegroundSession()
sl@0
   547
	{
sl@0
   548
	if (iCurrentFocus)
sl@0
   549
		{
sl@0
   550
		_LIT(KWSERVKillWinGp,"Killing Session owning Window Group with Id=%d");
sl@0
   551
		if (wsDebugLog)
sl@0
   552
			wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything,KWSERVKillWinGp,iCurrentFocus->Identifier());
sl@0
   553
		iCurrentFocus->WsOwner()->SessionTerminate();
sl@0
   554
		}
sl@0
   555
	}
sl@0
   556
sl@0
   557
CWsWindowGroup* CScreen::FindNewFocus(CWsRootWindow* aRootWindow)
sl@0
   558
	{
sl@0
   559
	CWsWindowGroup* newFocus;
sl@0
   560
	for(newFocus=aRootWindow->Child();newFocus && newFocus->CanReceiveFocus()==EFalse;newFocus=newFocus->NextSibling()) {}
sl@0
   561
sl@0
   562
	return newFocus;
sl@0
   563
	}
sl@0
   564
sl@0
   565
void CScreen::ResetFocus(CWsWindowGroup* aClosingWindow)
sl@0
   566
	{
sl@0
   567
	CWsWindowGroup* oldFocus=iCurrentFocus;
sl@0
   568
	CWsWindowGroup* newFocus=NULL;
sl@0
   569
	CScreen* newFocusedScreen=NULL;
sl@0
   570
	iCurrentFocus=FindNewFocus(iRootWindow);
sl@0
   571
	TBool focusedScreen= EFalse;
sl@0
   572
	/*Focus policy is specified in the wsini.ini file using the keyword 'MULTIFOCUSPOLICY'.
sl@0
   573
	If the keyword is not specified, then the default policy is run.
sl@0
   574
	*/
sl@0
   575
	if(!CWsTop::MultiFocusPolicy())
sl@0
   576
		{
sl@0
   577
		focusedScreen=(this==CWsTop::CurrentFocusScreen()); //check if this screen is the focus screen
sl@0
   578
		if (!iCurrentFocus && focusedScreen)
sl@0
   579
			{
sl@0
   580
			/*If this screen is the focused screen but does not have a focusable window group, then search for the
sl@0
   581
			next screen that has a focusable window group and set that screen as the focused screen.
sl@0
   582
			*/
sl@0
   583
			CScreen* screen=NULL;
sl@0
   584
			TInt screenNo;
sl@0
   585
			for (screenNo=0; screenNo<CWsTop::NumberOfScreens() && !newFocus; ++screenNo)
sl@0
   586
				{
sl@0
   587
				if (screenNo!=iScreenNumber)
sl@0
   588
					{
sl@0
   589
					screen=CWsTop::Screen(screenNo);
sl@0
   590
					newFocus=FindNewFocus(screen->RootWindow());
sl@0
   591
					}
sl@0
   592
				}
sl@0
   593
			if (newFocus)
sl@0
   594
				newFocusedScreen=screen;
sl@0
   595
			}
sl@0
   596
		}
sl@0
   597
	/*Scenario A: multi-focus policy
sl@0
   598
			newFocusedScreen is NULL
sl@0
   599
			focusedScreen is EFalse
sl@0
   600
			CWsTop::MultiFocusPolicy() returns ETrue
sl@0
   601
			Check if the new focusable window group is not the same, send focus lost message to window group
sl@0
   602
			that has just lost focus and send focus gain message to window group that can receive focus.
sl@0
   603
	  Scenario B: single-focus policy (default)
sl@0
   604
			CWsTop::MultiFocusPolicy() returns EFalse
sl@0
   605
			Check if the new focusable window group is not the same or if there is a new focused screen, send focus lost
sl@0
   606
			message to window group that has just lost focus and send focus gain message to window group that can receive focus.
sl@0
   607
	*/
sl@0
   608
	if (iCurrentFocus!=oldFocus || newFocusedScreen)
sl@0
   609
		{
sl@0
   610
		if (oldFocus && (focusedScreen||CWsTop::MultiFocusPolicy()) && oldFocus!=aClosingWindow)
sl@0
   611
			{
sl@0
   612
			oldFocus->LostFocus();
sl@0
   613
			}
sl@0
   614
		if (newFocusedScreen)
sl@0
   615
			{
sl@0
   616
			CWsTop::SetCurrentFocusScreen(newFocusedScreen);
sl@0
   617
			newFocus->ReceivedFocus();
sl@0
   618
			}
sl@0
   619
		else if (iCurrentFocus && (focusedScreen||CWsTop::MultiFocusPolicy()))
sl@0
   620
			{
sl@0
   621
			iCurrentFocus->ReceivedFocus();
sl@0
   622
			}
sl@0
   623
		WsPointer::UpdatePointerCursor();
sl@0
   624
		TWindowServerEvent::SendFocusChangedEvents();
sl@0
   625
		}
sl@0
   626
	TWindowServerEvent::SendGroupListChangedEvents();
sl@0
   627
	}
sl@0
   628
sl@0
   629
void CScreen::SetShadowVector(const TPoint &aShadowShift)
sl@0
   630
	{
sl@0
   631
	iShadowShift=aShadowShift;
sl@0
   632
	}
sl@0
   633
sl@0
   634
void CScreen::RemoveFromDefaultOwningList(CWsWindowGroup *aDestroyedGroup)
sl@0
   635
	{
sl@0
   636
	for (CWsWindowGroup **group=&iDefaultOwningWindow;*group;group=(*group)->NextDefaultOwningWindowPtr())
sl@0
   637
		{
sl@0
   638
		if (*group==aDestroyedGroup)
sl@0
   639
			{
sl@0
   640
			*group=*aDestroyedGroup->NextDefaultOwningWindowPtr();
sl@0
   641
			break;
sl@0
   642
			}
sl@0
   643
		}
sl@0
   644
	}
sl@0
   645
sl@0
   646
void CScreen::SetDefaultOwningWindow(CWsWindowGroup *aGroup)
sl@0
   647
	{
sl@0
   648
	RemoveFromDefaultOwningList(aGroup);
sl@0
   649
	aGroup->SetNextDefaultOwningWindow(iDefaultOwningWindow);
sl@0
   650
	iDefaultOwningWindow=aGroup;
sl@0
   651
	}
sl@0
   652
sl@0
   653
void CScreen::GetScanLine(const TWsSdCmdGetScanLine *aGetScanLine)
sl@0
   654
	{
sl@0
   655
	TRgb buf[EGetScanLineBufLen];
sl@0
   656
	TPtr8 des((TUint8 *)&buf[0],EGetScanLineBufLen*sizeof(TRgb));
sl@0
   657
	TPoint pos(aGetScanLine->pos);
sl@0
   658
	TInt read=0;
sl@0
   659
	TInt len=(des.MaxLength()*EGetScanLineBufLen)/CFbsBitmap::ScanLineLength(EGetScanLineBufLen,aGetScanLine->dispMode);
sl@0
   660
	if (aGetScanLine->len < 0 || (CFbsBitmap::ScanLineLength(aGetScanLine->len, aGetScanLine->dispMode) >
sl@0
   661
									CWsClient::CurrentClient()->ClientMessage().GetDesMaxLength(1)))
sl@0
   662
		{
sl@0
   663
		CWsClient::PanicCurrentClient(EWservPanicInvalidParameter);
sl@0
   664
		}
sl@0
   665
	FOREVER
sl@0
   666
		{
sl@0
   667
		if ((aGetScanLine->len-read)<len)
sl@0
   668
			len=aGetScanLine->len-read;
sl@0
   669
		iScreenDevice->GetScanLine(des,pos,len,aGetScanLine->dispMode);
sl@0
   670
		CWsClient::ReplyBuf(des);
sl@0
   671
		read+=len;
sl@0
   672
		if (read==aGetScanLine->len)
sl@0
   673
			break;
sl@0
   674
		pos.iX+=len;
sl@0
   675
		}
sl@0
   676
	}
sl@0
   677
sl@0
   678
void CScreen::MaxNumColors(TInt& aColors,TInt& aGrays)
sl@0
   679
	{
sl@0
   680
	aGrays=0;
sl@0
   681
	aColors=TDisplayModeUtils::NumDisplayModeColors(DisplayMode());
sl@0
   682
	if (!TDisplayModeUtils::IsDisplayModeColor(DisplayMode()))
sl@0
   683
		{
sl@0
   684
		aGrays=aColors;
sl@0
   685
		aColors=0;
sl@0
   686
		}
sl@0
   687
	}
sl@0
   688
sl@0
   689
#define MODE_TO_FLAG(x) 1<<(x-1)
sl@0
   690
#define ROTATION_TO_FLAG(x) 1<<x
sl@0
   691
TInt CScreen::ColorModesFlag()
sl@0
   692
	{
sl@0
   693
	return MODE_TO_FLAG(DisplayMode());
sl@0
   694
	}
sl@0
   695
sl@0
   696
void CScreen::Update()
sl@0
   697
	{
sl@0
   698
#if defined(__WINS__) && defined(_DEBUG)
sl@0
   699
	if (iOffScreenBitmap)
sl@0
   700
		iOffScreenBitmap->Update();
sl@0
   701
#endif
sl@0
   702
sl@0
   703
	if (iRedirectGc)
sl@0
   704
		TWindowServerEvent::NotifyDrawer(TWservCrEvent(TWservCrEvent::EScreenUpdated, iScreenNumber));
sl@0
   705
	else
sl@0
   706
		iScreenDevice->Update();
sl@0
   707
	}
sl@0
   708
sl@0
   709
void CScreen::UpdateGcs()
sl@0
   710
	{
sl@0
   711
	iScreenGdi->Activate(iScreenDevice);
sl@0
   712
	}
sl@0
   713
sl@0
   714
void CScreen::ChangeDisplayModeForAllOffScreenBitmap(TBool aSwapWidthAndHeight/*=EFalse*/)
sl@0
   715
	{
sl@0
   716
	TInt err;
sl@0
   717
	if (iOffScreenBitmap)
sl@0
   718
		{
sl@0
   719
		err=iOffScreenBitmap->DisplayModeChanged(aSwapWidthAndHeight);
sl@0
   720
		if(err!=KErrNone)
sl@0
   721
			{
sl@0
   722
			delete iOffScreenBitmap;
sl@0
   723
			iOffScreenBitmap=NULL;
sl@0
   724
			}
sl@0
   725
		}
sl@0
   726
	}
sl@0
   727
sl@0
   728
CFbsScreenDevice *CScreen::ScreenDevice()
sl@0
   729
	{
sl@0
   730
	return(iScreenDevice);
sl@0
   731
	}
sl@0
   732
sl@0
   733
void CScreen::UpdateOrientation()
sl@0
   734
	{
sl@0
   735
	CFbsBitGc::TGraphicsOrientation orientation=Orientation();
sl@0
   736
	iScreenGdi->SetOrientation(orientation);
sl@0
   737
	TWservCrEvent crEvent(TWservCrEvent::EScreenOrientationChanged,iScreenNumber,&orientation);
sl@0
   738
	TWindowServerEvent::NotifyDrawer(crEvent);
sl@0
   739
	}
sl@0
   740
sl@0
   741
void CScreen::SetPointerCursorArea(TInt aMode,const TRect& aRect)
sl@0
   742
	{
sl@0
   743
	(*iModes)[aMode]->iPointerCursorArea=aRect;
sl@0
   744
	WsPointer::SetPointerCursorPos(WsPointer::PointerCursorPos());
sl@0
   745
	}
sl@0
   746
sl@0
   747
CFbsBitGc::TGraphicsOrientation CScreen::Orientation()
sl@0
   748
	{
sl@0
   749
  	WS_ASSERT_DEBUG(IsValidScreenSizeMode(iScreenSizeMode),EWsPanicInvalidScreenSizeMode);
sl@0
   750
	return (*iModes)[iScreenSizeMode]->iRotation;
sl@0
   751
	}
sl@0
   752
sl@0
   753
TRect CScreen::DrawableArea() const
sl@0
   754
	{
sl@0
   755
	TRect drawRect;
sl@0
   756
	iScreenDevice->GetDrawRect(drawRect);
sl@0
   757
	return drawRect;
sl@0
   758
	}
sl@0
   759
sl@0
   760
TClientPanic CScreen::SetModeRotation(TInt aMode,CFbsBitGc::TGraphicsOrientation aRotation)
sl@0
   761
	{
sl@0
   762
	if (!IsValidScreenSizeMode(aMode))
sl@0
   763
		return EWservPanicScreenModeNumber;
sl@0
   764
	TSizeMode& mode=*(*iModes)[aMode];
sl@0
   765
	if (!(ROTATION_TO_FLAG(aRotation)&mode.iAlternativeRotations))
sl@0
   766
		return EWservPanicRotation;
sl@0
   767
	TInt oldRotation=mode.iRotation;
sl@0
   768
	mode.iRotation=aRotation;
sl@0
   769
	CWsWindowGroup::NewOrientation(aMode,aRotation, iRootWindow);
sl@0
   770
	if (aMode==ScreenSizeMode())
sl@0
   771
		{
sl@0
   772
		UpdateOrientation();
sl@0
   773
		TBool shouldSwapWidthAndHeight=ShouldSwapWidthAndHeightOffScBitmap(oldRotation);
sl@0
   774
		ChangeDisplayModeForAllOffScreenBitmap(shouldSwapWidthAndHeight);
sl@0
   775
		iRootWindow->OrientationChanged();
sl@0
   776
		}
sl@0
   777
	return EWservNoPanic;
sl@0
   778
	}
sl@0
   779
sl@0
   780
void CScreen::CycleDisplaySize()
sl@0
   781
	{
sl@0
   782
	TInt newMode = iScreenSizeMode;
sl@0
   783
	TSizeMode* sizeMode = NULL;
sl@0
   784
	do
sl@0
   785
		{
sl@0
   786
		newMode = (newMode+1)%iModes->Count();
sl@0
   787
		sizeMode = (*iModes)[newMode];
sl@0
   788
		}
sl@0
   789
	while (sizeMode==NULL);
sl@0
   790
	doSetScreenMode(newMode);
sl@0
   791
	}
sl@0
   792
sl@0
   793
inline TBool CScreen::ShouldSwapWidthAndHeightOffScBitmap(TInt aOldRotation)
sl@0
   794
	{
sl@0
   795
	TInt rot=Abs((*iModes)[iScreenSizeMode]->iRotation-aOldRotation);
sl@0
   796
	return (rot==1||rot==3);
sl@0
   797
	}
sl@0
   798
sl@0
   799
void CScreen::doSetScreenMode(TInt aMode)
sl@0
   800
	{
sl@0
   801
  	WS_ASSERT_DEBUG(IsValidScreenSizeMode(aMode),EWsPanicInvalidScreenSizeMode);
sl@0
   802
sl@0
   803
	TWindowServerEvent::NotifyDrawer(TWservCrEvent(TWservCrEvent::EScreenSizeModeAboutToChange, aMode));
sl@0
   804
sl@0
   805
	TInt oldRotation=(*iModes)[iScreenSizeMode]->iRotation;
sl@0
   806
	iScreenSizeMode=aMode;
sl@0
   807
	TBool shouldSwapWidthAndHeight=ShouldSwapWidthAndHeightOffScBitmap(oldRotation);
sl@0
   808
	CWsWindowGroup::SetScreenDeviceValidStates(ETrue,shouldSwapWidthAndHeight,this);
sl@0
   809
	if (shouldSwapWidthAndHeight)
sl@0
   810
		{
sl@0
   811
		SetPhysicalScreenSize();
sl@0
   812
		}
sl@0
   813
	TWindowServerEvent::SendScreenDeviceChangedEvents(this);
sl@0
   814
	ResetFocus(NULL);
sl@0
   815
	}
sl@0
   816
sl@0
   817
void CScreen::UpdateOffScreenBitmapGc(const TBool aSwapWidthAndHeight)
sl@0
   818
	{
sl@0
   819
	if (iOffScreenBitmap)
sl@0
   820
		{
sl@0
   821
		iOffScreenBitmap->UpdateGc(aSwapWidthAndHeight);
sl@0
   822
		}
sl@0
   823
	}
sl@0
   824
sl@0
   825
void CScreen::CycleOrientation()
sl@0
   826
	{
sl@0
   827
  	WS_ASSERT_DEBUG(IsValidScreenSizeMode(iScreenSizeMode),EWsPanicInvalidScreenSizeMode);
sl@0
   828
	TSizeMode& currentSizeMode=*(*iModes)[iScreenSizeMode];
sl@0
   829
	TUint rotations=currentSizeMode.iAlternativeRotations;
sl@0
   830
	TInt currentRotation=currentSizeMode.iRotation;
sl@0
   831
	TInt rotation=currentRotation+1;
sl@0
   832
	while (rotation!=currentRotation)
sl@0
   833
		{
sl@0
   834
		if (rotation>CFbsBitGc::EGraphicsOrientationRotated270)
sl@0
   835
			rotation=CFbsBitGc::EGraphicsOrientationNormal;
sl@0
   836
		if (ROTATION_TO_FLAG(rotation)&rotations)
sl@0
   837
			break;
sl@0
   838
		++rotation;
sl@0
   839
		}
sl@0
   840
	if (rotation==currentRotation)
sl@0
   841
		{
sl@0
   842
		if (rotation>CFbsBitGc::EGraphicsOrientationRotated90)
sl@0
   843
			rotation-=2;
sl@0
   844
		else
sl@0
   845
			rotation+=2;
sl@0
   846
		}
sl@0
   847
	currentSizeMode.iRotation=REINTERPRET_CAST(CFbsBitGc::TGraphicsOrientation&,rotation);
sl@0
   848
	CWsWindowGroup::NewOrientation(iScreenSizeMode,currentSizeMode.iRotation, iRootWindow);
sl@0
   849
sl@0
   850
	UpdateOrientation();
sl@0
   851
	TBool shouldSwapWidthAndHeight=ShouldSwapWidthAndHeightOffScBitmap(currentRotation);
sl@0
   852
	ChangeDisplayModeForAllOffScreenBitmap(shouldSwapWidthAndHeight);
sl@0
   853
	if (shouldSwapWidthAndHeight)
sl@0
   854
		{
sl@0
   855
		SetPhysicalScreenSize();
sl@0
   856
		}
sl@0
   857
	iRootWindow->OrientationChanged();
sl@0
   858
	}
sl@0
   859
sl@0
   860
TPoint CScreen::PhysicalToLogical(TPoint aPhysicalPt)
sl@0
   861
	{
sl@0
   862
	const TSizeMode& mode=ScreenSizeModeData();
sl@0
   863
	TPoint logicalPt;
sl@0
   864
	logicalPt=aPhysicalPt-mode.iOrigin;
sl@0
   865
	if (mode.iScreenScale.iWidth!=1)
sl@0
   866
		logicalPt.iX=(logicalPt.iX>=0 ? logicalPt.iX/mode.iScreenScale.iWidth : (logicalPt.iX-(mode.iScreenScale.iWidth-1))/mode.iScreenScale.iWidth);
sl@0
   867
	if (mode.iScreenScale.iHeight!=1)
sl@0
   868
		logicalPt.iY=(logicalPt.iY>=0 ? logicalPt.iY/mode.iScreenScale.iHeight : (logicalPt.iY-(mode.iScreenScale.iHeight-1))/mode.iScreenScale.iHeight);
sl@0
   869
	return logicalPt;
sl@0
   870
	}
sl@0
   871
sl@0
   872
void CScreen::LoadScreenSizesL(TSize aScreenSize)
sl@0
   873
	{
sl@0
   874
	_LIT(KWSERVNumScrSizeMode, "NUMSCREENMODES");
sl@0
   875
	TBool allowScrGap=WsIniFile->FindVar(iScreenNumber, KWSERVNumScrSizeMode, iNumScreenSizeModes);
sl@0
   876
	iModes=new(ELeave) RPointerArray<TSizeMode>(1);
sl@0
   877
	WS_ASSERT_DEBUG(!allowScrGap || (allowScrGap && iNumScreenSizeModes>0), EWsPanicInvalidScreenSizeMode);
sl@0
   878
	TInt screenNum=0;
sl@0
   879
	FOREVER
sl@0
   880
		{
sl@0
   881
		++screenNum;
sl@0
   882
		TBuf<32> varNameWidth;
sl@0
   883
		TBuf<32> varNameHeight;
sl@0
   884
		_LIT(KWSERVScreenWidthPattern,"SCR_WIDTH%d");
sl@0
   885
		varNameWidth.Format(KWSERVScreenWidthPattern,screenNum);
sl@0
   886
		_LIT(KWSERVScreenHeightPattern,"SCR_HEIGHT%d");
sl@0
   887
		varNameHeight.Format(KWSERVScreenHeightPattern,screenNum);
sl@0
   888
		TSize screenSize;
sl@0
   889
		if (!WsIniFile->FindVar(iScreenNumber, varNameWidth, screenSize.iWidth) ||
sl@0
   890
			!WsIniFile->FindVar(iScreenNumber, varNameHeight, screenSize.iHeight))
sl@0
   891
			{
sl@0
   892
			if (allowScrGap && screenNum<=iNumScreenSizeModes)
sl@0
   893
				{
sl@0
   894
				iModes->AppendL(NULL);
sl@0
   895
				continue;
sl@0
   896
				}
sl@0
   897
			else
sl@0
   898
				break;
sl@0
   899
			}
sl@0
   900
		if (screenSize.iWidth==0 && screenSize.iHeight==0)
sl@0
   901
			screenSize=aScreenSize;
sl@0
   902
		TSizeMode* newSizeMode=new(ELeave) TSizeMode(screenSize);
sl@0
   903
		CleanupStack::PushL(newSizeMode);
sl@0
   904
		iModes->AppendL(newSizeMode);
sl@0
   905
		CleanupStack::Pop(newSizeMode);
sl@0
   906
		++iNumSupportedScreenSizeModes;
sl@0
   907
		}
sl@0
   908
	// If sparse index is enabled and no screen size mode defined, all iModes entries will be NULL
sl@0
   909
	// Otherwise iModes will be empty
sl@0
   910
	if (iModes->Count()==0 || iNumSupportedScreenSizeModes==0)
sl@0
   911
		{
sl@0
   912
		TSizeMode* defaultSizeMode=new(ELeave) TSizeMode(aScreenSize);
sl@0
   913
		if (iModes->Count()>0)
sl@0
   914
			(*iModes)[0]=defaultSizeMode;
sl@0
   915
		else
sl@0
   916
			{
sl@0
   917
			CleanupStack::PushL(defaultSizeMode);
sl@0
   918
			iModes->AppendL(defaultSizeMode);
sl@0
   919
			CleanupStack::Pop(defaultSizeMode);
sl@0
   920
			}
sl@0
   921
		++iNumSupportedScreenSizeModes;
sl@0
   922
		}
sl@0
   923
	if (!allowScrGap)
sl@0
   924
		iNumScreenSizeModes=iNumSupportedScreenSizeModes;
sl@0
   925
	}
sl@0
   926
sl@0
   927
void CScreen::LoadScreenSizeProperties()
sl@0
   928
	{
sl@0
   929
	TBool orientations[4];
sl@0
   930
	TUint allowableRotations=0;
sl@0
   931
	TInt ii;
sl@0
   932
	iScreenGdi->OrientationsAvailable(orientations);
sl@0
   933
	for (ii=0;ii<4;++ii)
sl@0
   934
		{
sl@0
   935
		if (orientations[ii])
sl@0
   936
			allowableRotations|=ROTATION_TO_FLAG(ii);
sl@0
   937
		}
sl@0
   938
	TBuf<32> xScale;
sl@0
   939
	TBuf<32> yScale;
sl@0
   940
	_LIT(KWSERVScreenXScale,"SCR_XSCALE%d");
sl@0
   941
	_LIT(KWSERVScreenYScale,"SCR_YSCALE%d");
sl@0
   942
	for(TInt sizeLoop=0;sizeLoop<iModes->Count();sizeLoop++)
sl@0
   943
		{
sl@0
   944
		TSizeMode* modePtr=(*iModes)[sizeLoop];
sl@0
   945
		if (!modePtr)
sl@0
   946
			continue;
sl@0
   947
		TSizeMode& mode=*modePtr;
sl@0
   948
		TBuf<32> varLeft;
sl@0
   949
		TBuf<32> varTop;
sl@0
   950
		TBuf<32> varRotation;
sl@0
   951
		TBuf<32> varNameWidth;
sl@0
   952
		TBuf<32> varNameHeight;
sl@0
   953
		TBuf<32> varDisplayMode;
sl@0
   954
		_LIT(KWSERVScreenLeftPattern,"SCR_LEFT%d");
sl@0
   955
		varLeft.Format(KWSERVScreenLeftPattern,sizeLoop+1);
sl@0
   956
		_LIT(KWSERVScreenTopPattern,"SCR_TOP%d");
sl@0
   957
		varTop.Format(KWSERVScreenTopPattern,sizeLoop+1);
sl@0
   958
		_LIT(KWSERVScreenRotationPattern,"SCR_ROTATION%d");
sl@0
   959
		varRotation.Format(KWSERVScreenRotationPattern,sizeLoop+1);
sl@0
   960
		_LIT(KWSERVScreenTwipWidthPattern,"SCR_TWIP_WIDTH%d");
sl@0
   961
		varNameWidth.Format(KWSERVScreenTwipWidthPattern,sizeLoop+1);
sl@0
   962
		_LIT(KWSERVScreenTwipHeightPattern,"SCR_TWIP_HEIGHT%d");
sl@0
   963
		varNameHeight.Format(KWSERVScreenTwipHeightPattern,sizeLoop+1);
sl@0
   964
		_LIT(KWSERVScreenDisplayModePattern,"SCR_WINDOWMODE%d");
sl@0
   965
		varDisplayMode.Format(KWSERVScreenDisplayModePattern,sizeLoop+1);
sl@0
   966
		xScale.Format(KWSERVScreenXScale,sizeLoop+1);
sl@0
   967
		yScale.Format(KWSERVScreenYScale,sizeLoop+1);
sl@0
   968
		if (!WsIniFile->FindVar(iScreenNumber,xScale,mode.iScreenScale.iWidth))
sl@0
   969
			{
sl@0
   970
			mode.iScreenScale.iWidth=1;
sl@0
   971
			}
sl@0
   972
		if (!WsIniFile->FindVar(iScreenNumber,yScale,mode.iScreenScale.iHeight))
sl@0
   973
			{
sl@0
   974
			mode.iScreenScale.iHeight=1;
sl@0
   975
			}
sl@0
   976
		if (!WsIniFile->FindVar( iScreenNumber, varLeft,mode.iOrigin.iX))
sl@0
   977
			{
sl@0
   978
			mode.iOrigin.iX=0;
sl@0
   979
			}
sl@0
   980
		if (!WsIniFile->FindVar( iScreenNumber, varTop,mode.iOrigin.iY))
sl@0
   981
			{
sl@0
   982
			mode.iOrigin.iY=0;
sl@0
   983
			}
sl@0
   984
		TPtrC displayModeName(NULL,0);
sl@0
   985
		mode.iDefaultDisplayMode = iScreenDevice->DisplayMode();
sl@0
   986
		TInt rotation=CFbsBitGc::EGraphicsOrientationNormal;
sl@0
   987
		TUint allRotations=0;
sl@0
   988
		TPtrC rotList(NULL,0);
sl@0
   989
		if (WsIniFile->FindVar( iScreenNumber, varRotation,rotList))
sl@0
   990
			{
sl@0
   991
			TLex lex(rotList);
sl@0
   992
			TBool foundOne=EFalse;
sl@0
   993
			TInt rot;
sl@0
   994
sl@0
   995
			while (!lex.Eos())
sl@0
   996
				{
sl@0
   997
				if (!FindNextValue(lex, rot))
sl@0
   998
					{
sl@0
   999
					break;
sl@0
  1000
					}
sl@0
  1001
				if (rot<0 || rot>360)
sl@0
  1002
					{
sl@0
  1003
					continue;
sl@0
  1004
					}
sl@0
  1005
				if (rot>4)
sl@0
  1006
					{
sl@0
  1007
					rot/=90;
sl@0
  1008
					}
sl@0
  1009
				if (!foundOne)
sl@0
  1010
					{
sl@0
  1011
					rotation=rot;
sl@0
  1012
					foundOne=ETrue;
sl@0
  1013
					}
sl@0
  1014
				if (rot<=CFbsBitGc::EGraphicsOrientationRotated270)
sl@0
  1015
					{
sl@0
  1016
					allRotations|=ROTATION_TO_FLAG(rot);
sl@0
  1017
					}
sl@0
  1018
				}
sl@0
  1019
			}
sl@0
  1020
		if (allRotations==0)
sl@0
  1021
			allRotations=ROTATION_TO_FLAG(rotation);
sl@0
  1022
		WS_ASSERT_ALWAYS((ROTATION_TO_FLAG(rotation)&allowableRotations)>0, EWsPanicFailedToInitialise);
sl@0
  1023
		mode.iRotation=(CFbsBitGc::TGraphicsOrientation&)rotation;
sl@0
  1024
		mode.iAlternativeRotations=allRotations & allowableRotations;
sl@0
  1025
		
sl@0
  1026
		TSize twipsSize;
sl@0
  1027
		TSize pixels(mode.iScreenSize);
sl@0
  1028
		
sl@0
  1029
		switch(mode.iRotation)
sl@0
  1030
			{
sl@0
  1031
			// CFbsBitGc::TGraphicsOrientation
sl@0
  1032
			case CFbsBitGc::EGraphicsOrientationRotated90:
sl@0
  1033
			case CFbsBitGc::EGraphicsOrientationRotated270:
sl@0
  1034
				{
sl@0
  1035
				//swap the axes in order to use the correct twips per pixel ratio, as CFbsScreenDevice
sl@0
  1036
				//does not take into consideration rotation, when converting pixels to twips
sl@0
  1037
				if (!WsIniFile->FindVar( iScreenNumber, varNameWidth,twipsSize.iWidth))
sl@0
  1038
					twipsSize.iWidth=iScreenDevice->VerticalPixelsToTwips(pixels.iWidth);
sl@0
  1039
				if (!WsIniFile->FindVar( iScreenNumber, varNameHeight,twipsSize.iHeight))
sl@0
  1040
					twipsSize.iHeight=iScreenDevice->HorizontalPixelsToTwips(pixels.iHeight);
sl@0
  1041
				break;
sl@0
  1042
				}
sl@0
  1043
			case CFbsBitGc::EGraphicsOrientationNormal:
sl@0
  1044
			case CFbsBitGc::EGraphicsOrientationRotated180:
sl@0
  1045
				{
sl@0
  1046
				if (!WsIniFile->FindVar( iScreenNumber, varNameWidth,twipsSize.iWidth))
sl@0
  1047
					twipsSize.iWidth=iScreenDevice->HorizontalPixelsToTwips(pixels.iWidth);
sl@0
  1048
				if (!WsIniFile->FindVar( iScreenNumber, varNameHeight,twipsSize.iHeight))
sl@0
  1049
					twipsSize.iHeight=iScreenDevice->VerticalPixelsToTwips(pixels.iHeight);
sl@0
  1050
				break;
sl@0
  1051
				}
sl@0
  1052
			default:
sl@0
  1053
				WS_PANIC_ALWAYS(EWsPanicFailedToInitialise);
sl@0
  1054
				break;			
sl@0
  1055
			}
sl@0
  1056
		mode.iScreenTwipsSize=twipsSize;
sl@0
  1057
		}
sl@0
  1058
//
sl@0
  1059
	TInt intForFindVar=0;
sl@0
  1060
	_LIT(KWSERVIniFileVarSizeMode,"SIZE_MODE");
sl@0
  1061
	WsIniFile->FindVar( iScreenNumber, KWSERVIniFileVarSizeMode,intForFindVar);
sl@0
  1062
	iSizeEnforcementMode=(TScreenModeEnforcement)intForFindVar;
sl@0
  1063
	}
sl@0
  1064
sl@0
  1065
void CScreen::SetDigitiserAreas(const TSize& aScreenSize,const TRect& aDigitiserArea)
sl@0
  1066
	{
sl@0
  1067
	for(TInt sizeLoop=0;sizeLoop<iModes->Count();sizeLoop++)
sl@0
  1068
		{
sl@0
  1069
		TSizeMode* modePtr=(*iModes)[sizeLoop];
sl@0
  1070
		if (!modePtr)
sl@0
  1071
			continue;
sl@0
  1072
		TSizeMode& mode=*modePtr;
sl@0
  1073
		switch (mode.iRotation)
sl@0
  1074
			{
sl@0
  1075
			case CFbsBitGc::EGraphicsOrientationNormal:
sl@0
  1076
				mode.iPointerCursorArea=aDigitiserArea;
sl@0
  1077
				continue;
sl@0
  1078
			case CFbsBitGc::EGraphicsOrientationRotated90:
sl@0
  1079
				mode.iPointerCursorArea.SetRect(aDigitiserArea.iTl.iY,aScreenSize.iWidth-aDigitiserArea.iBr.iX,
sl@0
  1080
																aDigitiserArea.iBr.iY,aScreenSize.iWidth-aDigitiserArea.iTl.iX);
sl@0
  1081
				break;
sl@0
  1082
			case CFbsBitGc::EGraphicsOrientationRotated180:
sl@0
  1083
				mode.iPointerCursorArea.SetRect(-(aDigitiserArea.iBr-aScreenSize),-(aDigitiserArea.iTl-aScreenSize));
sl@0
  1084
				break;
sl@0
  1085
			case CFbsBitGc::EGraphicsOrientationRotated270:
sl@0
  1086
				mode.iPointerCursorArea.SetRect(aScreenSize.iHeight-aDigitiserArea.iBr.iY,aDigitiserArea.iTl.iX,
sl@0
  1087
																aScreenSize.iHeight-aDigitiserArea.iTl.iY,aDigitiserArea.iBr.iX);
sl@0
  1088
				break;
sl@0
  1089
			}
sl@0
  1090
		}
sl@0
  1091
	}
sl@0
  1092
sl@0
  1093
void CScreen::GetScreenSizeAndRotation(TPixelsTwipsAndRotation &aSar, TInt aScreenMode)
sl@0
  1094
	{
sl@0
  1095
	TSizeMode& mode=*(*iModes)[aScreenMode];
sl@0
  1096
	aSar.iRotation=mode.iRotation;
sl@0
  1097
	aSar.iPixelSize=mode.iScreenSize;
sl@0
  1098
	aSar.iTwipsSize=mode.iScreenTwipsSize;
sl@0
  1099
	if (aSar.iTwipsSize.iWidth==0)
sl@0
  1100
		{
sl@0
  1101
		aSar.iTwipsSize.iWidth=iScreenDevice->HorizontalPixelsToTwips(aSar.iPixelSize.iWidth);
sl@0
  1102
		aSar.iTwipsSize.iHeight=iScreenDevice->VerticalPixelsToTwips(aSar.iPixelSize.iHeight);
sl@0
  1103
		}
sl@0
  1104
	}
sl@0
  1105
sl@0
  1106
void CScreen::GetScreenSizeAndRotation(TPixelsAndRotation &aSar, TInt aScreenMode)
sl@0
  1107
	{
sl@0
  1108
	TSizeMode& mode=*(*iModes)[aScreenMode];
sl@0
  1109
	aSar.iRotation=mode.iRotation;
sl@0
  1110
	aSar.iPixelSize=mode.iScreenSize;
sl@0
  1111
	}
sl@0
  1112
sl@0
  1113
TBool CScreen::SetScreenModeEnforcement(TInt aMode)
sl@0
  1114
	{
sl@0
  1115
	if (aMode<0 || aMode>ESizeEnforcementPixelsTwipsAndRotation)
sl@0
  1116
		return EFalse;
sl@0
  1117
	TScreenModeEnforcement newMode=(TScreenModeEnforcement)aMode;
sl@0
  1118
	if (newMode!=iSizeEnforcementMode)
sl@0
  1119
		{
sl@0
  1120
		iSizeEnforcementMode=newMode;
sl@0
  1121
		CWsWindowGroup::SetScreenDeviceValidStates(EFalse,EFalse,this);
sl@0
  1122
		ResetFocus(NULL);
sl@0
  1123
		}
sl@0
  1124
	return ETrue;
sl@0
  1125
	}
sl@0
  1126
sl@0
  1127
CWsOffScreenBitmap* CScreen::OffScreenBitmap()
sl@0
  1128
	{
sl@0
  1129
	return iOffScreenBitmap;
sl@0
  1130
	}
sl@0
  1131
sl@0
  1132
CFbsDevice * CScreen::DrawDevice()
sl@0
  1133
	{
sl@0
  1134
	if (iOffScreenBitmap)
sl@0
  1135
		return iOffScreenBitmap->BitmapDevice();
sl@0
  1136
	else
sl@0
  1137
		return ScreenDevice();
sl@0
  1138
	}
sl@0
  1139
sl@0
  1140
void CScreen::FreeOffScreenBitmap()
sl@0
  1141
	{
sl@0
  1142
	// for Flicker Free test
sl@0
  1143
	/** Andy - this either needs to talk to render stages or simply be removed.
sl@0
  1144
	Deleting the OSB when CRPs already know it exists is one thing - we dont do it while
sl@0
  1145
	testing ones that can't cope - deleting it when render stages use it is something else.
sl@0
  1146
	Fortunately we never actually use it.
sl@0
  1147
	if (iOffScreenBitmap)
sl@0
  1148
		{
sl@0
  1149
		delete iOffScreenBitmap;
sl@0
  1150
		iOffScreenBitmap = NULL;
sl@0
  1151
		}
sl@0
  1152
	*/
sl@0
  1153
	}
sl@0
  1154
sl@0
  1155
void CScreen::IncContrast()
sl@0
  1156
	{
sl@0
  1157
	TInt contrast;
sl@0
  1158
	if (iMaxContrast<0)			//If failed to get it sofar get it again
sl@0
  1159
		TWindowServerEvent::ProcessErrorMessages(TWsErrorMessage::EContrast, HAL::Get(iScreenNumber,HALData::EDisplayContrastMax,iMaxContrast));
sl@0
  1160
	if (TWindowServerEvent::ProcessErrorMessages(TWsErrorMessage::EContrast, HAL::Get(iScreenNumber,HALData::EDisplayContrast,contrast)))
sl@0
  1161
		return;
sl@0
  1162
	if (contrast==iMaxContrast)
sl@0
  1163
		contrast=-1;
sl@0
  1164
	TWindowServerEvent::ProcessErrorMessages(TWsErrorMessage::EContrast, HAL::Set(iScreenNumber,HALData::EDisplayContrast,++contrast));
sl@0
  1165
	}
sl@0
  1166
sl@0
  1167
void CScreen::DecContrast()
sl@0
  1168
	{
sl@0
  1169
	TInt contrast;
sl@0
  1170
	if (TWindowServerEvent::ProcessErrorMessages(TWsErrorMessage::EContrast, HAL::Get(iScreenNumber,HALData::EDisplayContrast,contrast)))
sl@0
  1171
		return;
sl@0
  1172
	if (contrast==0)
sl@0
  1173
		{
sl@0
  1174
		if (iMaxContrast<0 && TWindowServerEvent::ProcessErrorMessages(TWsErrorMessage::EContrast,
sl@0
  1175
															HAL::Get(iScreenNumber,HALData::EDisplayContrastMax,iMaxContrast)))
sl@0
  1176
			return;
sl@0
  1177
		contrast=iMaxContrast+1;
sl@0
  1178
		}
sl@0
  1179
	TWindowServerEvent::ProcessErrorMessages(TWsErrorMessage::EContrast, HAL::Set(iScreenNumber,HALData::EDisplayContrast,--contrast));
sl@0
  1180
	}
sl@0
  1181
sl@0
  1182
void CScreen::IncBrightness()
sl@0
  1183
	{
sl@0
  1184
	TInt brightness;
sl@0
  1185
	if (iMaxBrightness<0)			//If failed to get it sofar get it again
sl@0
  1186
		TWindowServerEvent::ProcessErrorMessages(TWsErrorMessage::EBackLight, HAL::Get(iScreenNumber,HALData::EDisplayBrightnessMax,iMaxBrightness));
sl@0
  1187
	if (TWindowServerEvent::ProcessErrorMessages(TWsErrorMessage::EBackLight, HAL::Get(iScreenNumber,HALData::EDisplayBrightness,brightness)))
sl@0
  1188
		return;
sl@0
  1189
	if (brightness==iMaxBrightness)
sl@0
  1190
		brightness=-1;
sl@0
  1191
	TWindowServerEvent::ProcessErrorMessages(TWsErrorMessage::EBackLight, HAL::Set(iScreenNumber,HALData::EDisplayBrightness,++brightness));
sl@0
  1192
	}
sl@0
  1193
sl@0
  1194
void CScreen::DecBrightness()
sl@0
  1195
	{
sl@0
  1196
	TInt brightness;
sl@0
  1197
	if (TWindowServerEvent::ProcessErrorMessages(TWsErrorMessage::EBackLight, HAL::Get(iScreenNumber,HALData::EDisplayBrightness,brightness)))
sl@0
  1198
		return;
sl@0
  1199
	if (brightness==0)
sl@0
  1200
		{
sl@0
  1201
		if (iMaxBrightness<0 && TWindowServerEvent::ProcessErrorMessages(TWsErrorMessage::EBackLight,
sl@0
  1202
													HAL::Get(iScreenNumber,HALData::EDisplayBrightnessMax,iMaxBrightness)))
sl@0
  1203
			return;
sl@0
  1204
		brightness=iMaxBrightness+1;
sl@0
  1205
		}
sl@0
  1206
	TWindowServerEvent::ProcessErrorMessages(TWsErrorMessage::EBackLight, HAL::Set(iScreenNumber,HALData::EDisplayBrightness,--brightness));
sl@0
  1207
	}
sl@0
  1208
sl@0
  1209
TInt CScreen::GetScreenSizeModeListL()
sl@0
  1210
	{
sl@0
  1211
	RArray<TInt> list(iNumScreenSizeModes);
sl@0
  1212
	CleanupClosePushL(list);
sl@0
  1213
	TInt index;
sl@0
  1214
	for (index=0; index<iModes->Count(); ++index)
sl@0
  1215
		{
sl@0
  1216
		TSizeMode* modePtr=(*iModes)[index];
sl@0
  1217
		if (modePtr)
sl@0
  1218
			list.AppendL(index);
sl@0
  1219
		}
sl@0
  1220
	TInt count=list.Count();
sl@0
  1221
	CWsClient::ReplyBuf(&list[0], count*sizeof(TInt));
sl@0
  1222
	CleanupStack::PopAndDestroy(&list);
sl@0
  1223
	return count;
sl@0
  1224
	}
sl@0
  1225
sl@0
  1226
void CScreen::SetInitialScreenSizeMode()
sl@0
  1227
	{
sl@0
  1228
	// get first/lowest valid screen size mode, if mode 0 not available
sl@0
  1229
	TInt index;
sl@0
  1230
	for (index=0; index<iModes->Count(); ++index)
sl@0
  1231
		{
sl@0
  1232
		TSizeMode* modePtr=(*iModes)[index];
sl@0
  1233
		if (modePtr)
sl@0
  1234
			{
sl@0
  1235
			iScreenSizeMode=index;
sl@0
  1236
			break;
sl@0
  1237
			}
sl@0
  1238
		}
sl@0
  1239
	}
sl@0
  1240
sl@0
  1241
TDisplayMode CScreen::FirstDefaultDisplayMode() const
sl@0
  1242
	{
sl@0
  1243
	TInt mode=-1;
sl@0
  1244
	while ((*iModes)[++mode]==NULL)
sl@0
  1245
		{
sl@0
  1246
		WS_ASSERT_DEBUG(mode<iModes->Count()-1,EWsPanicInvalidScreenSizeMode);
sl@0
  1247
		}
sl@0
  1248
	return((*iModes)[mode]->iDefaultDisplayMode);
sl@0
  1249
	}
sl@0
  1250
sl@0
  1251
CFbsDevice* CScreen::GetFbsDevice()
sl@0
  1252
	{
sl@0
  1253
	if (iRedirectGc)
sl@0
  1254
		{
sl@0
  1255
		WS_ASSERT_DEBUG(iRedirectGc->Device(), EWsPanicNullDeviceHandle);
sl@0
  1256
		return static_cast<CFbsDevice*>(iRedirectGc->Device());
sl@0
  1257
		}
sl@0
  1258
	else
sl@0
  1259
		{
sl@0
  1260
		return iScreenDevice;
sl@0
  1261
		}
sl@0
  1262
	}
sl@0
  1263
sl@0
  1264
void CScreen::AddRedrawRegion(const TRegion& aRegion, TBool aSchedule, TRedrawDepth aDepth)
sl@0
  1265
	{
sl@0
  1266
	iRedraw->AddRedrawRegion(aRegion, aSchedule, aDepth);
sl@0
  1267
	}
sl@0
  1268
sl@0
  1269
void CScreen::DoRedrawNow()
sl@0
  1270
	{
sl@0
  1271
	iRedraw->DoRedrawNow();
sl@0
  1272
	}
sl@0
  1273
sl@0
  1274
// implementing MWsScreen
sl@0
  1275
sl@0
  1276
const TTime& CScreen::Now() const
sl@0
  1277
	{
sl@0
  1278
	return iRedraw->Now();
sl@0
  1279
	}
sl@0
  1280
sl@0
  1281
void CScreen::ScheduleAnimation(const TRect& aRect,const TTimeIntervalMicroSeconds& aFromNow,const TTimeIntervalMicroSeconds& aFreq,const TTimeIntervalMicroSeconds& aStop)
sl@0
  1282
	{
sl@0
  1283
	iRedraw->ScheduleAnimation(aRect,aFromNow,aFreq,aStop);
sl@0
  1284
	}
sl@0
  1285
sl@0
  1286
void CScreen::OnAnimation()
sl@0
  1287
	{
sl@0
  1288
	iRedraw->OnAnimation();
sl@0
  1289
	}
sl@0
  1290
	
sl@0
  1291
void CScreen::Redraw()
sl@0
  1292
	{
sl@0
  1293
	STACK_REGION bounds;
sl@0
  1294
	bounds.AddRect(DrawableArea());
sl@0
  1295
	AddRedrawRegion(bounds);
sl@0
  1296
	bounds.Close();
sl@0
  1297
	}
sl@0
  1298
sl@0
  1299
TBool CScreen::RedrawInvalid(const TArray<TGraphicDrawerId>& aInvalid)
sl@0
  1300
	{
sl@0
  1301
	TBool wasDirty = EFalse;
sl@0
  1302
	STACK_REGION bounds;
sl@0
  1303
	bounds.AddRect(DrawableArea());
sl@0
  1304
	STACK_REGION dirty;
sl@0
  1305
	TWalkWindowTreeCalcInvalidGraphics calc(&bounds,dirty,aInvalid);
sl@0
  1306
	if(calc.CreateSubRegion())
sl@0
  1307
		{
sl@0
  1308
		calc.CalcInvalid(*this);
sl@0
  1309
		if(dirty.CheckError() || dirty.Count())
sl@0
  1310
			{
sl@0
  1311
			Redraw();
sl@0
  1312
			wasDirty = ETrue;
sl@0
  1313
			}
sl@0
  1314
		calc.DestroyRegions();
sl@0
  1315
		}
sl@0
  1316
	dirty.Close();
sl@0
  1317
	bounds.Close();
sl@0
  1318
	return wasDirty;
sl@0
  1319
	}
sl@0
  1320
sl@0
  1321
/**
sl@0
  1322
 Overidding MWsObjectProvider
sl@0
  1323
*/
sl@0
  1324
TAny* CScreen::ResolveObjectInterface(TUint aTypeId)
sl@0
  1325
	{
sl@0
  1326
	TAny* interface = NULL;
sl@0
  1327
sl@0
  1328
	switch (aTypeId)
sl@0
  1329
		{
sl@0
  1330
		case MWsScreenConfig::EWsObjectInterfaceId:
sl@0
  1331
			interface = static_cast<MWsScreenConfig*>(this);
sl@0
  1332
			break;
sl@0
  1333
		case MWsFrontBuffer::EWsObjectInterfaceId:
sl@0
  1334
			interface = static_cast<MWsFrontBuffer*>(this);
sl@0
  1335
			break;	
sl@0
  1336
		case MWsWindow::EWsObjectInterfaceId:
sl@0
  1337
			interface = static_cast<MWsWindow*>(RootWindow());
sl@0
  1338
			break;
sl@0
  1339
		}
sl@0
  1340
	
sl@0
  1341
	if (!interface && iOffScreenBitmap)
sl@0
  1342
		interface = iOffScreenBitmap->ResolveObjectInterface(aTypeId);
sl@0
  1343
sl@0
  1344
	if (!interface)
sl@0
  1345
		interface = iRedraw->ResolveObjectInterface(aTypeId);
sl@0
  1346
sl@0
  1347
	return interface;
sl@0
  1348
	}
sl@0
  1349
sl@0
  1350
/**
sl@0
  1351
 Implementing MWsScreenConfig
sl@0
  1352
*/
sl@0
  1353
TDisplayMode CScreen::DisplayMode() const
sl@0
  1354
	{
sl@0
  1355
	return iScreenDevice->DisplayMode();
sl@0
  1356
	}
sl@0
  1357
sl@0
  1358
TSize CScreen::SizeInPixels() const
sl@0
  1359
	{
sl@0
  1360
	return iScreenDevice->SizeInPixels();
sl@0
  1361
	}
sl@0
  1362
sl@0
  1363
TSize CScreen::ScreenModeSizeInPixels() const
sl@0
  1364
	{
sl@0
  1365
	return (*iModes)[iScreenSizeMode]->iScreenSize;
sl@0
  1366
	}
sl@0
  1367
sl@0
  1368
TInt CScreen::Stride() const
sl@0
  1369
	{
sl@0
  1370
	return iScreenDevice->Stride();
sl@0
  1371
	}
sl@0
  1372
sl@0
  1373
CFbsBitGc::TGraphicsOrientation CScreen::Orientation() const
sl@0
  1374
	{
sl@0
  1375
	return iScreenDevice->Orientation();
sl@0
  1376
	}
sl@0
  1377
sl@0
  1378
TInt CScreen::SizeMode() const
sl@0
  1379
	{
sl@0
  1380
	return iScreenSizeMode;
sl@0
  1381
	}
sl@0
  1382
sl@0
  1383
TSize CScreen::ScalingFactor() const
sl@0
  1384
	{
sl@0
  1385
	return (*iModes)[iScreenSizeMode]->iScreenScale;
sl@0
  1386
	}
sl@0
  1387
sl@0
  1388
TPoint CScreen::Origin() const
sl@0
  1389
	{
sl@0
  1390
	return (*iModes)[iScreenSizeMode]->iOrigin;
sl@0
  1391
	}
sl@0
  1392
sl@0
  1393
TPoint CScreen::ScaledOrigin() const
sl@0
  1394
	{
sl@0
  1395
	return (*iModes)[iScreenSizeMode]->ScaledOrigin();
sl@0
  1396
	}
sl@0
  1397
sl@0
  1398
/**
sl@0
  1399
 Implementing MWsFrontBuffer
sl@0
  1400
*/
sl@0
  1401
const TAny* CScreen::GetBits()
sl@0
  1402
	{
sl@0
  1403
	return iScreenDevice->Bits();
sl@0
  1404
	}
sl@0
  1405
sl@0
  1406
CFbsBitGc* CScreen::GetBitGc()
sl@0
  1407
	{
sl@0
  1408
	return iScreenGdi;
sl@0
  1409
	}
sl@0
  1410
sl@0
  1411
CFbsBitGc* CScreen::GetBitGcCurrent()
sl@0
  1412
	{
sl@0
  1413
	if (iRedirectGc)
sl@0
  1414
		return iRedirectGc;
sl@0
  1415
	else
sl@0
  1416
		return iScreenGdi;
sl@0
  1417
	}
sl@0
  1418
	
sl@0
  1419
/**
sl@0
  1420
 Redirect screen drawing to specified gc. Passing NULL will stop redirection.
sl@0
  1421
*/
sl@0
  1422
TInt CScreen::SetBitGc(CFbsBitGc* aBitGc)
sl@0
  1423
	{
sl@0
  1424
	if (aBitGc && (aBitGc==iScreenGdi || aBitGc==iRedirectGc))
sl@0
  1425
		return KErrAlreadyExists;
sl@0
  1426
sl@0
  1427
	if (aBitGc && !aBitGc->Device())
sl@0
  1428
		return KErrArgument;
sl@0
  1429
sl@0
  1430
	// screen shall not be redirected when there is at least one DSA client is actively drawing
sl@0
  1431
	if (aBitGc && iDsaDrawState==EDsaDrawStateDrawing)
sl@0
  1432
		return KErrInUse;
sl@0
  1433
sl@0
  1434
	iRedirectGc = aBitGc;
sl@0
  1435
	
sl@0
  1436
	// Redraw window CWindowGC objects have CFbsBitGcs active on the screen device and need reactivating:
sl@0
  1437
	TWalkWindowTreeReactivateGcs wwt;
sl@0
  1438
	RootWindow()->WalkWindowTree(wwt, EWalkChildren);
sl@0
  1439
	
sl@0
  1440
	// Andy - should we do something with the CPlaybackGc here?  Can they be active at this point?
sl@0
  1441
	// if so, do they care, or should it already be handled for them?
sl@0
  1442
sl@0
  1443
	return KErrNone;
sl@0
  1444
	}
sl@0
  1445
sl@0
  1446
TInt CScreen::SetBitGc(CFbsBitGc* aBitGc, TBool aInvalidateScreen)
sl@0
  1447
	{
sl@0
  1448
	const TInt err = SetBitGc(aBitGc);
sl@0
  1449
sl@0
  1450
	if (err==KErrNone && aInvalidateScreen)
sl@0
  1451
		iRootWindow->InvalidateWholeScreen();
sl@0
  1452
sl@0
  1453
	return err;
sl@0
  1454
	}
sl@0
  1455
sl@0
  1456
void CScreen::DiscardAllSchedules()
sl@0
  1457
	{
sl@0
  1458
	iRedraw->DiscardAllSchedules();
sl@0
  1459
	}
sl@0
  1460
sl@0
  1461
void CScreen::ScheduleRegionUpdate(const TRegion* aDefinitelyDirty)
sl@0
  1462
	{
sl@0
  1463
	iRedraw->ScheduleRegionUpdate(aDefinitelyDirty);
sl@0
  1464
	}
sl@0
  1465
void	CScreen::DSARegionSyncStart( CWsDirectScreenAccess& aDSA )
sl@0
  1466
	{
sl@0
  1467
	iRedraw->BanThisRegionUpdate( aDSA.RegionUnderSync() );
sl@0
  1468
	}
sl@0
  1469
sl@0
  1470
void	CScreen::DSARegionSyncOver( CWsDirectScreenAccess& aDSA  )
sl@0
  1471
	{
sl@0
  1472
	iRedraw->LiftRegionUpdateBan( aDSA.RegionUnderSync()  );
sl@0
  1473
	}
sl@0
  1474
sl@0
  1475
TBool CScreen::IsUpdatePending()
sl@0
  1476
	{
sl@0
  1477
	return iRedraw->IsUpdatePending();
sl@0
  1478
	}
sl@0
  1479
sl@0
  1480
TBool 	CScreen::IsDSAClientWindow( const CWsClientWindow* aWin ) const
sl@0
  1481
	{
sl@0
  1482
	TBool res = EFalse; 
sl@0
  1483
	if ( ! iDirects.IsEmpty() )
sl@0
  1484
		{
sl@0
  1485
		TSglQueIter<CWsDirectScreenAccess> iter( (TSglQueBase&)iDirects );
sl@0
  1486
		iter.SetToFirst();
sl@0
  1487
		CWsDirectScreenAccess* dsa;
sl@0
  1488
		while ( (dsa = iter++) != NULL && !res )
sl@0
  1489
			{
sl@0
  1490
			res =  (dsa->ClientWindow() == aWin ) && ( dsa->IsVisible() || dsa->IsSyncTimeoutPending() );
sl@0
  1491
			}
sl@0
  1492
		}
sl@0
  1493
	return res;	
sl@0
  1494
	}
sl@0
  1495
sl@0
  1496
void CScreen::AcceptFadeRequest( CWsWindow* aWin, TBool aIsFaded, TBool aIsBehind, TBool aIncludeChildren )
sl@0
  1497
	{
sl@0
  1498
	iRedraw->AcceptFadeRequest( aWin, aIsFaded, aIsBehind, aIncludeChildren );
sl@0
  1499
	}