Revision: 201025
authorDremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Tue, 06 Jul 2010 15:18:10 +0300
changeset 43 95d73125a086
parent 42 b80cfcbd075a
child 45 c1d3b75cab24
child 48 7ced047fb7ae
Revision: 201025 Kit: 2010127
uiacceltk/hitchcock/ServerCore/Src/alfbridge.cpp
uiacceltk/hitchcock/coretoolkit/rendervg10/src/HuiVg10Texture.cpp
uiacceltk/hitchcock/goommonitor/data/goomconfig.xml
uiacceltk/hitchcock/goommonitor/inc/goomactionlist.h
uiacceltk/hitchcock/goommonitor/inc/goomactionref.h
uiacceltk/hitchcock/goommonitor/inc/goomcloseapp.h
uiacceltk/hitchcock/goommonitor/inc/goommemorymonitor.h
uiacceltk/hitchcock/goommonitor/inc/goomwindowgrouplist.h
uiacceltk/hitchcock/goommonitor/src/goomactionlist.cpp
uiacceltk/hitchcock/goommonitor/src/goomactionref.cpp
uiacceltk/hitchcock/goommonitor/src/goomcloseapp.cpp
uiacceltk/hitchcock/goommonitor/src/goommemorymonitor.cpp
uiacceltk/hitchcock/goommonitor/src/goommemorymonitorsession.cpp
uiacceltk/hitchcock/goommonitor/src/goomwindowgrouplist.cpp
--- a/uiacceltk/hitchcock/ServerCore/Src/alfbridge.cpp	Wed Jun 23 19:14:05 2010 +0300
+++ b/uiacceltk/hitchcock/ServerCore/Src/alfbridge.cpp	Tue Jul 06 15:18:10 2010 +0300
@@ -2718,7 +2718,7 @@
                     viz = CHuiCanvasVisual::AddNewL(control, layout);
 				    }
 
-				__ALFFXLOGSTRING2("CAlfBridge::HandleNewWindowL visual: 0x%x, id 0x%x", viz, windowNodeId);
+				__ALFFXLOGSTRING3("CAlfBridge::HandleNewWindowL visual: 0x%x, id 0x%x, Owner group Uid: 0x%x", viz, windowNodeId, viz->Owner().ControlGroup()->SecureId());
 				AddVisual( 
 				    windowNodeId, 
 					windowAttributes->iClientHandle, 
@@ -3430,7 +3430,7 @@
 #ifdef	USE_APPLICATION_ENDFULLSCREEN_TIMEOUT	
 	    if (iFSFxData
 	            && iFSFxData->iEffectType != CFullScreenEffectState::ENotDefinedEffect 
-	            && ((iFSFxData->State() == EWaitEndFullScreen && iFSFxData->iTwoPhaseEffect <= CFullScreenEffectState::EFirstPartRunning)))
+	            && ((iFSFxData->State() == EWaitEndFullScreen && iFSFxData->iTwoPhaseEffect <= CFullScreenEffectState::ESecondPartActive)))
 	        {
 	        CHuiControlGroup *to_group = NULL;
             if (iFSFxData->iEffectType == CFullScreenEffectState::EExitEffect)
@@ -4892,7 +4892,7 @@
     if (aLayout)
         {
 		TRAPD(err, StoreRenderBufferStartL(aLayout));
-		__ALFFXLOGSTRING2("CAlfBridge::FreezeLayoutUntilEffectDestroyed - StoreRenderBufferStartL call returned: %d for layout 0x%x", err, aLayout);
+		__ALFFXLOGSTRING3("CAlfBridge::FreezeLayoutUntilEffectDestroyed - Storing SecureId x%x, StoreRenderBufferStartL call returned: %d for layout 0x%x", aLayout->Owner().ControlGroup()->SecureId(), err, aLayout);
 		if (err == KErrNone)
 			{
             // Freeze only, if buffer was reserved succesfully 
@@ -6910,6 +6910,13 @@
             continue;
             }
 
+        if (controlgroup.ResourceId() == iAlfWindowGroupNodeId)
+            {
+            // ALF window doesn't have drawing and it's meant to be completely semitransparent,
+            // so skip.
+            continue;
+            }
+
         CHuiCanvasVisual* layout = (CHuiCanvasVisual*)&control.Visual(0);
         
         // For optimization reasons, check if all visuals below in Z-order are covered    
--- a/uiacceltk/hitchcock/coretoolkit/rendervg10/src/HuiVg10Texture.cpp	Wed Jun 23 19:14:05 2010 +0300
+++ b/uiacceltk/hitchcock/coretoolkit/rendervg10/src/HuiVg10Texture.cpp	Tue Jul 06 15:18:10 2010 +0300
@@ -1387,6 +1387,7 @@
             else
                 aNvgEngine->DrawNvg(GetNvgDataWithoutHeader(aNVGData), size, NULL, NULL);
             }
+#ifndef __WINS__
         // assume 32bpp for the icon, don't cache if it's too large
         TInt bitmapBytes = aDestSize.iWidth*aDestSize.iHeight*4;
         if (bitmapBytes < 128*128*4)
@@ -1416,6 +1417,7 @@
                 delete rasterizedIcon;
                 }
             }
+#endif
         }
 
     // restore the old surface before restoring original modes
