34 |
34 |
35 /*! |
35 /*! |
36 @hbserver |
36 @hbserver |
37 \class HbIconDataCache |
37 \class HbIconDataCache |
38 \brief HbIconDataCache provides an implementation for the theme server's icon cache. |
38 \brief HbIconDataCache provides an implementation for the theme server's icon cache. |
39 It acts as a central repository for storing the various details of all the icons cached in the server. |
39 It acts as a central repository for storing the various details |
40 It provides various methods to insert new items, remove items as well as find existing cached items in the cache. |
40 of all the icons cached in the server. It provides various methods to insert new items, |
|
41 remove items as well as find existing cached items in the cache. |
41 It also has methods to limit the cache size both on Gpu as well as Cpu shared memory. |
42 It also has methods to limit the cache size both on Gpu as well as Cpu shared memory. |
42 |
43 |
43 Reference count based caching - On performing an Icon look up in the server, if the icon is not already cached, |
44 Reference count based caching - On performing an Icon look up in the server, |
44 the cache item is created and inserted into cache and its reference count is incremented. |
45 if the icon is not already cached, the cache item is created and inserted into cache |
45 If the same icon is requested by another application, the cached instance is returned and only the reference |
46 and its reference count is incremented. |
46 count is incremented. Similarly, the refrence count is decremented whenever an icon is destroyed. |
47 If the same icon is requested by another application, the cached instance is returned |
|
48 and only the reference count is incremented. |
|
49 Similarly, the refrence count is decremented whenever an icon is destroyed. |
47 |
50 |
48 LRU policy is used for removal of icons from cache. |
51 LRU policy is used for removal of icons from cache. |
49 The cache maintains two separate doubly link lists to maintain the order of the least recently used icons created |
52 The cache maintains two separate doubly link lists to maintain the order |
50 in GPU memory as well as those created in the shared memory. Whenever, the reference count for a cached item becomes 0, |
53 of the least recently used icons created in GPU memory as well as those created |
|
54 in the shared memory. Whenever, the reference count for a cached item becomes 0, |
51 it is not deleted from the cache rather; the cached icon instance is appended to the LRU list. |
55 it is not deleted from the cache rather; the cached icon instance is appended to the LRU list. |
52 Consider now that a scenario arrives when the cache has reached its max limit and there are some unused icons |
56 Consider now that a scenario arrives when the cache has reached its max limit |
53 (i.e. icons with reference count = 0) in the LRU list. Suppose at this point there is a new icon caching request. |
57 and there are some unused icons (i.e. icons with reference count = 0) in the LRU list. |
54 In such a scenario, the unused icons, starting with those at the beginning of the LRU lists are removed from the cache, |
58 Suppose at this point there is a new icon caching request. |
55 one after the other, till the new icon can be accommodated. |
59 In such a scenario, the unused icons, starting with those at the beginning of the LRU lists |
|
60 are removed from the cache one after the other, till the new icon can be accommodated. |
56 |
61 |
57 Description of data members |
62 Description of data members |
58 // A list that maintains an ordered collection of least recently used icons in GPU |
63 // A list that maintains an ordered collection of least recently used icons in GPU |
59 // which are not being referred to anymore( i.e icons with reference count = 0) |
64 // which are not being referred to anymore( i.e icons with reference count = 0) |
60 HbDLinkList gpuLruList; |
65 HbDLinkList gpuLruList; |
135 gpuLruList.removeAll(); |
139 gpuLruList.removeAll(); |
136 cpuLruList.removeAll(); |
140 cpuLruList.removeAll(); |
137 |
141 |
138 GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory) |
142 GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory) |
139 QHash<HbIconKey, HbIconCacheItem*>::const_iterator itEnd(cache->constEnd()); |
143 QHash<HbIconKey, HbIconCacheItem*>::const_iterator itEnd(cache->constEnd()); |
140 for (QHash < HbIconKey, |
144 for (QHash<HbIconKey, |
141 HbIconCacheItem* >::const_iterator iter = cache->constBegin(); |
145 HbIconCacheItem *>::const_iterator iter = cache->constBegin(); |
142 iter != itEnd; |
146 iter != itEnd; |
143 ++iter) { |
147 ++iter) { |
144 HbIconCacheItem* temp = iter.value(); |
148 HbIconCacheItem *temp = iter.value(); |
145 if (temp->rasterIconData.type != INVALID_FORMAT) { |
149 if (temp->rasterIconData.type != INVALID_FORMAT) { |
146 switch (temp->rasterIconData.type) { |
150 switch (temp->rasterIconData.type) { |
147 case PIC : |
151 case PIC : |
148 manager->free(temp->rasterIconData.picData.offset); |
152 manager->free(temp->rasterIconData.picData.offset); |
149 break; |
153 break; |
204 Provides a mechanism for finidng whether a cache item is present in the cache. |
208 Provides a mechanism for finidng whether a cache item is present in the cache. |
205 If found, returns the cache item and increments the reference count else returns NULL. |
209 If found, returns the cache item and increments the reference count else returns NULL. |
206 \a key denotes the unique identifier for the cache item that is to be searched in the cache. |
210 \a key denotes the unique identifier for the cache item that is to be searched in the cache. |
207 |
211 |
208 */ |
212 */ |
209 HbIconCacheItem* HbIconDataCache::getCacheItem(const HbIconKey &key , |
213 HbIconCacheItem *HbIconDataCache::getCacheItem(const HbIconKey &key, |
210 HbRenderingMode currentRenderingMode, |
214 HbRenderingMode currentRenderingMode, |
211 bool isMultiIconPiece) |
215 bool isMultiIconPiece) |
212 { |
216 { |
213 HbIconCacheItem* item = 0; |
217 HbIconCacheItem *item = 0; |
214 |
218 |
215 if (!cache->contains(key)) { |
219 if (!cache->contains(key)) { |
216 return 0; |
220 return 0; |
217 } |
221 } |
218 // Get the cache item associated with the key |
222 // Get the cache item associated with the key |
246 // If the Icon does not have GPU shared data and there is enough space to cache |
250 // If the Icon does not have GPU shared data and there is enough space to cache |
247 // the icon in GPU cache now, we go ahead and create GPU shared data |
251 // the icon in GPU cache now, we go ahead and create GPU shared data |
248 if ((item->rasterIconData.type == INVALID_FORMAT) && |
252 if ((item->rasterIconData.type == INVALID_FORMAT) && |
249 (goodMemory && !isMultiIconPiece)) { |
253 (goodMemory && !isMultiIconPiece)) { |
250 if (item->vectorIconData.type == NVG) { |
254 if (item->vectorIconData.type == NVG) { |
251 |
|
252 HbIconCacheItemCreator::createCacheItem(*item, key, currentRenderingMode); |
255 HbIconCacheItemCreator::createCacheItem(*item, key, currentRenderingMode); |
253 if (item->rasterIconData.type != INVALID_FORMAT) { |
256 if (item->rasterIconData.type != INVALID_FORMAT) { |
254 currentGpuCacheSize += item->rasterIconDataCost; |
257 currentGpuCacheSize += item->rasterIconDataCost; |
255 } |
258 } |
256 } |
259 } |
257 |
|
258 //Debug Code for Test Purpose |
260 //Debug Code for Test Purpose |
259 #ifdef HB_ICON_CACHE_DEBUG |
261 #ifdef HB_ICON_CACHE_DEBUG |
260 addedItemMem = item->rasterIconDataCost; |
262 addedItemMem = item->rasterIconDataCost; |
261 #endif |
263 #endif |
262 } |
264 } |
263 |
|
264 // If the Icon is present in CPU LRU list, then remove it from the list |
265 // If the Icon is present in CPU LRU list, then remove it from the list |
265 if (((item->cpuLink.next() != 0) || (item->cpuLink.prev() != 0)) || |
266 if (((item->cpuLink.next() != 0) || (item->cpuLink.prev() != 0)) || |
266 ((item == cpuLruList.front()) && (item == cpuLruList.back()))) { |
267 ((item == cpuLruList.front()) && (item == cpuLruList.back()))) { |
267 cpuLruList.removeNode(item); |
268 cpuLruList.removeNode(item); |
268 if (item->rasterIconData.type == OTHER_SUPPORTED_FORMATS) { |
269 if (item->rasterIconData.type == OTHER_SUPPORTED_FORMATS) { |
312 /*! |
313 /*! |
313 \fn HbIconDataCache::insert() |
314 \fn HbIconDataCache::insert() |
314 Provides a mechanism for inserting items into the cache. |
315 Provides a mechanism for inserting items into the cache. |
315 Checks are first done to see whether item can be accomodated in the GPU memory. |
316 Checks are first done to see whether item can be accomodated in the GPU memory. |
316 If so the Gpu limits are updated. Next it tries to cache the item in the Cpu. |
317 If so the Gpu limits are updated. Next it tries to cache the item in the Cpu. |
317 If possible, the Cpu limits are updated. If niether is possible, a failure to insert is returned. |
318 If possible, the Cpu limits are updated. If neither is possible, |
318 In case of success, the item is inserted into the cache and the reference count for the item is incremented by 1. |
319 a failure to insert is returned. |
|
320 In case of success, the item is inserted into the cache and |
|
321 the reference count for the item is incremented by 1. |
319 \a key denotes the unique identifier for the cache item that is to be inserted into the cache. |
322 \a key denotes the unique identifier for the cache item that is to be inserted into the cache. |
320 \a item the cache item that is to be inserted into the cache. |
323 \a item the cache item that is to be inserted into the cache. |
321 |
324 |
322 */ |
325 */ |
323 bool HbIconDataCache::insert(const HbIconKey &key, HbIconCacheItem* item) |
326 bool HbIconDataCache::insert(const HbIconKey &key, HbIconCacheItem *item) |
324 { |
327 { |
325 if (!item) |
328 if (!item) { |
326 return false; |
329 return false; |
|
330 } |
327 |
331 |
328 // Check if Item can be accomdated in GPU cache |
332 // Check if Item can be accomdated in GPU cache |
329 bool gpuCaching = isItemCachableInGpu(item); |
333 bool gpuCaching = isItemCachableInGpu(item); |
330 // Check if Item can be accomdated in CPU cache |
334 // Check if Item can be accomdated in CPU cache |
331 bool cpuCaching = isItemCachableInCpu(item); |
335 bool cpuCaching = isItemCachableInCpu(item); |
332 |
336 |
333 // Item cannot be inserted either into GPU cache memory or CPU cache memory |
337 // Item cannot be inserted either into GPU cache memory or CPU cache memory |
334 if ((!gpuCaching) && (!cpuCaching)) { |
338 if ((!gpuCaching) && (!cpuCaching)) { |
335 return false; |
339 return false; |
336 } |
340 } |
337 |
|
338 // Item can be accomdated in GPU cache |
341 // Item can be accomdated in GPU cache |
339 if (gpuCaching) { |
342 if (gpuCaching) { |
340 // Increment the GPU cache size |
343 // Increment the GPU cache size |
341 if( item->rasterIconDataCost <= maxGpuCacheLimit ) { |
344 if( item->rasterIconDataCost <= maxGpuCacheLimit ) { |
342 currentGpuCacheSize += item->rasterIconDataCost; |
345 currentGpuCacheSize += item->rasterIconDataCost; |
357 // Increment the CPU cache size |
360 // Increment the CPU cache size |
358 if (item->vectorIconDataCost <= (maxCpuCacheLimit - currentCpuCacheSize)) { |
361 if (item->vectorIconDataCost <= (maxCpuCacheLimit - currentCpuCacheSize)) { |
359 currentCpuCacheSize += item->vectorIconDataCost; |
362 currentCpuCacheSize += item->vectorIconDataCost; |
360 } else { |
363 } else { |
361 // New item's icon data cost is more than available free CPU cahe size |
364 // New item's icon data cost is more than available free CPU cahe size |
362 // Check if some items, whose ref count is 0, can be removed to make way for new item |
365 // Check if some items, whose ref count is 0, |
|
366 // can be removed to make way for new item |
363 createCpuCacheSpace(item->vectorIconDataCost); |
367 createCpuCacheSpace(item->vectorIconDataCost); |
364 currentCpuCacheSize += item->vectorIconDataCost; |
368 currentCpuCacheSize += item->vectorIconDataCost; |
365 } |
369 } |
366 } |
370 } |
367 |
|
368 if (currentCpuCacheSize > maxCpuCacheLimit) { |
371 if (currentCpuCacheSize > maxCpuCacheLimit) { |
369 currentCpuCacheSize = maxCpuCacheLimit; |
372 currentCpuCacheSize = maxCpuCacheLimit; |
370 } |
373 } |
371 } |
374 } |
372 QHash<HbIconKey, HbIconCacheItem*>::iterator iter = cache->insert(key, const_cast<HbIconCacheItem*>(item)); |
375 QHash<HbIconKey, HbIconCacheItem*>::iterator iter = |
|
376 cache->insert(key, const_cast<HbIconCacheItem*>(item)); |
373 if (iter == cache->end()) { |
377 if (iter == cache->end()) { |
374 return false; |
378 return false; |
375 } |
379 } |
376 |
380 |
377 item->refCount ++; |
381 item->refCount ++; |
383 if (gpuCaching) { |
387 if (gpuCaching) { |
384 addedItemMem = item->rasterIconDataCost; |
388 addedItemMem = item->rasterIconDataCost; |
385 } else if (cpuCaching) { |
389 } else if (cpuCaching) { |
386 addedItemMem = item->vectorIconDataCost; |
390 addedItemMem = item->vectorIconDataCost; |
387 } |
391 } |
388 qDebug() << "HbIconDataCache::insert: " << "Item " << key.filename<<" inserted in Server-Cache"; |
392 qDebug() << "HbIconDataCache::insert: " << "Item " << key.filename |
|
393 << " inserted in Server-Cache"; |
389 qDebug() << "HbIconDataCache::insert: Server RefCount now = " << item->refCount; |
394 qDebug() << "HbIconDataCache::insert: Server RefCount now = " << item->refCount; |
390 #endif |
395 #endif |
391 |
396 |
392 return true; |
397 return true; |
393 } |
398 } |
394 |
399 |
395 /*! |
400 /*! |
396 \fn HbIconDataCache::remove() |
401 \fn HbIconDataCache::remove() |
397 Remove provides a mechanism for decrementing the reference count of a cached item. |
402 Remove provides a mechanism for decrementing the reference count of a cached item. |
398 In case the reference count becomes 0, the cache item instance is appended to the corresponding LRU list. |
403 In case the reference count becomes 0, |
399 Actual removal of the cache item from the cache only occurs when the cache has reached a max limit and a new request for |
404 the cache item instance is appended to the corresponding LRU list. |
400 insert comes. |
405 Actual removal of the cache item from the cache only occurs |
401 \a key denotes the unique identifier for the cache item whose ref count is to be decremented in the cache. |
406 when the cache has reached a max limit and a new request for insert comes. |
402 |
407 \a key denotes the unique identifier for the cache item whose |
403 */ |
408 ref count is to be decremented in the cache. |
404 bool HbIconDataCache::remove(const HbIconKey& key, bool keepInCache) |
409 |
|
410 */ |
|
411 bool HbIconDataCache::remove(const HbIconKey &key, bool keepInCache) |
405 { |
412 { |
406 if (key.filename.isEmpty() || !cache->contains(key)) { |
413 if (key.filename.isEmpty() || !cache->contains(key)) { |
407 return false; |
414 return false; |
408 } |
415 } |
409 HbIconCacheItem* item = (*cache)[(key)]; |
416 HbIconCacheItem *item = (*cache)[(key)]; |
410 item->refCount--; |
417 item->refCount--; |
411 |
418 |
412 //Debug Code for Test Purpose |
419 //Debug Code for Test Purpose |
413 #ifdef HB_ICON_CACHE_DEBUG |
420 #ifdef HB_ICON_CACHE_DEBUG |
414 remRfCount = item->refCount; |
421 remRfCount = item->refCount; |
423 releaseRasterItem(item); |
430 releaseRasterItem(item); |
424 removeFromCache(key, item); |
431 removeFromCache(key, item); |
425 return true; |
432 return true; |
426 } |
433 } |
427 } |
434 } |
428 |
|
429 if (item->rasterIconData.type == OTHER_SUPPORTED_FORMATS) { |
435 if (item->rasterIconData.type == OTHER_SUPPORTED_FORMATS) { |
430 if (keepInCache) { |
436 if (keepInCache) { |
431 cpuLruList.insertBack(item); |
437 cpuLruList.insertBack(item); |
432 updateCpuLruSize(item->rasterIconDataCost); |
438 updateCpuLruSize(item->rasterIconDataCost); |
433 } else { |
439 } else { |
434 releaseRasterItem(item); |
440 releaseRasterItem(item); |
435 removeFromCache(key, item); |
441 removeFromCache(key, item); |
436 return true; |
442 return true; |
437 } |
443 } |
438 } |
444 } |
439 |
|
440 |
|
441 //Debug Code for Test Purpose |
445 //Debug Code for Test Purpose |
442 #ifdef HB_ICON_CACHE_DEBUG |
446 #ifdef HB_ICON_CACHE_DEBUG |
443 if (! enableCaching) { |
447 if (! enableCaching) { |
444 currentGpuCacheSize -= item->rasterIconDataCost; |
448 currentGpuCacheSize -= item->rasterIconDataCost; |
445 removedItemMem = item->rasterIconDataCost; |
449 removedItemMem = item->rasterIconDataCost; |
452 if (currentGpuCacheSize < 0) { |
456 if (currentGpuCacheSize < 0) { |
453 currentGpuCacheSize = 0; |
457 currentGpuCacheSize = 0; |
454 } |
458 } |
455 } else { |
459 } else { |
456 #endif |
460 #endif |
457 |
|
458 |
|
459 //Debug Code for Test Purpose |
461 //Debug Code for Test Purpose |
460 #ifdef HB_ICON_CACHE_DEBUG |
462 #ifdef HB_ICON_CACHE_DEBUG |
461 rasterLruListCount++; |
463 rasterLruListCount++; |
462 } |
464 } |
463 #endif |
465 #endif |
464 |
|
465 |
466 |
466 if ((item->vectorIconData.type != INVALID_FORMAT) && item->refCount == 0) { |
467 if ((item->vectorIconData.type != INVALID_FORMAT) && item->refCount == 0) { |
467 |
468 |
468 //Debug Code for Test Purpose |
469 //Debug Code for Test Purpose |
469 #ifdef HB_ICON_CACHE_DEBUG |
470 #ifdef HB_ICON_CACHE_DEBUG |
557 } |
557 } |
558 |
558 |
559 /*! |
559 /*! |
560 \fn HbIconDataCache::contains() |
560 \fn HbIconDataCache::contains() |
561 Provides a mecahnism for finding whether an item exists in cache. |
561 Provides a mecahnism for finding whether an item exists in cache. |
562 Is different from the find function in that, this function simply checks whether an item is presentin cache, whereas find |
562 Is different from the find function in that, |
|
563 this function simply checks whether an item is presentin cache, whereas find |
563 also performs additional operations such as incrementing the reference count. |
564 also performs additional operations such as incrementing the reference count. |
564 \a key denotes the unique identifier for the cache item that is to be found into the cache. |
565 \a key denotes the unique identifier for the cache item that is to be found into the cache. |
565 |
566 |
566 */ |
567 */ |
567 bool HbIconDataCache::contains(const HbIconKey &key)const |
568 bool HbIconDataCache::contains(const HbIconKey &key) const |
568 { |
569 { |
569 return (cache->contains(key)); |
570 return (cache->contains(key)); |
570 } |
571 } |
571 |
572 |
572 /*! |
573 /*! |
573 \fn HbIconDataCache::value() |
574 \fn HbIconDataCache::value() |
574 Value provides a mechanism for returning the value of the cache item associated with the key |
575 Value provides a mechanism for returning the value of the cache item associated with the key |
575 \a key denotes the unique identifier for the cache item whose value is to be returned |
576 \a key denotes the unique identifier for the cache item whose value is to be returned |
576 |
577 |
577 */ |
578 */ |
578 HbIconCacheItem* HbIconDataCache::value(const HbIconKey &key)const |
579 HbIconCacheItem *HbIconDataCache::value(const HbIconKey &key) const |
579 { |
580 { |
580 if (cache->contains(key)) { |
581 if (cache->contains(key)) { |
581 return cache->value(key); |
582 return cache->value(key); |
582 } else { |
583 } else { |
583 return 0; |
584 return 0; |
584 } |
585 } |
585 } |
586 } |
586 |
587 |
587 |
|
588 /*! |
588 /*! |
589 \fn HbIconDataCache::isItemCachableInGpu() |
589 \fn HbIconDataCache::isItemCachableInGpu() |
590 Checks if the new item can be accomdated in the Gpu memory. |
590 Checks if the new item can be accomdated in the Gpu memory. |
591 \a item is the new item to be cached |
591 \a item is the new item to be cached |
592 BLOB is always cached in cpu so this function always returns false for such items. |
592 BLOB is always cached in cpu so this function always returns false for such items. |
593 */ |
593 */ |
594 bool HbIconDataCache::isItemCachableInGpu(const HbIconCacheItem* item)const |
594 bool HbIconDataCache::isItemCachableInGpu(const HbIconCacheItem *item) const |
595 { |
595 { |
596 if (maxGpuCacheLimit <= 0 || item->rasterIconDataCost <= 0 || item->blobIconData.type != INVALID_FORMAT || |
596 if (maxGpuCacheLimit <= 0 || item->rasterIconDataCost <= 0 |
597 item->rasterIconData.type != SGIMAGE) { |
597 || item->blobIconData.type != INVALID_FORMAT || item->rasterIconData.type != SGIMAGE) { |
598 return false; |
598 return false; |
599 } |
599 } |
600 // Item's GPU Icon's cost is greater than the max GPU Limit |
600 // Item's GPU Icon's cost is greater than the max GPU Limit |
601 if (item->rasterIconDataCost > maxGpuCacheLimit) |
601 if (item->rasterIconDataCost > maxGpuCacheLimit) { |
602 return false; |
602 return false; |
603 |
603 } |
604 return true; |
604 return true; |
605 } |
605 } |
606 |
606 |
607 /*! |
607 /*! |
608 \fn HbIconDataCache::isItemCachableInCpu() |
608 \fn HbIconDataCache::isItemCachableInCpu() |
609 Checks if the new item can be accomdated in the cpu shared memory. |
609 Checks if the new item can be accomdated in the cpu shared memory. |
610 \a item is the new item to be cached |
610 \a item is the new item to be cached |
611 BLOB is always cached in cpu, never in gpu. |
611 BLOB is always cached in cpu, never in gpu. |
612 */ |
612 */ |
613 bool HbIconDataCache::isItemCachableInCpu(const HbIconCacheItem* item)const |
613 bool HbIconDataCache::isItemCachableInCpu(const HbIconCacheItem *item) const |
614 { |
614 { |
615 if (maxCpuCacheLimit <= 0) { |
615 if (maxCpuCacheLimit <= 0) { |
616 return false; |
616 return false; |
617 } |
617 } |
618 if (item->rasterIconData.type == OTHER_SUPPORTED_FORMATS) { |
618 if (item->rasterIconData.type == OTHER_SUPPORTED_FORMATS) { |
620 return false; |
620 return false; |
621 } |
621 } |
622 if (item->rasterIconDataCost <= (maxCpuCacheLimit - currentCpuCacheSize)) { |
622 if (item->rasterIconDataCost <= (maxCpuCacheLimit - currentCpuCacheSize)) { |
623 return true; |
623 return true; |
624 } else { |
624 } else { |
625 return (item->rasterIconDataCost <= (maxCpuCacheLimit - currentCpuCacheSize) + cpuLruListSize); |
625 return (item->rasterIconDataCost <= (maxCpuCacheLimit - currentCpuCacheSize) |
626 } |
626 + cpuLruListSize); |
627 } |
627 } |
628 |
628 } |
629 if (item->vectorIconData.type != INVALID_FORMAT) { |
629 if (item->vectorIconData.type != INVALID_FORMAT) { |
630 if (item->vectorIconDataCost <= 0 || item->vectorIconDataCost > maxCpuCacheLimit) { |
630 if (item->vectorIconDataCost <= 0 || item->vectorIconDataCost > maxCpuCacheLimit) { |
631 return false; |
631 return false; |
632 } |
632 } |
633 if (item->vectorIconDataCost <= (maxCpuCacheLimit - currentCpuCacheSize)) { |
633 if (item->vectorIconDataCost <= (maxCpuCacheLimit - currentCpuCacheSize)) { |
634 return true; |
634 return true; |
635 } else { |
635 } else { |
636 return (item->vectorIconDataCost <= (maxCpuCacheLimit - currentCpuCacheSize) + cpuLruListSize); |
636 return (item->vectorIconDataCost <= (maxCpuCacheLimit - currentCpuCacheSize) |
|
637 + cpuLruListSize); |
637 } |
638 } |
638 } |
639 } |
639 return false; |
640 return false; |
640 } |
641 } |
641 |
642 |
642 /*! |
643 /*! |
643 \fn HbIconDataCache::createGpuCacheSpace() |
644 \fn HbIconDataCache::createGpuCacheSpace() |
644 This method provides a way to remove the unused icons( icons with ref count =0. |
645 This method provides a way to remove the unused icons( icons with ref count =0. |
645 It starts removing the icons from the cache, starting with those that are at the front of the Gpu LRU list. |
646 It starts removing the icons from the cache, |
|
647 starting with those that are at the front of the Gpu LRU list. |
646 It continues removal of items till there is enough space created to cache the new item in Gpu |
648 It continues removal of items till there is enough space created to cache the new item in Gpu |
647 \a itemCost - cost of the new item to be cached in the Gpu memory |
649 \a itemCost - cost of the new item to be cached in the Gpu memory |
648 |
650 |
649 */ |
651 */ |
650 void HbIconDataCache::createGpuCacheSpace(int itemCost) |
652 void HbIconDataCache::createGpuCacheSpace(int itemCost) |
651 { |
653 { |
652 if (!gpuLruList.isEmpty()) { |
654 if (!gpuLruList.isEmpty()) { |
653 // Keep removing items from the cache till there is |
655 // Keep removing items from the cache till there is |
654 // enough space to accomdate the new item |
656 // enough space to accomdate the new item |
655 int freedMemory = 0; |
657 int freedMemory = 0; |
656 while (itemCost > (freedMemory)) { |
658 while (itemCost > freedMemory) { |
657 HbIconCacheItem* itemToRemove = gpuLruList.removeFront(); |
659 HbIconCacheItem *itemToRemove = gpuLruList.removeFront(); |
658 // Decrement the Size by the cost of the removed icon's data cost |
660 // Decrement the Size by the cost of the removed icon's data cost |
659 //GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory) |
|
660 //qDebug() << "HbIconDataCache : Calling SgImage Close. Cost = %d "<< itemToRemove->rasterIconDataCost; |
|
661 #ifdef HB_SGIMAGE_ICON |
661 #ifdef HB_SGIMAGE_ICON |
662 #ifdef HB_ICON_CACHE_DEBUG |
662 #ifdef HB_ICON_CACHE_DEBUG |
663 qDebug() << "HbIconDataCache : Calling SgImage Close. Cost = %d "<< itemToRemove->rasterIconDataCost; |
663 qDebug() << "HbIconDataCache : Calling SgImage Close. Cost = %d " |
664 #endif |
664 << itemToRemove->rasterIconDataCost; |
665 HbSgImageRenderer::removeSgImageFromHash(itemToRemove->rasterIconData.sgImageData.id); |
665 #endif |
|
666 HbSgImageRenderer::removeSgImageFromHash(itemToRemove->rasterIconData.sgImageData.id); |
666 #endif |
667 #endif |
667 itemToRemove->rasterIconData.type = INVALID_FORMAT; |
668 itemToRemove->rasterIconData.type = INVALID_FORMAT; |
668 itemToRemove->gpuLink.setNext(0); |
669 itemToRemove->gpuLink.setNext(0); |
669 itemToRemove->gpuLink.setPrev(0); |
670 itemToRemove->gpuLink.setPrev(0); |
670 currentGpuCacheSize -= itemToRemove->rasterIconDataCost; |
671 currentGpuCacheSize -= itemToRemove->rasterIconDataCost; |
684 rasterLruListCount--; |
684 rasterLruListCount--; |
685 if (rasterLruListCount < 0) { |
685 if (rasterLruListCount < 0) { |
686 rasterLruListCount = 0; |
686 rasterLruListCount = 0; |
687 } |
687 } |
688 #endif |
688 #endif |
689 |
|
690 // This is the case where Icon has no CPU data and |
689 // This is the case where Icon has no CPU data and |
691 // the GPU cached data has also been deleted to make way for new Icon |
690 // the GPU cached data has also been deleted to make way for new Icon |
692 // In such a case the Item can be removed from the Hash |
691 // In such a case the Item can be removed from the Hash |
693 |
692 |
694 if ((itemToRemove->rasterIconData.type == INVALID_FORMAT) && |
693 if ((itemToRemove->rasterIconData.type == INVALID_FORMAT) && |
701 } |
700 } |
702 |
701 |
703 /*! |
702 /*! |
704 \fn HbIconDataCache::createCpuCacheSpace() |
703 \fn HbIconDataCache::createCpuCacheSpace() |
705 This method provides a way to remove the unused icons( icons with ref count =0). |
704 This method provides a way to remove the unused icons( icons with ref count =0). |
706 It starts removing the icons from the cache, starting with those that are at the front of the CPU LRU list. |
705 It starts removing the icons from the cache, |
|
706 starting with those that are at the front of the CPU LRU list. |
707 It continues removal of items till there is enough space created to cache the new item in Cpu |
707 It continues removal of items till there is enough space created to cache the new item in Cpu |
708 \a itemCost - cost of the new item to be cached in the Cpu memory |
708 \a itemCost - cost of the new item to be cached in the Cpu memory |
709 |
709 |
710 */ |
710 */ |
711 void HbIconDataCache::createCpuCacheSpace(int itemCost) |
711 void HbIconDataCache::createCpuCacheSpace(int itemCost) |
713 if (!cpuLruList.isEmpty()) { |
713 if (!cpuLruList.isEmpty()) { |
714 // Keep removing items from the cache till there is |
714 // Keep removing items from the cache till there is |
715 // enough space to accomdate the new item |
715 // enough space to accomdate the new item |
716 GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory) |
716 GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory) |
717 while (itemCost > (maxCpuCacheLimit - currentCpuCacheSize)) { |
717 while (itemCost > (maxCpuCacheLimit - currentCpuCacheSize)) { |
718 HbIconCacheItem* itemToRemove = cpuLruList.removeFront(); |
718 HbIconCacheItem *itemToRemove = cpuLruList.removeFront(); |
719 if (itemToRemove->rasterIconData.type == OTHER_SUPPORTED_FORMATS) { |
719 if (itemToRemove->rasterIconData.type == OTHER_SUPPORTED_FORMATS) { |
720 manager->free(itemToRemove->rasterIconData.pixmapData.offset); |
720 manager->free(itemToRemove->rasterIconData.pixmapData.offset); |
721 itemToRemove->rasterIconData.type = INVALID_FORMAT; |
721 itemToRemove->rasterIconData.type = INVALID_FORMAT; |
722 currentCpuCacheSize -= itemToRemove->rasterIconDataCost; |
722 currentCpuCacheSize -= itemToRemove->rasterIconDataCost; |
723 updateCpuLruSize(-itemToRemove->rasterIconDataCost); |
723 updateCpuLruSize(-itemToRemove->rasterIconDataCost); |
734 itemToRemove->vectorIconData.type = INVALID_FORMAT; |
734 itemToRemove->vectorIconData.type = INVALID_FORMAT; |
735 currentCpuCacheSize -= itemToRemove->vectorIconDataCost; |
735 currentCpuCacheSize -= itemToRemove->vectorIconDataCost; |
736 updateCpuLruSize(-itemToRemove->vectorIconDataCost); |
736 updateCpuLruSize(-itemToRemove->vectorIconDataCost); |
737 } |
737 } |
738 |
738 |
739 |
|
740 itemToRemove->cpuLink.setNext(0); |
739 itemToRemove->cpuLink.setNext(0); |
741 itemToRemove->cpuLink.setPrev(0); |
740 itemToRemove->cpuLink.setPrev(0); |
742 |
741 |
743 if (currentCpuCacheSize < 0) { |
742 if (currentCpuCacheSize < 0) { |
744 currentCpuCacheSize = 0; |
743 currentCpuCacheSize = 0; |
745 } |
744 } |
746 |
|
747 if (cpuLruListSize < 0) { |
745 if (cpuLruListSize < 0) { |
748 cpuLruListSize = 0; |
746 cpuLruListSize = 0; |
749 } |
747 } |
750 |
748 |
751 //Debug Code for Test Purpose |
749 //Debug Code for Test Purpose |
754 vectorLruListCount--; |
752 vectorLruListCount--; |
755 if (vectorLruListCount < 0) { |
753 if (vectorLruListCount < 0) { |
756 vectorLruListCount = 0; |
754 vectorLruListCount = 0; |
757 } |
755 } |
758 #endif |
756 #endif |
759 |
|
760 // This is the case where Icon has no CPU data and |
757 // This is the case where Icon has no CPU data and |
761 // the GPU cached data has also been deleted to make way for new Icon |
758 // the GPU cached data has also been deleted to make way for new Icon |
762 // In such a case the Item can be removed from the Hash |
759 // In such a case the Item can be removed from the Hash |
763 |
|
764 if ((itemToRemove->vectorIconData.type == INVALID_FORMAT) && |
760 if ((itemToRemove->vectorIconData.type == INVALID_FORMAT) && |
765 (itemToRemove->rasterIconData.type == INVALID_FORMAT)) { |
761 (itemToRemove->rasterIconData.type == INVALID_FORMAT)) { |
766 cache->remove(cache->key(itemToRemove)); |
762 cache->remove(cache->key(itemToRemove)); |
767 delete itemToRemove; |
763 delete itemToRemove; |
768 } |
764 } |
795 } |
791 } |
796 |
792 |
797 // Iterate through the cache and remove any active SgImages, before the context |
793 // Iterate through the cache and remove any active SgImages, before the context |
798 // is destroyed. |
794 // is destroyed. |
799 QHash<HbIconKey, HbIconCacheItem*>::const_iterator itEnd(cache->constEnd()); |
795 QHash<HbIconKey, HbIconCacheItem*>::const_iterator itEnd(cache->constEnd()); |
800 for (QHash < HbIconKey, |
796 for (QHash<HbIconKey, |
801 HbIconCacheItem* >::const_iterator iter = cache->constBegin(); |
797 HbIconCacheItem *>::const_iterator iter = cache->constBegin(); |
802 iter != itEnd; |
798 iter != itEnd; |
803 ++iter) { |
799 ++iter) { |
804 HbIconCacheItem* temp = iter.value(); |
800 HbIconCacheItem *temp = iter.value(); |
805 if( temp->rasterIconData.type == SGIMAGE ){ |
801 if( temp->rasterIconData.type == SGIMAGE ){ |
806 #ifdef HB_SGIMAGE_ICON |
802 #ifdef HB_SGIMAGE_ICON |
807 HbSgImageRenderer::removeSgImageFromHash(temp->rasterIconData.sgImageData.id); |
803 HbSgImageRenderer::removeSgImageFromHash(temp->rasterIconData.sgImageData.id); |
808 #endif |
804 #endif |
809 temp->rasterIconData.type = INVALID_FORMAT; |
805 temp->rasterIconData.type = INVALID_FORMAT; |
810 temp->gpuLink.setNext(0); |
806 temp->gpuLink.setNext(0); |
811 temp->gpuLink.setPrev(0); |
807 temp->gpuLink.setPrev(0); |
812 currentGpuCacheSize -= temp->rasterIconDataCost; |
808 currentGpuCacheSize -= temp->rasterIconDataCost; |
813 } |
809 } |
814 } |
810 } |
815 |
|
816 } |
811 } |
817 |
812 |
818 /*! |
813 /*! |
819 \fn HbIconDataCache::freeUnusedGpuResources() |
814 \fn HbIconDataCache::freeUnusedGpuResources() |
820 This function internally calls createGpuCacheSpace() which will free up |
815 This function internally calls createGpuCacheSpace() which will free up |
827 |
822 |
828 QVector<const HbIconKey *> HbIconDataCache::getKeys(const QString &filename) const |
823 QVector<const HbIconKey *> HbIconDataCache::getKeys(const QString &filename) const |
829 { |
824 { |
830 QVector<const HbIconKey *> keys; |
825 QVector<const HbIconKey *> keys; |
831 QHash<HbIconKey, HbIconCacheItem*>::const_iterator itEnd(cache->constEnd()); |
826 QHash<HbIconKey, HbIconCacheItem*>::const_iterator itEnd(cache->constEnd()); |
832 for (QHash < HbIconKey, |
827 for (QHash<HbIconKey, |
833 HbIconCacheItem* >::const_iterator iter = cache->constBegin(); |
828 HbIconCacheItem *>::const_iterator iter = cache->constBegin(); |
834 iter != itEnd; |
829 iter != itEnd; |
835 ++iter) { |
830 ++iter) { |
836 const HbIconKey *key = &iter.key(); |
831 const HbIconKey *key = &iter.key(); |
837 if (key->filename == filename) { |
832 if (key->filename == filename) { |
838 keys.append(key); |
833 keys.append(key); |
843 |
838 |
844 //Debug Code for Test Purpose |
839 //Debug Code for Test Purpose |
845 #ifdef HB_ICON_CACHE_DEBUG |
840 #ifdef HB_ICON_CACHE_DEBUG |
846 void HbIconDataCache::cleanVectorLRUList() |
841 void HbIconDataCache::cleanVectorLRUList() |
847 { |
842 { |
848 |
|
849 // remove all the items in cpu LRU list. |
843 // remove all the items in cpu LRU list. |
850 while (cpuLruList.front()) { |
844 while (cpuLruList.front()) { |
851 HbIconCacheItem* itemToRemove = cpuLruList.removeFront(); |
845 HbIconCacheItem *itemToRemove = cpuLruList.removeFront(); |
852 |
846 |
853 // update the member |
847 // update the member |
854 currentCpuCacheSize -= itemToRemove->vectorIconDataCost; |
848 currentCpuCacheSize -= itemToRemove->vectorIconDataCost; |
855 cpuLruListSize -= itemToRemove->vectorIconDataCost; |
849 cpuLruListSize -= itemToRemove->vectorIconDataCost; |
856 if (currentCpuCacheSize < 0) { |
850 if (currentCpuCacheSize < 0) { |
866 vectorLruListCount--; |
860 vectorLruListCount--; |
867 if (vectorLruListCount < 0) { |
861 if (vectorLruListCount < 0) { |
868 vectorLruListCount = 0; |
862 vectorLruListCount = 0; |
869 } |
863 } |
870 #endif |
864 #endif |
871 |
|
872 // remove the shared memory allocatedfor this item. |
865 // remove the shared memory allocatedfor this item. |
873 releaseVectorItem(itemToRemove); |
866 releaseVectorItem(itemToRemove); |
874 |
867 |
875 // release item from cache |
868 // release item from cache |
876 removeFromCache(cache->key(itemToRemove), itemToRemove); |
869 removeFromCache(cache->key(itemToRemove), itemToRemove); |
877 } |
870 } |
878 } |
871 } |
879 #endif // HB_ICON_CACHE_DEBUG |
872 #endif // HB_ICON_CACHE_DEBUG |
880 |
873 |
881 void HbIconDataCache::releaseVectorItem(HbIconCacheItem* releaseItem) |
874 void HbIconDataCache::releaseVectorItem(HbIconCacheItem *releaseItem) |
882 { |
875 { |
883 if (!releaseItem) { |
876 if (!releaseItem) { |
884 return; |
877 return; |
885 } |
878 } |
886 GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory) |
879 GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory) |
901 } |
894 } |
902 |
895 |
903 #ifdef HB_ICON_CACHE_DEBUG |
896 #ifdef HB_ICON_CACHE_DEBUG |
904 void HbIconDataCache::cleanRasterLRUList() |
897 void HbIconDataCache::cleanRasterLRUList() |
905 { |
898 { |
906 |
|
907 // remove all the items from the gpu LRU list |
899 // remove all the items from the gpu LRU list |
908 while (gpuLruList.front()) { |
900 while (gpuLruList.front()) { |
909 HbIconCacheItem* itemToRemove = gpuLruList.removeFront(); |
901 HbIconCacheItem *itemToRemove = gpuLruList.removeFront(); |
910 |
902 |
911 // update the member |
903 // update the member |
912 currentGpuCacheSize -= itemToRemove->rasterIconDataCost; |
904 currentGpuCacheSize -= itemToRemove->rasterIconDataCost; |
913 gpuLruListSize -= itemToRemove->rasterIconDataCost; |
905 gpuLruListSize -= itemToRemove->rasterIconDataCost; |
914 |
906 |
915 if (currentGpuCacheSize < 0) { |
907 if (currentGpuCacheSize < 0) { |
916 currentGpuCacheSize = 0; |
908 currentGpuCacheSize = 0; |
917 } |
909 } |
918 |
|
919 if (gpuLruListSize < 0) { |
910 if (gpuLruListSize < 0) { |
920 gpuLruListSize = 0; |
911 gpuLruListSize = 0; |
921 } |
912 } |
922 #ifdef HB_ICON_CACHE_DEBUG |
913 #ifdef HB_ICON_CACHE_DEBUG |
923 removedItemMem = itemToRemove->rasterIconDataCost; |
914 removedItemMem = itemToRemove->rasterIconDataCost; |
924 rasterLruListCount--; |
915 rasterLruListCount--; |
925 if (rasterLruListCount < 0) { |
916 if (rasterLruListCount < 0) { |
926 rasterLruListCount = 0; |
917 rasterLruListCount = 0; |
927 } |
918 } |
928 #endif |
919 #endif |
929 |
|
930 // release the shared memory (later raster memory)of this item. |
920 // release the shared memory (later raster memory)of this item. |
931 releaseRasterItem(itemToRemove); |
921 releaseRasterItem(itemToRemove); |
932 |
922 |
933 // relese from the cache. |
923 // relese from the cache. |
934 removeFromCache(cache->key(itemToRemove), itemToRemove); |
924 removeFromCache(cache->key(itemToRemove), itemToRemove); |
935 } |
925 } |
936 } |
926 } |
937 #endif // HB_ICON_CACHE_DEBUG |
927 #endif // HB_ICON_CACHE_DEBUG |
938 |
928 |
939 void HbIconDataCache::releaseRasterItem(HbIconCacheItem* releaseItem) |
929 void HbIconDataCache::releaseRasterItem(HbIconCacheItem *releaseItem) |
940 { |
930 { |
941 if (!releaseItem) { |
931 if (!releaseItem) { |
942 return; |
932 return; |
943 } |
933 } |
944 GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory) |
934 GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory) |
945 // release the removed item data |
935 // release the removed item data |
946 manager->free(releaseItem->rasterIconData.pixmapData.offset); |
936 manager->free(releaseItem->rasterIconData.pixmapData.offset); |
947 releaseItem->rasterIconData.type = INVALID_FORMAT; |
937 releaseItem->rasterIconData.type = INVALID_FORMAT; |
948 } |
938 } |
949 |
939 |
950 void HbIconDataCache::removeFromCache(const HbIconKey &key, const HbIconCacheItem* releaseItem) |
940 void HbIconDataCache::removeFromCache(const HbIconKey &key, const HbIconCacheItem *releaseItem) |
951 { |
941 { |
952 if (!releaseItem) { |
942 if (!releaseItem) { |
953 return; |
943 return; |
954 } |
944 } |
955 |
945 |
956 if ((releaseItem->vectorIconData.type == INVALID_FORMAT) && |
946 if (releaseItem->vectorIconData.type == INVALID_FORMAT |
957 (releaseItem->rasterIconData.type == INVALID_FORMAT)) { |
947 && releaseItem->rasterIconData.type == INVALID_FORMAT) { |
958 cache->remove(key); |
948 cache->remove(key); |
959 delete releaseItem; |
949 delete releaseItem; |
960 } |
950 } |
961 } |
951 } |
962 |
952 |