skins/AknSkins/srvsrc/AknsSrvWallpaperCache.cpp
branchRCL_3
changeset 58 a2f9480e2280
parent 45 6ef40bf8fd34
child 106 e4e3998ddda2
equal deleted inserted replaced
55:33ddb261ab37 58:a2f9480e2280
    59 * Add a image to wallpaper cache
    59 * Add a image to wallpaper cache
    60 */
    60 */
    61 TAknsSrvWallpaper* CAknsSrvWallpaperCache::AddL( RFs& aRFs, const TDesC& aFileName, 
    61 TAknsSrvWallpaper* CAknsSrvWallpaperCache::AddL( RFs& aRFs, const TDesC& aFileName, 
    62         const TSize aTrgSize, const TSize aMaxSize )
    62         const TSize aTrgSize, const TSize aMaxSize )
    63     {
    63     {
    64     
       
    65     if ( aFileName.Length() == 0 )
    64     if ( aFileName.Length() == 0 )
    66         {
    65         {
    67         return NULL;
    66         return NULL;
    68         }
    67         }
    69     	
    68     	
    71         {
    70         {
    72         TryDecodeImageL( aRFs,aFileName );
    71         TryDecodeImageL( aRFs,aFileName );
    73         return NULL;
    72         return NULL;
    74         }
    73         }
    75     
    74     
    76     TBool cached = EFalse;
       
    77     TAknsSrvWallpaper* wp = NULL;
    75     TAknsSrvWallpaper* wp = NULL;
    78     
       
    79     wp = CachedImage( aFileName );
    76     wp = CachedImage( aFileName );
    80     if ( !wp )
    77     if ( wp )
    81         {
    78         {
    82         wp = new ( ELeave ) TAknsSrvWallpaper;
    79         return wp;
    83         ZeroItem ( *wp );
    80         }
    84         CleanupStack::PushL( wp );
    81 
    85         }
    82     wp = new ( ELeave ) TAknsSrvWallpaper;
    86     else
    83     ZeroItem ( *wp );
    87         {
    84     CleanupStack::PushL( wp );
    88         cached = ETrue;
       
    89         }
       
    90 
    85 
    91     
    86     
    92     _LIT( KSvgFileExt, ".svg" );
    87     _LIT( KSvgFileExt, ".svg" );
    93     TBool isSvgFormat = aFileName.Right(4).CompareF( KSvgFileExt ) == 0;
    88     TBool isSvgFormat = aFileName.Right(4).CompareF( KSvgFileExt ) == 0;
    94     
    89     
    95     TBool needDecodePortrait = EFalse;
    90     TSize prtSize, lscSize;
    96     TBool needDecodeLandscape = EFalse;    
       
    97 
    91 
    98     if( aTrgSize.iHeight >= aTrgSize.iWidth ) //Portait
    92     if( aTrgSize.iHeight >= aTrgSize.iWidth ) //Portait
    99         {
    93         {
   100         if ( aTrgSize != iPrtSize || ( !wp->iPortrait && !wp->iPortraitMask) )
    94         prtSize = aTrgSize;
   101             {
    95         lscSize = TSize( aTrgSize.iHeight, aTrgSize.iWidth );
   102             needDecodePortrait = ETrue;
       
   103             iPrtSize = aTrgSize;
       
   104             }
       
   105         }
    96         }
   106     else //Landscape
    97     else //Landscape
   107         {
    98         {
   108         if ( aTrgSize != iLscSize || ( !wp->iLandscape && !wp->iLandscapeMask ) )
    99         prtSize = TSize( aTrgSize.iHeight, aTrgSize.iWidth );
   109             {
   100         lscSize = aTrgSize;
   110             needDecodeLandscape = ETrue;
       
   111             iLscSize = aTrgSize;
       
   112             }
       
   113         }
   101         }
   114     
   102     
   115     if( isSvgFormat )   
   103     if( isSvgFormat )   
   116         {
   104         {
   117         if( needDecodePortrait )
   105         CAknsSrvSVGImageDecoder* svgdecoder = CAknsSrvSVGImageDecoder::NewL();
   118             {
   106         CleanupStack::PushL( svgdecoder );
   119             CAknsSrvSVGImageDecoder* svgdecoder = CAknsSrvSVGImageDecoder::NewL();
   107         svgdecoder->DecodeImageL( aFileName, prtSize, wp->iPortrait,
   120             CleanupStack::PushL( svgdecoder );
   108             wp->iPortraitMask );
   121             svgdecoder->DecodeImageL(
   109         svgdecoder->DecodeImageL( aFileName, lscSize, wp->iLandscape,
   122                 aFileName,
   110             wp->iLandscapeMask );
   123                 aTrgSize,
   111         CleanupStack::PopAndDestroy( svgdecoder );
   124                 wp->iPortrait,
       
   125                 wp->iPortraitMask );
       
   126             CleanupStack::PopAndDestroy( svgdecoder );
       
   127             }
       
   128         if( needDecodeLandscape )
       
   129             {
       
   130             CAknsSrvSVGImageDecoder* svgdecoder = CAknsSrvSVGImageDecoder::NewL();
       
   131             CleanupStack::PushL( svgdecoder );
       
   132             svgdecoder->DecodeImageL(
       
   133                 aFileName,
       
   134                 aTrgSize,
       
   135                 wp->iLandscape,
       
   136                 wp->iLandscapeMask );
       
   137             CleanupStack::PopAndDestroy( svgdecoder );
       
   138             }
       
   139         }
   112         }
   140     else
   113     else
   141         {
   114         {
   142         if( needDecodePortrait )
   115         CAknsSrvImageConverter::DecodeImageL( aRFs, aFileName, prtSize,
   143             {
   116             wp->iPortrait, wp->iPortraitMask, aMaxSize );
   144             CAknsSrvImageConverter::DecodeImageL(
   117         CAknsSrvImageConverter::DecodeImageL( aRFs, aFileName, lscSize,
   145                 aRFs,
   118             wp->iLandscape, wp->iLandscapeMask, aMaxSize );
   146                 aFileName,
   119         }
   147                 aTrgSize,
   120 
   148                 wp->iPortrait,
       
   149                 wp->iPortraitMask,
       
   150                 aMaxSize );
       
   151             }
       
   152         if( needDecodeLandscape )
       
   153             {
       
   154             CAknsSrvImageConverter::DecodeImageL(
       
   155                 aRFs,
       
   156                 aFileName,
       
   157                 aTrgSize,
       
   158                 wp->iLandscape,
       
   159                 wp->iLandscapeMask,
       
   160                 aMaxSize );
       
   161             }
       
   162         }
       
   163     wp->iName.Copy( aFileName );
   121     wp->iName.Copy( aFileName );
   164     if ( !cached )
   122 
   165         {
   123     RemoveOldestItem();
   166         RemoveOldestItem();        
   124     iCache.Append( wp );
   167         iCache.Append( wp );
   125     CleanupStack::Pop( wp ); 
   168         CleanupStack::Pop( wp ); 
   126 
   169         }
       
   170     return wp;
   127     return wp;
   171     }
   128     }
   172 
   129 
   173 /**
   130 /**
   174 * Try Decode image
   131 * Try Decode image