--- a/uiacceltk/hitchcock/goommonitor/data/goomconfig.xml	Wed Jun 23 19:14:05 2010 +0300
+++ b/uiacceltk/hitchcock/goommonitor/data/goomconfig.xml	Tue Jul 06 15:18:10 2010 +0300
@@ -36,8 +36,8 @@
   <app uid="101F857A" low_ram_threshold="1000" good_ram_threshold="30000" skip_plugin="2002B3AE" icon_cache="0" use_sw_rend="Yes"></app> <!-- Camera --> 
   <app uid="200159B2" low_ram_threshold="5000" good_ram_threshold="10000" skip_plugin="2002B3AE"></app> <!-- MPlayer -->
   <app uid="102824CD" low_ram_threshold="5000" good_ram_threshold="10000" skip_plugin="2002B3AE"></app> <!-- Embedded mplayer -->
-  <app uid="200009EE" low_ram_threshold="3637" good_ram_threshold="10000" target_free_on_startup="15000"></app> <!-- Photos -->
-  <app uid="101FD693" low_ram_threshold="5000" good_ram_threshold="10000" target_free_on_startup="26000"></app> <!-- Flashlite -->
+  <app uid="200009EE" low_ram_threshold="3637" good_ram_threshold="10000" target_free_on_startup="10000"></app> <!-- Photos -->
+  <app uid="101FD693" low_ram_threshold="5000" good_ram_threshold="10000" skip_plugin="2002C30A" target_free_on_startup="26000"></app> <!-- Flashlite -->
 
 	</app_specific_thresholds>
 
--- a/uiacceltk/hitchcock/goommonitor/inc/goomactionlist.h	Wed Jun 23 19:14:05 2010 +0300
+++ b/uiacceltk/hitchcock/goommonitor/inc/goomactionlist.h	Tue Jul 06 15:18:10 2010 +0300
@@ -263,10 +263,11 @@
     TBool iRunningKillAppActions;
     
     TUint iCurrentPluginRun;
-    RArray<TInt> iLowOnMemWgs;
+//    RArray<TInt> iLowOnMemWgs;
     TBool iUseSwRendering;
     TBool iTryOptional; // we did everything we could but still missing some bits, try again with different app targets
     TBool iOptionalTried; // no need to overperform though
+    TUint iAppIndex;
     };
 
 #include "goomactionlist.inl"
--- a/uiacceltk/hitchcock/goommonitor/inc/goomactionref.h	Wed Jun 23 19:14:05 2010 +0300
+++ b/uiacceltk/hitchcock/goommonitor/inc/goomactionref.h	Tue Jul 06 15:18:10 2010 +0300
@@ -23,6 +23,7 @@
 #include "goomactionconfig.h"
 
 class CGOomRunPlugin;
+class CGOomAction;
 
 /**
  *  Encapsulates a reference to an action. 
@@ -61,6 +62,7 @@
     CGOomRunPlugin& RunPlugin();
     TInt CloseTimeout() const;
     TInt WaitAfterClose() const;
+    TBool IsRunning();
 
 private: //data
     
@@ -73,6 +75,8 @@
     CGOomRunPlugin* iRunPlugin; //For Plugins. Not owned
     TInt iCloseTimeout; //For AppClose
     TInt iWaitAfterClose; //For AppClose
+public:
+    CGOomAction* iAppPlugin; // because of stupid desing, not owned
     };
 
 #endif /*GOOMACTIONREF_H_*/
--- a/uiacceltk/hitchcock/goommonitor/inc/goomcloseapp.h	Wed Jun 23 19:14:05 2010 +0300
+++ b/uiacceltk/hitchcock/goommonitor/inc/goomcloseapp.h	Tue Jul 06 15:18:10 2010 +0300
@@ -71,6 +71,10 @@
 
     inline TUint WgId() const;
     
+    
+    /** Ask nice */
+    void ConditionalClose();
+    
     /** When the gentle push is not enough (i.e. force is required) **/
     void KillTask();
     
@@ -100,6 +104,8 @@
      * Own
      */
     CGOomAppCloseWatcher* iAppCloseWatcher; 
+    
+    TBool iAlreadyGaveUp;
     };
 
 #include "goomcloseapp.inl"
--- a/uiacceltk/hitchcock/goommonitor/inc/goommemorymonitor.h	Wed Jun 23 19:14:05 2010 +0300
+++ b/uiacceltk/hitchcock/goommonitor/inc/goommemorymonitor.h	Tue Jul 06 15:18:10 2010 +0300
@@ -27,6 +27,8 @@
 #include "goomwindowgrouplist.h"
 #include "goomtraces.h"
 
+#define ALWAYS_SW_REND 0	//enable only for testing purpose - will force sw rendering no matter what
+
 // ---------------------------------------------------------
 // CMemoryMonitor
 // ---------------------------------------------------------
@@ -56,6 +58,12 @@
             EGOomTriggerRequestMemory,
             EGOomTriggerThresholdCrossed
             };
+    
+    enum TGOomMemMode
+        {
+        EGOomGoodMemMode = 0,
+        EGOomLowMemMode
+        };
 
 public: // event handlers
     void FreeMemThresholdCrossedL(TInt aAction = 0, TInt aThreshold = 0);
