Revision: 201031 RCL_3
authorDremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Thu, 19 Aug 2010 10:48:02 +0300
branchRCL_3
changeset 18 1801340c26a2
parent 17 c9d868f1e20c
child 19 e5af45d51884
Revision: 201031 Kit: 201033
uiaccelerator_plat/alf_core_toolkit_api/inc/uiacceltk/HuiCanvasVisual.h
uiaccelerator_plat/alf_core_toolkit_api/inc/uiacceltk/HuiEnv.h
uiaccelerator_plat/alf_extended_visual_api/tsrc/group/alf_extended_visual_api.pkg
uiaccelerator_plat/alf_visual_api/inc/goommonitor/goommonitorplugin.hrh
uiaccelerator_plat/alf_visual_api/inc/goommonitor/goommonitorsession.h
uiacceltk/hitchcock/AlfDecoderServerClient/src/alfdecoderserverclient.cpp
uiacceltk/hitchcock/Client/src/alfdrawer.cpp
uiacceltk/hitchcock/CommonInc/alfbridgecommands.h
uiacceltk/hitchcock/ServerCore/Inc/alfbridge.h
uiacceltk/hitchcock/ServerCore/Inc/alfeffectutils.h
uiacceltk/hitchcock/ServerCore/Inc/alfnodes.h
uiacceltk/hitchcock/ServerCore/Inc/alfstreamerbridge.h
uiacceltk/hitchcock/ServerCore/Inc/alfwindow.h
uiacceltk/hitchcock/ServerCore/Inc/alfwindowdata.h
uiacceltk/hitchcock/ServerCore/Src/alfappservercore.mmp
uiacceltk/hitchcock/ServerCore/Src/alfappsrvsession.cpp
uiacceltk/hitchcock/ServerCore/Src/alfappsrvsessionBase.cpp
uiacceltk/hitchcock/ServerCore/Src/alfappui.cpp
uiacceltk/hitchcock/ServerCore/Src/alfbridge.cpp
uiacceltk/hitchcock/ServerCore/Src/alfeffectutils.cpp
uiacceltk/hitchcock/ServerCore/Src/alfnodes.cpp
uiacceltk/hitchcock/ServerCore/Src/alfstaticfactory.cpp
uiacceltk/hitchcock/ServerCore/Src/alfstreamerbridge.cpp
uiacceltk/hitchcock/ServerCore/Src/alfstreamerserver.cpp
uiacceltk/hitchcock/ServerCore/Src/alfwindow.cpp
uiacceltk/hitchcock/ServerCore/Src/alfwindowmanager.cpp
uiacceltk/hitchcock/coretoolkit/BWINS/hitchcocku.DEF
uiacceltk/hitchcock/coretoolkit/eabi/hitchcocku.DEF
uiacceltk/hitchcock/coretoolkit/inc/HuiFxFilterLayer.h
uiacceltk/hitchcock/coretoolkit/inc/HuiFxGroupLayer.h
uiacceltk/hitchcock/coretoolkit/inc/HuiFxLayer.h
uiacceltk/hitchcock/coretoolkit/inc/HuiFxVisualLayer.h
uiacceltk/hitchcock/coretoolkit/rendervg10/inc/HuiVg10RenderPlugin.h
uiacceltk/hitchcock/coretoolkit/rendervg10/src/HuiFxVg10Engine.cpp
uiacceltk/hitchcock/coretoolkit/rendervg10/src/HuiFxVg10OffscreenRenderbuffer.cpp
uiacceltk/hitchcock/coretoolkit/rendervg10/src/HuiVg10RenderPlugin.cpp
uiacceltk/hitchcock/coretoolkit/rendervg10/src/HuiVg10Texture.cpp
uiacceltk/hitchcock/coretoolkit/rendervg10/src/HuiVg10VGImageBinder.cpp
uiacceltk/hitchcock/coretoolkit/rendervg10/src/huivg10canvasrenderbuffer.cpp
uiacceltk/hitchcock/coretoolkit/src/HuiCanvasTextureCache.cpp
uiacceltk/hitchcock/coretoolkit/src/HuiCanvasVisual.cpp
uiacceltk/hitchcock/coretoolkit/src/HuiEnv.cpp
uiacceltk/hitchcock/coretoolkit/src/HuiFxEffect.cpp
uiacceltk/hitchcock/coretoolkit/src/HuiFxEffectParser.cpp
uiacceltk/hitchcock/coretoolkit/src/HuiFxFilterLayer.cpp
uiacceltk/hitchcock/coretoolkit/src/HuiFxGroupLayer.cpp
uiacceltk/hitchcock/coretoolkit/src/HuiFxLayer.cpp
uiacceltk/hitchcock/coretoolkit/src/HuiFxVisualLayer.cpp
uiacceltk/hitchcock/coretoolkit/src/HuiGridLayout.cpp
uiacceltk/hitchcock/coretoolkit/src/HuiImageVisual.cpp
uiacceltk/hitchcock/coretoolkit/src/HuiVisual.cpp
uiacceltk/hitchcock/coretoolkit/src/huicanvaswspainter.cpp
uiacceltk/hitchcock/goommonitor/data/goomconfig.xml
uiacceltk/hitchcock/goommonitor/inc/goommemorymonitorsession.h
uiacceltk/hitchcock/goommonitor/src/goomactionlist.cpp
uiacceltk/hitchcock/goommonitor/src/goomcloseapp.cpp
uiacceltk/hitchcock/goommonitor/src/goommemorymonitor.cpp
uiacceltk/hitchcock/goommonitor/src/goommemorymonitorsession.cpp
uiacceltk/hitchcock/goommonitor/src/goomrunplugin.cpp
uiacceltk/hitchcock/goommonitor/src/goomwindowgrouplist.cpp
uiacceltk/hitchcock/plugins/alfoogmplugin/src/alfoogmplugin.cpp
uiacceltk/hitchcock/plugins/alftranseffect/alftranseffectplugin/src/alfgfxeffects.cpp
uiacceltk/hitchcock/plugins/alftranseffect/alftranseffectplugin/src/alfserverdrawer.cpp
uiacceltk/hitchcock/plugins/alftranseffect/alftranseffectplugin/src/states.cpp
uiacceltk/hitchcock/plugins/alftranseffect/alftranseffectplugin/src/wsserverdrawercontroller.cpp
--- a/uiaccelerator_plat/alf_core_toolkit_api/inc/uiacceltk/HuiCanvasVisual.h	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiaccelerator_plat/alf_core_toolkit_api/inc/uiacceltk/HuiCanvasVisual.h	Thu Aug 19 10:48:02 2010 +0300
@@ -112,7 +112,9 @@
     /** Flag to indicate whether surface is visible (based on visibility calculation) */
     EHuiCanvasFlagSurfaceVisible = 0x800,
     /** Flag to indicate avkon clearer window. This needs to be drawn, but excluded in the heuristics determining application screen coverage */
-    EHuiCanvasFlagDistractionWindow = 0x1000
+    EHuiCanvasFlagDistractionWindow = 0x1000,
+    /** Flag to indicate that visual is not ready */
+    EHuiCanvasVisualFlagNotReady = 0x2000
     };
 
 /**
--- a/uiaccelerator_plat/alf_core_toolkit_api/inc/uiacceltk/HuiEnv.h	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiaccelerator_plat/alf_core_toolkit_api/inc/uiacceltk/HuiEnv.h	Thu Aug 19 10:48:02 2010 +0300
@@ -1006,6 +1006,9 @@
     IMPORT_C void NotifyMemoryLevel(THuiMemoryLevel aMemoryLevel);
     IMPORT_C THuiMemoryLevel MemoryLevel();
     
+    // This is for internally use only, tries to free any available cached resources alf may have reserved
+    IMPORT_C void HandleOutOfTextureMemory();
+    
     void DoSynchronize();
     TBool iPauseDrawing;
 private:
--- a/uiaccelerator_plat/alf_extended_visual_api/tsrc/group/alf_extended_visual_api.pkg	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiaccelerator_plat/alf_extended_visual_api/tsrc/group/alf_extended_visual_api.pkg	Thu Aug 19 10:48:02 2010 +0300
@@ -14,7 +14,7 @@
 ; Description: 
 ;
 
-;-----------------------------------------------------------------------------
+;-----------------------------------------------------------------------------
 ; Copyright © 2004, Digia Inc. All rights reserved. All other trademarks are
 ; the property of their respective owners.
 ;-----------------------------------------------------------------------------
--- a/uiaccelerator_plat/alf_visual_api/inc/goommonitor/goommonitorplugin.hrh	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiaccelerator_plat/alf_visual_api/inc/goommonitor/goommonitorplugin.hrh	Thu Aug 19 10:48:02 2010 +0300
@@ -25,8 +25,6 @@
 // Extension interface "uids"
 #define KGoomClientSecureId     0x1000
 
-// Goom Events through Window Server
-#define KGoomMemoryLowEvent 0x10282DBF
-#define KGoomMemoryGoodEvent 0x20026790
+
 
 #endif // GOOMMONITORPLUGIN_HRH
--- a/uiaccelerator_plat/alf_visual_api/inc/goommonitor/goommonitorsession.h	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiaccelerator_plat/alf_visual_api/inc/goommonitor/goommonitorsession.h	Thu Aug 19 10:48:02 2010 +0300
@@ -21,6 +21,10 @@
 
 #include <e32std.h>
 
+// Goom Events through Window Server
+#define KGoomMemoryLowEvent 0x10282DBF
+#define KGoomMemoryGoodEvent 0x20026790
+
 /**
  *  The maximum amount of memory that can be allocated without permission.
  */
--- a/uiacceltk/hitchcock/AlfDecoderServerClient/src/alfdecoderserverclient.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/AlfDecoderServerClient/src/alfdecoderserverclient.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -98,13 +98,21 @@
 	        }
 	    else
 	    	{
+            // Maximum heap size for alfredserver thread. 
+            // Emulator has smaller heap size in order not to cause memory issues.
+#ifdef __WINSCW__
+            const TInt KAlfServerMaxHeapSize = 10*1024*1024;
+#else
+            const TInt KAlfServerMaxHeapSize = 16*1024*1024;
+#endif
+
     	    RThread serverThread;
     	    User::LeaveIfError(serverThread.Create(
 	    	        KAlfServerThreadName,
 	    	        AlfThreadFucntion,
 	    	        16384, // magic
 	    	        4*1024*1024, // uses own heap for now
-	    	        10*1024*1024,
+	    	        KAlfServerMaxHeapSize,
 	    	        0,
 	    	        EOwnerThread));
 	    	    
--- a/uiacceltk/hitchcock/Client/src/alfdrawer.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/Client/src/alfdrawer.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -51,7 +51,7 @@
     TInt ReadPixels(CFbsBitmap* aBitmap);
 
 private:
-    RAlfDirectClient iClient;
+    RAlfDirectClient& iClient;
     };
    
 /**
--- a/uiacceltk/hitchcock/CommonInc/alfbridgecommands.h	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/CommonInc/alfbridgecommands.h	Thu Aug 19 10:48:02 2010 +0300
@@ -84,6 +84,7 @@
     EAlfDSSetTransparencyAlphaChannel,
     EAlfDSIncludeToVisibilityCalculation,
     EAlfDSSetDistractionWindow,
+    EAlfDSSetScreenDeviceValid,
 
     KUnInitialized // This must be kept as last command!
     };
--- a/uiacceltk/hitchcock/ServerCore/Inc/alfbridge.h	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/ServerCore/Inc/alfbridge.h	Thu Aug 19 10:48:02 2010 +0300
@@ -318,6 +318,25 @@
             TInt aDuration,
             TBool& aCoverageRegionModified );
 
+    // Experimental
+    
+    /**
+     * Checks if visual that's flagged as not ready for current orientation is reachable.
+     */
+    TBool IsVisualNotReadyReachable();
+
+    /**
+     * Recursive helper function for IsVisualNotReadyReachable.
+     */
+    TBool IsVisualNotReadyReachableRecursive(
+            CHuiLayout* aLayout,
+            CHuiControlGroup& aControlGroup,
+            CHuiControl& aControl,
+            TBool& aFullscreenCovered, 
+            const TRect& aFullscreen,
+            CAlfScreen* aScreen,
+            TBool aChildCanBeOpaque, 
+            TBool aOnlyForEmbeddedAlfApp);
 	
     void LayoutSwitchStart();
     void LayoutSwitchComplete();
@@ -406,7 +425,16 @@
 	*/    
     TBool StoreLayoutIfRequiredByEffectL(CHuiLayout* aLayout, CFullScreenEffectState& aEvent, TBool& aNeededStoredLayout);
 
+    /**
+     * HandleGfxRedirection
+	 *
+	 * Redirect effect to correct application in case of effect requested for host application, but
+	 * embedded (chained) application is on top of it.
+	 *
+     * If effect setup has been already made for the layout, effect is not redirected.  
+     */
     void HandleGfxRedirection(CFullScreenEffectState& aEvent, CHuiLayout*& aLayout);
+
     /**
      * Handles begin and end fullscreen events
      */
@@ -592,6 +620,8 @@
 	
 	void HandleIncludeToVisibilityCalculationL( TAlfBridgerData& aData );
 	
+	void HandleSetScreenDeviceValidL( TAlfBridgerData& aData );
+	
 	void HandleSetWindowAreaL( TAlfBridgerData& aData );
 	
 	void HandleReorderWindowL( TAlfBridgerData& aData );
@@ -879,6 +909,16 @@
      */
     void UpdateRootVisualsToFullscreen();
     
+    /**
+     * Report memory consumption details (if enabled).
+     */
+    void ReportMemory();
+    
+    /**
+     * Clears rasterizer cache.
+     */
+    void ClearRasterizerCache();
+    
 private:
 
     RPointerArray<CAlfScreen> iAlfScreens;
--- a/uiacceltk/hitchcock/ServerCore/Inc/alfeffectutils.h	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/ServerCore/Inc/alfeffectutils.h	Thu Aug 19 10:48:02 2010 +0300
@@ -124,6 +124,7 @@
         void Blank(TBool aEnabled);
         void LowMemoryEvent();
         void BeginLayoutSwitch();
+        void ImplicitBlank();
         
         void Event(TEvent aEvent);
         void Transition(TState aNewState, TState aPreviousState);
@@ -138,7 +139,8 @@
         void HandleThemeEvent(TEvent aEvent);
 
         void FreezeFinished();
-
+        void HandleBlankChange();
+        
     public:            
         TBool IsThemeEffectEnabled() const;
         TBool LayoutSwitchEffectsExist() const;
@@ -166,6 +168,7 @@
         
         static TInt DoFreezeFinished(TAny* aAny);
         static TInt DoNextLayoutSwitchContext(TAny* aAny);
+        static TInt DoImplicitBlankOff(TAny* aAny);
         
     private: // Data
         
@@ -174,9 +177,12 @@
         TThreadPriority iOriginalPriority;
         CAlfRosterFreezeEndTimer* iRosterFreezeEndTimer;
         TBool iBlankEnabled;
+        TBool iImplicitBlankEnabled;
+        TBool iAknBlankEnabled;
         
         TState iCurrentState;
         TBool iLayoutSwitchNotCompleted;
+        CPeriodic* iImplicitBlankTimer;
 	};
 
 // ---------------------------------------------------------
--- a/uiacceltk/hitchcock/ServerCore/Inc/alfnodes.h	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/ServerCore/Inc/alfnodes.h	Thu Aug 19 10:48:02 2010 +0300
@@ -58,7 +58,9 @@
             CAlfHierarchyModel* aModel, 
             RMemReadStream* aStream, 
             MWsWindowTreeNode::TType aType );
