|
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 // Window server 'server' class |
|
15 // |
|
16 // |
|
17 |
|
18 #include "server.h" |
|
19 #include "panics.h" |
|
20 #include "wstop.h" |
|
21 #include "EVENT.H" |
|
22 #include <Graphics/WSGRAPHICDRAWERINTERFACE.H> |
|
23 #include <bitdraw.h> |
|
24 #include <hal.h> |
|
25 #include "inifile.h" |
|
26 #include "wspluginmanager.h" |
|
27 |
|
28 GLREF_D CDebugLogBase *wsDebugLog; |
|
29 |
|
30 const TUint KRangeCount = 1; |
|
31 // We use a lot of 64 bit time calculations, but a periodic can only cope with signed 32 bit times |
|
32 // which gives them a limit of about 35 minutes. |
|
33 // Fortunately, our animtions are safe if redrawn early. Every half an hour isn't going to hurt. |
|
34 const TTimeIntervalMicroSeconds KHalfHour = 30 * 60 * 1000 * 1000; |
|
35 |
|
36 const TInt KWsServRanges[KRangeCount] = |
|
37 { |
|
38 0 |
|
39 }; |
|
40 |
|
41 const TUint8 KElementsIndex[KRangeCount] = |
|
42 { |
|
43 CPolicyServer::EAlwaysPass, |
|
44 }; |
|
45 |
|
46 const CPolicyServer::TPolicyElement KPolicyElements[] = |
|
47 { |
|
48 {_INIT_SECURITY_POLICY_C1(ECapabilityPowerMgmt), CPolicyServer::EFailClient}, |
|
49 {_INIT_SECURITY_POLICY_C1(ECapabilitySwEvent), CPolicyServer::EFailClient}, |
|
50 {_INIT_SECURITY_POLICY_C1(ECapabilityWriteDeviceData), CPolicyServer::EFailClient} |
|
51 }; |
|
52 |
|
53 const CPolicyServer::TPolicy KWsServPolicy = |
|
54 { |
|
55 CPolicyServer::EAlwaysPass, |
|
56 KRangeCount, |
|
57 KWsServRanges, |
|
58 KElementsIndex, |
|
59 KPolicyElements |
|
60 }; |
|
61 |
|
62 // CWindowServer::CDefaultAnimationScheduler \\\\\\\\\\\\\\\\\\\\\\\\\\\ |
|
63 |
|
64 class CWindowServer::CDefaultAnimationScheduler: public CBase, public MWsAnimationScheduler |
|
65 { |
|
66 public: |
|
67 enum TInactivityBehaviour |
|
68 { |
|
69 EStopAnimation, |
|
70 EStopAllDrawing, |
|
71 EIgnore, |
|
72 }; |
|
73 class CKickBack; |
|
74 CDefaultAnimationScheduler(MWsGraphicDrawerEnvironment& aEnv); |
|
75 ~CDefaultAnimationScheduler(); |
|
76 void ConstructL(); //LeaveScan: member of nested class declaration |
|
77 // implementing MWsAnimationScheduler |
|
78 void ScheduleAnimation(MWsScreen& aScreen,const TTime& aWhen); |
|
79 void UnscheduleAnimation(MWsScreen& aScreen); |
|
80 void Invalidate(const TGraphicDrawerId& aId); |
|
81 void OnInactive(); |
|
82 void OnActive(); |
|
83 void ScheduleRedraw(MWsScreen& aScreen,const TTime& aWhen); |
|
84 void DoRedrawNow(MWsScreen& aScreen); |
|
85 TInt RemoveGraphicDrawer(const TGraphicDrawerId &aId); |
|
86 |
|
87 private: |
|
88 static TBool OnIdleCallBack(TAny* aAny); |
|
89 void OnIdleCallBack(TBool aForceRedraw); |
|
90 static TBool OnTickCallBack(TAny* aAny); |
|
91 void OnTickCallBack(); |
|
92 static TBool OnKickBack(TAny* aAny); |
|
93 void OnKickBack(); |
|
94 private: |
|
95 MWsGraphicDrawerEnvironment& iEnv; |
|
96 static const TInt64 KRedrawGrace; |
|
97 static const TInt64 KAnimationGrace; |
|
98 static const TInt64 KDsaAnimationGrace; |
|
99 CAsyncCallBack* iIdleInitiator; |
|
100 CPeriodic* iTick; |
|
101 CKickBack* iKickBack; |
|
102 struct TSchedule |
|
103 { |
|
104 MWsScreen* iScreen; // used as a unique index, searching with FindInUnsignedKeyOrder |
|
105 TBool iSchedule; |
|
106 TTime iWhen; |
|
107 TInt iGeneration; |
|
108 }; |
|
109 RArray<TSchedule> iSchedule; |
|
110 TInt iGeneration; |
|
111 RArray<TGraphicDrawerId> iInvalidated; |
|
112 TBool iInvalidateAll; // if we could not add to iInvalidated, we have to instead redraw everything |
|
113 TTime iWhenDesired; |
|
114 TBool iInactive; |
|
115 TBool iInactiveDraws; |
|
116 TTime iExpectedTime; |
|
117 TBool iRedrawScheduled; |
|
118 TInt64 iRedrawGracePeriod; |
|
119 TInt64 iAnimationGracePeriod; |
|
120 TInt64 iDsaAnimationGracePeriod; |
|
121 TInactivityBehaviour iInactivityBehaviour; |
|
122 }; |
|
123 |
|
124 TInt CWindowServer::CDefaultAnimationScheduler::RemoveGraphicDrawer(const TGraphicDrawerId &aId) |
|
125 { |
|
126 TInt index=iInvalidated.Find(aId); |
|
127 if (index!=KErrNotFound) |
|
128 iInvalidated.Remove(index); |
|
129 return index; |
|
130 } |
|
131 |
|
132 class CWindowServer::CDefaultAnimationScheduler::CKickBack: public CActive |
|
133 { |
|
134 public: |
|
135 CKickBack(const TCallBack& aCallBack); |
|
136 void ConstructL(); |
|
137 void RequestKickBack(); |
|
138 ~CKickBack(); |
|
139 private: |
|
140 static TInt IdleThreadFunc(TAny* aAny); |
|
141 void Loop(); |
|
142 // from CActive |
|
143 void RunL(); // fires when kicked back by the idle thread |
|
144 void DoCancel(); |
|
145 private: |
|
146 RThread iWservThread; |
|
147 RThread iIdleThread; |
|
148 TRequestStatus iIdleStatus; |
|
149 TCallBack iCallBack; |
|
150 }; |
|
151 |
|
152 CWindowServer::CDefaultAnimationScheduler::CKickBack::CKickBack(const TCallBack& aCallBack) : |
|
153 CActive(EPriorityNormal), |
|
154 iCallBack(aCallBack) |
|
155 { |
|
156 CActiveScheduler::Add(this); |
|
157 } |
|
158 |
|
159 void CWindowServer::CDefaultAnimationScheduler::CKickBack::ConstructL() |
|
160 { |
|
161 _LIT(KIdleThreadName,"NearlyIdleKickBack"); |
|
162 const TInt KStackSize = 1024; |
|
163 User::LeaveIfError(iWservThread.Open(iWservThread.Id())); |
|
164 User::LeaveIfError(iIdleThread.Create(KIdleThreadName(),IdleThreadFunc,KStackSize,NULL,this)); |
|
165 iIdleThread.SetPriority(EPriorityAbsoluteVeryLow); |
|
166 iIdleThread.Resume(); |
|
167 } |
|
168 |
|
169 void CWindowServer::CDefaultAnimationScheduler::CKickBack::RequestKickBack() |
|
170 { |
|
171 if (!IsActive()) |
|
172 { |
|
173 iStatus = KRequestPending; |
|
174 SetActive(); |
|
175 TRequestStatus * status = &iIdleStatus; |
|
176 iIdleThread.RequestComplete(status, KErrNone); |
|
177 } |
|
178 } |
|
179 |
|
180 void CWindowServer::CDefaultAnimationScheduler::CKickBack::Loop() |
|
181 { |
|
182 FOREVER |
|
183 { |
|
184 // This is used here for performance reasons. |
|
185 User::WaitForRequest(iIdleStatus); |
|
186 iIdleStatus = KRequestPending; |
|
187 if (IsActive()&& (iStatus == KRequestPending)) |
|
188 { |
|
189 TRequestStatus * status = &iStatus; |
|
190 iWservThread.RequestComplete(status,KErrNone); |
|
191 } |
|
192 } |
|
193 } |
|
194 |
|
195 void CWindowServer::CDefaultAnimationScheduler::CKickBack::RunL() |
|
196 { |
|
197 iCallBack.CallBack(); |
|
198 } |
|
199 |
|
200 void CWindowServer::CDefaultAnimationScheduler::CKickBack::DoCancel() |
|
201 { |
|
202 } |
|
203 |
|
204 CWindowServer::CDefaultAnimationScheduler::CKickBack::~CKickBack() |
|
205 { |
|
206 Cancel(); |
|
207 iWservThread.Close(); |
|
208 iIdleThread.Kill(0); |
|
209 iIdleThread.Close(); |
|
210 } |
|
211 |
|
212 TInt CWindowServer::CDefaultAnimationScheduler::CKickBack::IdleThreadFunc(TAny* aAny) |
|
213 { |
|
214 CKickBack* owner = reinterpret_cast<CKickBack*>(aAny); |
|
215 ASSERT(owner); |
|
216 if(owner) |
|
217 { |
|
218 owner->Loop(); |
|
219 } |
|
220 return KErrNone; |
|
221 } |
|
222 |
|
223 // If using the default animation scheduler on a device, these two numbers may be worth tweaking in the inifile |
|
224 // However, both are maximum periods - wserv will go faster than either if nothing else is using the system. |
|
225 const TInt64 CWindowServer::CDefaultAnimationScheduler::KRedrawGrace = 0; // do redraws immediately |
|
226 const TInt64 CWindowServer::CDefaultAnimationScheduler::KAnimationGrace = 35000; // insist upon 35ms grace for other threads to run when animating |
|
227 const TInt64 CWindowServer::CDefaultAnimationScheduler::KDsaAnimationGrace = 35000; // insist upon 35ms grace for other threads to run when animating during DSA |
|
228 |
|
229 CWindowServer::CDefaultAnimationScheduler::CDefaultAnimationScheduler(MWsGraphicDrawerEnvironment& aEnv): |
|
230 iEnv(aEnv), iSchedule(1,_FOFF(TSchedule,iScreen)) |
|
231 { |
|
232 } |
|
233 |
|
234 CWindowServer::CDefaultAnimationScheduler::~CDefaultAnimationScheduler() |
|
235 { |
|
236 iSchedule.Close(); |
|
237 iInvalidated.Close(); |
|
238 delete iKickBack; |
|
239 delete iIdleInitiator; |
|
240 delete iTick; |
|
241 } |
|
242 |
|
243 void CWindowServer::CDefaultAnimationScheduler::ConstructL() |
|
244 { |
|
245 _LIT(KOnInactive,"ONINACTIVE"); |
|
246 _LIT(KStopAnimation,"STOPANIMATION"); |
|
247 _LIT(KStopAllDrawing,"STOPALLDRAWING"); |
|
248 _LIT(KIgnore,"IGNORE"); |
|
249 |
|
250 TPtrC inactivityBehaviourString; |
|
251 WsIniFile->FindVar(KOnInactive,inactivityBehaviourString); |
|
252 if(inactivityBehaviourString.CompareF(KStopAnimation)==0) |
|
253 iInactivityBehaviour = EStopAnimation; |
|
254 else if(inactivityBehaviourString.CompareF(KStopAllDrawing)==0) |
|
255 iInactivityBehaviour = EStopAllDrawing; |
|
256 else if(inactivityBehaviourString.CompareF(KIgnore)==0) |
|
257 iInactivityBehaviour = EIgnore; |
|
258 |
|
259 _LIT(KRedrawGracePeriod, "REDRAWGRACEPERIOD"); |
|
260 TInt tmp = KRedrawGrace; |
|
261 WsIniFile->FindVar(KRedrawGracePeriod, tmp); |
|
262 iRedrawGracePeriod = tmp; |
|
263 |
|
264 _LIT(KAnimationGracePeriod, "ANIMATIONGRACEPERIOD"); |
|
265 tmp = KAnimationGrace; |
|
266 WsIniFile->FindVar(KAnimationGracePeriod, tmp); |
|
267 iAnimationGracePeriod = tmp; |
|
268 |
|
269 _LIT(KDsaAnimationGracePeriod, "DSAANIMATIONGRACEPERIOD"); |
|
270 tmp = KDsaAnimationGrace; |
|
271 WsIniFile->FindVar(KDsaAnimationGracePeriod, tmp); |
|
272 iDsaAnimationGracePeriod = tmp; |
|
273 |
|
274 iIdleInitiator = new(ELeave) CAsyncCallBack(TCallBack(OnIdleCallBack,this),EWsGraphicAnimateAwaitIdlePriority); |
|
275 iTick = CPeriodic::NewL(EWsGraphicAnimatePriority); |
|
276 |
|
277 _LIT(KDisableIdleAnimation, "DISABLEIDLEANIMATION"); |
|
278 if (!WsIniFile->FindVar(KDisableIdleAnimation)) |
|
279 { |
|
280 iKickBack = new CKickBack(TCallBack(OnKickBack,this)); |
|
281 iKickBack->ConstructL(); |
|
282 } |
|
283 } |
|
284 |
|
285 void CWindowServer::CDefaultAnimationScheduler::Invalidate(const TGraphicDrawerId& aId) |
|
286 { |
|
287 if(!iInvalidateAll) |
|
288 { |
|
289 switch(iInvalidated.InsertInOrder(aId,TLinearOrder<TGraphicDrawerId>(TGraphicDrawerId::Compare))) |
|
290 { |
|
291 case KErrNone: |
|
292 break; |
|
293 case KErrAlreadyExists: |
|
294 break; |
|
295 default: |
|
296 iInvalidateAll = ETrue; |
|
297 iInvalidated.Reset(); |
|
298 } |
|
299 } |
|
300 iIdleInitiator->CallBack(); |
|
301 } |
|
302 |
|
303 void CWindowServer::CDefaultAnimationScheduler::OnInactive() |
|
304 { |
|
305 iInactive = ETrue; |
|
306 } |
|
307 |
|
308 void CWindowServer::CDefaultAnimationScheduler::OnActive() |
|
309 { |
|
310 iInactive = EFalse; |
|
311 if(iInactiveDraws) |
|
312 { |
|
313 iInactiveDraws = EFalse; |
|
314 iIdleInitiator->CallBack(); |
|
315 } |
|
316 } |
|
317 |
|
318 void CWindowServer::CDefaultAnimationScheduler::ScheduleRedraw(MWsScreen& aScreen,const TTime& aWhen) |
|
319 { |
|
320 iRedrawScheduled = ETrue; |
|
321 ScheduleAnimation(aScreen, aWhen); |
|
322 } |
|
323 |
|
324 void CWindowServer::CDefaultAnimationScheduler::DoRedrawNow(MWsScreen& /*aScreen*/) |
|
325 { |
|
326 OnIdleCallBack(ETrue); |
|
327 } |
|
328 |
|
329 void CWindowServer::CDefaultAnimationScheduler::ScheduleAnimation(MWsScreen& aScreen,const TTime& aWhen) |
|
330 { |
|
331 TSchedule schedule; |
|
332 schedule.iScreen = &aScreen; |
|
333 schedule.iSchedule = ETrue; |
|
334 schedule.iWhen = aWhen; |
|
335 schedule.iGeneration = iGeneration; |
|
336 TBool ok = EFalse; |
|
337 const TInt idx = iSchedule.FindInUnsignedKeyOrder(schedule); |
|
338 if(0 <= idx) |
|
339 { |
|
340 if(iSchedule[idx].iSchedule) |
|
341 { |
|
342 if(iSchedule[idx].iWhen > aWhen) |
|
343 { |
|
344 iSchedule[idx].iWhen = aWhen; |
|
345 } |
|
346 } |
|
347 else |
|
348 { |
|
349 iSchedule[idx] = schedule; |
|
350 } |
|
351 iSchedule[idx].iGeneration = iGeneration; |
|
352 ok = ETrue; |
|
353 } |
|
354 else |
|
355 { |
|
356 ok = (KErrNone == iSchedule.InsertInUnsignedKeyOrder(schedule)); |
|
357 } |
|
358 if(ok) |
|
359 { |
|
360 //If the animation runs at very high rate which exceeds the rate WSERV can |
|
361 //perform the rendering, it is possible that WSERV animation loop will monopolize |
|
362 //processor time. |
|
363 User::After(0); // to yeild from the animation loop |
|
364 |
|
365 iIdleInitiator->CallBack(); |
|
366 } |
|
367 } |
|
368 |
|
369 void CWindowServer::CDefaultAnimationScheduler::UnscheduleAnimation(MWsScreen& aScreen) |
|
370 { |
|
371 TSchedule schedule; |
|
372 schedule.iScreen = &aScreen; |
|
373 const TInt idx = iSchedule.FindInUnsignedKeyOrder(schedule); |
|
374 if(0 <= idx) |
|
375 { |
|
376 iSchedule[idx].iSchedule = EFalse; |
|
377 } |
|
378 } |
|
379 |
|
380 TBool CWindowServer::CDefaultAnimationScheduler::OnIdleCallBack(TAny* aAny) |
|
381 { |
|
382 CDefaultAnimationScheduler* self = reinterpret_cast<CDefaultAnimationScheduler*>(aAny); |
|
383 ASSERT(self); |
|
384 if(self) |
|
385 { |
|
386 self->OnIdleCallBack(EFalse); |
|
387 } |
|
388 return EFalse; //ignored by caller |
|
389 } |
|
390 |
|
391 void CWindowServer::CDefaultAnimationScheduler::OnIdleCallBack(TBool aForceRedraw) |
|
392 { |
|
393 TBool wasActive = EFalse; |
|
394 if (iTick->IsActive()) |
|
395 { |
|
396 wasActive = ETrue; |
|
397 iTick->Cancel(); // stop ticker, as we'll reschedule if necessary |
|
398 } |
|
399 if (aForceRedraw) |
|
400 { |
|
401 // Don't need to update iExpectedTime as we will not schedule a tick. |
|
402 // Don't need to update iWhenDesired as we will not schedule a kick-back. |
|
403 OnTickCallBack(); |
|
404 return; |
|
405 } |
|
406 TBool tick = (iInvalidateAll || iInvalidated.Count()); |
|
407 TTimeIntervalMicroSeconds next = 0LL; |
|
408 const TInt count = iSchedule.Count(); |
|
409 TTime now; |
|
410 now.UniversalTime(); |
|
411 if(count) |
|
412 { |
|
413 // work out the next wanted tick |
|
414 TBool animTick = EFalse; |
|
415 for(TInt i=0; i<count; i++) |
|
416 { |
|
417 if(iSchedule[i].iSchedule) |
|
418 { |
|
419 const TTime when = iSchedule[i].iWhen; |
|
420 const TTimeIntervalMicroSeconds fromNow = when.MicroSecondsFrom(now); |
|
421 if(!animTick || (fromNow < next)) |
|
422 { |
|
423 animTick = ETrue; |
|
424 tick = ETrue; |
|
425 next = fromNow; |
|
426 iWhenDesired = when; |
|
427 } |
|
428 } |
|
429 } |
|
430 } |
|
431 if(tick) |
|
432 { |
|
433 TInt64 grace; |
|
434 if (iRedrawScheduled) |
|
435 grace = iRedrawGracePeriod; |
|
436 else if (EFalse) // DSA active |
|
437 grace = iDsaAnimationGracePeriod; |
|
438 else |
|
439 grace = iAnimationGracePeriod; |
|
440 if (wasActive) |
|
441 { |
|
442 TInt64 minimum = iExpectedTime.MicroSecondsFrom(now).Int64(); |
|
443 if (minimum >= 0 && grace > minimum) |
|
444 grace = minimum; |
|
445 } |
|
446 |
|
447 if (next.Int64() <= 0) |
|
448 next = 0LL ; // No kickback/tick is needed. Make sure next == default grace period. |
|
449 |
|
450 if(next < grace) |
|
451 { |
|
452 next = grace; |
|
453 if (iKickBack) |
|
454 iKickBack->RequestKickBack(); |
|
455 } |
|
456 else if (next > KHalfHour) |
|
457 next = KHalfHour; |
|
458 |
|
459 iExpectedTime=now + next; |
|
460 if (next.Int64() > 0) |
|
461 { |
|
462 iTick->Start(next.Int64(),0,TCallBack(OnTickCallBack,this)); |
|
463 } |
|
464 else |
|
465 { |
|
466 OnTickCallBack(); // scheduling for 0 doesn't actually execute immediately |
|
467 } |
|
468 } |
|
469 } |
|
470 |
|
471 TBool CWindowServer::CDefaultAnimationScheduler::OnKickBack(TAny* aAny) |
|
472 { |
|
473 CDefaultAnimationScheduler* self = reinterpret_cast<CDefaultAnimationScheduler*>(aAny); |
|
474 ASSERT(self); |
|
475 if(self) |
|
476 { |
|
477 self->OnKickBack(); |
|
478 } |
|
479 return EFalse; //ignored by caller |
|
480 } |
|
481 |
|
482 void CWindowServer::CDefaultAnimationScheduler::OnKickBack() |
|
483 { |
|
484 if (iTick->IsActive()) |
|
485 { |
|
486 iTick->Cancel(); |
|
487 TTime now; |
|
488 now.UniversalTime(); |
|
489 |
|
490 TTimeIntervalMicroSeconds fromNow = iWhenDesired.MicroSecondsFrom(now); |
|
491 |
|
492 if (fromNow < 0) |
|
493 { |
|
494 OnTickCallBack(); |
|
495 } |
|
496 else |
|
497 { |
|
498 if (fromNow > KHalfHour) |
|
499 fromNow = KHalfHour; |
|
500 iTick->Start(fromNow.Int64(),0,TCallBack(OnTickCallBack, this)); |
|
501 } |
|
502 } |
|
503 } |
|
504 |
|
505 TBool CWindowServer::CDefaultAnimationScheduler::OnTickCallBack(TAny* aAny) |
|
506 { |
|
507 CDefaultAnimationScheduler* self = reinterpret_cast<CDefaultAnimationScheduler*>(aAny); |
|
508 ASSERT(self); |
|
509 if(self) |
|
510 { |
|
511 self->OnTickCallBack(); |
|
512 } |
|
513 return EFalse; |
|
514 } |
|
515 |
|
516 void CWindowServer::CDefaultAnimationScheduler::OnTickCallBack() |
|
517 { |
|
518 iTick->Cancel(); |
|
519 |
|
520 switch(iInactivityBehaviour) |
|
521 { |
|
522 case EStopAnimation : |
|
523 // only client redraws if inactive. server side drawing stopped. |
|
524 if(iInactive && !iRedrawScheduled) |
|
525 { |
|
526 iInactiveDraws = ETrue; |
|
527 return; |
|
528 } |
|
529 break; |
|
530 case EStopAllDrawing : |
|
531 // if screen off, stop both client and server side drawing. |
|
532 if(iInactive) |
|
533 { |
|
534 iInactiveDraws = ETrue; |
|
535 return; |
|
536 } |
|
537 break; |
|
538 case EIgnore : |
|
539 default : |
|
540 // ignore inactivity and draw as normal |
|
541 break; |
|
542 } |
|
543 |
|
544 iRedrawScheduled = EFalse; |
|
545 |
|
546 TTime now; |
|
547 now.UniversalTime(); |
|
548 CWsActiveScheduler::Static()->AccumReclaimedIdleTime(Max(0LL,now.MicroSecondsFrom(iExpectedTime).Int64())); |
|
549 |
|
550 TInt drewCount = 0; |
|
551 TInt scheduledCount = 0; |
|
552 /* first redraw any screens that are affected by invalidated graphic IDs */ |
|
553 if(iInvalidateAll || iInvalidated.Count()) |
|
554 { |
|
555 // cancel idle callback if it's already scheduled as we're going to redraw all invalidated |
|
556 // request at this point and clear invalidated array |
|
557 if (iIdleInitiator->IsActive()) |
|
558 iIdleInitiator->Cancel(); |
|
559 const TArray<TGraphicDrawerId> invalidArray = iInvalidated.Array(); |
|
560 const TInt screenCount = iEnv.ScreenCount(); |
|
561 for(TInt i=0; i<screenCount; i++) |
|
562 { |
|
563 MWsScreen* screen = iEnv.Screen(i); |
|
564 if(screen) |
|
565 { |
|
566 drewCount++; |
|
567 if(iInvalidateAll) |
|
568 { |
|
569 Redraw(*screen); |
|
570 } |
|
571 else |
|
572 { |
|
573 RedrawInvalid(*screen,invalidArray); |
|
574 } |
|
575 } |
|
576 } |
|
577 iInvalidateAll = EFalse; |
|
578 iInvalidated.Reset(); |
|
579 } |
|
580 /* iSchedule might resize during this call because an Animate() on a screen might reschedule another animation etc */ |
|
581 TInt generation = iGeneration++; |
|
582 TBool drew; |
|
583 do |
|
584 { |
|
585 drew = EFalse; |
|
586 const TInt count = iSchedule.Count(); |
|
587 for(TInt i=0; i<count; i++) |
|
588 { |
|
589 if(iSchedule[i].iSchedule) |
|
590 { |
|
591 scheduledCount++; |
|
592 if(iSchedule[i].iGeneration == generation) |
|
593 { |
|
594 iSchedule[i].iSchedule = EFalse; // denote not to tick; it can be rescheduled in the subsequent call to Animate() |
|
595 Animate(*(iSchedule[i].iScreen)); |
|
596 drew = ETrue; |
|
597 drewCount++; |
|
598 break; // go back to outer do while(drew) |
|
599 } |
|
600 } |
|
601 } |
|
602 } while(drew); |
|
603 __DEBUG_ONLY( |
|
604 TBool idleIsActive = iIdleInitiator->IsActive(); |
|
605 if(scheduledCount || !drewCount) |
|
606 { |
|
607 TBool rescheduled = EFalse; |
|
608 for(TInt i=0; i<iSchedule.Count(); i++) |
|
609 { |
|
610 rescheduled |= iSchedule[i].iSchedule; |
|
611 } |
|
612 if(!rescheduled) |
|
613 { |
|
614 //__DEBUGGER(); |
|
615 } |
|
616 }) |
|
617 } |
|
618 |
|
619 // CWindowServer \\\\\\\\\\\\\\\\\\\\\\\\\\\ |
|
620 |
|
621 CWindowServer *CWindowServer::NewL() |
|
622 // |
|
623 // Create a new CWindowServer. |
|
624 // |
|
625 { |
|
626 CWindowServer* self = new(ELeave) CWindowServer(); |
|
627 CleanupStack::PushL(self); |
|
628 self->ConstructL(); |
|
629 CleanupStack::Pop(self); |
|
630 return self; |
|
631 } |
|
632 |
|
633 CWindowServer::CWindowServer() |
|
634 // |
|
635 // Constructor. |
|
636 // |
|
637 : CPolicyServer(EMainServerPriority,KWsServPolicy) |
|
638 { |
|
639 } |
|
640 |
|
641 CWindowServer::~CWindowServer() |
|
642 { |
|
643 iMemoryReleases.Reset(); |
|
644 WS_ASSERT_DEBUG(iDrawerMasterIndex.IsEmpty(), EWsPanicWsGraphic); |
|
645 iDrawerMasterIndex.Close(); |
|
646 |
|
647 delete iDefaultAnimationScheduler; |
|
648 iDefaultAnimationScheduler = NULL; // might be called from clients during server destruction |
|
649 iCustomAnimationScheduler = NULL; // not owned |
|
650 delete iPluginManager; |
|
651 } |
|
652 |
|
653 void CWindowServer::ConstructL() |
|
654 { |
|
655 iPluginManager = CWsPluginManager::NewL(*this); |
|
656 iDefaultAnimationScheduler = new(ELeave) CDefaultAnimationScheduler(*this); |
|
657 iDefaultAnimationScheduler->ConstructL(); |
|
658 RegisterMemoryRelease(this); |
|
659 } |
|
660 |
|
661 /** Creates a new client for this server. */ |
|
662 CSession2* CWindowServer::NewSessionL(const TVersion& aVersion,const RMessage2& aMessage) const |
|
663 { |
|
664 TVersion v(KWservMajorVersionNumber,KWservMinorVersionNumber,KWservBuildVersionNumber); |
|
665 if (User::QueryVersionSupported(v,aVersion)==EFalse) |
|
666 User::Leave(KErrNotSupported); |
|
667 RThread thread; |
|
668 User::LeaveIfError(aMessage.Client(thread)); |
|
669 return(new(ELeave) CWsClient(thread)); |
|
670 } |
|
671 |
|
672 TInt CWindowServer::SessionCount() |
|
673 { |
|
674 iSessionIter.SetToFirst(); |
|
675 TInt count=0; |
|
676 while(iSessionIter++) |
|
677 count++; |
|
678 return(count); |
|
679 } |
|
680 |
|
681 const CWsGraphicDrawer* CWindowServer::ResolveGraphic(const TGraphicDrawerId& aId) const |
|
682 { |
|
683 return iDrawerMasterIndex.ResolveGraphic(aId); |
|
684 } |
|
685 |
|
686 void CWindowServer::Invalidate(const TGraphicDrawerId& aId) |
|
687 { |
|
688 AnimationScheduler()->Invalidate(aId); |
|
689 } |
|
690 |
|
691 TInt CWindowServer::ScreenCount() const |
|
692 { |
|
693 return CWsTop::NumberOfScreens(); |
|
694 } |
|
695 |
|
696 MWsScreen* CWindowServer::Screen(TInt aIndex) |
|
697 { |
|
698 if((aIndex >= 0) && (aIndex < ScreenCount())) |
|
699 { |
|
700 return CWsTop::Screen(aIndex); |
|
701 } |
|
702 return NULL; |
|
703 } |
|
704 |
|
705 const MWsScreen* CWindowServer::Screen(TInt aIndex) const |
|
706 { |
|
707 if((aIndex >= 0) && (aIndex < ScreenCount())) |
|
708 { |
|
709 return CWsTop::Screen(aIndex); |
|
710 } |
|
711 return NULL; |
|
712 } |
|
713 |
|
714 /** |
|
715 Custom Animation Scheduler |
|
716 */ |
|
717 TBool CWindowServer::SetCustomAnimationScheduler(MWsAnimationScheduler* aScheduler) |
|
718 { |
|
719 if(!iCustomAnimationScheduler && aScheduler) |
|
720 { |
|
721 iCustomAnimationScheduler = aScheduler; |
|
722 return ETrue; |
|
723 } |
|
724 return EFalse; |
|
725 } |
|
726 |
|
727 TBool CWindowServer::HasCustomAnimationScheduler() const |
|
728 { |
|
729 return !!iCustomAnimationScheduler; |
|
730 } |
|
731 |
|
732 TBool CWindowServer::ClearCustomAnimationScheduler(MWsAnimationScheduler* aCurrentScheduler) |
|
733 { |
|
734 if(iCustomAnimationScheduler && (iCustomAnimationScheduler == aCurrentScheduler)) |
|
735 { |
|
736 iCustomAnimationScheduler = NULL; |
|
737 return ETrue; |
|
738 } |
|
739 return EFalse; |
|
740 } |
|
741 |
|
742 MWsAnimationScheduler* CWindowServer::AnimationScheduler() |
|
743 { |
|
744 if(iCustomAnimationScheduler) |
|
745 { |
|
746 return iCustomAnimationScheduler; |
|
747 } |
|
748 return iDefaultAnimationScheduler; |
|
749 } |
|
750 |
|
751 TInt CWindowServer::RegisterEventHandler(CWsGraphicDrawer* aDrawer, MWsEventHandler* aHandler, TUint32 aEventMask) |
|
752 { |
|
753 if (!aDrawer || !aHandler || aEventMask==0) |
|
754 return KErrArgument; |
|
755 TInt err = TWindowServerEvent::RegisterDrawerHandler(aDrawer, aEventMask); |
|
756 if (err != KErrNone) |
|
757 return err; |
|
758 aDrawer->SetEventHandler(aHandler); |
|
759 return KErrNone; |
|
760 } |
|
761 |
|
762 TInt CWindowServer::UnregisterEventHandler(CWsGraphicDrawer* aDrawer) |
|
763 { |
|
764 if (!aDrawer || (aDrawer && !aDrawer->HasEventHandler())) |
|
765 return KErrArgument; |
|
766 TInt err = TWindowServerEvent::UnregisterDrawerHandler(aDrawer); |
|
767 if (err != KErrNone) |
|
768 return err; |
|
769 aDrawer->SetEventHandler(NULL); |
|
770 return KErrNone; |
|
771 } |
|
772 |
|
773 TInt CWindowServer::RegisterWsEventHandler(MWsEventHandler* aHandler, TUint32 aEventMask) |
|
774 { |
|
775 if (!aHandler || aEventMask==0) |
|
776 return KErrArgument; |
|
777 return TWindowServerEvent::RegisterWsEventHandler(aHandler, aEventMask); |
|
778 } |
|
779 |
|
780 TInt CWindowServer::UnregisterWsEventHandler(MWsEventHandler* aHandler) |
|
781 { |
|
782 return TWindowServerEvent::UnregisterWsEventHandler(aHandler); |
|
783 } |
|
784 |
|
785 TInt CWindowServer::RegisterRawEventHandler(MEventHandler* aHandler) |
|
786 { |
|
787 if (!aHandler) |
|
788 return KErrArgument; |
|
789 TRAPD(err, TWindowServerEvent::PotentialEventHandlerL(1)); |
|
790 if (err != KErrNone) |
|
791 return err; |
|
792 TWindowServerEvent::AddEventHandler(aHandler); |
|
793 return KErrNone; |
|
794 } |
|
795 |
|
796 void CWindowServer::UnregisterRawEventHandler(MEventHandler* aHandler) |
|
797 { |
|
798 TWindowServerEvent::RemoveEventHandler(aHandler); |
|
799 TWindowServerEvent::PotentialEventHandlerL(-1); // can't leave for -1 |
|
800 } |
|
801 |
|
802 void CWindowServer::PostRawEvent(const TRawEvent & aEvent) |
|
803 { |
|
804 TWindowServerEvent::ProcessRawEvent(aEvent); |
|
805 } |
|
806 |
|
807 void CWindowServer::PostKeyEvent(const TKeyEvent & aEvent) |
|
808 { |
|
809 TWindowServerEvent::ProcessKeyEvent(aEvent, 0); |
|
810 } |
|
811 |
|
812 TAny* CWindowServer::ResolveObjectInterface(TUint aTypeId) |
|
813 { |
|
814 switch(aTypeId) |
|
815 { |
|
816 case MWsActiveSchedulerDebug::EWsObjectInterfaceId: |
|
817 return static_cast<MWsActiveSchedulerDebug*>(CWsActiveScheduler::Static()); |
|
818 case MWsIniFile::EWsObjectInterfaceId: |
|
819 return static_cast<MWsIniFile*>(WsIniFile); |
|
820 case MWsRawEventServer::EWsObjectInterfaceId: |
|
821 return static_cast<MWsRawEventServer*>(this); |
|
822 } |
|
823 |
|
824 if (iPluginManager) |
|
825 return iPluginManager->ResolveObjectInterface(aTypeId); |
|
826 |
|
827 return NULL; |
|
828 } |
|
829 |
|
830 void CWindowServer::Log(TInt aPriority,const TDesC &aFmt,TInt aParam) |
|
831 { |
|
832 if (wsDebugLog) |
|
833 { |
|
834 wsDebugLog->MiscMessage(aPriority, aFmt, aParam); |
|
835 } |
|
836 } |
|
837 |
|
838 // CWsGraphicDrawer master index |
|
839 |
|
840 TInt CWindowServer::AddGraphicDrawer(CWsGraphicDrawer* aDrawer) |
|
841 { |
|
842 return iDrawerMasterIndex.Add(aDrawer); |
|
843 } |
|
844 |
|
845 TInt CWindowServer::SwapGraphicDrawer(CWsGraphicDrawer* aDrawer) |
|
846 { |
|
847 return iDrawerMasterIndex.Swap(aDrawer); |
|
848 } |
|
849 |
|
850 TInt CWindowServer::RemoveGraphicDrawer(const TGraphicDrawerId& aId) |
|
851 { |
|
852 iDefaultAnimationScheduler->RemoveGraphicDrawer(aId); |
|
853 return iDrawerMasterIndex.Remove(aId); |
|
854 } |
|
855 |
|
856 TInt CWindowServer::RemoveAllGraphicDrawers(const MWsClient& aOwner) |
|
857 { |
|
858 return iDrawerMasterIndex.RemoveAll(aOwner); |
|
859 } |
|
860 |
|
861 CWsPluginManager* CWindowServer::PluginManager() |
|
862 { |
|
863 return iPluginManager; |
|
864 } |
|
865 |
|
866 TInt CWindowServer::RegisterMemoryRelease(MWsMemoryRelease * aMemoryRelease) |
|
867 { |
|
868 return iMemoryReleases.Append(aMemoryRelease); |
|
869 } |
|
870 |
|
871 void CWindowServer::UnregisterMemoryRelease(MWsMemoryRelease * aMemoryRelease) |
|
872 { |
|
873 for (TInt i = iMemoryReleases.Count() - 1; i >= 0; --i) |
|
874 { |
|
875 if (iMemoryReleases[i] == aMemoryRelease) |
|
876 { |
|
877 iMemoryReleases.Remove(i); |
|
878 break; |
|
879 } |
|
880 } |
|
881 } |
|
882 |
|
883 TBool CWindowServer::ReleaseMemory(TMemoryReleaseLevel aLevel) |
|
884 { |
|
885 return CWsWindow::ReleaseMemory(aLevel); |
|
886 } |
|
887 |
|
888 TBool CWindowServer::ReleaseMemory() |
|
889 { |
|
890 TBool released = EFalse; |
|
891 for (TInt level = MWsMemoryRelease::ELow; !released && level <= MWsMemoryRelease::EHigh; ++level) |
|
892 { |
|
893 for (TInt i = iMemoryReleases.Count() - 1; !released && i >= 0; --i) |
|
894 { |
|
895 released = iMemoryReleases[i]->ReleaseMemory(static_cast<TMemoryReleaseLevel>(level)); |
|
896 } |
|
897 } |
|
898 return released; |
|
899 } |
|
900 |