uiacceltk/hitchcock/Client/src/alftexture.cpp
changeset 0 15bf7259bb7c
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   Texture
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "alf/alftexture.h"
       
    21 #include "alf/alfenv.h"
       
    22 #include "alf/alftexturemanager.h"
       
    23 #include "alfclient.h"
       
    24 
       
    25 struct CAlfTexture::TPrivateData
       
    26     {
       
    27     TInt iServerSideHandle;
       
    28 
       
    29     CAlfEnv* iEnv;
       
    30 
       
    31     /** Specify upload behavior - how to convert the bitmap
       
    32       to texture. */
       
    33     TAlfTextureFlags iFlags;
       
    34 
       
    35     /** Resource location for the texture. */
       
    36     HBufC* iFileName;
       
    37 
       
    38     /** Bitmap content provider. Alternative content (re)loading
       
    39      * mechanism to filenames (loading from a file). */
       
    40     MAlfBitmapProvider* iBitmapProvider; 
       
    41 
       
    42     /** A flag to tell if texture is ready to be used */
       
    43     TBool iHasContent;
       
    44 
       
    45     TSize iTextureMaxSize;
       
    46 
       
    47     TSize iSize;
       
    48 
       
    49     TInt iId;
       
    50     
       
    51     TUid iManagerId;
       
    52     
       
    53     TBool iAnimated;
       
    54     
       
    55     TInt iPriority;
       
    56     
       
    57     /** Flags to tell that texture has been released by unloading or release */
       
    58     TInt iReleaseFlags;
       
    59     
       
    60     TAlfTextureAutoSizeParams iAutoSizeParams;
       
    61     
       
    62     TBool iRefCounted;
       
    63     
       
    64     TInt iRefCountingAction;
       
    65     };
       
    66 
       
    67 
       
    68 // ======== MEMBER FUNCTIONS ========
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // Constructor
       
    72 // ---------------------------------------------------------------------------
       
    73 //
       
    74 CAlfTexture::CAlfTexture()
       
    75 	{
       
    76 		
       
    77 	}
       
    78 
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // ?description
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 EXPORT_C CAlfTexture::~CAlfTexture()
       
    85 	{
       
    86 	if ( iData )
       
    87 	    {
       
    88 	    iData->iEnv->Client().TextureDelete(iData->iId, iData->iManagerId.iUid);    
       
    89 	    delete iData->iFileName;
       
    90 	    iData->iFileName = NULL;
       
    91 
       
    92     	CAlfTextureManager* manager = NULL;
       
    93     	if (iData->iManagerId == TUid::Uid(0))
       
    94     	    {
       
    95     	    manager = &iData->iEnv->TextureManager();	        
       
    96     	    }
       
    97     	else
       
    98     	    {
       
    99     	    manager = iData->iEnv->SharedTextureManager(iData->iManagerId);	            
       
   100     	    } 	       
       
   101 
       
   102     	if (iData->iId != 0)
       
   103     	    {
       
   104         	manager->RemoveTexture(*this);
       
   105     	    }
       
   106 	    }
       
   107 	delete iData;
       
   108 	iData = NULL;
       
   109 	}
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 // ?description
       
   113 // ---------------------------------------------------------------------------
       
   114 //
       
   115 CAlfTexture* CAlfTexture::NewL(CAlfEnv& aEnv, TUid aManagerUid, TInt aId, 
       
   116     TInt aBitmapHandle, TInt aMaskHandle, TAlfTextureFlags aFlags,TBool aAnimated)
       
   117 	{
       
   118 	CAlfTexture* self = 
       
   119 		CAlfTexture::NewLC(aEnv, aManagerUid, aId, aBitmapHandle, aMaskHandle, aFlags,aAnimated);        
       
   120     CleanupStack::Pop( self );
       
   121     return self;		
       
   122 	}
       
   123 	
       
   124 
       
   125 // ---------------------------------------------------------------------------
       
   126 // ?description
       
   127 // ---------------------------------------------------------------------------
       
   128 //
       
   129 CAlfTexture* CAlfTexture::NewLC(CAlfEnv& aEnv, TUid aManagerUid, TInt aId, 
       
   130     TInt aBitmapHandle, TInt aMaskHandle, TAlfTextureFlags aFlags,TBool aAnimated)
       
   131 	{
       
   132     CAlfTexture* self = new( ELeave ) CAlfTexture();
       
   133     CleanupStack::PushL( self );
       
   134     self->ConstructL(aEnv, aManagerUid, aId, aBitmapHandle, aMaskHandle, aFlags,aAnimated);
       
   135     return self;	
       
   136 	}
       
   137 
       
   138 // ---------------------------------------------------------------------------
       
   139 // ?description
       
   140 // ---------------------------------------------------------------------------
       
   141 //
       
   142 void CAlfTexture::ConstructL(CAlfEnv& aEnv, TUid aManagerUid, TInt aId, 
       
   143     TInt aBitmapHandle, TInt aMaskHandle, TAlfTextureFlags aFlags, TBool aAnimated)
       
   144 	{
       
   145     iData = new (ELeave) TPrivateData;
       
   146     iData->iEnv = &aEnv;
       
   147     iData->iId = aId;
       
   148     iData->iFileName = NULL;
       
   149     iData->iBitmapProvider = NULL;
       
   150     iData->iFlags = aFlags;
       
   151     iData->iTextureMaxSize = TSize(0,0);
       
   152     iData->iManagerId = aManagerUid; 
       
   153     iData->iAnimated = aAnimated;
       
   154     iData->iPriority = EAlfTexturePriorityNormal;
       
   155     iData->iReleaseFlags = 0;
       
   156     iData->iAutoSizeParams = TAlfTextureAutoSizeParams();
       
   157     iData->iRefCounted = EFalse;
       
   158     iData->iRefCountingAction = CAlfTexture::ERefCountingActionUnload;
       
   159     if (aAnimated)
       
   160         {
       
   161         iData->iServerSideHandle = NULL;
       
   162         }
       
   163     else
       
   164         {
       
   165         
       
   166         iData->iServerSideHandle = 
       
   167         	iData->iEnv->Client().TextureCreateL( aId, aBitmapHandle, 
       
   168         	aMaskHandle, aFlags, iData->iManagerId.iUid );    	            
       
   169 	    }
       
   170     if (aBitmapHandle != 0 || aMaskHandle != 0)
       
   171         {
       
   172         iData->iHasContent = ETrue;	
       
   173         }
       
   174     else
       
   175         {
       
   176         iData->iHasContent = EFalse;	        
       
   177         }    
       
   178 	
       
   179 	CAlfTextureManager* manager = NULL;
       
   180 	if (iData->iManagerId == TUid::Uid(0))
       
   181 	    {
       
   182 	    manager = &iData->iEnv->TextureManager();	        
       
   183 	    }
       
   184 	else
       
   185 	    {
       
   186 	    manager = iData->iEnv->SharedTextureManager(iData->iManagerId);	            
       
   187 	    } 
       
   188 	    
       
   189 	if (iData->iId != 0)
       
   190 	    {
       
   191     	manager->AppendTextureL(this);	        
       
   192 	    }
       
   193 	}
       
   194 
       
   195 // ---------------------------------------------------------------------------
       
   196 // ?description
       
   197 // ---------------------------------------------------------------------------
       
   198 //
       
   199 void CAlfTexture::SetServerHandle(TInt aHandle)
       
   200     {
       
   201     iData->iServerSideHandle = aHandle;
       
   202     }
       
   203     
       
   204 // ---------------------------------------------------------------------------
       
   205 // ?description
       
   206 // ---------------------------------------------------------------------------
       
   207 //
       
   208 EXPORT_C TInt CAlfTexture::ServerHandle() const
       
   209     {
       
   210     return iData->iServerSideHandle;
       
   211     }
       
   212 
       
   213 // ---------------------------------------------------------------------------
       
   214 // ?description
       
   215 // ---------------------------------------------------------------------------
       
   216 //
       
   217 void CAlfTexture::SetBitmapProvider(MAlfBitmapProvider* aBitmapProvider)
       
   218     {
       
   219     iData->iBitmapProvider = aBitmapProvider;
       
   220     }
       
   221     
       
   222 // ---------------------------------------------------------------------------
       
   223 // ?description
       
   224 // ---------------------------------------------------------------------------
       
   225 //
       
   226 MAlfBitmapProvider* CAlfTexture::BitmapProvider() const
       
   227     {
       
   228     return iData->iBitmapProvider;                
       
   229     }
       
   230     
       
   231 // ---------------------------------------------------------------------------
       
   232 // ?description
       
   233 // ---------------------------------------------------------------------------
       
   234 //
       
   235 void CAlfTexture::SetFileNameL(const TFileName & aFileName)
       
   236     {
       
   237     delete iData->iFileName;
       
   238     iData->iFileName = NULL;
       
   239     if (aFileName.Length()>0)
       
   240         {
       
   241         iData->iFileName = aFileName.AllocL();
       
   242         if (iData->iAnimated)
       
   243             {
       
   244             iData->iServerSideHandle = 
       
   245         	iData->iEnv->Client().TextureCreateAnimatedL( iData->iId, 
       
   246             iData->iFlags, iData->iManagerId.iUid,*iData->iFileName );    	            
       
   247             }
       
   248         }       
       
   249     }
       
   250     
       
   251 // ---------------------------------------------------------------------------
       
   252 // ?description
       
   253 // ---------------------------------------------------------------------------
       
   254 //
       
   255 EXPORT_C HBufC* CAlfTexture::FileName() const
       
   256     {
       
   257     return iData->iFileName;                        
       
   258     }
       
   259 
       
   260 // ---------------------------------------------------------------------------
       
   261 // ?description
       
   262 // ---------------------------------------------------------------------------
       
   263 //
       
   264 EXPORT_C TBool CAlfTexture::HasContent() const
       
   265     {
       
   266     TBool retVal = EFalse;
       
   267     iData->iEnv->Client().TextureHasContent(retVal, 
       
   268         iData->iId, 
       
   269         iData->iManagerId.iUid);
       
   270     return retVal;                                
       
   271     }
       
   272     
       
   273 // ---------------------------------------------------------------------------
       
   274 // ?description
       
   275 // ---------------------------------------------------------------------------
       
   276 //
       
   277 void CAlfTexture::SetMaxTextureSize(TSize aTextureMaxSize)
       
   278     {
       
   279     iData->iTextureMaxSize = aTextureMaxSize;    
       
   280     }
       
   281 
       
   282 // ---------------------------------------------------------------------------
       
   283 // ?description
       
   284 // ---------------------------------------------------------------------------
       
   285 //
       
   286 EXPORT_C TSize CAlfTexture::MaxTextureSize()
       
   287     {
       
   288     return iData->iTextureMaxSize;    
       
   289     }
       
   290 
       
   291 // ---------------------------------------------------------------------------
       
   292 // ?description
       
   293 // ---------------------------------------------------------------------------
       
   294 //
       
   295 EXPORT_C TInt CAlfTexture::Id() const
       
   296     {
       
   297     return iData->iId;        
       
   298     }
       
   299     
       
   300 // ---------------------------------------------------------------------------
       
   301 // ?description
       
   302 // ---------------------------------------------------------------------------
       
   303 //
       
   304 TAlfTextureFlags CAlfTexture::Flags() const
       
   305     {
       
   306     return iData->iFlags;                
       
   307     }
       
   308 
       
   309 // ---------------------------------------------------------------------------
       
   310 // ?description
       
   311 // ---------------------------------------------------------------------------
       
   312 //
       
   313 void CAlfTexture::SetFlags(TAlfTextureFlags aFlags)
       
   314     {
       
   315     iData->iFlags = aFlags;    
       
   316     }
       
   317 
       
   318 // ---------------------------------------------------------------------------
       
   319 // ?description
       
   320 // ---------------------------------------------------------------------------
       
   321 //
       
   322 void CAlfTexture::SetSize(TSize aSize)
       
   323     {
       
   324     iData->iSize = aSize;
       
   325     }
       
   326 
       
   327 // ---------------------------------------------------------------------------
       
   328 // ?description
       
   329 // ---------------------------------------------------------------------------
       
   330 //
       
   331 EXPORT_C TBool CAlfTexture::IsAnimated() const
       
   332     {
       
   333     return iData->iAnimated;
       
   334     }
       
   335 
       
   336 // ---------------------------------------------------------------------------
       
   337 // ?description
       
   338 // ---------------------------------------------------------------------------
       
   339 //
       
   340 EXPORT_C void CAlfTexture::StartAnimation()
       
   341     {
       
   342     if (iData->iAnimated)
       
   343         {
       
   344         iData->iEnv->Client().TextureStartAnimation( iData->iId );
       
   345         }
       
   346     }
       
   347 
       
   348 // ---------------------------------------------------------------------------
       
   349 // ?description
       
   350 // ---------------------------------------------------------------------------
       
   351 //
       
   352 EXPORT_C void CAlfTexture::StopAnimation()
       
   353     {
       
   354     if (iData->iAnimated)
       
   355         {
       
   356         iData->iEnv->Client().TextureStopAnimation( iData->iId );
       
   357         }
       
   358     }
       
   359  
       
   360 // ---------------------------------------------------------------------------
       
   361 // Sets the texture release priority
       
   362 // ---------------------------------------------------------------------------
       
   363 //   
       
   364 EXPORT_C void CAlfTexture::SetPriority( TInt aPriority )
       
   365     {
       
   366     iData->iPriority = aPriority;
       
   367     }
       
   368 
       
   369 // ---------------------------------------------------------------------------
       
   370 // Returns the texture release priority
       
   371 // ---------------------------------------------------------------------------
       
   372 //    
       
   373 EXPORT_C TInt CAlfTexture::Priority() const
       
   374     {
       
   375     return iData->iPriority;
       
   376     }
       
   377 
       
   378 
       
   379 // ---------------------------------------------------------------------------
       
   380 // ?description
       
   381 // ---------------------------------------------------------------------------
       
   382 //
       
   383 EXPORT_C TSize CAlfTexture::Size() const
       
   384     {
       
   385     return iData->iSize;
       
   386     }
       
   387     
       
   388 // ---------------------------------------------------------------------------
       
   389 // ?description
       
   390 // ---------------------------------------------------------------------------
       
   391 //
       
   392 TInt CAlfTexture::ReleaseFlags() const
       
   393     {
       
   394     return iData->iReleaseFlags;
       
   395     }
       
   396 
       
   397 // ---------------------------------------------------------------------------
       
   398 // ?description
       
   399 // ---------------------------------------------------------------------------
       
   400 //
       
   401 void CAlfTexture::SetReleaseFlags(TInt aReleaseFlags) 
       
   402     {
       
   403     iData->iReleaseFlags = aReleaseFlags;
       
   404     }
       
   405 
       
   406 // ---------------------------------------------------------------------------
       
   407 // Sets autosize related parameters.
       
   408 // ---------------------------------------------------------------------------
       
   409 //
       
   410 EXPORT_C void CAlfTexture::SetAutoSizeParams
       
   411     (const TAlfTextureAutoSizeParams& aParams)
       
   412     {
       
   413     TInt err = iData->iEnv->Client().TextureSetAutoSizeParams( iData->iId, 
       
   414         iData->iManagerId.iUid, aParams );
       
   415     if (err == KErrNone)
       
   416         {
       
   417         iData->iAutoSizeParams = aParams;            
       
   418         }    
       
   419     }
       
   420     
       
   421 // ---------------------------------------------------------------------------
       
   422 // Gets autosize related parameters.
       
   423 // ---------------------------------------------------------------------------
       
   424 //
       
   425 EXPORT_C TAlfTextureAutoSizeParams CAlfTexture::AutoSizeParams() const
       
   426     {
       
   427     return iData->iAutoSizeParams;        
       
   428     }
       
   429 
       
   430 
       
   431 
       
   432 
       
   433 
       
   434 // ---------------------------------------------------------------------------
       
   435 // 
       
   436 // ---------------------------------------------------------------------------
       
   437 //
       
   438 EXPORT_C void CAlfTexture::EnableRefCounting(TBool aEnable)
       
   439     {
       
   440     iData->iRefCounted = aEnable;
       
   441     }
       
   442     
       
   443 // ---------------------------------------------------------------------------
       
   444 // 
       
   445 // ---------------------------------------------------------------------------
       
   446 //
       
   447 EXPORT_C TBool CAlfTexture::RefCountingEnabled()
       
   448     {
       
   449     return iData->iRefCounted;    
       
   450     }
       
   451     
       
   452 // ---------------------------------------------------------------------------
       
   453 // 
       
   454 // ---------------------------------------------------------------------------
       
   455 //
       
   456 EXPORT_C void CAlfTexture::SetRefCountingAction(TInt aAction)
       
   457     {
       
   458     iData->iRefCountingAction = aAction;                    
       
   459     }
       
   460 
       
   461 // ---------------------------------------------------------------------------
       
   462 // 
       
   463 // ---------------------------------------------------------------------------
       
   464 //
       
   465 EXPORT_C TInt CAlfTexture::RefCountingAction() const
       
   466     {
       
   467     return iData->iRefCountingAction;            
       
   468     }
       
   469     
       
   470 // ---------------------------------------------------------------------------
       
   471 // 
       
   472 // ---------------------------------------------------------------------------
       
   473 //
       
   474 CAlfTextureManager* CAlfTexture::TextureManager()
       
   475     {
       
   476 	CAlfTextureManager* manager = NULL;
       
   477 	if (iData->iManagerId == TUid::Uid(0))
       
   478 	    {
       
   479 	    manager = &iData->iEnv->TextureManager();	        
       
   480 	    }
       
   481 	else
       
   482 	    {
       
   483 	    manager = iData->iEnv->SharedTextureManager(iData->iManagerId);	            
       
   484 	    }
       
   485 	return manager;     	               
       
   486     }
       
   487     
       
   488