@@ -91,9 +99,10 @@
     void SessionInCriticalAllocation(TBool aPostponeMemGood, TUint aClientId)
         {
         FUNC_LOG;
+        TInt oldCount = iClientsRequestingMemory.Count();
+        
         if (aPostponeMemGood)
             {
-            iPostponeMemGood++;
             if(iClientsRequestingMemory.Find(aClientId) == KErrNotFound)
                 iClientsRequestingMemory.Append(aClientId);
             
@@ -101,21 +110,20 @@
             }
         else
             {
-            iPostponeMemGood--;
+            if(aClientId == 0)
+                {
+                iClientsRequestingMemory.Reset();
+                }
+            
             TInt idx = iClientsRequestingMemory.Find(aClientId);
             if(idx != KErrNotFound)
                 {
                 iClientsRequestingMemory.Remove(idx);
                 TRACES2("SessionInCriticalAllocation : ENDING Critical Allocations for Client %x, ClientsRequestingMemory Count %d", aClientId, iClientsRequestingMemory.Count());
                 }
-            
-             if(iPostponeMemGood<0)
-                {
-                iPostponeMemGood = 0;
-                }
             }
         TRACES1("SessionInCriticalAllocation : ClientsRequestingMemory Count %d", iClientsRequestingMemory.Count());    
-        if (iClientsRequestingMemory.Count() == 0)
+        if (oldCount && iClientsRequestingMemory.Count() == 0)
             {
             DoPostponedMemoryGood();
             }
@@ -126,13 +134,14 @@
     
     TBool NeedToPostponeMemGood()
         {
-        //return (iPostponeMemGood != 0);
         return (iClientsRequestingMemory.Count() != 0);
         } 
     
     void WaitAndSynchroniseMemoryState();
     void SynchroniseMemoryState();
     
+    void SwitchMemMode(TGOomMemMode aMemMode);
+    
 private:
     CMemoryMonitor();
     void ConstructL();
@@ -201,13 +210,19 @@
     CGoomThresholdCrossed* iMemAllocationsGoingDown;
     
     TInt iForegroundAppUid;
-    TInt iPostponeMemGood;
     
     RArray<TUint> iClientsRequestingMemory;
     
     TGOomTrigger iTrigger;
     
     CGOomSynchTimer* iSynchTimer;
+    
+    TBool iMemMode;
+    TBool iForegroundAppHasChanged;
+    
+    TInt iRendswitched;
+    
+    RArray<TInt> iLowOnMemWgs;
     };
 
 
--- a/uiacceltk/hitchcock/goommonitor/inc/goomwindowgrouplist.h	Wed Jun 23 19:14:05 2010 +0300
+++ b/uiacceltk/hitchcock/goommonitor/inc/goomwindowgrouplist.h	Tue Jul 06 15:18:10 2010 +0300
@@ -78,7 +78,7 @@
     
     // Find all the windowgroups in the list that matches application id for this window group
     void GetAllWgIdsMatchingAppId(TInt aWgId, RArray<TInt> & WgIdList) const;
-
+/*
     TInt LowOnMemWgs(TInt aIndex) 
         {
         if (aIndex >= iLowOnMemWgs.Count() || aIndex < 0)
@@ -90,9 +90,11 @@
             return iLowOnMemWgs[aIndex];
             }
         }
-
+*/
     TInt FindParentIdL(TInt aWgId);    
     
+    void GetListOfWindowGroupsWSurfaces(RArray<TInt>& aLowOnMemWgs);
+    
 private:    
 
     void CollapseWindowGroupTree(RArray<TInt>& aWgsHavingSurfaces);
