os/graphics/windowing/windowserver/nga/SERVER/scrdev.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 1995-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
// Screen device
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include "ScrDev.H"
sl@0
    19
#include "Direct.H"
sl@0
    20
sl@0
    21
#include <hal.h>
sl@0
    22
#include <graphics/wsscreendevice.h>
sl@0
    23
#include "W32STD.H"
sl@0
    24
#include "server.h"
sl@0
    25
#include "gc.h"
sl@0
    26
#include "rootwin.h"
sl@0
    27
#include "windowgroup.h"
sl@0
    28
#include "wstop.h"
sl@0
    29
#include "EVENT.H"
sl@0
    30
#include "panics.h"
sl@0
    31
#include "../CLIENT/w32comm.h"
sl@0
    32
#include "devicemap.h"
sl@0
    33
#include <graphics/wsdisplaycontrol.h>
sl@0
    34
#include "wsdisplaychangeao.h"
sl@0
    35
#include <graphics/wstestscreencapture.h>
sl@0
    36
#include <graphics/WSGRAPHICDRAWERINTERFACE.H>
sl@0
    37
sl@0
    38
const TInt KEikSrvsSid=0x10003a4a;
sl@0
    39
sl@0
    40
static _LIT_SECURITY_POLICY_C1(KSecurityPolicy_WriteDeviceData,ECapabilityWriteDeviceData);
sl@0
    41
	
sl@0
    42
/*DWsScreenDevice*/
sl@0
    43
sl@0
    44
DWsScreenDevice::DWsScreenDevice(CWsClient* aOwner, TInt aDefaultScreenNumber, TUint aClientScreenDevicePointer)
sl@0
    45
		: CWsScreenObject(aOwner, WS_HANDLE_SCREEN_DEVICE, CWsTop::Screen( aDefaultScreenNumber ))
sl@0
    46
		,iClientScreenDevicePointer(aClientScreenDevicePointer)
sl@0
    47
	{
sl@0
    48
	MWsScreen* pOI=Screen();
sl@0
    49
	iDispCont=pOI->ObjectInterface<MWsDisplayControl>();
sl@0
    50
	iDispMap =pOI->ObjectInterface<MWsDisplayMapping>();
sl@0
    51
	iTestScreenCapture = pOI->ObjectInterface<MWsTestScreenCapture>();
sl@0
    52
	}
sl@0
    53
sl@0
    54
DWsScreenDevice::~DWsScreenDevice()
sl@0
    55
	{
sl@0
    56
	//remove it for display change notification, if it asked for notification
sl@0
    57
	Screen()->RemoveNotificationClient(iWsOwner);
sl@0
    58
	}
sl@0
    59
sl@0
    60
void DWsScreenDevice::CopyScreenToBitmapL(const TRect &aRect, TInt aHandle)
sl@0
    61
	{
sl@0
    62
	iScreen->DoRedrawNow();
sl@0
    63
sl@0
    64
	CFbsBitmap *bitmap=new(ELeave) CFbsBitmap();
sl@0
    65
	CleanupStack::PushL(bitmap);
sl@0
    66
	TInt ret = bitmap->Duplicate(aHandle);
sl@0
    67
	if (ret == KErrNoMemory)
sl@0
    68
		{
sl@0
    69
		User::Leave(ret);
sl@0
    70
		}
sl@0
    71
	if (ret != KErrNone)
sl@0
    72
		OwnerPanic(EWservPanicBitmap);
sl@0
    73
sl@0
    74
	iScreen->ScreenDevice().CopyScreenToBitmapL(bitmap, aRect);
sl@0
    75
	CleanupStack::PopAndDestroy(bitmap);
sl@0
    76
	}
sl@0
    77
sl@0
    78
