skins/AknSkins/alsrc/AknsAlEffectContext.cpp
changeset 0 05e9090e2422
equal deleted inserted replaced
-1:000000000000 0:05e9090e2422
       
     1 /*
       
     2 * Copyright (c) 2004-2008 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:  Class for providing effect context for effect plugins.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "AknsRlErr.h"
       
    21 #include "AknsAlEffectContext.h"
       
    22 
       
    23 // -----------------------------------------------------------------------------
       
    24 // CAknsAlEffectContext::CAknsAlEffectContext
       
    25 // -----------------------------------------------------------------------------
       
    26 //
       
    27 CAknsAlEffectContext::CAknsAlEffectContext()
       
    28     {
       
    29     // Derived from CBase -> all data is zeroed
       
    30     }
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // CAknsAlEffectContext::NewL
       
    34 // -----------------------------------------------------------------------------
       
    35 //
       
    36 CAknsAlEffectContext* CAknsAlEffectContext::NewL()
       
    37     {
       
    38     CAknsAlEffectContext* self = new(ELeave) CAknsAlEffectContext();
       
    39     return self;
       
    40     }
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // CAknsAlEffectContext::~CAknsAlEffectContext
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 CAknsAlEffectContext::~CAknsAlEffectContext()
       
    47     {
       
    48     ReleaseLayers(); //lint !e1551 No exception thrown
       
    49     }
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CAknsAlEffectContext::ConfigureL
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 void CAknsAlEffectContext::ConfigureL( const TSize& aSize,
       
    56                                        TDisplayMode aRgbMode,
       
    57                                        TInt aInputLayerIndex,
       
    58                                        TInt aInputLayerMode )
       
    59     {
       
    60     iLayerSize = aSize;
       
    61     iRgbMode = aRgbMode;
       
    62 
       
    63     ReleaseLayers();
       
    64 
       
    65     if( aInputLayerIndex < 0 ) // Input layer is set to none
       
    66         {
       
    67         return;
       
    68         }
       
    69 
       
    70     CreateIfNeededL( aInputLayerIndex, aInputLayerMode, ETrue );
       
    71     }
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // CAknsAlEffectContext::RgbBitmap
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 CFbsBitmap* CAknsAlEffectContext::RgbBitmap( TInt aLayerIndex ) const
       
    78     {
       
    79     if( aLayerIndex < 0 || aLayerIndex >= KAknsAlEffectContextLayerN )
       
    80         return NULL;
       
    81 
       
    82     return iLayers[aLayerIndex].iRGBBitmap;
       
    83     }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CAknsAlEffectContext::AlphaBitmap
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 CFbsBitmap* CAknsAlEffectContext::AlphaBitmap( TInt aLayerIndex ) const
       
    90     {
       
    91     if( aLayerIndex < 0 || aLayerIndex >= KAknsAlEffectContextLayerN )
       
    92         return NULL;
       
    93 
       
    94     return iLayers[aLayerIndex].iAlphaBitmap;
       
    95     }
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CAknsAlEffectContext::RgbGc
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 CFbsBitGc* CAknsAlEffectContext::RgbGc( TInt aIndex ) const
       
   102     {
       
   103     if( aIndex < 0 || aIndex >= KAknsAlEffectContextLayerN )
       
   104         return NULL;
       
   105 
       
   106     return iLayers[aIndex].iRGBGc;
       
   107     }
       
   108 
       
   109 // -----------------------------------------------------------------------------
       
   110 // CAknsAlEffectContext::AlphaGc
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 CFbsBitGc* CAknsAlEffectContext::AlphaGc( TInt aIndex ) const
       
   114     {
       
   115     if( aIndex < 0 || aIndex >= KAknsAlEffectContextLayerN )
       
   116         return NULL;
       
   117 
       
   118     return iLayers[aIndex].iAlphaGc;
       
   119     }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CAknsAlEffectContext::ReleaseInputLayers
       
   123 // -----------------------------------------------------------------------------
       
   124 //
       
   125 void CAknsAlEffectContext::ReleaseInputLayers( TInt aOutputLayerIndex )
       
   126     {
       
   127     // It is possible that output layer is also one of the input layers ->
       
   128     // delete all layers that are not output layer.
       
   129     for( int i=0; i < KAknsAlEffectContextLayerN; i++ )
       
   130         {
       
   131         if( i != aOutputLayerIndex )
       
   132             {
       
   133             ReleaseLayer( i );
       
   134             }
       
   135         }
       
   136     }
       
   137 
       
   138 // -----------------------------------------------------------------------------
       
   139 // CAknsAlEffectContext::SetSkinSrvSession
       
   140 // -----------------------------------------------------------------------------
       
   141 //
       
   142 void CAknsAlEffectContext::SetSkinSrvSession( RAknsSrvSession* aSession )
       
   143     {
       
   144     iSession = aSession;
       
   145     }
       
   146 
       
   147 // -----------------------------------------------------------------------------
       
   148 // CAknsAlEffectContext::LayerSize
       
   149 // -----------------------------------------------------------------------------
       
   150 //
       
   151 const TSize CAknsAlEffectContext::LayerSize()
       
   152     {
       
   153     return iLayerSize;
       
   154     }
       
   155 
       
   156 // -----------------------------------------------------------------------------
       
   157 // CAknsAlEffectContext::GetLayerDataL
       
   158 // -----------------------------------------------------------------------------
       
   159 //
       
   160 void CAknsAlEffectContext::GetLayerDataL( TAknsRlLayerData& aData,
       
   161                                           const TInt aLayerIndex,
       
   162                                           const TInt aLayerStatus,
       
   163                                           const TBool aInitialize )
       
   164     {
       
   165     if( ( aLayerIndex < 0 ) || ( aLayerIndex >= KAknsAlEffectContextLayerN ) )
       
   166         {
       
   167         User::Leave( KAknsRlErrBadLayerIndex );
       
   168         }
       
   169 
       
   170     CreateIfNeededL( aLayerIndex, aLayerStatus, aInitialize );
       
   171 
       
   172     /*lint -save -e661 */ // Index is boundary checked above
       
   173     if( (aLayerStatus==KAknsRlLayerRGBOnly) ||
       
   174         (aLayerStatus==KAknsRlLayerRGBA) )
       
   175         {
       
   176         aData.iRGBBitmap = iLayers[aLayerIndex].iRGBBitmap;
       
   177         aData.iRGBDevice = iLayers[aLayerIndex].iRGBDevice;
       
   178         aData.iRGBGc     = iLayers[aLayerIndex].iRGBGc;
       
   179         }
       
   180 
       
   181     if( (aLayerStatus==KAknsRlLayerAlphaOnly) ||
       
   182         (aLayerStatus==KAknsRlLayerRGBA) )
       
   183         {
       
   184         aData.iAlphaBitmap = iLayers[aLayerIndex].iAlphaBitmap;
       
   185         aData.iAlphaDevice = iLayers[aLayerIndex].iAlphaDevice;
       
   186         aData.iAlphaGc     = iLayers[aLayerIndex].iAlphaGc;
       
   187         }
       
   188     /*lint -restore */
       
   189     }
       
   190 
       
   191 // -----------------------------------------------------------------------------
       
   192 // CAknsAlEffectContext::GetSkinSrvSession
       
   193 // -----------------------------------------------------------------------------
       
   194 //
       
   195 RAknsSrvSession* CAknsAlEffectContext::GetSkinSrvSession()
       
   196     {
       
   197     return iSession;
       
   198     }
       
   199 
       
   200 // -----------------------------------------------------------------------------
       
   201 // CAknsAlEffectContext::CreateIfNeededL
       
   202 // -----------------------------------------------------------------------------
       
   203 //
       
   204 void CAknsAlEffectContext::CreateIfNeededL( const TInt aLayerIndex,
       
   205     const TInt aLayerStatus, const TBool aInitialize )
       
   206     {
       
   207     if( ( aLayerIndex < 0 ) || ( aLayerIndex >= KAknsAlEffectContextLayerN ) )
       
   208         {
       
   209         User::Leave( KAknsRlErrBadLayerIndex );
       
   210         }
       
   211 
       
   212     /*lint -save -e661 */ // Index is boundary checked above
       
   213     if( iLayers[aLayerIndex].iRGBBitmap &&
       
   214         iLayers[aLayerIndex].iAlphaBitmap ) return;
       
   215 
       
   216     if( iLayers[aLayerIndex].iRGBBitmap ||
       
   217         iLayers[aLayerIndex].iAlphaBitmap )
       
   218         User::Leave( KAknsRlErrInternalState );
       
   219 
       
   220     TSize size = LayerSize();
       
   221 
       
   222     CFbsBitmap* bitmap = new (ELeave) CFbsBitmap();
       
   223     CleanupStack::PushL( bitmap );
       
   224     User::LeaveIfError( bitmap->Create( size, iRgbMode ) );
       
   225 
       
   226     CFbsBitmapDevice* dev = CFbsBitmapDevice::NewL( bitmap );
       
   227     CleanupStack::PushL( dev );
       
   228 
       
   229     CFbsBitGc* gc = CFbsBitGc::NewL();
       
   230     CleanupStack::PushL( gc );
       
   231     gc->Activate( dev );
       
   232 
       
   233     iLayers[aLayerIndex].iRGBBitmap = bitmap;
       
   234     iLayers[aLayerIndex].iRGBDevice = dev;
       
   235     iLayers[aLayerIndex].iRGBGc = gc;
       
   236     CleanupStack::Pop(3); // gc, dev, bitmap
       
   237 
       
   238     bitmap = new (ELeave) CFbsBitmap();
       
   239     CleanupStack::PushL( bitmap );
       
   240     User::LeaveIfError( bitmap->Create( size, EGray256 ) );
       
   241 
       
   242     dev = CFbsBitmapDevice::NewL( bitmap );
       
   243     CleanupStack::PushL( dev );
       
   244 
       
   245     gc = CFbsBitGc::NewL();
       
   246     CleanupStack::PushL( gc );
       
   247     gc->Activate( dev );
       
   248 
       
   249     iLayers[aLayerIndex].iAlphaBitmap = bitmap;
       
   250     iLayers[aLayerIndex].iAlphaDevice = dev;
       
   251     iLayers[aLayerIndex].iAlphaGc = gc;
       
   252     CleanupStack::Pop(3); // gc, dev, bitmap
       
   253 
       
   254     if( aInitialize )
       
   255         {
       
   256         switch( aLayerStatus )
       
   257             {
       
   258             case KAknsRlLayerRGBOnly:
       
   259                 iLayers[aLayerIndex].iRGBGc->SetBrushColor( KRgbBlack );
       
   260                 iLayers[aLayerIndex].iRGBGc->Clear();
       
   261                 iLayers[aLayerIndex].iAlphaGc->SetBrushColor( KRgbWhite );
       
   262                 iLayers[aLayerIndex].iAlphaGc->Clear();
       
   263                 break;
       
   264             default:
       
   265                 iLayers[aLayerIndex].iRGBGc->SetBrushColor( KRgbBlack );
       
   266                 iLayers[aLayerIndex].iRGBGc->Clear();
       
   267                 iLayers[aLayerIndex].iAlphaGc->SetBrushColor( KRgbBlack );
       
   268                 iLayers[aLayerIndex].iAlphaGc->Clear();
       
   269                 break;
       
   270             }
       
   271         }
       
   272     /*lint -restore */
       
   273     }//lint !e661 Layer index is boundary checked
       
   274 
       
   275 // -----------------------------------------------------------------------------
       
   276 // CAknsAlEffectContext::ReleaseLayers
       
   277 // -----------------------------------------------------------------------------
       
   278 //
       
   279 void CAknsAlEffectContext::ReleaseLayers()
       
   280     {
       
   281     for( TInt i=0; i < KAknsAlEffectContextLayerN; i++ )
       
   282         {
       
   283         ReleaseLayer( i );
       
   284         }
       
   285     }
       
   286 // -----------------------------------------------------------------------------
       
   287 // CAknsAlEffectContext::ReleaseLayer
       
   288 // -----------------------------------------------------------------------------
       
   289 //
       
   290 void CAknsAlEffectContext::ReleaseLayer( const TInt aLayerIndex )
       
   291     {
       
   292     ASSERT( aLayerIndex >= 0 && aLayerIndex < KAknsAlEffectContextLayerN );
       
   293 
       
   294     /*lint -save -e661 */ // Never called with invalid index
       
   295     delete iLayers[aLayerIndex].iRGBBitmap;
       
   296     delete iLayers[aLayerIndex].iRGBDevice;
       
   297     delete iLayers[aLayerIndex].iRGBGc;
       
   298     delete iLayers[aLayerIndex].iAlphaBitmap;
       
   299     delete iLayers[aLayerIndex].iAlphaDevice;
       
   300     delete iLayers[aLayerIndex].iAlphaGc;
       
   301 
       
   302     iLayers[aLayerIndex].iRGBBitmap   = NULL;
       
   303     iLayers[aLayerIndex].iRGBDevice   = NULL;
       
   304     iLayers[aLayerIndex].iRGBGc       = NULL;
       
   305     iLayers[aLayerIndex].iAlphaBitmap = NULL;
       
   306     iLayers[aLayerIndex].iAlphaDevice = NULL;
       
   307     iLayers[aLayerIndex].iAlphaGc     = NULL;
       
   308     /*lint -restore */
       
   309     }
       
   310 
       
   311 // End of File