javauis/mmapi_akn/baseline/src/cmmacamerawindow.cpp
changeset 21 2a9601315dfc
child 23 98ccebc37403
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     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 //  Include Files
       
    21 #include <eikenv.h>
       
    22 #include <gdi.h>
       
    23 #include <jdebug.h>
       
    24 #include <AknsUtils.h>
       
    25 #include <AknsDrawUtils.h>
       
    26 
       
    27 #include <cameraapp.mbg>
       
    28 
       
    29 // Used for iDisplay member
       
    30 
       
    31 #include "cmmacamerawindow.h"
       
    32 
       
    33 // Camera viewfinder start delay
       
    34 const TInt KStarterTimeout = 100000; //100 msecs
       
    35 
       
    36 // Margin of icon displayed instead of viewfinder in case of error
       
    37 const TInt KErrorIconMargin = 5; //5 pixels
       
    38 
       
    39 
       
    40 _LIT(KCameraAppBitmapFile, "z:\\resource\\apps\\cameraapp.mif");
       
    41 
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // CMMACameraWindow::NewL
       
    45 // Two-phased constructor.
       
    46 // Use this method to create a CMMACameraWindow instance.
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 CMMACameraWindow* CMMACameraWindow::NewL(TInt aCameraHandle)
       
    50 {
       
    51     CMMACameraWindow* self = new(ELeave)CMMACameraWindow(aCameraHandle);
       
    52     return self;
       
    53 }
       
    54 
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // CMMACameraWindow::~CMMACameraWindow
       
    58 // Destructor.
       
    59 // NOTE: iUICamera have to be deleted by ReleaseUiResources() called
       
    60 //       from UI thread
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 CMMACameraWindow::~CMMACameraWindow()
       
    64 {
       
    65     // It's not allowed to delete any nonsharable object here.
       
    66     // This must be done in Destroy().
       
    67     // If the iDisplay is set,
       
    68     // instance should be deleted by sending
       
    69     // event from UI to be received by MUiEventConsumer.
       
    70 }
       
    71 
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // CMMACameraWindow::ViewFinderActive
       
    75 // Gets an information if the viewfinder is started.
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 TBool CMMACameraWindow::ViewFinderActive()
       
    79 {
       
    80     return iUICamera && iViewFinderVisible;
       
    81 }
       
    82 
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 // CMMACameraWindow::SetStarted
       
    86 // Notifies window about Started state change.
       
    87 // If started, tries to start viewfinder.
       
    88 // If not started, stops viewfinder.
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 void CMMACameraWindow::SetStarted(TBool aStarted)
       
    92 {
       
    93     iStarted = aStarted;
       
    94     if (iDisplay)
       
    95     {
       
    96         if (iStarted)
       
    97         {
       
    98             iDisplay->UIGetCallback(
       
    99                 *this, CMMACameraWindow::EShowViewFinder);
       
   100         }
       
   101         else
       
   102         {
       
   103             iDisplay->UIGetCallback(
       
   104                 *this, CMMACameraWindow::EHideViewFinder);
       
   105         }
       
   106     }
       
   107 }
       
   108 
       
   109 
       
   110 // ---------------------------------------------------------------------------
       
   111 // CMMACameraWindow::SetDisplay
       
   112 // Sets iDisplay used to invoke callbacks from UI thread.
       
   113 // ---------------------------------------------------------------------------
       
   114 //
       
   115 void CMMACameraWindow::SetDisplay(MMMADisplay *aDisplay)
       
   116 {
       
   117     if (iDisplay != aDisplay)
       
   118     {
       
   119         if (iDisplay)
       
   120         {
       
   121             // Clear the resources created within the old Display
       
   122             iDisplay->UIGetCallback(
       
   123                 *this, CMMACameraWindow::EDeleteViewFinder);
       
   124         }
       
   125 
       
   126         // Set the new Display
       
   127         iDisplay = aDisplay;
       
   128 
       
   129         if (iDisplay)
       
   130         {
       
   131             // Get a DSA resources for the new Display
       
   132             iDisplay->UIGetDSAResources(*this, MMMADisplay::EMmaThread);
       
   133         }
       
   134     }
       
   135 }
       
   136 
       
   137 
       
   138 // ---------------------------------------------------------------------------
       
   139 // From class MMMADisplayWindow
       
   140 // CMMACameraWindow::SetDestinationBitmapL
       
   141 //
       
   142 // ---------------------------------------------------------------------------
       
   143 //
       
   144 void CMMACameraWindow::SetDestinationBitmapL(CFbsBitmap* /*aBitmap*/)
       
   145 {
       
   146     // Ignored, this window will not be used for actual drawing
       
   147     DEBUG("CMMACameraWindow::SetDestinationBitmapL");
       
   148 }
       
   149 
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 // From class MMMADisplayWindow
       
   153 // CMMACameraWindow::DrawFrameL
       
   154 //
       
   155 // ---------------------------------------------------------------------------
       
   156 //
       
   157 void CMMACameraWindow::DrawFrameL(const CFbsBitmap* /*aBitmap*/)
       
   158 {
       
   159     // Ignored, this window will not be used for actual drawing
       
   160 }
       
   161 
       
   162 
       
   163 // ---------------------------------------------------------------------------
       
   164 // From class MMMADisplayWindow
       
   165 // CMMACameraWindow::SetDrawRect
       
   166 //
       
   167 // ---------------------------------------------------------------------------
       
   168 //
       
   169 void CMMACameraWindow::SetDrawRect(const TRect& aRect)
       
   170 {
       
   171     // MMAPI thread
       
   172     DEBUG_INT2("MMA::CMMACameraWindow::SetDrawRect TL:%d,%d",
       
   173                aRect.iTl.iX, aRect.iTl.iY);
       
   174     DEBUG_INT2("MMA::CMMACameraWindow::SetDrawRect BR:%d,%d",
       
   175                aRect.iBr.iX, aRect.iBr.iY);
       
   176 
       
   177     iDrawRect = aRect;
       
   178 
       
   179     if (iDisplay)
       
   180     {
       
   181         iDisplay->UIGetCallback(*this, CMMACameraWindow::EResetViewFinder);
       
   182     }
       
   183 }
       
   184 
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 // From class MMMADisplayWindow
       
   188 // CMMACameraWindow::SetDrawRectThread
       
   189 //
       
   190 // ---------------------------------------------------------------------------
       
   191 //
       
   192 void CMMACameraWindow::SetDrawRectThread(const TRect& aRect)
       
   193 {
       
   194     DEBUG_INT2("MMA::CMMACameraWindow::SetDrawRectThread TL:%d,%d",
       
   195                aRect.iTl.iX, aRect.iTl.iY);
       
   196     DEBUG_INT2("MMA::CMMACameraWindow::SetDrawRectThread BR:%d,%d",
       
   197                aRect.iBr.iX, aRect.iBr.iY);
       
   198 
       
   199     // Note: Runs in UI thread only
       
   200 
       
   201     // Bitmap window's rect can be set in any thread.
       
   202     if (iDrawRect != aRect)
       
   203     {
       
   204         iDrawRect = aRect;
       
   205 
       
   206         // Stop and start ViewFinder to update position
       
   207         ResetViewFinder();
       
   208     }
       
   209 
       
   210 }
       
   211 
       
   212 
       
   213 // ---------------------------------------------------------------------------
       
   214 // From class MMMADisplayWindow
       
   215 // CMMACameraWindow::DrawRect
       
   216 //
       
   217 // ---------------------------------------------------------------------------
       
   218 //
       
   219 const TRect& CMMACameraWindow::DrawRect()
       
   220 {
       
   221     return iDrawRect;
       
   222 }
       
   223 
       
   224 
       
   225 // ---------------------------------------------------------------------------
       
   226 // From class MMMADisplayWindow
       
   227 // CMMACameraWindow::WindowSize
       
   228 //
       
   229 // ---------------------------------------------------------------------------
       
   230 //
       
   231 TSize CMMACameraWindow::WindowSize()
       
   232 {
       
   233     return iDrawRect.Size();
       
   234 }
       
   235 
       
   236 
       
   237 // ---------------------------------------------------------------------------
       
   238 // From class MMMADisplayWindow
       
   239 // CMMACameraWindow::SetPosition
       
   240 //
       
   241 // ---------------------------------------------------------------------------
       
   242 //
       
   243 void CMMACameraWindow::SetPosition(const TPoint& aPosition)
       
   244 {
       
   245     // Note: Runs in UI thread only
       
   246     SetDrawRectThread(TRect(aPosition, iDrawRect.Size()));
       
   247 }
       
   248 
       
   249 
       
   250 // ---------------------------------------------------------------------------
       
   251 // From class MMMADisplayWindow
       
   252 // CMMACameraWindow::SetVisible
       
   253 //
       
   254 // ---------------------------------------------------------------------------
       
   255 //
       
   256 void CMMACameraWindow::SetVisible(TBool aVisible, TBool aUseEventServer)
       
   257 {
       
   258     iVisible = aVisible;
       
   259 
       
   260     if (aUseEventServer)
       
   261     {
       
   262         // We are in UI thread now.
       
   263         SetViewFinderVisibility(aVisible);
       
   264     }
       
   265     else
       
   266     {
       
   267         // MMAPI thread
       
   268         if (iDisplay)
       
   269         {
       
   270             if (aVisible)
       
   271             {
       
   272                 iDisplay->UIGetCallback(
       
   273                     *this, CMMACameraWindow::EShowViewFinder);
       
   274             }
       
   275             else
       
   276             {
       
   277                 iDisplay->UIGetCallback(
       
   278                     *this, CMMACameraWindow::EHideViewFinder);
       
   279             }
       
   280         }
       
   281     }
       
   282 }
       
   283 
       
   284 
       
   285 // ---------------------------------------------------------------------------
       
   286 // From class MMMADisplayWindow
       
   287 // CMMACameraWindow::SetWindowRect
       
   288 //
       
   289 // ---------------------------------------------------------------------------
       
   290 //
       
   291 void CMMACameraWindow::SetWindowRect(
       
   292     const TRect& aRect,
       
   293     MMMADisplay::TThreadType aThreadType)
       
   294 {
       
   295     DEBUG_INT2("MMA::CMMACameraWindow::SetWindowRect TL:%d,%d",
       
   296                aRect.iTl.iX, aRect.iTl.iY);
       
   297     DEBUG_INT2("MMA::CMMACameraWindow::SetWindowRect BR:%d,%d",
       
   298                aRect.iBr.iX, aRect.iBr.iY);
       
   299 
       
   300     if (iClientRect != aRect)
       
   301     {
       
   302         iClientRect = aRect;
       
   303 
       
   304         if (aThreadType == MMMADisplay::EUiThread)
       
   305         {
       
   306             ResetViewFinder();
       
   307         }
       
   308         else
       
   309         {
       
   310             iDisplay->UIGetCallback(
       
   311                 *this, CMMACameraWindow::EResetViewFinder);
       
   312         }
       
   313     }
       
   314 
       
   315 
       
   316 }
       
   317 
       
   318 
       
   319 // ---------------------------------------------------------------------------
       
   320 // From class MMMADisplayWindow
       
   321 // CMMACameraWindow::WindowRect
       
   322 //
       
   323 // ---------------------------------------------------------------------------
       
   324 //
       
   325 const TRect& CMMACameraWindow::WindowRect()
       
   326 {
       
   327     return iClientRect;
       
   328 }
       
   329 
       
   330 
       
   331 // ---------------------------------------------------------------------------
       
   332 // From class MMMADisplayWindow
       
   333 // CMMACameraWindow::GetDisplayWindowType
       
   334 //
       
   335 // ---------------------------------------------------------------------------
       
   336 //
       
   337 MMMADisplayWindow::TDisplayWindowType
       
   338 CMMACameraWindow::GetDisplayWindowType() const
       
   339 {
       
   340     return EDisplayWindowTypeIsCamera;
       
   341 }
       
   342 
       
   343 
       
   344 // ---------------------------------------------------------------------------
       
   345 // From class MMMADisplayWindow
       
   346 // CMMACameraWindow::IsVisible
       
   347 //
       
   348 // ---------------------------------------------------------------------------
       
   349 //
       
   350 TBool CMMACameraWindow::IsVisible() const
       
   351 {
       
   352     return iVisible;
       
   353 }
       
   354 
       
   355 
       
   356 // ---------------------------------------------------------------------------
       
   357 // From class MMMADisplayWindow
       
   358 // CMMACameraWindow::ContainerSet
       
   359 //
       
   360 // ---------------------------------------------------------------------------
       
   361 //
       
   362 void CMMACameraWindow::ContainerSet()
       
   363 {
       
   364     // We are in UI thread now
       
   365 
       
   366     // Container was probably not set when
       
   367     // iDisplay was set,
       
   368     // we can now try get the DSA stuff again
       
   369     if (!iUICamera && iDisplay)
       
   370     {
       
   371         // Get a DSA stuff for the new Display
       
   372         iDisplay->UIGetDSAResources(*this, MMMADisplay::EUiThread);
       
   373     }
       
   374 }
       
   375 
       
   376 
       
   377 // ---------------------------------------------------------------------------
       
   378 // From class MMMADisplayWindow
       
   379 // CMMACameraWindow::ContainerDestroyed
       
   380 //
       
   381 // ---------------------------------------------------------------------------
       
   382 //
       
   383 void CMMACameraWindow::ContainerDestroyed()
       
   384 {
       
   385     // We are in UI thread now
       
   386     ReleaseUiResources();
       
   387 }
       
   388 
       
   389 
       
   390 // ---------------------------------------------------------------------------
       
   391 // From class MCameraObserver
       
   392 // CMMACameraWindow::ReserveComplete
       
   393 //
       
   394 // ---------------------------------------------------------------------------
       
   395 //
       
   396 void CMMACameraWindow::ReserveComplete(TInt aError)
       
   397 {
       
   398     DEBUG_INT("MMA::CMMACameraWindow::ReserveComplete %d", aError);
       
   399 
       
   400     if (aError == KErrNone)
       
   401     {
       
   402         // camera will notify completion with PowerOnComplete method.
       
   403         iUICamera->PowerOn();
       
   404     }
       
   405 }
       
   406 
       
   407 
       
   408 // ---------------------------------------------------------------------------
       
   409 // From class MCameraObserver
       
   410 // CMMACameraWindow::PowerOnComplete
       
   411 //
       
   412 // ---------------------------------------------------------------------------
       
   413 //
       
   414 void CMMACameraWindow::PowerOnComplete(TInt aError)
       
   415 {
       
   416     DEBUG_INT("MMA::CMMACameraWindow::PowerOnComplete %d", aError);
       
   417 
       
   418     if (aError == KErrNone)
       
   419     {
       
   420         iCameraPowerOn = ETrue;
       
   421         SetViewFinderVisibility(ETrue);
       
   422     }
       
   423 }
       
   424 
       
   425 
       
   426 // ---------------------------------------------------------------------------
       
   427 // From class MCameraObserver
       
   428 // CMMACameraWindow::ViewFinderFrameReady
       
   429 //
       
   430 // ---------------------------------------------------------------------------
       
   431 //
       
   432 void CMMACameraWindow::ViewFinderFrameReady(CFbsBitmap& /*aFrame*/)
       
   433 {
       
   434     // Empty implementation of the interface method
       
   435     DEBUG("MMA::CMMACameraWindow::ViewFinderFrameReady");
       
   436 }
       
   437 
       
   438 
       
   439 // ---------------------------------------------------------------------------
       
   440 // From class MCameraObserver
       
   441 // CMMACameraWindow::ImageReady
       
   442 //
       
   443 // ---------------------------------------------------------------------------
       
   444 //
       
   445 void CMMACameraWindow::ImageReady(CFbsBitmap* /*aBitmap*/,
       
   446                                   HBufC8* /*aData*/,
       
   447                                   TInt /*aError*/)
       
   448 {
       
   449     // Empty implementation of the interface method
       
   450     DEBUG("MMA::CMMACameraWindow::ImageReady");
       
   451 }
       
   452 
       
   453 
       
   454 // ---------------------------------------------------------------------------
       
   455 // From class MCameraObserver
       
   456 // CMMACameraWindow::FrameBufferReady
       
   457 //
       
   458 // ---------------------------------------------------------------------------
       
   459 //
       
   460 void CMMACameraWindow::FrameBufferReady(MFrameBuffer* /*aFrameBuffer*/,
       
   461                                         TInt /*aError*/)
       
   462 {
       
   463     // Empty implementation of the interface method
       
   464     DEBUG("MMA::CMMACameraWindow::FrameBufferReady");
       
   465 }
       
   466 
       
   467 
       
   468 // ---------------------------------------------------------------------------
       
   469 // From class MDirectScreenAccess.
       
   470 // CMMACameraWindow::AbortNow
       
   471 //
       
   472 // ---------------------------------------------------------------------------
       
   473 //
       
   474 void CMMACameraWindow::AbortNow(
       
   475     RDirectScreenAccess::TTerminationReasons /*aReasons*/)
       
   476 {
       
   477     SetViewFinderVisibility(EFalse);
       
   478 }
       
   479 
       
   480 
       
   481 // ---------------------------------------------------------------------------
       
   482 // From class MDirectScreenAccess.
       
   483 // CMMACameraWindow::Restart
       
   484 //
       
   485 // ---------------------------------------------------------------------------
       
   486 //
       
   487 void CMMACameraWindow::Restart(
       
   488     RDirectScreenAccess::TTerminationReasons /*aReasons*/)
       
   489 {
       
   490     SetViewFinderVisibility(ETrue);
       
   491 }
       
   492 
       
   493 
       
   494 // ---------------------------------------------------------------------------
       
   495 // CMMACameraWindow::CMMACameraWindow
       
   496 // C++ constructor.
       
   497 // ---------------------------------------------------------------------------
       
   498 //
       
   499 CMMACameraWindow::CMMACameraWindow(TInt aCameraHandle):
       
   500         iVisible(EFalse),
       
   501         iStarted(EFalse),
       
   502         iViewFinderVisible(EFalse),
       
   503         iCameraPowerOn(EFalse),
       
   504         iDrawRect(0, 0, 0, 0),
       
   505         iClientRect(0, 0, 0, 0),
       
   506         iCameraHandle(aCameraHandle),
       
   507         iUICamera(NULL),
       
   508         iDisplay(NULL),
       
   509         iStarterTimer(NULL),
       
   510         iDirectAccess(NULL),
       
   511         iErrorIconBitmap(NULL),
       
   512         iErrorIconMaskBitmap(NULL),
       
   513         iRWindowRect(0, 0, 0, 0)
       
   514 {
       
   515 }
       
   516 
       
   517 
       
   518 // ---------------------------------------------------------------------------
       
   519 // CMMACameraWindow::UIStartViewFinder
       
   520 // Creates UI Camera.
       
   521 // This CCamera instance is duplicated from handle given to the constructor.
       
   522 // Have to be called from the thread which UI Camera will be controlled from.
       
   523 // ---------------------------------------------------------------------------
       
   524 //
       
   525 void CMMACameraWindow::UIStartViewFinder(
       
   526     RWsSession &aWs,
       
   527     CWsScreenDevice &aScreenDevice,
       
   528     RWindowBase &aWindow)
       
   529 {
       
   530     DEBUG("MMA::CMMACameraWindow::UIStartViewFinder");
       
   531 
       
   532     iWs = &aWs;
       
   533     iScreenDevice = &aScreenDevice;
       
   534     iWindow = &aWindow;
       
   535 
       
   536     if (!iUICamera)
       
   537     {
       
   538         TRAPD(error, iUICamera =
       
   539                   CCamera::NewDuplicateL(*this, iCameraHandle));
       
   540 
       
   541         DEBUG_INT(
       
   542             "MMA::CMMACameraWindow::UIStartViewFinder - NewDuplicateL %d",
       
   543             error);
       
   544 
       
   545         if (error == KErrNone)
       
   546         {
       
   547             iUICamera->Reserve();
       
   548         }
       
   549     }
       
   550 }
       
   551 
       
   552 
       
   553 // ---------------------------------------------------------------------------
       
   554 // CMMACameraWindow::SetViewFinderVisibility
       
   555 // If UI Camera have been created, it starts/hides the DirectViewFinder.
       
   556 // Have to be called from UI thread in which iUICamera instance was created.
       
   557 // ---------------------------------------------------------------------------
       
   558 //
       
   559 void CMMACameraWindow::SetViewFinderVisibility(TBool aVisible)
       
   560 {
       
   561     DEBUG_INT("MMA::CMMACameraWindow::SetViewFinderVisibility - %d",
       
   562               aVisible);
       
   563 
       
   564     if (!iUICamera || !iCameraPowerOn || iViewFinderVisible == aVisible)
       
   565     {
       
   566         return;
       
   567     }
       
   568 
       
   569     if (aVisible)
       
   570     {
       
   571         // Viewfinder is going to start
       
   572         if (!iVisible || !iStarted)
       
   573         {
       
   574             return;
       
   575         }
       
   576 
       
   577         iViewFinderVisible = ETrue;
       
   578 
       
   579         if (!iStarterTimer)
       
   580         {
       
   581             // If starter timer haven't been created yet, create an instance
       
   582             TRAPD(
       
   583                 timerErr,
       
   584                 iStarterTimer = CPeriodic::NewL(CActive::EPriorityIdle));
       
   585 
       
   586             if (timerErr != KErrNone)
       
   587             {
       
   588                 DEBUG_INT(
       
   589                     "MMA::CMMACameraWindow::SetViewFinderVisibility - timer error = %d",
       
   590                     timerErr);
       
   591                 __ASSERT_DEBUG(EFalse, User::Invariant());
       
   592             }
       
   593         }
       
   594 
       
   595         if (!iStarterTimer->IsActive())
       
   596         {
       
   597             iStarterTimer->Start(
       
   598                 KStarterTimeout,
       
   599                 0,
       
   600                 TCallBack(StarterTimerCallback, this));
       
   601         }
       
   602     }
       
   603     else
       
   604     {
       
   605         // Viewfinder is going to be cancelled
       
   606         DEBUG(
       
   607             "MMA::CMMACameraWindow::SetViewFinderVisibility - Stopping VF");
       
   608 
       
   609         if (iStarterTimer && iStarterTimer->IsActive())
       
   610         {
       
   611             // Cancel the running starter timer
       
   612             iStarterTimer->Cancel();
       
   613         }
       
   614 
       
   615         if (iUICamera->ViewFinderActive())
       
   616         {
       
   617             iUICamera->StopViewFinder();
       
   618         }
       
   619         if (iDirectAccess->IsActive())
       
   620         {
       
   621             iDirectAccess->Cancel();
       
   622         }
       
   623 
       
   624         iViewFinderVisible = EFalse;
       
   625     }
       
   626 }
       
   627 
       
   628 
       
   629 // ---------------------------------------------------------------------------
       
   630 // CMMACameraWindow::StarterTimerCallback
       
   631 // Executed at the expiry of the iStartedTimer.
       
   632 // ---------------------------------------------------------------------------
       
   633 //
       
   634 TInt CMMACameraWindow::StarterTimerCallback(TAny* aThis)
       
   635 {
       
   636     CMMACameraWindow* self = static_cast<CMMACameraWindow*>(aThis);
       
   637     ASSERT(self);
       
   638 
       
   639     self->StartViewFinder();
       
   640 
       
   641     // We don't want to run the callback again
       
   642     return EFalse;
       
   643 }
       
   644 
       
   645 
       
   646 // ---------------------------------------------------------------------------
       
   647 // From class MMMADisplayWindow
       
   648 // CMMACameraWindow::SetRWindowRect
       
   649 //
       
   650 // ---------------------------------------------------------------------------
       
   651 //
       
   652 void CMMACameraWindow::SetRWindowRect(const TRect& aRect,
       
   653                                       MMMADisplay::TThreadType aThreadType)
       
   654 {
       
   655     DEBUG_INT2("MID::CMMACameraWindow::SetRWindowRect TL %d %d",
       
   656                aRect.iTl.iX, aRect.iTl.iY);
       
   657     DEBUG_INT2("MID::CMMACameraWindow::SetRWindowRect BR %d %d",
       
   658                aRect.iBr.iX, aRect.iBr.iY);
       
   659 
       
   660     iRWindowRect = aRect;
       
   661 
       
   662     if (MMMADisplay::EMmaThread == aThreadType)
       
   663     {
       
   664         if (iDisplay)
       
   665         {
       
   666             iDisplay->UIGetCallback(*this,
       
   667                                     CMMACameraWindow::EResetViewFinder);
       
   668         }
       
   669     }
       
   670     else if (MMMADisplay::EUiThread == aThreadType)
       
   671     {
       
   672         ResetViewFinder();
       
   673     }
       
   674 }
       
   675 
       
   676 
       
   677 // ---------------------------------------------------------------------------
       
   678 // CMMACameraWindow::StartViewFinder
       
   679 // Starts viewfinder.
       
   680 // ---------------------------------------------------------------------------
       
   681 //
       
   682 void CMMACameraWindow::StartViewFinder()
       
   683 {
       
   684     DEBUG(" < StartViewFinder");
       
   685 
       
   686     ASSERT(iUICamera);
       
   687     ASSERT(iCameraPowerOn);
       
   688     ASSERT(iStarted);
       
   689 
       
   690     iStarterTimer->Cancel();
       
   691 
       
   692     // align client rect to RWindow, viewfinder
       
   693     // display co-ordinates is w.r.t to RWindow
       
   694     TRect relativeClientRect;
       
   695     relativeClientRect = iClientRect;
       
   696     relativeClientRect.Move(-iRWindowRect.iTl);
       
   697 
       
   698     // Set the drawing area
       
   699     TRect drawRect(iDrawRect);
       
   700     drawRect.Move(relativeClientRect.iTl);
       
   701 
       
   702     DEBUG_INT2(
       
   703         "MMA::CMMACameraWindow::StartViewFinder - Starting VF TL:%d,%d",
       
   704         drawRect.iTl.iX,
       
   705         drawRect.iTl.iY);
       
   706     DEBUG_INT2(
       
   707         "MMA::CMMACameraWindow::StartViewFinder - Starting VF BR:%d,%d",
       
   708         drawRect.iBr.iX,
       
   709         drawRect.iBr.iY);
       
   710 
       
   711     TRAPD(vfError, iUICamera->StartViewFinderDirectL(
       
   712               *iWs, *iScreenDevice, *iWindow, drawRect));
       
   713 
       
   714     if (vfError == KErrNone)
       
   715     {
       
   716         DEBUG("MMA::CMMACameraWindow::StartViewFinder - Start OK");
       
   717     }
       
   718     else
       
   719     {
       
   720         DEBUG_INT(
       
   721             "MMA::CMMACameraWindow::StartViewFinder()  - \
       
   722 StartViewFinderDirectL error=%d", vfError);
       
   723 
       
   724         TRAP_IGNORE(DrawViewFinderErrorL(vfError, drawRect));
       
   725     }
       
   726 
       
   727     DEBUG(" > StartViewFinder");
       
   728 }
       
   729 
       
   730 
       
   731 // ---------------------------------------------------------------------------
       
   732 // CMMACameraWindow::DrawViewFinderError()
       
   733 // Draws the error message to specified area.
       
   734 // Used in cases when viewfinder is unable to start.
       
   735 // ---------------------------------------------------------------------------
       
   736 //
       
   737 void CMMACameraWindow::DrawViewFinderErrorL(
       
   738     const TInt /*aError*/,
       
   739     const TRect& aDrawRect)
       
   740 {
       
   741 
       
   742     ASSERT(iDirectAccess);
       
   743     TInt dcError = KErrNone;
       
   744     if (!iDirectAccess->IsActive())
       
   745     {
       
   746         TRAP(dcError, iDirectAccess->StartL());
       
   747     }
       
   748 
       
   749     TRect drawRect(aDrawRect);
       
   750 
       
   751     if (dcError == KErrNone)
       
   752     {
       
   753         drawRect.Intersection(iClientRect);
       
   754         drawRect.Move(-iWindow->AbsPosition());
       
   755 
       
   756         CFbsBitGc* directGc = iDirectAccess->Gc();
       
   757         directGc->SetClippingRect(drawRect);
       
   758         directGc->SetBrushColor(TRgb(128,128,128));
       
   759         directGc->SetPenColor(TRgb(128,0,0));
       
   760         directGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   761         directGc->SetPenStyle(CGraphicsContext::ESolidPen);
       
   762         directGc->SetDrawMode(CGraphicsContext::EDrawModeWriteAlpha);
       
   763         directGc->DrawRect(drawRect);
       
   764 
       
   765         if (!iErrorIconBitmap || !iErrorIconMaskBitmap)
       
   766         {
       
   767             if (iErrorIconBitmap)
       
   768             {
       
   769                 delete iErrorIconBitmap;
       
   770                 iErrorIconBitmap = NULL;
       
   771             }
       
   772 
       
   773             if (iErrorIconMaskBitmap)
       
   774             {
       
   775                 delete iErrorIconMaskBitmap;
       
   776                 iErrorIconMaskBitmap = NULL;
       
   777             }
       
   778 
       
   779             AknsUtils::CreateIconL(
       
   780                 AknsUtils::SkinInstance(),
       
   781                 KAknsIIDQgnIndiCam4Camera,
       
   782                 iErrorIconBitmap,
       
   783                 iErrorIconMaskBitmap,
       
   784                 KCameraAppBitmapFile,
       
   785                 EMbmCameraappQgn_indi_cam4_camera,
       
   786                 EMbmCameraappQgn_indi_cam4_camera_mask
       
   787             );
       
   788         }
       
   789 
       
   790         //TRect iconRect
       
   791         drawRect.iTl.iX += KErrorIconMargin;
       
   792         drawRect.iTl.iY += KErrorIconMargin;
       
   793         drawRect.iBr.iX -= KErrorIconMargin;
       
   794         drawRect.iBr.iY -= KErrorIconMargin;
       
   795 
       
   796         if (iErrorIconBitmap->SizeInPixels() != drawRect.Size())
       
   797         {
       
   798             AknIconUtils::SetSize(iErrorIconBitmap, drawRect.Size());
       
   799             AknIconUtils::SetSize(iErrorIconMaskBitmap, drawRect.Size());
       
   800         }
       
   801 
       
   802         directGc->BitBltMasked(
       
   803             drawRect.iTl, iErrorIconBitmap,
       
   804             TRect(iErrorIconBitmap->SizeInPixels()),
       
   805             iErrorIconMaskBitmap, EFalse);
       
   806 
       
   807         iDirectAccess->ScreenDevice()->Update();
       
   808     }
       
   809 
       
   810 }
       
   811 
       
   812 
       
   813 // ---------------------------------------------------------------------------
       
   814 // CMMACameraWindow::ReleaseUiResources()
       
   815 // Stops the DirectViewFinder and deletes UI Camera instance
       
   816 // Have to be called from UI thread in which UI Camera
       
   817 // have been created before the CMMACameraWindow instance
       
   818 // is deleted.
       
   819 // ---------------------------------------------------------------------------
       
   820 //
       
   821 void CMMACameraWindow::ReleaseUiResources()
       
   822 {
       
   823     if (iUICamera)
       
   824     {
       
   825         SetViewFinderVisibility(EFalse);
       
   826         // iStarterTimer is cancelled by previous call
       
   827         // it can be deleted now
       
   828         delete iStarterTimer;
       
   829         iStarterTimer = NULL;
       
   830         iUICamera->Release();
       
   831         delete iUICamera;
       
   832         iUICamera = NULL;
       
   833         iCameraPowerOn = EFalse;
       
   834         iDirectAccess->Cancel();
       
   835         delete iDirectAccess;
       
   836         iDirectAccess = NULL;
       
   837         delete iErrorIconBitmap;
       
   838         iErrorIconBitmap = NULL;
       
   839         delete iErrorIconMaskBitmap;
       
   840         iErrorIconMaskBitmap = NULL;
       
   841     }
       
   842 }
       
   843 
       
   844 
       
   845 // ---------------------------------------------------------------------------
       
   846 // CMMACameraWindow::ResetViewFinder
       
   847 // Resets (stops and starts) viewfinder
       
   848 // ---------------------------------------------------------------------------
       
   849 //
       
   850 void CMMACameraWindow::ResetViewFinder()
       
   851 {
       
   852 
       
   853     if (iStarterTimer && !iStarterTimer->IsActive() && iStarted)
       
   854     {
       
   855         SetViewFinderVisibility(EFalse);
       
   856         SetViewFinderVisibility(ETrue);
       
   857     }
       
   858 }
       
   859 
       
   860 
       
   861 // ---------------------------------------------------------------------------
       
   862 // CMMACameraWindow::Destroy
       
   863 // Deletes this object.
       
   864 // ---------------------------------------------------------------------------
       
   865 //
       
   866 void CMMACameraWindow::Destroy()
       
   867 {
       
   868     // Delete itself
       
   869     delete this;
       
   870 }
       
   871 
       
   872 
       
   873 // ---------------------------------------------------------------------------
       
   874 // From class MUiEventConsumer.
       
   875 // CMMACameraWindow::MdcDSAResourcesCallback
       
   876 // Callback to iDisplay->UIGetDSAResources().
       
   877 // Invoked asynchronously from UI Event Server thread.
       
   878 // ---------------------------------------------------------------------------
       
   879 //
       
   880 void CMMACameraWindow::MdcDSAResourcesCallback(
       
   881     RWsSession &aWs,
       
   882     CWsScreenDevice &aScreenDevice,
       
   883     RWindowBase &aWindow)
       
   884 {
       
   885     TRAPD(error, iDirectAccess = CDirectScreenAccess::NewL(aWs,
       
   886                                  aScreenDevice,
       
   887                                  aWindow,
       
   888                                  *this));
       
   889     DEBUG_INT("MMA::CMMACameraWindow::MdcDSAResourcesCallback, error = %d", error);
       
   890     if (KErrNone != error)
       
   891     {
       
   892         return;
       
   893     }
       
   894     this->UIStartViewFinder(aWs, aScreenDevice, aWindow);
       
   895 }
       
   896 
       
   897 
       
   898 // ---------------------------------------------------------------------------
       
   899 // From class MUiEventConsumer.
       
   900 // CMMACameraWindow::MdcUICallback
       
   901 // Callback to iDisplay->UIGetCallback().
       
   902 // Invoked asynchronously from UI Event Server thread.
       
   903 // ---------------------------------------------------------------------------
       
   904 //
       
   905 void CMMACameraWindow::MdcUICallback(TInt aCallbackId)
       
   906 {
       
   907     DEBUG("MMA::CMMACameraWindow::MdcUICallback");
       
   908 
       
   909     switch (aCallbackId)
       
   910     {
       
   911     case EDeleteViewFinder:
       
   912         ReleaseUiResources();
       
   913         break;
       
   914     case EHideViewFinder:
       
   915         SetViewFinderVisibility(EFalse);
       
   916         break;
       
   917     case EShowViewFinder:
       
   918         SetViewFinderVisibility(ETrue);
       
   919         break;
       
   920     case EResetViewFinder:
       
   921         ResetViewFinder();
       
   922         break;
       
   923     case EDestroyWindow:
       
   924         Destroy();
       
   925         break;
       
   926     }
       
   927 }
       
   928 
       
   929 
       
   930 //  END OF FILE