3041 // |
3041 // |
3042 // --------------------------------------------------------------------------- |
3042 // --------------------------------------------------------------------------- |
3043 // |
3043 // |
3044 void CHuiCanvasTextureCache::HandleOutOfTextureMemory() |
3044 void CHuiCanvasTextureCache::HandleOutOfTextureMemory() |
3045 { |
3045 { |
3046 RDebug::Print(_L("CHuiCanvasTextureCache::HandleOutOfTextureMemory: Out of memory happened !")); |
3046 #ifdef HUI_DEBUG_PRINT_CANVAS_TEXTURE_CACHE |
3047 |
3047 RDebug::Print(_L("CHuiCanvasTextureCache::HandleOutOfTextureMemory")); |
|
3048 #endif |
3048 DeleteAllReleasedEntries(EFalse); |
3049 DeleteAllReleasedEntries(EFalse); |
3049 |
3050 |
3050 // TODO: Who you gonna call when texture memory is full and we cannot ourself |
3051 // TODO: Who you gonna call when texture memory is full and we cannot ourself |
3051 // delete anymore textures ? |
3052 // delete anymore textures ? |
3052 // |
3053 // |
3136 // |
3137 // |
3137 TInt CHuiCanvasTextureCache::CalculateUnusedCanvasTextureUsageInKbytes() |
3138 TInt CHuiCanvasTextureCache::CalculateUnusedCanvasTextureUsageInKbytes() |
3138 { |
3139 { |
3139 // TODO: This should handle NVG textures |
3140 // TODO: This should handle NVG textures |
3140 |
3141 |
|
3142 // No need to fetch only the unused texture entries to a separate binary |
|
3143 // ordered tree (with FindUnusedEntries()), just going the cached |
|
3144 // texts & images through once is enough. |
3141 TInt totalUnusedTextureBytes = 0; |
3145 TInt totalUnusedTextureBytes = 0; |
|
3146 TSize textureSize(0,0); |
3142 |
3147 |
3143 // Texts |
3148 // Texts |
3144 RPointerArray<CHuiCanvasTextImage> textEntries; |
3149 for(TInt i = iCachedTexts.Count() - 1; i >= 0; i--) |
3145 |
3150 { |
3146 FindUnusedTextEntries(textEntries); |
3151 CHuiCanvasTextImage* entry = iCachedTexts[i]; |
3147 |
3152 // Check if the texture is being used.. |
3148 for(TInt i=textEntries.Count() - 1; i >= 0; i--) |
3153 if (!entry->iActiveUsers.Count()) |
3149 { |
3154 { |
3150 TSize textureSize = textEntries[i]->iTexture->Size(); |
3155 // ..and if not, add it to the sum. |
3151 totalUnusedTextureBytes += textureSize.iWidth * textureSize.iHeight * KHuiCanvasTextEstimatedBpp/8.f; |
3156 textureSize = entry->iTexture->Size(); |
3152 } |
3157 totalUnusedTextureBytes += textureSize.iWidth * textureSize.iHeight * KHuiCanvasTextEstimatedBpp/8.f; |
3153 |
3158 } |
3154 textEntries.Close(); |
3159 } |
3155 |
3160 |
3156 // Images |
3161 // Images, just like texts. |
3157 RPointerArray<CHuiCanvasGraphicImage> imageEntries; |
3162 for(TInt i = iCachedImages.Count() - 1; i >= 0; i--) |
3158 |
3163 { |
3159 FindUnusedImageEntries(imageEntries); |
3164 CHuiCanvasGraphicImage* entry = iCachedImages[i]; |
3160 |
3165 if (!entry->iActiveUsers.Count()) |
3161 for(TInt i=imageEntries.Count() - 1; i >= 0; i--) |
3166 { |
3162 { |
3167 TBool is16bit = EFalse; |
3163 TBool is16bit = EFalse; |
3168 if (entry->iBitmap && !entry->iMask && entry->iBitmap->ExtendedBitmapType() == KNullUid && entry->iBitmap->DisplayMode() == EColor64K) |
3164 if (imageEntries[i]->iBitmap && !imageEntries[i]->iMask && imageEntries[i]->iBitmap->ExtendedBitmapType() == KNullUid &&imageEntries[i]->iBitmap->DisplayMode() == EColor64K) |
3169 { |
3165 { |
3170 is16bit = ETrue; |
3166 is16bit = ETrue; |
3171 } |
3167 } |
3172 textureSize = entry->iTexture->Size(); |
3168 |
3173 totalUnusedTextureBytes += textureSize.iWidth * textureSize.iHeight * (is16bit ? KHuiCanvasImageEstimatedBpp/16.f : KHuiCanvasImageEstimatedBpp/8.f); |
3169 TSize textureSize = imageEntries[i]->iTexture->Size(); |
3174 } |
3170 totalUnusedTextureBytes += textureSize.iWidth * textureSize.iHeight * (is16bit ? KHuiCanvasImageEstimatedBpp/16.f : KHuiCanvasImageEstimatedBpp/8.f); |
3175 } |
3171 } |
3176 |
3172 |
|
3173 imageEntries.Close(); |
|
3174 |
|
3175 return totalUnusedTextureBytes/1024; |
3177 return totalUnusedTextureBytes/1024; |
3176 } |
3178 } |
3177 |
3179 |
3178 // --------------------------------------------------------------------------- |
3180 // --------------------------------------------------------------------------- |
3179 // |
3181 // |