-
+    
+    static void ReportOOM();
+    
 protected:
 
 	void ConstructL( 
--- a/uiacceltk/hitchcock/ServerCore/Inc/alfstreamerbridge.h	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/ServerCore/Inc/alfstreamerbridge.h	Thu Aug 19 10:48:02 2010 +0300
@@ -30,7 +30,8 @@
 class CAlfStreamerServer;
 class CAlfCommandDebug;
 
-const TInt KInitialVariableBufferSize = 2000;
+const TInt KInitialVariableBufferSize = 35000; // enough until booting to idle
+const TInt KIncreaseVariableBufferSize = 2000;
 
 // basic signalling for frame flow control
 const TInt KRELEASEWINDOWSERVER = 0;
--- a/uiacceltk/hitchcock/ServerCore/Inc/alfwindow.h	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/ServerCore/Inc/alfwindow.h	Thu Aug 19 10:48:02 2010 +0300
@@ -48,6 +48,8 @@
     static CAlfWindow* NewL(TUint aId, CAlfWindowManager& aOwner, const TSize& aSizeInPixels);
     
     virtual ~CAlfWindow();
+    
+    static void ReportOOM();
         
 public: 
     // getters
@@ -288,8 +290,19 @@
      * Include to visibility calculation.
      */
     void IncludeToVisibilityCalculation(TBool aActive);
-    
-    public: // utils
+
+    /**
+     * Sets screen device valid/invalid.
+     * @param aValid ETrue if screen device valid, EFalse otherwise.
+     */
+    void SetScreenDeviceValid(TBool aValid);
+	
+    /**
+     * Returns ETrue if screen device is valid.
+     */
+    TBool IsScreenDeviceValid() const;    
+
+public: // utils
     
     /**
 	 * SetFlag
--- a/uiacceltk/hitchcock/ServerCore/Inc/alfwindowdata.h	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/ServerCore/Inc/alfwindowdata.h	Thu Aug 19 10:48:02 2010 +0300
@@ -60,6 +60,7 @@
     
     TBool iTransparencyAlphaChannel;
     TBool iIncludeToVisibilityCalculation;
+    TBool iScreenDeviceValid;
     };
 
 
--- a/uiacceltk/hitchcock/ServerCore/Src/alfappservercore.mmp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/ServerCore/Src/alfappservercore.mmp	Thu Aug 19 10:48:02 2010 +0300
@@ -38,6 +38,11 @@
 
 // MACRO ALF_DEBUG_PRINT_NODE_INFO
 
+// Have these lines active if you want to have additional memory logging.
+// Comment these lines out if you don't want any memory logging.
+//MACRO ALF_MEMORYLOGGING
+//#define ALF_MEMORYLOGGING
+
 
 TARGET                  alfappservercore.dll
 TARGETTYPE              dll
@@ -134,3 +139,7 @@
 #ifdef HUI_DEBUG_TRACK_DRAWING
 LIBRARY					alfcommanddebug.lib
 #endif
+
+#ifdef ALF_MEMORYLOGGING
+LIBRARY                 hal.lib
+#endif
--- a/uiacceltk/hitchcock/ServerCore/Src/alfappsrvsession.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/ServerCore/Src/alfappsrvsession.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -296,20 +296,6 @@
        	iAnimatedTextures.operator[](index)->EnableAnimation(ETrue);     
         }
 
-    if ( aDoTransitionEffect && AlfServer()->TransitionEffects()->IsEnabled() &&
-         (display->DisplayType() != CHuiDisplay::EDisplayOffScreenBuffer))        
-        {
-       	ASSERT(AlfServer()->TransitionEffects() != NULL);
-       	AlfServer()->TransitionEffects()->StartPhase( MAlfTransEffectPlugin::EFirstPhase, 
-       	    aDoTransitionEffect, *iEffectEnv );            
-       	
-       	iControlGroupOrder.Reset();
-        }
-    else
-        {
-//        ShowControlGroupsInOrderL(*display);
-        }    
-
 	// This is needed for Huitk BitBlit() to succeed 
     
 #ifdef SYMBIAN_BUILD_GCE
@@ -358,9 +344,6 @@
         return didTransition;
         }
 
-/*        
-#ifdef HUI_FX
-*/
     if (display->DisplayType() != CHuiDisplay::EDisplayOffScreenBuffer) 
     	{
     	// Disable all animated textures for the session
@@ -375,40 +358,6 @@
        	// as the background will be visible if the effect does not cover full screen
        	// or is partially transparent.
     	}
-/*    	
-#else
-    // Do not hide or set transparency if this is off-screen buffer         
-    if (display->DisplayType() != CHuiDisplay::EDisplayOffScreenBuffer) 
-    	{
-    	// Disable all animated textures for the session
-    	for (TInt index = 0; index < iAnimatedTextures.Count(); index++)
-        	{
-      		iAnimatedTextures.operator[](index)->EnableAnimation(EFalse); 
-        	}
-
-     	if ( aDoTransitionEffect && AlfServer()->TransitionEffects()->IsEnabled() )
-        	{
-        	StoreControlGroupOrderL(*display, EFalse ); // do not hide  
-        	ASSERT(AlfServer()->TransitionEffects() != NULL);
-        	AlfServer()->TransitionEffects()->StartPhase( MAlfTransEffectPlugin::EFirstPhase, 
-            	aDoTransitionEffect, *iEffectEnv );            
-        	didTransition = ETrue;
-        	}
-    	// Hide control groups 
-    	else 
-        	{
-        	StoreControlGroupOrderL(*display, ETrue ); // hide as well     
-    		}
-    		
-#ifdef SYMBIAN_BUILD_GCE
-        // When alf application is not focused we dont draw background because it is
-        // not visible as the alf application is not visible either (its controlgroups
-        // were just hidden in the code above).
-   	    display->SetClearBackgroundL(CHuiDisplay::EClearNone);
-#endif
-    	}
-#endif    		
-*/
     
     return didTransition;
     }
@@ -2742,13 +2691,16 @@
         iTextureInfo.Remove( pos );
         }
 
-    if (!iTextureInfo.Count())
+    //Photos is never killed if it is excluded here. hence commenting
+	/*
+	if (!iTextureInfo.Count())
         {
         if (AlfAppUi()->BridgerClient())
             {
             AlfAppUi()->BridgerClient()->SendBlind(EAlfExcludeFromGoomTargets, TIpcArgs(SecureId(),ClientWindowGroup()));
             }
         }
+	*/
     }
 
 TInt CAlfAppSrvSession::GetTextureSize( 
--- a/uiacceltk/hitchcock/ServerCore/Src/alfappsrvsessionBase.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/ServerCore/Src/alfappsrvsessionBase.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -406,6 +406,11 @@
     {
     __ASSERT_DEBUG(iData, USER_INVARIANT());
     iData->iClientWindowGroupId = aId;
+	//Adding this app to goom list - otherwise app like photos will never be killed
+    if (AlfAppUi()->BridgerClient())
+        {
+        AlfAppUi()->BridgerClient()->SendBlind(EAlfVolunteerForGoomTarget, TIpcArgs(iData->iSecureId, iData->iClientWindowGroupId));
+        }
     }
 
 // ---------------------------------------------------------------------------
--- a/uiacceltk/hitchcock/ServerCore/Src/alfappui.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/ServerCore/Src/alfappui.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -972,7 +972,7 @@
 // Handles window server event.
 // ---------------------------------------------------------------------------
 //
-EXPORT_C void CAlfAppUi::HandleWsEventL(const TWsEvent& aEvent, CCoeControl* aDestination)
+EXPORT_C void CAlfAppUi::HandleWsEventL(const TWsEvent& aEvent, CCoeControl* /*aDestination*/)
     {
     if (aEvent.Type() >= EEventPointer && aEvent.Type() <= 	EEventDragDrop )
         {
@@ -1253,7 +1253,7 @@
     }
 
 
-TTypeUid::Ptr CAlfAppUi::MopSupplyObject(TTypeUid aId)
+TTypeUid::Ptr CAlfAppUi::MopSupplyObject(TTypeUid /*aId*/)
     {
     return TTypeUid::Null();
     }
--- a/uiacceltk/hitchcock/ServerCore/Src/alfbridge.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/ServerCore/Src/alfbridge.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -84,6 +84,13 @@
 #include <bautils.h>
 #endif
 
+#ifdef ALF_MEMORYLOGGING
+#include <hal.h>
+#endif
+
+#include <graphics/fbsrasterizer.h>
+#include <graphics/fbsrasterizerclearcache.h>
+
 const TInt KVisualTransformationStepRotate    = 0;
 
 const TReal32 KAlfVisualDefaultOpacity = 1.0f;
@@ -132,6 +139,9 @@
 // its layout properly.
 const TInt KAlfCheckCoverageFromMultipleGroups = 20;
 
+// Duration to wait if visual is not ready for current orientation.
+// 1 unit = 50ms.
+const TInt KAlfCheckVisualIsNotReady = 15;
 
 NONSHARABLE_CLASS( TAlfBridgeDrawerWrapper ) : public MAlfDrawerScreenInterface
     {
@@ -907,6 +917,11 @@
         entry.iWindowGroupNodeId = aWindowGroupNodeId;
         entry.iClientWindowGroupId = aClientWindowGroupId;  
         entry.iSecureId = aSecureId;
+        // Add to the control group. HandleGfxEventL effect redirection will need this information
+        entry.iScreenNumber = aScreenNumber;
+        iAlfScreens[aScreenNumber]->iControlGroups.Append(entry);
+        CleanupStack::Pop(group);                
+
         // we have received start effect for this group, but the group did not exist in alf universe at the time. hide the group.
         if (iFSFxData
                 && (iFSFxData->State() == EWaitingWindowGroup || iFSFxData->State() == EEndFullScreenReceivedWaitingWindowGroup)
@@ -947,11 +962,6 @@
                 HandleGfxStopEvent( EFalse ); // destroys iFSFxData and iFSFXDataPart2
                 }
             }     
-        entry.iScreenNumber = aScreenNumber;
-//        entry.iRole = EHuiWindowGroupContainer;
-
-        iAlfScreens[aScreenNumber]->iControlGroups.Append(entry);
-        CleanupStack::Pop(group);                
 
         if (iAlfScreens[aScreenNumber]->iDisplay)
             ShowControlGroupL(iAlfScreens[aScreenNumber]->iDisplay->Roster(), *group, KHuiRosterShowAtTop, aScreenNumber); 
@@ -1643,6 +1653,10 @@
                             fullscreenCovered = ETrue;
                             firstAlfControlGroupFound = ETrue;  // change flag so that we don't go in this branch again
                             }
+                        else
+                            {
+                            hostContainer->SetFlags(EHuiVisualFlagInactive);
+                            }
                         }
                     }
                 else // else put as inactive
@@ -2502,6 +2516,12 @@
                 HandleIncludeToVisibilityCalculationL( data );
                 break;
                 }
+            case EAlfDSSetScreenDeviceValid:
+                {
+                HandleSetScreenDeviceValidL( data );
+                break;
+                }
+                
             case EAlfDSSetWindowArea:
                 {
                 HandleSetWindowAreaL( data );
@@ -2874,6 +2894,10 @@
 			}
 		}
 	iAlfScreens[0]->SetVisualTreeVisibilityChanged(ETrue);
+	
+#ifdef ALF_MEMORYLOGGING
+    ReportMemory();
+#endif
 	}
 
 // ---------------------------------------------------------------------------
@@ -3224,6 +3248,42 @@
     }
 
 // ---------------------------------------------------------------------------
+// HandleSetScreenDeviceValidL
+// ---------------------------------------------------------------------------
+// 
+void CAlfBridge::HandleSetScreenDeviceValidL( TAlfBridgerData& aData )
+    {
+	TInt windowNodeId = aData.iInt2;
+	TAlfWindowAttributes* windowAttributes = (TAlfWindowAttributes*) (*iHost)->GetVarDataL( (TInt)aData.iPtr );
+
+	// fetch visual
+	CHuiCanvasVisual* viz = (CHuiCanvasVisual*)FindVisual(windowNodeId);
+	if (viz)
+		{
+#ifdef HUI_DEBUG_TRACK_DRAWING
+        if ( viz->Tracking() )
+            {
+            RDebug::Print(_L("CAlfBridge::HandleSetScreenDeviceValidL - Tracked visual"));
+            }
+#endif
+		if ( windowAttributes->iActive )
+		    {
+		    viz->ClearCanvasFlags( EHuiCanvasVisualFlagNotReady );
+		    }
+		else
+		    {
+		    viz->SetCanvasFlags( EHuiCanvasVisualFlagNotReady );
+		    }
+		
+	    iAlfScreens[0]->SetVisualTreeVisibilityChanged(ETrue);
+		}
+	else
+		{
+		__ALFLOGSTRING("CAlfBridge::HandleSetScreenDeviceValidL, EAlfDSSetScreenDeviceValid: Visual not found!");                                                
+		}          
+    }
+
+// ---------------------------------------------------------------------------
 // HandleSetWindowAreaL
 // ---------------------------------------------------------------------------
 // 
@@ -3315,6 +3375,8 @@
 				}    
 			#endif
 
+            TBool wasInvalidReachable = IsVisualNotReadyReachable();
+
 			CHuiControlGroup* controlGroup = FindControlGroup(windowGroupNodeId);
 			
             if (!controlGroup)
@@ -3355,6 +3417,20 @@
 				}
 			
 			ReorderAlfControlGroupsL();                                        
+
+            // Usually, layout switch is initiated by akncapserver before window group in new orientation 
+            // becomes visible. However, sometimes either akncapserver isn't fast enough or then applications 
+            // perform operations in wrong order. To reduce flickering, uiaccelerator provides implicit blanker.
+
+            // We will check if there is a visual that is not ready for current orientation.
+            // If such visual is found before fullscreen is covered then we will enable
+            // implicit blanker. That gives akncapserver some time to start layout switch.
+	
+            if (!wasInvalidReachable && IsVisualNotReadyReachable())
+                {
+                iLayoutSwitchEffectCoordinator->ImplicitBlank();
+                }
+
 			break;    
 			}
 		case EAlfWinTreeNodeClient:
@@ -3914,11 +3990,12 @@
 	TAlfWindowAttributes* windowAttributes = (TAlfWindowAttributes*)(*iHost)->GetVarDataL( (TInt)aData.iPtr );
 	// fetch visual
 	CHuiCanvasVisual* viz = FindVisual(windowNodeId);
-
+	CHuiControlGroup* controlgroup = FindControlGroup(windowGroupNodeId, 0);
+	
     // We should not do this for alf window, but renderstage does not know if it is
     // handling alf window or other window, so we ignore the request here if needed.
     // TODO: When alf apps work in multiple display, check here for every displays alf groups...
-	if (viz && iAlfWindowGroupNodeId != windowGroupNodeId)
+	if (viz && iAlfWindowGroupNodeId != windowGroupNodeId && controlgroup && controlgroup->SecureId() != iAlfSecureId )
 		{
         viz->SetLayerExtent(windowAttributes->iSurfaceExtent);
 		// Set surface extend area to be cleared with fully transparent color
@@ -4393,9 +4470,18 @@
                     effectFlags |= KHuiFxEffectExcludeChildrenFlag;
                     //RDebug::Print(_L("CAlfBridge::SetupFadeEffectL - no children faded by parent"));
                     }
-                __ALFFXLOGSTRING1("CAlfBridge::SetupFadeEffectL - insert fade 0x%x", &aVisual);
-                TRAP( err, engine->LoadEffectL(*iFadeEffectFile, effect, aVisual.Effectable(), NULL, NULL, 0, effectFlags ) );
-                didFadeEffectLoad = ETrue;
+                
+                if (iHuiEnv->MemoryLevel() <= EHuiMemoryLevelLowest)
+                    {
+                    __ALFFXLOGSTRING("CAlfBridge::SetupFadeEffectL - Skipping because in SW rendering mode");
+                    didFadeEffectLoad = EFalse;
+                    }
+                else
+                    {
+                    __ALFFXLOGSTRING1("CAlfBridge::SetupFadeEffectL - insert fade 0x%x", &aVisual);
+                    TRAP( err, engine->LoadEffectL(*iFadeEffectFile, effect, aVisual.Effectable(), NULL, NULL, 0, effectFlags ) );
+                    didFadeEffectLoad = ETrue;
+                    }
         		}
         	}
         }
@@ -4762,6 +4848,7 @@
     
 void CAlfBridge::HandleGfxRedirection(CFullScreenEffectState& aEvent, CHuiLayout*& aToLayout)
     {
+    __ALFFXLOGSTRING2("CAlfBridge::HandleGfxRedirection - Redirection check for SecureId 0x%x. Effect setup result: %d.", aEvent.iToSecureId, aEvent.iSetupDone);
     TInt windowGroupNodeId = FindWindowGroupNodeId(*((*aToLayout).Owner().ControlGroup()));
     CHuiControlGroup* chainedGroup = NULL;
     
@@ -4791,7 +4878,8 @@
                 }
             }
         groupList.Close();
-        // If there are multiple standalone app groups (e.g. single application having multiple groups), effecting anything would be a guess.
+        // Skip effect redirection if the end result is uncertain. This is the case, if
+        // there are multiple standalone app groups (e.g. single application having multiple groups), 
         if (standaloneGroups>1)
             {
             chainedGroup = NULL;
@@ -4809,23 +4897,37 @@
         chainedGroup = FindControlGroup(chainedId);
         }
     
