uiacceltk/hitchcock/ServerCore/Src/alfbridge.cpp
branchRCL_3
changeset 17 c9d868f1e20c
parent 15 cd0ae4656946
child 18 1801340c26a2
--- a/uiacceltk/hitchcock/ServerCore/Src/alfbridge.cpp	Mon Jun 21 16:41:52 2010 +0300
+++ b/uiacceltk/hitchcock/ServerCore/Src/alfbridge.cpp	Thu Jul 15 19:40:07 2010 +0300
@@ -196,6 +196,7 @@
     delete iEffectEndTimer;
     iDeadControlGroups.Close();
     iEffectWindowGroups.Close();
+    iWindowChainsArray.Close();
     delete iFSFxData;
     delete iFSFXDataPart2;
 
@@ -269,7 +270,11 @@
 void CAlfBridge::RegisterFadeEffectL()
     {
     // TODO: RND, REMOVE MMC DRIVE-F, WHEN NOT REQUIRED FOR TESTING
+#ifdef USE_ALTERNATIVE_EFFECTS_FROM_MMC
     _LIT(KDrivePrefence,"FZC"); 
+#else
+    _LIT(KDrivePrefence,"Z");
+#endif
     // Force register fade effect. Try first MMC, then ROM.
     CHuiFxEngine* engine = iHuiEnv->EffectsEngine();
     RFs& fs = CHuiStatic::FsSession();
@@ -460,7 +465,57 @@
     while(node);
 	return NULL;
     }
-	
+
+// ---------------------------------------------------------------------------
+// FindChainedGroup
+// ---------------------------------------------------------------------------
+// 
+TUint32 CAlfBridge::FindChainedGroup(
+    TUint32 aTreeNodeId)
+    {
+    THashMapIter<TUint32, TChainData> iter(iWindowChainsArray);
+    TChainData const * data = 0;
+    do
+        {
+        data = iter.NextValue();
+        if (data && data->iParent == aTreeNodeId)
+            {
+            TUint32 chainedTo = FindChainedGroup(data->iChainee);
+            if (!chainedTo)
+                {
+                return data->iChainee; 
+                }
+            else
+                {
+                return chainedTo;
+                }
+            }
+        }
+    while(data);
+    return NULL;
+    }
+
+// ---------------------------------------------------------------------------
+// IsChainedGroup
+// ---------------------------------------------------------------------------
+// 
+TBool CAlfBridge::IsChainedGroup(
+    TUint32 aTreeNodeId)
+    {
+    THashMapIter<TUint32, TChainData> iter(iWindowChainsArray);
+    TChainData const * data = 0;
+    do
+        {
+        data = iter.NextValue();
+        if (data && data->iChainee == aTreeNodeId)
+            {
+            return ETrue;
+            }
+        }
+    while(data);
+    return EFalse;
+    }
+
 // ---------------------------------------------------------------------------
 // ---------------------------------------------------------------------------
 // 
@@ -480,13 +535,13 @@
 // FindClientWindowGroupId
 // ---------------------------------------------------------------------------
 //