--- a/uiacceltk/hitchcock/goommonitor/src/goomactionlist.cpp	Wed Jun 23 19:14:05 2010 +0300
+++ b/uiacceltk/hitchcock/goommonitor/src/goomactionlist.cpp	Tue Jul 06 15:18:10 2010 +0300
@@ -214,11 +214,12 @@
     {
     FUNC_LOG;
     
-//    iActionRefs.Reset();
-//    iCurrentActionIndex = 0;
+    // we can't reset action index here because plugins would miss memory good events
+
+    iAppIndex = 0;
     
     aWindowGroupList.RefreshL(iTryOptional);
-    
+/*    
     for (TInt i = 0; aWindowGroupList.LowOnMemWgs(i) != KErrNotFound ; i++ )
         {
         if ( iLowOnMemWgs.Find(aWindowGroupList.LowOnMemWgs(i)) == KErrNotFound)
@@ -226,7 +227,7 @@
             iLowOnMemWgs.Append(aWindowGroupList.LowOnMemWgs(i));    
             }
         }
-        
+*/        
     iRunningKillAppActions = ETrue;
     
     if (aWindowGroupList.Count())
@@ -303,6 +304,7 @@
                     TInt err = iActionRefs.InsertInOrder(ref, ComparePriorities);
                     if ((err != KErrNone) && (err != KErrAlreadyExists))
                         {
+                        TRACES3("BuildActionListL: Adding app to action list, Uid = %x, wgId = %d, err = %d", appId, wgId, err);
                         User::Leave(err);
                         }
                     TRACES3("BuildActionListL: Adding app to action list, Uid = %x, wgId = %d, wgIndex = %d", appId, wgId, wgIndex);
@@ -352,18 +354,22 @@
         
         TActionRef ref = iActionRefs[iCurrentActionIndex];
         CGOomAction* action = NULL;
-        if (ref.Type() == TActionRef::EAppClose)
-            {
-            action = iCloseAppActions[numberOfRunningActions];
+        if (ref.Type() == TActionRef::EAppClose )
+            {     
+            iAppIndex%=iCloseAppActions.Count();
+            TRACES2("Proceeding with app action from index %d, out of %d", iAppIndex, iCloseAppActions.Count() );
+            action = iCloseAppActions[iAppIndex];
+            iAppIndex++;
             static_cast<CGOomCloseApp*>(action)->Reconfigure(ref);
             
+            ref.iAppPlugin = action;
+            
             //Double checking again if this app is now in foreground, if yes then we dont kill
             CApaWindowGroupName* wgName = CApaWindowGroupName::NewLC(iWs, iWs.GetFocusWindowGroup());
             
             TInt32 fgApp = wgName->AppUid().iUid;
             TInt32 appId = iMonitor.GetWindowGroupList()->AppIdfromWgId(ref.WgId(), ETrue);
-            
-            
+                  
             if(appId == fgApp)
                 {
                 TRACES1("Foreground App wgid %x, spared by GOOM", appId);
@@ -402,7 +408,15 @@
             if(spared)
                 {
                 iCurrentActionIndex++;
-                continue;
+                if (iCurrentActionIndex >= iActionRefs.Count())
+                    {
+                    StateChanged();
+                    return;
+                    }
+                else
+                    {    
+                    continue;
+                    }
                 }
             }
         else
@@ -471,8 +485,8 @@
             {
             iTryOptional = EFalse;
             iOptionalTried = EFalse;
-
             TRACES("CGOomActionList::FreeMemory: No usable memory freeing action has been found");
+            iFreeingMemory = EFalse;
             iServer.CloseAppsFinished(freeMemory, EFalse);
             iMonitor.WaitAndSynchroniseMemoryState();
             }
@@ -484,7 +498,8 @@
 void CGOomActionList::MemoryGood()
     {
     FUNC_LOG;
-
+    if(!ALWAYS_SW_REND)
+        {
     TInt actionRefIndex = iActionRefs.Count();
 
     // Go through each of the action references, if it's a plugin action then call MemoryGood on it
@@ -497,7 +512,10 @@
             iActionRefs[actionRefIndex].RunPlugin().MemoryGood();
             }
         }
-    // notify window groups which were triggered to low mem that 
+    // notify window groups which were triggered to low mem that
+    iMonitor.SwitchMemMode(CMemoryMonitor::EGOomGoodMemMode);
+        }
+/*    
     TWsEvent event;
     event.SetType(KGoomMemoryGoodEvent); // naive
 
@@ -507,7 +525,8 @@
         iWs.SendEventToWindowGroup(iLowOnMemWgs[i], event);
 #endif // #ifdef SYMBIAN_GRAPHICS_WSERV_QT_EFFECTS
         iLowOnMemWgs.Remove(i);
-		}    
+		}
+*/		    
     }
 
 TBool CGOomActionList::FreeMemoryAboveTarget(TInt& aFreeMemory)
@@ -612,9 +631,13 @@
     FUNC_LOG;
 
     TInt index = iCloseAppActions.Count();
+    TRACES1("CGOomCloseApp::AppNotExiting: count of actions %d",index);
+
     while (index--)
         {
         CGOomCloseApp* action = iCloseAppActions[index];
+        TRACES3("CGOomCloseApp::AppNotExiting: %d %d %d", aWgId, action->WgId(), action->IsRunning());
+        
         if ( (action->WgId() == aWgId) && (action->IsRunning()) )
             {
             TRACES1("CGOomCloseApp::AppNotExiting: App with window group id %d has not responded to the close event", aWgId);
@@ -631,23 +654,12 @@
 
     TBool allActionsComplete = ETrue;
 
-    // Note that the actions themselves are responsible for timing out if necessary.
-    TInt index = iCloseAppActions.Count();
-    while ((index--) && (allActionsComplete))
+    TInt index = iActionRefs.Count();
+	while ((index--) && (allActionsComplete))
         {
-        if (iCloseAppActions[index]->IsRunning())
+        if (iActionRefs[index].IsRunning())
             {
-            TRACES1("CGOomActionList::StateChanged. CloseAppAction %d STILL RUNNING. PROBLEM !!! YOU SHOULD NEVER SEE THIS", index);
-            allActionsComplete = EFalse;
-            }
-        }
-
-    index = iRunPluginActions.Count();
-    while ((index--) && (allActionsComplete))
-        {
-        if (iRunPluginActions[index]->IsRunning())
-            {
-            TRACES1("CGOomActionList::StateChanged. PluginAction %d STILL RUNNING. PROBLEM !!! YOU SHOULD NEVER SEE THIS", index);
+            TRACES1("CGOomActionList::StateChanged. Action %d STILL RUNNING.", index);
             allActionsComplete = EFalse;
             }
         }
@@ -665,59 +677,44 @@
             // If we are still below the good-memory-threshold then continue running actions
             {            
             TRACES2("CGOomActionList::StateChanged: Finished Action %d out of %d",iCurrentActionIndex, iActionRefs.Count());
-            
-            
-            if (iCurrentActionIndex >= iActionRefs.Count())
+
+            if (iCurrentActionIndex < iActionRefs.Count())
                 {
-                if(iRunningKillAppActions)
-                    {
-                    iRunningKillAppActions = EFalse;
-                    // There are no more actions to try, so we give up
-                    TRACES1("CGOomActionList::StateChanged: All current actions complete, below good threshold with no more actions available. freeMemory=%d", freeMemory);
-                    
-                    /* Do not call memory good immidiately after freeing memory for some app
-                    if (freeMemory >= iCurrentTarget && !iMonitor.NeedToPostponeMemGood())
-                    {                    
-                    MemoryGood();
-                    }
-                     */
-                    if (!iTryOptional && !iOptionalTried && freeMemory < 25*1024*1024 ) // magic, should read this from config
-                        { 
-                        iTryOptional = ETrue;
-                        iOptionalTried = EFalse;
-                        iMonitor.RunCloseAppActions(iMaxPriority);
-                        }
-                    else
-                        {
-                        iTryOptional = EFalse;       
-                        iServer.CloseAppsFinished(freeMemory, EFalse);
-                        iMonitor.WaitAndSynchroniseMemoryState();
-                        }
+                // There are still more actions to try, so we continue
+                TRACES1("CGOomActionList::StateChanged: All current actions complete, running more actions. freeMemory=%d", freeMemory);
+                return FreeMemory(iMaxPriority);
+                } 
+                                   
+            if(iRunningKillAppActions)
+	            {
+                iRunningKillAppActions = EFalse;
+
+                if (!iTryOptional && !iOptionalTried && freeMemory < 25*1024*1024 ) // magic, should read this from config
+                    { 
+                    iTryOptional = ETrue;
+                    iOptionalTried = ETrue;
+                    iMonitor.RunCloseAppActions(iMaxPriority);
                     }
                 else
                     {
-                    TRACES1("CGOomActionList::StateChanged: All current Plugin actions complete, below good threshold, Time to kill bad guys. freeMemory=%d", freeMemory);
-                    iRunningKillAppActions = ETrue;
-                    iMonitor.RunCloseAppActions(iMaxPriority);
+                    // There are no more actions to try, so we give up
+                    TRACES1("CGOomActionList::StateChanged: All current actions complete, below good threshold with no more actions available. freeMemory=%d", freeMemory);
+                    iTryOptional = EFalse;       
+                    iServer.CloseAppsFinished(freeMemory, EFalse);
+                    iMonitor.WaitAndSynchroniseMemoryState();
                     }
-                
                 }
             else
                 {
-                // There are still more actions to try, so we continue
-                TRACES1("CGOomActionList::StateChanged: All current actions complete, running more actions. freeMemory=%d", freeMemory);
-                FreeMemory(iMaxPriority);
+                TRACES1("CGOomActionList::StateChanged: All current Plugin actions complete, below good threshold, Time to kill bad guys. freeMemory=%d", freeMemory);
+                iRunningKillAppActions = ETrue;
+                iMonitor.RunCloseAppActions(iMaxPriority);
                 }
+        
             }
         else
             {
             TRACES1("CGOomActionList::StateChanged: All current actions complete, memory good. freeMemory=%d", freeMemory);
-            /* Do not call memory good immidiately after freeing memory for some app
-			if(freeMemory > iMonitor.GetGoodThreshold() && !iMonitor.NeedToPostponeMemGood())
-                {
-                MemoryGood();
-                }
-            */
             iRunningKillAppActions = EFalse;
             iServer.CloseAppsFinished(freeMemory, ETrue);
             iMonitor.WaitAndSynchroniseMemoryState();
--- a/uiacceltk/hitchcock/goommonitor/src/goomactionref.cpp	Wed Jun 23 19:14:05 2010 +0300
+++ b/uiacceltk/hitchcock/goommonitor/src/goomactionref.cpp	Tue Jul 06 15:18:10 2010 +0300
@@ -17,14 +17,15 @@
 
 
 #include "goomactionref.h"
+#include "goomrunplugin.h"
 
 TActionRef::TActionRef(TActionType aType, TInt aPriority, TGOomSyncMode aSyncMode, TInt aRamEstimate, CGOomRunPlugin& aRunPlugin, TUint aWgIndexOfTargetApp)
-    : iType(aType), iPriority(aPriority), iSyncMode(aSyncMode), iRamEstimate(aRamEstimate), iWgIndex(aWgIndexOfTargetApp), iRunPlugin(&aRunPlugin)
+    : iType(aType), iPriority(aPriority), iSyncMode(aSyncMode), iRamEstimate(aRamEstimate), iWgIndex(aWgIndexOfTargetApp), iRunPlugin(&aRunPlugin), iAppPlugin(0)
     {   
     }
 
 TActionRef::TActionRef(TActionType aType, TInt aPriority, TGOomSyncMode aSyncMode, TInt aRamEstimate, TInt aWgId, TUint aWgIndex, TInt aCloseTimeout, TInt aWaitAfterClose)
-: iType(aType), iPriority(aPriority), iSyncMode(aSyncMode), iRamEstimate(aRamEstimate), iWgId(aWgId), iWgIndex(aWgIndex), iRunPlugin(NULL), iCloseTimeout(aCloseTimeout), iWaitAfterClose(aWaitAfterClose)
+: iType(aType), iPriority(aPriority), iSyncMode(aSyncMode), iRamEstimate(aRamEstimate), iWgId(aWgId), iWgIndex(aWgIndex), iRunPlugin(NULL), iCloseTimeout(aCloseTimeout), iWaitAfterClose(aWaitAfterClose), iAppPlugin(0)
     {   
     }
 
@@ -78,3 +79,16 @@
     {
     return *iRunPlugin;
     }
+
+TBool TActionRef::IsRunning()
+    {
+    if (iRunPlugin)
+        {
+        return iRunPlugin->IsRunning();
+        }
+    else if (iAppPlugin)
+        {
+        return iAppPlugin->IsRunning();
+        }
+    return EFalse;
+    }         
--- a/uiacceltk/hitchcock/goommonitor/src/goomcloseapp.cpp	Wed Jun 23 19:14:05 2010 +0300
+++ b/uiacceltk/hitchcock/goommonitor/src/goomcloseapp.cpp	Tue Jul 06 15:18:10 2010 +0300
@@ -18,6 +18,8 @@
 
 #include <apgtask.h>
 
+#include "goommemorymonitor.h"
+#include "goomwindowgrouplist.h"
 #include "goomcloseapp.h"
 #include "goomtraces.h"
 #include "goomappclosetimer.h"
@@ -42,18 +44,38 @@
     {
     FUNC_LOG;
 
+    if ( iAlreadyGaveUp )	//will this ever be true ??? iAlredyGaveup is set true in closeAppEvent, which is called only if app gets notified by goom, which happens only after this
+        {
+        if (iAppCloseTimer)
+        	{
+			iAppCloseTimer->Cancel();
+    		}
+			
+    	if (iAppCloseWatcher)
+        	{
+			iAppCloseWatcher->Cancel();
+			}
+			
+		RDebug::Printf("GOOM: I should not activate actions for app that already refused to exit !!!!");
+        MemoryFreed(KErrNone);
+        return;
+        }    
+
     iAppCloserRunning = ETrue;
     
     // Set the TApaTask to the app
     iCurrentTask.SetWgId(iWgId);
     
     // Start a timer and the thread watcher 
-    iAppCloseTimer->SetState(CGOomAppCloseTimer::EGOomAppClosing);
+    /*
+	iAppCloseTimer->SetState(CGOomAppCloseTimer::EGOomAppClosing);
     iAppCloseTimer->After(iCloseTimeout * 1000);
     iAppCloseWatcher->Start(iCurrentTask);
     // Tell the app to close
     TRACES2("CGOomCloseApp::FreeMemory: Closing app with window group id %d Timeout = %d",iWgId, iCloseTimeout);
     iCurrentTask.EndTask();
+	*/
+	ConditionalClose();
     }
 
 CGOomCloseApp::~CGOomCloseApp()
@@ -77,19 +99,19 @@
 
     // The application has closed (or we have a timeout)
     iAppCloserRunning = EFalse;
+    iAlreadyGaveUp = ETrue;
     
     if (iAppCloseTimer)
         {
-            iAppCloseTimer->Cancel();
-            iAppCloseTimer->SetState(CGOomAppCloseTimer::EGOomAppKilled);
-            iAppCloseTimer->After(iWaitAfterClose * 1000);
+        iAppCloseTimer->Cancel();
+        iAppCloseTimer->SetState(CGOomAppCloseTimer::EGOomAppKilled);
+        iAppCloseTimer->After(iWaitAfterClose * 1000);
         }
     
     if (iAppCloseWatcher)
+        {
         iAppCloseWatcher->Cancel(); 
-    
-    
-    //MemoryFreed(KErrNone);
+        }    
     }
 
 void CGOomCloseApp::Reconfigure(const TActionRef& aRef)
@@ -99,6 +121,7 @@
     iWgId = aRef.WgId();    
     iCloseTimeout = aRef.CloseTimeout();
     iWaitAfterClose = aRef.WaitAfterClose();
+	iAlreadyGaveUp = EFalse;
     }
 
 void CGOomCloseApp::ConstructL()
@@ -115,6 +138,38 @@
     FUNC_LOG;
     }
 
+TBool IsConsumingMemory(TInt aWgId)
+    {
+    FUNC_LOG;
+    // Something more efficient could be done here
+    CMemoryMonitor* globalMemoryMonitor = static_cast<CMemoryMonitor*>(Dll::Tls());
+    globalMemoryMonitor->GetWindowGroupList()->Refresh();
+    return (globalMemoryMonitor->GetWindowGroupList()->GetIndexFromWgId(aWgId) != KErrNotFound);
+    }    
+    
+void CGOomCloseApp::ConditionalClose()
+    {
+    FUNC_LOG;
+    // Start a timer and the thread watcher 
+    iAppCloseTimer->SetState(CGOomAppCloseTimer::EGOomAppClosing);
+    iAppCloseTimer->After(iCloseTimeout * 1000);
+    // Tell the app to close
+	// We are not asking system applications to exit anyway, so we'll send legacy event only
+	// even we have powermgmt capability 
+    TRACES2("CGOomCloseApp::FreeMemory: Closing app with window group id %d Timeout = %d",iWgId, iCloseTimeout);
+	TWsEvent event;
+	event.SetType(EEventUser);
+	TInt* eventData = (TInt*)(event.EventData());
+	*eventData = EApaSystemEventShutdown;
+	eventData++;
+	*eventData = KGoomMemoryLowEvent;
+	
+	// should proxy the session..
+    CMemoryMonitor* globalMemoryMonitor = static_cast<CMemoryMonitor*>(Dll::Tls());
+    globalMemoryMonitor->iWs.SendEventToWindowGroup(iWgId, event);
+    }    
+
+
 // ----------------------------------------------
 // Callback from iAppCloseTimer
 // App refused to exit gracefully on given time
@@ -127,12 +182,18 @@
         {
         iAppCloseWatcher->Cancel(); 
         }
-    
-    iCurrentTask.KillTask();
-    iAppCloserRunning = EFalse;
-    
-    iAppCloseTimer->SetState(CGOomAppCloseTimer::EGOomAppKilled);
-    iAppCloseTimer->After(iWaitAfterClose * 1000);
+        
+    if(IsConsumingMemory(iWgId))    
+        {    
+        iCurrentTask.KillTask();
+        iAppCloserRunning = EFalse; // not sure if intended (?)
+        iAppCloseTimer->SetState(CGOomAppCloseTimer::EGOomAppKilled);
+        iAppCloseTimer->After(iWaitAfterClose * 1000);
+        }
+    else
+        { // application has released its graphics resources -> we are no more interested about it
+        CloseAppEvent();
+        }    
     //MemoryFreed(KErrNone);
     }
 
--- a/uiacceltk/hitchcock/goommonitor/src/goommemorymonitor.cpp	Wed Jun 23 19:14:05 2010 +0300
+++ b/uiacceltk/hitchcock/goommonitor/src/goommemorymonitor.cpp	Tue Jul 06 15:18:10 2010 +0300
@@ -102,6 +102,8 @@
 #ifdef _DEBUG
     delete iLogger;
 #endif
+    
+    iClientsRequestingMemory.Close();
     }
 
 // ---------------------------------------------------------