void DWsScreenDevice::CommandL(TInt aOpcode, const TAny *aCmdData)
sl@0
    79
	{
sl@0
    80
	TWsSdCmdUnion pData;
sl@0
    81
	pData.any=aCmdData;
sl@0
    82
	switch(aOpcode)
sl@0
    83
		{
sl@0
    84
		case EWsSdOpGetNumScreenModes:
sl@0
    85
			SetReply(iScreen->NumScreenSizeModes());
sl@0
    86
			break;
sl@0
    87
		case EWsSdOpGetScreenMode:
sl@0
    88
			SetReply(iScreen->ScreenSizeMode());
sl@0
    89
			break;
sl@0
    90
		case EWsSdOpSetScreenMode:
sl@0
    91
			{
sl@0
    92
			if(!KSecurityPolicy_WriteDeviceData().CheckPolicy(iWsOwner->ClientMessage(),__PLATSEC_DIAGNOSTIC_STRING("Capability check failed for CWsScreenDevice::SetScreenMode API")))
sl@0
    93
				{
sl@0
    94
				iWsOwner->PPanic(EWservPanicPermissionDenied);
sl@0
    95
				}
sl@0
    96
			SetScreenMode(*pData.Int);
sl@0
    97
			}
sl@0
    98
			break;
sl@0
    99
		case EWsSdOpSetModeRotation:
sl@0
   100
			{
sl@0
   101
			if(KSecurityPolicy_WriteDeviceData().CheckPolicy(iWsOwner->ClientMessage(),__PLATSEC_DIAGNOSTIC_STRING("Capability check failed for CWsScreenDevice::SetModeRotation API")))
sl@0
   102
				{
sl@0
   103
				TClientPanic panic=iScreen->SetModeRotation(pData.SetScreenRotation->mode,pData.SetScreenRotation->rotation);
sl@0
   104
				if (panic)
sl@0
   105
					OwnerPanic(panic);
sl@0
   106
				}
sl@0
   107
			}
sl@0
   108
			break;
sl@0
   109
		case EWsSdOpGetRotationList:
sl@0
   110
			if (!iScreen->IsValidScreenSizeMode(*pData.Int))
sl@0
   111
				OwnerPanic(EWservPanicScreenModeNumber);
sl@0
   112
			SetReply(iScreen->ScreenSizeModeData(*pData.Int).iAlternativeRotations);
sl@0
   113
			break;
sl@0
   114
		case EWsSdOpGetScreenModeSizeAndRotation:
sl@0
   115
			GetScreenSizeAndRotationCmd(*pData.Int);
sl@0
   116
			break;
sl@0
   117
		case EWsSdOpGetScreenModeSizeAndRotation2:
sl@0
   118
			GetScreenSizeAndRotationCmd2(*pData.Int);
sl@0
   119
			break;
sl@0
   120
		case EWsSdOpSetScreenSizeAndRotation:
sl@0
   121
			SetScreenSizeAndRotation(*pData.PixelsTwipsAndRotation);
sl@0
   122
			break;
sl@0
   123
		case EWsSdOpSetScreenSizeAndRotation2:
sl@0
   124
			SetScreenSizeAndRotation(*pData.PixelsAndRotation);
sl@0
   125
			break;
sl@0
   126
		case EWsSdOpGetDefaultScreenSizeAndRotation:
sl@0
   127
			GetScreenSizeAndRotationCmd(iScreen->ScreenSizeMode());
sl@0
   128
			break;
sl@0
   129
		case EWsSdOpGetDefaultScreenSizeAndRotation2:
sl@0
   130
			GetScreenSizeAndRotationCmd2(iScreen->ScreenSizeMode());
sl@0
   131
			break;
sl@0
   132
		case EWsSdOpGetScreenModeDisplayMode:
sl@0
   133
			GetScreenModeDisplayMode(*pData.Int);
sl@0
   134
			break;
sl@0
   135
		case EWsSdOpGetScreenModeScale:
sl@0
   136
			if (!iScreen->IsValidScreenSizeMode(*pData.Int))
sl@0
   137
				OwnerPanic(EWservPanicScreenModeNumber);
sl@0
   138
			CWsClient::ReplySize(TSize(1,1));
sl@0
   139
			break;
sl@0
   140
		case EWsSdOpGetCurrentScreenModeScale:
sl@0
   141
			CWsClient::ReplySize(TSize(1,1));
sl@0
   142
			break;
sl@0
   143
		case EWsSdOpSetAppScreenMode:
sl@0
   144
			SetAppScreenMode(*pData.Int);
sl@0
   145
			break;
sl@0
   146
		case EWsSdOpGetCurrentScreenModeScaledOrigin:
sl@0
   147
			//scaling is not supported, but origin is.
sl@0
   148
			CWsClient::ReplyPoint(iScreen->Origin());
sl@0
   149
			break;
sl@0
   150
		case EWsSdOpGetScreenModeScaledOrigin:
sl@0
   151
			{
sl@0
   152
			if (!iScreen->IsValidScreenSizeMode(*pData.Int))
sl@0
   153
				OwnerPanic(EWservPanicScreenModeNumber);
sl@0
   154
			//scaling is not supported, but origin is.
sl@0
   155
			const TSizeMode& sizeMode=iScreen->ScreenSizeModeData(*pData.Int);
sl@0
   156
			CWsClient::ReplyPoint(sizeMode.iOrigin);
sl@0
   157
			}
sl@0
   158
			break;
sl@0
   159
		case EWsSdOpGetCurrentScreenModeAttributes:
sl@0
   160
			GetCurrentScreenModeAttributes();
sl@0
   161
			break;
sl@0
   162
		case EWsSdOpSetCurrentScreenModeAttributes:
sl@0
   163
			if(!KSecurityPolicy_WriteDeviceData().CheckPolicy(iWsOwner->ClientMessage(),__PLATSEC_DIAGNOSTIC_STRING("Capability check failed for CWsScreenDevice::SetCurrentScreenModeAttributes API, API should be used for test purposes only")))
sl@0
   164
				{
sl@0
   165
				iWsOwner->PPanic(EWservPanicPermissionDenied);
sl@0
   166
				}
sl@0
   167
			SetCurrentScreenModeAttributes(*pData.ScreenSizeMode);
sl@0
   168
			break;
sl@0
   169
		case EWsSdOpSetScreenModeEnforcement:
sl@0
   170
			{
sl@0
   171
			if(!KSecurityPolicy_WriteDeviceData().CheckPolicy(iWsOwner->ClientMessage(),__PLATSEC_DIAGNOSTIC_STRING("Capability check failed for CWsScreenDevice::SetScreenModeEnforcement API")))
sl@0
   172
				{
sl@0
   173
				iWsOwner->PPanic(EWservPanicPermissionDenied);
sl@0
   174
				}
sl@0
   175
			if (!iScreen->SetScreenModeEnforcement(*pData.Int))
sl@0
   176
				OwnerPanic(EWservPanicScreenEnforcementMode);
sl@0
   177
			}
sl@0
   178
			break;
sl@0
   179
		case EWsSdOpScreenModeEnforcement:
sl@0
   180
			SetReply(iScreen->SizeEnforcementMode());
sl@0
   181
			break;
sl@0
   182
		case EWsSdOpGetDefaultScreenModeOrigin:
sl@0
   183
			CWsClient::ReplyPoint(iScreen->Origin());
sl@0
   184
			break;
sl@0
   185
		case EWsSdOpGetScreenModeOrigin:
sl@0
   186
			{
sl@0
   187
			if (!iScreen->IsValidScreenSizeMode(*pData.Int))
sl@0
   188
				OwnerPanic(EWservPanicScreenModeNumber);
sl@0
   189
			const TSizeMode& mode=iScreen->ScreenSizeModeData(*pData.Int);
sl@0
   190
			CWsClient::ReplyPoint(mode.iOrigin);
sl@0
   191
			}
sl@0
   192
			break;
sl@0
   193
		case EWsSdOpPixel:
sl@0
   194
			{
sl@0
   195
			iScreen->DoRedrawNow();
sl@0
   196
			TRgb rgb;
sl@0
   197
			iScreen->ScreenDevice().GetPixel(rgb,*pData.Point);
sl@0
   198
			SetReply(rgb.Internal());
sl@0
   199
			}
sl@0
   200
			break;
sl@0
   201
		case EWsSdOpGetScanLine:
sl@0
   202
			iScreen->DoRedrawNow();
sl@0
   203
			iScreen->GetScanLine(pData.GetScanLine);
sl@0
   204
			break;
sl@0
   205
		case EWsSdOpTwipsSize:
sl@0
   206
			CWsClient::ReplySize(AppScreenSizeInTwips()); 
sl@0
   207
			break;
sl@0
   208
		case EWsSdOpPixelSize:
sl@0
   209
			CWsClient::ReplySize(AppScreenSizeInPixels()); 
sl@0
   210
			break;
sl@0
   211
		case EWsSdOpHorizontalTwipsToPixels:
sl@0
   212
			SetReply(iScreen->DeviceMap().HorizontalTwipsToPixels(*pData.UInt));
sl@0
   213
			break;
sl@0
   214
		case EWsSdOpVerticalTwipsToPixels:
sl@0
   215
			SetReply(iScreen->DeviceMap().VerticalTwipsToPixels(*pData.UInt));
sl@0
   216
			break;
sl@0
   217
		case EWsSdOpHorizontalPixelsToTwips:
sl@0
   218
			SetReply(iScreen->DeviceMap().HorizontalPixelsToTwips(*pData.UInt));
sl@0
   219
			break;
sl@0
   220
		case EWsSdOpVerticalPixelsToTwips:
sl@0
   221
			SetReply(iScreen->DeviceMap().VerticalPixelsToTwips(*pData.UInt));
sl@0
   222
			break;
sl@0
   223
		case EWsSdOpPointerRect:
sl@0
   224
			{
sl@0
   225
			MWsScreen* pOI=iScreen;
sl@0
   226
			const MWsScreenDevice* screenDevice = pOI->ObjectInterface<MWsScreenDevice>();
sl@0
   227
			WS_ASSERT_ALWAYS(screenDevice, EWsPanicScreenDeviceMissing);
sl@0
   228
			CWsClient::ReplyRect(screenDevice->PointerRect());
sl@0
   229
			}
sl@0
   230
			break;
sl@0
   231
		case EWsSdOpFree:
sl@0
   232
			{
sl@0
   233
			// Mark any group windows associated with the screen device being deleted
sl@0
   234
			CWsRootWindow* root=iScreen->RootWindow();
sl@0
   235
			for (CWsWindowGroup* grp = root->Child(); grp; grp = grp->NextSibling())
sl@0
   236
				{
sl@0
   237
				if (grp->Device() == this)
sl@0
   238
					{
sl@0
   239
#if defined(_DEBUG)
sl@0
   240
 					grp->SetScreenDeviceDeleted();
sl@0
   241
#endif
sl@0
   242
					grp->SetScreenDevice(NULL);
sl@0
   243
					}
sl@0
   244
				}
sl@0
   245
			}
sl@0
   246
			// Let our owner (CWsClient) know that a screen device is being deleted so it
sl@0
   247
			// can check whether to reset its iPrimaryScreenDevice member or not
sl@0
   248
			if (WsOwner())				
sl@0
   249
				WsOwner()->NotifyScreenDeviceDeleted(this);
sl@0
   250
			delete this;
sl@0
   251
			break;
sl@0
   252
		case EWsSdOpDisplayMode:
sl@0
   253
			SetReply(iScreen->DisplayMode());
sl@0
   254
			break;
sl@0
   255
		case EWsSdOpRectCompare:
sl@0
   256
			{
sl@0
   257
//			if (pData.RectCompare->flags&CWsScreenDevice::EIncludeSprite)
sl@0
   258
//				{
sl@0
   259
//				SpriteManager()->IncrementProcessingSprites();
sl@0
   260
//				}
sl@0
   261
sl@0
   262
			RWsTextCursor * cursor = 0;
sl@0
   263
			if (!(pData.RectCompare->flags&CWsScreenDevice::EIncludeTextCursor))	
sl@0
   264
				cursor = CWsTop::CurrentTextCursor();
sl@0
   265
			if (cursor)
sl@0
   266
				cursor->Disable();
sl@0
   267
			iScreen->DoRedrawNow();
sl@0
   268
			SetReply(iScreen->ScreenDevice().RectCompare(pData.RectCompare->rect1, pData.RectCompare->rect2));
sl@0
   269
sl@0
   270
			if (cursor)
sl@0
   271
				cursor->Enable();
sl@0
   272
sl@0
   273
//			if (pData.RectCompare->flags&CWsScreenDevice::EIncludeSprite)
sl@0
   274
//				{
sl@0
   275
//				SpriteManager()->DecrementProcessingSprites();
sl@0
   276
//				}
sl@0
   277
			}
sl@0
   278
			break;
sl@0
   279
		case EWsSdOpCopyScreenToBitmap:
sl@0
   280
			CopyScreenToBitmapL(TRect(iScreen->SizeInPixels()), pData.CopyScreenToBitmap->handle);
sl@0
   281
			break;
sl@0
   282
		case EWsSdOpCopyScreenToBitmap2:
sl@0
   283
			CopyScreenToBitmapL(pData.CopyScreenToBitmap2->rect,pData.CopyScreenToBitmap2->handle);
sl@0
   284
			break;
sl@0
   285
		case EWsSdOpPaletteAttributes:
sl@0
   286
			{
sl@0
   287
			TInt numEntries = 0;
sl@0
   288
			MWsScreen* pOI=iScreen;
sl@0
   289
			MWsPalette* palette = pOI->ObjectInterface<MWsPalette>();
sl@0
   290
sl@0
   291
			if (palette)
sl@0
   292
				{
sl@0
   293
				TBool modifiable;
sl@0
   294
				palette->PaletteAttributes(modifiable, numEntries);
sl@0
   295
				if (modifiable)
sl@0
   296
					numEntries |= EWsSdSetableBitFlag;
sl@0
   297
				}
sl@0
   298
			else
sl@0
   299
				{
sl@0
   300
				TInt aGrays;
sl@0
   301
				iScreen->MaxNumColors(numEntries, aGrays);
sl@0
   302
				}
sl@0
   303
sl@0
   304
			SetReply(numEntries);
sl@0
   305
			}
sl@0
   306
			break;
sl@0
   307
		case EWsSdOpSetPalette:
sl@0
   308
			{
sl@0
   309
			if(!KSecurityPolicy_WriteDeviceData().CheckPolicy(iWsOwner->ClientMessage(),__PLATSEC_DIAGNOSTIC_STRING("Capability check failed for CWsScreenDevice::SetPalette API")))
sl@0
   310
				{
sl@0
   311
				User::Leave(KErrPermissionDenied);
sl@0
   312
				}
sl@0
   313
			SetPaletteL();
sl@0
   314
			}
sl@0
   315
			break;
sl@0
   316
		case EWsSdOpGetPalette:
sl@0
   317
			GetPalette(*pData.Int);
sl@0
   318
			break;
sl@0
   319
			
sl@0
   320
		case EWsSdOpGetScreenNumber:
sl@0
   321
			SetReply(iScreen->ScreenNumber());
sl@0
   322
			break;
sl@0
   323
		case EWsSdOpGetScreenSizeModeList:
sl@0
   324
			SetReply(iScreen->GetScreenSizeModeListL());
sl@0
   325
			break;
sl@0
   326
		case EWsClOpSetBackLight:
sl@0
   327
			{
sl@0
   328
			TInt err=KErrNone;
sl@0
   329
			if(Screen()->BackLightFlag() && iWsOwner->ClientMessage().SecureId()==KEikSrvsSid)
sl@0
   330
				{
sl@0
   331
				TWindowServerEvent::ProcessErrorMessages(TWsErrorMessage::EBackLight, err=HAL::Set(iScreen->ScreenNumber(),HALData::EBacklightState,*pData.Int));
sl@0
   332
				SetReply(err);
sl@0
   333
				}
sl@0
   334
			else
sl@0
   335
				{
sl@0
   336
				User::Leave(KErrPermissionDenied);				
sl@0
   337
				}
sl@0
   338
			}
sl@0
   339
			break;
sl@0
   340
		case EWsSdOpIsScreenModeDynamic:
sl@0
   341
			{
sl@0
   342
			TInt mode = (*pData.Int == -1) ? iAppMode : *pData.Int;
sl@0
   343
			TInt flags=0;
sl@0
   344
			TRAPD(err,flags = Screen()->ModeFlagsL(mode));
sl@0
   345
			if (err == KErrNone && flags & MWsScreenConfigList::EDynamic)
sl@0
   346
				{
sl@0
   347
				SetReply(ETrue);
sl@0
   348
				}
sl@0
   349
			else
sl@0
   350
				{
sl@0
   351
				SetReply(EFalse);
sl@0
   352
				}
sl@0
   353
			}
sl@0
   354
			break;
sl@0
   355
			
sl@0
   356
		default:
sl@0
   357
			ExtensionCommandL(aOpcode, aCmdData);
sl@0
   358
			break;
sl@0
   359
		}
sl@0
   360
	}
