camerauis/cameraapp/generic/src/CamBmpRotatorAo.cpp
branchRCL_3
changeset 24 bac7acad7cb3
parent 0 1ddebce53859
equal deleted inserted replaced
23:61bc0f252b2b 24:bac7acad7cb3
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Utility class to rotate bitmaps*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <e32base.h>
       
    21 #include <e32std.h>
       
    22 #include "CamBmpRotatorAo.h"
       
    23 #include "camlogging.h"
       
    24 
       
    25 // CONSTANTS
       
    26 
       
    27 // MACROS
       
    28 
       
    29 // LOCAL CONSTANTS AND MACROS
       
    30 
       
    31 // MODULE DATA STRUCTURES
       
    32 
       
    33 // LOCAL FUNCTION PROTOTYPES
       
    34 
       
    35 // FORWARD DECLARATIONS
       
    36 
       
    37 // ============================= LOCAL FUNCTIONS ===============================
       
    38 
       
    39 // ============================ MEMBER FUNCTIONS ===============================
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // CCamBmpRotatorAo::CCamBmpRotatorAo
       
    43 // C++ constructor
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 CCamBmpRotatorAo::CCamBmpRotatorAo() : CActive( EPriorityHigh )
       
    47     {    
       
    48     }
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CCamBmpRotatorAo::ConstructL
       
    52 // Second phase constructor.
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 void CCamBmpRotatorAo::ConstructL()
       
    56     {    
       
    57     iRotator = CBitmapRotator::NewL();
       
    58     CActiveScheduler::Add( this );
       
    59     }
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // CCamBmpRotatorAo::NewL
       
    63 // Two-phased constructor.
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 CCamBmpRotatorAo* CCamBmpRotatorAo::NewL()
       
    67     {
       
    68     CCamBmpRotatorAo* self = new( ELeave ) CCamBmpRotatorAo();
       
    69     CleanupStack::PushL( self );
       
    70     self->ConstructL();
       
    71     CleanupStack::Pop( self );
       
    72     return self;
       
    73     }
       
    74 
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // CCamBmpRotatorAo::~CCamBmpRotatorAo()
       
    78 // Destructor
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 CCamBmpRotatorAo::~CCamBmpRotatorAo()
       
    82   {
       
    83   PRINT( _L("Camera => ~CCamBmpRotatorAo") );
       
    84   if ( IsActive() )
       
    85     {
       
    86     Cancel();
       
    87     }
       
    88   
       
    89   delete iRotator;
       
    90   iQueue.ResetAndDestroy();
       
    91   PRINT( _L("Camera <= ~CCamBmpRotatorAo") );
       
    92   }
       
    93 
       
    94 
       
    95     
       
    96 // -----------------------------------------------------------------------------
       
    97 // CCamBmpRotatorAo::AddToQueueL
       
    98 // Adds the specified bitmap/rotator to the queue of items to be rotated
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 void CCamBmpRotatorAo::AddToQueueL( CFbsBitmap* aBitmap, CBitmapRotator::TRotationAngle aAngle )
       
   102     {
       
   103     CRotateTask* task = new ( ELeave ) CRotateTask;
       
   104     CleanupStack::PushL( task );
       
   105     task->iBitmap = aBitmap;
       
   106     task->iAngle = aAngle;
       
   107     User::LeaveIfError( iQueue.Append( task ) );        
       
   108     CleanupStack::Pop( task );
       
   109     }
       
   110     
       
   111 // -----------------------------------------------------------------------------
       
   112 // CCamBmpRotatorAo::RunL
       
   113 // Called when a rotation operation is completed (or cancelled)
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 void CCamBmpRotatorAo::RunL()
       
   117     {
       
   118     // Pop the completed image from the queue.
       
   119     CRotateTask* task = iQueue[0];    
       
   120     iQueue.Remove( 0 );    
       
   121     delete task;  // NOTE: no need to delete bitmap (as not owned)
       
   122         
       
   123     // If rotate completed successfully...
       
   124     // ... and there are more left on the queue...
       
   125     // ... then start the next rotate
       
   126     if ( iStatus.Int() == KErrNone )
       
   127         {
       
   128         if ( iQueue.Count() > 0 )
       
   129             {
       
   130             StartNextRotate();
       
   131             }    
       
   132         }
       
   133     else 
       
   134         {
       
   135         // Rotation failed; cancel further rotation attempts in 
       
   136         // the queue
       
   137         iQueue.ResetAndDestroy();
       
   138         }
       
   139     }
       
   140     
       
   141 // -----------------------------------------------------------------------------
       
   142 // CCamBmpRotatorAo::DoCancel
       
   143 // Called to cancel an outstanding rotation operation
       
   144 // -----------------------------------------------------------------------------
       
   145 //
       
   146 void CCamBmpRotatorAo::DoCancel()
       
   147     {
       
   148     iRotator->Cancel();
       
   149     }
       
   150     
       
   151 // -----------------------------------------------------------------------------
       
   152 // CCamBmpRotatorAo::StartNextRotate
       
   153 // Called to start the next queued rotation task.  If no tasks are queued, does nothing
       
   154 // -----------------------------------------------------------------------------
       
   155 //
       
   156 void CCamBmpRotatorAo::StartNextRotate()
       
   157     {
       
   158     if ( iQueue.Count() == 0 )
       
   159         return;
       
   160     
       
   161     CRotateTask* task = iQueue[0];
       
   162        
       
   163     iRotator->Rotate( &iStatus, *task->iBitmap, task->iAngle );
       
   164     SetActive();
       
   165     }
       
   166 
       
   167 //  End of File