@@ -231,8 +233,12 @@
         TRACES1("FreeMemThresholdCrossedL : crossed low threshold %d", iLowThreshold);
         iMemAllocationsGrowing->Stop();
         iMemAllocationsGoingDown->Continue();
-        if((iTrigger == EGOomTriggerNone) && !NeedToPostponeMemGood() && !iSynchTimer->IsActive() )
+        if((iTrigger == EGOomTriggerNone) && !NeedToPostponeMemGood())
+            {
+            if(iSynchTimer->IsActive())
+                iSynchTimer->Cancel();
             StartFreeSomeRamL(iGoodThreshold, EGOomTriggerThresholdCrossed);
+            }
         }
 #endif
     }
@@ -252,7 +258,7 @@
     // Refresh the low and good memory thresholds as they may have changed due to the new foreground application
     RefreshThresholds(aForegroundAppUid);
     
-    if(iCurrentTarget)
+    if(iCurrentTarget || ALWAYS_SW_REND)
         {
         StartFreeSomeRamL(iCurrentTarget, EGOomTriggerFocusChanged);
         }
@@ -275,6 +281,13 @@
 
     TRACES2("MemoryMonitor::StartFreeSomeRamL freeMemoryAboveTarget = %d, freeMemory = %d", freeMemoryAboveCurrentTarget, freeMemory);
 