-    if (chainedGroup)
-        {
-        __ALFFXLOGSTRING2("CAlfBridge::HandleGfxEffects - Chained app found for this application. Transferring effect from 0x%x to 0x%x.", aToLayout->Owner().ControlGroup()->SecureId(), chainedGroup->SecureId());
+	// Redirection is skipped if the host layout has been already prepared (in practice added 
+	// to iEffectCleanupStack) for the effect.
+    if (chainedGroup && !aEvent.iSetupDone)
+        {
+        __ALFFXLOGSTRING2("CAlfBridge::HandleGfxRedirection - Chained app found for this application. Transferring effect from 0x%x to 0x%x.", aToLayout->Owner().ControlGroup()->SecureId(), chainedGroup->SecureId());
         aToLayout = (CHuiLayout*)&chainedGroup->Control(0).Visual(0);
         // we'll change the original effect request to point to this new group. Thus, if effect is 
         // canceled, it will be removed from the right place.
-        aEvent.iIsRedirected = ETrue;
+        
         aEvent.iToSecureId = chainedGroup->SecureId(); // Update the effect
         aEvent.iToWg = FindClientWindowGroupId(*chainedGroup);
         
         if (iFSFXDataPart2)
             {
-            iFSFXDataPart2->iIsRedirected = ETrue;
             iFSFXDataPart2->iToSecureId = aEvent.iToSecureId;
             iFSFXDataPart2->iToWg = aEvent.iToWg;
             }
         }
+    else
+        {
+        __ALFFXLOGSTRING2("CAlfBridge::HandleGfxRedirection - Skip redirection for SecureId 0x%x. Chained group: 0x%x", aEvent.iToSecureId, chainedGroup);
+        }
+    // Redirection attemp is allowed to happen only once, because this redirects effects for 
+	// _running_ embedded applications that must exist at the time of the request. 
+	// We are not interested in the embedded applications effects. Start effects for embedded applications
+	// are not currently supported.
+    aEvent.iIsRedirected = ETrue;
+    if (iFSFXDataPart2)
+        {
+        iFSFXDataPart2->iIsRedirected = ETrue;
+        }
     }
 
 // ---------------------------------------------------------------------------
@@ -4835,7 +4937,7 @@
 //
 TBool CAlfBridge::HandleGfxEventL(CFullScreenEffectState& aEvent, CHuiLayout* aToLayout, CHuiLayout* /*aFromLayout */)
     {
-    __ALFFXLOGSTRING3("CAlfBridge::HandleGfxEventL - To SecureUid: 0x%x, From SecureUid: 0x%x, effect %S", aEvent.iToSecureId, aEvent.iFromSecureId, aEvent.iEffectName);
+    __ALFFXLOGSTRING4("CAlfBridge::HandleGfxEventL - Operation: %d, To SecureUid: 0x%x, From SecureUid: 0x%x, effect %S", aEvent.iOperation, aEvent.iToSecureId, aEvent.iFromSecureId, aEvent.iEffectName);
     __ALFFXLOGSTRING3("CAlfBridge::HandleGfxEventL - To layout: 0x%x Effect handle: %d, Action: %d", aToLayout, aEvent.iHandle, aEvent.iAction);
     
     if (!aEvent.iIsRedirected)
@@ -4976,12 +5078,18 @@
                         
                     if (aToLayout)
                         {
-                         
-                        // However, if this is timeout, then we should be having update to date screenshot for the long app start effect usage
-                        // For the second part of the effect, screenshot must be update. Thus the transition may continue smoothly, where app_start_long.fxml finished.
-                        if ((aEvent.iLongAppStartTimeout && !aToLayout->StoredRenderBuffer()) 
-                                || aEvent.iTwoPhaseEffect == CFullScreenEffectState::ESecondPartActive // update the screenshot, that the app_start effect can use the end result of app_start_long.fxml as input
-								)
+                        // 1. If this is timeout, then we should be update the 
+						//    screenshot for the long app start effect usage. 
+                        // 2. For the second part of the effect, screenshot must be 
+						//    update. Thus the transition may continue smoothly, where app_start_long.fxml finished.
+						// 3. Sometimes BeginFullScreen has not run for the effect. For instance 
+						//    when window group is created after EndFullScreen was received. 
+                        TBool requiresScreenshot = NeedsStoredBuffers(iHuiEnv->EffectsEngine(), *aEvent.iEffectName);
+                        TBool hasScreenshot = TBool(aToLayout->StoredRenderBuffer());
+                        if ((aEvent.iLongAppStartTimeout && !hasScreenshot)  // (1)
+                                || aEvent.iTwoPhaseEffect == CFullScreenEffectState::ESecondPartActive // (2) 
+								|| (requiresScreenshot && !hasScreenshot) // (3)
+                                )
                             {
                             __ALFFXLOGSTRING1("CAlfBridge::HandleGfxEventL  - taking screenshot for the timeout appstart effect. Handle: %d",  aEvent.iHandle );
                             aToLayout->SetStoredRenderBufferModificationsEnabled(ETrue);
@@ -5022,13 +5130,18 @@
                                 }
                             else
                                 {
+								// SetupEffectLayoutContainerL always returns ETrue. Code cleanup needed.
                                 layoutEffectable = SetupEffectLayoutContainerL(aEvent.iHandle,aToLayout, ETrue, EFalse, aEvent.iCanDestroyOrHideImmediately);
                                 }
-                            aEvent.iSetupDone = layoutEffectable; 
+                            aEvent.iSetupDone = ETrue;
+                            if (iFSFXDataPart2)
+                                {
+                                iFSFXDataPart2->iSetupDone = aEvent.iSetupDone;
+                                }
                             aToLayout->SetStoredRenderBufferModificationsEnabled(ETrue);
                             }
 
-                        if (layoutEffectable)
+                        if (layoutEffectable) // Note, this is always ETrue
                             {
                             TInt effectFlags = 0;
                             TInt activeEffectGroup = engine->ActiveGroupEffect();
@@ -5877,9 +5990,7 @@
     CControlEffectState* fxData = new (ELeave) CControlEffectState;
     CleanupStack::PushL(fxData);
     fxData->ConstructL(action, stream);
-    iControlEffectData = fxData;
-    CleanupStack::Pop(fxData);
-
+    
     // We now have all the data sent to us.
     stream.Release();
 
@@ -5892,21 +6003,22 @@
 
     if (visual)
         {
-        HandleGfxControlEventL(*iControlEffectData, visual);
+        HandleGfxControlEventL(*fxData, visual);
+        CleanupStack::PopAndDestroy(fxData);
         }
     else
         {
+       iControlEffectData = fxData; // move ownership
+        // Control was not found. Apply effect later when control appears in HandleNewWindow
         __ALFFXLOGSTRING2("CAlfBridge::HandleGfxControlEffectsL - Control not found. iClientHandle %d, iClientGroupHandle %d", 
                 iControlEffectData->iClientHandle, 
                 iControlEffectData->iClientGroupHandle);
+       CleanupStack::Pop(fxData);
         return;
         }
     iAlfScreens[0]->iDisplay->SetDirty();
     iHuiEnv->ContinueRefresh();
 
-    delete iControlEffectData;
-    iControlEffectData = NULL;
-
     __ALFFXLOGSTRING("HandleGfxControlEffectsL - end");
     }
 
@@ -6155,7 +6267,7 @@
             sourceViz->Owner().Remove(sourceViz);
              
             delete sourceViz;
-            __ALFFXLOGSTRING1("CAlfBridge::RemoveTemporaryPresenterItem - Destroying sourceViz: 0x%x", sourceViz);
+            __ALFFXLOGSTRING1("CAlfBridge::CleanFxItem - Destroying sourceViz: 0x%x", sourceViz);
             aEffectItem.iEffectedVisual = NULL;
             }
         else
@@ -6170,7 +6282,7 @@
 TBool CAlfBridge::CleanFxVisual(CHuiVisual* aVisual,
         TInt aHandle)
     {
-    __ALFFXLOGSTRING2("CAlfBridge::RemoveTemporaryPresenterVisual - cleaning handle: %d, 0x%x", aHandle, aVisual);
+    __ALFFXLOGSTRING2("CAlfBridge::CleanFxVisual - cleaning handle: %d, 0x%x", aHandle, aVisual);
     TInt visualsRemoved = 0;
     for (TInt i = 0; i < iEffectCleanupStack.Count(); i++)
         {
@@ -6780,6 +6892,14 @@
         {
         iManualRefreshTimer->Cancel();
         }
+    if (!aEnable)
+        {
+        ClearRasterizerCache();
+        }
+
+#ifdef ALF_MEMORYLOGGING
+    ReportMemory();
+#endif
     }
 
 // ---------------------------------------------------------------------------
@@ -7389,6 +7509,14 @@
             TRect displayRect = visualDisplayRect;
             visualDisplayRect = canvasVisual->CommandBufferCoverage(aOrientation);
 
+            if (aDuration <= KAlfCheckVisualIsNotReady && !visualRectIsCovered && visualIsVisible && 
+                !displayRect.IsEmpty() && (canvasVisual->CanvasFlags() & EHuiCanvasVisualFlagNotReady))
+                {
+                __ALFLOGSTRING("CAlfBridge::IsLayoutSwitchReady not ready - invalid screen device reachable");                 
+                visualTreeReady = EFalse;
+                break;
+                }
+
             // Heuristic: Check that visual drawing isn't completely empty.
             if ( aDuration <= KAlfCheckVisualDrawingNotEmpty && !visualRectIsCovered &&
                  visualIsVisible && visualDisplayRect.IsEmpty() )
@@ -7469,6 +7597,262 @@
     return visualTreeReady;
     }
 
+// ---------------------------------------------------------------------------
+// ---------------------------------------------------------------------------
+// 
+TBool CAlfBridge::IsVisualNotReadyReachable()
+    {
+    TBool invalidReachable = ETrue;
+
+    if (!iAlfScreens.Count())
+        {
+        return EFalse;
+        }
+   
+    iTempRegion.Clear();
+    iTempRegion2.Clear();
+    
+    CAlfScreen* screen = iAlfScreens[0];
+    TRect fullscreen = TRect(TPoint(0,0), screen->Size());
+    TInt orientation = screen->iDisplay->Orientation();
+    
+    TBool fullscreenCovered = EFalse;
+	TBool alfClientWindowGroupVisible = EFalse;
+		
+    // Skip the topmost (effect) layer, start from floating sprite group
+    for (TInt j=screen->iDisplay->Roster().Count() - screen->FixedControlGroupCount(); j>=0; j--)
+        {                
+        CHuiControlGroup& controlgroup = screen->iDisplay->Roster().ControlGroup(j);
+        CHuiControl& control = controlgroup.Control(0);
+
+        if (control.Role() == EHuiFpsIndicatorContainer)
+            {
+            // FPS container doesn't contain canvas visuals
+            continue;
+            }
+
+        CHuiCanvasVisual* layout = (CHuiCanvasVisual*)&control.Visual(0);
+        
+        // For optimization reasons, check if all visuals below in Z-order are covered    
+        if (!fullscreenCovered)
+            {
+            fullscreenCovered = IsRectCoveredByRegion(fullscreen, iTempRegion);            
+            }    
+    
+        if (fullscreenCovered)
+            {
+            break;
+            }    
+        
+        // ALF applications are handled by checking if their visuals cover the whole screen.
+        if (control.Role() == EHuiSessionContainer)
+            {
+            CHuiLayout* hostContainer = control.ContainerLayout( NULL );
+            TInt flags = hostContainer->Flags();            
+            if (alfClientWindowGroupVisible)
+                {
+                // check visual sizes if client has not made this control group hidden
+                if(!(flags&EHuiVisualFlagUnderOpaqueHint))
+                    {
+                    if(iAppUi)
+                        {
+                        CAlfAppSrvSessionBase* alfSrvSession = iAppUi->SrvSessionForControlGroup(controlgroup);
+                        
+                        TInt clientWindowGroupId = alfSrvSession->ClientWindowGroup();
+                        // checking the case if there are multiple alf application openend.
+                        if (clientWindowGroupId == iAppUi->GetLastActiveClient())
+                            {
+                            return EFalse;
+                            }
+                        }
+                    }
+                }
+            continue;
+            }
+        
+        TBool hasActiveVisualsInVisualTree(EFalse);
+        
+        if (alfClientWindowGroupVisible && (controlgroup.ResourceId() == iAlfWindowGroupNodeId))
+            {
+            invalidReachable =
+               IsVisualNotReadyReachableRecursive( layout, controlgroup, control, 
+                   hasActiveVisualsInVisualTree, fullscreen, screen, 
+                   IsVisualOpaque(*layout), alfClientWindowGroupVisible);            
+            }
+        else
+            {
+            invalidReachable =
+               IsVisualNotReadyReachableRecursive( layout, controlgroup, control, 
+                   fullscreenCovered, fullscreen, screen, 
+                   IsVisualOpaque(*layout), EFalse);      
+            }
+
+        if (invalidReachable)
+            {
+            // Problem found in IsInvalidScreenDeviceVisualReachableRecursive
+            break;
+            }
+
+        if ( controlgroup.iAlfApp && layout->iOpacity.Now() > 0.0f )
+            {
+            alfClientWindowGroupVisible = ETrue;
+            }
+        }
+
+    iTempRegion2.Clear();
+    
+    return invalidReachable;
+    }
+
+// ---------------------------------------------------------------------------
+// ---------------------------------------------------------------------------
+// 
+TBool CAlfBridge::IsVisualNotReadyReachableRecursive(
+        CHuiLayout* aLayout,
+        CHuiControlGroup& aControlGroup,
+        CHuiControl& aControl,
+        TBool& aFullscreenCovered, 
+        const TRect& aFullscreen,
+        CAlfScreen* aScreen,
+        TBool aChildCanBeOpaque, 
+        TBool aOnlyForEmbeddedAlfApp)
+    {
+    TBool invalidReachable = EFalse;
+    TRect visualDisplayRect;
+    TBool visualRectIsCovered = EFalse;
+    TBool visualIsOpaque = EFalse;
+    TBool visualIsActive = EFalse;
+    CHuiCanvasVisual* canvasVisual = NULL;
+
+    for (TInt i = aLayout->Count() - 1; i >= 0; i--)
+        {
+        visualDisplayRect = TRect(0,0,0,0);
+        visualRectIsCovered = EFalse;
+        visualIsOpaque = EFalse;
+        visualIsActive = EFalse;
+        
+        canvasVisual = (CHuiCanvasVisual*)(&aLayout->Visual(i));
+
+        // Distraction windows are completely ignored.
+        TBool distractionWindow = (canvasVisual->CanvasFlags() & EHuiCanvasFlagDistractionWindow);
+        if ( distractionWindow )
+            {
+            continue;
+            }
+
+        visualIsOpaque = aChildCanBeOpaque && IsVisualOpaque(*canvasVisual);
+        TBool visualIsVisible = (canvasVisual->iOpacity.Now() > 0.01f);       
+        
+        if (canvasVisual->Count() && visualIsVisible)
+            {
+            invalidReachable = IsVisualNotReadyReachableRecursive( canvasVisual, aControlGroup, aControl, 
+                aFullscreenCovered, aFullscreen, aScreen, 
+                visualIsOpaque, EFalse);
+                
+            if (invalidReachable)
+                {
+                break;
+                }
+            }
+
+        // Calculate visual display rect
+        visualDisplayRect = canvasVisual->DisplayRect();
+    
+        ClipVisualRect(visualDisplayRect, aLayout->DisplayRect());
+        ClipVisualRect(visualDisplayRect, aFullscreen);
+        
+        // Check if covered.
+        if (aFullscreenCovered)
+            {
+            visualRectIsCovered = ETrue;    
+            }
+        else
+            {            
+            // Check if this visual is covered by other opaque visuals which rects are in "covered" region
+            // it should not check for alf event window group, when we have embedded alf application,
+            // because we have assumed that alf app will have full screen covered
+            if(!aOnlyForEmbeddedAlfApp)
+                {
+                visualRectIsCovered = IsRectCoveredByRegion(visualDisplayRect, iTempRegion);
+                }                                
+            }
+    
+	    // Determine if visual is active from coverage point of view.
+        visualIsActive = EFalse;
+        if (visualRectIsCovered)
+            {                                        
+            if (!(canvasVisual->Flags() & EHuiVisualFlagAlwaysDraw)) 
+                {
+                visualIsActive = EFalse;                
+                }
+            else
+                { 
+                visualIsActive = ETrue;
+                }                
+            }
+        else
+            {
+			visualIsActive = ETrue;
+            }
+        
+        // Sprites and effects as we consider them always as transparent and also
+        // if controlgroup is transformed somehow    
+        if (aControl.Role() == EHuiFullScreenEffectContainer || 
+            aControl.Role() == EHuiWindowFloatingSpriteContainer ||
+            aControlGroup.IsTransformed())
+            {
+            visualIsOpaque = EFalse;    
+            }
+           
+        // Check that command buffers are ok.
+        if ( visualIsActive )
+            {
+            if (!visualRectIsCovered && visualIsVisible && !visualDisplayRect.IsEmpty() && 
+                (canvasVisual->CanvasFlags() & EHuiCanvasVisualFlagNotReady))
+                {
+                __ALFLOGSTRING("CAlfBridge::IsLayoutSwitchReady not ready reachable");                   
+                invalidReachable = ETrue;
+                break;
+                }
+            }
+			
+        if (visualIsActive && visualIsOpaque && !visualRectIsCovered)
+            { 
+            // New visibility system takes only window shape into account.
+            if ( canvasVisual->CanvasFlags() & EHuiCanvasFlagIncludeToVisibilityCalculation )
+                {
+                if ( !canvasVisual->HasCustomShape() )
+                    {                    
+                    TRect displayRect(canvasVisual->DisplayRect());
+                    ClipVisualRect(displayRect, aLayout->DisplayRect());
+                    ClipVisualRect(displayRect, aFullscreen);
+
+                    iTempRegion.AddRect(displayRect);
+                    iTempRegion.Tidy();
+                    }
+                else
+                    {
+                    TRect displayRect = canvasVisual->DisplayRect();
+                    const TRegion& region = canvasVisual->ShapeRegion();
+                    TPoint delta = -canvasVisual->ShapeOrigin() + displayRect.iTl;
+                
+                    for (TInt i = 0; i < region.Count(); ++i)
+                        {
+                        TRect coveredRect(region[i]);
+                        coveredRect.Move(delta);
+                        ClipVisualRect(coveredRect, aFullscreen);
+
+                        iTempRegion.AddRect(coveredRect);
+                        }
+                    iTempRegion.Tidy();
+                    }
+                }
+            }        
+        } // for loop end : children checking loop
+     
+    return invalidReachable;
+    }
+
 TBool CAlfBridge::IsFullScreenDrawnRecursiveAlfContent(CHuiVisual* aVisual, TRect& aFullScreen)
     {
     if(aVisual)
@@ -7757,4 +8141,39 @@
     return hasAlfContent;
     }
 
