photosgallery/viewframework/texturemanager/src/glxtexturemanagerimpl.cpp
changeset 1 9ba538e329bd
parent 0 4e91876724a2
child 9 6b87b143d312
equal deleted inserted replaced
0:4e91876724a2 1:9ba538e329bd
   282         
   282         
   283         // trap create texture
   283         // trap create texture
   284        TRAPD(err, texture = &iAlfTextureManager.CreateTextureL(
   284        TRAPD(err, texture = &iAlfTextureManager.CreateTextureL(
   285                                                icon.iTextureId, 
   285                                                icon.iTextureId, 
   286                                                this, 
   286                                                this, 
   287                                                EAlfTextureFlagDefault));                                     
   287                                                EAlfTextureFlagDefault));
   288         if(err)
   288         if(err)
   289             {
   289             {
   290             // if error delete entry and leave
   290             // if error delete entry and leave
   291             iIconList.Remove(iIconList.Count() - 1);
   291             iIconList.Remove(iIconList.Count() - 1);
   292             User::Leave(err);    
   292             User::Leave(err);    
   296             // if no error add texture to entry
   296             // if no error add texture to entry
   297             iIconList[iIconList.Count() - 1].iTexture = texture;
   297             iIconList[iIconList.Count() - 1].iTexture = texture;
   298             }
   298             }
   299         }
   299         }
   300 
   300 
   301     User::LeaveIfNull(texture); //should not be possible        
   301     if (NULL == texture)
       
   302         {
       
   303         User::Leave(KErrNotFound);
       
   304         }
       
   305     
   302     return *texture;
   306     return *texture;
   303     }
   307     }
   304 
   308 
   305 
   309 
   306 
   310 
   322     
   326     
   323     // If the current thumbnail matches what is required then return the current texture otherwise
   327     // If the current thumbnail matches what is required then return the current texture otherwise
   324     // create a new one.
   328     // create a new one.
   325     if (!GetThumbnailAttributeAndIndexL(aSize, aMedia, aIdSpaceId, thumbnailIndex, thumbNailAttribute))
   329     if (!GetThumbnailAttributeAndIndexL(aSize, aMedia, aIdSpaceId, thumbnailIndex, thumbNailAttribute))
   326         {
   330         {
       
   331         // only texture is missing. 
       
   332         if ( (NULL != iThumbnailList[thumbnailIndex].iBitmap) && (NULL == iThumbnailList[thumbnailIndex].iTexture)) 
       
   333             {
       
   334             CAlfTexture* newTexture = &iAlfTextureManager.CreateTextureL(
       
   335                                                                     iThumbnailList[thumbnailIndex].iTextureId, 
       
   336                                                                     this, 
       
   337                                                                     EAlfTextureFlagDefault);
       
   338             iThumbnailList[thumbnailIndex].iTexture = newTexture ;
       
   339             }
   327         return *iThumbnailList[thumbnailIndex].iTexture;
   340         return *iThumbnailList[thumbnailIndex].iTexture;
   328         }
   341         }
   329          
   342          
   330     // We have 2 scenarios here.
   343     // We have 2 scenarios here.
   331     // 1) We do not have a thumbnail
   344     // 1) We do not have a thumbnail
   515             if(!aAllTexture)
   528             if(!aAllTexture)
   516                 break;
   529                 break;
   517             }
   530             }
   518         }
   531         }
   519     }
   532     }
       
   533 
       
   534 // -----------------------------------------------------------------------------
       
   535 // FlushTextures Removes All Textures
       
   536 // -----------------------------------------------------------------------------
       
   537 //
       
   538 void CGlxTextureManagerImpl::FlushTextures()
       
   539     {
       
   540     TRACER("CGlxTextureManagerImpl::FlushTextures");
       
   541 
       
   542     TInt textureID ;
       
   543     TInt i = iThumbnailList.Count();
       
   544     
       
   545     while(i > 0)
       
   546         {
       
   547         --i;
       
   548         textureID = iThumbnailList[i].iTextureId;
       
   549         iAlfTextureManager.UnloadTexture(textureID );
       
   550         iThumbnailList[i].iTexture = NULL;
       
   551         }
       
   552     
       
   553     i = iIconList.Count();
       
   554     while(i > 0)
       
   555         {
       
   556         --i;
       
   557         textureID = iIconList[i].iTextureId;
       
   558         iAlfTextureManager.UnloadTexture(textureID );
       
   559         iIconList[i].iTexture = NULL;
       
   560         }
       
   561     
       
   562     i = iZoomedList.Count();
       
   563     while(i > 0)
       
   564         {
       
   565         --i;
       
   566         textureID = iZoomedList[i].iTextureId;
       
   567         iAlfTextureManager.UnloadTexture(textureID );
       
   568         iZoomedList[i].iTexture = NULL;
       
   569         }
       
   570     }
       
   571 
   520 // -----------------------------------------------------------------------------
   572 // -----------------------------------------------------------------------------
   521 // GetThumbnailAttributeAndIndexL
   573 // GetThumbnailAttributeAndIndexL
   522 // -----------------------------------------------------------------------------
   574 // -----------------------------------------------------------------------------
   523 //
   575 //
   524 TBool CGlxTextureManagerImpl::GetThumbnailAttributeAndIndexL( TSize aSize,
   576 TBool CGlxTextureManagerImpl::GetThumbnailAttributeAndIndexL( TSize aSize,
   549                 // No need to do anything
   601                 // No need to do anything
   550                 return EFalse;
   602                 return EFalse;
   551                 }
   603                 }
   552             }
   604             }
   553         }
   605         }
   554         
       
   555     return ETrue;
   606     return ETrue;
   556     }
   607     }
   557 
   608 // -----------------------------------------------------------------------------
       
   609 // CreateNewTextureL
       
   610 // -----------------------------------------------------------------------------
       
   611 CAlfTexture* CGlxTextureManagerImpl::CreateZoomedTextureL()
       
   612     {
       
   613     TRACER("CGlxTextureManagerImpl::CreateZoomedTextureL");
       
   614     TInt count = iZoomedList.Count();
       
   615     TInt index = 0 ;
       
   616     
       
   617     for (index = count-1; index >=0  ; index--)
       
   618         {
       
   619         if (NULL == iZoomedList[index].iTexture)
       
   620             {
       
   621             if (NULL != iZoomedList[index].iBitmap)
       
   622                 {
       
   623                 // If we got this far we need to create a new texture
       
   624                 iZoomedList[index].iTextureId = NextTextureId();
       
   625                 iZoomedList[index].iTexture = &iAlfTextureManager.CreateTextureL(
       
   626                                                                        iZoomedList[index].iTextureId, 
       
   627                                                                        this, 
       
   628                                                                        EAlfTextureFlagDefault);
       
   629                 return iZoomedList[index].iTexture ;
       
   630                 }
       
   631             }
       
   632         }
       
   633     return NULL;
       
   634     }
   558 // -----------------------------------------------------------------------------
   635 // -----------------------------------------------------------------------------
   559 // CreateNewTextureL
   636 // CreateNewTextureL
   560 // -----------------------------------------------------------------------------
   637 // -----------------------------------------------------------------------------
   561 CAlfTexture& CGlxTextureManagerImpl::CreateNewTextureL( TSize aSize,
   638 CAlfTexture& CGlxTextureManagerImpl::CreateNewTextureL( TSize aSize,
   562     const TGlxMedia& aMedia, const TGlxIdSpaceId& aIdSpaceId,
   639     const TGlxMedia& aMedia, const TGlxIdSpaceId& aIdSpaceId,
   608     if( aIsThumbnailTexture )
   685     if( aIsThumbnailTexture )
   609 	    {
   686 	    {
   610 	     //Add to the thumbnail list
   687 	     //Add to the thumbnail list
   611         GLX_LOG_INFO("CGlxTextureManagerImpl::CreateNewTextureL iThumbnailList.Append ");
   688         GLX_LOG_INFO("CGlxTextureManagerImpl::CreateNewTextureL iThumbnailList.Append ");
   612 	    iThumbnailList.Append(aThumbData); 	
   689 	    iThumbnailList.Append(aThumbData); 	
   613 	    }   
   690 	    }
   614    else
   691    else
   615 	   {
   692 	   {
   616         GLX_LOG_INFO1("CGlxTextureManagerImpl::CreateNewTextureL,count=%d",iZoomedList.Count());
   693         GLX_LOG_INFO1("CGlxTextureManagerImpl::CreateNewTextureL,count=%d",iZoomedList.Count());
   617 	   iZoomedList.Append(aThumbData);
   694 	   iZoomedList.Append(aThumbData);
   618 	   }
   695 	   }
   629         GLX_LOG_INFO("CGlxTextureManagerImpl::CreateNewTextureL aIsThumbnailTexture ");
   706         GLX_LOG_INFO("CGlxTextureManagerImpl::CreateNewTextureL aIsThumbnailTexture ");
   630 	    TInt index = iThumbnailList.Count()-1;
   707 	    TInt index = iThumbnailList.Count()-1;
   631 	    iThumbnailList[index].iTexture = newTexture;
   708 	    iThumbnailList[index].iTexture = newTexture;
   632 	    iThumbnailList[index].iRequiredSize = aSize;
   709 	    iThumbnailList[index].iRequiredSize = aSize;
   633 	    }
   710 	    }
   634 	    
       
   635 	else
   711 	else
   636 	    {
   712 	    {
   637         GLX_LOG_INFO("CGlxTextureManagerImpl::CreateNewTextureL else aIsThumbnailTexture ");
   713         GLX_LOG_INFO("CGlxTextureManagerImpl::CreateNewTextureL else aIsThumbnailTexture ");
   638 	    TInt index = iZoomedList.Count()-1;
   714 	    TInt index = iZoomedList.Count()-1;
   639 	    iZoomedList[index].iTexture = newTexture;
   715 	    iZoomedList[index].iTexture = newTexture;
   654        }
   730        }
   655 	
   731 	
   656     return *newTexture;
   732     return *newTexture;
   657     }
   733     }
   658 
   734 
   659 
       
   660 // -----------------------------------------------------------------------------
   735 // -----------------------------------------------------------------------------
   661 // CreateZoomedTextureL
   736 // CreateZoomedTextureL
   662 // -----------------------------------------------------------------------------
   737 // -----------------------------------------------------------------------------
   663 //  
   738 //  
   664 CAlfTexture& CGlxTextureManagerImpl::CreateZoomedTextureL(
   739 CAlfTexture& CGlxTextureManagerImpl::CreateZoomedTextureL(
   665                     const TGlxMedia& aMedia, const TMPXAttribute& aAttribute,
   740                     const TGlxMedia& aMedia, const TMPXAttribute& aAttribute,
   666                     TGlxIdSpaceId aIdSpaceId, MGlxTextureObserver* aObserver)
   741                     TGlxIdSpaceId aIdSpaceId, MGlxTextureObserver* aObserver)
   667     {
   742     {
   668     TRACER("CGlxTextureManagerImpl::CreateZoomedTextureL");
   743     TRACER("CGlxTextureManagerImpl::CreateZoomedTextureL");
   669     if(!iZoomDecoder)
   744     if(!iZoomDecoder)
   670 		{
   745         {
   671 		 GLX_LOG_INFO("CGlxTextureManagerImpl:: CreateZoomedTextureL,iZoomDecoder == NULL");
   746         GLX_LOG_INFO("CGlxTextureManagerImpl:: CreateZoomedTextureL,iZoomDecoder == NULL");
   672 		 iZoomDecoder = CGlxBitmapDecoderWrapper::NewL(this);
   747         iZoomDecoder = CGlxBitmapDecoderWrapper::NewL(this);
   673 		}
   748         }
   674     
   749         
   675     TGlxThumbnailIcon aThumbData;
   750     TGlxThumbnailIcon aThumbData;
   676         
   751             
   677     aThumbData.iTextureId = NextTextureId();
   752     aThumbData.iTextureId = NextTextureId();
   678     aThumbData.iTexture = NULL;
   753     aThumbData.iTexture = NULL;
   679     aThumbData.iAttribId = aAttribute;
   754     aThumbData.iAttribId = aAttribute;
   680     aThumbData.iMediaId = aMedia.Id();
   755     aThumbData.iMediaId = aMedia.Id();
   681     aThumbData.iIdSpaceId = aIdSpaceId;
   756     aThumbData.iIdSpaceId = aIdSpaceId;
   691 	   
   766 	   
   692 	iZoomedList[index].iBitmap=NULL;
   767 	iZoomedList[index].iBitmap=NULL;
   693 	iZoomedList[index].iObserver = aObserver ;  
   768 	iZoomedList[index].iObserver = aObserver ;  
   694 
   769 
   695 	iZoomDecoder->DoDecodeImageL(aMedia.Uri(), iZoomedList.Count()-1);
   770 	iZoomDecoder->DoDecodeImageL(aMedia.Uri(), iZoomedList.Count()-1);
   696 		
       
   697 	return *(iZoomedList[index].iTexture);
   771 	return *(iZoomedList[index].iTexture);
   698     }
   772     }
   699 
   773 
   700 // -----------------------------------------------------------------------------
   774 // -----------------------------------------------------------------------------
   701 // CreateAnimatedGifTextureL
   775 // CreateAnimatedGifTextureL
   879                                  bitmapId, 
   953                                  bitmapId, 
   880                                  maskId );
   954                                  maskId );
   881         }
   955         }
   882 
   956 
   883     // Leave if bitmap or mask is NULL.
   957     // Leave if bitmap or mask is NULL.
   884     User::LeaveIfNull( aBitmap );
   958     
   885 
   959     if (NULL == aBitmap)
       
   960         {
       
   961         User::Leave(KErrNotFound);
       
   962         }
       
   963     
   886     // set size
   964     // set size
   887     // In preference use requested size if there is one
   965     // In preference use requested size if there is one
   888     TInt height =TInt(iResUtil->PossToPixels(icon.iHeightInPoss));
   966     TInt height =TInt(iResUtil->PossToPixels(icon.iHeightInPoss));
   889     TInt width =TInt(iResUtil->PossToPixels(icon.iWidthInPoss));
   967     TInt width =TInt(iResUtil->PossToPixels(icon.iWidthInPoss));
   890     
   968     
  1021     TRACER("CGlxTextureManagerImpl::HandleBitmapDecodedL");
  1099     TRACER("CGlxTextureManagerImpl::HandleBitmapDecodedL");
  1022     CAlfTexture* newTexture = NULL;
  1100     CAlfTexture* newTexture = NULL;
  1023     TBool textureCreated = ETrue;
  1101     TBool textureCreated = ETrue;
  1024     TInt textureID = -1;
  1102     TInt textureID = -1;
  1025     TInt textureToBeUnloaded = -1;
  1103     TInt textureToBeUnloaded = -1;
  1026     
  1104 
  1027     //check if the image is decoded
  1105     //check if the image is decoded
  1028     if(aBitmap != NULL)
  1106     if(aBitmap != NULL)
  1029 		    {
  1107         {
  1030 		    iZoomedList[aThumbnailIndex].iBitmap = aBitmap;
  1108         iZoomedList[aThumbnailIndex].iBitmap = aBitmap;
  1031   			
  1109 
  1032   			//if we already have a texture then dont unload the texture before creating 
  1110         //if we already have a texture then dont unload the texture before creating 
  1033   			//the next one. It might happen that because of low memory we might not be able
  1111         //the next one. It might happen that because of low memory we might not be able
  1034   			//to create a new texture.
  1112         //to create a new texture.
  1035 			  if(iZoomedList[aThumbnailIndex].iTexture)
  1113         if(iZoomedList[aThumbnailIndex].iTexture)
  1036 			    {				    
  1114             {				    
  1037 			    textureID = NextTextureId();
  1115             textureID = NextTextureId();
  1038 			    textureToBeUnloaded = iZoomedList[aThumbnailIndex].iTextureId  ;   
  1116             textureToBeUnloaded = iZoomedList[aThumbnailIndex].iTextureId  ;   
  1039 			    iZoomedList[aThumbnailIndex].iTextureId = textureID  ;
  1117             iZoomedList[aThumbnailIndex].iTextureId = textureID  ;
  1040 			  	}
  1118             }
  1041 			  else
  1119         else
  1042 				  {
  1120             {
  1043 				  textureID = iZoomedList[aThumbnailIndex].iTextureId;
  1121             textureID = iZoomedList[aThumbnailIndex].iTextureId;
  1044 				  }
  1122             }
  1045 				  		
       
  1046 		    TRAPD(err, newTexture = &iAlfTextureManager.CreateTextureL(
       
  1047 		    												 textureID, this, EAlfTextureFlagDefault));
       
  1048 		    if ( KErrNone != err && KErrNoMemory == err )
       
  1049 		        {  
       
  1050 		        GLX_LOG_INFO("CGlxTextureManagerImpl::HandleBitmapDecoded ReleaseRam : START RAM  RELEASE");
       
  1051 		        iCache->ReleaseRAML(ETrue);
       
  1052 		        TRAPD(err, newTexture = &iAlfTextureManager.CreateTextureL(textureID, this, EAlfTextureFlagDefault));
       
  1053 		        if ( KErrNone != err && KErrNoMemory == err )
       
  1054 		            {
       
  1055 		            GLX_LOG_INFO("CGlxTextureManagerImpl::HandleBitmapDecoded CreateTextureL : LOW MEMORY CONDITION");
       
  1056 		            textureCreated = EFalse;
       
  1057 		            }		
       
  1058 		        }
       
  1059 		    }    
       
  1060 		    else
       
  1061 		    {
       
  1062 		     textureCreated = EFalse;	     
       
  1063 		    }
       
  1064     
       
  1065     if(iZoomedList[aThumbnailIndex].iBitmap)
       
  1066         {
       
  1067         GLX_LOG_INFO("CGlxTextureManagerImpl::HandleBitmapDecoded delete iBitmap");
       
  1068     		delete iZoomedList[aThumbnailIndex].iBitmap;
       
  1069     		iZoomedList[aThumbnailIndex].iBitmap = NULL;
       
  1070         }
       
  1071         
  1123         
       
  1124         TRAPD(err, newTexture = &iAlfTextureManager.CreateTextureL(
       
  1125                                              textureID, this, EAlfTextureFlagDefault));
       
  1126         if ( KErrNone != err && KErrNoMemory == err )
       
  1127             {  
       
  1128             GLX_LOG_INFO("CGlxTextureManagerImpl::HandleBitmapDecoded ReleaseRam : START RAM  RELEASE");
       
  1129             iCache->ReleaseRAML(ETrue);
       
  1130             TRAPD(err, newTexture = &iAlfTextureManager.CreateTextureL(textureID, this, EAlfTextureFlagDefault));
       
  1131             if ( KErrNone != err && KErrNoMemory == err )
       
  1132                 {
       
  1133                 GLX_LOG_INFO("CGlxTextureManagerImpl::HandleBitmapDecoded CreateTextureL : LOW MEMORY CONDITION");
       
  1134                 textureCreated = EFalse;
       
  1135                 }		
       
  1136             }
       
  1137         }    
       
  1138     else
       
  1139         {
       
  1140         textureCreated = EFalse;	     
       
  1141         }
       
  1142 
       
  1143 
       
  1144 
  1072     if (textureCreated && (NULL != newTexture))
  1145     if (textureCreated && (NULL != newTexture))
  1073         {
  1146         {
  1074         GLX_LOG_INFO("CGlxTextureManagerImpl::HandleBitmapDecoded textureCreated && newTexture");
  1147         GLX_LOG_INFO("CGlxTextureManagerImpl::HandleBitmapDecoded textureCreated && newTexture");
  1075         //If the new texture is created then unload the old texture and store the new texture and textureID.
  1148         //If the new texture is created then unload the old texture and store the new texture and textureID.
  1076         if(iZoomedList[aThumbnailIndex].iTexture)
  1149         if(iZoomedList[aThumbnailIndex].iTexture)
  1077 				    {				    
  1150             {				    
  1078 				    GLX_LOG_INFO("CGlxTextureManagerImpl::HandleBitmapDecoded Unloading Old Texture");
  1151             GLX_LOG_INFO("CGlxTextureManagerImpl::HandleBitmapDecoded Unloading Old Texture");
  1079 				    iAlfTextureManager.UnloadTexture(textureToBeUnloaded );
  1152             iAlfTextureManager.UnloadTexture(textureToBeUnloaded );
  1080 				  	}
  1153             }
  1081 				iZoomedList[aThumbnailIndex].iTextureId = textureID;
  1154         iZoomedList[aThumbnailIndex].iTextureId = textureID;
  1082 				
       
  1083         iZoomedList[aThumbnailIndex].iTexture = newTexture;
  1155         iZoomedList[aThumbnailIndex].iTexture = newTexture;
  1084         }
  1156         }
  1085     
  1157 
  1086     if (iZoomedList[aThumbnailIndex].iObserver)
  1158     if (iZoomedList[aThumbnailIndex].iObserver)
  1087         {
  1159         {
  1088         GLX_LOG_INFO("CGlxTextureManagerImpl::HandleBitmapDecoded TextureContentChangedL");
  1160         GLX_LOG_INFO("CGlxTextureManagerImpl::HandleBitmapDecoded TextureContentChangedL");
  1089         iZoomedList[aThumbnailIndex].iObserver->TextureContentChangedL( textureCreated ,iZoomedList[aThumbnailIndex].iTexture);
  1161         iZoomedList[aThumbnailIndex].iObserver->TextureContentChangedL( textureCreated ,iZoomedList[aThumbnailIndex].iTexture);
  1090         }
  1162         }