mmlibs/mmfw/src/Client/Video/mediaclientvideodisplaybody.cpp
branchRCL_3
changeset 12 b74061f7f3d2
parent 11 d5f04de580b7
child 19 8184f75a63d4
equal deleted inserted replaced
11:d5f04de580b7 12:b74061f7f3d2
   164     DEBUG_PRINTF3("CMediaClientVideoDisplayBody::AddDisplayWindowL - aScaleWidth %f, aScaleHeight %f", aScaleWidth, aScaleHeight);
   164     DEBUG_PRINTF3("CMediaClientVideoDisplayBody::AddDisplayWindowL - aScaleWidth %f, aScaleHeight %f", aScaleWidth, aScaleHeight);
   165     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::AddDisplayWindowL - aRotation %d", aRotation);
   165     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::AddDisplayWindowL - aRotation %d", aRotation);
   166     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::AddDisplayWindowL - aAutoScaleType %d", aAutoScaleType);
   166     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::AddDisplayWindowL - aAutoScaleType %d", aAutoScaleType);
   167     DEBUG_PRINTF3("CMediaClientVideoDisplayBody::AddDisplayWindowL - aHorizPos %d, aVertPos %d", aHorizPos, aVertPos);
   167     DEBUG_PRINTF3("CMediaClientVideoDisplayBody::AddDisplayWindowL - aHorizPos %d, aVertPos %d", aHorizPos, aVertPos);
   168 
   168 
       
   169 	if (!IsRotationValid(aRotation))
       
   170 		{
       
   171 		User::Leave(KErrArgument);
       
   172 		}
       
   173 
       
   174 	if (!IsAutoScaleTypeValid(aAutoScaleType))
       
   175 		{
       
   176 		User::Leave(KErrArgument);
       
   177 		}
       
   178 
   169 	TInt pos = iClientWindows.Find(aWindow->WsHandle(), TWindowData::CompareByWsHandle);
   179 	TInt pos = iClientWindows.Find(aWindow->WsHandle(), TWindowData::CompareByWsHandle);
   170 	
   180 	
   171 	if (pos != KErrNotFound)
   181 	if (pos != KErrNotFound)
   172 		{
   182 		{
   173 		User::Leave(KErrInUse);
   183 		User::Leave(KErrInUse);
   293             }
   303             }
   294         }
   304         }
   295     
   305     
   296     err = RedrawWindows(aCropRegion);
   306     err = RedrawWindows(aCropRegion);
   297     
   307     
   298     DEBUG_PRINTF("CMediaClientVideoDisplayBody::SurfaceCreated ---");
   308     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SurfaceCreated --- Return error %d", err);
   299 	return err;
   309 	return err;
   300 	}
   310 	}
   301 
   311 
   302 void CMediaClientVideoDisplayBody::RemoveBackgroundSurface(TBool aTriggerRedraw)
   312 void CMediaClientVideoDisplayBody::RemoveBackgroundSurface(TBool aTriggerRedraw)
   303 	{
   313 	{
   352     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);
   353     DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SurfaceCreated - aAspectRatio %d/%d", aAspectRatio.iNumerator, aAspectRatio.iDenominator);
   363     DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SurfaceCreated - aAspectRatio %d/%d", aAspectRatio.iNumerator, aAspectRatio.iDenominator);
   354 
   364 
   355     if (!IsSurfaceCreated())
   365     if (!IsSurfaceCreated())
   356 		{
   366 		{
       
   367 		DEBUG_PRINTF("CMediaClientVideoDisplayBody::SurfaceParametersChanged --- Return error KErrNotSupproted");
   357 		return KErrNotSupported;
   368 		return KErrNotSupported;
   358 		}
   369 		}
   359 
   370 
   360 	if (iSurfaceId != aSurfaceId)
   371 	if (iSurfaceId != aSurfaceId)
   361 		{
   372 		{
       
   373 		DEBUG_PRINTF("CMediaClientVideoDisplayBody::SurfaceParametersChanged --- Return error KErrInUse");
   362 		return KErrInUse;
   374 		return KErrInUse;
   363 		}
   375 		}
   364 	
   376 
   365 	iCropRect = aCropRect;
       
   366 	iAspectRatio = aAspectRatio;
       
   367 	
       
   368 	if (iEventHandler)
   377 	if (iEventHandler)
   369 		{
   378 		{
   370 		iEventHandler->MmsehSurfaceParametersChanged(iSurfaceId, iCropRect, iAspectRatio);
   379 		iEventHandler->MmsehSurfaceParametersChanged(iSurfaceId, aCropRect, aAspectRatio);
   371 		}
   380 		}
   372 
   381 
   373 	RedrawWindows(iCropRegion);
   382 	TInt error = KErrNone;
   374 	
   383 	if (iCropRect != aCropRect || iAspectRatio != aAspectRatio)
   375 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SurfaceParametersChanged ---");
   384 		{
   376 	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;
   377 	}
   408 	}
   378 	
   409 	
   379 TInt CMediaClientVideoDisplayBody::RedrawWindows(const TRect& aCropRegion)
   410 TInt CMediaClientVideoDisplayBody::RedrawWindows(const TRect& aCropRegion)
   380 	{
   411 	{
   381 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::RedrawWindows +++");
   412 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::RedrawWindows +++");
   400 		
   431 		
   401 	DEBUG_PRINTF2("CMediaClientVideoDisplayBody::RedrawWindows --- return with %d", err);
   432 	DEBUG_PRINTF2("CMediaClientVideoDisplayBody::RedrawWindows --- return with %d", err);
   402 	return err;
   433 	return err;
   403 	}
   434 	}
   404 
   435 
   405 void CMediaClientVideoDisplayBody::UpdateCropRegionL(const TRect& aCropRegion, TInt aPos)
   436 void CMediaClientVideoDisplayBody::UpdateCropRegionL(const TRect& aCropRegion, TInt aPos, TBool aRedrawIndividualWindow)
   406     {
   437     {
   407     DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateCropRegionL +++");
   438     DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateCropRegionL +++");
   408 
   439 
   409     TRect prevCropRegion(iCropRegion);
   440     TRect prevCropRegion(iCropRegion);
   410     iCropRegion = aCropRegion;
   441     iCropRegion = aCropRegion;
   411     
   442     
   412     if (IsSurfaceCreated())
   443     if (IsSurfaceCreated())
   413         {
   444         {
   414         if(prevCropRegion == aCropRegion)
   445         if(prevCropRegion == aCropRegion)
   415             {
   446             {
   416             if(!iSwitchedToExternalDisplay)
   447             if(!iSwitchedToExternalDisplay && aRedrawIndividualWindow)
   417                 {
   448                 {
   418                 User::LeaveIfError(SetBackgroundSurface(iClientWindows[aPos], aCropRegion));
   449                 User::LeaveIfError(SetBackgroundSurface(iClientWindows[aPos], aCropRegion));
   419                 }
   450                 }
   420             }
   451             }
   421         else
   452         else
   422             {
   453             {
   423             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 				}
   424             }
   460             }
   425         }
   461         }
   426     DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateCropRegionL ---");    
   462     DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateCropRegionL ---");    
   427     }
   463     }
   428 
   464 
   432     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetAutoScaleL - aWindow WsHandle 0x%X", aWindow.WsHandle());
   468     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetAutoScaleL - aWindow WsHandle 0x%X", aWindow.WsHandle());
   433     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetAutoScaleL - aScaleType %d", aScaleType);
   469     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetAutoScaleL - aScaleType %d", aScaleType);
   434     DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SetAutoScaleL - aHorizPos %d, aVertPos %d", aHorizPos, aVertPos);
   470     DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SetAutoScaleL - aHorizPos %d, aVertPos %d", aHorizPos, aVertPos);
   435     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);
   436 
   472 
       
   473 	if (!IsAutoScaleTypeValid(aScaleType))
       
   474 		{
       
   475 		User::Leave(KErrArgument);
       
   476 		}
       
   477 
   437     TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
   478     TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
   438 	User::LeaveIfError(pos);
   479 	User::LeaveIfError(pos);
   439 	
   480 
   440 	iClientWindows[pos].iAutoScaleType = aScaleType;
   481 	TBool parameterChanged = EFalse;
   441 	iClientWindows[pos].iHorizPos = aHorizPos;
   482 	if (aScaleType != iClientWindows[pos].iAutoScaleType || aHorizPos != iClientWindows[pos].iHorizPos || aVertPos != iClientWindows[pos].iVertPos)
   442 	iClientWindows[pos].iVertPos = aVertPos;
   483 		{
   443 
   484 		iClientWindows[pos].iAutoScaleType = aScaleType;
   444 	UpdateCropRegionL(aCropRegion, pos);
   485 		iClientWindows[pos].iHorizPos = aHorizPos;
   445 	
   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 
   446 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetAutoScaleL ---");
   496 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetAutoScaleL ---");
   447 	}
   497 	}
   448 	
   498 	
   449 
   499 
   450 void CMediaClientVideoDisplayBody::SetRotationL(const RWindowBase& aWindow, TVideoRotation aRotation, const TRect& aCropRegion)
   500 void CMediaClientVideoDisplayBody::SetRotationL(const RWindowBase& aWindow, TVideoRotation aRotation, const TRect& aCropRegion)
   452 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetRotationL +++");
   502 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetRotationL +++");
   453     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetRotationL - aWindow WsHandle 0x%X", aWindow.WsHandle());
   503     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetRotationL - aWindow WsHandle 0x%X", aWindow.WsHandle());
   454     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetRotationL - aRotation %d", aRotation);
   504     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetRotationL - aRotation %d", aRotation);
   455     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);
   456 
   506 
       
   507 	if (!IsRotationValid(aRotation))
       
   508 		{
       
   509 		User::Leave(KErrArgument);
       
   510 		}
       
   511 
   457     TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
   512     TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
   458 	User::LeaveIfError(pos);
   513 	User::LeaveIfError(pos);
   459 	
   514 
   460 	iClientWindows[pos].iRotation = aRotation;
   515 	TBool parameterChanged = EFalse;
   461 
   516 	if (aRotation != iClientWindows[pos].iRotation)
   462     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);
   463 
   527 
   464 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetRotationL ---");
   528 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetRotationL ---");
   465 	}
   529 	}
   466 
   530 
   467 TVideoRotation CMediaClientVideoDisplayBody::RotationL(const RWindowBase& aWindow)
   531 TVideoRotation CMediaClientVideoDisplayBody::RotationL(const RWindowBase& aWindow)
   487 	if (aWidthPercentage <= 0.0 || aHeightPercentage <= 0.0)
   551 	if (aWidthPercentage <= 0.0 || aHeightPercentage <= 0.0)
   488 		{
   552 		{
   489 		User::Leave(KErrArgument);
   553 		User::Leave(KErrArgument);
   490 		}
   554 		}
   491 
   555 
   492 	iClientWindows[pos].iScaleWidth = aWidthPercentage;
   556 	TBool parameterChanged = EFalse;
   493 	iClientWindows[pos].iScaleHeight = aHeightPercentage;
   557 	if (aWidthPercentage != iClientWindows[pos].iScaleWidth ||
   494 	iClientWindows[pos].iAutoScaleType = EAutoScaleNone;
   558 	    aHeightPercentage != iClientWindows[pos].iScaleHeight ||
   495 	
   559 		EAutoScaleNone != iClientWindows[pos].iAutoScaleType)
   496     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);
   497 	
   572 	
   498     DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetScaleFactorL ---");
   573     DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetScaleFactorL ---");
   499 	}
   574 	}
   500 	
   575 	
   501 void CMediaClientVideoDisplayBody::GetScaleFactorL(const RWindowBase& aWindow, TReal32& aWidthPercentage, TReal32& aHeightPercentage)
   576 void CMediaClientVideoDisplayBody::GetScaleFactorL(const RWindowBase& aWindow, TReal32& aWidthPercentage, TReal32& aHeightPercentage)
   513 	{
   588 	{
   514 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetAutoScaleL +++");
   589 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetAutoScaleL +++");
   515     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetAutoScaleL - aScaleType %d", aScaleType);
   590     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetAutoScaleL - aScaleType %d", aScaleType);
   516     DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SetAutoScaleL - aHorizPos %d, aVertPos %d", aHorizPos, aVertPos);
   591     DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SetAutoScaleL - aHorizPos %d, aVertPos %d", aHorizPos, aVertPos);
   517     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);
   518 	
   593 
       
   594 	if (!IsAutoScaleTypeValid(aScaleType))
       
   595 		{
       
   596 		User::Leave(KErrArgument);
       
   597 		}
       
   598 
   519     TRect prevCropRegion(iCropRegion);
   599     TRect prevCropRegion(iCropRegion);
   520 	iCropRegion = aCropRegion;
   600 	iCropRegion = aCropRegion;
       
   601 	
       
   602 	TBool parameterChanged;
   521 	TInt count = iClientWindows.Count();
   603 	TInt count = iClientWindows.Count();
   522 	
   604 
   523 	for (TInt i = 0; i < count; ++i)
   605 	for (TInt i = 0; i < count; ++i)
   524 		{
   606 		{
   525 		iClientWindows[i].iAutoScaleType = aScaleType;
   607 		parameterChanged = EFalse;
   526 		iClientWindows[i].iHorizPos = aHorizPos;
   608 		if (aScaleType != iClientWindows[i].iAutoScaleType || aHorizPos != iClientWindows[i].iHorizPos || aVertPos != iClientWindows[i].iVertPos)
   527 		iClientWindows[i].iVertPos = aVertPos;
   609 			{
   528 	    if (IsSurfaceCreated() && !iSwitchedToExternalDisplay)
   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)))
   529 			{
   623 			{
   530 			User::LeaveIfError(SetBackgroundSurface(iClientWindows[i], aCropRegion));
   624 			User::LeaveIfError(SetBackgroundSurface(iClientWindows[i], aCropRegion));
   531 			}
   625 			}
   532 		}
   626 		}
   533 	
   627 
   534 	if (IsSurfaceCreated() && iSwitchedToExternalDisplay && (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))
   535         {
   631         {
   536         User::LeaveIfError(RedrawWindows(aCropRegion));
   632         User::LeaveIfError(RedrawWindows(aCropRegion));
   537         }
   633         }
   538 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetAutoScaleL ---");
   634 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetAutoScaleL ---");
   539 	}
   635 	}
   543 	{
   639 	{
   544 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetRotationL +++");
   640 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetRotationL +++");
   545     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetRotationL - aRotation %d", aRotation);
   641     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetRotationL - aRotation %d", aRotation);
   546     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);
   547 
   643 
       
   644 	if (!IsRotationValid(aRotation))
       
   645 		{
       
   646 		User::Leave(KErrArgument);
       
   647 		}
       
   648 
   548     TRect prevCropRegion(iCropRegion);
   649     TRect prevCropRegion(iCropRegion);
   549     iCropRegion = aCropRegion;
   650     iCropRegion = aCropRegion;
       
   651 
       
   652 	TBool parameterChanged;
   550 	TInt count = iClientWindows.Count();
   653 	TInt count = iClientWindows.Count();
   551 	
   654 	
   552 	for (TInt i = 0; i < count; ++i)
   655 	for (TInt i = 0; i < count; ++i)
   553 		{
   656 		{
   554 		iClientWindows[i].iRotation = aRotation;
   657 		parameterChanged = EFalse;
   555         if (IsSurfaceCreated() && !iSwitchedToExternalDisplay)
   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)))
   556 			{
   671 			{
   557 			User::LeaveIfError(SetBackgroundSurface(iClientWindows[i], aCropRegion));
   672 			User::LeaveIfError(SetBackgroundSurface(iClientWindows[i], aCropRegion));
   558 			}
   673 			}
   559 		}
   674 		}
   560 	
   675 	
   561     if (IsSurfaceCreated() && iSwitchedToExternalDisplay && (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))
   562         {
   679         {
   563         User::LeaveIfError(RedrawWindows(aCropRegion));
   680         User::LeaveIfError(RedrawWindows(aCropRegion));
   564         }
   681         }
   565 	   
   682 	   
   566 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetRotationL ---");
   683 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetRotationL ---");
   577 		User::Leave(KErrArgument);
   694 		User::Leave(KErrArgument);
   578 		}
   695 		}
   579 	
   696 	
   580     TRect prevCropRegion(iCropRegion);
   697     TRect prevCropRegion(iCropRegion);
   581 	iCropRegion = aCropRegion;
   698 	iCropRegion = aCropRegion;
       
   699 
       
   700 	TBool parameterChanged;
   582 	TInt count = iClientWindows.Count();
   701 	TInt count = iClientWindows.Count();
   583 	
   702 	
   584 	for (TInt i = 0; i < count; ++i)
   703 	for (TInt i = 0; i < count; ++i)
   585 		{
   704 		{
   586 		iClientWindows[i].iScaleWidth = aWidthPercentage;
   705 		parameterChanged = EFalse;
   587 		iClientWindows[i].iScaleHeight = aHeightPercentage;
   706 		
   588 		iClientWindows[i].iAutoScaleType = EAutoScaleNone;
   707 		if (aWidthPercentage != iClientWindows[i].iScaleWidth ||
   589         if (IsSurfaceCreated() && !iSwitchedToExternalDisplay)
   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)))
   590 			{
   724 			{
   591 			User::LeaveIfError(SetBackgroundSurface(iClientWindows[i], aCropRegion));
   725 			User::LeaveIfError(SetBackgroundSurface(iClientWindows[i], aCropRegion));
   592 			}
   726 			}
   593 		}
   727 		}
   594 	
   728 
   595     if (IsSurfaceCreated() && iSwitchedToExternalDisplay && (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))
   596         {
   732         {
   597         User::LeaveIfError(RedrawWindows(aCropRegion));
   733         User::LeaveIfError(RedrawWindows(aCropRegion));
   598         }
   734         }
   599 	   
   735 	   
   600 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetScaleFactorL ---");
   736 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetScaleFactorL ---");
   607     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);
   608     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);
   609 	
   745 	
   610 	TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
   746 	TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
   611 	User::LeaveIfError(pos);
   747 	User::LeaveIfError(pos);
   612 	
   748 
   613 	iClientWindows[pos].iClipRect = aWindowClipRect;
   749 	TBool parameterChanged = EFalse;
   614 
   750 	if (aWindowClipRect != iClientWindows[pos].iClipRect)
   615     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);
   616 
   766 
   617     DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetWindowClipRectL ---");
   767     DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetWindowClipRectL ---");
   618 	}
   768 	}
   619 	
   769 	
   620 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)
   624     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);
   625     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);
   626 
   776 
   627     TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
   777     TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
   628 	User::LeaveIfError(pos);
   778 	User::LeaveIfError(pos);
   629 	
   779 
   630 	iClientWindows[pos].iVideoExtent = aVideoExtent;
   780 	TBool parameterChanged = EFalse;
   631 
   781 	if (aVideoExtent != iClientWindows[pos].iVideoExtent)
   632     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);
   633     
   792     
   634 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetVideoExtentL ---");
   793 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetVideoExtentL ---");
   635 	}
   794 	}
   636 	
   795 	
   637 TBool CMediaClientVideoDisplayBody::HasWindows() const
   796 TBool CMediaClientVideoDisplayBody::HasWindows() const
  1219         {
  1378         {
  1220         TRAPD(err, CreateExtDisplayHandlerL());
  1379         TRAPD(err, CreateExtDisplayHandlerL());
  1221         DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SwitchSurface CreateExtDisplayHandlerL error %d", err);
  1380         DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SwitchSurface CreateExtDisplayHandlerL error %d", err);
  1222         if(err == KErrNone)
  1381         if(err == KErrNone)
  1223             {
  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();
  1224             RemoveBackgroundSurface(ETrue);
  1388             RemoveBackgroundSurface(ETrue);
  1225             SetWindowArrayPtr2Ext();
  1389             SetWindowArrayPtr2Ext();
  1226             RedrawWindows(iCropRegion);
       
  1227             }
  1390             }
  1228         }
  1391         }
  1229     else if(iSwitchedToExternalDisplay)
  1392     else if(iSwitchedToExternalDisplay)
  1230         {
  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();
  1231         RemoveBackgroundSurface(ETrue);
  1399         RemoveBackgroundSurface(ETrue);
  1232         RemoveExtDisplayHandler();
  1400         RemoveExtDisplayHandler();
  1233         SetWindowArrayPtr2Client();
  1401         SetWindowArrayPtr2Client();
  1234         RedrawWindows(iCropRegion);
       
  1235         }
  1402         }
  1236 
  1403 
  1237     DEBUG_PRINTF("CMediaClientVideoDisplayBody::SwitchSurface ---");
  1404     DEBUG_PRINTF("CMediaClientVideoDisplayBody::SwitchSurface ---");
  1238     }
  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 	}