+void CAlfBridge::ReportMemory()
+    {
+#ifdef ALF_MEMORYLOGGING
+    TInt totalSpaceAllocated = 0;
+    TInt cellsAllocatedInHeap = User::AllocSize(totalSpaceAllocated);
+    TInt largestFreeBlock = 0;
+    TInt totalFreeSpaceInHeap = User::Available(largestFreeBlock);
+    TInt freeRAM = 0;
+    if ( HAL::Get( HALData::EMemoryRAMFree, freeRAM ) != KErrNone )
+        {
+        freeRAM = -1;
+        }
+    TInt timestamp = User::NTickCount();
+        
+    RDebug::Printf("%x CAlfBridge::ReportMemory - Allocated space: %d, Amount of allocated cells: %d, Largest free block: %d, Free space in heap: %d",
+            timestamp,
+            totalSpaceAllocated,
+            cellsAllocatedInHeap,
+            largestFreeBlock,
+            totalFreeSpaceInHeap);
+    RDebug::Printf("%x CAlfBridge::ReportMemory - Free RAM in system: %d", timestamp, freeRAM);
+#endif    
+    }
+
+void CAlfBridge::ClearRasterizerCache()
+    {
+    CFbsRasterizer* rasterizer = CFbsBitmap::Rasterizer();
+    MFbsRasterizerClearCache* cacheInterfacePtr = NULL;
+    rasterizer->GetInterface(TUid::Uid(KUidFbsRasterizerClearCache), (TAny*&)cacheInterfacePtr);
+    if (cacheInterfacePtr)
+        {
+        cacheInterfacePtr->ClearCache();
+        }
+    }
+
 // end of file
--- a/uiacceltk/hitchcock/ServerCore/Src/alfeffectutils.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/ServerCore/Src/alfeffectutils.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -27,6 +27,8 @@
 // Maximum amount of end checks to be performed. 
 // This can be lower, should be visible enough to see, if heuristics fail.
 const TInt KRosterFreezeEndAttempts = 50;
+// Timeout for implicit blank off.
+const TInt KAlfImplicitBlankerTimeoutInMs = 250;
 
 // ---------------------------------------------------------
 // CAlfRosterFreezeEndTimer
@@ -119,6 +121,8 @@
 
 CAlfLayoutSwitchEffectCoordinator::~CAlfLayoutSwitchEffectCoordinator()
     {   
+    delete iRosterFreezeEndTimer;
+    delete iImplicitBlankTimer;
     }
 
 // ---------------------------------------------------------
@@ -128,8 +132,64 @@
 void CAlfLayoutSwitchEffectCoordinator::Blank(TBool aEnabled)
     {
     __ALFLOGSTRING1("CAlfLayoutSwitchEffectCoordinator::Blank %d", aEnabled);
-    iBlankEnabled = aEnabled;
-    Event( aEnabled ? EEventBlankOn : EEventBlankOff );
+    iAknBlankEnabled = aEnabled;
+    HandleBlankChange();
+    }
+
+// ---------------------------------------------------------
+// CAlfLayoutSwitchEffectCoordinator::ImplicitBlank
+// ---------------------------------------------------------
+//
+void CAlfLayoutSwitchEffectCoordinator::ImplicitBlank()
+    {
+    __ALFLOGSTRING("CAlfLayoutSwitchEffectCoordinator::ImplicitBlank");
+        
+    if (!iImplicitBlankTimer)
+        {
+        iImplicitBlankTimer = CPeriodic::New(CActive::EPriorityHigh);
+        if (!iImplicitBlankTimer)
+            {
+            return;
+            }
+        }
+        
+    iImplicitBlankEnabled = ETrue;
+    HandleBlankChange();
+    
+    if (iImplicitBlankTimer)
+        {
+        iImplicitBlankTimer->Cancel();
+        iImplicitBlankTimer->Start(KAlfImplicitBlankerTimeoutInMs*1000, KAlfImplicitBlankerTimeoutInMs*1000, 
+            TCallBack(DoImplicitBlankOff, this));
+        }
+    }
+    
+// ---------------------------------------------------------
+// CAlfLayoutSwitchEffectCoordinator::DoImplicitBlankOff
+// ---------------------------------------------------------
+//
+TInt CAlfLayoutSwitchEffectCoordinator::DoImplicitBlankOff(TAny* aAny)
+    {
+    __ALFLOGSTRING("CAlfLayoutSwitchEffectCoordinator::DoImplicitBlankOff");
+        
+    CAlfLayoutSwitchEffectCoordinator* self = static_cast<CAlfLayoutSwitchEffectCoordinator*>(aAny);
+    self->iImplicitBlankTimer->Cancel();
+    self->iImplicitBlankEnabled = EFalse;
+    self->HandleBlankChange();
+    
+    return KErrNone;
+    }
+
+// ---------------------------------------------------------
+// CAlfLayoutSwitchEffectCoordinator::HandleBlankChange
+// ---------------------------------------------------------
+//
+void CAlfLayoutSwitchEffectCoordinator::HandleBlankChange()
+    {
+    TBool newBlankState = iAknBlankEnabled || iImplicitBlankEnabled;
+    
+    iBlankEnabled = newBlankState;
+    Event( newBlankState ? EEventBlankOn : EEventBlankOff );
     }
     
 // ---------------------------------------------------------
--- a/uiacceltk/hitchcock/ServerCore/Src/alfnodes.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/ServerCore/Src/alfnodes.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -33,6 +33,11 @@
 #else
     #include "alflogger.h"
 #endif
+
+#ifdef ALF_MEMORYLOGGING
+#include <hal.h>
+#endif
+
 // ---------------------------------------------------------------------------
 // Constructor
 // ---------------------------------------------------------------------------
@@ -42,6 +47,30 @@
     {
     }
 
+
+void CAlfNode::ReportOOM()
+    {
+#ifdef ALF_MEMORYLOGGING
+    RDebug::Printf("CAlfNode::ReportOOM");
+
+    TInt totalSpaceAllocated = 0;
+    TInt cellsAllocatedInHeap = User::AllocSize(totalSpaceAllocated);
+    TInt largestFreeBlock = 0;
+    TInt totalFreeSpaceInHeap = User::Available(largestFreeBlock);
+    TInt freeRAM = 0;
+    if ( HAL::Get( HALData::EMemoryRAMFree, freeRAM ) != KErrNone )
+        {
+        freeRAM = -1;
+        }
+        
+    RDebug::Printf("CAlfNode::ReportOOM - Allocated space: %d, Amount of allocated cells: %d, Largest free block: %d, Free space in heap: %d",
+            totalSpaceAllocated,
+            cellsAllocatedInHeap,
+            largestFreeBlock,
+            totalFreeSpaceInHeap);
+    RDebug::Printf("CAlfNode::ReportOOM - Free RAM in system: %d", freeRAM);
+#endif
+    }
 // ---------------------------------------------------------------------------
 // ConstructL
 // ---------------------------------------------------------------------------
@@ -365,61 +394,60 @@
 // ---------------------------------------------------------------------------
 //
 
-// ---------------------------------------------------------------------------
-// CAlfNode::TraverseNodeTree
-// Traverse through node tree and fill node array 
-// ---------------------------------------------------------------------------
-//
-
 void CAlfNode::TraverseNodeTree( CAlfNode* node,  RPointerArray<CAlfNode>& nodes, TBool aTraverseOnlySiblings, TBool aAddMe)
     {
     // Exit if we've already finished walking the tree.
     if ( node == NULL) 
         { 
-        __ALFLOGSTRING(" returning NULL");                                  
+        __ALFLOGSTRING("TraverseNodeTree returning - NULL");                                  
         return;
         }
-    if (!aTraverseOnlySiblings)
+    
+    while ( node )
         {
-        if ( node->iSpriteChild ) 
-            {
-        CAlfNode* spritenode = node->iSpriteChild ;
-            while ( spritenode )
+        if (!aTraverseOnlySiblings)
+            {   
+            if ( node->iSpriteChild ) 
+                {
+                CAlfNode* spritenode = node->iSpriteChild ;
+                while ( spritenode )
+                    {
+                    nodes.Append( spritenode );                
+                    spritenode = spritenode->iSibling;
+                    }
+                }
+    
+            if( node->iTextCursor )
                 {
-                nodes.Append( spritenode );                
-                spritenode = spritenode->iSibling;
+                nodes.Append(node->iTextCursor );            
                 }
-            }
     
-        if( node->iTextCursor )
-            {
-            nodes.Append(node->iTextCursor );            
-            }
-    
-        if( node->iAnimChild )
+            if( node->iAnimChild )
+                {
+                CAlfNode* animnode = node->iAnimChild ;
+                while ( animnode )
+                    {
+                    nodes.Append( animnode );                
+                    animnode = animnode->iSibling;
+                    }
+                }
+        
+            if ( node->iChild)
+                {                
+                TraverseNodeTree(node->iChild , nodes, EFalse, ETrue);            
+                }
+            } 
+
+        if (aAddMe)
             {
-            CAlfNode* animnode = node->iAnimChild ;
-            while ( animnode )
-                {
-                nodes.Append( animnode );                
-                animnode = animnode->iSibling;
-                }
+            nodes.Append( node );
             }
-        
-        if ( node->iChild)
-            {                
-            TraverseNodeTree(node->iChild , nodes, EFalse, ETrue);            
-            }
-        } 
 
-    if (aAddMe)
-        {
-        nodes.Append( node );
-        }
-
-    if ( node->iSibling )
-        {                
-        TraverseNodeTree(node->iSibling, nodes, ETrue, ETrue);               
+        // Without recursion, continue with the following:
+        // TraverseNodeTree(node->iSibling, nodes, ETrue, ETrue);
+        node = node->iSibling;
+        aTraverseOnlySiblings = ETrue;
+        aAddMe = ETrue;
         }
     }
 
@@ -990,7 +1018,14 @@
     {
     TAny* attributes = NULL;
     TRAP_IGNORE(attributes = (TAny*)iModel->Server().Bridge()->AppendVarDataL( aSize, aIndex ))
-    Mem::FillZ( (TUint8*)attributes, aSize ); // Initialize the returned memory area to 0
+    if (attributes)
+        {
+        Mem::FillZ( (TUint8*)attributes, aSize ); // Initialize the returned memory area to 0
+        }
+    else
+        {
+        CAlfNode::ReportOOM();
+        }
     return attributes;
     }
 
@@ -1307,14 +1342,21 @@
             // position must be updated, because it not necessary the first drawn.
             TInt offset;
             TAlfWindowAttributes* windowAttributes = (TAlfWindowAttributes*)CreateWindowAttributes(offset, sizeof(TAlfWindowAttributes));
-            windowAttributes->iOrdinalPosition = ordinal; 
-            windowAttributes->iWindowNodeType = iType;
-            windowAttributes->iScreenNumber = iScreenNumber;
-            // for updating window group ordinals
-            iModel->Server().Bridge()->AddData( EAlfDSReorder, 
-                    iGroupId, 
-                    iId, 
-                    (TAny*)offset );
+            if (windowAttributes)
+                {
+                windowAttributes->iOrdinalPosition = ordinal; 
+                windowAttributes->iWindowNodeType = iType;
+                windowAttributes->iScreenNumber = iScreenNumber;
+                // for updating window group ordinals
+                iModel->Server().Bridge()->AddData( EAlfDSReorder, 
+                        iGroupId, 
+                        iId, 
+                        (TAny*)offset );
+                }
+			else
+				{
+		        CAlfNode::ReportOOM();
+				}
             }
         }
     AMT_MAP_NODE_SET_ORDINAL_POSITION();
@@ -1384,8 +1426,10 @@
         {
         nodeFlags |= EAlfWinNodeFlagOpaque;         
         }
-        
-    if ( iType == MWsWindowTreeNode::EWinTreeNodeStandardTextCursor )
+    
+	// New drawing commands always replace all the previous drawing commands for text cursor and anim nodes.
+    if (   iType == MWsWindowTreeNode::EWinTreeNodeStandardTextCursor 
+        || iType == MWsWindowTreeNode:: EWinTreeNodeAnim )
         {
         emptyBuffer = ETrue;
         }
@@ -1510,6 +1554,13 @@
                 }
             break;
             }
+        case MWsWindowTreeObserver::EScreenDeviceValid:
+            {
+            iWindow->SetScreenDeviceValid(aNewValue);
+            break;
+            }
+        default:
+            break;
         }
     if ( aFlag == MWsWindowTreeObserver::ENonFading && HasChildren() )
         {
@@ -1902,17 +1953,24 @@
     
     TInt offset;
     TAlfWindowAttributes* windowAttributes = (TAlfWindowAttributes*)CreateWindowAttributes(offset, sizeof(TAlfWindowAttributes));
-    windowAttributes->iWindowNodeType = iType; 
-    windowAttributes->iClientHandle = clientHandle;
-    windowAttributes->iScreenNumber = iScreenNumber;
-    windowAttributes->iSecureId = iSecureId;
-    windowAttributes->iParentNodeId = parentId;
-	
-    iModel->Server().Bridge()->AddData( EAlfDSNewWindow, 
-            iGroupId, 
-            iId, 
-            (TAny*)offset );
-    
+    if (windowAttributes)
+        {
+        windowAttributes->iWindowNodeType = iType; 
+        windowAttributes->iClientHandle = clientHandle;
+        windowAttributes->iScreenNumber = iScreenNumber;
+        windowAttributes->iSecureId = iSecureId;
+        windowAttributes->iParentNodeId = parentId;
+        
+        iModel->Server().Bridge()->AddData( EAlfDSNewWindow, 
+                iGroupId, 
+                iId, 
+                (TAny*)offset );
+        }
+    else
+        {
+        CAlfNode::ReportOOM();
+        }
+        
     AMT_MAP_STREAMER_NODE_GROUP_CONSTRUCT();
 	}
 
@@ -2005,13 +2063,20 @@
         {
         TInt offset;
         TAlfWindowAttributes* windowAttributes = (TAlfWindowAttributes*)CreateWindowAttributes(offset, sizeof(TAlfWindowAttributes));
-        windowAttributes->iWindowNodeType = iType; 
-        windowAttributes->iScreenNumber = iScreenNumber; 
-
-        iModel->Server().Bridge()->AddData( EAlfDSDestroyWindow, 
-                iGroupId, 
-                iId, 
-                (TAny*)offset );
+        if (windowAttributes)
+            {
+            windowAttributes->iWindowNodeType = iType; 
+            windowAttributes->iScreenNumber = iScreenNumber; 
+    
+            iModel->Server().Bridge()->AddData( EAlfDSDestroyWindow, 
+                    iGroupId, 
+                    iId, 
+                    (TAny*)offset );
+            }
+		else
+			{
+			CAlfNode::ReportOOM();
+			}
         iWindow = 0; // just in case
         }
     RemoveDependencies( iParent->iChild );