+    if(ALWAYS_SW_REND)
+        {
+		if(iMemMode == EGOomLowMemMode)
+		return;
+		}
+	else
+		{
     if (freeMemoryAboveCurrentTarget)
         {
         /*if(freeMemory >= iGoodThreshold && !NeedToPostponeMemGood())
@@ -282,14 +295,17 @@
                 iGOomActionList->MemoryGood();
             }
         */
-        if(!iGOomActionList->UseSwRendering())
+        if(!(iGOomActionList->UseSwRendering() && (iMemMode != EGOomLowMemMode)))
             {
             iServer->CloseAppsFinished(freeMemory, ETrue);
             WaitAndSynchroniseMemoryState();
-            return;
+            if(aTrigger == EGOomTriggerRequestMemory)
+                User::Leave(KErrCompletion);
+            else
+                return;
             }
         }
-
+        }
     // update wg list only when actually about to use it 
     //iGOomWindowGroupList->Refresh();
 
@@ -304,9 +320,40 @@
     iGOomActionList->SetCurrentTarget(iCurrentTarget);
 
     iTrigger = aTrigger;
+    
+    iGOomActionList->SetUseSwRendering(ETrue); //Always use SW rendering in low mode .. (for now..) 
     // Run the memory freeing actions
     iGOomActionList->FreeMemory(aMaxPriority);
     