-TInt CAlfBridge::FindClientWindowGroupId( TInt aScreenNumber, CHuiControlGroup& aControlGroup  )
-    {
-    for (TInt i=0; i<iAlfScreens[aScreenNumber]->iControlGroups.Count();i++)
-        {
-        if( iAlfScreens[aScreenNumber]->iControlGroups[i].iControlGroup == &aControlGroup )
-            {
-            return iAlfScreens[aScreenNumber]->iControlGroups[i].iClientWindowGroupId;
+TInt CAlfBridge::FindClientWindowGroupId(CHuiControlGroup& aControlGroup  )
+    {
+    for (TInt i=0; i<iAlfScreens[0]->iControlGroups.Count();i++)
+        {
+        if( iAlfScreens[0]->iControlGroups[i].iControlGroup == &aControlGroup )
+            {
+            return iAlfScreens[0]->iControlGroups[i].iClientWindowGroupId;
             }
         }
     return KErrNotFound;
@@ -496,13 +551,13 @@
 // FindWindowGroupNodeId
 // ---------------------------------------------------------------------------
 //
-TInt CAlfBridge::FindWindowGroupNodeId( TInt aScreenNumber, CHuiControlGroup& aControlGroup ) const
-    {
-    for (TInt i=0; i<iAlfScreens[aScreenNumber]->iControlGroups.Count();i++)
-        {
-        if( iAlfScreens[aScreenNumber]->iControlGroups[i].iControlGroup == &aControlGroup )
-            {
-            return iAlfScreens[aScreenNumber]->iControlGroups[i].iWindowGroupNodeId;
+TInt CAlfBridge::FindWindowGroupNodeId(CHuiControlGroup& aControlGroup ) const
+    {
+    for (TInt i=0; i<iAlfScreens[0]->iControlGroups.Count();i++)
+        {
+        if( iAlfScreens[0]->iControlGroups[i].iControlGroup == &aControlGroup )
+            {
+            return iAlfScreens[0]->iControlGroups[i].iWindowGroupNodeId;
             }
         }
     return KErrNotFound;
@@ -576,6 +631,28 @@
     }
 
 // ---------------------------------------------------------------------------
+// FindControlGroupBySecureId
+// May return multiple groups
+// ---------------------------------------------------------------------------
+//
+void CAlfBridge::FindControlGroupBySecureId( TInt aSecureId, RPointerArray<CHuiControlGroup>& aGroupList)
+    {
+    if ( aSecureId == 0 )
+        {
+        return;
+        }
+    
+    for ( TInt i = 0; i < iAlfScreens[0]->iControlGroups.Count(); i++ )
+        {
+        TAlfControlGroupEntry& groupEntry = iAlfScreens[0]->iControlGroups[i];
+        if ( groupEntry.iSecureId == aSecureId )
+            {
+            aGroupList.Append(groupEntry.iControlGroup);
+            }
+        }        
+    }
+
+// ---------------------------------------------------------------------------
 // FindControlGroupByFullScreenToEffect
 // ---------------------------------------------------------------------------
 //
@@ -794,7 +871,7 @@
             TInt aSecureId,
             TInt aScreenNumber )
     {
-    CHuiControlGroup* group = FindControlGroup(aWindowGroupNodeId,aScreenNumber);
+    CHuiControlGroup* group = FindControlGroup(aWindowGroupNodeId);
     if (!group)
         {
         group = &iHuiEnv->NewControlGroupL(aWindowGroupNodeId); 
@@ -1089,14 +1166,14 @@
                        {
                        lSyncDone = ETrue;
                        CHuiControlGroup &lGroup = aRoster.ControlGroup(i+1);
-                       TInt clientWindowGroupId = FindClientWindowGroupId( aScreenNumber, lGroup );
+                       TInt clientWindowGroupId = FindClientWindowGroupId(lGroup );
                        iAppUi->AdjustWindowGroupPositionL(clientWindowGroupId,CAlfAppServer::EBehindOfParent);
                        }
                        if(!lSyncDone && aGroup.iAlfApp && aRoster.ControlGroup(i-1).ResourceId() != iAlfWindowGroupNodeId )
                            {
                           
                           CHuiControlGroup &lGroup = aRoster.ControlGroup(i);
-                          TInt clientWindowGroupId = FindClientWindowGroupId( aScreenNumber, lGroup );
+                          TInt clientWindowGroupId = FindClientWindowGroupId(lGroup );
                           iAppUi->AdjustWindowGroupPositionL(clientWindowGroupId,CAlfAppServer::EBehindOfParent);
                            }
                        break;
@@ -1145,7 +1222,7 @@
                 {
                 iAlfWindowGroupNodeId = iAlfScreens[0]->iControlGroups[i].iWindowGroupNodeId;
                 
-                CHuiControlGroup* controlGroup = FindControlGroup(iAlfWindowGroupNodeId, 0);
+                CHuiControlGroup* controlGroup = FindControlGroup(iAlfWindowGroupNodeId);
                 CHuiControl& control = controlGroup->Control(0);
                 CHuiVisual* layout = &control.Visual(0);
                 iAlfScreens[0]->iDisplay->Roster().SetAlfEventWindow(layout);
@@ -1279,7 +1356,7 @@
                 numBuf.AppendNum(fps, TRealFormat(5,1));
                 TRAP_IGNORE(
                         {
-                        iAlfScreens[screenNumber]->iFPSText->SetTextL( numBuf );
+                        iAlfScreens[0]->iFPSText->SetTextL( numBuf );
                         })
                 }
             }
@@ -1290,10 +1367,10 @@
             iActivated = (err == KErrNone);            
             }
                     
-        if (iAlfScreens[screenNumber]->IsVisualTreeVisibilityChanged())
+        if (iAlfScreens[0]->IsVisualTreeVisibilityChanged())
             {
             HandleVisualVisibility( screenNumber );    
-            iAlfScreens[screenNumber]->SetVisualTreeVisibilityChanged(EFalse);
+            iAlfScreens[0]->SetVisualTreeVisibilityChanged(EFalse);
             }
         }
     }
@@ -1356,7 +1433,10 @@
     transparent |= (!((aVisual.Flags() & EHuiVisualFlagOpaqueHint) == EHuiVisualFlagOpaqueHint));
     transparent |= (aVisual.iOpacity.Now() < KAlfVisualDefaultOpacity);
     transparent |= (aVisual.iOpacity.Target() < KAlfVisualDefaultOpacity);
-    
+    if(aVisual.Effect())
+        {
+        transparent |= (aVisual.iEffectOpacity < KAlfVisualDefaultOpacity);
+        }
     return  !transparent;            
     }
 
@@ -1487,6 +1567,7 @@
 	
 	TBool alfWindowGroupFoundVisible = EFalse;
 	TBool alfClientWindowGroupVisible = EFalse;
+	TBool firstAlfControlGroupFound = EFalse;
 	
     AMT_SET_VALUE( iVisibleVisualCount, 0 );
 	
@@ -1539,7 +1620,7 @@
                 }
             // !fullscreenCovered need to be checked because for fullscreen
             // alf applications alf event window group could be on top of alf client windowgroup
-            if ( (alfClientWindowGroupVisible || !fullscreenCovered)  && activeSession)
+            if ( (!firstAlfControlGroupFound || !fullscreenCovered)  && activeSession)
                 {
                 // clear inactive flag if client has not made this controlgroup hidden
                 if(!(flags&EHuiVisualFlagUnderOpaqueHint))
@@ -1560,7 +1641,7 @@
                             iTempRegion.AddRect(fullscreen);
                             iTempRegion.Tidy();
                             fullscreenCovered = ETrue;
-                            alfClientWindowGroupVisible = EFalse;  // change flag so that we don't go in this branch again
+                            firstAlfControlGroupFound = ETrue;  // change flag so that we don't go in this branch again
                             }
                         }
                     }
@@ -1630,9 +1711,56 @@
                    subTreeCovered, hasLayers, IsVisualOpaque(*layout) );
             }
         
-
-        TBool hasFadeEffectsInVisualTree = (layout->CanvasFlags() & EHuiCanvasFlagExternalFadeExistsInsideVisualTree);        
-
+        if ( hasLayers && iActivated )
+            {
+            HandleLayerVisibility( layout, controlgroup, control, hasActiveVisualsInVisualTree );
+            }
+        
+        TBool isLayoutActive = !(layout->Flags() & EHuiVisualFlagInactive);        
+        
+        // we need to set /clear inactive flags before we evaluate the fade effect,
+        // otherwise the fade effect will be removed without a reason in
+        // some use cases
+        if (isLayoutActive && (fullscreenCovered || (!hasActiveVisualsInVisualTree && !IsOpaqueEffect(layout->Effect()))))
+            {
+            // don't inactivate alf event wg if alf client is visible
+            if( !( alfClientWindowGroupVisible && (controlgroup.ResourceId() == iAlfWindowGroupNodeId)) )
+                // Setting also the root visual (layout) as inactive, if it had none
+                // active children. This is because otherwise the Inactive checks won't
+                // work correctly within RosterImpl ScanDirty & ClearChanged phases.
+                // If root visual is having an opaque effect, it must remain active
+                {
+                layout->SetFlag(EHuiVisualFlagInactive);
+                }
+            }
+        else if(!isLayoutActive && !fullscreenCovered && (hasActiveVisualsInVisualTree || IsOpaqueEffect(layout->Effect())) ||
+                (alfClientWindowGroupVisible && (controlgroup.ResourceId() == iAlfWindowGroupNodeId)) )
+            {
+            layout->ClearFlag(EHuiVisualFlagInactive);
+            layout->SetPos(fullscreen.iTl);
+            layout->SetSize(fullscreen.Size());
+            
+		    // New visible window group may have received effect just before appearing to the screen.
+			// start the effect if this is the case.
+            if(iFSFxData && iFSFxData->iToSecureId == controlgroup.SecureId() )
+                {
+                TInt windowGroupId = FindClientWindowGroupId(controlgroup);
+
+                if (iFSFxData->iToWg == windowGroupId && iFSFxData->State() == EWaitEndFullScreen &&
+                        iFSFxData->iTwoPhaseEffect <= CFullScreenEffectState::ESecondPartActive)
+                    {
+                    GfxTriggerEffectWhenFullScreenDrawn(&controlgroup);
+                    }
+                }
+            }
+
+        // If root visuals effect is marked as opaque, then add whole screen area as covered.
+        if (!fullscreenCovered)
+            {
+            fullscreenCovered = IsOpaqueEffect(layout->Effect());
+            }    
+
+        
         // if native alf app is found visible and the client it self is not covering whole screen, we can assume that alf content
         // fills the rest. 
         // this is for embedded native alf application cases. Otherwise chained window groups tend to