sl@0
   361
sl@0
   362
void DWsScreenDevice::ExtensionCommandL(TInt aOpcode, const TAny *aCmdData)
sl@0
   363
	{
sl@0
   364
	TWsSdCmdUnion pData;
sl@0
   365
	pData.any=aCmdData;
sl@0
   366
	switch(aOpcode)
sl@0
   367
		{
sl@0
   368
		case EWsSdOpExtensionsSupported:
sl@0
   369
			{
sl@0
   370
			TInt reply=0;
sl@0
   371
			if (iDispCont)
sl@0
   372
				{
sl@0
   373
				reply|=TWsSdXDisplayControl;
sl@0
   374
				}
sl@0
   375
			if(iDispMap)
sl@0
   376
				{
sl@0
   377
				reply|=TWsSdXDisplayMapping;
sl@0
   378
				}
sl@0
   379
			MWsScreen* pOI=Screen();
sl@0
   380
			iTestScreenCapture = pOI->ObjectInterface<MWsTestScreenCapture>();
sl@0
   381
			if (iTestScreenCapture != NULL)
sl@0
   382
				{
sl@0
   383
				reply|=TWsSdXDebugComposition;
sl@0
   384
				}
sl@0
   385
			SetReply(reply);
sl@0
   386
			}
sl@0
   387
			break; 
sl@0
   388
		case EWsSdOpXDcGetNumberOfResolutions:
sl@0
   389
			{
sl@0
   390
			if (iDispCont)
sl@0
   391
				{
sl@0
   392
				SetReply(iDispCont->NumberOfResolutions());
sl@0
   393
				}
sl@0
   394
			else
sl@0
   395
				{
sl@0
   396
				SetReply(KErrNotSupported);
sl@0
   397
				}
sl@0
   398
			}
sl@0
   399
			break; 
sl@0
   400
		case EWsSdOpXDcGetResolutionsList:
sl@0
   401
			{
sl@0
   402
			if (iDispCont)
sl@0
   403
				{
sl@0
   404
				RArray<MWsDisplayControl::TResolution> resolutions;
sl@0
   405
				TInt err = iDispCont->GetResolutions(resolutions);
sl@0
   406
				if(err != KErrNone)
sl@0
   407
					{
sl@0
   408
					SetReply(err);
sl@0
   409
					resolutions.Close();
sl@0
   410
					break;
sl@0
   411
					}
sl@0
   412
				TInt bufLength = resolutions.Count()*sizeof(MWsDisplayControl::TResolution);
sl@0
   413
				SetReply(bufLength);
sl@0
   414
				 
sl@0
   415
				if(CWsClient::ReplyBufSpace() >= bufLength)
sl@0
   416
					{	//must not overflow the client's allocated storage.
sl@0
   417
					CWsClient::ReplyBuf(&resolutions[0], bufLength);
sl@0
   418
					}
sl@0
   419
				resolutions.Close();
sl@0
   420
				}
sl@0
   421
			else
sl@0
   422
				{
sl@0
   423
				SetReply(KErrNotSupported);
sl@0
   424
				}
sl@0
   425
			}
sl@0
   426
			break;
sl@0
   427
		case EWsSdOpXDcGetConfiguration:
sl@0
   428
			{
sl@0
   429
			if(iDispCont)
sl@0
   430
				{
sl@0
   431
				TDisplayConfiguration dispConfig = *pData.DisplayConfiguration;
sl@0
   432
				if (dispConfig.Version() < sizeof(TDisplayConfiguration))
sl@0
   433
					{
sl@0
   434
					//Test not required until there are multiple configuration sizes
sl@0
   435
					__ASSERT_COMPILE(sizeof(TDisplayConfiguration1)==sizeof(TDisplayConfiguration));
sl@0
   436
					//if (dispConfig.Version() != sizeof(TDisplayConfiguration1))
sl@0
   437
						{
sl@0
   438
						CWsClient::PanicCurrentClient(EWservPanicInvalidDisplayConfiguration);
sl@0
   439
						}
sl@0
   440
					}
sl@0
   441
				iDispCont->GetConfiguration(dispConfig);
sl@0
   442
				TInt expectedVersion = pData.DisplayConfiguration->Version();
sl@0
   443
				if (sizeof(TDisplayConfiguration)< expectedVersion)
sl@0
   444
					expectedVersion = sizeof(TDisplayConfiguration);
sl@0
   445
				CWsClient::ReplyBuf(&dispConfig, expectedVersion);
sl@0
   446
				}
sl@0
   447
			else
sl@0
   448
				{
sl@0
   449
				SetReply(KErrNotSupported);
sl@0
   450
				}
sl@0
   451
			SetReply(KErrNone);
sl@0
   452
			}
sl@0
   453
			break;
sl@0
   454
		case EWsSdOpXDcSetConfiguration:
sl@0
   455
			{
sl@0
   456
			TDisplayConfiguration dispConfig = *pData.DisplayConfiguration;
sl@0
   457
			if (dispConfig.Version() < TDisplayConfiguration().Version())
sl@0
   458
				{
sl@0
   459
				//Test not required until there are multiple configuration sizes
sl@0
   460
				__ASSERT_COMPILE(sizeof(TDisplayConfiguration1)==sizeof(TDisplayConfiguration));
sl@0
   461
				//if (dispConfig.Version() != sizeof(TDisplayConfiguration1))
sl@0
   462
					{
sl@0
   463
					CWsClient::PanicCurrentClient(EWservPanicInvalidDisplayConfiguration);
sl@0
   464
					}
sl@0
   465
				}
sl@0
   466
			TInt reply=Screen()->SetConfiguration(dispConfig);
sl@0
   467
			SetReply(reply);
sl@0
   468
			}
sl@0
   469
			break;
sl@0
   470
	
sl@0
   471
		case EWsSdOpXDcGetPreferredDisplayVersion:
sl@0
   472
			{
sl@0
   473
			if (iDispCont)
sl@0
   474
				{
sl@0
   475
				SetReply(iDispCont->PreferredDisplayVersion());
sl@0
   476
				}
sl@0
   477
			else
sl@0
   478
				{
sl@0
   479
				SetReply(KErrNotSupported);
sl@0
   480
				}
sl@0
   481
			}
sl@0
   482
			break;
sl@0
   483
		case EWsSdOpXDcNotifyOnDisplayChange:
sl@0
   484
			{
sl@0
   485
			if(iDispCont)
sl@0
   486
				{
sl@0
   487
				SetReply(Screen()->AddNotificationClient(iWsOwner));
sl@0
   488
				}
sl@0
   489
			else
sl@0
   490
				{
sl@0
   491
				SetReply(KErrNotSupported);
sl@0
   492
				}
sl@0
   493
			}
sl@0
   494
			break;
sl@0
   495
		case EWsSdOpXDcNotifyOnDisplayChangeCancel:
sl@0
   496
			{
sl@0
   497
			if (iDispCont)
sl@0
   498
				{
sl@0
   499
				Screen()->RemoveNotificationClient(iWsOwner);
sl@0
   500
				SetReply(KErrNone);
sl@0
   501
				}
sl@0
   502
			else
sl@0
   503
				{
sl@0
   504
				SetReply(KErrNotSupported);
sl@0
   505
				}
sl@0
   506
			}
sl@0
   507
			break;
sl@0
   508
		case EWsSdOpXTestScreenCapture:
sl@0
   509
			TestScreenCaptureL(pData.any);
sl@0
   510
			break;
sl@0
   511
		case EWsSdOpXTestScreenCaptureSize:
sl@0
   512
		    CWsClient::ReplySize(iScreen->SizeInPixels());
sl@0
   513
            break;
sl@0
   514
		case EWsSdOpXDcDisplayChangeEventEnabled:
sl@0
   515
			{
sl@0
   516
			if(iDispCont)
sl@0
   517
				{
sl@0
   518
				if(Screen()->FindNotificationClient(iWsOwner) != KErrNotFound)
sl@0
   519
					{
sl@0
   520
					SetReply(1);
sl@0
   521
					break;
sl@0
   522
					}
sl@0
   523
				}
sl@0
   524
			
sl@0
   525
			SetReply(0);
sl@0
   526
		
sl@0
   527
			}
sl@0
   528
			break;
sl@0
   529
		case EWsSdOpXDmMapExtent:
sl@0
   530
			{
sl@0
   531
			if(iDispMap)
sl@0
   532
				{
sl@0
   533
				TWsSdCmdMapCoordinates mapCoord = *pData.MapCoordinates;
sl@0
   534
				TRect targetRect;
sl@0
   535
				TInt err = iDispMap->MapCoordinates(mapCoord.sourceSpace, mapCoord.sourceRect, mapCoord.targetSpace, targetRect);
sl@0
   536
				if(err != KErrNone)
sl@0
   537
					{
sl@0
   538
					SetReply(err);
sl@0
   539
					}
sl@0
   540
				else
sl@0
   541
					{
sl@0
   542
					CWsClient::ReplyBuf(&targetRect, sizeof(TRect));
sl@0
   543
					SetReply(KErrNone);
sl@0
   544
					}
sl@0
   545
				}
sl@0
   546
			else
sl@0
   547
				{
sl@0
   548
				SetReply(KErrNotSupported);
sl@0
   549
				}
sl@0
   550
			}
sl@0
   551
			break;
sl@0
   552
		default:
sl@0
   553
			OwnerPanic(EWservPanicOpcode);
sl@0
   554
			break;
sl@0
   555
		}
sl@0
   556
	}
