Update contrib.
1 // Copyright (c) 2002-2010 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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include "mediaclientvideodisplaybody.h"
17 #include "mediaclientvideotrace.h"
18 #include "mediaclientpolicyserverclient.h"
19 #include <surfaceeventhandler.h>
20 #include <mmf/plugin/mmfmediaclientextdisplayinterface.hrh>
22 #include <ecom/ecom.h>
23 #include <centralrepository.h>
25 const TUid KCRUidTvoutSettings = {0x1020730B};
26 const TUint32 KSettingsTvAspectRatio = 0x00000001;
28 #ifdef MEDIA_CLIENT_SURFACE_NOT_REMOVED_FROM_CLIENT_WINDOW
29 // make sure that off screen is bottom right and not top left. This makes it more efficient for GCE backend
31 const TInt KHiddenExtentA = 2000; // rect Ax and Ay co-ordinate used to set extent off screen
32 const TInt KHiddenExtentB = 2001; // rect Bx and By co-ordinate used to set extent off screen
35 CMediaClientVideoDisplayBody* CMediaClientVideoDisplayBody::NewL(TInt aDisplayId, TBool aExtDisplaySwitchingControl)
37 DEBUG_PRINTF("CMediaClientVideoDisplayBody::NewL +++");
38 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::NewL - aDisplayId %d", aDisplayId);
39 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::NewL - aExtDisplaySwitchingControl %d", aExtDisplaySwitchingControl);
41 CMediaClientVideoDisplayBody* self = new (ELeave) CMediaClientVideoDisplayBody(aDisplayId);
42 CleanupStack::PushL(self);
43 self->ConstructL(aExtDisplaySwitchingControl);
44 CleanupStack::Pop(self);
45 DEBUG_PRINTF("CMediaClientVideoDisplayBody::NewL ---");
49 CMediaClientVideoDisplayBody* CMediaClientVideoDisplayBody::NewL(TInt aDisplayId, const TSurfaceId& aSurfaceId,
50 const TRect& aCropRect, TVideoAspectRatio aAspectRatio, TBool aExtDisplaySwitchingControl)
52 DEBUG_PRINTF("CMediaClientVideoDisplayBody::NewL +++");
53 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::NewL - aDisplayId %d", aDisplayId);
54 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::NewL - aSurfaceId %08x:%08x:%08x:%08x", aSurfaceId.iInternal[3], aSurfaceId.iInternal[2], aSurfaceId.iInternal[1], aSurfaceId.iInternal[0]);
55 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::NewL - aCropRect %d,%d - %d,%d", aCropRect.iTl.iX, aCropRect.iTl.iY, aCropRect.iBr.iX, aCropRect.iBr.iY);
56 DEBUG_PRINTF3("CMediaClientVideoDisplayBody::NewL - aAspectRatio %d/%d", aAspectRatio.iNumerator, aAspectRatio.iDenominator);
57 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::NewL - aExtDisplaySwitchingControl %d", aExtDisplaySwitchingControl);
59 if(aSurfaceId.IsNull())
61 User::Leave(KErrArgument);
63 CMediaClientVideoDisplayBody* self = new(ELeave) CMediaClientVideoDisplayBody(aDisplayId, aSurfaceId, aCropRect, aAspectRatio);
64 CleanupStack::PushL(self);
65 self->ConstructL(aExtDisplaySwitchingControl);
67 DEBUG_PRINTF("CMediaClientVideoDisplayBody::NewL ---");
71 void CMediaClientVideoDisplayBody::ConstructL(TBool aExtDisplaySwitchingControl)
73 DEBUG_PRINTF("CMediaClientVideoDisplayBody::ConstructL +++");
75 SetWindowArrayPtr2Client();
77 // External display switching and wserv events are only possible if there is
78 // an active scheduler in client thread
79 if(CActiveScheduler::Current())
81 CreateExtDisplayPluginL();
82 iWsEventObserver = CMediaClientWsEventObserver::NewL(*this);
84 iServerClient = CMediaClientPolicyServerClient::NewL();
85 if(iServerClient->Connect() != KErrNone)
91 if(IsSurfaceCreated() && iServerClient)
93 iServerClient->SetSurface(iSurfaceId);
96 // Try and enable display switching by default. If this leaves then do so quietly.
97 // Either the client has no scheduler installed or the device does not support external
98 // switching (i.e. no plugin was found)
99 TRAPD(err, SetExternalDisplaySwitchingL(aExtDisplaySwitchingControl));
100 err = err; // remove compile warning
101 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::ConstructL SetExternalDisplaySwitchingL returned with %d", err);
105 DEBUG_PRINTF("CMediaClientVideoDisplayBody::ConstructL No CActiveScheduler - ext display and focus features disabled ");
107 DEBUG_PRINTF("CMediaClientVideoDisplayBody::ConstructL ---");
110 CMediaClientVideoDisplayBody::CMediaClientVideoDisplayBody(TInt aDisplayId, const TSurfaceId& aSurfaceId,
111 const TRect& aCropRect, TVideoAspectRatio aAspectRatio) :
112 iDisplayId(aDisplayId),
113 iSurfaceId(aSurfaceId),
114 iCropRect(aCropRect),
115 iAspectRatio(aAspectRatio)
117 DEBUG_PRINTF("CMediaClientVideoDisplayBody::CMediaClientVideoDisplayBody +++");
118 DEBUG_PRINTF("CMediaClientVideoDisplayBody::CMediaClientVideoDisplayBody ---");
121 CMediaClientVideoDisplayBody::CMediaClientVideoDisplayBody(TInt aDisplayId) :
122 iDisplayId(aDisplayId)
124 DEBUG_PRINTF("CMediaClientVideoDisplayBody::CMediaClientVideoDisplayBody +++");
125 DEBUG_PRINTF("CMediaClientVideoDisplayBody::CMediaClientVideoDisplayBody ---");
128 CMediaClientVideoDisplayBody::~CMediaClientVideoDisplayBody()
130 DEBUG_PRINTF("CMediaClientVideoDisplayBody::~CMediaClientVideoDisplayBody +++");
132 // remove for whichever array is current
133 RemoveBackgroundSurface(ETrue);
135 #ifdef MEDIA_CLIENT_SURFACE_NOT_REMOVED_FROM_CLIENT_WINDOW
136 if(iSwitchedToExternalDisplay)
138 SetWindowArrayPtr2Client();
139 RemoveBackgroundSurface(ETrue);
143 iClientWindows.Close();
144 iExtDisplayWindows.Close();
146 delete iExtDisplayHandler;
147 RemoveExtDisplayPlugin();
148 REComSession::FinalClose();
150 delete iWsEventObserver;
152 delete iServerClient;
154 DEBUG_PRINTF("CMediaClientVideoDisplayBody::~CMediaClientVideoDisplayBody ---");
157 void CMediaClientVideoDisplayBody::AddDisplayL(MMMFSurfaceEventHandler& aEventHandler)
159 DEBUG_PRINTF("CMediaClientVideoDisplayBody::AddDisplayL +++");
162 User::Leave(KErrInUse);
165 iEventHandler = &aEventHandler;
167 if (IsSurfaceCreated())
169 iEventHandler->MmsehSurfaceCreated(iDisplayId, iSurfaceId, iCropRect, iAspectRatio);
171 DEBUG_PRINTF("CMediaClientVideoDisplayBody::AddDisplayL ---");
174 void CMediaClientVideoDisplayBody::AddDisplayWindowL(const RWindowBase* aWindow, const TRect& aClipRect, const TRect& aCropRegion, const TRect& aVideoExtent,
175 TReal32 aScaleWidth, TReal32 aScaleHeight, TVideoRotation aRotation,
176 TAutoScaleType aAutoScaleType, TInt aHorizPos, TInt aVertPos, RWindow* aWindow2)
178 DEBUG_PRINTF("CMediaClientVideoDisplayBody::AddDisplayWindowL +++");
179 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::AddDisplayWindowL - aWindow WsHandle 0x%X", aWindow->WsHandle());
180 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::AddDisplayWindowL - aClipRect %d,%d - %d,%d", aClipRect.iTl.iX, aClipRect.iTl.iY, aClipRect.iBr.iX, aClipRect.iBr.iY);
181 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::AddDisplayWindowL - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
182 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::AddDisplayWindowL - aVideoExtent %d,%d - %d,%d", aVideoExtent.iTl.iX, aVideoExtent.iTl.iY, aVideoExtent.iBr.iX, aVideoExtent.iBr.iY);
183 DEBUG_PRINTF3("CMediaClientVideoDisplayBody::AddDisplayWindowL - aScaleWidth %f, aScaleHeight %f", aScaleWidth, aScaleHeight);
184 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::AddDisplayWindowL - aRotation %d", aRotation);
185 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::AddDisplayWindowL - aAutoScaleType %d", aAutoScaleType);
186 DEBUG_PRINTF3("CMediaClientVideoDisplayBody::AddDisplayWindowL - aHorizPos %d, aVertPos %d", aHorizPos, aVertPos);
188 if (!IsRotationValid(aRotation))
190 User::Leave(KErrArgument);
193 if (!IsAutoScaleTypeValid(aAutoScaleType))
195 User::Leave(KErrArgument);
198 TInt pos = iClientWindows.Find(aWindow->WsHandle(), TWindowData::CompareByWsHandle);
200 if (pos != KErrNotFound)
202 User::Leave(KErrInUse);
205 TWindowData winData(aWindow, aClipRect, aVideoExtent, aScaleWidth, aScaleHeight, aRotation, aAutoScaleType, aHorizPos, aVertPos, aWindow2);
206 iClientWindows.AppendL(winData);
208 iCropRegion = aCropRegion;
210 TBool prevClientWindowIsInFocus = iClientWindowIsInFocus;
213 if (IsSurfaceCreated())
215 // if first window was just added OR the new window has moved us from out of focus to in focus
216 if(((iClientWindows.Count() == 1) || !prevClientWindowIsInFocus) && iClientRequestedExtDisplaySwitching &&
217 iClientWindowIsInFocus && iExtDisplayConnected)
219 TRAPD(err, CreateExtDisplayHandlerL());
220 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::AddDisplayWindowL CreateExtDisplayHandlerL error %d", err);
223 #ifdef MEDIA_CLIENT_SURFACE_NOT_REMOVED_FROM_CLIENT_WINDOW
224 // attach surface to client window and hide
225 // ignore error - no handling required
226 SetHiddenBackgroundSurfaceOnClientWindow(winData);
228 // handle external display
229 SetWindowArrayPtr2Ext();
230 User::LeaveIfError(RedrawWindows(aCropRegion));
234 if(!iSwitchedToExternalDisplay)
236 User::LeaveIfError(SetBackgroundSurface(winData, aCropRegion));
239 DEBUG_PRINTF("CMediaClientVideoDisplayBody::AddDisplayWindowL ---");
242 void CMediaClientVideoDisplayBody::UpdateDisplayWindowL(const RWindowBase* aWindow, const TRect& aClipRect, const TRect& aCropRegion, const TRect& aVideoExtent,
243 TReal32 aScaleWidth, TReal32 aScaleHeight, TVideoRotation aRotation,
244 TAutoScaleType aAutoScaleType, TInt aHorizPos, TInt aVertPos, RWindow* aWindow2)
246 DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateDisplayWindowL +++");
247 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::UpdateDisplayWindowL - aWindow WsHandle 0x%X", aWindow->WsHandle());
248 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::UpdateDisplayWindowL - aClipRect %d,%d - %d,%d", aClipRect.iTl.iX, aClipRect.iTl.iY, aClipRect.iBr.iX, aClipRect.iBr.iY);
249 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::UpdateDisplayWindowL - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
250 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::UpdateDisplayWindowL - aVideoExtent %d,%d - %d,%d", aVideoExtent.iTl.iX, aVideoExtent.iTl.iY, aVideoExtent.iBr.iX, aVideoExtent.iBr.iY);
251 DEBUG_PRINTF3("CMediaClientVideoDisplayBody::UpdateDisplayWindowL - aScaleWidth %f, aScaleHeight %f", aScaleWidth, aScaleHeight);
252 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::UpdateDisplayWindowL - aRotation %d", aRotation);
253 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::UpdateDisplayWindowL - aAutoScaleType %d", aAutoScaleType);
254 DEBUG_PRINTF3("CMediaClientVideoDisplayBody::UpdateDisplayWindowL - aHorizPos %d, aVertPos %d", aHorizPos, aVertPos);
256 if (!IsRotationValid(aRotation))
258 User::Leave(KErrArgument);
261 if (!IsAutoScaleTypeValid(aAutoScaleType))
263 User::Leave(KErrArgument);
266 TInt pos = iClientWindows.Find(aWindow->WsHandle(), TWindowData::CompareByWsHandle);
267 User::LeaveIfError(pos);
268 iClientWindows.Remove(pos);
270 TWindowData winData(aWindow, aClipRect, aVideoExtent, aScaleWidth, aScaleHeight, aRotation, aAutoScaleType, aHorizPos, aVertPos, aWindow2);
271 iClientWindows.AppendL(winData);
273 TRect prevCropRegion = iCropRegion;
274 iCropRegion = aCropRegion;
276 if (IsSurfaceCreated())
278 if(ClientCropRegionChangeRequiresRedraw(prevCropRegion, aCropRegion, iCropRect))
280 // all windows need to be redrawn
281 User::LeaveIfError(RedrawWindows(aCropRegion));
285 // only redraw affected window as other window data may have changed
286 if(!iSwitchedToExternalDisplay)
288 User::LeaveIfError(SetBackgroundSurface(winData, aCropRegion));
293 DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateDisplayWindowL ---");
296 void CMediaClientVideoDisplayBody::RemoveDisplay()
298 DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveDisplay +++");
299 iEventHandler = NULL;
300 DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveDisplay ---");
303 TInt CMediaClientVideoDisplayBody::RemoveDisplayWindow(const RWindowBase& aWindow)
305 DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveDisplayWindow +++");
306 TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
310 #ifdef MEDIA_CLIENT_SURFACE_NOT_REMOVED_FROM_CLIENT_WINDOW
311 if(IsSurfaceCreated())
313 if(IsSurfaceCreated() && !iSwitchedToExternalDisplay)
316 iClientWindows[pos].iWindow->RemoveBackgroundSurface(ETrue);
317 // Make sure all window rendering has completed before proceeding
318 RWsSession* ws = iClientWindows[pos].iWindow->Session();
325 iClientWindows.Remove(pos);
327 TBool prevClientWindowIsInFocus = iClientWindowIsInFocus;
330 // if only window was just removed OR removal has moved us from in focus to out of focus
331 if((iClientWindows.Count() == 0 || prevClientWindowIsInFocus) && iSwitchedToExternalDisplay &&
332 !iClientWindowIsInFocus)
334 RemoveBackgroundSurface(ETrue);
335 SetWindowArrayPtr2Client();
336 RemoveExtDisplayHandler();
337 RedrawWindows(iCropRegion);
341 DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveDisplayWindow ---");
346 TInt CMediaClientVideoDisplayBody::SurfaceCreated(const TSurfaceId& aSurfaceId, const TRect& aCropRect, TVideoAspectRatio aAspectRatio, const TRect& aCropRegion)
348 DEBUG_PRINTF("CMediaClientVideoDisplayBody::SurfaceCreated +++");
349 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SurfaceCreated - aSurfaceId %08x:%08x:%08x:%08x", aSurfaceId.iInternal[3], aSurfaceId.iInternal[2], aSurfaceId.iInternal[1], aSurfaceId.iInternal[0]);
350 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SurfaceCreated - aCropRect %d,%d - %d,%d", aCropRect.iTl.iX, aCropRect.iTl.iY, aCropRect.iBr.iX, aCropRect.iBr.iY);
351 DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SurfaceCreated - aAspectRatio %d/%d", aAspectRatio.iNumerator, aAspectRatio.iDenominator);
352 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SurfaceCreated - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
354 TBool emitEvent = EFalse;
355 if((iSurfaceId != aSurfaceId) && (!aSurfaceId.IsNull()))
360 iSurfaceId = aSurfaceId;
361 iCropRect = aCropRect;
362 iAspectRatio = aAspectRatio;
363 iCropRegion = aCropRegion;
367 iServerClient->SetSurface(iSurfaceId);
370 if (emitEvent && iEventHandler)
372 iEventHandler->MmsehSurfaceCreated(iDisplayId, iSurfaceId, iCropRect, iAspectRatio);
376 if((iClientWindows.Count() > 0) && iClientRequestedExtDisplaySwitching && iClientWindowIsInFocus)
378 if(iExtDisplayConnected && !iExtDisplayHandler)
380 TRAP(err, CreateExtDisplayHandlerL());
381 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SurfaceCreated CreateExtDisplayHandlerL error %d", err);
384 #ifdef MEDIA_CLIENT_SURFACE_NOT_REMOVED_FROM_CLIENT_WINDOW
385 SetHiddenBackgroundSurfaceOnAllClientWindows();
387 SetWindowArrayPtr2Ext();
392 err = RedrawWindows(aCropRegion);
394 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SurfaceCreated --- Return error %d", err);
398 void CMediaClientVideoDisplayBody::RemoveBackgroundSurface(TBool aTriggerRedraw)
400 DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveBackgroundSurface +++");
401 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::RemoveBackgroundSurface - iSurfaceId %08x:%08x:%08x:%08x", iSurfaceId.iInternal[3], iSurfaceId.iInternal[2], iSurfaceId.iInternal[1], iSurfaceId.iInternal[0]);
403 if (IsSurfaceCreated())
405 RWsSession* ws = NULL;
406 TInt count = iWindowsArrayPtr->Count();
408 for (TInt i = 0; i < count; ++i)
410 (*iWindowsArrayPtr)[i].iWindow->RemoveBackgroundSurface(aTriggerRedraw);
411 // Make sure all window rendering has completed before proceeding
412 ws = (*iWindowsArrayPtr)[i].iWindow->Session();
419 DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveBackgroundSurface ---");
422 void CMediaClientVideoDisplayBody::RemoveSurface(TBool aControllerEvent)
424 DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveSurface +++");
425 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::RemoveSurface - iSurfaceId %08x:%08x:%08x:%08x", iSurfaceId.iInternal[3], iSurfaceId.iInternal[2], iSurfaceId.iInternal[1], iSurfaceId.iInternal[0]);
427 if (IsSurfaceCreated())
429 RemoveBackgroundSurface(ETrue);
431 if (iEventHandler && aControllerEvent)
433 iEventHandler->MmsehRemoveSurface(iSurfaceId);
436 if(iSwitchedToExternalDisplay)
438 SetWindowArrayPtr2Client();
439 #ifdef MEDIA_CLIENT_SURFACE_NOT_REMOVED_FROM_CLIENT_WINDOW
440 RemoveBackgroundSurface(ETrue);
442 RemoveExtDisplayHandler();
444 iSurfaceId = TSurfaceId::CreateNullId();
447 DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveSurface ---");
450 TInt CMediaClientVideoDisplayBody::SurfaceParametersChanged(const TSurfaceId& aSurfaceId, const TRect& aCropRect, TVideoAspectRatio aAspectRatio)
452 DEBUG_PRINTF("CMediaClientVideoDisplayBody::SurfaceParametersChanged +++");
453 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SurfaceCreated - aSurfaceId %08x:%08x:%08x:%08x", aSurfaceId.iInternal[3], aSurfaceId.iInternal[2], aSurfaceId.iInternal[1], aSurfaceId.iInternal[0]);
454 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SurfaceCreated - aCropRect %d,%d - %d,%d", aCropRect.iTl.iX, aCropRect.iTl.iY, aCropRect.iBr.iX, aCropRect.iBr.iY);
455 DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SurfaceCreated - aAspectRatio %d/%d", aAspectRatio.iNumerator, aAspectRatio.iDenominator);
457 if (!IsSurfaceCreated())
459 DEBUG_PRINTF("CMediaClientVideoDisplayBody::SurfaceParametersChanged --- Return error KErrNotSupproted");
460 return KErrNotSupported;
463 if (iSurfaceId != aSurfaceId)
465 DEBUG_PRINTF("CMediaClientVideoDisplayBody::SurfaceParametersChanged --- Return error KErrInUse");
471 iEventHandler->MmsehSurfaceParametersChanged(iSurfaceId, aCropRect, aAspectRatio);
474 TInt error = KErrNone;
475 if (iCropRect != aCropRect || iAspectRatio != aAspectRatio)
477 // We only need to redraw if the aspect ratio has changed, or the area of the video to
478 // display (i.e the intersection of client crop region and surface crop rectangle) has changed.
479 TBool redraw = EFalse;
480 if (iAspectRatio != aAspectRatio || SurfaceCropRectChangeRequiresRedraw(iCropRect, aCropRect, iCropRegion))
485 iCropRect = aCropRect;
486 iAspectRatio = aAspectRatio;
490 error = RedrawWindows(iCropRegion);
495 DEBUG_PRINTF("CMediaClientVideoDisplayBody::SurfaceParametersChanged - Surface parameters have not changed");
498 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SurfaceParametersChanged --- Return error %d", error);
502 TInt CMediaClientVideoDisplayBody::RedrawWindows(const TRect& aCropRegion)
504 DEBUG_PRINTF("CMediaClientVideoDisplayBody::RedrawWindows +++");
507 iCropRegion = aCropRegion;
509 if(IsSurfaceCreated())
511 TInt count = iWindowsArrayPtr->Count();
513 for (TInt i = 0; i < count; ++i)
515 err = SetBackgroundSurface((*iWindowsArrayPtr)[i], aCropRegion);
524 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::RedrawWindows --- return with %d", err);
528 void CMediaClientVideoDisplayBody::UpdateCropRegionL(const TRect& aCropRegion, TInt aPos, TBool aRedrawIndividualWindow)
530 DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateCropRegionL +++");
532 TRect prevCropRegion(iCropRegion);
533 iCropRegion = aCropRegion;
535 if (IsSurfaceCreated())
537 if(prevCropRegion == aCropRegion)
539 if(!iSwitchedToExternalDisplay && aRedrawIndividualWindow)
541 User::LeaveIfError(SetBackgroundSurface(iClientWindows[aPos], aCropRegion));
546 // We only need to redraw if the area of the video to display (i.e the
547 // intersection of client crop region and surface crop rectangle) has changed.
548 if (ClientCropRegionChangeRequiresRedraw(prevCropRegion, aCropRegion, iCropRect))
550 User::LeaveIfError(RedrawWindows(aCropRegion));
554 DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateCropRegionL ---");
557 void CMediaClientVideoDisplayBody::SetAutoScaleL(const RWindowBase& aWindow, TAutoScaleType aScaleType, TInt aHorizPos, TInt aVertPos, const TRect& aCropRegion)
559 DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetAutoScaleL +++");
560 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetAutoScaleL - aWindow WsHandle 0x%X", aWindow.WsHandle());
561 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetAutoScaleL - aScaleType %d", aScaleType);
562 DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SetAutoScaleL - aHorizPos %d, aVertPos %d", aHorizPos, aVertPos);
563 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetAutoScaleL - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
565 if (!IsAutoScaleTypeValid(aScaleType))
567 User::Leave(KErrArgument);
570 TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
571 User::LeaveIfError(pos);
573 TBool parameterChanged = EFalse;
574 if (aScaleType != iClientWindows[pos].iAutoScaleType || aHorizPos != iClientWindows[pos].iHorizPos || aVertPos != iClientWindows[pos].iVertPos)
576 iClientWindows[pos].iAutoScaleType = aScaleType;
577 iClientWindows[pos].iHorizPos = aHorizPos;
578 iClientWindows[pos].iVertPos = aVertPos;
579 parameterChanged = ETrue;
583 DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetAutoScaleL - Scale parameters have not changed");
586 UpdateCropRegionL(aCropRegion, pos, parameterChanged);
588 DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetAutoScaleL ---");
592 void CMediaClientVideoDisplayBody::SetRotationL(const RWindowBase& aWindow, TVideoRotation aRotation, const TRect& aCropRegion)
594 DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetRotationL +++");
595 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetRotationL - aWindow WsHandle 0x%X", aWindow.WsHandle());
596 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetRotationL - aRotation %d", aRotation);
597 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetRotationL - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
599 if (!IsRotationValid(aRotation))
601 User::Leave(KErrArgument);
604 TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
605 User::LeaveIfError(pos);
607 TBool parameterChanged = EFalse;
608 if (aRotation != iClientWindows[pos].iRotation)
610 iClientWindows[pos].iRotation = aRotation;
611 parameterChanged = ETrue;
615 DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetRotationL - Rotation has not changed");
618 UpdateCropRegionL(aCropRegion, pos, parameterChanged);
620 DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetRotationL ---");
623 TVideoRotation CMediaClientVideoDisplayBody::RotationL(const RWindowBase& aWindow)
625 DEBUG_PRINTF("CMediaClientVideoDisplayBody::RotationL +++");
626 TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
627 User::LeaveIfError(pos);
629 DEBUG_PRINTF("CMediaClientVideoDisplayBody::RotationL ---");
630 return iClientWindows[pos].iRotation;
633 void CMediaClientVideoDisplayBody::SetScaleFactorL(const RWindowBase& aWindow, TReal32 aWidthPercentage, TReal32 aHeightPercentage, const TRect& aCropRegion)
635 DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetScaleFactorL +++");
636 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetScaleFactorL - aWindow WsHandle 0x%X", aWindow.WsHandle());
637 DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SetScaleFactorL - aWidthPercentage %f, aHeightPercentage %f", aWidthPercentage, aHeightPercentage);
638 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetScaleFactorL - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
640 TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
641 User::LeaveIfError(pos);
643 if (aWidthPercentage <= 0.0 || aHeightPercentage <= 0.0)
645 User::Leave(KErrArgument);
648 TBool parameterChanged = EFalse;
649 if (aWidthPercentage != iClientWindows[pos].iScaleWidth ||
650 aHeightPercentage != iClientWindows[pos].iScaleHeight ||
651 EAutoScaleNone != iClientWindows[pos].iAutoScaleType)
653 iClientWindows[pos].iScaleWidth = aWidthPercentage;
654 iClientWindows[pos].iScaleHeight = aHeightPercentage;
655 iClientWindows[pos].iAutoScaleType = EAutoScaleNone;
656 parameterChanged = ETrue;
660 DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetScaleFactorL - Scale parameters have not changed");
663 UpdateCropRegionL(aCropRegion, pos, parameterChanged);
665 DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetScaleFactorL ---");
668 void CMediaClientVideoDisplayBody::GetScaleFactorL(const RWindowBase& aWindow, TReal32& aWidthPercentage, TReal32& aHeightPercentage)
670 DEBUG_PRINTF("CMediaClientVideoDisplayBody::GetScaleFactorL +++");
671 TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
672 User::LeaveIfError(pos);
674 aWidthPercentage = iClientWindows[pos].iScaleWidth;
675 aHeightPercentage = iClientWindows[pos].iScaleHeight;
676 DEBUG_PRINTF("CMediaClientVideoDisplayBody::GetScaleFactorL ---");
679 void CMediaClientVideoDisplayBody::SetAutoScaleL(TAutoScaleType aScaleType, TInt aHorizPos, TInt aVertPos, const TRect& aCropRegion)
681 DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetAutoScaleL +++");
682 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetAutoScaleL - aScaleType %d", aScaleType);
683 DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SetAutoScaleL - aHorizPos %d, aVertPos %d", aHorizPos, aVertPos);
684 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetAutoScaleL - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
686 if (!IsAutoScaleTypeValid(aScaleType))
688 User::Leave(KErrArgument);
691 TRect prevCropRegion(iCropRegion);
692 iCropRegion = aCropRegion;
694 TBool parameterChanged;
695 TInt count = iClientWindows.Count();
697 for (TInt i = 0; i < count; ++i)
699 parameterChanged = EFalse;
700 if (aScaleType != iClientWindows[i].iAutoScaleType || aHorizPos != iClientWindows[i].iHorizPos || aVertPos != iClientWindows[i].iVertPos)
702 iClientWindows[i].iAutoScaleType = aScaleType;
703 iClientWindows[i].iHorizPos = aHorizPos;
704 iClientWindows[i].iVertPos = aVertPos;
705 parameterChanged = ETrue;
709 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetAutoScaleL - Scale parameters for window pos %d have not changed", i);
712 // We only need to redraw if the scale parameters have changed, or the area of the video
713 // to display (i.e the intersection of client crop region and surface crop rectangle) has changed.
714 if (IsSurfaceCreated() && !iSwitchedToExternalDisplay && (parameterChanged || ClientCropRegionChangeRequiresRedraw(prevCropRegion, aCropRegion, iCropRect)))
716 User::LeaveIfError(SetBackgroundSurface(iClientWindows[i], aCropRegion));
720 // We only need to redraw if the area of the video to display (i.e the
721 // intersection of client crop region and surface crop rectangle) has changed.
722 if (IsSurfaceCreated() && iSwitchedToExternalDisplay && ClientCropRegionChangeRequiresRedraw(prevCropRegion, aCropRegion, iCropRect))
724 User::LeaveIfError(RedrawWindows(aCropRegion));
726 DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetAutoScaleL ---");
730 void CMediaClientVideoDisplayBody::SetRotationL(TVideoRotation aRotation, const TRect& aCropRegion)
732 DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetRotationL +++");
733 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetRotationL - aRotation %d", aRotation);
734 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetRotationL - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
736 if (!IsRotationValid(aRotation))
738 User::Leave(KErrArgument);
741 TRect prevCropRegion(iCropRegion);
742 iCropRegion = aCropRegion;
744 TBool parameterChanged;
745 TInt count = iClientWindows.Count();
747 for (TInt i = 0; i < count; ++i)
749 parameterChanged = EFalse;
750 if (aRotation != iClientWindows[i].iRotation)
752 iClientWindows[i].iRotation = aRotation;
753 parameterChanged = ETrue;
757 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetRotationL - Rotation for window pos %d has not changed", i);
760 // We only need to redraw if the scale parameters have changed, or the area of the video
761 // to display (i.e the intersection of client crop region and surface crop rectangle) has changed.
762 if (IsSurfaceCreated() && !iSwitchedToExternalDisplay && (parameterChanged || ClientCropRegionChangeRequiresRedraw(prevCropRegion, aCropRegion, iCropRect)))
764 User::LeaveIfError(SetBackgroundSurface(iClientWindows[i], aCropRegion));
768 // We only need to redraw if the area of the video to display (i.e the
769 // intersection of client crop region and surface crop rectangle) has changed.
770 if (IsSurfaceCreated() && iSwitchedToExternalDisplay && ClientCropRegionChangeRequiresRedraw(prevCropRegion, aCropRegion, iCropRect))
772 User::LeaveIfError(RedrawWindows(aCropRegion));
775 DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetRotationL ---");
778 void CMediaClientVideoDisplayBody::SetScaleFactorL(TReal32 aWidthPercentage, TReal32 aHeightPercentage, const TRect& aCropRegion)
780 DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetScaleFactorL +++");
781 DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SetScaleFactorL - aWidthPercentage %f, aHeightPercentage %f", aWidthPercentage, aHeightPercentage);
782 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetScaleFactorL - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
784 if (aWidthPercentage <= 0.0 || aHeightPercentage <= 0.0)
786 User::Leave(KErrArgument);
789 TRect prevCropRegion(iCropRegion);
790 iCropRegion = aCropRegion;
792 TBool parameterChanged;
793 TInt count = iClientWindows.Count();
795 for (TInt i = 0; i < count; ++i)
797 parameterChanged = EFalse;
799 if (aWidthPercentage != iClientWindows[i].iScaleWidth ||
800 aHeightPercentage != iClientWindows[i].iScaleHeight ||
801 EAutoScaleNone != iClientWindows[i].iAutoScaleType)
803 iClientWindows[i].iScaleWidth = aWidthPercentage;
804 iClientWindows[i].iScaleHeight = aHeightPercentage;
805 iClientWindows[i].iAutoScaleType = EAutoScaleNone;
806 parameterChanged = ETrue;
810 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetScaleFactorL - Scale parameters for window pos %d have not changed", i);
813 // We only need to redraw if the scale parameters have changed, or the area of the video to
814 // display (i.e the intersection of client crop region and surface crop rectangle) has changed.
815 if (IsSurfaceCreated() && !iSwitchedToExternalDisplay && (parameterChanged || ClientCropRegionChangeRequiresRedraw(prevCropRegion, aCropRegion, iCropRect)))
817 User::LeaveIfError(SetBackgroundSurface(iClientWindows[i], aCropRegion));
821 // We only need to redraw if the area of the video to display (i.e the
822 // intersection of client crop region and surface crop rectangle) has changed.
823 if (IsSurfaceCreated() && iSwitchedToExternalDisplay && ClientCropRegionChangeRequiresRedraw(prevCropRegion, aCropRegion, iCropRect))
825 User::LeaveIfError(RedrawWindows(aCropRegion));
828 DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetScaleFactorL ---");
831 void CMediaClientVideoDisplayBody::SetWindowClipRectL(const RWindowBase& aWindow, const TRect& aWindowClipRect, const TRect& aCropRegion)
833 DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetWindowClipRectL +++");
834 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetWindowClipRectL - aWindow WsHandle 0x%X", aWindow.WsHandle());
835 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetWindowClipRectL - aWindowClipRect %d,%d - %d,%d", aWindowClipRect.iTl.iX, aWindowClipRect.iTl.iY, aWindowClipRect.iBr.iX, aWindowClipRect.iBr.iY);
836 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetWindowClipRectL - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
838 TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
839 User::LeaveIfError(pos);
841 TBool parameterChanged = EFalse;
842 if (aWindowClipRect != iClientWindows[pos].iClipRect)
844 // We only want to redraw if the change in the clipping rectangle would result
845 // in a change to the area of the display used for the video.
846 // The video is always displayed in the intersection of the clipping rectangle
847 // and the video extent, so check if this has changed.
848 parameterChanged = IntersectionAreaChanged(iClientWindows[pos].iClipRect, aWindowClipRect, iClientWindows[pos].iVideoExtent);
850 iClientWindows[pos].iClipRect = aWindowClipRect;
854 DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetWindowClipRectL - Clip rect parameter has not changed");
857 UpdateCropRegionL(aCropRegion, pos, parameterChanged);
859 DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetWindowClipRectL ---");
862 void CMediaClientVideoDisplayBody::SetVideoExtentL(const RWindowBase& aWindow, const TRect& aVideoExtent, const TRect& aCropRegion)
864 DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetVideoExtentL +++");
865 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetVideoExtentL - aWindow WsHandle 0x%X", aWindow.WsHandle());
866 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetVideoExtentL - aVideoExtent %d,%d - %d,%d", aVideoExtent.iTl.iX, aVideoExtent.iTl.iY, aVideoExtent.iBr.iX, aVideoExtent.iBr.iY);
867 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetVideoExtentL - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
869 TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
870 User::LeaveIfError(pos);
872 TBool parameterChanged = EFalse;
873 if (aVideoExtent != iClientWindows[pos].iVideoExtent)
875 iClientWindows[pos].iVideoExtent = aVideoExtent;
876 parameterChanged = ETrue;
880 DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetVideoExtentL - Video extent parameter has not changed");
883 UpdateCropRegionL(aCropRegion, pos, parameterChanged);
885 DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetVideoExtentL ---");
888 TBool CMediaClientVideoDisplayBody::HasWindows() const
890 DEBUG_PRINTF("CMediaClientVideoDisplayBody::HasWindows +++");
891 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::HasWindows --- return %d", (iClientWindows.Count() > 0));
892 return (iClientWindows.Count() > 0);
895 TInt CMediaClientVideoDisplayBody::SetBackgroundSurface(TWindowData& aWindowData,
896 const TRect& aCropRegion)
898 DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetBackgroundSurface +++");
899 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetBackgroundSurface - iWindow WsHandle 0x%X", aWindowData.iWindow->WsHandle());
900 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetBackgroundSurface - iWindow abs pos %d,%d - width %d, height %d", aWindowData.iWindow->AbsPosition().iX, aWindowData.iWindow->AbsPosition().iY, aWindowData.iWindow->Size().iWidth, aWindowData.iWindow->Size().iHeight);
901 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetBackgroundSurface - iClipRect %d,%d - %d,%d", aWindowData.iClipRect.iTl.iX, aWindowData.iClipRect.iTl.iY, aWindowData.iClipRect.iBr.iX, aWindowData.iClipRect.iBr.iY);
902 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetBackgroundSurface - iVideoExtent %d,%d - %d,%d", aWindowData.iVideoExtent.iTl.iX, aWindowData.iVideoExtent.iTl.iY, aWindowData.iVideoExtent.iBr.iX, aWindowData.iVideoExtent.iBr.iY);
903 DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SetBackgroundSurface - iScaleWidth %f, iScaleHeight %f", aWindowData.iScaleWidth, aWindowData.iScaleHeight);
904 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetBackgroundSurface - iRotation %d", aWindowData.iRotation);
905 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetBackgroundSurface - iAutoScaleType %d", aWindowData.iAutoScaleType);
906 DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SetBackgroundSurface - iHorizPos %d, iVertPos %d", aWindowData.iHorizPos, aWindowData.iVertPos);
907 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetBackgroundSurface - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
909 // required as this private function is called directly from external friend class
910 iCropRegion = aCropRegion;
912 // viewport is the viewable area of surface
913 TRect viewport(iCropRect);
914 if (aCropRegion.Width() > 0 || aCropRegion.Height() > 0)
916 viewport.Intersection(aCropRegion);
919 // Viewport is 0 size, don't show any video
920 if (viewport.Width() <= 0 || viewport.Height() <= 0)
922 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetBackgroundSurface --- Returned with error %d", KErrArgument);
926 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetBackgroundSurface - viewport1 %d,%d - %d,%d", viewport.iTl.iX, viewport.iTl.iY, viewport.iBr.iX, viewport.iBr.iY);
928 TRect videoExtent(aWindowData.iVideoExtent);
930 TReal32 inputWidth = 0.0f;
931 TReal32 inputHeight = 0.0f;
932 TReal32 pixelAspectRatio = 0.0f;
933 switch (aWindowData.iRotation)
935 case EVideoRotationNone:
936 case EVideoRotationClockwise180:
937 inputWidth = static_cast<TReal32>(viewport.Width());
938 inputHeight = static_cast<TReal32>(viewport.Height());
939 pixelAspectRatio = static_cast<TReal32>(iAspectRatio.iNumerator) / iAspectRatio.iDenominator;
941 case EVideoRotationClockwise90:
942 case EVideoRotationClockwise270:
943 inputWidth = static_cast<TReal32>(viewport.Height());
944 inputHeight = static_cast<TReal32>(viewport.Width());
945 pixelAspectRatio = static_cast<TReal32>(iAspectRatio.iDenominator) / iAspectRatio.iNumerator;
948 // Should never get to default unless there's been some programming error.
949 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetBackgroundSurface --- Returned with error %d", KErrArgument);
953 TReal32 viewportAspect = pixelAspectRatio * inputWidth / inputHeight;
954 TReal32 vidextAspect = static_cast<TReal32>(videoExtent.Width()) / static_cast<TReal32>(videoExtent.Height());
956 DEBUG_PRINTF4("CMediaClientVideoDisplayBody::SetBackgroundSurface - inputWidth %f, inputHeight %f, PAR %f", inputWidth, inputHeight, pixelAspectRatio);
957 DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SetBackgroundSurface - viewportAspect %f, vidextAspect %f", viewportAspect, vidextAspect);
959 // Set the extent to the display area in the window. The final height and with is to
960 // be changed by deltaHeight and deltaWidth respectively.
961 TRect extent(videoExtent);
963 TInt deltaHeight = 0;
966 if (aWindowData.iAutoScaleType == EAutoScaleBestFit)
968 if (viewportAspect > vidextAspect)
970 // Shrink height to get the correct aspect ratio
971 deltaHeight = (TInt) (extent.Width() / viewportAspect - extent.Height());
975 // Shrink width to get the correct aspect ratio
976 deltaWidth = (TInt) (extent.Height() * viewportAspect - extent.Width());
979 else if (aWindowData.iAutoScaleType == EAutoScaleClip)
981 if (viewportAspect > vidextAspect)
983 // Expand width to get the correct aspect ratio
984 deltaWidth = (TInt) (extent.Height() * viewportAspect - extent.Width());
988 // Expand height to get the correct aspect ratio
989 deltaHeight = (TInt) (extent.Width() / viewportAspect - extent.Height());
992 else if (aWindowData.iAutoScaleType == EAutoScaleStretch)
994 if(iSwitchedToExternalDisplay)
996 UpdateDeltaForExtDisplay(viewportAspect, videoExtent, deltaHeight, deltaWidth);
999 else if (aWindowData.iAutoScaleType == EAutoScaleNone)
1001 // for non-square pixels, reduce one dimension
1002 // XXX other option is to enlarge in the other dimension
1003 if(pixelAspectRatio > 1)
1005 inputHeight /= pixelAspectRatio;
1007 else if(pixelAspectRatio < 1)
1009 inputWidth *= pixelAspectRatio;
1011 deltaHeight = (TInt) (inputHeight * aWindowData.iScaleHeight * 0.01 - videoExtent.Height());
1012 deltaWidth = (TInt) (inputWidth * aWindowData.iScaleWidth * 0.01 - videoExtent.Width());
1015 DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SetBackgroundSurface - deltaWidth %d, deltaHeight %d", deltaWidth, deltaHeight);
1017 // Change the width of the extent in the proper directions and propertions.
1018 switch (aWindowData.iHorizPos)
1020 case EHorizontalAlignCenter:
1021 extent.iTl.iX -= deltaWidth / 2;
1022 extent.iBr.iX += deltaWidth / 2;
1024 case EHorizontalAlignLeft:
1025 extent.iBr.iX += deltaWidth;
1027 case EHorizontalAlignRight:
1028 extent.iTl.iX -= deltaWidth;
1031 TInt width = extent.Width() + deltaWidth;
1032 extent.iTl.iX += aWindowData.iHorizPos;
1033 extent.iBr.iX = extent.iTl.iX + width;
1037 // Change the height of the extent in the proper directions and propertions.
1038 switch (aWindowData.iVertPos)
1040 case EVerticalAlignCenter:
1041 extent.iTl.iY -= deltaHeight / 2;
1042 extent.iBr.iY += deltaHeight / 2;
1044 case EVerticalAlignTop:
1045 extent.iBr.iY += deltaHeight;
1047 case EVerticalAlignBottom:
1048 extent.iTl.iY -= deltaHeight;
1051 TInt height = extent.Height() + deltaHeight;
1052 extent.iTl.iY += aWindowData.iVertPos;
1053 extent.iBr.iY = extent.iTl.iY + height;
1057 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetBackgroundSurface - extent1 %d,%d - %d,%d", extent.iTl.iX, extent.iTl.iY, extent.iBr.iX, extent.iBr.iY);
1059 // The video should not be displayed outside the intended video extent or clipping rectangle.
1060 // The extent already has the correct size and position for displaying the entire viewport.
1061 // The viewport is clipped such that the video is not moved/distorted when we take the extent
1062 // to be the intersection of itself and the intended video extent.
1064 TRect viewableArea(videoExtent);
1065 viewableArea.Intersection(aWindowData.iClipRect);
1067 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetBackgroundSurface - viewableArea %d,%d - %d,%d", viewableArea.iTl.iX, viewableArea.iTl.iY, viewableArea.iBr.iX, viewableArea.iBr.iY);
1069 // Number of pixels (in window coordinates) to be clipped on the right, bottom, top and left sides of
1071 TInt dr = Max(0, extent.iBr.iX - viewableArea.iBr.iX);
1072 TInt db = Max(0, extent.iBr.iY - viewableArea.iBr.iY);
1073 TInt dt = Max(0, viewableArea.iTl.iY - extent.iTl.iY);
1074 TInt dl = Max(0, viewableArea.iTl.iX - extent.iTl.iX);
1076 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetBackgroundSurface - dr %d, db %d, dt %d, dl %d", dr, db, dt, dl);
1078 // Calculate the number of pixels in the video per window pixel in both x and y directions.
1079 TReal32 wRatio = 0.0f;
1080 TReal32 hRatio = 0.0f;
1082 // Make sure we don't divide by 0
1083 if (extent.Width() != 0)
1085 wRatio = inputWidth / static_cast<TReal32>(extent.Width());
1088 if (extent.Height() != 0)
1090 hRatio = inputHeight / static_cast<TReal32>(extent.Height());
1093 DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SetBackgroundSurface - wRatio %f, hRatio %f", wRatio, hRatio);
1095 // Clip the viewport
1096 switch (aWindowData.iRotation)
1098 case EVideoRotationNone:
1099 viewport.iBr.iX -= (TInt) (wRatio * static_cast<TReal32>(dr));
1100 viewport.iBr.iY -= (TInt) (hRatio * static_cast<TReal32>(db));
1101 viewport.iTl.iX += (TInt) (wRatio * static_cast<TReal32>(dl));
1102 viewport.iTl.iY += (TInt) (hRatio * static_cast<TReal32>(dt));
1104 case EVideoRotationClockwise180:
1105 viewport.iBr.iX -= (TInt) (wRatio * static_cast<TReal32>(dl));
1106 viewport.iBr.iY -= (TInt) (hRatio * static_cast<TReal32>(dt));
1107 viewport.iTl.iX += (TInt) (wRatio * static_cast<TReal32>(dr));
1108 viewport.iTl.iY += (TInt) (hRatio * static_cast<TReal32>(db));
1110 case EVideoRotationClockwise90:
1111 viewport.iBr.iX -= (TInt) (wRatio * static_cast<TReal32>(db));
1112 viewport.iBr.iY -= (TInt) (hRatio * static_cast<TReal32>(dl));
1113 viewport.iTl.iX += (TInt) (wRatio * static_cast<TReal32>(dt));
1114 viewport.iTl.iY += (TInt) (hRatio * static_cast<TReal32>(dr));
1116 case EVideoRotationClockwise270:
1117 viewport.iBr.iX -= (TInt) (wRatio * static_cast<TReal32>(dt));
1118 viewport.iBr.iY -= (TInt) (hRatio * static_cast<TReal32>(dr));
1119 viewport.iTl.iX += (TInt) (wRatio * static_cast<TReal32>(db));
1120 viewport.iTl.iY += (TInt) (hRatio * static_cast<TReal32>(dl));
1123 // Should never get to default unless there's been some programming error.
1124 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetBackgroundSurface --- Returned with error %d", KErrArgument);
1125 return KErrArgument;
1128 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetBackgroundSurface - viewport2 %d,%d - %d,%d", viewport.iTl.iX, viewport.iTl.iY, viewport.iBr.iX, viewport.iBr.iY);
1131 extent.Intersection(viewableArea);
1133 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetBackgroundSurface - extent2 %d,%d - %d,%d", extent.iTl.iX, extent.iTl.iY, extent.iBr.iX, extent.iBr.iY);
1135 aWindowData.iSurfaceConfig.SetViewport(viewport);
1136 aWindowData.iSurfaceConfig.SetExtent(extent);
1137 aWindowData.iSurfaceConfig.SetOrientation(ConvertRotation(aWindowData.iRotation));
1139 aWindowData.iSurfaceConfig.SetSurfaceId(iSurfaceId);
1141 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetBackgroundSurface - iSurfaceId %08x:%08x:%08x:%08x",
1142 iSurfaceId.iInternal[3], iSurfaceId.iInternal[2], iSurfaceId.iInternal[1], iSurfaceId.iInternal[0]);
1144 // Get the rectangle that bounds the crop rectangle and the viewport. This should be
1145 // the same as the crop rectangle as long as the viewport does not go outside this area.
1146 TRect rect(iCropRect);
1147 rect.BoundingRect(viewport);
1148 TInt err = KErrNone;
1150 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetBackgroundSurface - rect %d,%d - %d,%d", rect.iTl.iX, rect.iTl.iY, rect.iBr.iX, rect.iBr.iY);
1152 // Check if the viewport and extent can be displayed as a background surface. The viewport
1153 // is valid if it is within the crop rectangle and is not empty. The extent is valid if
1155 if (rect == iCropRect && !viewport.IsEmpty() && !extent.IsEmpty())
1157 DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetBackgroundSurface - Calling SetBackgroundSurface");
1158 err = aWindowData.iWindow->SetBackgroundSurface(aWindowData.iSurfaceConfig, ETrue);
1161 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetBackgroundSurface --- err %d", err);
1165 TBool CMediaClientVideoDisplayBody::IsUsed() const
1167 DEBUG_PRINTF("CMediaClientVideoDisplayBody::IsUsed +++");
1168 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::IsUsed --- return %d", (iEventHandler || iClientWindows.Count() > 0));
1169 return (iEventHandler || iClientWindows.Count() > 0);
1173 TBool CMediaClientVideoDisplayBody::IsSurfaceCreated() const
1175 DEBUG_PRINTF("CMediaClientVideoDisplayBody::IsSurfaceCreated +++");
1176 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::IsSurfaceCreated --- return %d", !(iSurfaceId.IsNull()));
1177 return !(iSurfaceId.IsNull());
1180 TInt CMediaClientVideoDisplayBody::DisplayId() const
1182 DEBUG_PRINTF("CMediaClientVideoDisplayBody::DisplayId +++");
1183 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::DisplayId --- return %d", iDisplayId);
1187 TInt CMediaClientVideoDisplayBody::CompareByDisplay(const TInt* aDisplayId, const CMediaClientVideoDisplayBody& aDisplay)
1189 DEBUG_PRINTF("CMediaClientVideoDisplayBody::CompareByDisplay +++");
1190 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::CompareByDisplay --- return %d", (*aDisplayId - aDisplay.DisplayId()));
1191 return (*aDisplayId - aDisplay.DisplayId());
1194 TInt CMediaClientVideoDisplayBody::Compare(const CMediaClientVideoDisplayBody& aLeft, const CMediaClientVideoDisplayBody& aRight)
1196 DEBUG_PRINTF("CMediaClientVideoDisplayBody::Compare +++");
1197 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::Compare --- return %d", (aLeft.DisplayId() - aRight.DisplayId()));
1198 return (aLeft.DisplayId() - aRight.DisplayId());
1201 CFbsBitGc::TGraphicsOrientation CMediaClientVideoDisplayBody::ConvertRotation(TVideoRotation aRotation)
1203 DEBUG_PRINTF("CMediaClientVideoDisplayBody::ConvertRotation +++");
1205 CFbsBitGc::TGraphicsOrientation orientation;
1209 case EVideoRotationNone:
1210 orientation = CFbsBitGc::EGraphicsOrientationNormal;
1212 case EVideoRotationClockwise90:
1213 orientation = CFbsBitGc::EGraphicsOrientationRotated270;
1215 case EVideoRotationClockwise180:
1216 orientation = CFbsBitGc::EGraphicsOrientationRotated180;
1218 case EVideoRotationClockwise270:
1219 orientation = CFbsBitGc::EGraphicsOrientationRotated90;
1222 // Should never get to default unless there's been some programming error.
1223 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::ConvertRotation --- Failed due to %d bad aRotation argument", aRotation);
1224 __ASSERT_DEBUG(FALSE, User::Invariant());
1225 // Use the normal option otherwise
1226 orientation = CFbsBitGc::EGraphicsOrientationNormal;
1228 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::ConvertRotation --- return %d", orientation);
1232 CMediaClientVideoDisplayBody* CMediaClientVideoDisplayBody::FindDisplayWithWindowL(const RPointerArray<CMediaClientVideoDisplayBody>& aDisplays, const RWindowBase& aWindow)
1234 DEBUG_PRINTF("CMediaClientVideoDisplayBody::FindDisplayWithWindowL +++");
1235 TInt count = aDisplays.Count();
1237 for (TInt i = 0; i < count; ++i)
1239 CMediaClientVideoDisplayBody* display = aDisplays[i];
1241 if (display->iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle) != KErrNotFound)
1243 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::FindDisplayWithWindowL window found at position ", i);
1244 DEBUG_PRINTF("CMediaClientVideoDisplayBody::FindDisplayWithWindowL ---");
1249 User::Leave(KErrNotFound);
1253 RArray<CMediaClientVideoDisplayBody::TWindowData>& CMediaClientVideoDisplayBody::Windows()
1255 DEBUG_PRINTF("CMediaClientVideoDisplayBody::Windows +++");
1256 DEBUG_PRINTF("CMediaClientVideoDisplayBody::Windows ---");
1257 return iClientWindows;
1260 void CMediaClientVideoDisplayBody::SetExternalDisplaySwitchingL(TBool aControl)
1262 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetExternalDisplaySwitchingL +++ aControl=%d", aControl);
1265 if(!iExtDisplaySwitchingSupported)
1267 User::Leave(KErrNotSupported);
1270 // need active scheduler installed
1271 if(!CActiveScheduler::Current())
1273 User::Leave(KErrNotReady);
1276 if(iClientRequestedExtDisplaySwitching != aControl)
1278 iClientRequestedExtDisplaySwitching = aControl;
1282 DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetExternalDisplaySwitchingL ---");
1285 void CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected(TExtDisplayConnectionProviderConnType aExtDisplayConnType)
1287 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected +++ aExtDisplayConnType=%d", aExtDisplayConnType);
1289 if(aExtDisplayConnType != iExtDisplayConnType)
1291 TExtDisplayConnectionProviderConnType prevExtDisplayConnType = iExtDisplayConnType;
1292 iExtDisplayConnType = aExtDisplayConnType;
1294 if(prevExtDisplayConnType == EExtDisplayConnectionProviderConnTypeDisconnected)
1296 // disconnected -> connected - don't care which type it is
1297 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected disconnected -> connected(type %d)", iExtDisplayConnType);
1298 iExtDisplayConnected = ETrue;
1301 else if(iExtDisplayConnType == EExtDisplayConnectionProviderConnTypeDisconnected)
1303 // connected -> disconnected - don't care from which type it is
1304 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected connected(type %d) -> disconnected", prevExtDisplayConnType);
1305 iExtDisplayConnected = EFalse;
1310 // If we get this far then the connection type has changed from "AV Out -> HDMI" or "HDMI -> AV Out"
1311 // Both are likely. "AV Out -> HDMI" occurs if AV Out cable is connected and HDMI cable is then connected.
1312 // "HDMI -> AV Out" occurs if both AV Out and HDMI cables are connected and HDMI cable is then disconnected.
1313 // HDMI is preferred over AV Out.
1315 // update external display window data
1316 iExtDisplayHandler->UpdateWindow();
1317 TRect externalDisplayRect(TPoint(0, 0), iExtDisplayHandler->DisplaySizeInPixels());
1318 (*iWindowsArrayPtr)[0].iClipRect = externalDisplayRect;
1319 (*iWindowsArrayPtr)[0].iVideoExtent = externalDisplayRect;
1320 TRAPD(err, (*iWindowsArrayPtr)[0].iAutoScaleType = ExtDisplayAutoScaleTypeL());
1323 RemoveBackgroundSurface(ETrue);
1324 RedrawWindows(iCropRegion);
1328 // Not a lot we can do. Just keep as it is but external display output will be incorrect.
1329 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected ExtDisplayAutoScaleTypeL failed %d", err);
1335 DEBUG_PRINTF("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected No change to connection type");
1338 DEBUG_PRINTF("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected ---");
1341 void CMediaClientVideoDisplayBody::SetWindowArrayPtr2Client()
1343 DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetWindowArrayPtr2Client +++");
1345 iWindowsArrayPtr = &iClientWindows;
1346 iSwitchedToExternalDisplay = EFalse;
1348 DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetWindowArrayPtr2Client ---");
1351 void CMediaClientVideoDisplayBody::SetWindowArrayPtr2Ext()
1353 DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetWindowArrayPtr2Ext +++");
1355 iWindowsArrayPtr = &iExtDisplayWindows;
1356 iSwitchedToExternalDisplay = ETrue;
1358 DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetWindowArrayPtr2Ext ---");
1361 void CMediaClientVideoDisplayBody::CreateExtDisplayHandlerL()
1363 DEBUG_PRINTF("CMediaClientVideoDisplayBody::CreateExtDisplayHandlerL +++");
1365 CMediaClientExtDisplayHandler* extDisplayHandler = CMediaClientExtDisplayHandler::NewL(iExtDisplayConnectionProvider->ExtDisplayId());
1366 CleanupStack::PushL(extDisplayHandler);
1368 TWindowData windowData;
1369 windowData.iWindow = extDisplayHandler->Window();
1370 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::CreateExtDisplayHandlerL - iWindow WsHandle 0x%X", windowData.iWindow->WsHandle());
1372 TRect externalDisplayRect(TPoint(0, 0), extDisplayHandler->DisplaySizeInPixels());
1373 windowData.iClipRect = externalDisplayRect;
1374 windowData.iVideoExtent = externalDisplayRect;
1375 // windowData.iScaleWidth only required for EAutoScaleNone
1376 // windowData.iScaleWidth only required for EAutoScaleNone
1377 windowData.iRotation = EVideoRotationNone;
1378 windowData.iAutoScaleType = ExtDisplayAutoScaleTypeL();
1379 windowData.iHorizPos = EHorizontalAlignCenter;
1380 windowData.iVertPos = EVerticalAlignCenter;
1381 // windowData.iWindow2 not used
1383 iExtDisplayWindows.AppendL(windowData);
1384 CleanupStack::Pop(extDisplayHandler);
1385 iExtDisplayHandler = extDisplayHandler;
1387 DEBUG_PRINTF("CMediaClientVideoDisplayBody::CreateExtDisplayHandlerL ---");
1390 void CMediaClientVideoDisplayBody::RemoveExtDisplayHandler()
1392 DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveExtDisplayHandler +++");
1394 delete iExtDisplayHandler;
1395 iExtDisplayHandler = NULL;
1396 iExtDisplayWindows.Reset();
1398 DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveExtDisplayHandler ---");
1401 void CMediaClientVideoDisplayBody::CreateExtDisplayPluginL()
1403 DEBUG_PRINTF("CMediaClientVideoDisplayBody::CreateExtDisplayPluginL +++");
1405 iExtDisplayConnectionProvider = CExtDisplayConnectionProviderInterface::NewL();
1407 if(iExtDisplayConnectionProvider)
1409 iExtDisplaySwitchingSupported = ETrue;
1410 iExtDisplayConnectionProvider->SetExtDisplayConnectionProviderCallback(*this);
1411 iExtDisplayConnType = iExtDisplayConnectionProvider->ExtDisplayConnType();
1412 iExtDisplayConnected = (iExtDisplayConnType != EExtDisplayConnectionProviderConnTypeDisconnected);
1415 DEBUG_PRINTF("CMediaClientVideoDisplayBody::CreateExtDisplayPluginL ---");
1418 void CMediaClientVideoDisplayBody::RemoveExtDisplayPlugin()
1420 DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveExtDisplayPlugin +++");
1422 if(iExtDisplaySwitchingSupported)
1424 delete iExtDisplayConnectionProvider;
1425 iExtDisplayConnectionProvider = NULL;
1426 iExtDisplaySwitchingSupported = EFalse;
1427 iExtDisplayConnected = EFalse;
1429 DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveExtDisplayPlugin ---");
1432 void CMediaClientVideoDisplayBody::MmcweoFocusWindowGroupChanged()
1434 DEBUG_PRINTF("CMediaClientVideoDisplayBody::MweocFocusWindowGroupChanged +++");
1436 TBool prevClientWindowIsInFocus = iClientWindowIsInFocus;
1439 if(prevClientWindowIsInFocus != iClientWindowIsInFocus)
1444 DEBUG_PRINTF("CMediaClientVideoDisplayBody::MweocFocusWindowGroupChanged ---");
1447 TBool CMediaClientVideoDisplayBody::MmcweoIgnoreProcess(TSecureId aId)
1449 DEBUG_PRINTF("CMediaClientVideoDisplayBody::MmcweoIgnoreProcess +++");
1451 TBool ignore = ETrue;
1454 ignore = iServerClient->IgnoreProcess(aId);
1456 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::MmcweoIgnoreProcess --- return %d", ignore);
1460 void CMediaClientVideoDisplayBody::UpdateFocus()
1462 DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateFocus +++");
1464 if(!iWsEventObserver)
1466 iClientWindowIsInFocus = ETrue;
1467 DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateFocus Event Observer is NULL");
1468 DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateFocus ---");
1472 TBool prevClientWindowIsInFocus = iClientWindowIsInFocus;
1475 if(iWsEventObserver->FocusWindowGroupId(focusGroupId) == KErrNone)
1477 iClientWindowIsInFocus = EFalse;
1478 TInt count = iClientWindows.Count();
1479 for(TInt i = 0; i < count; i++)
1481 if(iClientWindows[i].iWindow->WindowGroupId() == focusGroupId)
1483 iClientWindowIsInFocus = ETrue;
1490 DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateFocus Error retrieving focus WgId from observer");
1491 iClientWindowIsInFocus = ETrue;
1494 if(iServerClient && (prevClientWindowIsInFocus != iClientWindowIsInFocus))
1496 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::MweocFocusWindowGroupChanged calling server, focus %d", iClientWindowIsInFocus);
1497 iServerClient->FocusChanged(iClientWindowIsInFocus);
1500 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::UpdateFocus Client window in focus %d", iClientWindowIsInFocus);
1501 DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateFocus ---");
1504 void CMediaClientVideoDisplayBody::SwitchSurface()
1506 DEBUG_PRINTF("CMediaClientVideoDisplayBody::SwitchSurface +++");
1508 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SwitchSurface SurfaceCreated %d", IsSurfaceCreated());
1509 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SwitchSurface Client window count %d", iClientWindows.Count());
1510 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SwitchSurface Client Requested Ext Display Switching %d", iClientRequestedExtDisplaySwitching);
1511 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SwitchSurface Client Window in Focus %d", iClientWindowIsInFocus);
1512 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SwitchSurface External Display Connected %d", iExtDisplayConnected);
1514 if(IsSurfaceCreated() && (iClientWindows.Count() > 0) && iClientRequestedExtDisplaySwitching &&
1515 iClientWindowIsInFocus && iExtDisplayConnected)
1517 TRAPD(err, CreateExtDisplayHandlerL());
1518 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SwitchSurface CreateExtDisplayHandlerL error %d", err);
1521 SetWindowArrayPtr2Ext();
1522 RedrawWindows(iCropRegion);
1524 #ifdef MEDIA_CLIENT_SURFACE_NOT_REMOVED_FROM_CLIENT_WINDOW
1525 // Hide surface so that video is not seen on client window
1526 HideAllClientWindows();
1528 // Surface removed from window
1529 SetWindowArrayPtr2Client();
1530 RemoveBackgroundSurface(ETrue);
1531 SetWindowArrayPtr2Ext();
1535 else if(iSwitchedToExternalDisplay)
1537 // Set background surface for clientwindows before removing from external display window.
1538 SetWindowArrayPtr2Client();
1539 // RedrawWindows handles both the case where the surface was removed from client window and
1540 // also the case where the surface was hidden from client window
1541 RedrawWindows(iCropRegion);
1542 SetWindowArrayPtr2Ext();
1543 RemoveBackgroundSurface(ETrue);
1544 RemoveExtDisplayHandler();
1545 SetWindowArrayPtr2Client();
1548 DEBUG_PRINTF("CMediaClientVideoDisplayBody::SwitchSurface ---");
1551 TBool CMediaClientVideoDisplayBody::IsRotationValid(TVideoRotation aVideoRotation)
1553 if (aVideoRotation == EVideoRotationNone ||
1554 aVideoRotation == EVideoRotationClockwise90 ||
1555 aVideoRotation == EVideoRotationClockwise180 ||
1556 aVideoRotation == EVideoRotationClockwise270)
1561 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::IsRotationValid - Rotation %d not valid", aVideoRotation);
1565 TBool CMediaClientVideoDisplayBody::IsAutoScaleTypeValid(TAutoScaleType aAutoScaleType)
1567 if (aAutoScaleType == EAutoScaleNone ||
1568 aAutoScaleType == EAutoScaleBestFit ||
1569 aAutoScaleType == EAutoScaleClip ||
1570 aAutoScaleType == EAutoScaleStretch)
1575 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::IsAutoScaleTypeValid - Auto scale %d not valid", aAutoScaleType);
1580 Check whether a change in the surface crop rectangle would mean that the surface viewport calculated in SetBackgroundSurface would change.
1581 The surface viewport is the intersection of the surface crop rectangle and the client crop region
1583 TBool CMediaClientVideoDisplayBody::SurfaceCropRectChangeRequiresRedraw(TRect aOldSurfaceCropRect, TRect aNewSurfaceCropRect, TRect aClientCropRegion)
1585 DEBUG_PRINTF("CMediaClientVideoDisplayBody::SurfaceCropRectChangeRequiresRedraw +++");
1587 // If aClientCropRegion is empty then it is not currently being used in the SetBackgroundSurface calculations.
1588 // This means that only aOldSurfaceCropRect is being used to decide which part of the video is displayed.
1589 // By setting aClientCropRect to the same as aOldSurfaceCropRect we ensure that only aOldSurfaceCropRect is
1590 // used in the subsequent intersection area checks.
1591 if (aClientCropRegion.IsEmpty())
1593 DEBUG_PRINTF("CMediaClientVideoDisplayBody::SurfaceCropRectChangeRequiresRedraw - Client crop region is empty");
1594 aClientCropRegion = aOldSurfaceCropRect;
1597 TBool ret = IntersectionAreaChanged(aOldSurfaceCropRect, aNewSurfaceCropRect, aClientCropRegion);
1599 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SurfaceCropRectChangeRequiresRedraw --- ret = %d", ret);
1605 Check whether a change in the client crop region would mean that the surface viewport calculated in SetBackgroundSurface would change.
1606 The surface viewport is the intersection of the surface crop rectangle and the client crop region
1608 TBool CMediaClientVideoDisplayBody::ClientCropRegionChangeRequiresRedraw(TRect aOldClientCropRegion, TRect aNewClientCropRegion, TRect aSurfaceCropRect)
1610 DEBUG_PRINTF("CMediaClientVideoDisplayBody::ClientCropRegionChangeRequiresRedraw +++");
1612 // If aOldClientCropRegion is empty then it is not currently being used in the SetBackgroundSurface calculations.
1613 // This means that only aSurfaceCropRect is being used to decide which part of the video is displayed. By
1614 // setting aOldClientCropRegion to the same as aSurfaceCropRect we ensure that only aSurfaceCropRect is
1615 // used in the subsequent intersection area checks.
1616 if (aOldClientCropRegion.IsEmpty())
1618 DEBUG_PRINTF("CMediaClientVideoDisplayBody::ClientCropRegionChangeRequiresRedraw - Old client crop region is empty");
1619 aOldClientCropRegion = aSurfaceCropRect;
1622 // If aNewClientCropRegion is empty then it will not be used in the SetBackgroundSurface calculations.
1623 // This means that only aSurfaceCropRect will impact which part of the video is displayed. By
1624 // setting aNewClientCropRegion to the same as aSurfaceCropRect we ensure that only aSurfaceCropRect is
1625 // used in the subsequent intersection area checks.
1626 if (aNewClientCropRegion.IsEmpty())
1628 DEBUG_PRINTF("CMediaClientVideoDisplayBody::ClientCropRegionChangeRequiresRedraw - New client crop region is empty");
1629 aNewClientCropRegion = aSurfaceCropRect;
1632 TBool ret = IntersectionAreaChanged(aOldClientCropRegion, aNewClientCropRegion, aSurfaceCropRect);
1634 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::ClientCropRegionChangeRequiresRedraw --- ret = %d", ret);
1640 Check whether the change in size of a rectangle means its intersection with another rectangle has changed.
1641 This is used to check whether changes in things like the surface crop rectangle, client crop region, and window clip rectangle, would mean
1642 the area of video displayed would change.
1644 TBool CMediaClientVideoDisplayBody::IntersectionAreaChanged(TRect aOldRect, TRect aNewRect, TRect aOtherRect)
1646 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::IntersectionAreaChanged - aOldRect %d,%d - %d,%d", aOldRect.iTl.iX, aOldRect.iTl.iY, aOldRect.iBr.iX, aOldRect.iBr.iY);
1647 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::IntersectionAreaChanged - aNewRect %d,%d - %d,%d", aNewRect.iTl.iX, aNewRect.iTl.iY, aNewRect.iBr.iX, aNewRect.iBr.iY);
1648 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::IntersectionAreaChanged - aOtherRect %d,%d - %d,%d", aOtherRect.iTl.iX, aOtherRect.iTl.iY, aOtherRect.iBr.iX, aOtherRect.iBr.iY);
1650 aOldRect.Intersection(aOtherRect);
1651 aNewRect.Intersection(aOtherRect);
1653 if (aOldRect != aNewRect)
1655 DEBUG_PRINTF("CMediaClientVideoDisplayBody::IntersectionAreaChanged --- Intersection area has changed");
1659 DEBUG_PRINTF("CMediaClientVideoDisplayBody::IntersectionAreaChanged --- Intersection area has not changed");
1664 * This function calculates the delta width and delta height for AV out when the TV-Out setting is set to "widescreen".
1666 * AV out has fixed resolution whether TV-Out is set to "normal" or "widescreen". The TV-Out setting indicates
1667 * that the video should be scaled so that when displayed on a corresponding TV the aspect looks correct.
1669 * When displaying video on a widescreen TV through AV out, because the resolution is the same the TV stretches
1670 * the video horizontally. When displaying on a normal TV no stretching takes place.
1672 * For "normal" TAutoScaleType::EAutoScaleClip is used.
1674 * For "widescreen" this function calculates the width delta and height delta required so that when the video is stretched
1675 * the aspect looks correct on a widescreen TV.
1677 * This function must only be called when autoscale is set to TAutoScaleType::EAutoScaleStretch and an external display is
1680 void CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay(TReal32 aViewportAspect, const TRect& aVideoExtent, TInt& aDeltaHeight, TInt& aDeltaWidth)
1682 DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay +++");
1683 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay aViewportAspect %f", aViewportAspect);
1684 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay aVideoExtent %d,%d - %d,%d", aVideoExtent.iTl.iX, aVideoExtent.iTl.iY, aVideoExtent.iBr.iX, aVideoExtent.iBr.iY);
1685 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay aDeltaHeight %d", aDeltaHeight);
1686 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay aDeltaWidth %d", aDeltaWidth);
1691 TReal32 wideScreenAspect = (TReal32)16 / (TReal32)9;
1692 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay wideScreenAspect %f", wideScreenAspect);
1694 if(aViewportAspect == wideScreenAspect)
1696 // no need to calculate
1697 DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay - Viewport Aspect equals wideScreenAspect");
1698 DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay - width delta and height delta not changed");
1700 else if(aViewportAspect < wideScreenAspect)
1702 DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay - Viewport Aspect is less than wideScreenAspect");
1704 // calculate video width for viewport that when stretched looks ok on widescreen
1705 TReal32 correctedWidth = (TReal32)aVideoExtent.Width() * aViewportAspect / wideScreenAspect;
1706 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay corrected viewport width %f", correctedWidth);
1708 aDeltaWidth = correctedWidth - aVideoExtent.Width();
1710 else // aViewportAspect > wideScreenAspect
1712 DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay - Viewport Aspect is greater than wideScreenAspect");
1714 // calculate video height for viewport that when stretched looks ok on widescreen
1715 TReal32 correctedHeight = (TReal32)aVideoExtent.Height() * wideScreenAspect / aViewportAspect;
1716 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay corrected viewport height %f", correctedHeight);
1718 aDeltaHeight = aVideoExtent.Height() - correctedHeight;
1720 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay --- aDeltaHeight %d", aDeltaHeight);
1721 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay --- aDeltaWidth %d", aDeltaWidth);
1722 DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay ---");
1725 TBool CMediaClientVideoDisplayBody::IsWideScreenL()
1727 DEBUG_PRINTF("CMediaClientVideoDisplayBody::IsWideScreenL +++");
1729 CRepository* repo = CRepository::NewLC(KCRUidTvoutSettings);
1731 User::LeaveIfError(repo->Get(KSettingsTvAspectRatio, value));
1733 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::IsWideScreenL Tv Apect Ratio set to %d, 0=4x3 1=16x9", value);
1735 CleanupStack::PopAndDestroy(repo);
1737 TBool ret = value > 0;
1738 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::IsWideScreenL --- return %d", ret);
1742 TAutoScaleType CMediaClientVideoDisplayBody::ExtDisplayAutoScaleTypeL()
1744 DEBUG_PRINTF("CMediaClientVideoDisplayBody::ExtDisplayAutoScaleTypeL +++");
1746 // EExtDisplayConnectionProviderConnTypeHdmi - EAutoScaleBestFit
1747 // EExtDisplayConnectionProviderConnTypeAnalog / normal - EAutoScaleBestFit
1748 // EExtDisplayConnectionProviderConnTypeAnalog / widescreen - EAutoScaleStretch
1750 TAutoScaleType autoScaleType;
1751 if((iExtDisplayConnType == EExtDisplayConnectionProviderConnTypeAnalog) && IsWideScreenL())
1753 DEBUG_PRINTF("CMediaClientVideoDisplayBody::ExtDisplayAutoScaleTypeL External display scale type EAutoScaleStretch");
1754 autoScaleType = EAutoScaleStretch;
1758 DEBUG_PRINTF("CMediaClientVideoDisplayBody::ExtDisplayAutoScaleTypeL External display scale type EAutoScaleBestFit");
1759 autoScaleType = EAutoScaleBestFit;
1762 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::ExtDisplayAutoScaleTypeL --- return %d", autoScaleType);
1763 return autoScaleType;
1766 #ifdef MEDIA_CLIENT_SURFACE_NOT_REMOVED_FROM_CLIENT_WINDOW
1768 void CMediaClientVideoDisplayBody::HideAllClientWindows()
1770 DEBUG_PRINTF("CMediaClientVideoDisplayBody::HideAllClientWindows +++");
1772 TInt count = iClientWindows.Count();
1773 for (TInt i = 0; i < count; ++i)
1775 // ignore error - cannot be handled
1776 HideWindow(iClientWindows[i].iWindow);
1779 DEBUG_PRINTF("CMediaClientVideoDisplayBody::HideAllClientWindows ---");
1782 TInt CMediaClientVideoDisplayBody::HideWindow(RWindowBase* aWindow)
1784 DEBUG_PRINTF("CMediaClientVideoDisplayBody::HideWindow +++");
1786 TSurfaceConfiguration config;
1787 TInt err = aWindow->GetBackgroundSurface(config);
1788 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::HideWindow GetBackgroundSurface error %d", err);
1792 config.GetSurfaceId(surface);
1793 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::HideWindow - Retrieved Surface %08x:%08x:%08x:%08x",
1794 surface.iInternal[3], surface.iInternal[2], surface.iInternal[1], surface.iInternal[0]);
1797 if (err == KErrNone)
1799 config.SetExtent(TRect(KHiddenExtentA, KHiddenExtentA, KHiddenExtentB, KHiddenExtentB));
1800 err = aWindow->SetBackgroundSurface(config, ETrue);
1801 // Make sure all window rendering has completed before proceeding
1802 RWsSession* ws = aWindow->Session();
1807 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::HideWindow SetBackgroundSurface error %d", err);
1810 DEBUG_PRINTF("CMediaClientVideoDisplayBody::HideWindow ---");
1814 void CMediaClientVideoDisplayBody::SetHiddenBackgroundSurfaceOnAllClientWindows()
1816 DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetHiddenBackgroundSurfaceOnAllClientWindows +++");
1818 TInt count = iClientWindows.Count();
1819 for (TInt i = 0; i < count; ++i)
1821 // ignore error - cannot be handled
1822 SetHiddenBackgroundSurfaceOnClientWindow(iClientWindows[i]);
1825 DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetHiddenBackgroundSurfaceOnAllClientWindows ---");
1829 TInt CMediaClientVideoDisplayBody::SetHiddenBackgroundSurfaceOnClientWindow(TWindowData& aWindowData)
1831 DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetHiddenBackgroundSurfaceOnClientWindow +++");
1832 DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetHiddenBackgroundSurfaceOnClientWindow - iSurfaceId %08x:%08x:%08x:%08x",
1833 iSurfaceId.iInternal[3], iSurfaceId.iInternal[2], iSurfaceId.iInternal[1], iSurfaceId.iInternal[0]);
1835 TSurfaceConfiguration config;
1836 config.SetExtent(TRect(KHiddenExtentA, KHiddenExtentA, KHiddenExtentB, KHiddenExtentB));
1837 config.SetSurfaceId(iSurfaceId);
1838 TInt err = aWindowData.iWindow->SetBackgroundSurface(config, ETrue);
1840 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetHiddenBackgroundSurfaceOnClientWindow ---, return %d", err);