@@ -1649,39 +1777,9 @@
                 alfClientWindowGroupVisible = ETrue;
                 }
             }
-        
-        // If root visuals effect is marked as opaque, then add whole screen area as covered.
-        if (!fullscreenCovered)
-            {
-            fullscreenCovered = IsOpaqueEffect(layout->Effect());
-            }                    
-        
-        if ( hasLayers && iActivated )
-            {
-            HandleLayerVisibility( layout, controlgroup, control, hasActiveVisualsInVisualTree );
-            }
-        
-        TBool isLayoutActive = !(layout->Flags() & EHuiVisualFlagInactive);        
-        
-        // we need to set /clear inactive flags before we evaluate the fade effect,
-        // otherwise the fade effect will be removed without a reason in
-        // some use cases
-        if (isLayoutActive && !hasActiveVisualsInVisualTree && !IsOpaqueEffect(layout->Effect()))
-            {
-            // Setting also the root visual (layout) as inactive, if it had none
-			// active children. This is because otherwise the Inactive checks won't
-			// work correctly within RosterImpl ScanDirty & ClearChanged phases.
-			// If root visual is having an opaque effect, it must remain active
-            layout->SetFlag(EHuiVisualFlagInactive);
-            }
-        else if(!isLayoutActive && (hasActiveVisualsInVisualTree || IsOpaqueEffect(layout->Effect())))
-            {
-            layout->ClearFlag(EHuiVisualFlagInactive);
-            layout->SetPos(fullscreen.iTl);
-            layout->SetSize(fullscreen.Size());
-            }
- 
             
+        TBool hasFadeEffectsInVisualTree = (layout->CanvasFlags() & EHuiCanvasFlagExternalFadeExistsInsideVisualTree);        
+
 		// If we layout is active setup the fade effects. Also if it is inactive, but has been
 		// flagged as containing fade effect, then run the setup as well so that effects which
 		// are no more needed get removed.
@@ -2452,14 +2550,12 @@
                 }
             case EAlfDSGroupChained:
             	{
-            	__ALFLOGSTRING("CAlfBridge::DoDispatchL, EAlfDSGroupChained");    
-            	// TODO, link groups 
+            	HandleGroupChained(data);
             	break;
             	}
             case EAlfDSGroupChainBroken:
             	{
-            	__ALFLOGSTRING("CAlfBridge::DoDispatchL, EAlfDSGroupChainBroken");    
-            	// TODO, break link
+            	HandleGroupChainBroken(data);
             	break;
             	}
             case EAlfDSMoveWindowToNewGroup:
@@ -2668,7 +2764,6 @@
 	TInt windowGroupNodeId = aData.iInt1;
 	TInt windowNodeId = aData.iInt2;
 	TAlfWindowAttributes* windowAttributes = (TAlfWindowAttributes*) (*iHost)->GetVarDataL( (TInt)aData.iPtr );
-	TInt screenNumber = windowAttributes->iScreenNumber; 
 	__ALFLOGSTRING1("CAlfBridge::HandleNewWindowL: new window %d!",windowNodeId);    
 	                
 	switch (windowAttributes->iWindowNodeType)
@@ -2679,7 +2774,8 @@
 			        windowGroupNodeId, 
 			        windowAttributes->iClientHandle, 
 			        windowAttributes->iSecureId,
-			        screenNumber);                            
+			        0 // Only one screen for avkon content supported 
+					);                            
 
 			// We just received notification for our own window group creation, store its node id for doing
 			// faster lookups later...
@@ -2695,11 +2791,11 @@
 		case EAlfWinTreeNodeSprite:
 		case EAlfWinTreeNodeTextCursor:
 			{
-			CHuiControlGroup* controlGroup = FindControlGroup(windowGroupNodeId,screenNumber);
+			CHuiControlGroup* controlGroup = FindControlGroup(windowGroupNodeId);
 			// Floating sprites only require own group. Normal sprites should behave as normal visuals.
 			if (!controlGroup && windowAttributes->iWindowNodeType == EAlfWinTreeNodeSprite )
 				{                            
-				controlGroup = iAlfScreens[screenNumber]->iFloatingSpriteControlGroup;
+				controlGroup = iAlfScreens[0]->iFloatingSpriteControlGroup;
 				}
 
 			if (controlGroup)
@@ -2718,7 +2814,7 @@
                     viz = CHuiCanvasVisual::AddNewL(control, layout);
 				    }
 
-				__ALFFXLOGSTRING2("CAlfBridge::HandleNewWindowL visual: 0x%x, id 0x%x", viz, windowNodeId);
+				__ALFFXLOGSTRING3("CAlfBridge::HandleNewWindowL visual: 0x%x, id 0x%x, Owner group Uid: 0x%x", viz, windowNodeId, viz->Owner().ControlGroup()->SecureId());
 				AddVisual( 
 				    windowNodeId, 
 					windowAttributes->iClientHandle, 
@@ -2777,7 +2873,7 @@
 			__ALFLOGSTRING("CAlfBridge::HandleNewWindowL: Unknown window node type received !");
 			}
 		}
-	iAlfScreens[screenNumber]->SetVisualTreeVisibilityChanged(ETrue);
+	iAlfScreens[0]->SetVisualTreeVisibilityChanged(ETrue);
 	}
 
 // ---------------------------------------------------------------------------
@@ -2860,14 +2956,13 @@
 	TInt windowNodeId = aData.iInt2;
 
 	TAlfWindowAttributes* windowAttributes = (TAlfWindowAttributes*) (*iHost)->GetVarDataL( (TInt)aData.iPtr );
