src/hbservers/hbthemeserver/hbicondatacache_p.cpp
changeset 21 4633027730f5
parent 7 923ff622b8b9
child 23 e6ad4ef83b23
--- a/src/hbservers/hbthemeserver/hbicondatacache_p.cpp	Tue Jul 06 14:36:53 2010 +0300
+++ b/src/hbservers/hbthemeserver/hbicondatacache_p.cpp	Wed Aug 18 10:05:37 2010 +0300
@@ -187,6 +187,14 @@
         delete   iter.value();
     }
     cache->clear();
+    
+    // close the sgimage driver after all the 
+	// sgimage items and its memory were deleted.
+#ifdef HB_SGIMAGE_ICON
+    if (!goodMemory && (currentGpuCacheSize <= 0) ) {
+        HbSgImageRenderer::global()->terminate();
+    }
+#endif
 
     //Debug Code for Test Purpose
 #ifdef HB_ICON_CACHE_DEBUG
@@ -306,7 +314,14 @@
              << "Cache hit in Server-Cache for" << key.filename;
     qDebug() << "HbIconDataCache::getCacheItem: Server RefCount now = " << item->refCount;
 #endif
-
+    if( EHWRendering == key.renderMode && 
+        ESWRendering == currentRenderingMode && 
+        INVALID_FORMAT == item->rasterIconData.type &&
+        NVG == item->vectorIconData.type ) {
+        HbIconCacheItemCreator::createCacheItem(*item, key, currentRenderingMode);
+        //deleting the vectordata type here.
+        releaseVectorItem(item);
+     }
     return item;
 }
 
@@ -423,12 +438,23 @@
 
     if (item->refCount == 0) {
         if (item->rasterIconData.type == SGIMAGE) {
-            if (keepInCache) {
+            if (keepInCache && goodMemory) {
                 gpuLruList.insertBack(item);
                 updateGpuLruSize(item->rasterIconDataCost);
             } else {
-                releaseRasterItem(item);
-                removeFromCache(key, item);
+#ifdef HB_SGIMAGE_ICON                                     
+                HbSgImageRenderer::removeSgImageFromHash(
+                        item->rasterIconData.sgImageData.id);
+                item->rasterIconData.type = INVALID_FORMAT;
+#endif
+                removeFromCache(key, item);   
+                // close the sgimage driver after all the 
+                // sgimage items and its memory were deleted.
+#ifdef HB_SGIMAGE_ICON
+                if (!goodMemory && (currentGpuCacheSize <= 0) ) {
+                    HbSgImageRenderer::global()->terminate();
+                }
+#endif  
                 return true;
             }
         }
@@ -699,6 +725,13 @@
                 delete itemToRemove;
             }
         }
+        // close the sgimage driver after all the 
+		// sgimage items and its memory were deleted.
+#ifdef HB_SGIMAGE_ICON
+        if (!goodMemory && (currentGpuCacheSize <= 0) ) {
+            HbSgImageRenderer::global()->terminate();
+        }
+#endif     
     }
 }
 
@@ -787,15 +820,16 @@
 void HbIconDataCache::freeGpuRam(int bytes, bool useSwRendering)
 {
     goodMemory = false;
-    if (bytes  <= gpuLruListSize) {
+    if ((bytes  <= gpuLruListSize) && !useSwRendering) {
         createGpuCacheSpace(bytes);
     } else {
         createGpuCacheSpace(gpuLruListSize);
     }
-    
-    if (useSwRendering) {
-    // Iterate through the cache and remove any active SgImages, before the context
-    // is destroyed.
+}
+
+int HbIconDataCache::cachedSgImagesCount() const 
+{
+    int sgImagesCount = 0;
     QHash<HbIconKey, HbIconCacheItem*>::const_iterator itEnd(cache->constEnd());
     for (QHash<HbIconKey,
             HbIconCacheItem *>::const_iterator iter = cache->constBegin();
@@ -803,18 +837,33 @@
             ++iter) {
         HbIconCacheItem *temp = iter.value();
         if( temp->rasterIconData.type == SGIMAGE ){
-#ifdef HB_SGIMAGE_ICON
-            HbSgImageRenderer::removeSgImageFromHash(temp->rasterIconData.sgImageData.id);
-#endif
-            temp->rasterIconData.type = INVALID_FORMAT;
-            currentGpuCacheSize -= temp->rasterIconDataCost;
+            sgImagesCount++;
         }
     }
-    gpuLruList.removeAll();
-    gpuLruListSize = 0;
-    }    	    
+    return sgImagesCount;
+
 }
 
+int HbIconDataCache::cachedPixmapCount() const
+{
+    int pixmapCount = 0;
+    QHash<HbIconKey, HbIconCacheItem*>::const_iterator itEnd(cache->constEnd());
+    for (QHash<HbIconKey,
+            HbIconCacheItem *>::const_iterator iter = cache->constBegin();
+            iter != itEnd;
+            ++iter) {
+        HbIconCacheItem *temp = iter.value();
+        if( temp->rasterIconData.type == OTHER_SUPPORTED_FORMATS ){
+            pixmapCount++;
+        }
+    }
+    return pixmapCount;
+}
+
+void HbIconDataCache::freeGpuRam()
+{
+    freeGpuRam(gpuLruListSize, false);
+}
 /*!
     \fn HbIconDataCache::freeUnusedGpuResources()
     This function internally calls createGpuCacheSpace() which will free up