javauis/mmapi_qt/baseline/src.nga/cmmasurfacewindow.cpp
branchRCL_3
changeset 65 ae942d28ec0e
equal deleted inserted replaced
60:6c158198356e 65:ae942d28ec0e
       
     1 /*
       
     2 * Copyright (c) 2002-2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  This class implements MMMADisplayWindow functionality
       
    15 *               in graphics surface based displays for Helix engine.
       
    16 *
       
    17 */
       
    18 
       
    19 //  Include Files
       
    20 #include <logger.h>
       
    21 #include <w32std.h>
       
    22 #include "cmmasurfacewindow.h"
       
    23 #include "cmmaplayer.h"
       
    24 
       
    25 // Used for iDisplay member
       
    26 #include "mmmadisplay.h"
       
    27 
       
    28 CMMASurfaceWindow* CMMASurfaceWindow::NewL(
       
    29     MMAFunctionServer* aEventSource,
       
    30     CMMAPlayer* aPlayer)
       
    31 {
       
    32     CMMASurfaceWindow* self =
       
    33         new(ELeave) CMMASurfaceWindow(aEventSource,
       
    34                                       aPlayer);
       
    35     return self;
       
    36 }
       
    37 
       
    38 // Destructor (virtual by CBase)
       
    39 CMMASurfaceWindow::~CMMASurfaceWindow()
       
    40 {
       
    41     // It's not allowed to delete any nonsharable object here.
       
    42     // This must be done in Destroy().
       
    43     // If the iDisplay is set,
       
    44     // instance should be deleted by sending
       
    45     // event from UI to be received by MUiEventConsumer.
       
    46 }
       
    47 
       
    48 CMMASurfaceWindow::CMMASurfaceWindow(
       
    49     MMAFunctionServer* aEventSource,
       
    50     CMMAPlayer* aPlayer):
       
    51         iEventSource(aEventSource),
       
    52         iPlayer(aPlayer),
       
    53         iVideoDisplayInitState(EUIResourcesAndSurfaceParametersNotSet)
       
    54 {
       
    55     // Empty rect until video size is known
       
    56     iContentRect.SetRect(0, 0, 0, 0);
       
    57     iParentRect.SetRect(0, 0, 0, 0);
       
    58     iRWindowRect.SetRect(0, 0, 0, 0);
       
    59 }
       
    60 
       
    61 void CMMASurfaceWindow::SetDestinationBitmapL(CFbsBitmap* /*aBitmap*/)
       
    62 {
       
    63     // Ignored, this window will not be used for actual drawing
       
    64 }
       
    65 
       
    66 void CMMASurfaceWindow::DrawFrameL(const CFbsBitmap* /*aBitmap*/)
       
    67 {
       
    68     // Ignored, this window will not be used for actual drawing
       
    69 }
       
    70 
       
    71 void CMMASurfaceWindow::SetDrawRectThread(const TRect& aRect)
       
    72 {
       
    73     LOG2(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::SetDrawRectThread TL %d %d",
       
    74          aRect.iTl.iX, aRect.iTl.iY);
       
    75     LOG2(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::SetDrawRectThread BR %d %d",
       
    76          aRect.iBr.iX, aRect.iBr.iY);
       
    77 
       
    78     iContentRect = aRect;
       
    79 
       
    80     TInt error = StaticRedrawVideo(*this);
       
    81     if (KErrNone != error)
       
    82     {
       
    83         ELOG1(EJavaMMAPI, "CMMASurfaceWindow::SetDrawRectThread, StaticRedrawVideo error = %d", error);
       
    84     }
       
    85 }
       
    86 
       
    87 void CMMASurfaceWindow::SetRWindowRect(const TRect& aRect,
       
    88                                        MMMADisplay::TThreadType aThreadType)
       
    89 {
       
    90     LOG2(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::SetRWindowRect TL %d %d",
       
    91          aRect.iTl.iX, aRect.iTl.iY);
       
    92     LOG2(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::SetRWindowRect BR %d %d",
       
    93          aRect.iBr.iX, aRect.iBr.iY);
       
    94 
       
    95     if (iRWindowRect == aRect)
       
    96     {
       
    97         return;
       
    98     }
       
    99 
       
   100     iRWindowRect = aRect;
       
   101 
       
   102     if (MMMADisplay::EMmaThread == aThreadType)
       
   103     {
       
   104         if (iDisplay)
       
   105         {
       
   106             //iDisplay->UIGetCallback(*this,
       
   107 //                                    CMMASurfaceWindow::ESetClipRect);
       
   108             // MMAPI UI 3.x req.
       
   109             TBool iseSWT = iDisplay->iseSWT();
       
   110             if (iseSWT)
       
   111             {
       
   112                 UICallback((TInt)CMMASurfaceWindow::ESetClipRect);
       
   113             }
       
   114             else
       
   115             {
       
   116                 iDisplay->GetCallbackInUiThread((TInt)CMMASurfaceWindow::ESetClipRect);
       
   117             }
       
   118         }
       
   119     }
       
   120     else if (MMMADisplay::EUiThread == aThreadType)
       
   121     {
       
   122         TInt error = SetClipRect();
       
   123         if (KErrNone != error)
       
   124         {
       
   125             LOG1(EJavaMMAPI,EInfo,"CMMASurfaceWindow::SetRWindowRect, error = %d", error);
       
   126         }
       
   127     }
       
   128 }
       
   129 
       
   130 TInt CMMASurfaceWindow::SetClipRect()
       
   131 {
       
   132     LOG(EJavaMMAPI,EInfo,"CMMASurfaceWindow::SetClipRect");
       
   133 
       
   134     // CMediaClientVideoDisplay expects client to RemoveDisplayWindow
       
   135     // and AddDisplayWindow again everytime when RWindow rect changes
       
   136     if (iMediaClientVideoDisplay && iWindow)
       
   137     {
       
   138         iMediaClientVideoDisplay->RemoveDisplayWindow(*iWindow);
       
   139 
       
   140         TRect contentRect;
       
   141         if (iVisible)
       
   142         {
       
   143             contentRect = iContentRect;
       
   144         }
       
   145         else
       
   146         {
       
   147             TRect emptyRect(0,0,0,0);
       
   148             contentRect = emptyRect;
       
   149         }
       
   150 
       
   151         // align parent rect with respect to RWindow
       
   152         TRect relativeParentRect;
       
   153         relativeParentRect = iParentRect;
       
   154         relativeParentRect.Move(-iRWindowRect.iTl);
       
   155 
       
   156         // setting video draw rect and adjusting it to window
       
   157         TRect drawRect = contentRect;
       
   158         drawRect.Move(relativeParentRect.iTl);
       
   159         LOG2(EJavaMMAPI, EInfo, "CMMASurfaceWindow::SetClipRect(): iRWindowRect size = %d x %d", iRWindowRect.Width(), iRWindowRect.Height());
       
   160         TRect clipRect(0,0,iRWindowRect.Width(),iRWindowRect.Height());
       
   161         TRAPD(error, iMediaClientVideoDisplay->AddDisplayWindowL(iWindow,
       
   162                 clipRect, // new clip rect
       
   163                 iVideoCropRegion,
       
   164                 drawRect,  // video extent
       
   165                 0.0f, // ignore
       
   166                 0.0f, // ignore
       
   167                 EVideoRotationNone,
       
   168                 EAutoScaleBestFit,
       
   169                 EHorizontalAlignCenter,
       
   170                 EVerticalAlignCenter,
       
   171                 (RWindow*)iWindow));
       
   172 
       
   173         LOG(EJavaMMAPI,EInfo,"CMMASurfaceWindow::SetClipRect -");
       
   174         return error;
       
   175     }
       
   176     return KErrNone;
       
   177 }
       
   178 
       
   179 void CMMASurfaceWindow::SetDrawRect(const TRect& aRect)
       
   180 {
       
   181     LOG2(EJavaMMAPI,EInfo,"CMMASurfaceWindow::SetDrawRect TL %d %d",
       
   182          aRect.iTl.iX, aRect.iTl.iY);
       
   183     LOG2(EJavaMMAPI,EInfo,"CMMASurfaceWindow::SetDrawRect BR %d %d",
       
   184          aRect.iBr.iX, aRect.iBr.iY);
       
   185 
       
   186     iContentRect = aRect;
       
   187     LOG1(EJavaMMAPI,EInfo,"CMMASurfaceWindow::SetDrawRect aRect %d",iContentRect);
       
   188     if (iDisplay)
       
   189     {
       
   190         // iDisplay->UIGetCallback( *this,
       
   191         //                         CMMASurfaceWindow::ESetDrawRect );
       
   192         // MMAPI UI 3.x req.
       
   193         TBool iseSWT = iDisplay->iseSWT();
       
   194         if (iseSWT)
       
   195         {
       
   196             UICallback((TInt)CMMASurfaceWindow::ESetDrawRect);
       
   197         }
       
   198         else
       
   199         {
       
   200             iDisplay->GetCallbackInUiThread((TInt)CMMASurfaceWindow::ESetDrawRect);
       
   201         }
       
   202         LOG(EJavaMMAPI,EInfo,"CMMASurfaceWindow::SetDrawRect, after GetCallbackInUiThread");
       
   203     }
       
   204 }
       
   205 
       
   206 TInt CMMASurfaceWindow::StaticRedrawVideo(CMMASurfaceWindow& aSurfaceWindow)
       
   207 {
       
   208     LOG(EJavaMMAPI,EInfo,"CMMASurfaceWindow::StaticRedrawVideo +");
       
   209     TRAPD(error, aSurfaceWindow.RedrawVideoL());
       
   210     LOG1(EJavaMMAPI,EInfo,"CMMASurfaceWindow::RedrawVideoL - error = %d",error);
       
   211     return error;
       
   212 }
       
   213 
       
   214 void CMMASurfaceWindow::RedrawVideoL()
       
   215 {
       
   216     LOG(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::RedrawVideoL +");
       
   217     if (!iMediaClientVideoDisplay)
       
   218     {
       
   219         LOG(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::RedrawVideoL: no MediaClientVideoDisplay set, aborting -");
       
   220         return;
       
   221     }
       
   222     //iVisible = true;
       
   223     if (iWindow)
       
   224     {
       
   225         TRect contentRect;
       
   226         if (iVisible)
       
   227         {
       
   228             LOG2(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::RedrawVideoL: if visible true iContentRect = %d X %d",iContentRect.Width(),iContentRect.Height());
       
   229             contentRect = iContentRect;
       
   230             // ScaleVideoL(contentRect);
       
   231         }
       
   232         else
       
   233         {
       
   234             LOG(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::RedrawVideoL - if visible false");
       
   235             TRect emptyRect(0,0,0,0);
       
   236             contentRect = emptyRect;
       
   237         }
       
   238         LOG2(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::RedrawVideoL: RedrawWindows() - before intersection contentRect = %d X %d",contentRect.Width(),contentRect.Height());
       
   239 
       
   240         // align parent rect with respect to RWindow
       
   241         TRect relativeParentRect;
       
   242         relativeParentRect = iParentRect;
       
   243         LOG2(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::RedrawVideoL: RedrawWindows() - before moving parentRect = %d X %d",relativeParentRect.Width(),relativeParentRect.Height());
       
   244 
       
   245         LOG2(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::RedrawVideoL: RedrawWindows() - before moving parentRect.iTL = %d X %d",relativeParentRect.iTl.iX,relativeParentRect.iTl.iY);
       
   246         LOG2(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::RedrawVideoL: RedrawWindows() - before moving parentRect.iBr = %d X %d\n\n",relativeParentRect.iBr.iX,relativeParentRect.iBr.iY);
       
   247         LOG2(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::RedrawVideoL: RedrawWindows() - iRWindowRect.iTL = %d X %d",iRWindowRect.iTl.iX,iRWindowRect.iTl.iY);
       
   248         LOG2(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::RedrawVideoL: RedrawWindows() - iRWindowRect.iBr = %d X %d\n\n",iRWindowRect.iBr.iX,iRWindowRect.iBr.iY);
       
   249 
       
   250 
       
   251 
       
   252         relativeParentRect.Move(-iRWindowRect.iTl);
       
   253         LOG2(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::RedrawVideoL: RedrawWindows() -after moving parentRect = %d X %d",relativeParentRect.Width(),relativeParentRect.Height());
       
   254         LOG2(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::RedrawVideoL: RedrawWindows() - after moving parentRect.iTL = %d X %d",relativeParentRect.iTl.iX,relativeParentRect.iTl.iY);
       
   255         LOG2(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::RedrawVideoL: RedrawWindows() - after moving parentRect.iBr = %d X %d\n\n",relativeParentRect.iBr.iX,relativeParentRect.iBr.iY);
       
   256         LOG2(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::RedrawVideoL: RedrawWindows() - before moving draw rect.iTL = %d X %d",contentRect.iTl.iX,contentRect.iTl.iY);
       
   257         LOG2(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::RedrawVideoL: RedrawWindows() - before moving draw rect.iBr = %d X %d",contentRect.iBr.iX,contentRect.iBr.iY);
       
   258 
       
   259         // setting video draw rect and adjusting it to window
       
   260         TRect drawRect = contentRect;
       
   261         drawRect.Move(relativeParentRect.iTl);
       
   262 
       
   263         LOG2(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::RedrawVideoL: RedrawWindows() - after moving draw rect = %d X %d",drawRect.Width(),drawRect.Height());
       
   264         LOG2(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::RedrawVideoL: RedrawWindows() - after moving draw rect.iTL = %d X %d",drawRect.iTl.iX,drawRect.iTl.iY);
       
   265         LOG2(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::RedrawVideoL: RedrawWindows() - after moving draw rect.iBr = %d X %d",drawRect.iBr.iX,drawRect.iBr.iY);
       
   266 
       
   267 
       
   268 
       
   269         LOG2(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::RedrawVideoL: RedrawWindows() - iVideoCropRegion.iTL = %d X %d",iVideoCropRegion.iTl.iX,iVideoCropRegion.iTl.iY);
       
   270         LOG2(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::RedrawVideoL: RedrawWindows() - iVideoCropRegion.iBr = %d X %d\n\n",iVideoCropRegion.iBr.iX,iVideoCropRegion.iBr.iY);
       
   271 
       
   272         /*TRect temp1(TPoint(127,8),TPoint(255,104));
       
   273         TRect temp2(TPoint(0,0),TPoint(128,96));
       
   274         iMediaClientVideoDisplay->SetVideoExtentL(*iWindow,
       
   275                   temp1,
       
   276                   temp2);*/
       
   277         iMediaClientVideoDisplay->SetVideoExtentL(*iWindow,
       
   278                 drawRect,
       
   279                 iVideoCropRegion);
       
   280 
       
   281 
       
   282         LOG(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::RedrawvideoL() - after setVideoExtentL");
       
   283 
       
   284         //LOG2( EJavaMMAPI, EInfo,  "CMMASurfaceWindow::RedrawVideoL: RedrawWindows() -  areaRect = %d X %d",areaRect.Width(),areaRect.Height() );
       
   285 
       
   286         iMediaClientVideoDisplay->RedrawWindows(iVideoCropRegion);
       
   287         LOG(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::RedrawvideoL() - after redrawWindows");
       
   288         //iMediaClientVideoDisplay->RedrawWindows(temp2);
       
   289         ((RWindow*)iWindow)->Invalidate();
       
   290         LOG(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::RedrawvideoL() -");
       
   291     }
       
   292 }
       
   293 
       
   294 
       
   295 
       
   296 const TRect& CMMASurfaceWindow::DrawRect()
       
   297 {
       
   298     return iContentRect;
       
   299 }
       
   300 
       
   301 TSize CMMASurfaceWindow::WindowSize()
       
   302 {
       
   303     return iParentRect.Size();
       
   304 }
       
   305 
       
   306 void CMMASurfaceWindow::SetPosition(const TPoint& aPosition)
       
   307 {
       
   308     LOG(EJavaMMAPI, EInfo,  "+ CMMASurfaceWindow::SetPosition");
       
   309     iContentRect = TRect(aPosition, iContentRect.Size());
       
   310     TInt error = StaticRedrawVideo(*this);
       
   311     if (KErrNone != error)
       
   312     {
       
   313         ELOG1(EJavaMMAPI, "CMMASurfaceWindow::SetPosition, StaticRedrawVideo error = %d", error);
       
   314     }
       
   315 }
       
   316 
       
   317 TBool CMMASurfaceWindow::IsVisible() const
       
   318 {
       
   319     LOG1(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::IsVisible %d ", iVisible);
       
   320     return iVisible;
       
   321 }
       
   322 
       
   323 void CMMASurfaceWindow::SetVisible(TBool aVisible, TBool aUseEventServer)
       
   324 {
       
   325     LOG1(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::SetVisible aVisible %d", aVisible);
       
   326     RPointerArray< CMMAPlayer > players = iEventSource->Players();
       
   327 
       
   328     if (players.Find(iPlayer) != KErrNotFound)
       
   329     {
       
   330         LOG(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::SetVisible : Player found");
       
   331         if (aVisible != iVisible)
       
   332         {
       
   333             LOG(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::SetVisible: Changed visibility");
       
   334             iVisible = aVisible;
       
   335 
       
   336             if (aUseEventServer)
       
   337             {
       
   338                 /*TInt error = StaticRedrawVideo(*this);
       
   339                 if (KErrNone != error)
       
   340                 {
       
   341                     LOG1(EJavaMMAPI,EInfo,"CMMASurfaceWindow::SetVisible, StaticRedrawVideo error = %d", error);
       
   342                 }*/
       
   343                 TRAPD(error,DoSetVisibleL());
       
   344                 if (error != KErrNone)
       
   345                 {
       
   346                     LOG1(EJavaMMAPI, EInfo,"CMMASurfaceWindow::SetVisible,DoSetVisibleL error = %d", error);
       
   347                 }
       
   348             }
       
   349             else
       
   350             {
       
   351                 if (iDisplay)
       
   352                 {
       
   353 
       
   354                     LOG(EJavaMMAPI,EInfo,"CMMASurfaceWindow::SetVisible,calling GetCallbackInUiThread");
       
   355                     //iDisplay->GetCallbackInUiThread((TInt)CMMASurfaceWindow::ESetDrawRect);
       
   356                     iDisplay->GetCallbackInUiThread((TInt)CMMASurfaceWindow::EChangeVisibility);
       
   357                     LOG(EJavaMMAPI,EInfo,"CMMASurfaceWindow::SetVisible,after GetCallbackInUiThread");
       
   358 
       
   359                 }
       
   360 
       
   361             }
       
   362         }
       
   363     }
       
   364 }
       
   365 
       
   366 void CMMASurfaceWindow::DoSetVisibleL()
       
   367 {
       
   368     LOG(EJavaMMAPI,EInfo,"CMMASurfaceWindow::DoSetVisible +");
       
   369     if (iVisible)
       
   370     {
       
   371         TRect contentRect;
       
   372         if (iVisible)
       
   373         {
       
   374             contentRect = iContentRect;
       
   375         }
       
   376         else
       
   377         {
       
   378             TRect emptyRect(0,0,0,0);
       
   379             contentRect = emptyRect;
       
   380         }
       
   381 
       
   382         // align parent rect with respect to RWindow
       
   383         TRect relativeParentRect;
       
   384         relativeParentRect = iParentRect;
       
   385         relativeParentRect.Move(-iRWindowRect.iTl);
       
   386 
       
   387         // setting video draw rect and adjusting it to window
       
   388         TRect drawRect = contentRect;
       
   389         drawRect.Move(relativeParentRect.iTl);
       
   390 
       
   391         TRect clipRect(0,0,iRWindowRect.Width(),iRWindowRect.Height());
       
   392         //iWindow->SetExtentErr(TPoint(127,8),TSize(128,96));
       
   393         LOG(EJavaMMAPI,EInfo,"CMMASurfaceWindow::DoSetVisible:: AddDisplayWindowL");
       
   394         if (iMediaClientVideoDisplay)
       
   395         {
       
   396             iMediaClientVideoDisplay->AddDisplayWindowL(iWindow,
       
   397                     clipRect,
       
   398                     iVideoCropRegion,
       
   399                     drawRect,  // video extent
       
   400                     0.0f, // ignore
       
   401                     0.0f, // ignore
       
   402                     EVideoRotationNone,
       
   403                     EAutoScaleBestFit,
       
   404                     EHorizontalAlignCenter,
       
   405                     EVerticalAlignCenter,
       
   406                     (RWindow*)iWindow);
       
   407         }
       
   408         RedrawVideoL();
       
   409     }
       
   410     else
       
   411     {
       
   412         if (iWindow && iMediaClientVideoDisplay)
       
   413         {
       
   414             iMediaClientVideoDisplay->RemoveDisplayWindow(*iWindow);
       
   415         }
       
   416     }
       
   417     LOG(EJavaMMAPI,EInfo,"CMMASurfaceWindow::DoSetVisible -");
       
   418 }
       
   419 
       
   420 void CMMASurfaceWindow::SetWindowRect(const TRect& aRect,MMMADisplay::TThreadType /*aThreadType*/)
       
   421 {
       
   422     LOG2(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::SetWindowRect aRect TL %d %d",
       
   423          aRect.iTl.iX, aRect.iTl.iY);
       
   424     LOG2(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::SetWindowRect aRect BR %d %d",
       
   425          aRect.iBr.iX, aRect.iBr.iY);
       
   426 
       
   427     iParentRect = aRect;
       
   428 }
       
   429 
       
   430 void CMMASurfaceWindow::SetVideoCropRegion(const TRect& aRect)
       
   431 {
       
   432     // video size
       
   433     iVideoCropRegion = aRect;
       
   434 }
       
   435 
       
   436 const TRect& CMMASurfaceWindow::WindowRect()
       
   437 {
       
   438     return iParentRect;
       
   439 }
       
   440 
       
   441 void CMMASurfaceWindow::ContainerDestroyed()
       
   442 {
       
   443     // We are in UI thread context now.
       
   444     CleanVideoDisplay();
       
   445 }
       
   446 
       
   447 void CMMASurfaceWindow::SetDisplay(MMMADisplay *aDisplay)
       
   448 {
       
   449     LOG(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::SetDisplay +");
       
   450 
       
   451     if (iDisplay != aDisplay)
       
   452     {
       
   453         if (iDisplay)
       
   454         {
       
   455             // Clear the resources created within the old Display
       
   456             TBool iseSWT = iDisplay->iseSWT();
       
   457             if (iseSWT)
       
   458             {
       
   459                 UICallback((TInt)CMMASurfaceWindow::ECleanVideoDisplay);
       
   460             }
       
   461             else
       
   462             {
       
   463                 iDisplay->GetCallbackInUiThread((TInt)CMMASurfaceWindow::ECleanVideoDisplay);
       
   464             }
       
   465         }
       
   466 
       
   467         // Set the new Display
       
   468         iDisplay = aDisplay;
       
   469 
       
   470         /*if ( iDisplay )
       
   471             {
       
   472             // Get a DSA resources for the new Display
       
   473             //iDisplay->UIGetDSAResources( *this, MMMADisplay::EMmaThread );
       
   474             CMMACanvasDisplay* display =  static_cast< CMMACanvasDisplay* >( iDisplay );
       
   475 
       
   476             display->GetWindowResources( this, MMMADisplay::EMmaThread );
       
   477             }
       
   478 
       
   479             */
       
   480     }
       
   481 
       
   482     LOG(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::SetDisplay -");
       
   483 }
       
   484 
       
   485 void CMMASurfaceWindow::ContainerSet()
       
   486 {
       
   487     LOG(EJavaMMAPI,EInfo, "CMMASurfaceWindow::ContainerSet");
       
   488     // We are in UI thread now
       
   489 
       
   490     // Container was probably not set when
       
   491     // iDisplay was set,
       
   492     // we can now try get the DSA stuff again
       
   493     if (iDisplay)
       
   494     {
       
   495         // Get a DSA stuff for the new Display
       
   496 //        iDisplay->UIGetDSAResources( *this, MMMADisplay::EUiThread );
       
   497     }
       
   498 }
       
   499 
       
   500 void CMMASurfaceWindow::Destroy()
       
   501 {
       
   502     LOG(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::Destroy");
       
   503     // Delete itself
       
   504     delete this;
       
   505 }
       
   506 
       
   507 void CMMASurfaceWindow::ProcureWindowResourcesFromQWidget(RWsSession * aWs,
       
   508         CWsScreenDevice* aScreenDevice,
       
   509         RWindowBase* aWindow)
       
   510 {
       
   511     iWs = aWs;
       
   512     iScreenDevice = aScreenDevice;
       
   513     iWindow = aWindow;
       
   514     LOG(EJavaMMAPI,EInfo, "CMMASurfaceWindow::ProcureWindowResourcesFromQWidget");
       
   515     switch (iVideoDisplayInitState)
       
   516     {
       
   517     case EUIResourcesAndSurfaceParametersNotSet:
       
   518     {
       
   519         LOG(EJavaMMAPI,EInfo, "CMMASurfaceWindow::ProcureWindowResourcesFromQWidget  -8");
       
   520         iVideoDisplayInitState =
       
   521             EUIResourcesSetAndSurfaceParametersNotSet;
       
   522     }
       
   523     break;
       
   524     case ESurfaceParametersSetAndUIResourcesNotSet:
       
   525     {
       
   526         LOG(EJavaMMAPI,EInfo, "CMMASurfaceWindow::ProcureWindowResourcesFromQWidget  -9");
       
   527         iVideoDisplayInitState =
       
   528             EUIResourcesAndSurfaceParametersSet;
       
   529     }
       
   530     break;
       
   531     // can not occur
       
   532     case EUIResourcesSetAndSurfaceParametersNotSet:
       
   533     case EUIResourcesAndSurfaceParametersSet:
       
   534     default:
       
   535     {
       
   536         LOG(EJavaMMAPI,EInfo, "CMMASurfaceWindow::ProcureWindowResourcesFromQWidget  -10");
       
   537         __ASSERT_DEBUG(EFalse, User::Invariant());
       
   538     }
       
   539     break;
       
   540     }
       
   541 
       
   542     if (iVideoDisplayInitState == EUIResourcesAndSurfaceParametersSet)
       
   543     {
       
   544         LOG(EJavaMMAPI,EInfo, "CMMASurfaceWindow::ProcureWindowResourcesFromQWidget  -11");
       
   545         TRAPD(error, InitVideoDisplayL());
       
   546         LOG(EJavaMMAPI,EInfo, "CMMASurfaceWindow::ProcureWindowResourcesFromQWidget  -12");
       
   547         if (KErrNone != error)
       
   548         {
       
   549             ELOG1(EJavaMMAPI, "CMMASurfaceWindow::MdcDSAResourcesCallback, error = %d", error);
       
   550         }
       
   551     }
       
   552 
       
   553 }
       
   554 /*
       
   555 void CMMASurfaceWindow::MdcDSAResourcesCallback(
       
   556     RWsSession &aWs,
       
   557     CWsScreenDevice &aScreenDevice,
       
   558     RWindowBase &aWindow )
       
   559     {
       
   560     LOG(EJavaMMAPI,EInfo, "CMMASurfaceWindow::MdcDSAResourcesCallback" );
       
   561 
       
   562     // We are in UI thread context now.
       
   563     iWs = &aWs;
       
   564     iScreenDevice = &aScreenDevice;
       
   565     iWindow = &aWindow;
       
   566 
       
   567         switch ( iVideoDisplayInitState )
       
   568           {
       
   569             case EUIResourcesAndSurfaceParametersNotSet:
       
   570                  {
       
   571                  iVideoDisplayInitState =
       
   572                  EUIResourcesSetAndSurfaceParametersNotSet;
       
   573                  }
       
   574                  break;
       
   575             case ESurfaceParametersSetAndUIResourcesNotSet:
       
   576                  {
       
   577                  iVideoDisplayInitState =
       
   578                  EUIResourcesAndSurfaceParametersSet;
       
   579                  }
       
   580                  break;
       
   581              // can not occur
       
   582             case EUIResourcesSetAndSurfaceParametersNotSet:
       
   583           case EUIResourcesAndSurfaceParametersSet:
       
   584             default:
       
   585            {
       
   586              __ASSERT_DEBUG( EFalse, User::Invariant() );
       
   587            }
       
   588                  break;
       
   589           }
       
   590 
       
   591         if( iVideoDisplayInitState == EUIResourcesAndSurfaceParametersSet )
       
   592             {
       
   593             TRAPD(error, InitVideoDisplayL());
       
   594             if ( KErrNone != error )
       
   595                 {
       
   596                 LOG1(EJavaMMAPI,EInfo,"CMMASurfaceWindow::MdcDSAResourcesCallback, error = %d", error);
       
   597                 }
       
   598             }
       
   599     }
       
   600 */
       
   601 void CMMASurfaceWindow::UICallback(TInt aCallbackId)
       
   602 {
       
   603     // We are in UI thread context now.
       
   604     LOG1(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::UICallback CallbackId = %d", aCallbackId);
       
   605 
       
   606     TInt error = KErrNone;
       
   607     switch (aCallbackId)
       
   608     {
       
   609     case ESetClipRect:
       
   610     {
       
   611         error = SetClipRect();
       
   612         LOG1(EJavaMMAPI,EInfo,"CMMASurfaceWindow::UICallback,SetClipRect error = %d", error);
       
   613     }
       
   614     break;
       
   615     case ERemoveSurface:
       
   616     {
       
   617         LOG(EJavaMMAPI, EInfo, "CMMASurfaceWindow::UICallback, ERemoveSurface ");
       
   618         DoRemoveSurface();
       
   619     }
       
   620     break;
       
   621     case ESetDrawRect:
       
   622     {
       
   623         error = StaticRedrawVideo(*this);
       
   624         ELOG1(EJavaMMAPI, "CMMASurfaceWindow::UICallback,StaticRedrawVideo error = %d", error);
       
   625     }
       
   626     break;
       
   627     case EInitVideoDisplay:
       
   628     {
       
   629         TRAP(error, InitVideoDisplayL());
       
   630         ELOG1(EJavaMMAPI, "CMMASurfaceWindow::UICallback,InitVideoDisplayL error = %d", error);
       
   631     }
       
   632     break;
       
   633     case ESetChangedSurfaceParameters:
       
   634     {
       
   635         DoSetChangedSurfaceParameters();
       
   636     }
       
   637     break;
       
   638     case EResetSurfaceParameters:
       
   639     {
       
   640         DoResetSurfaceParameters();
       
   641     }
       
   642     break;
       
   643     case ECleanVideoDisplay:
       
   644     {
       
   645         CleanVideoDisplay();
       
   646     }
       
   647     break;
       
   648     case EDestroyWindow:
       
   649     {
       
   650         Destroy();
       
   651     }
       
   652     break;
       
   653     case EChangeVisibility:
       
   654     {
       
   655         TRAPD(error,DoSetVisibleL());
       
   656         if (error != KErrNone)
       
   657         {
       
   658             LOG1(EJavaMMAPI, EInfo,"CMMASurfaceWindow::UICallback,DoSetVisibleL error = %d", error);
       
   659         }
       
   660     }
       
   661     break;
       
   662     default:
       
   663     {
       
   664         __ASSERT_DEBUG(EFalse, User::Invariant());
       
   665     }
       
   666     break;
       
   667     }
       
   668 }
       
   669 
       
   670 void CMMASurfaceWindow::SetSurfaceParameters(const TSurfaceId& aSurfaceId,
       
   671         const TRect& aCropRect,
       
   672         const TVideoAspectRatio& aPixelAspectRatio)
       
   673 {
       
   674     iSurfaceId = aSurfaceId;
       
   675     iCropRect = aCropRect;
       
   676     iPixelAspectRatio = aPixelAspectRatio;
       
   677 
       
   678     switch (iVideoDisplayInitState)
       
   679     {
       
   680     case EUIResourcesAndSurfaceParametersNotSet:
       
   681     {
       
   682         iVideoDisplayInitState =
       
   683             ESurfaceParametersSetAndUIResourcesNotSet;
       
   684     }
       
   685     break;
       
   686     case EUIResourcesSetAndSurfaceParametersNotSet:
       
   687     {
       
   688         iVideoDisplayInitState =
       
   689             EUIResourcesAndSurfaceParametersSet;
       
   690     }
       
   691     break;
       
   692     // control reaches below two switch cases when
       
   693     // playback is looped using setLoopCount() in java.
       
   694     case ESurfaceParametersSetAndUIResourcesNotSet:
       
   695     {
       
   696     }
       
   697     break;
       
   698     // update surface parameters and return with out calling
       
   699     // InitVideoDisplayL again.
       
   700     case EUIResourcesAndSurfaceParametersSet:
       
   701     {
       
   702         // iDisplay->UIGetCallback( *this, CMMASurfaceWindow::EResetSurfaceParameters );
       
   703         //MMAPI UI 3.x req.
       
   704         LOG(EJavaMMAPI,EInfo,"CMMASurfaceWindow::SetSurfaceParameters : switch case EUIResourcesAndSurfaceParametersSet +");
       
   705         TBool iseSWT = iDisplay->iseSWT();
       
   706         if (iseSWT)
       
   707         {
       
   708             UICallback((TInt)CMMASurfaceWindow::EResetSurfaceParameters);
       
   709         }
       
   710         else
       
   711         {
       
   712             iDisplay->GetCallbackInUiThread((TInt)CMMASurfaceWindow::EResetSurfaceParameters);
       
   713         }
       
   714         LOG(EJavaMMAPI,EInfo,"CMMASurfaceWindow::SetSurfaceParameters : switch case EUIResourcesAndSurfaceParametersSet -");
       
   715         return;
       
   716     }
       
   717     // break; not reachable
       
   718     default: // can not occur
       
   719     {
       
   720         __ASSERT_DEBUG(EFalse, User::Invariant());
       
   721     }
       
   722     break;
       
   723     }
       
   724 
       
   725     if (iVideoDisplayInitState == EUIResourcesAndSurfaceParametersSet)
       
   726     {
       
   727         //iDisplay->UIGetCallback( *this, CMMASurfaceWindow::EInitVideoDisplay );
       
   728         //MMAPI UI 3.x req.
       
   729         TBool iseSWT = iDisplay->iseSWT();
       
   730         if (iseSWT)
       
   731         {
       
   732             UICallback((TInt)CMMASurfaceWindow::EInitVideoDisplay);
       
   733         }
       
   734         else
       
   735         {
       
   736             LOG(EJavaMMAPI,EInfo,"CMMASurfaceWindow::SetSurfaceParameters,EUIResourcesAndSurfaceParametersSet");
       
   737             iDisplay->GetCallbackInUiThread((TInt)CMMASurfaceWindow::EInitVideoDisplay);
       
   738         }
       
   739     }
       
   740 }
       
   741 
       
   742 void CMMASurfaceWindow::SetChangedSurfaceParameters(const TSurfaceId& aSurfaceId,
       
   743         const TRect& aCropRect,
       
   744         const TVideoAspectRatio& aPixelAspectRatio)
       
   745 {
       
   746     iSurfaceId = aSurfaceId;
       
   747     iCropRect = aCropRect;
       
   748     iPixelAspectRatio = aPixelAspectRatio;
       
   749 
       
   750     if (iDisplay)
       
   751     {
       
   752         //iDisplay->UIGetCallback(*this, CMMASurfaceWindow::ESetChangedSurfaceParameters);
       
   753         LOG(EJavaMMAPI,EInfo,"CMMASurfaceWindow::SetChangedSurfaceParameters + ");
       
   754         TBool iseSWT = iDisplay->iseSWT();
       
   755         if (iseSWT)
       
   756         {
       
   757             UICallback((TInt)CMMASurfaceWindow::ESetChangedSurfaceParameters);
       
   758         }
       
   759         else
       
   760         {
       
   761             iDisplay->GetCallbackInUiThread((TInt)CMMASurfaceWindow::ESetChangedSurfaceParameters);
       
   762         }
       
   763         LOG(EJavaMMAPI,EInfo,"CMMASurfaceWindow::SetChangedSurfaceParameters - ");
       
   764 
       
   765     }
       
   766 }
       
   767 
       
   768 void CMMASurfaceWindow::RemoveSurface()
       
   769 {
       
   770     LOG(EJavaMMAPI, EInfo, "CMMASurfaceWindow::RemoveSurface() +");
       
   771     if (iDisplay)
       
   772     {
       
   773         iDisplay->GetCallbackInUiThread((TInt)CMMASurfaceWindow::ERemoveSurface);
       
   774     }
       
   775     LOG(EJavaMMAPI, EInfo, "CMMASurfaceWindow::RemoveSurface() -");
       
   776 }
       
   777 
       
   778 void CMMASurfaceWindow::DoRemoveSurface()
       
   779 {
       
   780     LOG(EJavaMMAPI, EInfo, "CMMASurfaceWindow::DoRemoveSurface() +");
       
   781     if (iMediaClientVideoDisplay)
       
   782     {
       
   783         LOG(EJavaMMAPI,EInfo,"CMMASurfaceWindow::DoRemoveSurface, Removing Surface");
       
   784         iMediaClientVideoDisplay->RemoveSurface();
       
   785         LOG(EJavaMMAPI,EInfo,"CMMASurfaceWindow::DoRemoveSurface, Surface Removed");
       
   786 
       
   787     }
       
   788     LOG(EJavaMMAPI, EInfo, "CMMASurfaceWindow::DoRemoveSurface() -");
       
   789 }
       
   790 
       
   791 void CMMASurfaceWindow::DoResetSurfaceParameters()
       
   792 {
       
   793     __ASSERT_DEBUG((iMediaClientVideoDisplay != NULL), User::Invariant());
       
   794 
       
   795     if (iMediaClientVideoDisplay)
       
   796     {
       
   797         iMediaClientVideoDisplay->RemoveSurface();
       
   798         TInt error = iMediaClientVideoDisplay->SurfaceCreated(iSurfaceId,
       
   799                      iCropRect,
       
   800                      iPixelAspectRatio,
       
   801                      iVideoCropRegion);
       
   802 
       
   803         ELOG1(EJavaMMAPI, "CMMASurfaceWindow::DoResetSurfaceParameters,SurfaceCreated error = %d", error);
       
   804 
       
   805         iMediaClientVideoDisplay->RedrawWindows(iVideoCropRegion);
       
   806     }
       
   807 }
       
   808 
       
   809 void CMMASurfaceWindow::DoSetChangedSurfaceParameters()
       
   810 {
       
   811     if (iMediaClientVideoDisplay)
       
   812     {
       
   813         TInt error = iMediaClientVideoDisplay->SurfaceParametersChanged(iSurfaceId,
       
   814                      iCropRect,
       
   815                      iPixelAspectRatio);
       
   816 
       
   817         ELOG1(EJavaMMAPI, "CMMASurfaceWindow::DoSetChangedSurfaceParameters,SurfaceParametersChanged, error = %d", error);
       
   818 
       
   819         iMediaClientVideoDisplay->RedrawWindows(iVideoCropRegion);
       
   820     }
       
   821 }
       
   822 
       
   823 void CMMASurfaceWindow::InitVideoDisplayL()
       
   824 {
       
   825     if (iVideoDisplayInitState != EUIResourcesAndSurfaceParametersSet)
       
   826     {
       
   827         User::Leave(KErrNotReady);
       
   828     }
       
   829 
       
   830     // check that this is the first time we are creating instance.
       
   831     if (iMediaClientVideoDisplay)
       
   832     {
       
   833         __ASSERT_DEBUG(EFalse, User::Invariant());
       
   834     }
       
   835 
       
   836     iMediaClientVideoDisplay =
       
   837         CMediaClientVideoDisplay::NewL(iScreenDevice->GetScreenNumber(),
       
   838                                        iSurfaceId,
       
   839                                        iCropRect,
       
   840                                        iPixelAspectRatio);
       
   841 
       
   842     // video is not scaled untill user requests explicitly
       
   843     // so retain same video width & height.
       
   844     //TReal32 scaleWidthPercent = 100.0f;
       
   845     //TReal32 scaleHeightPercent = 100.0f;
       
   846 
       
   847     // video rotation feature not supported in MMAPI
       
   848     //TVideoRotation videoRotation(EVideoRotationNone);
       
   849     // no automatic scaling, can be controlled only via VideoControl
       
   850     //TAutoScaleType autoScaleType = EAutoScaleNone;
       
   851 
       
   852     // always align video to the top left corner of the display area
       
   853     //TInt horizontalPosition(EHorizontalAlignLeft);
       
   854     //TInt verticalPosition(EVerticalAlignTop);
       
   855 
       
   856     TInt error = iMediaClientVideoDisplay->SurfaceCreated(iSurfaceId,
       
   857                  iCropRect,
       
   858                  iPixelAspectRatio,
       
   859                  iVideoCropRegion);
       
   860 
       
   861     ELOG1(EJavaMMAPI,  "CMMASurfaceWindow::InitVideoDisplayL error = %d", error);
       
   862     User::LeaveIfError(error);
       
   863 
       
   864     TRect contentRect;
       
   865     if (iVisible)
       
   866     {
       
   867         contentRect = iContentRect;
       
   868     }
       
   869     else
       
   870     {
       
   871         TRect emptyRect(0,0,0,0);
       
   872         contentRect = emptyRect;
       
   873     }
       
   874 
       
   875     // align parent rect with respect to RWindow
       
   876     TRect relativeParentRect;
       
   877     relativeParentRect = iParentRect;
       
   878     relativeParentRect.Move(-iRWindowRect.iTl);
       
   879 
       
   880     // setting video draw rect and adjusting it to window
       
   881     TRect drawRect = contentRect;
       
   882     drawRect.Move(relativeParentRect.iTl);
       
   883 
       
   884     TRect clipRect(0,0,iRWindowRect.Width(),iRWindowRect.Height());
       
   885     //iWindow->SetExtentErr(TPoint(127,8),TSize(128,96));
       
   886     iMediaClientVideoDisplay->AddDisplayWindowL(iWindow,
       
   887             clipRect,
       
   888             iVideoCropRegion,
       
   889             drawRect,  // video extent
       
   890             0.0f, // ignore
       
   891             0.0f, // ignore
       
   892             EVideoRotationNone,
       
   893             EAutoScaleBestFit,
       
   894             EHorizontalAlignCenter,
       
   895             EVerticalAlignCenter,
       
   896             (RWindow*)iWindow);
       
   897 
       
   898 
       
   899 
       
   900     RedrawVideoL();
       
   901 }
       
   902 
       
   903 void CMMASurfaceWindow::CleanVideoDisplay()
       
   904 {
       
   905     LOG(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::CleanVideoDisplay +");
       
   906 
       
   907     SetVisible(EFalse, ETrue);
       
   908     if (iMediaClientVideoDisplay)
       
   909     {
       
   910         if (iWindow)
       
   911         {
       
   912             iMediaClientVideoDisplay->RemoveDisplayWindow(*iWindow);
       
   913         }
       
   914         iMediaClientVideoDisplay->RemoveSurface();
       
   915         delete iMediaClientVideoDisplay;
       
   916 
       
   917         iMediaClientVideoDisplay = NULL;
       
   918         iWindow = NULL;
       
   919         iScreenDevice = NULL;
       
   920         iWs = NULL;
       
   921     }
       
   922 
       
   923     LOG(EJavaMMAPI, EInfo,  "CMMASurfaceWindow::CleanVideoDisplay -");
       
   924 }
       
   925 
       
   926 
       
   927 //  END OF FILE