uiacceltk/hitchcock/goommonitor/inc/goommemorymonitor.h
branchRCL_3
changeset 3 d8a3531bc6b8
parent 0 15bf7259bb7c
child 7 433cbbb6a04b
equal deleted inserted replaced
0:15bf7259bb7c 3:d8a3531bc6b8
    23 #include <f32file.h>
    23 #include <f32file.h>
    24 #include <w32std.h>
    24 #include <w32std.h>
    25 #include <EGL/egl.h>
    25 #include <EGL/egl.h>
    26 #include "goomglobalconfig.h"
    26 #include "goomglobalconfig.h"
    27 #include "goomwindowgrouplist.h"
    27 #include "goomwindowgrouplist.h"
       
    28 #include "goomtraces.h"
    28 
    29 
    29 // ---------------------------------------------------------
    30 // ---------------------------------------------------------
    30 // CMemoryMonitor
    31 // CMemoryMonitor
    31 // ---------------------------------------------------------
    32 // ---------------------------------------------------------
    32 //
    33 //
    38 class CGOomConfig;
    39 class CGOomConfig;
    39 class CGoomThresholdCrossed;
    40 class CGoomThresholdCrossed;
    40 
    41 
    41 typedef EGLBoolean (*NOK_resource_profiling)(EGLDisplay, EGLint, EGLint*, EGLint, EGLint*);
    42 typedef EGLBoolean (*NOK_resource_profiling)(EGLDisplay, EGLint, EGLint*, EGLint, EGLint*);
    42 
    43 
       
    44 class CGOomSynchTimer;
       
    45 
    43 NONSHARABLE_CLASS(CMemoryMonitor) : public CBase
    46 NONSHARABLE_CLASS(CMemoryMonitor) : public CBase
    44     {
    47     {
    45 public:
    48 public:
    46     static CMemoryMonitor* NewL();
    49     static CMemoryMonitor* NewL();
    47     ~CMemoryMonitor();
    50     ~CMemoryMonitor();
       
    51     
       
    52     enum TGOomTrigger   //How free memory operation was triggered
       
    53             {
       
    54             EGOomFocusChanged = 0,
       
    55             EGOomRequestMemory,
       
    56             EGOomThresholdCrossed
       
    57             };
    48 
    58 
    49 public: // event handlers
    59 public: // event handlers
    50     void FreeMemThresholdCrossedL(TInt aAction = 0, TInt aThreshold = 0);
    60     void FreeMemThresholdCrossedL(TInt aAction = 0, TInt aThreshold = 0);
    51     void AppNotExiting(TInt aWgId);
    61     void AppNotExiting(TInt aWgId);
    52     void StartFreeSomeRamL(TInt aTargetFree);
    62     void StartFreeSomeRamL(TInt aTargetFree, TGOomTrigger aTrigger);
    53     void FreeOptionalRamL(TInt aTargetFree, TInt aPluginId, TBool aUseAbsolute = EFalse); // The ID of the plugin that will clear up the allocation, used to determine the priority of the allocation
    63     void FreeOptionalRamL(TInt aTargetFree, TInt aPluginId, TBool aUseAbsolute = EFalse); // The ID of the plugin that will clear up the allocation, used to determine the priority of the allocation
    54     void RequestFreeMemoryL(TInt aTargetFree, TBool aUseAbsolute = EFalse);
    64     void RequestFreeMemoryL(TInt aTargetFree, TBool aUseAbsolute = EFalse);
    55     void HandleFocusedWgChangeL(TInt aForegroundAppUid = KErrNotFound);
    65     void HandleFocusedWgChangeL(TInt aForegroundAppUid = KErrNotFound);
    56     static const CGOomGlobalConfig& GlobalConfig();
    66     static const CGOomGlobalConfig& GlobalConfig();
    57     void SetPriorityBusy(TInt aWgId);
    67     void SetPriorityBusy(TInt aWgId);
    59     void SetPriorityHigh(TInt aWgId);
    69     void SetPriorityHigh(TInt aWgId);
    60     void ResetTargets(TInt aTarget = 0);
    70     void ResetTargets(TInt aTarget = 0);
    61     TInt GetFreeMemory();
    71     TInt GetFreeMemory();
    62     void RunCloseAppActions(TInt aMaxPriority);
    72     void RunCloseAppActions(TInt aMaxPriority);
    63     CGOomWindowGroupList * GetWindowGroupList() const;
    73     CGOomWindowGroupList * GetWindowGroupList() const;
       
    74     TBool IsSafeToProcessNewRequest(TUint aClientId);
    64         
    75         
    65     
    76     
    66     void SetActiveClient(TInt aClientId)
    77     void SetActiveClient(TInt aClientId)
    67         {
    78         {
    68         iActiveClientId = aClientId;
    79         iActiveClientId = aClientId;
    75 
    86 
    76     TInt ForegroundAppUid()
    87     TInt ForegroundAppUid()
    77         {
    88         {
    78         return iForegroundAppUid;
    89         return iForegroundAppUid;
    79         } 
    90         } 
    80     void SessionInCriticalAllocation(TBool aPostponeMemGood)
    91     void SessionInCriticalAllocation(TBool aPostponeMemGood, TUint aClientId)
    81         {
    92         {
       
    93         FUNC_LOG;
    82         if (aPostponeMemGood)
    94         if (aPostponeMemGood)
    83             {
    95             {
    84             iPostponeMemGood++;
    96             iPostponeMemGood++;
       
    97             if(iClientsRequestingMemory.Find(aClientId) == KErrNotFound)
       
    98                 iClientsRequestingMemory.Append(aClientId);
       
    99             
       
   100             TRACES2("SessionInCriticalAllocation : STARTING Critical Allocations for Client %x, ClientsRequestingMemory Count %d", aClientId, iClientsRequestingMemory.Count());
    85             }
   101             }
    86         else
   102         else
    87             {
   103             {
    88             iPostponeMemGood--;
   104             iPostponeMemGood--;
    89             if(iPostponeMemGood<0)
   105             TInt idx = iClientsRequestingMemory.Find(aClientId);
       
   106             if(idx != KErrNotFound)
       
   107                 {
       
   108                 iClientsRequestingMemory.Remove(idx);
       
   109                 TRACES2("SessionInCriticalAllocation : ENDING Critical Allocations for Client %x, ClientsRequestingMemory Count %d", aClientId, iClientsRequestingMemory.Count());
       
   110                 }
       
   111             
       
   112              if(iPostponeMemGood<0)
    90                 {
   113                 {
    91                 iPostponeMemGood = 0;
   114                 iPostponeMemGood = 0;
    92                 }
   115                 }
    93             }
   116             }
    94                         
   117         TRACES1("SessionInCriticalAllocation : ClientsRequestingMemory Count %d", iClientsRequestingMemory.Count());    
    95         if (iPostponeMemGood == 0)
   118         if (iClientsRequestingMemory.Count() == 0)
    96             {
   119             {
    97             DoPostponedMemoryGood();
   120             DoPostponedMemoryGood();
    98             }
   121             }
    99         
   122         
   100         } 
   123         } 
   101     
   124     
   102     void DoPostponedMemoryGood();
   125     void DoPostponedMemoryGood();
   103     
   126     
   104     TBool NeedToPostponeMemGood()
   127     TBool NeedToPostponeMemGood()
   105         {
   128         {
   106         return (iPostponeMemGood != 0);
   129         //return (iPostponeMemGood != 0);
       
   130         return (iClientsRequestingMemory.Count() != 0);
   107         } 
   131         } 
       
   132     
       
   133     void WaitAndSynchroniseMemoryState();
       
   134     void SynchroniseMemoryState();
   108     
   135     
   109 private:
   136 private:
   110     CMemoryMonitor();
   137     CMemoryMonitor();
   111     void ConstructL();
   138     void ConstructL();
   112     TBool FreeGraphicsMemoryAboveThresholdL(TInt& aCurrentFreeMemory);
   139     TBool FreeGraphicsMemoryAboveThresholdL(TInt& aCurrentFreeMemory);
   113     void CloseNextApp();
   140     void CloseNextApp();
   114     void RefreshThresholds(TInt aForegroundAppUid = KErrNotFound);
   141     void RefreshThresholds(TInt aForegroundAppUid = KErrNotFound);
   115     void StartFreeSomeRamL(TInt aTargetFree, TInt aMaxPriority);
   142     void StartFreeSomeRamL(TInt aTargetFree, TInt aMaxPriority, TGOomTrigger aTrigger);
   116     void AppClosePriorityChanged(TInt aWgId, TInt aPriority);
   143     void AppClosePriorityChanged(TInt aWgId, TInt aPriority);
       
   144     
   117     
   145     
   118 public:
   146 public:
   119     // All members are owned
   147     // All members are owned
   120     // generally useful sessions
   148     // generally useful sessions
   121     RFs iFs;
   149     RFs iFs;
   172     CGoomThresholdCrossed* iMemAllocationsGrowing;
   200     CGoomThresholdCrossed* iMemAllocationsGrowing;
   173     CGoomThresholdCrossed* iMemAllocationsGoingDown;
   201     CGoomThresholdCrossed* iMemAllocationsGoingDown;
   174     
   202     
   175     TInt iForegroundAppUid;
   203     TInt iForegroundAppUid;
   176     TInt iPostponeMemGood;
   204     TInt iPostponeMemGood;
       
   205     
       
   206     RArray<TUint> iClientsRequestingMemory;
       
   207     
       
   208     TGOomTrigger iTrigger;
       
   209     
       
   210     CGOomSynchTimer* iSynchTimer;
   177     };
   211     };
   178 
   212 
       
   213 
       
   214 
       
   215 NONSHARABLE_CLASS(CGOomSynchTimer) : public CTimer
       
   216     {
       
   217     public:
       
   218         static CGOomSynchTimer* NewL(CMemoryMonitor& aMonitor);
       
   219         
       
   220     private:
       
   221         CMemoryMonitor& iMonitor;
       
   222         CGOomSynchTimer(CMemoryMonitor& aMonitor);
       
   223         void RunL();
       
   224     };
       
   225 
       
   226 
   179 #endif /*GOOMMEMORYMONITOR_H*/
   227 #endif /*GOOMMEMORYMONITOR_H*/