1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/windowing/windowserver/nga/SERVER/scrdev.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,864 @@
1.4 +// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// Screen device
1.18 +//
1.19 +//
1.20 +
1.21 +#include "ScrDev.H"
1.22 +#include "Direct.H"
1.23 +
1.24 +#include <hal.h>
1.25 +#include <graphics/wsscreendevice.h>
1.26 +#include "W32STD.H"
1.27 +#include "server.h"
1.28 +#include "gc.h"
1.29 +#include "rootwin.h"
1.30 +#include "windowgroup.h"
1.31 +#include "wstop.h"
1.32 +#include "EVENT.H"
1.33 +#include "panics.h"
1.34 +#include "../CLIENT/w32comm.h"
1.35 +#include "devicemap.h"
1.36 +#include <graphics/wsdisplaycontrol.h>
1.37 +#include "wsdisplaychangeao.h"
1.38 +#include <graphics/wstestscreencapture.h>
1.39 +#include <graphics/WSGRAPHICDRAWERINTERFACE.H>
1.40 +
1.41 +const TInt KEikSrvsSid=0x10003a4a;
1.42 +
1.43 +static _LIT_SECURITY_POLICY_C1(KSecurityPolicy_WriteDeviceData,ECapabilityWriteDeviceData);
1.44 +
1.45 +/*DWsScreenDevice*/
1.46 +
1.47 +DWsScreenDevice::DWsScreenDevice(CWsClient* aOwner, TInt aDefaultScreenNumber, TUint aClientScreenDevicePointer)
1.48 + : CWsScreenObject(aOwner, WS_HANDLE_SCREEN_DEVICE, CWsTop::Screen( aDefaultScreenNumber ))
1.49 + ,iClientScreenDevicePointer(aClientScreenDevicePointer)
1.50 + {
1.51 + MWsScreen* pOI=Screen();
1.52 + iDispCont=pOI->ObjectInterface<MWsDisplayControl>();
1.53 + iDispMap =pOI->ObjectInterface<MWsDisplayMapping>();
1.54 + iTestScreenCapture = pOI->ObjectInterface<MWsTestScreenCapture>();
1.55 + }
1.56 +
1.57 +DWsScreenDevice::~DWsScreenDevice()
1.58 + {
1.59 + //remove it for display change notification, if it asked for notification
1.60 + Screen()->RemoveNotificationClient(iWsOwner);
1.61 + }
1.62 +
1.63 +void DWsScreenDevice::CopyScreenToBitmapL(const TRect &aRect, TInt aHandle)
1.64 + {
1.65 + iScreen->DoRedrawNow();
1.66 +
1.67 + CFbsBitmap *bitmap=new(ELeave) CFbsBitmap();
1.68 + CleanupStack::PushL(bitmap);
1.69 + TInt ret = bitmap->Duplicate(aHandle);
1.70 + if (ret == KErrNoMemory)
1.71 + {
1.72 + User::Leave(ret);
1.73 + }
1.74 + if (ret != KErrNone)
1.75 + OwnerPanic(EWservPanicBitmap);
1.76 +
1.77 + iScreen->ScreenDevice().CopyScreenToBitmapL(bitmap, aRect);
1.78 + CleanupStack::PopAndDestroy(bitmap);
1.79 + }
1.80 +
1.81 +void DWsScreenDevice::CommandL(TInt aOpcode, const TAny *aCmdData)
1.82 + {
1.83 + TWsSdCmdUnion pData;
1.84 + pData.any=aCmdData;
1.85 + switch(aOpcode)
1.86 + {
1.87 + case EWsSdOpGetNumScreenModes:
1.88 + SetReply(iScreen->NumScreenSizeModes());
1.89 + break;
1.90 + case EWsSdOpGetScreenMode:
1.91 + SetReply(iScreen->ScreenSizeMode());
1.92 + break;
1.93 + case EWsSdOpSetScreenMode:
1.94 + {
1.95 + if(!KSecurityPolicy_WriteDeviceData().CheckPolicy(iWsOwner->ClientMessage(),__PLATSEC_DIAGNOSTIC_STRING("Capability check failed for CWsScreenDevice::SetScreenMode API")))
1.96 + {
1.97 + iWsOwner->PPanic(EWservPanicPermissionDenied);
1.98 + }
1.99 + SetScreenMode(*pData.Int);
1.100 + }
1.101 + break;
1.102 + case EWsSdOpSetModeRotation:
1.103 + {
1.104 + if(KSecurityPolicy_WriteDeviceData().CheckPolicy(iWsOwner->ClientMessage(),__PLATSEC_DIAGNOSTIC_STRING("Capability check failed for CWsScreenDevice::SetModeRotation API")))
1.105 + {
1.106 + TClientPanic panic=iScreen->SetModeRotation(pData.SetScreenRotation->mode,pData.SetScreenRotation->rotation);
1.107 + if (panic)
1.108 + OwnerPanic(panic);
1.109 + }
1.110 + }
1.111 + break;
1.112 + case EWsSdOpGetRotationList:
1.113 + if (!iScreen->IsValidScreenSizeMode(*pData.Int))
1.114 + OwnerPanic(EWservPanicScreenModeNumber);
1.115 + SetReply(iScreen->ScreenSizeModeData(*pData.Int).iAlternativeRotations);
1.116 + break;
1.117 + case EWsSdOpGetScreenModeSizeAndRotation:
1.118 + GetScreenSizeAndRotationCmd(*pData.Int);
1.119 + break;
1.120 + case EWsSdOpGetScreenModeSizeAndRotation2:
1.121 + GetScreenSizeAndRotationCmd2(*pData.Int);
1.122 + break;
1.123 + case EWsSdOpSetScreenSizeAndRotation:
1.124 + SetScreenSizeAndRotation(*pData.PixelsTwipsAndRotation);
1.125 + break;
1.126 + case EWsSdOpSetScreenSizeAndRotation2:
1.127 + SetScreenSizeAndRotation(*pData.PixelsAndRotation);
1.128 + break;
1.129 + case EWsSdOpGetDefaultScreenSizeAndRotation:
1.130 + GetScreenSizeAndRotationCmd(iScreen->ScreenSizeMode());
1.131 + break;
1.132 + case EWsSdOpGetDefaultScreenSizeAndRotation2:
1.133 + GetScreenSizeAndRotationCmd2(iScreen->ScreenSizeMode());
1.134 + break;
1.135 + case EWsSdOpGetScreenModeDisplayMode:
1.136 + GetScreenModeDisplayMode(*pData.Int);
1.137 + break;
1.138 + case EWsSdOpGetScreenModeScale:
1.139 + if (!iScreen->IsValidScreenSizeMode(*pData.Int))
1.140 + OwnerPanic(EWservPanicScreenModeNumber);
1.141 + CWsClient::ReplySize(TSize(1,1));
1.142 + break;
1.143 + case EWsSdOpGetCurrentScreenModeScale:
1.144 + CWsClient::ReplySize(TSize(1,1));
1.145 + break;
1.146 + case EWsSdOpSetAppScreenMode:
1.147 + SetAppScreenMode(*pData.Int);
1.148 + break;
1.149 + case EWsSdOpGetCurrentScreenModeScaledOrigin:
1.150 + //scaling is not supported, but origin is.
1.151 + CWsClient::ReplyPoint(iScreen->Origin());
1.152 + break;
1.153 + case EWsSdOpGetScreenModeScaledOrigin:
1.154 + {
1.155 + if (!iScreen->IsValidScreenSizeMode(*pData.Int))
1.156 + OwnerPanic(EWservPanicScreenModeNumber);
1.157 + //scaling is not supported, but origin is.
1.158 + const TSizeMode& sizeMode=iScreen->ScreenSizeModeData(*pData.Int);
1.159 + CWsClient::ReplyPoint(sizeMode.iOrigin);
1.160 + }
1.161 + break;
1.162 + case EWsSdOpGetCurrentScreenModeAttributes:
1.163 + GetCurrentScreenModeAttributes();
1.164 + break;
1.165 + case EWsSdOpSetCurrentScreenModeAttributes:
1.166 + if(!KSecurityPolicy_WriteDeviceData().CheckPolicy(iWsOwner->ClientMessage(),__PLATSEC_DIAGNOSTIC_STRING("Capability check failed for CWsScreenDevice::SetCurrentScreenModeAttributes API, API should be used for test purposes only")))
1.167 + {
1.168 + iWsOwner->PPanic(EWservPanicPermissionDenied);
1.169 + }
1.170 + SetCurrentScreenModeAttributes(*pData.ScreenSizeMode);
1.171 + break;
1.172 + case EWsSdOpSetScreenModeEnforcement:
1.173 + {
1.174 + if(!KSecurityPolicy_WriteDeviceData().CheckPolicy(iWsOwner->ClientMessage(),__PLATSEC_DIAGNOSTIC_STRING("Capability check failed for CWsScreenDevice::SetScreenModeEnforcement API")))
1.175 + {
1.176 + iWsOwner->PPanic(EWservPanicPermissionDenied);
1.177 + }
1.178 + if (!iScreen->SetScreenModeEnforcement(*pData.Int))
1.179 + OwnerPanic(EWservPanicScreenEnforcementMode);
1.180 + }
1.181 + break;
1.182 + case EWsSdOpScreenModeEnforcement:
1.183 + SetReply(iScreen->SizeEnforcementMode());
1.184 + break;
1.185 + case EWsSdOpGetDefaultScreenModeOrigin:
1.186 + CWsClient::ReplyPoint(iScreen->Origin());
1.187 + break;
1.188 + case EWsSdOpGetScreenModeOrigin:
1.189 + {
1.190 + if (!iScreen->IsValidScreenSizeMode(*pData.Int))
1.191 + OwnerPanic(EWservPanicScreenModeNumber);
1.192 + const TSizeMode& mode=iScreen->ScreenSizeModeData(*pData.Int);
1.193 + CWsClient::ReplyPoint(mode.iOrigin);
1.194 + }
1.195 + break;
1.196 + case EWsSdOpPixel:
1.197 + {
1.198 + iScreen->DoRedrawNow();
1.199 + TRgb rgb;
1.200 + iScreen->ScreenDevice().GetPixel(rgb,*pData.Point);
1.201 + SetReply(rgb.Internal());
1.202 + }
1.203 + break;
1.204 + case EWsSdOpGetScanLine:
1.205 + iScreen->DoRedrawNow();
1.206 + iScreen->GetScanLine(pData.GetScanLine);
1.207 + break;
1.208 + case EWsSdOpTwipsSize:
1.209 + CWsClient::ReplySize(AppScreenSizeInTwips());
1.210 + break;
1.211 + case EWsSdOpPixelSize:
1.212 + CWsClient::ReplySize(AppScreenSizeInPixels());
1.213 + break;
1.214 + case EWsSdOpHorizontalTwipsToPixels:
1.215 + SetReply(iScreen->DeviceMap().HorizontalTwipsToPixels(*pData.UInt));
1.216 + break;
1.217 + case EWsSdOpVerticalTwipsToPixels:
1.218 + SetReply(iScreen->DeviceMap().VerticalTwipsToPixels(*pData.UInt));
1.219 + break;
1.220 + case EWsSdOpHorizontalPixelsToTwips:
1.221 + SetReply(iScreen->DeviceMap().HorizontalPixelsToTwips(*pData.UInt));
1.222 + break;
1.223 + case EWsSdOpVerticalPixelsToTwips:
1.224 + SetReply(iScreen->DeviceMap().VerticalPixelsToTwips(*pData.UInt));
1.225 + break;
1.226 + case EWsSdOpPointerRect:
1.227 + {
1.228 + MWsScreen* pOI=iScreen;
1.229 + const MWsScreenDevice* screenDevice = pOI->ObjectInterface<MWsScreenDevice>();
1.230 + WS_ASSERT_ALWAYS(screenDevice, EWsPanicScreenDeviceMissing);
1.231 + CWsClient::ReplyRect(screenDevice->PointerRect());
1.232 + }
1.233 + break;
1.234 + case EWsSdOpFree:
1.235 + {
1.236 + // Mark any group windows associated with the screen device being deleted
1.237 + CWsRootWindow* root=iScreen->RootWindow();
1.238 + for (CWsWindowGroup* grp = root->Child(); grp; grp = grp->NextSibling())
1.239 + {
1.240 + if (grp->Device() == this)
1.241 + {
1.242 +#if defined(_DEBUG)
1.243 + grp->SetScreenDeviceDeleted();
1.244 +#endif
1.245 + grp->SetScreenDevice(NULL);
1.246 + }
1.247 + }
1.248 + }
1.249 + // Let our owner (CWsClient) know that a screen device is being deleted so it
1.250 + // can check whether to reset its iPrimaryScreenDevice member or not
1.251 + if (WsOwner())
1.252 + WsOwner()->NotifyScreenDeviceDeleted(this);
1.253 + delete this;
1.254 + break;
1.255 + case EWsSdOpDisplayMode:
1.256 + SetReply(iScreen->DisplayMode());
1.257 + break;
1.258 + case EWsSdOpRectCompare:
1.259 + {
1.260 +// if (pData.RectCompare->flags&CWsScreenDevice::EIncludeSprite)
1.261 +// {
1.262 +// SpriteManager()->IncrementProcessingSprites();
1.263 +// }
1.264 +
1.265 + RWsTextCursor * cursor = 0;
1.266 + if (!(pData.RectCompare->flags&CWsScreenDevice::EIncludeTextCursor))
1.267 + cursor = CWsTop::CurrentTextCursor();
1.268 + if (cursor)
1.269 + cursor->Disable();
1.270 + iScreen->DoRedrawNow();
1.271 + SetReply(iScreen->ScreenDevice().RectCompare(pData.RectCompare->rect1, pData.RectCompare->rect2));
1.272 +
1.273 + if (cursor)
1.274 + cursor->Enable();
1.275 +
1.276 +// if (pData.RectCompare->flags&CWsScreenDevice::EIncludeSprite)
1.277 +// {
1.278 +// SpriteManager()->DecrementProcessingSprites();
1.279 +// }
1.280 + }
1.281 + break;
1.282 + case EWsSdOpCopyScreenToBitmap:
1.283 + CopyScreenToBitmapL(TRect(iScreen->SizeInPixels()), pData.CopyScreenToBitmap->handle);
1.284 + break;
1.285 + case EWsSdOpCopyScreenToBitmap2:
1.286 + CopyScreenToBitmapL(pData.CopyScreenToBitmap2->rect,pData.CopyScreenToBitmap2->handle);
1.287 + break;
1.288 + case EWsSdOpPaletteAttributes:
1.289 + {
1.290 + TInt numEntries = 0;
1.291 + MWsScreen* pOI=iScreen;
1.292 + MWsPalette* palette = pOI->ObjectInterface<MWsPalette>();
1.293 +
1.294 + if (palette)
1.295 + {
1.296 + TBool modifiable;
1.297 + palette->PaletteAttributes(modifiable, numEntries);
1.298 + if (modifiable)
1.299 + numEntries |= EWsSdSetableBitFlag;
1.300 + }
1.301 + else
1.302 + {
1.303 + TInt aGrays;
1.304 + iScreen->MaxNumColors(numEntries, aGrays);
1.305 + }
1.306 +
1.307 + SetReply(numEntries);
1.308 + }
1.309 + break;
1.310 + case EWsSdOpSetPalette:
1.311 + {
1.312 + if(!KSecurityPolicy_WriteDeviceData().CheckPolicy(iWsOwner->ClientMessage(),__PLATSEC_DIAGNOSTIC_STRING("Capability check failed for CWsScreenDevice::SetPalette API")))
1.313 + {
1.314 + User::Leave(KErrPermissionDenied);
1.315 + }
1.316 + SetPaletteL();
1.317 + }
1.318 + break;
1.319 + case EWsSdOpGetPalette:
1.320 + GetPalette(*pData.Int);
1.321 + break;
1.322 +
1.323 + case EWsSdOpGetScreenNumber:
1.324 + SetReply(iScreen->ScreenNumber());
1.325 + break;
1.326 + case EWsSdOpGetScreenSizeModeList:
1.327 + SetReply(iScreen->GetScreenSizeModeListL());
1.328 + break;
1.329 + case EWsClOpSetBackLight:
1.330 + {
1.331 + TInt err=KErrNone;
1.332 + if(Screen()->BackLightFlag() && iWsOwner->ClientMessage().SecureId()==KEikSrvsSid)
1.333 + {
1.334 + TWindowServerEvent::ProcessErrorMessages(TWsErrorMessage::EBackLight, err=HAL::Set(iScreen->ScreenNumber(),HALData::EBacklightState,*pData.Int));
1.335 + SetReply(err);
1.336 + }
1.337 + else
1.338 + {
1.339 + User::Leave(KErrPermissionDenied);
1.340 + }
1.341 + }
1.342 + break;
1.343 + case EWsSdOpIsScreenModeDynamic:
1.344 + {
1.345 + TInt mode = (*pData.Int == -1) ? iAppMode : *pData.Int;
1.346 + TInt flags=0;
1.347 + TRAPD(err,flags = Screen()->ModeFlagsL(mode));
1.348 + if (err == KErrNone && flags & MWsScreenConfigList::EDynamic)
1.349 + {
1.350 + SetReply(ETrue);
1.351 + }
1.352 + else
1.353 + {
1.354 + SetReply(EFalse);
1.355 + }
1.356 + }
1.357 + break;
1.358 +
1.359 + default:
1.360 + ExtensionCommandL(aOpcode, aCmdData);
1.361 + break;
1.362 + }
1.363 + }
1.364 +
1.365 +void DWsScreenDevice::ExtensionCommandL(TInt aOpcode, const TAny *aCmdData)
1.366 + {
1.367 + TWsSdCmdUnion pData;
1.368 + pData.any=aCmdData;
1.369 + switch(aOpcode)
1.370 + {
1.371 + case EWsSdOpExtensionsSupported:
1.372 + {
1.373 + TInt reply=0;
1.374 + if (iDispCont)
1.375 + {
1.376 + reply|=TWsSdXDisplayControl;
1.377 + }
1.378 + if(iDispMap)
1.379 + {
1.380 + reply|=TWsSdXDisplayMapping;
1.381 + }
1.382 + MWsScreen* pOI=Screen();
1.383 + iTestScreenCapture = pOI->ObjectInterface<MWsTestScreenCapture>();
1.384 + if (iTestScreenCapture != NULL)
1.385 + {
1.386 + reply|=TWsSdXDebugComposition;
1.387 + }
1.388 + SetReply(reply);
1.389 + }
1.390 + break;
1.391 + case EWsSdOpXDcGetNumberOfResolutions:
1.392 + {
1.393 + if (iDispCont)
1.394 + {
1.395 + SetReply(iDispCont->NumberOfResolutions());
1.396 + }
1.397 + else
1.398 + {
1.399 + SetReply(KErrNotSupported);
1.400 + }
1.401 + }
1.402 + break;
1.403 + case EWsSdOpXDcGetResolutionsList:
1.404 + {
1.405 + if (iDispCont)
1.406 + {
1.407 + RArray<MWsDisplayControl::TResolution> resolutions;
1.408 + TInt err = iDispCont->GetResolutions(resolutions);
1.409 + if(err != KErrNone)
1.410 + {
1.411 + SetReply(err);
1.412 + resolutions.Close();
1.413 + break;
1.414 + }
1.415 + TInt bufLength = resolutions.Count()*sizeof(MWsDisplayControl::TResolution);
1.416 + SetReply(bufLength);
1.417 +
1.418 + if(CWsClient::ReplyBufSpace() >= bufLength)
1.419 + { //must not overflow the client's allocated storage.
1.420 + CWsClient::ReplyBuf(&resolutions[0], bufLength);
1.421 + }
1.422 + resolutions.Close();
1.423 + }
1.424 + else
1.425 + {
1.426 + SetReply(KErrNotSupported);
1.427 + }
1.428 + }
1.429 + break;
1.430 + case EWsSdOpXDcGetConfiguration:
1.431 + {
1.432 + if(iDispCont)
1.433 + {
1.434 + TDisplayConfiguration dispConfig = *pData.DisplayConfiguration;
1.435 + if (dispConfig.Version() < sizeof(TDisplayConfiguration))
1.436 + {
1.437 + //Test not required until there are multiple configuration sizes
1.438 + __ASSERT_COMPILE(sizeof(TDisplayConfiguration1)==sizeof(TDisplayConfiguration));
1.439 + //if (dispConfig.Version() != sizeof(TDisplayConfiguration1))
1.440 + {
1.441 + CWsClient::PanicCurrentClient(EWservPanicInvalidDisplayConfiguration);
1.442 + }
1.443 + }
1.444 + iDispCont->GetConfiguration(dispConfig);
1.445 + TInt expectedVersion = pData.DisplayConfiguration->Version();
1.446 + if (sizeof(TDisplayConfiguration)< expectedVersion)
1.447 + expectedVersion = sizeof(TDisplayConfiguration);
1.448 + CWsClient::ReplyBuf(&dispConfig, expectedVersion);
1.449 + }
1.450 + else
1.451 + {
1.452 + SetReply(KErrNotSupported);
1.453 + }
1.454 + SetReply(KErrNone);
1.455 + }
1.456 + break;
1.457 + case EWsSdOpXDcSetConfiguration:
1.458 + {
1.459 + TDisplayConfiguration dispConfig = *pData.DisplayConfiguration;
1.460 + if (dispConfig.Version() < TDisplayConfiguration().Version())
1.461 + {
1.462 + //Test not required until there are multiple configuration sizes
1.463 + __ASSERT_COMPILE(sizeof(TDisplayConfiguration1)==sizeof(TDisplayConfiguration));
1.464 + //if (dispConfig.Version() != sizeof(TDisplayConfiguration1))
1.465 + {
1.466 + CWsClient::PanicCurrentClient(EWservPanicInvalidDisplayConfiguration);
1.467 + }
1.468 + }
1.469 + TInt reply=Screen()->SetConfiguration(dispConfig);
1.470 + SetReply(reply);
1.471 + }
1.472 + break;
1.473 +
1.474 + case EWsSdOpXDcGetPreferredDisplayVersion:
1.475 + {
1.476 + if (iDispCont)
1.477 + {
1.478 + SetReply(iDispCont->PreferredDisplayVersion());
1.479 + }
1.480 + else
1.481 + {
1.482 + SetReply(KErrNotSupported);
1.483 + }
1.484 + }
1.485 + break;
1.486 + case EWsSdOpXDcNotifyOnDisplayChange:
1.487 + {
1.488 + if(iDispCont)
1.489 + {
1.490 + SetReply(Screen()->AddNotificationClient(iWsOwner));
1.491 + }
1.492 + else
1.493 + {
1.494 + SetReply(KErrNotSupported);
1.495 + }
1.496 + }
1.497 + break;
1.498 + case EWsSdOpXDcNotifyOnDisplayChangeCancel:
1.499 + {
1.500 + if (iDispCont)
1.501 + {
1.502 + Screen()->RemoveNotificationClient(iWsOwner);
1.503 + SetReply(KErrNone);
1.504 + }
1.505 + else
1.506 + {
1.507 + SetReply(KErrNotSupported);
1.508 + }
1.509 + }
1.510 + break;
1.511 + case EWsSdOpXTestScreenCapture:
1.512 + TestScreenCaptureL(pData.any);
1.513 + break;
1.514 + case EWsSdOpXTestScreenCaptureSize:
1.515 + CWsClient::ReplySize(iScreen->SizeInPixels());
1.516 + break;
1.517 + case EWsSdOpXDcDisplayChangeEventEnabled:
1.518 + {
1.519 + if(iDispCont)
1.520 + {
1.521 + if(Screen()->FindNotificationClient(iWsOwner) != KErrNotFound)
1.522 + {
1.523 + SetReply(1);
1.524 + break;
1.525 + }
1.526 + }
1.527 +
1.528 + SetReply(0);
1.529 +
1.530 + }
1.531 + break;
1.532 + case EWsSdOpXDmMapExtent:
1.533 + {
1.534 + if(iDispMap)
1.535 + {
1.536 + TWsSdCmdMapCoordinates mapCoord = *pData.MapCoordinates;
1.537 + TRect targetRect;
1.538 + TInt err = iDispMap->MapCoordinates(mapCoord.sourceSpace, mapCoord.sourceRect, mapCoord.targetSpace, targetRect);
1.539 + if(err != KErrNone)
1.540 + {
1.541 + SetReply(err);
1.542 + }
1.543 + else
1.544 + {
1.545 + CWsClient::ReplyBuf(&targetRect, sizeof(TRect));
1.546 + SetReply(KErrNone);
1.547 + }
1.548 + }
1.549 + else
1.550 + {
1.551 + SetReply(KErrNotSupported);
1.552 + }
1.553 + }
1.554 + break;
1.555 + default:
1.556 + OwnerPanic(EWservPanicOpcode);
1.557 + break;
1.558 + }
1.559 + }
1.560 +
1.561 +void DWsScreenDevice::SetScreenMode(TInt aMode)
1.562 + {
1.563 + if (!iScreen->IsValidScreenSizeMode(aMode))
1.564 + OwnerPanic(EWservPanicScreenModeNumber);
1.565 + iScreen->doSetScreenMode(aMode);
1.566 + }
1.567 +
1.568 +TSize DWsScreenDevice::AppScreenSizeInPixels() const
1.569 + {
1.570 + if (iAppScreenSizeInPixels == TSize(-1,-1))
1.571 + {
1.572 + TSize returnSize;
1.573 + TRAP_IGNORE(returnSize = iScreen->ScreenModeSizeInPixelsL(iAppMode));
1.574 + return returnSize;
1.575 + }
1.576 + return iAppScreenSizeInPixels;
1.577 + }
1.578 +
1.579 +TSize DWsScreenDevice::AppScreenSizeInTwips() const
1.580 + {
1.581 + if (iAppScreenSizeInTwips == TSize(-1,-1))
1.582 + {
1.583 + TSize returnSize;
1.584 + TRAP_IGNORE(returnSize = iScreen->ScreenModeSizeInTwipsL(iAppMode));
1.585 + return returnSize;
1.586 + }
1.587 + return iAppScreenSizeInTwips;
1.588 + }
1.589 +
1.590 +TBool DWsScreenDevice::ScreenDeviceValidState() const
1.591 + {
1.592 + WS_ASSERT_DEBUG(iScreen->IsValidScreenSizeMode(iScreen->ScreenSizeMode()), EWsPanicInvalidScreenSizeMode);
1.593 + const TSizeMode& currentMode=iScreen->ScreenSizeModeData();
1.594 + TBool state=ETrue;
1.595 +
1.596 + // In all enforcement modes scale should match, so check scale first
1.597 + if (iScreen->SizeEnforcementMode()!=ESizeEnforcementNone)
1.598 + {
1.599 + TSize appScreenSizeInPixels = AppScreenSizeInPixels();
1.600 + if (currentMode.iRotation!=iAppRotation)
1.601 + {
1.602 + state=EFalse;
1.603 + }
1.604 + else if (!(appScreenSizeInPixels == currentMode.iScreenSize))
1.605 + {
1.606 + state=EFalse;
1.607 + }
1.608 + }
1.609 + if (iScreen->SizeEnforcementMode()==ESizeEnforcementPixelsTwipsAndRotation)
1.610 + {
1.611 + TSize appScreenSizeInTwips = AppScreenSizeInTwips();
1.612 + if (!(appScreenSizeInTwips == currentMode.iScreenTwipsSize))
1.613 + {
1.614 + state=EFalse;
1.615 + }
1.616 + }
1.617 + return(state);
1.618 + }
1.619 +
1.620 +void DWsScreenDevice::ConstructL()
1.621 +//
1.622 +// App specific construct
1.623 +//
1.624 + {
1.625 + NewObjL();
1.626 + const TSizeMode& mode=iScreen->ScreenSizeModeData(iScreen->ScreenSizeMode());
1.627 + TInt modeNumber = iScreen->ScreenSizeMode();
1.628 + TInt flags = iScreen->ModeFlagsL(modeNumber);
1.629 + if (flags & MWsScreenConfigList::EDynamic)
1.630 + {
1.631 + iAppScreenSizeInPixels = TSize(-1,-1);
1.632 + iAppScreenSizeInTwips = TSize(-1,-1);
1.633 + }
1.634 + else
1.635 + {
1.636 + iAppScreenSizeInPixels=mode.iScreenSize;
1.637 + iAppScreenSizeInTwips=mode.iScreenTwipsSize;
1.638 + }
1.639 + iAppRotation=mode.iRotation;
1.640 + iAppMode=modeNumber;
1.641 + }
1.642 +
1.643 +void DWsScreenDevice::SetScreenSizeAndRotation(const TPixelsTwipsAndRotation &aSar)
1.644 + {
1.645 + iAppScreenSizeInPixels=aSar.iPixelSize;
1.646 + iAppScreenSizeInTwips=aSar.iTwipsSize;
1.647 + iAppRotation=aSar.iRotation;
1.648 + SetScreenDeviceValidStates(this);
1.649 + TInt flags=0;
1.650 + TRAP_IGNORE(flags = iScreen->ModeFlagsL(iScreen->ScreenSizeMode()));
1.651 + if (flags & MWsScreenConfigList::EDynamic)
1.652 + {
1.653 + iAppScreenSizeInPixels = TSize(-1,-1);
1.654 + iAppScreenSizeInTwips = TSize(-1,-1);
1.655 + }
1.656 + }
1.657 +
1.658 +void DWsScreenDevice::SetScreenSizeAndRotation(const TPixelsAndRotation &aSar)
1.659 + {
1.660 + iAppScreenSizeInPixels=aSar.iPixelSize;
1.661 + iAppScreenSizeInTwips.iWidth=iScreen->DeviceMap().HorizontalPixelsToTwips(iAppScreenSizeInPixels.iWidth);
1.662 + iAppScreenSizeInTwips.iHeight=iScreen->DeviceMap().VerticalPixelsToTwips(iAppScreenSizeInPixels.iHeight);
1.663 + iAppRotation=aSar.iRotation;
1.664 + SetScreenDeviceValidStates(this);
1.665 + TInt flags=0;
1.666 + TRAP_IGNORE(flags = iScreen->ModeFlagsL(iScreen->ScreenSizeMode()));
1.667 + if (flags & MWsScreenConfigList::EDynamic)
1.668 + {
1.669 + iAppScreenSizeInPixels = TSize(-1,-1);
1.670 + iAppScreenSizeInTwips = TSize(-1,-1);
1.671 + }
1.672 + }
1.673 +
1.674 +void DWsScreenDevice::GetCurrentScreenModeAttributes()
1.675 + {
1.676 + TSizeMode aModeData=iScreen->ScreenSizeModeData();
1.677 + CWsClient::ReplyBuf(&aModeData,sizeof(aModeData));
1.678 + }
1.679 +
1.680 +void DWsScreenDevice::SetCurrentScreenModeAttributes(const TSizeMode &aModeData)
1.681 + {
1.682 +#if defined(_DEBUG)
1.683 + if (aModeData.iScreenScale.iWidth==0 || aModeData.iScreenScale.iHeight==0)
1.684 + OwnerPanic(EWservPanicScreenModeNumber);
1.685 +#endif
1.686 + iScreen->SetCurrentScreenModeAttributes(aModeData);
1.687 + }
1.688 +
1.689 +void DWsScreenDevice::GetScreenSizeAndRotationCmd(TInt aMode)
1.690 + {
1.691 + if (!iScreen->IsValidScreenSizeMode(aMode))
1.692 + OwnerPanic(EWservPanicScreenModeNumber);
1.693 + TPixelsTwipsAndRotation sar;
1.694 + iScreen->GetScreenSizeAndRotation(sar,aMode);
1.695 + CWsClient::ReplyBuf(&sar, sizeof(sar));
1.696 + }
1.697 +
1.698 +void DWsScreenDevice::GetScreenSizeAndRotationCmd2(TInt aMode)
1.699 + {
1.700 + if (!iScreen->IsValidScreenSizeMode(aMode))
1.701 + OwnerPanic(EWservPanicScreenModeNumber);
1.702 + TPixelsAndRotation sar;
1.703 + iScreen->GetScreenSizeAndRotation(sar,aMode);
1.704 + CWsClient::ReplyBuf(&sar, sizeof(sar));
1.705 + }
1.706 +
1.707 +void DWsScreenDevice::GetScreenModeDisplayMode(const TInt aMode)
1.708 + {
1.709 + if (!iScreen->IsValidScreenSizeMode(aMode))
1.710 + {
1.711 + OwnerPanic(EWservPanicScreenModeNumber);
1.712 + }
1.713 + SetReply(STATIC_CAST(TInt,iScreen->DefaultDisplayMode(aMode)));
1.714 + }
1.715 +
1.716 +void DWsScreenDevice::SetAppScreenMode(TInt aMode)
1.717 + {
1.718 + if (!iScreen->IsValidScreenSizeMode(aMode))
1.719 + {
1.720 + OwnerPanic(EWservPanicScreenModeNumber);
1.721 + }
1.722 + const TSizeMode& sizeMode=iScreen->ScreenSizeModeData(aMode);
1.723 + TInt flags=0;
1.724 + TRAP_IGNORE(flags = iScreen->ModeFlagsL(aMode));
1.725 + if (flags & MWsScreenConfigList::EDynamic)
1.726 + {
1.727 + iAppScreenSizeInPixels = TSize(-1,-1);
1.728 + iAppScreenSizeInTwips = TSize(-1,-1);
1.729 + }
1.730 + else
1.731 + {
1.732 + iAppScreenSizeInPixels=sizeMode.iScreenSize;
1.733 + iAppScreenSizeInTwips=sizeMode.iScreenTwipsSize;
1.734 + }
1.735 + iAppMode=aMode;
1.736 + iAppRotation=sizeMode.iRotation;
1.737 + CWsWindowGroup::SetScreenDeviceValidStates(this);
1.738 + }
1.739 +
1.740 +#define ROTATION_TO_FLAG(x) 1<<x
1.741 +
1.742 +void DWsScreenDevice::SetScreenDeviceValidStates(const DWsScreenDevice *aDevice)
1.743 + {
1.744 + TInt modes=iScreen->NumScreenSizeModes();
1.745 + TInt mode;
1.746 + for (mode=0;mode<modes;++mode)
1.747 + {
1.748 + TInt flags=0;
1.749 + TRAPD(err,flags = iScreen->ModeFlagsL(mode));
1.750 + if (err != KErrNone || flags&MWsScreenConfigList::EDynamic)
1.751 + {
1.752 + continue;
1.753 + }
1.754 + const TSizeMode& sizeMode=iScreen->ScreenSizeModeData(mode);
1.755 + if (iAppScreenSizeInPixels==sizeMode.iScreenSize && ROTATION_TO_FLAG(iAppRotation)&sizeMode.iAlternativeRotations)
1.756 + {
1.757 + iAppMode=mode;
1.758 + break;
1.759 + }
1.760 + }
1.761 + CWsWindowGroup::SetScreenDeviceValidStates(aDevice);
1.762 + }
1.763 +
1.764 +void DWsScreenDevice::NewOrientation(TInt aMode,CFbsBitGc::TGraphicsOrientation aRotation)
1.765 + {
1.766 + if (iAppMode==aMode)
1.767 + iAppRotation=aRotation;
1.768 + }
1.769 +
1.770 +void DWsScreenDevice::SetPaletteL()
1.771 + {
1.772 + MWsScreen* pOI=iScreen;
1.773 + MWsPalette* paletteInterface = pOI->ObjectInterface<MWsPalette>();
1.774 +
1.775 + if (paletteInterface)
1.776 + {
1.777 + const TInt size=iWsOwner->ClientMessage().GetDesLength(KRemoteBufferMessageSlot);
1.778 + TInt numEntries=size/sizeof(TRgb);
1.779 + CPalette* palette=CPalette::NewL(numEntries);
1.780 + CleanupStack::PushL(palette);
1.781 + TPtr8 paletteData(NULL,0);
1.782 + palette->GetDataPtr(0,numEntries,paletteData);
1.783 + iWsOwner->RemoteReadL(paletteData,0);
1.784 + SetReply(paletteInterface->SetCustomPalette(palette));
1.785 + CleanupStack::PopAndDestroy(palette);
1.786 + }
1.787 + else
1.788 + SetReply(KErrNotSupported);
1.789 + }
1.790 +
1.791 +void DWsScreenDevice::GetPalette(TInt aNumColors)
1.792 + {
1.793 + MWsScreen* pOI=iScreen;
1.794 + MWsPalette* paletteInterface = pOI->ObjectInterface<MWsPalette>();
1.795 +
1.796 + if (paletteInterface)
1.797 + {
1.798 + CPalette* palette = NULL;
1.799 + TInt ret = paletteInterface->GetPalette(palette);
1.800 +
1.801 + if (ret != KErrNone)
1.802 + {
1.803 + SetReply(ret);
1.804 + return;
1.805 + }
1.806 +
1.807 + ret = palette->Entries();
1.808 +
1.809 + if (ret != aNumColors)
1.810 + {
1.811 + delete palette;
1.812 + SetReply(ret);
1.813 + return;
1.814 + }
1.815 +
1.816 + TPtr8 paletteData(NULL,0);
1.817 + palette->GetDataPtr(0,ret,paletteData);
1.818 + CWsClient::ReplyBuf(paletteData);
1.819 + SetReply(KErrNone);
1.820 + delete palette;
1.821 + }
1.822 + else
1.823 + SetReply(KErrNotSupported);
1.824 + }
1.825 +
1.826 +TUint DWsScreenDevice::ClientDevicePointer()
1.827 + {
1.828 + return iClientScreenDevicePointer;
1.829 + }
1.830 +//Integer version means callers don't need exported panic enumeration
1.831 +void DWsScreenDevice::PanicCurrentClient(TInt aPanic)
1.832 + {
1.833 + PanicCurrentClient((TClientPanic)aPanic);
1.834 + }
1.835 +
1.836 +//Allows render stage to initiate a client panic
1.837 +void DWsScreenDevice::PanicCurrentClient(TClientPanic aPanic)
1.838 + {
1.839 + CWsClient::PanicCurrentClient(aPanic);
1.840 + }
1.841 +
1.842 +void DWsScreenDevice::SetReply(TInt aReply)
1.843 + {
1.844 + CWsObject::SetReply(aReply);
1.845 + }
1.846 +
1.847 +void DWsScreenDevice::RedrawNowIfPending()
1.848 + {
1.849 + iScreen->RedrawNowIfPending();
1.850 + }
1.851 +
1.852 +void DWsScreenDevice::ReplyBuf(const TAny* aSource, TInt aLength)
1.853 + {
1.854 + TPtrC8 src(reinterpret_cast<const TUint8*>(aSource),aLength);
1.855 + CWsClient::ReplyBuf(src);
1.856 + }
1.857 +
1.858 +void DWsScreenDevice::TestScreenCaptureL(const TAny* aMessage)
1.859 + {
1.860 + if (iTestScreenCapture == NULL)
1.861 + {
1.862 + // at this point we expect that Screen Capture Interface exists always
1.863 + OwnerPanic(EWservPanicScreenCaptureInvalidRequest);
1.864 + SetReply(KErrNotSupported);
1.865 + }
1.866 + iTestScreenCapture->TestScreenCaptureL(aMessage, *static_cast<MWsScreenDeviceUtils*>(this));
1.867 + }