uiacceltk/hitchcock/ServerCore/Inc/alfsrvtexturemanager.h
changeset 0 15bf7259bb7c
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     1 /*
       
     2 * Copyright (c) 2008 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:   Server side texture manager
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef C_ALFSRVTEXTUREMANAGER_H
       
    21 #define C_ALFSRVTEXTUREMANAGER_H
       
    22 
       
    23 #include <e32base.h>
       
    24 #include <uiacceltk/HuiTextureManager.h>
       
    25 
       
    26 class CHuiEnv;
       
    27 class CAlfAppSrvSession;
       
    28 class MAlfSrvTextureManagerClient;
       
    29 
       
    30 /**
       
    31  *  Server side texture manager.
       
    32  *
       
    33  *  This texture manager is responsible for managing texture ids and
       
    34  *  handling auto size textures.
       
    35  *  
       
    36  *  @since S60 v5.0
       
    37  */
       
    38 NONSHARABLE_CLASS( CAlfSrvTextureManager ) 
       
    39     : public CBase, 
       
    40       private MHuiTextureAutoSizeObserver
       
    41     {
       
    42 public:
       
    43 
       
    44     /**
       
    45      * Two-phased constructor.
       
    46      * @return new instance of CAlfSrvTextureManager.
       
    47      */
       
    48     static CAlfSrvTextureManager* NewL();
       
    49    
       
    50     /**
       
    51      * Destructor.
       
    52      */
       
    53     virtual ~CAlfSrvTextureManager();
       
    54 
       
    55     /**
       
    56      * This will be called when environment has been created.
       
    57      * @param aEnv reference to environment.
       
    58      */
       
    59     void HandleEnvCreateL( CHuiEnv& aEnv );
       
    60 
       
    61     /**
       
    62      * This will be called just before environment is deleted.
       
    63      */
       
    64     void HandleEnvToBeDeleted();
       
    65 
       
    66     //
       
    67     // Texture Id management
       
    68     //
       
    69 
       
    70     /**
       
    71      * Creates new texture id.
       
    72      * @param aClientOwnerId client owner id.
       
    73      * @param aClientSideId client side id.
       
    74      * @param aClientSideManagerId client side manager id.
       
    75      * @param aReUseAnyDeletedId ETrue if reuse is allowed.
       
    76      * @return texture id.
       
    77      */
       
    78     TInt CreateTextureId(
       
    79         const TProcessId& aClientOwnerId, 
       
    80         TInt aClientSideId, 
       
    81         TInt aClientSideManagerId, 
       
    82         TBool aReUseAnyDeletedId  );
       
    83 
       
    84     /**
       
    85      * Finds server side id based in client side id.
       
    86      * @param aClientOwnerId client owner id.
       
    87      * @param aClientSideId client side id.
       
    88      * @param aClientSideManagerId client side manager id.
       
    89      * @param aIgnoreOwnerForSharedTextures ignore owner.
       
    90      * @return texture id.
       
    91      */
       
    92     TInt ExistingTextureId(
       
    93         const TProcessId& aClientOwnerId, 
       
    94         TInt aClientSideId, 
       
    95         TInt aClientSideManagerId, 
       
    96         TBool aIgnoreOwnerForSharedTextures = EFalse );
       
    97 
       
    98     /**
       
    99      * Releases texture id.
       
   100      * @param aClientOwnerId client owner id.
       
   101      * @param aClientSideId client side id.
       
   102      * @param aClientSideManagerId client side manager id.
       
   103      * @return reference count.
       
   104      */
       
   105     TInt ReleaseTextureId(
       
   106         const TProcessId& aClientOwnerId,
       
   107         TInt aClientSideId, 
       
   108         TInt aClientSideManagerId );
       
   109 
       
   110     /**
       
   111      * Deletes texture id.
       
   112      * @param aClientOwnerId client owner id.
       
   113      * @param aClientSideId client side id.
       
   114      * @param aClientSideManagerId client side manager id.
       
   115      * @return reference count.
       
   116      */
       
   117     TInt DeleteTextureId(
       
   118         const TProcessId& aClientOwnerId,
       
   119         TInt aClientSideId, 
       
   120         TInt aClientSideManagerId );
       
   121 
       
   122     /**
       
   123      * Validates skin for texture id.
       
   124      * @param aClientOwnerId client owner id.
       
   125      * @param aClientSideId client side id.
       
   126      * @param aClientSideManagerId client side manager id.
       
   127      * @return 1 if skin change coordinator already set, 0 otherwise.
       
   128      */
       
   129     TInt ValidateSkinForTextureId(
       
   130         const TProcessId& aClientOwnerId,
       
   131         TInt aClientSideId, 
       
   132         TInt aClientSideManagerId );
       
   133     
       
   134     /**
       
   135      * Destroyes deleted texture ids.
       
   136      * @param aClientOwnerId client owner id.
       
   137      * @return 0.
       
   138      */
       
   139     TInt DestroyDeletedTextureIds(const TProcessId& aClientOwnerId); 
       
   140 
       
   141     //
       
   142     // Auto size texture
       
   143     //
       
   144 
       
   145     /**
       
   146      * Adds client for auto size textures handling.
       
   147      * Note: Clients must remove itself upon destruction using 
       
   148      *       @c RemoveClient method.
       
   149      * @param aClientOwnerId client owner id.
       
   150      * @param aClient reference to client interface.
       
   151      */
       
   152     void AddClientL( 
       
   153         const TProcessId& aClientOwnerId, 
       
   154         MAlfSrvTextureManagerClient& aClient );
       
   155 
       
   156     /**
       
   157      * Removes client.
       
   158      * @param aClient client.
       
   159      */    
       
   160     void RemoveClient( MAlfSrvTextureManagerClient& aClient );
       
   161         
       
   162 private:
       
   163 
       
   164     /**
       
   165      * Constructor.
       
   166      */
       
   167     CAlfSrvTextureManager();
       
   168 
       
   169     /**
       
   170      * Finds client side texture id based on server side id.
       
   171      * Note that shared textures are ignored.
       
   172      * 
       
   173      * @param aServerSideId server side id.
       
   174      * @param aClientSideId this is updated to contain client side id.
       
   175      * @param aOwnerUid this is updated to contain owner uid.
       
   176      * @return ETrue if found, EFalse otherwise.
       
   177      */
       
   178     TBool FindByTextureId( 
       
   179         TInt aServerSideId,
       
   180         TInt& aClientSideId,
       
   181         TProcessId& aOwnerId ) const;
       
   182 
       
   183     /**
       
   184      * Finds index of client.
       
   185      * @param aClient client to look for.
       
   186      * @return index or KErrNotFound if not found.
       
   187      */
       
   188     TInt FindClient( MAlfSrvTextureManagerClient& aClient ) const;
       
   189     
       
   190     /**
       
   191      * Finds client interface based on owner id. This one also
       
   192      * marks corresponding client so that completion of auto size 
       
   193      * changes is informed.
       
   194      * 
       
   195      * @param aOwnerId owner id.
       
   196      * @return client interface, NULL if not found.
       
   197      */
       
   198     MAlfSrvTextureManagerClient* FindClientAndMark( 
       
   199         const TProcessId& aOwnerId );
       
   200 
       
   201     /**
       
   202      * Notifies marked clients of completion of auto size events.
       
   203      * This also clears marks.
       
   204      */
       
   205     void NotifyTextureSizeChangesCompleted();
       
   206 
       
   207     /**
       
   208      * Calculates index from value.
       
   209      * @param aValue value from THuiTextureAutoSizeParams.
       
   210      * @return index.
       
   211      */
       
   212     static TInt IndexFromParameter( TInt aValue );
       
   213 
       
   214     /**
       
   215      * Checks if resize is needed.
       
   216      * @param aCurrentValue current height/width.
       
   217      * @param aNewValue new height/width.
       
   218      * @param aTexture reference to texture.
       
   219      * @return ETrue if resize is needed, EFalse otherwise.
       
   220      */
       
   221     static TBool CheckIfShouldResize( 
       
   222         TInt aCurrentValue, TInt aNewValue, const CHuiTexture& aTexture );
       
   223 
       
   224     /**
       
   225      * Checks if resize is needed.
       
   226      * @param aCurrentSize current size.
       
   227      * @param aNewSize new size.
       
   228      * @param aTexture reference to texture.
       
   229      * @param aDeliveryPriority this will contain delivery priority.
       
   230      * @return ETrue if resize is needed, EFalse otherwise.
       
   231      */
       
   232     static TBool CheckIfResizeNeeded(
       
   233         const TSize& aCurrentSize, const TSize& aNewSize,
       
   234         const CHuiTexture& aTexture, TInt& aDeliveryPriority );
       
   235 
       
   236     /**
       
   237      * Rounds real value to integer.
       
   238      * @param aValue value to be rounded.
       
   239      * @return result value.
       
   240      */
       
   241     inline TInt RoundToInteger( const TReal32& aValue ) const;
       
   242     
       
   243     /**
       
   244      * Calculates new size if resize is needed.
       
   245      * @param aTexture reference to texture.
       
   246      * @param aPreferredSize preferred size.
       
   247      * @param aCurrentSize current size.
       
   248      * @param aNewSize this will contain new size.
       
   249      * @param aDeliveryPriority this will contain delivery priority.
       
   250      * @return ETrue upon success, EFalse otherwise.
       
   251      */
       
   252     TBool CalculateNewSizeIfResizeNeeded( 
       
   253         const CHuiTexture& aTexture, 
       
   254         const THuiRealSize& aPreferredSize,
       
   255         const TSize& aCurrentSize,
       
   256         TSize& aNewSize,
       
   257         TInt& aDeliveryPriority ) const;
       
   258 
       
   259     /**
       
   260      * This one decides new size for current texture.
       
   261      * @param aClient client interface.
       
   262      * @param aClientSideTextureId client side texture id.
       
   263      * @param aTexture texture.
       
   264      * @param aPreferredSize preferred size.
       
   265      */
       
   266     void HandlePreferredSizeChanged( 
       
   267         MAlfSrvTextureManagerClient& aClient, 
       
   268         TInt aClientSideTextureId, 
       
   269         const CHuiTexture& aTexture, 
       
   270         const THuiRealSize& aPreferredSize );
       
   271 
       
   272 // from base class MHuiTextureAutoSizeObserver
       
   273 
       
   274     /**
       
   275      * Handles preferred texture properties changes.
       
   276      * @param aTexture texture.
       
   277      * @param aServerSideTextureId server side texture id.
       
   278      * @param aPreferredSize preferred size.
       
   279      */
       
   280     virtual TBool PreferredSizeChanged(const CHuiTexture& aTexture, 
       
   281         TInt aServerSideTextureId, 
       
   282         const THuiRealSize& aPreferredSize );
       
   283 
       
   284     /**
       
   285      * Handles completion of preferred size changes (for now).
       
   286      */
       
   287     virtual void PreferredSizeReportCompleted();
       
   288 
       
   289 private: // data
       
   290 
       
   291     /**
       
   292      * Pointer to environment.
       
   293      * Not own.
       
   294      */
       
   295     CHuiEnv* iEnv;
       
   296 
       
   297     /**
       
   298      * Global value which is used to assign unique texture ids 
       
   299      * in the serverside.
       
   300      */
       
   301     TInt iNextTextureId;
       
   302 
       
   303     /**
       
   304      * Structure containing information about a texture.
       
   305      */
       
   306     struct TUsedTexture 
       
   307         {
       
   308         TUsedTexture()
       
   309             :iClientSideId(0), 
       
   310              iClientSideManagerId(0), 
       
   311              iServerSideId(0), 
       
   312              iOwnerId(), 
       
   313              iReleased(EFalse), 
       
   314              iDeleted(EFalse),
       
   315              iSkinChangeCoordinator(EFalse){}
       
   316         
       
   317         /** The client side texture id */
       
   318         TInt   iClientSideId;
       
   319         /** client side texture manager of the texture */
       
   320         TInt32 iClientSideManagerId;                
       
   321         /** The server side texture id */
       
   322         TInt   iServerSideId;
       
   323         /** Owner process of the texture */
       
   324         TProcessId iOwnerId;
       
   325         /** Released */
       
   326         TBool iReleased;
       
   327         /** Deleted */
       
   328         TBool iDeleted;
       
   329         /** Skin change coordinator for shared textures, only one entry with same id has this set to ETrue */
       
   330         TBool iSkinChangeCoordinator;
       
   331         };
       
   332         
       
   333     /** 
       
   334      * Array of used textures. Items are not deleted from this array when 
       
   335      * application exists because hitchcock texture manager does not delete
       
   336      * textures either (only unloads).
       
   337      * This array is used when texture is re-created again.
       
   338      * Own.
       
   339      */
       
   340     RArray<TUsedTexture> iUsedTextures;
       
   341 
       
   342     /**
       
   343      * Structure defining mapping from owner id to
       
   344      * client interface used for auto size textures.
       
   345      */
       
   346     struct TClientItem
       
   347         {
       
   348         TProcessId iOwnerId;
       
   349         MAlfSrvTextureManagerClient* iClient;
       
   350         TBool iIsMarked;
       
   351         };
       
   352         
       
   353     /**
       
   354      * Mapping from texture owner id to client interface.
       
   355      * Own.
       
   356      */
       
   357     RArray< TClientItem > iClients;
       
   358 
       
   359     /**
       
   360      * Boolean flag indicating if renderer is OpenGL.
       
   361      */
       
   362     TBool iIsRendererHWA;
       
   363     };
       
   364 
       
   365 #endif // C_CLASSNAME_H