@@ -2144,19 +2209,26 @@
     TInt offset;
     // pass rest of the cursor data
     TAlfCursorDataBufferAttributes* attributes = (TAlfCursorDataBufferAttributes*)CreateWindowAttributes(offset, sizeof(TAlfCursorDataBufferAttributes));
-    attributes->iColor = iColor;
-    attributes->iFlags = iFlags;
-    attributes->iFlashInterval = iFlashInterval;
-    attributes->iScreenNumber = iScreenNumber;
-    
-    aModel->Server().Bridge()->AddData( EAlfDSSetCursorData, 
-            iGroupId, 
-            iId, 
-            (TAny*)offset );
-    
-    UpdateOrdinalPosition();
-    
-    AMT_MAP_STREAMER_TEXT_CURSOR_CONSTRUCT();
+    if (attributes)
+        {
+        attributes->iColor = iColor;
+        attributes->iFlags = iFlags;
+        attributes->iFlashInterval = iFlashInterval;
+        attributes->iScreenNumber = iScreenNumber;
+        
+        aModel->Server().Bridge()->AddData( EAlfDSSetCursorData, 
+                iGroupId, 
+                iId, 
+                (TAny*)offset );
+        
+        UpdateOrdinalPosition();
+        
+        AMT_MAP_STREAMER_TEXT_CURSOR_CONSTRUCT();
+        }
+	else
+		{
+		CAlfNode::ReportOOM();
+		}
     }
 
 // ---------------------------------------------------------------------------
@@ -2206,17 +2278,23 @@
         }
     TInt offset;
     TAlfCursorDataBufferAttributes* attributes = (TAlfCursorDataBufferAttributes*)CreateWindowAttributes(offset, sizeof(TAlfCursorDataBufferAttributes));
-       attributes->iColor = iColor;
-       attributes->iFlags = iFlags;
-       attributes->iFlashInterval = iFlashInterval;
-       attributes->iScreenNumber = iScreenNumber;
-       __ALFLOGSTRING("Forwarding cursor data");
-       iModel->Server().Bridge()->AddData( EAlfDSSetCursorData, 
+    if (attributes)
+        {
+        attributes->iColor = iColor;
+        attributes->iFlags = iFlags;
+        attributes->iFlashInterval = iFlashInterval;
+        attributes->iScreenNumber = iScreenNumber;
+        __ALFLOGSTRING("Forwarding cursor data");
+        iModel->Server().Bridge()->AddData( EAlfDSSetCursorData, 
                iGroupId, 
                iId, 
                (TAny*)offset );
-       
-   AMT_MAP_STREAMER_TEXT_CURSOR_CHANGE();
+        AMT_MAP_STREAMER_TEXT_CURSOR_CHANGE();
+        }
+	else
+		{
+		CAlfNode::ReportOOM();
+		}		
     }
 CAlfNodeTextCursor::~CAlfNodeTextCursor( )
     {
--- a/uiacceltk/hitchcock/ServerCore/Src/alfstaticfactory.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/ServerCore/Src/alfstaticfactory.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -69,7 +69,12 @@
         iPtr(ptr),
         iSession(aSession)
         {}
-        
+
+    void ClearPtr()
+        {
+        iPtr = NULL;
+        }
+    
     TBool OfferEventL(const THuiEvent& aEvent)
         {
         if ( aEvent.IsPointerEvent() )
@@ -116,9 +121,13 @@
     
     ~CAlfControl2()
         {
-        *iPtr = 0;
+		// iPtr might have been cleared previously
+        if (iPtr != NULL)
+            {
+            *iPtr = 0;
+            }
         
-        // Remove possbile pointer observers
+        // Remove possible pointer observers
         if ( Env().DisplayCount() )
             {
             CHuiDisplay& disp = Env().PrimaryDisplay(); // assume one display
@@ -144,7 +153,14 @@
     void HandleCmdL(TInt aCommandId, const TDesC8& aInputBuffer, TDes8& aResponse);    
     CAlfControl2* iControl;
     ~CAlfControlHandler() 
-        { 
+        {
+		// Clear the control's iPtr so that it wouldn't be left as dangling pointer
+		// and cause potential memory corruption
+        if (iControl != NULL)
+            {
+            iControl->ClearPtr();
+            }
+        
         if (iControl && !iControl->ControlGroup())
             {
             delete iControl; 
--- a/uiacceltk/hitchcock/ServerCore/Src/alfstreamerbridge.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/ServerCore/Src/alfstreamerbridge.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -96,6 +96,7 @@
     {
     iDataBuf.Close();
     iQueueSema.Close();
+    iMessages.Close();
 #ifdef ALF_DEBUG_TRACK_DRAWING
     delete iCommandDebugger;
 #endif
@@ -203,7 +204,8 @@
         }
     else if (iVarDataAddedButNotPosted)
         {
-	iVarDataAddedButNotPosted = EFalse; // data lost 
+		__ALFLOGSTRING1("CAlfStreamerBridge::AddData - Data lost, error: %d", err);
+        iVarDataAddedButNotPosted = EFalse; // data lost 
         iQueueSema.Signal();
         }
 	    
@@ -413,7 +415,7 @@
         }
     if ( iDataBuf.Length() + aSize >= iDataBuf.MaxLength() )
         {
-        TRAPD(err, iDataBuf.ReAllocL( iDataBuf.MaxLength() + KInitialVariableBufferSize ));
+        TRAPD(err, iDataBuf.ReAllocL( iDataBuf.MaxLength() + aSize + KIncreaseVariableBufferSize ));
         if ( err )
             {
             __ALFLOGSTRING("CAlfStreamerBridge::AppendVarDataL, realloc failed");
--- a/uiacceltk/hitchcock/ServerCore/Src/alfstreamerserver.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/ServerCore/Src/alfstreamerserver.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -227,14 +227,19 @@
 CAlfStreamerServer::~CAlfStreamerServer()
     {
     delete iThemesListener;
-    delete iWindowMgr;
     delete iWindowHierarcy;
+    iWindowHierarcy = NULL;
     iCompositionSessions.Close();
     iCompositionHostSessions.Close();
     iCompositionTokens.Close();
     iWindowServerSessions.Close();
     iAlfTargets.Close();
     iOptionalGRAM.Close();
+    iSignals.Close();
+     // Remove "effectpluginnotunloaded" from 10282CAF.rss in order to really unload effect plugin
+    // iWindowMgr->DestroyPlugin(TUid::Uid(0x2001e2cf)); // effects plugin. window manager needed for unloading.
+    delete iWindowMgr;
+    iWindowMgr = NULL;
     }
 
 void CAlfStreamerServer::AppendCompositionSessionL(CAlfStreamerServerSession* aSession, TBool aHost)
@@ -797,6 +802,12 @@
     TInt i = 0;
     RImplInfoPtrArray pluginArray;
     REComSession::ListImplementationsL( KAlfGfxPluginInterfaceUId, pluginArray );    
+    CAlfWindowManager* windowMgr = NULL;
+    if (Server())
+        {
+        windowMgr = ((CAlfStreamerServer*)(Server()))->WindowMgr();
+        }
+            
     for ( i = iLoadedPlugins.Count() - 1; i >= 0; i-- )
         {
         TInt j = 0;    
@@ -805,9 +816,9 @@
             TUid loaded = TUid::Uid(iLoadedPlugins[i]);
             TUid listed = pluginArray[j]->ImplementationUid();
             TPtrC8 listedopaque = pluginArray[j]->OpaqueData();
-            if ( loaded == listed && ( (listedopaque.CompareF( KAlfDoNotUnloadPlugin )) != 0 ) )
+            if ( loaded == listed && ( (listedopaque.CompareF( KAlfDoNotUnloadPlugin )) != 0 ) && windowMgr)
                 {
-                ((CAlfStreamerServer*)(Server()))->WindowMgr()->DestroyPlugin(TUid::Uid(iLoadedPlugins[i]));
+                windowMgr->DestroyPlugin(TUid::Uid(iLoadedPlugins[i]));
                 }
             }
         }
--- a/uiacceltk/hitchcock/ServerCore/Src/alfwindow.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/ServerCore/Src/alfwindow.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -28,6 +28,10 @@
 #include <string.h>
 #include <s32mem.h>
 
+#ifdef ALF_MEMORYLOGGING
+#include <hal.h>
+#endif
+
 // ---------------------------------------------------------------------------
 // NewL
 // ---------------------------------------------------------------------------
@@ -59,7 +63,30 @@
         delete iData;
         }
     }
-        
+
+void CAlfWindow::ReportOOM()
+    {
+#ifdef ALF_MEMORYLOGGING
+    RDebug::Printf("CAlfWindow::ReportOOM");
+    TInt totalSpaceAllocated = 0;
+    TInt cellAllocatedInHeap = User::AllocSize(totalSpaceAllocated);
+    TInt largestFreeBlock = 0;
+    TInt totalFreeSpaceInHeap = User::Available(largestFreeBlock);
+    TInt freeRAM = 0;
+    if ( HAL::Get( HALData::EMemoryRAMFree, freeRAM ) != KErrNone )
+        {
+        freeRAM = -1;
+        }
+
+    RDebug::Printf("CAlfWindow::ReportOOM - Allocated space: %d, Amount of allocated cells: %d, Largest free block: %d, Free space in heap: %d",
+            totalSpaceAllocated,
+            cellAllocatedInHeap,
+            largestFreeBlock,
+            totalFreeSpaceInHeap);
+    RDebug::Printf("CAlfWindow::ReportOOM - Free RAM in system: %d", freeRAM);
+#endif
+    }
+
 // ---------------------------------------------------------------------------
 // WsInfo
 // ---------------------------------------------------------------------------
@@ -507,21 +534,28 @@
     const TInt size = ( 4*aRegion.Count() + 4 ) * sizeof(TInt32);
     TAny* data = (TAny*)iData->iWindowManager->Bridge()->AppendVarDataL( size, aOffset );
 
-    RMemWriteStream str( data, size );
-    str.WriteInt32L( aScreenNumber );
-    str.WriteInt32L( aOrigin.iX );
-    str.WriteInt32L( aOrigin.iY );
-    str.WriteInt32L( aRegion.Count() );
-        
-    for (TInt i = 0; i < aRegion.Count(); ++i )
+    if (data)
         {
-        const TRect rect(aRegion[i]);
-        str.WriteInt32L(rect.iTl.iX);
-        str.WriteInt32L(rect.iTl.iY);
-        str.WriteInt32L(rect.iBr.iX);
-        str.WriteInt32L(rect.iBr.iY);
+        RMemWriteStream str( data, size );
+        str.WriteInt32L( aScreenNumber );
+        str.WriteInt32L( aOrigin.iX );
+        str.WriteInt32L( aOrigin.iY );
+        str.WriteInt32L( aRegion.Count() );
+            
+        for (TInt i = 0; i < aRegion.Count(); ++i )
+            {
+            const TRect rect(aRegion[i]);
+            str.WriteInt32L(rect.iTl.iX);
+            str.WriteInt32L(rect.iTl.iY);
+            str.WriteInt32L(rect.iBr.iX);
+            str.WriteInt32L(rect.iBr.iY);
+            }
         }
-    
+    else
+        {
+        CAlfWindow::ReportOOM();
+        }
+        
     return data;
     }
 
@@ -629,6 +663,56 @@
     }
 
 // ---------------------------------------------------------------------------
+// SetScreenDeviceValid
+// ---------------------------------------------------------------------------
+//
+void CAlfWindow::SetScreenDeviceValid(TBool aValid)
+    {
+    if ( WsInfo().iNodeType != MWsWindowTreeNode::EWinTreeNodeClient )
+        {
+        // We intentionally omit other than client windows. Actually, we 
+		// we should get this valid information only for top level windows.
+		return;
+        }
+
+    if (!IsInsertedToScene())
+        {
+        iData->iScreenDeviceValid = aValid;
+        return;        
+        }
+        
+    TAlfWServInfo wservInfo = WsInfo();
+
+    TInt offset;
+    TAlfWindowAttributes* windowAttributes = CreateWindowAttributes(offset);
+    if ( windowAttributes )
+        {
+        windowAttributes->iActive = aValid; 
+        windowAttributes->iScreenNumber = wservInfo.iScreenNumber;
+        
+        TAlfBridgerData d;
+        d.Set(EAlfDSSetScreenDeviceValid, 
+            wservInfo.iRefId.iWindowGroupId, 
+            wservInfo.iRefId.iWindowIdentifer, 
+            (TAny*)offset); 
+
+        if (iData->iWindowManager->PostIt(d))
+            {
+            iData->iScreenDeviceValid = aValid;
+            }
+        }    
+    }
+
+// ---------------------------------------------------------------------------
+// IsScreenDeviceValid
+// ---------------------------------------------------------------------------
+//
+TBool CAlfWindow::IsScreenDeviceValid() const
+    {
+    return iData->iScreenDeviceValid;
+    }
+
+// ---------------------------------------------------------------------------
 // IsIncludedToVisibilityCalculation
 // ---------------------------------------------------------------------------
 //
@@ -707,6 +791,7 @@
     iData->iWindowArea = RRegion();
     iData->iTransparencyAlphaChannel = EFalse;
     iData->iIncludeToVisibilityCalculation = EFalse;
+    iData->iScreenDeviceValid = ETrue;
     
     SetSize(aSizeInPixels);
     }
@@ -891,6 +976,10 @@
             // ???
             }
         }
+    else
+        {
+        ReportOOM();
+        }
     
     }
 
@@ -924,6 +1013,10 @@
             // ???
             }
         }
+    else
+        {
+        CAlfWindow::ReportOOM();
+        }
     }
 
 // ---------------------------------------------------------------------------
@@ -955,6 +1048,10 @@
         {
         *attributes = empty;
         }
+    else
+        {
+        CAlfWindow::ReportOOM();
+        }
     return attributes;
     }
 
@@ -971,5 +1068,9 @@
         {
         *windowCommandBuffer = empty;
         }
+    else
+        {
+        CAlfWindow::ReportOOM();
+        }
     return windowCommandBuffer;
     }
--- a/uiacceltk/hitchcock/ServerCore/Src/alfwindowmanager.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/ServerCore/Src/alfwindowmanager.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -208,6 +208,7 @@
 	aWindow->SetSurfaceExtent(aWindow->SurfaceExtent());
     aWindow->SetWindowArea();
     aWindow->SetTransparencyAlphaChannel(aWindow->TransparencyAlphaChannel());
+    aWindow->SetScreenDeviceValid(aWindow->IsScreenDeviceValid());
     aWindow->IncludeToVisibilityCalculation(aWindow->IsIncludedToVisibilityCalculation());
 	aWindow->SetActive(aWindow->IsActive());
 	}
@@ -253,16 +254,23 @@
 
         TInt offset;
         TAlfWindowAttributes* windowAttributes = CreateWindowAttributes(offset);
-        windowAttributes->iWindowNodeType = wservInfo.iNodeType; 
-        windowAttributes->iScreenNumber = wservInfo.iScreenNumber; 
+        if (windowAttributes)
+            {
+            windowAttributes->iWindowNodeType = wservInfo.iNodeType; 
+            windowAttributes->iScreenNumber = wservInfo.iScreenNumber; 
 
-    	TAlfBridgerData data;
-        data.Set(EAlfDSDestroyWindow, 
-            wservInfo.iRefId.iWindowGroupId, 
-            wservInfo.iRefId.iWindowIdentifer, 
-            (TAny*)offset); 
-
-        PostIt(data);
+            TAlfBridgerData data;
+            data.Set(EAlfDSDestroyWindow, 
+                wservInfo.iRefId.iWindowGroupId, 
+                wservInfo.iRefId.iWindowIdentifer, 
+                (TAny*)offset); 
+    
+            PostIt(data);
+            }
+		else
+            {
+            CAlfWindow::ReportOOM();
+            }
 
         iData->iWindows.Remove(i);
         delete &aWindow;
@@ -316,7 +324,7 @@
 // Decaprecated
 // ---------------------------------------------------------------------------
 //   
-EXPORT_C CAlfWindow* CAlfWindowManager::ReserveL( const TWindowIdentifier& /*aId*/, TBool aReserveBuffer /*= ETrue*/ )
+EXPORT_C CAlfWindow* CAlfWindowManager::ReserveL( const TWindowIdentifier& /*aId*/, TBool /*aReserveBuffer = ETrue*/ )
     {
     return 0; // we never get here 
     }