-	TInt screenNumber = windowAttributes->iScreenNumber;
-
+	
 	switch (windowAttributes->iWindowNodeType)
 		{
 		case EAlfWinTreeNodeGroup:
 			{
 			HandleVisualVisibility(0);
-			DeleteControlGroupL(windowGroupNodeId, screenNumber);                            
+			DeleteControlGroupL(windowGroupNodeId);                            
 			break;    
 			}
 		case EAlfWinTreeNodeClient:
@@ -2887,7 +2982,7 @@
 			CHuiCanvasVisual* viz;
 			
 			viz = (CHuiCanvasVisual*)FindVisual(windowNodeId);
-			CHuiControlGroup* controlGroup = FindControlGroup( windowGroupNodeId, screenNumber );
+			CHuiControlGroup* controlGroup = FindControlGroup( windowGroupNodeId);
 		     // Sprite is in its own group, and can be deleted normally.
 			if ( !controlGroup  && windowAttributes->iWindowNodeType != EAlfWinTreeNodeSprite )
 			    {
@@ -2927,7 +3022,7 @@
 		}
 	// TODO: Toolkit does not support recycling (of visuals),
 	// this is not in line with Nokia environmental policy...
-	iAlfScreens[screenNumber]->SetVisualTreeVisibilityChanged(ETrue);
+	iAlfScreens[0]->SetVisualTreeVisibilityChanged(ETrue);
 	}
 
 // ---------------------------------------------------------------------------
@@ -2938,7 +3033,6 @@
 	{
 	TInt windowNodeId = aData.iInt2;
 	TAlfWindowAttributes* windowAttributes = (TAlfWindowAttributes*) (*iHost)->GetVarDataL( (TInt)aData.iPtr );
-	TInt screenNumber = windowAttributes->iScreenNumber;
 	// fetch visual
 	CHuiVisual* viz = FindVisual(windowNodeId);
 	if (viz)
@@ -2950,8 +3044,8 @@
 		    }
 #endif
 
-		viz->SetPos(windowAttributes->iPosition, windowAttributes->iTransitionTime);
-		  iAlfScreens[screenNumber]->SetVisualTreeVisibilityChanged(ETrue); // TODO: Check if really changed   
+        viz->SetPos(windowAttributes->iPosition, windowAttributes->iTransitionTime);
+        iAlfScreens[0]->SetVisualTreeVisibilityChanged(ETrue); // TODO: Check if really changed   
 		}
 	else
 		{
@@ -2973,7 +3067,6 @@
 	{
 	TInt windowNodeId = aData.iInt2;
 	TAlfWindowAttributes* windowAttributes = (TAlfWindowAttributes*) (*iHost)->GetVarDataL( (TInt)aData.iPtr );
-	TInt screenNumber = windowAttributes->iScreenNumber;
 	// fetch visual
 	CHuiVisual* viz = FindVisual(windowNodeId);
 	if (viz)
@@ -2990,7 +3083,7 @@
 		{
 		__ALFLOGSTRING("CAlfBridge::HandleSetWindowSizeL, EAlfDSSetWindowSize: Visual not found!");    
 		}   
-    iAlfScreens[screenNumber]->SetVisualTreeVisibilityChanged(ETrue);
+    iAlfScreens[0]->SetVisualTreeVisibilityChanged(ETrue);
     
     AMT_INC_COUNTER_IF(viz, iVisualSizeChangedCount );
     AMT_SET_VALUE_IF(viz, iLatestVisualExtentRect, TRect( windowAttributes->iPosition, windowAttributes->iSize ) );
@@ -3036,7 +3129,6 @@
 	{
 	TInt windowNodeId = aData.iInt2;
 	TAlfWindowAttributes* windowAttributes = (TAlfWindowAttributes*) (*iHost)->GetVarDataL( (TInt)aData.iPtr );
-	TInt screenNumber = windowAttributes->iScreenNumber;
 	// fetch visual
 	CHuiVisual* viz = FindVisual(windowNodeId);
 	if (viz)
@@ -3047,9 +3139,9 @@
             RDebug::Print(_L("CAlfBridge::HandleSetWindowOpacityL - Tracked visual"));
             }
 #endif
-		viz->iOpacity.Set(windowAttributes->iOpacity, windowAttributes->iTransitionTime);
-		  iAlfScreens[screenNumber]->SetVisualTreeVisibilityChanged(ETrue);  // TODO: Check if really changed  
-		}
+        viz->iOpacity.Set(windowAttributes->iOpacity, windowAttributes->iTransitionTime);
+        iAlfScreens[0]->SetVisualTreeVisibilityChanged(ETrue);  // TODO: Check if really changed  
+        }
 	else
 		{
 		__ALFLOGSTRING("CAlfBridge::HandleSetWindowOpacityL, EAlfDSSetWindowOpacity: Visual not found!");                                                
@@ -3064,7 +3156,6 @@
     {
 	TInt windowNodeId = aData.iInt2;
 	TAlfWindowAttributes* windowAttributes = (TAlfWindowAttributes*) (*iHost)->GetVarDataL( (TInt)aData.iPtr );
-	TInt screenNumber = windowAttributes->iScreenNumber;
 	// fetch visual
 	CHuiVisual* viz = FindVisual(windowNodeId);
 	if (viz)
@@ -3084,7 +3175,7 @@
 		    viz->SetFlag( EHuiVisualFlagOpaqueHint );
 		    }
 		
-	    iAlfScreens[screenNumber]->SetVisualTreeVisibilityChanged(ETrue);  // TODO: Check if really changed  
+	    iAlfScreens[0]->SetVisualTreeVisibilityChanged(ETrue);  // TODO: Check if really changed  
 		}
 	else
 		{
@@ -3100,7 +3191,6 @@
     {
     TInt windowNodeId = aData.iInt2;
     TAlfWindowAttributes* windowAttributes = (TAlfWindowAttributes*) (*iHost)->GetVarDataL( (TInt)aData.iPtr );
-    TInt screenNumber = windowAttributes->iScreenNumber;
     // fetch visual
     CHuiVisual* viz = FindVisual(windowNodeId);
     if (viz)
@@ -3125,7 +3215,7 @@
                 }
             }
         
