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