+    SwitchMemMode(EGOomLowMemMode);
+    }
+
+void CMemoryMonitor::SwitchMemMode(TGOomMemMode aMemMode)
+    {
+    if(iMemMode == aMemMode)
+        return;
+
+#ifdef SYMBIAN_GRAPHICS_WSERV_QT_EFFECTS    
+    TWsEvent event;
+ 
+    if(aMemMode == EGOomLowMemMode)
+        {
+        iLowOnMemWgs.Reset();
+        iGOomWindowGroupList->GetListOfWindowGroupsWSurfaces(iLowOnMemWgs);
+        event.SetType(KGoomMemoryLowEvent);
+        }
+    else
+        {
+        event.SetType(KGoomMemoryGoodEvent);
+        }
+    
+    for (TInt i = iLowOnMemWgs.Count()-1; i>=0; i--)
+        {
+        iWs.SendEventToWindowGroup(iLowOnMemWgs[i], event);
+        }
+#endif
+    
+    iMemMode = aMemMode;
     }
 
 void CMemoryMonitor::RunCloseAppActions(TInt aMaxPriority)
@@ -736,7 +783,6 @@
             }
         }
     
-    TRACES1("Going to process new request %d",iPostponeMemGood);
     return ETrue;
     }
 
@@ -776,15 +822,9 @@
     TInt current = GetFreeMemory();
     if(current >= iGoodThreshold)
         {
-        if(!NeedToPostponeMemGood())
-            {
-            TRACES("SynchroniseMemoryState calling MemoryGOOD");
-            iGOomActionList->MemoryGood();
-            }
-        else
-            {
-            iMemAllocationsGoingDown->Continue();
-            }
+        iClientsRequestingMemory.Reset();
+        TRACES("SynchroniseMemoryState calling MemoryGOOD");
+        iGOomActionList->MemoryGood();
         }
     else if(current < iLowThreshold)
         {
--- a/uiacceltk/hitchcock/goommonitor/src/goommemorymonitorsession.cpp	Wed Jun 23 19:14:05 2010 +0300
+++ b/uiacceltk/hitchcock/goommonitor/src/goommemorymonitorsession.cpp	Tue Jul 06 15:18:10 2010 +0300
@@ -35,12 +35,7 @@
 CMemoryMonitorSession::~CMemoryMonitorSession()
     {
     FUNC_LOG;
-	/* TODO - need to add the right condition
-    if (iUseAbsoluteTargets)
-        { // se3ssion terminated while on critical allocation, release lock
-        Server().Monitor().SessionInCriticalAllocation(0);
-        }
-	*/
+    Server().Monitor().SessionInCriticalAllocation(0,0);
     CloseAppsFinished(0, EFalse);
     }
 
@@ -91,7 +86,12 @@
                 Server().Monitor().SessionInCriticalAllocation(1, clientId);
                 
                 TRAPD(err, Monitor().RequestFreeMemoryL(aMessage.Int0()));
-                if (err)
+                if(err == KErrCompletion) 
+                    {
+                    TRACES("There is already enough memory - nothing to do");
+                    Server().Monitor().SessionInCriticalAllocation(0, clientId);
+                    }
+                else if (err != KErrNone )
                     {
                     // completes the message if that was left to pending
                     TRACES1("Error in RequestFreeMemory %d", err);
--- a/uiacceltk/hitchcock/goommonitor/src/goomwindowgrouplist.cpp	Wed Jun 23 19:14:05 2010 +0300
+++ b/uiacceltk/hitchcock/goommonitor/src/goomwindowgrouplist.cpp	Tue Jul 06 15:18:10 2010 +0300
@@ -42,6 +42,18 @@
     FUNC_LOG;
     }
 
+void CGOomWindowGroupList::GetListOfWindowGroupsWSurfaces(RArray<TInt>& aLowOnMemWgs)
+    {
+    if (!iAlfClient.Handle())
+       {
+       if(iAlfClient.Connect() != KErrNone)
+           return;
+       }
+    
+    iAlfClient.GetListOfWindowGroupsWSurfaces(&aLowOnMemWgs);
+    }
+   
+
 // Update the list of window groups
 void CGOomWindowGroupList::Refresh(TBool aOptionalOnly)
     {
@@ -72,14 +84,14 @@
         {
         User::LeaveIfError(iAlfClient.Connect());
         }
-    iLowOnMemWgs.Reset();
+    //iLowOnMemWgs.Reset();
     RArray<TInt> inactiveSurfaces;
 
     // ignore possible errors, we have information from profiling extension anyway
     if (!aOptionalOnly)
         {
         iAlfClient.GetListOfInactiveWindowGroupsWSurfaces(&inactiveSurfaces);    
-        iAlfClient.GetListOfWindowGroupsWSurfaces(&iLowOnMemWgs);
+        //iAlfClient.GetListOfWindowGroupsWSurfaces(&iLowOnMemWgs);
         }
     else
         { // first iteration: try to cope with window group ID's only
@@ -233,7 +245,7 @@
     
     // Remove all child window groups, promote parents to foremost child position
     CollapseWindowGroupTree(inactiveSurfaces);
-    
+/*    
 #ifdef SYMBIAN_GRAPHICS_WSERV_QT_EFFECTS
     TWsEvent event;
     event.SetType(KGoomMemoryLowEvent); // naive
@@ -244,7 +256,7 @@
         }
         
 #endif    
-    
+*/    
     // Note the current foreground window ID (if there is one)
     TBool oldForegroundWindowExists = EFalse;