mmlibs/mmfw/src/Client/Video/mediaclientvideodisplaybody.cpp
changeset 15 c1e808730d6c
parent 13 efebd1779a59
child 24 2672ba96448e
child 26 c36d67f77f75
equal deleted inserted replaced
13:efebd1779a59 15:c1e808730d6c
    13 // Description:
    13 // Description:
    14 //
    14 //
    15 
    15 
    16 #include "mediaclientvideodisplaybody.h"
    16 #include "mediaclientvideodisplaybody.h"
    17 #include "mediaclientvideotrace.h"
    17 #include "mediaclientvideotrace.h"
       
    18 #include "mediaclientpolicyserverclient.h"
    18 #include <surfaceeventhandler.h>
    19 #include <surfaceeventhandler.h>
    19 #include <mmf/plugin/mmfmediaclientextdisplayinterface.hrh>
    20 #include <mmf/plugin/mmfmediaclientextdisplayinterface.hrh>
    20 #include <e32cmn.h>
    21 #include <e32cmn.h>
    21 #include <ecom/ecom.h>
    22 #include <ecom/ecom.h>
    22 
    23 
    60 	{
    61 	{
    61 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::ConstructL +++");
    62 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::ConstructL +++");
    62 
    63 
    63 	SetWindowArrayPtr2Client();
    64 	SetWindowArrayPtr2Client();
    64 
    65 
    65 	CreateExtDisplayPluginL();
    66 	// External display switching and wserv events are only possible if there is
    66 	
    67 	// an active scheduler in client thread
    67 	// Try and enable display switching by default. If this leaves then do so quietly.
    68 	if(CActiveScheduler::Current())
    68 	// Either the client has no scheduler installed or the device does not support external
    69 	    {
    69 	// switching (i.e. no plugin was found) 
    70         CreateExtDisplayPluginL();
    70 	TRAPD(err, SetExternalDisplaySwitchingL(aExtDisplaySwitchingControl));
    71         iWsEventObserver = CMediaClientWsEventObserver::NewL(*this);
    71 	err = err; // remove compile warning
    72 
    72 	DEBUG_PRINTF2("CMediaClientVideoDisplayBody::ConstructL SetExternalDisplaySwitchingL returned with %d", err);
    73         iServerClient = CMediaClientPolicyServerClient::NewL();
    73 	
    74         if(iServerClient->Connect() != KErrNone)
       
    75             {
       
    76             delete iServerClient;
       
    77             iServerClient = NULL;
       
    78             }
       
    79         
       
    80         if(IsSurfaceCreated() && iServerClient)
       
    81             {
       
    82             iServerClient->SetSurface(iSurfaceId);
       
    83             }
       
    84         
       
    85         // Try and enable display switching by default. If this leaves then do so quietly.
       
    86         // Either the client has no scheduler installed or the device does not support external
       
    87         // switching (i.e. no plugin was found) 
       
    88         TRAPD(err, SetExternalDisplaySwitchingL(aExtDisplaySwitchingControl));
       
    89         err = err; // remove compile warning
       
    90         DEBUG_PRINTF2("CMediaClientVideoDisplayBody::ConstructL SetExternalDisplaySwitchingL returned with %d", err);
       
    91 	    }
       
    92 	else
       
    93 	    {
       
    94 	    DEBUG_PRINTF("CMediaClientVideoDisplayBody::ConstructL No CActiveScheduler - ext display and focus features disabled ");
       
    95 	    }
    74 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::ConstructL ---");
    96 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::ConstructL ---");
    75 	}
    97 	}
    76 
    98 
    77 CMediaClientVideoDisplayBody::CMediaClientVideoDisplayBody(TInt aDisplayId, const TSurfaceId& aSurfaceId,
    99 CMediaClientVideoDisplayBody::CMediaClientVideoDisplayBody(TInt aDisplayId, const TSurfaceId& aSurfaceId,
    78 		const TRect& aCropRect, TVideoAspectRatio aAspectRatio) :
   100 		const TRect& aCropRect, TVideoAspectRatio aAspectRatio) :
   104 
   126 
   105 	delete iExtDisplayHandler;
   127 	delete iExtDisplayHandler;
   106 	RemoveExtDisplayPlugin();
   128 	RemoveExtDisplayPlugin();
   107 	REComSession::FinalClose();
   129 	REComSession::FinalClose();
   108 	
   130 	
       
   131     delete iWsEventObserver;
       
   132 
       
   133     delete iServerClient;
       
   134     
   109 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::~CMediaClientVideoDisplayBody ---");
   135 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::~CMediaClientVideoDisplayBody ---");
   110 	}
   136 	}
   111 
   137 
   112 void CMediaClientVideoDisplayBody::AddDisplayL(MMMFSurfaceEventHandler& aEventHandler)
   138 void CMediaClientVideoDisplayBody::AddDisplayL(MMMFSurfaceEventHandler& aEventHandler)
   113 	{
   139 	{
   127 	}
   153 	}
   128 	
   154 	
   129 void CMediaClientVideoDisplayBody::AddDisplayWindowL(const RWindowBase* aWindow, const TRect& aClipRect, const TRect& aCropRegion, const TRect& aVideoExtent, 
   155 void CMediaClientVideoDisplayBody::AddDisplayWindowL(const RWindowBase* aWindow, const TRect& aClipRect, const TRect& aCropRegion, const TRect& aVideoExtent, 
   130 															TReal32 aScaleWidth, TReal32 aScaleHeight, TVideoRotation aRotation, 
   156 															TReal32 aScaleWidth, TReal32 aScaleHeight, TVideoRotation aRotation, 
   131 															TAutoScaleType aAutoScaleType, TInt aHorizPos, TInt aVertPos, RWindow* aWindow2)
   157 															TAutoScaleType aAutoScaleType, TInt aHorizPos, TInt aVertPos, RWindow* aWindow2)
   132 	{
   158 	{	
   133 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::AddDisplayWindowL +++");
   159 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::AddDisplayWindowL +++");
   134     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::AddDisplayWindowL - aWindow WsHandle 0x%X", aWindow->WsHandle());
   160     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);
   161     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);
   162     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);
   163     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);
   164     DEBUG_PRINTF3("CMediaClientVideoDisplayBody::AddDisplayWindowL - aScaleWidth %f, aScaleHeight %f", aScaleWidth, aScaleHeight);
   139     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::AddDisplayWindowL - aRotation %d", aRotation);
   165     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::AddDisplayWindowL - aRotation %d", aRotation);
   140     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::AddDisplayWindowL - aAutoScaleType %d", aAutoScaleType);
   166     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::AddDisplayWindowL - aAutoScaleType %d", aAutoScaleType);
   141     DEBUG_PRINTF3("CMediaClientVideoDisplayBody::AddDisplayWindowL - aHorizPos %d, aVertPos %d", aHorizPos, aVertPos);
   167     DEBUG_PRINTF3("CMediaClientVideoDisplayBody::AddDisplayWindowL - aHorizPos %d, aVertPos %d", aHorizPos, aVertPos);
   142 
   168 
       
   169 	if (!IsRotationValid(aRotation))
       
   170 		{
       
   171 		User::Leave(KErrArgument);
       
   172 		}
       
   173 
       
   174 	if (!IsAutoScaleTypeValid(aAutoScaleType))
       
   175 		{
       
   176 		User::Leave(KErrArgument);
       
   177 		}
       
   178 
   143 	TInt pos = iClientWindows.Find(aWindow->WsHandle(), TWindowData::CompareByWsHandle);
   179 	TInt pos = iClientWindows.Find(aWindow->WsHandle(), TWindowData::CompareByWsHandle);
   144 	
   180 	
   145 	if (pos != KErrNotFound)
   181 	if (pos != KErrNotFound)
   146 		{
   182 		{
   147 		User::Leave(KErrInUse);
   183 		User::Leave(KErrInUse);
   150 	TWindowData winData(aWindow, aClipRect, aVideoExtent, aScaleWidth, aScaleHeight, aRotation, aAutoScaleType, aHorizPos, aVertPos, aWindow2);
   186 	TWindowData winData(aWindow, aClipRect, aVideoExtent, aScaleWidth, aScaleHeight, aRotation, aAutoScaleType, aHorizPos, aVertPos, aWindow2);
   151 	iClientWindows.AppendL(winData);
   187 	iClientWindows.AppendL(winData);
   152 	
   188 	
   153 	iCropRegion = aCropRegion;
   189 	iCropRegion = aCropRegion;
   154 	
   190 	
       
   191 	TBool prevClientWindowIsInFocus = iClientWindowIsInFocus;
       
   192     UpdateFocus();
       
   193 	
   155 	if (IsSurfaceCreated())
   194 	if (IsSurfaceCreated())
   156 		{
   195 		{
   157 		// first client window just added
   196         // if first window was just added OR the new window has moved us from out of focus to in focus
   158         if((iClientWindows.Count() == 1) && iClientRequestedExtDisplaySwitching)
   197         if(((iClientWindows.Count() == 1) || !prevClientWindowIsInFocus) && iClientRequestedExtDisplaySwitching &&
   159             {
   198                 iClientWindowIsInFocus && iExtDisplayConnected)
   160             if(iExtDisplayConnected)
   199             {
       
   200             TRAPD(err, CreateExtDisplayHandlerL());
       
   201             DEBUG_PRINTF2("CMediaClientVideoDisplayBody::AddDisplayWindowL CreateExtDisplayHandlerL error %d", err);
       
   202             if(err == KErrNone)
   161                 {
   203                 {
   162                 TRAPD(err, CreateExtDisplayHandlerL());
   204                 SetWindowArrayPtr2Ext();
   163                 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::AddDisplayWindowL CreateExtDisplayHandlerL error %d", err);
   205                 User::LeaveIfError(RedrawWindows(aCropRegion));
   164                 if(err == KErrNone)
       
   165                     {
       
   166                     SetWindowArrayPtr2Ext();
       
   167                     User::LeaveIfError(RedrawWindows(aCropRegion));
       
   168                     }
       
   169                 }
   206                 }
   170             }
   207             }
   171         
   208         
   172         if(!iExtDisplayConnected || !iExtDisplayHandler)
   209         if(!iSwitchedToExternalDisplay)
   173             {
   210             {
   174             User::LeaveIfError(SetBackgroundSurface(winData, aCropRegion));
   211             User::LeaveIfError(SetBackgroundSurface(winData, aCropRegion));
   175             }
   212             }
   176 		}
   213 		}
   177 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::AddDisplayWindowL ---");
   214 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::AddDisplayWindowL ---");
   188 	{
   225 	{
   189 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveDisplayWindow +++");
   226 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveDisplayWindow +++");
   190 	TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
   227 	TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
   191 	
   228 	
   192 	if (pos >= 0)
   229 	if (pos >= 0)
   193 		{
   230 	    {
   194 		if (IsSurfaceCreated() && (!iExtDisplayConnected || !iExtDisplayHandler))
   231 	    if(IsSurfaceCreated() && !iSwitchedToExternalDisplay)
   195 			{
   232             {
   196 			iClientWindows[pos].iWindow->RemoveBackgroundSurface(ETrue);
   233             iClientWindows[pos].iWindow->RemoveBackgroundSurface(ETrue);
   197             // Make sure all window rendering has completed before proceeding
   234             // Make sure all window rendering has completed before proceeding
   198             RWsSession* ws = iClientWindows[pos].iWindow->Session();
   235             RWsSession* ws = iClientWindows[pos].iWindow->Session();
   199             if (ws)
   236             if (ws)
   200               {
   237                 {
   201               ws->Finish();
   238                 ws->Finish();
   202               }
   239                 }
   203 			}
   240             }
   204 		iClientWindows.Remove(pos);
   241 
   205 		
   242 	    iClientWindows.Remove(pos);
   206 		if(iClientWindows.Count() == 0 && iExtDisplayConnected && iExtDisplayHandler)
   243 	    
   207 		    {
   244 	    TBool prevClientWindowIsInFocus = iClientWindowIsInFocus;
   208 		    RemoveBackgroundSurface(ETrue);
   245         UpdateFocus();
   209 		    SetWindowArrayPtr2Client();
   246 
   210 		    RemoveExtDisplayHandler();
   247         // if only window was just removed OR removal has moved us from in focus to out of focus
   211 		    }
   248         if((iClientWindows.Count() == 0 || prevClientWindowIsInFocus) && iSwitchedToExternalDisplay &&
       
   249                 !iClientWindowIsInFocus)
       
   250             {
       
   251             RemoveBackgroundSurface(ETrue);
       
   252             SetWindowArrayPtr2Client();
       
   253             RemoveExtDisplayHandler();
       
   254             RedrawWindows(iCropRegion);
       
   255             }
   212 		}
   256 		}
   213 	
   257 	
   214 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveDisplayWindow ---");
   258 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveDisplayWindow ---");
   215 	return pos;
   259 	return pos;
   216 	}
   260 	}
   233 	iSurfaceId = aSurfaceId;
   277 	iSurfaceId = aSurfaceId;
   234 	iCropRect = aCropRect;
   278 	iCropRect = aCropRect;
   235 	iAspectRatio = aAspectRatio;
   279 	iAspectRatio = aAspectRatio;
   236 	iCropRegion = aCropRegion;
   280 	iCropRegion = aCropRegion;
   237 	
   281 	
       
   282 	if(iServerClient)
       
   283 	    {
       
   284         iServerClient->SetSurface(iSurfaceId);
       
   285 	    }
       
   286 	
   238 	if (emitEvent && iEventHandler)
   287 	if (emitEvent && iEventHandler)
   239 		{
   288 		{
   240 		iEventHandler->MmsehSurfaceCreated(iDisplayId, iSurfaceId, iCropRect, iAspectRatio);
   289 		iEventHandler->MmsehSurfaceCreated(iDisplayId, iSurfaceId, iCropRect, iAspectRatio);
   241 		}
   290 		}
   242 
   291 
   243 	TInt err = KErrNone;
   292 	TInt err = KErrNone;
   244     if((iClientWindows.Count() > 0) && iClientRequestedExtDisplaySwitching)
   293     if((iClientWindows.Count() > 0) && iClientRequestedExtDisplaySwitching && iClientWindowIsInFocus)
   245         {
   294         {
   246         if(iExtDisplayConnected && !iExtDisplayHandler)
   295         if(iExtDisplayConnected && !iExtDisplayHandler)
   247             {
   296             {
   248             TRAP(err, CreateExtDisplayHandlerL());
   297             TRAP(err, CreateExtDisplayHandlerL());
   249             DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SurfaceCreated CreateExtDisplayHandlerL error %d", err);
   298             DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SurfaceCreated CreateExtDisplayHandlerL error %d", err);
   254             }
   303             }
   255         }
   304         }
   256     
   305     
   257     err = RedrawWindows(aCropRegion);
   306     err = RedrawWindows(aCropRegion);
   258     
   307     
   259     DEBUG_PRINTF("CMediaClientVideoDisplayBody::SurfaceCreated ---");
   308     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SurfaceCreated --- Return error %d", err);
   260 	return err;
   309 	return err;
   261 	}
   310 	}
   262 
   311 
   263 void CMediaClientVideoDisplayBody::RemoveBackgroundSurface(TBool aTriggerRedraw)
   312 void CMediaClientVideoDisplayBody::RemoveBackgroundSurface(TBool aTriggerRedraw)
   264 	{
   313 	{
   294             iEventHandler->MmsehRemoveSurface(iSurfaceId);
   343             iEventHandler->MmsehRemoveSurface(iSurfaceId);
   295             }
   344             }
   296 
   345 
   297         iSurfaceId = TSurfaceId::CreateNullId();
   346         iSurfaceId = TSurfaceId::CreateNullId();
   298 
   347 
   299         if(iExtDisplayConnected && iExtDisplayHandler)
   348         if(iSwitchedToExternalDisplay)
   300             {
   349             {
   301             SetWindowArrayPtr2Client();
   350             SetWindowArrayPtr2Client();
   302             RemoveExtDisplayHandler();
   351             RemoveExtDisplayHandler();
   303             }
   352             }
   304         }
   353         }
   313     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SurfaceCreated - aCropRect %d,%d - %d,%d", aCropRect.iTl.iX, aCropRect.iTl.iY, aCropRect.iBr.iX, aCropRect.iBr.iY);
   362     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);
   363     DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SurfaceCreated - aAspectRatio %d/%d", aAspectRatio.iNumerator, aAspectRatio.iDenominator);
   315 
   364 
   316     if (!IsSurfaceCreated())
   365     if (!IsSurfaceCreated())
   317 		{
   366 		{
       
   367 		DEBUG_PRINTF("CMediaClientVideoDisplayBody::SurfaceParametersChanged --- Return error KErrNotSupproted");
   318 		return KErrNotSupported;
   368 		return KErrNotSupported;
   319 		}
   369 		}
   320 
   370 
   321 	if (iSurfaceId != aSurfaceId)
   371 	if (iSurfaceId != aSurfaceId)
   322 		{
   372 		{
       
   373 		DEBUG_PRINTF("CMediaClientVideoDisplayBody::SurfaceParametersChanged --- Return error KErrInUse");
   323 		return KErrInUse;
   374 		return KErrInUse;
   324 		}
   375 		}
   325 	
   376 
   326 	iCropRect = aCropRect;
       
   327 	iAspectRatio = aAspectRatio;
       
   328 	
       
   329 	if (iEventHandler)
   377 	if (iEventHandler)
   330 		{
   378 		{
   331 		iEventHandler->MmsehSurfaceParametersChanged(iSurfaceId, iCropRect, iAspectRatio);
   379 		iEventHandler->MmsehSurfaceParametersChanged(iSurfaceId, aCropRect, aAspectRatio);
   332 		}
   380 		}
   333 
   381 
   334 	RedrawWindows(iCropRegion);
   382 	TInt error = KErrNone;
   335 	
   383 	if (iCropRect != aCropRect || iAspectRatio != aAspectRatio)
   336 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SurfaceParametersChanged ---");
   384 		{
   337 	return KErrNone;
   385 		// We only need to redraw if the aspect ratio has changed, or the area of the video to
       
   386 		// display (i.e the intersection of client crop region and surface crop rectangle) has changed.
       
   387 		TBool redraw = EFalse;
       
   388 		if (iAspectRatio != aAspectRatio || SurfaceCropRectChangeRequiresRedraw(iCropRect, aCropRect, iCropRegion))
       
   389 			{
       
   390 			redraw = ETrue;
       
   391 			}
       
   392 
       
   393 		iCropRect = aCropRect;
       
   394 		iAspectRatio = aAspectRatio;
       
   395 
       
   396 		if (redraw)
       
   397 			{
       
   398 			error = RedrawWindows(iCropRegion);
       
   399 			}
       
   400 		}
       
   401 	else
       
   402 		{
       
   403 		DEBUG_PRINTF("CMediaClientVideoDisplayBody::SurfaceParametersChanged - Surface parameters have not changed");
       
   404 		}
       
   405 
       
   406 	DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SurfaceParametersChanged --- Return error %d", error);
       
   407 	return error;
   338 	}
   408 	}
   339 	
   409 	
   340 TInt CMediaClientVideoDisplayBody::RedrawWindows(const TRect& aCropRegion)
   410 TInt CMediaClientVideoDisplayBody::RedrawWindows(const TRect& aCropRegion)
   341 	{
   411 	{
   342 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::RedrawWindows +++");
   412 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::RedrawWindows +++");
   361 		
   431 		
   362 	DEBUG_PRINTF2("CMediaClientVideoDisplayBody::RedrawWindows --- return with %d", err);
   432 	DEBUG_PRINTF2("CMediaClientVideoDisplayBody::RedrawWindows --- return with %d", err);
   363 	return err;
   433 	return err;
   364 	}
   434 	}
   365 
   435 
   366 void CMediaClientVideoDisplayBody::UpdateCropRegionL(const TRect& aCropRegion, TInt aPos)
   436 void CMediaClientVideoDisplayBody::UpdateCropRegionL(const TRect& aCropRegion, TInt aPos, TBool aRedrawIndividualWindow)
   367     {
   437     {
   368     DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateCropRegionL +++");
   438     DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateCropRegionL +++");
   369 
   439 
   370     TRect prevCropRegion(iCropRegion);
   440     TRect prevCropRegion(iCropRegion);
   371     iCropRegion = aCropRegion;
   441     iCropRegion = aCropRegion;
   372     
   442     
   373     if (IsSurfaceCreated())
   443     if (IsSurfaceCreated())
   374         {
   444         {
   375         if(prevCropRegion == aCropRegion)
   445         if(prevCropRegion == aCropRegion)
   376             {
   446             {
   377             if(!iExtDisplayConnected || !iExtDisplayHandler)
   447             if(!iSwitchedToExternalDisplay && aRedrawIndividualWindow)
   378                 {
   448                 {
   379                 User::LeaveIfError(SetBackgroundSurface(iClientWindows[aPos], aCropRegion));
   449                 User::LeaveIfError(SetBackgroundSurface(iClientWindows[aPos], aCropRegion));
   380                 }
   450                 }
   381             }
   451             }
   382         else
   452         else
   383             {
   453             {
   384             User::LeaveIfError(RedrawWindows(aCropRegion));
   454 			// We only need to redraw if the area of the video to display (i.e the
       
   455 			// intersection of client crop region and surface crop rectangle) has changed.
       
   456 			if (ClientCropRegionChangeRequiresRedraw(prevCropRegion, aCropRegion, iCropRect))
       
   457 				{
       
   458 				User::LeaveIfError(RedrawWindows(aCropRegion));
       
   459 				}
   385             }
   460             }
   386         }
   461         }
   387     DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateCropRegionL ---");    
   462     DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateCropRegionL ---");    
   388     }
   463     }
   389 
   464 
   393     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetAutoScaleL - aWindow WsHandle 0x%X", aWindow.WsHandle());
   468     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetAutoScaleL - aWindow WsHandle 0x%X", aWindow.WsHandle());
   394     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetAutoScaleL - aScaleType %d", aScaleType);
   469     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetAutoScaleL - aScaleType %d", aScaleType);
   395     DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SetAutoScaleL - aHorizPos %d, aVertPos %d", aHorizPos, aVertPos);
   470     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);
   471     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetAutoScaleL - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
   397 
   472 
       
   473 	if (!IsAutoScaleTypeValid(aScaleType))
       
   474 		{
       
   475 		User::Leave(KErrArgument);
       
   476 		}
       
   477 
   398     TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
   478     TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
   399 	User::LeaveIfError(pos);
   479 	User::LeaveIfError(pos);
   400 	
   480 
   401 	iClientWindows[pos].iAutoScaleType = aScaleType;
   481 	TBool parameterChanged = EFalse;
   402 	iClientWindows[pos].iHorizPos = aHorizPos;
   482 	if (aScaleType != iClientWindows[pos].iAutoScaleType || aHorizPos != iClientWindows[pos].iHorizPos || aVertPos != iClientWindows[pos].iVertPos)
   403 	iClientWindows[pos].iVertPos = aVertPos;
   483 		{
   404 
   484 		iClientWindows[pos].iAutoScaleType = aScaleType;
   405 	UpdateCropRegionL(aCropRegion, pos);
   485 		iClientWindows[pos].iHorizPos = aHorizPos;
   406 	
   486 		iClientWindows[pos].iVertPos = aVertPos;
       
   487 		parameterChanged = ETrue;
       
   488 		}
       
   489 	else
       
   490 		{
       
   491 		DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetAutoScaleL - Scale parameters have not changed");
       
   492 		}
       
   493 
       
   494 	UpdateCropRegionL(aCropRegion, pos, parameterChanged);
       
   495 
   407 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetAutoScaleL ---");
   496 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetAutoScaleL ---");
   408 	}
   497 	}
   409 	
   498 	
   410 
   499 
   411 void CMediaClientVideoDisplayBody::SetRotationL(const RWindowBase& aWindow, TVideoRotation aRotation, const TRect& aCropRegion)
   500 void CMediaClientVideoDisplayBody::SetRotationL(const RWindowBase& aWindow, TVideoRotation aRotation, const TRect& aCropRegion)
   413 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetRotationL +++");
   502 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetRotationL +++");
   414     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetRotationL - aWindow WsHandle 0x%X", aWindow.WsHandle());
   503     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetRotationL - aWindow WsHandle 0x%X", aWindow.WsHandle());
   415     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetRotationL - aRotation %d", aRotation);
   504     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);
   505     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetRotationL - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
   417 
   506 
       
   507 	if (!IsRotationValid(aRotation))
       
   508 		{
       
   509 		User::Leave(KErrArgument);
       
   510 		}
       
   511 
   418     TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
   512     TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
   419 	User::LeaveIfError(pos);
   513 	User::LeaveIfError(pos);
   420 	
   514 
   421 	iClientWindows[pos].iRotation = aRotation;
   515 	TBool parameterChanged = EFalse;
   422 
   516 	if (aRotation != iClientWindows[pos].iRotation)
   423     UpdateCropRegionL(aCropRegion, pos);
   517 		{
       
   518 		iClientWindows[pos].iRotation = aRotation;
       
   519 		parameterChanged = ETrue;
       
   520 		}
       
   521 	else
       
   522 		{
       
   523 		DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetRotationL - Rotation has not changed");
       
   524 		}
       
   525 
       
   526     UpdateCropRegionL(aCropRegion, pos, parameterChanged);
   424 
   527 
   425 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetRotationL ---");
   528 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetRotationL ---");
   426 	}
   529 	}
   427 
   530 
   428 TVideoRotation CMediaClientVideoDisplayBody::RotationL(const RWindowBase& aWindow)
   531 TVideoRotation CMediaClientVideoDisplayBody::RotationL(const RWindowBase& aWindow)
   448 	if (aWidthPercentage <= 0.0 || aHeightPercentage <= 0.0)
   551 	if (aWidthPercentage <= 0.0 || aHeightPercentage <= 0.0)
   449 		{
   552 		{
   450 		User::Leave(KErrArgument);
   553 		User::Leave(KErrArgument);
   451 		}
   554 		}
   452 
   555 
   453 	iClientWindows[pos].iScaleWidth = aWidthPercentage;
   556 	TBool parameterChanged = EFalse;
   454 	iClientWindows[pos].iScaleHeight = aHeightPercentage;
   557 	if (aWidthPercentage != iClientWindows[pos].iScaleWidth ||
   455 	iClientWindows[pos].iAutoScaleType = EAutoScaleNone;
   558 	    aHeightPercentage != iClientWindows[pos].iScaleHeight ||
   456 	
   559 		EAutoScaleNone != iClientWindows[pos].iAutoScaleType)
   457     UpdateCropRegionL(aCropRegion, pos);
   560 		{
       
   561 		iClientWindows[pos].iScaleWidth = aWidthPercentage;
       
   562 		iClientWindows[pos].iScaleHeight = aHeightPercentage;
       
   563 		iClientWindows[pos].iAutoScaleType = EAutoScaleNone;
       
   564 		parameterChanged = ETrue;
       
   565 		}
       
   566 	else
       
   567 		{
       
   568 		DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetScaleFactorL - Scale parameters have not changed");
       
   569 		}
       
   570 
       
   571     UpdateCropRegionL(aCropRegion, pos, parameterChanged);
   458 	
   572 	
   459     DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetScaleFactorL ---");
   573     DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetScaleFactorL ---");
   460 	}
   574 	}
   461 	
   575 	
   462 void CMediaClientVideoDisplayBody::GetScaleFactorL(const RWindowBase& aWindow, TReal32& aWidthPercentage, TReal32& aHeightPercentage)
   576 void CMediaClientVideoDisplayBody::GetScaleFactorL(const RWindowBase& aWindow, TReal32& aWidthPercentage, TReal32& aHeightPercentage)
   474 	{
   588 	{
   475 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetAutoScaleL +++");
   589 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetAutoScaleL +++");
   476     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetAutoScaleL - aScaleType %d", aScaleType);
   590     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetAutoScaleL - aScaleType %d", aScaleType);
   477     DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SetAutoScaleL - aHorizPos %d, aVertPos %d", aHorizPos, aVertPos);
   591     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);
   592     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetAutoScaleL - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
   479 	
   593 
       
   594 	if (!IsAutoScaleTypeValid(aScaleType))
       
   595 		{
       
   596 		User::Leave(KErrArgument);
       
   597 		}
       
   598 
   480     TRect prevCropRegion(iCropRegion);
   599     TRect prevCropRegion(iCropRegion);
   481 	iCropRegion = aCropRegion;
   600 	iCropRegion = aCropRegion;
       
   601 	
       
   602 	TBool parameterChanged;
   482 	TInt count = iClientWindows.Count();
   603 	TInt count = iClientWindows.Count();
   483 	
   604 
   484 	for (TInt i = 0; i < count; ++i)
   605 	for (TInt i = 0; i < count; ++i)
   485 		{
   606 		{
   486 		iClientWindows[i].iAutoScaleType = aScaleType;
   607 		parameterChanged = EFalse;
   487 		iClientWindows[i].iHorizPos = aHorizPos;
   608 		if (aScaleType != iClientWindows[i].iAutoScaleType || aHorizPos != iClientWindows[i].iHorizPos || aVertPos != iClientWindows[i].iVertPos)
   488 		iClientWindows[i].iVertPos = aVertPos;
   609 			{
   489 	    if (IsSurfaceCreated() && (!iExtDisplayConnected || !iExtDisplayHandler))
   610 			iClientWindows[i].iAutoScaleType = aScaleType;
       
   611 			iClientWindows[i].iHorizPos = aHorizPos;
       
   612 			iClientWindows[i].iVertPos = aVertPos;
       
   613 			parameterChanged = ETrue;
       
   614 			}
       
   615 		else
       
   616 			{
       
   617 			DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetAutoScaleL - Scale parameters for window pos %d have not changed", i);
       
   618 			}
       
   619 
       
   620 		// We only need to redraw if the scale parameters have changed, or the area of the video
       
   621 		// to display (i.e the intersection of client crop region and surface crop rectangle) has changed.
       
   622 		if (IsSurfaceCreated() && !iSwitchedToExternalDisplay && (parameterChanged || ClientCropRegionChangeRequiresRedraw(prevCropRegion, aCropRegion, iCropRect)))
   490 			{
   623 			{
   491 			User::LeaveIfError(SetBackgroundSurface(iClientWindows[i], aCropRegion));
   624 			User::LeaveIfError(SetBackgroundSurface(iClientWindows[i], aCropRegion));
   492 			}
   625 			}
   493 		}
   626 		}
   494 	
   627 
   495 	if (IsSurfaceCreated() && iExtDisplayConnected && iExtDisplayHandler && (aCropRegion != prevCropRegion))
   628 	// We only need to redraw if the area of the video to display (i.e the
       
   629 	// intersection of client crop region and surface crop rectangle) has changed.
       
   630 	if (IsSurfaceCreated() && iSwitchedToExternalDisplay && ClientCropRegionChangeRequiresRedraw(prevCropRegion, aCropRegion, iCropRect))
   496         {
   631         {
   497         User::LeaveIfError(RedrawWindows(aCropRegion));
   632         User::LeaveIfError(RedrawWindows(aCropRegion));
   498         }
   633         }
   499 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetAutoScaleL ---");
   634 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetAutoScaleL ---");
   500 	}
   635 	}
   504 	{
   639 	{
   505 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetRotationL +++");
   640 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetRotationL +++");
   506     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetRotationL - aRotation %d", aRotation);
   641     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetRotationL - aRotation %d", aRotation);
   507     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetRotationL - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
   642     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetRotationL - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
   508 
   643 
       
   644 	if (!IsRotationValid(aRotation))
       
   645 		{
       
   646 		User::Leave(KErrArgument);
       
   647 		}
       
   648 
   509     TRect prevCropRegion(iCropRegion);
   649     TRect prevCropRegion(iCropRegion);
   510     iCropRegion = aCropRegion;
   650     iCropRegion = aCropRegion;
       
   651 
       
   652 	TBool parameterChanged;
   511 	TInt count = iClientWindows.Count();
   653 	TInt count = iClientWindows.Count();
   512 	
   654 	
   513 	for (TInt i = 0; i < count; ++i)
   655 	for (TInt i = 0; i < count; ++i)
   514 		{
   656 		{
   515 		iClientWindows[i].iRotation = aRotation;
   657 		parameterChanged = EFalse;
   516         if (IsSurfaceCreated() && (!iExtDisplayConnected || !iExtDisplayHandler))
   658 		if (aRotation != iClientWindows[i].iRotation)
       
   659 			{
       
   660 			iClientWindows[i].iRotation = aRotation;
       
   661 			parameterChanged = ETrue;
       
   662 			}
       
   663 		else
       
   664 			{
       
   665 			DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetRotationL - Rotation for window pos %d has not changed", i);
       
   666 			}
       
   667 
       
   668 		// We only need to redraw if the scale parameters have changed, or the area of the video
       
   669 		// to display (i.e the intersection of client crop region and surface crop rectangle) has changed.
       
   670 		if (IsSurfaceCreated() && !iSwitchedToExternalDisplay && (parameterChanged || ClientCropRegionChangeRequiresRedraw(prevCropRegion, aCropRegion, iCropRect)))
   517 			{
   671 			{
   518 			User::LeaveIfError(SetBackgroundSurface(iClientWindows[i], aCropRegion));
   672 			User::LeaveIfError(SetBackgroundSurface(iClientWindows[i], aCropRegion));
   519 			}
   673 			}
   520 		}
   674 		}
   521 	
   675 	
   522     if (IsSurfaceCreated() && iExtDisplayConnected && iExtDisplayHandler && (aCropRegion != prevCropRegion))
   676 	// We only need to redraw if the area of the video to display (i.e the
       
   677 	// intersection of client crop region and surface crop rectangle) has changed.
       
   678 	if (IsSurfaceCreated() && iSwitchedToExternalDisplay && ClientCropRegionChangeRequiresRedraw(prevCropRegion, aCropRegion, iCropRect))
   523         {
   679         {
   524         User::LeaveIfError(RedrawWindows(aCropRegion));
   680         User::LeaveIfError(RedrawWindows(aCropRegion));
   525         }
   681         }
   526 	   
   682 	   
   527 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetRotationL ---");
   683 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetRotationL ---");
   538 		User::Leave(KErrArgument);
   694 		User::Leave(KErrArgument);
   539 		}
   695 		}
   540 	
   696 	
   541     TRect prevCropRegion(iCropRegion);
   697     TRect prevCropRegion(iCropRegion);
   542 	iCropRegion = aCropRegion;
   698 	iCropRegion = aCropRegion;
       
   699 
       
   700 	TBool parameterChanged;
   543 	TInt count = iClientWindows.Count();
   701 	TInt count = iClientWindows.Count();
   544 	
   702 	
   545 	for (TInt i = 0; i < count; ++i)
   703 	for (TInt i = 0; i < count; ++i)
   546 		{
   704 		{
   547 		iClientWindows[i].iScaleWidth = aWidthPercentage;
   705 		parameterChanged = EFalse;
   548 		iClientWindows[i].iScaleHeight = aHeightPercentage;
   706 		
   549 		iClientWindows[i].iAutoScaleType = EAutoScaleNone;
   707 		if (aWidthPercentage != iClientWindows[i].iScaleWidth ||
   550         if (IsSurfaceCreated() && (!iExtDisplayConnected || !iExtDisplayHandler))
   708 		    aHeightPercentage != iClientWindows[i].iScaleHeight ||
       
   709 			EAutoScaleNone != iClientWindows[i].iAutoScaleType)
       
   710 			{
       
   711 			iClientWindows[i].iScaleWidth = aWidthPercentage;
       
   712 			iClientWindows[i].iScaleHeight = aHeightPercentage;
       
   713 			iClientWindows[i].iAutoScaleType = EAutoScaleNone;
       
   714 			parameterChanged = ETrue;
       
   715 			}
       
   716 		else
       
   717 			{
       
   718 			DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetScaleFactorL - Scale parameters for window pos %d have not changed", i);
       
   719 			}
       
   720 
       
   721 		// We only need to redraw if the scale parameters have changed, or the area of the video to
       
   722 		// display (i.e the intersection of client crop region and surface crop rectangle) has changed.
       
   723 		if (IsSurfaceCreated() && !iSwitchedToExternalDisplay && (parameterChanged || ClientCropRegionChangeRequiresRedraw(prevCropRegion, aCropRegion, iCropRect)))
   551 			{
   724 			{
   552 			User::LeaveIfError(SetBackgroundSurface(iClientWindows[i], aCropRegion));
   725 			User::LeaveIfError(SetBackgroundSurface(iClientWindows[i], aCropRegion));
   553 			}
   726 			}
   554 		}
   727 		}
   555 	
   728 
   556     if (IsSurfaceCreated() && iExtDisplayConnected && iExtDisplayHandler && (aCropRegion != prevCropRegion))
   729 	// We only need to redraw if the area of the video to display (i.e the
       
   730 	// intersection of client crop region and surface crop rectangle) has changed.
       
   731 	if (IsSurfaceCreated() && iSwitchedToExternalDisplay && ClientCropRegionChangeRequiresRedraw(prevCropRegion, aCropRegion, iCropRect))
   557         {
   732         {
   558         User::LeaveIfError(RedrawWindows(aCropRegion));
   733         User::LeaveIfError(RedrawWindows(aCropRegion));
   559         }
   734         }
   560 	   
   735 	   
   561 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetScaleFactorL ---");
   736 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetScaleFactorL ---");
   568     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetWindowClipRectL - aWindowClipRect %d,%d - %d,%d", aWindowClipRect.iTl.iX, aWindowClipRect.iTl.iY, aWindowClipRect.iBr.iX, aWindowClipRect.iBr.iY);
   743     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);
   744     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetWindowClipRectL - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
   570 	
   745 	
   571 	TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
   746 	TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
   572 	User::LeaveIfError(pos);
   747 	User::LeaveIfError(pos);
   573 	
   748 
   574 	iClientWindows[pos].iClipRect = aWindowClipRect;
   749 	TBool parameterChanged = EFalse;
   575 
   750 	if (aWindowClipRect != iClientWindows[pos].iClipRect)
   576     UpdateCropRegionL(aCropRegion, pos);
   751 		{
       
   752 		// We only want to redraw if the change in the clipping rectangle would result
       
   753 		// in a change to the area of the display used for the video.
       
   754 		// The video is always displayed in the intersection of the clipping rectangle
       
   755 		// and the video extent, so check if this has changed.
       
   756 		parameterChanged = IntersectionAreaChanged(iClientWindows[pos].iClipRect, aWindowClipRect, iClientWindows[pos].iVideoExtent);
       
   757 
       
   758 		iClientWindows[pos].iClipRect = aWindowClipRect;
       
   759 		}
       
   760 	else
       
   761 		{
       
   762 		DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetWindowClipRectL - Clip rect parameter has not changed");
       
   763 		}
       
   764 
       
   765     UpdateCropRegionL(aCropRegion, pos, parameterChanged);
   577 
   766 
   578     DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetWindowClipRectL ---");
   767     DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetWindowClipRectL ---");
   579 	}
   768 	}
   580 	
   769 	
   581 void CMediaClientVideoDisplayBody::SetVideoExtentL(const RWindowBase& aWindow, const TRect& aVideoExtent, const TRect& aCropRegion)
   770 void CMediaClientVideoDisplayBody::SetVideoExtentL(const RWindowBase& aWindow, const TRect& aVideoExtent, const TRect& aCropRegion)
   585     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetVideoExtentL - aVideoExtent %d,%d - %d,%d", aVideoExtent.iTl.iX, aVideoExtent.iTl.iY, aVideoExtent.iBr.iX, aVideoExtent.iBr.iY);
   774     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);
   775     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetVideoExtentL - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
   587 
   776 
   588     TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
   777     TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
   589 	User::LeaveIfError(pos);
   778 	User::LeaveIfError(pos);
   590 	
   779 
   591 	iClientWindows[pos].iVideoExtent = aVideoExtent;
   780 	TBool parameterChanged = EFalse;
   592 
   781 	if (aVideoExtent != iClientWindows[pos].iVideoExtent)
   593     UpdateCropRegionL(aCropRegion, pos);
   782 		{
       
   783 		iClientWindows[pos].iVideoExtent = aVideoExtent;
       
   784 		parameterChanged = ETrue;
       
   785 		}
       
   786 	else
       
   787 		{
       
   788 		DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetVideoExtentL - Video extent parameter has not changed");
       
   789 		}
       
   790 
       
   791     UpdateCropRegionL(aCropRegion, pos, parameterChanged);
   594     
   792     
   595 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetVideoExtentL ---");
   793 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetVideoExtentL ---");
   596 	}
   794 	}
   597 	
   795 	
   598 TBool CMediaClientVideoDisplayBody::HasWindows() const
   796 TBool CMediaClientVideoDisplayBody::HasWindows() const
   654             inputHeight = static_cast<TReal32>(viewport.Width());
   852             inputHeight = static_cast<TReal32>(viewport.Width());
   655             pixelAspectRatio = static_cast<TReal32>(iAspectRatio.iDenominator) / iAspectRatio.iNumerator;
   853             pixelAspectRatio = static_cast<TReal32>(iAspectRatio.iDenominator) / iAspectRatio.iNumerator;
   656             break;
   854             break;
   657         default:
   855         default:
   658             // Should never get to default unless there's been some programming error.
   856             // Should never get to default unless there's been some programming error.
   659             User::Invariant();
   857 			DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetBackgroundSurface --- Returned with error %d", KErrArgument);
   660             break;
   858 			return KErrArgument;
   661         }
   859         }
   662     
   860     
   663     TReal32 viewportAspect = pixelAspectRatio * inputWidth / inputHeight;
   861     TReal32 viewportAspect = pixelAspectRatio * inputWidth / inputHeight;
   664     TReal32 vidextAspect = static_cast<TReal32>(videoExtent.Width()) / static_cast<TReal32>(videoExtent.Height());
   862     TReal32 vidextAspect = static_cast<TReal32>(videoExtent.Width()) / static_cast<TReal32>(videoExtent.Height());
   665     
   863     
   826         viewport.iTl.iX += (TInt) (wRatio * static_cast<TReal32>(db));
  1024         viewport.iTl.iX += (TInt) (wRatio * static_cast<TReal32>(db));
   827         viewport.iTl.iY += (TInt) (hRatio * static_cast<TReal32>(dl));
  1025         viewport.iTl.iY += (TInt) (hRatio * static_cast<TReal32>(dl));
   828         break;
  1026         break;
   829     default:
  1027     default:
   830         // Should never get to default unless there's been some programming error.
  1028         // Should never get to default unless there's been some programming error.
   831         User::Invariant();
  1029 		DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetBackgroundSurface --- Returned with error %d", KErrArgument);
   832         break;
  1030         return KErrArgument;
   833     }
  1031     }
   834     
  1032     
   835     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetBackgroundSurface - viewport2 %d,%d - %d,%d", viewport.iTl.iX, viewport.iTl.iY, viewport.iBr.iX, viewport.iBr.iY);
  1033     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetBackgroundSurface - viewport2 %d,%d - %d,%d", viewport.iTl.iX, viewport.iTl.iY, viewport.iBr.iX, viewport.iBr.iY);
   836 
  1034 
   837     // Clip the extent.
  1035     // Clip the extent.
   922 		case EVideoRotationClockwise270:
  1120 		case EVideoRotationClockwise270:
   923 		    orientation = CFbsBitGc::EGraphicsOrientationRotated90;
  1121 		    orientation = CFbsBitGc::EGraphicsOrientationRotated90;
   924 		    break;
  1122 		    break;
   925 		default:
  1123 		default:
   926 			// Should never get to default unless there's been some programming error.
  1124 			// Should never get to default unless there's been some programming error.
   927 			User::Invariant();
  1125 			DEBUG_PRINTF2("CMediaClientVideoDisplayBody::ConvertRotation --- Failed due to %d bad aRotation argument", aRotation);
   928 			// This is never reached, just to keep the compiler happy
  1126 			__ASSERT_DEBUG(FALSE, User::Invariant());
       
  1127 			// Use the normal option otherwise
   929 			orientation = CFbsBitGc::EGraphicsOrientationNormal;
  1128 			orientation = CFbsBitGc::EGraphicsOrientationNormal;
   930 		}
  1129 		}
   931     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::ConvertRotation --- return %d", orientation);	
  1130     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::ConvertRotation --- return %d", orientation);	
   932     return orientation;
  1131     return orientation;
   933 	}
  1132 	}
   976         User::Leave(KErrNotReady);
  1175         User::Leave(KErrNotReady);
   977         }
  1176         }
   978 
  1177 
   979     if(iClientRequestedExtDisplaySwitching != aControl)
  1178     if(iClientRequestedExtDisplaySwitching != aControl)
   980         {
  1179         {
   981         iClientRequestedExtDisplaySwitching = aControl;
  1180         iClientRequestedExtDisplaySwitching = aControl;     
   982         
  1181         SwitchSurface();
   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         }
  1182         }
  1010     
  1183     
  1011     DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetExternalDisplaySwitchingL ---");
  1184     DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetExternalDisplaySwitchingL ---");
  1012     }
  1185     }
  1013 
  1186 
  1016 	DEBUG_PRINTF2("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected +++ aExtDisplayConnected=%d", aExtDisplayConnected);
  1189 	DEBUG_PRINTF2("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected +++ aExtDisplayConnected=%d", aExtDisplayConnected);
  1017 	
  1190 	
  1018 	if(iExtDisplayConnected != aExtDisplayConnected)
  1191 	if(iExtDisplayConnected != aExtDisplayConnected)
  1019 	    {
  1192 	    {
  1020 	    iExtDisplayConnected = aExtDisplayConnected;
  1193 	    iExtDisplayConnected = aExtDisplayConnected;
  1021 
  1194         SwitchSurface();
  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 	    }
  1195 	    }
  1044 	else
  1196 	else
  1045 	    {
  1197 	    {
  1046 	    DEBUG_PRINTF("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected No change in ext display connection status");
  1198 	    DEBUG_PRINTF("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected No change in ext display connection status");
  1047 	    }
  1199 	    }
  1052 void CMediaClientVideoDisplayBody::SetWindowArrayPtr2Client()
  1204 void CMediaClientVideoDisplayBody::SetWindowArrayPtr2Client()
  1053     {
  1205     {
  1054     DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetWindowArrayPtr2Client +++");
  1206     DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetWindowArrayPtr2Client +++");
  1055 
  1207 
  1056     iWindowsArrayPtr = &iClientWindows;
  1208     iWindowsArrayPtr = &iClientWindows;
       
  1209     iSwitchedToExternalDisplay = EFalse;
  1057 
  1210 
  1058     DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetWindowArrayPtr2Client ---");
  1211     DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetWindowArrayPtr2Client ---");
  1059     }
  1212     }
  1060 
  1213 
  1061 void CMediaClientVideoDisplayBody::SetWindowArrayPtr2Ext()
  1214 void CMediaClientVideoDisplayBody::SetWindowArrayPtr2Ext()
  1062     {
  1215     {
  1063     DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetWindowArrayPtr2Ext +++");
  1216     DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetWindowArrayPtr2Ext +++");
  1064 
  1217 
  1065     iWindowsArrayPtr = &iExtDisplayWindows;
  1218     iWindowsArrayPtr = &iExtDisplayWindows;
       
  1219     iSwitchedToExternalDisplay = ETrue;
  1066 
  1220 
  1067     DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetWindowArrayPtr2Ext ---");
  1221     DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetWindowArrayPtr2Ext ---");
  1068     }
  1222     }
  1069 
  1223 
  1070 void CMediaClientVideoDisplayBody::CreateExtDisplayHandlerL()
  1224 void CMediaClientVideoDisplayBody::CreateExtDisplayHandlerL()
  1134         iExtDisplaySwitchingSupported = EFalse;
  1288         iExtDisplaySwitchingSupported = EFalse;
  1135         iExtDisplayConnected = EFalse;
  1289         iExtDisplayConnected = EFalse;
  1136         }    
  1290         }    
  1137     DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveExtDisplayPlugin ---");
  1291     DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveExtDisplayPlugin ---");
  1138     }
  1292     }
       
  1293 
       
  1294 void CMediaClientVideoDisplayBody::MmcweoFocusWindowGroupChanged()
       
  1295     {
       
  1296     DEBUG_PRINTF("CMediaClientVideoDisplayBody::MweocFocusWindowGroupChanged +++");
       
  1297     
       
  1298     TBool prevClientWindowIsInFocus = iClientWindowIsInFocus;
       
  1299     UpdateFocus();
       
  1300     
       
  1301     if(prevClientWindowIsInFocus != iClientWindowIsInFocus)
       
  1302         {
       
  1303         SwitchSurface();
       
  1304         }
       
  1305     
       
  1306     DEBUG_PRINTF("CMediaClientVideoDisplayBody::MweocFocusWindowGroupChanged ---");
       
  1307     }
       
  1308 
       
  1309 TBool CMediaClientVideoDisplayBody::MmcweoIgnoreProcess(TSecureId aId)
       
  1310     {
       
  1311     DEBUG_PRINTF("CMediaClientVideoDisplayBody::MmcweoIgnoreProcess +++");
       
  1312     
       
  1313     TBool ignore = ETrue;
       
  1314     if (iServerClient)
       
  1315         {
       
  1316         ignore = iServerClient->IgnoreProcess(aId);
       
  1317         }
       
  1318     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::MmcweoIgnoreProcess --- return %d", ignore);
       
  1319     return ignore;
       
  1320     }
       
  1321 
       
  1322 void CMediaClientVideoDisplayBody::UpdateFocus()
       
  1323     {
       
  1324     DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateFocus +++");
       
  1325     
       
  1326     if(!iWsEventObserver)
       
  1327         {
       
  1328         iClientWindowIsInFocus = ETrue;
       
  1329         DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateFocus Event Observer is NULL");
       
  1330         DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateFocus ---");
       
  1331         return;
       
  1332         }
       
  1333     
       
  1334     TBool prevClientWindowIsInFocus = iClientWindowIsInFocus;
       
  1335     
       
  1336     TInt focusGroupId;
       
  1337     if(iWsEventObserver->FocusWindowGroupId(focusGroupId) == KErrNone)
       
  1338         {
       
  1339         iClientWindowIsInFocus = EFalse;
       
  1340         TInt count = iClientWindows.Count();
       
  1341         for(TInt i = 0; i < count; i++)
       
  1342             {
       
  1343             if(iClientWindows[i].iWindow->WindowGroupId() == focusGroupId)
       
  1344                 {
       
  1345                 iClientWindowIsInFocus = ETrue;
       
  1346                 break;
       
  1347                 }
       
  1348             }
       
  1349         }
       
  1350     else
       
  1351         {
       
  1352         DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateFocus Error retrieving focus WgId from observer");
       
  1353         iClientWindowIsInFocus = ETrue;
       
  1354         }
       
  1355 
       
  1356     if(iServerClient && (prevClientWindowIsInFocus != iClientWindowIsInFocus))
       
  1357         {
       
  1358         DEBUG_PRINTF2("CMediaClientVideoDisplayBody::MweocFocusWindowGroupChanged calling server, focus %d", iClientWindowIsInFocus);
       
  1359         iServerClient->FocusChanged(iClientWindowIsInFocus);
       
  1360         }
       
  1361     
       
  1362     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::UpdateFocus Client window in focus %d", iClientWindowIsInFocus);
       
  1363     DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateFocus ---");
       
  1364     }
       
  1365 
       
  1366 void CMediaClientVideoDisplayBody::SwitchSurface()
       
  1367     {
       
  1368     DEBUG_PRINTF("CMediaClientVideoDisplayBody::SwitchSurface +++");
       
  1369 
       
  1370     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SwitchSurface SurfaceCreated %d", IsSurfaceCreated());
       
  1371     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SwitchSurface Client window count %d", iClientWindows.Count());
       
  1372     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SwitchSurface Client Requested Ext Display Switching %d", iClientRequestedExtDisplaySwitching);
       
  1373     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SwitchSurface Client Window in Focus %d", iClientWindowIsInFocus);
       
  1374     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SwitchSurface External Display Connected %d", iExtDisplayConnected);
       
  1375 
       
  1376     if(IsSurfaceCreated() && (iClientWindows.Count() > 0) && iClientRequestedExtDisplaySwitching &&
       
  1377             iClientWindowIsInFocus && iExtDisplayConnected)
       
  1378         {
       
  1379         TRAPD(err, CreateExtDisplayHandlerL());
       
  1380         DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SwitchSurface CreateExtDisplayHandlerL error %d", err);
       
  1381         if(err == KErrNone)
       
  1382             {
       
  1383             // Set background surface for external display window before removing from client windows.
       
  1384             // Required for switching of paused video
       
  1385             SetWindowArrayPtr2Ext();
       
  1386             RedrawWindows(iCropRegion);
       
  1387             SetWindowArrayPtr2Client();
       
  1388             RemoveBackgroundSurface(ETrue);
       
  1389             SetWindowArrayPtr2Ext();
       
  1390             }
       
  1391         }
       
  1392     else if(iSwitchedToExternalDisplay)
       
  1393         {
       
  1394         // Set background surface for clientwindows before removing from external display window.
       
  1395         // Required for switching of paused video
       
  1396         SetWindowArrayPtr2Client();
       
  1397         RedrawWindows(iCropRegion);
       
  1398         SetWindowArrayPtr2Ext();
       
  1399         RemoveBackgroundSurface(ETrue);
       
  1400         RemoveExtDisplayHandler();
       
  1401         SetWindowArrayPtr2Client();
       
  1402         }
       
  1403 
       
  1404     DEBUG_PRINTF("CMediaClientVideoDisplayBody::SwitchSurface ---");
       
  1405     }
       
  1406 
       
  1407 TBool CMediaClientVideoDisplayBody::IsRotationValid(TVideoRotation aVideoRotation)
       
  1408 	{
       
  1409 	if (aVideoRotation == EVideoRotationNone ||
       
  1410 	    aVideoRotation == EVideoRotationClockwise90 ||
       
  1411 		aVideoRotation == EVideoRotationClockwise180 ||
       
  1412 		aVideoRotation == EVideoRotationClockwise270)
       
  1413 		{
       
  1414 		return ETrue;
       
  1415 		}
       
  1416 
       
  1417 	DEBUG_PRINTF2("CMediaClientVideoDisplayBody::IsRotationValid - Rotation %d not valid", aVideoRotation);
       
  1418 	return EFalse;
       
  1419 	}
       
  1420 
       
  1421 TBool CMediaClientVideoDisplayBody::IsAutoScaleTypeValid(TAutoScaleType aAutoScaleType)
       
  1422 	{
       
  1423 	if (aAutoScaleType == EAutoScaleNone ||
       
  1424 	    aAutoScaleType == EAutoScaleBestFit ||
       
  1425 	    aAutoScaleType == EAutoScaleClip ||
       
  1426 	    aAutoScaleType == EAutoScaleStretch)
       
  1427 		{
       
  1428 		return ETrue;
       
  1429 		}
       
  1430 
       
  1431 	DEBUG_PRINTF2("CMediaClientVideoDisplayBody::IsAutoScaleTypeValid - Auto scale %d not valid", aAutoScaleType);
       
  1432 	return EFalse;
       
  1433 	}
       
  1434 
       
  1435 /**
       
  1436 Check whether a change in the surface crop rectangle would mean that the surface viewport calculated in SetBackgroundSurface would change.
       
  1437 The surface viewport is the intersection of the surface crop rectangle and the client crop region
       
  1438 */
       
  1439 TBool CMediaClientVideoDisplayBody::SurfaceCropRectChangeRequiresRedraw(TRect aOldSurfaceCropRect, TRect aNewSurfaceCropRect, TRect aClientCropRegion)
       
  1440 	{
       
  1441 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SurfaceCropRectChangeRequiresRedraw +++");
       
  1442 	
       
  1443 	// If aClientCropRegion is empty then it is not currently being used in the SetBackgroundSurface calculations.
       
  1444 	// This means that only aOldSurfaceCropRect is being used to decide which part of the video is displayed.
       
  1445 	// By setting aClientCropRect to the same as aOldSurfaceCropRect we ensure that only aOldSurfaceCropRect is
       
  1446 	// used in the subsequent intersection area checks.
       
  1447 	if (aClientCropRegion.IsEmpty())
       
  1448 		{
       
  1449 		DEBUG_PRINTF("CMediaClientVideoDisplayBody::SurfaceCropRectChangeRequiresRedraw - Client crop region is empty");		
       
  1450 		aClientCropRegion = aOldSurfaceCropRect;
       
  1451 		}
       
  1452 
       
  1453 	TBool ret = IntersectionAreaChanged(aOldSurfaceCropRect, aNewSurfaceCropRect, aClientCropRegion);
       
  1454 
       
  1455 	DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SurfaceCropRectChangeRequiresRedraw --- ret = %d", ret);
       
  1456 
       
  1457 	return ret;
       
  1458 	}
       
  1459 
       
  1460 /**
       
  1461 Check whether a change in the client crop region would mean that the surface viewport calculated in SetBackgroundSurface would change.
       
  1462 The surface viewport is the intersection of the surface crop rectangle and the client crop region
       
  1463 */
       
  1464 TBool CMediaClientVideoDisplayBody::ClientCropRegionChangeRequiresRedraw(TRect aOldClientCropRegion, TRect aNewClientCropRegion, TRect aSurfaceCropRect)
       
  1465 	{
       
  1466 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::ClientCropRegionChangeRequiresRedraw +++");
       
  1467 
       
  1468 	// If aOldClientCropRegion is empty then it is not currently being used in the SetBackgroundSurface calculations.
       
  1469 	// This means that only aSurfaceCropRect is being used to decide which part of the video is displayed. By
       
  1470 	// setting aOldClientCropRegion to the same as aSurfaceCropRect we ensure that only aSurfaceCropRect is
       
  1471 	// used in the subsequent intersection area checks.
       
  1472 	if (aOldClientCropRegion.IsEmpty())
       
  1473 		{
       
  1474 		DEBUG_PRINTF("CMediaClientVideoDisplayBody::ClientCropRegionChangeRequiresRedraw - Old client crop region is empty");
       
  1475 		aOldClientCropRegion = aSurfaceCropRect;
       
  1476 		}
       
  1477 
       
  1478 	// If aNewClientCropRegion is empty then it will not be used in the SetBackgroundSurface calculations.
       
  1479 	// This means that only aSurfaceCropRect will impact which part of the video is displayed. By
       
  1480 	// setting aNewClientCropRegion to the same as aSurfaceCropRect we ensure that only aSurfaceCropRect is
       
  1481 	// used in the subsequent intersection area checks.
       
  1482 	if (aNewClientCropRegion.IsEmpty())
       
  1483 		{
       
  1484 		DEBUG_PRINTF("CMediaClientVideoDisplayBody::ClientCropRegionChangeRequiresRedraw - New client crop region is empty");
       
  1485 		aNewClientCropRegion = aSurfaceCropRect;
       
  1486 		}
       
  1487 
       
  1488 	TBool ret = IntersectionAreaChanged(aOldClientCropRegion, aNewClientCropRegion, aSurfaceCropRect);
       
  1489 
       
  1490 	DEBUG_PRINTF2("CMediaClientVideoDisplayBody::ClientCropRegionChangeRequiresRedraw --- ret = %d", ret);
       
  1491 
       
  1492 	return ret;
       
  1493 	}
       
  1494 
       
  1495 /**
       
  1496 Check whether the change in size of a rectangle means its intersection with another rectangle has changed.
       
  1497 This is used to check whether changes in things like the surface crop rectangle, client crop region, and window clip rectangle, would mean
       
  1498 the area of video displayed would change.
       
  1499 */
       
  1500 TBool CMediaClientVideoDisplayBody::IntersectionAreaChanged(TRect aOldRect, TRect aNewRect, TRect aOtherRect)
       
  1501 	{
       
  1502 	DEBUG_PRINTF5("CMediaClientVideoDisplayBody::IntersectionAreaChanged - aOldRect %d,%d - %d,%d", aOldRect.iTl.iX, aOldRect.iTl.iY, aOldRect.iBr.iX, aOldRect.iBr.iY);
       
  1503 	DEBUG_PRINTF5("CMediaClientVideoDisplayBody::IntersectionAreaChanged - aNewRect %d,%d - %d,%d", aNewRect.iTl.iX, aNewRect.iTl.iY, aNewRect.iBr.iX, aNewRect.iBr.iY);
       
  1504 	DEBUG_PRINTF5("CMediaClientVideoDisplayBody::IntersectionAreaChanged - aOtherRect %d,%d - %d,%d", aOtherRect.iTl.iX, aOtherRect.iTl.iY, aOtherRect.iBr.iX, aOtherRect.iBr.iY);
       
  1505 
       
  1506 	aOldRect.Intersection(aOtherRect);
       
  1507 	aNewRect.Intersection(aOtherRect);
       
  1508 
       
  1509 	if (aOldRect != aNewRect)
       
  1510 		{
       
  1511 		DEBUG_PRINTF("CMediaClientVideoDisplayBody::IntersectionAreaChanged - Intersection area has changed");
       
  1512 		return ETrue;
       
  1513 		}
       
  1514 
       
  1515 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::IntersectionAreaChanged - Intersection area has not changed");
       
  1516 	return EFalse;
       
  1517 	}