sl@0
   557
sl@0
   558
void DWsScreenDevice::SetScreenMode(TInt aMode)
sl@0
   559
	{
sl@0
   560
	if (!iScreen->IsValidScreenSizeMode(aMode))
sl@0
   561
		OwnerPanic(EWservPanicScreenModeNumber);
sl@0
   562
	iScreen->doSetScreenMode(aMode);
sl@0
   563
	}
sl@0
   564
sl@0
   565
TSize DWsScreenDevice::AppScreenSizeInPixels() const
sl@0
   566
	{
sl@0
   567
	if (iAppScreenSizeInPixels == TSize(-1,-1))
sl@0
   568
		{
sl@0
   569
		TSize returnSize;
sl@0
   570
		TRAP_IGNORE(returnSize = iScreen->ScreenModeSizeInPixelsL(iAppMode));
sl@0
   571
		return returnSize;
sl@0
   572
		}
sl@0
   573
	return iAppScreenSizeInPixels;
sl@0
   574
	}
sl@0
   575
sl@0
   576
TSize DWsScreenDevice::AppScreenSizeInTwips() const
sl@0
   577
	{
sl@0
   578
	if (iAppScreenSizeInTwips == TSize(-1,-1))
sl@0
   579
		{
sl@0
   580
		TSize returnSize;
sl@0
   581
		TRAP_IGNORE(returnSize = iScreen->ScreenModeSizeInTwipsL(iAppMode));
sl@0
   582
		return returnSize;
sl@0
   583
		}
sl@0
   584
	return iAppScreenSizeInTwips;
sl@0
   585
	}
