javauis/mmapi_qt/baseline/src.dsa/cmmadsawindow.cpp
changeset 23 98ccebc37403
child 26 dc7c549001d5
equal deleted inserted replaced
21:2a9601315dfc 23:98ccebc37403
       
     1 /*
       
     2 * Copyright (c) 2002-2009 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 Direct Screen Access based displays for Helix engine.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 //  Include Files
       
    21 #include <logger.h>
       
    22 #include "cmmadsawindow.h"
       
    23 #include "cmmaplayer.h"
       
    24 
       
    25 CMMADSAWindow* CMMADSAWindow::NewL(
       
    26     MMAFunctionServer* aEventSource,
       
    27     CMMAPlayer* aPlayer,
       
    28     RMMFVideoPlayControllerCustomCommands* aVPCustomCommand)
       
    29 {
       
    30     CMMADSAWindow* self =
       
    31         new(ELeave) CMMADSAWindow(aEventSource,
       
    32                                   aPlayer,
       
    33                                   aVPCustomCommand);
       
    34     CleanupStack::PushL(self);
       
    35     self->ConstructL();
       
    36     CleanupStack::Pop();
       
    37     return self;
       
    38 }
       
    39 
       
    40 // Destructor (virtual by CBase)
       
    41 CMMADSAWindow::~CMMADSAWindow()
       
    42 {
       
    43     LOG( EJavaMMAPI, EInfo, "CMMADSAWindow::~CMMADSAWindow");
       
    44 }
       
    45 
       
    46 CMMADSAWindow::CMMADSAWindow(
       
    47     MMAFunctionServer* aEventSource,
       
    48     CMMAPlayer* aPlayer,
       
    49     RMMFVideoPlayControllerCustomCommands* aVPCustomCommand)
       
    50         : iEventSource(aEventSource), iPlayer(aPlayer),
       
    51         iVideoPlayControllerCustomCommands(aVPCustomCommand),
       
    52         iDSAAborted(EFalse)
       
    53 {
       
    54     // Nothing to do.
       
    55 }
       
    56 
       
    57 void CMMADSAWindow::ConstructL()
       
    58 {
       
    59     iClientRect.SetRect(0, 0, 0, 0);
       
    60 
       
    61     // Empty rect until video size is known
       
    62     iDrawRect.SetRect(0, 0, 0, 0);
       
    63 }
       
    64 
       
    65 
       
    66 void CMMADSAWindow::SetDestinationBitmapL(CFbsBitmap* /*aBitmap*/)
       
    67 {
       
    68     // Ignored, this window will not be used for actual drawing
       
    69 }
       
    70 
       
    71 void CMMADSAWindow::DrawFrameL(const CFbsBitmap* /*aBitmap*/)
       
    72 {
       
    73     // Ignored, this window will not be used for actual drawing
       
    74 }
       
    75 
       
    76 // Local wrapper function to SetDrawRect method
       
    77 LOCAL_C void StaticSetDrawRect(
       
    78     CMMADSAWindow* aWindow,
       
    79     const TRect* aRect,
       
    80     MMAFunctionServer* aEventSource,
       
    81     CMMAPlayer* aPlayer)
       
    82 {
       
    83     RPointerArray< CMMAPlayer > players = aEventSource->Players();
       
    84     // Invoke SetDrawRect only if the player has not been cleaned
       
    85     if (players.Find(aPlayer) != KErrNotFound)
       
    86     {
       
    87         aWindow->SetDrawRect(*aRect);
       
    88     }
       
    89 }
       
    90 
       
    91 void CMMADSAWindow::SetDrawRectThread(const TRect& aRect)
       
    92 {
       
    93     // Call through event source changes thread to MMA event source thread
       
    94     // and new rect can be set with RMMFVideoPlayControllerCustomCommands
       
    95     // MMA player may be deleted after ExecuteV and before the static method
       
    96     // is called so Event source is used to check if a cleanup has
       
    97     // already been done for the player (for example due to MIDlet exit)
       
    98     iEventSource->ExecuteV(&StaticSetDrawRect,
       
    99                            this,
       
   100                            &aRect,
       
   101                            iEventSource,
       
   102                            iPlayer);
       
   103 }
       
   104 
       
   105 void CMMADSAWindow::SetDrawRect(const TRect& aRect)
       
   106 {
       
   107     LOG2( EJavaMMAPI, EInfo, "MID::CMMADSAWindow::SetDrawRect TL %d %d",
       
   108                aRect.iTl.iX, aRect.iTl.iY);
       
   109     LOG2( EJavaMMAPI, EInfo, "MID::CMMADSAWindow::SetDrawRect BR %d %d",
       
   110                aRect.iBr.iX, aRect.iBr.iY);
       
   111 
       
   112     // setting video draw rect and adjusting it to window
       
   113     iDrawRect = aRect;
       
   114     TRect drawRect = iDrawRect;
       
   115     drawRect.Move(iClientRect.iTl);
       
   116 
       
   117     if (!iVideoPlayControllerCustomCommands)
       
   118     {
       
   119         LOG( EJavaMMAPI, EInfo, "MID::CMMADSAWindow::SetDrawRect: no VideoPlayControllerCustomCommands set, aborting -");
       
   120         return;
       
   121     }
       
   122 
       
   123     if (iVisible)
       
   124     {
       
   125         LOG( EJavaMMAPI, EInfo, "MID::CMMADSAWindow::SetDrawRect: Abort DSA");
       
   126         iVideoPlayControllerCustomCommands->DirectScreenAccessEvent(EAbortDSA);
       
   127     }
       
   128 
       
   129     LOG2( EJavaMMAPI, EInfo, "MID::CMMADSAWindow::SetDrawRect: drawRect TL %d %d",
       
   130                drawRect.iTl.iX, drawRect.iTl.iY);
       
   131     LOG2( EJavaMMAPI, EInfo, "MID::CMMADSAWindow::SetDrawRect: drawRect BR %d %d",
       
   132                drawRect.iBr.iX, drawRect.iBr.iY);
       
   133 
       
   134     // Area where should be drawn is the intersection of drawRect and iClientRect.
       
   135     TRect areaRect = iClientRect;
       
   136     areaRect.Intersection(drawRect);
       
   137 
       
   138     LOG2( EJavaMMAPI, EInfo, "MID::CMMADSAWindow::SetDrawRect: areaRect TL %d %d",
       
   139                areaRect.iTl.iX, areaRect.iTl.iY);
       
   140     LOG2( EJavaMMAPI, EInfo, "MID::CMMADSAWindow::SetDrawRect: areaRect BR %d %d",
       
   141                areaRect.iBr.iX, areaRect.iBr.iY);
       
   142 
       
   143     if (iVisible && !iDSAAborted)
       
   144     {
       
   145         LOG( EJavaMMAPI, EInfo, "MID::CMMADSAWindow::SetDrawRect: SetDisplayWindow( drawRect, areaRect )");
       
   146         iVideoPlayControllerCustomCommands->SetDisplayWindow(
       
   147             drawRect , areaRect);
       
   148 
       
   149         LOG( EJavaMMAPI, EInfo, "MID::CMMADSAWindow::SetDrawRect: Update region (areaRect)");
       
   150         RRegion region(areaRect);
       
   151         iVideoPlayControllerCustomCommands->UpdateDisplayRegion(region);
       
   152         region.Close();
       
   153 
       
   154         LOG( EJavaMMAPI, EInfo, "MID::CMMADSAWindow::SetDrawRect: Resume DSA");
       
   155         iVideoPlayControllerCustomCommands->DirectScreenAccessEvent(EResumeDSA);
       
   156     }
       
   157     LOG( EJavaMMAPI, EInfo, "MID::CMMADSAWindow::SetDrawRect: -");
       
   158 }
       
   159 
       
   160 const TRect& CMMADSAWindow::DrawRect()
       
   161 {
       
   162     return iDrawRect;
       
   163 }
       
   164 
       
   165 TSize CMMADSAWindow::WindowSize()
       
   166 {
       
   167     return iClientRect.Size();
       
   168 }
       
   169 
       
   170 void CMMADSAWindow::SetPosition(const TPoint& aPosition)
       
   171 {
       
   172     // changing to MMA thread
       
   173     // MMA player may be deleted after ExecuteV and before the static method
       
   174     // is called so Event source is used to check if a cleanup has
       
   175     // already been done for the player (for example due to MIDlet exit)
       
   176     iEventSource->ExecuteV(&CMMADSAWindow::StaticSetWindowPosition,
       
   177                            this,
       
   178                            aPosition,
       
   179                            iEventSource,
       
   180                            iPlayer);
       
   181 }
       
   182 
       
   183 void CMMADSAWindow::StaticSetWindowPosition(
       
   184     CMMADSAWindow* aWindow,
       
   185     TPoint aPosition,
       
   186     MMAFunctionServer* aEventSource,
       
   187     CMMAPlayer* aPlayer)
       
   188 {
       
   189     RPointerArray< CMMAPlayer > players = aEventSource->Players();
       
   190     // Invoke SetDrawRect only if the player has not been cleaned
       
   191     if (players.Find(aPlayer) != KErrNotFound)
       
   192     {
       
   193         aWindow->SetDrawRect(TRect(aPosition, aWindow->iDrawRect.Size()));
       
   194     }
       
   195 }
       
   196 
       
   197 TBool CMMADSAWindow::IsVisible() const
       
   198 {
       
   199     LOG1( EJavaMMAPI, EInfo, "MID::CMMADSAWindow::IsVisible %d ", iVisible);
       
   200     return iVisible;
       
   201 }
       
   202 
       
   203 void CMMADSAWindow::SetVisible(TBool aVisible, TBool aUseEventServer)
       
   204 {
       
   205     LOG2( EJavaMMAPI, EInfo, "MID::CMMADSAWindow::SetVisible avisible=%d useES=%d +", aVisible, aUseEventServer);
       
   206     // Event server may not be used if we already in mma event server thread
       
   207     if (aUseEventServer)
       
   208     {
       
   209         // MMA player may be deleted after ExecuteV and before the static method
       
   210         // is called so Event source is used to check if a cleanup has
       
   211         // already been done for the player (for example due to MIDlet exit)
       
   212         iEventSource->ExecuteV(&CMMADSAWindow::SetWindowVisible,
       
   213                                this,
       
   214                                aVisible,
       
   215                                iEventSource,
       
   216                                iPlayer);
       
   217     }
       
   218     else
       
   219     {
       
   220         SetWindowVisible(this, aVisible, iEventSource, iPlayer);
       
   221     }
       
   222     LOG1( EJavaMMAPI, EInfo, "MID::CMMADSAWindow::SetVisible %d -", aVisible);
       
   223 }
       
   224 
       
   225 void CMMADSAWindow::SetWindowVisible(
       
   226     CMMADSAWindow* aWindow,
       
   227     TBool aVisible,
       
   228     MMAFunctionServer* aEventSource,
       
   229     CMMAPlayer* aPlayer)
       
   230 {
       
   231     LOG1( EJavaMMAPI, EInfo, "MID::CMMADSAWindow::SetWindowVisible aVisible %d", aVisible);
       
   232     RPointerArray< CMMAPlayer > players = aEventSource->Players();
       
   233     // Invoke SetDrawRect only if the player has not been cleaned
       
   234     if (players.Find(aPlayer) != KErrNotFound)
       
   235     {
       
   236         LOG( EJavaMMAPI, EInfo, "MID::CMMADSAWindow::SetWindowVisible : Player found");
       
   237         if (aVisible != aWindow->iVisible)
       
   238         {
       
   239             LOG( EJavaMMAPI, EInfo, "MID::CMMADSAWindow::SetWindowVisible: Changed visibility");
       
   240             aWindow->iVisible = aVisible;
       
   241         }
       
   242         if (aVisible)
       
   243         {
       
   244             LOG( EJavaMMAPI, EInfo, "MID::CMMADSAWindow::SetWindowVisible: aVisible = 1");
       
   245             const TRect drawRect = aWindow->DrawRect();
       
   246 
       
   247             aWindow->SetDrawRect(drawRect);
       
   248         }
       
   249         else
       
   250         {
       
   251             LOG( EJavaMMAPI, EInfo, "MID::CMMADSAWindow::SetWindowVisible: aVisible = 0");
       
   252             TRect emptyRect(0, 0, 0, 0);
       
   253 
       
   254             RRegion region(emptyRect);
       
   255             aWindow->iVideoPlayControllerCustomCommands->UpdateDisplayRegion(region);
       
   256             region.Close();
       
   257             LOG( EJavaMMAPI, EInfo, "MID::CMMADSAWindow::SetWindowVisible: Abort DSA");
       
   258 
       
   259             aWindow->iVideoPlayControllerCustomCommands->
       
   260             DirectScreenAccessEvent(EAbortDSA);
       
   261         }
       
   262 
       
   263     }
       
   264 }
       
   265 
       
   266 void CMMADSAWindow::SetWindowRect(const TRect& aRect,MMMADisplay::TThreadType /*aThreadType*/)
       
   267 {
       
   268     LOG2( EJavaMMAPI, EInfo, "MID::CMMADSAWindow::SetWindowRect aRect TL %d %d",
       
   269                aRect.iTl.iX, aRect.iTl.iY);
       
   270     LOG2( EJavaMMAPI, EInfo, "MID::CMMADSAWindow::SetWindowRect aRect BR %d %d",
       
   271                aRect.iBr.iX, aRect.iBr.iY);
       
   272 
       
   273     iClientRect = aRect;
       
   274 }
       
   275 
       
   276 const TRect& CMMADSAWindow::WindowRect()
       
   277 {
       
   278     return iClientRect;
       
   279 }
       
   280 
       
   281 
       
   282 void CMMADSAWindow::AbortDSA()
       
   283 {
       
   284     iDSAAborted = ETrue;
       
   285 
       
   286     // Always runs in UI thread
       
   287     iEventSource->ExecuteV(&StaticAbortDSA,
       
   288                            this,
       
   289                            iEventSource,
       
   290                            iPlayer);
       
   291 }
       
   292 
       
   293 
       
   294 void CMMADSAWindow::ResumeDSA()
       
   295 {
       
   296     iDSAAborted = EFalse;
       
   297 
       
   298     // Always runs in UI thread
       
   299     iEventSource->ExecuteV(&StaticResumeDSA,
       
   300                            this,
       
   301                            iEventSource,
       
   302                            iPlayer);
       
   303 }
       
   304 
       
   305 
       
   306 void CMMADSAWindow::StaticAbortDSA(
       
   307     CMMADSAWindow* aWindow,
       
   308     MMAFunctionServer* aEventSource,
       
   309     CMMAPlayer* aPlayer)
       
   310 {
       
   311     RPointerArray< CMMAPlayer > players = aEventSource->Players();
       
   312     // Invoke SetDrawRect only if the player has not been cleaned
       
   313     if (players.Find(aPlayer) != KErrNotFound &&
       
   314             aWindow->iVisible && aWindow->iVideoPlayControllerCustomCommands)
       
   315     {
       
   316         TRect emptyRect(0, 0, 0, 0);
       
   317 
       
   318         RRegion region(emptyRect);
       
   319         aWindow->iVideoPlayControllerCustomCommands->UpdateDisplayRegion(region);
       
   320         region.Close();
       
   321         aWindow->iVideoPlayControllerCustomCommands->DirectScreenAccessEvent(EAbortDSA);
       
   322     }
       
   323 }
       
   324 
       
   325 
       
   326 void CMMADSAWindow::StaticResumeDSA(
       
   327     CMMADSAWindow* aWindow,
       
   328     MMAFunctionServer* aEventSource,
       
   329     CMMAPlayer* aPlayer)
       
   330 {
       
   331     RPointerArray< CMMAPlayer > players = aEventSource->Players();
       
   332     // Invoke SetDrawRect only if the player has not been cleaned
       
   333     if (players.Find(aPlayer) != KErrNotFound &&
       
   334             aWindow->iVisible && aWindow->iVideoPlayControllerCustomCommands)
       
   335     {
       
   336         TRect drawRect = aWindow->iDrawRect;
       
   337         drawRect.Move(aWindow->iClientRect.iTl);
       
   338 
       
   339         // Area where should be drawn is the intersection of drawRect and iClientRect.
       
   340         TRect areaRect = aWindow->iClientRect;
       
   341         areaRect.Intersection(drawRect);
       
   342 
       
   343         aWindow->iVideoPlayControllerCustomCommands->SetDisplayWindow(
       
   344             drawRect , areaRect);
       
   345 
       
   346         RRegion region(areaRect);
       
   347         aWindow->iVideoPlayControllerCustomCommands->UpdateDisplayRegion(region);
       
   348         region.Close();
       
   349 
       
   350         aWindow->iVideoPlayControllerCustomCommands->DirectScreenAccessEvent(EResumeDSA);
       
   351     }
       
   352 }
       
   353 
       
   354 void CMMADSAWindow::ContainerDestroyed()
       
   355 {
       
   356     SetVisible(EFalse, ETrue);
       
   357 }
       
   358 
       
   359 //  END OF FILE