javauis/mmapi_akn/baseline/inc.dsa/cmmacamerawindow.h
branchRCL_3
changeset 26 2455ef1f5bbc
parent 18 9ac0a0a7da70
equal deleted inserted replaced
25:ae942d28ec0e 26:2455ef1f5bbc
       
     1 /*
       
     2 * Copyright (c) 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 *                for Camera viewfinder usage.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #ifndef CMMACAMERAWINDOW_H
       
    21 #define CMMACAMERAWINDOW_H
       
    22 
       
    23 //  INCLUDES
       
    24 #include <ecam.h>
       
    25 #include <reflcdui.h>
       
    26 #include <w32std.h>
       
    27 #include "mmmadisplaywindow.h"
       
    28 #include "mmmadisplay.h"
       
    29 //  CONSTANTS
       
    30 
       
    31 //  FORWARD DECLARATIONS
       
    32 class CFbsBitmap;
       
    33 class RWsSession;
       
    34 class CWsScreenDevice;
       
    35 class RWindowBase;
       
    36 class MMMADisplay;
       
    37 
       
    38 //  CLASS DECLARATION
       
    39 /**
       
    40 * This class implements MMMADisplayWindow functionality
       
    41 * to use with CMMACameraPlayer.
       
    42 * It duplicates its camera instance within the UI thread
       
    43 * and displays the viewfinder using the UI
       
    44 * DirectScreenAccess resources.
       
    45 *
       
    46 * @since S60 v5.0
       
    47 */
       
    48 
       
    49 
       
    50 NONSHARABLE_CLASS(CMMACameraWindow): public CBase,
       
    51         public MMMADisplayWindow,
       
    52         public MCameraObserver,
       
    53         public MUiEventConsumer,
       
    54         public MDirectScreenAccess
       
    55 {
       
    56 public:
       
    57     enum TUiCallbackType
       
    58     {
       
    59         EDeleteViewFinder = 1,
       
    60         EHideViewFinder,
       
    61         EShowViewFinder,
       
    62         EResetViewFinder,
       
    63         EDestroyWindow
       
    64     };
       
    65 
       
    66     /**
       
    67      * Two-phased constructor.
       
    68      *
       
    69      * @param  aCameraHandle A handle to existing CCamera instance.
       
    70      */
       
    71     static CMMACameraWindow* NewL(TInt aCameraHandle);
       
    72 
       
    73 
       
    74     /**
       
    75      * Destructor.
       
    76      */
       
    77     ~CMMACameraWindow();
       
    78 
       
    79     /**
       
    80      * Gets an information if the DirectViewFinder is started
       
    81      *
       
    82      * @since  S60 v5.0
       
    83      * @return ETrue if DirectViewFinder is active
       
    84      */
       
    85     TBool ViewFinderActive();
       
    86 
       
    87     /**
       
    88      * Notifies window about Started state change
       
    89      *
       
    90      * @since S60 v5.0
       
    91      * @param aStarted Indicates that camera player is in started state
       
    92      */
       
    93     void SetStarted(TBool aStarted);
       
    94 
       
    95     /**
       
    96      * Sets iDisplay
       
    97      * Used to invoke callbacks in UI thread
       
    98      *
       
    99      * @since  S60 v5.0
       
   100      * @param "aDisplay" A Display to be used for callbacks.
       
   101      *         When set, the duplicated CCamera is created in UI thread
       
   102      *         and the necessary DSA resources are got.
       
   103      *         When replacing an old Display (set earlier)
       
   104      *         all the old resources are deleted.
       
   105      *         NULL deletes all allocated UI resources.
       
   106      */
       
   107     void SetDisplay(MMMADisplay *aDisplay);
       
   108 
       
   109 
       
   110 // from base class MMMADisplayWindow
       
   111     void SetDestinationBitmapL(CFbsBitmap* aBitmap);
       
   112     void DrawFrameL(const CFbsBitmap* aBitmap);
       
   113     void SetDrawRect(const TRect& aRect);
       
   114     void SetDrawRectThread(const TRect& aRect);
       
   115     const TRect& DrawRect();
       
   116     TSize WindowSize();
       
   117     void SetPosition(const TPoint& aPosition);
       
   118     void SetVisible(TBool aVisible, TBool aUseEventServer = ETrue);
       
   119     void SetWindowRect(const TRect& aRect,MMMADisplay::TThreadType aThreadType);
       
   120     const TRect& WindowRect();
       
   121     TDisplayWindowType GetDisplayWindowType() const;
       
   122     TBool IsVisible() const;
       
   123     void ContainerSet();
       
   124     void ContainerDestroyed();
       
   125 
       
   126 
       
   127 // from base class MCameraObserver
       
   128     void ReserveComplete(TInt aError);
       
   129     void PowerOnComplete(TInt aError);
       
   130     void ViewFinderFrameReady(CFbsBitmap& aFrame);
       
   131 
       
   132     void ImageReady(CFbsBitmap* aBitmap,
       
   133                     HBufC8* aData,
       
   134                     TInt aError);
       
   135 
       
   136     void FrameBufferReady(MFrameBuffer* aFrameBuffer,
       
   137                           TInt aError);
       
   138 
       
   139 
       
   140 // from base class MUiEventConsumer
       
   141     void MdcDSAResourcesCallback(
       
   142         RWsSession &aWs,
       
   143         CWsScreenDevice &aScreenDevice,
       
   144         RWindowBase &aWindow);
       
   145     void MdcUICallback(TInt aCallbackId);
       
   146 
       
   147 
       
   148 // from base class MDirectScreenAccess
       
   149     void AbortNow(RDirectScreenAccess::TTerminationReasons aReasons);
       
   150     void Restart(RDirectScreenAccess::TTerminationReasons aReasons);
       
   151 
       
   152 
       
   153 private:
       
   154     /**
       
   155      * Constructor.
       
   156      * @see CMMACameraWindow::NewL()
       
   157      */
       
   158     CMMACameraWindow(TInt aCameraIndex);
       
   159 
       
   160     /**
       
   161      * Creates UI Camera -
       
   162      * a new CCamera instance (duplicated from handle
       
   163      * given to the constructor)
       
   164      * Have to be called from the thread which UI Camera
       
   165      * will be controlled from
       
   166      *
       
   167      * @since  S60 v5.0
       
   168      * @param "aWs" WS session from the last MdcDSAResourcesCallback
       
   169      * @param "aScreenDevice" Screen from the last MdcDSAResourcesCallback
       
   170      * @param "aWindow" Window from the last MdcDSAResourcesCallback
       
   171      */
       
   172     void UIStartViewFinder(RWsSession &aWs, CWsScreenDevice &aScreenDevice, RWindowBase &aWindow);
       
   173 
       
   174     /**
       
   175      * If UI Camera have been created
       
   176      * it starts/hides the DirectViewFinder
       
   177      * Have to be called from UI thread in which UI Camera
       
   178      * have been created!
       
   179      *
       
   180      * @since  S60 v5.0
       
   181      * @param "aVisible" If true DirectViewFinder is started, else stopped
       
   182      */
       
   183     void SetViewFinderVisibility(TBool aVisible);
       
   184 
       
   185     /**
       
   186      * Stops the DirectViewFinder and deletes UI Camera instance
       
   187      * Have to be called from UI thread in which UI Camera
       
   188      * have been created before the CMMACameraWindow instance
       
   189      * is deleted!
       
   190      *
       
   191      * @since  S60 v5.0
       
   192      */
       
   193     void ReleaseUiResources();
       
   194 
       
   195     /**
       
   196      * The callback method invoked by starter timer
       
   197      *
       
   198      * @since  S60 v5.0
       
   199      * @param  aThis An instance of CMMACameraWindow
       
   200      * @return Always returns EFalse
       
   201      */
       
   202     static TInt StarterTimerCallback(TAny* aThis);
       
   203 
       
   204     /**
       
   205      * Starts viewfinder.
       
   206      *
       
   207      * @since  S60 v5.0
       
   208      */
       
   209     void StartViewFinder();
       
   210 
       
   211     /**
       
   212      * Resets (stops and starts) viewfinder
       
   213      *
       
   214      * @since  S60 v5.0
       
   215      */
       
   216     void ResetViewFinder();
       
   217 
       
   218     /**
       
   219      * Draws the underlayer of viewfinder.
       
   220      * Used to clear the alpha value.
       
   221      * Uses Direct Screen Access.
       
   222      *
       
   223      * @since  S60 v5.0
       
   224      * @return EFalse if DSA start failed, but may work in the next attempt.
       
   225                ETrue if DSA start passed.
       
   226      */
       
   227     TBool DrawUnderlayer();
       
   228 
       
   229     /**
       
   230      * Draws the error message to specified area.
       
   231      * Used in cases when viewfinder is unable to start
       
   232      *
       
   233      * @since  S60 v5.0
       
   234      * @param aError Viewfinder error id
       
   235      * @param aDrawRect Area to draw to
       
   236      */
       
   237     void DrawViewFinderErrorL(const TInt aError, const TRect& aDrawRect);
       
   238 
       
   239     /**
       
   240      * Deletes this object.
       
   241      *
       
   242      * @since  S60 v5.0
       
   243      */
       
   244     void Destroy();
       
   245 
       
   246 private:  // data
       
   247     /**
       
   248      * Indicates the window visibility.
       
   249      */
       
   250     TBool iVisible;
       
   251 
       
   252     /**
       
   253      * Indicated that owning player is in Started state.
       
   254      */
       
   255     TBool iStarted;
       
   256 
       
   257     /**
       
   258      * Indicates that Direct viewfinder is displayed on screen.
       
   259      */
       
   260     TBool iViewFinderVisible;
       
   261 
       
   262     /**
       
   263      * Indicates that duplicated camera (iUICamera) is powered on.
       
   264      */
       
   265     TBool iCameraPowerOn;
       
   266 
       
   267     /**
       
   268      * Rectangle to display viewfinder on (Window coordinates).
       
   269      */
       
   270     TRect iDrawRect;
       
   271 
       
   272     /**
       
   273      * The area of the window.
       
   274      */
       
   275     TRect iClientRect;
       
   276 
       
   277     /**
       
   278      * The handle of original camera instance.
       
   279      */
       
   280     TInt iCameraHandle;
       
   281 
       
   282     /**
       
   283      * UI Camera instance
       
   284      * Duplicated from iCameraHandle.
       
   285      * Adjustable and usable from UI thread only.
       
   286      * Own.
       
   287      */
       
   288     CCamera* iUICamera;
       
   289 
       
   290     /**
       
   291      * Display instance used to invoke UI callbacks.
       
   292      * Not owned.
       
   293      */
       
   294     MMMADisplay* iDisplay;
       
   295 
       
   296     /**
       
   297      * Window server session used by UI thread.
       
   298      * Adjustable and usable from UI thread only.
       
   299      * Not owned.
       
   300      */
       
   301     RWsSession* iWs;
       
   302 
       
   303     /**
       
   304      * Screen device used by UI thread.
       
   305      * Adjustable and usable from UI thread only.
       
   306      * Not owned.
       
   307      */
       
   308     CWsScreenDevice* iScreenDevice;
       
   309 
       
   310     /**
       
   311      * Window to draw viewfinder on.
       
   312      * Adjustable and usable from UI thread only.
       
   313      * From UI thread.
       
   314      * Not owned.
       
   315      */
       
   316     RWindowBase* iWindow;
       
   317 
       
   318     /**
       
   319      * The timer to delay viewfinder start
       
   320      * to avoid many showing/hidding request
       
   321      * (for instance when scrolling the viewfinder)
       
   322      * Adjustable and usable from UI thread only.
       
   323      * Own.
       
   324      */
       
   325     CPeriodic* iStarterTimer;
       
   326 
       
   327     /**
       
   328      * Direct screen access used to draw the underlayer.
       
   329      * Adjustable and usable from UI thread only.
       
   330      * Own.
       
   331      */
       
   332     CDirectScreenAccess* iDirectAccess;
       
   333 
       
   334     /**
       
   335      * Count of remaining allowed DSA restarts.
       
   336      * In some cases (like screen orientation change)
       
   337      * the DSA fails to start for some time.
       
   338      * Therefore the start is tried more times.
       
   339      */
       
   340     TUint iRemainingDSAStartAttempts;
       
   341 
       
   342     /**
       
   343      * An icon used to display instead of viewfinder.
       
   344      * in case that viewfinder start fails.
       
   345      * Own.
       
   346      */
       
   347     CFbsBitmap* iErrorIconBitmap;
       
   348 
       
   349     /**
       
   350      * Bitmap mask of iErrorIconBitmap.
       
   351      * Own.
       
   352      */
       
   353     CFbsBitmap* iErrorIconMaskBitmap;
       
   354 };
       
   355 
       
   356 #endif // CMMACAMERAWINDOW_H