sl@0
   586
sl@0
   587
TBool DWsScreenDevice::ScreenDeviceValidState() const
sl@0
   588
	{
sl@0
   589
	WS_ASSERT_DEBUG(iScreen->IsValidScreenSizeMode(iScreen->ScreenSizeMode()), EWsPanicInvalidScreenSizeMode);
sl@0
   590
	const TSizeMode& currentMode=iScreen->ScreenSizeModeData();
sl@0
   591
	TBool state=ETrue;
sl@0
   592
	
sl@0
   593
	// In all enforcement modes scale should match, so check scale first
sl@0
   594
	if (iScreen->SizeEnforcementMode()!=ESizeEnforcementNone)
sl@0
   595
		{
sl@0
   596
		TSize appScreenSizeInPixels = AppScreenSizeInPixels();
sl@0
   597
		if (currentMode.iRotation!=iAppRotation)
sl@0
   598
			{
sl@0
   599
			state=EFalse;
sl@0
   600
			}
sl@0
   601
		else if (!(appScreenSizeInPixels == currentMode.iScreenSize))
sl@0
   602
			{
sl@0
   603
			state=EFalse;
sl@0
   604
			}
sl@0
   605
		}
sl@0
   606
	if (iScreen->SizeEnforcementMode()==ESizeEnforcementPixelsTwipsAndRotation)
sl@0
   607
		{
sl@0
   608
		TSize appScreenSizeInTwips = AppScreenSizeInTwips();
sl@0
   609
		if (!(appScreenSizeInTwips == currentMode.iScreenTwipsSize))
sl@0
   610
			{
sl@0
   611
			state=EFalse;
sl@0
   612
			}
sl@0
   613
		}
sl@0
   614
	return(state);
sl@0
   615
	}