-        iAlfScreens[screenNumber]->SetVisualTreeVisibilityChanged(ETrue);  // TODO: Check if really changed  
+        iAlfScreens[0]->SetVisualTreeVisibilityChanged(ETrue);  // TODO: Check if really changed  
         }
     else
         {
@@ -3142,7 +3232,6 @@
 	TInt windowNodeId = aData.iInt2;
 	TAny* ptr = (TAny*)(*iHost)->GetVarDataL( (TInt)aData.iPtr );
 	
-	TInt screenNumber = 0;
 	TPoint origin;
 	TInt count = 0;
 	RRegion region;
@@ -3150,7 +3239,7 @@
 	
 	    {
 	    RMemReadStream str(ptr, 4*sizeof(TInt32));	
-	    screenNumber = str.ReadInt32L(); 
+	    str.ReadInt32L(); // screen number, obsolete 
     	origin.iX = str.ReadInt32L();
 	    origin.iY = str.ReadInt32L();
 	    count = str.ReadInt32L();
@@ -3188,7 +3277,7 @@
 		CHuiCanvasVisual* canvas = static_cast<CHuiCanvasVisual*>(viz);
 		canvas->SetShape( origin, region );
 		
-		iAlfScreens[screenNumber]->SetVisualTreeVisibilityChanged(ETrue);
+		iAlfScreens[0]->SetVisualTreeVisibilityChanged(ETrue);
 		}
 	else
 		{
@@ -3207,7 +3296,6 @@
 	TInt windowGroupNodeId = aData.iInt1;
 	TInt windowNodeId = aData.iInt2;
 	TAlfWindowAttributes* windowAttributes = (TAlfWindowAttributes*) (*iHost)->GetVarDataL( (TInt)aData.iPtr );
-	TInt screenNumber = windowAttributes->iScreenNumber;
 	TInt ordinalPosition = windowAttributes->iOrdinalPosition;
 
 	switch (windowAttributes->iWindowNodeType)
@@ -3227,7 +3315,7 @@
 				}    
 			#endif
 
-			CHuiControlGroup* controlGroup = FindControlGroup(windowGroupNodeId,screenNumber);
+			CHuiControlGroup* controlGroup = FindControlGroup(windowGroupNodeId);
 			
             if (!controlGroup)
                 {
@@ -3235,11 +3323,11 @@
                 }
             ResolveAfterEffectAppearingApplicationL(controlGroup); // does nothing, if effect is not active on this control group
 			// Window server nodes are in inverted Z-order, we switch it here.
-			iAlfScreens[screenNumber]->iDisplay->Roster().Hide(*controlGroup);                            
+			iAlfScreens[0]->iDisplay->Roster().Hide(*controlGroup);                            
 			TInt wsWindowGroupCount = 0;
-			for (TInt i=0; i<iAlfScreens[screenNumber]->iDisplay->Roster().Count();i++)
+			for (TInt i=0; i<iAlfScreens[0]->iDisplay->Roster().Count();i++)
 				{
-                if (iAlfScreens[screenNumber]->iDisplay->Roster().ControlGroup(i).Control(0).Role()==EHuiWindowGroupContainer)
+                if (iAlfScreens[0]->iDisplay->Roster().ControlGroup(i).Control(0).Role()==EHuiWindowGroupContainer)
 					{
 					wsWindowGroupCount++;    
 					}
@@ -3257,16 +3345,16 @@
 				ordinalPosition = -1; // show at top ?    
 				}
 			
-			if (iAlfScreens[screenNumber]->iDisplay && controlGroup)
+			if (iAlfScreens[0]->iDisplay && controlGroup)
 				{
-				ShowControlGroupL(iAlfScreens[screenNumber]->iDisplay->Roster(), *controlGroup, ordinalPosition, screenNumber); 
+				ShowControlGroupL(iAlfScreens[0]->iDisplay->Roster(), *controlGroup, ordinalPosition); 
 				}
 			else
 				{
-				__ALFLOGSTRING2("CAlfBridge::HandleReorderWindowL, EAlfDSReorder: Control group not found! Screen: %d, Id: %d ", screenNumber, windowNodeId );        
+				__ALFLOGSTRING1("CAlfBridge::HandleReorderWindowL, EAlfDSReorder: Control group not found! Id: %d ", windowNodeId );        
 				}
 			
-			ReorderAlfControlGroupsL(screenNumber);                                        
+			ReorderAlfControlGroupsL();                                        
 			break;    
 			}
 		case EAlfWinTreeNodeClient:
@@ -3304,7 +3392,7 @@
 				}
 			else
 				{
-				__ALFLOGSTRING2("CAlfBridge::HandleReorderWindowL, EAlfDSReorder: Visual not found! Screen: %d, Id: %d ", screenNumber, windowNodeId );    
+				__ALFLOGSTRING1("CAlfBridge::HandleReorderWindowL, EAlfDSReorder: Visual not found! Id: %d ", windowNodeId );    
 				}                       
 			break;
 			}
@@ -3315,7 +3403,7 @@
 			}
 		}
   
-	iAlfScreens[screenNumber]->SetVisualTreeVisibilityChanged(ETrue); // TODO: Check if really changed
+	iAlfScreens[0]->SetVisualTreeVisibilityChanged(ETrue); // TODO: Check if really changed
 
 	AMT_MAP_BRIDGE_SET_ORDINAL_POSITION();
 	}
@@ -3329,7 +3417,6 @@
 	TInt windowGroupNodeId = aData.iInt1;
 	TInt windowNodeId = aData.iInt2;
 	TAlfWindowCommandBufferAttributes* bufferAttributes = (TAlfWindowCommandBufferAttributes*)(*iHost)->GetVarDataL( (TInt)aData.iPtr );
-	TInt screenNumber = bufferAttributes->iScreenNumber;
 
 	CHuiCanvasVisual* viz = (CHuiCanvasVisual*)FindVisual(windowNodeId);
 	
@@ -3341,7 +3428,7 @@
 #ifdef HUI_DEBUG_TRACK_DRAWING
         TBool tracking( EFalse );
 	CHuiControlGroup* controlGroup = FindControlGroup( windowGroupNodeId, screenNumber );
-	CAlfScreen* screen = iAlfScreens[screenNumber];
+	CAlfScreen* screen = iAlfScreens[0];
 	
 	//TInt clientWindowGroupId = FindClientWindowGroupId( screenNumber, *controlGroup );
 	// NOTE, THE FOLLOWING WServClientFileName MAY CAUSE DEADLOCK. 
@@ -3364,7 +3451,7 @@
 	        {
             // For performance resons, only set visual tree changed if this 
             // was the first buffer for the window. 
-	        iAlfScreens[screenNumber]->SetVisualTreeVisibilityChanged(ETrue);
+	        iAlfScreens[0]->SetVisualTreeVisibilityChanged(ETrue);
 	        }
 
 		TPtrC8 commands((TUint8*)bufferAttributes->iBuffer, bufferAttributes->iBufferLength);
