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