sl@0
   616
sl@0
   617
void DWsScreenDevice::ConstructL()
sl@0
   618
//
sl@0
   619
// App specific construct
sl@0
   620
//
sl@0
   621
	{
sl@0
   622
	NewObjL();
sl@0
   623
	const TSizeMode& mode=iScreen->ScreenSizeModeData(iScreen->ScreenSizeMode());
sl@0
   624
	TInt modeNumber = iScreen->ScreenSizeMode();
sl@0
   625
	TInt flags = iScreen->ModeFlagsL(modeNumber);
sl@0
   626
	if (flags & MWsScreenConfigList::EDynamic)
sl@0
   627
		{
sl@0
   628
		iAppScreenSizeInPixels = TSize(-1,-1);
sl@0
   629
		iAppScreenSizeInTwips = TSize(-1,-1);
sl@0
   630
		}
sl@0
   631
	else
sl@0
   632
		{
sl@0
   633
		iAppScreenSizeInPixels=mode.iScreenSize;
sl@0
   634
		iAppScreenSizeInTwips=mode.iScreenTwipsSize;
sl@0
   635
		}
sl@0
   636
	iAppRotation=mode.iRotation;
sl@0
   637
	iAppMode=modeNumber;
sl@0
   638
	}
sl@0
   639
sl@0
   640
void DWsScreenDevice::SetScreenSizeAndRotation(const TPixelsTwipsAndRotation &aSar)
sl@0
   641
	{
sl@0
   642
	iAppScreenSizeInPixels=aSar.iPixelSize;
sl@0
   643
	iAppScreenSizeInTwips=aSar.iTwipsSize;
sl@0
   644
	iAppRotation=aSar.iRotation;
sl@0
   645
	SetScreenDeviceValidStates(this);
sl@0
   646
	TInt flags=0;
sl@0
   647
	TRAP_IGNORE(flags = iScreen->ModeFlagsL(iScreen->ScreenSizeMode()));
sl@0
   648
	if (flags & MWsScreenConfigList::EDynamic)
sl@0
   649
		{
sl@0
   650
		iAppScreenSizeInPixels = TSize(-1,-1);
sl@0
   651
		iAppScreenSizeInTwips = TSize(-1,-1);
sl@0
   652
		}
sl@0
   653
	}
sl@0
   654
sl@0
   655
