uiacceltk/hitchcock/coretoolkit/src/HuiS60Skin.cpp
branchRCL_3
changeset 8 10534483575f
parent 3 d8a3531bc6b8
child 10 88b23e2e82e1
--- a/uiacceltk/hitchcock/coretoolkit/src/HuiS60Skin.cpp	Fri Mar 12 15:47:04 2010 +0200
+++ b/uiacceltk/hitchcock/coretoolkit/src/HuiS60Skin.cpp	Mon Mar 15 12:43:37 2010 +0200
@@ -59,7 +59,6 @@
     iSkinControlContext = CAknsBasicBackgroundControlContext::NewL(
         KAknsIIDQsnBgScreen, TRect(TPoint(0, 0), HuiUtil::ScreenSize()), ETrue);
     iSpare = new (ELeave) TPrivData;
-    iSkinChanged = ETrue;
     }
 
 
@@ -143,7 +142,7 @@
         iBackgroundTexture->SetSkinContent(ETrue);
         iBackgroundTexture->iContentObservers.AppendL(*this);
         }
-    else if(iSkinChanged)
+    else if(iReloadBackground || !iBackgroundTexture->HasContent() )
         {
         iBackgroundTexture->Reset();
         delete iBackgroundBitmap;
@@ -163,10 +162,33 @@
     HUI_DEBUG1(_L("CHuiS60Skin::UpdateBackgroundL - Free memory at exit: %i"), HuiUtil::FreeMemory());
     }
 
+void CHuiS60Skin::FreeAllBackgroundTextureResources()
+    {
+    // delete old contents
+
+    TBackgroundTexture bgTexture;
+    TInt itemCount = ((TPrivData*)(iSpare))->iBackgrounds.Count(); 
+    for (TInt index = 0; index < itemCount; index++)
+        {
+        bgTexture = ((TPrivData*)(iSpare))->iBackgrounds[index];
+        if( bgTexture.iBackgroundTexture )
+            {
+            bgTexture.iBackgroundTexture->Reset();
+            }
+        }
+    
+    delete iBackgroundTexture;
+    iBackgroundTexture = NULL;
+    delete iBackgroundBitmap;
+    iBackgroundBitmap = NULL;
+    iBackgroundRect = TRect(0,0,0,0);
+    iCachedSkinItems.ResetAndDestroy();      
+    }
+
 
 EXPORT_C void CHuiS60Skin::SkinContentChanged()
     {
-    iSkinChanged = ETrue;
+    FreeAllBackgroundTextureResources();
     }
 
 EXPORT_C void CHuiS60Skin::SkinConfigurationChanged(
@@ -191,7 +213,8 @@
     if(aSkinTextureId == EHuiSkinBackgroundTexture && 
     	CHuiStatic::Renderer().Id () != EHuiRenderPluginBitgdi) 
         {
-        if(!iBackgroundTexture || iReloadBackground || iSkinChanged)
+        if(!iBackgroundTexture || ( iBackgroundTexture && !iBackgroundTexture->HasContent() ) ||  
+           iReloadBackground )            
             {
             UpdateBackgroundL();
             iReloadBackground = EFalse;
@@ -227,12 +250,11 @@
 EXPORT_C void CHuiS60Skin::NotifyDisplaySizeChangedL()
     {
     // The background is now different.
-    SkinContentChanged(); // for changing the iSkinChanged flag
+    SkinContentChanged(); // to delete old contents
+    
     Env().NotifySkinChangedL();
     Env().TextStyleManager().NotifyDisplaySizeChangedL();
     ReloadBgTexturesL();
-
-    iSkinChanged = EFalse;
     }
 
 
@@ -343,7 +365,7 @@
 
         CFbsBitmap* bitmap = new (ELeave) CFbsBitmap();
         CleanupStack::PushL(bitmap);
-        User::LeaveIfError( bitmap->Create(skinrect.Size(), EColor64K) );        
+        User::LeaveIfError( bitmap->Create(skinrect.Size(), EColor16MAP) );        
 
         CFbsBitmapDevice* device = CFbsBitmapDevice::NewL(bitmap);
         CleanupStack::PushL(device);
@@ -366,7 +388,7 @@
     else
         {
         CFbsBitmap* bitmap = SearchCachedSkinItemBitmap(aID);
-        if(iSkinChanged || !bitmap)
+        if(!bitmap)
             {
             TRect skinrect;
             TRect dummy;
@@ -427,7 +449,11 @@
         {
         bgTexture = ((TPrivData*)(iSpare))->iBackgrounds[index];
         delete bgTexture.iBackgroundTexture;
+        bgTexture.iBackgroundTexture = NULL;
+        // put back. In case of a leave NULL texture is stored and we can try to re-create it later
+        ((TPrivData*)(iSpare))->iBackgrounds[index] = bgTexture; 
         bgTexture.iBackgroundTexture = CreateSkinBackgroundL(bgTexture.iID);
+        // texture created succesfully
         ((TPrivData*)(iSpare))->iBackgrounds[index] = bgTexture;
         }
     }
@@ -449,8 +475,18 @@
         if (bgItem.ClearMode() == CHuiDisplay::EClearWithSkinBackground)
             {
             bgTexture.iID = bgItem.SkinBackground();
-            bgTexture.iBackgroundTexture = CreateSkinBackgroundL(bgItem.SkinBackground());
-            ((TPrivData*)(iSpare))->iBackgrounds.Append(bgTexture);
+            bgTexture.iBackgroundTexture = NULL;
+            TRAPD(err, bgTexture.iBackgroundTexture = CreateSkinBackgroundL(bgItem.SkinBackground()));
+            // if texture creation failed because our own internal services were busy
+            // still append NULL texture so we know to try it again later
+            if(err == KErrNone || err == KErrTimedOut )
+                { 
+                ((TPrivData*)(iSpare))->iBackgrounds.Append(bgTexture);
+                }
+            else
+                {
+                User::Leave(err);
+                }
             }
         }           
     }
@@ -473,6 +509,19 @@
         bgTexture = ((TPrivData*)(iSpare))->iBackgrounds[index];
         if (bgTexture.iID == aID)
             {
+            if(!bgTexture.iBackgroundTexture && !bgTexture.iBackgroundTexture->HasContent())
+                {
+                delete bgTexture.iBackgroundTexture;
+                bgTexture.iBackgroundTexture = NULL;
+                TRAPD(err, bgTexture.iBackgroundTexture = CreateSkinBackgroundL(bgTexture.iID));
+                // put bgTexture back to the array also in leave cases
+                // otherwise we could leave invalid pointer in array
+                ((TPrivData*)(iSpare))->iBackgrounds[index] = bgTexture;
+                if(err)
+                    {
+                    return NULL; // creating failed for some reason
+                    }
+                }
             return bgTexture.iBackgroundTexture;
             }
         }