@@ -658,7 +666,14 @@
     TAlfWindowAttributes empty;
     TAlfWindowAttributes* attributes = NULL;
     TRAP_IGNORE(attributes = (TAlfWindowAttributes*)Bridge()->AppendVarDataL( sizeof(TAlfWindowAttributes), aIndex ))
-    *attributes = empty;
+    if (attributes)
+        {
+        *attributes = empty;
+        }
+    else
+        {
+        CAlfWindow::ReportOOM();
+        }
     return attributes;
     }
 
@@ -671,7 +686,14 @@
     TAlfWindowCommandBufferAttributes empty;    
     TAlfWindowCommandBufferAttributes* windowCommandBuffer = NULL;    
     TRAP_IGNORE(windowCommandBuffer = (TAlfWindowCommandBufferAttributes*)Bridge()->AppendVarDataL( sizeof(TAlfWindowCommandBufferAttributes), aIndex ))    
-    *windowCommandBuffer = empty;
+    if (windowCommandBuffer)
+        {
+        *windowCommandBuffer = empty;
+        }
+    else
+        {
+        CAlfWindow::ReportOOM();
+        }
     return windowCommandBuffer;
     }
 
--- a/uiacceltk/hitchcock/coretoolkit/BWINS/hitchcocku.DEF	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/coretoolkit/BWINS/hitchcocku.DEF	Thu Aug 19 10:48:02 2010 +0300
@@ -1604,4 +1604,9 @@
 	?Find@CAppIconCache@@QAEPAVCFbsBitmap@@_JVTSize@@@Z @ 1603 NONAME ; class CFbsBitmap * CAppIconCache::Find(long long)
 	?SetSkinSizeChangePending@CHuiDisplay@@QAEXXZ @ 1604 NONAME ; void CHuiDisplay::SetSkinSizeChangePending(void)	
 	?EffectReadyToDrawNextFrame@CHuiVisual@@UBEHXZ @ 1605 NONAME ; int CHuiVisual::EffectReadyToDrawNextFrame(void) const
+	?HandleOutOfTextureMemory@CHuiEnv@@QAEXXZ @ 1606 NONAME ; void CHuiEnv::HandleOutOfTextureMemory(void)
+	?ReleaseAllCachedRenderTargets@CHuiFxVisualLayer@@UAEXAAVCHuiFxEngine@@@Z @ 1607 NONAME ; void CHuiFxVisualLayer::ReleaseAllCachedRenderTargets(class CHuiFxEngine &)
+	?ReleaseAllCachedRenderTargets@CHuiFxGroupLayer@@UAEXAAVCHuiFxEngine@@@Z @ 1608 NONAME ; void CHuiFxGroupLayer::ReleaseAllCachedRenderTargets(class CHuiFxEngine &)
+	?ReleaseAllCachedRenderTargets@CHuiFxFilterLayer@@UAEXAAVCHuiFxEngine@@@Z @ 1609 NONAME ; void CHuiFxFilterLayer::ReleaseAllCachedRenderTargets(class CHuiFxEngine &)
+	?ReleaseAllCachedRenderTargets@CHuiFxLayer@@UAEXAAVCHuiFxEngine@@@Z @ 1610 NONAME ; void CHuiFxLayer::ReleaseAllCachedRenderTargets(class CHuiFxEngine &)
 
--- a/uiacceltk/hitchcock/coretoolkit/eabi/hitchcocku.DEF	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/coretoolkit/eabi/hitchcocku.DEF	Thu Aug 19 10:48:02 2010 +0300
@@ -2005,4 +2005,9 @@
 	_ZNK7CHuiEnv12AppIconCacheEv @ 2004 NONAME
 	_ZN11CHuiDisplay24SetSkinSizeChangePendingEv @ 2005 NONAME
 	_ZNK10CHuiVisual26EffectReadyToDrawNextFrameEv @ 2006 NONAME
+	_ZN7CHuiEnv24HandleOutOfTextureMemoryEv @ 2007 NONAME
+	_ZN11CHuiFxLayer29ReleaseAllCachedRenderTargetsER12CHuiFxEngine @ 2008 NONAME
+	_ZN16CHuiFxGroupLayer29ReleaseAllCachedRenderTargetsER12CHuiFxEngine @ 2009 NONAME
+	_ZN17CHuiFxFilterLayer29ReleaseAllCachedRenderTargetsER12CHuiFxEngine @ 2010 NONAME
+	_ZN17CHuiFxVisualLayer29ReleaseAllCachedRenderTargetsER12CHuiFxEngine @ 2011 NONAME
 
--- a/uiacceltk/hitchcock/coretoolkit/inc/HuiFxFilterLayer.h	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/coretoolkit/inc/HuiFxFilterLayer.h	Thu Aug 19 10:48:02 2010 +0300
@@ -31,6 +31,7 @@
     IMPORT_C ~CHuiFxFilterLayer();
     IMPORT_C static CHuiFxFilterLayer* NewL(CHuiFxFilter* aFilter); // takes ownership
     IMPORT_C TBool PrepareDrawL(CHuiFxEngine& aEngine);
+    IMPORT_C void ReleaseAllCachedRenderTargets(CHuiFxEngine& aEngine);
     IMPORT_C void Draw(CHuiFxEngine& aEngine, CHuiGc& aGc, CHuiFxRenderbuffer& aTarget, CHuiFxRenderbuffer& aSource, TBool aHasSurface);
     IMPORT_C CHuiFxFilter& Filter() const;
     IMPORT_C TBool Changed() const;
--- a/uiacceltk/hitchcock/coretoolkit/inc/HuiFxGroupLayer.h	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/coretoolkit/inc/HuiFxGroupLayer.h	Thu Aug 19 10:48:02 2010 +0300
@@ -27,6 +27,7 @@
 public:
     IMPORT_C ~CHuiFxGroupLayer();
     IMPORT_C static CHuiFxGroupLayer* NewL(TBool aIsRoot = EFalse);
+    IMPORT_C void ReleaseAllCachedRenderTargets(CHuiFxEngine& aEngine);
     IMPORT_C TBool PrepareDrawL(CHuiFxEngine& aEngine);
     IMPORT_C void Draw(CHuiFxEngine& aEngine, CHuiGc& aGc, CHuiFxRenderbuffer& aTarget, CHuiFxRenderbuffer& aSource, TBool aHasSurface);
     IMPORT_C void AddLayerL(const CHuiFxLayer* aLayer); // takes ownership
--- a/uiacceltk/hitchcock/coretoolkit/inc/HuiFxLayer.h	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/coretoolkit/inc/HuiFxLayer.h	Thu Aug 19 10:48:02 2010 +0300
@@ -32,6 +32,7 @@
     IMPORT_C virtual ~CHuiFxLayer();
 
     IMPORT_C virtual TBool PrepareDrawL(CHuiFxEngine& aEngine);
+    IMPORT_C virtual void ReleaseAllCachedRenderTargets(CHuiFxEngine& aEngine);
     virtual void Draw(CHuiFxEngine& aEngine, CHuiGc& aGc, CHuiFxRenderbuffer& aTarget, CHuiFxRenderbuffer& aSource, TBool aHasSurface) = 0;
     IMPORT_C virtual TBool VisualArea(TRect& aRect);
     IMPORT_C virtual TBool Margin( TMargins &m );
--- a/uiacceltk/hitchcock/coretoolkit/inc/HuiFxVisualLayer.h	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/coretoolkit/inc/HuiFxVisualLayer.h	Thu Aug 19 10:48:02 2010 +0300
@@ -32,6 +32,7 @@
     IMPORT_C static CHuiFxVisualLayer* NewL(MHuiEffectable* aVisual); // param mandatory
     IMPORT_C ~CHuiFxVisualLayer();
     IMPORT_C TBool PrepareDrawL(CHuiFxEngine& aEngine);
+    IMPORT_C void ReleaseAllCachedRenderTargets(CHuiFxEngine& aEngine);
     IMPORT_C void Draw(CHuiFxEngine& aEngine, CHuiGc& aGc, CHuiFxRenderbuffer& aTarget, CHuiFxRenderbuffer& aSource, TBool aHasSurface);
     IMPORT_C TBool VisualArea( TRect& aRect );
     IMPORT_C void AdvanceTime(TReal32 aElapsedTime);
--- a/uiacceltk/hitchcock/coretoolkit/rendervg10/inc/HuiVg10RenderPlugin.h	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/coretoolkit/rendervg10/inc/HuiVg10RenderPlugin.h	Thu Aug 19 10:48:02 2010 +0300
@@ -298,6 +298,15 @@
 	    return iEGLStateForTextureUpload;
 	    }
 	
+    /**
+     * Helper function for creating new PBuffer surfaces.
+	 * If out of memory happens this method tries to internally free all
+	 * the possible memory that can be freed and tries again. If still there is
+	 * not enough available memory EGL_NO_SURFACE is returned
+     */
+    EGLSurface CreatePBufferSurface(EGLDisplay aDisplay,
+                EGLenum aBuffertype, EGLClientBuffer aBuffer, EGLConfig aConfig);
+    
 protected:
 
     /* Constructors. */
--- a/uiacceltk/hitchcock/coretoolkit/rendervg10/src/HuiFxVg10Engine.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/coretoolkit/rendervg10/src/HuiFxVg10Engine.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -45,7 +45,8 @@
     CHuiFxEngine::ConstructL(EHuiFxEngineVg10);
     iPlugin = &aPlugin;
     iDefaultBuffer = 0;
-    iCompPaint = vgCreatePaint();
+	// usually we don't have any vg context set at this point, so we cannot yet create the actual paint
+    iCompPaint = VG_INVALID_HANDLE; 
     }
 
 CHuiFxVg10Engine::~CHuiFxVg10Engine()
--- a/uiacceltk/hitchcock/coretoolkit/rendervg10/src/HuiFxVg10OffscreenRenderbuffer.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/coretoolkit/rendervg10/src/HuiFxVg10OffscreenRenderbuffer.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -69,13 +69,26 @@
     // Create a context
     iContext = eglCreateContext(iPlugin->EglDisplay(), config,
             iPlugin->EglSharedContext(), NULL);
-    ASSERT(iContext);
+
+    if(iContext == EGL_NO_CONTEXT)
+        {
+        EGLint err = eglGetError();
+        RDebug::Print(_L("CHuiFxVg10OffscreenRenderbuffer::InitializeL() - EGLContext creation failed: EglError -- %04x"), err);
+        User::Leave(KErrGeneral);
+        }
     
     // Create a pbuffer surface
-    iSurface = eglCreatePbufferFromClientBuffer(iPlugin->EglDisplay(), EGL_OPENVG_IMAGE,
-                                                iImage, config, NULL);
-    ASSERT(iSurface);   
-    
+    CHuiVg10RenderPlugin& renderer = CHuiStatic::Vg10Renderer();
+    iSurface = renderer.CreatePBufferSurface(iPlugin->EglDisplay(), EGL_OPENVG_IMAGE,                                 
+                                    iImage, config);
+
+    if(iSurface == EGL_NO_SURFACE)
+         {
+         EGLint err = eglGetError();
+         RDebug::Print(_L("CHuiFxVg10OffscreenRenderbuffer::InitializeL() - EGLSurface creation failed: EglError -- %04x"), err);
+         User::Leave(KErrGeneral);
+         }
+   
     // Initialize the context
     iGc = iPlugin->CreateGcL();
     this->InitGc(aSize);
--- a/uiacceltk/hitchcock/coretoolkit/rendervg10/src/HuiVg10RenderPlugin.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/coretoolkit/rendervg10/src/HuiVg10RenderPlugin.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -565,3 +565,23 @@
 #endif
     }
 
+
+EGLSurface CHuiVg10RenderPlugin::CreatePBufferSurface(EGLDisplay aDisplay,
+            EGLenum aBuffertype, EGLClientBuffer aBuffer, EGLConfig aConfig)
+    {
+    EGLSurface newSurface = EGL_NO_SURFACE;
+    newSurface = eglCreatePbufferFromClientBuffer(aDisplay, aBuffertype, aBuffer, aConfig, NULL);
+
+    // if oom condition, free all the cached memory and try again
+    if(newSurface == EGL_NO_SURFACE)
+        {
+        if(eglGetError() == EGL_BAD_ALLOC)
+            {
+            CHuiEnv* env = CHuiEnv::Static();  
+            env->HandleOutOfTextureMemory();
+            newSurface = eglCreatePbufferFromClientBuffer(aDisplay, aBuffertype, aBuffer, aConfig, NULL);
+            }
+        }
+    return newSurface;
+    }
+
--- a/uiacceltk/hitchcock/coretoolkit/rendervg10/src/HuiVg10Texture.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/coretoolkit/rendervg10/src/HuiVg10Texture.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -1256,7 +1256,7 @@
     VGImageFormat imageInternalFormat = VG_sARGB_8888;
 #endif
     
-    VGbitfield qualityFlags = VG_IMAGE_QUALITY_NONANTIALIASED; // | VG_IMAGE_QUALITY_BETTER | VG_IMAGE_QUALITY_FASTER;
+    VGbitfield qualityFlags = VG_IMAGE_QUALITY_NONANTIALIASED | VG_IMAGE_QUALITY_BETTER | VG_IMAGE_QUALITY_FASTER;
     image = vgCreateImage(imageInternalFormat, aDestSize.iWidth, aDestSize.iHeight, qualityFlags);
     
     // Get the configs and displays etc. needed for creating the surface
@@ -1288,11 +1288,13 @@
 #endif
     
     // The VGImage will act as the surface, so the drawing will go directly to the VGImage
+    // Note - we do not call iRenderPlugin.CreatePBufferSurface since that could call
+    // CHuiEnv::HandleOutOfTextureMemory and that could cause this texture to be reset.
     EGLSurface newSurface = eglCreatePbufferFromClientBuffer(
         display, EGL_OPENVG_IMAGE,
         static_cast<EGLClientBuffer>(image),    // Use the image as buffer
         config, NULL);
