skins/AknSkins/src/AknsScalabilityUtils.cpp
changeset 0 05e9090e2422
child 1 ba33815114d6
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:  Internal utility class to handle scalability-related
       
    15                  operations.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "AknsCppPreface.h"
       
    22 
       
    23 #include <coecntrl.h>
       
    24 #include <w32std.h>
       
    25 #include <AknIconUtils.h>
       
    26 #include <akniconconfig.h>
       
    27 
       
    28 #include "AknsScalabilityUtils.h"
       
    29 
       
    30 #include <AknsDrawUtils.h>
       
    31 #include <AknsItemData.h>
       
    32 #include <AknsImageAttributeData.h>
       
    33 #include "AknsTemporaryBitmap.h"
       
    34 
       
    35 #include "AknsRlRenderer.h"
       
    36 #include "AknsRlMasterLayout.h"
       
    37 #include "AknsAppSkinInstance.h"
       
    38 #include "AknsAlConversionUtil.h"
       
    39 #include <AknsDrawUtils.h>
       
    40 
       
    41 #include "AknSkinsVariant.hrh"
       
    42 
       
    43 #include "AknsDebug.h"
       
    44 #include "AknsBackgroundLayout.h"
       
    45 
       
    46 // CONSTANTS
       
    47 
       
    48 static const TInt KAknsSURErrNoParent   = -9000;
       
    49 static const TInt KAknsSURErrNoLayout   = -9001;
       
    50 static const TInt KAknsSURErrNoData     = -9002;
       
    51 
       
    52 static const TInt KAknsSURecursionLimit = 8;
       
    53 
       
    54 // ============================= LOCAL FUNCTIONS ===============================
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // GetSourceSize
       
    58 //
       
    59 // Retrieves source size based on the given size parameter and image data.
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 static TSize GetSourceSize(
       
    63     const TSize& aOverridingSize, const TSize& aTargetLayoutSize,
       
    64     CFbsBitmap* aBitmap, TBool& aPreserved )
       
    65     {
       
    66     // Use overriding size, if defined
       
    67     if( aOverridingSize.iWidth>=0 && aOverridingSize.iHeight>=0 )
       
    68         {
       
    69         return aOverridingSize;
       
    70         }
       
    71 
       
    72     if( aBitmap )
       
    73         {
       
    74         if( AknIconUtils::IsMifIcon( aBitmap ) )
       
    75             {
       
    76             TSize svgSize( aTargetLayoutSize );
       
    77             // Preserve icon data
       
    78             AknIconUtils::PreserveIconData( aBitmap );
       
    79             aPreserved = ETrue;
       
    80             // Set source rectangle from SVG dimension
       
    81             if( AknIconUtils::GetContentDimensions( aBitmap, svgSize ) )
       
    82                 {
       
    83                 AKNS_TRACE_ERROR("AknsScalabilityUtils-GetSourceSize GetContentDimensions FAILED!");
       
    84                 }
       
    85             return svgSize;
       
    86             }
       
    87         else
       
    88             {
       
    89             // Set source rectangle from bitmap dimension
       
    90             return aBitmap->SizeInPixels();
       
    91             }
       
    92         }
       
    93 
       
    94     return aTargetLayoutSize;
       
    95     }
       
    96 
       
    97 void DestroyPreservedIcon( TAny* aBitmap )
       
    98     {
       
    99     CFbsBitmap* bitmap = static_cast<CFbsBitmap*>(aBitmap);
       
   100     if ( bitmap )
       
   101         {
       
   102         AknIconUtils::DestroyIconData( bitmap );
       
   103         }
       
   104     }
       
   105 
       
   106 // ============================ MEMBER FUNCTIONS ===============================
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // AknsScalabilityUtils::DrawPartialCachedImage
       
   110 // (commented in the header).
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 TBool AknsScalabilityUtils::DrawPartialCachedImage(
       
   114     MAknsSkinInstance* /*aSkin*/, CBitmapContext& aGc, const TRect& aTrgLayoutRect,
       
   115     const TRect& aTrgDrawRect, CAknsImageItemData* aImgData,
       
   116     const TAknsItemID& /*aIID*/, const TAknsImageAttributeData* aAttr,
       
   117     const TInt aDrawParam )
       
   118     {
       
   119     // Check for empty draw rectangle
       
   120     if( aTrgDrawRect.IsEmpty() )
       
   121         {
       
   122         return ETrue;
       
   123         }
       
   124 
       
   125     TBool isChained (EFalse);
       
   126     if (aImgData && (aDrawParam&KAknsDrawParamChained))
       
   127         {
       
   128         isChained = ETrue;
       
   129         }
       
   130 
       
   131     // @TODO KAknsDrawParamAlphaOnly supports only soft masks!
       
   132 
       
   133     // Attribute retrieval
       
   134     TAknsImageAttributeData attr;
       
   135     //lint --e{961} Valid logic
       
   136     if( aAttr )
       
   137         {
       
   138         AKNS_TRACE_INFO("AknsScalabilityUtils::DPCI Using supplied attributes");
       
   139         attr.Set( *aAttr );
       
   140         }
       
   141     else if( aImgData->Attributes() )
       
   142         {
       
   143         AKNS_TRACE_INFO("AknsScalabilityUtils::DPCI Using data attributes");
       
   144         attr.Set( *(aImgData->Attributes()) );
       
   145         }
       
   146 
       
   147     TAknsItemType type = aImgData->Type();
       
   148 
       
   149     // Sanity checks
       
   150 
       
   151     if( AknsUtils::IsDerivedType( EAknsITBitmap, type ) )
       
   152         {
       
   153         if( !static_cast<CAknsBitmapItemData*>(aImgData)->Bitmap() )
       
   154             {
       
   155             AKNS_TRACE_ERROR("AknsScalabilityUtils::DPCI Bitmap is NULL");
       
   156             return EFalse;
       
   157             }
       
   158         }
       
   159     if( AknsUtils::IsDerivedType( EAknsITMaskedBitmap, type ) )
       
   160         {
       
   161         if( !static_cast<CAknsMaskedBitmapItemData*>(aImgData)->Mask() )
       
   162             {
       
   163             AKNS_TRACE_ERROR("AknsScalabilityUtils::DPCI Mask is NULL");
       
   164             return EFalse;
       
   165             }
       
   166         }
       
   167 
       
   168     // Graphics type detection
       
   169 
       
   170     CFbsBitmap* bdBmp = NULL;
       
   171     if( AknsUtils::IsDerivedType( EAknsITBitmap, type ) )
       
   172         {
       
   173         bdBmp = static_cast<CAknsBitmapItemData*>(aImgData)->Bitmap();
       
   174         }
       
   175 
       
   176     TSize overridingSize( -1, -1 ); // By default there is no overriding size
       
   177 
       
   178     // Backward compatibility operations
       
   179 
       
   180     if( !(attr.iAttributes&EAknsImageAttributeNBC) )
       
   181         {
       
   182         // Scale NONE and ALIGNED images to the entire rectangle
       
   183         if( (attr.iAttributes==EAknsImageAttributeNone) ||
       
   184             (attr.iAttributes&EAknsImageAttributeAlign) )
       
   185             {
       
   186             AKNS_TRACE_INFO("AknsScalabilityUtils::DPCI BC scale" );
       
   187             overridingSize = aTrgLayoutRect.Size();
       
   188             }
       
   189         }
       
   190 
       
   191     // Concrete image layout
       
   192 
       
   193     if( attr.iAttributes & EAknsImageAttributeSize )
       
   194         {
       
   195         overridingSize = attr.iSize;
       
   196         }
       
   197 
       
   198     if( (attr.iAttributes & EAknsImageAttributeStretch) || 
       
   199           (attr.iAttributes & EAknsImageAttributeTileX) ||
       
   200             (attr.iAttributes & EAknsImageAttributeTileY) )
       
   201         {
       
   202         overridingSize = aTrgLayoutRect.Size();
       
   203         }
       
   204 
       
   205     TBool iconPreserved = EFalse;
       
   206     TRect imgRect( aTrgLayoutRect.iTl,
       
   207         GetSourceSize( overridingSize, aTrgLayoutRect.Size(), bdBmp, iconPreserved ) );
       
   208     if ( iconPreserved )
       
   209         {
       
   210         // Let's make room to the cleanupstack so that the following TCleanupItem
       
   211         // PushL never leaves.
       
   212         TRAPD( err,
       
   213             CleanupStack::PushL( static_cast<TAny*>(NULL) );
       
   214             CleanupStack::Pop(); // NULL
       
   215             );
       
   216         if ( err )
       
   217             {
       
   218             iconPreserved = EFalse;
       
   219             }
       
   220         else
       
   221             {
       
   222             // Now - this should never leave. Leavescan still complains about this, 
       
   223             // but it should be ignored.
       
   224             CleanupStack::PushL( TCleanupItem( DestroyPreservedIcon, bdBmp ) );
       
   225             }
       
   226         }
       
   227 
       
   228     if( attr.iAttributes & EAknsImageAttributeCoords )
       
   229         {
       
   230         imgRect.Move( attr.iCoords );
       
   231         }
       
   232 
       
   233     if( attr.iAttributes & EAknsImageAttributeAlign )
       
   234         {
       
   235         switch( attr.iAlignment & EAknsImageAlignVMask )
       
   236             {
       
   237             case EAknsImageAlignVBottom:
       
   238                 {
       
   239                 imgRect.Move( 0, aTrgLayoutRect.Height() - imgRect.Height() );
       
   240                 break;
       
   241                 }
       
   242             case EAknsImageAlignVCenter:
       
   243                 {
       
   244                 // Negative values should not appear, and thus "rounding to
       
   245                 // the wrong direction" is acceptable.
       
   246                 imgRect.Move( 0, ( aTrgLayoutRect.Height() -
       
   247                     imgRect.Height() ) >> 1 ); //lint !e702
       
   248                 break;
       
   249                 }
       
   250             default: // incl. EAknsImageAlignVTop
       
   251                 {
       
   252                 break;
       
   253                 }
       
   254             } //lint !e788 Default correct for unexpected values
       
   255         switch( attr.iAlignment & EAknsImageAlignHMask )
       
   256             {
       
   257             case EAknsImageAlignHRight:
       
   258                 {
       
   259                 imgRect.Move( aTrgLayoutRect.Width() - imgRect.Width(), 0 );
       
   260                 break;
       
   261                 }
       
   262             case EAknsImageAlignHCenter:
       
   263                 {
       
   264                 // Negative values should not appear, and thus "rounding to
       
   265                 // the wrong direction" is acceptable.
       
   266                 imgRect.Move( ( aTrgLayoutRect.Width() -
       
   267                     imgRect.Width() ) >> 1, 0 ); //lint !e702
       
   268                 break;
       
   269                 }
       
   270             default: // incl. EAknsImageAlignHLeft
       
   271                 {
       
   272                 break;
       
   273                 }
       
   274             } //lint !e788 Default correct for unexpected values
       
   275         }
       
   276 
       
   277     TRect uncroppedImgRect = imgRect;
       
   278     imgRect.Intersection( aTrgLayoutRect );
       
   279 
       
   280     AKNS_TRACE_INFO2("AknsScalabilityUtils::DPCI ImgRectSize=%i,%i", imgRect.Size().iWidth, imgRect.Size().iHeight );
       
   281 
       
   282     // Drawing
       
   283 
       
   284     if( (attr.iAttributes & EAknsImageAttributeTile) ||
       
   285         (attr.iAttributes & EAknsImageAttributeTileX) ||
       
   286         (attr.iAttributes & EAknsImageAttributeTileY) )
       
   287         {
       
   288         if( bdBmp )
       
   289             {
       
   290             TInt setSizeErr( KErrUnknown );
       
   291 
       
   292             if( attr.iAttributes & EAknsImageAttributeTile )
       
   293                 {
       
   294                 setSizeErr = AknIconUtils::SetSize( bdBmp,
       
   295                     uncroppedImgRect.Size(), EAspectRatioNotPreserved );
       
   296                 }
       
   297             else if( attr.iAttributes & EAknsImageAttributeTileX )
       
   298                 {
       
   299                 setSizeErr = AknIconUtils::SetSize( bdBmp,
       
   300                     TSize( KMaxTInt, aTrgLayoutRect.Height() ),
       
   301                     EAspectRatioPreservedAndUnusedSpaceRemoved );
       
   302                 }
       
   303             else if( attr.iAttributes & EAknsImageAttributeTileY )
       
   304                 {
       
   305                 setSizeErr = AknIconUtils::SetSize( bdBmp,
       
   306                     TSize( aTrgLayoutRect.Width(), KMaxTInt ),
       
   307                     EAspectRatioPreservedAndUnusedSpaceRemoved );
       
   308                 }
       
   309             // Destroy icon data
       
   310             if ( iconPreserved )
       
   311                 {
       
   312                 CleanupStack::PopAndDestroy(); // DestroyPreservedIcon
       
   313                 }
       
   314             if( setSizeErr )
       
   315                 {
       
   316                 AKNS_TRACE_ERROR1("AknsScalabilityUtils::DPCI SetSize (in tiling) FAILED, err=%i", setSizeErr);
       
   317                 return EFalse;
       
   318                 }
       
   319             iconPreserved = EFalse;
       
   320             }
       
   321 
       
   322         if( aDrawParam&KAknsDrawParamPrepareOnly )
       
   323             {
       
   324             // Prepare only, return before drawing
       
   325             if ( iconPreserved )
       
   326                 {
       
   327                 CleanupStack::PopAndDestroy(); // DestroyPreservedIcon
       
   328                 }
       
   329             return ETrue;
       
   330             }
       
   331 
       
   332         //lint --e{961} Valid logic
       
   333         // RGB-only drawing falls to next branch
       
   334         if( AknsUtils::IsDerivedType( EAknsITMaskedBitmap, type ) &&
       
   335             (!(aDrawParam&KAknsDrawParamRGBOnly)) )
       
   336             {
       
   337             // This fallback functionality draws tiled masked bitmaps.
       
   338             // It's known to be slow - therefore such elements are strongly
       
   339             // discouraged.
       
   340             CAknsMaskedBitmapItemData* bmpData =
       
   341                 static_cast<CAknsMaskedBitmapItemData*>(aImgData);
       
   342 
       
   343             aGc.SetClippingRect( aTrgDrawRect );
       
   344             aGc.SetBrushStyle(CGraphicsContext::ENullBrush);
       
   345 
       
   346             TSize tileSize( bmpData->Bitmap()->SizeInPixels() );
       
   347 
       
   348             for( int tileY = aTrgLayoutRect.iTl.iY;
       
   349                 tileY < aTrgLayoutRect.iBr.iY;
       
   350                 tileY += tileSize.iHeight )
       
   351                 {
       
   352                 for( int tileX = aTrgLayoutRect.iTl.iX;
       
   353                     tileX < aTrgLayoutRect.iBr.iX;
       
   354                     tileX += tileSize.iWidth )
       
   355                     {
       
   356                     TRect tileRect( TPoint( tileX, tileY ), tileSize );
       
   357                     if( !tileRect.Intersects( aTrgDrawRect ) )
       
   358                         {
       
   359                         // Skip tiles that fall outside the drawing rectangle
       
   360                         continue;
       
   361                         }
       
   362                     if( aDrawParam&KAknsSDMAlphaOnly )
       
   363                         {
       
   364                         aGc.BitBlt( tileRect.iTl, bmpData->Mask(),
       
   365                             TRect( TPoint(0,0), tileSize ) );
       
   366                         }
       
   367                     else
       
   368                         {
       
   369                         aGc.BitBltMasked( tileRect.iTl, bmpData->Bitmap(),
       
   370                             TRect( TPoint(0,0), tileSize ),
       
   371                             bmpData->Mask(), ETrue );
       
   372                         }
       
   373                     }
       
   374                 }
       
   375 
       
   376             aGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   377             aGc.CancelClippingRect();
       
   378             }
       
   379         else if( AknsUtils::IsDerivedType( EAknsITBitmap, type ) )
       
   380             {
       
   381             if( aDrawParam&KAknsSDMAlphaOnly )
       
   382                 {
       
   383                 // Do not draw anything
       
   384                 if ( iconPreserved )
       
   385                     {
       
   386                     CleanupStack::PopAndDestroy(); // DestroyPreservedIcon
       
   387                     }
       
   388                 return ETrue;
       
   389                 }
       
   390 
       
   391             CAknsBitmapItemData* bmpData =
       
   392                 static_cast<CAknsBitmapItemData*>(aImgData);
       
   393 
       
   394             aGc.UseBrushPattern( bmpData->Bitmap() );
       
   395             aGc.SetBrushOrigin( aTrgLayoutRect.iTl );
       
   396             aGc.SetBrushStyle(CGraphicsContext::EPatternedBrush);
       
   397 
       
   398             aGc.DrawRect( aTrgDrawRect );
       
   399 
       
   400             aGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   401             aGc.DiscardBrushPattern();
       
   402             }
       
   403         }
       
   404     else
       
   405         {
       
   406         // Size must be set (to support SVG icons)
       
   407         // This also handles stretching of masks transparently
       
   408         if( AknsUtils::IsDerivedType( EAknsITBitmap, type ) )
       
   409             {
       
   410             CAknsBitmapItemData* bmpData =
       
   411                 static_cast<CAknsBitmapItemData*>(aImgData);
       
   412             if( AknIconUtils::SetSize( bmpData->Bitmap(),
       
   413                 imgRect.Size(), EAspectRatioNotPreserved ) )
       
   414                 {
       
   415                 AKNS_TRACE_ERROR("AknsScalabilityUtils::DPCI SetSize FAILED!");
       
   416                 if ( iconPreserved )
       
   417                     {
       
   418                     CleanupStack::PopAndDestroy(); // DestroyPreservedIcon
       
   419                     }
       
   420                 return EFalse;
       
   421                 }
       
   422             }
       
   423         if( bdBmp )
       
   424             {
       
   425             // Destroy icon data
       
   426             if ( iconPreserved )
       
   427                 {
       
   428                 iconPreserved = EFalse;
       
   429                 CleanupStack::PopAndDestroy(); // DestroyPreservedIcon
       
   430                 }
       
   431             }
       
   432 
       
   433         if( aDrawParam&KAknsDrawParamPrepareOnly )
       
   434             {
       
   435             // Prepare only, return before drawing
       
   436             if ( iconPreserved )
       
   437                 {
       
   438                 CleanupStack::PopAndDestroy(); // DestroyPreservedIcon
       
   439                 }
       
   440             return ETrue;
       
   441             }
       
   442 
       
   443         TRect imgDrawRect = imgRect;
       
   444         imgDrawRect.Intersection( aTrgDrawRect );
       
   445         TPoint imgDrawPoint = imgDrawRect.iTl - uncroppedImgRect.iTl;
       
   446 
       
   447 
       
   448         TBool isMasked = AknsUtils::IsDerivedType( EAknsITMaskedBitmap, type);
       
   449         CAknsMaskedBitmapItemData* bmpData =
       
   450                 static_cast<CAknsMaskedBitmapItemData*>(aImgData);
       
   451 
       
   452         TRect drawrect = isChained ? TRect( imgDrawPoint + aImgData->DrawRect().iTl,imgDrawRect.Size() ) :
       
   453                                      TRect( imgDrawPoint,imgDrawRect.Size() );
       
   454         // RGB-only falls to next branch
       
   455         if( isMasked && bmpData->Mask()
       
   456             && (!(aDrawParam&KAknsDrawParamRGBOnly)) )
       
   457             {
       
   458             aGc.SetBrushStyle(CGraphicsContext::ENullBrush);
       
   459             if( aDrawParam&KAknsSDMAlphaOnly)
       
   460                 {
       
   461                 aGc.BitBlt( imgDrawRect.iTl, bmpData->Mask(), drawrect );
       
   462                 }
       
   463             else
       
   464                 {
       
   465                 aGc.BitBltMasked( imgDrawRect.iTl, bmpData->Bitmap(), drawrect, bmpData->Mask(), ETrue );
       
   466                 }
       
   467             int m = bmpData->Bitmap()->DisplayMode();
       
   468             aGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   469             }
       
   470         else if( AknsUtils::IsDerivedType( EAknsITBitmap, type ) )
       
   471             {
       
   472             if( aDrawParam&KAknsSDMAlphaOnly )
       
   473                 {
       
   474                 // Do not draw anything
       
   475                 if ( iconPreserved )
       
   476                     {
       
   477                     AknIconUtils::DestroyIconData( bdBmp );
       
   478                     }
       
   479                 return ETrue;
       
   480                 }
       
   481 
       
   482             CAknsBitmapItemData* bmpData2 =
       
   483                 static_cast<CAknsBitmapItemData*>(aImgData);
       
   484             int m = bmpData2->Bitmap()->DisplayMode();
       
   485             aGc.BitBlt(imgDrawRect.iTl, bmpData2->Bitmap(), drawrect );
       
   486             
       
   487             }
       
   488         }
       
   489     return ETrue;
       
   490     }
       
   491 
       
   492 // ============================= LOCAL FUNCTIONS ===============================
       
   493 
       
   494 // -----------------------------------------------------------------------------
       
   495 // CachedLayoutBitmap
       
   496 //
       
   497 // Retrieves a cached masked bitmap representing particular layout item
       
   498 // (or @c NULL if not found).
       
   499 //
       
   500 // -----------------------------------------------------------------------------
       
   501 //
       
   502 CAknsImageItemData* CachedLayoutBitmap( CAknsAppSkinInstance* aSkin,
       
   503     const TAknsItemID& aIID, const TSize& /*aSize*/,
       
   504     const TSize& aLayoutSize, const TInt aLayout, TBool& aMorphingOut, const TBool& aLocalItem )
       
   505     {
       
   506     return aSkin->GetLayoutBitmap( aIID, aLayoutSize, aLayout, aMorphingOut, aLocalItem );
       
   507     }
       
   508 
       
   509 // ============================ MEMBER FUNCTIONS ===============================
       
   510 
       
   511 // -----------------------------------------------------------------------------
       
   512 // AknsScalabilityUtils::ProcessDefL
       
   513 // (commented in the header).
       
   514 // If additional handling is added - then might leave. Leave indication 'L'
       
   515 // left for future purposes.
       
   516 // -----------------------------------------------------------------------------
       
   517 //
       
   518 CAknsItemDef* AknsScalabilityUtils::ProcessDefL( CAknsItemDef* aDef )
       
   519     {
       
   520     // INSERTION POINT for any additional handling
       
   521     return aDef;
       
   522     }
       
   523 
       
   524 // -----------------------------------------------------------------------------
       
   525 // AknsScalabilityUtils::ConvertToBitmap
       
   526 // (commented in the header).
       
   527 // -----------------------------------------------------------------------------
       
   528 //
       
   529 CAknsImageItemData* AknsScalabilityUtils::ConvertToBitmap(
       
   530     CAknsAppSkinInstance* aSkin, const TAknsItemID aIID,const TAknsBackground* aLayout)
       
   531     {
       
   532     AKNS_TRACE_INFO2("AknsScalabilityUtils::ConvertToBitmap Called for item %x %x", aIID.iMajor, aIID.iMinor );
       
   533 
       
   534     //  Comment out so that client can always get image
       
   535     //  aSkin->BeginRender is used later for sync,Refer bug EHLU-7GBDRY&ESNN-7HN92G
       
   536     //if( aSkin->IsUpdateInProgress() )
       
   537     //    {
       
   538     //    AKNS_TRACE_INFO("AknsScalabilityUtils::ConvertToBitmap Update in progress, exiting immediately." );
       
   539     //    return NULL;
       
   540     //    }
       
   541 
       
   542     CAknsImageItemData* renderedData = NULL;
       
   543 
       
   544     CAknsRlMasterLayout* masterLayout = aSkin->MasterLayout();
       
   545     TInt layoutType = masterLayout->CurrentLayoutType();
       
   546     TSize layoutSize = masterLayout->CurrentLayoutSize();
       
   547     
       
   548     if (aIID == KAknsIIDQsnBgScreen && aLayout)
       
   549         {
       
   550         const TSize QvgaPrtSize = TSize(240,320);
       
   551         const TSize QhdPrtSize = TSize(360,640);
       
   552         if ( layoutSize == QvgaPrtSize && aLayout->iRect.Size() == QhdPrtSize)
       
   553             {
       
   554             //Change Compatible Qvga background to a Qhd background
       
   555             const TInt QhdLayoutType = 0x10283389;    
       
   556             layoutType = QhdLayoutType; //Qhd LayoutType
       
   557             layoutSize = QhdPrtSize;//Qhd Protrait Size
       
   558             }
       
   559         }
       
   560     aSkin->BeginRender();
       
   561 
       
   562     TRect ignored1;
       
   563     TBool ignored2;
       
   564     TBool ignored3 = EFalse;
       
   565     TRAPD( renderErr, ( renderedData=RecursiveCacheRenderL(
       
   566         aSkin, aIID, layoutType, *(masterLayout), layoutSize, ignored1, ignored2, ignored3 ) ) );
       
   567 
       
   568     aSkin->EndRender();
       
   569 
       
   570     if( renderErr )
       
   571         {
       
   572         AKNS_TRACE_ERROR1("AknsScalabilityUtils::ConvertToBitmap Rendering error %i", renderErr );
       
   573         }
       
   574 
       
   575     return renderedData;
       
   576     }
       
   577 
       
   578 // -----------------------------------------------------------------------------
       
   579 // AknsScalabilityUtils::ConcreteEffectQueue
       
   580 // (commented in the header).
       
   581 // -----------------------------------------------------------------------------
       
   582 //
       
   583 TAknsItemID AknsScalabilityUtils::ConcreteEffectQueue(
       
   584     CAknsAppSkinInstance* aSkin, const TAknsItemID& aIID )
       
   585     {
       
   586     TAknsItemID iid = aIID;
       
   587     TInt findLevel = 0;
       
   588     while( findLevel < KAknsSURecursionLimit )
       
   589         {
       
   590         // First, check whether this is a morphing element
       
   591         CAknsAnimationItemData* adata = static_cast<CAknsAnimationItemData*>(
       
   592             aSkin->GetCachedItemData( iid, EAknsITAnimation ) );
       
   593         if( adata && adata->Morphing() )
       
   594             {
       
   595             return iid;
       
   596             }
       
   597 
       
   598         // Otherwise, search for scalable item
       
   599         CAknsEffectQueueItemData* data =
       
   600             static_cast<CAknsEffectQueueItemData*>(
       
   601             aSkin->GetCachedItemData( iid, EAknsITEffectQueue ) );
       
   602         if( !data )
       
   603             {
       
   604             // Not found
       
   605             AKNS_TRACE_INFO2("AknsScalabilityUtils::ConcreteEffectQueue No data found for %x %x", iid.iMajor, iid.iMinor );
       
   606             return KAknsIIDNone;
       
   607             }
       
   608 
       
   609         TAknsItemID refIid = data->RefItem();
       
   610         if( refIid == KAknsIIDDefault )
       
   611             {
       
   612             // Concrete item
       
   613             return iid;
       
   614             }
       
   615         else
       
   616             {
       
   617             iid = refIid;
       
   618             }
       
   619         }
       
   620 
       
   621     AKNS_TRACE_ERROR2("AknsScalabilityUtils::ConcreteEffectQueue SEARCH LIMIT EXCEEDED for %x %x", aIID.iMajor, aIID.iMinor );
       
   622     return KAknsIIDNone;
       
   623     }
       
   624 
       
   625 // -----------------------------------------------------------------------------
       
   626 // AknsScalabilityUtils::GetBackwardCompatibilityColor
       
   627 // (commented in the header).
       
   628 // -----------------------------------------------------------------------------
       
   629 //
       
   630 TBool AknsScalabilityUtils::GetBackwardCompatibilityColor(
       
   631     MAknsSkinInstance* aInstance, TRgb& aRgb,
       
   632     const TAknsItemID& aID, const TInt aIndex )
       
   633     {
       
   634     CAknsColorTableItemData* colorData = static_cast<CAknsColorTableItemData*>(
       
   635         aInstance->GetCachedItemData(
       
   636         KAknsIIDQsnComponentColors, EAknsITColorTable ) );
       
   637     // If there is no old table or it's marked NBC, do not use it.
       
   638     if( (!colorData)
       
   639         || (colorData->Attributes()->iAttributes&EAknsImageAttributeNBC) )
       
   640         {
       
   641         return EFalse;
       
   642         }
       
   643 
       
   644     TInt ccIndex = KErrNotFound;
       
   645     if( aID == KAknsIIDQsnIconColors )
       
   646         {
       
   647         switch( aIndex )
       
   648             {
       
   649             case EAknsCIQsnIconColorsCG1:  // icon #1    main area; idle    status indicators    #215
       
   650                 ccIndex = EAknsCIQsnComponentColorsCG1; // #1 status indicators
       
   651                 break;
       
   652             case EAknsCIQsnIconColorsCG2:  // icon #2    status area    universal indicator pane icons    #215
       
   653             case EAknsCIQsnIconColorsCG3:  // icon #3    status area    reception off icon    #215
       
   654                 ccIndex = EAknsCIQsnComponentColorsCG3; // #3 universal status indicators
       
   655                 break;
       
   656             case EAknsCIQsnIconColorsCG4:  // icon #4    navi pane    editing state icons    #0
       
   657             case EAknsCIQsnIconColorsCG5:  // icon #5    navi pane    signal iconpacket data indications    #0
       
   658             case EAknsCIQsnIconColorsCG6:  // icon #6    navi pane    battery icon    #0
       
   659             case EAknsCIQsnIconColorsCG7:  // icon #7    navi pane    other navi pane icons (e.g. tab 1 icons)    #0
       
   660             case EAknsCIQsnIconColorsCG20: // icon #20    stacon area    universal indicator pane icons    #0
       
   661             case EAknsCIQsnIconColorsCG21: // icon #21    stacon area    reception off icon    #0
       
   662             case EAknsCIQsnIconColorsCG22: // icon #22    stacon navi pane    editing state icons    #0
       
   663             case EAknsCIQsnIconColorsCG23: // icon #23    stacon navi pane    signal iconpacket data indications    #0
       
   664             case EAknsCIQsnIconColorsCG24: // icon #24    stacon navi pane    battery icon    #0
       
   665             case EAknsCIQsnIconColorsCG25: // icon #25    stacon navi pane    other navi pane icons (e.g. tab 1 icons)    #0
       
   666                 ccIndex = EAknsCIQsnComponentColorsCG2; // #2 navi pane text, editing state icons, navi pane arrows, other navi pane icons, gprs indications, tab 1 icons
       
   667                 break;
       
   668             case EAknsCIQsnIconColorsCG8:  // icon #8    active tab    active tab icon colour    #215
       
   669                 ccIndex = EAknsCIQsnComponentColorsCG6a; // #6a tab 2 icons, tab 3 icons, tab 4 icons (active)
       
   670                 break;
       
   671             case EAknsCIQsnIconColorsCG9:  // icon #9    passive tab    passive tab icon colour    #243
       
   672                 ccIndex = EAknsCIQsnComponentColorsCG6b; // #6b tab 2 icons, tab 3 icons, tab 4 icons (passive)
       
   673                 break;
       
   674             case EAknsCIQsnIconColorsCG10: // icon #10    popup window    query editing state icons    #210
       
   675                 ccIndex = EAknsCIQsnComponentColorsCG4; // #4 query editing state icons
       
   676                 break;
       
   677             case EAknsCIQsnIconColorsCG11: // icon #11    call graphics    call status icons    #215
       
   678                 ccIndex = EAknsCIQsnComponentColorsCG5; // #5 call status icons
       
   679                 break;
       
   680             case EAknsCIQsnIconColorsCG12: // icon #12
       
   681                 // Intentionally unassigned, use default
       
   682                 break;
       
   683             case EAknsCIQsnIconColorsCG13: // icon #13    main area    additional list icons    #215
       
   684             case EAknsCIQsnIconColorsCG14: // icon #14    settings popup list    checkbox, radio button    #215
       
   685             case EAknsCIQsnIconColorsCG15: // icon #15    form popup list    checkbox, radio button    #215
       
   686             case EAknsCIQsnIconColorsCG16: // icon #16    list highlight    additional list iconsform checkbox, radio button    #215
       
   687             case EAknsCIQsnIconColorsCG17: // icon #17    grid highlight    additional list iconsgms images    #215
       
   688             case EAknsCIQsnIconColorsCG19: // icon #19    calendar views    additional list icons    #215
       
   689                 // Although there is BC item (#11), do not use it
       
   690                 // Old skins do not necessarily define correct main pane colors
       
   691                 break;
       
   692             case EAknsCIQsnIconColorsCG18: // icon #18    setting list highlight    checkbox, radio button    #0
       
   693                 // Intentionally unassigned, use default
       
   694                 break;
       
   695             }
       
   696         }
       
   697     else if( aID == KAknsIIDQsnTextColors )
       
   698         {
       
   699         switch( aIndex )
       
   700             {
       
   701             case EAknsCIQsnTextColorsCG1:  // text #1    status area    title text    #215
       
   702             case EAknsCIQsnTextColorsCG36: // text #36  status area title text in idle #215
       
   703                 ccIndex = EAknsCIQsnComponentColorsCG10; // #10 title font color
       
   704                 break;
       
   705             case EAknsCIQsnTextColorsCG2:  // text #2    navi pane    navi pane texts    #0
       
   706             case EAknsCIQsnTextColorsCG37: // text #37  stacon area title text  #0
       
   707             case EAknsCIQsnTextColorsCG38: // text #38  stacon area title text in idle #0
       
   708             case EAknsCIQsnTextColorsCG39: // text #39  stacon area top softkey text    #0
       
   709             case EAknsCIQsnTextColorsCG40: // text #40  stacon area bottom softkey text    #0
       
   710             case EAknsCIQsnTextColorsCG41: // text #41  stacon area top softkey text in idle #0
       
   711             case EAknsCIQsnTextColorsCG42: // text #42  stacon area bottom softkey text in idle #0
       
   712             case EAknsCIQsnTextColorsCG43: // text #43  stacon navi pane text   #0
       
   713                 ccIndex = EAknsCIQsnComponentColorsCG2; // #2 navi pane text, editing state icons, navi pane arrows, other navi pane icons, gprs indications, tab 1 icons
       
   714                 break;
       
   715             case EAknsCIQsnTextColorsCG3:  // text #3    active tab    active tab text    #215
       
   716                 ccIndex = EAknsCIQsnComponentColorsCG6a; // #6a tab 2 icons, tab 3 icons, tab 4 icons (active)
       
   717                 break;
       
   718             case EAknsCIQsnTextColorsCG4:  // text #4    passive tab    passive tab text    #243
       
   719                 ccIndex = EAknsCIQsnComponentColorsCG6b; // #6b tab 2 icons, tab 3 icons, tab 4 icons (passive)
       
   720                 break;
       
   721             case EAknsCIQsnTextColorsCG5:  // text #5    power save state    time/date power save text    #0
       
   722                 // Intentionally unassigned, use default
       
   723                 break;
       
   724             case EAknsCIQsnTextColorsCG6:  // text #6    main area    main area texts    #215
       
   725             case EAknsCIQsnTextColorsCG7:  // text #7    settings popup list    settings list item text    #215
       
   726             case EAknsCIQsnTextColorsCG8:  // text #8    form popup listform input field    form list item textform data entry text    #215
       
   727             case EAknsCIQsnTextColorsCG9:  // text #9    application grid    unfocused application title texts     #215
       
   728             case EAknsCIQsnTextColorsCG10: // text #10    list highlight    list texts    #215
       
   729             case EAknsCIQsnTextColorsCG11: // text #11    grid highlight    grid text     #215
       
   730             case EAknsCIQsnTextColorsCG22: // text #22    calendar month viewcalendar day view    active month day numbersday view list items    #215
       
   731             case EAknsCIQsnTextColorsCG23: // text #23    calendar month viewcalendar week view    day abbreviationshoursweek numbers    #215
       
   732             case EAknsCIQsnTextColorsCG33: // text #33    pinboard/list view    item title    #215
       
   733             case EAknsCIQsnTextColorsCG35: // text #35  active idle text    #215
       
   734                 // Although there are BC item (#11, #14, #15), do not use them
       
   735                 // Old skins do not necessarily define correct main pane colors
       
   736                 break;
       
   737             case EAknsCIQsnTextColorsCG12: // text #12    settings popup list highlight;settings list item value box    settings value item text    #0
       
   738                 // Intentionally unassigned, use default
       
   739                 break;
       
   740             case EAknsCIQsnTextColorsCG13: // text #13    control pane general    left softkey text    #215
       
   741             case EAknsCIQsnTextColorsCG14: // text #14    control pane general    right softkey text    #215
       
   742             case EAknsCIQsnTextColorsCG15: // text #15    control pane idle    left softkey text    #215
       
   743             case EAknsCIQsnTextColorsCG16: // text #16  control pane idle    right softkey text    #215
       
   744             case EAknsCIQsnTextColorsCG17: // text #17    control pane popup windows    left softkey text    #215
       
   745             case EAknsCIQsnTextColorsCG18: // text #18    control pane popup windows    right softkey text    #215
       
   746                 ccIndex = EAknsCIQsnComponentColorsCG12; // #12 softkey texts
       
   747                 break;
       
   748             case EAknsCIQsnTextColorsCG19: // text #19    popup windows    popup windows text    #215
       
   749             case EAknsCIQsnTextColorsCG20: // text #20    submenu popup windows    submenu texts    #215
       
   750                 ccIndex = EAknsCIQsnComponentColorsCG13; // #13 popup windows text
       
   751                 break;
       
   752             case EAknsCIQsnTextColorsCG21: // text #21    calendar month view    passive month day numbers    #221
       
   753                 ccIndex = EAknsCIQsnComponentColorsCG16; // #16 calendar month view passive month numbers
       
   754                 break;
       
   755             case EAknsCIQsnTextColorsCG24: // text #24    cut/copy/paste highlight    copied text    #0
       
   756                 // Intentionally unassigned, use default
       
   757                 break;
       
   758             case EAknsCIQsnTextColorsCG25: // text #25    find pane    search string text    #215
       
   759             case EAknsCIQsnTextColorsCG26: // text #26    settings input field    setting text entry    #215
       
   760             case EAknsCIQsnTextColorsCG27: // text #27    query input field    query text entry    #215
       
   761             case EAknsCIQsnTextColorsCG32: // text #32    pinboard input field    item title/find string    #215
       
   762                 ccIndex = EAknsCIQsnComponentColorsCG18; // #18 search string text, text input, code/date/time entry
       
   763                 break;
       
   764             case EAknsCIQsnTextColorsCG28: // text #28    power save mode    time/date shadow text    #215
       
   765                 // Intentionally unassigned, use default
       
   766                 break;
       
   767             case EAknsCIQsnTextColorsCG29: // text #29    calculator paper     operator/operand    #215
       
   768                 // Intentionally unassigned, use default
       
   769                 break;
       
   770             case EAknsCIQsnTextColorsCG30: // text #30    calculator display    result    #210
       
   771                 // Intentionally unassigned, use default
       
   772                 break;
       
   773             case EAknsCIQsnTextColorsCG31: // text #31  calculator display    result shadow    #219
       
   774                 // Intentionally unassigned, use default
       
   775                 break;
       
   776             case EAknsCIQsnTextColorsCG34: // text #34    notepad    note text    #215
       
   777                 // Intentionally unassigned, use default
       
   778                 break;
       
   779             }
       
   780         }
       
   781     else if( aID == KAknsIIDQsnLineColors )
       
   782         {
       
   783         switch( aIndex )
       
   784             {
       
   785             case EAknsCIQsnLineColorsCG1: // line #1    calendar day/week/month view    lines     #215
       
   786             case EAknsCIQsnLineColorsCG3: // line #3    heading pane    heading pane separator line    #215
       
   787             case EAknsCIQsnLineColorsCG6: // line #6    lists    column separator lines    #215
       
   788             case EAknsCIQsnLineColorsCG7: // line #7    setting list    column separator lines    #215
       
   789                 ccIndex = EAknsCIQsnComponentColorsCG7; // #7 separator lines, primary separator lines
       
   790                 break;
       
   791             case EAknsCIQsnLineColorsCG2: // line #2    calendar day/week/month view    lines     #221
       
   792             case EAknsCIQsnLineColorsCG4: // line #4    main pane    grid cell separator lines    #221
       
   793             case EAknsCIQsnLineColorsCG5: // line #5    popup windows    grid cell separator lines    #221
       
   794             case EAknsCIQsnLineColorsCG11: // line #11    popup     separator line in options menu    #221
       
   795                 ccIndex = EAknsCIQsnComponentColorsCG8; // #8 separator lines, secondary separator lines
       
   796                 break;
       
   797             case EAknsCIQsnLineColorsCG8: // line #8    form    slider line     #215
       
   798             case EAknsCIQsnLineColorsCG9: // line #9    settings list    value item slider line    #215
       
   799             case EAknsCIQsnLineColorsCG10: // line #10    opened settings list    value item slider line    #215
       
   800                 // Intentionally unassigned, use default
       
   801                 break;
       
   802             }
       
   803         }
       
   804     else if( aID == KAknsIIDQsnOtherColors )
       
   805         {
       
   806         switch( aIndex )
       
   807             {
       
   808             case EAknsCIQsnOtherColorsCG1: // other #1    calendar week view    public event    #35
       
   809                 ccIndex = EAknsCIQsnComponentColorsCG20; // #20 public event
       
   810                 break;
       
   811             case EAknsCIQsnOtherColorsCG2: // other #2    calendar week view    private event    #210
       
   812                 ccIndex = EAknsCIQsnComponentColorsCG21; // #21 private event
       
   813                 break;
       
   814             case EAknsCIQsnOtherColorsCG3: // other #3    calendar week view    not synchronized event    #35 dimmed
       
   815                 ccIndex = EAknsCIQsnComponentColorsCG22; // #22 not synchronized event
       
   816                 break;
       
   817             case EAknsCIQsnOtherColorsCG4: // other #4    calendar week view    2 or more events overlapping    #215
       
   818                 ccIndex = EAknsCIQsnComponentColorsCG23; // #23 2 or more events overlapping
       
   819                 break;
       
   820             case EAknsCIQsnOtherColorsCG5: // other #5    calendar month view    event indication on focused month    #215
       
   821             case EAknsCIQsnOtherColorsCG6: // other #6    calendar month view    event indication on unfocused month    #221
       
   822                 // Intentionally unassigned, use default
       
   823                 break;
       
   824             }
       
   825         }
       
   826     else if( aID == KAknsIIDQsnHighlightColors )
       
   827         {
       
   828         switch( aIndex )
       
   829             {
       
   830             case EAknsCIQsnHighlightColorsCG1: // highlight #1    link highlight     browser link highlight colour; japanese fep predictive candidate indication;automatic find item indcation    #244
       
   831                 // Intentionally unassigned, use default
       
   832                 break;
       
   833             case EAknsCIQsnHighlightColorsCG2: // highlight #2    cut/copy/paste     cut/copy/paste highlight    #210
       
   834                 ccIndex = EAknsCIQsnComponentColorsCG17; // #17 input, text entry
       
   835                 break;
       
   836             case EAknsCIQsnHighlightColorsCG3: // highlight #3    link indication    link text and underline indication    #210
       
   837                 // Intentionally unassigned, use default
       
   838                 break;
       
   839             }
       
   840         }
       
   841 
       
   842     if( ccIndex >= 0 )
       
   843         {
       
   844         TRAPD( err, colorData->GetColorL( ccIndex, aRgb ) );
       
   845         if( err == KErrNone )
       
   846             {
       
   847             return ETrue;
       
   848             }
       
   849         }
       
   850 
       
   851     return EFalse;
       
   852     }
       
   853 
       
   854 // -----------------------------------------------------------------------------
       
   855 // AknsScalabilityUtils::RecursiveCacheRenderL
       
   856 // (commented in the header).
       
   857 // -----------------------------------------------------------------------------
       
   858 //
       
   859 CAknsImageItemData* AknsScalabilityUtils::RecursiveCacheRenderL(
       
   860     CAknsAppSkinInstance* aSkin, const TAknsItemID aIID,
       
   861     const TInt aLayoutType,
       
   862     CAknsRlMasterLayout& aLayoutMaster, const TSize& aLayoutSize, TRect& aRectOut, TBool& aMorphingOut, TBool& aLocalItem )
       
   863     {
       
   864     AKNS_TRACE_INFO2("AknsScalabilityUtils::RecursiveCacheRenderL (START) Rendering %x %x", aIID.iMajor, aIID.iMinor );
       
   865 
       
   866     if ( aIID == KAknsIIDWallpaper ) 
       
   867         {
       
   868         aSkin->ReleaseItem( KAknsIIDWallpaper );	
       
   869         }
       
   870 
       
   871     CAknsItemDef* itemToFind = NULL;
       
   872 
       
   873     if (aSkin->iLocalItemDefArray.Count() && !aLocalItem )
       
   874         {
       
   875         TInt index = 0;
       
   876 
       
   877         itemToFind = CAknsItemDef::NewL( aIID );
       
   878         if( (aSkin->iLocalItemDefArray.FindInOrder( itemToFind, index,
       
   879                 CAknsItemDef::LinearOrder ) == KErrNone) )
       
   880             {
       
   881             aLocalItem = ETrue;
       
   882             }
       
   883         delete itemToFind;
       
   884         }
       
   885 
       
   886     TBool morphing( EFalse );
       
   887 
       
   888     TAknsItemID thisIid = ConcreteEffectQueue( aSkin, aIID );
       
   889     TBool hasData( ETrue );
       
   890     if( thisIid == KAknsIIDNone )
       
   891         {
       
   892         AKNS_TRACE_INFO2("AknsScalabilityUtils::RecursiveCacheRenderL No concrete item found for %x %x", aIID.iMajor, aIID.iMinor );
       
   893         hasData = EFalse;
       
   894         thisIid = aIID;
       
   895         }
       
   896 
       
   897 
       
   898     TAknsItemID parent = aLayoutMaster.GetParent( thisIid );
       
   899     TRect parentRect;
       
   900     CAknsImageItemData* parentData = NULL;
       
   901 
       
   902     if( parent == KAknsIIDDefault )
       
   903         {
       
   904         // Item can not be rendered (no definite parent)
       
   905         AKNS_TRACE_ERROR2("AknsScalabilityUtils::RecursiveCacheRenderL Can not render, no parent for %x %x", thisIid.iMajor, thisIid.iMinor );
       
   906         User::Leave( KAknsSURErrNoParent );
       
   907         }
       
   908     else if( parent != KAknsIIDNone )
       
   909         {
       
   910         TBool parentMorphing( EFalse );
       
   911         parentData = RecursiveCacheRenderL( aSkin, parent, aLayoutType,
       
   912             aLayoutMaster, aLayoutSize, parentRect, parentMorphing, aLocalItem );
       
   913         if( parentMorphing ) morphing = ETrue;
       
   914         }
       
   915     else
       
   916         {
       
   917         // Root element (KAknsIIDNone)
       
   918         parentRect = TRect(0,0,KMaxTInt,KMaxTInt);
       
   919         if( !hasData )
       
   920             {
       
   921             AKNS_TRACE_ERROR2("AknsScalabilityUtils::RecursiveCacheRenderL Root element has no data %x %x", thisIid.iMajor, thisIid.iMinor );
       
   922             User::Leave( KAknsSURErrNoData );
       
   923             }
       
   924         }
       
   925 
       
   926     // First get the layout
       
   927 
       
   928     TRect rect;
       
   929     if( aLayoutMaster.GetItemLayout( thisIid, parentRect, rect ) == EFalse )
       
   930         {
       
   931         AKNS_TRACE_ERROR2("AknsScalabilityUtils::RecursiveCacheRenderL Can not render, no layout for %x %x", thisIid.iMajor, thisIid.iMinor );
       
   932         User::Leave( KAknsSURErrNoLayout );
       
   933         }
       
   934     aRectOut = rect;
       
   935 
       
   936     // If already rendered, nothing further to do
       
   937     TBool bitmapMorphing( EFalse );
       
   938     CAknsImageItemData* existingData = CachedLayoutBitmap( aSkin, thisIid,
       
   939         rect.Size(), aLayoutSize, aLayoutType, bitmapMorphing, aLocalItem );
       
   940     if( bitmapMorphing ) morphing = ETrue;
       
   941     if( existingData )
       
   942         {
       
   943         aMorphingOut = morphing;
       
   944         return existingData;
       
   945         }
       
   946 
       
   947     // Otherwise, start rendering
       
   948 
       
   949     CAknsMaskedBitmapItemData* thisData = CAknsMaskedBitmapItemData::NewL();
       
   950     CleanupStack::PushL( thisData ); // (1)
       
   951 
       
   952      // if this item is "empty" and parent has data
       
   953     if (!hasData && parentData)
       
   954         {
       
   955         // parent is the root element, or
       
   956         // parent has rendered itself
       
   957         if (parentData->ParentIID() == KAknsIIDNone)
       
   958             {
       
   959             thisData->SetDrawRect(aRectOut);
       
   960             thisData->SetParentIID(parent);
       
   961             }
       
   962         else
       
   963             {
       
   964             if (parentRect.iTl != TPoint(0,0) && aRectOut.iTl == TPoint(0,0))
       
   965                 {
       
   966                 thisData->SetDrawRect(TRect(parentRect.iTl,aRectOut.Size()));
       
   967                 }
       
   968             else
       
   969                 {
       
   970                 thisData->SetDrawRect(aRectOut);
       
   971                 }
       
   972             thisData->SetParentIID(parentData->ParentIID());
       
   973             }
       
   974         thisData->SetBitmap(NULL);
       
   975         thisData->SetMask(NULL);
       
   976 
       
   977         TAknsImageAttributeData attributes;
       
   978         attributes.iAttributes = EAknsImageAttributeNBC;
       
   979         thisData->SetAttributesL( attributes );
       
   980         CleanupStack::Pop( thisData );
       
   981         aSkin->AddLayoutBitmapL( thisIid, thisData, aLayoutType, aLayoutSize, morphing, aLocalItem );
       
   982         // Skin instance may choose to re-create the item, thus re-fetch
       
   983         aMorphingOut = morphing;
       
   984         return CachedLayoutBitmap( aSkin, thisIid, rect.Size(),
       
   985             aLayoutSize, aLayoutType, morphing, aLocalItem );
       
   986         }
       
   987 
       
   988     CAknsEffectQueueItemData* queue = NULL;
       
   989     TBool queueOwned( EFalse );
       
   990     if( hasData )
       
   991         {
       
   992         queue = static_cast<CAknsEffectQueueItemData*>(
       
   993             aSkin->GetCachedItemData( thisIid, EAknsITEffectQueue ) );
       
   994         if( !queue )
       
   995             {
       
   996             // If no queue exists, if may be a morphing item
       
   997             CAknsAnimationItemData* animation = NULL;
       
   998             animation = static_cast<CAknsAnimationItemData*>(
       
   999                 aSkin->GetCachedItemData( thisIid, EAknsITAnimation ) );
       
  1000             if( animation && animation->Morphing() )
       
  1001                 {
       
  1002                 // Fetch timestamp
       
  1003                 TTime timeStamp;
       
  1004                 CAknsStringItemData* ttData =
       
  1005                     static_cast<CAknsStringItemData*>(
       
  1006                     aSkin->CreateUncachedItemDataL(
       
  1007                     KAknsIIDPropertyMorphingTime, EAknsITString ) );
       
  1008                 CleanupStack::PushL( ttData );
       
  1009                 if( ttData )
       
  1010                     {
       
  1011                     const TUint* hiPtr = reinterpret_cast<const TUint*>(ttData->String().Ptr());
       
  1012                     const TUint* loPtr = hiPtr+1;
       
  1013                     timeStamp = MAKE_TINT64( *hiPtr, *loPtr );
       
  1014                     }
       
  1015                 else
       
  1016                     {
       
  1017                     // In case the server did not update timestamp, use hometime
       
  1018                     timeStamp.HomeTime();
       
  1019                     }
       
  1020                 CleanupStack::PopAndDestroy( ttData );
       
  1021 
       
  1022                 // Convert to queue
       
  1023                 queue = AknsAlConversionUtil::AnimationToEffectQueueL( *animation, timeStamp );
       
  1024 
       
  1025                 // Queue is now owned by us
       
  1026                 CleanupStack::PushL( queue );
       
  1027                 queueOwned = ETrue;
       
  1028 
       
  1029                 morphing = ETrue;
       
  1030                 }
       
  1031             }
       
  1032 
       
  1033         if( !queue )
       
  1034             {
       
  1035             // Still no data, abort
       
  1036             AKNS_TRACE_ERROR2("AknsScalabilityUtils::RecursiveCacheRenderL Existing data vanished %x %x", thisIid.iMajor, thisIid.iMinor );
       
  1037             User::Leave( KAknsSURErrNoData );
       
  1038             }
       
  1039         }
       
  1040 
       
  1041     MAknsRlRenderer* renderer = aSkin->DefaultRenderer();
       
  1042 
       
  1043     CFbsBitmap* bitmap = NULL;
       
  1044     CFbsBitmap* alpha = NULL;
       
  1045 
       
  1046     MAknsRlCommandIterator* commands = NULL;
       
  1047     TInt inputLayer = 0;
       
  1048     TInt outputLayer = 0;
       
  1049     if( hasData )
       
  1050         {
       
  1051         commands = queue->CreateCommandIteratorL();
       
  1052         inputLayer = queue->InputLayer();
       
  1053         outputLayer = queue->OutputLayer();
       
  1054         }
       
  1055     CleanupStack::PushL( TCleanupItem(
       
  1056         MAknsRlCommandIterator::CleanupOperation, commands ) ); // (2)
       
  1057 
       
  1058     CFbsBitmap* parentBitmap = NULL;
       
  1059     CFbsBitmap* parentAlpha = NULL;
       
  1060     CAknsImageItemData* realParent = parentData;
       
  1061     TRect realRect = rect;
       
  1062     if (parentData&& parentData->ParentIID() != KAknsIIDNone)
       
  1063         {
       
  1064         realParent = CachedLayoutBitmap( aSkin, parentData->ParentIID(), rect.Size(),
       
  1065             aLayoutSize, aLayoutType, morphing, aLocalItem );
       
  1066         if (!realParent)
       
  1067             {
       
  1068             TAknsItemID concreteiid = ConcreteEffectQueue( aSkin, parentData->ParentIID() );
       
  1069             realParent = CachedLayoutBitmap( aSkin, concreteiid, rect.Size(),
       
  1070                 aLayoutSize, aLayoutType, morphing, aLocalItem );
       
  1071             }
       
  1072         if (hasData)
       
  1073             {
       
  1074             if (realParent && realParent->ParentIID() == KAknsIIDNone && aRectOut.iTl == TPoint(0,0))
       
  1075                 {
       
  1076                 realRect = parentRect;
       
  1077                 }
       
  1078             if (inputLayer >= 0 && parentData->ParentIID() != KAknsIIDNone)
       
  1079                 {
       
  1080                 // input layer present and the parent is not a root element,
       
  1081                 // need to adjust the realrect
       
  1082                 if (realRect.iTl != parentRect.iTl)
       
  1083                     {
       
  1084                     realRect.iTl.iY+=parentRect.iTl.iY;
       
  1085                     realRect.iBr.iY+=parentRect.iTl.iY;
       
  1086                     }
       
  1087                 }
       
  1088             }
       
  1089         }
       
  1090     // Bitmap and mask is being created, no leaves allowed
       
  1091     if( realParent &&
       
  1092         AknsUtils::IsDerivedType( EAknsITBitmap, realParent->Type() ) )
       
  1093         {
       
  1094         parentBitmap = static_cast<CAknsBitmapItemData*>(
       
  1095             realParent)->Bitmap();
       
  1096         if( AknsUtils::IsDerivedType( EAknsITMaskedBitmap, realParent->Type() ) )
       
  1097             {
       
  1098             parentAlpha = static_cast<CAknsMaskedBitmapItemData*>(
       
  1099                 realParent)->Mask();
       
  1100             }
       
  1101         TInt rendererErr = renderer->RenderItemWithBackground(
       
  1102             bitmap, alpha, outputLayer, commands, rect.Size(),
       
  1103             parentBitmap, parentAlpha, realRect, inputLayer );
       
  1104         if( rendererErr )
       
  1105             {
       
  1106             AKNS_TRACE_ERROR3("AknScalabilityUtils::RecursiveCacheRenderL Renderer (RIWB) for %x %x exited with ERROR %i", thisIid.iMajor, thisIid.iMinor, rendererErr );
       
  1107             User::Leave( rendererErr );
       
  1108             }
       
  1109         }
       
  1110     else
       
  1111         {
       
  1112         // Root element
       
  1113         TInt rendererErr = renderer->RenderItem(
       
  1114             bitmap, alpha,
       
  1115             outputLayer, commands, rect.Size() );
       
  1116         if( rendererErr )
       
  1117             {
       
  1118             AKNS_TRACE_ERROR3("AknScalabilityUtils::RecursiveCacheRenderL Renderer (RI) for %x %x exited with ERROR %i", thisIid.iMajor, thisIid.iMinor, rendererErr );
       
  1119             User::Leave( rendererErr );
       
  1120             }
       
  1121         }
       
  1122 
       
  1123     thisData->DestroyAndSetBitmap( bitmap );
       
  1124     thisData->DestroyAndSetMask( alpha );
       
  1125     // Leaves are OK after this point
       
  1126 
       
  1127     CleanupStack::PopAndDestroy(1); // commands (1)
       
  1128 
       
  1129     // Adjust data according to queue setup
       
  1130     if( hasData )
       
  1131         {
       
  1132         switch( queue->OutputLayerMode() )
       
  1133             {
       
  1134             case KAknsRlLayerRGBA:
       
  1135                 // Do nothing
       
  1136                 AKNS_TRACE_INFO("AknsScalabilityUtils::RecursiveCacheRenderL No adjustment necessary");
       
  1137                 break;
       
  1138             case KAknsRlLayerRGBOnly:
       
  1139                 // Drop alpha
       
  1140                 thisData->DestroyAndSetMask( NULL );
       
  1141                 AKNS_TRACE_INFO("AknsScalabilityUtils::RecursiveCacheRenderL Alpha-output dropped");
       
  1142                 break;
       
  1143             default:
       
  1144                 AKNS_TRACE_ERROR1("AknsScalabilityUtils::RecursiveCacheRenderL Invalid output mode %i", queue->OutputLayerMode() );
       
  1145                 break;
       
  1146             }
       
  1147         }
       
  1148     else
       
  1149         {
       
  1150         // No data, but parent exists (with bitmap but no mask)
       
  1151         if( realParent && parentBitmap && (!parentAlpha) )
       
  1152             {
       
  1153             // Drop alpha
       
  1154             thisData->DestroyAndSetMask( NULL );
       
  1155             AKNS_TRACE_INFO("AknsScalabilityUtils::RecursiveCacheRenderL Fall-through alpha-output dropped");
       
  1156             }
       
  1157         else
       
  1158             {
       
  1159             AKNS_TRACE_INFO("AknsScalabilityUtils::RecursiveCacheRenderL No fall-through adjustment necessary");
       
  1160             }
       
  1161         }
       
  1162 
       
  1163     // Post-processing, only if compression is defined
       
  1164     AknIconConfig::CompressIfPreferred(thisData->Bitmap(), thisData->Mask());
       
  1165 
       
  1166     // Disable backward compatibility, size should be already correct
       
  1167     TAknsImageAttributeData attributes;
       
  1168     attributes.iAttributes = EAknsImageAttributeNBC;
       
  1169     thisData->SetAttributesL( attributes );
       
  1170 
       
  1171     // Destroy owned queue, if any
       
  1172     if( queueOwned )
       
  1173         {
       
  1174         CleanupStack::PopAndDestroy( queue );
       
  1175         }
       
  1176 
       
  1177     // Ownership transfer
       
  1178     CleanupStack::Pop( thisData ); // thisData (0)
       
  1179     aSkin->AddLayoutBitmapL( thisIid, thisData, aLayoutType, aLayoutSize, morphing, aLocalItem );
       
  1180 
       
  1181     // Skin instance may choose to re-create the item, thus re-fetch
       
  1182     aMorphingOut = morphing;
       
  1183     return CachedLayoutBitmap( aSkin, thisIid, rect.Size(),
       
  1184         aLayoutSize, aLayoutType, morphing, aLocalItem );
       
  1185     }
       
  1186 
       
  1187 //  End of File