@@ -3425,12 +3512,14 @@
 		}
 	else
 		{
-		__ALFLOGSTRING3("CAlfBridge::HandlePostCanvasBufferL, EAlfDSPostCanvasBuffer: Visual not found! Screen: %d, Id: %d, GroupId: %d ", screenNumber, windowNodeId, windowGroupNodeId );                                 
+		__ALFLOGSTRING2("CAlfBridge::HandlePostCanvasBufferL, EAlfDSPostCanvasBuffer: Visual not found! Id: %d, GroupId: %d ",  windowNodeId, windowGroupNodeId );                                 
 		}    
+	    // Uncomment the following for tracking which application is doing drawing
+        //__ALFFXLOGSTRING1("CAlfBridge::HandlePostCanvasBufferL 0x%x", viz->Owner().ControlGroup()->SecureId());
 #ifdef	USE_APPLICATION_ENDFULLSCREEN_TIMEOUT	
 	    if (iFSFxData
 	            && iFSFxData->iEffectType != CFullScreenEffectState::ENotDefinedEffect 
-	            && ((iFSFxData->State() == EWaitEndFullScreen && iFSFxData->iTwoPhaseEffect <= CFullScreenEffectState::EFirstPartRunning)))
+	            && ((iFSFxData->State() == EWaitEndFullScreen && iFSFxData->iTwoPhaseEffect <= CFullScreenEffectState::ESecondPartActive)))
 	        {
 	        CHuiControlGroup *to_group = NULL;
             if (iFSFxData->iEffectType == CFullScreenEffectState::EExitEffect)
@@ -3505,6 +3594,7 @@
     TInt effectIndex;
     if (!HasActiveEffect(aVisual, effectIndex))
         {
+        __ALFFXLOGSTRING2("CAlfBridge::SetWindowActiveL 0x%x - New state: %d", aVisual, aActive);
         // Does not have effect
         if (aActive)
             {
@@ -3570,7 +3660,6 @@
 	TInt windowGroupNodeId = aData.iInt1;
 	TInt windowNodeId = aData.iInt2;
 	TAlfWindowAttributes* windowAttributes = (TAlfWindowAttributes*)(*iHost)->GetVarDataL( (TInt)aData.iPtr );
-	TInt screenNumber = windowAttributes->iScreenNumber;
 
     if (windowAttributes->iWindowNodeType == EAlfWinTreeNodeTextCursor && iCursorTimer)
 	    {
@@ -3589,7 +3678,7 @@
 		{
 		case EAlfWinTreeNodeGroup:
 			{
-			CHuiControlGroup* controlGroup = FindControlGroup(windowGroupNodeId,screenNumber);
+			CHuiControlGroup* controlGroup = FindControlGroup(windowGroupNodeId);
 			if (controlGroup)
 				{
 				CHuiControl& control = controlGroup->Control(0);
@@ -3635,7 +3724,7 @@
 			break;                       	        
 			}
 		}
-    iAlfScreens[screenNumber]->SetVisualTreeVisibilityChanged(ETrue);	// TODO: Check if really changed                       
+    iAlfScreens[0]->SetVisualTreeVisibilityChanged(ETrue);	// TODO: Check if really changed                       
 
     AMT_INC_COUNTER( iTotalVisualFlagChangedCount );
     AMT_INC_COUNTER_IF( windowAttributes->iActive, iActiveVisualCount );
@@ -3657,7 +3746,6 @@
     TInt windowGroupNodeId = aData.iInt1;
     TInt windowNodeId = aData.iInt2;
     TAlfWindowAttributes* windowAttributes = (TAlfWindowAttributes*)(*iHost)->GetVarDataL( (TInt)aData.iPtr );
-    TInt screenNumber = windowAttributes->iScreenNumber;
     TInt windowFlag = windowAttributes->iActive;
     THuiVisualFlags visualFlag = (THuiVisualFlags)0;
     switch(windowFlag)
@@ -3679,7 +3767,7 @@
         {
         case EAlfWinTreeNodeGroup:
             {
-            CHuiControlGroup* controlGroup = FindControlGroup(windowGroupNodeId,screenNumber);
+            CHuiControlGroup* controlGroup = FindControlGroup(windowGroupNodeId);
             if (controlGroup)
                 {
                 CHuiControl& control = controlGroup->Control(0);
@@ -3740,7 +3828,7 @@
             break;                                  
             }
         }
-    iAlfScreens[screenNumber]->SetVisualTreeVisibilityChanged(ETrue); // TODO: Check if really changed                       
+    iAlfScreens[0]->SetVisualTreeVisibilityChanged(ETrue); // TODO: Check if really changed                       
     }
 
 // ---------------------------------------------------------------------------
@@ -3824,7 +3912,6 @@
 	TInt windowGroupNodeId = aData.iInt1;
 	TInt windowNodeId = aData.iInt2;
 	TAlfWindowAttributes* windowAttributes = (TAlfWindowAttributes*)(*iHost)->GetVarDataL( (TInt)aData.iPtr );
-	TInt screenNumber = windowAttributes->iScreenNumber;
 	// fetch visual
 	CHuiCanvasVisual* viz = FindVisual(windowNodeId);
 
@@ -3860,7 +3947,7 @@
 		if (iAlfWindowGroupNodeId != windowGroupNodeId)
 		    __ALFLOGSTRING("CAlfBridge::HandleSetSurfaceExtentL, EAlfDSSetSurfaceExtent: Visual not found!");    
 		}                            
-    iAlfScreens[screenNumber]->SetVisualTreeVisibilityChanged(ETrue); // TODO: Check if really changed   
+    iAlfScreens[0]->SetVisualTreeVisibilityChanged(ETrue); // TODO: Check if really changed   
 	}
 
 // ---------------------------------------------------------------------------
@@ -3872,7 +3959,6 @@
     TInt windowGroupNodeId = aData.iInt1;
     TInt windowNodeId = aData.iInt2;
     TAlfWindowAttributes* windowAttributes = (TAlfWindowAttributes*)(*iHost)->GetVarDataL( (TInt)aData.iPtr );
-    TInt screenNumber = windowAttributes->iScreenNumber;
     
     // fetch visual
     CHuiCanvasVisual* viz = (CHuiCanvasVisual*)FindVisual(windowNodeId);
@@ -3889,7 +3975,7 @@
         if (iAlfWindowGroupNodeId != windowGroupNodeId)
             __ALFLOGSTRING("CAlfBridge::HandleLayerUsesAlphaFlagChanged: Visual not found!");    
         }                            
-    iAlfScreens[screenNumber]->SetVisualTreeVisibilityChanged(ETrue); // TODO: Check if really changed   
+    iAlfScreens[0]->SetVisualTreeVisibilityChanged(ETrue); // TODO: Check if really changed   
     }
 
 
@@ -4334,6 +4420,45 @@
     return (didFadeEffectLoad || alreadyFaded);
     }
 