void DWsScreenDevice::SetScreenSizeAndRotation(const TPixelsAndRotation &aSar)
sl@0
   656
	{
sl@0
   657
	iAppScreenSizeInPixels=aSar.iPixelSize;
sl@0
   658
	iAppScreenSizeInTwips.iWidth=iScreen->DeviceMap().HorizontalPixelsToTwips(iAppScreenSizeInPixels.iWidth);
sl@0
   659
	iAppScreenSizeInTwips.iHeight=iScreen->DeviceMap().VerticalPixelsToTwips(iAppScreenSizeInPixels.iHeight);
sl@0
   660
	iAppRotation=aSar.iRotation;
sl@0
   661
	SetScreenDeviceValidStates(this);
sl@0
   662
	TInt flags=0;
sl@0
   663
	TRAP_IGNORE(flags = iScreen->ModeFlagsL(iScreen->ScreenSizeMode()));
sl@0
   664
	if (flags & MWsScreenConfigList::EDynamic)
sl@0
   665
		{
sl@0
   666
		iAppScreenSizeInPixels = TSize(-1,-1);
sl@0
   667
		iAppScreenSizeInTwips = TSize(-1,-1);
sl@0
   668
		}
sl@0
   669
	}
sl@0
   670
sl@0
   671
void DWsScreenDevice::GetCurrentScreenModeAttributes()
sl@0
   672
	{
sl@0
   673
	TSizeMode aModeData=iScreen->ScreenSizeModeData();
sl@0
   674
	CWsClient::ReplyBuf(&aModeData,sizeof(aModeData));
sl@0
   675
	}
sl@0
   676
sl@0
   677
void DWsScreenDevice::SetCurrentScreenModeAttributes(const TSizeMode &aModeData)
sl@0
   678
	{
sl@0
   679
#if defined(_DEBUG)
sl@0
   680
	if (aModeData.iScreenScale.iWidth==0 || aModeData.iScreenScale.iHeight==0)
sl@0
   681
		OwnerPanic(EWservPanicScreenModeNumber);
sl@0
   682
#endif
sl@0
   683
	iScreen->SetCurrentScreenModeAttributes(aModeData);
sl@0
   684
	}
sl@0
   685
sl@0
   686
void DWsScreenDevice::GetScreenSizeAndRotationCmd(TInt aMode)
sl@0
   687
	{
sl@0
   688
	if (!iScreen->IsValidScreenSizeMode(aMode))
sl@0
   689
		OwnerPanic(EWservPanicScreenModeNumber);
sl@0
   690
	TPixelsTwipsAndRotation sar;
sl@0
   691
	iScreen->GetScreenSizeAndRotation(sar,aMode);
sl@0
   692
	CWsClient::ReplyBuf(&sar, sizeof(sar));
sl@0
   693
	}
sl@0
   694
sl@0
   695
void DWsScreenDevice::GetScreenSizeAndRotationCmd2(TInt aMode)
sl@0
   696
	{
sl@0
   697
	if (!iScreen->IsValidScreenSizeMode(aMode))
sl@0
   698
		OwnerPanic(EWservPanicScreenModeNumber);
sl@0
   699
	TPixelsAndRotation sar;
sl@0
   700
	iScreen->GetScreenSizeAndRotation(sar,aMode);
sl@0
   701
	CWsClient::ReplyBuf(&sar, sizeof(sar));
sl@0
   702
	}
sl@0
   703
sl@0
   704
void DWsScreenDevice::GetScreenModeDisplayMode(const TInt aMode)
sl@0
   705
	{
sl@0
   706
	if (!iScreen->IsValidScreenSizeMode(aMode))
sl@0
   707
		{
sl@0
   708
		OwnerPanic(EWservPanicScreenModeNumber);
sl@0
   709
		}
sl@0
   710
	SetReply(STATIC_CAST(TInt,iScreen->DefaultDisplayMode(aMode)));
sl@0
   711
	}
sl@0
   712
sl@0
   713
void DWsScreenDevice::SetAppScreenMode(TInt aMode)
sl@0
   714
	{
sl@0
   715
	if (!iScreen->IsValidScreenSizeMode(aMode))
sl@0
   716
		{
sl@0
   717
		OwnerPanic(EWservPanicScreenModeNumber);
sl@0
   718
		}
sl@0
   719
	const TSizeMode& sizeMode=iScreen->ScreenSizeModeData(aMode);
sl@0
   720
	TInt flags=0;
sl@0
   721
	TRAP_IGNORE(flags = iScreen->ModeFlagsL(aMode));
sl@0
   722
	if (flags & MWsScreenConfigList::EDynamic)
sl@0
   723
		{
sl@0
   724
		iAppScreenSizeInPixels = TSize(-1,-1);
sl@0
   725
		iAppScreenSizeInTwips = TSize(-1,-1);
sl@0
   726
		}
sl@0
   727
	else
sl@0
   728
		{
sl@0
   729
		iAppScreenSizeInPixels=sizeMode.iScreenSize;
sl@0
   730
		iAppScreenSizeInTwips=sizeMode.iScreenTwipsSize;
sl@0
   731
		}
sl@0
   732
	iAppMode=aMode;
sl@0
   733
	iAppRotation=sizeMode.iRotation;
sl@0
   734
	CWsWindowGroup::SetScreenDeviceValidStates(this);
sl@0
   735
	}
sl@0
   736
sl@0
   737
#define ROTATION_TO_FLAG(x) 1<<x
sl@0
   738
sl@0
   739
