src/hbservers/hbthemeserver/hbicondatacache_p.cpp
changeset 21 4633027730f5
parent 7 923ff622b8b9
child 23 e6ad4ef83b23
equal deleted inserted replaced
7:923ff622b8b9 21:4633027730f5
   185             manager->free(temp->blobIconData.blobData.offset);
   185             manager->free(temp->blobIconData.blobData.offset);
   186         }
   186         }
   187         delete   iter.value();
   187         delete   iter.value();
   188     }
   188     }
   189     cache->clear();
   189     cache->clear();
       
   190     
       
   191     // close the sgimage driver after all the 
       
   192 	// sgimage items and its memory were deleted.
       
   193 #ifdef HB_SGIMAGE_ICON
       
   194     if (!goodMemory && (currentGpuCacheSize <= 0) ) {
       
   195         HbSgImageRenderer::global()->terminate();
       
   196     }
       
   197 #endif
   190 
   198 
   191     //Debug Code for Test Purpose
   199     //Debug Code for Test Purpose
   192 #ifdef HB_ICON_CACHE_DEBUG
   200 #ifdef HB_ICON_CACHE_DEBUG
   193     addedItemRefCount = 0;
   201     addedItemRefCount = 0;
   194     addedItemMem = 0;
   202     addedItemMem = 0;
   304     addedItemRefCount = item->refCount;
   312     addedItemRefCount = item->refCount;
   305     qDebug() << "HbIconDataCache::getCacheItem: "
   313     qDebug() << "HbIconDataCache::getCacheItem: "
   306              << "Cache hit in Server-Cache for" << key.filename;
   314              << "Cache hit in Server-Cache for" << key.filename;
   307     qDebug() << "HbIconDataCache::getCacheItem: Server RefCount now = " << item->refCount;
   315     qDebug() << "HbIconDataCache::getCacheItem: Server RefCount now = " << item->refCount;
   308 #endif
   316 #endif
   309 
   317     if( EHWRendering == key.renderMode && 
       
   318         ESWRendering == currentRenderingMode && 
       
   319         INVALID_FORMAT == item->rasterIconData.type &&
       
   320         NVG == item->vectorIconData.type ) {
       
   321         HbIconCacheItemCreator::createCacheItem(*item, key, currentRenderingMode);
       
   322         //deleting the vectordata type here.
       
   323         releaseVectorItem(item);
       
   324      }
   310     return item;
   325     return item;
   311 }
   326 }
   312 
   327 
   313 /*!
   328 /*!
   314     \fn HbIconDataCache::insert()
   329     \fn HbIconDataCache::insert()
   421     remRfCount = item->refCount;
   436     remRfCount = item->refCount;
   422 #endif
   437 #endif
   423 
   438 
   424     if (item->refCount == 0) {
   439     if (item->refCount == 0) {
   425         if (item->rasterIconData.type == SGIMAGE) {
   440         if (item->rasterIconData.type == SGIMAGE) {
   426             if (keepInCache) {
   441             if (keepInCache && goodMemory) {
   427                 gpuLruList.insertBack(item);
   442                 gpuLruList.insertBack(item);
   428                 updateGpuLruSize(item->rasterIconDataCost);
   443                 updateGpuLruSize(item->rasterIconDataCost);
   429             } else {
   444             } else {
   430                 releaseRasterItem(item);
   445 #ifdef HB_SGIMAGE_ICON                                     
   431                 removeFromCache(key, item);
   446                 HbSgImageRenderer::removeSgImageFromHash(
       
   447                         item->rasterIconData.sgImageData.id);
       
   448                 item->rasterIconData.type = INVALID_FORMAT;
       
   449 #endif
       
   450                 removeFromCache(key, item);   
       
   451                 // close the sgimage driver after all the 
       
   452                 // sgimage items and its memory were deleted.
       
   453 #ifdef HB_SGIMAGE_ICON
       
   454                 if (!goodMemory && (currentGpuCacheSize <= 0) ) {
       
   455                     HbSgImageRenderer::global()->terminate();
       
   456                 }
       
   457 #endif  
   432                 return true;
   458                 return true;
   433             }
   459             }
   434         }
   460         }
   435         if (item->rasterIconData.type == OTHER_SUPPORTED_FORMATS) {
   461         if (item->rasterIconData.type == OTHER_SUPPORTED_FORMATS) {
   436             if (keepInCache) {
   462             if (keepInCache) {
   697                     (itemToRemove->vectorIconData.type == INVALID_FORMAT)) {
   723                     (itemToRemove->vectorIconData.type == INVALID_FORMAT)) {
   698                 cache->remove(cache->key(itemToRemove));
   724                 cache->remove(cache->key(itemToRemove));
   699                 delete itemToRemove;
   725                 delete itemToRemove;
   700             }
   726             }
   701         }
   727         }
       
   728         // close the sgimage driver after all the 
       
   729 		// sgimage items and its memory were deleted.
       
   730 #ifdef HB_SGIMAGE_ICON
       
   731         if (!goodMemory && (currentGpuCacheSize <= 0) ) {
       
   732             HbSgImageRenderer::global()->terminate();
       
   733         }
       
   734 #endif     
   702     }
   735     }
   703 }
   736 }
   704 
   737 
   705 /*!
   738 /*!
   706     \fn HbIconDataCache::createCpuCacheSpace()
   739     \fn HbIconDataCache::createCpuCacheSpace()
   785 }
   818 }
   786 
   819 
   787 void HbIconDataCache::freeGpuRam(int bytes, bool useSwRendering)
   820 void HbIconDataCache::freeGpuRam(int bytes, bool useSwRendering)
   788 {
   821 {
   789     goodMemory = false;
   822     goodMemory = false;
   790     if (bytes  <= gpuLruListSize) {
   823     if ((bytes  <= gpuLruListSize) && !useSwRendering) {
   791         createGpuCacheSpace(bytes);
   824         createGpuCacheSpace(bytes);
   792     } else {
   825     } else {
   793         createGpuCacheSpace(gpuLruListSize);
   826         createGpuCacheSpace(gpuLruListSize);
   794     }
   827     }
   795     
   828 }
   796     if (useSwRendering) {
   829 
   797     // Iterate through the cache and remove any active SgImages, before the context
   830 int HbIconDataCache::cachedSgImagesCount() const 
   798     // is destroyed.
   831 {
       
   832     int sgImagesCount = 0;
   799     QHash<HbIconKey, HbIconCacheItem*>::const_iterator itEnd(cache->constEnd());
   833     QHash<HbIconKey, HbIconCacheItem*>::const_iterator itEnd(cache->constEnd());
   800     for (QHash<HbIconKey,
   834     for (QHash<HbIconKey,
   801             HbIconCacheItem *>::const_iterator iter = cache->constBegin();
   835             HbIconCacheItem *>::const_iterator iter = cache->constBegin();
   802             iter != itEnd;
   836             iter != itEnd;
   803             ++iter) {
   837             ++iter) {
   804         HbIconCacheItem *temp = iter.value();
   838         HbIconCacheItem *temp = iter.value();
   805         if( temp->rasterIconData.type == SGIMAGE ){
   839         if( temp->rasterIconData.type == SGIMAGE ){
   806 #ifdef HB_SGIMAGE_ICON
   840             sgImagesCount++;
   807             HbSgImageRenderer::removeSgImageFromHash(temp->rasterIconData.sgImageData.id);
   841         }
   808 #endif
   842     }
   809             temp->rasterIconData.type = INVALID_FORMAT;
   843     return sgImagesCount;
   810             currentGpuCacheSize -= temp->rasterIconDataCost;
   844 
   811         }
   845 }
   812     }
   846 
   813     gpuLruList.removeAll();
   847 int HbIconDataCache::cachedPixmapCount() const
   814     gpuLruListSize = 0;
   848 {
   815     }    	    
   849     int pixmapCount = 0;
   816 }
   850     QHash<HbIconKey, HbIconCacheItem*>::const_iterator itEnd(cache->constEnd());
   817 
   851     for (QHash<HbIconKey,
       
   852             HbIconCacheItem *>::const_iterator iter = cache->constBegin();
       
   853             iter != itEnd;
       
   854             ++iter) {
       
   855         HbIconCacheItem *temp = iter.value();
       
   856         if( temp->rasterIconData.type == OTHER_SUPPORTED_FORMATS ){
       
   857             pixmapCount++;
       
   858         }
       
   859     }
       
   860     return pixmapCount;
       
   861 }
       
   862 
       
   863 void HbIconDataCache::freeGpuRam()
       
   864 {
       
   865     freeGpuRam(gpuLruListSize, false);
       
   866 }
   818 /*!
   867 /*!
   819     \fn HbIconDataCache::freeUnusedGpuResources()
   868     \fn HbIconDataCache::freeUnusedGpuResources()
   820     This function internally calls createGpuCacheSpace() which will free up
   869     This function internally calls createGpuCacheSpace() which will free up
   821     all the unused sgImage icons.
   870     all the unused sgImage icons.
   822  */
   871  */