+// ---------------------------------------------------------------------------
+//	HandleGroupChained
+//
+// 	Chain information is used for redirecting effects to correct windowgroup
+// ---------------------------------------------------------------------------
+//
+void CAlfBridge::HandleGroupChained( TAlfBridgerData& aData)
+    {
+    TInt parentId = aData.iInt1;
+    TInt chainedId = aData.iInt2;
+       
+    TChainData data(parentId, chainedId);
+    iWindowChainsArray.Insert(parentId,data);
+    __ALFFXLOGSTRING3("CAlfBridge::DoDispatchL, EAlfDSGroupChained %d chained to %d (host), iWindowChainsArray.Count() = %d", chainedId, parentId, iWindowChainsArray.Count());
+#ifdef _ALF_FXLOGGING
+    CHuiControlGroup* parent = FindControlGroup(parentId);
+    CHuiControlGroup* chained = FindControlGroup(chainedId);
+
+    if (parent)
+        {
+        RDebug::Printf("CAlfBridge::DoDispatch - parent: 0x%x", parent->SecureId());
+        }
+    if (chained)
+        {
+        RDebug::Printf("CAlfBridge::DoDispatch - chained: 0x%x", chained->SecureId());
+        }
+#endif
+    } 
+
+// ---------------------------------------------------------------------------
+// HandleGroupChainBroken
+// ---------------------------------------------------------------------------
+//
+void CAlfBridge::HandleGroupChainBroken( TAlfBridgerData& aData)
+    {
+    TInt parentId = aData.iInt2;
+    iWindowChainsArray.Remove(parentId);
+    __ALFFXLOGSTRING2("CAlfBridge::DoDispatchL, EAlfDSGroupChainBroken - parent: %d, iWindowChainsArray.Count() = %d", parentId, iWindowChainsArray.Count());
+    }
 
 // ---------------------------------------------------------------------------
 // HandleMoveWindowToNewGroupL
@@ -4342,7 +4467,6 @@
 void CAlfBridge::HandleMoveWindowToNewGroupL( TAlfBridgerData& aData )
     {
     TInt windowNodeId = aData.iInt1;
-    TInt screenNumber = aData.iInt2;
     TInt newWindowGroupNodeId = (TInt)aData.iPtr;
    
     CHuiCanvasVisual* viz = (CHuiCanvasVisual*)FindVisual(windowNodeId);
@@ -4352,7 +4476,7 @@
     TInt oldWindowGroupId = 0; 
     if ( oldControlGroup  )
         {
-        oldWindowGroupId = FindWindowGroupNodeId(screenNumber, *oldControlGroup );
+        oldWindowGroupId = FindWindowGroupNodeId(*oldControlGroup );
         }   
     __ALFLOGSTRING3("CAlfBridge::HandleMoveWindowToNewGroupL moving nodeId 0x%x from group 0x%x to 0x%x ",windowNodeId, oldWindowGroupId, newWindowGroupNodeId );
 #endif
@@ -4386,7 +4510,7 @@
         viz->Owner().Remove(viz);
         
         // #2 insert visual to the beginning of the new group
-        CHuiControlGroup* newControlGroup = FindControlGroup(newWindowGroupNodeId,screenNumber);
+        CHuiControlGroup* newControlGroup = FindControlGroup(newWindowGroupNodeId);
         if (newControlGroup)
             {
             CHuiControl& newControl = newControlGroup->Control(0);
@@ -4432,7 +4556,7 @@
         }
     else
         {
-        CHuiControlGroup* cg = FindControlGroup(windowNodeId, 0); // TODO: Screen            
+        CHuiControlGroup* cg = FindControlGroup(windowNodeId); // TODO: Screen            
         if (cg) 
             {
             CHuiControl& control = cg->Control(0);
@@ -4624,11 +4748,101 @@
         }
     }
 
-TBool CAlfBridge::HandleGfxEventL(CFullScreenEffectState& aEvent, CHuiLayout* aToLayout, CHuiLayout *aFromLayout)
+// ---------------------------------------------------------------------------
+// HandleGfxRedirection
+//
+// This effect might have been request for the host application, while the intent was to show it on the application started embedded.
+// Embedded application has its _own_ windowgroup separate from the host application. Fullscreen effect are shown on a windowgroup level.
+// e.g. Messaging -> New Message (editor), or Settings -> Themes (application)
+// Wserv notifies us the window group chaining of applications. See HandleGroupChained and HandleGroupChainBroken for more details. This code
+// will redirect the requested effect on correct windowgroup.
+//
+// NOTE! If embedded application effects are implemented, this will need revision
+// ---------------------------------------------------------------------------
+    
+void CAlfBridge::HandleGfxRedirection(CFullScreenEffectState& aEvent, CHuiLayout*& aToLayout)
+    {
+    TInt windowGroupNodeId = FindWindowGroupNodeId(*((*aToLayout).Owner().ControlGroup()));
+    CHuiControlGroup* chainedGroup = NULL;
+    
+    // check, if the effect is being asked for chained application. This propably indicates that there are two or more instances of it and 
+    // effect was supposed to go to the single standalone instance
+    if (IsChainedGroup(windowGroupNodeId))
+        { 
+        RPointerArray<CHuiControlGroup> groupList;
+        FindControlGroupBySecureId(aEvent.iToSecureId, groupList);
+        TInt i = groupList.Count();
+        TInt standaloneGroups = 0;
+        while(--i >= 0)
+            {
+            windowGroupNodeId = FindWindowGroupNodeId(*groupList[i]);
+            
+            if (!IsChainedGroup(windowGroupNodeId))
+                {
+                // This is an educated guess, which will make the standalone version to have effect. 
+                // Currently (tm) standard appstart effect is never requested for embbedded instances. 
+                chainedGroup = groupList[i];
+                standaloneGroups++;
+                __ALFFXLOGSTRING2("CAlfBridge::HandleGfxRedirection - Wg id: %d is NOT chained. Index: %d",windowGroupNodeId, i);
+                }
+            else
+                {
+                __ALFFXLOGSTRING2("CAlfBridge::HandleGfxRedirection - Wg id: %d IS chained. Index: %d", windowGroupNodeId, i);
+                }
+            }
+        groupList.Close();
+        // If there are multiple standalone app groups (e.g. single application having multiple groups), effecting anything would be a guess.
+        if (standaloneGroups>1)
+            {
+            chainedGroup = NULL;
+            aEvent.iIsRedirected = ETrue;
+            if (iFSFXDataPart2)
+                {
+                iFSFXDataPart2->iIsRedirected = ETrue;
+                }
+            }
+        }
+    else
+        {
+        // Which group is chained to this group?
+        TUint32 chainedId = FindChainedGroup(windowGroupNodeId); 
+        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());
+        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;
+            }
+        }
+    }
+
+// ---------------------------------------------------------------------------
+// HandleGfxEventL
+//
+// ---------------------------------------------------------------------------
+//
+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 - To layout: 0x%x, From layout: 0x%x, Effect handle: %d, Action: %d", aToLayout, aFromLayout, aEvent.iHandle, aEvent.iAction);
-    
+    __ALFFXLOGSTRING3("CAlfBridge::HandleGfxEventL - To layout: 0x%x Effect handle: %d, Action: %d", aToLayout, aEvent.iHandle, aEvent.iAction);
+    
+    if (!aEvent.iIsRedirected)
+        {
+        HandleGfxRedirection(aEvent, aToLayout);
+        }
+        
     TInt err = KErrNone;
     TBool failed = EFalse;
     
