uiacceltk/hitchcock/ServerCore/Src/alfbridge.cpp
branchRCL_3
changeset 6 10534483575f
parent 5 433cbbb6a04b
child 7 88b23e2e82e1
equal deleted inserted replaced
5:433cbbb6a04b 6:10534483575f
    85 
    85 
    86 const TInt KVisualTransformationStepRotate    = 0;
    86 const TInt KVisualTransformationStepRotate    = 0;
    87 
    87 
    88 const TReal32 KAlfVisualDefaultOpacity = 1.0f;
    88 const TReal32 KAlfVisualDefaultOpacity = 1.0f;
    89 //const TReal32 KAlfVisualDefaultOpacity = 0.5f;
    89 //const TReal32 KAlfVisualDefaultOpacity = 0.5f;
       
    90 const TInt KEffectCleanupDelayInMs = 10;
    90 
    91 
    91 _LIT8(KAlfWindowGroupContainerControlTag, "WGROUP");
    92 _LIT8(KAlfWindowGroupContainerControlTag, "WGROUP");
    92 
    93 
    93 // #define USE_APPLICATION_ENDFULLSCREEN_TIMEOUT
    94 #define USE_APPLICATION_ENDFULLSCREEN_TIMEOUT
    94 // This debug option shows window groups in a grid
    95 // This debug option shows window groups in a grid
    95 //#define ALF_DEBUG_VISUALIZE_WINDOWGROUP_ORDER
    96 //#define ALF_DEBUG_VISUALIZE_WINDOWGROUP_ORDER
    96 
    97 
    97 
    98 
    98 const TInt KFadeAction = 6000;
    99 const TInt KFadeAction = 6000;
   180         {
   181         {
   181         iPrintFPS = ETrue;
   182         iPrintFPS = ETrue;
   182         }
   183         }
   183 #endif
   184 #endif
   184 #endif //SYMBIAN_BUILD_GCE
   185 #endif //SYMBIAN_BUILD_GCE
   185     // create the key for indication transition ends
   186    
   186     // No access restrictions for starters
       
   187     TInt err = RProperty::Define( KPSAlfDomain, KAlfTransitionStatus,
       
   188         RProperty::EInt );
       
   189     if (!err)
       
   190         {
       
   191         // Initialize to no transition    
       
   192         RProperty::Set( KPSAlfDomain, KAlfTransitionStatus, 0 );
       
   193         }
       
   194 
       
   195     iEffectEndTimer = CAlfEffectEndTimer::NewL( *this );
   187     iEffectEndTimer = CAlfEffectEndTimer::NewL( *this );
   196     iWindowHashArray.ReserveL( 500 );
   188     iWindowHashArray.ReserveL( 500 );
   197     iAlfRegisteredEffects.ReserveL(10);
   189     iAlfRegisteredEffects.ReserveL(10);
   198     
   190     
   199 #ifdef HUI_DEBUG_TRACK_DRAWING
   191 #ifdef HUI_DEBUG_TRACK_DRAWING
   468         }
   460         }
   469     return NULL;       
   461     return NULL;       
   470     }
   462     }
   471 
   463 
   472 // ---------------------------------------------------------------------------
   464 // ---------------------------------------------------------------------------
       
   465 // FindControlGroupBySecureId
   473 // ---------------------------------------------------------------------------
   466 // ---------------------------------------------------------------------------
   474 //
   467 //
   475 CHuiControlGroup* CAlfBridge::FindControlGroupByAppId( TInt aAppId )
   468 CHuiControlGroup* CAlfBridge::FindControlGroupBySecureId( TInt aSecureId, TInt aWgId ) const
   476     {
   469     {
       
   470     if ( aSecureId == 0 )
       
   471         {
       
   472         return NULL;
       
   473         }
       
   474     
   477     for ( TInt i = 0; i < iAlfScreens[0]->iControlGroups.Count(); i++ )
   475     for ( TInt i = 0; i < iAlfScreens[0]->iControlGroups.Count(); i++ )
   478         {
   476         {
   479         if ( iAlfScreens[0]->iControlGroups[i].iSecureId == aAppId )
   477         TAlfControlGroupEntry& groupEntry = iAlfScreens[0]->iControlGroups[i];
   480             {
   478         if ( groupEntry.iSecureId == aSecureId )
   481             return iAlfScreens[0]->iControlGroups[i].iControlGroup;
   479             {
       
   480             if ( aWgId != -1 )
       
   481                 {
       
   482                 // match the window group as well
       
   483                 if ( groupEntry.iClientWindowGroupId == aWgId )
       
   484                     {
       
   485                     // found match
       
   486                     return groupEntry.iControlGroup;
       
   487                     }
       
   488                 // found a matching SID, but the window group ID was incorrect. keep going...
       
   489                 }
       
   490             else
       
   491                 {
       
   492                 // done for the day
       
   493                 return groupEntry.iControlGroup;
       
   494                 }
   482             }
   495             }
   483         }        
   496         }        
   484     return NULL;       
   497     return NULL;       
   485     }
   498     }
   486 
   499 
   487 // ---------------------------------------------------------------------------
   500 // ---------------------------------------------------------------------------
       
   501 // FindControlGroupByFullScreenToEffect
       
   502 // ---------------------------------------------------------------------------
       
   503 //
       
   504 CHuiControlGroup* CAlfBridge::FindControlGroupByFullScreenToEffect() const
       
   505     {
       
   506     if ( iFullScreenEffectData )
       
   507         {
       
   508         return FindControlGroupBySecureId( iFullScreenEffectData->iToSecureId, iFullScreenEffectData->iToWg ); 
       
   509         }
       
   510     return NULL;
       
   511     }
       
   512 
       
   513 // ---------------------------------------------------------------------------
       
   514 // FindControlGroupByFullScreenFromEffect
       
   515 // ---------------------------------------------------------------------------
       
   516 //
       
   517 CHuiControlGroup* CAlfBridge::FindControlGroupByFullScreenFromEffect() const
       
   518     {
       
   519     if ( iFullScreenEffectData )
       
   520         {
       
   521         return FindControlGroupBySecureId( iFullScreenEffectData->iFromSecureId, iFullScreenEffectData->iFromWg );
       
   522         }
       
   523     return NULL;
       
   524     }
       
   525 
       
   526 // ---------------------------------------------------------------------------
   488 // ---------------------------------------------------------------------------
   527 // ---------------------------------------------------------------------------
   489 //
   528 //
   490 
   529 
   491 void CAlfBridge::ListFamilyTreeL( RPointerArray<CHuiLayout>& aArray, const CHuiLayout* aLayout )
   530 void CAlfBridge::ListFamilyTreeL( RPointerArray<CHuiLayout>& aArray, const CHuiLayout* aLayout )
   492     {
   531     {
   512 void CAlfBridge::ResolveAfterEffectAppearingApplicationL(CHuiControlGroup* aGroup)
   551 void CAlfBridge::ResolveAfterEffectAppearingApplicationL(CHuiControlGroup* aGroup)
   513     {
   552     {
   514 #ifdef USE_APPLICATION_ENDFULLSCREEN_TIMEOUT
   553 #ifdef USE_APPLICATION_ENDFULLSCREEN_TIMEOUT
   515     if (iFullScreenEffectData && iFullScreenEffectData->iEffectType == CFullScreenEffectState::EExitEffect)
   554     if (iFullScreenEffectData && iFullScreenEffectData->iEffectType == CFullScreenEffectState::EExitEffect)
   516         {
   555         {
   517         CHuiControlGroup *exitingGroupInEffect = FindControlGroupByAppId(iFullScreenEffectData->iToAppId);
   556         CHuiControlGroup *exitingGroupInEffect = FindControlGroupByFullScreenToEffect();
   518         if (exitingGroupInEffect == aGroup)
   557         if (exitingGroupInEffect == aGroup)
   519             {
   558             {
   520             CHuiRoster& roster = iAlfScreens[0]->iDisplay->Roster();
   559             CHuiRoster& roster = iAlfScreens[0]->iDisplay->Roster();
   521             CHuiControlGroup* nextToBecomeVisible = NULL;
   560             CHuiControlGroup* nextToBecomeVisible = NULL;
   522             // resolve who is under this application in roster
   561             // resolve who is under this application in roster
   534                 {
   573                 {
   535                 for(TInt j = 0 ; j < iAlfScreens[0]->iControlGroups.Count() - 1 ; j++)
   574                 for(TInt j = 0 ; j < iAlfScreens[0]->iControlGroups.Count() - 1 ; j++)
   536                     {
   575                     {
   537                     if (iAlfScreens[0]->iControlGroups[j].iControlGroup == nextToBecomeVisible)
   576                     if (iAlfScreens[0]->iControlGroups[j].iControlGroup == nextToBecomeVisible)
   538                         {
   577                         {
   539                         iFullScreenEffectData->iFromAppId = iAlfScreens[0]->iControlGroups[j].iSecureId;
   578                         iFullScreenEffectData->iFromSecureId = iAlfScreens[0]->iControlGroups[j].iSecureId;
   540                         __ALFFXLOGSTRING1("CAlfBridge::ResolveAfterEffectAppearingApplicationL - Found underneath application uid: 0x%x. Start track drawing for exit effect.", iFullScreenEffectData->iFromAppId );
   579                         iFullScreenEffectData->iFromWg = iAlfScreens[0]->iControlGroups[j].iClientWindowGroupId;
       
   580                         __ALFFXLOGSTRING2("CAlfBridge::ResolveAfterEffectAppearingApplicationL - Found underneath application uid: 0x%x, window group: %d -  Start track drawing for exit effect.", iFullScreenEffectData->iFromAppId, iFullScreenEffectData->iFromWg );
   541                         break;
   581                         break;
   542                         }
   582                         }
   543                     }
   583                     }
   544                 }
   584                 }
   545             }
   585             }
   680         entry.iClientWindowGroupId = aClientWindowGroupId;  
   720         entry.iClientWindowGroupId = aClientWindowGroupId;  
   681         entry.iSecureId = aSecureId;
   721         entry.iSecureId = aSecureId;
   682         // we have received start effect for this group, but the group did not exist in alf universe at the time. hide the group.
   722         // we have received start effect for this group, but the group did not exist in alf universe at the time. hide the group.
   683         if (iFullScreenEffectData
   723         if (iFullScreenEffectData
   684                 && iFullScreenEffectData->iWaitingWindowGroup
   724                 && iFullScreenEffectData->iWaitingWindowGroup
   685                 && iFullScreenEffectData->iToAppId == aSecureId)
   725                 && iFullScreenEffectData->iToSecureId == aSecureId)
   686             {
   726             {
       
   727             iFullScreenEffectData->iToWg = aClientWindowGroupId;
   687             CHuiControlGroup* fromGroup = NULL;
   728             CHuiControlGroup* fromGroup = NULL;
   688             CHuiLayout* fromLayout = NULL; 
   729             CHuiLayout* fromLayout = NULL; 
   689             fromGroup = FindControlGroupByAppId(iFullScreenEffectData->iFromAppId);
   730             fromGroup = FindControlGroupByFullScreenFromEffect();
   690             if (fromGroup)
   731             if (fromGroup)
   691                 {
   732                 {
   692                 CHuiControl& control2 = fromGroup->Control(0);
   733                 CHuiControl& control2 = fromGroup->Control(0);
   693                 fromLayout = (CHuiLayout*)&control2.Visual(0);
   734                 fromLayout = (CHuiLayout*)&control2.Visual(0);
   694                 }
   735                 }
   917             // Topmost
   958             // Topmost
   918             for (TInt i=aRoster.Count() - screen->FixedControlGroupCount(); i >= 0; i--)
   959             for (TInt i=aRoster.Count() - screen->FixedControlGroupCount(); i >= 0; i--)
   919                 {
   960                 {
   920                 if (aRoster.ControlGroup(i).Control(0).Role() == EAlfWindowGroupContainer)
   961                 if (aRoster.ControlGroup(i).Control(0).Role() == EAlfWindowGroupContainer)
   921                     {
   962                     {
       
   963                     // increasing the count, assuming that WindowControlGroup is not in the Roster
       
   964                     i++;
   922                     aRoster.ShowL(aGroup, i); 
   965                     aRoster.ShowL(aGroup, i); 
   923                     break;
   966                     break;
   924                     }                    
   967                     }                    
   925                 }                                                             
   968                 }                                                             
   926             }
   969             }
  1077                         iAlfScreens[screenNumber]->iFPSText->SetTextL( numBuf );
  1120                         iAlfScreens[screenNumber]->iFPSText->SetTextL( numBuf );
  1078                         })
  1121                         })
  1079                 }
  1122                 }
  1080             }
  1123             }
  1081 #endif
  1124 #endif
  1082         
  1125         if (!iActivated)            
       
  1126             {
       
  1127             TInt err = iBridgerClient.Connect();
       
  1128             iActivated = (err == KErrNone);            
       
  1129             }
       
  1130                     
  1083         if (iAlfScreens[screenNumber]->IsVisualTreeVisibilityChanged())
  1131         if (iAlfScreens[screenNumber]->IsVisualTreeVisibilityChanged())
  1084             {
  1132             {
  1085             HandleVisualVisibility( screenNumber );    
  1133             HandleVisualVisibility( screenNumber );    
  1086             iAlfScreens[screenNumber]->SetVisualTreeVisibilityChanged(EFalse);
  1134             iAlfScreens[screenNumber]->SetVisualTreeVisibilityChanged(EFalse);
  1087             }
       
  1088 
       
  1089         if (!iActivated)            
       
  1090             {
       
  1091             iBridgerClient.Connect();
       
  1092             iActivated = ETrue;            
       
  1093             }
  1135             }
  1094         }
  1136         }
  1095     }
  1137     }
  1096 
  1138 
  1097 // ---------------------------------------------------------------------------
  1139 // ---------------------------------------------------------------------------
  1251                 screen->iSwRenderingTarget ) );
  1293                 screen->iSwRenderingTarget ) );
  1252             }
  1294             }
  1253         }
  1295         }
  1254     
  1296     
  1255     TBool fullscreenCovered = EFalse;
  1297     TBool fullscreenCovered = EFalse;
       
  1298     CAlfAppSrvSessionBase* topMostAlfSrvSession = NULL;
       
  1299     
  1256     //iActiveVisualCount = 0;
  1300     //iActiveVisualCount = 0;
  1257     iBgSurfaceFound = EFalse;
  1301     iBgSurfaceFound = EFalse;
  1258     //iPaintedArea = 0;  
  1302     //iPaintedArea = 0;  
  1259     
  1303     
  1260     // Check if effect group has an effect with opaque hint.
  1304     // Check if effect group has an effect with opaque hint.
  1270     else if (fxExternalContent && IsOpaqueEffect(fxExternalContent->Effect()))
  1314     else if (fxExternalContent && IsOpaqueEffect(fxExternalContent->Effect()))
  1271         {
  1315         {
  1272         fullscreenCovered = ETrue;
  1316         fullscreenCovered = ETrue;
  1273         }    
  1317         }    
  1274     
  1318     
  1275     #ifdef USE_MODULE_TEST_HOOKS_FOR_ALF
  1319 	
  1276     iTempTotalActiveVisualCount = 0;
  1320 	TBool alfWindowGroupFoundVisible = EFalse;
  1277     iTempTotalPassiveVisualCount = 0;
  1321 
  1278     #endif
  1322     AMT_SET_VALUE( iVisibleVisualCount, 0 );
  1279 	
  1323 	
  1280     // skip the topmost (effect) layer, start from floating sprite group
  1324     // skip the topmost (effect) layer, start from floating sprite group
  1281     for (TInt j=screen->iDisplay->Roster().Count() - screen->FixedControlGroupCount(); j>=0; j--)
  1325     for (TInt j=screen->iDisplay->Roster().Count() - screen->FixedControlGroupCount(); j>=0; j--)
  1282         {                
  1326         {                
  1283 #ifdef ALF_DEBUG_PRINT_WINDOWGROUP_ORDER
  1327 #ifdef ALF_DEBUG_PRINT_WINDOWGROUP_ORDER
  1300             {
  1344             {
  1301             RDebug::Print(_L("CAlfBridge::HandleVisualVisibility: tracked visual 0x%x"), canvasVisual);
  1345             RDebug::Print(_L("CAlfBridge::HandleVisualVisibility: tracked visual 0x%x"), canvasVisual);
  1302             }
  1346             }
  1303 #endif            
  1347 #endif            
  1304             
  1348             
  1305         // Dont mess with alf control group visuals, alf session handling does it for us
       
  1306         // just add the rect to covered region because alf draws solid background.
       
  1307         if (control.Role() == EAlfSessionContainer)
       
  1308             {
       
  1309             iTempRegion.AddRect(fullscreen);
       
  1310             iTempRegion.Tidy();                                    
       
  1311             continue;
       
  1312             }
       
  1313         
  1349         
  1314         // For optimization reasons, check if all visuals below in Z-order are covered    
  1350         // For optimization reasons, check if all visuals below in Z-order are covered    
  1315         if (!fullscreenCovered)
  1351         if (!fullscreenCovered)
  1316             {
  1352             {
  1317             fullscreenCovered = IsRectCoveredByRegion(fullscreen, iTempRegion);            
  1353             fullscreenCovered = IsRectCoveredByRegion(fullscreen, iTempRegion);            
  1319             if (fullscreenCovered)
  1355             if (fullscreenCovered)
  1320                 __ALFLOGSTRING("Full screen covered!");                    
  1356                 __ALFLOGSTRING("Full screen covered!");                    
  1321 #endif
  1357 #endif
  1322             }
  1358             }
  1323         
  1359         
       
  1360         
       
  1361         // Dont mess with alf control group visuals, alf session handling does it for us
       
  1362         if (control.Role() == EAlfSessionContainer)
       
  1363             {
       
  1364             CHuiLayout* hostContainer = control.ContainerLayout( NULL );
       
  1365             TInt flags = hostContainer->Flags();            
       
  1366             if (!fullscreenCovered)
       
  1367                 {
       
  1368                 // clear inactive flag if client has not made this controlgroup hidden
       
  1369                 if(!(flags&EHuiVisualFlagUnderOpaqueHint))
       
  1370                     {
       
  1371                     alfWindowGroupFoundVisible = ETrue;
       
  1372                     if(iAppUi)
       
  1373                         {
       
  1374                         topMostAlfSrvSession = iAppUi->SrvSessionForControlGroup(controlgroup);
       
  1375                         }
       
  1376                     hostContainer->ClearFlags(EHuiVisualFlagInactive);
       
  1377 
       
  1378                     // just add the rect to covered region because alf draws solid background
       
  1379                     iTempRegion.AddRect(fullscreen);
       
  1380                     iTempRegion.Tidy();
       
  1381                     fullscreenCovered = ETrue;
       
  1382                     }
       
  1383                 else // else put as inactive
       
  1384                     {
       
  1385                     hostContainer->SetFlags(EHuiVisualFlagInactive);
       
  1386                     }
       
  1387                 }
       
  1388             else if(!alfWindowGroupFoundVisible || flags&EHuiVisualFlagUnderOpaqueHint)
       
  1389                 {
       
  1390                 // this alf session control group should not be visible anymore because avkon application is on top
       
  1391                 // -> change to inactive
       
  1392                 hostContainer->SetFlags(EHuiVisualFlagInactive);
       
  1393                 }
       
  1394             else if(!(flags&EHuiVisualFlagUnderOpaqueHint)) // alf app covers full screen
       
  1395                 {
       
  1396                 // check if current controlgroup belongs to same srvsession as the topmost visible alf session container
       
  1397                 CAlfAppSrvSessionBase* alfsrvsession = NULL;
       
  1398                 if(iAppUi)
       
  1399                     {
       
  1400                     alfsrvsession = iAppUi->SrvSessionForControlGroup(controlgroup);
       
  1401                     }
       
  1402                 if(topMostAlfSrvSession!=NULL && topMostAlfSrvSession == alfsrvsession)
       
  1403                     {
       
  1404                     hostContainer->ClearFlags(EHuiVisualFlagInactive);
       
  1405                     }
       
  1406                 else
       
  1407                     {
       
  1408                     hostContainer->SetFlags(EHuiVisualFlagInactive);
       
  1409                     }
       
  1410                 }
       
  1411             continue;
       
  1412             }
       
  1413 
       
  1414 
       
  1415 
       
  1416         
  1324         if (!fullscreenCovered)
  1417         if (!fullscreenCovered)
  1325             {
  1418             {
  1326             fullscreenCovered = screen->iDisplay->Roster().IsVisibleContentFrozen();
  1419             fullscreenCovered = screen->iDisplay->Roster().IsVisibleContentFrozen();
  1327 #ifdef ALF_DEBUG_PRINT_WINDOWGROUP_ORDER
  1420 #ifdef ALF_DEBUG_PRINT_WINDOWGROUP_ORDER
  1328             if (fullscreenCovered)
  1421             if (fullscreenCovered)
  1329                 __ALFLOGSTRING("Full screen covered because of frozen roster content");                    
  1422                 __ALFLOGSTRING("Full screen covered because of frozen roster content");                    
  1330 #endif
  1423 #endif
  1331             }
  1424             }
  1332         
  1425         
  1333         TBool subTreeCovered = EFalse;
  1426         TBool subTreeCovered = EFalse;
  1334         TBool hasActiveVisualsInVisualTree = HandleLayoutVisualVisibility( layout, controlgroup, control, fullscreenCovered, fullscreen, screen, subTreeCovered, IsVisualOpaque(*layout)  );    
  1427         TBool hasLayers = EFalse;
       
  1428         TBool hasActiveVisualsInVisualTree = 
       
  1429             HandleLayoutVisualVisibility( layout, controlgroup, control, 
       
  1430                 fullscreenCovered, fullscreen, screen, 
       
  1431                 subTreeCovered, hasLayers, IsVisualOpaque(*layout) );    
  1335         TBool hasFadeEffectsInVisualTree = (layout->CanvasFlags() & EHuiCanvasFlagExternalFadeExistsInsideVisualTree);        
  1432         TBool hasFadeEffectsInVisualTree = (layout->CanvasFlags() & EHuiCanvasFlagExternalFadeExistsInsideVisualTree);        
  1336 
  1433 
  1337         // If root visuals effect is marked as opaque, then add whole screen area as covered.
  1434         // If root visuals effect is marked as opaque, then add whole screen area as covered.
  1338         if (!fullscreenCovered)
  1435         if (!fullscreenCovered)
  1339             {
  1436             {
  1340             fullscreenCovered = IsOpaqueEffect(layout->Effect());
  1437             fullscreenCovered = IsOpaqueEffect(layout->Effect());
  1341             }                    
  1438             }                    
  1342         
  1439         
       
  1440         if ( hasLayers && iActivated )
       
  1441             {
       
  1442             HandleLayerVisibility( layout, controlgroup, control, hasActiveVisualsInVisualTree );
       
  1443             }
       
  1444             
  1343 		// If we layout is active setup the fade effects. Also if it is inactive, but has been
  1445 		// If we layout is active setup the fade effects. Also if it is inactive, but has been
  1344 		// flagged as containing fade effect, then run the setup as well so that effects which
  1446 		// flagged as containing fade effect, then run the setup as well so that effects which
  1345 		// are no more needed get removed.
  1447 		// are no more needed get removed.
  1346         if (hasActiveVisualsInVisualTree || (!hasActiveVisualsInVisualTree && hasFadeEffectsInVisualTree))
  1448         if (hasActiveVisualsInVisualTree || (!hasActiveVisualsInVisualTree && hasFadeEffectsInVisualTree))
  1347             {
  1449             {
  1362                 {
  1464                 {
  1363                 layout->ClearCanvasFlags(EHuiCanvasFlagExternalFadeExistsInsideVisualTree);            
  1465                 layout->ClearCanvasFlags(EHuiCanvasFlagExternalFadeExistsInsideVisualTree);            
  1364                 }
  1466                 }
  1365             }
  1467             }
  1366         
  1468         
  1367         if (!hasActiveVisualsInVisualTree)
  1469         TBool isLayoutActive = !(layout->Flags() & EHuiVisualFlagInactive);        
       
  1470         if (isLayoutActive && !hasActiveVisualsInVisualTree)
  1368             {
  1471             {
  1369             // Setting also the root visual (layout) as inactive, if it had none
  1472             // Setting also the root visual (layout) as inactive, if it had none
  1370 			// active children. This is because otherwise the Inactive checks won't
  1473 						// active children. This is because otherwise the Inactive checks won't
  1371 			// work correctly within RosterImpl ScanDirty & ClearChanged phases.
  1474 						// work correctly within RosterImpl ScanDirty & ClearChanged phases.
  1372             layout->SetFlag(EHuiVisualFlagInactive);
  1475             layout->SetFlag(EHuiVisualFlagInactive);
  1373             }
  1476             }
  1374         else
  1477         else if(!isLayoutActive && hasActiveVisualsInVisualTree)
  1375             {
  1478             {
  1376             layout->ClearFlag(EHuiVisualFlagInactive);
  1479             layout->ClearFlag(EHuiVisualFlagInactive);
       
  1480             layout->SetPos(fullscreen.iTl);
       
  1481             layout->SetSize(fullscreen.Size());
  1377             }
  1482             }
  1378         
  1483         
  1379 #ifdef ALF_DEBUG_PRINT_WINDOWGROUP_ORDER
  1484 #ifdef ALF_DEBUG_PRINT_WINDOWGROUP_ORDER
  1380         __ALFLOGSTRING1(">>>> HandleVisualVisibility: Control group index: %d", j );
  1485         __ALFLOGSTRING1(">>>> HandleVisualVisibility: Control group index: %d", j );
  1381         __ALFLOGSTRING1(">>>> HandleVisualVisibility: Active visuals : %d", activevisualcount );
  1486         __ALFLOGSTRING1(">>>> HandleVisualVisibility: Active visuals : %d", activevisualcount );
  1382         __ALFLOGSTRING1(">>>> HandleVisualVisibility: Passive visuals: %d", passivevisualcount );
  1487         __ALFLOGSTRING1(">>>> HandleVisualVisibility: Passive visuals: %d", passivevisualcount );
  1383 #endif
  1488 #endif
  1384             
  1489             
  1385         }
  1490         }
  1386     if (iBgSurfaceFound)
  1491     if (iActivated)
  1387         {
  1492         {
  1388         if (!iInLowMemMode)
  1493         if (iBgSurfaceFound)
  1389             {
  1494             {
  1390             SetLowMemory(ETrue);
  1495             if (!iInLowMemMode)
  1391             iBridgerClient.SendBlind(KAlfCompositionTargetHidden, TIpcArgs());
  1496                 {
  1392             iInLowMemMode = ETrue;            
  1497                 SetLowMemory(ETrue);
  1393             }
  1498                 // Notify Bg anim
  1394         }
  1499                 iBridgerClient.SendBlind(EAlfQueueRequestBGSessions, TIpcArgs(KAlfCompositionTargetHidden));
  1395     else if (iInLowMemMode)
  1500                 iInLowMemMode = ETrue;            
  1396         {
  1501                 }
  1397         SetLowMemory(EFalse);
  1502             }
  1398         iBridgerClient.SendBlind(KAlfCompositionTargetVisible, TIpcArgs());
  1503         else if (iInLowMemMode)
  1399         iInLowMemMode = EFalse;
  1504             {
  1400         }
  1505             SetLowMemory(EFalse);
  1401 
  1506             // Notify Bg anim
       
  1507             iBridgerClient.SendBlind(EAlfQueueRequestBGSessions, TIpcArgs(KAlfCompositionTargetVisible));
       
  1508             iInLowMemMode = EFalse;
       
  1509             }
       
  1510         }
       
  1511 
       
  1512     if ( iSwRenderingEnabled )
       
  1513         {
       
  1514         screen->iDisplay->SetForegroundTextureOptions( alfWindowGroupFoundVisible );
       
  1515         }
  1402 
  1516 
  1403     // Finally, if there are fadeeffects applied to windowgroups, make sure first one does not
  1517     // Finally, if there are fadeeffects applied to windowgroups, make sure first one does not
  1404     // blend itself, but other windowgroups do blend. Otherwise windowgrouops above others
  1518     // blend itself, but other windowgroups do blend. Otherwise windowgrouops above others
  1405     // would clear the screen areas where they do not really draw.
  1519     // would clear the screen areas where they do not really draw.
  1406     if (fadeEffectInScreen)
  1520     if (fadeEffectInScreen)
  1407         {
  1521         {
  1408         TBool firstFadedWindowGroupFound = EFalse;
  1522         TBool alwaysblend = EFalse;
  1409         for (TInt j=0; j<screen->iDisplay->Roster().Count() - screen->FixedControlGroupCount(); j++) // skip the topmost (effect) layer 
  1523         for (TInt j=0; j<screen->iDisplay->Roster().Count() - screen->FixedControlGroupCount(); j++) // skip the topmost (effect) layer 
  1410             {                
  1524             {                
  1411             CHuiControlGroup& controlgroup = iAlfScreens[aScreenNumber]->iDisplay->Roster().ControlGroup(j);
  1525             CHuiControlGroup& controlgroup = iAlfScreens[aScreenNumber]->iDisplay->Roster().ControlGroup(j);
  1412             CHuiControl& control = controlgroup.Control(0);
  1526             CHuiControl& control = controlgroup.Control(0);
  1413             CHuiVisual* layout = &control.Visual(0);
  1527             CHuiVisual* layout = &control.Visual(0);
  1414             if (layout->Effect() && (layout->Effect()->EffectFlags() & KHuiFadeEffectFlag))
  1528             if (layout->Effect() && (layout->Effect()->EffectFlags() & KHuiFadeEffectFlag))
  1415                 {
  1529                 {
  1416                 if (firstFadedWindowGroupFound)
  1530                 if (alwaysblend)
  1417                     {
  1531                     {
  1418                     TInt flags = layout->Effect()->EffectFlags();
  1532                     TInt flags = layout->Effect()->EffectFlags();
  1419                     flags |= KHuiFxAlwaysBlend; // Workaround for opaque layout canvasvisual.
  1533                     flags |= KHuiFxAlwaysBlend; // Workaround for opaque layout canvasvisual.
  1420                     layout->Effect()->SetEffectFlags(flags);
  1534                     layout->Effect()->SetEffectFlags(flags);
  1421                     }
  1535                     }
  1424                     {
  1538                     {
  1425                     // Special handling for ALF fading...fading happens via empty alf originated event window group
  1539                     // Special handling for ALF fading...fading happens via empty alf originated event window group
  1426                     TInt flags = layout->Effect()->EffectFlags();
  1540                     TInt flags = layout->Effect()->EffectFlags();
  1427                     flags |= KHuiFxEnableBackgroundInAllLayers; // This forces effect to happen to background pixels that are read from surface. 
  1541                     flags |= KHuiFxEnableBackgroundInAllLayers; // This forces effect to happen to background pixels that are read from surface. 
  1428                     flags |= KHuiFxFrozenBackground; // To get optimal UI performance, we ignore changes in ALF scene when it is faded.
  1542                     flags |= KHuiFxFrozenBackground; // To get optimal UI performance, we ignore changes in ALF scene when it is faded.
       
  1543                     alwaysblend = ETrue;
  1429                     layout->Effect()->SetEffectFlags(flags);                            
  1544                     layout->Effect()->SetEffectFlags(flags);                            
  1430                     }
  1545                     }                
  1431                 
  1546                 }
  1432                 firstFadedWindowGroupFound = ETrue;
  1547             }
  1433                 }
  1548         }
  1434             }
       
  1435         }
       
  1436 
       
  1437     AMT_FUNC_EXC(AMT_DATA()->iActiveVisualCount = iTempTotalActiveVisualCount;
       
  1438                  AMT_DATA()->iPassiveVisualCount = iTempTotalPassiveVisualCount;
       
  1439                  AMT_DATA()->PrintState()
       
  1440                  );
       
  1441     }
  1549     }
  1442 
  1550 
  1443 TBool CAlfBridge::HandleLayoutVisualVisibility(
  1551 TBool CAlfBridge::HandleLayoutVisualVisibility(
  1444         CHuiLayout* aLayout, 
  1552         CHuiLayout* aLayout, 
  1445         CHuiControlGroup& aControlGroup,
  1553         CHuiControlGroup& aControlGroup,
  1446         CHuiControl& aControl,
  1554         CHuiControl& aControl,
  1447         TBool& aFullscreenCovered, 
  1555         TBool& aFullscreenCovered, 
  1448         TRect& aFullscreen,
  1556         TRect& aFullscreen,
  1449         CAlfScreen* aScreen,
  1557         CAlfScreen* aScreen,
  1450         TBool& aSubtreeVisible, 
  1558         TBool& aSubtreeVisible, 
       
  1559         TBool& aHasVisualsWithLayers,
  1451         TBool aChildCanBeOpaque )
  1560         TBool aChildCanBeOpaque )
  1452     {
  1561     {
  1453     TBool visualTreeActive = EFalse;
  1562     TBool visualTreeActive = EFalse;
  1454     TRect visualDisplayRect;
  1563     TRect visualDisplayRect;
  1455     TBool visualRectIsCovered = EFalse;
  1564     TBool visualRectIsCovered = EFalse;
  1473         // Child can be considered to be opaque only if all parents are opaque and
  1582         // Child can be considered to be opaque only if all parents are opaque and
  1474         // visual itself is opaque.
  1583         // visual itself is opaque.
  1475         // For example, parent can have opacity < 1 and that affects children as well.
  1584         // For example, parent can have opacity < 1 and that affects children as well.
  1476         // As another example, parent can have scaling transformation.
  1585         // As another example, parent can have scaling transformation.
  1477         visualIsOpaque = aChildCanBeOpaque && IsVisualOpaque(*canvasVisual);
  1586         visualIsOpaque = aChildCanBeOpaque && IsVisualOpaque(*canvasVisual);
       
  1587         
       
  1588         if (!canvasVisual->LayerExtent().IsEmpty())
       
  1589             {
       
  1590             aHasVisualsWithLayers = ETrue;
       
  1591             }        
       
  1592 
  1478         if (canvasVisual->Count())
  1593         if (canvasVisual->Count())
  1479             {
  1594             {
  1480             visualTreeActive |= HandleLayoutVisualVisibility( canvasVisual, aControlGroup, aControl, aFullscreenCovered, aFullscreen, aScreen, visualSubtreeVisible, visualIsOpaque );
  1595             visualTreeActive |= HandleLayoutVisualVisibility( canvasVisual, aControlGroup, aControl, 
       
  1596                 aFullscreenCovered, aFullscreen, aScreen, 
       
  1597                 visualSubtreeVisible, aHasVisualsWithLayers, visualIsOpaque );
  1481             }
  1598             }
  1482     #ifdef HUI_DEBUG_TRACK_DRAWING  
  1599     #ifdef HUI_DEBUG_TRACK_DRAWING  
  1483         if ( canvasVisual->Tracking() )
  1600         if ( canvasVisual->Tracking() )
  1484             {
  1601             {
  1485             RDebug::Print(_L("CAlfBridge::HandleVisualVisibility: tracked visual 0x%x"), canvasVisual);
  1602             RDebug::Print(_L("CAlfBridge::HandleVisualVisibility: tracked visual 0x%x"), canvasVisual);
  1561                 
  1678                 
  1562             if (!wasInactive)
  1679             if (!wasInactive)
  1563                 {
  1680                 {
  1564                 aScreen->iDisplay->SetDirty();
  1681                 aScreen->iDisplay->SetDirty();
  1565                 }                
  1682                 }                
  1566             
  1683 
  1567             #ifdef USE_MODULE_TEST_HOOKS_FOR_ALF
       
  1568             iTempTotalPassiveVisualCount++;
       
  1569             #endif
       
  1570             
       
  1571             #ifdef ALF_DEBUG_PRINT_WINDOWGROUP_ORDER
  1684             #ifdef ALF_DEBUG_PRINT_WINDOWGROUP_ORDER
  1572                     passivevisualcount++;
  1685                     passivevisualcount++;
  1573             #endif
  1686             #endif
  1574             }
  1687             }
  1575         else
  1688         else
  1604                     // we would be triggering for example background animation
  1717                     // we would be triggering for example background animation
  1605                     // on / off quite rapidly........
  1718                     // on / off quite rapidly........
  1606                     if ( r == Display(0)->VisibleArea())
  1719                     if ( r == Display(0)->VisibleArea())
  1607                         {
  1720                         {
  1608                         // Final test. Surface must not be ALF surface, but some other surface.                        
  1721                         // Final test. Surface must not be ALF surface, but some other surface.                        
  1609                         CHuiControlGroup* alfControlGroup = FindControlGroupByAppId( iAlfSecureId );
  1722                         CHuiControlGroup* alfControlGroup = FindControlGroupBySecureId( iAlfSecureId );
  1610                         if (alfControlGroup != &aControlGroup)
  1723                         if (alfControlGroup != &aControlGroup)
  1611                             {                        
  1724                             {                        
  1612                             iBgSurfaceFound = ETrue;
  1725                             iBgSurfaceFound = ETrue;
  1613                             }
  1726                             }
  1614                         }
  1727                         }
  1617 
  1730 
  1618             if (wasInactive)
  1731             if (wasInactive)
  1619                 {
  1732                 {
  1620                 canvasVisual->SetChanged();
  1733                 canvasVisual->SetChanged();
  1621                 }
  1734                 }
  1622             #ifdef USE_MODULE_TEST_HOOKS_FOR_ALF
       
  1623             iTempTotalActiveVisualCount++;
       
  1624             #endif
       
  1625 
  1735 
  1626             #ifdef ALF_DEBUG_PRINT_WINDOWGROUP_ORDER
  1736             #ifdef ALF_DEBUG_PRINT_WINDOWGROUP_ORDER
  1627             activevisualcount++;
  1737             activevisualcount++;
  1628             #endif
  1738             #endif
  1629             }
  1739             }
  1630             
  1740 
       
  1741 
       
  1742         
  1631         // Finally check the area that this visual covers and add it to covered region
  1743         // Finally check the area that this visual covers and add it to covered region
  1632         visualIsActive = !(canvasVisual->Flags() & EHuiVisualFlagInactive);
  1744         visualIsActive = !(canvasVisual->Flags() & EHuiVisualFlagInactive);
  1633     
  1745     
  1634         // Sprites and effects as we consider them always as transparent and also
  1746         // Sprites and effects as we consider them always as transparent and also
  1635         // if controlgroup is transformed somehow    
  1747         // if controlgroup is transformed somehow    
  1646     #ifdef ALF_DEBUG_PRINT_WINDOWGROUP_ORDER
  1758     #ifdef ALF_DEBUG_PRINT_WINDOWGROUP_ORDER
  1647             if (canvasVisual->PaintedAreaCount())
  1759             if (canvasVisual->PaintedAreaCount())
  1648                 __ALFLOGSTRING2("Visual has painted areas: displayrect: iTl: %i, %i", visualDisplayRect.iTl.iX, visualDisplayRect.iTl.iY);                    
  1760                 __ALFLOGSTRING2("Visual has painted areas: displayrect: iTl: %i, %i", visualDisplayRect.iTl.iX, visualDisplayRect.iTl.iY);                    
  1649                 __ALFLOGSTRING2("Visual has painted areas: displayrect: iBr: %i, %i", visualDisplayRect.iBr.iX,visualDisplayRect.iBr.iY);
  1761                 __ALFLOGSTRING2("Visual has painted areas: displayrect: iBr: %i, %i", visualDisplayRect.iBr.iX,visualDisplayRect.iBr.iY);
  1650                 #endif
  1762                 #endif
       
  1763 #ifndef ALF_OLD_VISIBILITY
       
  1764             // New visibility system takes only window shape into account.
       
  1765             if ( canvasVisual->CanvasFlags() & EHuiCanvasFlagIncludeToVisibilityCalculation )
       
  1766                 {
       
  1767                 if ( !canvasVisual->HasCustomShape() )
       
  1768                     {
       
  1769                     TRect displayRect(canvasVisual->DisplayRect());
       
  1770                     ClipVisualRect(displayRect, aFullscreen);
       
  1771 
       
  1772 #ifdef ALF_DEBUG_PRINT_WINDOWGROUP_ORDER
       
  1773                     __ALFLOGSTRING2("Covered rect: iTl: %i, %i", displayRect.iTl.iX, displayRect.iTl.iY);                    
       
  1774                     __ALFLOGSTRING2("Covered rect: iBr: %i, %i", displayRect.iBr.iX, displayRect.iBr.iY);
       
  1775 #endif
       
  1776 
       
  1777                     iTempRegion.AddRect(displayRect);
       
  1778                     iTempRegion.Tidy();
       
  1779                     }
       
  1780                 else
       
  1781                     {
       
  1782                     TRect displayRect = canvasVisual->DisplayRect();
       
  1783                     const TRegion& region = canvasVisual->ShapeRegion();
       
  1784                     TPoint delta = -canvasVisual->ShapeOrigin() + displayRect.iTl;
       
  1785                 
       
  1786                     for (TInt i = 0; i < region.Count(); ++i)
       
  1787                         {
       
  1788                         TRect coveredRect(region[i]);
       
  1789                         coveredRect.Move(delta);
       
  1790                         ClipVisualRect(coveredRect, aFullscreen);
       
  1791 
       
  1792 #ifdef ALF_DEBUG_PRINT_WINDOWGROUP_ORDER
       
  1793                         __ALFLOGSTRING2("Covered rect: iTl: %i, %i", coveredRect.iTl.iX, coveredRect.iTl.iY);                    
       
  1794                         __ALFLOGSTRING2("Covered rect: iBr: %i, %i", coveredRect.iBr.iX, coveredRect.iBr.iY);
       
  1795 #endif
       
  1796                     
       
  1797                         iTempRegion.AddRect(coveredRect);
       
  1798                         iTempRegion.Tidy();
       
  1799                         }
       
  1800                     }
       
  1801                 }
       
  1802 #else
  1651             for (TInt k=0; k < canvasVisual->PaintedAreaCount(); k++)
  1803             for (TInt k=0; k < canvasVisual->PaintedAreaCount(); k++)
  1652                 {                                
  1804                 {                                
  1653                 THuiCanvasPaintedArea paintArea = canvasVisual->PaintedArea(k);
  1805                 THuiCanvasPaintedArea paintArea = canvasVisual->PaintedArea(k);
  1654                 TRect coveredRect = paintArea.iPaintedRect;
  1806                 TRect coveredRect = paintArea.iPaintedRect;
  1655                                 
  1807                                 
  1671             // If effect is marked as opaque, then add whole visual area as covered.
  1823             // If effect is marked as opaque, then add whole visual area as covered.
  1672             if (IsOpaqueEffect(canvasVisual->Effect()))
  1824             if (IsOpaqueEffect(canvasVisual->Effect()))
  1673                 {
  1825                 {
  1674                 iTempRegion.AddRect(visualDisplayRect);
  1826                 iTempRegion.AddRect(visualDisplayRect);
  1675                 iTempRegion.Tidy();
  1827                 iTempRegion.Tidy();
  1676                 }            
  1828                 }
       
  1829 #endif				
  1677             }                                        
  1830             }                                        
  1678         visualTreeActive |= visualIsActive;
  1831         visualTreeActive |= visualIsActive;
       
  1832         
       
  1833         // iVisibleVisualCount is cleared in HandleVisualVisibility()
       
  1834         AMT_INC_COUNTER_IF( visualIsActive && !visualRectIsCovered , iVisibleVisualCount );
  1679         } // for loop end : children checking loop
  1835         } // for loop end : children checking loop
  1680      
  1836      
  1681     return visualTreeActive;
  1837     return visualTreeActive;
  1682     }
  1838     }
  1683 
  1839 
       
  1840 
       
  1841 // ---------------------------------------------------------------------------
       
  1842 // ---------------------------------------------------------------------------
       
  1843 // 
       
  1844 void CAlfBridge::HandleLayerVisibility(
       
  1845         CHuiLayout* aLayout,
       
  1846         CHuiControlGroup& aControlGroup,
       
  1847         CHuiControl& aControl,
       
  1848         TBool aVisible )
       
  1849     {
       
  1850     CHuiCanvasVisual* canvasVisual = NULL;
       
  1851 
       
  1852     for (TInt i = aLayout->Count()-1; i >= 0; i--)
       
  1853         {
       
  1854         canvasVisual = (CHuiCanvasVisual*)(&aLayout->Visual(i));
       
  1855         
       
  1856         if (canvasVisual->Count())
       
  1857             {
       
  1858             HandleLayerVisibility( 
       
  1859                 canvasVisual, aControlGroup, 
       
  1860                 aControl, aVisible );
       
  1861             }            
       
  1862 
       
  1863         if (!canvasVisual->LayerExtent().IsEmpty())
       
  1864             {
       
  1865             // Determine if surface is visible.
       
  1866             TBool surfaceWasVisible = ( canvasVisual->CanvasFlags() & EHuiCanvasFlagSurfaceVisible );
       
  1867             TBool surfaceWasInvisible = ( canvasVisual->CanvasFlags() & EHuiCanvasFlagSurfaceInvisible );
       
  1868             __ALFLOGSTRING2("CAlfBridge::HideTarget: %d %d", aVisible, surfaceWasVisible);
       
  1869 
       
  1870             TBool forcedUpdate = !surfaceWasVisible && !surfaceWasInvisible;
       
  1871     
       
  1872             if ( !aVisible && ( forcedUpdate || surfaceWasVisible ) )
       
  1873                 {
       
  1874                 // notify surface observer that it has been hidden
       
  1875                 __ALFLOGSTRING("CAlfBridge::HideTarget >>");
       
  1876                 TLex8 lex(canvasVisual->Tag());
       
  1877                 TInt windowId(0);
       
  1878                 if (lex.Val(windowId) == KErrNone)
       
  1879                     {
       
  1880                     __ALFLOGSTRING1("CAlfBridge::HideTarget: WindowId: %d", windowId);
       
  1881                     canvasVisual->SetCanvasFlags( EHuiCanvasFlagSurfaceInvisible );
       
  1882                     canvasVisual->ClearCanvasFlags( EHuiCanvasFlagSurfaceVisible );
       
  1883                     
       
  1884                     iBridgerClient.SendBlind(EAlfPostDataToCompositionTarget, TIpcArgs(KAlfCompositionTargetHidden, windowId));                    
       
  1885                     iBridgerClient.SendBlind(EAlfPostDataToCompositionClient, TIpcArgs(KAlfCompositionTargetHidden, windowId));
       
  1886                     }
       
  1887                 __ALFLOGSTRING("CAlfBridge::HideTarget <<");
       
  1888                 }
       
  1889             else if ( aVisible && ( forcedUpdate || surfaceWasInvisible ) )
       
  1890                 {
       
  1891                 // notify surface observer that it has been hidden
       
  1892                 __ALFLOGSTRING("CAlfBridge::ShowTarget >>");
       
  1893                 TLex8 lex(canvasVisual->Tag());
       
  1894                 TInt windowId(0);
       
  1895                 if (lex.Val(windowId) == KErrNone)
       
  1896                     {
       
  1897                     __ALFLOGSTRING1("CAlfBridge::ShowTarget: WindowId: %d", windowId);
       
  1898                     canvasVisual->ClearCanvasFlags( EHuiCanvasFlagSurfaceInvisible );
       
  1899                     canvasVisual->SetCanvasFlags( EHuiCanvasFlagSurfaceVisible );
       
  1900                     
       
  1901                     iBridgerClient.SendBlind(EAlfPostDataToCompositionTarget, TIpcArgs(KAlfCompositionTargetVisible, windowId));                    
       
  1902                     iBridgerClient.SendBlind(EAlfPostDataToCompositionClient, TIpcArgs(KAlfCompositionTargetVisible, windowId));
       
  1903                     }
       
  1904                 __ALFLOGSTRING("CAlfBridge::ShowTarget <<");
       
  1905                 }
       
  1906             else
       
  1907                 {
       
  1908                 // No change - ignore.
       
  1909                 }
       
  1910             }
       
  1911         } // for loop end : children checking loop
       
  1912     }
  1684 
  1913 
  1685 // ---------------------------------------------------------------------------
  1914 // ---------------------------------------------------------------------------
  1686 // ---------------------------------------------------------------------------
  1915 // ---------------------------------------------------------------------------
  1687 // 
  1916 // 
  1688 void CAlfBridge::ClearCanvasVisualCommandSets(TBool aInactiveOnly)
  1917 void CAlfBridge::ClearCanvasVisualCommandSets(TBool aInactiveOnly)
  1821                 break;
  2050                 break;
  1822                 }
  2051                 }
  1823             case EAlfDSSetWindowOpacity:
  2052             case EAlfDSSetWindowOpacity:
  1824                 {
  2053                 {
  1825                 HandleSetWindowOpacityL( data );
  2054                 HandleSetWindowOpacityL( data );
       
  2055                 break;
       
  2056                 }
       
  2057             case EAlfDSSetTransparencyAlphaChannel:
       
  2058                 {
       
  2059                 HandleSetTransparencyAlphaChannelL( data );
       
  2060                 break;
       
  2061                 }
       
  2062             case EAlfDSIncludeToVisibilityCalculation:
       
  2063                 {
       
  2064                 HandleIncludeToVisibilityCalculationL( data );
       
  2065                 break;
       
  2066                 }
       
  2067             case EAlfDSSetWindowArea:
       
  2068                 {
       
  2069                 HandleSetWindowAreaL( data );
  1826                 break;
  2070                 break;
  1827                 }
  2071                 }
  1828             case EAlfDSRefreshCallback:
  2072             case EAlfDSRefreshCallback:
  1829                 {
  2073                 {
  1830                 iHuiEnv->ContinueRefresh();
  2074                 iHuiEnv->ContinueRefresh();
  1913             case EAlfStopEffectFx:
  2157             case EAlfStopEffectFx:
  1914                 {
  2158                 {
  1915                 HandleGfxStopEffectsL( data );
  2159                 HandleGfxStopEffectsL( data );
  1916                 break;
  2160                 break;
  1917                 }
  2161                 }
       
  2162             case EAlfStopControlEffectFx:
       
  2163                 {
       
  2164                 HandleGfxStopControlEffectsL( data );
       
  2165                 break;
       
  2166                 }
  1918             case EAlfControlEffectFx:
  2167             case EAlfControlEffectFx:
  1919                 {
  2168                 {
  1920                 HandleGfxControlEffectsL( data );
  2169                 HandleGfxControlEffectsL( data );
  1921                 break;
  2170                 break;
  1922                 }
  2171                 }
  2133 				    }
  2382 				    }
  2134 				else
  2383 				else
  2135 				    {
  2384 				    {
  2136                     viz = CHuiCanvasVisual::AddNewL(control, layout);
  2385                     viz = CHuiCanvasVisual::AddNewL(control, layout);
  2137 				    }
  2386 				    }
       
  2387 
  2138 				__ALFFXLOGSTRING2("CAlfBridge::HandleNewWindowL visual: 0x%x, id 0x%x", viz, windowNodeId);
  2388 				__ALFFXLOGSTRING2("CAlfBridge::HandleNewWindowL visual: 0x%x, id 0x%x", viz, windowNodeId);
  2139 				AddVisual( 
  2389 				AddVisual( 
  2140 				    windowNodeId, 
  2390 				    windowNodeId, 
  2141 					windowAttributes->iClientHandle, 
  2391 					windowAttributes->iClientHandle, 
  2142 					windowAttributes->iClientGroupHandle, 
  2392 					windowAttributes->iClientGroupHandle, 
  2365 		__ALFLOGSTRING("CAlfBridge::HandleSetWindowPosL, EAlfDSSetWindowPos: Visual not found!");    
  2615 		__ALFLOGSTRING("CAlfBridge::HandleSetWindowPosL, EAlfDSSetWindowPos: Visual not found!");    
  2366 		}   
  2616 		}   
  2367 
  2617 
  2368     AMT_INC_COUNTER_IF( viz, iVisualPositionChangedCount );
  2618     AMT_INC_COUNTER_IF( viz, iVisualPositionChangedCount );
  2369     AMT_SET_VALUE_IF( viz, iLatestVisualExtentRect, TRect( windowAttributes->iPosition, windowAttributes->iSize ) );
  2619     AMT_SET_VALUE_IF( viz, iLatestVisualExtentRect, TRect( windowAttributes->iPosition, windowAttributes->iSize ) );
       
  2620     AMT_MAP_SET_VALUE_IF( ( viz && iWindowHashArray.Find( windowNodeId ) ),
       
  2621                           iPositionMap, iWindowHashArray.Find( windowNodeId )->iClientSideId, 
       
  2622                           windowAttributes->iPosition, EAlfModuleTestTypeBridgeChangePosition );    
  2370 	}
  2623 	}
  2371 
  2624 
  2372 // ---------------------------------------------------------------------------
  2625 // ---------------------------------------------------------------------------
  2373 // HandleSetWindowSizeL
  2626 // HandleSetWindowSizeL
  2374 // ---------------------------------------------------------------------------
  2627 // ---------------------------------------------------------------------------
  2395 		__ALFLOGSTRING("CAlfBridge::HandleSetWindowSizeL, EAlfDSSetWindowSize: Visual not found!");    
  2648 		__ALFLOGSTRING("CAlfBridge::HandleSetWindowSizeL, EAlfDSSetWindowSize: Visual not found!");    
  2396 		}   
  2649 		}   
  2397     iAlfScreens[screenNumber]->SetVisualTreeVisibilityChanged(ETrue);
  2650     iAlfScreens[screenNumber]->SetVisualTreeVisibilityChanged(ETrue);
  2398     
  2651     
  2399     AMT_INC_COUNTER_IF(viz, iVisualSizeChangedCount );
  2652     AMT_INC_COUNTER_IF(viz, iVisualSizeChangedCount );
  2400     AMT_SET_VALUE_IF(viz, iLatestVisualExtentRect, TRect( windowAttributes->iPosition, windowAttributes->iSize ) );        
  2653     AMT_SET_VALUE_IF(viz, iLatestVisualExtentRect, TRect( windowAttributes->iPosition, windowAttributes->iSize ) );
       
  2654     AMT_MAP_SET_VALUE_IF( ( viz && iWindowHashArray.Find( windowNodeId ) ), 
       
  2655                           iSizeMap, iWindowHashArray.Find( windowNodeId )->iClientSideId, 
       
  2656                           windowAttributes->iSize, EAlfModuleTestTypeBridgeChangeSize );
  2401 	}
  2657 	}
  2402 
  2658 
  2403 // ---------------------------------------------------------------------------
  2659 // ---------------------------------------------------------------------------
  2404 // HandleSetWindowRotationL
  2660 // HandleSetWindowRotationL
  2405 // ---------------------------------------------------------------------------
  2661 // ---------------------------------------------------------------------------
  2452 		}
  2708 		}
  2453 	else
  2709 	else
  2454 		{
  2710 		{
  2455 		__ALFLOGSTRING("CAlfBridge::HandleSetWindowOpacityL, EAlfDSSetWindowOpacity: Visual not found!");                                                
  2711 		__ALFLOGSTRING("CAlfBridge::HandleSetWindowOpacityL, EAlfDSSetWindowOpacity: Visual not found!");                                                
  2456 		}  
  2712 		}  
       
  2713 	}
       
  2714 
       
  2715 // ---------------------------------------------------------------------------
       
  2716 // HandleSetTransparencyAlphaChannel
       
  2717 // ---------------------------------------------------------------------------
       
  2718 // 
       
  2719 void CAlfBridge::HandleSetTransparencyAlphaChannelL( TAlfBridgerData& aData )
       
  2720     {
       
  2721 	TInt windowNodeId = aData.iInt2;
       
  2722 	TAlfWindowAttributes* windowAttributes = (TAlfWindowAttributes*) (*iHost)->GetVarDataL( (TInt)aData.iPtr );
       
  2723 	TInt screenNumber = windowAttributes->iScreenNumber;
       
  2724 	// fetch visual
       
  2725 	CHuiVisual* viz = FindVisual(windowNodeId);
       
  2726 	if (viz)
       
  2727 		{
       
  2728 #ifdef HUI_DEBUG_TRACK_DRAWING
       
  2729         if ( viz->Tracking() )
       
  2730             {
       
  2731             RDebug::Print(_L("CAlfBridge::HandleSetTransparencyAlphaChannel - Tracked visual"));
       
  2732             }
       
  2733 #endif
       
  2734 		if ( windowAttributes->iActive )
       
  2735 		    {
       
  2736 		    viz->ClearFlag( EHuiVisualFlagOpaqueHint );
       
  2737 		    }
       
  2738 		else
       
  2739 		    {
       
  2740 		    viz->SetFlag( EHuiVisualFlagOpaqueHint );
       
  2741 		    }
       
  2742 		
       
  2743 	    iAlfScreens[screenNumber]->SetVisualTreeVisibilityChanged(ETrue);  // TODO: Check if really changed  
       
  2744 		}
       
  2745 	else
       
  2746 		{
       
  2747 		__ALFLOGSTRING("CAlfBridge::HandleSetTransparencyAlphaChannel, EAlfDSSetTransparencyAlphaChannel: Visual not found!");                                                
       
  2748 		}          
       
  2749     }
       
  2750 
       
  2751 // ---------------------------------------------------------------------------
       
  2752 // HandleSetWindowAreaL
       
  2753 // ---------------------------------------------------------------------------
       
  2754 // 
       
  2755 void CAlfBridge::HandleIncludeToVisibilityCalculationL( TAlfBridgerData& aData )
       
  2756     {
       
  2757     TInt windowNodeId = aData.iInt2;
       
  2758     TAlfWindowAttributes* windowAttributes = (TAlfWindowAttributes*) (*iHost)->GetVarDataL( (TInt)aData.iPtr );
       
  2759     TInt screenNumber = windowAttributes->iScreenNumber;
       
  2760     // fetch visual
       
  2761     CHuiVisual* viz = FindVisual(windowNodeId);
       
  2762     if (viz)
       
  2763         {
       
  2764 #ifdef HUI_DEBUG_TRACK_DRAWING
       
  2765         if ( viz->Tracking() )
       
  2766             {
       
  2767             RDebug::Print(_L("CAlfBridge::HandleIncludeToVisibilityCalculationL - Tracked visual"));
       
  2768             }
       
  2769 #endif
       
  2770         if ( windowAttributes->iWindowNodeType == EAlfWinTreeNodeClient )
       
  2771             {
       
  2772             CHuiCanvasVisual* canvasVisual = static_cast<CHuiCanvasVisual*>(viz);
       
  2773             
       
  2774             if ( windowAttributes->iActive )
       
  2775                 {
       
  2776                 canvasVisual->SetCanvasFlags( EHuiCanvasFlagIncludeToVisibilityCalculation );
       
  2777                 }
       
  2778             else
       
  2779                 {
       
  2780                 canvasVisual->ClearCanvasFlags( EHuiCanvasFlagIncludeToVisibilityCalculation );
       
  2781                 }
       
  2782             }
       
  2783         
       
  2784         iAlfScreens[screenNumber]->SetVisualTreeVisibilityChanged(ETrue);  // TODO: Check if really changed  
       
  2785         }
       
  2786     else
       
  2787         {
       
  2788         __ALFLOGSTRING("CAlfBridge::HandleIncludeToVisibilityCalculationL, EAlfDSIncludeToVisibilityCalculation: Visual not found!");                                                
       
  2789         }              
       
  2790     }
       
  2791 
       
  2792 // ---------------------------------------------------------------------------
       
  2793 // HandleSetWindowAreaL
       
  2794 // ---------------------------------------------------------------------------
       
  2795 // 
       
  2796 void CAlfBridge::HandleSetWindowAreaL( TAlfBridgerData& aData )
       
  2797 	{
       
  2798 	TInt windowNodeId = aData.iInt2;
       
  2799 	TAny* ptr = (TAny*)(*iHost)->GetVarDataL( (TInt)aData.iPtr );
       
  2800 	
       
  2801 	TInt screenNumber = 0;
       
  2802 	TPoint origin;
       
  2803 	TInt count = 0;
       
  2804 	RRegion region;
       
  2805 	CleanupClosePushL( region );
       
  2806 	
       
  2807 	    {
       
  2808 	    RMemReadStream str(ptr, 4*sizeof(TInt32));	
       
  2809 	    screenNumber = str.ReadInt32L(); 
       
  2810     	origin.iX = str.ReadInt32L();
       
  2811 	    origin.iY = str.ReadInt32L();
       
  2812 	    count = str.ReadInt32L();
       
  2813         str.Release();
       
  2814         }
       
  2815 
       
  2816     if ( count > 0 )        
       
  2817         {
       
  2818         RMemReadStream str(((TUint8*)ptr) + 4*sizeof(TInt32), 4*sizeof(TInt32)*count);
       
  2819         TRect rect;
       
  2820         for (TInt i = 0; i < count; ++i)
       
  2821             {
       
  2822             rect.iTl.iX = str.ReadInt32L();
       
  2823             rect.iTl.iY = str.ReadInt32L();
       
  2824             rect.iBr.iX = str.ReadInt32L();
       
  2825             rect.iBr.iY = str.ReadInt32L();
       
  2826             region.AddRect(rect);
       
  2827             }
       
  2828         str.Release();
       
  2829         }
       
  2830     
       
  2831 	
       
  2832 	// fetch visual
       
  2833 	CHuiVisual* viz = FindVisual(windowNodeId);
       
  2834 	if (viz)
       
  2835 		{
       
  2836 #ifdef HUI_DEBUG_TRACK_DRAWING
       
  2837         if ( viz->Tracking() )
       
  2838             {
       
  2839             RDebug::Print(_L("CAlfBridge::HandleSetWindowAreaL - Tracked visual"));
       
  2840             }
       
  2841 #endif
       
  2842 		
       
  2843 		
       
  2844 		CHuiCanvasVisual* canvas = static_cast<CHuiCanvasVisual*>(viz);
       
  2845 		canvas->SetShape( origin, region );
       
  2846 		
       
  2847 		iAlfScreens[screenNumber]->SetVisualTreeVisibilityChanged(ETrue);
       
  2848 		}
       
  2849 	else
       
  2850 		{
       
  2851 		__ALFLOGSTRING("CAlfBridge::HandleSetWindowAreaL, EAlfDSSetWindowArea: Visual not found!");                                                
       
  2852 		}  
       
  2853 		
       
  2854     CleanupStack::PopAndDestroy();
  2457 	}
  2855 	}
  2458 
  2856 
  2459 // ---------------------------------------------------------------------------
  2857 // ---------------------------------------------------------------------------
  2460 // HandleReorderWindowL
  2858 // HandleReorderWindowL
  2461 // ---------------------------------------------------------------------------
  2859 // ---------------------------------------------------------------------------
  2665 #ifdef	USE_APPLICATION_ENDFULLSCREEN_TIMEOUT	
  3063 #ifdef	USE_APPLICATION_ENDFULLSCREEN_TIMEOUT	
  2666 	    if (iFullScreenEffectData 
  3064 	    if (iFullScreenEffectData 
  2667 	            && iFullScreenEffectData->iEffectType != CFullScreenEffectState::ENotDefinedEffect 
  3065 	            && iFullScreenEffectData->iEffectType != CFullScreenEffectState::ENotDefinedEffect 
  2668 	            && !iFullScreenEffectData->iEndFullScreen)
  3066 	            && !iFullScreenEffectData->iEndFullScreen)
  2669 	        {
  3067 	        {
  2670             TInt toAppUid; 
  3068 
       
  3069 	        CHuiControlGroup *to_group = NULL;
  2671             if (iFullScreenEffectData->iEffectType == CFullScreenEffectState::EExitEffect)
  3070             if (iFullScreenEffectData->iEffectType == CFullScreenEffectState::EExitEffect)
  2672                 {
  3071                 {
  2673                 toAppUid = iFullScreenEffectData->iFromAppId;
  3072                 to_group = FindControlGroupByFullScreenFromEffect();
  2674                 }
  3073                 }
  2675             else
  3074             else
  2676                 {
  3075                 {
  2677                 toAppUid = iFullScreenEffectData->iToAppId;
  3076                 to_group = FindControlGroupByFullScreenToEffect();
  2678                 }
  3077                 }
  2679             
  3078             
  2680             CHuiControlGroup *to_group = FindControlGroupByAppId(toAppUid);
       
  2681 	    
  3079 	    
  2682 	        // 1. if we get drawing commands after BeginFullScreen, we need to generate EndFullScreen call.
  3080 	        // 1. if we get drawing commands after BeginFullScreen, we need to generate EndFullScreen call.
  2683 	        // 2. only the first drawing commands will trigger EndFullScreen
  3081 	        // 2. only the first drawing commands will trigger EndFullScreen
  2684 	        // (this mechanism is here because we want to remove delay from fullscreen effects - and EndFullScreens are coming from application too late)
  3082 	        // (this mechanism is here because we want to remove delay from fullscreen effects - and EndFullScreens are coming from application too late)
  2685 	        
  3083 	        
  2686 	        if (viz->Owner().ControlGroup() == to_group)
  3084 	        if (viz->Owner().ControlGroup() == to_group)
  2687 	            {
  3085 	            {
  2688                 iFullScreenEffectData->ResetTimerL(this);
  3086                 if (!iFullScreenEffectData->iDrawingCompleteTimer)
  2689                 iFullScreenEffectData->iDisplaySize = iAlfScreens[0]->Size(); 
  3087                     {
       
  3088                     iFullScreenEffectData->InitDelayedEffectL(this, iAlfScreens[0]->Size());
       
  3089                     }
  2690                 THuiCanvasPaintedArea p = viz->PaintedArea(0);
  3090                 THuiCanvasPaintedArea p = viz->PaintedArea(0);
  2691 	            iFullScreenEffectData->iPaintedRegion.AddRect( p.iPaintedRect.Round() );
  3091 	            iFullScreenEffectData->iPaintedRegion.AddRect( p.iPaintedRect.Round() );
  2692 	            TRect b = iFullScreenEffectData->iPaintedRegion.BoundingRect();
  3092 	            TRect b = iFullScreenEffectData->iPaintedRegion.BoundingRect();
  2693 	            __ALFFXLOGSTRING3(
  3093 	            __ALFFXLOGSTRING3(
  2694 	                    "CAlfBridge::HandlePostCanvasBufferL : Effect to visual 0x%x, Covered rect: iTl.iX: %d , iTl.iY: %d",
  3094 	                    "CAlfBridge::HandlePostCanvasBufferL : Effect to visual 0x%x, Covered rect: iTl.iX: %d , iTl.iY: %d",
  2696 	                    b.iTl.iX, 
  3096 	                    b.iTl.iX, 
  2697 	                    b.iTl.iY);
  3097 	                    b.iTl.iY);
  2698 	            __ALFFXLOGSTRING2("CAlfBridge::HandlePostCanvasBufferL : iBr.iX: %d, iBr.iY: %d", b.iBr.iX, b.iBr.iY);
  3098 	            __ALFFXLOGSTRING2("CAlfBridge::HandlePostCanvasBufferL : iBr.iX: %d, iBr.iY: %d", b.iBr.iX, b.iBr.iY);
  2699 	                        }
  3099 	                        }
  2700 	        }
  3100 	        }
  2701 	        // END TP HACK
       
  2702 #endif
  3101 #endif
  2703 	}
  3102 	}
  2704 
  3103 
  2705 // ---------------------------------------------------------------------------
  3104 // ---------------------------------------------------------------------------
  2706 // HandleGfxEndFullScreenTimeout
  3105 // HandleGfxEndFullScreenTimeout
  2710     {
  3109     {
  2711     if (aFullScreenEffectData->iEndFullScreen)
  3110     if (aFullScreenEffectData->iEndFullScreen)
  2712         {
  3111         {
  2713         return;
  3112         return;
  2714         }
  3113         }
  2715     CHuiControlGroup *to_group = FindControlGroupByAppId(aFullScreenEffectData->iToAppId);
  3114     CHuiControlGroup *to_group = FindControlGroupByFullScreenToEffect();
  2716     CHuiControlGroup *from_group = FindControlGroupByAppId( aFullScreenEffectData->iFromAppId );
  3115     CHuiControlGroup *from_group = FindControlGroupByFullScreenFromEffect();
  2717     CHuiLayout *to_layout = NULL;
  3116     CHuiLayout *to_layout = NULL;
  2718     CHuiLayout *from_layout = NULL;
  3117     CHuiLayout *from_layout = NULL;
  2719     if (!to_group) // group has been destroyed and moved to effectControlGroup for waiting the application exit effect EndFullScreen trigger 
  3118     if (!to_group) // group has been destroyed and moved to effectControlGroup for waiting the application exit effect EndFullScreen trigger 
  2720          {
  3119          {
  2721         to_layout = FindLayoutByEffectHandle(aFullScreenEffectData->iHandle);
  3120         to_layout = FindLayoutByEffectHandle(aFullScreenEffectData->iHandle);
  2738         __ALFFXLOGSTRING1("CAlfBridge::HandleGfxEndFullScreenTimeout : Enough app drawing. Trigger EndFullScreen for layout 0x%x", to_layout);    
  3137         __ALFFXLOGSTRING1("CAlfBridge::HandleGfxEndFullScreenTimeout : Enough app drawing. Trigger EndFullScreen for layout 0x%x", to_layout);    
  2739         HandleGfxEventL( *aFullScreenEffectData, to_layout, from_layout );
  3138         HandleGfxEventL( *aFullScreenEffectData, to_layout, from_layout );
  2740         }
  3139         }
  2741 
  3140 
  2742     aFullScreenEffectData->iEndFullScreen = ETrue;
  3141     aFullScreenEffectData->iEndFullScreen = ETrue;
       
  3142     iAlfScreens[0]->SetVisualTreeVisibilityChanged(ETrue);
  2743     }
  3143     }
  2744 
  3144 
  2745 // ---------------------------------------------------------------------------
  3145 // ---------------------------------------------------------------------------
  2746 // SetWindowActiveL
  3146 // SetWindowActiveL
  2747 // ---------------------------------------------------------------------------
  3147 // ---------------------------------------------------------------------------
  2781                 }
  3181                 }
  2782             aVisual->ClearFlag(EHuiVisualFlagShouldBeHidden);
  3182             aVisual->ClearFlag(EHuiVisualFlagShouldBeHidden);
  2783             }
  3183             }
  2784         else
  3184         else
  2785             {
  3185             {
  2786 			// this prevents windows disappearing before their effect has finished
  3186 			// this prevents windows disappearing before their effect has finished, unless it makes no difference. 
  2787             aVisual->SetFlag(EHuiVisualFlagShouldBeHidden);
  3187             // For instance, if the visual is being shown by a screenshot in some other visual, then having this visual around 
  2788             aVisual->ClearFlag(EHuiVisualFlagShouldBeShown);
  3188             // will only break the "live view"
       
  3189             if (iEffectCleanupStack[effectIndex].iCanDestroyOrHideImmediately && !aVisual->Effect())
       
  3190                 {
       
  3191                 aVisual->ClearFlags(EHuiVisualFlagShouldBeShown | EHuiVisualFlagShouldBeHidden);
       
  3192                 aVisual->iOpacity.Set(0.0f);    
       
  3193                 }
       
  3194             else
       
  3195                 {
       
  3196                 aVisual->SetFlag(EHuiVisualFlagShouldBeHidden);
       
  3197                 aVisual->ClearFlag(EHuiVisualFlagShouldBeShown);
       
  3198                 }
  2789             }
  3199             }
  2790         }
  3200         }
  2791     }
  3201     }
  2792 
  3202 
  2793 // ---------------------------------------------------------------------------
  3203 // ---------------------------------------------------------------------------
  2847                    {
  3257                    {
  2848                    RDebug::Print(_L("CAlfBridge::HandleSetWindowActiveL - Tracked visual"));
  3258                    RDebug::Print(_L("CAlfBridge::HandleSetWindowActiveL - Tracked visual"));
  2849                    }
  3259                    }
  2850 #endif
  3260 #endif
  2851 				// Uses opacity for now                            
  3261 				// Uses opacity for now                            
  2852                 SetWindowActiveL(viz, windowAttributes->iActive);
  3262                 SetWindowActiveL(viz, windowAttributes->iActive);                
  2853                 }
  3263                 }
  2854 			else
  3264 			else
  2855 				{
  3265 				{
  2856 				__ALFLOGSTRING("CAlfBridge::HandleSetWindowActiveL, EAlfDSSetWindowActive: Visual not found!");     
  3266 				__ALFLOGSTRING("CAlfBridge::HandleSetWindowActiveL, EAlfDSSetWindowActive: Visual not found!");     
  2857 				}    
  3267 				}    
  2863 			USER_INVARIANT();
  3273 			USER_INVARIANT();
  2864 			break;                       	        
  3274 			break;                       	        
  2865 			}
  3275 			}
  2866 		}
  3276 		}
  2867     iAlfScreens[screenNumber]->SetVisualTreeVisibilityChanged(ETrue);	// TODO: Check if really changed                       
  3277     iAlfScreens[screenNumber]->SetVisualTreeVisibilityChanged(ETrue);	// TODO: Check if really changed                       
       
  3278 
       
  3279     AMT_INC_COUNTER( iTotalVisualFlagChangedCount );
       
  3280     AMT_INC_COUNTER_IF( windowAttributes->iActive, iActiveVisualCount );
       
  3281     AMT_INC_COUNTER_IF( !windowAttributes->iActive, iPassiveVisualCount );
       
  3282     AMT_MAP_INC_VALUE_IF( ( iWindowHashArray.Find( windowNodeId ) ), 
       
  3283                           iIntMap, iWindowHashArray.Find( windowNodeId )->iClientSideId, 
       
  3284                           EAlfModuleTestTypeBridgeChangeFlag );    
  2868 	}
  3285 	}
  2869 
  3286 
  2870 
  3287 
  2871 // ---------------------------------------------------------------------------
  3288 // ---------------------------------------------------------------------------
  2872 // HandleSetWindowFlagL
  3289 // HandleSetWindowFlagL
  3066 			viz->SetClearBackground(CHuiDisplay::EClearWithColor);
  3483 			viz->SetClearBackground(CHuiDisplay::EClearWithColor);
  3067 			viz->SetBackgroundColor(fullyTransparentColor);
  3484 			viz->SetBackgroundColor(fullyTransparentColor);
  3068 			}
  3485 			}
  3069 		else
  3486 		else
  3070 			{
  3487 			{
  3071 			viz->SetClearBackground(CHuiDisplay::EClearNone);
  3488             viz->SetClearBackground(CHuiDisplay::EClearNone);
       
  3489 
       
  3490             // Force update
       
  3491             viz->ClearCanvasFlags( EHuiCanvasFlagSurfaceInvisible );
       
  3492             viz->ClearCanvasFlags( EHuiCanvasFlagSurfaceVisible );
  3072 			}		
  3493 			}		
  3073 		}
  3494 		}
  3074 	else
  3495 	else
  3075 		{
  3496 		{
  3076 		if (iAlfWindowGroupNodeId != windowGroupNodeId)
  3497 		if (iAlfWindowGroupNodeId != windowGroupNodeId)
  3686     return aEngine->FxmlUsesInput1(aFileName);
  4107     return aEngine->FxmlUsesInput1(aFileName);
  3687     }
  4108     }
  3688 	
  4109 	
  3689 TBool CAlfBridge::HandleGfxEventL(CFullScreenEffectState& aEvent, CHuiLayout* aToLayout, CHuiLayout *aFromLayout)
  4110 TBool CAlfBridge::HandleGfxEventL(CFullScreenEffectState& aEvent, CHuiLayout* aToLayout, CHuiLayout *aFromLayout)
  3690     {
  4111     {
       
  4112     __ALFFXLOGSTRING4("CAlfBridge::HandleGfxEventL - To layout: 0x%x, From layout: 0x%x, Effect handle: %d, Action: %d", aToLayout, aFromLayout, aEvent.iHandle, aEvent.iAction);
  3691     TInt err = KErrNone;
  4113     TInt err = KErrNone;
  3692     TBool failed = EFalse;
  4114     TBool failed = EFalse;
  3693     
  4115     
  3694     // Check if there is an effects engine in HuiEnv
  4116     // Check if there is an effects engine in HuiEnv
  3695     CHuiFxEffect* effect = NULL;
  4117     CHuiFxEffect* effect = NULL;
  3716                     TRAP(err,StoreRenderBufferStartL(aToLayout));
  4138                     TRAP(err,StoreRenderBufferStartL(aToLayout));
  3717                     __ALFFXLOGSTRING1("CAlfBridge::HandleGfxEventL - EBeginFullScreen: Screenshot result: KErrNone == %d", err);
  4139                     __ALFFXLOGSTRING1("CAlfBridge::HandleGfxEventL - EBeginFullScreen: Screenshot result: KErrNone == %d", err);
  3718                     if (err == KErrNone)
  4140                     if (err == KErrNone)
  3719                         {
  4141                         {
  3720                         aToLayout->SetFreezeState(ETrue);
  4142                         aToLayout->SetFreezeState(ETrue);
       
  4143                         aEvent.iCanDestroyOrHideImmediately = ETrue; // if children of this layout are hidden or destroyed during effect, that can happen immediately
  3721                         }
  4144                         }
  3722                     else
  4145                     else
  3723                         {
  4146                         {
  3724                         return ETrue; // failed, effect will be canceled
  4147                         return ETrue; // failed, effect will be canceled
  3725                         }
  4148                         }
  3726                     }
  4149                     }
  3727 
  4150 
  3728                 switch(aEvent.iAction)
  4151                 switch(aEvent.iAction)
  3729                     {
  4152                     {
       
  4153                     case AknTransEffect::EApplicationActivate:
  3730                     case AknTransEffect::EApplicationStart:
  4154                     case AknTransEffect::EApplicationStart:
  3731                     case AknTransEffect::EApplicationStartRect:
  4155                     case AknTransEffect::EApplicationStartRect:
       
  4156                     case AknTransEffect::EApplicationStartSwitch:
       
  4157                     case AknTransEffect::EApplicationStartSwitchRect:
  3732                         {
  4158                         {
  3733                         aToLayout->iOpacity.Set(0.0f);    // these are meant for applications that yet dont have anything to show
  4159                         aToLayout->iOpacity.Set(0.0f);    // these are meant for applications that are not yet ready to be drawn, but possible already on the foreground
  3734                         FreezeLayoutUntilEffectDestroyedL(aFromLayout, aEvent.iHandle);
  4160                         FreezeLayoutUntilEffectDestroyedL(aFromLayout, aEvent.iHandle);
  3735                         aEvent.iEffectType = CFullScreenEffectState::EStartEffect;
  4161                         aEvent.iEffectType = CFullScreenEffectState::EStartEffect;
  3736                         break;
  4162                         break;
  3737                         }
  4163                         }
  3738                     case AknTransEffect::EApplicationStartSwitch:
       
  3739                     case AknTransEffect::EApplicationStartSwitchRect:
       
  3740                         {
       
  3741                         aToLayout->iOpacity.Set(0.0f);    // this is meant for applications that are in the background.
       
  3742                         FreezeLayoutUntilEffectDestroyedL(aFromLayout, aEvent.iHandle);
       
  3743                         aEvent.iEffectType = CFullScreenEffectState::EStartEffect;
       
  3744                         break;
       
  3745                         }
       
  3746 
       
  3747                     case AknTransEffect::EApplicationExit:
  4164                     case AknTransEffect::EApplicationExit:
  3748                         {
  4165                         {
  3749                         aEvent.iEffectType = CFullScreenEffectState::EExitEffect;
  4166                         aEvent.iEffectType = CFullScreenEffectState::EExitEffect;
  3750                         // The effect should start when the new view is ready,
  4167                         // The effect should start when the new view is ready,
  3751                         // but we have no signal telling us that, so we just have to do our best
  4168                         // but we have no signal telling us that, so we just have to do our best
  3764                             }
  4181                             }
  3765                         if ( aEvent.iAction == AknTransEffect::EApplicationExit && !(aToLayout->Flags() & EHuiVisualFlagInactive)) 
  4182                         if ( aEvent.iAction == AknTransEffect::EApplicationExit && !(aToLayout->Flags() & EHuiVisualFlagInactive)) 
  3766                             {
  4183                             {
  3767                             // this will tag the visual, that they cannot be hidden by HandleVisualVisibility
  4184                             // this will tag the visual, that they cannot be hidden by HandleVisualVisibility
  3768                             // Initialize layout for the exit effect  
  4185                             // Initialize layout for the exit effect  
  3769                             iLayoutInitializedForExitEffect = SetupEffectLayoutContainerL(aEvent.iHandle, aToLayout, ETrue);
  4186                             iLayoutInitializedForExitEffect = SetupEffectLayoutContainerL(aEvent.iHandle, aToLayout, ETrue, aEvent.iCanDestroyOrHideImmediately);
  3770                             __ALFFXLOGSTRING1("CAlfBridge::HandleGfxEventL - EBeginFullscreen - iLayoutInitializedForExitEffect: %d", iLayoutInitializedForExitEffect);
  4187                             __ALFFXLOGSTRING1("CAlfBridge::HandleGfxEventL - EBeginFullscreen - iLayoutInitializedForExitEffect: %d", iLayoutInitializedForExitEffect);
  3771                             aEvent.iSetupDone = iLayoutInitializedForExitEffect; 
  4188                             aEvent.iSetupDone = iLayoutInitializedForExitEffect; 
  3772                             }
  4189                             }
  3773                         else
  4190                         else
  3774                             {
  4191                             {
  3804                             }
  4221                             }
  3805                         else
  4222                         else
  3806                         	{
  4223                         	{
  3807                             // add visuals to visual cleanupstack
  4224                             // add visuals to visual cleanupstack
  3808                             aToLayout->SetStoredRenderBufferModificationsEnabled(EFalse);
  4225                             aToLayout->SetStoredRenderBufferModificationsEnabled(EFalse);
  3809                             layoutEffectable = SetupEffectLayoutContainerL(aEvent.iHandle,aToLayout, EFalse);
  4226                             layoutEffectable = SetupEffectLayoutContainerL(aEvent.iHandle,aToLayout, EFalse, aEvent.iCanDestroyOrHideImmediately);
  3810                             aEvent.iSetupDone = layoutEffectable; 
  4227                             aEvent.iSetupDone = layoutEffectable; 
  3811                             aToLayout->SetStoredRenderBufferModificationsEnabled(ETrue);
  4228                             aToLayout->SetStoredRenderBufferModificationsEnabled(ETrue);
  3812                             }
  4229                             }
  3813 
  4230 
  3814                         if (layoutEffectable)
  4231                         if (layoutEffectable)
  3894     RemoveTemporaryPresenterVisual(NULL, fxData->iHandle);
  4311     RemoveTemporaryPresenterVisual(NULL, fxData->iHandle);
  3895     // this was abort, so we might have received earlier event hiding this window. Here we'll bring it 
  4312     // this was abort, so we might have received earlier event hiding this window. Here we'll bring it 
  3896     // back
  4313     // back
  3897     if (fxData->iToAppId && fxData->iToAppId != KErrNotFound)
  4314     if (fxData->iToAppId && fxData->iToAppId != KErrNotFound)
  3898         {
  4315         {
  3899         RemoveEffectFromApp(fxData->iToAppId);
  4316         RemoveEffectFromApp(fxData->iToSecureId, fxData->iToWg );
  3900         RemoveEffectFromApp(fxData->iFromAppId);
  4317         RemoveEffectFromApp(fxData->iFromSecureId, fxData->iFromWg );
  3901         }
  4318         }
  3902     else
  4319     else
  3903         {
  4320         {
  3904         // abort ALL effects
  4321         // abort ALL effects
  3905         RemoveAllTemporaryPresenterVisuals();
  4322         RemoveAllTemporaryPresenterVisuals();
  3915     
  4332     
  3916     CleanupStack::PopAndDestroy( fxData );
  4333     CleanupStack::PopAndDestroy( fxData );
  3917     __ALFFXLOGSTRING("CAlfBridge::HandleGfxStopEvent - END");
  4334     __ALFFXLOGSTRING("CAlfBridge::HandleGfxStopEvent - END");
  3918     }
  4335     }
  3919 
  4336 
  3920 void CAlfBridge::RemoveEffectFromApp(TInt aAppUid)
  4337 void CAlfBridge::RemoveEffectFromApp(TInt aSecureId, TInt aWgId )
  3921     {
  4338     {
  3922     if(aAppUid <= 0)
  4339     if(aSecureId == 0)
  3923         {
  4340         {
  3924         return;
  4341         return;
  3925         }
  4342         }
  3926     CHuiControlGroup* group = FindControlGroupByAppId(aAppUid);
  4343     CHuiControlGroup* group = NULL;
       
  4344     if ( aWgId > 0 )
       
  4345         {
       
  4346         // check with the specific window gruop
       
  4347         group = FindControlGroupBySecureId(aSecureId, aWgId);
       
  4348         }
       
  4349     else 
       
  4350         {
       
  4351         // any window gruop will do
       
  4352         group = FindControlGroupBySecureId(aSecureId);
       
  4353         }
       
  4354     
  3927     if (group)
  4355     if (group)
  3928         {
  4356         {
  3929         CHuiControl& control = group->Control(0);
  4357         CHuiControl& control = group->Control(0);
  3930         CHuiLayout* layout = (CHuiLayout*)&control.Visual(0);
  4358         CHuiLayout* layout = (CHuiLayout*)&control.Visual(0);
  3931     
  4359     
  3990 			}
  4418 			}
  3991             
  4419             
  3992             if (iFullScreenEffectData && iFullScreenEffectData->iToAppId != fxData->iToAppId)
  4420             if (iFullScreenEffectData && iFullScreenEffectData->iToAppId != fxData->iToAppId)
  3993                 {
  4421                 {
  3994 				__ALFFXLOGSTRING("CAlfBridge::HandleGfxEffectsL - WARNING - Another fullscreen effect to different app. Deleting the previous ongoing effect"); 
  4422 				__ALFFXLOGSTRING("CAlfBridge::HandleGfxEffectsL - WARNING - Another fullscreen effect to different app. Deleting the previous ongoing effect"); 
  3995                 RemoveEffectFromApp(iFullScreenEffectData->iToAppId);// Fullscreen effect for another app has arrived, and the previous has not finished and abort effect was not called.
  4423                 RemoveEffectFromApp(iFullScreenEffectData->iToSecureId, iFullScreenEffectData->iToWg);// Fullscreen effect for another app has arrived, and the previous has not finished and abort effect was not called.
  3996                 RemoveEffectFromApp(iFullScreenEffectData->iFromAppId);
  4424                 RemoveEffectFromApp(iFullScreenEffectData->iFromSecureId, iFullScreenEffectData->iFromWg);
  3997                 // Fullscreen effect for another 
  4425                 // Fullscreen effect for another 
  3998                 }
  4426                 }
  3999             
  4427             
  4000             delete iFullScreenEffectData;
  4428             delete iFullScreenEffectData;
  4001             iFullScreenEffectData = fxData;
  4429             iFullScreenEffectData = fxData;
  4044 
  4472 
  4045     CFullScreenEffectState* fxData = iFullScreenEffectData;
  4473     CFullScreenEffectState* fxData = iFullScreenEffectData;
  4046     fxData->iOperation = operation;
  4474     fxData->iOperation = operation;
  4047     fxData->iWaitingWindowGroup = EFalse;
  4475     fxData->iWaitingWindowGroup = EFalse;
  4048 
  4476 
  4049     __ALFFXLOGSTRING3("Operation: %d, handle: %d, type: %d", operation, fxData->iHandle, fxData->iType);
  4477     __ALFFXLOGSTRING3("CAlfBridge::HandleGfxEffectsL - Operation: %d, handle: %d, type: %d", operation, fxData->iHandle, fxData->iType);
  4050     __ALFFXLOGSTRING2("wg1: %d, wg2: %d", fxData->iWg1, fxData->iWg2);
  4478     __ALFFXLOGSTRING2("CAlfBridge::HandleGfxEffectsL - towg: %d, fromwg: %d", fxData->iToWg, fxData->iFromWg);
  4051 
  4479 
  4052     // find root nodes and attach effects to them
  4480     // find root nodes and attach effects to them
  4053     // First we need a windowgroup node id. So far we have a list of window ids
  4481     // First we need a windowgroup node id. So far we have a list of window ids
  4054 
  4482 
  4055     // wg2 is the window group that is supposed to disappear from view
  4483     // wg2 is the window group that is supposed to disappear from view
  4079 
  4507 
  4080     // This effect is triggered either by BeginFullScreen or by EndFullScreen
  4508     // This effect is triggered either by BeginFullScreen or by EndFullScreen
  4081     // depending on if we have an application that is already running or not
  4509     // depending on if we have an application that is already running or not
  4082 
  4510 
  4083     //    TAlfControlGroupEntry* alfGroup = NULL;
  4511     //    TAlfControlGroupEntry* alfGroup = NULL;
  4084     // TODO: 
       
  4085     //wg1 = (*iHost)->FindWgForAppUid(TUid::Uid(toAppId1));
       
  4086     //if (!wg1 && action != AknTransEffect::EApplicationExit )
       
  4087     // 	{
       
  4088     // 	// window group is not available yet, but it will be created in short while.
       
  4089     //  	iEffectWaitingWindowgroup.Append(toAppId1);
       
  4090     //  	}
       
  4091     // TODO: when ids available from wserv...
       
  4092     // if ( appUid1 )
       
  4093     //{
       
  4094     //	 group1 = FindControlGrouAppUId( appUid1, screen1, &alfGroup );
       
  4095     // }
       
  4096 
  4512 
  4097     TBool failed = EFalse;
  4513     TBool failed = EFalse;
  4098     if (fxData->iToAppId && fxData->iToAppId != KErrNotFound)
  4514     if (fxData->iToAppId && fxData->iToAppId != KErrNotFound)
  4099         {        
  4515         {        
  4100         CHuiControlGroup* toGroup = NULL;
  4516         CHuiControlGroup* toGroup = NULL;
  4101         CHuiLayout* toLayout = NULL; 
  4517         CHuiLayout* toLayout = NULL; 
  4102         toGroup = FindControlGroupByAppId(fxData->iToAppId);
  4518         toGroup = FindControlGroupByFullScreenToEffect();
  4103 
  4519 
  4104         CHuiControlGroup* fromGroup = NULL;
  4520         CHuiControlGroup* fromGroup = NULL;
  4105         CHuiLayout* fromLayout = NULL; 
  4521         CHuiLayout* fromLayout = NULL; 
  4106         fromGroup = FindControlGroupByAppId(fxData->iFromAppId);
  4522         fromGroup = FindControlGroupByFullScreenFromEffect();
  4107 
  4523 
  4108         if (!toGroup) // group has been destroyed and moved to effectControlGroup for waiting the application exit effect EndFullScreen trigger 
  4524         if (!toGroup) // group has been destroyed and moved to effectControlGroup for waiting the application exit effect EndFullScreen trigger 
  4109             {
  4525             {
  4110             toLayout = FindLayoutByEffectHandle(fxData->iHandle);
  4526             toLayout = FindLayoutByEffectHandle(fxData->iHandle);
  4111             }
  4527             }
  4180         RemoveAllTemporaryPresenterVisuals();
  4596         RemoveAllTemporaryPresenterVisuals();
  4181         iHuiEnv->ContinueRefresh();
  4597         iHuiEnv->ContinueRefresh();
  4182         }
  4598         }
  4183     __ALFFXLOGSTRING("CAlfBridge::HandleGfxStopEffectsL - end");
  4599     __ALFFXLOGSTRING("CAlfBridge::HandleGfxStopEffectsL - end");
  4184     }
  4600     }
       
  4601 
       
  4602 void CAlfBridge::HandleGfxStopControlEffectsL(TAlfBridgerData data)
       
  4603     {
       
  4604     TInt length = data.iInt2;
       
  4605     __ALFFXLOGSTRING1("CAlfBridge::HandleGfxStopControlEffectsL - Reading bridge data %d", (TInt)data.iPtr);
       
  4606     void* bridgeBuffer = (void*) (*iHost)->GetEffectsDataL( (TInt)data.iPtr );    
       
  4607     RMemReadStream stream( bridgeBuffer, length );
       
  4608     
       
  4609     TInt operation = stream.ReadInt32L();
       
  4610     TInt handle = stream.ReadInt32L();
       
  4611     stream.Release();
       
  4612 
       
  4613     if (handle != KErrNotFound)
       
  4614         {
       
  4615         __ALFFXLOGSTRING1("CAlfBridge::HandleGfxStopControlEffectsL - Remove effect with handle: %d", handle);
       
  4616         RemoveTemporaryPresenterVisual(NULL, handle);
       
  4617         iHuiEnv->ContinueRefresh();
       
  4618         }
       
  4619     __ALFFXLOGSTRING("CAlfBridge::HandleGfxStopControlEffectsL - end");
       
  4620     }
       
  4621 
  4185 
  4622 
  4186 void CAlfBridge::HandleRegisterEffectL( TAlfBridgerData data )
  4623 void CAlfBridge::HandleRegisterEffectL( TAlfBridgerData data )
  4187     {     
  4624     {     
  4188     TInt action = data.iInt1;
  4625     TInt action = data.iInt1;
  4189     TInt length = data.iInt2;    
  4626     TInt length = data.iInt2;    
  4236         CHuiVisual* aSourceVisual, 
  4673         CHuiVisual* aSourceVisual, 
  4237         CHuiLayout* aTargetLayout, 
  4674         CHuiLayout* aTargetLayout, 
  4238         CHuiControl* aEffectControl, 
  4675         CHuiControl* aEffectControl, 
  4239         TBool aInsertTemporaryVisual,
  4676         TBool aInsertTemporaryVisual,
  4240         TInt& aItemDestroyed,
  4677         TInt& aItemDestroyed,
  4241         TBool aIsExitEffect)
  4678         TBool aIsExitEffect,
       
  4679         TBool aCanDestroyOrHideImmediately)
  4242     {
  4680     {
  4243     CHuiCanvasVisual* temporaryPresenterVisual = NULL;
  4681     CHuiCanvasVisual* temporaryPresenterVisual = NULL;
  4244     TInt enableEffect = ETrue;
  4682     TInt enableEffect = ETrue;
  4245     
  4683     
  4246     if (aSourceVisual->iOpacity.Now() >= 0.01)
  4684     if (aSourceVisual->iOpacity.Now() >= 0.01 && !(aSourceVisual->Flags() & EHuiVisualFlagShouldBeHidden))
  4247         {
  4685         {
  4248         aSourceVisual->SetFlag(EHuiVisualFlagShouldBeShown);
  4686         aSourceVisual->SetFlag(EHuiVisualFlagShouldBeShown);
  4249         }
  4687         }
  4250     
  4688     
  4251     aSourceVisual->ClearFlags(EHuiVisualFlagShouldBeInactive | EHuiVisualFlagShouldBeUnderOpaqueHint);
  4689     aSourceVisual->ClearFlags(EHuiVisualFlagShouldBeInactive | EHuiVisualFlagShouldBeUnderOpaqueHint);
  4285             TEffectCleanupStruct item = TEffectCleanupStruct(
  4723             TEffectCleanupStruct item = TEffectCleanupStruct(
  4286                     aEffectHandle,
  4724                     aEffectHandle,
  4287                     aSourceVisual, 
  4725                     aSourceVisual, 
  4288                     temporaryPresenterVisual,
  4726                     temporaryPresenterVisual,
  4289                     ETrue,
  4727                     ETrue,
  4290                     aIsExitEffect);
  4728                     aIsExitEffect,
       
  4729                     aCanDestroyOrHideImmediately);
  4291             iEffectCleanupStack.AppendL(item);
  4730             iEffectCleanupStack.AppendL(item);
  4292             }
  4731             }
  4293         else
  4732         else
  4294             {
  4733             {
  4295             // this will be a child of another visual, and draw by its parent external content visual
  4734             // this will be a child of another visual, and draw by its parent external content visual
  4296             // aSourceVisual->SetFlag(EHuiVisualFlagDrawOnlyAsExternalContent);
  4735             // aSourceVisual->SetFlag(EHuiVisualFlagDrawOnlyAsExternalContent);
  4297             TEffectCleanupStruct item = TEffectCleanupStruct(aEffectHandle,
  4736             TEffectCleanupStruct item = TEffectCleanupStruct(aEffectHandle,
  4298                         aSourceVisual, NULL, EFalse,
  4737                         aSourceVisual, NULL, EFalse,
  4299                         aIsExitEffect);
  4738                         aIsExitEffect,
       
  4739                         aCanDestroyOrHideImmediately);
  4300             iEffectCleanupStack.AppendL(item);
  4740             iEffectCleanupStack.AppendL(item);
  4301             }
  4741             }
  4302      }
  4742      }
  4303     return temporaryPresenterVisual;
  4743     return temporaryPresenterVisual;
  4304     }
  4744     }
  4308         CHuiLayout* aSourceLayout, 
  4748         CHuiLayout* aSourceLayout, 
  4309         CHuiLayout* aTargetLayout, 
  4749         CHuiLayout* aTargetLayout, 
  4310         CHuiControl* aEffectControl,
  4750         CHuiControl* aEffectControl,
  4311         TInt& aItemsDestroyed,
  4751         TInt& aItemsDestroyed,
  4312         TBool aAddLayout,
  4752         TBool aAddLayout,
  4313         TBool aIsExitEffect)
  4753         TBool aIsExitEffect,
       
  4754         TBool aCanDestroyOrHideImmediately)
  4314     {
  4755     {
  4315     __ALFFXLOGSTRING2("CAlfBridge::AddToEffectLayoutContainerL 0x%x is having %d children", aSourceLayout, aSourceLayout->Count());
  4756     __ALFFXLOGSTRING2("CAlfBridge::AddToEffectLayoutContainerL 0x%x is having %d children", aSourceLayout, aSourceLayout->Count());
  4316     if (aAddLayout)
  4757     if (aAddLayout)
  4317         {
  4758         {
  4318         AddEffectItemL(aEffectHandle, aSourceLayout, aTargetLayout, aEffectControl, EFalse, aItemsDestroyed, aIsExitEffect);
  4759         AddEffectItemL(aEffectHandle, aSourceLayout, aTargetLayout, aEffectControl, EFalse, aItemsDestroyed, aIsExitEffect, aCanDestroyOrHideImmediately);
  4319         }
  4760         }
  4320         
  4761         
  4321     for (TInt i = 0; i < aSourceLayout->Count(); i++)
  4762     for (TInt i = 0; i < aSourceLayout->Count(); i++)
  4322            {
  4763            {
  4323            CHuiCanvasVisual& sourceVisual = static_cast<CHuiCanvasVisual&> (aSourceLayout->Visual(i));
  4764            CHuiCanvasVisual& sourceVisual = static_cast<CHuiCanvasVisual&> (aSourceLayout->Visual(i));
  4324            
  4765            
  4325            if (sourceVisual.Count())
  4766            if (sourceVisual.Count())
  4326                {
  4767                {
  4327                CHuiLayout& layout = static_cast<CHuiLayout&> (aSourceLayout->Visual(i));
  4768                CHuiLayout& layout = static_cast<CHuiLayout&> (aSourceLayout->Visual(i));
  4328                AddToEffectLayoutContainerL(aEffectHandle, &layout, NULL, aEffectControl, aItemsDestroyed, EFalse,aIsExitEffect );
  4769                AddToEffectLayoutContainerL(aEffectHandle, &layout, NULL, aEffectControl, aItemsDestroyed, EFalse,aIsExitEffect, aCanDestroyOrHideImmediately );
  4329                }
  4770                }
  4330            AddEffectItemL(aEffectHandle, &sourceVisual, aTargetLayout, aEffectControl, EFalse, aItemsDestroyed, aIsExitEffect);
  4771            AddEffectItemL(aEffectHandle, &sourceVisual, aTargetLayout, aEffectControl, EFalse, aItemsDestroyed, aIsExitEffect, aCanDestroyOrHideImmediately);
  4331            }
  4772            }
  4332     __ALFFXLOGSTRING2("CAlfBridge::AddToEffectLayoutContainerL 0x%x end of children", aSourceLayout, aSourceLayout->Count());
  4773     __ALFFXLOGSTRING2("CAlfBridge::AddToEffectLayoutContainerL 0x%x end of children", aSourceLayout, aSourceLayout->Count());
  4333     }
  4774     }
  4334 
  4775 
  4335 TBool CAlfBridge::SetupEffectLayoutContainerL(TInt aHandle,CHuiLayout* aSourceLayout, TBool aIsExitEffect)
  4776 TBool CAlfBridge::SetupEffectLayoutContainerL(TInt aHandle,CHuiLayout* aSourceLayout, TBool aIsExitEffect, TBool aCanDestroyOrHideImmediately)
  4336     {
  4777     {
  4337     __ALFFXLOGSTRING3("CAlfBridge::SetupEffectLayoutContainerL - aHandle: %d, aSourceLayout: 0x%x, aIsExitEffect: % d >>", aHandle, aSourceLayout, aIsExitEffect );
  4778     __ALFFXLOGSTRING4("CAlfBridge::SetupEffectLayoutContainerL - aHandle: %d, aSourceLayout: 0x%x, aIsExitEffect: % d, CanDestroyOrHideImmediately: %d >>", 
       
  4779             aHandle, 
       
  4780             aSourceLayout, 
       
  4781             aIsExitEffect,
       
  4782             aCanDestroyOrHideImmediately );
  4338     
  4783     
  4339     if (aSourceLayout->Flags() & EHuiVisualFlagDrawOnlyAsExternalContent)
  4784     if (aSourceLayout->Flags() & EHuiVisualFlagDrawOnlyAsExternalContent)
  4340         {
  4785         {
  4341         // the requested visual is already having an effect. 
  4786         // the requested visual is already having an effect. 
  4342         __ALFFXLOGSTRING("CAlfBridge::SetupEffectLayoutContainerL - WE ARE ALREADY HAVING EFFECT! WHAT TO DO??");
  4787         __ALFFXLOGSTRING("CAlfBridge::SetupEffectLayoutContainerL - WE ARE ALREADY HAVING EFFECT! WHAT TO DO??");
  4347     CHuiLayout& effectControlGroupLayout = (CHuiLayout&) effectControlGroup.Visual(0);
  4792     CHuiLayout& effectControlGroupLayout = (CHuiLayout&) effectControlGroup.Visual(0);
  4348 
  4793 
  4349     // CHuiCanvasVisual* temporaryPresenterLayout = CHuiCanvasVisual::AddNewL( effectControlGroup, &effectControlGroupLayout);
  4794     // CHuiCanvasVisual* temporaryPresenterLayout = CHuiCanvasVisual::AddNewL( effectControlGroup, &effectControlGroupLayout);
  4350     // create presenter visual and set bindings
  4795     // create presenter visual and set bindings
  4351     TInt itemsDestroyed(0);
  4796     TInt itemsDestroyed(0);
  4352     AddToEffectLayoutContainerL(aHandle, aSourceLayout, NULL, &effectControlGroup, itemsDestroyed, EFalse, aIsExitEffect);
  4797     AddToEffectLayoutContainerL(aHandle, aSourceLayout, NULL, &effectControlGroup, itemsDestroyed, EFalse, aIsExitEffect, aCanDestroyOrHideImmediately);
  4353 
  4798 
  4354     if (aIsExitEffect)
  4799     if (aIsExitEffect)
  4355         {
  4800         {
  4356         CHuiCanvasVisual* temporaryPresenterVisual = AddEffectItemL(aHandle, aSourceLayout, &effectControlGroupLayout, &effectControlGroup, ETrue, itemsDestroyed, aIsExitEffect);
  4801         CHuiCanvasVisual* temporaryPresenterVisual = AddEffectItemL(aHandle, aSourceLayout, &effectControlGroupLayout, &effectControlGroup, ETrue, itemsDestroyed, aIsExitEffect, EFalse);
  4357         aSourceLayout->SetFlag(EHuiVisualFlagDrawOnlyAsExternalContent);
  4802         aSourceLayout->SetFlag(EHuiVisualFlagDrawOnlyAsExternalContent);
  4358         __ALFFXLOGSTRING3("CAlfBridge::SetupEffectLayoutContainerL - adding handle: %d, 0x%x (source layout)-> 0x%x (presenter layout) to iEffectCleanupStack", aHandle, aSourceLayout, temporaryPresenterVisual);
  4803         __ALFFXLOGSTRING3("CAlfBridge::SetupEffectLayoutContainerL - adding handle: %d, 0x%x (source layout)-> 0x%x (presenter layout) to iEffectCleanupStack", aHandle, aSourceLayout, temporaryPresenterVisual);
  4359         }
  4804         }
  4360     else
  4805     else
  4361         {
  4806         {
  4362         AddEffectItemL(aHandle, aSourceLayout, NULL, &effectControlGroup, EFalse, itemsDestroyed, EFalse);
  4807         AddEffectItemL(aHandle, aSourceLayout, NULL, &effectControlGroup, EFalse, itemsDestroyed, EFalse, EFalse);
  4363         __ALFFXLOGSTRING2("CAlfBridge::SetupEffectLayoutContainerL - adding handle: %d, 0x%x (source layout), NO presenter layout) to iEffectCleanupStack", aHandle, aSourceLayout);
  4808         __ALFFXLOGSTRING2("CAlfBridge::SetupEffectLayoutContainerL - adding handle: %d, 0x%x (source layout), NO presenter layout) to iEffectCleanupStack", aHandle, aSourceLayout);
  4364         }
  4809         }
  4365     iAlfScreens[0]->iVisualTreeVisibilityChanged = ETrue;
  4810     iAlfScreens[0]->iVisualTreeVisibilityChanged = ETrue;
  4366     iAlfScreens[0]->iDisplay->SetDirty();
  4811     iAlfScreens[0]->iDisplay->SetDirty();
  4367     if (itemsDestroyed)
  4812     if (itemsDestroyed)
  4368         {
  4813         {
  4369         __ALFFXLOGSTRING3("CAlfBridge::SetupEffectLayoutContainerL - trying to put effect on destroyed visuals. Skipping effect visual: 0x%x, handle %d, %d items destroyed", aSourceLayout, aHandle, itemsDestroyed);
  4814         __ALFFXLOGSTRING3("CAlfBridge::SetupEffectLayoutContainerL - trying to put effect on destroyed visuals. Skipping effect visual: 0x%x, handle %d, %d items destroyed", aSourceLayout, aHandle, itemsDestroyed);
  4370         }
  4815         }
  4371     __ALFFXLOGSTRING("CAlfBridge::SetupEffectLayoutContainerL");
  4816     __ALFFXLOGSTRING("CAlfBridge::SetupEffectLayoutContainerL");
  4372     return ETrue; // TBool(!itemsDestroyed);
  4817     return ETrue; // TBool(!itemsDestroyed);
  4373     }
       
  4374 
       
  4375 void CAlfBridge::SetupEffectContainerL(TInt aHandle,
       
  4376         CHuiCanvasVisual* aSourceVisual, TBool aIsExitEffect)
       
  4377     {
       
  4378     // if the original visual is having an effect, then remove it.
       
  4379     if (HasActiveEffect(aSourceVisual))
       
  4380         {
       
  4381         RemoveTemporaryPresenterVisual(aSourceVisual); 
       
  4382         }
       
  4383         
       
  4384     // Create new temporary presenter visual for the effect
       
  4385     CHuiControl& effectControlGroup =
       
  4386             iAlfScreens[0]->iFullscreenEffectControlGroup->Control(0);
       
  4387     CHuiLayout* layout = (CHuiLayout*) &effectControlGroup.Visual(0);
       
  4388     CHuiCanvasVisual* temporaryPresenterVisual = NULL;
       
  4389     temporaryPresenterVisual = CHuiCanvasVisual::AddNewL(effectControlGroup, layout);
       
  4390     // attach the source to the presenter visual
       
  4391     temporaryPresenterVisual->SetExternalContentL(aSourceVisual);
       
  4392     aSourceVisual->SetFlag(EHuiVisualFlagDrawOnlyAsExternalContent);
       
  4393     temporaryPresenterVisual->ClearFlag(EHuiVisualFlagInactive);
       
  4394     aSourceVisual->SetChanged();
       
  4395     // append to cleanup stack. this is cleaned in RemoveTemporaryVisuals after effect has finished
       
  4396     iEffectCleanupStack.AppendL(TEffectCleanupStruct(aHandle, aSourceVisual, temporaryPresenterVisual, EFalse /*iIsLayout*/, aIsExitEffect));
       
  4397     __ALFFXLOGSTRING3("CAlfBridge::SetupEffectContainerL - adding handle: %d, 0x%x (source visual)-> 0x%x (presenter visual)", aHandle, aSourceVisual, temporaryPresenterVisual);
       
  4398     }
  4818     }
  4399 
  4819 
  4400 void CAlfBridge::HandleGfxControlEffectsL( TAlfBridgerData data )
  4820 void CAlfBridge::HandleGfxControlEffectsL( TAlfBridgerData data )
  4401     {
  4821     {
  4402     TInt action = data.iInt1;
  4822     TInt action = data.iInt1;
  4460         }
  4880         }
  4461 
  4881 
  4462     if (engine)
  4882     if (engine)
  4463         {
  4883         {
  4464         // clear out old effect if this visual has one
  4884         // clear out old effect if this visual has one
  4465         __ALFFXLOGSTRING1("HandleGfxControlEffectsL - loading effect %S", &aEvent.iEffectName );
  4885         __ALFFXLOGSTRING2("HandleGfxControlEffectsL - loading effect %S on visual 0x%x", aEvent.iEffectName, aCanvasVisual );
  4466         __ALFFXLOGSTRING1("HandleGfxControlEffectsL - loading control effect, handle %d", aEvent.iHandle );
  4886         __ALFFXLOGSTRING1("HandleGfxControlEffectsL - loading control effect, handle %d", aEvent.iHandle );
  4467         if (HasActiveEffect(aCanvasVisual))
  4887         if (aCanvasVisual->Effect())
  4468             {
  4888             {
  4469             __ALFFXLOGSTRING1("HandleGfxControlEffectsL - 0x%x has active effect. Requesting removal.", aCanvasVisual);
  4889             __ALFFXLOGSTRING1("HandleGfxControlEffectsL - 0x%x has active effect. Requesting removal.", aCanvasVisual);
  4470             // another effect coming to already effected visual. E.g. close options menu, while opening effect still ongoing
  4890             // another effect coming to already effected visual. E.g. close options menu, while opening effect still ongoing
  4471             RemoveTemporaryPresenterVisual(aCanvasVisual);
  4891             RemoveTemporaryPresenterVisual(aCanvasVisual);
  4472             }
  4892             }
  4482                 // Lets make it visible again, and ask it to be hidden in the end of the effect
  4902                 // Lets make it visible again, and ask it to be hidden in the end of the effect
  4483                 // this enables at least the notes disappear effects
  4903                 // this enables at least the notes disappear effects
  4484                 aCanvasVisual->iOpacity.Set(KAlfVisualDefaultOpacity);
  4904                 aCanvasVisual->iOpacity.Set(KAlfVisualDefaultOpacity);
  4485                 // visual->SetFlag(EHuiVisualFlagShouldBeHidden);
  4905                 // visual->SetFlag(EHuiVisualFlagShouldBeHidden);
  4486                 }*/
  4906                 }*/
  4487             layoutEffectable = SetupEffectLayoutContainerL(aEvent.iHandle, aCanvasVisual, ETrue);
  4907             layoutEffectable = SetupEffectLayoutContainerL(aEvent.iHandle, aCanvasVisual, ETrue, EFalse);
  4488             }
  4908             }
  4489         else
  4909         else
  4490             {
  4910             {
  4491             layoutEffectable = SetupEffectLayoutContainerL(aEvent.iHandle, aCanvasVisual, EFalse);
  4911             layoutEffectable = SetupEffectLayoutContainerL(aEvent.iHandle, aCanvasVisual, EFalse, EFalse);
  4492             }
  4912             }
  4493         if (layoutEffectable)
  4913         if (layoutEffectable)
  4494             {
  4914             {
  4495             TRAP( err, engine->LoadGroupEffectL(*aEvent.iEffectName, effect, aCanvasVisual->Effectable(), engine->ActiveGroupEffect(), NULL, this, aEvent.iHandle, KHuiFxDelayRunUntilFirstFrameHasBeenDrawn ) );
  4915             TRAP( err, engine->LoadGroupEffectL(*aEvent.iEffectName, effect, aCanvasVisual->Effectable(), engine->ActiveGroupEffect(), NULL, this, aEvent.iHandle, KHuiFxDelayRunUntilFirstFrameHasBeenDrawn ) );
  4496             }
  4916             }
  4550         }
  4970         }
  4551 	
  4971 	
  4552     if (showVisual)
  4972     if (showVisual)
  4553         {
  4973         {
  4554         sourceViz->iOpacity.Set(KAlfVisualDefaultOpacity);
  4974         sourceViz->iOpacity.Set(KAlfVisualDefaultOpacity);
  4555         sourceViz->ClearFlag(EHuiVisualFlagShouldBeShown); // it is now hidden
  4975         sourceViz->ClearFlag(EHuiVisualFlagShouldBeShown); // it is now shown
  4556         }
  4976         }
  4557     
  4977     
  4558     if (destroyVisual)
  4978     if (destroyVisual)
  4559     	{
  4979     	{
  4560     	sourceViz->iOpacity.Set(0.0f);
  4980     	sourceViz->iOpacity.Set(0.0f);
  4630             __ALFFXLOGSTRING1("CAlfBridge::RemoveTemporaryPresenterItem - Destroying sourceViz: 0x%x", sourceViz);
  5050             __ALFFXLOGSTRING1("CAlfBridge::RemoveTemporaryPresenterItem - Destroying sourceViz: 0x%x", sourceViz);
  4631             aEffectItem.iEffectedVisual = NULL;
  5051             aEffectItem.iEffectedVisual = NULL;
  4632             }
  5052             }
  4633         else
  5053         else
  4634             {
  5054             {
  4635             TLex8 lex(sourceViz->Tag());
       
  4636             TInt nodeId;
       
  4637             lex.Val(nodeId);
       
  4638             DestroyWindow(sourceViz, ETrue);
  5055             DestroyWindow(sourceViz, ETrue);
  4639             }
  5056             }
  4640         }
  5057         }
  4641     return TBool(destroyVisual);
  5058     return TBool(destroyVisual);
  4642     }
  5059     }
  4713         if (aVisual == iEffectCleanupStack[i].iEffectedVisual)
  5130         if (aVisual == iEffectCleanupStack[i].iEffectedVisual)
  4714             {
  5131             {
  4715             return iEffectCleanupStack[i].iHandle;
  5132             return iEffectCleanupStack[i].iHandle;
  4716             }
  5133             }
  4717         }
  5134         }
  4718     __ALFFXLOGSTRING1(" CAlfBridge::SetupEffectLayoutContainerL - Could not find handle for 0x%x", aVisual);
  5135     __ALFFXLOGSTRING1("CAlfBridge::FindEffectHandle - Could not find handle for 0x%x", aVisual);
  4719     return KErrNotFound;
  5136     return KErrNotFound;
  4720     }
  5137     }
  4721 
  5138 
  4722 CHuiLayout* CAlfBridge::FindLayoutByEffectHandle(TInt aHandle)
  5139 CHuiLayout* CAlfBridge::FindLayoutByEffectHandle(TInt aHandle)
  4723     {
  5140     {
  4741     TInt itemsRemoved(0);
  5158     TInt itemsRemoved(0);
  4742     CHuiControl& effectControlGroup =  iAlfScreens[0]->iFullscreenEffectControlGroup->Control(0);
  5159     CHuiControl& effectControlGroup =  iAlfScreens[0]->iFullscreenEffectControlGroup->Control(0);
  4743     CHuiLayout* effectControlGroupLayout = (CHuiLayout*) &effectControlGroup.Visual(0);
  5160     CHuiLayout* effectControlGroupLayout = (CHuiLayout*) &effectControlGroup.Visual(0);
  4744     __ALFFXLOGSTRING1("CAlfBridge::RemoveTemporaryPresenterVisuals - BEGIN - effects in layout %d", effectControlGroupLayout->Count());
  5161     __ALFFXLOGSTRING1("CAlfBridge::RemoveTemporaryPresenterVisuals - BEGIN - effects in layout %d", effectControlGroupLayout->Count());
  4745 
  5162 
  4746     while (iFinishedCleanupStackEffects.Count())
  5163     while(iFinishedCleanupStackEffects.Count())
  4747         {
  5164         {
  4748         for (TInt i = 0; i < iEffectCleanupStack.Count() && iFinishedCleanupStackEffects.Count(); i++)
  5165         for (TInt i = 0; i < iEffectCleanupStack.Count() ; i++)
  4749             {
  5166             {
  4750             __ALFFXLOGSTRING2("CAlfBridge::RemoveTemporaryPresenterVisuals - looping, finished count: %d, index in active effecs: %d", iFinishedCleanupStackEffects.Count(), i );
  5167             __ALFFXLOGSTRING2("CAlfBridge::RemoveTemporaryPresenterVisuals - looping, finished count: %d, index in active effecs: %d", iFinishedCleanupStackEffects.Count(), i );
  4751        
       
  4752             TEffectCleanupStruct& effectItem = iEffectCleanupStack[i];
  5168             TEffectCleanupStruct& effectItem = iEffectCleanupStack[i];
       
  5169              
  4753             if (iFinishedCleanupStackEffects[0] == effectItem.iHandle)
  5170             if (iFinishedCleanupStackEffects[0] == effectItem.iHandle)
  4754                 {
  5171                 {
  4755                 if (RemoveTemporaryPresenterItem(effectItem))
  5172                 if (RemoveTemporaryPresenterItem(effectItem))
  4756                     {
  5173                     {
  4757                     itemsRemoved++;
  5174                     itemsRemoved++;
  4758                     }
  5175                     }
  4759                 if (iEffectCleanupStack.Count() > i)
  5176                 if (iEffectCleanupStack.Count() > i)
  4760                     {
  5177                     {
  4761                     iEffectCleanupStack.Remove(i);
  5178                     iEffectCleanupStack.Remove(i);
       
  5179                     break;
  4762                     }
  5180                     }
  4763                 iFinishedCleanupStackEffects.Remove(0);
  5181                 }
  4764                 i--;
  5182             }
  4765                 }
  5183         iFinishedCleanupStackEffects.Remove(0);
  4766             }
  5184        }
  4767         }
  5185     
       
  5186     if (iFinishedCleanupStackEffects.Count())
       
  5187         {
       
  5188         __ALFFXLOGSTRING1("CAlfBridge::RemoveTemporaryPresenterVisuals - There are still %d finished effects, that could not be found. They have been cleaned already. Reseting the array", iFinishedCleanupStackEffects.Count());
       
  5189         iFinishedCleanupStackEffects.Reset();
       
  5190         }
       
  5191     
  4768     iAlfScreens[0]->iVisualTreeVisibilityChanged = ETrue; // TODO: Check if really changed   
  5192     iAlfScreens[0]->iVisualTreeVisibilityChanged = ETrue; // TODO: Check if really changed   
  4769     iAlfScreens[0]->iDisplay->SetDirty();
  5193     iAlfScreens[0]->iDisplay->SetDirty();
  4770 	__ALFFXLOGSTRING1("CAlfBridge::RemoveTemporaryPresenterVisuals - END - effects in layout %d", effectControlGroupLayout->Count());
  5194 	__ALFFXLOGSTRING1("CAlfBridge::RemoveTemporaryPresenterVisuals - END - effects in layout %d", effectControlGroupLayout->Count());
  4771     return itemsRemoved;
  5195     return itemsRemoved;
  4772     }
  5196     }
  4804     // around will be cleared when HandleGfxStopEffectsL is called
  5228     // around will be cleared when HandleGfxStopEffectsL is called
  4805 
  5229 
  4806     // iFinishedCleanupStackEffects.Append(aHandle);
  5230     // iFinishedCleanupStackEffects.Append(aHandle);
  4807     if (!iEffectEndTimer->IsActive())
  5231     if (!iEffectEndTimer->IsActive())
  4808         {
  5232         {
  4809         iEffectEndTimer->Start( 10000, aHandle );
  5233         iEffectEndTimer->AddFinishedHandleL(aHandle);
       
  5234         iEffectEndTimer->Start(KEffectCleanupDelayInMs * 1000);
       
  5235         }
       
  5236     else
       
  5237         {
       
  5238         iEffectEndTimer->AddFinishedHandleL(aHandle);
  4810         }
  5239         }
  4811 
  5240 
  4812     // We should do visual visibility scan after effect is ended
  5241     // We should do visual visibility scan after effect is ended
  4813     iAlfScreens[0]->SetVisualTreeVisibilityChanged(ETrue);
  5242     iAlfScreens[0]->SetVisualTreeVisibilityChanged(ETrue);
  4814     }
  5243     }
  4819     	{
  5248     	{
  4820     	if(aHandle==iEffectCleanupStack[i].iHandle)
  5249     	if(aHandle==iEffectCleanupStack[i].iHandle)
  4821     		{
  5250     		{
  4822     		// effect might have been cleaned even without this callback. e.g. closing of applicaion while option menu disappear 
  5251     		// effect might have been cleaned even without this callback. e.g. closing of applicaion while option menu disappear 
  4823     		// effect is running, would cause it. There is no need to request cleaning again.
  5252     		// effect is running, would cause it. There is no need to request cleaning again.
       
  5253             __ALFFXLOGSTRING2("CAlfBridge::TransitionFinishedHandlerL - Request cleaning for handle %d on visual 0x%x", aHandle, iEffectCleanupStack[i].iEffectedVisual);
  4824     		iFinishedCleanupStackEffects.Append(aHandle);
  5254     		iFinishedCleanupStackEffects.Append(aHandle);
  4825     		}
  5255     		}
  4826     	}
  5256     	}
  4827     // If the finish request comes from the plugin, the plugin is not interested
  5257     // If the finish request comes from the plugin, the plugin is not interested
  4828     // in getting a notification of the transition end.
  5258     // in getting a notification of the transition end.
  5282         }
  5712         }
  5283     
  5713     
  5284     if ( memoryLevel != iHuiEnv->MemoryLevel() )
  5714     if ( memoryLevel != iHuiEnv->MemoryLevel() )
  5285         {    
  5715         {    
  5286         __ALFLOGSTRING1("CAlfBridge::DoUpdateMemoryLevel -> %d", memoryLevel);
  5716         __ALFLOGSTRING1("CAlfBridge::DoUpdateMemoryLevel -> %d", memoryLevel);
       
  5717         TBool nowGoodMemory = !(memoryLevel < EHuiMemoryLevelNormal);
       
  5718         TBool wasGoodMemory = !(iHuiEnv->MemoryLevel() < EHuiMemoryLevelNormal);
       
  5719         
       
  5720         if (iActivated)
       
  5721             {
       
  5722             if (nowGoodMemory && !wasGoodMemory)
       
  5723                 {
       
  5724                 iBridgerClient.SendBlind(KAlfCompositionGoodOnGraphicsMemory, TIpcArgs());
       
  5725                 }
       
  5726             else if (!nowGoodMemory && wasGoodMemory)
       
  5727                 {
       
  5728                 iBridgerClient.SendBlind(KAlfCompositionLowOnGraphicsMemory, TIpcArgs());
       
  5729                 }
       
  5730             else
       
  5731                 {
       
  5732                 // No change.
       
  5733                 }
       
  5734             }
       
  5735         
  5287         if ( memoryLevel <= EHuiMemoryLevelLowest)
  5736         if ( memoryLevel <= EHuiMemoryLevelLowest)
  5288             {
  5737             {
  5289             LowMemoryCancelAllEffects();
  5738             LowMemoryCancelAllEffects();
  5290             }
  5739             }
  5291             
  5740             
  5309     __ALFLOGSTRING("CAlfBridge::LowMemoryCancelAllEffects");
  5758     __ALFLOGSTRING("CAlfBridge::LowMemoryCancelAllEffects");
  5310     iLayoutSwitchEffectCoordinator->Cancel();
  5759     iLayoutSwitchEffectCoordinator->Cancel();
  5311     HandleGfxStopEvent( EFalse );
  5760     HandleGfxStopEvent( EFalse );
  5312 	__ALFLOGSTRING("CAlfBridge::LowMemoryCancelAllEffects done");
  5761 	__ALFLOGSTRING("CAlfBridge::LowMemoryCancelAllEffects done");
  5313 	}
  5762 	}
       
  5763 
       
  5764 // ---------------------------------------------------------------------------
       
  5765 // ---------------------------------------------------------------------------
       
  5766 // 
       
  5767 TInt CAlfBridge::GetSizeAndRotation(TSize& aSize, TInt& aRotation)
       
  5768     {
       
  5769     if ( !iAlfScreens.Count() )
       
  5770         {
       
  5771         return KErrNotReady;
       
  5772         }
       
  5773 
       
  5774     switch (iAlfScreens[0]->iDisplay->Orientation())
       
  5775         {
       
  5776     case CHuiGc::EOrientationCCW90:
       
  5777         aRotation = 1;
       
  5778         break;
       
  5779     case CHuiGc::EOrientation180:
       
  5780         aRotation = 2;
       
  5781         break;
       
  5782     case CHuiGc::EOrientationCW90:
       
  5783         aRotation = 3;
       
  5784         break;
       
  5785     case CHuiGc::EOrientationNormal:
       
  5786     default:
       
  5787         aRotation = 0;
       
  5788         break;
       
  5789         }    
       
  5790 
       
  5791     aSize = iAlfScreens[0]->iDisplay->Size();
       
  5792 
       
  5793     __ALFLOGSTRING3("CAlfBridge::GetSizeAndRotation %d x %d, rot %d", aSize.iWidth, aSize.iHeight, aRotation);
       
  5794     return KErrNone;
       
  5795     }
       
  5796     
       
  5797 // ---------------------------------------------------------------------------
       
  5798 // ---------------------------------------------------------------------------
       
  5799 // 
       
  5800 TInt CAlfBridge::ReadPixels(CFbsBitmap* aBitmap)
       
  5801     {
       
  5802     if ( !iAlfScreens.Count() )
       
  5803         {
       
  5804         return KErrNotReady;
       
  5805         }
       
  5806     __ALFLOGSTRING("CAlfBridge::ReadPixels");  
       
  5807     TRAPD(err, iAlfScreens[0]->iDisplay->CopyScreenToBitmapL(aBitmap));
       
  5808     __ALFLOGSTRING1("CAlfBridge::ReadPixels ret %d", err);    
       
  5809     return err;
       
  5810     }
  5314 
  5811 
  5315 // ---------------------------------------------------------------------------
  5812 // ---------------------------------------------------------------------------
  5316 // ---------------------------------------------------------------------------
  5813 // ---------------------------------------------------------------------------
  5317 // 
  5814 // 
  5318 void CAlfBridge::Synchronized(TInt aId)
  5815 void CAlfBridge::Synchronized(TInt aId)
  5348 TBool CAlfBridge::IsAlfOriginatedWindow(CHuiCanvasVisual& aVisual)
  5845 TBool CAlfBridge::IsAlfOriginatedWindow(CHuiCanvasVisual& aVisual)
  5349     {
  5846     {
  5350     return (aVisual.Owner().ControlGroup()->ResourceId() == iAlfWindowGroupNodeId);
  5847     return (aVisual.Owner().ControlGroup()->ResourceId() == iAlfWindowGroupNodeId);
  5351     }
  5848     }
  5352 
  5849 
       
  5850 // experimental
       
  5851 TBool CAlfBridge::IsFullScreenDrawn( TInt aOrientation)
       
  5852     {
       
  5853     if (!iAlfScreens.Count())
       
  5854         return EFalse;
       
  5855     aOrientation = iAlfScreens[0]->iDisplay->Orientation();            
       
  5856     iTempRegion.Clear();
       
  5857     
       
  5858     CAlfScreen* screen = iAlfScreens[0];
       
  5859     TRect fullscreen = TRect(TPoint(0,0), screen->Size());
       
  5860     TBool fadeEffectInScreen = EFalse;
       
  5861     
       
  5862     TBool fullscreenCovered = EFalse;
       
  5863     CAlfAppSrvSessionBase* topMostAlfSrvSession = NULL;
       
  5864     
       
  5865     //iActiveVisualCount = 0;
       
  5866     iBgSurfaceFound = EFalse;
       
  5867     //iPaintedArea = 0;  
       
  5868     
       
  5869     // Check if effect group has an effect with opaque hint.
       
  5870     CHuiControlGroup& fxcontrolgroup = *(iAlfScreens[0]->iFullscreenEffectControlGroup);
       
  5871     CHuiControl& fxcontrol = fxcontrolgroup.Control(0);
       
  5872     CHuiCanvasVisual* fxlayout = (CHuiCanvasVisual*)&fxcontrol.Visual(0);
       
  5873     CHuiVisual* fxExternalContent = fxlayout->ExternalContent();
       
  5874     
       
  5875     if (fxlayout && IsOpaqueEffect(fxlayout->Effect()))
       
  5876         {
       
  5877         fullscreenCovered = ETrue;    
       
  5878         }
       
  5879     else if (fxExternalContent && IsOpaqueEffect(fxExternalContent->Effect()))
       
  5880         {
       
  5881         fullscreenCovered = ETrue;
       
  5882         }    
       
  5883     
       
  5884     
       
  5885     TBool alfWindowGroupFoundVisible = EFalse;
       
  5886 
       
  5887     AMT_SET_VALUE( iVisibleVisualCount, 0 );
       
  5888     
       
  5889     // skip the topmost (effect) layer, start from floating sprite group
       
  5890     for (TInt j=screen->iDisplay->Roster().Count() - screen->FixedControlGroupCount(); j>=0; j--)
       
  5891         {                
       
  5892         CHuiControlGroup& controlgroup = iAlfScreens[0]->iDisplay->Roster().ControlGroup(j);
       
  5893         CHuiControl& control = controlgroup.Control(0);
       
  5894 
       
  5895         if (control.Role() == EAlfFpsIndicatorContainer)
       
  5896             {
       
  5897             // FPS container doesn't contain canvas visuals
       
  5898             continue;
       
  5899             }
       
  5900 
       
  5901         CHuiCanvasVisual* layout = (CHuiCanvasVisual*)&control.Visual(0);
       
  5902        
       
  5903         // For optimization reasons, check if all visuals below in Z-order are covered    
       
  5904         if (!fullscreenCovered)
       
  5905             {
       
  5906             fullscreenCovered = IsRectCoveredByRegion(fullscreen, iTempRegion);            
       
  5907             }
       
  5908         
       
  5909         // Dont mess with alf control group visuals, alf session handling does it for us
       
  5910         if (control.Role() == EAlfSessionContainer)
       
  5911             {
       
  5912             CHuiLayout* hostContainer = control.ContainerLayout( NULL );
       
  5913             TInt flags = hostContainer->Flags();            
       
  5914             if (!fullscreenCovered)
       
  5915                 {
       
  5916                 // clear inactive flag if client has not made this controlgroup hidden
       
  5917                 if(!(flags&EHuiVisualFlagUnderOpaqueHint))
       
  5918                     {
       
  5919                     alfWindowGroupFoundVisible = ETrue;
       
  5920                     if(iAppUi)
       
  5921                         {
       
  5922                         topMostAlfSrvSession = iAppUi->SrvSessionForControlGroup(controlgroup);
       
  5923                         }
       
  5924 
       
  5925                     // just add the rect to covered region because alf draws solid background
       
  5926                     iTempRegion.AddRect(fullscreen);
       
  5927                     iTempRegion.Tidy();
       
  5928                     fullscreenCovered = ETrue;
       
  5929                     }
       
  5930                 }
       
  5931             else if(!alfWindowGroupFoundVisible || flags&EHuiVisualFlagUnderOpaqueHint)
       
  5932                 {
       
  5933                 // this alf session control group should not be visible anymore because avkon application is on top
       
  5934                 // -> change to inactive
       
  5935                 
       
  5936                 }
       
  5937             else if(!(flags&EHuiVisualFlagUnderOpaqueHint)) // alf app covers full screen
       
  5938                 {
       
  5939                 // check if current controlgroup belongs to same srvsession as the topmost visible alf session container
       
  5940                 CAlfAppSrvSessionBase* alfsrvsession = NULL;
       
  5941                 if(iAppUi)
       
  5942                     {
       
  5943                     alfsrvsession = iAppUi->SrvSessionForControlGroup(controlgroup);
       
  5944                     }
       
  5945                 if(topMostAlfSrvSession!=NULL && topMostAlfSrvSession == alfsrvsession)
       
  5946                     {
       
  5947                 
       
  5948                     }
       
  5949                 else
       
  5950                     {
       
  5951                 
       
  5952                     }
       
  5953                 }
       
  5954             continue;
       
  5955             }
       
  5956         
       
  5957         __ALFLOGSTRING1("CAlfBridge::IsFullScreenDraw - fullscreen covered %d", fullscreenCovered)
       
  5958         TBool subTreeCovered = EFalse;
       
  5959         TBool hasLayers = EFalse;
       
  5960         TBool hasActiveVisualsInVisualTree = 
       
  5961                 IsFullScreenDrawnRecursive( layout, controlgroup, control, fullscreenCovered, fullscreen, screen,subTreeCovered, hasLayers, IsVisualOpaque(*layout), aOrientation );    
       
  5962         TBool hasFadeEffectsInVisualTree = (layout->CanvasFlags() & EHuiCanvasFlagExternalFadeExistsInsideVisualTree);        
       
  5963 
       
  5964         // If root visuals effect is marked as opaque, then add whole screen area as covered.
       
  5965         if (!fullscreenCovered)
       
  5966             {
       
  5967             fullscreenCovered = IsOpaqueEffect(layout->Effect());
       
  5968             }                    
       
  5969         // "has layers" has been removed 
       
  5970         // If we layout is active setup the fade effects. Also if it is inactive, but has been
       
  5971         // flagged as containing fade effect, then run the setup as well so that effects which
       
  5972         // are no more needed get removed.
       
  5973             
       
  5974         TBool isLayoutActive = !(layout->Flags() & EHuiVisualFlagInactive);        
       
  5975         if (isLayoutActive && !hasActiveVisualsInVisualTree)
       
  5976             {
       
  5977             // Setting also the root visual (layout) as inactive, if it had none
       
  5978                         // active children. This is because otherwise the Inactive checks won't
       
  5979                         // work correctly within RosterImpl ScanDirty & ClearChanged phases.
       
  5980         
       
  5981             }
       
  5982         else if(!isLayoutActive && hasActiveVisualsInVisualTree)
       
  5983             {
       
  5984             }
       
  5985         if (fullscreenCovered)
       
  5986             {
       
  5987             return ETrue;
       
  5988             }
       
  5989         }
       
  5990     return fullscreenCovered;
       
  5991     }
       
  5992 
       
  5993 TBool CAlfBridge::IsFullScreenDrawnRecursive(
       
  5994         CHuiLayout* aLayout, 
       
  5995         CHuiControlGroup& aControlGroup,
       
  5996         CHuiControl& aControl,
       
  5997         TBool& aFullscreenCovered, 
       
  5998         TRect& aFullscreen,
       
  5999         CAlfScreen* aScreen,
       
  6000         TBool& aSubtreeVisible, 
       
  6001         TBool& aHasVisualsWithLayers,
       
  6002         TBool aChildCanBeOpaque,
       
  6003         TInt aOrientation)
       
  6004     {
       
  6005     TBool visualTreeActive = EFalse;
       
  6006     TRect visualDisplayRect;
       
  6007     TBool visualRectIsCovered = EFalse;
       
  6008     TBool visualIsOpaque = EFalse;
       
  6009     TBool visualIsActive = EFalse;
       
  6010     CHuiCanvasVisual* canvasVisual = NULL;
       
  6011 
       
  6012     for (TInt i=aLayout->Count()-1; i >= 0; i--)
       
  6013         {
       
  6014         visualDisplayRect = TRect(0,0,0,0);
       
  6015         visualRectIsCovered = EFalse;
       
  6016         visualIsOpaque = EFalse;
       
  6017         visualIsActive = EFalse;
       
  6018         TBool visualSubtreeVisible = EFalse;
       
  6019         
       
  6020         // Check first if visual itself is hidden or does hide other visuals below 
       
  6021         // in z-order. If it does not hide, then we do not add its displayrect to covering 
       
  6022         // region.
       
  6023         canvasVisual = (CHuiCanvasVisual*)(&aLayout->Visual(i));
       
  6024         
       
  6025         // Child can be considered to be opaque only if all parents are opaque and
       
  6026         // visual itself is opaque.
       
  6027         // For example, parent can have opacity < 1 and that affects children as well.
       
  6028         // As another example, parent can have scaling transformation.
       
  6029         visualIsOpaque = aChildCanBeOpaque && IsVisualOpaque(*canvasVisual);
       
  6030         
       
  6031         if (visualIsOpaque && !canvasVisual->LayerExtent().IsEmpty())
       
  6032             {
       
  6033             aHasVisualsWithLayers = ETrue;
       
  6034             }        
       
  6035 
       
  6036         if (canvasVisual->Count())
       
  6037             {
       
  6038             visualTreeActive |= IsFullScreenDrawnRecursive( canvasVisual, aControlGroup, aControl,aFullscreenCovered, aFullscreen, aScreen,visualSubtreeVisible, aHasVisualsWithLayers, visualIsOpaque, aOrientation );
       
  6039             }
       
  6040            
       
  6041         
       
  6042         if (visualSubtreeVisible)
       
  6043             {
       
  6044             aSubtreeVisible = ETrue;
       
  6045             }
       
  6046             
       
  6047         // Optimization, it is faster to check fullscreen than read visuals displayrect
       
  6048         if (aFullscreenCovered)
       
  6049             {
       
  6050             visualRectIsCovered = ETrue;    
       
  6051             }
       
  6052         else
       
  6053             {
       
  6054             // add the rect only if the window contains drawing for the new orientation
       
  6055             visualDisplayRect = canvasVisual->CommandBufferCoverage(aOrientation);
       
  6056     
       
  6057             // Make sure we clip visual rect to visible screen area
       
  6058             ClipVisualRect(visualDisplayRect, aFullscreen);
       
  6059             
       
  6060             // Check if this visual is covered by other opaque visuals which rects are in "covered" region           
       
  6061             visualRectIsCovered = IsRectCoveredByRegion(visualDisplayRect, iTempRegion);                    
       
  6062             }
       
  6063 
       
  6064         // Finally check the area that this visual covers and add it to covered region
       
  6065         visualIsActive = !(canvasVisual->Flags() & EHuiVisualFlagInactive);
       
  6066     
       
  6067         // Sprites and effects as we consider them always as transparent and also
       
  6068         // if controlgroup is transformed somehow    
       
  6069         
       
  6070         if (aControl.Role() == EAlfFullScreenEffectContainer 
       
  6071             || aControl.Role() == EAlfWindowFloatingSpriteContainer ||
       
  6072             aControlGroup.IsTransformed())
       
  6073             {
       
  6074             visualIsOpaque = EFalse;    
       
  6075             }
       
  6076     
       
  6077         if (visualIsActive && visualIsOpaque && !visualRectIsCovered)
       
  6078             { 
       
  6079             // New visibility system takes only window shape into account.
       
  6080             if ( canvasVisual->CanvasFlags() & EHuiCanvasFlagIncludeToVisibilityCalculation )
       
  6081                 {
       
  6082                 if ( !canvasVisual->HasCustomShape() )
       
  6083                     {
       
  6084                     TRect displayRect(canvasVisual->DisplayRect());
       
  6085                     ClipVisualRect(displayRect, aFullscreen);
       
  6086                     iTempRegion.AddRect(displayRect);
       
  6087                     iTempRegion.Tidy();
       
  6088                     }
       
  6089                 else
       
  6090                     {
       
  6091                     TRect displayRect = canvasVisual->DisplayRect();
       
  6092                     const TRegion& region = canvasVisual->ShapeRegion();
       
  6093                     TPoint delta = -canvasVisual->ShapeOrigin() + displayRect.iTl;
       
  6094                 
       
  6095                     for (TInt i = 0; i < region.Count(); ++i)
       
  6096                         {
       
  6097                         TRect coveredRect(region[i]);
       
  6098                         coveredRect.Move(delta);
       
  6099                         ClipVisualRect(coveredRect, aFullscreen);
       
  6100                         iTempRegion.AddRect(coveredRect);
       
  6101                         iTempRegion.Tidy();
       
  6102                         }
       
  6103                     }
       
  6104                 }
       
  6105             }                                   
       
  6106         visualTreeActive |= visualIsActive;
       
  6107         
       
  6108         // iVisibleVisualCount is cleared in HandleVisualVisibility()
       
  6109         AMT_INC_COUNTER_IF( visualIsActive && !visualRectIsCovered , iVisibleVisualCount );
       
  6110         } // for loop end : children checking loop
       
  6111      
       
  6112     return visualTreeActive;
       
  6113     }
       
  6114 
  5353 // end of file
  6115 // end of file