-    
+        
     // Report error in debug mode, if failed creating the surface
     if ( newSurface == EGL_NO_SURFACE )
         {
--- a/uiacceltk/hitchcock/coretoolkit/rendervg10/src/HuiVg10VGImageBinder.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/coretoolkit/rendervg10/src/HuiVg10VGImageBinder.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -98,10 +98,11 @@
         EGLConfig config = iRenderPlugin->EglConfig(0);
 
         // Create a pbuffer surface
-        iEglPBufferSurface_Client = eglCreatePbufferFromClientBuffer(iRenderPlugin->EglDisplay(),
-                EGL_OPENVG_IMAGE, 
-                static_cast<EGLClientBuffer>(aBuffer),    // Use the param image as buffer
-                config, NULL);
+        iEglPBufferSurface_Client = iRenderPlugin->CreatePBufferSurface(iRenderPlugin->EglDisplay(),
+                                                                EGL_OPENVG_IMAGE, 
+                                                                static_cast<EGLClientBuffer>(aBuffer),
+                                                                config );        
+        
         if (iEglPBufferSurface_Client == EGL_NO_SURFACE)
             {
             HUI_DEBUG1(_L("CHuiVg10VgImageBinder::BindClientBuffer() - EGL Surface could not be created, eglErr: %04x"), eglGetError() );
--- a/uiacceltk/hitchcock/coretoolkit/rendervg10/src/huivg10canvasrenderbuffer.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/coretoolkit/rendervg10/src/huivg10canvasrenderbuffer.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -145,7 +145,7 @@
     iContext = eglCreateContext(renderer.EglDisplay(), config,
             renderer.EglSharedContext(), NULL);
 
-    if(!iContext)
+    if(iContext == EGL_NO_CONTEXT)
         {
         PopEGLContext();
 
@@ -155,9 +155,11 @@
         }
 
     // Create a pbuffer surface
-    iSurface = eglCreatePbufferFromClientBuffer(renderer.EglDisplay(), EGL_OPENVG_IMAGE,
-                                                iImage, config, NULL);
-    if(!iSurface)
+
+    iSurface = renderer.CreatePBufferSurface(renderer.EglDisplay(), EGL_OPENVG_IMAGE,                                 
+                                    iImage, config);
+  
+    if(iSurface == EGL_NO_SURFACE)
         {
         PopEGLContext();
 
--- a/uiacceltk/hitchcock/coretoolkit/src/HuiCanvasTextureCache.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/coretoolkit/src/HuiCanvasTextureCache.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -3043,8 +3043,9 @@
 //
 void CHuiCanvasTextureCache::HandleOutOfTextureMemory()
     {
-    RDebug::Print(_L("CHuiCanvasTextureCache::HandleOutOfTextureMemory: Out of memory happened !"));
-
+#ifdef HUI_DEBUG_PRINT_CANVAS_TEXTURE_CACHE
+    RDebug::Print(_L("CHuiCanvasTextureCache::HandleOutOfTextureMemory"));
+#endif
     DeleteAllReleasedEntries(EFalse);    
     
     // TODO: Who you gonna call when texture memory is full and we cannot ourself
--- a/uiacceltk/hitchcock/coretoolkit/src/HuiCanvasVisual.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/coretoolkit/src/HuiCanvasVisual.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -290,7 +290,7 @@
         
     if (iCanvasVisualData->iCommandSetType == ECommandBufferWs || iCanvasVisualData->iCommandSetType == ECommandBufferAlf)
         {
-        TRAPD(err, iCanvasVisualData->iCanvasPainter->HandleBufferL(aDisplayRect, aAction, *this, aGc, DisplayRect().iTl.Round()));  
+        TRAPD(err, iCanvasVisualData->iCanvasPainter->HandleBufferL(aDisplayRect, aAction, *this, aGc, DisplayRect().iTl.Round()));
         if (err)
         	{
         	HUI_DEBUG2(_L("CHuiCanvasVisual::HandleBufferL returned:%d command type was: %d"), err,iCanvasVisualData->iCommandSetType);
@@ -449,6 +449,7 @@
 
     // Flag to know what we did
     TBool didDrawEffect = EFalse;
+    TBool drawChildren = ETrue; // only if didDrawEffect holds
     
     if (EffectActive())
         {
@@ -474,21 +475,38 @@
             refreshCache |= Display()->RosterImpl().NativeAppsContentChanged();
             }
         Effectable()->EffectSetOpacityAdditive(0.0f, ETrue);
+        
         // PrepareDraw will update iEffectOpacity to correct opacity for this effect frame        
         if(Effect()->PrepareDrawL(aGc, area))
             {
 			// let's still check if effect is making visual fully transparent
-            if(CanSkipDrawing())
+            if(!CanSkipDrawing())
                 {
-                return;
+                // Note that EHuiVisualFlagOpaqueHint improves performance a lot in cached effect drawing 
+                TBool transparent = EFalse; 
+                
+                // This is special case, only child below group visual.
+                // Workaround - can be removed once opaque & transparent visual hierarchies are handled better.
+                if ( !Layout() && Count() == 1 ) 
+                    {
+                    const CHuiVisual* visual = &Visual(0);
+
+                    transparent |= (!(visual->Flags() & EHuiVisualFlagOpaqueHint)); // Does not have opaque hint -> always transparent
+                    transparent |= visual->iOpacity.Now() < 1.0f; // Opacity less than 1.0f -> always transparent
+                    transparent |= visual->Effect() && !visual->LoadingEffect() && (visual->iEffectOpacity < 1.0f); // effect opacity is less than 1.0f
+                    }
+
+                transparent |= (!(Flags() & EHuiVisualFlagOpaqueHint)); // Does not have opaque hint -> always transparent
+                transparent |= iOpacity.Now() < 1.0f; // Opacity less than 1.0f -> always transparent
+                transparent |= iEffectOpacity < 1.0f; // effect opacity is less than 1.0f
+                
+                didDrawEffect = Effect()->CachedDraw(aGc, area, refreshCache, !transparent, iCanvasVisualData->iPaintedRegion, layer );
                 }
-            // Note that EHuiVisualFlagOpaqueHint improves performance a lot in cached effect drawing 
-            TBool transparent = EFalse; 
-            transparent |= (!(Flags() & EHuiVisualFlagOpaqueHint)); // Does not have opaque hint -> always transparent
-            transparent |= iOpacity.Now() < 1.0f; // Opacity less than 1.0f -> always transparent
-            transparent |= iEffectOpacity < 1.0f; // effect opacity is less than 1.0f
-
-            didDrawEffect = Effect()->CachedDraw(aGc, area, refreshCache, !transparent, iCanvasVisualData->iPaintedRegion, layer );
+            else
+                {
+                didDrawEffect = ETrue;
+                drawChildren = EFalse;
+                }
             }
         }
     
@@ -507,12 +525,12 @@
         // Draw all children
         DrawCanvasChildren(aGc, 0, 0);
         }
-    else if (didDrawEffect && !EffectIsAppliedToChildren())
+    else if (didDrawEffect && drawChildren && !EffectIsAppliedToChildren())
         {
         // Draw all children
         DrawCanvasChildren(aGc, 0, 0);    
         }
-    else if (didDrawEffect && EffectIsAppliedToChildren())
+    else if (didDrawEffect && drawChildren && EffectIsAppliedToChildren())
         {
         // Draw only children which do not want to have parent effect applied to them
         DrawCanvasChildren(aGc, EHuiCanvasFlagExcludeFromParentEffect, 0);        
--- a/uiacceltk/hitchcock/coretoolkit/src/HuiEnv.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/coretoolkit/src/HuiEnv.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -1781,6 +1781,12 @@
     return iMemoryLevel;
     }
 
+EXPORT_C void CHuiEnv::HandleOutOfTextureMemory()
+    {
+    iCanvasTextureCache->HandleOutOfTextureMemory();
+    }
+
+
 EXPORT_C void CHuiEnv::Synchronize(TInt aId, MHuiSynchronizationObserver* aObserver)
     {
     TInt err = iSynchObservers.Append(aObserver);
--- a/uiacceltk/hitchcock/coretoolkit/src/HuiFxEffect.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/coretoolkit/src/HuiFxEffect.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -85,12 +85,11 @@
 
 EXPORT_C CHuiFxEffect::~CHuiFxEffect()
     {
+    ReleaseCachedRenderTarget();
+    
     delete iRoot;
     iRoot = NULL;
     NotifyEffectEndObserver();
-    
-    ReleaseCachedRenderTarget();
-    
     iEngine->RemoveEffect(this);
     if (iEngine && iGroupId != KErrNotFound && !(iFlags & KHuiReadyToDrawNotified))
         {
@@ -181,6 +180,11 @@
         iEngine->ReleaseRenderbuffer(iCachedRenderTarget);
         iCachedRenderTarget = NULL;
         }                
+    
+    if(iRoot)
+        {
+        iRoot->ReleaseAllCachedRenderTargets(*iEngine);
+        }
     }
 
 void CHuiFxEffect::PrepareCachedRenderTarget(const TPoint& aPosition, const TSize& aSize, TBool aClear, TBool aEnableBackground)
@@ -189,7 +193,8 @@
     if (iCachedRenderTarget && 
         iCachedRenderTarget->Size() != aSize)
         {
-        ReleaseCachedRenderTarget();
+        iEngine->ReleaseRenderbuffer(iCachedRenderTarget);
+        iCachedRenderTarget = NULL;
         }            
     
     // Accure new buffer
@@ -441,7 +446,11 @@
     else
         {
         // Release cached render target just in case it is reserved for some reason
-        ReleaseCachedRenderTarget();
+        if (iCachedRenderTarget)
+            {
+            iEngine->ReleaseRenderbuffer(iCachedRenderTarget);
+            iCachedRenderTarget = NULL;
+            }  
 
         // Use default onscreen render target
         if (!target)
--- a/uiacceltk/hitchcock/coretoolkit/src/HuiFxEffectParser.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/coretoolkit/src/HuiFxEffectParser.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -729,7 +729,7 @@
             TReal32 time = ParseFloatAttributeL(aNode, KLitAt);
             TReal32 aux1 = ParseFloatAttributeL(aNode, KLitAux1, EFalse);
             TReal32 aux2 = ParseFloatAttributeL(aNode, KLitAux2, EFalse);
-            VALUE_TYPE value = ParseAnimationKeyFrameValueL<PARAM_TYPE::ValueType, TIMELINE_TYPE>(aNode->FirstChild(), aTimeLine);
+            VALUE_TYPE value = ParseAnimationKeyFrameValueL<typename PARAM_TYPE::ValueType, TIMELINE_TYPE>(aNode->FirstChild(), aTimeLine);
             TRAPD(err, aTimeLine.AppendKeyFrameL(time, value, aux1, aux2));
             if (err != KErrNone)
                 {
--- a/uiacceltk/hitchcock/coretoolkit/src/HuiFxFilterLayer.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/coretoolkit/src/HuiFxFilterLayer.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -76,6 +76,10 @@
     return iFilter->PrepareDrawL(aEngine);
     }
 
+EXPORT_C void CHuiFxFilterLayer::ReleaseAllCachedRenderTargets(CHuiFxEngine& /*aEngine*/)
+    {
+    // currently filter effects do not permanently reserve their render targets, only for frame drawing.
+    }
 
 EXPORT_C TBool CHuiFxFilterLayer::Changed() const
     {
--- a/uiacceltk/hitchcock/coretoolkit/src/HuiFxGroupLayer.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/coretoolkit/src/HuiFxGroupLayer.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -171,6 +171,17 @@
     return ETrue;
     }
 
+EXPORT_C void CHuiFxGroupLayer::ReleaseAllCachedRenderTargets(CHuiFxEngine& aEngine)
+    {
+    // Currently grouplayer itself does not use any cached render buffers which it would not free right after drawing a frame
+
+    // still release all child layer's render targets
+    for( TInt i=0 ; i < iLayers.Count() ; i++ )
+        {
+        iLayers[i]->ReleaseAllCachedRenderTargets(aEngine);
+        }    
+    }
+
 EXPORT_C void CHuiFxGroupLayer::Draw(CHuiFxEngine& aEngine, CHuiGc& aGc, CHuiFxRenderbuffer& aTarget, 
                                      CHuiFxRenderbuffer& aSource, TBool aHasSurface)
     {
--- a/uiacceltk/hitchcock/coretoolkit/src/HuiFxLayer.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/coretoolkit/src/HuiFxLayer.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -63,6 +63,12 @@
     return ETrue;
     }
 
+EXPORT_C void CHuiFxLayer::ReleaseAllCachedRenderTargets(CHuiFxEngine& /*aEngine*/)
+    {
+    // Nothing to do
+    }
+
+
 EXPORT_C TBool CHuiFxLayer::VisualArea( TRect& /*aRect*/ )
     {
     // No area in base class
--- a/uiacceltk/hitchcock/coretoolkit/src/HuiFxVisualLayer.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/coretoolkit/src/HuiFxVisualLayer.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -206,10 +206,6 @@
 #ifdef HUIFX_TRACE    
     RDebug::Print(_L("CHuiFxVisualLayer::~CHuiFxVisualLayer - 0x%x "), this);
 #endif
-    if(iRenderBuffer && iEngine)
-        {
-        iEngine->ReleaseRenderbuffer(iRenderBuffer);
-        }
     
     delete iExtBitmapFile;
     delete iParameterManager;
@@ -240,6 +236,16 @@
     return ETrue;
     }
 
+EXPORT_C void CHuiFxVisualLayer::ReleaseAllCachedRenderTargets(CHuiFxEngine& aEngine)
+    {
+    if(iRenderBuffer)
+        {
+        aEngine.ReleaseRenderbuffer(iRenderBuffer);
+        iRenderBuffer = NULL;
+        }
+    }
+
+
 EXPORT_C void CHuiFxVisualLayer::Draw(CHuiFxEngine& aEngine, CHuiGc& aGc, CHuiFxRenderbuffer &aTarget, CHuiFxRenderbuffer& /*aSource*/, TBool /*aHasSurface*/)
     {
 #ifdef HUIFX_TRACE    
@@ -252,8 +258,7 @@
     
     if (iRenderBuffer && iRenderBuffer->Size() != backbufferSize)
         {
-        iEngine->ReleaseRenderbuffer(iRenderBuffer);
-        iRenderBuffer = NULL;
+        ReleaseAllCachedRenderTargets(aEngine);
         }
     
     if(!iRenderBuffer)
@@ -263,7 +268,6 @@
             {
             return;
             }
-        iEngine = &aEngine;
         forceRefresh = ETrue;
         }
     
@@ -538,7 +542,13 @@
     {
     if( iVisualContentOpaque != aOpaque || aChanged)
         {
-        iVisualContentChanged = aChanged;
+        iVisualContentChanged = ETrue;
         }
+    else
+        {
+        iVisualContentChanged = EFalse;
+        }
+    
     iVisualContentOpaque = aOpaque;
     }
+	
--- a/uiacceltk/hitchcock/coretoolkit/src/HuiGridLayout.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/coretoolkit/src/HuiGridLayout.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -273,7 +273,8 @@
     axis.iWeights.Reset();
     for(TInt i = 0; i < aWeights.Count(); ++i)
         {
-        THuiMetric weight(TReal32(aWeights[i]), EHuiUnitWeight);
+        TInt weightValue(aWeights[i]);
+        THuiMetric weight(TReal32(weightValue), EHuiUnitWeight); 
         User::LeaveIfError(axis.iWeights.Append(weight));
         }
     }
@@ -284,7 +285,8 @@
     axis.iWeights.Reset();
     for(TInt i = 0; i < aWeights.Count(); ++i)
         {
-        THuiMetric weight(TReal32(aWeights[i]), EHuiUnitWeight);
+        TInt weightValue(aWeights[i]);
+        THuiMetric weight(TReal32(weightValue), EHuiUnitWeight); 
         User::LeaveIfError(axis.iWeights.Append(weight));
         }
     }
--- a/uiacceltk/hitchcock/coretoolkit/src/HuiImageVisual.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/coretoolkit/src/HuiImageVisual.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -301,6 +301,11 @@
     // Actual color of the image.
     aGc.SetPenAlpha(TInt(effectiveOpacity * 255));
     aGc.SetPenColor(iColor);
+    
+    // Render Alf image visuals always with high quality. Otherwise scaling etc. with ALF apis
+    // might produce low-quality
+    const THuiQuality oldQuality = aGc.Quality(); // store the original quality
+    aGc.SetQuality(EHuiQualityAccurate);
 
     // Apply special color mode.
     if(iColorMode == EColorDimmed)
@@ -386,6 +391,8 @@
                 }
             }
         }
+    
+    aGc.SetQuality(oldQuality); // restore quality
 
     // Disable special color modes.
     if(iColorMode == EColorDimmed)
--- a/uiacceltk/hitchcock/coretoolkit/src/HuiVisual.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/coretoolkit/src/HuiVisual.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -45,10 +45,12 @@
     {
 public: // Functions
     // Constructor: initialize the data
-    THuiVisualPrivateData() : iTacticons(), iDropShadow(NULL)
+    THuiVisualPrivateData() 
+        : iTacticons(), iDropShadow(NULL), iEffect(NULL),
+          iEffectParser(NULL), iEffectable(NULL), iStoredRenderBuffer(NULL),
+          iStoredRenderBufferModificationsEnabled(ETrue),
+          iFreezed(EFalse)
         {
-        iEffect = NULL;
-        iEffectParser = NULL;
         }
         
     // Destructor: destruct the data
@@ -228,7 +230,6 @@
     {
     iVisualData = new (ELeave) THuiVisualPrivateData;
     iVisualData->iEffectable = new CHuiEffectable(this);
-    iVisualData->iStoredRenderBuffer = NULL;
     }
 
 
@@ -277,12 +278,15 @@
     delete iBrushes;
     delete iTag;
     delete iTransform;
-    delete iVisualData->iEffectable;
-    if (iVisualData->iStoredRenderBuffer)
+    if (iVisualData)
         {
-        iVisualData->iStoredRenderBuffer->UnInitialize();
+        delete iVisualData->iEffectable;
+        if (iVisualData->iStoredRenderBuffer)
+            {
+            iVisualData->iStoredRenderBuffer->UnInitialize();
+            }
+        delete iVisualData->iStoredRenderBuffer;
         }
-    delete iVisualData->iStoredRenderBuffer;
     delete iVisualData;
     
     iOwner = NULL;
--- a/uiacceltk/hitchcock/coretoolkit/src/huicanvaswspainter.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/coretoolkit/src/huicanvaswspainter.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -2754,7 +2754,15 @@
     if ( oldGc && oldGc != iCanvasWsGc )
         {
         oldGc->ClearCache();
+        
+        // delete SW rendering GC when not needed
+        if ( oldGc == iCanvasWsBitGc ) 
+            {
+            delete iCanvasWsBitGc;
+            iCanvasWsBitGc = NULL;
+            }
         }
+
     if ( iCanvasWsGc )
         {
         // Forward 'enable render buffer' setting to new GC.
--- a/uiacceltk/hitchcock/goommonitor/data/goomconfig.xml	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/goommonitor/data/goomconfig.xml	Thu Aug 19 10:48:02 2010 +0300
@@ -47,7 +47,7 @@
 <!--		The uid DEFAULT_APP refers to all applications, which priority is not specifically
 		defined in the conf file.
 -->
-		<close_app uid="DEFAULT_APP" priority="80" sync_mode="check" close_timeout="1000" wait_after_close="2000">
+		<close_app uid="DEFAULT_APP" priority="80" sync_mode="check" close_timeout="1000" wait_after_close="1000">
 			<app_close_idle_priority idle_time="900" priority="50"></app_close_idle_priority>
 			<app_close_idle_priority idle_time="43200" priority="20"></app_close_idle_priority>
 		</close_app>
@@ -79,8 +79,8 @@
 		defined in the conf file.
 -->
 		<system_plugin uid="DEFAULT_PLUGIN" priority="10" sync_mode="check" sw_rend="not_supported"></system_plugin>
-		<system_plugin uid="E4B6C988" priority="3" sync_mode="check" sw_rend="supported"></system_plugin> <!-- ALFOOGMPLUGIN -->
-		<system_plugin uid="2002DC75" priority="4" sync_mode="check" sw_rend="supported"></system_plugin> <!-- HbThemeserverOOGMPLUGIN? -->
+		<system_plugin uid="2002DC75" priority="3" sync_mode="continue" sw_rend="supported"></system_plugin> <!-- HbThemeserverOOGMPLUGIN? -->
+		<system_plugin uid="E4B6C988" priority="4" sync_mode="check" sw_rend="supported"></system_plugin> <!-- ALFOOGMPLUGIN -->
 		<system_plugin uid="2002C30A" priority="5" sync_mode="continue"></system_plugin> <!-- FLASHOOGMPLUGIN -->
 	</system_plugin_settings>
 	
--- a/uiacceltk/hitchcock/goommonitor/inc/goommemorymonitorsession.h	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/goommonitor/inc/goommemorymonitorsession.h	Thu Aug 19 10:48:02 2010 +0300
@@ -42,6 +42,7 @@
     TInt iFunction;
     TInt iMinimumMemoryRequested;
     TBool iUseAbsoluteTargets;
+    TUint iClientId;
     };
 
 #endif /*GOOMMEMORYMONITORSESSION_H*/
--- a/uiacceltk/hitchcock/goommonitor/src/goomactionlist.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/goommonitor/src/goomactionlist.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -235,7 +235,7 @@
     if (aWindowGroupList.Count())
             {
             // Go through each item in the wglist, create an app close action for this application
-            TInt wgIndex = aWindowGroupList.Count() - 1;
+            TInt wgIndex = 0;
             
             TRACES1("BuildActionListL: Windowgroup list count %d ",aWindowGroupList.Count());
     
@@ -246,7 +246,7 @@
     
             TRACES1("BuildActionListL: Foreground App %x ", foregroundUid);
             
-            while (wgIndex >= 0)
+            while (wgIndex < aWindowGroupList.Count())
                 {
                 CGOomCloseAppConfig* appCloseConfig = NULL;
     
@@ -256,7 +256,8 @@
                 
                 if(AppCloseActionAlreadyExists(aWindowGroupList, appId))
                     {
-                    wgIndex--;
+                    TRACES2("CGOomActionList::BuildKillAppActionListL - Action item already exists for this app %x wgid %d", appId, aWindowGroupList.WgId(wgIndex).iId)
+                    wgIndex++;
                     continue;
                     }
                     
@@ -318,7 +319,7 @@
                     TRACES3("BuildActionListL: Adding app to action list, Uid = %x, wgId = %d, wgIndex = %d", appId, wgId, wgIndex);
                     }
     
-                wgIndex--;
+                wgIndex++;
                 }
             }
             
@@ -334,7 +335,10 @@
         if(ref.Type() == TActionRef::EAppClose )
             {
             if(aWindowGroupList.AppIdfromWgId(ref.WgId(), ETrue) == appId)
+                {
+                TRACES2("CGOomActionList::AppCloseActionAlreadyExists AppId %x already added with wgid %d",appId, ref.WgId());
                 return ETrue;
+                }
             }
         }
         return EFalse;