@@ -4680,8 +4894,6 @@
                     case AknTransEffect::EApplicationStartSwitchRect:
                     case KAlfFSTaskSwapperAppStart:
                         {
-                        aToLayout->iOpacity.Set(0.0f);    // these are meant for applications that are not yet ready to be drawn, but possible already on the foreground
-                        FreezeLayoutUntilEffectDestroyedL(aFromLayout, aEvent.iHandle);
                         aEvent.iEffectType = CFullScreenEffectState::EStartEffect;
                         if (iFSFXDataPart2)
                             {
@@ -4764,10 +4976,12 @@
                         
                     if (aToLayout)
                         {
-                        // if this was timeout appstart effect, we need to take screenshot at this point. 
-                        // It was not taken in the beginfullscreen
-                        
-                        if (aEvent.iLongAppStartTimeout)
+                         
+                        // 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
+								)
                             {
                             __ALFFXLOGSTRING1("CAlfBridge::HandleGfxEventL  - taking screenshot for the timeout appstart effect. Handle: %d",  aEvent.iHandle );
                             aToLayout->SetStoredRenderBufferModificationsEnabled(ETrue);
@@ -4824,8 +5038,7 @@
                                 }
                             __ALFFXLOGSTRING1("CAlfBridge::HandleGfxEventL - Active effect group: %d", activeEffectGroup);
                             effectFlags = KHuiFxDelayRunUntilFirstFrameHasBeenDrawn;
-                            if (FxmlHasOpaqueHint(iHuiEnv->EffectsEngine(), *aEvent.iEffectName) ||
-                                    aEvent.iTwoPhaseEffect == CFullScreenEffectState::ESecondPartActive)
+                            if (FxmlHasOpaqueHint(iHuiEnv->EffectsEngine(), *aEvent.iEffectName))
                                 {
                                 effectFlags |= KHuiFxOpaqueHint;
                                 }
@@ -4892,13 +5105,16 @@
     if (aLayout)
         {
 		TRAPD(err, StoreRenderBufferStartL(aLayout));
-		__ALFFXLOGSTRING2("CAlfBridge::FreezeLayoutUntilEffectDestroyed - StoreRenderBufferStartL call returned: %d for layout 0x%x", err, aLayout);
+		__ALFFXLOGSTRING3("CAlfBridge::FreezeLayoutUntilEffectDestroyed - Storing SecureId x%x, StoreRenderBufferStartL call returned: %d for layout 0x%x", aLayout->Owner().ControlGroup()->SecureId(), err, aLayout);
 		if (err == KErrNone)
 			{
             // Freeze only, if buffer was reserved succesfully 
             aLayout->SetFreezeState(ETrue);
-        	TBool itemsDestroyed;
-    	    AddFxItemL(aHandle, aLayout, NULL, NULL, EFalse, itemsDestroyed, ETrue, EFalse);
+        	if (!HasActiveEffect(aLayout))
+        	    {
+        	    TBool itemsDestroyed;
+        	    AddFxItemL(aHandle, aLayout, NULL, NULL, EFalse, itemsDestroyed, ETrue, EFalse);
+        	    }
 	        iFSFxData->iAppStartScreenshotItemHandle = aHandle;
 			}
         }
@@ -5009,7 +5225,7 @@
     // If we are in low memory state, we don't want to do any effects
     if(iHuiEnv->MemoryLevel() < EHuiMemoryLevelReduced)
         {
-        __ALFFXLOGSTRING("CAlfBridge::HandleGfxEffectsL - Returning because memory level below NORMAL");
+        __ALFFXLOGSTRING("CAlfBridge::HandleGfxEffectsL - WARNING! - Returning because memory level below NORMAL - EFFECT IS NOT SHOWN!");
 		stream.Release();
         return;
         }
@@ -5247,6 +5463,7 @@
                 && fxData->iOperation == MAlfGfxEffectPlugin::EBeginFullscreen 
                 && fxData->iEffectType == CFullScreenEffectState::EStartEffect)
             {
+            __ALFFXLOGSTRING("CAlfBridge::HandleGfxEffectsL - Try triggering effect immediately");
             GfxTriggerEffectWhenFullScreenDrawn(toGroup);
             }
         }
@@ -5296,9 +5513,10 @@
     
     CHuiControl& control = aToGroup->Control(0);
     CHuiLayout* toLayout = control.VisualCount() > 0 ? (CHuiLayout*)&control.Visual(0) : NULL;
-    if (!toLayout)
+    if (!toLayout || (toLayout->Flags() & EHuiVisualFlagInactive ))
         {
         // no point starting effect, if the layout is still inactive.
+		__ALFFXLOGSTRING1("CAlfBridge::GfxTriggerEffectWhenFullScreenDrawn - Do not trigger. Layout 0x%x inactive or not found.", toLayout);
         return EFalse;
         }
     TBool opaque = ETrue; // in app start case the layout is propably not opaque. Fake it.
@@ -5307,7 +5525,7 @@
     // alf content check is relavant only for alf apps
     if (!fullscreenCovered && aToGroup->iAlfApp) 
         {
-        TInt clientGroupId = FindClientWindowGroupId(0, *aToGroup);
+        TInt clientGroupId = FindClientWindowGroupId(*aToGroup);
         if (clientGroupId != KErrNotFound)
             {
             fullscreenCovered = HasActiveAlfContent(clientGroupId);