void DWsScreenDevice::SetScreenDeviceValidStates(const DWsScreenDevice *aDevice)
sl@0
   740
	{
sl@0
   741
	TInt modes=iScreen->NumScreenSizeModes();
sl@0
   742
	TInt mode;
sl@0
   743
	for (mode=0;mode<modes;++mode)
sl@0
   744
		{
sl@0
   745
		TInt flags=0;
sl@0
   746
		TRAPD(err,flags = iScreen->ModeFlagsL(mode));
sl@0
   747
		if (err != KErrNone || flags&MWsScreenConfigList::EDynamic)
sl@0
   748
			{
sl@0
   749
			continue;
sl@0
   750
			}
sl@0
   751
		const TSizeMode& sizeMode=iScreen->ScreenSizeModeData(mode);
sl@0
   752
		if (iAppScreenSizeInPixels==sizeMode.iScreenSize && ROTATION_TO_FLAG(iAppRotation)&sizeMode.iAlternativeRotations)
sl@0
   753
			{
sl@0
   754
			iAppMode=mode;
sl@0
   755
			break;
sl@0
   756
			}
sl@0
   757
		}
sl@0
   758
	CWsWindowGroup::SetScreenDeviceValidStates(aDevice);
sl@0
   759
	}
sl@0
   760
sl@0
   761
void DWsScreenDevice::NewOrientation(TInt aMode,CFbsBitGc::TGraphicsOrientation aRotation)
sl@0
   762
	{
sl@0
   763
	if (iAppMode==aMode)
sl@0
   764
		iAppRotation=aRotation;
sl@0
   765
	}
sl@0
   766
sl@0
   767
void DWsScreenDevice::SetPaletteL()
sl@0
   768
	{
sl@0
   769
	MWsScreen* pOI=iScreen;
sl@0
   770
	MWsPalette* paletteInterface = pOI->ObjectInterface<MWsPalette>();
sl@0
   771
sl@0
   772
	if (paletteInterface)
sl@0
   773
		{
sl@0
   774
		const TInt size=iWsOwner->ClientMessage().GetDesLength(KRemoteBufferMessageSlot);
sl@0
   775
		TInt numEntries=size/sizeof(TRgb);
sl@0
   776
		CPalette* palette=CPalette::NewL(numEntries);
sl@0
   777
		CleanupStack::PushL(palette);
sl@0
   778
		TPtr8 paletteData(NULL,0);
sl@0
   779
		palette->GetDataPtr(0,numEntries,paletteData);
sl@0
   780
		iWsOwner->RemoteReadL(paletteData,0);
sl@0
   781
		SetReply(paletteInterface->SetCustomPalette(palette));
sl@0
   782
		CleanupStack::PopAndDestroy(palette);
sl@0
   783
		}
sl@0
   784
	else
sl@0
   785
		SetReply(KErrNotSupported);
sl@0
   786
	}
sl@0
   787
sl@0
   788
void DWsScreenDevice::GetPalette(TInt aNumColors)
sl@0
   789
	{
sl@0
   790
	MWsScreen* pOI=iScreen;
sl@0
   791
	MWsPalette* paletteInterface = pOI->ObjectInterface<MWsPalette>();
sl@0
   792
sl@0
   793
	if (paletteInterface)
sl@0
   794
		{
sl@0
   795
		CPalette* palette = NULL;
sl@0
   796
		TInt ret = paletteInterface->GetPalette(palette);
sl@0
   797
sl@0
   798
		if (ret != KErrNone)
sl@0
   799
			{
sl@0
   800
			SetReply(ret);
sl@0
   801
			return;
sl@0
   802
			}
sl@0
   803
sl@0
   804
		ret = palette->Entries();
sl@0
   805
sl@0
   806
		if (ret != aNumColors)
sl@0
   807
			{
sl@0
   808
			delete palette;
sl@0
   809
			SetReply(ret);
sl@0
   810
			return;
sl@0
   811
			}
sl@0
   812
sl@0
   813
		TPtr8 paletteData(NULL,0);
sl@0
   814
		palette->GetDataPtr(0,ret,paletteData);
sl@0
   815
		CWsClient::ReplyBuf(paletteData);
sl@0
   816
		SetReply(KErrNone);
sl@0
   817
		delete palette;
sl@0
   818
		}
sl@0
   819
	else
sl@0
   820
		SetReply(KErrNotSupported);
sl@0
   821
	}
sl@0
   822
sl@0
   823
TUint DWsScreenDevice::ClientDevicePointer()
sl@0
   824
	{
sl@0
   825
	return iClientScreenDevicePointer;	
sl@0
   826
	}
sl@0
   827
//Integer version means callers don't need exported panic enumeration
sl@0
   828
void DWsScreenDevice::PanicCurrentClient(TInt aPanic)
sl@0
   829
	{
sl@0
   830
	PanicCurrentClient((TClientPanic)aPanic);
sl@0
   831
	}
sl@0
   832
sl@0
   833
//Allows render stage to initiate a client panic
sl@0
   834
void DWsScreenDevice::PanicCurrentClient(TClientPanic aPanic)
sl@0
   835
	{
sl@0
   836
	CWsClient::PanicCurrentClient(aPanic);
sl@0
   837
	}
sl@0
   838
sl@0
   839
void DWsScreenDevice::SetReply(TInt aReply)
sl@0
   840
	{
sl@0
   841
	CWsObject::SetReply(aReply);
sl@0
   842
	}
sl@0
   843
sl@0
   844
void DWsScreenDevice::RedrawNowIfPending()
sl@0
   845
	{
sl@0
   846
	iScreen->RedrawNowIfPending();
sl@0
   847
	}
sl@0
   848
sl@0
   849
void DWsScreenDevice::ReplyBuf(const TAny* aSource, TInt aLength)
sl@0
   850
	{
sl@0
   851
	TPtrC8 src(reinterpret_cast<const TUint8*>(aSource),aLength);
sl@0
   852
	CWsClient::ReplyBuf(src);
sl@0
   853
	}
sl@0
   854
sl@0
   855
void DWsScreenDevice::TestScreenCaptureL(const TAny* aMessage)
sl@0
   856
	{
sl@0
   857
	if (iTestScreenCapture == NULL)
sl@0
   858
		{
sl@0
   859
		// at this point we expect that Screen Capture Interface exists always
sl@0
   860
		OwnerPanic(EWservPanicScreenCaptureInvalidRequest);
sl@0
   861
		SetReply(KErrNotSupported);
sl@0
   862
		}
sl@0
   863
	iTestScreenCapture->TestScreenCaptureL(aMessage, *static_cast<MWsScreenDeviceUtils*>(this));
sl@0
   864
	}