@@ -661,19 +665,21 @@
     {
     FUNC_LOG;
 
-    TInt index = iCloseAppActions.Count();
-    TRACES1("CGOomCloseApp::AppNotExiting: count of actions %d",index);
+    TInt index = 0;
 
-    while (index--)
+    while (index < iCloseAppActions.Count())
         {
         CGOomCloseApp* action = iCloseAppActions[index];
-        TRACES3("CGOomCloseApp::AppNotExiting: %d %d %d", aWgId, action->WgId(), action->IsRunning());
+        TRACES3("CGOomCloseApp::AppNotExiting: recvd from %d , checking against %d , isRunning %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);
+            TRACES1("CGOomCloseApp::AppNotExiting: App with window group id %d has responded to the close event", aWgId);
             action->CloseAppEvent();
+            break;
             }
+        
+        index++;
         }
     }
 
--- a/uiacceltk/hitchcock/goommonitor/src/goomcloseapp.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/goommonitor/src/goomcloseapp.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -25,6 +25,7 @@
 #include "goomappclosetimer.h"
 #include "goomappclosewatcher.h"
 #include "goomactionref.h"
+#include "goommonitorsession.h"
 
 
 CGOomCloseApp* CGOomCloseApp::NewL(MGOomActionObserver& aStateChangeObserver, RWsSession& aWs)
--- a/uiacceltk/hitchcock/goommonitor/src/goommemorymonitor.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/goommonitor/src/goommemorymonitor.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -205,10 +205,9 @@
     FUNC_LOG;
     // keep only one notification active at a moment
 #ifdef USE_ASYNCYH_NOTIFICATIONS 
-   
+    TInt current = GetFreeMemory();
     if (aThreshold == EGL_PROF_TOTAL_MEMORY_USAGE_LT_NOK)
         {
-        TInt current = GetFreeMemory();
         if(current >= iGoodThreshold  && (!NeedToPostponeMemGood()))
             {
             TRACES2("FreeMemThresholdCrossedL : crossed good threshold Free %d, GThresh %d, Calling MemoryGood",current, iGoodThreshold);
@@ -230,15 +229,20 @@
         }
     else//if aThreshold == EGL_PROF_TOTAL_MEMORY_USAGE_GT_NOK
         {
-        TRACES1("FreeMemThresholdCrossedL : crossed low threshold %d", iLowThreshold);
-        iMemAllocationsGrowing->Stop();
-        iMemAllocationsGoingDown->Continue();
-        if((iTrigger == EGOomTriggerNone) && !NeedToPostponeMemGood())
+        if(current < iLowThreshold)
             {
-            if(iSynchTimer->IsActive())
-                iSynchTimer->Cancel();
-            StartFreeSomeRamL(iGoodThreshold, EGOomTriggerThresholdCrossed);
+            TRACES1("FreeMemThresholdCrossedL : crossed low threshold %d", iLowThreshold);
+            iMemAllocationsGrowing->Stop();
+            iMemAllocationsGoingDown->Continue();
+            if((iTrigger == EGOomTriggerNone) && !NeedToPostponeMemGood())
+                {
+                if(iSynchTimer->IsActive())
+                    iSynchTimer->Cancel();
+                StartFreeSomeRamL(iGoodThreshold, EGOomTriggerThresholdCrossed);
+                }
             }
+        else
+            TRACES2("FreeMemThresholdCrossedL : crossed low threshold %d, FALSE ALARM, FreeMem = %d", iLowThreshold, current);
         }
 #endif
     }
@@ -253,7 +257,17 @@
         {
         return;
         }
-    iForegroundAppUid = aForegroundAppUid;    
+    
+    if(iForegroundAppUid != aForegroundAppUid)
+        {
+        iForegroundAppUid = aForegroundAppUid;
+        iForegroundAppHasChanged = ETrue;
+        iRendswitched = 0;
+        }
+    else
+        {
+        iForegroundAppHasChanged = EFalse;
+        }
 
     // Refresh the low and good memory thresholds as they may have changed due to the new foreground application
     RefreshThresholds(aForegroundAppUid);
@@ -338,12 +352,25 @@
  
     if(aMemMode == EGOomLowMemMode)
         {
+        if(iRendswitched < 3)
+            iRendswitched ++;
+        else
+            return;
+        
         iLowOnMemWgs.Reset();
         iGOomWindowGroupList->GetListOfWindowGroupsWSurfaces(iLowOnMemWgs);
         event.SetType(KGoomMemoryLowEvent);
         }
     else
         {
+        if(iRendswitched > 0)
+            {
+            if(iRendswitched < 3)
+                iRendswitched ++;
+            else
+                return;
+            }
+    
         event.SetType(KGoomMemoryGoodEvent);
         }
     
--- a/uiacceltk/hitchcock/goommonitor/src/goommemorymonitorsession.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/goommonitor/src/goommemorymonitorsession.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -35,7 +35,7 @@
 CMemoryMonitorSession::~CMemoryMonitorSession()
     {
     FUNC_LOG;
-    Server().Monitor().SessionInCriticalAllocation(0,0);
+    Server().Monitor().SessionInCriticalAllocation(0,iClientId);
     CloseAppsFinished(0, EFalse);
     }
 
@@ -61,35 +61,35 @@
     RThread t;
     aMessage.Client(t);
     
-    TUint clientId = t.SecureId();
+    iClientId = t.SecureId();
     t.Close();
     
-    TRACES1("NEW REQUEST from client %x", clientId);
+    TRACES1("NEW REQUEST from client %x", iClientId);
     switch (aMessage.Function())
         {
         case EGOomMonitorRequestFreeMemory:
 
             //Do not take any more requests from the same client if previous request being served
-            if (!iRequestFreeRam.IsNull() && !Server().Monitor().IsSafeToProcessNewRequest(clientId))
+            if (!iRequestFreeRam.IsNull() && !Server().Monitor().IsSafeToProcessNewRequest(iClientId))
                 {
-                TRACES1("CANNOT PROCESS NEW REQUEST from %x", clientId);
+                TRACES1("CANNOT PROCESS NEW REQUEST from %x", iClientId);
                 aMessage.Complete(KErrInUse);
                 return;
                 }
             
-            Server().Monitor().SetActiveClient(clientId);
+            Server().Monitor().SetActiveClient(iClientId);
             // message will be completed when CloseAppsFinished() is called.
             if (aMessage.Int1() == 0)
                 {
                 iRequestFreeRam = aMessage;
 
-                Server().Monitor().SessionInCriticalAllocation(1, clientId);
+                Server().Monitor().SessionInCriticalAllocation(1, iClientId);
                 
                 TRAPD(err, Monitor().RequestFreeMemoryL(aMessage.Int0()));
                 if(err == KErrCompletion) 
                     {
                     TRACES("There is already enough memory - nothing to do");
-                    Server().Monitor().SessionInCriticalAllocation(0, clientId);
+                    Server().Monitor().SessionInCriticalAllocation(0, iClientId);
                     }
                 else if (err != KErrNone )
                     {
@@ -108,8 +108,8 @@
             break;
             
         case EGOomMonitorMemoryAllocationsComplete:
-            TRACES1("ServiceL : Memory Allocations complete from %x", clientId);
-            Server().Monitor().SessionInCriticalAllocation(0, clientId);
+            TRACES1("ServiceL : Memory Allocations complete from %x", iClientId);
+            Server().Monitor().SessionInCriticalAllocation(0, iClientId);
             aMessage.Complete(KErrNone);
             break;
 
@@ -118,7 +118,7 @@
                 {
                 iRequestFreeRam.Complete(KErrCancel);
                 }
-            Server().Monitor().SessionInCriticalAllocation(0, clientId);
+            Server().Monitor().SessionInCriticalAllocation(0, iClientId);
             aMessage.Complete(KErrNone);
             break;
 
@@ -128,11 +128,11 @@
             break;
 
         case EGOomMonitorRequestOptionalRam:
-            if (!iRequestFreeRam.IsNull() && !Server().Monitor().IsSafeToProcessNewRequest(clientId))
+            if (!iRequestFreeRam.IsNull() && !Server().Monitor().IsSafeToProcessNewRequest(iClientId))
                 {
                 aMessage.Complete(KErrInUse);
                 }
-            Server().Monitor().SetActiveClient(clientId);
+            Server().Monitor().SetActiveClient(iClientId);
             // message will be completed when CloseAppsFinished() is called.
             iRequestFreeRam = aMessage;
             iMinimumMemoryRequested = aMessage.Int1();
--- a/uiacceltk/hitchcock/goommonitor/src/goomrunplugin.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/goommonitor/src/goomrunplugin.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -57,6 +57,7 @@
     else
         {
         iPlugin.FreeRam(aBytesRequested, 0);
+        iFreeMemoryWithSwRenderingCalled = EFalse;
         }
 
     iFreeMemoryCalled = ETrue;
--- a/uiacceltk/hitchcock/goommonitor/src/goomwindowgrouplist.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/goommonitor/src/goomwindowgrouplist.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -241,23 +241,13 @@
     // Refresh window group list
     // get all window groups, with info about parents
     TInt numGroups = iWs.NumWindowGroups();
+    iWgIds.Reset();
     iWgIds.ReserveL(numGroups);
     User::LeaveIfError(iWs.WindowGroupList(&iWgIds));
     
     // 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
 
-    for (TInt i = iLowOnMemWgs.Count()-1; i>=0; i--)
-        {
-        iWs.SendEventToWindowGroup(iLowOnMemWgs[i], event);
-        }
-        
-#endif    
-*/    
     // Note the current foreground window ID (if there is one)
     TBool oldForegroundWindowExists = EFalse;
 
@@ -292,6 +282,7 @@
         TUint secureId = AppId(index,ETrue);
         TBool found = 0;
         TInt i = 0;
+        //TRACES1("Checking WG ID : %d", iWgIds[index].iId); 
         //todo - do we really need to check this list , when we have all ids in inactiveSurfaces[]
         for(i = 0; i < processIds.Count(); i++)
             {
@@ -316,8 +307,7 @@
             }
         
         if(!found)
-            {
-            TRACES1("Checking WG ID : %d", iWgIds[index].iId);             
+            {            
             for(TInt ii = 0; ii < inactiveSurfaces.Count(); ii++)
                 {
                 if (iWgIds[index].iId == inactiveSurfaces[ii] )
--- a/uiacceltk/hitchcock/plugins/alfoogmplugin/src/alfoogmplugin.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/plugins/alfoogmplugin/src/alfoogmplugin.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -51,7 +51,7 @@
 //
 CAlfOogmMonitorPlugin::~CAlfOogmMonitorPlugin()
     {
-    
+    iAlfDirectClient.Disconnect();
     }
 
 // -----------------------------------------------------------------------------
--- a/uiacceltk/hitchcock/plugins/alftranseffect/alftranseffectplugin/src/alfgfxeffects.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/plugins/alftranseffect/alftranseffectplugin/src/alfgfxeffects.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -143,6 +143,7 @@
     delete iPolicyHandler;
     delete iSysDisable;
     delete iEngine;
+    delete iSyncronizedGroupDefitionEndChecker;
     __ALFFXLOGSTRING("CAlfGfxEffects::~CAlfGfxEffects <<");
     }
     
--- a/uiacceltk/hitchcock/plugins/alftranseffect/alftranseffectplugin/src/alfserverdrawer.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/plugins/alftranseffect/alftranseffectplugin/src/alfserverdrawer.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -283,6 +283,7 @@
     delete iControlController;
     delete iFullScreenController;
     delete iFinishFullScreen;
+    delete iControlTimeout;
     delete iFullScreenTimeout;
     iActiveControlFx.Close();
 #ifdef USE_MODULE_TEST_HOOKS_FOR_ALF
--- a/uiacceltk/hitchcock/plugins/alftranseffect/alftranseffectplugin/src/states.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/plugins/alftranseffect/alftranseffectplugin/src/states.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -234,8 +234,7 @@
 			iEngine.SendAbortFullscreen();
 			return CRestingState::NewL(iEngine,iHandler);
 		case EFinishFullscreen:
-		    if ( ( iEngine.Action() == 1001 || iEngine.Action() == AknTransEffect::EApplicationExit ) &&
-		        !iEngine.EffectFinishedFullScreen() )
+		    if (!iEngine.EffectFinishedFullScreen())
 		        {
 		        iEngine.SendAbortFullscreen();
 		        }
--- a/uiacceltk/hitchcock/plugins/alftranseffect/alftranseffectplugin/src/wsserverdrawercontroller.cpp	Thu Jul 15 19:40:07 2010 +0300
+++ b/uiacceltk/hitchcock/plugins/alftranseffect/alftranseffectplugin/src/wsserverdrawercontroller.cpp	Thu Aug 19 10:48:02 2010 +0300
@@ -694,7 +694,6 @@
 		}
 #endif //WSSERVERDRAWER_TIME_LOG
 
-/////////////////////
 	if(aType == AknTransEffect::EParameterAvkonInternal)	
 		{ 
 		const TUid appuid = aUid1;