javauis/mmapi_qt/baseline/src.nga/cmmasurfacewindow.cpp
changeset 26 dc7c549001d5
parent 23 98ccebc37403
child 47 f40128debb5d
child 49 35baca0e7a2e
--- a/javauis/mmapi_qt/baseline/src.nga/cmmasurfacewindow.cpp	Fri May 14 15:47:24 2010 +0300
+++ b/javauis/mmapi_qt/baseline/src.nga/cmmasurfacewindow.cpp	Thu May 27 12:49:31 2010 +0300
@@ -18,6 +18,7 @@
 
 //  Include Files
 #include <logger.h>
+#include <W32STD.H>
 #include "cmmasurfacewindow.h"
 #include "cmmaplayer.h"
 
@@ -67,29 +68,34 @@
     // Ignored, this window will not be used for actual drawing
 }
 
-void CMMASurfaceWindow::SetDrawRectThread( const TRect& aRect )
-    {
-    LOG2( EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::SetDrawRectThread TL %d %d",
-    	aRect.iTl.iX, aRect.iTl.iY );
-    LOG2( EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::SetDrawRectThread BR %d %d",
-    	aRect.iBr.iX, aRect.iBr.iY );
+void CMMASurfaceWindow::SetDrawRectThread(const TRect& aRect)
+{
+    LOG2(EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::SetDrawRectThread TL %d %d",
+         aRect.iTl.iX, aRect.iTl.iY);
+    LOG2(EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::SetDrawRectThread BR %d %d",
+         aRect.iBr.iX, aRect.iBr.iY);
 
     iContentRect = aRect;
-    
+
     TInt error = StaticRedrawVideo(*this);
-    if ( KErrNone != error  )
-		 {
-     ELOG1( EJavaMMAPI, "MID::CMMASurfaceWindow::SetDrawRectThread, StaticRedrawVideo error = %d", error);
-     }
+    if (KErrNone != error)
+    {
+        ELOG1(EJavaMMAPI, "MID::CMMASurfaceWindow::SetDrawRectThread, StaticRedrawVideo error = %d", error);
     }
+}
 
 void CMMASurfaceWindow::SetRWindowRect(const TRect& aRect,
                                        MMMADisplay::TThreadType aThreadType)
 {
-		LOG2( EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::SetRWindowRect TL %d %d",
-               aRect.iTl.iX, aRect.iTl.iY);
-    LOG2( EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::SetRWindowRect BR %d %d",
-               aRect.iBr.iX, aRect.iBr.iY);
+    LOG2(EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::SetRWindowRect TL %d %d",
+         aRect.iTl.iX, aRect.iTl.iY);
+    LOG2(EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::SetRWindowRect BR %d %d",
+         aRect.iBr.iX, aRect.iBr.iY);
+
+    if (iRWindowRect == aRect)
+    {
+        return;
+    }
 
     iRWindowRect = aRect;
 
@@ -97,68 +103,36 @@
     {
         if (iDisplay)
         {
-				/*		    iDisplay->UIGetCallback( *this,
-                                    CMMASurfaceWindow::ESetDrawRect);
-        */                            
-	     // MMAPI UI 3.x req.
-	     iDisplay->GetCallbackInUiThread( (TInt)CMMASurfaceWindow::ESetDrawRect );
-       LOG(EJavaMMAPI,EInfo,"MID::CMMASurfaceWindow::SetRWindowRect after GetCallbackInUiThread " );
-
+            //iDisplay->UIGetCallback(*this,
+//                                    CMMASurfaceWindow::ESetClipRect);
+            // MMAPI UI 3.x req.
+            iDisplay->GetCallbackInUiThread((TInt)CMMASurfaceWindow::ESetClipRect);
         }
     }
     else if (MMMADisplay::EUiThread == aThreadType)
     {
-        /*TInt error = StaticRedrawVideo(*this);
+        TInt error = SetClipRect();
         if (KErrNone != error)
         {
-		   LOG1(EJavaMMAPI,EInfo,"MID::CMMASurfaceWindow::SetRWindowRect, StaticRedrawVideo error = %d", error);
+            LOG1(EJavaMMAPI,EInfo,"MID::CMMASurfaceWindow::SetRWindowRect, error = %d", error);
         }
-				*/
-		   LOG(EJavaMMAPI,EInfo,"MID::CMMASurfaceWindow::SetRWindowRect else GetCallbackInUiThread + " );
-		   iDisplay->GetCallbackInUiThread( (TInt)CMMASurfaceWindow::ESetDrawRect );
-       LOG(EJavaMMAPI,EInfo,"MID::CMMASurfaceWindow::SetRWindowRect else GetCallbackInUiThread -" );
     }
 }
 
-void CMMASurfaceWindow::SetDrawRect( const TRect& aRect )
-		{
-		LOG2( EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::SetDrawRect TL %d %d",
-    	aRect.iTl.iX, aRect.iTl.iY );
-    LOG2( EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::SetDrawRect BR %d %d",
-    	aRect.iBr.iX, aRect.iBr.iY );
+TInt CMMASurfaceWindow::SetClipRect()
+{
+    LOG(EJavaMMAPI,EInfo,"MID::CMMASurfaceWindow::SetClipRect");
 
-		iContentRect = aRect;
-		if ( iDisplay )
-		  {
-		 // iDisplay->UIGetCallback( *this,
-		  //                         CMMASurfaceWindow::ESetDrawRect );
-		   // MMAPI UI 3.x req.
-		   iDisplay->GetCallbackInUiThread((TInt)CMMASurfaceWindow::ESetDrawRect);
-       LOG(EJavaMMAPI,EInfo,"MID::CMMASurfaceWindow::SetDrawRect, after GetCallbackInUiThread");
-		  }
-		}
+    // CMediaClientVideoDisplay expects client to RemoveDisplayWindow
+    // and AddDisplayWindow again everytime when RWindow rect changes
+    if (iMediaClientVideoDisplay && iWindow)
+    {
+        iMediaClientVideoDisplay->RemoveDisplayWindow(*iWindow);
 
-TInt CMMASurfaceWindow::StaticRedrawVideo(CMMASurfaceWindow& aSurfaceWindow)
-{
-    TRAPD(error, aSurfaceWindow.RedrawVideoL());
-    return error;
-}
-
-void CMMASurfaceWindow::RedrawVideoL()
-{
-    if (!iMediaClientVideoDisplay)
-    {
-      LOG( EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::RedrawVideoL: no MediaClientVideoDisplay set, aborting -" );
-        return;
-    }
-
-    if (iWindow)
-    {
         TRect contentRect;
         if (iVisible)
         {
             contentRect = iContentRect;
-            ScaleVideoL(contentRect);
         }
         else
         {
@@ -175,52 +149,133 @@
         TRect drawRect = contentRect;
         drawRect.Move(relativeParentRect.iTl);
 
-        // Area where should be drawn is the intersection of drawRect and relativeParentRect.
-        TRect areaRect = relativeParentRect;
-        areaRect.Intersection(drawRect);
-
-        iMediaClientVideoDisplay->SetWindowClipRectL(*iWindow,
-                areaRect,
-                iVideoCropRegion);
+        TRect clipRect(0,0,iRWindowRect.Width(),iRWindowRect.Height());
+        TRAPD(error, iMediaClientVideoDisplay->AddDisplayWindowL(iWindow,
+                clipRect, // new clip rect
+                iVideoCropRegion,
+                drawRect,  // video extent
+                0.0f, // ignore
+                0.0f, // ignore
+                EVideoRotationNone,
+                EAutoScaleBestFit,
+                EHorizontalAlignLeft,
+                EVerticalAlignTop,
+                (RWindow*)iWindow));
 
-        iMediaClientVideoDisplay->SetVideoExtentL(*iWindow,
-                areaRect,
-                iVideoCropRegion);
+        LOG(EJavaMMAPI,EInfo,"MID::CMMASurfaceWindow::SetClipRect -");
+        return error;
+    }
+    return KErrNone;
+}
 
-			LOG2( EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::RedrawVideoL: RedrawWindows() areaRect is %d X %d",areaRect.Width(),areaRect.Height() );
+void CMMASurfaceWindow::SetDrawRect(const TRect& aRect)
+{
+    LOG2(EJavaMMAPI,EInfo,"MID::CMMASurfaceWindow::SetDrawRect TL %d %d",
+         aRect.iTl.iX, aRect.iTl.iY);
+    LOG2(EJavaMMAPI,EInfo,"MID::CMMASurfaceWindow::SetDrawRect BR %d %d",
+         aRect.iBr.iX, aRect.iBr.iY);
 
-        iMediaClientVideoDisplay->RedrawWindows(iVideoCropRegion);
+    iContentRect = aRect;
+    if (iDisplay)
+    {
+        // iDisplay->UIGetCallback( *this,
+        //                         CMMASurfaceWindow::ESetDrawRect );
+        // MMAPI UI 3.x req.
+        iDisplay->GetCallbackInUiThread((TInt)CMMASurfaceWindow::ESetDrawRect);
+        LOG(EJavaMMAPI,EInfo,"MID::CMMASurfaceWindow::SetDrawRect, after GetCallbackInUiThread");
     }
 }
 
-void CMMASurfaceWindow::ScaleVideoL(const TRect& aRect)
+TInt CMMASurfaceWindow::StaticRedrawVideo(CMMASurfaceWindow& aSurfaceWindow)
 {
-    // return without scaling incase cropregion dimensions are zero
-    if (!(iVideoCropRegion.Width() && iVideoCropRegion.Height()))
+    LOG(EJavaMMAPI,EInfo,"CMMASurfaceWindow::RedrawVideoL +");
+    TRAPD(error, aSurfaceWindow.RedrawVideoL());
+    LOG1(EJavaMMAPI,EInfo,"CMMASurfaceWindow::RedrawVideoL - error = %d",error);
+    return error;
+}
+
+void CMMASurfaceWindow::RedrawVideoL()
+{
+    LOG(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::RedrawVideoL +");
+    if (!iMediaClientVideoDisplay)
     {
+        LOG(EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::RedrawVideoL: no MediaClientVideoDisplay set, aborting -");
         return;
     }
+    iVisible = true;
+    if (iWindow)
+    {
+        TRect contentRect;
+        if (iVisible)
+        {
+            LOG2(EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::RedrawVideoL: if visible true iContentRect = %d X %d",iContentRect.Width(),iContentRect.Height());
+            contentRect = iContentRect;
+            // ScaleVideoL(contentRect);
+        }
+        else
+        {
+            LOG(EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::RedrawVideoL - if visible false");
+            TRect emptyRect(0,0,0,0);
+            contentRect = emptyRect;
+        }
+        LOG2(EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::RedrawVideoL: RedrawWindows() - before intersection contentRect = %d X %d",contentRect.Width(),contentRect.Height());
 
-    TReal32 numerator = 1.0f * (aRect.Width() - iVideoCropRegion.Width());
-    TReal32 denominator = 1.0f * iVideoCropRegion.Width();
-    // new video width percent(relative to the original width) to
-    // which video has to be scaled.
-    TReal32 scaleWidthPercent = 100.0f + (100.0f * (numerator/denominator));
+        // align parent rect with respect to RWindow
+        TRect relativeParentRect;
+        relativeParentRect = iParentRect;
+        LOG2(EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::RedrawVideoL: RedrawWindows() - before moving parentRect = %d X %d",relativeParentRect.Width(),relativeParentRect.Height());
+
+        LOG2(EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::RedrawVideoL: RedrawWindows() - before moving parentRect.iTL = %d X %d",relativeParentRect.iTl.iX,relativeParentRect.iTl.iY);
+        LOG2(EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::RedrawVideoL: RedrawWindows() - before moving parentRect.iBr = %d X %d\n\n",relativeParentRect.iBr.iX,relativeParentRect.iBr.iY);
+        LOG2(EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::RedrawVideoL: RedrawWindows() - iRWindowRect.iTL = %d X %d",iRWindowRect.iTl.iX,iRWindowRect.iTl.iY);
+        LOG2(EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::RedrawVideoL: RedrawWindows() - iRWindowRect.iBr = %d X %d\n\n",iRWindowRect.iBr.iX,iRWindowRect.iBr.iY);
+
+
+
+        relativeParentRect.Move(-iRWindowRect.iTl);
+        LOG2(EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::RedrawVideoL: RedrawWindows() -after moving parentRect = %d X %d",relativeParentRect.Width(),relativeParentRect.Height());
+        LOG2(EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::RedrawVideoL: RedrawWindows() - after moving parentRect.iTL = %d X %d",relativeParentRect.iTl.iX,relativeParentRect.iTl.iY);
+        LOG2(EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::RedrawVideoL: RedrawWindows() - after moving parentRect.iBr = %d X %d\n\n",relativeParentRect.iBr.iX,relativeParentRect.iBr.iY);
+        LOG2(EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::RedrawVideoL: RedrawWindows() - before moving draw rect.iTL = %d X %d",contentRect.iTl.iX,contentRect.iTl.iY);
+        LOG2(EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::RedrawVideoL: RedrawWindows() - before moving draw rect.iBr = %d X %d",contentRect.iBr.iX,contentRect.iBr.iY);
 
-    numerator = 1.0f * (aRect.Height() - iVideoCropRegion.Height());
-    denominator = 1.0f * iVideoCropRegion.Height();
-    // new video height percent(relative to the original height) to
-    // which video has to be scaled.
-    TReal32 scaleHeightPercent = 100.0f + (100.0f * (numerator/denominator));
+        // setting video draw rect and adjusting it to window
+        TRect drawRect = contentRect;
+        drawRect.Move(relativeParentRect.iTl);
+
+        LOG2(EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::RedrawVideoL: RedrawWindows() - after moving draw rect = %d X %d",drawRect.Width(),drawRect.Height());
+        LOG2(EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::RedrawVideoL: RedrawWindows() - after moving draw rect.iTL = %d X %d",drawRect.iTl.iX,drawRect.iTl.iY);
+        LOG2(EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::RedrawVideoL: RedrawWindows() - after moving draw rect.iBr = %d X %d",drawRect.iBr.iX,drawRect.iBr.iY);
+
+
+
+        LOG2(EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::RedrawVideoL: RedrawWindows() - iVideoCropRegion.iTL = %d X %d",iVideoCropRegion.iTl.iX,iVideoCropRegion.iTl.iY);
+        LOG2(EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::RedrawVideoL: RedrawWindows() - iVideoCropRegion.iBr = %d X %d\n\n",iVideoCropRegion.iBr.iX,iVideoCropRegion.iBr.iY);
 
-	LOG2( EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow:: scaleWidthPercent, scaleHeightPercent %d %d",
-	scaleWidthPercent, scaleHeightPercent );
+        /*TRect temp1(TPoint(127,8),TPoint(255,104));
+        TRect temp2(TPoint(0,0),TPoint(128,96));
+        iMediaClientVideoDisplay->SetVideoExtentL(*iWindow,
+                  temp1,
+                  temp2);*/
+        iMediaClientVideoDisplay->SetVideoExtentL(*iWindow,
+                drawRect,
+                iVideoCropRegion);
+
+
+        LOG(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::RedrawvideoL() - after setVideoExtentL");
 
-    iMediaClientVideoDisplay->SetScaleFactorL(scaleWidthPercent,
-            scaleHeightPercent,
-            iVideoCropRegion);
+        //LOG2( EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::RedrawVideoL: RedrawWindows() -  areaRect = %d X %d",areaRect.Width(),areaRect.Height() );
+
+        iMediaClientVideoDisplay->RedrawWindows(iVideoCropRegion);
+        LOG(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::RedrawvideoL() - after redrawWindows");
+        //iMediaClientVideoDisplay->RedrawWindows(temp2);
+        ((RWindow*)iWindow)->Invalidate();
+        LOG(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::RedrawvideoL() -");
+    }
 }
 
+
+
 const TRect& CMMASurfaceWindow::DrawRect()
 {
     return iContentRect;
@@ -233,70 +288,64 @@
 
 void CMMASurfaceWindow::SetPosition(const TPoint& aPosition)
 {
+    LOG(EJavaMMAPI, EInfo,  "+ CMMASurfaceWindow::SetPosition");
     iContentRect = TRect(aPosition, iContentRect.Size());
     TInt error = StaticRedrawVideo(*this);
     if (KErrNone != error)
     {
-   ELOG1( EJavaMMAPI, "MID::CMMASurfaceWindow::SetPosition, StaticRedrawVideo error = %d", error);
+        ELOG1(EJavaMMAPI, "MID::CMMASurfaceWindow::SetPosition, StaticRedrawVideo error = %d", error);
     }
 }
 
 TBool CMMASurfaceWindow::IsVisible() const
-  {
-  LOG1( EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::IsVisible %d ", iVisible );
-  return iVisible;
-  }
+{
+    LOG1(EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::IsVisible %d ", iVisible);
+    return iVisible;
+}
 
 void CMMASurfaceWindow::SetVisible(TBool aVisible, TBool aUseEventServer)
 {
-  LOG1( EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::SetVisible aVisible %d", aVisible );
+    LOG1(EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::SetVisible aVisible %d", aVisible);
     RPointerArray< CMMAPlayer > players = iEventSource->Players();
 
     if (players.Find(iPlayer) != KErrNotFound)
     {
-    LOG( EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::SetVisible : Player found");
+        LOG(EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::SetVisible : Player found");
         if (aVisible != iVisible)
         {
-    	LOG( EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::SetVisible: Changed visibility" );
+            LOG(EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::SetVisible: Changed visibility");
             iVisible = aVisible;
-            if (iDisplay)
-            {
-      			 //MMAPI UI 3.x req.
-     					iDisplay->GetCallbackInUiThread((TInt)CMMASurfaceWindow::ESetDrawRect);
-     					LOG(EJavaMMAPI,EInfo,"MID::CMMASurfaceWindow::SetVisible,GetCallbackInUiThread");
-            }
-            
 
-											          /*  if (aUseEventServer)
-											            {
-											                TInt error = StaticRedrawVideo(*this);
-											                if (KErrNone != error)
-											                {
-											         ELOG1( EJavaMMAPI, "MID::CMMASurfaceWindow::SetVisible, StaticRedrawVideo error = %d", error);
-											                }
-											            }
-											            else // in MMA thread, so switch to UI thread
-											            {
-											                if (iDisplay)
-											                {
-													      				//iDisplay->UIGetCallback(*this,
-													     				  //                     CMMASurfaceWindow::ESetDrawRect );
-													    				  //MMAPI UI 3.x req.
-													     					iDisplay->GetCallbackInUiThread((TInt)CMMASurfaceWindow::ESetDrawRect);
-											         					LOG(EJavaMMAPI,EInfo,"MID::CMMASurfaceWindow::SetVisible,GetCallbackInUiThread");
-											                }
-											            }
-											            */
+            if (aUseEventServer)
+            {
+                //TInt error = StaticRedrawVideo(*this);
+                iDisplay->GetCallbackInUiThread((TInt)CMMASurfaceWindow::ESetDrawRect);
+                //  if (KErrNone != error)
+                // {
+                //ELOG1( EJavaMMAPI, "MID::CMMASurfaceWindow::SetVisible, StaticRedrawVideo error = %d", error);
+                //   }
+            }
+            else // in MMA thread, so switch to UI thread
+            {
+                if (iDisplay)
+                {
+                    //iDisplay->UIGetCallback(*this,
+                    //                     CMMASurfaceWindow::ESetDrawRect );
+                    //MMAPI UI 3.x req.
+                    iDisplay->GetCallbackInUiThread((TInt)CMMASurfaceWindow::ESetDrawRect);
+                    LOG(EJavaMMAPI,EInfo,"MID::CMMASurfaceWindow::SetVisible,GetCallbackInUiThread");
+                }
+            }
         }
     }
 }
 
 void CMMASurfaceWindow::SetWindowRect(const TRect& aRect,MMMADisplay::TThreadType /*aThreadType*/)
 {
-    LOG2( EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::SetWindowRect aRect TL %d %d",
-               aRect.iTl.iX, aRect.iTl.iY);
-    LOG2( EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::SetWindowRect aRect BR %d %d",
-               aRect.iBr.iX, aRect.iBr.iY);
+    LOG2(EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::SetWindowRect aRect TL %d %d",
+         aRect.iTl.iX, aRect.iTl.iY);
+    LOG2(EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::SetWindowRect aRect BR %d %d",
+         aRect.iBr.iX, aRect.iBr.iY);
 
     iParentRect = aRect;
 }
@@ -320,14 +369,14 @@
 
 void CMMASurfaceWindow::SetDisplay(MMMADisplay *aDisplay)
 {
-    LOG( EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::SetDisplay +" );
+    LOG(EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::SetDisplay +");
 
     if (iDisplay != aDisplay)
     {
         if (iDisplay)
         {
             // Clear the resources created within the old Display
-         	 iDisplay->GetCallbackInUiThread((TInt)CMMASurfaceWindow::ECleanVideoDisplay );
+            iDisplay->GetCallbackInUiThread((TInt)CMMASurfaceWindow::ECleanVideoDisplay);
         }
 
         // Set the new Display
@@ -343,14 +392,14 @@
             }
 
             */
-        }
-
-    LOG( EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::SetDisplay -" );
     }
 
+    LOG(EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::SetDisplay -");
+}
+
 void CMMASurfaceWindow::ContainerSet()
-    {
-    	LOG(EJavaMMAPI,EInfo, "MID::CMMASurfaceWindow::ContainerSet" );
+{
+    LOG(EJavaMMAPI,EInfo, "MID::CMMASurfaceWindow::ContainerSet");
     // We are in UI thread now
 
     // Container was probably not set when
@@ -360,63 +409,63 @@
     {
         // Get a DSA stuff for the new Display
 //        iDisplay->UIGetDSAResources( *this, MMMADisplay::EUiThread );
+    }
+}
+
+void CMMASurfaceWindow::Destroy()
+{
+    LOG(EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::Destroy");
+    // Delete itself
+    delete this;
+}
+
+void CMMASurfaceWindow::ProcureWindowResourcesFromQWidget(RWsSession * aWs,
+        CWsScreenDevice* aScreenDevice,
+        RWindowBase* aWindow)
+{
+    iWs = aWs;
+    iScreenDevice = aScreenDevice;
+    iWindow = aWindow;
+    LOG(EJavaMMAPI,EInfo, "MID::CMMASurfaceWindow::ProcureWindowResourcesFromQWidget");
+    switch (iVideoDisplayInitState)
+    {
+    case EUIResourcesAndSurfaceParametersNotSet:
+    {
+        LOG(EJavaMMAPI,EInfo, "MID::CMMASurfaceWindow::ProcureWindowResourcesFromQWidget  -8");
+        iVideoDisplayInitState =
+            EUIResourcesSetAndSurfaceParametersNotSet;
+    }
+    break;
+    case ESurfaceParametersSetAndUIResourcesNotSet:
+    {
+        LOG(EJavaMMAPI,EInfo, "MID::CMMASurfaceWindow::ProcureWindowResourcesFromQWidget  -9");
+        iVideoDisplayInitState =
+            EUIResourcesAndSurfaceParametersSet;
+    }
+    break;
+    // can not occur
+    case EUIResourcesSetAndSurfaceParametersNotSet:
+    case EUIResourcesAndSurfaceParametersSet:
+    default:
+    {
+        LOG(EJavaMMAPI,EInfo, "MID::CMMASurfaceWindow::ProcureWindowResourcesFromQWidget  -10");
+        __ASSERT_DEBUG(EFalse, User::Invariant());
+    }
+    break;
+    }
+
+    if (iVideoDisplayInitState == EUIResourcesAndSurfaceParametersSet)
+    {
+        LOG(EJavaMMAPI,EInfo, "MID::CMMASurfaceWindow::ProcureWindowResourcesFromQWidget  -11");
+        TRAPD(error, InitVideoDisplayL());
+        LOG(EJavaMMAPI,EInfo, "MID::CMMASurfaceWindow::ProcureWindowResourcesFromQWidget  -12");
+        if (KErrNone != error)
+        {
+            ELOG1(EJavaMMAPI, "MID::CMMASurfaceWindow::MdcDSAResourcesCallback, error = %d", error);
         }
     }
 
-void CMMASurfaceWindow::Destroy()
-    {
-    LOG( EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::Destroy" );
-    // Delete itself
-    delete this;
-    }
-
-void CMMASurfaceWindow::ProcureWindowResourcesFromQWidget(RWsSession * aWs,
-    CWsScreenDevice* aScreenDevice,
-    RWindowBase* aWindow)
-	{
-		iWs = aWs;
-    iScreenDevice = aScreenDevice;
-    iWindow = aWindow;
-		LOG(EJavaMMAPI,EInfo, "MID::CMMASurfaceWindow::ProcureWindowResourcesFromQWidget" );
-		switch ( iVideoDisplayInitState )
-		  {
-		  	LOG(EJavaMMAPI,EInfo, "MID::CMMASurfaceWindow::ProcureWindowResourcesFromQWidget  -7" );
-			case EUIResourcesAndSurfaceParametersNotSet:
-			     {
-			     LOG(EJavaMMAPI,EInfo, "MID::CMMASurfaceWindow::ProcureWindowResourcesFromQWidget  -8" );
-			     iVideoDisplayInitState =
-			     EUIResourcesSetAndSurfaceParametersNotSet;
-			     }
-			     break;
-			case ESurfaceParametersSetAndUIResourcesNotSet:
-			     {
-			     	LOG(EJavaMMAPI,EInfo, "MID::CMMASurfaceWindow::ProcureWindowResourcesFromQWidget  -9" );
-			     iVideoDisplayInitState =
-			     EUIResourcesAndSurfaceParametersSet;
-			     }
-			     break;
-			 // can not occur
-			case EUIResourcesSetAndSurfaceParametersNotSet:
-		  case EUIResourcesAndSurfaceParametersSet:
-			default:
-           {LOG(EJavaMMAPI,EInfo, "MID::CMMASurfaceWindow::ProcureWindowResourcesFromQWidget  -10" );
-      		 __ASSERT_DEBUG( EFalse, User::Invariant() );
-           }
-			     break;
-		  }
-
-		if( iVideoDisplayInitState == EUIResourcesAndSurfaceParametersSet )
-			{
-				LOG(EJavaMMAPI,EInfo, "MID::CMMASurfaceWindow::ProcureWindowResourcesFromQWidget  -11" );
-			TRAPD(error, InitVideoDisplayL());
-			LOG(EJavaMMAPI,EInfo, "MID::CMMASurfaceWindow::ProcureWindowResourcesFromQWidget  -12" );
-			if ( KErrNone != error )
-				{
-				ELOG1( EJavaMMAPI, "MID::CMMASurfaceWindow::MdcDSAResourcesCallback, error = %d", error);
-				}
-			}
-
-	}
+}
 /*
 void CMMASurfaceWindow::MdcDSAResourcesCallback(
     RWsSession &aWs,
@@ -430,48 +479,54 @@
     iScreenDevice = &aScreenDevice;
     iWindow = &aWindow;
 
-		switch ( iVideoDisplayInitState )
-		  {
-			case EUIResourcesAndSurfaceParametersNotSet:
-			     {
-			     iVideoDisplayInitState =
-			     EUIResourcesSetAndSurfaceParametersNotSet;
-			     }
-			     break;
-			case ESurfaceParametersSetAndUIResourcesNotSet:
-			     {
-			     iVideoDisplayInitState =
-			     EUIResourcesAndSurfaceParametersSet;
-			     }
-			     break;
-			 // can not occur
-			case EUIResourcesSetAndSurfaceParametersNotSet:
-		  case EUIResourcesAndSurfaceParametersSet:
-			default:
+        switch ( iVideoDisplayInitState )
+          {
+            case EUIResourcesAndSurfaceParametersNotSet:
+                 {
+                 iVideoDisplayInitState =
+                 EUIResourcesSetAndSurfaceParametersNotSet;
+                 }
+                 break;
+            case ESurfaceParametersSetAndUIResourcesNotSet:
+                 {
+                 iVideoDisplayInitState =
+                 EUIResourcesAndSurfaceParametersSet;
+                 }
+                 break;
+             // can not occur
+            case EUIResourcesSetAndSurfaceParametersNotSet:
+          case EUIResourcesAndSurfaceParametersSet:
+            default:
            {
-      		 __ASSERT_DEBUG( EFalse, User::Invariant() );
+             __ASSERT_DEBUG( EFalse, User::Invariant() );
            }
-			     break;
-		  }
+                 break;
+          }
 
-		if( iVideoDisplayInitState == EUIResourcesAndSurfaceParametersSet )
-			{
-			TRAPD(error, InitVideoDisplayL());
-			if ( KErrNone != error )
-				{
-				LOG1(EJavaMMAPI,EInfo,"MID::CMMASurfaceWindow::MdcDSAResourcesCallback, error = %d", error);
-				}
-			}
+        if( iVideoDisplayInitState == EUIResourcesAndSurfaceParametersSet )
+            {
+            TRAPD(error, InitVideoDisplayL());
+            if ( KErrNone != error )
+                {
+                LOG1(EJavaMMAPI,EInfo,"MID::CMMASurfaceWindow::MdcDSAResourcesCallback, error = %d", error);
+                }
+            }
     }
 */
-void CMMASurfaceWindow::UICallback( TInt aCallbackId )
-    {
+void CMMASurfaceWindow::UICallback(TInt aCallbackId)
+{
     // We are in UI thread context now.
-    LOG1( EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::MdcUICallback CallbackId = %d", aCallbackId );
+    LOG1(EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::MdcUICallback CallbackId = %d", aCallbackId);
 
     TInt error = KErrNone;
     switch (aCallbackId)
     {
+    case ESetClipRect:
+    {
+        error = SetClipRect();
+        LOG1(EJavaMMAPI,EInfo,"MID::CMMASurfaceWindow::MdcUICallback,SetClipRect error = %d", error);
+    }
+    break;
     case ERemoveSurface:
     {
         DoRemoveSurface();
@@ -480,13 +535,13 @@
     case ESetDrawRect:
     {
         error = StaticRedrawVideo(*this);
-           ELOG1( EJavaMMAPI, "MID::CMMASurfaceWindow::MdcUICallback,StaticRedrawVideo error = %d", error);
+        ELOG1(EJavaMMAPI, "MID::CMMASurfaceWindow::MdcUICallback,StaticRedrawVideo error = %d", error);
     }
     break;
     case EInitVideoDisplay:
     {
         TRAP(error, InitVideoDisplayL());
-			     ELOG1( EJavaMMAPI, "MID::CMMASurfaceWindow::MdcUICallback,InitVideoDisplayL error = %d", error);
+        ELOG1(EJavaMMAPI, "MID::CMMASurfaceWindow::MdcUICallback,InitVideoDisplayL error = %d", error);
     }
     break;
     case ESetChangedSurfaceParameters:
@@ -525,53 +580,53 @@
     iCropRect = aCropRect;
     iPixelAspectRatio = aPixelAspectRatio;
 
-    switch ( iVideoDisplayInitState )
-		  {
-			case EUIResourcesAndSurfaceParametersNotSet:
-			     {
-			     iVideoDisplayInitState =
-			     ESurfaceParametersSetAndUIResourcesNotSet;
-			     }
-			     break;
-			case EUIResourcesSetAndSurfaceParametersNotSet:
-			     {
-			     iVideoDisplayInitState =
-			     EUIResourcesAndSurfaceParametersSet;
-			     }
-			     break;
-			  // control reaches below two switch cases when
-			  // playback is looped using setLoopCount() in java.
-		  case ESurfaceParametersSetAndUIResourcesNotSet:
-		  	   {
-			     }
-			     break;
-			  // update surface parameters and return with out calling
-			  // InitVideoDisplayL again.
-			case EUIResourcesAndSurfaceParametersSet:
-			     {
-			    // iDisplay->UIGetCallback( *this, CMMASurfaceWindow::EResetSurfaceParameters );
-			    //MMAPI UI 3.x req.
-			    LOG(EJavaMMAPI,EInfo,"CMMASurfaceWindow::SetSurfaceParameters : switch case EUIResourcesAndSurfaceParametersSet +");
-			    iDisplay->GetCallbackInUiThread( (TInt)CMMASurfaceWindow::EResetSurfaceParameters );
-			    LOG(EJavaMMAPI,EInfo,"CMMASurfaceWindow::SetSurfaceParameters : switch case EUIResourcesAndSurfaceParametersSet -");
-			     return;
-			     }
-			     // break; not reachable
-			default: // can not occur
-           {
-      		 __ASSERT_DEBUG( EFalse, User::Invariant() );
-           }
-			     break;
-		  }
+    switch (iVideoDisplayInitState)
+    {
+    case EUIResourcesAndSurfaceParametersNotSet:
+    {
+        iVideoDisplayInitState =
+            ESurfaceParametersSetAndUIResourcesNotSet;
+    }
+    break;
+    case EUIResourcesSetAndSurfaceParametersNotSet:
+    {
+        iVideoDisplayInitState =
+            EUIResourcesAndSurfaceParametersSet;
+    }
+    break;
+    // control reaches below two switch cases when
+    // playback is looped using setLoopCount() in java.
+    case ESurfaceParametersSetAndUIResourcesNotSet:
+    {
+    }
+    break;
+    // update surface parameters and return with out calling
+    // InitVideoDisplayL again.
+    case EUIResourcesAndSurfaceParametersSet:
+    {
+        // iDisplay->UIGetCallback( *this, CMMASurfaceWindow::EResetSurfaceParameters );
+        //MMAPI UI 3.x req.
+        LOG(EJavaMMAPI,EInfo,"CMMASurfaceWindow::SetSurfaceParameters : switch case EUIResourcesAndSurfaceParametersSet +");
+        iDisplay->GetCallbackInUiThread((TInt)CMMASurfaceWindow::EResetSurfaceParameters);
+        LOG(EJavaMMAPI,EInfo,"CMMASurfaceWindow::SetSurfaceParameters : switch case EUIResourcesAndSurfaceParametersSet -");
+        return;
+    }
+    // break; not reachable
+    default: // can not occur
+    {
+        __ASSERT_DEBUG(EFalse, User::Invariant());
+    }
+    break;
+    }
 
-    if ( iVideoDisplayInitState == EUIResourcesAndSurfaceParametersSet )
-    	{
-    	//iDisplay->UIGetCallback( *this, CMMASurfaceWindow::EInitVideoDisplay );
-    	//MMAPI UI 3.x req.
-    	iDisplay->GetCallbackInUiThread( (TInt)CMMASurfaceWindow::EInitVideoDisplay );
-			LOG(EJavaMMAPI,EInfo,"CMMASurfaceWindow::SetSurfaceParameters,EUIResourcesAndSurfaceParametersSet");
-    	}
-		}
+    if (iVideoDisplayInitState == EUIResourcesAndSurfaceParametersSet)
+    {
+        //iDisplay->UIGetCallback( *this, CMMASurfaceWindow::EInitVideoDisplay );
+        //MMAPI UI 3.x req.
+        iDisplay->GetCallbackInUiThread((TInt)CMMASurfaceWindow::EInitVideoDisplay);
+        LOG(EJavaMMAPI,EInfo,"CMMASurfaceWindow::SetSurfaceParameters,EUIResourcesAndSurfaceParametersSet");
+    }
+}
 
 void CMMASurfaceWindow::SetChangedSurfaceParameters(const TSurfaceId& aSurfaceId,
         const TRect& aCropRect,
@@ -584,18 +639,18 @@
     if (iDisplay)
     {
         //iDisplay->UIGetCallback(*this, CMMASurfaceWindow::ESetChangedSurfaceParameters);
-    	LOG(EJavaMMAPI,EInfo,"CMMASurfaceWindow::SetChangedSurfaceParameters + ");
-    	iDisplay->GetCallbackInUiThread((TInt)CMMASurfaceWindow::ESetChangedSurfaceParameters);
-    	LOG(EJavaMMAPI,EInfo,"CMMASurfaceWindow::SetChangedSurfaceParameters - ");
+        LOG(EJavaMMAPI,EInfo,"CMMASurfaceWindow::SetChangedSurfaceParameters + ");
+        iDisplay->GetCallbackInUiThread((TInt)CMMASurfaceWindow::ESetChangedSurfaceParameters);
+        LOG(EJavaMMAPI,EInfo,"CMMASurfaceWindow::SetChangedSurfaceParameters - ");
 
-	}
+    }
 }
 
 void CMMASurfaceWindow::RemoveSurface()
 {
     if (iDisplay)
     {
-        iDisplay->GetCallbackInUiThread((TInt)CMMASurfaceWindow::ERemoveSurface);                         	
+        iDisplay->GetCallbackInUiThread((TInt)CMMASurfaceWindow::ERemoveSurface);
     }
 }
 
@@ -615,13 +670,13 @@
 
     if (iMediaClientVideoDisplay)
     {
-    	iMediaClientVideoDisplay->RemoveSurface();
+        iMediaClientVideoDisplay->RemoveSurface();
         TInt error = iMediaClientVideoDisplay->SurfaceCreated(iSurfaceId,
                      iCropRect,
                      iPixelAspectRatio,
                      iVideoCropRegion);
 
-      ELOG1( EJavaMMAPI, "MID::CMMASurfaceWindow::DoResetSurfaceParameters,SurfaceCreated error = %d", error);
+        ELOG1(EJavaMMAPI, "MID::CMMASurfaceWindow::DoResetSurfaceParameters,SurfaceCreated error = %d", error);
 
         iMediaClientVideoDisplay->RedrawWindows(iVideoCropRegion);
     }
@@ -635,7 +690,7 @@
                      iCropRect,
                      iPixelAspectRatio);
 
-			ELOG1( EJavaMMAPI, "MID::CMMASurfaceWindow::DoSetChangedSurfaceParameters,SurfaceParametersChanged, error = %d", error);
+        ELOG1(EJavaMMAPI, "MID::CMMASurfaceWindow::DoSetChangedSurfaceParameters,SurfaceParametersChanged, error = %d", error);
 
         iMediaClientVideoDisplay->RedrawWindows(iVideoCropRegion);
     }
@@ -662,44 +717,68 @@
 
     // video is not scaled untill user requests explicitly
     // so retain same video width & height.
-    TReal32 scaleWidthPercent = 100.0f;
-    TReal32 scaleHeightPercent = 100.0f;
+    //TReal32 scaleWidthPercent = 100.0f;
+    //TReal32 scaleHeightPercent = 100.0f;
 
     // video rotation feature not supported in MMAPI
-    TVideoRotation videoRotation(EVideoRotationNone);
+    //TVideoRotation videoRotation(EVideoRotationNone);
     // no automatic scaling, can be controlled only via VideoControl
-    TAutoScaleType autoScaleType = EAutoScaleNone;
+    //TAutoScaleType autoScaleType = EAutoScaleNone;
 
     // always align video to the top left corner of the display area
-    TInt horizontalPosition(EHorizontalAlignLeft);
-    TInt verticalPosition(EVerticalAlignTop);
+    //TInt horizontalPosition(EHorizontalAlignLeft);
+    //TInt verticalPosition(EVerticalAlignTop);
 
     TInt error = iMediaClientVideoDisplay->SurfaceCreated(iSurfaceId,
                  iCropRect,
                  iPixelAspectRatio,
                  iVideoCropRegion);
 
-		ELOG1( EJavaMMAPI,  "MID::CMMASurfaceWindow::InitVideoDisplayL error = %d", error );
+    ELOG1(EJavaMMAPI,  "MID::CMMASurfaceWindow::InitVideoDisplayL error = %d", error);
     User::LeaveIfError(error);
 
+    TRect contentRect;
+    if (iVisible)
+    {
+        contentRect = iContentRect;
+    }
+    else
+    {
+        TRect emptyRect(0,0,0,0);
+        contentRect = emptyRect;
+    }
+
+    // align parent rect with respect to RWindow
+    TRect relativeParentRect;
+    relativeParentRect = iParentRect;
+    relativeParentRect.Move(-iRWindowRect.iTl);
+
+    // setting video draw rect and adjusting it to window
+    TRect drawRect = contentRect;
+    drawRect.Move(relativeParentRect.iTl);
+
+    TRect clipRect(0,0,iRWindowRect.Width(),iRWindowRect.Height());
+    //iWindow->SetExtentErr(TPoint(127,8),TSize(128,96));
     iMediaClientVideoDisplay->AddDisplayWindowL(iWindow,
-            iContentRect,
+            clipRect,
             iVideoCropRegion,
-            iContentRect,
-            scaleWidthPercent,
-            scaleHeightPercent,
-            videoRotation,
-            autoScaleType,
-            horizontalPosition,
-            verticalPosition,
+            drawRect,  // video extent
+            0.0f, // ignore
+            0.0f, // ignore
+            EVideoRotationNone,
+            EAutoScaleBestFit,
+            EHorizontalAlignLeft,
+            EVerticalAlignTop,
             (RWindow*)iWindow);
 
+
+
     RedrawVideoL();
 }
 
 void CMMASurfaceWindow::CleanVideoDisplay()
 {
-		LOG( EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::CleanVideoDisplay +" );
+    LOG(EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::CleanVideoDisplay +");
 
     SetVisible(EFalse, ETrue);
     if (iMediaClientVideoDisplay)
@@ -717,12 +796,8 @@
         iWs = NULL;
     }
 
-    LOG( EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::CleanVideoDisplay -" );
+    LOG(EJavaMMAPI, EInfo,  "MID::CMMASurfaceWindow::CleanVideoDisplay -");
 }
 
 
-CMMAPlayer* CMMASurfaceWindow::UiPlayer()
-	{
-		  return iPlayer;
-	}
 //  END OF FILE