1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/windowing/windowserver/nga/CLIENT/scrdevextension.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,352 @@
1.4 +// Copyright (c) 2008-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 +//
1.18 +
1.19 +#include "scrdevextension.h"
1.20 +#include "../SERVER/w32cmd.h"
1.21 +#include <graphics/displaycontrolbase.h>
1.22 +#include "CLIENT.H"
1.23 +#include "w32comm.h"
1.24 +
1.25 +CWsScreenDevice::CScrDevExtension::CScrDevExtension(RWsBuffer *aBuffer,TInt32 aWsHandle): MWsClientClass(aBuffer)
1.26 + {
1.27 + iWsHandle=aWsHandle;
1.28 + __ASSERT_DEBUG(aBuffer,Panic(EW32PanicBadClientInterface));
1.29 + __ASSERT_DEBUG(aWsHandle,Panic(EW32PanicBadClientInterface));
1.30 + }
1.31 +
1.32 +CWsScreenDevice::CScrDevExtension::~CScrDevExtension()
1.33 + {
1.34 + //typeface store is not owned by this class, and is created/destroyed in CWsScreenDevice
1.35 + }
1.36 +/** Interface Extension capability
1.37 + * Use of this interface going forward will allow the published client interface to be dynamically extended.
1.38 + * Note that the pointer returned is only good for the lifetime of the called CBase derived object.
1.39 + * @pre caller has already checked that the implementation is initialised using RepeatableConstruct
1.40 + * @param aInterfaceId uniqueid or well known id of interface
1.41 + * @return pointer to interface object matching this ID or NULL if no match.
1.42 + **/
1.43 +void* CWsScreenDevice::CScrDevExtension::GetInterface(TUint aInterfaceId)
1.44 + {
1.45 + if (RepeatableConstruct()<KErrNone)
1.46 + {
1.47 + return NULL;
1.48 + }
1.49 + __ASSERT_DEBUG(this!=NULL,Panic(EW32PanicBadClientInterface));
1.50 + __ASSERT_DEBUG(iBuffer,Panic(EW32PanicBadClientInterface));
1.51 + __ASSERT_DEBUG(iWsHandle!=NULL,Panic(EW32PanicBadClientInterface));
1.52 +
1.53 + switch (aInterfaceId)
1.54 + {
1.55 + case MDisplayControlBase::ETypeId:
1.56 + if (iSupportedExtensionsBits&TWsSdXDisplayControl)
1.57 + {
1.58 + return static_cast<MDisplayControlBase*>(this);
1.59 + }
1.60 + break;
1.61 + case MDisplayControl::ETypeId:
1.62 + if (iSupportedExtensionsBits&TWsSdXDisplayControl)
1.63 + {
1.64 + return static_cast<MDisplayControl*>(this);
1.65 + }
1.66 + break;
1.67 + case MDisplayMappingBase::ETypeId:
1.68 + if(iSupportedExtensionsBits&TWsSdXDisplayMapping)
1.69 + {
1.70 + return static_cast<MDisplayMappingBase*>(this);
1.71 + }
1.72 + break;
1.73 + case MDisplayMapping::ETypeId:
1.74 + if(iSupportedExtensionsBits&TWsSdXDisplayMapping)
1.75 + {
1.76 + return static_cast<MDisplayMapping*>(this);
1.77 + }
1.78 + break;
1.79 + case MTestScreenCapture::ETypeId:
1.80 + {
1.81 + TInt requiredIf = TWsSdXDebugComposition | TWsSdXDisplayMapping;
1.82 + if ((iSupportedExtensionsBits & requiredIf) == requiredIf)
1.83 + {
1.84 + return static_cast<MTestScreenCapture*>(this);
1.85 + }
1.86 + break;
1.87 + }
1.88 + default:
1.89 + break;
1.90 + }
1.91 + return NULL;
1.92 +}
1.93 +//Accessor to typeface store instance
1.94 +CFbsTypefaceStore* CWsScreenDevice::CScrDevExtension::TypefaceStore()
1.95 + {
1.96 + return iTypefaceStore;
1.97 + }
1.98 +//Accessor to typeface store instance
1.99 +void CWsScreenDevice::CScrDevExtension::SetTypefaceStore(CFbsTypefaceStore* aTypeFaceStore)
1.100 + {
1.101 + iTypefaceStore=aTypeFaceStore;
1.102 + }
1.103 +
1.104 +/**
1.105 + * Constructs the extension interface implementation, or returns error if interface is not available.
1.106 + * After success, the interface is then always available and is not re-constructed if method called again,
1.107 + * but after failure the construct attempt will be repeated (and fail again) if the method is called again.
1.108 + * Clients would be expected to make then keep a pointer to this interface, not get new ones repeatedly.
1.109 + * Note that if the extension was not allocated, then "this" could be NULL
1.110 + * @param aWsHandle server-side object handle to use in messages if first time
1.111 + * @return KErrNone if initialised correctly, or a standard error code.
1.112 + **/
1.113 +TInt CWsScreenDevice::CScrDevExtension::RepeatableConstruct()
1.114 + {
1.115 + if (this==NULL)
1.116 + {
1.117 + return KErrNoMemory; //The extension was not allocated. Making this call is bad!
1.118 + }
1.119 + __ASSERT_DEBUG(iBuffer,Panic(EW32PanicBadClientInterface));
1.120 + __ASSERT_DEBUG(iWsHandle,Panic(EW32PanicBadClientInterface));
1.121 + if (iSupportedExtensionsBits==0)
1.122 + { //need to initialise
1.123 + TInt ExtensionsOrError= WriteReply(EWsSdOpExtensionsSupported);
1.124 + if (ExtensionsOrError&TWsSdXReservedErrorFlag)
1.125 + {
1.126 + //Server is allowed to report that lower level drivers did not support dynamic screen res.
1.127 + //Any other error is unexpected
1.128 + __ASSERT_DEBUG(ExtensionsOrError==KErrExtensionNotSupported,Panic(EW32PanicBadClientInterface));
1.129 + ExtensionsOrError=TWsSdXReservedErrorFlag;
1.130 + return ExtensionsOrError;
1.131 + }
1.132 + else
1.133 + {
1.134 + iSupportedExtensionsBits=ExtensionsOrError;
1.135 + }
1.136 + }
1.137 + return KErrNone;
1.138 + }
1.139 +
1.140 +TInt CWsScreenDevice::CScrDevExtension::NumberOfResolutions() const
1.141 + {
1.142 + __ASSERT_DEBUG(iSupportedExtensionsBits&TWsSdXDisplayControl,Panic(EW32PanicBadClientInterface));
1.143 + TInt numResOrError=WriteReply(EWsSdOpXDcGetNumberOfResolutions);
1.144 + return numResOrError;
1.145 + }
1.146 +
1.147 +TInt CWsScreenDevice::CScrDevExtension::FillResolutionArray(TInt aNumOfRes, RArray<TResolution>& aResolutions) const
1.148 + {
1.149 + TInt arrayMaxSize=aResolutions.Count();
1.150 + if (arrayMaxSize < aNumOfRes)
1.151 + {
1.152 + //Array is too small or not initialized
1.153 + TResolution emptyRes(TSize(0,0),TSize(0,0)); //ARM BUILD needs this form of constructor!
1.154 + for (TInt index = 0;index < aNumOfRes-arrayMaxSize;index++)
1.155 + aResolutions.Append(emptyRes);
1.156 +
1.157 + //reset arrayMaxSize
1.158 + arrayMaxSize = aNumOfRes;
1.159 + }
1.160 + //Else array is large enough.
1.161 +
1.162 + TPtr8 pArr((TUint8*)&aResolutions[0],arrayMaxSize*sizeof(TResolution),arrayMaxSize*sizeof(TResolution));
1.163 + return WriteReplyP(NULL,0,TWriteDescriptorType(&pArr),EWsSdOpXDcGetResolutionsList);
1.164 + }
1.165 +TInt CWsScreenDevice::CScrDevExtension::GetResolutions(RArray<TResolution>& aResolutions) const
1.166 + {
1.167 + TInt result;
1.168 + __ASSERT_DEBUG(iSupportedExtensionsBits&TWsSdXDisplayControl,Panic(EW32PanicBadClientInterface));
1.169 +
1.170 + TInt resCount=WriteReply(EWsSdOpXDcGetNumberOfResolutions);
1.171 + if(resCount < KErrNone)
1.172 + {
1.173 + return resCount;
1.174 + }
1.175 +
1.176 + result=aResolutions.Reserve(resCount);
1.177 + if (result<KErrNone)
1.178 + {
1.179 + return result; //Failed - probably KErrNoMemory
1.180 + }
1.181 +
1.182 + if(resCount > 0)
1.183 + {
1.184 + result = FillResolutionArray(resCount, aResolutions);
1.185 + if (result<KErrNone)
1.186 + {
1.187 + return result; //Content of the array is "undefined"
1.188 + }
1.189 + __ASSERT_DEBUG((result%sizeof(TResolution))==0,Panic(EW32PanicSizeNotExpected));
1.190 + result=result/sizeof(TResolution);
1.191 +
1.192 + if(result > aResolutions.Count())
1.193 + {
1.194 + //The resolution list at server side is larger and can't fit in client buffer we supplied
1.195 + //The Content of the array is undefined at this point.
1.196 + //Give it one more try
1.197 + result = FillResolutionArray(result, aResolutions);
1.198 + if(result < KErrNone)
1.199 + {
1.200 + return result;
1.201 + }
1.202 + __ASSERT_DEBUG((result%sizeof(TResolution))==0,Panic(EW32PanicSizeNotExpected));
1.203 + result=result/sizeof(TResolution);
1.204 +
1.205 + if(result > aResolutions.Count())
1.206 + {//give up
1.207 + return KErrCorrupt; //which means resolution list is changing during the process of getting it
1.208 + }
1.209 + }
1.210 +
1.211 + TInt arrayMaxSize = aResolutions.Count();
1.212 + while(result<arrayMaxSize)
1.213 + {
1.214 + aResolutions.Remove(--arrayMaxSize);
1.215 + }
1.216 + }
1.217 + else
1.218 + {
1.219 + aResolutions.Reset(); //There's not available resolutions
1.220 + }
1.221 + return KErrNone; //Content of array is good.
1.222 + }
1.223 +
1.224 +void CWsScreenDevice::CScrDevExtension::GetConfiguration(TDisplayConfiguration& aConfig) const
1.225 + {
1.226 + __ASSERT_DEBUG(iSupportedExtensionsBits&TWsSdXDisplayControl,Panic(EW32PanicBadClientInterface));
1.227 + TInt currentVersion = aConfig.Version();
1.228 + if (sizeof(TDisplayConfiguration)<currentVersion)
1.229 + currentVersion = sizeof(TDisplayConfiguration);
1.230 + TPtr8 displayPtr((TUint8 *)&aConfig, currentVersion);
1.231 + WriteReplyP(&aConfig, sizeof(TDisplayConfiguration), &displayPtr, EWsSdOpXDcGetConfiguration);
1.232 + }
1.233 +TInt CWsScreenDevice::CScrDevExtension::SetConfiguration(const TDisplayConfiguration& aConfig)
1.234 + {
1.235 + __ASSERT_DEBUG(iSupportedExtensionsBits&TWsSdXDisplayControl,Panic(EW32PanicBadClientInterface));
1.236 + TInt currentVersion = aConfig.Version();
1.237 + if (TDisplayConfiguration().Version()<currentVersion)
1.238 + currentVersion = TDisplayConfiguration().Version();
1.239 + TInt reply=WriteReply(&aConfig, sizeof(TDisplayConfiguration), EWsSdOpXDcSetConfiguration);
1.240 + return reply;
1.241 + }
1.242 +TInt CWsScreenDevice::CScrDevExtension::PreferredDisplayVersion() const
1.243 + {
1.244 + __ASSERT_DEBUG(iSupportedExtensionsBits&TWsSdXDisplayControl,Panic(EW32PanicBadClientInterface));
1.245 + TInt reply=WriteReply(EWsSdOpXDcGetPreferredDisplayVersion);
1.246 + return reply;
1.247 + }
1.248 +
1.249 +TBool CWsScreenDevice::CScrDevExtension::DisplayChangeEventsEnabled() const
1.250 + {
1.251 + __ASSERT_DEBUG(iSupportedExtensionsBits&TWsSdXDisplayControl,Panic(EW32PanicBadClientInterface));
1.252 + if(WriteReply(EWsSdOpXDcDisplayChangeEventEnabled))
1.253 + return ETrue;
1.254 + return EFalse;
1.255 + }
1.256 +void CWsScreenDevice::CScrDevExtension::EnableDisplayChangeEvents(TBool aEnable)
1.257 + {
1.258 + __ASSERT_DEBUG(iSupportedExtensionsBits&TWsSdXDisplayControl,Panic(EW32PanicBadClientInterface));
1.259 + if(aEnable)
1.260 + Write(EWsSdOpXDcNotifyOnDisplayChange);
1.261 + else
1.262 + Write(EWsSdOpXDcNotifyOnDisplayChangeCancel);
1.263 + }
1.264 +TInt CWsScreenDevice::CScrDevExtension::MapCoordinates(TCoordinateSpace aSourceSpace, const TRect& aSource, TCoordinateSpace aTargetSpace, TRect& aTarget) const
1.265 + {
1.266 + TWsSdCmdMapCoordinates cmdMapCoord(aSource, aSourceSpace, aTargetSpace);
1.267 + TPtr8 targetRectPtr((TUint8 *)&aTarget, sizeof(TRect));
1.268 + TInt reply = WriteReplyP(&cmdMapCoord, sizeof(TWsSdCmdMapCoordinates), &targetRectPtr, EWsSdOpXDmMapExtent);
1.269 + return reply;
1.270 + }
1.271 +
1.272 +void CWsScreenDevice::CScrDevExtension::GetMaximumWindowExtent(TRect& aExtent) const
1.273 + {
1.274 + TDisplayConfiguration config;
1.275 + GetConfiguration(config);
1.276 + aExtent.SetRect(0,0,0,0);
1.277 + if(config.IsDefined(TDisplayConfigurationBase::EResolution))
1.278 + {
1.279 + TSize fullUiSize;
1.280 + config.GetResolution(fullUiSize);
1.281 + TRect fullUiRect(TPoint(0,0), fullUiSize);
1.282 + aExtent=fullUiRect;
1.283 +#ifdef _DEBUG
1.284 + TInt err =
1.285 +#endif
1.286 + MapCoordinates(EFullScreenSpace, fullUiRect, EApplicationSpace, aExtent);
1.287 + //This should NOT fail even if display is detached/disabled.
1.288 + __ASSERT_DEBUG(err>=KErrNone, Panic(EW32PanicBadClientInterface));
1.289 + }
1.290 + }
1.291 +void CWsScreenDevice::CScrDevExtension::GetMaximumSurfaceSize(TSize& aPixels, TSize& aTwips) const
1.292 + {
1.293 + TDisplayConfiguration config;
1.294 + GetConfiguration(config);
1.295 + TInt err = KErrGeneral;
1.296 + TSize fullUiSize;
1.297 + aPixels=fullUiSize;
1.298 + aTwips=fullUiSize;
1.299 + if(config.IsDefined(TDisplayConfigurationBase::EResolution))
1.300 + {
1.301 + config.GetResolution(fullUiSize);
1.302 + TRect fullUiRect(TPoint(0,0), fullUiSize);
1.303 + TRect compositionRect;
1.304 + err = MapCoordinates(EFullScreenSpace, fullUiRect, ECompositionSpace, compositionRect);
1.305 + //This WILL fail if display is detached/disabled.
1.306 + if(err == KErrNone)
1.307 + {
1.308 + aPixels = compositionRect.Size();
1.309 + }
1.310 + }
1.311 + if(config.IsDefined(TDisplayConfigurationBase::EResolutionTwips))
1.312 + {
1.313 + config.GetResolutionTwips(aTwips);
1.314 + }
1.315 + //Why can't this function return an error?
1.316 + //In case of error the return values will be empty.
1.317 + }
1.318 +
1.319 +void CWsScreenDevice::CScrDevExtension::GetDisplayExtentOfWindow(const RWindowBase& aWindow, TRect& aExtent) const
1.320 + {
1.321 + TRect winRect(aWindow.AbsPosition(), aWindow.Size());
1.322 + aExtent.SetRect(0,0,0,0);
1.323 + TInt err = MapCoordinates(EApplicationSpace, winRect, ECompositionSpace, aExtent);
1.324 + //This WILL fail if display is detached/disabled.
1.325 + //Why can't this function return an error?
1.326 + //In case of error the return values will be empty.
1.327 + }
1.328 +
1.329 +TInt CWsScreenDevice::CScrDevExtension::TranslateExtent(const TRect& aInitial, TRect& aTarget) const
1.330 + {
1.331 + TPckgBuf<TRect> rectRes;
1.332 + TWsScsComposeScreenCommand translateExtentCmd(EWsScsTranslateExtent, aInitial);
1.333 + TInt ret = WriteReplyP(&translateExtentCmd, sizeof(translateExtentCmd), &rectRes, EWsSdOpXTestScreenCapture);
1.334 + if (ret == KErrNone)
1.335 + {
1.336 + aTarget=rectRes();
1.337 + }
1.338 + return ret;
1.339 + }
1.340 +
1.341 +TInt CWsScreenDevice::CScrDevExtension::GetCompositedSize(TSize& aSize) const
1.342 + {
1.343 + TPckgBuf<TSize> sizePkg;
1.344 + WriteReplyP(&sizePkg,EWsSdOpXTestScreenCaptureSize);
1.345 + aSize = sizePkg();
1.346 + return KErrNone;
1.347 + }
1.348 +
1.349 +TInt CWsScreenDevice::CScrDevExtension::ComposeScreen(const CFbsBitmap& aBitmap) const
1.350 + {
1.351 + TInt bitmapHandle = aBitmap.Handle();
1.352 + AddToBitmapArray(bitmapHandle);
1.353 + TWsScsComposeScreenCommand composeScreenCmd(EWsScsScreenCompose, bitmapHandle);
1.354 + return(WriteReply(&composeScreenCmd,sizeof(composeScreenCmd), EWsSdOpXTestScreenCapture));
1.355 + }