vtprotocolplugins/DisplaySink/src/CVtImageRotator.cpp
changeset 0 ed9695c8bcbe
equal deleted inserted replaced
-1:000000000000 0:ed9695c8bcbe
       
     1 /*
       
     2 * Copyright (c) 2004 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:  Image Transforms subsystem.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include <e32svr.h>
       
    22 #include <fbs.h>
       
    23 
       
    24 #include "cvtimagerotator.h"
       
    25 #include "CVtImageRotatorImplMirrorFlip.h"
       
    26 #include "CVtImageRotatorImplClockwise.h"
       
    27 
       
    28 // CONSTANTS
       
    29 
       
    30 _LIT( KModuleName, "CVtImageRotator" );
       
    31 
       
    32 // MACROS
       
    33 
       
    34 #ifdef _DEBUG
       
    35 #    define __IF_DEBUG(t) {RDebug::t;}
       
    36 #else
       
    37 #    define __IF_DEBUG(t)
       
    38 #endif
       
    39 
       
    40 // ============================ MEMBER FUNCTIONS ===============================
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // CVtImageRotator::NewL( MVtImageRotatorObserver& aObserver,
       
    44 //  TPriority aPriority )
       
    45 // -----------------------------------------------------------------------------
       
    46 EXPORT_C CVtImageRotator* CVtImageRotator::NewL(
       
    47     MVtImageRotatorObserver& aObserver,
       
    48     TPriority aPriority)
       
    49     {
       
    50     CVtImageRotator* self = new ( ELeave ) CVtImageRotator( aObserver, aPriority );
       
    51     CleanupStack::PushL( self );
       
    52     self->ConstructL();
       
    53     CleanupStack::Pop(); // self
       
    54     return self;
       
    55     }
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CVtImageRotator::~CVtImageRotator()
       
    59 // -----------------------------------------------------------------------------
       
    60 EXPORT_C CVtImageRotator::~CVtImageRotator()
       
    61     {
       
    62 	Cancel();
       
    63     delete iAsyncCallBack;
       
    64     delete iHeapLock;
       
    65 	delete iRotatorImpl;
       
    66     }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CVtImageRotator::ScaleL( const CVtImage& aSource,
       
    70 //  CVtImage& aTarget, const TRotationAngle& aAngle )
       
    71 // -----------------------------------------------------------------------------
       
    72 EXPORT_C void CVtImageRotator::RotateL( const CVtImage& aSource,
       
    73     CVtImage& aTarget, const TRotationAngle& aAngle )
       
    74     {
       
    75     if ( !IsActive() )
       
    76         {
       
    77         CreateRotatorL( aAngle );
       
    78         iRotatorImpl->SetSourceTargetL( aSource, aTarget );
       
    79         iCancelled = EFalse;
       
    80         Activate();
       
    81         iAsyncCallBack->CallBack();
       
    82         }
       
    83     else
       
    84         {
       
    85         User::Panic( KModuleName(), EBusy );
       
    86         }
       
    87     }
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // CVtImageRotator::Rotate
       
    91 // -----------------------------------------------------------------------------
       
    92 EXPORT_C void CVtImageRotator::Rotate(
       
    93     const CVtImage& aSource,
       
    94     CVtImage& aTarget, const TRotationAngle& aAngle )
       
    95     {
       
    96     TRAPD( result, RotateL( aSource, aTarget, aAngle ) );
       
    97     if ( result != KErrNone )
       
    98         {
       
    99         Activate();
       
   100         Signal( result );
       
   101         }
       
   102     }
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // CVtImageRotator::CVtImageRotator( MVtImageRotatorObserver& aObserver,
       
   106 //  TPriority aPriority )
       
   107 // -----------------------------------------------------------------------------
       
   108 CVtImageRotator::CVtImageRotator( MVtImageRotatorObserver& aObserver,
       
   109                                   TPriority aPriority )
       
   110 : CActive( aPriority ), iObserver( aObserver )
       
   111     {
       
   112     CActiveScheduler::Add( this );
       
   113     }
       
   114 
       
   115 // -----------------------------------------------------------------------------
       
   116 // CVtImageRotator::ConstructL()
       
   117 // -----------------------------------------------------------------------------
       
   118 void CVtImageRotator::ConstructL()
       
   119     {
       
   120     iHeapLock = new ( ELeave ) CFbsBitmap();
       
   121     iHeapLock->Create( TSize( 1, 1 ), EColor256 );
       
   122     iAsyncCallBack = new ( ELeave )
       
   123         CAsyncCallBack( TCallBack( StaticRotate, this ), Priority() );
       
   124     }
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // CVtImageRotator::CreateRotatorL( const TRotationAngle& aAngle )
       
   128 // -----------------------------------------------------------------------------
       
   129 void CVtImageRotator::CreateRotatorL( const TRotationAngle& aAngle )
       
   130     {
       
   131     if( iRotatorImpl )
       
   132         {
       
   133         if( iRotatorImpl->SupportsRotationAngle( aAngle ) )
       
   134             {
       
   135             iRotatorImpl->SetAngle( aAngle );
       
   136             return;
       
   137             }
       
   138         delete iRotatorImpl;
       
   139         iRotatorImpl = 0;
       
   140         }
       
   141 
       
   142     switch( aAngle )
       
   143         {
       
   144         case E90DegreesClockwise:
       
   145         case E270DegreesClockwise:
       
   146             iRotatorImpl =
       
   147                 new ( ELeave ) CVtImageRotatorImplClockwise( aAngle );
       
   148             break;
       
   149 
       
   150         case EMirrorHorizontalAxis:
       
   151         case EFlipVerticalAxis:
       
   152         case E180DegreesClockwise:
       
   153             iRotatorImpl =
       
   154                 new ( ELeave ) CVtImageRotatorImplMirrorFlip( aAngle );
       
   155             break;
       
   156 
       
   157         default:
       
   158             User::Leave( KErrNotSupported );
       
   159         }
       
   160     }
       
   161 
       
   162 // -----------------------------------------------------------------------------
       
   163 // CVtImageRotator::Activate
       
   164 // -----------------------------------------------------------------------------
       
   165 void CVtImageRotator::Activate()
       
   166     {
       
   167     iStatus = KRequestPending;
       
   168     SetActive();
       
   169     }
       
   170 
       
   171 // -----------------------------------------------------------------------------
       
   172 // CVtImageRotator::Signal( TInt aError )
       
   173 // -----------------------------------------------------------------------------
       
   174 void CVtImageRotator::Signal( TInt aError )
       
   175     {
       
   176     TRequestStatus* pStatus = &iStatus;
       
   177     User::RequestComplete( pStatus, aError );
       
   178     }
       
   179 
       
   180 // -----------------------------------------------------------------------------
       
   181 // CVtImageRotator::RunL()
       
   182 // -----------------------------------------------------------------------------
       
   183 void CVtImageRotator::RunL()
       
   184     {
       
   185     iObserver.RotationFinished( iStatus.Int() );
       
   186     }
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 // CVtImageRotator::DoCancel()
       
   190 // -----------------------------------------------------------------------------
       
   191 void CVtImageRotator::DoCancel()
       
   192     {
       
   193     if ( iStatus == KRequestPending )
       
   194         {
       
   195         iCancelled = ETrue;
       
   196         Signal( KErrCancel );
       
   197         iObserver.RotationFinished( KErrCancel );
       
   198         }
       
   199     }
       
   200 
       
   201 // -----------------------------------------------------------------------------
       
   202 // CVtImageRotator::StaticRotate()
       
   203 // -----------------------------------------------------------------------------
       
   204 TInt CVtImageRotator::StaticRotate( TAny* aPtr )
       
   205     {
       
   206     CVtImageRotator* self = reinterpret_cast< CVtImageRotator* >( aPtr );
       
   207     self->DoRotate();
       
   208     return KErrNone;
       
   209     }
       
   210 
       
   211 // -----------------------------------------------------------------------------
       
   212 // CVtImageRotator::DoRotate
       
   213 // -----------------------------------------------------------------------------
       
   214 void CVtImageRotator::DoRotate()
       
   215     {
       
   216     if ( !iCancelled )
       
   217         {
       
   218         TBool more;
       
   219         TBool needsLock = iRotatorImpl->NeedHeapLock();
       
   220         if( needsLock )
       
   221             {
       
   222             iHeapLock->LockHeap( ETrue );
       
   223             }
       
   224         TInt result = iRotatorImpl->Rotate( more );
       
   225         if( needsLock )
       
   226             {
       
   227             iHeapLock->UnlockHeap( ETrue );
       
   228             }
       
   229         if( !more || ( result != KErrNone ) )
       
   230             {
       
   231             Signal( result );
       
   232             }
       
   233         else
       
   234             {
       
   235             iAsyncCallBack->CallBack();
       
   236             }
       
   237         }
       
   238     }
       
   239 
       
   240 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   241 
       
   242 // End of File
       
   243 
       
   244