|
1 /* |
|
2 * Copyright (c) 2006-2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implementation of CHuiDisplay, a drawing buffer into which a |
|
15 * the toolkit contents (visuals) are drawn. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #include "uiacceltk/HuiDisplay.h" // Class definition |
|
22 #include "uiacceltk/HuiStatic.h" |
|
23 #include "HuiRenderPlugin.h" |
|
24 #include "HuiRenderSurface.h" |
|
25 #include "uiacceltk/HuiEnv.h" |
|
26 #include "HuiRosterImpl.h" |
|
27 #include "uiacceltk/HuiSkin.h" |
|
28 #include "uiacceltk/HuiTransformation.h" |
|
29 #include "uiacceltk/HuiUtil.h" |
|
30 #include "uiacceltk/HuiTexture.h" |
|
31 #include "uiacceltk/HuiProbe.h" |
|
32 #include "uiacceltk/HuiS60Skin.h" |
|
33 #include "uiacceltk/HuiGc.h" |
|
34 #ifndef __SERIES60_30__ |
|
35 #include "HuiTargetBitmap.h" |
|
36 #endif |
|
37 #include "uiacceltk/HuiControlGroup.h" |
|
38 #include "alf/alfconstants.h" |
|
39 |
|
40 #ifdef RD_ALF_IN_PLATFORM |
|
41 #include <displaylayoutmetrics.cdl.h> |
|
42 #endif // RD_ALF_IN_PLATFORM |
|
43 |
|
44 #include <AknsRendererWrapper.h> |
|
45 #include <AknsDrawUtils.h> |
|
46 |
|
47 #include <coecntrl.h> |
|
48 #include <uiacceltk/huidisplaybackgrounditem.h> |
|
49 #include "huiskinbackroundlayout.h" |
|
50 #include "HuiFxEngine.h" |
|
51 |
|
52 const TUid KHuiInternalFbsBitmapBufferGcUid = {0x2000e5a3}; |
|
53 |
|
54 //#define HUI_DEBUG_PRINT_PERFORMANCE_INTERVAL |
|
55 |
|
56 |
|
57 // *** Class CHuiFbsBitmapBufferGc |
|
58 |
|
59 class CHuiFbsBitmapBufferGc: public CBase, public MHuiFbsBitmapBufferGc |
|
60 { |
|
61 public: |
|
62 CHuiFbsBitmapBufferGc(CFbsBitmap* aBitmap) :iBitmap(aBitmap) {}; |
|
63 |
|
64 private: // From MHuiFbsBitmapBufferGc |
|
65 void ReleaseGc(); |
|
66 CFbsBitmap* Bitmap(); |
|
67 |
|
68 private: |
|
69 CFbsBitmap* iBitmap; // not owned |
|
70 }; |
|
71 |
|
72 |
|
73 void CHuiFbsBitmapBufferGc::ReleaseGc() |
|
74 { |
|
75 // Line "delete(this)" should always be the last line in this method. |
|
76 // If you change this method behaviour make sure you know what caveats "delete(this)" has. |
|
77 delete(this); |
|
78 } |
|
79 |
|
80 CFbsBitmap* CHuiFbsBitmapBufferGc::Bitmap() |
|
81 { |
|
82 return iBitmap; |
|
83 } |
|
84 |
|
85 // *** Class CHuiDisplay |
|
86 |
|
87 CHuiDisplay::CHuiDisplay(CHuiEnv& aEnv, RWindow* aNativeWindow, TInt aDisplayType, TUid aBackBufferUid ) |
|
88 : iEnv(aEnv), |
|
89 iDisplayType(aDisplayType), |
|
90 iActive(ETrue), |
|
91 iBackgroundColor(KRgbBlack), |
|
92 iUpdateRenderState(ETrue), |
|
93 iUsageHint(EHuiDisplayUsageGeneric), |
|
94 iOnForeground(ETrue), |
|
95 iScreenBufferUid(aBackBufferUid), |
|
96 iUseTransformedDirtyRegions(EFalse), |
|
97 iDrawVisualOutline( EDrawVisualOutlineNone ), |
|
98 iNativeWindow(aNativeWindow) |
|
99 { |
|
100 } |
|
101 |
|
102 CHuiDisplay::CHuiDisplay(CHuiEnv& aEnv, CCoeControl* aNativeControl, TInt aDisplayType, TUid aBackBufferUid ) |
|
103 : iEnv(aEnv), |
|
104 iDisplayType(aDisplayType), |
|
105 iNativeControl(aNativeControl), |
|
106 iSize(0, 0), |
|
107 iActive(ETrue), |
|
108 iBackgroundColor(KRgbBlack), |
|
109 iUpdateRenderState(ETrue), |
|
110 iUsageHint(EHuiDisplayUsageGeneric), |
|
111 iOnForeground(ETrue), |
|
112 iScreenBufferUid(aBackBufferUid), |
|
113 iUseTransformedDirtyRegions(EFalse), |
|
114 iDrawDirtyRegions( EFalse ), |
|
115 iDrawVisualOutline( EDrawVisualOutlineNone ) |
|
116 { |
|
117 } |
|
118 |
|
119 |
|
120 void CHuiDisplay::ConstructL(const TRect& aRect, CHuiRoster* aSharedRoster) |
|
121 { |
|
122 HUI_DEBUG1(_L("CHuiDisplay::ConstructL - Free memory in beginning: %i"), HuiUtil::FreeMemory()); |
|
123 |
|
124 // Register this display to receive foreground lost / gained events. |
|
125 /* CCoeEnv* coeEnv = CCoeEnv::Static(); |
|
126 if(coeEnv && NativeWindow()) |
|
127 { |
|
128 coeEnv->AddMessageMonitorObserverL(*this); |
|
129 NativeWindow()->EnableVisibilityChangeEvents(); |
|
130 } |
|
131 */ |
|
132 |
|
133 iSize = aRect.Size(); |
|
134 |
|
135 // Create a rendering surface. |
|
136 iRenderSurface = CHuiStatic::Renderer().CreateRenderSurfaceL(*this); |
|
137 |
|
138 iCurrentDirtyRegions = &iDirtyRegions; |
|
139 |
|
140 // Preserve previous dirty rect info only if the surface uses both dirty rects and double |
|
141 // buffering |
|
142 TUint flags = MHuiRenderSurface::EFlagUseDirtyRects | MHuiRenderSurface::EFlagUseDoubleBuffering; |
|
143 TBool preservePreviousDirtyRectInfo = ((iRenderSurface->Flags() & flags) == flags); |
|
144 |
|
145 if (preservePreviousDirtyRectInfo) |
|
146 { |
|
147 iPreviousDirtyRegions = &iDirtyRegions2; |
|
148 } |
|
149 |
|
150 // Create a control roster. |
|
151 if(aSharedRoster) |
|
152 { |
|
153 iRoster.Set(aSharedRoster, EHuiDoesNotHaveOwnership); |
|
154 } |
|
155 else |
|
156 { |
|
157 // Construct a private roster. |
|
158 CHuiRosterImpl* roster = new (ELeave) CHuiRosterImpl(this); |
|
159 iRoster.Set(roster, EHuiHasOwnership); |
|
160 } |
|
161 |
|
162 // Transformation for the entire display. |
|
163 iTransform = CHuiTransformation::NewL(); |
|
164 // Window transformation for the entire display. |
|
165 iWindowTransform = CHuiTransformation::NewL(); |
|
166 |
|
167 SetScreenBufferLock(EFalse); |
|
168 |
|
169 // Create a graphics context. |
|
170 iGc = CHuiStatic::Renderer().CreateGcL(); |
|
171 |
|
172 HUI_DEBUG1(_L("CHuiDisplay::ConstructL - Free memory after GC created: %i"), HuiUtil::FreeMemory()); |
|
173 |
|
174 SetVisibleArea(TRect(TPoint(0, 0), iSize)); |
|
175 |
|
176 HUI_DEBUG1(_L("CHuiDisplay::ConstructL - Free memory after surface created: %i"), HuiUtil::FreeMemory()); |
|
177 |
|
178 if ( !CHuiStatic::Renderer().Allows( EHuiRenderPluginAllowPBufferSurfaces ) ) |
|
179 // There is no default render surface, so make this one current |
|
180 // immediately to enable texture loading. |
|
181 { |
|
182 iRenderSurface->MakeCurrent(); |
|
183 } |
|
184 |
|
185 // When dirty regions are transformed it is possible to avoid |
|
186 // full display refresh in many cases -> better performance. |
|
187 iGc->EnableTransformedClippingRects(iUseTransformedDirtyRegions); |
|
188 |
|
189 HUI_DEBUG1(_L("CHuiDisplay::ConstructL - Free memory when exiting ConstructL: %i"), HuiUtil::FreeMemory()); |
|
190 } |
|
191 |
|
192 |
|
193 EXPORT_C CHuiDisplay::~CHuiDisplay() |
|
194 { |
|
195 HUI_DEBUG1(_L("CHuiDisplay %x destructor"), this); |
|
196 |
|
197 // Unregister this display from foreground gained / lost events. |
|
198 // CCoeEnv* coeEnv = CCoeEnv::Static(); |
|
199 // if(coeEnv && NativeWindow()) |
|
200 // { |
|
201 // coeEnv->RemoveMessageMonitorObserver(*this); |
|
202 // } |
|
203 |
|
204 // Notify observers of deletion. |
|
205 |
|
206 if(iScreenBufferObserver) |
|
207 { |
|
208 iScreenBufferObserver->HandleScreenBufferEvent(iScreenBufferUid, MHuiScreenBufferObserver::EDeleted); |
|
209 } |
|
210 |
|
211 for(TInt i = 0; i < iDeletionObservers.Count(); ++i) |
|
212 { |
|
213 iDeletionObservers[i].NotifyDisplayDeletion(*this); |
|
214 } |
|
215 iDeletionObservers.Reset(); |
|
216 iRefreshObservers.Reset(); |
|
217 iVisibleAreaObservers.Reset(); |
|
218 iRosterObservers.Reset(); |
|
219 |
|
220 iDirtyRegions.Close(); |
|
221 iDirtyRegions2.Close(); |
|
222 if ( iCurrentDirtyRegions ) |
|
223 { |
|
224 iCurrentDirtyRegions->Close(); |
|
225 } |
|
226 iCurrentDirtyRegions = NULL; |
|
227 |
|
228 if ( iPreviousDirtyRegions ) |
|
229 { |
|
230 iPreviousDirtyRegions->Close(); |
|
231 } |
|
232 iPreviousDirtyRegions = NULL; |
|
233 |
|
234 delete iRenderSurface; |
|
235 iRenderSurface = NULL; |
|
236 |
|
237 delete iGc; |
|
238 iGc = NULL; |
|
239 |
|
240 delete iTransform; |
|
241 iTransform = NULL; |
|
242 |
|
243 delete iWindowTransform; |
|
244 iWindowTransform = NULL; |
|
245 |
|
246 iEnv.RemoveDisplay(*this); |
|
247 |
|
248 iNativeControl = NULL; |
|
249 |
|
250 iBackgroundItems.Close(); |
|
251 |
|
252 delete iForegroundTexture; |
|
253 |
|
254 delete iForegroundBitmapGc; |
|
255 delete iForegroundBitmapDevice; |
|
256 iForegroundBitmap = NULL; |
|
257 } |
|
258 |
|
259 TReal32 CHuiDisplay::UnitValue() const |
|
260 { |
|
261 #ifdef RD_ALF_IN_PLATFORM |
|
262 // this will be correct according to the currently loaded layout pack for the current display |
|
263 if (CCoeEnv::Static()) |
|
264 { |
|
265 return Display_Layout_Metrics::UnitValue(); |
|
266 } |
|
267 else |
|
268 { |
|
269 return 1.0f; |
|
270 } |
|
271 #else // RD_ALF_IN_PLATFORM |
|
272 // not supported |
|
273 return 1.0f; |
|
274 #endif // RD_ALF_IN_PLATFORM |
|
275 } |
|
276 |
|
277 void CHuiDisplay::MonitorWsMessage(const TWsEvent& aEvent) |
|
278 { |
|
279 switch(aEvent.Type()) |
|
280 { |
|
281 case EEventWindowVisibilityChanged: |
|
282 { |
|
283 const TBool wasOnForeground = iOnForeground; |
|
284 |
|
285 // iOnForeground = !(aEvent.VisibilityChanged()->iFlags&TWsVisibilityChangedEvent::ENotVisible); |
|
286 |
|
287 if ( !wasOnForeground && iOnForeground ) |
|
288 { |
|
289 // Becomes visible, force refresh. |
|
290 // This is needed for example in case of resolution changes. |
|
291 SetDirty(); |
|
292 } |
|
293 break; |
|
294 } |
|
295 |
|
296 default: |
|
297 break; |
|
298 } |
|
299 } |
|
300 |
|
301 |
|
302 CHuiGc* CHuiDisplay::Gc() |
|
303 { |
|
304 ASSERT(iGc != NULL); |
|
305 |
|
306 return iGc; |
|
307 } |
|
308 |
|
309 EXPORT_C CCoeControl* CHuiDisplay::NativeControl() |
|
310 { |
|
311 return iNativeControl; |
|
312 } |
|
313 |
|
314 |
|
315 EXPORT_C RDrawableWindow* CHuiDisplay::NativeWindow() |
|
316 { |
|
317 if (iNativeWindow) |
|
318 { |
|
319 return iNativeWindow; |
|
320 } |
|
321 |
|
322 else if(iNativeControl) |
|
323 { |
|
324 return iNativeControl->DrawableWindow(); |
|
325 } |
|
326 |
|
327 return 0; |
|
328 } |
|
329 |
|
330 |
|
331 EXPORT_C CHuiEnv& CHuiDisplay::Env() |
|
332 { |
|
333 return iEnv; |
|
334 } |
|
335 |
|
336 |
|
337 EXPORT_C MHuiRenderSurface& CHuiDisplay::RenderSurface() const |
|
338 { |
|
339 return *iRenderSurface; |
|
340 } |
|
341 |
|
342 |
|
343 EXPORT_C CHuiRoster& CHuiDisplay::Roster() |
|
344 { |
|
345 return iRoster.Ref(); |
|
346 } |
|
347 |
|
348 |
|
349 EXPORT_C const CHuiRoster& CHuiDisplay::Roster() const |
|
350 { |
|
351 return iRoster.Ref(); |
|
352 } |
|
353 |
|
354 |
|
355 EXPORT_C void CHuiDisplay::Show(TBool aShow) |
|
356 { |
|
357 iRenderSurface->HandleVisibilityEvent(aShow); |
|
358 |
|
359 // Update projection and GC state on the next refresh. |
|
360 iUpdateRenderState = ETrue; |
|
361 } |
|
362 |
|
363 |
|
364 CHuiRosterImpl& CHuiDisplay::RosterImpl() const |
|
365 { |
|
366 return STATIC_CAST(CHuiRosterImpl&, iRoster.NonConstRef()); |
|
367 } |
|
368 |
|
369 |
|
370 EXPORT_C void CHuiDisplay::SetSizeL(const TSize& aSize) |
|
371 { |
|
372 iSize = aSize; |
|
373 |
|
374 // Update projection and GC state on the next refresh. |
|
375 iUpdateRenderState = ETrue; |
|
376 |
|
377 if(iRenderSurface) |
|
378 { |
|
379 iRenderSurface->SetSizeL(iSize); |
|
380 } |
|
381 } |
|
382 |
|
383 |
|
384 EXPORT_C TSize CHuiDisplay::Size() const |
|
385 { |
|
386 return iSize; |
|
387 } |
|
388 |
|
389 |
|
390 EXPORT_C TRect CHuiDisplay::VisibleArea() const |
|
391 { |
|
392 return iGc->DisplayArea(); |
|
393 } |
|
394 |
|
395 |
|
396 EXPORT_C void CHuiDisplay::SetVisibleArea(const TRect& aArea) |
|
397 { |
|
398 if(iGc) |
|
399 { |
|
400 // If clipping has been defined for visible are, it is now invalid so disable. |
|
401 SetVisibleAreaClippingRect(TRect(0,0,0,0)); |
|
402 |
|
403 iGc->SetDisplayArea(aArea); |
|
404 // Make sure everything gets redrawn. |
|
405 SetDirty(); |
|
406 |
|
407 // Can change the roster rect only if the roster is own |
|
408 // \todo This should be prevented also for other shared roster types. |
|
409 RosterImpl().SetRect(aArea); |
|
410 |
|
411 // Update projection and GC state on the next refresh. |
|
412 iUpdateRenderState = ETrue; |
|
413 |
|
414 // Inform observers. |
|
415 for(TInt i = 0; i < iVisibleAreaObservers.Count(); ++i) |
|
416 { |
|
417 iVisibleAreaObservers[i].NotifyDisplayVisibleAreaChanged(*this); |
|
418 } |
|
419 } |
|
420 } |
|
421 |
|
422 |
|
423 EXPORT_C void CHuiDisplay::Activate(TBool aActivate) |
|
424 { |
|
425 iActive = aActivate; |
|
426 |
|
427 if(iActive) |
|
428 { |
|
429 // This is the display now using the roster. Only meaningful when the |
|
430 // roster is shared between many displays. |
|
431 RosterImpl().SetDisplay(this); |
|
432 } |
|
433 } |
|
434 |
|
435 |
|
436 EXPORT_C TBool CHuiDisplay::Active() const |
|
437 { |
|
438 return iActive; |
|
439 } |
|
440 |
|
441 |
|
442 EXPORT_C void CHuiDisplay::SetOrientation(CHuiGc::TOrientation aOrientation) |
|
443 { |
|
444 if (iGc->Orientation() == aOrientation) |
|
445 { |
|
446 return; |
|
447 } |
|
448 |
|
449 iGc->SetOrientation(aOrientation); |
|
450 |
|
451 // The effective visible area, as seen by the UI, changes. |
|
452 RosterImpl().SetRect(VisibleArea()); |
|
453 for(TInt i = 0; i < iVisibleAreaObservers.Count(); ++i) |
|
454 { |
|
455 iVisibleAreaObservers[i].NotifyDisplayVisibleAreaChanged(*this); |
|
456 } |
|
457 |
|
458 SetDirty(); |
|
459 |
|
460 // Update projection and GC state on the next refresh. |
|
461 iUpdateRenderState = ETrue; |
|
462 |
|
463 // Clear effect engine cache as it most likely now contains buffers which |
|
464 // sizes are not very well reusable. It would be better to have "fifo" or |
|
465 // something in the cache implementation but until that just release everything here |
|
466 // when display layout changes. |
|
467 CHuiFxEngine* fxEngine = Env().EffectsEngine(); |
|
468 if (fxEngine) |
|
469 { |
|
470 fxEngine->ClearCache(); |
|
471 } |
|
472 } |
|
473 |
|
474 |
|
475 EXPORT_C CHuiGc::TOrientation CHuiDisplay::Orientation() const |
|
476 { |
|
477 return iGc->Orientation(); |
|
478 } |
|
479 |
|
480 |
|
481 EXPORT_C void CHuiDisplay::SetDirty() |
|
482 { |
|
483 // Mark the entire display dirty. |
|
484 HUI_DEBUG(_L("CHuiDisplay::SetDirty() - called.")); |
|
485 |
|
486 if ( iWholeDisplayAreaIsDirty ) |
|
487 { |
|
488 return; |
|
489 } |
|
490 |
|
491 TRect displayArea = iGc->DisplayArea(); |
|
492 AddDirtyRegion(displayArea, *iCurrentDirtyRegions); |
|
493 if (iPreviousDirtyRegions) |
|
494 { |
|
495 AddDirtyRegion(displayArea, *iPreviousDirtyRegions); |
|
496 } |
|
497 iEnv.ContinueRefresh(); |
|
498 |
|
499 iWholeDisplayAreaIsDirty = ETrue; |
|
500 } |
|
501 |
|
502 |
|
503 TBool CHuiDisplay::IsDirty() const |
|
504 { |
|
505 //iRoster->ScanDirty(); |
|
506 //return iDirtyRegions.Count() > 0; |
|
507 |
|
508 /** @todo Determine this better. There should be a way to quickly |
|
509 determine if the display needs to be updated; although |
|
510 a visual change scan is also a possiblity if it is done |
|
511 once per frame. */ |
|
512 |
|
513 return iActive; |
|
514 } |
|
515 |
|
516 |
|
517 void CHuiDisplay::AddDirtyRegion(const TRect& aDirtyRegion) |
|
518 { |
|
519 // Whole screen has been set dirty, no need to add new areas. |
|
520 if (iWholeDisplayAreaIsDirty && iGotDirtyReports) |
|
521 { |
|
522 return; |
|
523 } |
|
524 |
|
525 TRect clippedDirtyRect = aDirtyRegion; |
|
526 |
|
527 if (UseTransformedDirtyRegions()) |
|
528 { |
|
529 TransformDirtyRect(clippedDirtyRect); |
|
530 } |
|
531 |
|
532 ClipDirtyRect(clippedDirtyRect); |
|
533 |
|
534 // If whole screen is set dirty, update flag which can be used to avoid |
|
535 // further unnecessary dirty area calculations |
|
536 if (iGc && (iGc->DisplayArea() == clippedDirtyRect)) |
|
537 { |
|
538 iWholeDisplayAreaIsDirty = ETrue; |
|
539 } |
|
540 |
|
541 // At least one dirty region was reported. |
|
542 iGotDirtyReports = ETrue; |
|
543 |
|
544 AddDirtyRegion(clippedDirtyRect, *iCurrentDirtyRegions); |
|
545 } |
|
546 |
|
547 |
|
548 void CHuiDisplay::CombineAndAddDirtyRegion(const TRect& aPrevDirtyRegion, TRect& aDirtyRegion) |
|
549 { |
|
550 // aPrevDirtyRegion has already been transformed, but aDirtyRegion is not (yet) |
|
551 // transformed. |
|
552 |
|
553 TRect dirtyRect = aDirtyRegion; |
|
554 |
|
555 if (!dirtyRect.IsEmpty() && UseTransformedDirtyRegions()) |
|
556 { |
|
557 TransformDirtyRect(dirtyRect); |
|
558 } |
|
559 |
|
560 TRect transformedNewDirtyRect = dirtyRect; |
|
561 |
|
562 // If the whole display is not dirty, update current combined dirty region |
|
563 if (!iWholeDisplayAreaIsDirty) |
|
564 { |
|
565 dirtyRect.BoundingRect(aPrevDirtyRegion); |
|
566 |
|
567 ClipDirtyRect(dirtyRect); |
|
568 |
|
569 if (iGc && (iGc->DisplayArea() == dirtyRect)) |
|
570 { |
|
571 // If whole screen is set dirty, update flag which can be used to avoid |
|
572 // further unnecessary dirty area calculations |
|
573 iWholeDisplayAreaIsDirty = ETrue; |
|
574 } |
|
575 |
|
576 // At least one dirty region was reported. |
|
577 iGotDirtyReports = ETrue; |
|
578 AddDirtyRegion(dirtyRect, *iCurrentDirtyRegions); |
|
579 } |
|
580 // We must only transform the (new) dirtyregion, not combine or anything else here |
|
581 aDirtyRegion = transformedNewDirtyRect; |
|
582 } |
|
583 |
|
584 |
|
585 void CHuiDisplay::AddDirtyRegion(const TRect& aDirtyRegion, RDirtyRegions& aRegions, TBool /*aGrow*/) |
|
586 { |
|
587 TBool combined = ETrue; |
|
588 TInt i = 0; |
|
589 TInt k = 0; |
|
590 |
|
591 aRegions.Append(aDirtyRegion); |
|
592 |
|
593 // Combine overlapping regions. |
|
594 while(combined && aRegions.Count() > 1) |
|
595 { |
|
596 combined = EFalse; |
|
597 |
|
598 // Check that none of the regions overlap each other. |
|
599 /** @todo Performance? */ |
|
600 for(i = 0; i < aRegions.Count(); ++i) |
|
601 { |
|
602 TRect expanded = aRegions[i]; |
|
603 expanded.Grow(20, 20); //(8, 8); |
|
604 |
|
605 for(k = i + 1; k < aRegions.Count(); ++k) |
|
606 { |
|
607 // E: comment out for lazy merging |
|
608 if(aRegions[k].Intersects(expanded)) |
|
609 { |
|
610 // Remove the latter one. |
|
611 aRegions[i].BoundingRect(aRegions[k]); |
|
612 aRegions.Remove(k); |
|
613 --k; |
|
614 combined = ETrue; |
|
615 } |
|
616 } |
|
617 } |
|
618 } |
|
619 } |
|
620 |
|
621 |
|
622 TBool CHuiDisplay::Refresh() |
|
623 { |
|
624 HUI_DEBUGF(_L("CHuiDisplay::Refresh() - Entering.")); |
|
625 HUI_PROBE_PROGRAMFLOW_ENTER(MHuiProbe::EProgramFlowPointRefresh) |
|
626 |
|
627 #ifdef HUI_DEBUG_PRINT_PERFORMANCE_INTERVAL |
|
628 RDebug::Print(_L("CHuiDisplay::Refresh: starting measuring.")); |
|
629 TTime startTime; |
|
630 startTime.UniversalTime(); |
|
631 #endif |
|
632 |
|
633 |
|
634 // Prevent display refresh, if the display is on background. |
|
635 if(!iOnForeground || IsScreenBufferLocked()) |
|
636 { |
|
637 return EFalse; |
|
638 } |
|
639 |
|
640 TBool useDirtyRects = (RenderSurface().Flags() & MHuiRenderSurface::EFlagUseDirtyRects) |
|
641 == MHuiRenderSurface::EFlagUseDirtyRects; |
|
642 |
|
643 iWholeDisplayAreaIsDirty = EFalse; |
|
644 |
|
645 if(iUpdateRenderState) |
|
646 { |
|
647 // Set state when requested. |
|
648 iGc->InitState(); |
|
649 iGc->SetProjection(); |
|
650 |
|
651 iUpdateRenderState = EFalse; |
|
652 } |
|
653 |
|
654 // Let the skin know that we're now drawing in this context. |
|
655 iEnv.Skin().SetContext(*iGc); |
|
656 |
|
657 TRect displayArea = iGc->DisplayArea(); |
|
658 |
|
659 // Notify observers of the display refresh. |
|
660 TInt i = 0; |
|
661 for(i = 0; i < iRefreshObservers.Count(); ++i) |
|
662 { |
|
663 iRefreshObservers[i].NotifyDisplayRefreshStarted(*this); |
|
664 } |
|
665 #ifdef HUI_DEBUG_PRINT_PERFORMANCE_INTERVAL |
|
666 TTime afterNotifiedTime; |
|
667 afterNotifiedTime.UniversalTime(); |
|
668 #endif |
|
669 |
|
670 |
|
671 if (IsDisplayTypeTvOut()) |
|
672 { |
|
673 // Scale shared roster to Tv-out screen |
|
674 TReal32 scaleFactorX = (TReal32)Size().iWidth / (TReal32)RosterImpl().Rect().Width(); |
|
675 TReal32 scaleFactorY = (TReal32)Size().iHeight / (TReal32)RosterImpl().Rect().Height(); |
|
676 // Calculate window transformations |
|
677 iWindowTransform->LoadIdentity(); |
|
678 iWindowTransform->Scale(scaleFactorX, scaleFactorY, 1.f); |
|
679 } |
|
680 |
|
681 // THuiRenderer renderer = iEnv.Renderer(); |
|
682 TBool hasTransformations = iTransform->Count() != 0 || iWindowTransform->Count() != 0 || RosterImpl().HasTransformedControlGroups(); |
|
683 TBool cantUseDirtyRectsInThisFrame = hasTransformations && !UseTransformedDirtyRegions(); |
|
684 |
|
685 // When refresh is forced, there is no need to scan dirty areas. |
|
686 if (iEnv.RefreshMode() != EHuiRefreshModeForced) |
|
687 { |
|
688 // Flag that tells us if any dirty regions were reported for |
|
689 // this frame. |
|
690 iGotDirtyReports = (iCurrentDirtyRegions->Count() > 0); |
|
691 |
|
692 // Tell all visuals to post their dirty regions (for the current state). |
|
693 if (UseTransformedDirtyRegions()) |
|
694 { |
|
695 RosterImpl().ScanTransformedDirty(*iGc, this); |
|
696 } |
|
697 else |
|
698 { |
|
699 RosterImpl().ScanDirty(); |
|
700 } |
|
701 |
|
702 if (!useDirtyRects || cantUseDirtyRectsInThisFrame || iEnv.EffectsEngine()->HasActiveEffects()) |
|
703 { |
|
704 // Just redraw everything |
|
705 iCurrentDirtyRegions->Reset(); |
|
706 AddDirtyRegion(displayArea, *iCurrentDirtyRegions, EFalse); |
|
707 } |
|
708 } |
|
709 else |
|
710 { |
|
711 iGotDirtyReports = ETrue; |
|
712 |
|
713 // Just redraw everything since determining dirty regions is |
|
714 // complicated with a transformed display. |
|
715 iCurrentDirtyRegions->Reset(); |
|
716 AddDirtyRegion(displayArea); |
|
717 } |
|
718 |
|
719 // We can return now if there are no new or old dirty areas |
|
720 if (!iGotDirtyReports && (!iPreviousDirtyRegions || (iPreviousDirtyRegions->Count() == 0))) |
|
721 { |
|
722 iCurrentDirtyRegions->Reset(); |
|
723 return EFalse; |
|
724 } |
|
725 |
|
726 // Form the real list of dirty regions by combining the dirty regions of |
|
727 // this frame and the previous frame (this is needed when buffer swapping |
|
728 // is used; with buffer copying a single list of dirty regions would |
|
729 // suffice). |
|
730 RDirtyRegions dirty; |
|
731 for(i = 0; i < iCurrentDirtyRegions->Count(); ++i) |
|
732 { |
|
733 dirty.Append((*iCurrentDirtyRegions)[i]); |
|
734 } |
|
735 if (iPreviousDirtyRegions) |
|
736 { |
|
737 for(i = 0; i < iPreviousDirtyRegions->Count(); ++i) |
|
738 { |
|
739 AddDirtyRegion((*iPreviousDirtyRegions)[i], dirty, EFalse); |
|
740 } |
|
741 } |
|
742 |
|
743 // Do initializations for new frame |
|
744 // initnewframe may clear the screen, and it may be that |
|
745 // the clipping rectangle is not set up correctly |
|
746 // atleast if the dirty area tracking is on.. |
|
747 iGc->SetPenColor(iBackgroundColor); |
|
748 iGc->InitNewFrame(); |
|
749 |
|
750 if ( iDrawDirtyRegions ) |
|
751 { |
|
752 // Show dirty. |
|
753 // This will draw the whole background with black. |
|
754 iGc->SetPenColor(KRgbBlack); |
|
755 iGc->Disable(CHuiGc::EFeatureClipping); |
|
756 iGc->Clear(); |
|
757 } |
|
758 |
|
759 |
|
760 // Set up clipping. |
|
761 TInt markedClipStackCount = iGc->ClipStackCount(); |
|
762 if(useDirtyRects) |
|
763 { |
|
764 iGc->Enable(CHuiGc::EFeatureClipping); |
|
765 } |
|
766 |
|
767 // Assume that we succeed to clean the dirty regions |
|
768 TBool dirtyRegionsCleaned = ETrue; |
|
769 |
|
770 // Set dirty rect in render surface to minimize screen update |
|
771 // Only implemented for BitGdi renderer for now |
|
772 TRect mergedDirtyRect; |
|
773 if (dirty.Count() > 0) |
|
774 { |
|
775 mergedDirtyRect = dirty[0]; |
|
776 } |
|
777 |
|
778 if (useDirtyRects) |
|
779 { |
|
780 // When Bitgdi renderer used set dirty rect in render surface |
|
781 // to minimize screen update in CHuiBitgdiRenderSurface::SwapBuffers |
|
782 if (dirty.Count() == 1) |
|
783 { |
|
784 ClipDirtyRect(mergedDirtyRect, VisibleAreaClippingRect()); |
|
785 iRenderSurface->SetDirtyRect(mergedDirtyRect); |
|
786 } |
|
787 else if (dirty.Count() > 1) |
|
788 { |
|
789 for(i = 1; i < dirty.Count(); ++i) |
|
790 { |
|
791 TRect r(dirty[i]); |
|
792 // check top left corner to expand or not |
|
793 if (r.iTl.iX < mergedDirtyRect.iTl.iX) |
|
794 { |
|
795 mergedDirtyRect.iTl.iX = r.iTl.iX; |
|
796 } |
|
797 if (r.iTl.iY < mergedDirtyRect.iTl.iY) |
|
798 { |
|
799 mergedDirtyRect.iTl.iY = r.iTl.iY; |
|
800 } |
|
801 // check bottom right corner to expand or not |
|
802 if (mergedDirtyRect.iBr.iX < r.iBr.iX) |
|
803 { |
|
804 mergedDirtyRect.iBr.iX = r.iBr.iX; |
|
805 } |
|
806 if (mergedDirtyRect.iBr.iY < r.iBr.iY) |
|
807 { |
|
808 mergedDirtyRect.iBr.iY = r.iBr.iY; |
|
809 } |
|
810 } |
|
811 |
|
812 ClipDirtyRect(mergedDirtyRect, VisibleAreaClippingRect()); |
|
813 iRenderSurface->SetDirtyRect(mergedDirtyRect); |
|
814 } |
|
815 else |
|
816 { |
|
817 // for PC lint |
|
818 } |
|
819 |
|
820 if ( iDrawDirtyRegions ) |
|
821 { |
|
822 // This will disable the clipping of the frame buffer when |
|
823 // blitting on the screen. |
|
824 iRenderSurface->SetDirtyRect(displayArea); |
|
825 } |
|
826 } |
|
827 |
|
828 // Merge into max one dirty area when HW accelrated drawing is used |
|
829 if (useDirtyRects && IsRendererHWAccelerated()) |
|
830 { |
|
831 dirty.Reset(); |
|
832 dirty.Append(mergedDirtyRect); |
|
833 } |
|
834 |
|
835 #ifdef HUI_DEBUG_PRINT_PERFORMANCE_INTERVAL |
|
836 RDebug::Print(_L("CHuiDisplay::Refresh: Merged dirty rect: %d %d %d %d"), |
|
837 mergedDirtyRect.iTl.iX, |
|
838 mergedDirtyRect.iTl.iY, |
|
839 mergedDirtyRect.iBr.iX, |
|
840 mergedDirtyRect.iBr.iY); |
|
841 #endif |
|
842 |
|
843 // Usually there is only one dirty region (if any). |
|
844 for(i = 0; i < dirty.Count(); ++i) |
|
845 { |
|
846 // Set up the clipping rectangle. |
|
847 TRect dirtyRect = dirty[i]; |
|
848 ClipDirtyRect(dirtyRect, VisibleAreaClippingRect()); |
|
849 |
|
850 iGc->PushClip(); |
|
851 iGc->Clip(dirtyRect); |
|
852 |
|
853 if ( iForegroundBitmapGc ) |
|
854 { |
|
855 // If we are in SW rendering mode, then SW bitmap is blended. |
|
856 // However, it's possible that nothing is drawn below, so clear |
|
857 // background. |
|
858 const TRgb oldBgColor = iBackgroundColor; |
|
859 iBackgroundColor = KRgbBlack; |
|
860 iBackgroundColor.SetAlpha(0); |
|
861 ClearWithColor( dirtyRect ); |
|
862 iBackgroundColor = oldBgColor; |
|
863 } |
|
864 |
|
865 // Clear background for the dirty area |
|
866 if (iBackgroundItems.Count() != 0) |
|
867 { |
|
868 ClearWithBackgroundItems(dirtyRect); |
|
869 } |
|
870 else |
|
871 { |
|
872 switch (iClearBackground) |
|
873 { |
|
874 case EClearWithColor: |
|
875 { |
|
876 ClearWithColor(dirtyRect); |
|
877 break; |
|
878 } |
|
879 case EClearWithSkinBackground: |
|
880 { |
|
881 ClearWithSkinBackground(dirtyRect); |
|
882 break; |
|
883 } |
|
884 case EClearNone: |
|
885 default: |
|
886 { |
|
887 // Don't do anything |
|
888 break; |
|
889 } |
|
890 } |
|
891 } |
|
892 |
|
893 if ( iForegroundBitmapGc ) |
|
894 { |
|
895 iForegroundBitmapGc->Reset(); |
|
896 iForegroundBitmapGc->SetClippingRegion( iGc->ClipRegion() ); |
|
897 |
|
898 TRgb clearColor = KRgbBlack; |
|
899 clearColor.SetAlpha(0x00); |
|
900 |
|
901 iForegroundBitmapGc->SetDrawMode(CGraphicsContext::EDrawModeWriteAlpha); |
|
902 iForegroundBitmapGc->SetPenColor(clearColor); |
|
903 iForegroundBitmapGc->SetBrushColor(clearColor); |
|
904 iForegroundBitmapGc->SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
905 iForegroundBitmapGc->Clear(); |
|
906 iForegroundBitmapGc->Reset(); |
|
907 } |
|
908 |
|
909 for(TInt i = 0; i < iRosterObservers.Count(); i++) |
|
910 { |
|
911 iRosterObservers[i].NotifyRosterDrawStart(*this); |
|
912 } |
|
913 |
|
914 // Prepare dirty visuals for drawing |
|
915 // Draw only if the prepare was successful |
|
916 if (RosterImpl().PrepareDraw()) |
|
917 { |
|
918 // Draw all the dirty visuals (that are touching dirty regions). |
|
919 iGc->Enable(CHuiGc::EFeatureBlending); |
|
920 RosterImpl().Draw(*iGc, this); |
|
921 } |
|
922 else |
|
923 { |
|
924 HUI_DEBUGF(_L("CHuiDisplay::Refresh() - Failed to prepare drawing!")); |
|
925 dirtyRegionsCleaned = EFalse; |
|
926 } |
|
927 |
|
928 for(TInt i = 0; i < iRosterObservers.Count(); i++) |
|
929 { |
|
930 iRosterObservers[i].NotifyRosterDrawEnd(*this); |
|
931 } |
|
932 |
|
933 if (iForegroundTexture) |
|
934 { |
|
935 DrawForegroundTexture(); |
|
936 } |
|
937 |
|
938 // Return to the clipping rectangle that was in use previously. |
|
939 iGc->PopClip(); |
|
940 } |
|
941 |
|
942 dirty.Reset(); |
|
943 |
|
944 // There must be no disparity in the number of pushed clipping rectangles. |
|
945 // (equivalent to __ASSERT_ALWAYS) |
|
946 if(iGc->ClipStackCount() > markedClipStackCount) |
|
947 { |
|
948 THuiPanic::Panic(THuiPanic::EDisplayClipStackUnpopped); |
|
949 } |
|
950 if(iGc->ClipStackCount() < markedClipStackCount) |
|
951 { |
|
952 THuiPanic::Panic(THuiPanic::EDisplayClipStackEarlyPop); |
|
953 } |
|
954 |
|
955 // Reset and flip if we managed to clean (draw) everything |
|
956 if (iPreviousDirtyRegions && dirtyRegionsCleaned && iCurrentDirtyRegions->Count() > 0) |
|
957 { |
|
958 RDirtyRegions* tmp = iPreviousDirtyRegions; |
|
959 iPreviousDirtyRegions = iCurrentDirtyRegions; |
|
960 iCurrentDirtyRegions = tmp; |
|
961 } |
|
962 |
|
963 // Clear current dirty regions |
|
964 iCurrentDirtyRegions->Reset(); |
|
965 |
|
966 // Trick to swap gles buffers if we are drawing idle screens before refresh loop is going to |
|
967 // sleep. |
|
968 if( IsRendererHWAccelerated() && !iGotDirtyReports && !iScreenBufferObserver) |
|
969 { |
|
970 //RenderSurface().SwapBuffers(); [ohi] |
|
971 } |
|
972 |
|
973 // Tell the screen buffer observer that the buffer is complete |
|
974 if(iScreenBufferObserver) |
|
975 { |
|
976 SetScreenBufferLock(ETrue); // the observer should do unlock! |
|
977 |
|
978 TRect rect(VisibleArea()); // This is not the real display rect in ALF display case(!) |
|
979 TRect dirtyRect(mergedDirtyRect); |
|
980 |
|
981 // Update screen buffer GC bitmap |
|
982 if (DisplayType() != CHuiDisplay::EDisplayOffScreenBuffer) |
|
983 { |
|
984 TRAP_IGNORE(CHuiStatic::Renderer().UpdateOffScreenBitmapL(*this)); |
|
985 } |
|
986 |
|
987 if (iScreenBufferObserver->ScreenBufferComplete(iScreenBufferUid, rect, dirtyRect)) |
|
988 { |
|
989 SetScreenBufferLock(EFalse); |
|
990 } |
|
991 } |
|
992 |
|
993 iWholeDisplayAreaIsDirty = EFalse; |
|
994 |
|
995 HUI_PROBE_PROGRAMFLOW_EXIT(MHuiProbe::EProgramFlowPointRefresh) |
|
996 HUI_DEBUGF(_L("CHuiDisplay::Refresh() - Exiting.")); |
|
997 |
|
998 #ifdef HUI_DEBUG_PRINT_PERFORMANCE_INTERVAL |
|
999 TTime endTime; |
|
1000 endTime.UniversalTime(); |
|
1001 TInt timeInMs = endTime.MicroSecondsFrom( startTime ).Int64()/1000; |
|
1002 TInt notifyTimeInMs = afterNotifiedTime.MicroSecondsFrom( startTime ).Int64()/1000; |
|
1003 TInt restTimeInMs = endTime.MicroSecondsFrom( afterNotifiedTime ).Int64()/1000; |
|
1004 |
|
1005 RDebug::Print(_L("CHuiDisplay::Refresh: took %i ms"), timeInMs); |
|
1006 RDebug::Print(_L("CHuiDisplay::Refresh: notify refresh observers took %i ms"), notifyTimeInMs); |
|
1007 RDebug::Print(_L("CHuiDisplay::Refresh: rest took %i ms"), restTimeInMs); |
|
1008 |
|
1009 #endif |
|
1010 |
|
1011 |
|
1012 // If something was reported (even if eventually clipped), we'll say that |
|
1013 // there was some activity. If it was clipped and did not show up on the |
|
1014 // display, it may soon (re)appear, so let's be cautious. |
|
1015 return iGotDirtyReports; |
|
1016 } |
|
1017 |
|
1018 |
|
1019 EXPORT_C CHuiTransformation& CHuiDisplay::Transformation() const |
|
1020 { |
|
1021 return *iTransform; |
|
1022 } |
|
1023 |
|
1024 |
|
1025 EXPORT_C void CHuiDisplay::SetClearBackgroundL(TClearMode aClearBackground) |
|
1026 { |
|
1027 // Make sure that background resource allocation is succeeded. |
|
1028 if(aClearBackground == EClearWithSkinBackground) |
|
1029 { |
|
1030 iEnv.Skin().TextureL(EHuiSkinBackgroundTexture); |
|
1031 } |
|
1032 |
|
1033 iClearBackground = aClearBackground; |
|
1034 iBackgroundItems.Reset(); |
|
1035 } |
|
1036 |
|
1037 |
|
1038 EXPORT_C void CHuiDisplay::SetBackgroundColor(const TRgb& aBackgroundColor) |
|
1039 { |
|
1040 iBackgroundColor = aBackgroundColor; |
|
1041 } |
|
1042 |
|
1043 |
|
1044 EXPORT_C void CHuiDisplay::SetUseDepth(TBool aUseDepth) |
|
1045 { |
|
1046 iUseDepth = aUseDepth; |
|
1047 } |
|
1048 |
|
1049 |
|
1050 EXPORT_C TUint8* CHuiDisplay::CaptureLC(TSize& aSize) const |
|
1051 { |
|
1052 return iGc->CaptureLC(aSize); |
|
1053 } |
|
1054 |
|
1055 |
|
1056 EXPORT_C void CHuiDisplay::SetQuality(THuiQuality aRenderingQuality) |
|
1057 { |
|
1058 if(iGc) |
|
1059 { |
|
1060 iGc->SetQuality(aRenderingQuality); |
|
1061 SetDirty(); |
|
1062 } |
|
1063 } |
|
1064 |
|
1065 |
|
1066 EXPORT_C THuiQuality CHuiDisplay::Quality() const |
|
1067 { |
|
1068 if(iGc) |
|
1069 { |
|
1070 return iGc->Quality(); |
|
1071 } |
|
1072 return EHuiQualityAccurate; |
|
1073 } |
|
1074 |
|
1075 |
|
1076 EXPORT_C void CHuiDisplay::Release() |
|
1077 { |
|
1078 // Free the render surface. |
|
1079 ASSERT(iRenderSurface != NULL); |
|
1080 HUI_DEBUG(_L("CHuiDisplay::Release() - Releasing render surface.")); |
|
1081 iRenderSurface->Release(); |
|
1082 |
|
1083 HUI_DEBUG(_L("CHuiDisplay::Release() - Display released.")); |
|
1084 } |
|
1085 |
|
1086 |
|
1087 EXPORT_C void CHuiDisplay::RestoreL() |
|
1088 { |
|
1089 HUI_DEBUG(_L("CHuiDisplay::RestoreL() - Restoring display resources.")); |
|
1090 |
|
1091 // Reconfigure graphics context when display is refreshed. |
|
1092 iUpdateRenderState = ETrue; |
|
1093 |
|
1094 // Create a rendering surface. |
|
1095 iRenderSurface->RestoreL(); |
|
1096 } |
|
1097 |
|
1098 |
|
1099 EXPORT_C TInt CHuiDisplay::DisplayType() |
|
1100 { |
|
1101 return iDisplayType; |
|
1102 } |
|
1103 |
|
1104 EXPORT_C TUid CHuiDisplay::ScreenBufferUid() |
|
1105 { |
|
1106 return iScreenBufferUid; |
|
1107 } |
|
1108 |
|
1109 |
|
1110 EXPORT_C TBool CHuiDisplay::IsScreenBufferLocked() const |
|
1111 { |
|
1112 return iIsScreenBufferLocked; |
|
1113 } |
|
1114 |
|
1115 |
|
1116 EXPORT_C void CHuiDisplay::SetScreenBufferLock(TBool aLock) |
|
1117 { |
|
1118 iIsScreenBufferLocked = aLock; |
|
1119 } |
|
1120 |
|
1121 |
|
1122 EXPORT_C MHuiBufferDrawer* CHuiDisplay::GetDrawingInterface(const TUid& /*aInterfaceUid*/) |
|
1123 { |
|
1124 return (MHuiBufferDrawer*)NULL; |
|
1125 } |
|
1126 |
|
1127 |
|
1128 EXPORT_C MHuiGc* CHuiDisplay::GetGraphicsContext(const TUid& aInterfaceUid) |
|
1129 { |
|
1130 MHuiGc* gc = NULL; |
|
1131 if (aInterfaceUid == KHuiInternalFbsBitmapBufferGcUid) |
|
1132 { |
|
1133 if (iEnv.Renderer() == EHuiRendererBitgdi) |
|
1134 { |
|
1135 CFbsBitmap* backBuffer = iRenderSurface->BackBuffer()->FbsBitmap(); |
|
1136 CHuiFbsBitmapBufferGc* bitmapGc = new CHuiFbsBitmapBufferGc(backBuffer); |
|
1137 gc = (MHuiFbsBitmapBufferGc*) bitmapGc; |
|
1138 } |
|
1139 else |
|
1140 { |
|
1141 if ( DisplayType() != CHuiDisplay::EDisplayOffScreenBuffer ) |
|
1142 { |
|
1143 gc =(MHuiFbsBitmapBufferGc*) new CHuiFbsBitmapBufferGc( |
|
1144 CHuiStatic::Renderer().OffScreenBitmap()); |
|
1145 } |
|
1146 } |
|
1147 } |
|
1148 return gc; |
|
1149 } |
|
1150 |
|
1151 EXPORT_C void CHuiDisplay::AddScreenBufferObserverL(MHuiScreenBufferObserver* aObserver) |
|
1152 { |
|
1153 if (DisplayType() != CHuiDisplay::EDisplayOffScreenBuffer) |
|
1154 { |
|
1155 CHuiStatic::Renderer().EnableOffScreenBitmapL(0); |
|
1156 } |
|
1157 |
|
1158 iScreenBufferObserver = aObserver; |
|
1159 SetScreenBufferLock(EFalse); |
|
1160 } |
|
1161 |
|
1162 |
|
1163 EXPORT_C void CHuiDisplay::RemoveScreenBufferObserver() |
|
1164 { |
|
1165 iScreenBufferObserver = NULL; |
|
1166 |
|
1167 if (DisplayType() != CHuiDisplay::EDisplayOffScreenBuffer) |
|
1168 { |
|
1169 CHuiStatic::Renderer().DisableOffScreenBitmap(); |
|
1170 } |
|
1171 |
|
1172 SetScreenBufferLock(EFalse); |
|
1173 } |
|
1174 |
|
1175 |
|
1176 EXPORT_C MHuiScreenBufferObserver* CHuiDisplay::ScreenBufferObserver() |
|
1177 { |
|
1178 return iScreenBufferObserver; |
|
1179 } |
|
1180 |
|
1181 |
|
1182 EXPORT_C void CHuiDisplay::DrawScreenBuffer() |
|
1183 { |
|
1184 if (DisplayType() != CHuiDisplay::EDisplayOffScreenBuffer) |
|
1185 { |
|
1186 TRAP_IGNORE(CHuiStatic::Renderer().DrawOffScreenBitmapToWindowL(*this)); |
|
1187 } |
|
1188 } |
|
1189 |
|
1190 |
|
1191 void CHuiDisplay::ClearChanged() |
|
1192 { |
|
1193 RosterImpl().ClearChanged(); |
|
1194 } |
|
1195 |
|
1196 EXPORT_C void CHuiDisplay::SetUsageL(TUint aUsageHint) |
|
1197 { |
|
1198 iUsageHint = aUsageHint; |
|
1199 if (iRenderSurface) |
|
1200 { |
|
1201 iRenderSurface->HandleDisplayUsageChangeL(); |
|
1202 } |
|
1203 } |
|
1204 |
|
1205 EXPORT_C TUint CHuiDisplay::Usage() const |
|
1206 { |
|
1207 return iUsageHint; |
|
1208 } |
|
1209 |
|
1210 |
|
1211 EXPORT_C TInt CHuiDisplay::GetPreferredTextureFormats(RPointerArray<CHuiDisplay::CTextureBitmapFormat>& aTextureFormats) |
|
1212 { |
|
1213 // Note: It would be better if preferred display mode was asked from the renderer itself |
|
1214 TInt err = KErrNone; |
|
1215 CHuiDisplay::CTextureBitmapFormat* format = NULL; |
|
1216 if (!IsRendererHWAccelerated()) |
|
1217 { |
|
1218 format = new CHuiDisplay::CTextureBitmapFormat(EColor64K, EGray256); |
|
1219 if (format != NULL) |
|
1220 { |
|
1221 err = aTextureFormats.Append(format); |
|
1222 } |
|
1223 } |
|
1224 else |
|
1225 { |
|
1226 format = new CHuiDisplay::CTextureBitmapFormat(EColor16MA, ENone); |
|
1227 if (format != NULL) |
|
1228 { |
|
1229 err = aTextureFormats.Append(format); |
|
1230 if (!err) |
|
1231 { |
|
1232 format = new CHuiDisplay::CTextureBitmapFormat(EColor64K, EGray256); |
|
1233 if (format != NULL) |
|
1234 { |
|
1235 err = aTextureFormats.Append(format); |
|
1236 } |
|
1237 } |
|
1238 } |
|
1239 } |
|
1240 |
|
1241 if (err) |
|
1242 { |
|
1243 delete(format); |
|
1244 } |
|
1245 |
|
1246 return (format == NULL) ? KErrNoMemory : err; |
|
1247 } |
|
1248 |
|
1249 |
|
1250 CHuiTransformation& CHuiDisplay::WindowTransformation() const |
|
1251 { |
|
1252 return *iWindowTransform; |
|
1253 } |
|
1254 |
|
1255 EXPORT_C TBool CHuiDisplay::IsDisplayTypeTvOut() const |
|
1256 { |
|
1257 return((iDisplayType == CHuiDisplay::EDisplayTvOut) || |
|
1258 (iDisplayType == CHuiDisplay::EDisplayTvOutWide) || |
|
1259 ((iDisplayType == CHuiDisplay::EDisplayNormal) && |
|
1260 ((iScreenBufferUid == KHuiUidBackBufferTvOutNormal) || |
|
1261 (iScreenBufferUid == KHuiUidBackBufferTvOutWide)))); |
|
1262 } |
|
1263 |
|
1264 TBool CHuiDisplay::IsRendererBitgdi() const |
|
1265 { |
|
1266 return (iEnv.Renderer() == EHuiRendererBitgdi); |
|
1267 } |
|
1268 |
|
1269 TBool CHuiDisplay::IsRendererHWAccelerated() const |
|
1270 { |
|
1271 return (iEnv.Renderer() != EHuiRendererBitgdi); |
|
1272 } |
|
1273 |
|
1274 void CHuiDisplay::ClipDirtyRect(TRect& aRect) |
|
1275 { |
|
1276 // Check if dirty regions partially outside display are reported, limit |
|
1277 // inside display area. |
|
1278 if(iGc) |
|
1279 { |
|
1280 TRect displayRect = iGc->DisplayArea(); |
|
1281 // If partially outside display area, we use intersection instead. |
|
1282 if (aRect.Intersects(displayRect)) |
|
1283 { |
|
1284 aRect.Intersection(displayRect); |
|
1285 } |
|
1286 } |
|
1287 } |
|
1288 |
|
1289 void CHuiDisplay::TransformDirtyRect(TRect& aRect) |
|
1290 { |
|
1291 if ( iGc ) |
|
1292 { |
|
1293 THuiRealRect realDirtyRect(aRect); |
|
1294 iGc->TransformDirtyRect(realDirtyRect); |
|
1295 aRect = TRect(HUI_ROUND_FLOAT_TO_INT(realDirtyRect.iTl.iX), HUI_ROUND_FLOAT_TO_INT(realDirtyRect.iTl.iY), |
|
1296 HUI_ROUND_FLOAT_TO_INT(realDirtyRect.iBr.iX), HUI_ROUND_FLOAT_TO_INT(realDirtyRect.iBr.iY)); |
|
1297 } |
|
1298 } |
|
1299 |
|
1300 TBool CHuiDisplay::UseTransformedDirtyRegions() const |
|
1301 { |
|
1302 return iUseTransformedDirtyRegions; |
|
1303 } |
|
1304 |
|
1305 EXPORT_C void CHuiDisplay::ShowDirtyRegions( TBool aShow ) |
|
1306 { |
|
1307 iDrawDirtyRegions = aShow; |
|
1308 } |
|
1309 |
|
1310 EXPORT_C void CHuiDisplay::SetDrawVisualOutline( TUint aDrawVisualOutline ) |
|
1311 { |
|
1312 iDrawVisualOutline = aDrawVisualOutline; |
|
1313 } |
|
1314 |
|
1315 TUint CHuiDisplay::DrawVisualOutline() const |
|
1316 { |
|
1317 return iDrawVisualOutline; |
|
1318 } |
|
1319 |
|
1320 TBool CHuiDisplay::IsDirtyScanNeeded() const |
|
1321 { |
|
1322 TUint flag = MHuiRenderSurface::EFlagUseDirtyRects; |
|
1323 TBool useDirtyRects = (RenderSurface().Flags() & flag) == flag; |
|
1324 return (useDirtyRects || !iGotDirtyReports); |
|
1325 } |
|
1326 |
|
1327 EXPORT_C void CHuiDisplay::SetBackgroundItemsL(const RArray<THuiDisplayBackgroundItem>& aItems) |
|
1328 { |
|
1329 iClearBackground = EClearNone; |
|
1330 iBackgroundItems.Reset(); |
|
1331 for(TInt i = 0; i < aItems.Count(); ++i) |
|
1332 { |
|
1333 iBackgroundItems.AppendL(aItems[i]); |
|
1334 } |
|
1335 if (IsRendererHWAccelerated()) |
|
1336 { |
|
1337 CHuiS60Skin* s60skin = static_cast<CHuiS60Skin*>(&iEnv.Skin()); |
|
1338 s60skin->UpdateBackgroundsL(iBackgroundItems); |
|
1339 } |
|
1340 SetDirty(); |
|
1341 } |
|
1342 |
|
1343 void CHuiDisplay::ClearWithColor(TRect aRect) |
|
1344 { |
|
1345 if (!IsRendererHWAccelerated()) |
|
1346 { |
|
1347 BitgdiClearWithColor(aRect); |
|
1348 } |
|
1349 else |
|
1350 { |
|
1351 HWAcceleratedClearWithColor(aRect); |
|
1352 } |
|
1353 } |
|
1354 |
|
1355 void CHuiDisplay::ClearWithSkinBackground(TRect aRect) |
|
1356 { |
|
1357 if (!IsRendererHWAccelerated()) |
|
1358 { |
|
1359 BitgdiClearWithSkinBackground(aRect); |
|
1360 } |
|
1361 else |
|
1362 { |
|
1363 HWAcceleratedClearWithSkinBackground(aRect); |
|
1364 } |
|
1365 } |
|
1366 |
|
1367 void CHuiDisplay::ClearWithBackgroundItems(TRect aRect) |
|
1368 { |
|
1369 if (!IsRendererHWAccelerated()) |
|
1370 { |
|
1371 BitgdiClearWithBackgroundItems(aRect); |
|
1372 } |
|
1373 else |
|
1374 { |
|
1375 HWAcceleratedClearWithBackgroundItems(aRect); |
|
1376 } |
|
1377 } |
|
1378 |
|
1379 |
|
1380 void CHuiDisplay::BitgdiClearWithColor(TRect /*aRect*/) |
|
1381 { |
|
1382 iGc->Enable(CHuiGc::EFeatureClipping); |
|
1383 iGc->Clear(); |
|
1384 } |
|
1385 |
|
1386 void CHuiDisplay::BitgdiClearWithSkinBackground(TRect aRect) |
|
1387 { |
|
1388 CCoeControl* nativeControl = NativeControl(); |
|
1389 CHuiS60Skin* s60skin = static_cast<CHuiS60Skin*>(&iEnv.Skin()); |
|
1390 CAknsBasicBackgroundControlContext* bgcontext = (CAknsBasicBackgroundControlContext*)s60skin->SkinControlContext(); |
|
1391 |
|
1392 CFbsBitGc* bitGc = iRenderSurface->BackBuffer()->Gc(); |
|
1393 if (nativeControl) |
|
1394 { |
|
1395 bgcontext->SetRect(TRect(TPoint(0, -nativeControl->Position().iY), HuiUtil::ScreenSize())); |
|
1396 } |
|
1397 else |
|
1398 { |
|
1399 bgcontext->SetRect(TRect(TPoint(0, 0), HuiUtil::ScreenSize())); |
|
1400 } |
|
1401 |
|
1402 // Draw the background onto the framebuffer |
|
1403 MAknsSkinInstance* skin = CHuiStatic::SkinInstance(); |
|
1404 TPoint tl = aRect.iTl; |
|
1405 TRect rect = aRect; |
|
1406 bgcontext->SetBitmap(KAknsIIDQsnBgScreen); |
|
1407 |
|
1408 AknsDrawUtils::DrawBackground(skin, bgcontext, NULL, |
|
1409 *bitGc, tl, rect, |
|
1410 KAknsDrawParamDefault); |
|
1411 } |
|
1412 |
|
1413 void CHuiDisplay::BitgdiClearWithBackgroundItems(TRect aRect) |
|
1414 { |
|
1415 CHuiS60Skin* s60skin = static_cast<CHuiS60Skin*>(&iEnv.Skin()); |
|
1416 CAknsBasicBackgroundControlContext* bgcontext = (CAknsBasicBackgroundControlContext*)s60skin->SkinControlContext(); |
|
1417 |
|
1418 CFbsBitGc* bitGc = iRenderSurface->BackBuffer()->Gc(); |
|
1419 THuiDisplayBackgroundItem item; |
|
1420 MAknsSkinInstance* skin = CHuiStatic::SkinInstance(); |
|
1421 |
|
1422 for (TInt index = 0; index < iBackgroundItems.Count(); index++) |
|
1423 { |
|
1424 TRect clearRect = aRect; |
|
1425 TRect skinRect = TRect(0,0,0,0); |
|
1426 TRect dummy = TRect(0,0,0,0); |
|
1427 |
|
1428 item = iBackgroundItems[index]; |
|
1429 switch (item.ClearMode()) |
|
1430 { |
|
1431 case EClearWithSkinBackground: |
|
1432 if (skin) |
|
1433 { |
|
1434 GetRectForItem(item.SkinBackground(), dummy, skinRect); |
|
1435 bgcontext->SetRect(skinRect); |
|
1436 bgcontext->SetBitmap(item.SkinBackground()); |
|
1437 skinRect.Intersection(aRect); |
|
1438 skinRect.Intersection(item.Rect()); |
|
1439 AknsDrawUtils::DrawBackground(skin, bgcontext, NULL, |
|
1440 *bitGc, skinRect.iTl, skinRect, |
|
1441 KAknsDrawParamDefault); |
|
1442 break; |
|
1443 } // else fall through |
|
1444 case EClearWithColor: |
|
1445 clearRect.Intersection(item.Rect()); |
|
1446 if (!clearRect.IsEmpty()) |
|
1447 { |
|
1448 bitGc->SetBrushColor(item.Color()); |
|
1449 bitGc->Clear(clearRect); |
|
1450 } |
|
1451 break; |
|
1452 case EClearNone: |
|
1453 default: |
|
1454 // do nothing... |
|
1455 break; |
|
1456 } |
|
1457 } |
|
1458 |
|
1459 } |
|
1460 |
|
1461 void CHuiDisplay::HWAcceleratedClearWithColor(TRect /*aRect*/) |
|
1462 { |
|
1463 iGc->SetPenColor(iBackgroundColor); |
|
1464 iGc->SetPenAlpha(iBackgroundColor.Alpha()); |
|
1465 iGc->Disable(CHuiGc::EFeatureBlending); |
|
1466 iGc->Enable(CHuiGc::EFeatureClipping); |
|
1467 iGc->Clear(); |
|
1468 } |
|
1469 |
|
1470 void CHuiDisplay::HWAcceleratedClearWithSkinBackground(TRect /*aRect*/) |
|
1471 { |
|
1472 // Acquire background texture |
|
1473 const CHuiTexture* backgroundTexture = NULL; |
|
1474 TInt err = iEnv.Skin().GetTexture(EHuiSkinBackgroundTexture, backgroundTexture); |
|
1475 ASSERT(backgroundTexture!=NULL); |
|
1476 __ASSERT_ALWAYS(err == KErrNone, USER_INVARIANT()); |
|
1477 |
|
1478 // Apply background texture |
|
1479 THuiImage background(*backgroundTexture); |
|
1480 |
|
1481 TPoint screenOrigin(0, 0); |
|
1482 iRenderSurface->GetScreenOrigin(screenOrigin); |
|
1483 // The origin is used to offset the background in the display's |
|
1484 // rendering surface, so that the background's origin is in the |
|
1485 // top left screen corner. |
|
1486 screenOrigin.iX = -screenOrigin.iX; |
|
1487 screenOrigin.iY = -screenOrigin.iY; |
|
1488 |
|
1489 iGc->SetPenColor(KRgbWhite); |
|
1490 iGc->SetPenAlpha(255); |
|
1491 iGc->SetAlign(EHuiAlignHLeft, EHuiAlignVTop); |
|
1492 iGc->Disable(CHuiGc::EFeatureBlending); |
|
1493 iGc->Enable(CHuiGc::EFeatureClipping); |
|
1494 iGc->DrawImage(background, screenOrigin, background.Texture().Size()); |
|
1495 } |
|
1496 |
|
1497 void CHuiDisplay::HWAcceleratedClearWithBackgroundItems(TRect aRect) |
|
1498 { |
|
1499 THuiDisplayBackgroundItem item; |
|
1500 CHuiS60Skin* s60skin = static_cast<CHuiS60Skin*>(&iEnv.Skin()); |
|
1501 CHuiTexture* backgroundTexture = NULL; |
|
1502 for (TInt index = 0; index < iBackgroundItems.Count(); index++) |
|
1503 { |
|
1504 item = iBackgroundItems[index]; |
|
1505 switch (item.ClearMode()) |
|
1506 { |
|
1507 case EClearNone: |
|
1508 // do nothing... |
|
1509 break; |
|
1510 case EClearWithColor: |
|
1511 // do not draw anything if background item rect does not intersect with dirty/ current clip rect |
|
1512 if( item.Rect().Intersects(aRect)) |
|
1513 { |
|
1514 iGc->SetPenColor(item.Color()); |
|
1515 iGc->SetPenAlpha(255); |
|
1516 iGc->SetAlign(EHuiAlignHLeft, EHuiAlignVTop); |
|
1517 iGc->Disable(CHuiGc::EFeatureBlending); |
|
1518 iGc->Enable(CHuiGc::EFeatureClipping); |
|
1519 iGc->PushClip(); |
|
1520 TRect temp = item.Rect(); |
|
1521 temp.Intersection(aRect); |
|
1522 iGc->Clip(temp); |
|
1523 iGc->Clear(); |
|
1524 iGc->PopClip(); |
|
1525 } |
|
1526 break; |
|
1527 case EClearWithSkinBackground: |
|
1528 TRect skinRect; |
|
1529 TRect dummy; |
|
1530 GetRectForItem(item.SkinBackground(), dummy, skinRect); |
|
1531 backgroundTexture = s60skin->BackgroundTexture(item.SkinBackground()); |
|
1532 if (backgroundTexture) |
|
1533 { |
|
1534 THuiImage background(*backgroundTexture); |
|
1535 |
|
1536 TPoint screenOrigin(0, 0); |
|
1537 iRenderSurface->GetScreenOrigin(screenOrigin); |
|
1538 screenOrigin.iX = -screenOrigin.iX; |
|
1539 screenOrigin.iY = -screenOrigin.iY; |
|
1540 screenOrigin+=skinRect.iTl; |
|
1541 |
|
1542 // do not draw anything if background item rects does not intersect with dirty/ current clip rect |
|
1543 skinRect.Intersection(item.Rect()); |
|
1544 if( skinRect.Intersects(aRect) ) |
|
1545 { |
|
1546 iGc->SetPenColor(KRgbWhite); |
|
1547 iGc->SetPenAlpha(255); |
|
1548 iGc->SetAlign(EHuiAlignHLeft, EHuiAlignVTop); |
|
1549 iGc->Disable(CHuiGc::EFeatureBlending); |
|
1550 iGc->Enable(CHuiGc::EFeatureClipping); |
|
1551 iGc->PushClip(); |
|
1552 skinRect.Intersection(aRect); |
|
1553 iGc->Clip(skinRect); |
|
1554 iGc->DrawImage(background, screenOrigin, background.Texture().Size()); |
|
1555 iGc->PopClip(); |
|
1556 } |
|
1557 } |
|
1558 break; |
|
1559 } |
|
1560 } |
|
1561 } |
|
1562 |
|
1563 EXPORT_C void CHuiDisplay::SetVisibleAreaClippingRect(const TRect& |
|
1564 #ifndef SYMBIAN_BUILD_GCE |
|
1565 aVisibleAreaClippingRect |
|
1566 #endif |
|
1567 ) |
|
1568 { |
|
1569 // Visible area clipping is disabled in NGA |
|
1570 #ifndef SYMBIAN_BUILD_GCE |
|
1571 iVisibleAreaClippingRect = aVisibleAreaClippingRect; |
|
1572 #endif |
|
1573 } |
|
1574 |
|
1575 TRect CHuiDisplay::VisibleAreaClippingRect() const |
|
1576 { |
|
1577 // Visible area clipping is disabled in NGA |
|
1578 #ifndef SYMBIAN_BUILD_GCE |
|
1579 if (IsVisibleAreaClippingEnabled()) |
|
1580 { |
|
1581 return iVisibleAreaClippingRect; |
|
1582 } |
|
1583 else |
|
1584 { |
|
1585 return VisibleArea(); |
|
1586 } |
|
1587 #else |
|
1588 return VisibleArea(); |
|
1589 #endif |
|
1590 } |
|
1591 |
|
1592 TBool CHuiDisplay::IsVisibleAreaClippingEnabled() const |
|
1593 { |
|
1594 // Visible area clipping is disabled in NGA |
|
1595 #ifndef SYMBIAN_BUILD_GCE |
|
1596 return iVisibleAreaClippingRect != TRect(0,0,0,0); |
|
1597 #else |
|
1598 return EFalse; |
|
1599 #endif |
|
1600 } |
|
1601 |
|
1602 void CHuiDisplay::ClipDirtyRect(TRect& aRect, TRect aClippingRect) |
|
1603 { |
|
1604 if (aRect.Intersects(aClippingRect)) |
|
1605 { |
|
1606 aRect.Intersection(aClippingRect); |
|
1607 } |
|
1608 } |
|
1609 |
|
1610 EXPORT_C void CHuiDisplay::SetForegroundTexture(CHuiTexture* aTexture) |
|
1611 { |
|
1612 if (iForegroundTexture != aTexture) |
|
1613 { |
|
1614 delete iForegroundTexture; |
|
1615 iForegroundTexture = aTexture; |
|
1616 SetDirty(); |
|
1617 } |
|
1618 } |
|
1619 |
|
1620 EXPORT_C CHuiTexture* CHuiDisplay::ForegroundTexture() const |
|
1621 { |
|
1622 return iForegroundTexture; |
|
1623 } |
|
1624 |
|
1625 |
|
1626 void CHuiDisplay::DrawForegroundTexture() |
|
1627 { |
|
1628 if (iForegroundTexture) |
|
1629 { |
|
1630 // The following is similar to HWAcceleratedClearWithSkinBackground, |
|
1631 // except blending is enabled. |
|
1632 |
|
1633 TPoint screenOrigin(0, 0); |
|
1634 iRenderSurface->GetScreenOrigin(screenOrigin); |
|
1635 screenOrigin.iX = -screenOrigin.iX; |
|
1636 screenOrigin.iY = -screenOrigin.iY; |
|
1637 |
|
1638 THuiImage image = THuiImage(*iForegroundTexture); |
|
1639 iGc->SetPenColor(KRgbWhite); |
|
1640 iGc->SetPenAlpha(255); |
|
1641 iGc->SetAlign(EHuiAlignHLeft, EHuiAlignVTop); |
|
1642 iGc->Enable(CHuiGc::EFeatureBlending); |
|
1643 iGc->Enable(CHuiGc::EFeatureClipping); |
|
1644 iGc->DrawImage(image, screenOrigin, image.Texture().Size()); |
|
1645 } |
|
1646 } |
|
1647 |
|
1648 EXPORT_C void CHuiDisplay::SetForegroundBitmapL(CFbsBitmap* aBitmap) |
|
1649 { |
|
1650 // Note this method may be called with same bitmap, e.g. |
|
1651 // when emulator display orientation is changed. Then we recreate |
|
1652 // device & context in order to avoid panics. |
|
1653 |
|
1654 if ( !aBitmap ) |
|
1655 { |
|
1656 delete iForegroundBitmapGc; |
|
1657 iForegroundBitmapGc = NULL; |
|
1658 delete iForegroundBitmapDevice; |
|
1659 iForegroundBitmapDevice = NULL; |
|
1660 iForegroundBitmap = NULL; |
|
1661 } |
|
1662 else |
|
1663 { |
|
1664 CFbsBitmapDevice* device = CFbsBitmapDevice::NewL( aBitmap ); |
|
1665 CleanupStack::PushL( device ); |
|
1666 |
|
1667 CFbsBitGc* gc = NULL; |
|
1668 User::LeaveIfError( device->CreateContext( gc ) ); |
|
1669 User::LeaveIfNull( gc ); |
|
1670 |
|
1671 CleanupStack::Pop( device ); |
|
1672 |
|
1673 iForegroundBitmap = aBitmap; |
|
1674 delete iForegroundBitmapDevice; |
|
1675 iForegroundBitmapDevice = device; |
|
1676 delete iForegroundBitmapGc; |
|
1677 iForegroundBitmapGc = gc; |
|
1678 } |
|
1679 } |
|
1680 |
|
1681 EXPORT_C CFbsBitmap* CHuiDisplay::ForegroundBitmap() const |
|
1682 { |
|
1683 return iForegroundBitmap; |
|
1684 } |
|
1685 |