javauis/mmapi_akn/baseline/src.nga/cmmacamerawindow.cpp
branchRCL_3
changeset 18 9ac0a0a7da70
child 24 6c158198356e
equal deleted inserted replaced
17:0fd27995241b 18:9ac0a0a7da70
       
     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 // From class MMMADisplayWindow
       
   214 // CMMACameraWindow::DrawRect
       
   215 //
       
   216 // ---------------------------------------------------------------------------
       
   217 //
       
   218 const TRect& CMMACameraWindow::DrawRect()
       
   219 {
       
   220     return iDrawRect;
       
   221 }
       
   222 
       
   223 
       
   224 // ---------------------------------------------------------------------------
       
   225 // From class MMMADisplayWindow
       
   226 // CMMACameraWindow::WindowSize
       
   227 //
       
   228 // ---------------------------------------------------------------------------
       
   229 //
       
   230 TSize CMMACameraWindow::WindowSize()
       
   231 {
       
   232     return iDrawRect.Size();
       
   233 }
       
   234 
       
   235 
       
   236 // ---------------------------------------------------------------------------
       
   237 // From class MMMADisplayWindow
       
   238 // CMMACameraWindow::SetPosition
       
   239 //
       
   240 // ---------------------------------------------------------------------------
       
   241 //
       
   242 void CMMACameraWindow::SetPosition(const TPoint& aPosition)
       
   243 {
       
   244     // Note: Runs in UI thread only
       
   245     SetDrawRectThread(TRect(aPosition, iDrawRect.Size()));
       
   246 }
       
   247 
       
   248 
       
   249 // ---------------------------------------------------------------------------
       
   250 // From class MMMADisplayWindow
       
   251 // CMMACameraWindow::SetVisible
       
   252 //
       
   253 // ---------------------------------------------------------------------------
       
   254 //
       
   255 void CMMACameraWindow::SetVisible(TBool aVisible, TBool aUseEventServer)
       
   256 {
       
   257     iVisible = aVisible;
       
   258 
       
   259     if (aUseEventServer)
       
   260     {
       
   261         // We are in UI thread now.
       
   262         SetViewFinderVisibility(aVisible);
       
   263     }
       
   264     else
       
   265     {
       
   266         // MMAPI thread
       
   267         if (iDisplay)
       
   268         {
       
   269             if (aVisible)
       
   270             {
       
   271                 iDisplay->UIGetCallback(
       
   272                     *this, CMMACameraWindow::EShowViewFinder);
       
   273             }
       
   274             else
       
   275             {
       
   276                 iDisplay->UIGetCallback(
       
   277                     *this, CMMACameraWindow::EHideViewFinder);
       
   278             }
       
   279         }
       
   280     }
       
   281 }
       
   282 
       
   283 
       
   284 // ---------------------------------------------------------------------------
       
   285 // From class MMMADisplayWindow
       
   286 // CMMACameraWindow::SetWindowRect
       
   287 //
       
   288 // ---------------------------------------------------------------------------
       
   289 //
       
   290 void CMMACameraWindow::SetWindowRect(
       
   291     const TRect& aRect,
       
   292     MMMADisplay::TThreadType aThreadType)
       
   293 {
       
   294     DEBUG_INT2("MMA::CMMACameraWindow::SetWindowRect TL:%d,%d",
       
   295                aRect.iTl.iX, aRect.iTl.iY);
       
   296     DEBUG_INT2("MMA::CMMACameraWindow::SetWindowRect BR:%d,%d",
       
   297                aRect.iBr.iX, aRect.iBr.iY);
       
   298 
       
   299     if (iClientRect != aRect)
       
   300     {
       
   301         iClientRect = aRect;
       
   302 
       
   303         if (aThreadType == MMMADisplay::EUiThread)
       
   304         {
       
   305             ResetViewFinder();
       
   306         }
       
   307         else
       
   308         {
       
   309             iDisplay->UIGetCallback(
       
   310                 *this, CMMACameraWindow::EResetViewFinder);
       
   311         }
       
   312     }
       
   313 }
       
   314 
       
   315 
       
   316 // ---------------------------------------------------------------------------
       
   317 // From class MMMADisplayWindow
       
   318 // CMMACameraWindow::WindowRect
       
   319 //
       
   320 // ---------------------------------------------------------------------------
       
   321 //
       
   322 const TRect& CMMACameraWindow::WindowRect()
       
   323 {
       
   324     return iClientRect;
       
   325 }
       
   326 
       
   327 
       
   328 // ---------------------------------------------------------------------------
       
   329 // From class MMMADisplayWindow
       
   330 // CMMACameraWindow::GetDisplayWindowType
       
   331 //
       
   332 // ---------------------------------------------------------------------------
       
   333 //
       
   334 MMMADisplayWindow::TDisplayWindowType
       
   335 CMMACameraWindow::GetDisplayWindowType() const
       
   336 {
       
   337     return EDisplayWindowTypeIsCamera;
       
   338 }
       
   339 
       
   340 
       
   341 // ---------------------------------------------------------------------------
       
   342 // From class MMMADisplayWindow
       
   343 // CMMACameraWindow::IsVisible
       
   344 //
       
   345 // ---------------------------------------------------------------------------
       
   346 //
       
   347 TBool CMMACameraWindow::IsVisible() const
       
   348 {
       
   349     return iVisible;
       
   350 }
       
   351 
       
   352 
       
   353 // ---------------------------------------------------------------------------
       
   354 // From class MMMADisplayWindow
       
   355 // CMMACameraWindow::ContainerSet
       
   356 //
       
   357 // ---------------------------------------------------------------------------
       
   358 //
       
   359 void CMMACameraWindow::ContainerSet()
       
   360 {
       
   361     // We are in UI thread now
       
   362 
       
   363     // Container was probably not set when
       
   364     // iDisplay was set,
       
   365     // we can now try get the DSA stuff again
       
   366     if (!iUICamera && iDisplay)
       
   367     {
       
   368         // Get a DSA stuff for the new Display
       
   369         iDisplay->UIGetDSAResources(*this, MMMADisplay::EUiThread);
       
   370     }
       
   371 }
       
   372 
       
   373 
       
   374 // ---------------------------------------------------------------------------
       
   375 // From class MMMADisplayWindow
       
   376 // CMMACameraWindow::ContainerDestroyed
       
   377 //
       
   378 // ---------------------------------------------------------------------------
       
   379 //
       
   380 void CMMACameraWindow::ContainerDestroyed()
       
   381 {
       
   382     // We are in UI thread now
       
   383     ReleaseUiResources();
       
   384 }
       
   385 
       
   386 
       
   387 // ---------------------------------------------------------------------------
       
   388 // From class MCameraObserver
       
   389 // CMMACameraWindow::ReserveComplete
       
   390 //
       
   391 // ---------------------------------------------------------------------------
       
   392 //
       
   393 void CMMACameraWindow::ReserveComplete(TInt aError)
       
   394 {
       
   395     DEBUG_INT("MMA::CMMACameraWindow::ReserveComplete %d", aError);
       
   396 
       
   397     if (aError == KErrNone)
       
   398     {
       
   399         // camera will notify completion with PowerOnComplete method.
       
   400         iUICamera->PowerOn();
       
   401     }
       
   402 }
       
   403 
       
   404 
       
   405 // ---------------------------------------------------------------------------
       
   406 // From class MCameraObserver
       
   407 // CMMACameraWindow::PowerOnComplete
       
   408 //
       
   409 // ---------------------------------------------------------------------------
       
   410 //
       
   411 void CMMACameraWindow::PowerOnComplete(TInt aError)
       
   412 {
       
   413     DEBUG_INT("MMA::CMMACameraWindow::PowerOnComplete %d", aError);
       
   414 
       
   415     if (aError == KErrNone)
       
   416     {
       
   417         iCameraPowerOn = ETrue;
       
   418         SetViewFinderVisibility(ETrue);
       
   419     }
       
   420 }
       
   421 
       
   422 
       
   423 // ---------------------------------------------------------------------------
       
   424 // From class MCameraObserver
       
   425 // CMMACameraWindow::ViewFinderFrameReady
       
   426 //
       
   427 // ---------------------------------------------------------------------------
       
   428 //
       
   429 void CMMACameraWindow::ViewFinderFrameReady(CFbsBitmap& /*aFrame*/)
       
   430 {
       
   431     // Empty implementation of the interface method
       
   432     DEBUG("MMA::CMMACameraWindow::ViewFinderFrameReady");
       
   433 }
       
   434 
       
   435 
       
   436 // ---------------------------------------------------------------------------
       
   437 // From class MCameraObserver
       
   438 // CMMACameraWindow::ImageReady
       
   439 //
       
   440 // ---------------------------------------------------------------------------
       
   441 //
       
   442 void CMMACameraWindow::ImageReady(CFbsBitmap* /*aBitmap*/,
       
   443                                   HBufC8* /*aData*/,
       
   444                                   TInt /*aError*/)
       
   445 {
       
   446     // Empty implementation of the interface method
       
   447     DEBUG("MMA::CMMACameraWindow::ImageReady");
       
   448 }
       
   449 
       
   450 
       
   451 // ---------------------------------------------------------------------------
       
   452 // From class MCameraObserver
       
   453 // CMMACameraWindow::FrameBufferReady
       
   454 //
       
   455 // ---------------------------------------------------------------------------
       
   456 //
       
   457 void CMMACameraWindow::FrameBufferReady(MFrameBuffer* /*aFrameBuffer*/,
       
   458                                         TInt /*aError*/)
       
   459 {
       
   460     // Empty implementation of the interface method
       
   461     DEBUG("MMA::CMMACameraWindow::FrameBufferReady");
       
   462 }
       
   463 
       
   464 
       
   465 // ---------------------------------------------------------------------------
       
   466 // From class MDirectScreenAccess.
       
   467 // CMMACameraWindow::AbortNow
       
   468 //
       
   469 // ---------------------------------------------------------------------------
       
   470 //
       
   471 void CMMACameraWindow::AbortNow(
       
   472     RDirectScreenAccess::TTerminationReasons /*aReasons*/)
       
   473 {
       
   474     SetViewFinderVisibility(EFalse);
       
   475 }
       
   476 
       
   477 
       
   478 // ---------------------------------------------------------------------------
       
   479 // From class MDirectScreenAccess.
       
   480 // CMMACameraWindow::Restart
       
   481 //
       
   482 // ---------------------------------------------------------------------------
       
   483 //
       
   484 void CMMACameraWindow::Restart(
       
   485     RDirectScreenAccess::TTerminationReasons /*aReasons*/)
       
   486 {
       
   487     SetViewFinderVisibility(ETrue);
       
   488 }
       
   489 
       
   490 
       
   491 // ---------------------------------------------------------------------------
       
   492 // CMMACameraWindow::CMMACameraWindow
       
   493 // C++ constructor.
       
   494 // ---------------------------------------------------------------------------
       
   495 //
       
   496 CMMACameraWindow::CMMACameraWindow(TInt aCameraHandle):
       
   497         iVisible(EFalse),
       
   498         iStarted(EFalse),
       
   499         iViewFinderVisible(EFalse),
       
   500         iCameraPowerOn(EFalse),
       
   501         iDrawRect(0, 0, 0, 0),
       
   502         iClientRect(0, 0, 0, 0),
       
   503         iCameraHandle(aCameraHandle),
       
   504         iUICamera(NULL),
       
   505         iDisplay(NULL),
       
   506         iStarterTimer(NULL),
       
   507         iDirectAccess(NULL),
       
   508         iErrorIconBitmap(NULL),
       
   509         iErrorIconMaskBitmap(NULL),
       
   510         iRWindowRect(0, 0, 0, 0)
       
   511 {
       
   512 }
       
   513 
       
   514 
       
   515 // ---------------------------------------------------------------------------
       
   516 // CMMACameraWindow::UIStartViewFinder
       
   517 // Creates UI Camera.
       
   518 // This CCamera instance is duplicated from handle given to the constructor.
       
   519 // Have to be called from the thread which UI Camera will be controlled from.
       
   520 // ---------------------------------------------------------------------------
       
   521 //
       
   522 void CMMACameraWindow::UIStartViewFinder(
       
   523     RWsSession &aWs,
       
   524     CWsScreenDevice &aScreenDevice,
       
   525     RWindowBase &aWindow)
       
   526 {
       
   527     DEBUG("MMA::CMMACameraWindow::UIStartViewFinder");
       
   528 
       
   529     iWs = &aWs;
       
   530     iScreenDevice = &aScreenDevice;
       
   531     iWindow = &aWindow;
       
   532 
       
   533     if (!iUICamera)
       
   534     {
       
   535         TRAPD(error, iUICamera =
       
   536                   CCamera::NewDuplicateL(*this, iCameraHandle));
       
   537 
       
   538         DEBUG_INT(
       
   539             "MMA::CMMACameraWindow::UIStartViewFinder - NewDuplicateL %d",
       
   540             error);
       
   541 
       
   542         if (error == KErrNone)
       
   543         {
       
   544             iUICamera->Reserve();
       
   545         }
       
   546     }
       
   547 }
       
   548 
       
   549 
       
   550 // ---------------------------------------------------------------------------
       
   551 // CMMACameraWindow::SetViewFinderVisibility
       
   552 // If UI Camera have been created, it starts/hides the DirectViewFinder.
       
   553 // Have to be called from UI thread in which iUICamera instance was created.
       
   554 // ---------------------------------------------------------------------------
       
   555 //
       
   556 void CMMACameraWindow::SetViewFinderVisibility(TBool aVisible)
       
   557 {
       
   558     DEBUG_INT("MMA::CMMACameraWindow::SetViewFinderVisibility - %d",
       
   559               aVisible);
       
   560 
       
   561     if (!iUICamera || !iCameraPowerOn || iViewFinderVisible == aVisible)
       
   562     {
       
   563         return;
       
   564     }
       
   565 
       
   566     if (aVisible)
       
   567     {
       
   568         // Viewfinder is going to start
       
   569         if (!iVisible || !iStarted)
       
   570         {
       
   571             return;
       
   572         }
       
   573 
       
   574         iViewFinderVisible = ETrue;
       
   575 
       
   576         if (!iStarterTimer)
       
   577         {
       
   578             // If starter timer haven't been created yet, create an instance
       
   579             TRAPD(
       
   580                 timerErr,
       
   581                 iStarterTimer = CPeriodic::NewL(CActive::EPriorityIdle));
       
   582 
       
   583             if (timerErr != KErrNone)
       
   584             {
       
   585                 DEBUG_INT(
       
   586                     "MMA::CMMACameraWindow::SetViewFinderVisibility - timer error = %d",
       
   587                     timerErr);
       
   588                 __ASSERT_DEBUG(EFalse, User::Invariant());
       
   589             }
       
   590         }
       
   591 
       
   592         if (!iStarterTimer->IsActive())
       
   593         {
       
   594             iStarterTimer->Start(
       
   595                 KStarterTimeout,
       
   596                 0,
       
   597                 TCallBack(StarterTimerCallback, this));
       
   598         }
       
   599     }
       
   600     else
       
   601     {
       
   602         // Viewfinder is going to be cancelled
       
   603         DEBUG(
       
   604             "MMA::CMMACameraWindow::SetViewFinderVisibility - Stopping VF");
       
   605 
       
   606         if (iStarterTimer && iStarterTimer->IsActive())
       
   607         {
       
   608             // Cancel the running starter timer
       
   609             iStarterTimer->Cancel();
       
   610         }
       
   611 
       
   612         if (iUICamera->ViewFinderActive())
       
   613         {
       
   614             iUICamera->StopViewFinder();
       
   615         }
       
   616 
       
   617         iViewFinderVisible = EFalse;
       
   618     }
       
   619 }
       
   620 
       
   621 
       
   622 // ---------------------------------------------------------------------------
       
   623 // CMMACameraWindow::StarterTimerCallback
       
   624 // Executed at the expiry of the iStartedTimer.
       
   625 // ---------------------------------------------------------------------------
       
   626 //
       
   627 TInt CMMACameraWindow::StarterTimerCallback(TAny* aThis)
       
   628 {
       
   629     CMMACameraWindow* self = static_cast<CMMACameraWindow*>(aThis);
       
   630     ASSERT(self);
       
   631 
       
   632     self->StartViewFinder();
       
   633 
       
   634     // We don't want to run the callback again
       
   635     return EFalse;
       
   636 }
       
   637 
       
   638 
       
   639 // ---------------------------------------------------------------------------
       
   640 // From class MMMADisplayWindow
       
   641 // CMMACameraWindow::SetRWindowRect
       
   642 //
       
   643 // ---------------------------------------------------------------------------
       
   644 //
       
   645 void CMMACameraWindow::SetRWindowRect(const TRect& aRect,
       
   646                                       MMMADisplay::TThreadType aThreadType)
       
   647 {
       
   648     DEBUG_INT2("MID::CMMACameraWindow::SetRWindowRect TL %d %d",
       
   649                aRect.iTl.iX, aRect.iTl.iY);
       
   650     DEBUG_INT2("MID::CMMACameraWindow::SetRWindowRect BR %d %d",
       
   651                aRect.iBr.iX, aRect.iBr.iY);
       
   652 
       
   653     iRWindowRect = aRect;
       
   654 
       
   655     if (MMMADisplay::EMmaThread == aThreadType)
       
   656     {
       
   657         if (iDisplay)
       
   658         {
       
   659             iDisplay->UIGetCallback(*this,
       
   660                                     CMMACameraWindow::EResetViewFinder);
       
   661         }
       
   662     }
       
   663     else if (MMMADisplay::EUiThread == aThreadType)
       
   664     {
       
   665         ResetViewFinder();
       
   666     }
       
   667 }
       
   668 
       
   669 
       
   670 // ---------------------------------------------------------------------------
       
   671 // CMMACameraWindow::StartViewFinder
       
   672 // Starts viewfinder.
       
   673 // ---------------------------------------------------------------------------
       
   674 //
       
   675 void CMMACameraWindow::StartViewFinder()
       
   676 {
       
   677     DEBUG(" < StartViewFinder");
       
   678 
       
   679     ASSERT(iUICamera);
       
   680     ASSERT(iCameraPowerOn);
       
   681     ASSERT(iStarted);
       
   682 
       
   683     iStarterTimer->Cancel();
       
   684 
       
   685     // align client rect to RWindow, viewfinder
       
   686     // display co-ordinates is w.r.t to RWindow
       
   687     TRect relativeClientRect;
       
   688     relativeClientRect = iClientRect;
       
   689     relativeClientRect.Move(-iRWindowRect.iTl);
       
   690 
       
   691     // Set the drawing area
       
   692     TRect drawRect(iDrawRect);
       
   693     drawRect.Move(relativeClientRect.iTl);
       
   694 
       
   695     DEBUG_INT2(
       
   696         "MMA::CMMACameraWindow::StartViewFinder - Starting VF TL:%d,%d",
       
   697         drawRect.iTl.iX,
       
   698         drawRect.iTl.iY);
       
   699     DEBUG_INT2(
       
   700         "MMA::CMMACameraWindow::StartViewFinder - Starting VF BR:%d,%d",
       
   701         drawRect.iBr.iX,
       
   702         drawRect.iBr.iY);
       
   703 
       
   704     TRAPD(vfError, iUICamera->StartViewFinderDirectL(
       
   705               *iWs, *iScreenDevice, *iWindow, drawRect));
       
   706 
       
   707     if (vfError == KErrNone)
       
   708     {
       
   709         DEBUG("MMA::CMMACameraWindow::StartViewFinder - Start OK");
       
   710     }
       
   711     else
       
   712     {
       
   713         DEBUG_INT("MMA::CMMACameraWindow::StartViewFinder()  - \
       
   714             StartViewFinderDirectL error=%d", vfError);
       
   715 
       
   716         TRAPD(error, DrawViewFinderErrorL(vfError, drawRect));
       
   717         if (KErrNone != error)
       
   718         {
       
   719             DEBUG_INT("MMA::CMMACameraWindow::StartViewFinder, \
       
   720                 DrawViewFinderErrorL error = %d", error);
       
   721         }
       
   722     }
       
   723 
       
   724     DEBUG(" > StartViewFinder");
       
   725 }
       
   726 
       
   727 
       
   728 // ---------------------------------------------------------------------------
       
   729 // CMMACameraWindow::DrawViewFinderError()
       
   730 // Draws the error message to specified area.
       
   731 // Used in cases when viewfinder is unable to start.
       
   732 // ---------------------------------------------------------------------------
       
   733 //
       
   734 void CMMACameraWindow::DrawViewFinderErrorL(
       
   735     const TInt /*aError*/,
       
   736     const TRect& aDrawRect)
       
   737 {
       
   738     if (!iDirectAccess)
       
   739     {
       
   740         if (!iWs || !iScreenDevice || !iWindow) return;
       
   741 
       
   742         DEBUG("MMA::CMMACameraWindow::DrawViewFinderErrorL - \
       
   743             Instantiating CDirectScreenAccess");
       
   744         iDirectAccess = CDirectScreenAccess::NewL(*iWs,
       
   745                                      *iScreenDevice,
       
   746                                      *iWindow,
       
   747                                      *this);
       
   748     }
       
   749 
       
   750     TInt dcError = KErrNone;
       
   751     if (!iDirectAccess->IsActive())
       
   752     {
       
   753         TRAP(dcError, iDirectAccess->StartL());
       
   754     }
       
   755 
       
   756     TRect drawRect(aDrawRect);
       
   757 
       
   758     if (dcError == KErrNone)
       
   759     {
       
   760         drawRect.Intersection(iClientRect);
       
   761         drawRect.Move(-iWindow->AbsPosition());
       
   762 
       
   763         CFbsBitGc* directGc = iDirectAccess->Gc();
       
   764         directGc->SetClippingRect(drawRect);
       
   765         directGc->SetBrushColor(TRgb(128,128,128));
       
   766         directGc->SetPenColor(TRgb(128,0,0));
       
   767         directGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   768         directGc->SetPenStyle(CGraphicsContext::ESolidPen);
       
   769         directGc->SetDrawMode(CGraphicsContext::EDrawModeWriteAlpha);
       
   770         directGc->DrawRect(drawRect);
       
   771 
       
   772         if (!iErrorIconBitmap || !iErrorIconMaskBitmap)
       
   773         {
       
   774             if (iErrorIconBitmap)
       
   775             {
       
   776                 delete iErrorIconBitmap;
       
   777                 iErrorIconBitmap = NULL;
       
   778             }
       
   779 
       
   780             if (iErrorIconMaskBitmap)
       
   781             {
       
   782                 delete iErrorIconMaskBitmap;
       
   783                 iErrorIconMaskBitmap = NULL;
       
   784             }
       
   785 
       
   786             AknsUtils::CreateIconL(
       
   787                 AknsUtils::SkinInstance(),
       
   788                 KAknsIIDQgnIndiCam4Camera,
       
   789                 iErrorIconBitmap,
       
   790                 iErrorIconMaskBitmap,
       
   791                 KCameraAppBitmapFile,
       
   792                 EMbmCameraappQgn_indi_cam4_camera,
       
   793                 EMbmCameraappQgn_indi_cam4_camera_mask
       
   794             );
       
   795         }
       
   796 
       
   797         //TRect iconRect
       
   798         drawRect.iTl.iX += KErrorIconMargin;
       
   799         drawRect.iTl.iY += KErrorIconMargin;
       
   800         drawRect.iBr.iX -= KErrorIconMargin;
       
   801         drawRect.iBr.iY -= KErrorIconMargin;
       
   802 
       
   803         if (iErrorIconBitmap->SizeInPixels() != drawRect.Size())
       
   804         {
       
   805             AknIconUtils::SetSize(iErrorIconBitmap, drawRect.Size());
       
   806             AknIconUtils::SetSize(iErrorIconMaskBitmap, drawRect.Size());
       
   807         }
       
   808 
       
   809         directGc->BitBltMasked(
       
   810             drawRect.iTl, iErrorIconBitmap,
       
   811             TRect(iErrorIconBitmap->SizeInPixels()),
       
   812             iErrorIconMaskBitmap, EFalse);
       
   813 
       
   814         iDirectAccess->ScreenDevice()->Update();
       
   815     }
       
   816 
       
   817 }
       
   818 
       
   819 
       
   820 // ---------------------------------------------------------------------------
       
   821 // CMMACameraWindow::ReleaseUiResources()
       
   822 // Stops the DirectViewFinder and deletes UI Camera instance
       
   823 // Have to be called from UI thread in which UI Camera
       
   824 // have been created before the CMMACameraWindow instance
       
   825 // is deleted.
       
   826 // ---------------------------------------------------------------------------
       
   827 //
       
   828 void CMMACameraWindow::ReleaseUiResources()
       
   829 {
       
   830     if (iUICamera)
       
   831     {
       
   832         SetViewFinderVisibility(EFalse);
       
   833         // iStarterTimer is cancelled by previous call
       
   834         // it can be deleted now
       
   835         delete iStarterTimer;
       
   836         iStarterTimer = NULL;
       
   837         iUICamera->Release();
       
   838         delete iUICamera;
       
   839         iUICamera = NULL;
       
   840         iCameraPowerOn = EFalse;
       
   841         if (iDirectAccess)
       
   842         {
       
   843             iDirectAccess->Cancel();
       
   844             delete iDirectAccess;
       
   845             iDirectAccess = NULL;
       
   846         }
       
   847         delete iErrorIconBitmap;
       
   848         iErrorIconBitmap = NULL;
       
   849         delete iErrorIconMaskBitmap;
       
   850         iErrorIconMaskBitmap = NULL;
       
   851     }
       
   852 }
       
   853 
       
   854 
       
   855 // ---------------------------------------------------------------------------
       
   856 // CMMACameraWindow::ResetViewFinder
       
   857 // Resets (stops and starts) viewfinder
       
   858 // ---------------------------------------------------------------------------
       
   859 //
       
   860 void CMMACameraWindow::ResetViewFinder()
       
   861 {
       
   862 
       
   863     if (iStarterTimer && !iStarterTimer->IsActive() && iStarted)
       
   864     {
       
   865         SetViewFinderVisibility(EFalse);
       
   866         SetViewFinderVisibility(ETrue);
       
   867     }
       
   868 }
       
   869 
       
   870 
       
   871 // ---------------------------------------------------------------------------
       
   872 // CMMACameraWindow::Destroy
       
   873 // Deletes this object.
       
   874 // ---------------------------------------------------------------------------
       
   875 //
       
   876 void CMMACameraWindow::Destroy()
       
   877 {
       
   878     // Delete itself
       
   879     delete this;
       
   880 }
       
   881 
       
   882 
       
   883 // ---------------------------------------------------------------------------
       
   884 // From class MUiEventConsumer.
       
   885 // CMMACameraWindow::MdcDSAResourcesCallback
       
   886 // Callback to iDisplay->UIGetDSAResources().
       
   887 // Invoked asynchronously from UI Event Server thread.
       
   888 // ---------------------------------------------------------------------------
       
   889 //
       
   890 void CMMACameraWindow::MdcDSAResourcesCallback(
       
   891     RWsSession &aWs,
       
   892     CWsScreenDevice &aScreenDevice,
       
   893     RWindowBase &aWindow)
       
   894 {
       
   895     this->UIStartViewFinder(aWs, aScreenDevice, aWindow);
       
   896 }
       
   897 
       
   898 
       
   899 // ---------------------------------------------------------------------------
       
   900 // From class MUiEventConsumer.
       
   901 // CMMACameraWindow::MdcUICallback
       
   902 // Callback to iDisplay->UIGetCallback().
       
   903 // Invoked asynchronously from UI Event Server thread.
       
   904 // ---------------------------------------------------------------------------
       
   905 //
       
   906 void CMMACameraWindow::MdcUICallback(TInt aCallbackId)
       
   907 {
       
   908     DEBUG("MMA::CMMACameraWindow::MdcUICallback");
       
   909 
       
   910     switch (aCallbackId)
       
   911     {
       
   912     case EDeleteViewFinder:
       
   913         ReleaseUiResources();
       
   914         break;
       
   915     case EHideViewFinder:
       
   916         SetViewFinderVisibility(EFalse);
       
   917         break;
       
   918     case EShowViewFinder:
       
   919         SetViewFinderVisibility(ETrue);
       
   920         break;
       
   921     case EResetViewFinder:
       
   922         ResetViewFinder();
       
   923         break;
       
   924     case EDestroyWindow:
       
   925         Destroy();
       
   926         break;
       
   927     }
       
   928 }
       
   929 
       
   930 
       
   931 //  END OF FILE