uiacceltk/hitchcock/coretoolkit/src/HuiS60Skin.cpp
branchRCL_3
changeset 3 d8a3531bc6b8
parent 0 15bf7259bb7c
child 6 10534483575f
equal deleted inserted replaced
0:15bf7259bb7c 3:d8a3531bc6b8
    70     delete iSkinControlContext;
    70     delete iSkinControlContext;
    71     delete iBackgroundTexture;
    71     delete iBackgroundTexture;
    72     if (iSkinSrvConnected)
    72     if (iSkinSrvConnected)
    73         iSkinSrvSession.Close();
    73         iSkinSrvSession.Close();
    74         
    74         
    75    delete iBackgroundBitmap;
    75     delete iBackgroundBitmap;
       
    76     iCachedSkinItems.ResetAndDestroy();
       
    77     iCachedSkinItems.Close();
    76     }
    78     }
    77 
    79 
    78 
    80 
    79 EXPORT_C THuiSkinLocation CHuiS60Skin::Location(THuiSkinElement aElement)
    81 EXPORT_C THuiSkinLocation CHuiS60Skin::Location(THuiSkinElement aElement)
    80     {
    82     {
   133     }
   135     }
   134 
   136 
   135 
   137 
   136 void CHuiS60Skin::UpdateBackgroundL()
   138 void CHuiS60Skin::UpdateBackgroundL()
   137     {
   139     {
   138     if(iBackgroundTexture)
   140     if(!iBackgroundTexture)
   139          {
   141         {
   140          iBackgroundTexture->Reset();
   142         iBackgroundTexture = CreateSkinBackgroundL(KAknsIIDQsnBgScreen);
   141          delete iBackgroundTexture;
   143         iBackgroundTexture->SetSkinContent(ETrue);
   142          iBackgroundTexture = 0;
   144         iBackgroundTexture->iContentObservers.AppendL(*this);
   143          }
   145         }
   144 
   146     else if(iSkinChanged)
   145     HUI_DEBUG1(_L("CHuiS60Skin::UpdateBackgroundL - Free memory in the beginning: %i"), HuiUtil::FreeMemory());
   147         {
   146     iBackgroundTexture = CreateSkinBackgroundL(KAknsIIDQsnBgScreen);
   148         iBackgroundTexture->Reset();
   147     iBackgroundTexture->SetSkinContent(ETrue);
   149         delete iBackgroundBitmap;
   148     iBackgroundTexture->iContentObservers.AppendL(*this);
   150         iBackgroundBitmap = NULL;
   149 
   151         iBackgroundBitmap = CHuiStatic::GetBgBitmapLC(KAknsIIDQsnBgScreen); 
       
   152         CleanupStack::Pop(iBackgroundBitmap);
       
   153         // update iBackgroundRect as well 
       
   154         TRect dummy;
       
   155         GetRectForItem(KAknsIIDQsnBgScreen, dummy, iBackgroundRect);
       
   156         iBackgroundTexture->UploadL(*iBackgroundBitmap,NULL,EHuiTextureUploadFlagRetainResolution );                
       
   157         iBackgroundTexture->SetSkinContent(ETrue);
       
   158         }
       
   159     else
       
   160         {
       
   161         // there should be already up-to-date background texture
       
   162         }
   150     HUI_DEBUG1(_L("CHuiS60Skin::UpdateBackgroundL - Free memory at exit: %i"), HuiUtil::FreeMemory());
   163     HUI_DEBUG1(_L("CHuiS60Skin::UpdateBackgroundL - Free memory at exit: %i"), HuiUtil::FreeMemory());
   151     }
   164     }
   152 
   165 
   153 
   166 
   154 void CHuiS60Skin::SkinContentChanged()
   167 EXPORT_C void CHuiS60Skin::SkinContentChanged()
   155     {
   168     {
   156     iSkinChanged = ETrue;
   169     iSkinChanged = ETrue;
   157     }
   170     }
   158 
   171 
   159 void CHuiS60Skin::SkinConfigurationChanged(
   172 EXPORT_C void CHuiS60Skin::SkinConfigurationChanged(
   160     const TAknsSkinStatusConfigurationChangeReason aReason )
   173     const TAknsSkinStatusConfigurationChangeReason aReason )
   161     {
   174     {
   162     
   175     
   163     }
   176     }
   164 void CHuiS60Skin::SkinPackageChanged(
   177 
       
   178 EXPORT_C void CHuiS60Skin::SkinPackageChanged(
   165     const TAknsSkinStatusPackageChangeReason aReason )
   179     const TAknsSkinStatusPackageChangeReason aReason )
   166     {
   180     {
   167     
   181     
   168     }
   182     }
   169 
   183 
   211 
   225 
   212 
   226 
   213 EXPORT_C void CHuiS60Skin::NotifyDisplaySizeChangedL()
   227 EXPORT_C void CHuiS60Skin::NotifyDisplaySizeChangedL()
   214     {
   228     {
   215     // The background is now different.
   229     // The background is now different.
   216     iReloadBackground = ETrue;
       
   217     SkinContentChanged(); // for changing the iSkinChanged flag
   230     SkinContentChanged(); // for changing the iSkinChanged flag
   218     Env().NotifySkinChangedL();
   231     Env().NotifySkinChangedL();
   219     Env().TextStyleManager().NotifyDisplaySizeChangedL();
   232     Env().TextStyleManager().NotifyDisplaySizeChangedL();
   220     ReloadBgTexturesL();
   233     ReloadBgTexturesL();
       
   234 
       
   235     iSkinChanged = EFalse;
   221     }
   236     }
   222 
   237 
   223 
   238 
   224 EXPORT_C TRgb CHuiS60Skin::StyleTextColor(THuiPreconfiguredTextStyle aStyle,
   239 EXPORT_C TRgb CHuiS60Skin::StyleTextColor(THuiPreconfiguredTextStyle aStyle,
   225                                           THuiBackgroundType aBackgroundType) const
   240                                           THuiBackgroundType aBackgroundType) const
   298         {
   313         {
   299         bgTexture = ((TPrivData*)(iSpare))->iBackgrounds[index];
   314         bgTexture = ((TPrivData*)(iSpare))->iBackgrounds[index];
   300         delete bgTexture.iBackgroundTexture;
   315         delete bgTexture.iBackgroundTexture;
   301         bgTexture.iBackgroundTexture = NULL;
   316         bgTexture.iBackgroundTexture = NULL;
   302         }
   317         }
   303     ((TPrivData*)(iSpare))->iBackgrounds.Reset(); 
   318     ((TPrivData*)(iSpare))->iBackgrounds.Reset();
   304     
   319     
       
   320     iCachedSkinItems.ResetAndDestroy(); // reset cached bg images & rects
   305     }
   321     }
   306     
   322     
   307     
   323     
   308 CHuiTexture* CHuiS60Skin::CreateSkinBackgroundL(const TAknsItemID& aID)
   324 CHuiTexture* CHuiS60Skin::CreateSkinBackgroundL(const TAknsItemID& aID)
   309     {
   325     {
   315         }
   331         }
   316     
   332     
   317     MAknsSkinInstance* skin = SkinInstance();
   333     MAknsSkinInstance* skin = SkinInstance();
   318     CHuiTexture* texture = CHuiTexture::NewL();
   334     CHuiTexture* texture = CHuiTexture::NewL();
   319     
   335     
   320     CleanupStack::PushL(texture);            
   336     CleanupStack::PushL(texture);
   321     if(iSkinChanged)
   337     
   322          {
   338     if (skin)
   323      
   339         {
   324         delete iBackgroundBitmap; 
   340         TRect skinrect;
   325         iBackgroundBitmap = NULL;
   341         TRect dummy;
   326         
   342         GetRectForItem(aID, dummy, skinrect);
   327         if (skin)
   343 
   328             {
   344         CFbsBitmap* bitmap = new (ELeave) CFbsBitmap();
       
   345         CleanupStack::PushL(bitmap);
       
   346         User::LeaveIfError( bitmap->Create(skinrect.Size(), EColor64K) );        
       
   347 
       
   348         CFbsBitmapDevice* device = CFbsBitmapDevice::NewL(bitmap);
       
   349         CleanupStack::PushL(device);
       
   350 
       
   351         CFbsBitGc* gc = 0;
       
   352         User::LeaveIfError( device->CreateContext(gc) );
       
   353         CleanupStack::PushL(gc);
       
   354         iSkinControlContext->SetRect(skinrect);
       
   355         iSkinControlContext->SetBitmap(aID);
       
   356 
       
   357         AknsDrawUtils::DrawBackground(skin, iSkinControlContext, NULL, *gc, TPoint(0,0), skinrect,
       
   358                           KAknsDrawParamDefault);
       
   359 
       
   360         CleanupStack::PopAndDestroy(gc);
       
   361         CleanupStack::PopAndDestroy(device);
       
   362 
       
   363         texture->UploadL(*bitmap,NULL,EHuiTextureUploadFlagRetainResolution );            
       
   364         CleanupStack::PopAndDestroy(bitmap);
       
   365         }
       
   366     else
       
   367         {
       
   368         CFbsBitmap* bitmap = SearchCachedSkinItemBitmap(aID);
       
   369         if(iSkinChanged || !bitmap)
       
   370             {
       
   371             TRect skinrect;
   329             TRect dummy;
   372             TRect dummy;
   330             TRect skinRect;
   373             GetRectForItem(aID, dummy, skinrect);
   331             GetRectForItem(aID, dummy, skinRect);
   374 
   332     
   375             if( aID == KAknsIIDQsnBgScreen) // handle normal background id differently
   333             iBackgroundBitmap = new (ELeave) CFbsBitmap();
   376                 {
   334             User::LeaveIfError( iBackgroundBitmap->Create(skinRect.Size(), EColor64K) );        
   377                 delete iBackgroundBitmap; 
   335     
   378                 iBackgroundBitmap = NULL;
   336             CFbsBitmapDevice* device = CFbsBitmapDevice::NewL(iBackgroundBitmap);
   379                 bitmap = CHuiStatic::GetBgBitmapLC(aID);
   337             CleanupStack::PushL(device);
   380                 CleanupStack::Pop(bitmap);
   338     
   381                 iBackgroundBitmap = bitmap;
   339             CFbsBitGc* gc = 0;
   382                 iBackgroundRect = skinrect;
   340             User::LeaveIfError( device->CreateContext(gc) );
   383                 }
   341             CleanupStack::PushL(gc);
   384             else // others are cached in skin item array
   342             iSkinControlContext->SetRect(skinRect);
   385                 {
   343             iSkinControlContext->SetBitmap(aID);
   386                 bitmap = CHuiStatic::GetBgBitmapLC(aID);
   344     
   387                 TInt index = SearchCachedSkinItemIndex(aID);
   345             AknsDrawUtils::DrawBackground(skin, iSkinControlContext, NULL, *gc, TPoint(0,0), skinRect,
   388                 if( index == KErrNotFound ) // add new
   346                               KAknsDrawParamDefault);
   389                     {
   347     
   390                     CSkinItem* newSkinItem = new (ELeave) CHuiS60Skin::CSkinItem();
   348             CleanupStack::PopAndDestroy(gc);
   391                     CleanupStack::PushL(newSkinItem);
   349             CleanupStack::PopAndDestroy(device);
   392                     newSkinItem->iId = aID;
   350             }
   393                     newSkinItem->iSkinRect = skinrect;
   351         else
   394                     newSkinItem->iBitmap = bitmap;
   352             {
   395                     User::LeaveIfError(iCachedSkinItems.Append(newSkinItem));
   353             iBackgroundBitmap = CHuiStatic::GetBgBitmapLC(aID);   
   396                     CleanupStack::Pop(newSkinItem);
   354             CleanupStack::Pop( iBackgroundBitmap );
   397                     }
   355             }
   398                 else // modify existing
   356          }
   399                     {
   357     texture->UploadL(*iBackgroundBitmap,NULL,EHuiTextureUploadFlagRetainResolution );            
   400                     iCachedSkinItems[index]->iSkinRect = skinrect;
   358     
   401                     delete iCachedSkinItems[index]->iBitmap;
       
   402                     iCachedSkinItems[index]->iBitmap = NULL; 
       
   403                     iCachedSkinItems[index]->iBitmap = bitmap;
       
   404                     }
       
   405                 CleanupStack::Pop(bitmap);                
       
   406                 }
       
   407             }
       
   408         texture->UploadL(*bitmap,NULL,EHuiTextureUploadFlagRetainResolution );            
       
   409         }
       
   410 
   359     CleanupStack::Pop(texture);
   411     CleanupStack::Pop(texture);
   360     iSkinChanged = EFalse;
       
   361     return texture;
   412     return texture;
   362     }
   413     }
   363 
   414 
   364 void CHuiS60Skin::ReloadBgTexturesL()
   415 void CHuiS60Skin::ReloadBgTexturesL()
   365     {
   416     {
   366     if (CHuiStatic::Renderer().Id () == EHuiRenderPluginBitgdi )
   417     if (CHuiStatic::Renderer().Id () == EHuiRenderPluginBitgdi )
   367         {
   418         {
   368         // no need to render the skin backgrounds separately on bitgdi
   419         // no need to render the skin backgrounds separately on bitgdi
   369         return;
   420         return;
   370         }
   421         }
       
   422     iCachedSkinItems.ResetAndDestroy(); // reset cached bg images & rects
       
   423     
   371     TBackgroundTexture bgTexture;
   424     TBackgroundTexture bgTexture;
   372     TInt itemCount = ((TPrivData*)(iSpare))->iBackgrounds.Count(); 
   425     TInt itemCount = ((TPrivData*)(iSpare))->iBackgrounds.Count(); 
   373     for (TInt index = 0; index < itemCount; index++)
   426     for (TInt index = 0; index < itemCount; index++)
   374         {
   427         {
   375         bgTexture = ((TPrivData*)(iSpare))->iBackgrounds[index];
   428         bgTexture = ((TPrivData*)(iSpare))->iBackgrounds[index];
   423             return bgTexture.iBackgroundTexture;
   476             return bgTexture.iBackgroundTexture;
   424             }
   477             }
   425         }
   478         }
   426     return NULL;
   479     return NULL;
   427     }
   480     }
       
   481 
       
   482 
       
   483 TInt CHuiS60Skin::SearchCachedSkinItemIndex(const TAknsItemID& aId)
       
   484     {
       
   485     TInt cacheditemsCount = iCachedSkinItems.Count();
       
   486     for(TInt i = 0; i < cacheditemsCount; i++ )
       
   487         {
       
   488         if( iCachedSkinItems[i]->iId == aId )
       
   489             {
       
   490             return i;
       
   491             }
       
   492         }
       
   493 
       
   494     HUI_DEBUG2(_L("CHuiS60Skin::SeachCachedSkinItemIndex - cached TAknsItemID %i %i (iMajor, iMinor) not found"), aId.iMajor, aId.iMinor );
       
   495 
       
   496     return KErrNotFound;
       
   497     }
       
   498 
       
   499 TRect CHuiS60Skin::SearchCachedSkinItemRect(const TAknsItemID& aId)
       
   500     {
       
   501     TRect returnRect = TRect();
       
   502     if(aId == KAknsIIDQsnBgScreen)
       
   503         {
       
   504         returnRect = iBackgroundRect;
       
   505         }
       
   506     else
       
   507         {
       
   508         TInt index = SearchCachedSkinItemIndex(aId);
       
   509         if(index != KErrNotFound )
       
   510             {
       
   511             returnRect = iCachedSkinItems[index]->iSkinRect;
       
   512             }
       
   513         }   
       
   514     return returnRect;
       
   515     }
       
   516 
       
   517 CFbsBitmap* CHuiS60Skin::SearchCachedSkinItemBitmap(const TAknsItemID& aId)
       
   518     {
       
   519     CFbsBitmap* bitmap = NULL;
       
   520     if(aId == KAknsIIDQsnBgScreen)
       
   521         {
       
   522         bitmap = iBackgroundBitmap;
       
   523         }
       
   524     else
       
   525         {
       
   526         TInt index = SearchCachedSkinItemIndex(aId);
       
   527         if(index != KErrNotFound )
       
   528             {
       
   529             bitmap = iCachedSkinItems[index]->iBitmap;
       
   530             }
       
   531         }   
       
   532     return bitmap;    
       
   533     }
       
   534 
       
   535 
       
   536 TRect CHuiS60Skin::SkinRect(const TAknsItemID& aID)
       
   537     {
       
   538     return SearchCachedSkinItemRect(aID);
       
   539     }