uiacceltk/hitchcock/AlfRenderStage/src/alfrenderstage.cpp
changeset 0 15bf7259bb7c
child 3 d8a3531bc6b8
child 13 8f67d927ea57
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   AlfRenderStage provides a way to redirect avkon drawing to a graphics accelerator
       
    15 *
       
    16 */
       
    17 
       
    18 #include "alfrenderstage.h"
       
    19 
       
    20 #include <fbs.h>
       
    21 #include <bitstd.h>
       
    22 #include <bitdev.h>
       
    23 #include <graphics/wsgraphicdrawer.h>
       
    24 #include <graphics/wsgraphicscontext.h>
       
    25 
       
    26 #include <alfdecoderserverclient.h>
       
    27 #include <huiwscanvascommands.h>
       
    28 #include <uiacceltk/HuiUtil.h>
       
    29 #include <alf/alfhintplugin.h>
       
    30 #include <alf/alfcompositionclient.h>
       
    31 
       
    32 #include "alflogger.h"
       
    33 #include "alfrsgc.h"
       
    34 #include "alfrssendbuffer.h"
       
    35 #include "alfasynchgoomsession.h"
       
    36 
       
    37 
       
    38 // ======== MEMBER FUNCTIONS ========
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // NewL
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 CAlfRenderStage* CAlfRenderStage::NewL(MWsGraphicDrawerEnvironment* aEnv,MWsScreen* aScreen, TInt aScreenNumber, CWsRenderStage* aNext)
       
    45 	{
       
    46 	CAlfRenderStage * stage = new(ELeave) CAlfRenderStage(aNext);
       
    47 	CleanupStack::PushL(stage);
       
    48 	stage->ConstructL(aEnv, aScreen, aScreenNumber);
       
    49 	CleanupStack::Pop(stage);
       
    50 	return stage;
       
    51 	}
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // C++ constructor
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 CAlfRenderStage::CAlfRenderStage(CWsRenderStage* aNext) : iNormalOrientation(ETrue), iNext(aNext)
       
    58 	{
       
    59 	}
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // C++ destructor
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 CAlfRenderStage::~CAlfRenderStage()
       
    66 	{
       
    67 	iWindowIds.Reset();
       
    68 	iEnv->UnregisterWsEventHandler(this);
       
    69 	iScreen = NULL;
       
    70 	delete iAlfSendBuffer;
       
    71 	delete iWsGraphicsContext;
       
    72 	delete iGoomSession;
       
    73 	
       
    74 	// Used just as a temporary holding place, do not delete!
       
    75 	iWindowDrawingNode = NULL;	
       
    76 	}
       
    77 
       
    78 // ---------------------------------------------------------------------------
       
    79 // ConstructL
       
    80 // ---------------------------------------------------------------------------
       
    81 //
       
    82 void CAlfRenderStage::ConstructL(MWsGraphicDrawerEnvironment* aEnv, MWsScreen* aScreen, TInt aScreenNumber)
       
    83 	{
       
    84 	iEnv = aEnv;
       
    85 	iScreen = aScreen;
       
    86 	iScreenNumber = aScreenNumber;
       
    87 	
       
    88 	__ALFLOGSTRING1("CAlfRenderStage: About to baseconstruct. iScreenNumber=%d", iScreenNumber);
       
    89 	CWsRenderStage::BaseConstructL();
       
    90     CWsRenderStage::SetNext(iNext);
       
    91 	
       
    92 	__ALFLOGSTRING("CAlfRenderStage: About to initialize send buffer");
       
    93     iAlfSendBuffer = CAlfRsSendBuffer::NewL( *this, aScreenNumber );
       
    94 	
       
    95 	iEnv->RegisterWsEventHandler( this, TWservCrEvent::EScreenOrientationChanged  );
       
    96 	iWsGraphicsContext = CAlfGraphicsContext::NewL( *iAlfSendBuffer );
       
    97 
       
    98     // Initialize segment redraw helper attributes to default values
       
    99     iWindowDrawingNode = NULL;
       
   100     iSegmentRedrawActive = EFalse;
       
   101     
       
   102     // Initialise system
       
   103     InitL();
       
   104 
       
   105     // set up the link for composition rs
       
   106     MAlfCompositionController* compcntrl = ( MAlfCompositionController*)ResolveObjectInterface(KAlfCompositionControllerIfUid);
       
   107     if (compcntrl)
       
   108       {
       
   109       compcntrl->AlfBridgeCallback(MAlfBridge::ESetWindowTreeObserver,(MAlfCompositionAgnosticWindowTreeObserver*)this);  
       
   110       }
       
   111 
       
   112     __ALFLOGSTRING("CAlfRenderStage: ready to rock");
       
   113     }
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // InitL
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 void CAlfRenderStage::InitL()
       
   120     {
       
   121     }
       
   122 
       
   123 
       
   124 // ---------------------------------------------------------------------------
       
   125 // ResolveObjectInterface
       
   126 // ---------------------------------------------------------------------------
       
   127 //
       
   128 TAny* CAlfRenderStage::ResolveObjectInterface(TUint aTypeId)
       
   129 	{
       
   130 	switch(aTypeId)
       
   131 		{
       
   132     	case MWsGraphicsContext::EWsObjectInterfaceId:
       
   133     		return static_cast<MWsGraphicsContext*>(iWsGraphicsContext);
       
   134     	case MWsTextCursor::EWsObjectInterfaceId:
       
   135     	    return static_cast<MWsTextCursor*>(this);
       
   136     	case KAlfCompositionAgnosticWindowTreeObserverInterfaceId:
       
   137     	    return static_cast<MAlfCompositionAgnosticWindowTreeObserver*>(this);
       
   138     	case MAlfHintObserver::EWsObjectInterfaceId:
       
   139     	    return static_cast<MAlfHintObserver*>(this);
       
   140 			
       
   141     	case MWsDrawAnnotationObserver::EWsObjectInterfaceId:
       
   142     	    return static_cast<MWsDrawAnnotationObserver*>(this);
       
   143     	default:
       
   144     	    return CWsRenderStage::ResolveObjectInterface(aTypeId);
       
   145 		}
       
   146 	}
       
   147 
       
   148 // ---------------------------------------------------------------------------
       
   149 // Begin
       
   150 // ---------------------------------------------------------------------------
       
   151 //
       
   152 void CAlfRenderStage::Begin(const TRegion* aRegion )
       
   153 	{
       
   154 	iDrawingActive = ETrue;
       
   155 	__ALFLOGSTRING1("CAlfRenderStage::Begin.  iScreenNumber=%d", iScreenNumber);
       
   156 	TRAPD( err, iAlfSendBuffer->PrepareBufferL() );
       
   157 	if ( err )
       
   158 	    {
       
   159 	    __ALFLOGSTRING1("CAlfRenderStage::Begin, Leave occured %d", err );
       
   160 	    }
       
   161 		
       
   162 	iUpdateRegion = aRegion;
       
   163 	iNext->Begin(aRegion);
       
   164 	}
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 // End
       
   168 // ---------------------------------------------------------------------------
       
   169 //
       
   170 void CAlfRenderStage::End( TRequestStatus* aFinished ) 
       
   171 	{
       
   172 	iDrawingActive = EFalse;
       
   173 	TInt err(KErrNone);
       
   174 	__ALFLOGSTRING2("CAlfRenderStage::End. iScreenNumber=%d, aFinished=%d", iScreenNumber,aFinished);
       
   175 	if (iAlfSendBuffer->FrameContainsDataL() ) 
       
   176 	    {
       
   177 	    TRAP( err, iAlfSendBuffer->SendL( aFinished ));
       
   178 	    }
       
   179 	else
       
   180 	    {
       
   181 	    __ALFLOGSTRING("CAlfRenderStage::End - Empty Frame");
       
   182 	    // frame was empty for some reason. Complete request.
       
   183 	    EndCallBack( aFinished );
       
   184 	    }
       
   185 	if ( err )
       
   186 	    {
       
   187 	    __ALFLOGSTRING("CAlfRenderStage::End, Leave occured!!");
       
   188 	    }
       
   189 	}
       
   190 
       
   191 // ---------------------------------------------------------------------------
       
   192 // EndCallBack
       
   193 // ---------------------------------------------------------------------------
       
   194 //
       
   195 void CAlfRenderStage::EndCallBack( TRequestStatus* aFinished )
       
   196     {   
       
   197     __ALFLOGSTRING("CAlfRenderStage::EndCallBack 1");
       
   198 	iNext->End(aFinished);
       
   199     __ALFLOGSTRING("CAlfRenderStage::EndCallBack 2");
       
   200     }
       
   201 
       
   202 // ---------------------------------------------------------------------------
       
   203 // ScreenNumber
       
   204 // ---------------------------------------------------------------------------
       
   205 //
       
   206 TInt CAlfRenderStage::ScreenNumber() const
       
   207 	{
       
   208     __ALFLOGSTRING1("CAlfRenderStage::ScreenNumber. screen=%d", iScreenNumber);
       
   209 	return iScreenNumber;
       
   210 	}
       
   211 // ---------------------------------------------------------------------------
       
   212 // SizeInPixels
       
   213 // ---------------------------------------------------------------------------
       
   214 //
       
   215 /*TSize CAlfRenderStage::SizeInPixels() const
       
   216 	{
       
   217     __ALFLOGSTRING2( "CAlfRenderStage::SizeInPixels() iNormalOrientation=%d, iScreenNumber=%d ",iNormalOrientation, iScreenNumber  );
       
   218     
       
   219 	TSize res = iDisplayPolicy->SizeInPixels();
       
   220 	
       
   221     if( !iNormalOrientation )
       
   222         {
       
   223         res = TSize( res.iHeight, res.iWidth ); 
       
   224         }
       
   225     
       
   226     __ALFLOGSTRING2( "CAlfRenderStage::SizeInPixels() %d x %d ", res.iWidth, res.iHeight );
       
   227 	return res;
       
   228 	}
       
   229 */
       
   230 void CAlfRenderStage::DrawTextCursor(const TTextCursorInfo& aTextCursorInfo)
       
   231     {
       
   232     TRegionFix<1> fullWindowRegion;
       
   233     	const TRegion *clippingRegion= &aTextCursorInfo.iRegion;
       
   234     	if (aTextCursorInfo.iRegion.CheckError())
       
   235     		{
       
   236     		fullWindowRegion.AddRect(aTextCursorInfo.iWindow->AbsRect());
       
   237     		clippingRegion = &fullWindowRegion;
       
   238     		}
       
   239 
       
   240     	if (clippingRegion->IsEmpty())
       
   241     		{
       
   242     		return;
       
   243     		}
       
   244 
       
   245     	iWsGraphicsContext->SetDrawMode(MWsGraphicsContext::EDrawModePEN);
       
   246 
       
   247     	switch (aTextCursorInfo.iTextCursorType)
       
   248     		{
       
   249     		case TTextCursor::ETypeRectangle:
       
   250     			{
       
   251     			iWsGraphicsContext->SetBrushStyle(MWsGraphicsContext::ESolidBrush);
       
   252     			iWsGraphicsContext->SetPenStyle(MWsGraphicsContext::ENullPen);
       
   253     			iWsGraphicsContext->SetBrushColor(KRgbBlack); /* we are ignoring aTextCursorInfo.iTextCursorColor */
       
   254     			}
       
   255     			break;
       
   256     		case TTextCursor::ETypeHollowRectangle:
       
   257     			{
       
   258     			iWsGraphicsContext->SetBrushStyle(MWsGraphicsContext::ENullBrush);
       
   259     			iWsGraphicsContext->SetPenStyle(MWsGraphicsContext::ESolidPen);
       
   260     			iWsGraphicsContext->SetPenColor(KRgbBlack); /* we are ignoring aTextCursorInfo.iTextCursorColor */
       
   261     			}
       
   262     			break;
       
   263     		default:
       
   264     		    {
       
   265     		    break;
       
   266     		    }
       
   267     		}
       
   268     	iWsGraphicsContext->SetClippingRegion(*clippingRegion);
       
   269     	//
       
   270     	// During Sprite drawing, the GC gets reset.  Possibly other code could
       
   271     	// have done this also.  So make sure we setup the origin so that window-relative
       
   272     	// co-ordinates work as expected; iCursorRect is in window co-ordinates.
       
   273     	//
       
   274     	iWsGraphicsContext->SetOrigin(aTextCursorInfo.iWindow->Origin());
       
   275     	iWsGraphicsContext->DrawRect(aTextCursorInfo.iCursorRect);    
       
   276     }
       
   277 
       
   278 // ---------------------------------------------------------------------------
       
   279 // DoHandleEvent
       
   280 // ---------------------------------------------------------------------------
       
   281 //
       
   282 void CAlfRenderStage::DoHandleEvent(const TWservCrEvent& aEvent)
       
   283     {
       
   284     TUint eventType = aEvent.Type();
       
   285     switch( eventType )
       
   286         {
       
   287     	case TWservCrEvent::EDeviceOrientationChanged:
       
   288     		{
       
   289     		__ALFLOGSTRING("CAlfRenderStage::DoHandleEvent EDeviceOrientationChanged");
       
   290     		break;
       
   291     		}
       
   292         default:
       
   293             // no other events have been registered
       
   294             break;
       
   295         }
       
   296     }
       
   297 
       
   298 // ---------------------------------------------------------------------------
       
   299 // WsGraphicsContext
       
   300 // ---------------------------------------------------------------------------
       
   301 //
       
   302 CAlfGraphicsContext* CAlfRenderStage::WsGraphicsContext()
       
   303     {
       
   304     return iWsGraphicsContext;
       
   305     }
       
   306 
       
   307 // ---------------------------------------------------------------------------
       
   308 // AlfSendBuffer
       
   309 // ---------------------------------------------------------------------------
       
   310 //
       
   311 CAlfRsSendBuffer* CAlfRenderStage::AlfSendBuffer()
       
   312     {
       
   313     return iAlfSendBuffer;
       
   314     }
       
   315 
       
   316 
       
   317 // ---------------------------------------------------------------------------
       
   318 // DoDrawTextCursor
       
   319 // ---------------------------------------------------------------------------
       
   320 //
       
   321 void CAlfRenderStage::DoDrawTextCursor( 
       
   322     const MWsWindowTreeNode& aWindowTreeNode, 
       
   323     const TRect& aExtent, 
       
   324     const TRect& aClipRect,
       
   325     const TRect& aCursorRect )
       
   326     {
       
   327     // It might be possible to reduce amount of drawing. 
       
   328     
       
   329     TRegionFix<1> drawRegion;
       
   330     drawRegion.AddRect( aExtent );
       
   331     TRegionFix<1> clipRegion;
       
   332     clipRegion.AddRect( aClipRect );
       
   333             
       
   334     WindowRedrawStart( aWindowTreeNode, drawRegion );
       
   335     iWsGraphicsContext->Reset();
       
   336     iWsGraphicsContext->SetDrawMode( MWsGraphicsContext::EDrawModePEN );
       
   337     iWsGraphicsContext->SetBrushStyle( MWsGraphicsContext::ESolidBrush );
       
   338     iWsGraphicsContext->SetPenStyle( MWsGraphicsContext::ESolidPen );
       
   339     iWsGraphicsContext->SetBrushColor( KRgbBlack ); // color from interface is white, so temporirily putting black
       
   340     //const TRect clipRect = cursor->ClipRect();
       
   341     //const TRect cursorRect = cursor->Rect();
       
   342     iWsGraphicsContext->SetClippingRegion( clipRegion );
       
   343     iWsGraphicsContext->DrawRect( aCursorRect );    
       
   344     WindowRedrawEnd( aWindowTreeNode );
       
   345     }
       
   346 
       
   347 // ---------------------------------------------------------------------------
       
   348 // NodeCreated
       
   349 // ---------------------------------------------------------------------------
       
   350 //
       
   351 void CAlfRenderStage::NodeCreated(const MWsWindowTreeNode& aWindowTreeNode, MWsWindowTreeNode const* aParent)
       
   352     {
       
   353     __ALFLOGSTRING("CAlfRenderStage::NodeCreated");
       
   354     // You need to enable ALF_DEBUG_TRACK_DRAWING in alfappservercore.mmp
       
   355     // and change this value to 1, if you want to track this node in debugger.
       
   356    
       
   357     iWindowIds.AppendL( (TInt) &aWindowTreeNode );
       
   358     TInt nodeType = aWindowTreeNode.NodeType();
       
   359     switch (nodeType)
       
   360         {
       
   361         case MWsWindowTreeNode::EWinTreeNodeClient:
       
   362             {
       
   363             const MWsWindow* window = aWindowTreeNode.Window();
       
   364             TInt ordinalPriority = window->OrdinalPriority();
       
   365             TInt windowId = window->Handle();
       
   366             TInt windowGroupId = KErrNotFound;
       
   367             
       
   368             const MWsWindowTreeNode* parentWindowGroup = aParent;
       
   369             while (parentWindowGroup)
       
   370                 {
       
   371                 if (parentWindowGroup->NodeType() == MWsWindowTreeNode::EWinTreeNodeGroup)
       
   372                     {
       
   373                     windowGroupId = parentWindowGroup->WindowGroup()->Identifier();
       
   374                     break;
       
   375                     }
       
   376                 parentWindowGroup = parentWindowGroup->ParentNode();
       
   377                 }
       
   378             TSize size = window->Size();
       
   379             TPoint origin = window->Origin();
       
   380             //TInt parent = GetIdentifierL(aParent );
       
   381     	    iAlfSendBuffer->WriteIntsL( EAlfNodeCreated,
       
   382     	        10,
       
   383     	        nodeType,
       
   384     	        &aWindowTreeNode,
       
   385     	        origin.iX,
       
   386     	        origin.iY,
       
   387     	        size.iWidth,
       
   388     	        size.iHeight,
       
   389     	        ordinalPriority,
       
   390     	        (TInt)aParent,
       
   391     	        windowGroupId,
       
   392     	        windowId
       
   393     	        );
       
   394             break;
       
   395             }
       
   396         case MWsWindowTreeNode::EWinTreeNodeRoot:
       
   397             {
       
   398             TSize size = TSize( 360, 640);
       
   399             TPoint origin = TPoint( 0, 0 );
       
   400             //TInt parent = GetIdentifierL(aParent );
       
   401             iAlfSendBuffer->WriteIntsL( EAlfNodeCreated,
       
   402                 6,
       
   403                 nodeType,
       
   404                 &aWindowTreeNode,
       
   405                 origin.iX,
       
   406                 origin.iY,
       
   407                 size.iWidth,
       
   408                 size.iHeight
       
   409                 );
       
   410             break;
       
   411             }
       
   412         case MWsWindowTreeNode::EWinTreeNodeGroup:
       
   413             {
       
   414             const MWsWindowGroup* windowGroup = aWindowTreeNode.WindowGroup();
       
   415             ASSERT(windowGroup);
       
   416 			TInt identifier = windowGroup->Identifier();
       
   417 			TInt secureId = windowGroup->Client()->SecureId();
       
   418 
       
   419 #ifndef __WINS__  
       
   420             if( iScreenNumber == 0 )
       
   421 		        {          
       
   422                 if ( secureId != 0x10207218 && // Capserver / AKA goom
       
   423                      secureId != 0x10204c27 )  // Policy server 
       
   424                     {
       
   425                     // Todo: Must actually check whether the configuration uses goom
       
   426                     // would create drastic performance hit in a system that does not need
       
   427                     // (and construct) goom
       
   428                     if ( !iGoomSession )
       
   429 	                    {
       
   430 	                    iGoomSession = new CAlfAsynchGoomSession;
       
   431 	                    }
       
   432                     if ( iGoomSession )
       
   433 	                    {
       
   434 	                    iGoomSession->AppAboutToStart(TUid::Uid(secureId));
       
   435 	                    }
       
   436 			        }
       
   437                 }
       
   438 #endif
       
   439 			
       
   440             iAlfSendBuffer->WriteIntsL( EAlfNodeCreated,
       
   441     	        5,
       
   442     	        nodeType,
       
   443     	        &aWindowTreeNode,
       
   444     	        identifier,
       
   445     	        secureId,
       
   446     	        (TInt)aParent
       
   447     	        );
       
   448             break;
       
   449             }
       
   450         case MWsWindowTreeNode::EWinTreeNodeSprite:
       
   451             {
       
   452             __ALFLOGSTRING1("CAlfRenderStage::NodeCreated node Id: %d", &aWindowTreeNode );
       
   453             TRect spriteRect = aWindowTreeNode.Sprite()->Rect();
       
   454             // TODO, MCL 09+
       
   455             // TSpriteType spriteType = aWindowTreeNode.Sprite()->SpriteType();
       
   456             iAlfSendBuffer->WriteIntsL( EAlfNodeCreated,
       
   457                 7,
       
   458                 nodeType,
       
   459                 &aWindowTreeNode,
       
   460                 spriteRect.iTl.iX,
       
   461                 spriteRect.iTl.iY,
       
   462                 spriteRect.iBr.iX,
       
   463                 spriteRect.iBr.iY,
       
   464                 // sprite type 
       
   465                 (TInt)aParent
       
   466                 );
       
   467             break;
       
   468             }
       
   469         case MWsWindowTreeNode::EWinTreeNodeAnim:
       
   470             {
       
   471             TSize size = TSize( 0, 0 );
       
   472             TPoint origin = TPoint( 0, 0 );
       
   473             iAlfSendBuffer->WriteIntsL( EAlfNodeCreated,
       
   474                     7,
       
   475                     nodeType,
       
   476                     &aWindowTreeNode,
       
   477                     origin.iX,
       
   478                     origin.iY,
       
   479                     size.iWidth,
       
   480                     size.iHeight,
       
   481                     (TInt)aParent
       
   482             );
       
   483             break;
       
   484             }
       
   485         case MWsWindowTreeNode::EWinTreeNodeStandardTextCursor:
       
   486             {
       
   487             // TODO
       
   488             // Use interface MWsStandardTextCursors for Type, Rect, cliptRect, flags, color and flashinterval
       
   489             const MWsStandardTextCursor* cursor = aWindowTreeNode.StandardTextCursor();
       
   490             
       
   491             iAlfSendBuffer->WriteIntsL( EAlfNodeCreated,
       
   492                     15,
       
   493                     nodeType,
       
   494                     &aWindowTreeNode,
       
   495                     cursor->Type(),
       
   496                     cursor->Rect().iTl.iX,
       
   497                     cursor->Rect().iTl.iY,
       
   498                     cursor->Rect().iBr.iX,
       
   499                     cursor->Rect().iBr.iY,
       
   500                     cursor->ClipRect().iTl.iX,
       
   501                     cursor->ClipRect().iTl.iY,
       
   502                     cursor->ClipRect().iBr.iX,
       
   503                     cursor->ClipRect().iBr.iY,
       
   504                     cursor->Flags(),
       
   505                     cursor->Color().Internal(),
       
   506                     cursor->FlashInterval().Int(),
       
   507                     (TInt)aParent );
       
   508             
       
   509             
       
   510             // Initial command buffer for the cursor
       
   511             DoDrawTextCursor( aWindowTreeNode, cursor->Rect(), cursor->ClipRect(), cursor->Rect() );
       
   512             break;
       
   513             }
       
   514         default:
       
   515             {
       
   516             __ALFLOGSTRING1("CAlfRenderStage:: EAlfNodeCreated, unknown node type: %i",  nodeType);
       
   517             break;
       
   518             }
       
   519         }
       
   520 #ifdef ALF_DEBUG_TRACK_DRAWING
       
   521     TInt trackThisNode = 0;
       
   522     if ( trackThisNode )
       
   523         {
       
   524         iAlfSendBuffer->WriteIntsL( EAlfDebugTrackNode, 2, (TInt32)&aWindowTreeNode, 1 );
       
   525         }
       
   526 #endif    
       
   527 	iAlfSendBuffer->CommitL();
       
   528     }
       
   529 
       
   530 // ---------------------------------------------------------------------------
       
   531 // NodeReleased
       
   532 // ---------------------------------------------------------------------------
       
   533 //
       
   534 void CAlfRenderStage::NodeReleased(const MWsWindowTreeNode& aWindowTreeNode)
       
   535     {
       
   536     __ALFLOGSTRING("CAlfRenderStage::NodeReleased");
       
   537     TInt nodeType = aWindowTreeNode.NodeType();
       
   538  
       
   539 #ifndef __WINS__     
       
   540 	if ( iScreenNumber == 0 )
       
   541         {
       
   542         if ( iGoomSession && nodeType == MWsWindowTreeNode::EWinTreeNodeGroup )
       
   543             {
       
   544             const MWsWindowGroup* windowGroup = aWindowTreeNode.WindowGroup();
       
   545             TInt secureId = windowGroup->Client()->SecureId();
       
   546         
       
   547             iGoomSession->AppClosed( TUid::Uid( secureId ) );
       
   548             }
       
   549 	    }
       
   550 #endif        
       
   551     
       
   552     iAlfSendBuffer->WriteIntsL( EAlfNodeReleased,
       
   553         2,
       
   554         nodeType,
       
   555         &aWindowTreeNode
       
   556         );
       
   557 	iAlfSendBuffer->CommitL();
       
   558 	TInt index = iWindowIds.Find( (TInt)&aWindowTreeNode );
       
   559 	if ( index != KErrNotFound )
       
   560 	    {
       
   561         iWindowIds.Remove( index );
       
   562 	    }
       
   563 	else
       
   564 	    {
       
   565 	    __ALFLOGSTRING("CAlfRenderStage::NodeReleased - WARNING: Node not found!!");
       
   566 	    }
       
   567 
       
   568     }
       
   569 
       
   570 // ---------------------------------------------------------------------------
       
   571 // NodeActivated
       
   572 // ---------------------------------------------------------------------------
       
   573 //
       
   574 void CAlfRenderStage::NodeActivated(const MWsWindowTreeNode& aWindowTreeNode)
       
   575     {
       
   576     __ALFLOGSTRING("CAlfRenderStage::NodeActivated >>");
       
   577     TInt nodeType = aWindowTreeNode.NodeType();
       
   578     iAlfSendBuffer->WriteIntsL( EAlfNodeActivated,
       
   579         2,
       
   580         nodeType,
       
   581         &aWindowTreeNode );
       
   582 
       
   583 	iAlfSendBuffer->CommitL();
       
   584     __ALFLOGSTRING("CAlfRenderStage::NodeActivated <<");
       
   585     }
       
   586 
       
   587 // ---------------------------------------------------------------------------
       
   588 // NodeExtentChanged
       
   589 // ---------------------------------------------------------------------------
       
   590 //
       
   591 void CAlfRenderStage::NodeExtentChanged(const MWsWindowTreeNode& aWindowTreeNode, const TRect& aRect)
       
   592     {
       
   593      __ALFLOGSTRING("CAlfRenderStage::NodeExtentChanged");
       
   594     if ( aWindowTreeNode.NodeType() == MWsWindowTreeNode::EWinTreeNodeStandardTextCursor )
       
   595         {           
       
   596         const MWsStandardTextCursor* cursor = aWindowTreeNode.StandardTextCursor();
       
   597         TRect rect(cursor->Rect());
       
   598         iAlfSendBuffer->WriteIntsL( EAlfNodeExtentChanged,
       
   599             5,
       
   600             rect.iTl.iX,
       
   601             rect.iTl.iY,
       
   602             rect.iBr.iX,
       
   603             rect.iBr.iY,
       
   604             &aWindowTreeNode
       
   605             );    
       
   606 
       
   607         DoDrawTextCursor( aWindowTreeNode, cursor->Rect(), cursor->ClipRect(), cursor->Rect() );          
       
   608         }
       
   609     else
       
   610         {
       
   611         iAlfSendBuffer->WriteIntsL( EAlfNodeExtentChanged,
       
   612             5,
       
   613             aRect.iTl.iX,
       
   614             aRect.iTl.iY,
       
   615             aRect.iBr.iX,
       
   616             aRect.iBr.iY,
       
   617             &aWindowTreeNode
       
   618             );    
       
   619         }
       
   620 	iAlfSendBuffer->CommitL();
       
   621     }
       
   622 
       
   623 // ---------------------------------------------------------------------------
       
   624 // SiblingOrderChanged
       
   625 // ---------------------------------------------------------------------------
       
   626 //
       
   627 void CAlfRenderStage::SiblingOrderChanged(const MWsWindowTreeNode& aWindowTreeNode, TInt aNewPos)
       
   628     {
       
   629     __ALFLOGSTRING("CAlfRenderStage::SiblingOrderChanged");
       
   630     TInt nodeType = aWindowTreeNode.NodeType();
       
   631     iAlfSendBuffer->WriteIntsL( EAlfNodeSiblingOrderChanged,
       
   632         2,
       
   633         aNewPos,
       
   634         &aWindowTreeNode );
       
   635 
       
   636     iAlfSendBuffer->CommitL();
       
   637         }
       
   638 
       
   639 // ---------------------------------------------------------------------------
       
   640 // FlagChanged
       
   641 // ---------------------------------------------------------------------------
       
   642 //
       
   643 void CAlfRenderStage::FlagChanged(const MWsWindowTreeNode& aWindowTreeNode, TInt aFlag, TBool aNewValue)
       
   644     {
       
   645     __ALFLOGSTRING("CAlfRenderStage::FlagChanged");
       
   646     iAlfSendBuffer->WriteIntsL(
       
   647             EAlfNodeFlagChanged,
       
   648             3,
       
   649             aFlag,
       
   650             aNewValue,
       
   651             &aWindowTreeNode   );
       
   652 	iAlfSendBuffer->CommitL();
       
   653     }
       
   654 
       
   655 // ---------------------------------------------------------------------------
       
   656 // AttributeChanged
       
   657 // ---------------------------------------------------------------------------
       
   658 //
       
   659 void CAlfRenderStage::AttributeChanged(const MWsWindowTreeNode& aWindowTreeNode, TInt aAttribute )
       
   660     {
       
   661     if ( aWindowTreeNode.NodeType() == MWsWindowTreeNode::EWinTreeNodeStandardTextCursor )
       
   662         {
       
   663         TInt32 nodeId = (TInt32)&aWindowTreeNode;
       
   664         switch( aAttribute )
       
   665             {
       
   666             case ECursorType:
       
   667                 {
       
   668                 iAlfSendBuffer->WriteIntsL(
       
   669                         EAlfNodeAttributeChanged,
       
   670                         3,
       
   671                         nodeId,
       
   672                         aAttribute,
       
   673                         aWindowTreeNode.StandardTextCursor()->Type() );
       
   674                 break;
       
   675                 }
       
   676             case ECursorClipRect:
       
   677                 {
       
   678                 const TRect rect = aWindowTreeNode.StandardTextCursor()->ClipRect();
       
   679                 iAlfSendBuffer->WriteIntsL(
       
   680                         EAlfNodeAttributeChanged,
       
   681                         6,
       
   682                         nodeId,
       
   683                         aAttribute,
       
   684                         rect.iTl.iX,
       
   685                         rect.iTl.iY,
       
   686                         rect.iBr.iX,
       
   687                         rect.iBr.iY );
       
   688 
       
   689                 const MWsStandardTextCursor* cursor = aWindowTreeNode.StandardTextCursor();       
       
   690                 DoDrawTextCursor( aWindowTreeNode, cursor->Rect(), cursor->ClipRect(), cursor->Rect() );
       
   691                 break;
       
   692                 }
       
   693             case ECursorFlags:
       
   694                 {
       
   695                 iAlfSendBuffer->WriteIntsL(
       
   696                         EAlfNodeAttributeChanged,
       
   697                         3,
       
   698                         nodeId,
       
   699                         aAttribute,
       
   700                         aWindowTreeNode.StandardTextCursor()->Flags() );
       
   701                 break;
       
   702                 }
       
   703             case ECursorColor:
       
   704                 {
       
   705                 iAlfSendBuffer->WriteIntsL(
       
   706                         EAlfNodeAttributeChanged,
       
   707                         3,
       
   708                         nodeId,
       
   709                         aAttribute,
       
   710                         aWindowTreeNode.StandardTextCursor()->Color().Internal() );
       
   711                 break;
       
   712                 }
       
   713             }
       
   714         iAlfSendBuffer->CommitL();
       
   715         } 
       
   716     }
       
   717 
       
   718 // ---------------------------------------------------------------------------
       
   719 // FadeCountChanged
       
   720 // ---------------------------------------------------------------------------
       
   721 //
       
   722 void CAlfRenderStage::FadeCountChanged(const MWsWindowTreeNode& aWindowTreeNode, TInt aFadeCount)
       
   723     {
       
   724     iAlfSendBuffer->WriteIntsL( EAlfNodeFadeCountChanged, 2, (TInt32)&aWindowTreeNode, aFadeCount );
       
   725 	iAlfSendBuffer->CommitL();
       
   726     }
       
   727 
       
   728 // ---------------------------------------------------------------------------
       
   729 // TransparentRegionChanged
       
   730 // ---------------------------------------------------------------------------
       
   731 //
       
   732 void CAlfRenderStage::TransparentRegionChanged(const MWsWindowTreeNode& /*aWindowTreeNode*/, const TRegion& /*aNewTransparentRegion*/, const TRegion* /*aNewOpaqueRegion*/)
       
   733     {
       
   734     // @todo
       
   735 	// NULL region received from wserv. causes crash. quickfix is to ignore this as the
       
   736 	// output is ignored in anycase in alfhierarchymodel.cpp
       
   737     /*
       
   738     iAlfSendBuffer->WriteIntsL( EAlfNodeTransparentRegionChanged, 1, (TUint32)&aWindowTreeNode );
       
   739     iAlfSendBuffer->WriteRegionL( EAlfNodeTransparentRegionChanged, aNewTransparentRegion );
       
   740     iAlfSendBuffer->WriteRegionL( EAlfNodeTransparentRegionChanged, *aNewOpaqueRegion );
       
   741     iAlfSendBuffer->CommitL();
       
   742     */
       
   743     }
       
   744 
       
   745 
       
   746 // ---------------------------------------------------------------------------
       
   747 // MovedToWindowGroup
       
   748 // ---------------------------------------------------------------------------
       
   749 //
       
   750 void CAlfRenderStage::MovedToWindowGroup(const MWsWindowTreeNode& aWindowTreeNode, const MWsWindowTreeNode& aNewWindowGroupNode)
       
   751     {
       
   752     iAlfSendBuffer->WriteIntsL( EAlfNodeMovedToWindowGroup, 2, (TUint32)&aWindowTreeNode, (TUint32)&aNewWindowGroupNode );
       
   753     iAlfSendBuffer->CommitL();
       
   754     }
       
   755 
       
   756 // ---------------------------------------------------------------------------
       
   757 // WindowGroupChained
       
   758 // ---------------------------------------------------------------------------
       
   759 //
       
   760 void CAlfRenderStage::WindowGroupChained(const MWsWindowTreeNode& aParent, const MWsWindowTreeNode& aChild)
       
   761     {
       
   762     __ALFLOGSTRING("CAlfRenderStage::WindowGroupChained");
       
   763     iAlfSendBuffer->WriteIntsL( EAlfNodeWindowGroupChained, 2, (TUint32)&aParent, (TUint32)&aChild );
       
   764 	iAlfSendBuffer->CommitL();
       
   765     }
       
   766 
       
   767 // ---------------------------------------------------------------------------
       
   768 // WindowGroupChainBrokenAfter
       
   769 // ---------------------------------------------------------------------------
       
   770 //
       
   771 void CAlfRenderStage::WindowGroupChainBrokenAfter(const MWsWindowTreeNode& aWindowGroupNode)
       
   772     {
       
   773     iAlfSendBuffer->WriteIntsL( EAlfNodeWindowGroupChainBrokenAfter, 1, (TUint32)&aWindowGroupNode );
       
   774     iAlfSendBuffer->CommitL();
       
   775     }
       
   776 
       
   777 
       
   778 // ---------------------------------------------------------------------------
       
   779 // WindowRedrawStart
       
   780 // ---------------------------------------------------------------------------
       
   781 //
       
   782 void CAlfRenderStage::WindowRedrawStart( const MWsWindowTreeNode& aWindowTreeNode, const TRegion& aRegion )
       
   783     {
       
   784     __ALFLOGSTRING("AlfRenderStage::WindowRedrawStart");
       
   785     iWsGraphicsContext->ResetDrawCommandCount();
       
   786     // This is being saved since SegmentRedraw stuff will call WindowRedraw methods 
       
   787     iWindowDrawingNode = &aWindowTreeNode;
       
   788 
       
   789 #ifdef ALF_DEBUG_TRACK_DRAWING
       
   790     TInt trackThisNode = 0;
       
   791     if ( trackThisNode )
       
   792         {
       
   793         iAlfSendBuffer->WriteIntsL( EAlfDebugTrackNode, 2, (TInt32)&aWindowTreeNode, 1 );
       
   794         }
       
   795 #endif   
       
   796     
       
   797     TInt shapeRectCount = 0;
       
   798     
       
   799     if ( aWindowTreeNode.NodeType() == MWsWindowTreeNode::EWinTreeNodeClient )
       
   800         {
       
   801         const TRegion& windowArea = aWindowTreeNode.Window()->WindowArea();
       
   802         if ( !(windowArea.Count() == 1 && windowArea.BoundingRect() == aWindowTreeNode.Window()->AbsRect())
       
   803                 && windowArea.Count() > 0)
       
   804             {
       
   805             /*
       
   806             TRect rect = aWindowTreeNode.Window()->AbsRect();
       
   807             RDebug::Print(_L("%d %d %d %d"), rect.iTl.iX, rect.iTl.iY, rect.iBr.iX, rect.iBr.iY );
       
   808             
       
   809             for ( TInt i= 0; i < windowArea.Count();i++)
       
   810                 {
       
   811                 TRect rect = windowArea[i]; 
       
   812                 RDebug::Print(_L("CAlfRenderStage::WindowRedrawStart - Shape") );
       
   813                 RDebug::Print(_L("%d %d %d %d"), rect.iTl.iX, rect.iTl.iY, rect.iBr.iX, rect.iBr.iY );
       
   814                 }
       
   815             */
       
   816             
       
   817             shapeRectCount = windowArea.Count();
       
   818             __ALFLOGSTRING1("CAlfRenderStage::WindowRedrawStart - some shape, %d rects", shapeRectCount );
       
   819             }
       
   820         }
       
   821     // Write window header
       
   822     iAlfSendBuffer->WriteWindowDataL( (TUint32)&aWindowTreeNode, aRegion.Count(), shapeRectCount );
       
   823     
       
   824     iAlfSendBuffer->WriteRegionL( EAlfSetUpdateRegion, aRegion );
       
   825 
       
   826     if ( shapeRectCount )
       
   827         {
       
   828         // Write Shape region only if defined
       
   829         iAlfSendBuffer->WriteRegionL( EAlfSetShapeRegion, aWindowTreeNode.Window()->WindowArea() );
       
   830         }
       
   831     }
       
   832  
       
   833 // ---------------------------------------------------------------------------
       
   834 // WindowRedrawEnd
       
   835 // ---------------------------------------------------------------------------
       
   836 //
       
   837 void CAlfRenderStage::WindowRedrawEnd( const MWsWindowTreeNode& /*aWindowTreeNode*/ )
       
   838     {
       
   839     __ALFLOGSTRING("AlfRenderStage::WindowRedrawEnd");
       
   840     iSegmentRedrawActive = EFalse;
       
   841     iAlfSendBuffer->EndFrameL();
       
   842     }
       
   843 
       
   844 // ---------------------------------------------------------------------------
       
   845 // WindowAnimRedrawStart
       
   846 // ---------------------------------------------------------------------------
       
   847 //
       
   848 void CAlfRenderStage::WindowAnimRedrawStart( const MWsWindowTreeNode& aWindowTreeNode, const TRegion& aRegion )
       
   849     {
       
   850     //_ALFLOGSTRING("AlfRenderStage::WindowAnimRedrawStart");
       
   851     WindowRedrawStart( aWindowTreeNode, aRegion );
       
   852     }
       
   853 
       
   854 // ---------------------------------------------------------------------------
       
   855 // WindowAnimRedrawEnd
       
   856 // ---------------------------------------------------------------------------
       
   857 //
       
   858 void CAlfRenderStage::WindowAnimRedrawEnd( const MWsWindowTreeNode& aWindowTreeNode )
       
   859     {
       
   860     //_ALFLOGSTRING("AlfRenderStage::WindowAnimRedrawEnd");
       
   861     WindowRedrawEnd( aWindowTreeNode );    
       
   862     }
       
   863 
       
   864 // ---------------------------------------------------------------------------
       
   865 // SpriteRedrawStart
       
   866 // ---------------------------------------------------------------------------
       
   867 //
       
   868 void CAlfRenderStage::SpriteRedrawStart( const MWsWindowTreeNode& aWindowTreeNode, const TRegion& aRegion )
       
   869     {
       
   870     WindowRedrawStart( aWindowTreeNode, aRegion );
       
   871     iSpriteRedraw = &aWindowTreeNode;
       
   872     iSpriteRedrawFlash = ESpriteFlashUndefined;
       
   873     }
       
   874 
       
   875 // ---------------------------------------------------------------------------
       
   876 // SpriteRedrawEnd
       
   877 // ---------------------------------------------------------------------------
       
   878 //
       
   879 void CAlfRenderStage::SpriteRedrawEnd( const MWsWindowTreeNode& aWindowTreeNode )
       
   880     {
       
   881     WindowRedrawEnd( aWindowTreeNode );
       
   882     const MWsWindowTreeNode* spriteRedraw = iSpriteRedraw;
       
   883     iSpriteRedraw = NULL;
       
   884     
       
   885     if ( spriteRedraw && iSpriteRedrawFlash != ESpriteFlashUndefined )
       
   886         {
       
   887         SpriteFlash( *spriteRedraw, iSpriteRedrawFlash == ESpriteFlashOn );
       
   888         iSpriteRedrawFlash = ESpriteFlashUndefined;
       
   889         }
       
   890     }
       
   891 
       
   892 // ---------------------------------------------------------------------------
       
   893 // SpriteFlash
       
   894 // ---------------------------------------------------------------------------
       
   895 //
       
   896 void CAlfRenderStage::SpriteFlash( const MWsWindowTreeNode& aWindowTreeNode, TBool aFlashOn )
       
   897     {
       
   898     __ALFLOGSTRING1("CAlfRenderStage::SpriteFlash %d", aFlashOn );
       
   899     if ( !iSpriteRedraw )
       
   900         {
       
   901         FlagChanged( aWindowTreeNode, MWsWindowTreeObserver::EVisible, aFlashOn );
       
   902         }
       
   903     else
       
   904         {
       
   905         iSpriteRedrawFlash = aFlashOn ? ESpriteFlashOn : ESpriteFlashOff;
       
   906         }
       
   907     }
       
   908 
       
   909 // ---------------------------------------------------------------------------
       
   910 // SegmentRedrawStart
       
   911 // ---------------------------------------------------------------------------
       
   912 //
       
   913 void CAlfRenderStage::SegmentRedrawStart( const TRegion& aRegion)
       
   914     {
       
   915     // If this is the first (and only ) time SegmentRedraw is being called within WindowRedrawStart
       
   916     // and WindowRedrawEnd, nothing needs to be done.
       
   917     //
       
   918     // Otherwise, if there's multiple segment redraws between WindowRedrawStart/End, we will separate
       
   919     // each segment to its own buffer.
       
   920     if (iSegmentRedrawActive)
       
   921         {
       
   922         WindowRedrawEnd(*iWindowDrawingNode);
       
   923         WindowRedrawStart(*iWindowDrawingNode, aRegion);
       
   924         }
       
   925     iSegmentRedrawActive = ETrue;
       
   926     }
       
   927 
       
   928 // ---------------------------------------------------------------------------
       
   929 // SegmentRedrawEnd
       
   930 // ---------------------------------------------------------------------------
       
   931 //
       
   932 void CAlfRenderStage::SegmentRedrawEnd(  )
       
   933     {
       
   934     }
       
   935 
       
   936 // ---------------------------------------------------------------------------
       
   937 // FadeAllChildren
       
   938 // ---------------------------------------------------------------------------
       
   939 //
       
   940 void CAlfRenderStage::FadeAllChildren(const MWsWindowTreeNode& aWindowTreeNode, TBool aFaded)
       
   941     {
       
   942     TUint32 nodeId = (TUint32)&aWindowTreeNode;
       
   943     iAlfSendBuffer->WriteIntsL( EAlfNodeFadeAllChildren, 2, nodeId, aFaded );                      
       
   944     iAlfSendBuffer->CommitL();
       
   945     }
       
   946 
       
   947 // ---------------------------------------------------------------------------
       
   948 // InsertTagL
       
   949 // ---------------------------------------------------------------------------
       
   950 //
       
   951 void CAlfRenderStage::InsertTagL( TInt aTag, TInt32 /*aParameter*/ )
       
   952     {
       
   953     // Must be between WindowRedrawStart and WindowRedrawEnd calls
       
   954     
       
   955     switch( aTag )
       
   956         {
       
   957         case CAlfHintGraphic::EAlfOffscreenContentBegin:
       
   958             {
       
   959             iAlfSendBuffer->SetFlag( EAlfTransparentContent );
       
   960             iAlfSendBuffer->WriteIntL( EAlfContentTag, aTag );
       
   961             break;
       
   962             }
       
   963         case CAlfHintGraphic::EAlfOffscreenContentEnd:
       
   964             {
       
   965             iAlfSendBuffer->WriteIntL( EAlfContentTag, aTag );
       
   966             break;
       
   967             }
       
   968         case  CAlfHintGraphic::EAlfOffscreenContentFlush:
       
   969             {
       
   970             iAlfSendBuffer->SetFlag( EAlfTransparentContentFlush );
       
   971             iAlfSendBuffer->SetFlag( EAlfTransparentContent );
       
   972             iAlfSendBuffer->WriteIntL( EAlfContentTag, aTag );
       
   973             break;
       
   974             }
       
   975         case CAlfHintGraphic::EAlfSetWindowId:
       
   976             {
       
   977             break;
       
   978             }
       
   979         case CAlfHintGraphic::EAlfEndSubWindow:
       
   980             {
       
   981             iAlfSendBuffer->EndMarkerL();
       
   982             break;
       
   983             }
       
   984             
       
   985         default:
       
   986             {
       
   987             break;
       
   988             }
       
   989         }
       
   990     }
       
   991 
       
   992 void CAlfRenderStage::InsertTagL( TInt aTag, TRect aBoundingRectangle, TInt aLayerId )
       
   993     {
       
   994     switch(aTag)
       
   995         {
       
   996         case CAlfHintGraphic::EAlfBeginSubWindow:
       
   997             {
       
   998             iAlfSendBuffer->StartMarkerL(aBoundingRectangle, aLayerId);
       
   999             break;
       
  1000             }
       
  1001         }
       
  1002     
       
  1003     }
       
  1004 
       
  1005 
       
  1006 // end of file