javauis/mmapi_akn/baseline/inc.nga/cmmasurfacewindow.h
branchRCL_3
changeset 19 04becd199f91
child 46 4376525cdefb
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     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 #ifndef CMMASURFACEWINDOW_H
       
    20 #define CMMASURFACEWINDOW_H
       
    21 
       
    22 
       
    23 //  INCLUDES
       
    24 #include <w32std.h>
       
    25 #include <reflcdui.h>
       
    26 #include <graphics/surface.h>
       
    27 #include <mmf/common/mmfvideosurfacecustomcommands.h>
       
    28 #include <mediaclientvideodisplay.h>
       
    29 
       
    30 #include <e32std.h>
       
    31 #include <mmf/common/mmfstandardcustomcommands.h>
       
    32 #include "mmmadisplaywindow.h"
       
    33 #include "cmmaeventsource.h"
       
    34 #include "cmmaplayer.h"
       
    35 
       
    36 //  FORWARD DECLARATIONS
       
    37 class RWsSession;
       
    38 class CWsScreenDevice;
       
    39 class RWindowBase;
       
    40 class MMMADisplay;
       
    41 
       
    42 //  CONSTANTS
       
    43 const TInt KMMAVideoMinDimension = 32; // minimum video width and height
       
    44 
       
    45 //  CLASS DECLARATION
       
    46 /**
       
    47 * This class implements MMMADisplayWindow functionality
       
    48 * in video display to graphics surface based displays for Helix engine.
       
    49 */
       
    50 NONSHARABLE_CLASS(CMMASurfaceWindow): public CBase,
       
    51         public MMMADisplayWindow,
       
    52         public MUiEventConsumer
       
    53 {
       
    54 public:
       
    55     /**
       
    56      * indicates what method needs to be called in UI thread context.
       
    57      */
       
    58     enum TUiCallbackType
       
    59     {
       
    60         ESetClipRect = 1,
       
    61         ERemoveSurface,
       
    62         ESetDrawRect,
       
    63         EInitVideoDisplay,
       
    64         EResetSurfaceParameters,
       
    65         ESetChangedSurfaceParameters,
       
    66         ECleanVideoDisplay,
       
    67         EDestroyWindow
       
    68     };
       
    69 
       
    70 private:
       
    71     /**
       
    72      * indicates different video display initialization states
       
    73      *
       
    74      * video display state transition can happen in following order:
       
    75      * 1. when MIDlet code is:
       
    76      * Player player = Manager.createPlayer(..);
       
    77      * player.realize();
       
    78      * VideoControl vc = (VideoControl)player.getControl("VideoControl");
       
    79      * vc.initDisplayMode(..);
       
    80      * player.start();
       
    81      *
       
    82      * EUIResourcesAndSurfaceParametersNotSet
       
    83      * EUIResourcesSetAndSurfaceParametersNotSet
       
    84      * EUIResourcesAndSurfaceParametersSet
       
    85      *
       
    86      *          OR
       
    87      *
       
    88      * 2. when MIDlet code is:
       
    89      * Player player = Manager.createPlayer(..);
       
    90      * player.start();
       
    91      * VideoControl vc = (VideoControl)player.getControl("VideoControl");
       
    92      * vc.initDisplayMode(..);
       
    93      *
       
    94      * EUIResourcesAndSurfaceParametersNotSet
       
    95      * ESurfaceParametersSetAndUIResourcesNotSet
       
    96      * EUIResourcesAndSurfaceParametersSet
       
    97      *
       
    98      * InitVideoDisplayL() should be called only after EUIResourcesAndSurfaceParametersSet
       
    99      * state is reached. ie both UI resources and surface parameters becomes available.
       
   100      *
       
   101      * 3. for below mentioned MIDlet code case:
       
   102      * Player player = Manager.createPlayer(..);
       
   103      * player.start(); // state transition is
       
   104      *
       
   105      * EUIResourcesAndSurfaceParametersNotSet
       
   106      * ESurfaceParametersSetAndUIResourcesNotSet
       
   107      * note that InitVideoDisplayL() is not called and video is not displayed in this case.
       
   108      */
       
   109     enum TVideoDisplayInitState
       
   110     {
       
   111         /**
       
   112          * indicates ui resources and surface parameters are not yet set.
       
   113          * UI resources are RWindowBase, CWsScreenDevice and RWsSession.
       
   114          * Surface parameters are TSurfaceId, TRect and TVideoAspectRatio.
       
   115          */
       
   116         EUIResourcesAndSurfaceParametersNotSet = 1,
       
   117         /**
       
   118          * indicates UI resources are set and surface parameters not yet set.
       
   119          * UI resources are set when initDisplayMode() is called and RWindow becomes available.
       
   120          */
       
   121         EUIResourcesSetAndSurfaceParametersNotSet,
       
   122         /**
       
   123          * indicates UI resources are not yet set and surface parameters are set.
       
   124          * Surface parameters are set when player.start() is called.
       
   125          */
       
   126         ESurfaceParametersSetAndUIResourcesNotSet,
       
   127         /**
       
   128          * indicates UI resources and surface parameters are set.
       
   129          */
       
   130         EUIResourcesAndSurfaceParametersSet
       
   131     };
       
   132 
       
   133 public:   // Constructors and destructors
       
   134     static CMMASurfaceWindow* NewL(
       
   135         CMMAEventSource* aEventSource,
       
   136         CMMAPlayer* aPlayer);
       
   137 
       
   138     virtual ~CMMASurfaceWindow();
       
   139 
       
   140 private:  // Constructors and destructors
       
   141     CMMASurfaceWindow(
       
   142         CMMAEventSource* aEventSource,
       
   143         CMMAPlayer* aPlayer);
       
   144 
       
   145 public: // Methods derived from MMMADisplayWindow
       
   146     void SetDestinationBitmapL(CFbsBitmap* aBitmap);
       
   147     void DrawFrameL(const CFbsBitmap* aBitmap);
       
   148     void SetDrawRect(const TRect& aRect);
       
   149     void SetDrawRectThread(const TRect& aRect);
       
   150     const TRect& DrawRect();
       
   151     TSize WindowSize();
       
   152     void SetPosition(const TPoint& aPosition);
       
   153     void SetVisible(TBool aVisible, TBool aUseEventServer = ETrue);
       
   154     void SetWindowRect(const TRect& aRect, MMMADisplay::TThreadType aThreadType);
       
   155     void SetVideoCropRegion(const TRect& aRect);
       
   156     void SetRWindowRect(const TRect& aRect, MMMADisplay::TThreadType aThreadType);
       
   157     const TRect& WindowRect();
       
   158     void ContainerDestroyed();
       
   159     void ContainerSet();
       
   160 
       
   161 public: // from base class MUiEventConsumer
       
   162     void MdcDSAResourcesCallback(RWsSession &aWs,
       
   163                                  CWsScreenDevice &aScreenDevice,
       
   164                                  RWindowBase &aWindow);
       
   165     void MdcUICallback(TInt aCallbackId);
       
   166 
       
   167 public: // New methods
       
   168     TBool IsVisible() const;
       
   169     void SetDisplay(MMMADisplay *aDisplay);
       
   170 
       
   171     /**
       
   172      * copies surface paramaters and intializes video display if
       
   173      * RWindow is already set, ie if intDisplayMode already called in midlet.
       
   174      * invokes InitVideoDisplayL() in UI thread context.
       
   175      *
       
   176      * @params aSurfaceId, aCropRect, aPixelAspectRatio surface paramaters.
       
   177      */
       
   178     void SetSurfaceParameters(const TSurfaceId& aSurfaceId,
       
   179                               const TRect& aCropRect,
       
   180                               const TVideoAspectRatio& aPixelAspectRatio);
       
   181 
       
   182     /**
       
   183      * invokes DoRemoveSurface() in UI thread context.
       
   184      */
       
   185     void RemoveSurface();
       
   186 
       
   187     /**
       
   188      * updates members variables with new surface parameters and invokes
       
   189      * DoSetChangedSurfaceParameters() in UI thread context.
       
   190      *
       
   191      * @params aSurfaceId, aCropRect, aPixelAspectRatio surface paramaters.
       
   192      */
       
   193     void SetChangedSurfaceParameters(const TSurfaceId& aSurfaceId,
       
   194                                      const TRect& aCropRect,
       
   195                                      const TVideoAspectRatio& aPixelAspectRatio);
       
   196 
       
   197 private: // New methods
       
   198     /**
       
   199      * starts video rendering to a graphics surface.
       
   200      * restarts video rendering to a graphics surafce with changed parameters.
       
   201      * This method must always be executed in UI-Thread context.
       
   202      */
       
   203     void RedrawVideoL();
       
   204 
       
   205     /**
       
   206      * utility function to invoke RedrawVideoL() function with in a TRAP harness.
       
   207      *
       
   208      * @param aSurfaceWindow reference to CMMASurfaceWindow instance on which RedrawVideoL()
       
   209      * has to be invoked
       
   210      * @return TInt Symbian OS error code, KErrNone if no error
       
   211      */
       
   212     static TInt StaticRedrawVideo(CMMASurfaceWindow& aSurfaceWindow);
       
   213 
       
   214     /**
       
   215      * creates new instance of CMediaClientVideoDisplay and intializes it with
       
   216      * surfaces and windows.
       
   217      * This method must always be executed in UI-Thread context.
       
   218      */
       
   219     void InitVideoDisplayL();
       
   220 
       
   221     /**
       
   222      * updates CMediaClientVideoDisplay with new RWindow rect value.
       
   223      * This method must always be executed in UI-Thread context.
       
   224      */
       
   225     TInt SetClipRect();
       
   226 
       
   227     /**
       
   228      * updates CMediaClientVideoDisplay instance with new surface parameters.
       
   229      * This method must always be executed in UI-Thread context.
       
   230      */
       
   231     void DoSetChangedSurfaceParameters();
       
   232 
       
   233     /**
       
   234      * resets CMediaClientVideoDisplay instance with new surface parameters.
       
   235      * This method must always be executed in UI-Thread context.
       
   236      */
       
   237     void DoResetSurfaceParameters();
       
   238 
       
   239     /**
       
   240      * Removes Surface from RWindow
       
   241      * This method must always be executed in UI-Thread context.
       
   242      */
       
   243     void DoRemoveSurface();
       
   244 
       
   245     /**
       
   246      * removes surfaces and windows from CMediaClientVideoDisplay instance
       
   247      * and deletes the instance.
       
   248      * This method must always be executed in UI-Thread context.
       
   249      */
       
   250     void CleanVideoDisplay();
       
   251 
       
   252     /**
       
   253      * Deletes this object.
       
   254      *
       
   255      * @since  S60 v5.2
       
   256      */
       
   257     void Destroy();
       
   258 
       
   259 private:  // Data
       
   260     /**
       
   261      * drawing area where video is rendered.
       
   262      */
       
   263     TRect iContentRect;
       
   264 
       
   265     /**
       
   266          * parent rectangle used for positioning contentRect.
       
   267          */
       
   268     TRect iParentRect;
       
   269 
       
   270     /**
       
   271      * Symbian RWindow rect
       
   272      */
       
   273     TRect iRWindowRect;
       
   274 
       
   275     /**
       
   276      * not owned, used for switching from UI thread to MMA thread
       
   277      */
       
   278     CMMAEventSource* iEventSource;
       
   279 
       
   280     /**
       
   281      * We must depend on player's state because direct screen access may
       
   282      * not be resumed before player is started.
       
   283      * not owned.
       
   284      */
       
   285     CMMAPlayer* iPlayer;
       
   286 
       
   287     /**
       
   288      * crop rectangle of video
       
   289      */
       
   290     TRect iVideoCropRegion;
       
   291 
       
   292     /**
       
   293      * owned, used for video display on surface
       
   294      * this instance is created & accessed in UI thread only.
       
   295      */
       
   296     CMediaClientVideoDisplay* iMediaClientVideoDisplay;
       
   297 
       
   298     /**
       
   299          * Display instance used to invoke UI callbacks.
       
   300          * Not owned.
       
   301          */
       
   302     MMMADisplay* iDisplay;
       
   303 
       
   304     /**
       
   305      * Window server session used by UI thread.
       
   306      * Adjustable and usable from UI thread only.
       
   307      * Not owned.
       
   308      */
       
   309     RWsSession* iWs;
       
   310 
       
   311     /**
       
   312      * Screen device used by UI thread.
       
   313      * Adjustable and usable from UI thread only.
       
   314      * Not owned.
       
   315      */
       
   316     CWsScreenDevice* iScreenDevice;
       
   317 
       
   318     /**
       
   319      * Window where video is displayed.
       
   320      * Adjustable and usable from UI thread only.
       
   321      * From UI thread.
       
   322      * Not owned.
       
   323      */
       
   324     RWindowBase* iWindow;
       
   325 
       
   326     /**
       
   327      * The surface to be created for composition.
       
   328      */
       
   329     TSurfaceId iSurfaceId;
       
   330 
       
   331     /**
       
   332          * The dimensions of the crop rectangle, relative to the video image.
       
   333          */
       
   334     TRect iCropRect;
       
   335 
       
   336     /**
       
   337          * The pixel aspect ratio to display video picture.
       
   338          */
       
   339     TVideoAspectRatio iPixelAspectRatio;
       
   340 
       
   341     /**
       
   342      * indicates the video display initialization state.
       
   343      *
       
   344      */
       
   345     TVideoDisplayInitState iVideoDisplayInitState;
       
   346 
       
   347     /**
       
   348      * Indicates if content need to be drawn.
       
   349      */
       
   350     TBool iVisible;
       
   351 
       
   352 };
       
   353 
       
   354 #endif // CMMASURFACEWINDOW_H