uiacceltk/hitchcock/goommonitor/src/goomwindowgrouplist.cpp
branchRCL_3
changeset 6 10534483575f
parent 3 d8a3531bc6b8
child 7 88b23e2e82e1
--- a/uiacceltk/hitchcock/goommonitor/src/goomwindowgrouplist.cpp	Fri Mar 12 15:47:04 2010 +0200
+++ b/uiacceltk/hitchcock/goommonitor/src/goomwindowgrouplist.cpp	Mon Mar 15 12:43:37 2010 +0200
@@ -68,128 +68,156 @@
     {
     FUNC_LOG;
   
-    NOK_resource_profiling eglQueryProfilingData = (NOK_resource_profiling)eglGetProcAddress("eglQueryProfilingDataNOK");
+    if (!iAlfClient.Handle())
+        {
+        User::LeaveIfError(iAlfClient.Connect());
+        }
+    iLowOnMemWgs.Reset();
+    User::LeaveIfError(iAlfClient.GetListOfInactiveWindowGroupsWSurfaces(&iLowOnMemWgs));
+
+    RArray<TInt>& inactiveSurfaces = iLowOnMemWgs;
+      
+    RArray<TUint64> processIds;
+    RArray<TUint> privMemUsed;
     
-    if (!eglQueryProfilingData)
+    if (inactiveSurfaces.Count() == 1) // ALF only 
+        {
+        NOK_resource_profiling eglQueryProfilingData = (NOK_resource_profiling)eglGetProcAddress("eglQueryProfilingDataNOK");
+    
+        if (!eglQueryProfilingData)
             {
             TRACES("RefreshL EGL_NOK_resource_profiling not available");
-            return;
+			return;
             }
     
-    EGLint data_count;
-    EGLint* prof_data;
-    TInt i(0);
-    RArray<TUint64> processIds;
-    RArray<TUint> privMemUsed;
-    RArray<TUint64> systemProcessIds;
+        EGLint data_count;
+        EGLint* prof_data;
+        TInt i(0);
+        RArray<TUint64> processIds;
+        RArray<TUint> privMemUsed;
+        RArray<TUint64> systemProcessIds;
         
-    EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
+        EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
 
-    /* Find out how much profiling data is available */
-    eglQueryProfilingData(dpy, EGL_PROF_QUERY_GLOBAL_BIT_NOK|
+        /* Find out how much profiling data is available */
+        eglQueryProfilingData(dpy, EGL_PROF_QUERY_GLOBAL_BIT_NOK|
                                 EGL_PROF_QUERY_MEMORY_USAGE_BIT_NOK,
                                 NULL, 0, &data_count);
     
-    /* Allocate room for the profiling data */
-    prof_data = (EGLint*)User::Alloc(data_count * sizeof(EGLint));
-    if (prof_data == NULL)
-        return;
+        /* Allocate room for the profiling data */
+        prof_data = (EGLint*)User::Alloc(data_count * sizeof(EGLint));
+        if (prof_data == NULL)
+		   {
+		   return;
+		   }
 
-    /* Retrieve the profiling data */
-    eglQueryProfilingData(dpy,   EGL_PROF_QUERY_GLOBAL_BIT_NOK|
+        /* Retrieve the profiling data */
+        eglQueryProfilingData(dpy,   EGL_PROF_QUERY_GLOBAL_BIT_NOK|
                                  EGL_PROF_QUERY_MEMORY_USAGE_BIT_NOK,
                                  prof_data,
                                  data_count,
                                  &data_count);
     
-    /* Iterate over the returned data */
-    TUint64 process_id;  
-    while (i < data_count)
-        {
-        TRACES2("RefreshL EGL_NOK_resource_profiling - index: %d data: %x", i, prof_data[i]);
-        switch (prof_data[i++])
-            {   
-            case EGL_PROF_PROCESS_ID_NOK:
-                {
-                if (sizeof(EGLNativeProcessIdTypeNOK) == 8)
+        /* Iterate over the returned data */
+        TUint64 process_id;  
+        while (i < data_count)
+            {
+            TRACES2("RefreshL EGL_NOK_resource_profiling - index: %d data: %x", i, prof_data[i]);
+            switch (prof_data[i++])
+                {   
+                case EGL_PROF_PROCESS_ID_NOK:
+                    {
+                    if (sizeof(EGLNativeProcessIdTypeNOK) == 8)
+                        {
+                        process_id = TUint64(prof_data[i]);
+                        process_id += (TUint64(prof_data[i + 1]) << 32);
+                        i+=2;
+                        }
+                    else
+                        {
+                        process_id = prof_data[i];
+                        i++;
+                        }
+                    break;
+                    }
+                case EGL_PROF_PROCESS_USED_PRIVATE_MEMORY_NOK:
                     {
-                    process_id = TUint64(prof_data[i]);
-                    process_id += (TUint64(prof_data[i + 1]) << 32);
-                    i+=2;
+                    TUint mem = prof_data[i];
+                    privMemUsed.Append(mem);
+
+                    TRACES1("Memory Usage by app is %d", mem);
+                    if(mem > KAllowedMemUsageForApps)
+                        processIds.Append(process_id);
+                
+                    i++;
+                    break;
                     }
-                else
+                case EGL_PROF_PROCESS_USED_SHARED_MEMORY_NOK:
                     {
-                    process_id = prof_data[i];
+                    TUint mem = prof_data[i];
+                    TRACES1("Shared Memory Usage by app is %d", mem);
+                    if(mem > KAllowedMemUsageForApps)
+                        processIds.Append(process_id);
                     i++;
+                    break;
+                    }
+                case EGL_PROF_USED_MEMORY_NOK:
+                case EGL_PROF_TOTAL_MEMORY_NOK:
+                default:
+                    {
+                    TRACES2("RefreshL index %d, data: %d\n", i, prof_data[i]);
+                    i++;
+                    break;
                     }
-                break;
                 }
-            case EGL_PROF_PROCESS_USED_PRIVATE_MEMORY_NOK:
+            }
+       
+       /* Free allocated memory */
+        User::Free(prof_data);
+    
+        TRACES1("RefreshL : %d Processes use gfx memory", processIds.Count());
+    
+        ///////////////////////////////////////////////////////////////////
+        // Optimization, no need to construct list if ALF is the only one
+        ///////////////////////////////////////////////////////////////////
+    
+        if (processIds.Count() == 1)
+            {
+            RProcess process;
+            TInt err =  process.Open(processIds[0]);
+            if(!err)
                 {
-                TUint mem = prof_data[i];
-                privMemUsed.Append(mem);
-
-                TRACES1("Memory Usage by app is %d", mem);
-                if(mem > KAllowedMemUsageForApps)
-                    processIds.Append(process_id);
-                
-                i++;
-                break;
-                }
-            case EGL_PROF_PROCESS_USED_SHARED_MEMORY_NOK:
-                {
-                TUint mem = prof_data[i];
-                TRACES1("Shared Memory Usage by app is %d", mem);
-                if(mem > KAllowedMemUsageForApps)
-                    processIds.Append(process_id);
-                i++;
-                break;
-                }
-            case EGL_PROF_USED_MEMORY_NOK:
-            case EGL_PROF_TOTAL_MEMORY_NOK:
-            default:
-                {
-                TRACES2("RefreshL index %d, data: %d\n", i, prof_data[i]);
-                i++;
-                break;
+                TInt secureId = process.SecureId();
+                process.Close();
+                if(secureId == 0x10003B20) // magic, wserv 
+                    {
+                    processIds.Close();
+                    TRACES("Only WServ using GFX mem, no need for app actions");
+                    return;
+                    }
                 }
             }
         }
-        
-    /* Free allocated memory */
-    User::Free(prof_data);
-    
-    TRACES1("RefreshL : %d Processes use gfx memory", processIds.Count());
+                
+    // Refresh window group list
+    // get all window groups, with info about parents
+    TInt numGroups = iWs.NumWindowGroups();
+    iWgIds.ReserveL(numGroups);
+    User::LeaveIfError(iWs.WindowGroupList(&iWgIds));
     
-    ///////////////////////////////////////////////////////////////////
-    // Optimization, no need to construct list if ALF is the only one
-    ///////////////////////////////////////////////////////////////////
+    // Remove all child window groups, promote parents to foremost child position
+    CollapseWindowGroupTree(inactiveSurfaces);
     
-    if (processIds.Count() == 1)
+#ifdef SYMBIAN_GRAPHICS_WSERV_QT_EFFECTS
+    TWsEvent event;
+    event.SetType(KGoomMemoryLowEvent); // naive
+
+    for (TInt i = inactiveSurfaces.Count()-1; i>=0; i--)
         {
-        RProcess process;
-        TInt err =  process.Open(processIds[0]);
-        if(!err)
-            {
-            TInt secureId = process.SecureId();
-            process.Close();
-            if(secureId == 0x10003B20) // magic, wserv 
-                {
-                processIds.Close();
-                TRACES("Only WServ using GFX mem, no need for app actions");
-                return;
-                }
-            }
+        iWs.SendEventToWindowGroup(inactiveSurfaces[i], event);
         }
         
-    // Refresh window group list
-    // get all window groups, with info about parents
-    TInt numGroups = iWs.NumWindowGroups(0);
-    iWgIds.ReserveL(numGroups);
-    User::LeaveIfError(iWs.WindowGroupList(0, &iWgIds));
-    
-    // Remove all child window groups, promote parents to foremost child position
-    CollapseWindowGroupTree();
+#endif    
     
     // Note the current foreground window ID (if there is one)
     TBool oldForegroundWindowExists = EFalse;
@@ -222,11 +250,11 @@
     while (index--)
         {
         //Remove if process is not in list of processes using gfx mem
-        TUint secureId = AppId(index,ETrue);
         TBool found = 0;
-        TInt i = 0;
+        TInt i = 0;    
         for(i = 0; i < processIds.Count(); i++)
             {
+            TUint secureId = AppId(index,ETrue);
             RProcess process;
             TInt er =  process.Open(processIds[i]);
             if(er != KErrNone)
@@ -246,44 +274,31 @@
                 }
             process.Close();
             }
+        TRACES1("Checking WG ID : %d", iWgIds[index].iId);             
+        for(TInt ii = 0; ii < inactiveSurfaces.Count(); ii++)
+           {
+            if (iWgIds[index].iId == inactiveSurfaces[ii] )
+               {
+               AppId(index,EFalse); // update iWgName for found only 
+               found = ETrue;
+               TRACES2("Found %d isSystem: %d",inactiveSurfaces[ii], iWgName->IsSystem())            
+               }     
+            }
         
-        if(!found)
+        if(!found || iWgName->IsSystem())
             {
             iWgIds.Remove(index);
             continue;
             }
-      
-        //check if it is system app
-        if(iWgName->IsSystem() /*|| iWgName->Hidden()*/)
-            {
-            TRACES3("System/Hidden app found %x, ISystem %d, IsHidden %d",secureId, iWgName->IsSystem()?1:0, iWgName->Hidden()?1:0);  
-            systemProcessIds.Append(secureId);
-            }
-      
         }
-       
-    processIds.Close();
+		
+    
+	processIds.Close();
     privMemUsed.Close();      
     
-    //check if any system apps are included
     index = iWgIds.Count();
     while (index--)
         {
-        TBool skipped = EFalse;
-        for(i = 0; i < systemProcessIds.Count(); i++)
-            {
-            if(AppId(index,ETrue) == systemProcessIds[i])
-                {
-                TRACES2("WgId %d belongs to system app %x. Removing from Kill List",iWgIds[index].iId, systemProcessIds[i]);
-                iWgIds.Remove(index);
-                skipped = ETrue;
-                break;
-                }
-            }
-        
-        if(skipped)
-            continue;
-        
         // See if there is a tick count entry for each window in the list
         TGOomWindowGroupProperties* wgProperties = iWgToPropertiesMapping.Find(iWgIds[index].iId);
         
@@ -295,9 +310,7 @@
             iWgToPropertiesMapping.InsertL(iWgIds[index].iId, wgProperties);
             }
         }
-    
-    systemProcessIds.Close();
-    
+    TRACES1("Number of applications using graphics mem: %d", iWgIds.Count());    
     }
 
 
@@ -417,7 +430,7 @@
   
 
 
-void CGOomWindowGroupList::CollapseWindowGroupTree()
+void CGOomWindowGroupList::CollapseWindowGroupTree(RArray<TInt>& aWgsHavingSurfaces)
     {
     FUNC_LOG;
 
@@ -430,6 +443,23 @@
             // Look for the parent position
             TInt parentPos = ii;        // use child pos as not-found signal
             TInt count = iWgIds.Count();
+            
+            for (TInt kk = aWgsHavingSurfaces.Count()-1; kk >=0; kk--)
+                {
+                if (aWgsHavingSurfaces[kk] ==info.iId && aWgsHavingSurfaces.Find(info.iParentId) == KErrNotFound )
+                    { // replace child if with parent ID    
+					aWgsHavingSurfaces.Append(info.iParentId);
+					ii=-1; // need to start all over again
+                    break;
+                    }
+                }
+				
+			if (ii == -1)
+				{
+				ii++;
+				continue;	
+				}
+				
             for (TInt jj=0; jj<count; jj++)
                 {
                 if (iWgIds[jj].iId == info.iParentId)
@@ -505,6 +535,8 @@
     iWgToPropertiesMapping.Close();
     iExistingWindowIds.Close();
     delete iWgName;
+    iAlfClient.Close();
+    iLowOnMemWgs.Close();
     }