sl@0: // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // Screen device sl@0: // sl@0: // sl@0: sl@0: #include "ScrDev.H" sl@0: #include "Direct.H" sl@0: sl@0: #include sl@0: #include sl@0: #include "server.h" sl@0: #include "gc.h" sl@0: #include "rootwin.h" sl@0: #include "windowgroup.h" sl@0: #include "wstop.h" sl@0: #include "EVENT.H" sl@0: #include "panics.h" sl@0: #include "../CLIENT/w32comm.h" sl@0: #include sl@0: sl@0: const TInt KEikSrvsSid=0x10003a4a; sl@0: sl@0: static _LIT_SECURITY_POLICY_C1(KSecurityPolicy_WriteDeviceData,ECapabilityWriteDeviceData); sl@0: sl@0: /*DWsScreenDevice*/ sl@0: sl@0: DWsScreenDevice::DWsScreenDevice(CWsClient* aOwner, TInt aDefaultScreenNumber, TUint aClientScreenDevicePointer) sl@0: : CWsScreenObject(aOwner, WS_HANDLE_SCREEN_DEVICE, CWsTop::Screen( aDefaultScreenNumber )), sl@0: iClientScreenDevicePointer(aClientScreenDevicePointer) sl@0: {} sl@0: sl@0: DWsScreenDevice::~DWsScreenDevice() sl@0: {} sl@0: sl@0: void DWsScreenDevice::CopyScreenToBitmapL(const TRect &aRect, TInt aHandle) sl@0: { sl@0: CFbsBitmap *bitmap=new(ELeave) CFbsBitmap(); sl@0: CleanupStack::PushL(bitmap); sl@0: TInt ret = bitmap->Duplicate(aHandle); sl@0: if (ret == KErrNoMemory) sl@0: { sl@0: User::Leave(ret); sl@0: } sl@0: if (ret != KErrNone) sl@0: OwnerPanic(EWservPanicBitmap); sl@0: sl@0: CFbsBitmapDevice *device=CFbsBitmapDevice::NewL(bitmap); sl@0: CleanupStack::PushL(device); sl@0: CFbsBitGc *gc; sl@0: User::LeaveIfError(device->CreateContext(gc)); sl@0: CleanupStack::PushL(gc); //Don't need to push this, but this is probably the eaiest way to delete it sl@0: gc->SetDrawMode( CGraphicsContext::EDrawModeWriteAlpha ); sl@0: gc->BitBlt(TPoint(), *iScreen->ScreenGdi(), aRect); sl@0: CleanupStack::PopAndDestroy(3); sl@0: } sl@0: sl@0: void DWsScreenDevice::CommandL(TInt aOpcode, const TAny *aCmdData) sl@0: { sl@0: TWsSdCmdUnion pData; sl@0: pData.any=aCmdData; sl@0: switch(aOpcode) sl@0: { sl@0: case EWsSdOpGetNumScreenModes: sl@0: SetReply(iScreen->NumScreenSizeModes()); sl@0: break; sl@0: case EWsSdOpGetScreenMode: sl@0: SetReply(iScreen->ScreenSizeMode()); sl@0: break; sl@0: case EWsSdOpSetScreenMode: sl@0: { sl@0: if(!KSecurityPolicy_WriteDeviceData().CheckPolicy(iWsOwner->ClientMessage(),__PLATSEC_DIAGNOSTIC_STRING("Capability check failed for CWsScreenDevice::SetScreenMode API"))) sl@0: { sl@0: iWsOwner->PPanic(EWservPanicPermissionDenied); sl@0: } sl@0: SetScreenMode(*pData.Int); sl@0: } sl@0: break; sl@0: case EWsSdOpSetModeRotation: sl@0: { sl@0: if(KSecurityPolicy_WriteDeviceData().CheckPolicy(iWsOwner->ClientMessage(),__PLATSEC_DIAGNOSTIC_STRING("Capability check failed for CWsScreenDevice::SetModeRotation API"))) sl@0: { sl@0: TClientPanic panic=iScreen->SetModeRotation(pData.SetScreenRotation->mode,pData.SetScreenRotation->rotation); sl@0: if (panic) sl@0: OwnerPanic(panic); sl@0: } sl@0: } sl@0: break; sl@0: case EWsSdOpGetRotationList: sl@0: if (!iScreen->IsValidScreenSizeMode(*pData.Int)) sl@0: OwnerPanic(EWservPanicScreenModeNumber); sl@0: SetReply(iScreen->ScreenSizeModeData(*pData.Int).iAlternativeRotations); sl@0: break; sl@0: case EWsSdOpGetScreenModeSizeAndRotation: sl@0: GetScreenSizeAndRotationCmd(*pData.Int); sl@0: break; sl@0: case EWsSdOpGetScreenModeSizeAndRotation2: sl@0: GetScreenSizeAndRotationCmd2(*pData.Int); sl@0: break; sl@0: case EWsSdOpSetScreenSizeAndRotation: sl@0: SetScreenSizeAndRotation(*pData.PixelsTwipsAndRotation); sl@0: break; sl@0: case EWsSdOpSetScreenSizeAndRotation2: sl@0: SetScreenSizeAndRotation(*pData.PixelsAndRotation); sl@0: break; sl@0: case EWsSdOpGetDefaultScreenSizeAndRotation: sl@0: GetScreenSizeAndRotationCmd(iScreen->ScreenSizeMode()); sl@0: break; sl@0: case EWsSdOpGetDefaultScreenSizeAndRotation2: sl@0: GetScreenSizeAndRotationCmd2(iScreen->ScreenSizeMode()); sl@0: break; sl@0: case EWsSdOpGetScreenModeDisplayMode: sl@0: GetScreenModeDisplayMode(*pData.Int); sl@0: break; sl@0: case EWsSdOpGetScreenModeScale: sl@0: GetScreenScale(*pData.Int); sl@0: break; sl@0: case EWsSdOpGetCurrentScreenModeScale: sl@0: GetScreenScale(iScreen->ScreenSizeMode()); sl@0: break; sl@0: case EWsSdOpSetAppScreenMode: sl@0: SetAppScreenMode(*pData.Int); sl@0: break; sl@0: case EWsSdOpGetCurrentScreenModeScaledOrigin: sl@0: CWsClient::ReplyPoint(iScreen->CurrentScreenModeScaledOrigin()); sl@0: break; sl@0: case EWsSdOpGetScreenModeScaledOrigin: sl@0: if (!iScreen->IsValidScreenSizeMode(*pData.Int)) sl@0: OwnerPanic(EWservPanicScreenModeNumber); sl@0: CWsClient::ReplyPoint(iScreen->ScreenModeScaledOrigin(*pData.Int)); sl@0: break; sl@0: case EWsSdOpGetCurrentScreenModeAttributes: sl@0: GetCurrentScreenModeAttributes(); sl@0: break; sl@0: case EWsSdOpSetCurrentScreenModeAttributes: sl@0: 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: { sl@0: iWsOwner->PPanic(EWservPanicPermissionDenied); sl@0: } sl@0: SetCurrentScreenModeAttributes(*pData.ScreenSizeMode); sl@0: break; sl@0: case EWsSdOpSetScreenModeEnforcement: sl@0: { sl@0: if(!KSecurityPolicy_WriteDeviceData().CheckPolicy(iWsOwner->ClientMessage(),__PLATSEC_DIAGNOSTIC_STRING("Capability check failed for CWsScreenDevice::SetScreenModeEnforcement API"))) sl@0: { sl@0: iWsOwner->PPanic(EWservPanicPermissionDenied); sl@0: } sl@0: if (!iScreen->SetScreenModeEnforcement(*pData.Int)) sl@0: OwnerPanic(EWservPanicScreenEnforcementMode); sl@0: } sl@0: break; sl@0: case EWsSdOpScreenModeEnforcement: sl@0: SetReply(iScreen->SizeEnforcementMode()); sl@0: break; sl@0: case EWsSdOpGetDefaultScreenModeOrigin: sl@0: GetScreenModeOriginCmd(iScreen->ScreenSizeMode()); sl@0: break; sl@0: case EWsSdOpGetScreenModeOrigin: sl@0: GetScreenModeOriginCmd(*pData.Int); sl@0: break; sl@0: case EWsSdOpPixel: sl@0: { sl@0: TRgb rgb; sl@0: iScreen->ScreenDevice()->GetPixel(rgb,*pData.Point); sl@0: SetReply(rgb.Internal()); sl@0: } sl@0: break; sl@0: case EWsSdOpGetScanLine: sl@0: iScreen->GetScanLine(pData.GetScanLine); sl@0: break; sl@0: case EWsSdOpTwipsSize: sl@0: CWsClient::ReplySize(iAppScreenSizeInTwips); sl@0: break; sl@0: case EWsSdOpPixelSize: sl@0: CWsClient::ReplySize(iAppScreenSizeInPixels); sl@0: break; sl@0: case EWsSdOpHorizontalTwipsToPixels: sl@0: SetReply(iScreen->ScreenDevice()->HorizontalTwipsToPixels(*pData.UInt)); sl@0: break; sl@0: case EWsSdOpVerticalTwipsToPixels: sl@0: SetReply(iScreen->ScreenDevice()->VerticalTwipsToPixels(*pData.UInt)); sl@0: break; sl@0: case EWsSdOpHorizontalPixelsToTwips: sl@0: SetReply(iScreen->ScreenDevice()->HorizontalPixelsToTwips(*pData.UInt)); sl@0: break; sl@0: case EWsSdOpVerticalPixelsToTwips: sl@0: SetReply(iScreen->ScreenDevice()->VerticalPixelsToTwips(*pData.UInt)); sl@0: break; sl@0: case EWsSdOpPointerRect: sl@0: { sl@0: TMachineInfoV1Buf macInfo; sl@0: UserHal::MachineInfo(macInfo); sl@0: TRect rect(-macInfo().iOffsetToDisplayInPixels,macInfo().iXYInputSizeInPixels); sl@0: CWsClient::ReplyRect(rect); sl@0: } sl@0: break; sl@0: case EWsSdOpFree: sl@0: { sl@0: // Mark any group windows associated with the screen device being deleted sl@0: CWsRootWindow* root=iScreen->RootWindow(); sl@0: for (CWsWindowGroup* grp = root->Child(); grp; grp = grp->NextSibling()) sl@0: { sl@0: if (grp->Device() == this) sl@0: { sl@0: #if defined(_DEBUG) sl@0: grp->SetScreenDeviceDeleted(); sl@0: #endif sl@0: grp->SetScreenDevice(NULL); sl@0: } sl@0: } sl@0: } sl@0: // Let our owner (CWsClient) know that a screen device is being deleted so it sl@0: // can check whether to reset its iPrimaryScreenDevice member or not sl@0: if (WsOwner()) sl@0: WsOwner()->NotifyScreenDeviceDeleted(this); sl@0: delete this; sl@0: break; sl@0: case EWsSdOpDisplayMode: sl@0: iScreen->ScreenGdi(); // To force display mode update if required sl@0: SetReply(iScreen->CurrentDisplayMode()); sl@0: break; sl@0: case EWsSdOpRectCompare: sl@0: { sl@0: // if (pData.RectCompare->flags&CWsScreenDevice::EIncludeSprite) sl@0: // { sl@0: // SpriteManager()->IncrementProcessingSprites(); sl@0: // } sl@0: sl@0: RWsTextCursor * cursor = 0; sl@0: if (!pData.RectCompare->flags&CWsScreenDevice::EIncludeTextCursor) sl@0: cursor = CWsTop::CurrentTextCursor(); sl@0: if (cursor) sl@0: cursor->Disable(); sl@0: sl@0: SetReply(iScreen->ScreenDevice()->RectCompare(pData.RectCompare->rect1,*iScreen->ScreenDevice(),pData.RectCompare->rect2)); sl@0: sl@0: if (cursor) sl@0: cursor->Enable(); sl@0: sl@0: // if (pData.RectCompare->flags&CWsScreenDevice::EIncludeSprite) sl@0: // { sl@0: // SpriteManager()->DecrementProcessingSprites(); sl@0: // } sl@0: } sl@0: break; sl@0: case EWsSdOpCopyScreenToBitmap: sl@0: CopyScreenToBitmapL(TRect(iScreen->ScreenDevice()->SizeInPixels()),pData.CopyScreenToBitmap->handle); sl@0: break; sl@0: case EWsSdOpCopyScreenToBitmap2: sl@0: CopyScreenToBitmapL(pData.CopyScreenToBitmap2->rect,pData.CopyScreenToBitmap2->handle); sl@0: break; sl@0: case EWsSdOpPaletteAttributes: sl@0: { sl@0: TBool modifiable; sl@0: TInt numEntries; sl@0: iScreen->ScreenDevice()->PaletteAttributes(modifiable,numEntries); sl@0: if (modifiable) sl@0: numEntries|=EWsSdSetableBitFlag; sl@0: SetReply(numEntries); sl@0: } sl@0: break; sl@0: case EWsSdOpSetPalette: sl@0: { sl@0: if(!KSecurityPolicy_WriteDeviceData().CheckPolicy(iWsOwner->ClientMessage(),__PLATSEC_DIAGNOSTIC_STRING("Capability check failed for CWsScreenDevice::SetPalette API"))) sl@0: { sl@0: User::Leave(KErrPermissionDenied); sl@0: } sl@0: SetPaletteL(); sl@0: } sl@0: break; sl@0: case EWsSdOpGetPalette: sl@0: GetPalette(*pData.Int); sl@0: break; sl@0: sl@0: case EWsSdOpGetScreenNumber: sl@0: SetReply(iScreen->ScreenNumber()); sl@0: break; sl@0: case EWsSdOpGetScreenSizeModeList: sl@0: SetReply(iScreen->GetScreenSizeModeListL()); sl@0: break; sl@0: case EWsClOpSetBackLight: sl@0: { sl@0: TInt err=KErrNone; sl@0: if(Screen()->BackLightFlag() && iWsOwner->ClientMessage().SecureId()==KEikSrvsSid) sl@0: { sl@0: TWindowServerEvent::ProcessErrorMessages(TWsErrorMessage::EBackLight, err=HAL::Set(iScreen->ScreenNumber(),HALData::EBacklightState,*pData.Int)); sl@0: SetReply(err); sl@0: } sl@0: else sl@0: { sl@0: User::Leave(KErrPermissionDenied); sl@0: } sl@0: } sl@0: break; sl@0: default: sl@0: OwnerPanic(EWservPanicOpcode); sl@0: break; sl@0: } sl@0: } sl@0: sl@0: sl@0: void DWsScreenDevice::SetScreenMode(TInt aMode) sl@0: { sl@0: if (!iScreen->IsValidScreenSizeMode(aMode)) sl@0: OwnerPanic(EWservPanicScreenModeNumber); sl@0: iScreen->doSetScreenMode(aMode); sl@0: } sl@0: sl@0: TBool DWsScreenDevice::ScreenDeviceValidState() const sl@0: { sl@0: WS_ASSERT_DEBUG(iScreen->IsValidScreenSizeMode(iScreen->ScreenSizeMode()), EWsPanicInvalidScreenSizeMode); sl@0: const TSizeMode& currentMode=iScreen->ScreenSizeModeData(); sl@0: TBool state=ETrue; sl@0: // In all enforcement modes scale should match, so check scale first sl@0: if (currentMode.iScreenScale!=iAppScale) sl@0: { sl@0: state=EFalse; sl@0: } sl@0: else sl@0: { sl@0: if (iScreen->SizeEnforcementMode()!=ESizeEnforcementNone) sl@0: { sl@0: if (currentMode.iRotation!=iAppRotation) sl@0: state=EFalse; sl@0: else if (currentMode.iScreenSize!=iAppScreenSizeInPixels) sl@0: state=EFalse; sl@0: } sl@0: if (iScreen->SizeEnforcementMode()==ESizeEnforcementPixelsTwipsAndRotation) sl@0: { sl@0: if (currentMode.iScreenTwipsSize!=iAppScreenSizeInTwips) sl@0: state=EFalse; sl@0: } sl@0: } sl@0: return(state); sl@0: } sl@0: sl@0: void DWsScreenDevice::ConstructL() sl@0: // sl@0: // App specific construct sl@0: // sl@0: { sl@0: NewObjL(); sl@0: const TSizeMode& mode=iScreen->ScreenSizeModeData(iScreen->ScreenSizeMode()); sl@0: iAppScreenSizeInPixels=mode.iScreenSize; sl@0: iAppScreenSizeInTwips=mode.iScreenTwipsSize; sl@0: iAppRotation=mode.iRotation; sl@0: iAppMode=iScreen->ScreenSizeMode(); sl@0: iAppScale=mode.iScreenScale; sl@0: } sl@0: sl@0: void DWsScreenDevice::SetScreenSizeAndRotation(const TPixelsTwipsAndRotation &aSar) sl@0: { sl@0: iAppScreenSizeInPixels=aSar.iPixelSize; sl@0: iAppScreenSizeInTwips=aSar.iTwipsSize; sl@0: iAppRotation=aSar.iRotation; sl@0: SetScreenDeviceValidStates(this); sl@0: } sl@0: sl@0: void DWsScreenDevice::SetScreenSizeAndRotation(const TPixelsAndRotation &aSar) sl@0: { sl@0: iAppScreenSizeInPixels=aSar.iPixelSize; sl@0: iAppScreenSizeInTwips.iWidth=iScreen->ScreenDevice()->HorizontalPixelsToTwips(iAppScreenSizeInPixels.iWidth); sl@0: iAppScreenSizeInTwips.iHeight=iScreen->ScreenDevice()->VerticalPixelsToTwips(iAppScreenSizeInPixels.iHeight); sl@0: iAppRotation=aSar.iRotation; sl@0: SetScreenDeviceValidStates(this); sl@0: } sl@0: sl@0: void DWsScreenDevice::GetScreenModeOriginCmd(TInt aMode) sl@0: { sl@0: if (!iScreen->IsValidScreenSizeMode(aMode)) sl@0: OwnerPanic(EWservPanicScreenModeNumber); sl@0: CWsClient::ReplyPoint(iScreen->ScreenModeOrigin(aMode)); sl@0: } sl@0: sl@0: void DWsScreenDevice::GetCurrentScreenModeAttributes() sl@0: { sl@0: TSizeMode aModeData=iScreen->ScreenSizeModeData(); sl@0: CWsClient::ReplyBuf(&aModeData,sizeof(aModeData)); sl@0: } sl@0: sl@0: void DWsScreenDevice::SetCurrentScreenModeAttributes(const TSizeMode &aModeData) sl@0: { sl@0: #if defined(_DEBUG) sl@0: if (aModeData.iScreenScale.iWidth==0 || aModeData.iScreenScale.iHeight==0) sl@0: OwnerPanic(EWservPanicScreenModeNumber); sl@0: #endif sl@0: iScreen->SetCurrentScreenModeAttributes(aModeData); sl@0: } sl@0: sl@0: void DWsScreenDevice::GetScreenSizeAndRotationCmd(TInt aMode) sl@0: { sl@0: if (!iScreen->IsValidScreenSizeMode(aMode)) sl@0: OwnerPanic(EWservPanicScreenModeNumber); sl@0: TPixelsTwipsAndRotation sar; sl@0: iScreen->GetScreenSizeAndRotation(sar,aMode); sl@0: CWsClient::ReplyBuf(&sar, sizeof(sar)); sl@0: } sl@0: sl@0: void DWsScreenDevice::GetScreenSizeAndRotationCmd2(TInt aMode) sl@0: { sl@0: if (!iScreen->IsValidScreenSizeMode(aMode)) sl@0: OwnerPanic(EWservPanicScreenModeNumber); sl@0: TPixelsAndRotation sar; sl@0: iScreen->GetScreenSizeAndRotation(sar,aMode); sl@0: CWsClient::ReplyBuf(&sar, sizeof(sar)); sl@0: } sl@0: sl@0: void DWsScreenDevice::GetScreenModeDisplayMode(const TInt aMode) sl@0: { sl@0: if (!iScreen->IsValidScreenSizeMode(aMode)) sl@0: { sl@0: OwnerPanic(EWservPanicScreenModeNumber); sl@0: } sl@0: SetReply(STATIC_CAST(TInt,iScreen->DefaultDisplayMode(aMode))); sl@0: } sl@0: sl@0: void DWsScreenDevice::GetScreenScale(TInt aMode) sl@0: { sl@0: if (!iScreen->IsValidScreenSizeMode(aMode)) sl@0: { sl@0: OwnerPanic(EWservPanicScreenModeNumber); sl@0: } sl@0: CWsClient::ReplySize(iScreen->GetScreenScale(aMode)); sl@0: } sl@0: sl@0: void DWsScreenDevice::SetAppScreenMode(TInt aMode) sl@0: { sl@0: if (!iScreen->IsValidScreenSizeMode(aMode)) sl@0: { sl@0: OwnerPanic(EWservPanicScreenModeNumber); sl@0: } sl@0: const TSizeMode& sizeMode=iScreen->ScreenSizeModeData(aMode); sl@0: iAppScreenSizeInPixels=sizeMode.iScreenSize; sl@0: iAppScreenSizeInTwips=sizeMode.iScreenTwipsSize; sl@0: iAppMode=aMode; sl@0: iAppScale=sizeMode.iScreenScale; sl@0: iAppRotation=sizeMode.iRotation; sl@0: CWsWindowGroup::SetScreenDeviceValidStates(this); sl@0: } sl@0: sl@0: #define ROTATION_TO_FLAG(x) 1<NumScreenSizeModes(); sl@0: TInt mode; sl@0: for (mode=0;modeIsValidScreenSizeMode(mode)) sl@0: continue; sl@0: const TSizeMode& sizeMode=iScreen->ScreenSizeModeData(mode); sl@0: if (iAppScreenSizeInPixels==sizeMode.iScreenSize && ROTATION_TO_FLAG(iAppRotation)&sizeMode.iAlternativeRotations) sl@0: { sl@0: iAppMode=mode; sl@0: iAppScale=sizeMode.iScreenScale; sl@0: break; sl@0: } sl@0: } sl@0: CWsWindowGroup::SetScreenDeviceValidStates(aDevice); sl@0: } sl@0: sl@0: void DWsScreenDevice::NewOrientation(TInt aMode,CFbsBitGc::TGraphicsOrientation aRotation) sl@0: { sl@0: if (iAppMode==aMode) sl@0: iAppRotation=aRotation; sl@0: } sl@0: sl@0: void DWsScreenDevice::SetPaletteL() sl@0: { sl@0: const TInt size=iWsOwner->ClientMessage().GetDesLength(KRemoteBufferMessageSlot); sl@0: TInt numEntries=size/sizeof(TRgb); sl@0: CPalette* palette=CPalette::NewL(numEntries); sl@0: CleanupStack::PushL(palette); sl@0: TPtr8 paletteData(NULL,0); sl@0: palette->GetDataPtr(0,numEntries,paletteData); sl@0: iWsOwner->RemoteReadL(paletteData,0); sl@0: SetReply(iScreen->ScreenDevice()->SetCustomPalette(palette)); sl@0: iScreen->Update((RWsRegion&)RootWindow()->WindowArea()); sl@0: CleanupStack::PopAndDestroy(palette); sl@0: } sl@0: sl@0: void DWsScreenDevice::GetPalette(TInt aNumColors) sl@0: { sl@0: CPalette* palette; sl@0: TInt ret=iScreen->ScreenDevice()->GetPalette(palette); sl@0: if (retEntries(); sl@0: if (ret!=aNumColors) sl@0: { sl@0: delete palette; sl@0: Reply: sl@0: SetReply(ret); sl@0: return; sl@0: } sl@0: TPtr8 paletteData(NULL,0); sl@0: palette->GetDataPtr(0,ret,paletteData); sl@0: CWsClient::ReplyBuf(paletteData); sl@0: SetReply(KErrNone); sl@0: delete palette; sl@0: } sl@0: sl@0: TUint DWsScreenDevice::ClientDevicePointer() sl@0: { sl@0: return iClientScreenDevicePointer; sl@0: }