mmlibs/mmfw/src/Client/Video/mediaclientvideodisplaybody.cpp
branchRCL_3
changeset 7 94dbab0a2133
parent 0 40261b775718
child 8 bc06d8566074
child 15 c1e808730d6c
equal deleted inserted replaced
3:f7d9134af83e 7:94dbab0a2133
     1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    14 //
    14 //
    15 
    15 
    16 #include "mediaclientvideodisplaybody.h"
    16 #include "mediaclientvideodisplaybody.h"
    17 #include "mediaclientvideotrace.h"
    17 #include "mediaclientvideotrace.h"
    18 #include <surfaceeventhandler.h>
    18 #include <surfaceeventhandler.h>
    19 
    19 #include <mmf/plugin/mmfmediaclientextdisplayinterface.hrh>
    20 CMediaClientVideoDisplayBody* CMediaClientVideoDisplayBody::NewL(TInt aDisplayId)
    20 #include <e32cmn.h>
    21 	{
    21 #include <ecom/ecom.h>
    22 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::NewL +++"));
    22 
    23 	CMediaClientVideoDisplayBody* self = new (ELeave) CMediaClientVideoDisplayBody(aDisplayId);
    23 CMediaClientVideoDisplayBody* CMediaClientVideoDisplayBody::NewL(TInt aDisplayId, TBool aExtDisplaySwitchingControl)
       
    24 	{
       
    25 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::NewL +++");
       
    26     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::NewL - aDisplayId %d", aDisplayId);
       
    27     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::NewL - aExtDisplaySwitchingControl %d", aExtDisplaySwitchingControl);
       
    28     
       
    29     CMediaClientVideoDisplayBody* self = new (ELeave) CMediaClientVideoDisplayBody(aDisplayId);
    24 	CleanupStack::PushL(self);
    30 	CleanupStack::PushL(self);
    25 	self->ConstructL();
    31 	self->ConstructL(aExtDisplaySwitchingControl);
    26 	CleanupStack::Pop(self);
    32 	CleanupStack::Pop(self);
    27 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::NewL ---"));
    33 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::NewL ---");
    28 	return self;
    34 	return self;
    29 	}
    35 	}
    30 
    36 
    31 CMediaClientVideoDisplayBody* CMediaClientVideoDisplayBody::NewL(TInt aDisplayId, const TSurfaceId& aSurfaceId,
    37 CMediaClientVideoDisplayBody* CMediaClientVideoDisplayBody::NewL(TInt aDisplayId, const TSurfaceId& aSurfaceId,
    32 		const TRect& aCropRect, TVideoAspectRatio aAspectRatio)
    38 		const TRect& aCropRect, TVideoAspectRatio aAspectRatio, TBool aExtDisplaySwitchingControl)
    33 	{
    39 	{
    34 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::NewL +++"));
    40 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::NewL +++");
       
    41 	DEBUG_PRINTF2("CMediaClientVideoDisplayBody::NewL - aDisplayId %d", aDisplayId);
       
    42     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::NewL - aSurfaceId 0x%X,0x%X,0x%X,0x%X", aSurfaceId.iInternal[0], aSurfaceId.iInternal[1], aSurfaceId.iInternal[2], aSurfaceId.iInternal[3]);
       
    43     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::NewL - aCropRect %d,%d - %d,%d", aCropRect.iTl.iX, aCropRect.iTl.iY, aCropRect.iBr.iX, aCropRect.iBr.iY);
       
    44     DEBUG_PRINTF3("CMediaClientVideoDisplayBody::NewL - aAspectRatio %d/%d", aAspectRatio.iNumerator, aAspectRatio.iDenominator);
       
    45     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::NewL - aExtDisplaySwitchingControl %d", aExtDisplaySwitchingControl);
       
    46 
    35 	if(aSurfaceId.IsNull())
    47 	if(aSurfaceId.IsNull())
    36 		{
    48 		{
    37 		User::Leave(KErrArgument);
    49 		User::Leave(KErrArgument);
    38 		}
    50 		}
    39 	CMediaClientVideoDisplayBody* self = new(ELeave) CMediaClientVideoDisplayBody(aDisplayId, aSurfaceId, aCropRect, aAspectRatio);
    51 	CMediaClientVideoDisplayBody* self = new(ELeave) CMediaClientVideoDisplayBody(aDisplayId, aSurfaceId, aCropRect, aAspectRatio);
    40 	CleanupStack::PushL(self);
    52 	CleanupStack::PushL(self);
    41 	self->ConstructL();
    53 	self->ConstructL(aExtDisplaySwitchingControl);
    42 	CleanupStack::Pop();
    54 	CleanupStack::Pop();
    43 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::NewL ---"));
    55 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::NewL ---");
    44 	return self;
    56 	return self;
    45 	}
    57 	}
    46 
    58 
    47 void CMediaClientVideoDisplayBody::ConstructL()
    59 void CMediaClientVideoDisplayBody::ConstructL(TBool aExtDisplaySwitchingControl)
    48 	{
    60 	{
    49 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::ConstructL +++"));
    61 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::ConstructL +++");
    50 	
    62 
    51 	iExtDisplaySwitchingSupported = CExtDisplayConnectionProviderInterface::ExternalDisplaySupportedL();
    63 	SetWindowArrayPtr2Client();
       
    64 
       
    65 	CreateExtDisplayPluginL();
    52 	
    66 	
    53 	// Try and enable display switching by default. If this leaves then do so quietly.
    67 	// Try and enable display switching by default. If this leaves then do so quietly.
    54 	// Either the client has no scheduler installed or the device does not support external
    68 	// Either the client has no scheduler installed or the device does not support external
    55 	// switching (i.e. no plugin was found) 
    69 	// switching (i.e. no plugin was found) 
    56 	TRAPD(err, SetExternalDisplaySwitchingL(ETrue));
    70 	TRAPD(err, SetExternalDisplaySwitchingL(aExtDisplaySwitchingControl));
    57 	err = err; // remove compile warning
    71 	err = err; // remove compile warning
    58 	DEBUG_PRINT2(_L("CMediaClientVideoDisplayBody::ConstructL SetExternalDisplaySwitchingL returned with %d"), err);
    72 	DEBUG_PRINTF2("CMediaClientVideoDisplayBody::ConstructL SetExternalDisplaySwitchingL returned with %d", err);
    59 	
    73 	
    60 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::ConstructL ---"));
    74 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::ConstructL ---");
    61 	}
    75 	}
    62 
    76 
    63 CMediaClientVideoDisplayBody::CMediaClientVideoDisplayBody(TInt aDisplayId, const TSurfaceId& aSurfaceId,
    77 CMediaClientVideoDisplayBody::CMediaClientVideoDisplayBody(TInt aDisplayId, const TSurfaceId& aSurfaceId,
    64 		const TRect& aCropRect, TVideoAspectRatio aAspectRatio) :
    78 		const TRect& aCropRect, TVideoAspectRatio aAspectRatio) :
    65 	iDisplayId(aDisplayId),
    79 	iDisplayId(aDisplayId),
    66 	iSurfaceId(aSurfaceId),
    80 	iSurfaceId(aSurfaceId),
    67 	iCropRect(aCropRect),
    81 	iCropRect(aCropRect),
    68 	iAspectRatio(aAspectRatio)
    82 	iAspectRatio(aAspectRatio)
    69 	{	
    83 	{	
    70 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::CMediaClientVideoDisplayBody +++"));
    84 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::CMediaClientVideoDisplayBody +++");
    71 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::CMediaClientVideoDisplayBody ---"));
    85 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::CMediaClientVideoDisplayBody ---");
    72 	}
    86 	}
    73 
    87 
    74 CMediaClientVideoDisplayBody::CMediaClientVideoDisplayBody(TInt aDisplayId) :
    88 CMediaClientVideoDisplayBody::CMediaClientVideoDisplayBody(TInt aDisplayId) :
    75 	iDisplayId(aDisplayId)
    89 	iDisplayId(aDisplayId)
    76 	{	
    90 	{	
    77 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::CMediaClientVideoDisplayBody +++"));
    91 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::CMediaClientVideoDisplayBody +++");
    78 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::CMediaClientVideoDisplayBody ---"));
    92 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::CMediaClientVideoDisplayBody ---");
    79 	}
    93 	}
    80 
    94 
    81 CMediaClientVideoDisplayBody::~CMediaClientVideoDisplayBody()
    95 CMediaClientVideoDisplayBody::~CMediaClientVideoDisplayBody()
    82 	{
    96 	{
    83 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::~CMediaClientVideoDisplayBody +++"));
    97 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::~CMediaClientVideoDisplayBody +++");
    84 
    98 
       
    99 	// remove for whichever array is current
    85 	RemoveBackgroundSurface(ETrue);
   100 	RemoveBackgroundSurface(ETrue);
    86 		
   101 
    87 	iWindows.Close();	
   102 	iClientWindows.Close();	
    88 	delete iExtDisplayConnectionProvider;
   103     iExtDisplayWindows.Close(); 
       
   104 
       
   105 	delete iExtDisplayHandler;
       
   106 	RemoveExtDisplayPlugin();
    89 	REComSession::FinalClose();
   107 	REComSession::FinalClose();
    90 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::~CMediaClientVideoDisplayBody ---"));
   108 	
       
   109 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::~CMediaClientVideoDisplayBody ---");
    91 	}
   110 	}
    92 
   111 
    93 void CMediaClientVideoDisplayBody::AddDisplayL(MMMFSurfaceEventHandler& aEventHandler)
   112 void CMediaClientVideoDisplayBody::AddDisplayL(MMMFSurfaceEventHandler& aEventHandler)
    94 	{
   113 	{
    95 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::AddDisplayL +++"));
   114 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::AddDisplayL +++");
    96 	if (iEventHandler != NULL)
   115 	if (iEventHandler)
    97 		{
   116 		{
    98 		User::Leave(KErrInUse);
   117 		User::Leave(KErrInUse);
    99 		}
   118 		}
   100 		
   119 		
   101 	iEventHandler = &aEventHandler;
   120 	iEventHandler = &aEventHandler;
   102 	
   121 	
   103 	if (IsSurfaceCreated())
   122 	if (IsSurfaceCreated())
   104 		{
   123 		{
   105 		iEventHandler->MmsehSurfaceCreated(iDisplayId, iSurfaceId, iCropRect, iAspectRatio);
   124 		iEventHandler->MmsehSurfaceCreated(iDisplayId, iSurfaceId, iCropRect, iAspectRatio);
   106 		}
   125 		}
   107 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::AddDisplayL ---"));
   126 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::AddDisplayL ---");
   108 	}
   127 	}
   109 	
   128 	
   110 void CMediaClientVideoDisplayBody::AddDisplayWindowL(const RWindowBase* aWindow, const TRect& aClipRect, const TRect& aCropRegion, const TRect& aVideoExtent, 
   129 void CMediaClientVideoDisplayBody::AddDisplayWindowL(const RWindowBase* aWindow, const TRect& aClipRect, const TRect& aCropRegion, const TRect& aVideoExtent, 
   111 															TReal32 aScaleWidth, TReal32 aScaleHeight, TVideoRotation aRotation, 
   130 															TReal32 aScaleWidth, TReal32 aScaleHeight, TVideoRotation aRotation, 
   112 															TAutoScaleType aAutoScaleType, TInt aHorizPos, TInt aVertPos, RWindow* aWindow2)
   131 															TAutoScaleType aAutoScaleType, TInt aHorizPos, TInt aVertPos, RWindow* aWindow2)
   113 	{
   132 	{
   114 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::AddDisplayWindowL +++"));
   133 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::AddDisplayWindowL +++");
   115 	TInt pos = iWindows.Find(aWindow->WsHandle(), TWindowData::CompareByWsHandle);
   134     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::AddDisplayWindowL - aWindow WsHandle 0x%X", aWindow->WsHandle());
       
   135     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::AddDisplayWindowL - aClipRect %d,%d - %d,%d", aClipRect.iTl.iX, aClipRect.iTl.iY, aClipRect.iBr.iX, aClipRect.iBr.iY);
       
   136     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::AddDisplayWindowL - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
       
   137     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::AddDisplayWindowL - aVideoExtent %d,%d - %d,%d", aVideoExtent.iTl.iX, aVideoExtent.iTl.iY, aVideoExtent.iBr.iX, aVideoExtent.iBr.iY);
       
   138     DEBUG_PRINTF3("CMediaClientVideoDisplayBody::AddDisplayWindowL - aScaleWidth %f, aScaleHeight %f", aScaleWidth, aScaleHeight);
       
   139     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::AddDisplayWindowL - aRotation %d", aRotation);
       
   140     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::AddDisplayWindowL - aAutoScaleType %d", aAutoScaleType);
       
   141     DEBUG_PRINTF3("CMediaClientVideoDisplayBody::AddDisplayWindowL - aHorizPos %d, aVertPos %d", aHorizPos, aVertPos);
       
   142 
       
   143 	TInt pos = iClientWindows.Find(aWindow->WsHandle(), TWindowData::CompareByWsHandle);
   116 	
   144 	
   117 	if (pos != KErrNotFound)
   145 	if (pos != KErrNotFound)
   118 		{
   146 		{
   119 		User::Leave(KErrInUse);
   147 		User::Leave(KErrInUse);
   120 		}
   148 		}
   121 	
   149 	
   122 	TWindowData winData(aWindow, aClipRect, aVideoExtent, aScaleWidth, aScaleHeight, aRotation, aAutoScaleType, aHorizPos, aVertPos, aWindow2);
   150 	TWindowData winData(aWindow, aClipRect, aVideoExtent, aScaleWidth, aScaleHeight, aRotation, aAutoScaleType, aHorizPos, aVertPos, aWindow2);
   123 	iWindows.AppendL(winData);
   151 	iClientWindows.AppendL(winData);
   124 	
   152 	
   125 	iCropRegion = aCropRegion;
   153 	iCropRegion = aCropRegion;
   126 	
   154 	
   127 	if (IsSurfaceCreated())
   155 	if (IsSurfaceCreated())
   128 		{
   156 		{
   129         if(iExtDisplaySwitchingSupported && iClientRequestedExtDisplaySwitching)
   157 		// first client window just added
   130             {
   158         if((iClientWindows.Count() == 1) && iClientRequestedExtDisplaySwitching)
   131             CreateExtDisplayConnProvAndRemoveSurfaceL(EFalse);
   159             {
       
   160             if(iExtDisplayConnected)
       
   161                 {
       
   162                 TRAPD(err, CreateExtDisplayHandlerL());
       
   163                 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::AddDisplayWindowL CreateExtDisplayHandlerL error %d", err);
       
   164                 if(err == KErrNone)
       
   165                     {
       
   166                     SetWindowArrayPtr2Ext();
       
   167                     User::LeaveIfError(RedrawWindows(aCropRegion));
       
   168                     }
       
   169                 }
   132             }
   170             }
   133         
   171         
   134         if(!iExtDisplayConnected)
   172         if(!iExtDisplayConnected || !iExtDisplayHandler)
   135             {
   173             {
   136             User::LeaveIfError(SetBackgroundSurface(winData, aCropRegion));
   174             User::LeaveIfError(SetBackgroundSurface(winData, aCropRegion));
   137             }
   175             }
   138 		}
   176 		}
   139 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::AddDisplayWindowL ---"));
   177 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::AddDisplayWindowL ---");
   140 	}
   178 	}
   141 
   179 
   142 void CMediaClientVideoDisplayBody::RemoveDisplay()
   180 void CMediaClientVideoDisplayBody::RemoveDisplay()
   143 	{
   181 	{
   144 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RemoveDisplay +++"));
   182 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveDisplay +++");
   145 	iEventHandler = NULL;
   183 	iEventHandler = NULL;
   146 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RemoveDisplay ---"));
   184 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveDisplay ---");
   147 	}	
   185 	}	
   148 
   186 
   149 TInt CMediaClientVideoDisplayBody::RemoveDisplayWindow(const RWindowBase& aWindow)
   187 TInt CMediaClientVideoDisplayBody::RemoveDisplayWindow(const RWindowBase& aWindow)
   150 	{
   188 	{
   151 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RemoveDisplayWindow +++"));
   189 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveDisplayWindow +++");
   152 	TInt pos = iWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
   190 	TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
   153 	
   191 	
   154 	if (pos >= 0)
   192 	if (pos >= 0)
   155 		{
   193 		{
   156 		if (IsSurfaceCreated())
   194 		if (IsSurfaceCreated() && (!iExtDisplayConnected || !iExtDisplayHandler))
   157 			{
   195 			{
   158 			iWindows[pos].iWindow->RemoveBackgroundSurface(ETrue);
   196 			iClientWindows[pos].iWindow->RemoveBackgroundSurface(ETrue);
   159 
   197             // Make sure all window rendering has completed before proceeding
   160 			// Make sure all window rendering has completed before proceeding
   198             RWsSession* ws = iClientWindows[pos].iWindow->Session();
   161 			RWsSession* ws = iWindows[pos].iWindow->Session();
   199             if (ws)
   162 			if (ws)
   200               {
   163 				{
   201               ws->Finish();
   164 				ws->Finish();
   202               }
   165 				}
       
   166 			}
   203 			}
   167 		iWindows.Remove(pos);
   204 		iClientWindows.Remove(pos);
   168 		
   205 		
   169 		if(iWindows.Count() == 0)
   206 		if(iClientWindows.Count() == 0 && iExtDisplayConnected && iExtDisplayHandler)
   170 		    {
   207 		    {
   171 		    RemoveExtDisplayConnProv();
   208 		    RemoveBackgroundSurface(ETrue);
       
   209 		    SetWindowArrayPtr2Client();
       
   210 		    RemoveExtDisplayHandler();
   172 		    }
   211 		    }
   173 		}
   212 		}
   174 	
   213 	
   175 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RemoveDisplayWindow ---"));
   214 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveDisplayWindow ---");
   176 	return pos;
   215 	return pos;
   177 	}
   216 	}
   178 
   217 
   179 
   218 
   180 TInt CMediaClientVideoDisplayBody::SurfaceCreated(const TSurfaceId& aSurfaceId, const TRect& aCropRect, TVideoAspectRatio aAspectRatio, const TRect& aCropRegion)
   219 TInt CMediaClientVideoDisplayBody::SurfaceCreated(const TSurfaceId& aSurfaceId, const TRect& aCropRect, TVideoAspectRatio aAspectRatio, const TRect& aCropRegion)
   181 	{
   220 	{
   182 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SurfaceCreated +++"));
   221 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SurfaceCreated +++");
   183 	TBool emitEvent = EFalse;
   222     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SurfaceCreated - aSurfaceId 0x%X,0x%X,0x%X,0x%X", aSurfaceId.iInternal[0], aSurfaceId.iInternal[1], aSurfaceId.iInternal[2], aSurfaceId.iInternal[3]);
       
   223     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SurfaceCreated - aCropRect %d,%d - %d,%d", aCropRect.iTl.iX, aCropRect.iTl.iY, aCropRect.iBr.iX, aCropRect.iBr.iY);
       
   224     DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SurfaceCreated - aAspectRatio %d/%d", aAspectRatio.iNumerator, aAspectRatio.iDenominator);
       
   225     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SurfaceCreated - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
       
   226 
       
   227     TBool emitEvent = EFalse;
   184 	if((iSurfaceId != aSurfaceId) && (!aSurfaceId.IsNull()))
   228 	if((iSurfaceId != aSurfaceId) && (!aSurfaceId.IsNull()))
   185 		{
   229 		{
   186 		emitEvent = ETrue;
   230 		emitEvent = ETrue;
   187 		}
   231 		}
   188 
   232 
   195 		{
   239 		{
   196 		iEventHandler->MmsehSurfaceCreated(iDisplayId, iSurfaceId, iCropRect, iAspectRatio);
   240 		iEventHandler->MmsehSurfaceCreated(iDisplayId, iSurfaceId, iCropRect, iAspectRatio);
   197 		}
   241 		}
   198 
   242 
   199 	TInt err = KErrNone;
   243 	TInt err = KErrNone;
   200     if(iExtDisplaySwitchingSupported && iClientRequestedExtDisplaySwitching)
   244     if((iClientWindows.Count() > 0) && iClientRequestedExtDisplaySwitching)
   201         {
   245         {
   202         TRAP(err, CreateExtDisplayConnProvAndRemoveSurfaceL(EFalse));
   246         if(iExtDisplayConnected && !iExtDisplayHandler)
   203         }
   247             {
   204     
   248             TRAP(err, CreateExtDisplayHandlerL());
   205     if(!iExtDisplayConnected)
   249             DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SurfaceCreated CreateExtDisplayHandlerL error %d", err);
   206         {
   250             if(err == KErrNone)
   207         err = RedrawWindows(aCropRegion);
   251                 {
   208         }
   252                 SetWindowArrayPtr2Ext();
   209     
   253                 }
   210     DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SurfaceCreated ---"));
   254             }
       
   255         }
       
   256     
       
   257     err = RedrawWindows(aCropRegion);
       
   258     
       
   259     DEBUG_PRINTF("CMediaClientVideoDisplayBody::SurfaceCreated ---");
   211 	return err;
   260 	return err;
   212 	}
   261 	}
   213 
   262 
   214 void CMediaClientVideoDisplayBody::RemoveBackgroundSurface(TBool aTriggerRedraw)
   263 void CMediaClientVideoDisplayBody::RemoveBackgroundSurface(TBool aTriggerRedraw)
   215 	{
   264 	{
   216 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RemoveBackgroundSurface +++"));
   265 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveBackgroundSurface +++");
   217 	if (IsSurfaceCreated())
   266 	if (IsSurfaceCreated())
   218 		{
   267 		{
   219 		TInt count = iWindows.Count();
       
   220 	
       
   221 		RWsSession* ws = NULL;
   268 		RWsSession* ws = NULL;
       
   269 		TInt count = iWindowsArrayPtr->Count();
       
   270 	
   222 		for (TInt i = 0; i < count; ++i)
   271 		for (TInt i = 0; i < count; ++i)
   223 			{
   272 			{
   224 			iWindows[i].iWindow->RemoveBackgroundSurface(aTriggerRedraw);
   273 			(*iWindowsArrayPtr)[i].iWindow->RemoveBackgroundSurface(aTriggerRedraw);
   225 			// Make sure all window rendering has completed before proceeding
   274             // Make sure all window rendering has completed before proceeding
   226 			ws = iWindows[i].iWindow->Session();
   275             ws = (*iWindowsArrayPtr)[i].iWindow->Session();
   227 			if (ws)
   276             if (ws)
   228 				{
   277                 {
   229 				ws->Finish();
   278                 ws->Finish();
   230 				}
   279                 }
   231 			}
   280 			}
   232 		}
   281 		}
   233 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RemoveBackgroundSurface ---"));
   282 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveBackgroundSurface ---");
   234 	}
   283 	}
   235 
   284 
   236 void CMediaClientVideoDisplayBody::RemoveSurface(TBool aControllerEvent)
   285 void CMediaClientVideoDisplayBody::RemoveSurface(TBool aControllerEvent)
   237     {
   286     {
   238     DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RemoveSurface +++"));
   287     DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveSurface +++");
   239     if (IsSurfaceCreated())
   288     if (IsSurfaceCreated())
   240         {
   289         {
   241         if(!iExtDisplayConnected)
   290         RemoveBackgroundSurface(ETrue);
   242             {
   291 
   243             RemoveBackgroundSurface(ETrue);
       
   244             }
       
   245         
       
   246         if (iEventHandler  && aControllerEvent)
   292         if (iEventHandler  && aControllerEvent)
   247             {
   293             {
   248             iEventHandler->MmsehRemoveSurface(iSurfaceId);
   294             iEventHandler->MmsehRemoveSurface(iSurfaceId);
   249             }
   295             }
   250 
   296 
   251         iSurfaceId = TSurfaceId::CreateNullId();
   297         iSurfaceId = TSurfaceId::CreateNullId();
   252 
   298 
   253         RemoveExtDisplayConnProv();
   299         if(iExtDisplayConnected && iExtDisplayHandler)
   254         }
   300             {
   255     
   301             SetWindowArrayPtr2Client();
   256     DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RemoveSurface ---"));
   302             RemoveExtDisplayHandler();
       
   303             }
       
   304         }
       
   305     
       
   306     DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveSurface ---");
   257     }
   307     }
   258 
   308 
   259 TInt CMediaClientVideoDisplayBody::SurfaceParametersChanged(const TSurfaceId& aSurfaceId, const TRect& aCropRect, TVideoAspectRatio aAspectRatio)
   309 TInt CMediaClientVideoDisplayBody::SurfaceParametersChanged(const TSurfaceId& aSurfaceId, const TRect& aCropRect, TVideoAspectRatio aAspectRatio)
   260 	{
   310 	{
   261 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SurfaceParametersChanged +++"));
   311 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SurfaceParametersChanged +++");
   262 	if (!IsSurfaceCreated())
   312     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SurfaceCreated - aSurfaceId 0x%X,0x%X,0x%X,0x%X", aSurfaceId.iInternal[0], aSurfaceId.iInternal[1], aSurfaceId.iInternal[2], aSurfaceId.iInternal[3]);
       
   313     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SurfaceCreated - aCropRect %d,%d - %d,%d", aCropRect.iTl.iX, aCropRect.iTl.iY, aCropRect.iBr.iX, aCropRect.iBr.iY);
       
   314     DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SurfaceCreated - aAspectRatio %d/%d", aAspectRatio.iNumerator, aAspectRatio.iDenominator);
       
   315 
       
   316     if (!IsSurfaceCreated())
   263 		{
   317 		{
   264 		return KErrNotSupported;
   318 		return KErrNotSupported;
   265 		}
   319 		}
   266 
   320 
   267 	if (iSurfaceId != aSurfaceId)
   321 	if (iSurfaceId != aSurfaceId)
   275 	if (iEventHandler)
   329 	if (iEventHandler)
   276 		{
   330 		{
   277 		iEventHandler->MmsehSurfaceParametersChanged(iSurfaceId, iCropRect, iAspectRatio);
   331 		iEventHandler->MmsehSurfaceParametersChanged(iSurfaceId, iCropRect, iAspectRatio);
   278 		}
   332 		}
   279 
   333 
   280 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SurfaceParametersChanged ---"));
   334 	RedrawWindows(iCropRegion);
       
   335 	
       
   336 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SurfaceParametersChanged ---");
   281 	return KErrNone;
   337 	return KErrNone;
   282 	}
   338 	}
   283 	
   339 	
   284 TInt CMediaClientVideoDisplayBody::RedrawWindows(const TRect& aCropRegion)
   340 TInt CMediaClientVideoDisplayBody::RedrawWindows(const TRect& aCropRegion)
   285 	{
   341 	{
   286 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RedrawWindows +++"));
   342 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::RedrawWindows +++");
   287 	TInt err = KErrNone;	
   343 	TInt err = KErrNone;	
   288 
   344 
   289 	iCropRegion = aCropRegion;
   345 	iCropRegion = aCropRegion;
   290 	
   346 	
   291 	if(IsSurfaceCreated())
   347 	if(IsSurfaceCreated())
   292 		{
   348 		{
   293 		TInt count = iWindows.Count();
   349 		TInt count = iWindowsArrayPtr->Count();
   294 	
   350 	
   295 		for (TInt i = 0; i < count; ++i)
   351 		for (TInt i = 0; i < count; ++i)
   296 			{
   352 			{
   297 			err = SetBackgroundSurface(iWindows[i], aCropRegion);
   353 			err = SetBackgroundSurface((*iWindowsArrayPtr)[i], aCropRegion);
   298 		
   354 		
   299 			if (err != KErrNone)
   355 			if (err != KErrNone)
   300 				{
   356 				{
   301 				break;
   357 				break;
   302 				}
   358 				}
   303 			}
   359 			}
   304 		}
   360 		}
   305 		
   361 		
   306 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RedrawWindows ---"));
   362 	DEBUG_PRINTF2("CMediaClientVideoDisplayBody::RedrawWindows --- return with %d", err);
   307 	return err;
   363 	return err;
   308 	}
   364 	}
   309 
   365 
       
   366 void CMediaClientVideoDisplayBody::UpdateCropRegionL(const TRect& aCropRegion, TInt aPos)
       
   367     {
       
   368     DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateCropRegionL +++");
       
   369 
       
   370     TRect prevCropRegion(iCropRegion);
       
   371     iCropRegion = aCropRegion;
       
   372     
       
   373     if (IsSurfaceCreated())
       
   374         {
       
   375         if(prevCropRegion == aCropRegion)
       
   376             {
       
   377             if(!iExtDisplayConnected || !iExtDisplayHandler)
       
   378                 {
       
   379                 User::LeaveIfError(SetBackgroundSurface(iClientWindows[aPos], aCropRegion));
       
   380                 }
       
   381             }
       
   382         else
       
   383             {
       
   384             User::LeaveIfError(RedrawWindows(aCropRegion));
       
   385             }
       
   386         }
       
   387     DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateCropRegionL ---");    
       
   388     }
       
   389 
   310 void CMediaClientVideoDisplayBody::SetAutoScaleL(const RWindowBase& aWindow, TAutoScaleType aScaleType, TInt aHorizPos, TInt aVertPos, const TRect& aCropRegion)
   390 void CMediaClientVideoDisplayBody::SetAutoScaleL(const RWindowBase& aWindow, TAutoScaleType aScaleType, TInt aHorizPos, TInt aVertPos, const TRect& aCropRegion)
   311 	{
   391 	{
   312 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetAutoScaleL +++"));
   392 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetAutoScaleL +++");
   313 	TInt pos = iWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
   393     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetAutoScaleL - aWindow WsHandle 0x%X", aWindow.WsHandle());
       
   394     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetAutoScaleL - aScaleType %d", aScaleType);
       
   395     DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SetAutoScaleL - aHorizPos %d, aVertPos %d", aHorizPos, aVertPos);
       
   396     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetAutoScaleL - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
       
   397 
       
   398     TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
   314 	User::LeaveIfError(pos);
   399 	User::LeaveIfError(pos);
   315 	
   400 	
   316 	iWindows[pos].iAutoScaleType = aScaleType;
   401 	iClientWindows[pos].iAutoScaleType = aScaleType;
   317 	iWindows[pos].iHorizPos = aHorizPos;
   402 	iClientWindows[pos].iHorizPos = aHorizPos;
   318 	iWindows[pos].iVertPos = aVertPos;
   403 	iClientWindows[pos].iVertPos = aVertPos;
       
   404 
       
   405 	UpdateCropRegionL(aCropRegion, pos);
       
   406 	
       
   407 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetAutoScaleL ---");
       
   408 	}
       
   409 	
       
   410 
       
   411 void CMediaClientVideoDisplayBody::SetRotationL(const RWindowBase& aWindow, TVideoRotation aRotation, const TRect& aCropRegion)
       
   412 	{
       
   413 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetRotationL +++");
       
   414     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetRotationL - aWindow WsHandle 0x%X", aWindow.WsHandle());
       
   415     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetRotationL - aRotation %d", aRotation);
       
   416     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetRotationL - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
       
   417 
       
   418     TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
       
   419 	User::LeaveIfError(pos);
       
   420 	
       
   421 	iClientWindows[pos].iRotation = aRotation;
       
   422 
       
   423     UpdateCropRegionL(aCropRegion, pos);
       
   424 
       
   425 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetRotationL ---");
       
   426 	}
       
   427 
       
   428 TVideoRotation CMediaClientVideoDisplayBody::RotationL(const RWindowBase& aWindow)
       
   429 	{
       
   430 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::RotationL +++");
       
   431 	TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
       
   432 	User::LeaveIfError(pos);
       
   433 	
       
   434 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::RotationL ---");
       
   435 	return iClientWindows[pos].iRotation;
       
   436 	}
       
   437 
       
   438 void CMediaClientVideoDisplayBody::SetScaleFactorL(const RWindowBase& aWindow, TReal32 aWidthPercentage, TReal32 aHeightPercentage, const TRect& aCropRegion)
       
   439 	{
       
   440 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetScaleFactorL +++");
       
   441     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetScaleFactorL - aWindow WsHandle 0x%X", aWindow.WsHandle());
       
   442     DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SetScaleFactorL - aWidthPercentage %f, aHeightPercentage %f", aWidthPercentage, aHeightPercentage);
       
   443     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetScaleFactorL - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
       
   444 
       
   445     TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
       
   446 	User::LeaveIfError(pos);
       
   447 	
       
   448 	if (aWidthPercentage <= 0.0 || aHeightPercentage <= 0.0)
       
   449 		{
       
   450 		User::Leave(KErrArgument);
       
   451 		}
       
   452 
       
   453 	iClientWindows[pos].iScaleWidth = aWidthPercentage;
       
   454 	iClientWindows[pos].iScaleHeight = aHeightPercentage;
       
   455 	iClientWindows[pos].iAutoScaleType = EAutoScaleNone;
       
   456 	
       
   457     UpdateCropRegionL(aCropRegion, pos);
       
   458 	
       
   459     DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetScaleFactorL ---");
       
   460 	}
       
   461 	
       
   462 void CMediaClientVideoDisplayBody::GetScaleFactorL(const RWindowBase& aWindow, TReal32& aWidthPercentage, TReal32& aHeightPercentage)
       
   463 	{
       
   464 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::GetScaleFactorL +++");
       
   465 	TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
       
   466 	User::LeaveIfError(pos);
       
   467 	
       
   468 	aWidthPercentage = iClientWindows[pos].iScaleWidth;
       
   469 	aHeightPercentage = iClientWindows[pos].iScaleHeight;
       
   470 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::GetScaleFactorL ---");
       
   471 	}
       
   472 
       
   473 void CMediaClientVideoDisplayBody::SetAutoScaleL(TAutoScaleType aScaleType, TInt aHorizPos, TInt aVertPos, const TRect& aCropRegion)
       
   474 	{
       
   475 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetAutoScaleL +++");
       
   476     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetAutoScaleL - aScaleType %d", aScaleType);
       
   477     DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SetAutoScaleL - aHorizPos %d, aVertPos %d", aHorizPos, aVertPos);
       
   478     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetAutoScaleL - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
       
   479 	
       
   480     TRect prevCropRegion(iCropRegion);
   319 	iCropRegion = aCropRegion;
   481 	iCropRegion = aCropRegion;
   320 	
   482 	TInt count = iClientWindows.Count();
   321 	if (IsSurfaceCreated() && !iExtDisplayConnected)
       
   322 		{
       
   323 		User::LeaveIfError(SetBackgroundSurface(iWindows[pos], aCropRegion));
       
   324 		}
       
   325 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetAutoScaleL ---"));
       
   326 	}
       
   327 	
       
   328 
       
   329 void CMediaClientVideoDisplayBody::SetRotationL(const RWindowBase& aWindow, TVideoRotation aRotation, const TRect& aCropRegion)
       
   330 	{
       
   331 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetRotationL +++"));
       
   332 	TInt pos = iWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
       
   333 	User::LeaveIfError(pos);
       
   334 	
       
   335 	iWindows[pos].iRotation = aRotation;
       
   336 	iCropRegion = aCropRegion;
       
   337 	
       
   338     if (IsSurfaceCreated() && !iExtDisplayConnected)
       
   339 		{
       
   340 		User::LeaveIfError(SetBackgroundSurface(iWindows[pos], aCropRegion));
       
   341 		}
       
   342 	
       
   343 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetRotationL ---"));
       
   344 	}
       
   345 
       
   346 TVideoRotation CMediaClientVideoDisplayBody::RotationL(const RWindowBase& aWindow)
       
   347 	{
       
   348 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RotationL +++"));
       
   349 	TInt pos = iWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
       
   350 	User::LeaveIfError(pos);
       
   351 	
       
   352 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RotationL ---"));
       
   353 	return iWindows[pos].iRotation;
       
   354 	}
       
   355 
       
   356 void CMediaClientVideoDisplayBody::SetScaleFactorL(const RWindowBase& aWindow, TReal32 aWidthPercentage, TReal32 aHeightPercentage, const TRect& aCropRegion)
       
   357 	{
       
   358 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetScaleFactorL +++"));
       
   359 	TInt pos = iWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
       
   360 	User::LeaveIfError(pos);
       
   361 	
       
   362 	if (aWidthPercentage <= 0.0 || aHeightPercentage <= 0.0)
       
   363 		{
       
   364 		User::Leave(KErrArgument);
       
   365 		}
       
   366 
       
   367 	
       
   368 	iWindows[pos].iScaleWidth = aWidthPercentage;
       
   369 	iWindows[pos].iScaleHeight = aHeightPercentage;
       
   370 	iWindows[pos].iAutoScaleType = EAutoScaleNone;
       
   371 	iCropRegion = aCropRegion;
       
   372 	
       
   373     if (IsSurfaceCreated() && !iExtDisplayConnected)
       
   374 		{
       
   375 		User::LeaveIfError(SetBackgroundSurface(iWindows[pos], aCropRegion));
       
   376 		}
       
   377 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetScaleFactorL ---"));
       
   378 	}
       
   379 	
       
   380 void CMediaClientVideoDisplayBody::GetScaleFactorL(const RWindowBase& aWindow, TReal32& aWidthPercentage, TReal32& aHeightPercentage)
       
   381 	{
       
   382 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::GetScaleFactorL +++"));
       
   383 	TInt pos = iWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
       
   384 	User::LeaveIfError(pos);
       
   385 	
       
   386 	aWidthPercentage = iWindows[pos].iScaleWidth;
       
   387 	aHeightPercentage = iWindows[pos].iScaleHeight;
       
   388 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::GetScaleFactorL ---"));
       
   389 	}
       
   390 
       
   391 void CMediaClientVideoDisplayBody::SetAutoScaleL(TAutoScaleType aScaleType, TInt aHorizPos, TInt aVertPos, const TRect& aCropRegion)
       
   392 	{
       
   393 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetAutoScaleL +++"));
       
   394 	
       
   395 	iCropRegion = aCropRegion;
       
   396 	TInt count = iWindows.Count();
       
   397 	
   483 	
   398 	for (TInt i = 0; i < count; ++i)
   484 	for (TInt i = 0; i < count; ++i)
   399 		{
   485 		{
   400 		iWindows[i].iAutoScaleType = aScaleType;
   486 		iClientWindows[i].iAutoScaleType = aScaleType;
   401 		iWindows[i].iHorizPos = aHorizPos;
   487 		iClientWindows[i].iHorizPos = aHorizPos;
   402 		iWindows[i].iVertPos = aVertPos;
   488 		iClientWindows[i].iVertPos = aVertPos;
   403 	    if (IsSurfaceCreated() && !iExtDisplayConnected)
   489 	    if (IsSurfaceCreated() && (!iExtDisplayConnected || !iExtDisplayHandler))
   404 			{
   490 			{
   405 			User::LeaveIfError(SetBackgroundSurface(iWindows[i], aCropRegion));
   491 			User::LeaveIfError(SetBackgroundSurface(iClientWindows[i], aCropRegion));
   406 			}
   492 			}
   407 		}
   493 		}
   408 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetAutoScaleL ---"));
   494 	
       
   495 	if (IsSurfaceCreated() && iExtDisplayConnected && iExtDisplayHandler && (aCropRegion != prevCropRegion))
       
   496         {
       
   497         User::LeaveIfError(RedrawWindows(aCropRegion));
       
   498         }
       
   499 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetAutoScaleL ---");
   409 	}
   500 	}
   410 
   501 
   411 
   502 
   412 void CMediaClientVideoDisplayBody::SetRotationL(TVideoRotation aRotation, const TRect& aCropRegion)
   503 void CMediaClientVideoDisplayBody::SetRotationL(TVideoRotation aRotation, const TRect& aCropRegion)
   413 	{
   504 	{
   414 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetRotationL +++"));
   505 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetRotationL +++");
   415 	iCropRegion = aCropRegion;
   506     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetRotationL - aRotation %d", aRotation);
   416 	TInt count = iWindows.Count();
   507     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetRotationL - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
       
   508 
       
   509     TRect prevCropRegion(iCropRegion);
       
   510     iCropRegion = aCropRegion;
       
   511 	TInt count = iClientWindows.Count();
   417 	
   512 	
   418 	for (TInt i = 0; i < count; ++i)
   513 	for (TInt i = 0; i < count; ++i)
   419 		{
   514 		{
   420 		iWindows[i].iRotation = aRotation;
   515 		iClientWindows[i].iRotation = aRotation;
   421 	    if (IsSurfaceCreated() && !iExtDisplayConnected)
   516         if (IsSurfaceCreated() && (!iExtDisplayConnected || !iExtDisplayHandler))
   422 			{
   517 			{
   423 			User::LeaveIfError(SetBackgroundSurface(iWindows[i], aCropRegion));
   518 			User::LeaveIfError(SetBackgroundSurface(iClientWindows[i], aCropRegion));
   424 			}
   519 			}
   425 		}
   520 		}
   426 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetRotationL ---"));
   521 	
       
   522     if (IsSurfaceCreated() && iExtDisplayConnected && iExtDisplayHandler && (aCropRegion != prevCropRegion))
       
   523         {
       
   524         User::LeaveIfError(RedrawWindows(aCropRegion));
       
   525         }
       
   526 	   
       
   527 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetRotationL ---");
   427 	}
   528 	}
   428 		
   529 		
   429 void CMediaClientVideoDisplayBody::SetScaleFactorL(TReal32 aWidthPercentage, TReal32 aHeightPercentage, const TRect& aCropRegion)
   530 void CMediaClientVideoDisplayBody::SetScaleFactorL(TReal32 aWidthPercentage, TReal32 aHeightPercentage, const TRect& aCropRegion)
   430 	{
   531 	{
   431 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetScaleFactorL +++"));
   532 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetScaleFactorL +++");
   432 	if (aWidthPercentage <= 0.0 || aHeightPercentage <= 0.0)
   533     DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SetScaleFactorL - aWidthPercentage %f, aHeightPercentage %f", aWidthPercentage, aHeightPercentage);
       
   534     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetScaleFactorL - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
       
   535 
       
   536     if (aWidthPercentage <= 0.0 || aHeightPercentage <= 0.0)
   433 		{
   537 		{
   434 		User::Leave(KErrArgument);
   538 		User::Leave(KErrArgument);
   435 		}
   539 		}
   436 	
   540 	
       
   541     TRect prevCropRegion(iCropRegion);
   437 	iCropRegion = aCropRegion;
   542 	iCropRegion = aCropRegion;
   438 	TInt count = iWindows.Count();
   543 	TInt count = iClientWindows.Count();
   439 	
   544 	
   440 	for (TInt i = 0; i < count; ++i)
   545 	for (TInt i = 0; i < count; ++i)
   441 		{
   546 		{
   442 		iWindows[i].iScaleWidth = aWidthPercentage;
   547 		iClientWindows[i].iScaleWidth = aWidthPercentage;
   443 		iWindows[i].iScaleHeight = aHeightPercentage;
   548 		iClientWindows[i].iScaleHeight = aHeightPercentage;
   444 		iWindows[i].iAutoScaleType = EAutoScaleNone;
   549 		iClientWindows[i].iAutoScaleType = EAutoScaleNone;
   445 	    if (IsSurfaceCreated() && !iExtDisplayConnected)
   550         if (IsSurfaceCreated() && (!iExtDisplayConnected || !iExtDisplayHandler))
   446 			{
   551 			{
   447 			User::LeaveIfError(SetBackgroundSurface(iWindows[i], aCropRegion));
   552 			User::LeaveIfError(SetBackgroundSurface(iClientWindows[i], aCropRegion));
   448 			}
   553 			}
   449 		}
   554 		}
   450 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetScaleFactorL ---"));
   555 	
       
   556     if (IsSurfaceCreated() && iExtDisplayConnected && iExtDisplayHandler && (aCropRegion != prevCropRegion))
       
   557         {
       
   558         User::LeaveIfError(RedrawWindows(aCropRegion));
       
   559         }
       
   560 	   
       
   561 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetScaleFactorL ---");
   451 	}
   562 	}
   452 
   563 
   453 void CMediaClientVideoDisplayBody::SetWindowClipRectL(const RWindowBase& aWindow, const TRect& aWindowClipRect, const TRect& aCropRegion)
   564 void CMediaClientVideoDisplayBody::SetWindowClipRectL(const RWindowBase& aWindow, const TRect& aWindowClipRect, const TRect& aCropRegion)
   454 	{
   565 	{
   455 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetWindowClipRectL +++"));
   566 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetWindowClipRectL +++");
   456 	
   567     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetWindowClipRectL - aWindow WsHandle 0x%X", aWindow.WsHandle());
   457 	TInt pos = iWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
   568     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetWindowClipRectL - aWindowClipRect %d,%d - %d,%d", aWindowClipRect.iTl.iX, aWindowClipRect.iTl.iY, aWindowClipRect.iBr.iX, aWindowClipRect.iBr.iY);
       
   569     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetWindowClipRectL - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
       
   570 	
       
   571 	TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
   458 	User::LeaveIfError(pos);
   572 	User::LeaveIfError(pos);
   459 	
   573 	
   460 	iWindows[pos].iClipRect = aWindowClipRect;
   574 	iClientWindows[pos].iClipRect = aWindowClipRect;
   461 	iCropRegion = aCropRegion;
   575 
   462 	
   576     UpdateCropRegionL(aCropRegion, pos);
   463     if (IsSurfaceCreated() && !iExtDisplayConnected)
   577 
   464 		{
   578     DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetWindowClipRectL ---");
   465 		User::LeaveIfError(SetBackgroundSurface(iWindows[pos], aCropRegion));
       
   466 		}
       
   467 	
       
   468 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetWindowClipRectL ---"));
       
   469 	}
   579 	}
   470 	
   580 	
   471 void CMediaClientVideoDisplayBody::SetVideoExtentL(const RWindowBase& aWindow, const TRect& aVideoExtent, const TRect& aCropRegion)
   581 void CMediaClientVideoDisplayBody::SetVideoExtentL(const RWindowBase& aWindow, const TRect& aVideoExtent, const TRect& aCropRegion)
   472 	{
   582 	{
   473 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetVideoExtentL +++"));
   583 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetVideoExtentL +++");
   474 	TInt pos = iWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
   584     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetVideoExtentL - aWindow WsHandle 0x%X", aWindow.WsHandle());
       
   585     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetVideoExtentL - aVideoExtent %d,%d - %d,%d", aVideoExtent.iTl.iX, aVideoExtent.iTl.iY, aVideoExtent.iBr.iX, aVideoExtent.iBr.iY);
       
   586     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetVideoExtentL - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
       
   587 
       
   588     TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
   475 	User::LeaveIfError(pos);
   589 	User::LeaveIfError(pos);
   476 	
   590 	
   477 	iWindows[pos].iVideoExtent = aVideoExtent;
   591 	iClientWindows[pos].iVideoExtent = aVideoExtent;
   478 	iCropRegion = aCropRegion;
   592 
   479 	
   593     UpdateCropRegionL(aCropRegion, pos);
   480     if (IsSurfaceCreated() && !iExtDisplayConnected)
   594     
   481 		{
   595 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetVideoExtentL ---");
   482 		User::LeaveIfError(SetBackgroundSurface(iWindows[pos], aCropRegion));
       
   483 		}
       
   484 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetVideoExtentL ---"));
       
   485 	}
   596 	}
   486 	
   597 	
   487 TBool CMediaClientVideoDisplayBody::HasWindows() const
   598 TBool CMediaClientVideoDisplayBody::HasWindows() const
   488 	{
   599 	{
   489 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::HasWindows +++"));
   600 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::HasWindows +++");
   490 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::HasWindows ---"));
   601 	DEBUG_PRINTF2("CMediaClientVideoDisplayBody::HasWindows --- return %d", (iClientWindows.Count() > 0));
   491 	return (iWindows.Count() > 0);
   602 	return (iClientWindows.Count() > 0);
   492 	}
   603 	}
   493 	
   604 	
   494 TInt CMediaClientVideoDisplayBody::SetBackgroundSurface(TWindowData& aWindowData,  
   605 TInt CMediaClientVideoDisplayBody::SetBackgroundSurface(TWindowData& aWindowData,  
   495 									const TRect& aCropRegion)
   606 									const TRect& aCropRegion)
   496 	{
   607 	{
   497 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetBackgroundSurface +++"));
   608 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetBackgroundSurface +++");
       
   609     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetBackgroundSurface - iWindow WsHandle 0x%X", aWindowData.iWindow->WsHandle());
       
   610     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);
       
   611     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);
       
   612     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);
       
   613     DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SetBackgroundSurface - iScaleWidth %f, iScaleHeight %f", aWindowData.iScaleWidth, aWindowData.iScaleHeight);
       
   614     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetBackgroundSurface - iRotation %d", aWindowData.iRotation);
       
   615     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetBackgroundSurface - iAutoScaleType %d", aWindowData.iAutoScaleType);
       
   616     DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SetBackgroundSurface - iHorizPos %d, iVertPos %d", aWindowData.iHorizPos, aWindowData.iVertPos);
       
   617     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetBackgroundSurface - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
   498 	
   618 	
   499 	// required as this private function is called directly from external friend class
   619 	// required as this private function is called directly from external friend class
   500 	iCropRegion = aCropRegion;
   620 	iCropRegion = aCropRegion;
   501 
   621 
   502     // viewport is the viewable area of surface
   622     // viewport is the viewable area of surface
   507         }
   627         }
   508     
   628     
   509     // Viewport is 0 size, don't show any video
   629     // Viewport is 0 size, don't show any video
   510     if (viewport.Width() <= 0 || viewport.Height() <= 0)
   630     if (viewport.Width() <= 0 || viewport.Height() <= 0)
   511         {
   631         {
       
   632         DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetBackgroundSurface --- Returned with error %d", KErrArgument);
   512         return KErrArgument;
   633         return KErrArgument;
   513         }
   634         }
   514 
   635 
   515 	TRect extent;
   636     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetBackgroundSurface - viewport1 %d,%d - %d,%d", viewport.iTl.iX, viewport.iTl.iY, viewport.iBr.iX, viewport.iBr.iY);
   516 	CalculateExtentAndViewport(aWindowData, extent, viewport);
       
   517 	
       
   518 	aWindowData.iSurfaceConfig.SetViewport(viewport);
       
   519 	aWindowData.iSurfaceConfig.SetExtent(extent);
       
   520 	aWindowData.iSurfaceConfig.SetOrientation(ConvertRotation(aWindowData.iRotation));
       
   521 	
       
   522 	aWindowData.iSurfaceConfig.SetSurfaceId(iSurfaceId);
       
   523 	
       
   524 	// Get the rectangle that bounds the crop rectangle and the viewport.  This should be
       
   525 	// the same as the crop rectangle as long as the viewport does not go outside this area.
       
   526 	TRect rect(iCropRect);
       
   527 	rect.BoundingRect(viewport);
       
   528 	TInt err = KErrNone;
       
   529 	
       
   530 	// Check if the viewport and extent can be displayed as a background surface. The viewport 
       
   531 	// is valid if it is within the crop rectangle and is not empty.  The extent is valid if 
       
   532 	// it is not empty. 
       
   533 	if (rect == iCropRect && !viewport.IsEmpty() && !extent.IsEmpty())
       
   534 		{
       
   535 		err = aWindowData.iWindow->SetBackgroundSurface(aWindowData.iSurfaceConfig, ETrue);
       
   536 		}
       
   537 
       
   538 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetBackgroundSurface ---"));
       
   539 	return err;
       
   540 	}
       
   541 
       
   542 void CMediaClientVideoDisplayBody::CalculateExtentAndViewport(const TWindowData& aWindowData, TRect& aExtent, TRect& aViewport)
       
   543     {
       
   544     DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::CalculateExtentAndViewport +++"));
       
   545 
   637 
   546     TRect videoExtent(aWindowData.iVideoExtent);
   638     TRect videoExtent(aWindowData.iVideoExtent);
   547     
   639     
   548     TReal32 inputWidth = 0.0f;
   640     TReal32 inputWidth = 0.0f;
   549     TReal32 inputHeight = 0.0f;
   641     TReal32 inputHeight = 0.0f;
   550     TReal32 pixelAspectRatio = 0.0f;
   642     TReal32 pixelAspectRatio = 0.0f;
   551     switch (aWindowData.iRotation)
   643     switch (aWindowData.iRotation)
   552         {
   644         {
   553         case EVideoRotationNone:
   645         case EVideoRotationNone:
   554         case EVideoRotationClockwise180:
   646         case EVideoRotationClockwise180:
   555             inputWidth = static_cast<TReal32>(aViewport.Width());
   647             inputWidth = static_cast<TReal32>(viewport.Width());
   556             inputHeight = static_cast<TReal32>(aViewport.Height());
   648             inputHeight = static_cast<TReal32>(viewport.Height());
   557             pixelAspectRatio = static_cast<TReal32>(iAspectRatio.iNumerator) / iAspectRatio.iDenominator;
   649             pixelAspectRatio = static_cast<TReal32>(iAspectRatio.iNumerator) / iAspectRatio.iDenominator;
   558             break;
   650             break;
   559         case EVideoRotationClockwise90:
   651         case EVideoRotationClockwise90:
   560         case EVideoRotationClockwise270:
   652         case EVideoRotationClockwise270:
   561             inputWidth = static_cast<TReal32>(aViewport.Height());
   653             inputWidth = static_cast<TReal32>(viewport.Height());
   562             inputHeight = static_cast<TReal32>(aViewport.Width());
   654             inputHeight = static_cast<TReal32>(viewport.Width());
   563             pixelAspectRatio = static_cast<TReal32>(iAspectRatio.iDenominator) / iAspectRatio.iNumerator;
   655             pixelAspectRatio = static_cast<TReal32>(iAspectRatio.iDenominator) / iAspectRatio.iNumerator;
   564             break;
   656             break;
   565         default:
   657         default:
   566             // Should never get to default unless there's been some programming error.
   658             // Should never get to default unless there's been some programming error.
   567             User::Invariant();
   659             User::Invariant();
   568             break;
   660             break;
   569         }
   661         }
   570         
   662     
   571     TReal32 viewportAspect = pixelAspectRatio * inputWidth / inputHeight;
   663     TReal32 viewportAspect = pixelAspectRatio * inputWidth / inputHeight;
   572     TReal32 vidextAspect = static_cast<TReal32>(videoExtent.Width()) / static_cast<TReal32>(videoExtent.Height());
   664     TReal32 vidextAspect = static_cast<TReal32>(videoExtent.Width()) / static_cast<TReal32>(videoExtent.Height());
   573     
   665     
       
   666     DEBUG_PRINTF4("CMediaClientVideoDisplayBody::SetBackgroundSurface - inputWidth %f, inputHeight %f, PAR %f", inputWidth, inputHeight, pixelAspectRatio);
       
   667     DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SetBackgroundSurface - viewportAspect %f, vidextAspect %f", viewportAspect, vidextAspect);
       
   668 
   574     // Set the extent to the display area in the window.  The final height and with is to 
   669     // Set the extent to the display area in the window.  The final height and with is to 
   575     // be changed by deltaHeight and deltaWidth respectively.
   670     // be changed by deltaHeight and deltaWidth respectively.
   576     aExtent = videoExtent;
   671     TRect extent(videoExtent);
   577     
   672 
   578     TInt deltaHeight = 0;
   673     TInt deltaHeight = 0;
   579     TInt deltaWidth = 0;
   674     TInt deltaWidth = 0;
   580     
   675     
   581     if (aWindowData.iAutoScaleType == EAutoScaleBestFit)
   676     if (aWindowData.iAutoScaleType == EAutoScaleBestFit)
   582         {
   677         {
   583         if (viewportAspect > vidextAspect)
   678         if (viewportAspect > vidextAspect)
   584             {
   679             {
   585             // Shrink height to get the correct aspect ratio
   680             // Shrink height to get the correct aspect ratio
   586             deltaHeight = (TInt) (aExtent.Width() / viewportAspect - aExtent.Height());
   681             deltaHeight = (TInt) (extent.Width() / viewportAspect - extent.Height());
   587             }
   682             }
   588         else
   683         else
   589             {
   684             {
   590             // Shrink width to get the correct aspect ratio
   685             // Shrink width to get the correct aspect ratio
   591             deltaWidth = (TInt) (aExtent.Height() * viewportAspect - aExtent.Width());
   686             deltaWidth = (TInt) (extent.Height() * viewportAspect - extent.Width());
   592             }
   687             }
   593         }
   688         }
   594     else if (aWindowData.iAutoScaleType == EAutoScaleClip)
   689     else if (aWindowData.iAutoScaleType == EAutoScaleClip)
   595         {
   690         {
   596         if (viewportAspect > vidextAspect)
   691         if (viewportAspect > vidextAspect)
   597             {
   692             {
   598             // Expand width to get the correct aspect ratio
   693             // Expand width to get the correct aspect ratio
   599             deltaWidth = (TInt) (aExtent.Height() * viewportAspect - aExtent.Width());
   694             deltaWidth = (TInt) (extent.Height() * viewportAspect - extent.Width());
   600             }
   695             }
   601         else
   696         else
   602             {
   697             {
   603             // Expand height to get the correct aspect ratio
   698             // Expand height to get the correct aspect ratio
   604             deltaHeight = (TInt) (aExtent.Width() / viewportAspect - aExtent.Height());
   699             deltaHeight = (TInt) (extent.Width() / viewportAspect - extent.Height());
   605             }
   700             }
   606         }
   701         }
   607     else if (aWindowData.iAutoScaleType == EAutoScaleStretch)
   702     else if (aWindowData.iAutoScaleType == EAutoScaleStretch)
   608         {
   703         {
   609         // Don't do anything: the extent is already set to the size of the video extent.
   704         // Don't do anything: the extent is already set to the size of the video extent.
   622             }
   717             }
   623         deltaHeight = (TInt) (inputHeight * aWindowData.iScaleHeight * 0.01 - videoExtent.Height());
   718         deltaHeight = (TInt) (inputHeight * aWindowData.iScaleHeight * 0.01 - videoExtent.Height());
   624         deltaWidth = (TInt) (inputWidth * aWindowData.iScaleWidth * 0.01 - videoExtent.Width());
   719         deltaWidth = (TInt) (inputWidth * aWindowData.iScaleWidth * 0.01 - videoExtent.Width());
   625         }
   720         }
   626     
   721     
       
   722     DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SetBackgroundSurface - deltaWidth %d, deltaHeight %d", deltaWidth, deltaHeight);
       
   723 
   627     // Change the width of the extent in the proper directions and propertions.
   724     // Change the width of the extent in the proper directions and propertions.
   628     switch (aWindowData.iHorizPos)
   725     switch (aWindowData.iHorizPos)
   629         {
   726         {
   630     case EHorizontalAlignCenter:
   727     case EHorizontalAlignCenter:
   631         aExtent.iTl.iX -= deltaWidth / 2;
   728         extent.iTl.iX -= deltaWidth / 2;
   632         aExtent.iBr.iX += deltaWidth / 2;
   729         extent.iBr.iX += deltaWidth / 2;
   633         break;
   730         break;
   634     case EHorizontalAlignLeft:
   731     case EHorizontalAlignLeft:
   635         aExtent.iBr.iX += deltaWidth;
   732         extent.iBr.iX += deltaWidth;
   636         break;
   733         break;
   637     case EHorizontalAlignRight:
   734     case EHorizontalAlignRight:
   638         aExtent.iTl.iX -= deltaWidth;
   735         extent.iTl.iX -= deltaWidth;
   639         break;
   736         break;
   640     default:
   737     default:
   641         TInt width = aExtent.Width() + deltaWidth;
   738         TInt width = extent.Width() + deltaWidth;
   642         aExtent.iTl.iX += aWindowData.iHorizPos;
   739         extent.iTl.iX += aWindowData.iHorizPos;
   643         aExtent.iBr.iX = aExtent.iTl.iX + width;
   740         extent.iBr.iX = extent.iTl.iX + width;
   644         break;
   741         break;
   645         }
   742         }
   646     
   743     
   647     // Change the height of the extent in the proper directions and propertions.
   744     // Change the height of the extent in the proper directions and propertions.
   648     switch (aWindowData.iVertPos)
   745     switch (aWindowData.iVertPos)
   649         {
   746         {
   650     case EVerticalAlignCenter:
   747     case EVerticalAlignCenter:
   651         aExtent.iTl.iY -= deltaHeight / 2;
   748         extent.iTl.iY -= deltaHeight / 2;
   652         aExtent.iBr.iY += deltaHeight / 2;
   749         extent.iBr.iY += deltaHeight / 2;
   653         break;
   750         break;
   654     case EVerticalAlignTop:
   751     case EVerticalAlignTop:
   655         aExtent.iBr.iY += deltaHeight;
   752         extent.iBr.iY += deltaHeight;
   656         break;
   753         break;
   657     case EVerticalAlignBottom:
   754     case EVerticalAlignBottom:
   658         aExtent.iTl.iY -= deltaHeight;
   755         extent.iTl.iY -= deltaHeight;
   659         break;
   756         break;
   660     default:
   757     default:
   661         TInt height = aExtent.Height() + deltaHeight;
   758         TInt height = extent.Height() + deltaHeight;
   662         aExtent.iTl.iY += aWindowData.iVertPos;
   759         extent.iTl.iY += aWindowData.iVertPos;
   663         aExtent.iBr.iY = aExtent.iTl.iY + height;
   760         extent.iBr.iY = extent.iTl.iY + height;
   664         break;
   761         break;
   665         }
   762         }
   666         
   763         
       
   764     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetBackgroundSurface - extent1 %d,%d - %d,%d", extent.iTl.iX, extent.iTl.iY, extent.iBr.iX, extent.iBr.iY);
       
   765 
   667     // The video should not be displayed outside the intended video extent or clipping rectangle.  
   766     // The video should not be displayed outside the intended video extent or clipping rectangle.  
   668     // The extent already has the correct size and position for displaying the entire viewport.  
   767     // The extent already has the correct size and position for displaying the entire viewport.  
   669     // The viewport is clipped such that the video is not moved/distorted when we take the extent 
   768     // The viewport is clipped such that the video is not moved/distorted when we take the extent 
   670     // to be the intersection of itself and the intended video extent.
   769     // to be the intersection of itself and the intended video extent.
   671     
   770     
   672     TRect viewableArea(videoExtent);
   771     TRect viewableArea(videoExtent);
   673     viewableArea.Intersection(aWindowData.iClipRect);
   772     viewableArea.Intersection(aWindowData.iClipRect);
   674     
   773     
       
   774     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetBackgroundSurface - viewableArea %d,%d - %d,%d", viewableArea.iTl.iX, viewableArea.iTl.iY, viewableArea.iBr.iX, viewableArea.iBr.iY);
       
   775 
   675     // Number of pixels (in window coordinates) to be clipped on the right, bottom, top and left sides of
   776     // Number of pixels (in window coordinates) to be clipped on the right, bottom, top and left sides of
   676     // the video.
   777     // the video.
   677     TInt dr = Max(0, aExtent.iBr.iX - viewableArea.iBr.iX);
   778     TInt dr = Max(0, extent.iBr.iX - viewableArea.iBr.iX);
   678     TInt db = Max(0, aExtent.iBr.iY - viewableArea.iBr.iY);
   779     TInt db = Max(0, extent.iBr.iY - viewableArea.iBr.iY);
   679     TInt dt = Max(0, viewableArea.iTl.iY - aExtent.iTl.iY);
   780     TInt dt = Max(0, viewableArea.iTl.iY - extent.iTl.iY);
   680     TInt dl = Max(0, viewableArea.iTl.iX - aExtent.iTl.iX);
   781     TInt dl = Max(0, viewableArea.iTl.iX - extent.iTl.iX);
   681     
   782     
       
   783     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetBackgroundSurface - dr %d, db %d, dt %d, dl %d", dr, db, dt, dl);
       
   784 
   682     // Calculate the number of pixels in the video per window pixel in both x and y directions.
   785     // Calculate the number of pixels in the video per window pixel in both x and y directions.
   683     TReal32 wRatio = 0.0f; 
   786     TReal32 wRatio = 0.0f; 
   684     TReal32 hRatio = 0.0f;
   787     TReal32 hRatio = 0.0f;
   685     
   788 
   686     // Make sure we don't divide by 0
   789     // Make sure we don't divide by 0
   687     if (aExtent.Width() != 0)
   790     if (extent.Width() != 0)
   688         {
   791         {
   689         wRatio = inputWidth / static_cast<TReal32>(aExtent.Width());
   792         wRatio = inputWidth / static_cast<TReal32>(extent.Width());
   690         }
   793         }
   691     
   794     
   692     if (aExtent.Height() != 0)
   795     if (extent.Height() != 0)
   693         {
   796         {
   694         hRatio = inputHeight / static_cast<TReal32>(aExtent.Height());
   797         hRatio = inputHeight / static_cast<TReal32>(extent.Height());
   695         }
   798         }
   696     
   799     
       
   800     DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SetBackgroundSurface - wRatio %f, hRatio %f", wRatio, hRatio);
       
   801 
   697     // Clip the viewport 
   802     // Clip the viewport 
   698     switch (aWindowData.iRotation)
   803     switch (aWindowData.iRotation)
   699         {
   804     {
   700         case EVideoRotationNone:
   805     case EVideoRotationNone:
   701             aViewport.iBr.iX -= (TInt) (wRatio * static_cast<TReal32>(dr));
   806         viewport.iBr.iX -= (TInt) (wRatio * static_cast<TReal32>(dr));
   702             aViewport.iBr.iY -= (TInt) (hRatio * static_cast<TReal32>(db));
   807         viewport.iBr.iY -= (TInt) (hRatio * static_cast<TReal32>(db));
   703             aViewport.iTl.iX += (TInt) (wRatio * static_cast<TReal32>(dl));
   808         viewport.iTl.iX += (TInt) (wRatio * static_cast<TReal32>(dl));
   704             aViewport.iTl.iY += (TInt) (hRatio * static_cast<TReal32>(dt));
   809         viewport.iTl.iY += (TInt) (hRatio * static_cast<TReal32>(dt));
   705             break;
   810         break;
   706         case EVideoRotationClockwise180:
   811     case EVideoRotationClockwise180:
   707             aViewport.iBr.iX -= (TInt) (wRatio * static_cast<TReal32>(dl));
   812         viewport.iBr.iX -= (TInt) (wRatio * static_cast<TReal32>(dl));
   708             aViewport.iBr.iY -= (TInt) (hRatio * static_cast<TReal32>(dt));
   813         viewport.iBr.iY -= (TInt) (hRatio * static_cast<TReal32>(dt));
   709             aViewport.iTl.iX += (TInt) (wRatio * static_cast<TReal32>(dr));
   814         viewport.iTl.iX += (TInt) (wRatio * static_cast<TReal32>(dr));
   710             aViewport.iTl.iY += (TInt) (hRatio * static_cast<TReal32>(db));
   815         viewport.iTl.iY += (TInt) (hRatio * static_cast<TReal32>(db));
   711             break;
   816         break;
   712         case EVideoRotationClockwise90:
   817     case EVideoRotationClockwise90:
   713             aViewport.iBr.iX -= (TInt) (wRatio * static_cast<TReal32>(db));
   818         viewport.iBr.iX -= (TInt) (wRatio * static_cast<TReal32>(db));
   714             aViewport.iBr.iY -= (TInt) (hRatio * static_cast<TReal32>(dl));
   819         viewport.iBr.iY -= (TInt) (hRatio * static_cast<TReal32>(dl));
   715             aViewport.iTl.iX += (TInt) (wRatio * static_cast<TReal32>(dt));
   820         viewport.iTl.iX += (TInt) (wRatio * static_cast<TReal32>(dt));
   716             aViewport.iTl.iY += (TInt) (hRatio * static_cast<TReal32>(dr));
   821         viewport.iTl.iY += (TInt) (hRatio * static_cast<TReal32>(dr));
   717             break;
   822         break;
   718         case EVideoRotationClockwise270:
   823     case EVideoRotationClockwise270:
   719             aViewport.iBr.iX -= (TInt) (wRatio * static_cast<TReal32>(dt));
   824         viewport.iBr.iX -= (TInt) (wRatio * static_cast<TReal32>(dt));
   720             aViewport.iBr.iY -= (TInt) (hRatio * static_cast<TReal32>(dr));
   825         viewport.iBr.iY -= (TInt) (hRatio * static_cast<TReal32>(dr));
   721             aViewport.iTl.iX += (TInt) (wRatio * static_cast<TReal32>(db));
   826         viewport.iTl.iX += (TInt) (wRatio * static_cast<TReal32>(db));
   722             aViewport.iTl.iY += (TInt) (hRatio * static_cast<TReal32>(dl));
   827         viewport.iTl.iY += (TInt) (hRatio * static_cast<TReal32>(dl));
   723             break;
   828         break;
   724         default:
   829     default:
   725             // Should never get to default unless there's been some programming error.
   830         // Should never get to default unless there's been some programming error.
   726             User::Invariant();
   831         User::Invariant();
   727             break;
   832         break;
   728         }
   833     }
   729     
   834     
       
   835     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetBackgroundSurface - viewport2 %d,%d - %d,%d", viewport.iTl.iX, viewport.iTl.iY, viewport.iBr.iX, viewport.iBr.iY);
       
   836 
   730     // Clip the extent.
   837     // Clip the extent.
   731     aExtent.Intersection(viewableArea);
   838     extent.Intersection(viewableArea);
   732     
   839     
   733     DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::CalculateExtentAndViewport ---"));
   840     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetBackgroundSurface - extent2 %d,%d - %d,%d", extent.iTl.iX, extent.iTl.iY, extent.iBr.iX, extent.iBr.iY);
       
   841 
       
   842     aWindowData.iSurfaceConfig.SetViewport(viewport);
       
   843     aWindowData.iSurfaceConfig.SetExtent(extent);
       
   844     aWindowData.iSurfaceConfig.SetOrientation(ConvertRotation(aWindowData.iRotation));
       
   845     
       
   846     aWindowData.iSurfaceConfig.SetSurfaceId(iSurfaceId);
       
   847     
       
   848     // Get the rectangle that bounds the crop rectangle and the viewport.  This should be
       
   849     // the same as the crop rectangle as long as the viewport does not go outside this area.
       
   850     TRect rect(iCropRect);
       
   851     rect.BoundingRect(viewport);
       
   852     TInt err = KErrNone;
       
   853     
       
   854     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetBackgroundSurface - rect %d,%d - %d,%d", rect.iTl.iX, rect.iTl.iY, rect.iBr.iX, rect.iBr.iY);
       
   855 
       
   856     // Check if the viewport and extent can be displayed as a background surface. The viewport 
       
   857     // is valid if it is within the crop rectangle and is not empty.  The extent is valid if 
       
   858     // it is not empty. 
       
   859     if (rect == iCropRect && !viewport.IsEmpty() && !extent.IsEmpty())
       
   860         {
       
   861         DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetBackgroundSurface - Calling SetBackgroundSurface");
       
   862         err = aWindowData.iWindow->SetBackgroundSurface(aWindowData.iSurfaceConfig, ETrue);
       
   863         }
       
   864 
       
   865     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetBackgroundSurface --- err %d", err);
       
   866     return err;
   734     }
   867     }
   735 
   868 
   736 TBool CMediaClientVideoDisplayBody::IsUsed() const
   869 TBool CMediaClientVideoDisplayBody::IsUsed() const
   737 	{
   870 	{
   738 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::IsUsed +++"));
   871 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::IsUsed +++");
   739 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::IsUsed ---"));
   872 	DEBUG_PRINTF2("CMediaClientVideoDisplayBody::IsUsed --- return %d", (iEventHandler || iClientWindows.Count() > 0));
   740 	return (iEventHandler != NULL || iWindows.Count() > 0);
   873 	return (iEventHandler || iClientWindows.Count() > 0);
   741 	}
   874 	}
   742 	
   875 	
   743 
   876 
   744 TBool CMediaClientVideoDisplayBody::IsSurfaceCreated() const
   877 TBool CMediaClientVideoDisplayBody::IsSurfaceCreated() const
   745 	{
   878 	{
   746 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::IsSurfaceCreated +++"));
   879 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::IsSurfaceCreated +++");
   747 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::IsSurfaceCreated ---"));
   880     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::IsSurfaceCreated --- return %d", !(iSurfaceId.IsNull()));
   748 	return !(iSurfaceId.IsNull());
   881 	return !(iSurfaceId.IsNull());
   749 	}
   882 	}
   750 		
   883 		
   751 TInt CMediaClientVideoDisplayBody::DisplayId() const
   884 TInt CMediaClientVideoDisplayBody::DisplayId() const
   752 	{
   885 	{
   753 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::DisplayId +++"));
   886 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::DisplayId +++");
   754 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::DisplayId ---"));
   887     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::DisplayId --- return %d", iDisplayId);
   755 	return iDisplayId;
   888 	return iDisplayId;
   756 	}
   889 	}
   757 	
   890 	
   758 TInt CMediaClientVideoDisplayBody::CompareByDisplay(const TInt* aDisplayId, const CMediaClientVideoDisplayBody& aDisplay)
   891 TInt CMediaClientVideoDisplayBody::CompareByDisplay(const TInt* aDisplayId, const CMediaClientVideoDisplayBody& aDisplay)
   759 	{
   892 	{
   760 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::CompareByDisplay +++"));
   893 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::CompareByDisplay +++");
   761 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::CompareByDisplay ---"));
   894     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::CompareByDisplay --- return %d", (*aDisplayId - aDisplay.DisplayId()));
   762 	return (*aDisplayId - aDisplay.DisplayId());
   895 	return (*aDisplayId - aDisplay.DisplayId());
   763 	}
   896 	}
   764 		
   897 		
   765 TInt CMediaClientVideoDisplayBody::Compare(const CMediaClientVideoDisplayBody& aLeft, const CMediaClientVideoDisplayBody& aRight)
   898 TInt CMediaClientVideoDisplayBody::Compare(const CMediaClientVideoDisplayBody& aLeft, const CMediaClientVideoDisplayBody& aRight)
   766 	{
   899 	{
   767 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::Compare +++"));
   900 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::Compare +++");
   768 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::Compare ---"));
   901     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::Compare --- return %d", (aLeft.DisplayId() - aRight.DisplayId()));
   769 	return (aLeft.DisplayId() - aRight.DisplayId());
   902 	return (aLeft.DisplayId() - aRight.DisplayId());
   770 	}
   903 	}
   771 	
   904 	
   772 CFbsBitGc::TGraphicsOrientation CMediaClientVideoDisplayBody::ConvertRotation(TVideoRotation aRotation)
   905 CFbsBitGc::TGraphicsOrientation CMediaClientVideoDisplayBody::ConvertRotation(TVideoRotation aRotation)
   773 	{
   906 	{
   774 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::ConvertRotation +++"));
   907 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::ConvertRotation +++");
   775 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::ConvertRotation ---"));
   908 	
       
   909 	CFbsBitGc::TGraphicsOrientation orientation;
       
   910 	
   776 	switch(aRotation)
   911 	switch(aRotation)
   777 		{
   912 		{
   778 		case EVideoRotationNone:
   913 		case EVideoRotationNone:
   779 			return CFbsBitGc::EGraphicsOrientationNormal;
   914 		    orientation = CFbsBitGc::EGraphicsOrientationNormal;
       
   915 		    break;
   780 		case EVideoRotationClockwise90:
   916 		case EVideoRotationClockwise90:
   781 			return CFbsBitGc::EGraphicsOrientationRotated270;
   917 		    orientation = CFbsBitGc::EGraphicsOrientationRotated270;
       
   918 		    break;
   782 		case EVideoRotationClockwise180:
   919 		case EVideoRotationClockwise180:
   783 			return CFbsBitGc::EGraphicsOrientationRotated180;
   920 		    orientation = CFbsBitGc::EGraphicsOrientationRotated180;
       
   921 		    break;
   784 		case EVideoRotationClockwise270:
   922 		case EVideoRotationClockwise270:
   785 			return CFbsBitGc::EGraphicsOrientationRotated90;
   923 		    orientation = CFbsBitGc::EGraphicsOrientationRotated90;
       
   924 		    break;
   786 		default:
   925 		default:
   787 			// Should never get to default unless there's been some programming error.
   926 			// Should never get to default unless there's been some programming error.
   788 			User::Invariant();
   927 			User::Invariant();
   789 			// This is never reached, just to keep the compiler happy
   928 			// This is never reached, just to keep the compiler happy
   790 			return CFbsBitGc::EGraphicsOrientationNormal;
   929 			orientation = CFbsBitGc::EGraphicsOrientationNormal;
   791 		}
   930 		}
       
   931     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::ConvertRotation --- return %d", orientation);	
       
   932     return orientation;
   792 	}
   933 	}
   793 
   934 
   794 CMediaClientVideoDisplayBody* CMediaClientVideoDisplayBody::FindDisplayWithWindowL(const RPointerArray<CMediaClientVideoDisplayBody>& aDisplays, const RWindowBase& aWindow)
   935 CMediaClientVideoDisplayBody* CMediaClientVideoDisplayBody::FindDisplayWithWindowL(const RPointerArray<CMediaClientVideoDisplayBody>& aDisplays, const RWindowBase& aWindow)
   795 	{
   936 	{
   796 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::FindDisplayWithWindowL +++"));
   937 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::FindDisplayWithWindowL +++");
   797 	TInt count = aDisplays.Count();
   938 	TInt count = aDisplays.Count();
   798 	
   939 	
   799 	for (TInt i = 0; i < count; ++i)
   940 	for (TInt i = 0; i < count; ++i)
   800 		{
   941 		{
   801 		CMediaClientVideoDisplayBody* display = aDisplays[i];
   942 		CMediaClientVideoDisplayBody* display = aDisplays[i];
   802 	
   943 	
   803 		if (display->iWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle) != KErrNotFound)
   944 		if (display->iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle) != KErrNotFound)
   804 			{
   945 			{
   805 			DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::FindDisplayWithWindowL ---"));
   946 			DEBUG_PRINTF2("CMediaClientVideoDisplayBody::FindDisplayWithWindowL window found at position ", i);
       
   947 			DEBUG_PRINTF("CMediaClientVideoDisplayBody::FindDisplayWithWindowL ---");
   806 			return display;	
   948 			return display;	
   807 			}
   949 			}
   808 		}
   950 		}
   809 		
   951 		
   810 	User::Leave(KErrNotFound);
   952 	User::Leave(KErrNotFound);
   811 	return NULL;
   953 	return NULL;
   812 	}
   954 	}
   813 	
   955 	
   814 RArray<CMediaClientVideoDisplayBody::TWindowData>& CMediaClientVideoDisplayBody::Windows()
   956 RArray<CMediaClientVideoDisplayBody::TWindowData>& CMediaClientVideoDisplayBody::Windows()
   815 	{
   957 	{
   816 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::Windows +++"));
   958 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::Windows +++");
   817 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::Windows ---"));
   959 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::Windows ---");
   818 	return iWindows;	
   960 	return iClientWindows;	
   819 	}
   961 	}
   820 
   962 
   821 void CMediaClientVideoDisplayBody::MedcpcExtDisplayCalculateExtentAndViewportL(TRect& aExtent, TRect& aViewport, TRect& aExternalDisplayRect)
   963 void CMediaClientVideoDisplayBody::SetExternalDisplaySwitchingL(TBool aControl)
   822     {
   964     {
   823     DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::MedcpcExtDisplayCalculateExtentAndViewportL +++"));
   965     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetExternalDisplaySwitchingL +++ aControl=%d", aControl);
       
   966 
       
   967     // not supported
       
   968     if(!iExtDisplaySwitchingSupported)
       
   969         {
       
   970         User::Leave(KErrNotSupported);
       
   971         }
       
   972     
       
   973     // need active scheduler installed
       
   974     if(!CActiveScheduler::Current())
       
   975         {
       
   976         User::Leave(KErrNotReady);
       
   977         }
       
   978 
       
   979     if(iClientRequestedExtDisplaySwitching != aControl)
       
   980         {
       
   981         iClientRequestedExtDisplaySwitching = aControl;
       
   982         
       
   983         DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetExternalDisplaySwitchingL SurfaceCreated %d", IsSurfaceCreated());
       
   984         DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetExternalDisplaySwitchingL Client window count %d", iClientWindows.Count());
       
   985         DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetExternalDisplaySwitchingL External Display Connected %d", iExtDisplayConnected);          
       
   986         DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetExternalDisplaySwitchingL Client Requested Ext Display Switching %d", iClientRequestedExtDisplaySwitching);          
       
   987         
       
   988         if(IsSurfaceCreated() && (iClientWindows.Count() > 0) && iExtDisplayConnected)
       
   989             {
       
   990             if(iClientRequestedExtDisplaySwitching)
       
   991                 {
       
   992                 TRAPD(err, CreateExtDisplayHandlerL());
       
   993                 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetExternalDisplaySwitchingL CreateExtDisplayHandlerL error %d", err);
       
   994                 if(err == KErrNone)
       
   995                     {
       
   996                     RemoveBackgroundSurface(ETrue);
       
   997                     SetWindowArrayPtr2Ext();
       
   998                     RedrawWindows(iCropRegion);
       
   999                     }
       
  1000                 }
       
  1001             else if(iExtDisplayHandler)
       
  1002                 {
       
  1003                 RemoveBackgroundSurface(ETrue);
       
  1004                 RemoveExtDisplayHandler();
       
  1005                 SetWindowArrayPtr2Client();
       
  1006                 RedrawWindows(iCropRegion);
       
  1007                 }
       
  1008             }
       
  1009         }
       
  1010     
       
  1011     DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetExternalDisplaySwitchingL ---");
       
  1012     }
       
  1013 
       
  1014 void CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected(TBool aExtDisplayConnected)
       
  1015 	{
       
  1016 	DEBUG_PRINTF2("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected +++ aExtDisplayConnected=%d", aExtDisplayConnected);
       
  1017 	
       
  1018 	if(iExtDisplayConnected != aExtDisplayConnected)
       
  1019 	    {
       
  1020 	    iExtDisplayConnected = aExtDisplayConnected;
       
  1021 
       
  1022         if(IsSurfaceCreated() && (iClientWindows.Count() > 0) && iClientRequestedExtDisplaySwitching)
       
  1023             {
       
  1024             if(iExtDisplayConnected)
       
  1025                 {
       
  1026                 TRAPD(err, CreateExtDisplayHandlerL());
       
  1027                 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected CreateExtDisplayHandlerL error %d", err);
       
  1028                 if(err == KErrNone)
       
  1029                     {
       
  1030                     RemoveBackgroundSurface(ETrue);
       
  1031                     SetWindowArrayPtr2Ext();
       
  1032                     RedrawWindows(iCropRegion);
       
  1033                     }
       
  1034                 }
       
  1035             else if(iExtDisplayHandler)
       
  1036                 {
       
  1037                 RemoveBackgroundSurface(ETrue);
       
  1038                 RemoveExtDisplayHandler();
       
  1039                 SetWindowArrayPtr2Client();
       
  1040                 RedrawWindows(iCropRegion);
       
  1041                 }
       
  1042             }
       
  1043 	    }
       
  1044 	else
       
  1045 	    {
       
  1046 	    DEBUG_PRINTF("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected No change in ext display connection status");
       
  1047 	    }
       
  1048 	
       
  1049 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected ---");
       
  1050 	}
       
  1051 
       
  1052 void CMediaClientVideoDisplayBody::SetWindowArrayPtr2Client()
       
  1053     {
       
  1054     DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetWindowArrayPtr2Client +++");
       
  1055 
       
  1056     iWindowsArrayPtr = &iClientWindows;
       
  1057 
       
  1058     DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetWindowArrayPtr2Client ---");
       
  1059     }
       
  1060 
       
  1061 void CMediaClientVideoDisplayBody::SetWindowArrayPtr2Ext()
       
  1062     {
       
  1063     DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetWindowArrayPtr2Ext +++");
       
  1064 
       
  1065     iWindowsArrayPtr = &iExtDisplayWindows;
       
  1066 
       
  1067     DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetWindowArrayPtr2Ext ---");
       
  1068     }
       
  1069 
       
  1070 void CMediaClientVideoDisplayBody::CreateExtDisplayHandlerL()
       
  1071     {
       
  1072     DEBUG_PRINTF("CMediaClientVideoDisplayBody::CreateExtDisplayHandlerL +++");
       
  1073 
       
  1074     CMediaClientExtDisplayHandler* extDisplayHandler = CMediaClientExtDisplayHandler::NewL(iExtDisplayConnectionProvider->ExtDisplayId());
       
  1075     CleanupStack::PushL(extDisplayHandler);
   824     
  1076     
   825     TWindowData windowData;
  1077     TWindowData windowData;
   826     windowData.iVideoExtent = aExternalDisplayRect;
  1078     windowData.iWindow = extDisplayHandler->Window();
       
  1079     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::CreateExtDisplayHandlerL - iWindow WsHandle 0x%X", windowData.iWindow->WsHandle());
       
  1080     
       
  1081     TRect externalDisplayRect(TPoint(0, 0), extDisplayHandler->DisplaySizeInPixels());
       
  1082     windowData.iClipRect = externalDisplayRect;
       
  1083     windowData.iVideoExtent = externalDisplayRect;
       
  1084     // windowData.iScaleWidth not required for EAutoScaleBestFit
       
  1085     // windowData.iScaleHeight not required for EAutoScaleBestFit
   827     windowData.iRotation = EVideoRotationNone;
  1086     windowData.iRotation = EVideoRotationNone;
   828     windowData.iAutoScaleType = EAutoScaleBestFit;
  1087     windowData.iAutoScaleType = EAutoScaleBestFit;
   829     windowData.iHorizPos = EHorizontalAlignCenter;
  1088     windowData.iHorizPos = EHorizontalAlignCenter;
   830     windowData.iVertPos = EVerticalAlignCenter;
  1089     windowData.iVertPos = EVerticalAlignCenter;
   831     windowData.iClipRect = aExternalDisplayRect;
  1090     // windowData.iWindow2 not used        
   832     
  1091     
   833     aViewport = iCropRect;
  1092     iExtDisplayWindows.AppendL(windowData);
   834     // Viewport is 0 size, don't show any video
  1093     CleanupStack::Pop(extDisplayHandler);
   835     if (aViewport.Width() <= 0 || aViewport.Height() <= 0)
  1094     iExtDisplayHandler = extDisplayHandler;
   836         {
  1095     
   837         User::Leave(KErrArgument);
  1096     DEBUG_PRINTF("CMediaClientVideoDisplayBody::CreateExtDisplayHandlerL ---");
   838         }
       
   839     
       
   840     CalculateExtentAndViewport(windowData, aExtent, aViewport);
       
   841     
       
   842     DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::MedcpcExtDisplayCalculateExtentAndViewportL ---"));
       
   843     }
  1097     }
   844 
  1098 
   845 void CMediaClientVideoDisplayBody::CreateExtDisplayConnProvAndRemoveSurfaceL(TBool aRemoveBackgroundSurface)
  1099 void CMediaClientVideoDisplayBody::RemoveExtDisplayHandler()
   846     {
  1100     {
   847     DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::CreateExtDisplayConnProvAndRemoveSurfaceL +++"));
  1101     DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveExtDisplayHandler +++");
   848 
  1102 
   849     if((iExtDisplayConnectionProvider == NULL) && (iWindows.Count() > 0))
  1103     delete iExtDisplayHandler;
   850         {
  1104     iExtDisplayHandler = NULL;
   851         iExtDisplayConnectionProvider = CExtDisplayConnectionProviderInterface::NewL(*this, iSurfaceId);
  1105     iExtDisplayWindows.Reset();
   852         iExtDisplayConnected = iExtDisplayConnectionProvider->ExtDisplayConnectedL();
  1106 
   853         
  1107     DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveExtDisplayHandler ---");
   854         if(iExtDisplayConnected && aRemoveBackgroundSurface)
       
   855             {
       
   856             RemoveBackgroundSurface(ETrue);
       
   857             }
       
   858         }
       
   859 
       
   860     DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::CreateExtDisplayConnProvAndRemoveSurfaceL ---"));
       
   861     }
  1108     }
   862    
  1109 
   863 void CMediaClientVideoDisplayBody::RemoveExtDisplayConnProvAndRedrawL()
  1110 void CMediaClientVideoDisplayBody::CreateExtDisplayPluginL()
   864     {
  1111     {
   865     DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RemoveExtDisplayConnProvAndRedrawL +++"));
  1112     DEBUG_PRINTF("CMediaClientVideoDisplayBody::CreateExtDisplayPluginL +++");
   866 
  1113     
   867     if(iExtDisplayConnectionProvider != NULL)
  1114     iExtDisplayConnectionProvider = CExtDisplayConnectionProviderInterface::NewL();
       
  1115     
       
  1116     if(iExtDisplayConnectionProvider)
       
  1117         {
       
  1118         iExtDisplaySwitchingSupported = ETrue;
       
  1119         iExtDisplayConnectionProvider->SetExtDisplayConnectionProviderCallback(*this);
       
  1120         iExtDisplayConnected = iExtDisplayConnectionProvider->ExtDisplayConnected();
       
  1121         }
       
  1122 
       
  1123     DEBUG_PRINTF("CMediaClientVideoDisplayBody::CreateExtDisplayPluginL ---");
       
  1124     }
       
  1125 
       
  1126 void CMediaClientVideoDisplayBody::RemoveExtDisplayPlugin()
       
  1127     {
       
  1128     DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveExtDisplayPlugin +++");
       
  1129     
       
  1130     if(iExtDisplaySwitchingSupported)
   868         {
  1131         {
   869         delete iExtDisplayConnectionProvider;
  1132         delete iExtDisplayConnectionProvider;
   870         REComSession::FinalClose();
       
   871         iExtDisplayConnectionProvider = NULL;
  1133         iExtDisplayConnectionProvider = NULL;
       
  1134         iExtDisplaySwitchingSupported = EFalse;
   872         iExtDisplayConnected = EFalse;
  1135         iExtDisplayConnected = EFalse;
   873         User::LeaveIfError(RedrawWindows(iCropRegion));
  1136         }    
   874         }
  1137     DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveExtDisplayPlugin ---");
   875 
       
   876     DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RemoveExtDisplayConnProvAndRedrawL ---"));
       
   877     }
  1138     }
   878 
       
   879 void CMediaClientVideoDisplayBody::RemoveExtDisplayConnProv()
       
   880     {
       
   881     DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RemoveExtDisplayConnProv +++"));
       
   882 
       
   883     if(iExtDisplayConnectionProvider != NULL)
       
   884         {
       
   885         delete iExtDisplayConnectionProvider;
       
   886         REComSession::FinalClose();
       
   887         iExtDisplayConnectionProvider = NULL;
       
   888         iExtDisplayConnected = EFalse;
       
   889         }
       
   890 
       
   891     DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RemoveExtDisplayConnProv ---"));
       
   892     }
       
   893 
       
   894 void CMediaClientVideoDisplayBody::SetExternalDisplaySwitchingL(TBool aControl)
       
   895     {
       
   896     DEBUG_PRINT2(_L("CMediaClientVideoDisplayBody::SetExternalDisplaySwitchingL +++ aControl=%d"), aControl);
       
   897 
       
   898     // not supported
       
   899     if(!iExtDisplaySwitchingSupported)
       
   900         {
       
   901         User::Leave(KErrNotSupported);
       
   902         }
       
   903     
       
   904     // need active scheduler installed
       
   905     if(CActiveScheduler::Current() == NULL)
       
   906         {
       
   907         User::Leave(KErrNotReady);
       
   908         }
       
   909 
       
   910     if(iClientRequestedExtDisplaySwitching != aControl)
       
   911         {
       
   912         iClientRequestedExtDisplaySwitching = aControl;
       
   913         
       
   914         if(IsSurfaceCreated())
       
   915             {
       
   916             if(iClientRequestedExtDisplaySwitching)
       
   917                 {
       
   918                 CreateExtDisplayConnProvAndRemoveSurfaceL(ETrue);
       
   919                 }
       
   920             else
       
   921                 {
       
   922                 RemoveExtDisplayConnProvAndRedrawL();
       
   923                 }
       
   924             }
       
   925         else
       
   926             {
       
   927             DEBUG_PRINT(_L("No Surface exists"));
       
   928             }
       
   929         }
       
   930     
       
   931     DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetExternalDisplaySwitchingL ---"));
       
   932     }
       
   933 
       
   934 void CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected(TBool aExtDisplayConnected)
       
   935 	{
       
   936 	DEBUG_PRINT2(_L("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected +++ aExtDisplayConnected=%d"), aExtDisplayConnected);
       
   937 	
       
   938 	if(iExtDisplayConnected != aExtDisplayConnected)
       
   939 	    {
       
   940 	    iExtDisplayConnected = aExtDisplayConnected;
       
   941 	    if(iExtDisplayConnected)
       
   942 	        {
       
   943 	        RemoveBackgroundSurface(ETrue);
       
   944 	        }
       
   945 	    else
       
   946 	        {
       
   947 	        // ignore error - no need to tell provider - but lets log it in case it fails
       
   948 	        TInt err = RedrawWindows(iCropRegion);
       
   949 	        DEBUG_PRINT2(_L("RedrawWindows returned with %d"), err);
       
   950 	        }
       
   951 	    }
       
   952 	else
       
   953 	    {
       
   954 	    DEBUG_PRINT(_L("No change in ext display connection status"));
       
   955 	    }
       
   956 	
       
   957 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected ---"));
       
   958 	}