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