src/hbservers/hbthemeserver/hbthemeserver_symbian.cpp
changeset 21 4633027730f5
parent 7 923ff622b8b9
child 23 e6ad4ef83b23
equal deleted inserted replaced
7:923ff622b8b9 21:4633027730f5
    52 #include "hbmemoryutils_p.h"
    52 #include "hbmemoryutils_p.h"
    53 #include "hbdeviceprofiledatabase_p.h"
    53 #include "hbdeviceprofiledatabase_p.h"
    54 #include "hbthemesystemeffect_p.h"
    54 #include "hbthemesystemeffect_p.h"
    55 #ifdef HB_SGIMAGE_ICON
    55 #ifdef HB_SGIMAGE_ICON
    56 #include "hbsgimagerenderer_p.h"
    56 #include "hbsgimagerenderer_p.h"
       
    57 #include <sgresource/sgerror.h>
    57 #endif
    58 #endif
    58 // 5 MB GPU cache size
    59 // 5 MB GPU cache size
    59 #define GPU_CACHE_SIZE 0x500000
    60 #define GPU_CACHE_SIZE 0x500000
    60 
    61 
    61 // 5 MB  CPU cache size
    62 // 5 MB  CPU cache size
    63 
    64 
    64 static const TInt KThemeName = 0;
    65 static const TInt KThemeName = 0;
    65 
    66 
    66 const QString KOperatorCPath = "C:/resource/hb/prioritytheme/icons/";
    67 const QString KOperatorCPath = "C:/resource/hb/prioritytheme/icons/";
    67 const QString KOperatorZPath = "Z:/resource/hb/prioritytheme/icons/";
    68 const QString KOperatorZPath = "Z:/resource/hb/prioritytheme/icons/";
       
    69 const QString KBaseThemePath = "z:/resource/hb/";
    68 
    70 
    69 bool HbThemeServerPrivate::gpuGoodMemoryState = true;
    71 bool HbThemeServerPrivate::gpuGoodMemoryState = true;
    70 // This is used as parent theme always regardless of the active theme
    72 // This is used as parent theme always regardless of the active theme
    71 
    73 
    72 //**********************************
    74 //**********************************
   110     QDir path(currentTheme);
   112     QDir path(currentTheme);
   111     iCurrentThemeName = path.dirName();
   113     iCurrentThemeName = path.dirName();
   112     iCurrentThemePath = path.absolutePath();
   114     iCurrentThemePath = path.absolutePath();
   113 
   115 
   114     cache = 0;
   116     cache = 0;
   115     cssCache = 0;
       
   116 
   117 
   117     QT_TRY {
   118     QT_TRY {
   118         //Create the Icon cache
   119         //Create the Icon cache
   119         cache = new HbIconDataCache();
   120         cache = new HbIconDataCache();
   120         //Create the CSS cache
       
   121         cssCache = new HbCache();
       
   122     } QT_CATCH(const std::bad_alloc &badalloc) {
   121     } QT_CATCH(const std::bad_alloc &badalloc) {
   123         delete cache;
   122         delete cache;
   124         delete cssCache;
       
   125         qt_symbian_exception2LeaveL(badalloc);
   123         qt_symbian_exception2LeaveL(badalloc);
   126     }
   124     }
   127     setMaxGpuCacheSize(GPU_CACHE_SIZE);
   125     setMaxGpuCacheSize(GPU_CACHE_SIZE);
   128     setMaxCpuCacheSize(CPU_CACHE_SIZE);
   126     setMaxCpuCacheSize(CPU_CACHE_SIZE);
   129 #if defined(HB_SGIMAGE_ICON) || defined(HB_NVG_CS_ICON)
   127 #if defined(HB_SGIMAGE_ICON) || defined(HB_NVG_CS_ICON)
   210 Destructor
   208 Destructor
   211  */
   209  */
   212 HbThemeServerPrivate::~HbThemeServerPrivate()
   210 HbThemeServerPrivate::~HbThemeServerPrivate()
   213 {
   211 {
   214     delete cache;
   212     delete cache;
   215     delete cssCache;
       
   216     cache = 0;      // so that HbThemeServerSession::~HbThemeServerSession can avoid using these pointers;
   213     cache = 0;      // so that HbThemeServerSession::~HbThemeServerSession can avoid using these pointers;
   217     cssCache = 0;   // it may be called inside HbThemeServerPrivate::~HbThemeServerPrivate
       
   218     TInt err = RProperty::Delete(KServerUid3, KNewThemeForThemeChanger);
   214     TInt err = RProperty::Delete(KServerUid3, KNewThemeForThemeChanger);
   219     if(err != KErrNotFound) {
   215     if(err != KErrNotFound) {
   220         User::LeaveIfError(err);
   216         User::LeaveIfError(err);
   221     }
   217     }
   222     // Delete the listener for Publish/Subscribe
   218     // Delete the listener for Publish/Subscribe
   260 /**
   256 /**
   261 Handles theme selection
   257 Handles theme selection
   262 */
   258 */
   263 void HbThemeServerPrivate::HandleThemeSelection( const QString& themeName)
   259 void HbThemeServerPrivate::HandleThemeSelection( const QString& themeName)
   264 {
   260 {
   265     QDir path(themeName.trimmed());
   261     QString cleanThemeName = themeName;
       
   262     if (!HbThemeUtils::isThemeValid(cleanThemeName)) {
       
   263         // check if the theme name is logical
       
   264         cleanThemeName = KBaseThemePath + HbThemeUtils::platformHierarchy + '/' +
       
   265                     HbThemeUtils::iconsResourceFolder + '/' + cleanThemeName;
       
   266     }
       
   267 
       
   268     QDir path(cleanThemeName);
   266     iCurrentThemeName = path.dirName();
   269     iCurrentThemeName = path.dirName();
   267     iCurrentThemePath = path.absolutePath();
   270     iCurrentThemePath = path.absolutePath();
   268 
   271 
   269     #ifdef THEME_INDEX_TRACES
   272     #ifdef THEME_INDEX_TRACES
   270     qDebug() << "ThemeIndex: theme change request, new theme =" << themeName.toUtf8();
   273     qDebug() << "ThemeIndex: theme change request, new theme =" << cleanThemeName.toUtf8();
   271     #endif
   274     #endif
       
   275 
   272 
   276 
   273     // Clear cached icons and session data
   277     // Clear cached icons and session data
   274     clearIconCache();
   278     clearIconCache();
   275     iSessionIter.SetToFirst();
   279     iSessionIter.SetToFirst();
   276     while(iSessionIter) {
   280     while(iSessionIter) {
   318     return (cache->insert(key, item));
   322     return (cache->insert(key, item));
   319 
   323 
   320 }
   324 }
   321 
   325 
   322 /**
   326 /**
   323  * HbThemeServerPrivate::insertCssCacheItem
       
   324  *
       
   325  * Inserts a css-cache item along with its key into the css-cache.
       
   326  */
       
   327 bool HbThemeServerPrivate::insertCssCacheItem(const QString& key,  HbCacheItem* item)
       
   328 {
       
   329     return (cssCache->insert(key, item));
       
   330 }
       
   331 
       
   332 /**
       
   333  * HbThemeServerPrivate::iconCacheItem
   327  * HbThemeServerPrivate::iconCacheItem
   334  *
   328  *
   335  * Retrieves a icon cache-item from the icon cache based on it's key.
   329  * Retrieves a icon cache-item from the icon cache based on it's key.
   336  */
   330  */
   337 HbIconCacheItem * HbThemeServerPrivate::iconCacheItem(const HbIconKey &key , bool isMultiIconPiece)
   331 HbIconCacheItem * HbThemeServerPrivate::iconCacheItem(const HbIconKey &key , bool isMultiIconPiece)
   338 {
   332 {
   339     return(cache->getCacheItem(key, renderMode, isMultiIconPiece));
   333     return(cache->getCacheItem(key, renderMode, isMultiIconPiece));
   340 }
   334 }
   341 
   335 
   342 /**
   336 /**
   343  * HbThemeServerPrivate::cssCacheItem
       
   344  *
       
   345  * Retrieves a css-cache item from the css cache based on it's key.
       
   346  */
       
   347 HbCacheItem * HbThemeServerPrivate::cssCacheItem(const QString &key)
       
   348 {
       
   349     return(cssCache->cacheItem(key));
       
   350 }
       
   351 
       
   352 /**
       
   353  * HbThemeServerPrivate::clearIconCache
   337  * HbThemeServerPrivate::clearIconCache
   354  *
   338  *
   355  * Clears icon cache.
   339  * Clears icon cache.
   356  */
   340  */
   357 void HbThemeServerPrivate::clearIconCache()
   341 void HbThemeServerPrivate::clearIconCache()
   358 {
   342 {
   359     cache->clear();
   343     cache->clear();
   360 }
       
   361 
       
   362 /**
       
   363  * HbThemeServerPrivate::clearCssCache
       
   364  *
       
   365  * Clears css cache.
       
   366  */
       
   367 void HbThemeServerPrivate::clearCssCache()
       
   368 {
       
   369     cssCache->clear();
       
   370 }
   344 }
   371 
   345 
   372 /**
   346 /**
   373  * HbThemeServerPrivate::CleanupSessionIconItem
   347  * HbThemeServerPrivate::CleanupSessionIconItem
   374  *
   348  *
   403         return item->vectorIconData.type;
   377         return item->vectorIconData.type;
   404     }
   378     }
   405 }
   379 }
   406 
   380 
   407 /**
   381 /**
   408  * HbThemeServerPrivate::CleanupSessionCssItem
       
   409  *
       
   410  * Removes a css cache-item from css-cache based on it's key.
       
   411  */
       
   412 void HbThemeServerPrivate::CleanupSessionCssItem(QString key)
       
   413 {
       
   414     /*
       
   415         Don't call any HbCache ( CssCache )  functions if HbThemeServerPrivate has already deleted it,
       
   416          which happens when ThemeServer is closed before the client(s).
       
   417     */
       
   418     if (cssCache) {
       
   419         cssCache->remove(key);
       
   420     }
       
   421 }
       
   422 
       
   423 /**
       
   424 HbThemeServerPrivate::setMaxGpuCacheSize
   382 HbThemeServerPrivate::setMaxGpuCacheSize
   425  */
   383  */
   426 void HbThemeServerPrivate::setMaxGpuCacheSize(int size)
   384 void HbThemeServerPrivate::setMaxGpuCacheSize(int size)
   427 {
   385 {
   428     cache->setMaxGpuCacheSize(size);
   386     cache->setMaxGpuCacheSize(size);
   444 
   402 
   445 void HbThemeServerPrivate::FreeGpuRam(int bytes, bool useSwRendering )
   403 void HbThemeServerPrivate::FreeGpuRam(int bytes, bool useSwRendering )
   446 {
   404 {
   447     gpuGoodMemoryState = false;
   405     gpuGoodMemoryState = false;
   448     cache->freeGpuRam(bytes, useSwRendering);
   406     cache->freeGpuRam(bytes, useSwRendering);
   449 #ifdef HB_SGIMAGE_ICON
   407 }
   450     if (useSwRendering) {
   408 
   451     HbSgImageRenderer::global()->terminate();
   409 void HbThemeServerPrivate::freeGpuRam()
   452     }    	
   410 {
   453 #endif
   411     cache->freeGpuRam();
   454 }
   412 }
   455 
       
   456 /**
   413 /**
   457  *  HbThemeServerPrivate::freeUnusedGpuResources
   414  *  HbThemeServerPrivate::freeUnusedGpuResources
   458  *  This function frees all unused SgImage icons
   415  *  This function frees all unused SgImage icons
   459  *
   416  *
   460  */
   417  */
   503 HbRenderingMode HbThemeServerPrivate::currentRenderingMode() const
   460 HbRenderingMode HbThemeServerPrivate::currentRenderingMode() const
   504 {
   461 {
   505     return renderMode;
   462     return renderMode;
   506 }
   463 }
   507 
   464 
       
   465 HbRenderingMode HbThemeServerPrivate::expectedRenderingMode(HbRenderingMode requsetedRenderingMode) const
       
   466 {
       
   467     HbRenderingMode renderingMode = ESWRendering;
       
   468 
       
   469 #if defined(HB_SGIMAGE_ICON) || defined(HB_NVG_CS_ICON)    
       
   470     if((requsetedRenderingMode == EHWRendering) &&
       
   471        (currentRenderingMode() == EHWRendering) &&
       
   472         HbThemeServerPrivate::gpuMemoryState()) {
       
   473         renderingMode = EHWRendering;
       
   474     }
       
   475 #endif    
       
   476     
       
   477     return renderingMode;
       
   478 }
       
   479 
   508 /**
   480 /**
   509  *  HbThemeServerPrivate::setCurrentRenderingMode
   481  *  HbThemeServerPrivate::setCurrentRenderingMode
   510  *  This function sets  ThemeServer's current rendering mode
   482  *  This function sets  ThemeServer's current rendering mode
   511  *
   483  *
   512  */
   484  */
   513 void HbThemeServerPrivate::setCurrentRenderingMode(HbRenderingMode currentMode)
   485 void HbThemeServerPrivate::setCurrentRenderingMode(HbRenderingMode currentMode)
   514 {
   486 {
   515     renderMode = currentMode;
   487     renderMode = currentMode;
   516 }
       
   517 
       
   518 //Debug Code for Test Purpose
       
   519 #ifdef HB_ICON_CACHE_DEBUG
       
   520 int HbThemeServerPrivate ::cacheIconCount() const
       
   521 {
       
   522     return cache->count();
       
   523 }
   488 }
   524 
   489 
   525 unsigned long HbThemeServerPrivate::totalGPUMemory()
   490 unsigned long HbThemeServerPrivate::totalGPUMemory()
   526 {
   491 {
   527 #ifdef HB_SGIMAGE_ICON
   492 #ifdef HB_SGIMAGE_ICON
   530 #else
   495 #else
   531     return 0;
   496     return 0;
   532 #endif
   497 #endif
   533 }
   498 }
   534 
   499 
       
   500 int HbThemeServerPrivate::cachedSgImagesCount() const
       
   501 {
       
   502     return cache->cachedSgImagesCount();
       
   503 }
       
   504 
       
   505 int HbThemeServerPrivate::cachedPixmapCount() const
       
   506 {
       
   507     return cache->cachedPixmapCount();
       
   508 }
       
   509 
   535 unsigned long HbThemeServerPrivate::freeGPUMemory()
   510 unsigned long HbThemeServerPrivate::freeGPUMemory()
   536 {
   511 {
   537 #ifdef HB_SGIMAGE_ICON
   512 #ifdef HB_SGIMAGE_ICON
       
   513 #ifdef HB_ICON_CACHE_DEBUG
   538     qDebug() << "Inside  HbThemeServerSymbian::freeGPUMemory()  " ;
   514     qDebug() << "Inside  HbThemeServerSymbian::freeGPUMemory()  " ;
       
   515 #endif    
   539     return HbSgImageRenderer::global()->freeGPUMemory();
   516     return HbSgImageRenderer::global()->freeGPUMemory();
   540 #else
   517 #else
   541     return 0;
   518     return 0;
   542 #endif
   519 #endif
   543 }
   520 }
       
   521 
       
   522 //Debug Code for Test Purpose
       
   523 #ifdef HB_ICON_CACHE_DEBUG
       
   524 int HbThemeServerPrivate ::cacheIconCount() const
       
   525 {
       
   526     return cache->count();
       
   527 }
       
   528 
   544 int HbThemeServerPrivate::freeVectorMemory()
   529 int HbThemeServerPrivate::freeVectorMemory()
   545 {
   530 {
   546     return cache->freeVectorMemory();
   531     return cache->freeVectorMemory();
   547 }
   532 }
   548 
   533 
   610 
   595 
   611 int HbThemeServerPrivate::vectorLruCount()
   596 int HbThemeServerPrivate::vectorLruCount()
   612 {
   597 {
   613     return cache->vectorLruCount();
   598     return cache->vectorLruCount();
   614 }
   599 }
   615 
       
   616 #endif
   600 #endif
   617 
   601 
   618 int HbThemeServerPrivate::gpuLRUSize() const
   602 int HbThemeServerPrivate::gpuLRUSize() const
   619 {
   603 {
   620     return cache->gpuLRUSize();
   604     return cache->gpuLRUSize();
   621 }
   605 }
   622 
   606 
   623 /**
   607 //*********************************
   624  * HbThemeServerPrivate::doCleanup()
       
   625  *
       
   626  * This function releases shared memory occupied by css-resources whose reference count is zero,
       
   627  * so that subsequent css-requests could be fulfilled by the server. Those css-files whose reference
       
   628  * count are zero, are already appended to the LRU list maintained by the css-cache. Since these resources
       
   629  * are not being referred to by any application, they can be removed from the cache and corresponding
       
   630  * shared memory can be freed up.
       
   631  */
       
   632 void HbThemeServerPrivate::doCleanup()
       
   633 {
       
   634     HbThemeServerUtils::cleanupUnusedCss(cssCache);
       
   635 }
       
   636   
       
   637 //**********************************
       
   638 //HbThemeServerSession
   608 //HbThemeServerSession
   639 //**********************************
   609 //**********************************
   640 /**
   610 /**
   641 This class represents a session with the  server.
   611 This class represents a session with the server.
   642 Functions are provided to respond appropriately to client messages.
   612 Functions are provided to respond appropriately to client messages.
   643 */
   613 */
   644 
   614 
   645 /**
   615 /**
   646 Constructor
   616 Constructor
   661     for (QList<HbIconKey>::const_iterator iter = sessionData.constBegin();
   631     for (QList<HbIconKey>::const_iterator iter = sessionData.constBegin();
   662             iter != itEnd;
   632             iter != itEnd;
   663             ++iter) {
   633             ++iter) {
   664         iServer->CleanupSessionIconItem(*iter);
   634         iServer->CleanupSessionIconItem(*iter);
   665     }
   635     }
   666     //clean up css related session-specific info
       
   667     QList<QString>::const_iterator iterEnd(sessionCssData.constEnd());
       
   668     for (QList<QString>::const_iterator iter = sessionCssData.constBegin();
       
   669             iter != iterEnd;
       
   670             ++iter) {
       
   671         iServer->CleanupSessionCssItem(*iter);
       
   672     }
       
   673 
   636 
   674     sessionData.clear();
   637     sessionData.clear();
   675     sessionCssData.clear();
       
   676 }
   638 }
   677 
   639 
   678 TIconParams HbThemeServerSession::ReadMessageAndRetrieveParams(const RMessage2& aMessage)
   640 TIconParams HbThemeServerSession::ReadMessageAndRetrieveParams(const RMessage2& aMessage)
   679 {
   641 {
   680     TInt deslen = aMessage.GetDesLength(0);
   642     TInt deslen = aMessage.GetDesLength(0);
   789         TInt freeVectMem = iServer->freeVectorMemory();
   751         TInt freeVectMem = iServer->freeVectorMemory();
   790         TPckg<TInt> out(freeVectMem);
   752         TPckg<TInt> out(freeVectMem);
   791         aMessage.WriteL(1, out);
   753         aMessage.WriteL(1, out);
   792         break;
   754         break;
   793     }
   755     }
   794 
       
   795     case EFreeGPUMem: {
       
   796         unsigned long freeMem = iServer->freeGPUMemory();
       
   797         TPckg<unsigned long> out(freeMem);
       
   798         aMessage.WriteL(1, out);
       
   799         break;
       
   800     }
       
   801     case ETotalGPUMem: {
       
   802         unsigned long totalMem = iServer->totalGPUMemory();
       
   803         TPckg<unsigned long> out(totalMem);
       
   804         aMessage.WriteL(1, out);
       
   805         break;
       
   806     }
       
   807     case ELastAddedItemMem: {
   756     case ELastAddedItemMem: {
   808         TInt lAddItemMem = iServer->lastAddedItemMem();
   757         TInt lAddItemMem = iServer->lastAddedItemMem();
   809         TPckg<TInt> out(lAddItemMem);
   758         TPckg<TInt> out(lAddItemMem);
   810         aMessage.WriteL(1, out);
   759         aMessage.WriteL(1, out);
   811         break;
   760         break;
   901     case EServerAllocReset: {
   850     case EServerAllocReset: {
   902         //TODO
   851         //TODO
   903         break;
   852         break;
   904     }
   853     }
   905 #endif
   854 #endif
       
   855     case EFreeGPUMem: {
       
   856         unsigned long freeMem = iServer->freeGPUMemory();
       
   857         TPckg<unsigned long> out(freeMem);
       
   858         aMessage.WriteL(1, out);
       
   859         break;
       
   860     }   
       
   861     case ECachedSgImages: {
       
   862         TInt cachedSgImages = iServer->cachedSgImagesCount();
       
   863         TPckg<TInt> out(cachedSgImages);
       
   864         aMessage.WriteL(1, out);
       
   865         break;
       
   866     }
       
   867     case ECachedPixmapImages: {
       
   868         TInt cachedPixImages = iServer->cachedPixmapCount();
       
   869         TPckg<TInt> out(cachedPixImages);
       
   870         aMessage.WriteL(1, out);
       
   871         break;
       
   872     }
       
   873     case ECurrentRenderingMode: {
       
   874         TInt currentRenderingMode = iServer->currentRenderingMode();
       
   875         TPckg<TInt> out(currentRenderingMode);
       
   876         aMessage.WriteL(1, out);
       
   877         break;
       
   878     }
       
   879     case ETotalGPUMem: {
       
   880         unsigned long totalMem = iServer->totalGPUMemory();
       
   881         TPckg<unsigned long> out(totalMem);
       
   882         aMessage.WriteL(1, out);
       
   883         break;
       
   884     }
   906 #ifdef HB_THEME_SERVER_MEMORY_REPORT
   885 #ifdef HB_THEME_SERVER_MEMORY_REPORT
   907     case ECreateMemoryReport: {
   886     case ECreateMemoryReport: {
   908         GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory);
   887         GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory);
   909         static_cast<HbSharedMemoryManager *>(manager)->createReport();
   888         static_cast<HbSharedMemoryManager *>(manager)->createReport();
   910         break;
   889         break;
   938         TInt mode = 0;
   917         TInt mode = 0;
   939         TPckg<TInt> paramPckg(mode);      
   918         TPckg<TInt> paramPckg(mode);      
   940         aMessage.ReadL(0, paramPckg, 0);
   919         aMessage.ReadL(0, paramPckg, 0);
   941         SwitchRenderingMode((HbRenderingMode)mode);
   920         SwitchRenderingMode((HbRenderingMode)mode);
   942         break;
   921         break;
   943     }
   922     }    
   944     case EFreeSharedMem: {
   923     case EFreeSharedMem: {
   945         int freeSharedMem = iServer->freeSharedMemory();
   924         int freeSharedMem = iServer->freeSharedMemory();
   946         TPckg<int> out(freeSharedMem);
   925         TPckg<int> out(freeSharedMem);
   947         aMessage.WriteL(1, out);
   926         aMessage.WriteL(1, out);
   948         break;
   927         break;
   960         break;
   939         break;
   961     }
   940     }
   962 
   941 
   963     case ETypefaceOffset: {
   942     case ETypefaceOffset: {
   964         HandleTypefaceReqL(aMessage);
   943         HandleTypefaceReqL(aMessage);
       
   944         break;
       
   945     }
       
   946     case EMissedHbCssLookup: {
       
   947         HandleMissedHbCssLookupL(aMessage);
   965         break;
   948         break;
   966     }
   949     }
   967 
   950 
   968 
   951 
   969 
   952 
   992         qDebug()<< "HbThemeServerSession::SwitchRenderingMode:GPU Memory After Switching to Software:" << sgImg->freeGPUMemory();
   975         qDebug()<< "HbThemeServerSession::SwitchRenderingMode:GPU Memory After Switching to Software:" << sgImg->freeGPUMemory();
   993 #endif //HB_ICON_CACHE_DEBUG            
   976 #endif //HB_ICON_CACHE_DEBUG            
   994     } 
   977     } 
   995 #endif
   978 #endif
   996 }
   979 }
   997 
       
   998 /**
   980 /**
   999  * HandleStyleSheetLookupL
   981  * HandleStyleSheetLookupL
  1000  */
   982  */
  1001 void HbThemeServerSession::HandleStyleSheetLookupL(const RMessage2& aMessage)
   983 void HbThemeServerSession::HandleStyleSheetLookupL(const RMessage2& aMessage)
  1002 {
   984 {
  1017 
   999 
  1018     HbLayeredStyleLoader::LayerPriority layerPriority = (HbLayeredStyleLoader::LayerPriority) priorityValue;
  1000     HbLayeredStyleLoader::LayerPriority layerPriority = (HbLayeredStyleLoader::LayerPriority) priorityValue;
  1019 
  1001 
  1020     QString cssFileName((QChar*)fileName.Ptr(), fileName.Length());
  1002     QString cssFileName((QChar*)fileName.Ptr(), fileName.Length());
  1021     HbSharedStyleSheetInfo offsetInfo;
  1003     HbSharedStyleSheetInfo offsetInfo;
  1022     HbCacheItem* cssCacheItem = iServer->cssCacheItem(cssFileName);
  1004 
  1023     bool insertKeyIntoSessionList = false;
  1005     offsetInfo.offset = HbThemeServerUtils::getSharedStylesheet(cssFileName, 
  1024     if (cssCacheItem) {
  1006             layerPriority, offsetInfo.fileExists);
  1025         //The item was found in the cache and reference count was incremented
  1007 
  1026         insertKeyIntoSessionList = true;
       
  1027         offsetInfo.offset = cssCacheItem->offset;
       
  1028     } else {
       
  1029         bool tryAgain = false;
       
  1030         do {
       
  1031             offsetInfo.offset = HbThemeServerUtils::getSharedStylesheet(cssFileName, layerPriority);
       
  1032             if (offsetInfo.offset >= 0) {
       
  1033                 HbCacheItem *cssItem =  new HbCacheItem(offsetInfo.offset, 0, cssFileName);
       
  1034                 insertKeyIntoSessionList = iServer->insertCssCacheItem(cssFileName, cssItem);
       
  1035                 if (layerPriority == HbLayeredStyleLoader::Priority_Core && cssItem->refCount == 1) {
       
  1036                     // This will make sure the requested stylesheet will always remain
       
  1037                     // in the primary and secondary cache.
       
  1038                     cssItem->incrementRefCount();
       
  1039                 }
       
  1040                 break;
       
  1041             } else if (offsetInfo.offset == OUT_OF_MEMORY_ERROR && tryAgain == false) {
       
  1042                 iServer->doCleanup();
       
  1043                 tryAgain = true;
       
  1044             } else if (offsetInfo.offset == OUT_OF_MEMORY_ERROR && tryAgain == true) {
       
  1045                 //try only once to free up memory, else offset remains -2
       
  1046                 tryAgain = false;
       
  1047             }
       
  1048         } while (tryAgain);
       
  1049     }
       
  1050     if (insertKeyIntoSessionList) {
       
  1051         //The session will only keep track of cssFiles that were either successfully found or were
       
  1052         //successfully inserted in the cache.
       
  1053         if (!sessionCssData.contains(cssFileName)) {
       
  1054             sessionCssData.append(cssFileName);
       
  1055         }
       
  1056     }
       
  1057     TPckg<HbSharedStyleSheetInfo> data(offsetInfo);
  1008     TPckg<HbSharedStyleSheetInfo> data(offsetInfo);
  1058     aMessage.WriteL(2, data);
  1009     aMessage.WriteL(2, data);
       
  1010 }
       
  1011 
       
  1012 /**
       
  1013  * HandleMissedHbCssLookupL
       
  1014  */
       
  1015 void HbThemeServerSession::HandleMissedHbCssLookupL(const RMessage2& aMessage)
       
  1016 {
       
  1017     HbSharedMissedHbCssInfo offsetInfo;
       
  1018     offsetInfo.offset = HbThemeServerUtils::getMissedHbCssFilesOffset();
       
  1019     TPckg<HbSharedMissedHbCssInfo> data(offsetInfo);
       
  1020     aMessage.WriteL(0, data);
  1059 }
  1021 }
  1060 
  1022 
  1061 static const TInt KMaxLayoutName = 256;
  1023 static const TInt KMaxLayoutName = 256;
  1062 static const TInt KMaxSectionName = 256;
  1024 static const TInt KMaxSectionName = 256;
  1063 
  1025 
  1080     QString wmlFileName((QChar*)fileName.Ptr(), fileName.Length());
  1042     QString wmlFileName((QChar*)fileName.Ptr(), fileName.Length());
  1081     QString layout((QChar*)layoutName.Ptr(), layoutName.Length());
  1043     QString layout((QChar*)layoutName.Ptr(), layoutName.Length());
  1082     QString section((QChar*)sectionName.Ptr(), sectionName.Length());
  1044     QString section((QChar*)sectionName.Ptr(), sectionName.Length());
  1083 
  1045 
  1084     HbSharedWMLInfo offsetInfo;
  1046     HbSharedWMLInfo offsetInfo;
  1085     offsetInfo.offset = HbThemeServerUtils::getSharedLayoutDefinition(wmlFileName, layout, section);
  1047     offsetInfo.offset = HbThemeServerUtils::getSharedLayoutDefinition(wmlFileName, layout, 
       
  1048             section, offsetInfo.fileExists);
  1086     TPckg<HbSharedWMLInfo> data(offsetInfo);
  1049     TPckg<HbSharedWMLInfo> data(offsetInfo);
  1087     aMessage.WriteL(3, data);
  1050     aMessage.WriteL(3, data);
  1088 }
  1051 }
  1089 
  1052 
  1090 
  1053 
  1136     HbIconKey key(filename, QSizeF(params.width, params.height),
  1099     HbIconKey key(filename, QSizeF(params.width, params.height),
  1137                   (Qt::AspectRatioMode)params.aspectRatioMode,
  1100                   (Qt::AspectRatioMode)params.aspectRatioMode,
  1138                   (QIcon::Mode)params.mode, params.mirrored, color,
  1101                   (QIcon::Mode)params.mode, params.mirrored, color,
  1139                   (HbRenderingMode)params.renderMode);
  1102                   (HbRenderingMode)params.renderMode);
  1140 
  1103 
  1141     HbIconCacheItem* cacheItem = iServer->iconCacheItem(key);
       
  1142     bool insertKeyIntoSessionList = false;
  1104     bool insertKeyIntoSessionList = false;
       
  1105     QString format = HbThemeServerUtils::formatFromPath(key.filename);
       
  1106 
       
  1107     HbIconCacheItem* cacheItem = getCachedIcon(key, format);    
  1143     if (cacheItem) {
  1108     if (cacheItem) {
  1144         insertKeyIntoSessionList = true; //The item was found in the cache and ref count was incremented
  1109         insertKeyIntoSessionList = true; //The item was found in the cache and ref count was incremented
  1145         if (cacheItem->rasterIconData.type != INVALID_FORMAT) {
  1110         if (cacheItem->rasterIconData.type != INVALID_FORMAT) {
  1146             data = cacheItem->rasterIconData;
  1111             data = cacheItem->rasterIconData;
  1147         } else if (cacheItem->vectorIconData.type != INVALID_FORMAT) {
  1112         } else if (cacheItem->vectorIconData.type != INVALID_FORMAT) {
  1151         } else {
  1116         } else {
  1152             data.type = INVALID_FORMAT;
  1117             data.type = INVALID_FORMAT;
  1153         }
  1118         }
  1154     } else {
  1119     } else {
  1155         QT_TRY {
  1120         QT_TRY {
  1156             QString format = HbThemeServerUtils::formatFromPath(key.filename);
       
  1157                 QScopedPointer <HbIconCacheItem> tempIconCacheItem(
  1121                 QScopedPointer <HbIconCacheItem> tempIconCacheItem(
  1158                     HbIconCacheItemCreator::createCacheItem(key,
  1122                     HbIconCacheItemCreator::createCacheItem(key,
  1159                         static_cast<HbIconLoader::IconLoaderOptions>(params.options),
  1123                         static_cast<HbIconLoader::IconLoaderOptions>(params.options),
  1160                         format, iServer->currentRenderingMode()));
  1124                         format, iServer->currentRenderingMode()));
  1161             cacheItem = tempIconCacheItem.data();
  1125             cacheItem = tempIconCacheItem.data();
  1168                     data = cacheItem->blobIconData;
  1132                     data = cacheItem->blobIconData;
  1169                 } else {
  1133                 } else {
  1170                     data.type = INVALID_FORMAT;
  1134                     data.type = INVALID_FORMAT;
  1171                 }
  1135                 }
  1172                 if (data.type != INVALID_FORMAT) {
  1136                 if (data.type != INVALID_FORMAT) {
       
  1137                     // set the rendering mode according to the actual rendering mode
       
  1138                     // in which the icon is created
       
  1139                     key.renderMode = cacheItem->renderingMode();
       
  1140                     
  1173                     insertKeyIntoSessionList = iServer->insertIconCacheItem(key, cacheItem);
  1141                     insertKeyIntoSessionList = iServer->insertIconCacheItem(key, cacheItem);
  1174                     if (!insertKeyIntoSessionList) {
  1142                     if (!insertKeyIntoSessionList) {
  1175                         FreeDataFromCacheItem(cacheItem);
  1143                         FreeDataFromCacheItem(cacheItem);
  1176                         tempIconCacheItem.take();
  1144                         tempIconCacheItem.take();
  1177                         delete cacheItem; // do delete the item after gpu/cpu memory is freed
  1145                         delete cacheItem; // do delete the item after gpu/cpu memory is freed
  1192     if (insertKeyIntoSessionList) {
  1160     if (insertKeyIntoSessionList) {
  1193         //The session will only keep track of icons that were either successfully found or were
  1161         //The session will only keep track of icons that were either successfully found or were
  1194         //successfully inserted in the cache.
  1162         //successfully inserted in the cache.
  1195         sessionData.append(key);
  1163         sessionData.append(key);
  1196     }
  1164     }
       
  1165 #ifdef HB_SGIMAGE_ICON
       
  1166     HbSgImageRenderer *sgImg = HbSgImageRenderer::global();
       
  1167     if (sgImg->lastError() == KErrNoGraphicsMemory ) {
       
  1168        iServer->freeGpuRam();
       
  1169     }
       
  1170 #endif
  1197     // create dshared pixmap info from HbIconCacheItem
  1171     // create dshared pixmap info from HbIconCacheItem
  1198     TPckg<HbSharedIconInfo> pixdata(data);
  1172     TPckg<HbSharedIconInfo> pixdata(data);
  1199     aMessage.WriteL(1, pixdata);
  1173     aMessage.WriteL(1, pixdata);
  1200 
  1174 
  1201 #ifdef THEME_SERVER_TRACES
  1175 #ifdef THEME_SERVER_TRACES
  1257                            static_cast<QIcon::Mode>(params.mode),
  1231                            static_cast<QIcon::Mode>(params.mode),
  1258                            params.mirrored,
  1232                            params.mirrored,
  1259                            color,
  1233                            color,
  1260                            static_cast<HbRenderingMode>(params.renderMode));
  1234                            static_cast<HbRenderingMode>(params.renderMode));
  1261 
  1235 
  1262     if (!IconInfoFromSingleIcon(finalIconKey, stitchedData)) {
  1236     if (!IconInfoFromSingleIcon(finalIconKey, stitchedData, QString())) {
  1263         HbMultiIconParams frameItemParams;
  1237         HbMultiIconParams frameItemParams;
  1264         int noOfPieces = 1;
  1238         int noOfPieces = 1;
  1265         if (iconId.contains("_3PV", Qt::CaseInsensitive) || iconId.contains("_3PH", Qt::CaseInsensitive)) {
  1239         if (iconId.contains("_3PV", Qt::CaseInsensitive) || iconId.contains("_3PH", Qt::CaseInsensitive)) {
  1266             noOfPieces = 3;
  1240             noOfPieces = 3;
  1267         } else if (iconId.contains("_9P", Qt::CaseInsensitive)) {
  1241         } else if (iconId.contains("_9P", Qt::CaseInsensitive)) {
  1296     // create dshared pixmap info from HbIconCacheItem
  1270     // create dshared pixmap info from HbIconCacheItem
  1297     TPckg<HbSharedIconInfo> pixdata(stitchedData);
  1271     TPckg<HbSharedIconInfo> pixdata(stitchedData);
  1298     aMessage.WriteL(1, pixdata);
  1272     aMessage.WriteL(1, pixdata);
  1299 }
  1273 }
  1300 
  1274 
       
  1275 HbIconCacheItem* HbThemeServerSession::getCachedIcon(HbIconKey & key, const QString & format)
       
  1276 {
       
  1277     HbIconCacheItem* cacheItem = 0;
       
  1278     
       
  1279     // try to find the icon in other rendering mode,
       
  1280     // if rendering will take place in another rendering mode
       
  1281     HbRenderingMode rm = iServer->expectedRenderingMode((HbRenderingMode)key.renderMode);
       
  1282     if (rm == key.renderMode) {
       
  1283         cacheItem = iServer->iconCacheItem(key);
       
  1284     } else if (rm != key.renderMode) {
       
  1285         HbIconKey newKey(key);
       
  1286         newKey.renderMode = rm;
       
  1287         cacheItem = iServer->iconCacheItem(newKey);
       
  1288         if (cacheItem) {
       
  1289             key.renderMode = rm;
       
  1290         }
       
  1291     }
       
  1292     
       
  1293     if (!cacheItem) {
       
  1294         // try search for icon in software mode if the icon is not of type nvg
       
  1295         // currently only nvg type is used to create RSgImage
       
  1296         if (format != HbIconCacheItemCreator::KNvg) {            
       
  1297             HbIconKey newKey(key);
       
  1298             newKey.renderMode = ESWRendering;
       
  1299             cacheItem = iServer->iconCacheItem(newKey);
       
  1300             if (cacheItem) {
       
  1301                 key.renderMode = ESWRendering;
       
  1302             }
       
  1303         }
       
  1304         
       
  1305     }
       
  1306     
       
  1307     return cacheItem;
       
  1308 }
       
  1309 
  1301 /**
  1310 /**
  1302  * HbThemeServerPrivate::IconInfoFromSingleIcon
  1311  * HbThemeServerPrivate::IconInfoFromSingleIcon
  1303   Checks for the cacheItem for a given key, if found gets the data relevant of the cacheItem.
  1312   Checks for the cacheItem for a given key, if found gets the data relevant of the cacheItem.
  1304  */
  1313  */
  1305 
  1314 
  1306 bool HbThemeServerSession::IconInfoFromSingleIcon(HbIconKey key,
  1315 bool HbThemeServerSession::IconInfoFromSingleIcon(HbIconKey key,
  1307         HbSharedIconInfo &stitchedData)
  1316         HbSharedIconInfo &stitchedData, const QString & format)
  1308 {
  1317 {
  1309     stitchedData.type = INVALID_FORMAT;
  1318     HbIconCacheItem* cacheItem = 0;
  1310     HbIconCacheItem * cacheItem = iServer->iconCacheItem(key, true);
  1319     
       
  1320     // try to find the icon in other rendering mode,
       
  1321     // if rendering will take place in another rendering mode
       
  1322     HbRenderingMode rm = iServer->expectedRenderingMode((HbRenderingMode)key.renderMode);
       
  1323     if (rm == key.renderMode) {
       
  1324         cacheItem = iServer->iconCacheItem(key, true);
       
  1325     } else if (rm != key.renderMode) {
       
  1326         HbIconKey newKey(key);
       
  1327         newKey.renderMode = rm;
       
  1328         cacheItem = iServer->iconCacheItem(newKey, true);
       
  1329         if (cacheItem) {
       
  1330             key.renderMode = rm;
       
  1331         }
       
  1332     }
       
  1333     
       
  1334     if (!cacheItem) {
       
  1335         if (!format.isEmpty()) {
       
  1336             // try search for icon in software mode if the icon is not of type nvg
       
  1337             // currently only nvg type is used to create RSgImage
       
  1338             if (format != HbIconCacheItemCreator::KNvg) {            
       
  1339                 HbIconKey newKey(key);
       
  1340                 key.renderMode = ESWRendering;
       
  1341                 cacheItem = iServer->iconCacheItem(newKey);
       
  1342                 if (cacheItem) {
       
  1343                     key.renderMode = ESWRendering;
       
  1344                 }
       
  1345             }
       
  1346         }
       
  1347     }
       
  1348     
  1311     if (cacheItem) {
  1349     if (cacheItem) {
  1312         GetDataFromCacheItem(cacheItem, stitchedData);
  1350         GetDataFromCacheItem(cacheItem, stitchedData);
  1313         return true; //The item was found in the cache and ref count was incremented
  1351         return true; //The item was found in the cache and ref count was incremented
  1314     }
  1352     }
  1315     return false;
  1353     return false;
  1389             tempCacheItem.take();
  1427             tempCacheItem.take();
  1390             delete cacheItem; // do delete the item after gpu/cpu memory is freed
  1428             delete cacheItem; // do delete the item after gpu/cpu memory is freed
  1391             stitchedData.type = INVALID_FORMAT;
  1429             stitchedData.type = INVALID_FORMAT;
  1392         }
  1430         }
  1393     }
  1431     }
       
  1432 #ifdef HB_SGIMAGE_ICON    
       
  1433     HbSgImageRenderer *sgImg = HbSgImageRenderer::global();
       
  1434     if (sgImg->lastError() == KErrNoGraphicsMemory ) {
       
  1435         iServer->freeGpuRam();
       
  1436     }
       
  1437 #endif    
  1394     if (tempCacheItem.data()) {
  1438     if (tempCacheItem.data()) {
  1395         tempCacheItem.take();
  1439         tempCacheItem.take();
  1396     }
  1440     }
  1397     return insertKeyIntoSessionList;
  1441     return insertKeyIntoSessionList;
  1398 }
  1442 }
  1421             HbSharedIconInfo data;
  1465             HbSharedIconInfo data;
  1422             bool iconPieceMirrored = false;
  1466             bool iconPieceMirrored = false;
  1423         HbIconKey key(frameItemParams.multiPartIconList.at(i), frameItemParams.multiPartIconData.pixmapSizes[i], 
  1467         HbIconKey key(frameItemParams.multiPartIconList.at(i), frameItemParams.multiPartIconData.pixmapSizes[i], 
  1424                       (Qt::AspectRatioMode)stichedKey.aspectRatioMode, (QIcon::Mode)stichedKey.mode, iconPieceMirrored, 
  1468                       (Qt::AspectRatioMode)stichedKey.aspectRatioMode, (QIcon::Mode)stichedKey.mode, iconPieceMirrored, 
  1425                       stichedKey.color,(HbRenderingMode)frameItemParams.renderMode);
  1469                       stichedKey.color,(HbRenderingMode)frameItemParams.renderMode);
  1426             insertKeyIntoSessionList = IconInfoFromSingleIcon(key, data);
  1470             insertKeyIntoSessionList = IconInfoFromSingleIcon(key, data, HbThemeServerUtils::formatFromPath(key.filename));
  1427             if (!insertKeyIntoSessionList) {
  1471             if (!insertKeyIntoSessionList) {
  1428                 insertKeyIntoSessionList = CreateCacheItemData(key, frameItemParams.options, data, true);
  1472                 insertKeyIntoSessionList = CreateCacheItemData(key, frameItemParams.options, data, true);
  1429             }
  1473             }
  1430             if ((data.type == INVALID_FORMAT) || (!insertKeyIntoSessionList)) {
  1474             if ((data.type == INVALID_FORMAT) || (!insertKeyIntoSessionList)) {
  1431                 failedToCreateParts = true;
  1475                 failedToCreateParts = true;
  1615             HbSharedIconInfo data;
  1659             HbSharedIconInfo data;
  1616             QString pieceName((QChar*)frameItemParams.iconList[i].Ptr(), frameItemParams.iconList[i].Length());
  1660             QString pieceName((QChar*)frameItemParams.iconList[i].Ptr(), frameItemParams.iconList[i].Length());
  1617             HbIconKey key(pieceName, frameItemParams.sizeList[i],
  1661             HbIconKey key(pieceName, frameItemParams.sizeList[i],
  1618                           (Qt::AspectRatioMode)frameItemParams.aspectRatioMode, (QIcon::Mode)frameItemParams.mode,
  1662                           (Qt::AspectRatioMode)frameItemParams.aspectRatioMode, (QIcon::Mode)frameItemParams.mode,
  1619                       (bool)frameItemParams.mirrored, color, (HbRenderingMode)frameItemParams.renderMode);
  1663                       (bool)frameItemParams.mirrored, color, (HbRenderingMode)frameItemParams.renderMode);
  1620             insertKeyIntoSessionList = IconInfoFromSingleIcon(key, data);
  1664             insertKeyIntoSessionList = IconInfoFromSingleIcon(key, data, HbThemeServerUtils::formatFromPath(key.filename));
  1621             if (!insertKeyIntoSessionList) {
  1665             if (!insertKeyIntoSessionList) {
  1622                 insertKeyIntoSessionList = CreateCacheItemData(key, 0, data, false);
  1666                 insertKeyIntoSessionList = CreateCacheItemData(key, 0, data, false);
  1623             }
  1667             }
  1624             if ((data.type != INVALID_FORMAT) || (insertKeyIntoSessionList)) {
  1668             if ((data.type != INVALID_FORMAT) || (insertKeyIntoSessionList)) {
  1625                 //The session will only keep track of icons that were either successfully found or were
  1669                 //The session will only keep track of icons that were either successfully found or were