|
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "scrdevextension.h" |
|
17 #include "../SERVER/w32cmd.h" |
|
18 #include <graphics/displaycontrolbase.h> |
|
19 #include "CLIENT.H" |
|
20 #include "w32comm.h" |
|
21 |
|
22 CWsScreenDevice::CScrDevExtension::CScrDevExtension(RWsBuffer *aBuffer,TInt32 aWsHandle): MWsClientClass(aBuffer) |
|
23 { |
|
24 iWsHandle=aWsHandle; |
|
25 __ASSERT_DEBUG(aBuffer,Panic(EW32PanicBadClientInterface)); |
|
26 __ASSERT_DEBUG(aWsHandle,Panic(EW32PanicBadClientInterface)); |
|
27 } |
|
28 |
|
29 CWsScreenDevice::CScrDevExtension::~CScrDevExtension() |
|
30 { |
|
31 //typeface store is not owned by this class, and is created/destroyed in CWsScreenDevice |
|
32 } |
|
33 /** Interface Extension capability |
|
34 * Use of this interface going forward will allow the published client interface to be dynamically extended. |
|
35 * Note that the pointer returned is only good for the lifetime of the called CBase derived object. |
|
36 * @pre caller has already checked that the implementation is initialised using RepeatableConstruct |
|
37 * @param aInterfaceId uniqueid or well known id of interface |
|
38 * @return pointer to interface object matching this ID or NULL if no match. |
|
39 **/ |
|
40 void* CWsScreenDevice::CScrDevExtension::GetInterface(TUint aInterfaceId) |
|
41 { |
|
42 if (RepeatableConstruct()<KErrNone) |
|
43 { |
|
44 return NULL; |
|
45 } |
|
46 __ASSERT_DEBUG(this!=NULL,Panic(EW32PanicBadClientInterface)); |
|
47 __ASSERT_DEBUG(iBuffer,Panic(EW32PanicBadClientInterface)); |
|
48 __ASSERT_DEBUG(iWsHandle!=NULL,Panic(EW32PanicBadClientInterface)); |
|
49 |
|
50 switch (aInterfaceId) |
|
51 { |
|
52 case MDisplayControlBase::ETypeId: |
|
53 if (iSupportedExtensionsBits&TWsSdXDisplayControl) |
|
54 { |
|
55 return static_cast<MDisplayControlBase*>(this); |
|
56 } |
|
57 break; |
|
58 case MDisplayControl::ETypeId: |
|
59 if (iSupportedExtensionsBits&TWsSdXDisplayControl) |
|
60 { |
|
61 return static_cast<MDisplayControl*>(this); |
|
62 } |
|
63 break; |
|
64 case MDisplayMappingBase::ETypeId: |
|
65 if(iSupportedExtensionsBits&TWsSdXDisplayMapping) |
|
66 { |
|
67 return static_cast<MDisplayMappingBase*>(this); |
|
68 } |
|
69 break; |
|
70 case MDisplayMapping::ETypeId: |
|
71 if(iSupportedExtensionsBits&TWsSdXDisplayMapping) |
|
72 { |
|
73 return static_cast<MDisplayMapping*>(this); |
|
74 } |
|
75 break; |
|
76 case MTestScreenCapture::ETypeId: |
|
77 { |
|
78 TInt requiredIf = TWsSdXDebugComposition | TWsSdXDisplayMapping; |
|
79 if ((iSupportedExtensionsBits & requiredIf) == requiredIf) |
|
80 { |
|
81 return static_cast<MTestScreenCapture*>(this); |
|
82 } |
|
83 break; |
|
84 } |
|
85 default: |
|
86 break; |
|
87 } |
|
88 return NULL; |
|
89 } |
|
90 //Accessor to typeface store instance |
|
91 CFbsTypefaceStore* CWsScreenDevice::CScrDevExtension::TypefaceStore() |
|
92 { |
|
93 return iTypefaceStore; |
|
94 } |
|
95 //Accessor to typeface store instance |
|
96 void CWsScreenDevice::CScrDevExtension::SetTypefaceStore(CFbsTypefaceStore* aTypeFaceStore) |
|
97 { |
|
98 iTypefaceStore=aTypeFaceStore; |
|
99 } |
|
100 |
|
101 /** |
|
102 * Constructs the extension interface implementation, or returns error if interface is not available. |
|
103 * After success, the interface is then always available and is not re-constructed if method called again, |
|
104 * but after failure the construct attempt will be repeated (and fail again) if the method is called again. |
|
105 * Clients would be expected to make then keep a pointer to this interface, not get new ones repeatedly. |
|
106 * Note that if the extension was not allocated, then "this" could be NULL |
|
107 * @param aWsHandle server-side object handle to use in messages if first time |
|
108 * @return KErrNone if initialised correctly, or a standard error code. |
|
109 **/ |
|
110 TInt CWsScreenDevice::CScrDevExtension::RepeatableConstruct() |
|
111 { |
|
112 if (this==NULL) |
|
113 { |
|
114 return KErrNoMemory; //The extension was not allocated. Making this call is bad! |
|
115 } |
|
116 __ASSERT_DEBUG(iBuffer,Panic(EW32PanicBadClientInterface)); |
|
117 __ASSERT_DEBUG(iWsHandle,Panic(EW32PanicBadClientInterface)); |
|
118 if (iSupportedExtensionsBits==0) |
|
119 { //need to initialise |
|
120 TInt ExtensionsOrError= WriteReply(EWsSdOpExtensionsSupported); |
|
121 if (ExtensionsOrError&TWsSdXReservedErrorFlag) |
|
122 { |
|
123 //Server is allowed to report that lower level drivers did not support dynamic screen res. |
|
124 //Any other error is unexpected |
|
125 __ASSERT_DEBUG(ExtensionsOrError==KErrExtensionNotSupported,Panic(EW32PanicBadClientInterface)); |
|
126 ExtensionsOrError=TWsSdXReservedErrorFlag; |
|
127 return ExtensionsOrError; |
|
128 } |
|
129 else |
|
130 { |
|
131 iSupportedExtensionsBits=ExtensionsOrError; |
|
132 } |
|
133 } |
|
134 return KErrNone; |
|
135 } |
|
136 |
|
137 TInt CWsScreenDevice::CScrDevExtension::NumberOfResolutions() const |
|
138 { |
|
139 __ASSERT_DEBUG(iSupportedExtensionsBits&TWsSdXDisplayControl,Panic(EW32PanicBadClientInterface)); |
|
140 TInt numResOrError=WriteReply(EWsSdOpXDcGetNumberOfResolutions); |
|
141 return numResOrError; |
|
142 } |
|
143 |
|
144 TInt CWsScreenDevice::CScrDevExtension::FillResolutionArray(TInt aNumOfRes, RArray<TResolution>& aResolutions) const |
|
145 { |
|
146 TInt arrayMaxSize=aResolutions.Count(); |
|
147 if (arrayMaxSize < aNumOfRes) |
|
148 { |
|
149 //Array is too small or not initialized |
|
150 TResolution emptyRes(TSize(0,0),TSize(0,0)); //ARM BUILD needs this form of constructor! |
|
151 for (TInt index = 0;index < aNumOfRes-arrayMaxSize;index++) |
|
152 aResolutions.Append(emptyRes); |
|
153 |
|
154 //reset arrayMaxSize |
|
155 arrayMaxSize = aNumOfRes; |
|
156 } |
|
157 //Else array is large enough. |
|
158 |
|
159 TPtr8 pArr((TUint8*)&aResolutions[0],arrayMaxSize*sizeof(TResolution),arrayMaxSize*sizeof(TResolution)); |
|
160 return WriteReplyP(NULL,0,TWriteDescriptorType(&pArr),EWsSdOpXDcGetResolutionsList); |
|
161 } |
|
162 TInt CWsScreenDevice::CScrDevExtension::GetResolutions(RArray<TResolution>& aResolutions) const |
|
163 { |
|
164 TInt result; |
|
165 __ASSERT_DEBUG(iSupportedExtensionsBits&TWsSdXDisplayControl,Panic(EW32PanicBadClientInterface)); |
|
166 |
|
167 TInt resCount=WriteReply(EWsSdOpXDcGetNumberOfResolutions); |
|
168 if(resCount < KErrNone) |
|
169 { |
|
170 return resCount; |
|
171 } |
|
172 |
|
173 result=aResolutions.Reserve(resCount); |
|
174 if (result<KErrNone) |
|
175 { |
|
176 return result; //Failed - probably KErrNoMemory |
|
177 } |
|
178 |
|
179 if(resCount > 0) |
|
180 { |
|
181 result = FillResolutionArray(resCount, aResolutions); |
|
182 if (result<KErrNone) |
|
183 { |
|
184 return result; //Content of the array is "undefined" |
|
185 } |
|
186 __ASSERT_DEBUG((result%sizeof(TResolution))==0,Panic(EW32PanicSizeNotExpected)); |
|
187 result=result/sizeof(TResolution); |
|
188 |
|
189 if(result > aResolutions.Count()) |
|
190 { |
|
191 //The resolution list at server side is larger and can't fit in client buffer we supplied |
|
192 //The Content of the array is undefined at this point. |
|
193 //Give it one more try |
|
194 result = FillResolutionArray(result, aResolutions); |
|
195 if(result < KErrNone) |
|
196 { |
|
197 return result; |
|
198 } |
|
199 __ASSERT_DEBUG((result%sizeof(TResolution))==0,Panic(EW32PanicSizeNotExpected)); |
|
200 result=result/sizeof(TResolution); |
|
201 |
|
202 if(result > aResolutions.Count()) |
|
203 {//give up |
|
204 return KErrCorrupt; //which means resolution list is changing during the process of getting it |
|
205 } |
|
206 } |
|
207 |
|
208 TInt arrayMaxSize = aResolutions.Count(); |
|
209 while(result<arrayMaxSize) |
|
210 { |
|
211 aResolutions.Remove(--arrayMaxSize); |
|
212 } |
|
213 } |
|
214 else |
|
215 { |
|
216 aResolutions.Reset(); //There's not available resolutions |
|
217 } |
|
218 return KErrNone; //Content of array is good. |
|
219 } |
|
220 |
|
221 void CWsScreenDevice::CScrDevExtension::GetConfiguration(TDisplayConfiguration& aConfig) const |
|
222 { |
|
223 __ASSERT_DEBUG(iSupportedExtensionsBits&TWsSdXDisplayControl,Panic(EW32PanicBadClientInterface)); |
|
224 TInt currentVersion = aConfig.Version(); |
|
225 if (sizeof(TDisplayConfiguration)<currentVersion) |
|
226 currentVersion = sizeof(TDisplayConfiguration); |
|
227 TPtr8 displayPtr((TUint8 *)&aConfig, currentVersion); |
|
228 WriteReplyP(&aConfig, sizeof(TDisplayConfiguration), &displayPtr, EWsSdOpXDcGetConfiguration); |
|
229 } |
|
230 TInt CWsScreenDevice::CScrDevExtension::SetConfiguration(const TDisplayConfiguration& aConfig) |
|
231 { |
|
232 __ASSERT_DEBUG(iSupportedExtensionsBits&TWsSdXDisplayControl,Panic(EW32PanicBadClientInterface)); |
|
233 TInt currentVersion = aConfig.Version(); |
|
234 if (TDisplayConfiguration().Version()<currentVersion) |
|
235 currentVersion = TDisplayConfiguration().Version(); |
|
236 TInt reply=WriteReply(&aConfig, sizeof(TDisplayConfiguration), EWsSdOpXDcSetConfiguration); |
|
237 return reply; |
|
238 } |
|
239 TInt CWsScreenDevice::CScrDevExtension::PreferredDisplayVersion() const |
|
240 { |
|
241 __ASSERT_DEBUG(iSupportedExtensionsBits&TWsSdXDisplayControl,Panic(EW32PanicBadClientInterface)); |
|
242 TInt reply=WriteReply(EWsSdOpXDcGetPreferredDisplayVersion); |
|
243 return reply; |
|
244 } |
|
245 |
|
246 TBool CWsScreenDevice::CScrDevExtension::DisplayChangeEventsEnabled() const |
|
247 { |
|
248 __ASSERT_DEBUG(iSupportedExtensionsBits&TWsSdXDisplayControl,Panic(EW32PanicBadClientInterface)); |
|
249 if(WriteReply(EWsSdOpXDcDisplayChangeEventEnabled)) |
|
250 return ETrue; |
|
251 return EFalse; |
|
252 } |
|
253 void CWsScreenDevice::CScrDevExtension::EnableDisplayChangeEvents(TBool aEnable) |
|
254 { |
|
255 __ASSERT_DEBUG(iSupportedExtensionsBits&TWsSdXDisplayControl,Panic(EW32PanicBadClientInterface)); |
|
256 if(aEnable) |
|
257 Write(EWsSdOpXDcNotifyOnDisplayChange); |
|
258 else |
|
259 Write(EWsSdOpXDcNotifyOnDisplayChangeCancel); |
|
260 } |
|
261 TInt CWsScreenDevice::CScrDevExtension::MapCoordinates(TCoordinateSpace aSourceSpace, const TRect& aSource, TCoordinateSpace aTargetSpace, TRect& aTarget) const |
|
262 { |
|
263 TWsSdCmdMapCoordinates cmdMapCoord(aSource, aSourceSpace, aTargetSpace); |
|
264 TPtr8 targetRectPtr((TUint8 *)&aTarget, sizeof(TRect)); |
|
265 TInt reply = WriteReplyP(&cmdMapCoord, sizeof(TWsSdCmdMapCoordinates), &targetRectPtr, EWsSdOpXDmMapExtent); |
|
266 return reply; |
|
267 } |
|
268 |
|
269 void CWsScreenDevice::CScrDevExtension::GetMaximumWindowExtent(TRect& aExtent) const |
|
270 { |
|
271 TDisplayConfiguration config; |
|
272 GetConfiguration(config); |
|
273 aExtent.SetRect(0,0,0,0); |
|
274 if(config.IsDefined(TDisplayConfigurationBase::EResolution)) |
|
275 { |
|
276 TSize fullUiSize; |
|
277 config.GetResolution(fullUiSize); |
|
278 TRect fullUiRect(TPoint(0,0), fullUiSize); |
|
279 aExtent=fullUiRect; |
|
280 #ifdef _DEBUG |
|
281 TInt err = |
|
282 #endif |
|
283 MapCoordinates(EFullScreenSpace, fullUiRect, EApplicationSpace, aExtent); |
|
284 //This should NOT fail even if display is detached/disabled. |
|
285 __ASSERT_DEBUG(err>=KErrNone, Panic(EW32PanicBadClientInterface)); |
|
286 } |
|
287 } |
|
288 void CWsScreenDevice::CScrDevExtension::GetMaximumSurfaceSize(TSize& aPixels, TSize& aTwips) const |
|
289 { |
|
290 TDisplayConfiguration config; |
|
291 GetConfiguration(config); |
|
292 TInt err = KErrGeneral; |
|
293 TSize fullUiSize; |
|
294 aPixels=fullUiSize; |
|
295 aTwips=fullUiSize; |
|
296 if(config.IsDefined(TDisplayConfigurationBase::EResolution)) |
|
297 { |
|
298 config.GetResolution(fullUiSize); |
|
299 TRect fullUiRect(TPoint(0,0), fullUiSize); |
|
300 TRect compositionRect; |
|
301 err = MapCoordinates(EFullScreenSpace, fullUiRect, ECompositionSpace, compositionRect); |
|
302 //This WILL fail if display is detached/disabled. |
|
303 if(err == KErrNone) |
|
304 { |
|
305 aPixels = compositionRect.Size(); |
|
306 } |
|
307 } |
|
308 if(config.IsDefined(TDisplayConfigurationBase::EResolutionTwips)) |
|
309 { |
|
310 config.GetResolutionTwips(aTwips); |
|
311 } |
|
312 //Why can't this function return an error? |
|
313 //In case of error the return values will be empty. |
|
314 } |
|
315 |
|
316 void CWsScreenDevice::CScrDevExtension::GetDisplayExtentOfWindow(const RWindowBase& aWindow, TRect& aExtent) const |
|
317 { |
|
318 TRect winRect(aWindow.AbsPosition(), aWindow.Size()); |
|
319 aExtent.SetRect(0,0,0,0); |
|
320 TInt err = MapCoordinates(EApplicationSpace, winRect, ECompositionSpace, aExtent); |
|
321 //This WILL fail if display is detached/disabled. |
|
322 //Why can't this function return an error? |
|
323 //In case of error the return values will be empty. |
|
324 } |
|
325 |
|
326 TInt CWsScreenDevice::CScrDevExtension::TranslateExtent(const TRect& aInitial, TRect& aTarget) const |
|
327 { |
|
328 TPckgBuf<TRect> rectRes; |
|
329 TWsScsComposeScreenCommand translateExtentCmd(EWsScsTranslateExtent, aInitial); |
|
330 TInt ret = WriteReplyP(&translateExtentCmd, sizeof(translateExtentCmd), &rectRes, EWsSdOpXTestScreenCapture); |
|
331 if (ret == KErrNone) |
|
332 { |
|
333 aTarget=rectRes(); |
|
334 } |
|
335 return ret; |
|
336 } |
|
337 |
|
338 TInt CWsScreenDevice::CScrDevExtension::GetCompositedSize(TSize& aSize) const |
|
339 { |
|
340 TPckgBuf<TSize> sizePkg; |
|
341 WriteReplyP(&sizePkg,EWsSdOpXTestScreenCaptureSize); |
|
342 aSize = sizePkg(); |
|
343 return KErrNone; |
|
344 } |
|
345 |
|
346 TInt CWsScreenDevice::CScrDevExtension::ComposeScreen(const CFbsBitmap& aBitmap) const |
|
347 { |
|
348 TInt bitmapHandle = aBitmap.Handle(); |
|
349 AddToBitmapArray(bitmapHandle); |
|
350 TWsScsComposeScreenCommand composeScreenCmd(EWsScsScreenCompose, bitmapHandle); |
|
351 return(WriteReply(&composeScreenCmd,sizeof(composeScreenCmd), EWsSdOpXTestScreenCapture)); |
|
352 } |