uiacceltk/hitchcock/coretoolkit/src/huicanvaswspainter.cpp
changeset 0 15bf7259bb7c
child 3 d8a3531bc6b8
child 13 8f67d927ea57
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     1 /*
       
     2 * Copyright (c) 2007-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:   Definition of CHuiCanvasWsPainter.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "huicanvaswspainter.h"
       
    21 
       
    22 #include "uiacceltk/HuiCanvasVisual.h"
       
    23 #include "HuiRenderPlugin.h"
       
    24 #include "uiacceltk/HuiGc.h"
       
    25 #include "uiacceltk/HuiPanic.h"
       
    26 #include "uiacceltk/HuiUtil.h"
       
    27 #include "uiacceltk/HuiStatic.h"
       
    28 #include "uiacceltk/HuiEnv.h"
       
    29 #include "uiacceltk/HuiControl.h"
       
    30 #include "uiacceltk/HuiVisual.h"
       
    31 #include "uiacceltk/HuiTextMesh.h"
       
    32 #include "uiacceltk/HuiCanvasCmdBufferReader.h"
       
    33 #include "huicanvasgc.h"
       
    34 #include "huicanvaswsgc.h"
       
    35 #include "HuiRenderSurface.h"
       
    36 #include "huicanvastexturecache.h"
       
    37 #include "huicanvasbackground.h"
       
    38 #include "huicanvaswsswgc.h"
       
    39 #include "huicanvasdebugwsgc.h"
       
    40 #include "huicanvaswsbitgc.h"
       
    41 #include "../../CommonInc/huiwscanvascommands.h"
       
    42 #include <graphics/wsgraphicscontext.h>
       
    43 
       
    44 #ifdef HUI_DEBUG_TRACK_DRAWING
       
    45 #include "alfloggingconfiguration.h"
       
    46 #include "alfcommanddebug.h"
       
    47 #endif
       
    48 #include <e32cmn.h>
       
    49 #include <AknLayoutFont.h>
       
    50 #include <graphics/lookuptable.h>
       
    51 
       
    52 #include "HuiCmdBufferBrush.h"
       
    53 
       
    54 /** 
       
    55  * Constants to define enabling/disabling render buffer automatically 
       
    56  *  incase there are frequently new buffers posted. 
       
    57  * 
       
    58  *  This may improve performance in some HW platforms.
       
    59  * 
       
    60  */
       
    61 const TBool KHuiCanvasAutomaticRenderBufferUsage = EFalse; // Disbaled until all UI isses has been solved  
       
    62 const TInt KHuiCanvasDisableRenderBufferHandleInterval = 100; // Milliseconds 
       
    63 const TInt KHuiCanvasEnableRenderBufferHandleInterval = 500;  // Milliseconds
       
    64 
       
    65 /** Internal constant to identify complex command buffers */
       
    66 const TInt KPossiblePerformanceProblemInWindow = 64;
       
    67 
       
    68 
       
    69 /** ETrue - use SelectGcL to select gc implementation, 
       
    70     EFalse - use KHuiDefaultCanvasWsGc. */
       
    71 const TBool KHuiUseSelectGc = ETrue;
       
    72 
       
    73 /** Change this to select default rendering ws gc implementation.
       
    74     Only used when KHuiUseSelectGc does not hold. */
       
    75 const THuiCanvasWsGcType KHuiDefaultCanvasWsGc = EHuiCanvasWsHw;
       
    76 
       
    77 //#define HUI_DEBUG_PRINT_PERFORMANCE_INTERVAL
       
    78 
       
    79 CHuiCanvasWsPainter* CHuiCanvasWsPainter::NewL()
       
    80 	{
       
    81 	CHuiCanvasWsPainter* self    = new ( ELeave ) CHuiCanvasWsPainter;
       
    82     CleanupStack::PushL( self );
       
    83     self->ConstructL();
       
    84     CleanupStack::Pop();
       
    85 	return self;
       
    86     }
       
    87 
       
    88 
       
    89 CHuiCanvasWsPainter::CHuiCanvasWsPainter()
       
    90     {
       
    91     }
       
    92 
       
    93 void CHuiCanvasWsPainter::ConstructL()
       
    94     {
       
    95     CHuiStatic::Env().AddMemoryLevelObserver(this);
       
    96     iWsCommandBufferReader = NULL;
       
    97     iPartialCommandBuffer = NULL;
       
    98     iCacheCleared = EFalse;
       
    99 
       
   100     if ( KHuiUseSelectGc )
       
   101         {
       
   102         SelectGcL();
       
   103         }
       
   104     else if (KHuiDefaultCanvasWsGc == EHuiCanvasWsHw)
       
   105         {
       
   106         iCanvasWsHwGc = CHuiCanvasWsHwGc::NewL();
       
   107         iCanvasWsGc = iCanvasWsHwGc;        
       
   108         }
       
   109     else if (KHuiDefaultCanvasWsGc == EHuiCanvasWsSw)
       
   110         {
       
   111         iCanvasWsSwGc = CHuiCanvasWsSwGc::NewL();
       
   112         iCanvasWsGc = iCanvasWsSwGc;            
       
   113         }    
       
   114     else if (KHuiDefaultCanvasWsGc == EHuiCanvasWsBit)
       
   115         {
       
   116         iCanvasWsBitGc = CHuiCanvasWsBitGc::NewL();
       
   117         iCanvasWsGc = iCanvasWsBitGc;            
       
   118         }    
       
   119     else
       
   120         {
       
   121         // Never happens, right.
       
   122         }
       
   123     
       
   124     iWsCommandBufferReader = new (ELeave) CHuiCanvasCmdBufferReader();    
       
   125 #ifdef HUI_DEBUG_TRACK_DRAWING
       
   126     iCommandDebugger = CAlfCommandDebug::NewL();
       
   127     CHuiCanvasWsGc* realGc = iCanvasWsGc;
       
   128     iCanvasWsGc = CHuiCanvasDebugWsGc::NewL( realGc, *iCommandDebugger );
       
   129     
       
   130 #endif
       
   131     }
       
   132 
       
   133 
       
   134 CHuiCanvasWsPainter::~CHuiCanvasWsPainter()
       
   135     {
       
   136     if (iCanvasVisual)
       
   137         {
       
   138         iCanvasVisual->Env().CanvasTextureCache().ReleaseAllCachedEntries(*iCanvasVisual);
       
   139         iCanvasVisual->Env().RemoveMemoryLevelObserver(this);
       
   140         }
       
   141     else
       
   142         {
       
   143         CHuiStatic::Env().RemoveMemoryLevelObserver(this);
       
   144         }
       
   145     
       
   146     ClearCommandSet();	
       
   147     delete iWsCommandBufferReader;	
       
   148     delete iCanvasWsHwGc;
       
   149     delete iCanvasWsSwGc;
       
   150     delete iCanvasWsBitGc;
       
   151 
       
   152     iTempRegion.Close();
       
   153     iTempCurrentSubRegion.Close();
       
   154     iTempIntersectingRegion.Close();
       
   155 #ifdef HUI_DEBUG_TRACK_DRAWING
       
   156     delete iCommandDebugger;
       
   157 #endif
       
   158     iFullUpdateRegion.Close();
       
   159     iShapeRegion.Close();
       
   160     }
       
   161     
       
   162 
       
   163 CHuiGc::TOrientation CHuiCanvasWsPainter::CalculateRelativeOrientation()
       
   164     {
       
   165     // Calculate drawing command rotation as relative to the current display rotation.
       
   166     // It may be that drawing commands has been sent when display was in different rotation.
       
   167     TInt last = iCommandBuffers.Count() - 1;
       
   168     CHuiGc::TOrientation relativeOrientation = CHuiGc::EOrientationNormal;    
       
   169     CHuiGc::TOrientation displayOrientation = CHuiStatic::Env().PrimaryDisplay().Orientation(); 
       
   170     CHuiGc::TOrientation drawingCommandOrientation = iCommandBuffers[last]->iOrientation; 
       
   171     
       
   172     TInt rotationAngle[] =
       
   173         {
       
   174         0, 
       
   175         270, 
       
   176         90, 
       
   177         180
       
   178         };
       
   179         
       
   180     TInt displayOrientationAngle = rotationAngle[displayOrientation];
       
   181     TInt drawingCommandOrientationAngle = rotationAngle[drawingCommandOrientation];    
       
   182     TInt relativeOrientationAngle = drawingCommandOrientationAngle - displayOrientationAngle;
       
   183     
       
   184     // Check over/underflow
       
   185     if (relativeOrientationAngle > 360)
       
   186         {
       
   187         relativeOrientationAngle -= 360;
       
   188         }
       
   189     else if (relativeOrientationAngle < 0)
       
   190         {
       
   191         relativeOrientationAngle += 360;
       
   192         }
       
   193     
       
   194     switch (relativeOrientationAngle)
       
   195         {
       
   196         case 0:
       
   197             {
       
   198             relativeOrientation = CHuiGc::EOrientationNormal;
       
   199             break;
       
   200             }
       
   201         case 90:
       
   202             {
       
   203             relativeOrientation = CHuiGc::EOrientationCW90;            
       
   204             break;
       
   205             }
       
   206         case 270:
       
   207             {
       
   208             relativeOrientation = CHuiGc::EOrientationCCW90;            
       
   209             break;
       
   210             }
       
   211         case 180:
       
   212             {
       
   213             relativeOrientation = CHuiGc::EOrientation180;            
       
   214             break;
       
   215             }
       
   216         default:
       
   217             {
       
   218             // As usual, this should not happen...but just in case it does use normal rotation
       
   219             relativeOrientation = CHuiGc::EOrientationNormal;
       
   220             break;
       
   221             }        
       
   222         }
       
   223     return relativeOrientation;
       
   224     }
       
   225 
       
   226 void CHuiCanvasWsPainter::HandleBufferL(TRect& aDisplayRect, TInt aAction, const CHuiCanvasVisual& aUser, CHuiGc* aGc, TPoint aPos ) 
       
   227     {   
       
   228 	#ifdef __ALF_SYMBIAN_RWINDOW_CLEARING_BUG_WORKAROUND__
       
   229     iTestFullDisplayRect = aDisplayRect;
       
   230 	#endif
       
   231     
       
   232     // Store user so that we can clear cache later
       
   233     iCanvasVisual = (CHuiCanvasVisual*)&aUser;
       
   234 
       
   235     // Let canvas know about user and gc
       
   236     CHuiCanvasGc& canvasGc = iCanvasWsGc->CanvasGc();
       
   237     canvasGc.SetVisual(aUser);
       
   238     if (aGc)
       
   239         {
       
   240         canvasGc.SetGc(*aGc);
       
   241         }
       
   242     
       
   243     if (iCommandBuffers.Count() != 0)
       
   244         {
       
   245 #ifdef HUI_DEBUG_PRINT_PERFORMANCE_INTERVAL
       
   246         RDebug::Print(_L(">> CHuiCanvasWsPainter::HandleBufferL this = %i, Action = %i"), this, aAction );
       
   247         TTime startTime;
       
   248         startTime.UniversalTime();
       
   249 #endif
       
   250 
       
   251         // Initialize canvas
       
   252         canvasGc.SetDefaults();   
       
   253 
       
   254         // Make sure we got up to date update reagion
       
   255         iFullUpdateRegion.Clear();                
       
   256         TInt bufferCount = iCommandBuffers.Count();
       
   257         for (TInt cb = 0; cb < bufferCount; cb++)
       
   258             {        
       
   259             iFullUpdateRegion.Union(iCommandBuffers[cb]->iUpdateRegion);
       
   260             }
       
   261         iFullUpdateRegion.Tidy();
       
   262         
       
   263 #ifdef HUI_DEBUG_PRINT_PERFORMANCE_INTERVAL
       
   264         const TRect updateRegionBoundingRect = iFullUpdateRegion.BoundingRect();        
       
   265         RDebug::Print(_L(">> CHuiCanvasWsPainter::HandleBufferL iFullUpdateRegion.BoundingRect() = (%i,%i) (%i,%i)"), 
       
   266                 updateRegionBoundingRect.iTl.iX,
       
   267                 updateRegionBoundingRect.iTl.iY,
       
   268                 updateRegionBoundingRect.iBr.iX,
       
   269                 updateRegionBoundingRect.iBr.iY
       
   270                 );
       
   271 
       
   272         if (iCanvasWsGc->Type() == EHuiCanvasWsSw)
       
   273             {
       
   274             RDebug::Print(_L(">> CHuiCanvasWsPainter::HandleBufferL - SW mode is used."));
       
   275             }
       
   276         else if (iCanvasWsGc->Type() == EHuiCanvasWsBit)
       
   277             {
       
   278             RDebug::Print(_L(">> CHuiCanvasWsPainter::HandleBufferL - BITGC mode is used."));
       
   279             }
       
   280         
       
   281         if (aUser.Effect())
       
   282             {
       
   283             RDebug::Print(_L(">> CHuiCanvasWsPainter::HandleBufferL - visual has EFFECT"));
       
   284             }
       
   285         
       
   286         
       
   287 #endif
       
   288         
       
   289         if (aAction == EDrawBuffer)
       
   290             {
       
   291             /* Check and enable render buffer if needed */
       
   292             EnableRenderBufferIfNeeded(ETrue);
       
   293 
       
   294             // Compenstate possible orientation mismatch between drawing commands and display orientation
       
   295             // by letting iCanvasWsGc know about it. Mismatch usually happens when screen is rotated and
       
   296             // it may cause visually unpleasent things at the screen.
       
   297             CHuiGc::TOrientation relativeOrientation = CalculateRelativeOrientation();
       
   298             iCanvasWsGc->SetRelativeOrientation(relativeOrientation);
       
   299             #ifdef HUI_DEBUG_PRINT_PERFORMANCE_INTERVAL
       
   300             RDebug::Print(_L(">> CHuiCanvasWsPainter::HandleBufferL - relativeOrientation = %i "), relativeOrientation);    
       
   301             #endif
       
   302             
       
   303             /* If window shape region has been changed, we should clear the window to get rid of old content. 
       
   304              * We also set all command buffers to "not drawn" state so that everything will be redrawn.
       
   305              */
       
   306             TBool isFullUpdateRegionCleared = EFalse;
       
   307             if(iShapeRegionClearingPending)
       
   308                 {
       
   309                 #ifdef HUI_DEBUG_PRINT_PERFORMANCE_INTERVAL
       
   310                 RDebug::Print(_L(">> CHuiCanvasWsPainter::HandleBufferL - Clearing fullupdateregion"));    
       
   311                 #endif
       
   312                 // Clear the window update region area
       
   313                 TBool doClear = ETrue;
       
   314                 iCanvasWsGc->EnableUpdateRegion(iFullUpdateRegion, doClear);
       
   315                 iCanvasWsGc->DisableUpdateRegion(); 
       
   316                 isFullUpdateRegionCleared = ETrue;
       
   317                 
       
   318                 // Cause a full redraw for the canvas visual
       
   319                 SetAllBuffersChanged(ETrue);    
       
   320                 ClearAllBufferStatusFlags(EHuiCanvasBufferStatusDrawn);
       
   321                 iShapeRegionClearingPending = EFalse;
       
   322                 }
       
   323             
       
   324             
       
   325             /* Check if we have buffers that are not yet been drawn (or we render buffer is disabled) */
       
   326             TBool cachePrepared = !HasCommandBuffersWithoutFlags(EHuiCanvasBufferStatusDrawn) || !iCanvasWsGc->IsRenderBufferEnabled();
       
   327 
       
   328             /* Begin draw. If render buffer is used this sets up the render buffer if needed */
       
   329             iCanvasWsGc->BeginActionL(aAction,aDisplayRect,aUser,cachePrepared,iFullUpdateRegion);                   
       
   330 
       
   331             #ifdef HUI_DEBUG_PRINT_PERFORMANCE_INTERVAL
       
   332             if (iCanvasWsGc->IsRenderBufferEnabled())
       
   333                 {
       
   334                 RDebug::Print(_L(">> CHuiCanvasWsPainter::HandleBufferL renderbuffer is ENABLED"));
       
   335                 }
       
   336             else
       
   337                 {
       
   338                 RDebug::Print(_L(">> CHuiCanvasWsPainter::HandleBufferL renderbuffer is DISABLED"));
       
   339                 }
       
   340             #endif
       
   341             
       
   342             /* We do not ignore unchanged buffers currently */
       
   343             TBool ignoreUnChangedBuffers = EFalse; 
       
   344 
       
   345             /* We can ignore buffers that only update areas which get clipped */
       
   346             TBool ignoreClippedBuffers = ETrue;            
       
   347             if (relativeOrientation != CHuiGc::EOrientationNormal)
       
   348                 {
       
   349                 ignoreClippedBuffers = EFalse;
       
   350                 }
       
   351             
       
   352             /* We can ignore buffers that has previously already been drawn into render buffer */
       
   353             TBool ignoreHandledBuffers = iCanvasWsGc->IsRenderBufferEnabled() && iCanvasWsGc->IsRenderBufferInitialized();                    
       
   354 
       
   355             
       
   356             /* 
       
   357              * We need to clear area if render buffer is used because otherwise it will cause dimming for semitransparent areas.
       
   358              * 
       
   359              * NOTE1: We do not clear if the window is opaque. This is a bit questionable, but Avkon seems to rely
       
   360              * quite much on luck with its drawing and there are areas in the windows which are not always covered
       
   361              * by drawing commands, thus random garabage from previous frames would be visible if such window
       
   362              * update area would always be cleared.
       
   363              * 
       
   364              * NOTE2: We handle window that has background clearing enabled similarly as transparent window
       
   365              *        because their wanted behaviour is similar to transparent window (user wants to see the stuff
       
   366              *        behind window drawing commands and may want to draw commands translucently). 
       
   367              *        
       
   368              * -> So always clear if drawing vie render buffer and window is transparent or has backround.       
       
   369              *        
       
   370              */            
       
   371             TBool clearBeforeHandlingBuffer = iCanvasWsGc->IsRenderBufferEnabled() 
       
   372                 && (!(aUser.Flags() & EHuiVisualFlagOpaqueHint) || aUser.IsBackgroundDrawingEnabled())
       
   373                 && !isFullUpdateRegionCleared;
       
   374                         
       
   375             // TODO: Should avoid trap, but EndActionL must always be called
       
   376             TRAPD(err, DoHandleAllBuffersL( aDisplayRect, aAction, aUser, aGc, aPos, 
       
   377                     ignoreUnChangedBuffers, 
       
   378                     ignoreClippedBuffers,
       
   379                     ignoreHandledBuffers,
       
   380                     clearBeforeHandlingBuffer));
       
   381             
       
   382             if (err != KErrNone)
       
   383                 {
       
   384                 RDebug::Print(_L("CHuiCanvasWsPainter::HandleBufferL(): draw error = %i "), err);
       
   385                 RenewAllBuffers();
       
   386                 }
       
   387             
       
   388             // Workaround for fact that WSERV sends command buffers that do not contain real drawing commands.
       
   389             // If there are no real drawing commnads, just avoid display update at the EndAction so that
       
   390             // we don't write empty pixels to screen and cause flicker. 
       
   391             TBool updateDisplay = HasCommandBuffers(EHuiCanvasBufferContainsDrawing);
       
   392             
       
   393             /* End draw. If render buffer is in use, this will update the screen */
       
   394             iCanvasWsGc->EndActionL(iFullUpdateRegion, updateDisplay);                 
       
   395             
       
   396             /* Mark that cache is not more clear */
       
   397             iCacheCleared = EFalse;
       
   398             }
       
   399         else if (aAction == EScanBuffer)
       
   400             {
       
   401             /* Check and enable render buffer if needed */
       
   402             EnableRenderBufferIfNeeded(ETrue);
       
   403             
       
   404             /* Check if we have buffers that are not yet prepared (or we render buffer is disabled) */
       
   405             TBool cachePrepared = !HasCommandBuffersWithoutFlags(EHuiCanvasBufferStatusScanned) || !iCanvasWsGc->IsRenderBufferEnabled();
       
   406 
       
   407             /* Begin scan. If render buffer is used this sets up the render buffer if needed */
       
   408             iCanvasWsGc->BeginActionL(aAction,aDisplayRect,aUser,cachePrepared,iFullUpdateRegion);    
       
   409 
       
   410             #ifdef HUI_DEBUG_PRINT_PERFORMANCE_INTERVAL
       
   411             if (iCanvasWsGc->IsRenderBufferEnabled())
       
   412                 {
       
   413                 RDebug::Print(_L(">> CHuiCanvasWsPainter::HandleBufferL renderbuffer is ENABLED"));
       
   414                 }
       
   415             else
       
   416                 {
       
   417                 RDebug::Print(_L(">> CHuiCanvasWsPainter::HandleBufferL renderbuffer is DISABLED"));
       
   418                 }
       
   419             #endif
       
   420             
       
   421             /* We do not ignore unchanged buffers currently */
       
   422             TBool ignoreUnChangedBuffers = EFalse;
       
   423             
       
   424             /* We do not ignore clipped buffers as they possibly contain items that may soon appear on the screen */
       
   425             TBool ignoreClippedBuffers = EFalse;                    
       
   426             
       
   427             /* We can ignore buffers that has previously already been scanned */
       
   428             TBool ignoreHandledBuffers = ETrue;     
       
   429 
       
   430             /* No need to clear area if scanning */
       
   431             TBool clearBeforeHandlingBuffer = EFalse;
       
   432             
       
   433             // TODO: Should avoid trap, but EndActionL must always be called
       
   434             TRAPD(err, DoHandleAllBuffersL( aDisplayRect, aAction, aUser, aGc, aPos, 
       
   435                     ignoreUnChangedBuffers, 
       
   436                     ignoreClippedBuffers,
       
   437                     ignoreHandledBuffers,
       
   438                     clearBeforeHandlingBuffer));    
       
   439             
       
   440             if (err != KErrNone)
       
   441                 {
       
   442                 RDebug::Print(_L("CHuiCanvasWsPainter::HandleBufferL(): scan error = %i "), err);
       
   443                 RenewAllBuffers();
       
   444                 }
       
   445             
       
   446             /* End draw. If render buffer is in use, this will update the screen */
       
   447             iCanvasWsGc->EndActionL(iFullUpdateRegion, EFalse);
       
   448 
       
   449             /* Mark that cache is not more clear */
       
   450             iCacheCleared = EFalse;
       
   451             
       
   452             /* Update dirty area to aDisplayRect in case this action is originated from dirty area scan */
       
   453             aDisplayRect = DirtyRect();
       
   454             }
       
   455             
       
   456                         
       
   457 #ifdef HUI_DEBUG_PRINT_PERFORMANCE_INTERVAL
       
   458         TTime endTime;
       
   459         endTime.UniversalTime();
       
   460         TInt timeInMs =  endTime.MicroSecondsFrom( startTime ).Int64()/1000;           
       
   461         RDebug::Print(_L(">> CHuiCanvasWsPainter::HandleBufferL took %i ms"), timeInMs);
       
   462 #endif
       
   463         }
       
   464         
       
   465     }
       
   466 
       
   467 void CHuiCanvasWsPainter::DoHandleAllBuffersL( TRect& aDisplayRect, 
       
   468                                                TInt aAction, 
       
   469                                                const CHuiCanvasVisual& aUser, 
       
   470                                                CHuiGc* aGc, 
       
   471                                                TPoint& aPos, 
       
   472                                                TBool aIgnoreUnChangedBuffers, 
       
   473                                                TBool aIgnoreClippedBuffers, 
       
   474                                                TBool aIgnoreHandledBuffers,
       
   475                                                TBool aClearBeforeHandlingBuffers) 
       
   476     {   
       
   477     UpdateBufferUpdateRegions(aPos);
       
   478 
       
   479     TInt bufferCount = iCommandBuffers.Count();
       
   480     for (TInt cb = 0; cb < bufferCount; cb++)
       
   481         {
       
   482         CHuiCanvasCommandBuffer* cmdbuffer = iCommandBuffers[cb];
       
   483 
       
   484         #ifdef HUI_DEBUG_PRINT_PERFORMANCE_INTERVAL
       
   485         RDebug::Print(_L(">> CHuiCanvasWsPainter::DoHandleAllBuffersL Buffer size: %i "), iCommandBuffers[cb]->iCommands->Size());                
       
   486         for (TInt k=0; k < cmdbuffer->iUpdateRegion.Count();k++)
       
   487             {
       
   488             RDebug::Print(_L(">> CHuiCanvasWsPainter::DoHandleAllBuffersL Buffer region rect: %i,%i, %i,%i "), 
       
   489                 cmdbuffer->iUpdateRegion[k].iTl.iX,
       
   490                 cmdbuffer->iUpdateRegion[k].iTl.iY,
       
   491                 cmdbuffer->iUpdateRegion[k].iBr.iX,
       
   492                 cmdbuffer->iUpdateRegion[k].iBr.iY);                
       
   493             }
       
   494         #endif
       
   495 
       
   496         if (aIgnoreUnChangedBuffers && !cmdbuffer->iChanged)
       
   497             {
       
   498             #ifdef HUI_DEBUG_PRINT_PERFORMANCE_INTERVAL
       
   499             RDebug::Print(_L(">> CHuiCanvasWsPainter::DoHandleAllBuffersL Skipping buffer, it has not changed"));                
       
   500             #endif            
       
   501             continue;            
       
   502             }
       
   503 
       
   504         if (aIgnoreHandledBuffers)
       
   505             {
       
   506             if (aAction == EDrawBuffer && (cmdbuffer->iStatusFlags & EHuiCanvasBufferStatusDrawn))
       
   507                 {
       
   508                 #ifdef HUI_DEBUG_PRINT_PERFORMANCE_INTERVAL
       
   509                 RDebug::Print(_L(">> CHuiCanvasWsPainter::DoHandleAllBuffersL Skipping buffer, it has already been drawn."));                
       
   510                 #endif                            
       
   511                 continue;
       
   512                 }
       
   513             else if (aAction == EScanBuffer && (cmdbuffer->iStatusFlags & EHuiCanvasBufferStatusScanned))
       
   514                 {
       
   515                 #ifdef HUI_DEBUG_PRINT_PERFORMANCE_INTERVAL
       
   516                 RDebug::Print(_L(">> CHuiCanvasWsPainter::DoHandleAllBuffersL Skipping buffer, it has already been scanned."));                
       
   517                 #endif            
       
   518                 continue;            
       
   519                 }
       
   520             else
       
   521                 {
       
   522                 // No, we dont ignore.                                
       
   523                 }
       
   524             }
       
   525             
       
   526         if (aIgnoreClippedBuffers && IsBufferCompletelyOutisideClippingRegion(*cmdbuffer))
       
   527             {
       
   528             #ifdef HUI_DEBUG_PRINT_PERFORMANCE_INTERVAL
       
   529             RDebug::Print(_L(">> CHuiCanvasWsPainter::DoHandleAllBuffersL: Skipping buffer %i, as it is completely clipped"), cb);
       
   530             #endif                    
       
   531             continue;
       
   532             }
       
   533               
       
   534         if (aGc)
       
   535             {
       
   536             #ifdef HUI_DEBUG_PRINT_PERFORMANCE_INTERVAL
       
   537             RDebug::Print(_L(">> CHuiCanvasWsPainter::DoHandleAllBuffersL ClipRegion before clipping to updateregion:"));                
       
   538             const TRegion& originalclipregion = aGc->ClipRegion(); 
       
   539             for (TInt k=0; k < originalclipregion.Count();k++)
       
   540                 {
       
   541                 
       
   542                 RDebug::Print(_L(">> CHuiCanvasWsPainter::DoHandleAllBuffersL original clip region rect: %i,%i, %i,%i "), 
       
   543                         originalclipregion[k].iTl.iX,
       
   544                         originalclipregion[k].iTl.iY,
       
   545                         originalclipregion[k].iBr.iX,
       
   546                         originalclipregion[k].iBr.iY);                
       
   547                 }
       
   548             #endif
       
   549 
       
   550             
       
   551             // If buffers has been scanned, but it does not seem to contain any real drawing commands we discard it            
       
   552             if (!(cmdbuffer->iStatusFlags & EHuiCanvasBufferContainsDrawing) && (cmdbuffer->iStatusFlags & EHuiCanvasBufferStatusScanned))
       
   553                 {
       
   554                 #ifdef HUI_DEBUG_PRINT_PERFORMANCE_INTERVAL
       
   555                 RDebug::Print(_L("CHuiCanvasWsPainter::DoHandleAllBuffersL: Hmmm, WSERV has sent buffer without real drawing commands."), cb);
       
   556                 #endif
       
   557                 continue;
       
   558                 }
       
   559             
       
   560             // Clip drawing to update area. This seems to improve performance although
       
   561             // it may depend on used HW.
       
   562             iCanvasWsGc->EnableUpdateRegion(iCommandBuffers[cb]->iUpdateRegion, aClearBeforeHandlingBuffers);
       
   563 
       
   564             #ifdef HUI_DEBUG_PRINT_PERFORMANCE_INTERVAL
       
   565             RDebug::Print(_L(">> CHuiCanvasWsPainter::DoHandleAllBuffersL ClipRegion after clipping to updateregion:"));                
       
   566             const TRegion& clipregion = aGc->ClipRegion(); 
       
   567             for (TInt k=0; k < originalclipregion.Count();k++)
       
   568                 {
       
   569                 
       
   570                 RDebug::Print(_L(">> CHuiCanvasWsPainter::DoHandleAllBuffersL current clip region rect: %i,%i, %i,%i "), 
       
   571                         clipregion[k].iTl.iX,
       
   572                         clipregion[k].iTl.iY,
       
   573                         clipregion[k].iBr.iX,
       
   574                         clipregion[k].iBr.iY);                
       
   575                 }
       
   576             #endif
       
   577             
       
   578             TRAPD(error, DoHandleBufferL(cb, aDisplayRect, aAction, aUser, aGc, aPos ));
       
   579             
       
   580             if (error)
       
   581                 {
       
   582                 #ifdef _DEBUG
       
   583                 RDebug::Print(_L("CHuiCanvasWsPainter::DoHandleAllBuffersL: Error in buffer %i, continuing."), cb);
       
   584                 #endif
       
   585                 }
       
   586             
       
   587             iCanvasWsGc->DisableUpdateRegion();
       
   588             }
       
   589         else
       
   590             {
       
   591             DoHandleBufferL(cb, aDisplayRect, aAction, aUser, aGc, aPos);
       
   592             }
       
   593         
       
   594         // Update buffer status
       
   595         if (aAction == EDrawBuffer)
       
   596             {
       
   597             cmdbuffer->SetStatusFlags(EHuiCanvasBufferStatusDrawn);
       
   598             }
       
   599         else if (aAction == EScanBuffer)
       
   600             {
       
   601             cmdbuffer->SetStatusFlags(EHuiCanvasBufferStatusScanned);            
       
   602             }
       
   603         else
       
   604             {
       
   605             // This should not happen
       
   606             }
       
   607         }         
       
   608     }
       
   609 
       
   610 
       
   611 void CHuiCanvasWsPainter::HandleBufferL(TRect& aDisplayRect, TInt aAction, const CHuiCanvasVisual& aUser, CHuiGc* aGc, TPoint aPos, TPtrC8 aCommands, CHuiCanvasCommandBuffer * /*buf*/)
       
   612     {
       
   613     TUint8 *ptr = const_cast<TUint8*>(aCommands.Ptr());
       
   614     TInt length = aCommands.Length();
       
   615     TPtr8 cmds(ptr, length, length);
       
   616     CHuiCanvasCommandBuffer *buf = new (ELeave)CHuiCanvasCommandBuffer;
       
   617     CleanupStack::PushL(buf);
       
   618     buf->iUpdateRegion.AddRect(aDisplayRect);
       
   619     if (iCanvasVisual && iCanvasVisual->Display())
       
   620         {
       
   621         buf->iOrientation = iCanvasVisual->Display()->Orientation();
       
   622         }
       
   623     DoHandleBufferStringL(-1, aDisplayRect, aAction, aUser, aGc, aPos, cmds, buf);
       
   624     CleanupStack::PopAndDestroy();
       
   625     }
       
   626 
       
   627 void CHuiCanvasWsPainter::DoPeekBufferL(TInt aIndex) 
       
   628     {   
       
   629     RMemReadStream& readerStream = iWsCommandBufferReader->Stream();
       
   630     CHuiCanvasCommandBuffer& commandBuffer = *iCommandBuffers[aIndex];
       
   631     HBufC8* cmdBuf = commandBuffer.iCommands;
       
   632     TInt bufLength =  cmdBuf->Length();
       
   633     
       
   634     TPtr8 des = cmdBuf->Des();
       
   635     iWsCommandBufferReader->Init( des, bufLength );
       
   636     TInt offset = 0; 
       
   637     TInt command = 0;
       
   638     TBool donePeeking = EFalse;
       
   639     do
       
   640         {
       
   641         command = readerStream.ReadUint8L();
       
   642         
       
   643         switch ( command )
       
   644             {
       
   645             case EAlfFrameContainsUnsupportedCommands:
       
   646                 {
       
   647                 TUint8 containsUnsupportedCommands = iWsCommandBufferReader->Stream().ReadUint8L();
       
   648                 if ( containsUnsupportedCommands )
       
   649                     {
       
   650                     commandBuffer.iContainsUnsupportedCommands = ETrue;
       
   651                     }
       
   652                 break;
       
   653                 }
       
   654             case EAlfFrameFlags:
       
   655                 {
       
   656                 TInt flags;
       
   657                 iWsCommandBufferReader->ReadInt32L( flags );
       
   658                 if (flags & EAlfTransparentContent)
       
   659                     {
       
   660                     EnableRenderBuffer(ETrue);
       
   661                     }                
       
   662                 break;
       
   663                 }
       
   664             case EAlfSetUpdateRegion: 
       
   665                 {
       
   666                 WsSetUpdateRegionL(aIndex);
       
   667 				commandBuffer.iPositionForUpdateRegion = Visual()->DisplayRect().iTl.Round();
       
   668                 break;
       
   669                 }
       
   670             case EAlfCommandIndexArrayHeader:
       
   671                 {
       
   672                 TInt tmp;
       
   673                 iWsCommandBufferReader->ReadInt8L(); // padding
       
   674                 iWsCommandBufferReader->ReadInt32L( tmp );
       
   675                 iWsCommandBufferReader->ReadInt32L( tmp );
       
   676                 break;
       
   677                 }
       
   678             case EAlfPacketPadding:
       
   679                 {
       
   680                 DoDigestPaddingL();
       
   681 				break;
       
   682                 }
       
   683             case EAlfSetShapeRegion: 
       
   684                 {
       
   685                 WsSetShapeRegionL( aIndex );
       
   686                 break;
       
   687                 }
       
   688             default:
       
   689                 {
       
   690                 donePeeking = ETrue;
       
   691                 break;    
       
   692                 }     
       
   693             }
       
   694         
       
   695    		offset = readerStream.Source()->TellL( MStreamBuf::ERead ).Offset();
       
   696        	
       
   697         } while( offset < bufLength && !donePeeking);
       
   698     
       
   699     iCommandBuffers[aIndex]->iOriginalDisplayRect = iCanvasVisual->DisplayRect();
       
   700     }
       
   701 
       
   702 
       
   703 #ifdef HUI_DEBUG_TRACK_DRAWING
       
   704 void CHuiCanvasWsPainter::DoHandleBufferL(TInt aIndex, TRect& aDisplayRect, TInt aAction, const CHuiCanvasVisual& aUser, CHuiGc* aGc, TPoint& aPos) 
       
   705 #else
       
   706 void CHuiCanvasWsPainter::DoHandleBufferL(TInt aIndex, TRect& aDisplayRect, TInt aAction, const CHuiCanvasVisual& aUser, CHuiGc* aGc, TPoint& aPos) 
       
   707 #endif
       
   708     {
       
   709     CHuiCanvasCommandBuffer* commandBuffer = iCommandBuffers[aIndex];
       
   710     HBufC8* cmdBuf = commandBuffer->iCommands;
       
   711 
       
   712 #ifdef HUI_DEBUG_TRACK_DRAWING
       
   713     if ( commandBuffer->iTrackedBuffer )
       
   714         {
       
   715         RDebug::Print( _L("CHuiCanvasWsPainter::DoHandleBufferL - Tracked buffer found"));
       
   716         switch ( aAction )
       
   717             {
       
   718             case EDrawBuffer:
       
   719                 {
       
   720                 RDebug::Print( _L("CHuiCanvasWsPainter::DoHandleBufferL - draw buffer"));
       
   721                 break;
       
   722                 }
       
   723             case EScanBuffer:
       
   724                 {
       
   725                 RDebug::Print( _L("CHuiCanvasWsPainter::DoHandleBufferL - scan buffer"));
       
   726                 break;
       
   727                 }
       
   728             default:;
       
   729             }
       
   730         }
       
   731 
       
   732     iCommandDebugger->StartFrame();
       
   733     if ( commandBuffer->iProcessName )
       
   734         {
       
   735         // UNCOMMENT THIS IF YOU WANT TO PRINT EVERYTHING
       
   736         // iCommandDebugger->SetPrint( ETrue );
       
   737         // UNCOMMENT THIS IF YOU WANT PRINTS ONLY FOR CERTAIN PROCESS!
       
   738         // DEFINE PROCESS NAME IN alfcommanddebug.cpp
       
   739         // iCommandDebugger->SetPrint( iCommandDebugger->TrackProcess( commandBuffer->iProcessName ) );
       
   740         RDebug::Print(_L("CHuiCanvasWsPainter::DoHandleBufferL - Process [%S]"), commandBuffer->iProcessName );
       
   741         }
       
   742     else
       
   743         {
       
   744 //        RDebug::Print(_L("CHuiCanvasWsPainter::DoHandleBufferL - Process [already dead or not found]"));
       
   745         }
       
   746 #endif
       
   747   
       
   748     TPtr8 des = cmdBuf->Des();
       
   749     DoHandleBufferStringL(aIndex, aDisplayRect, aAction, aUser, aGc, aPos, des, commandBuffer);
       
   750     }
       
   751 
       
   752 void CHuiCanvasWsPainter::DoHandleBufferStringL(TInt aIndex, TRect& /*aDisplayRect*/, TInt /*aAction*/, const CHuiCanvasVisual& /*aUser*/, CHuiGc* /*aGc*/, TPoint& aPos, TPtr8 aCmds, CHuiCanvasCommandBuffer *aCommandBuffer)
       
   753     {
       
   754     RMemReadStream& readerStream = iWsCommandBufferReader->Stream();    
       
   755     TInt bufLength =  aCmds.Length();
       
   756     TPtr8 des = aCmds;
       
   757     CHuiCanvasCommandBuffer *commandBuffer = aCommandBuffer;
       
   758     TPoint deltaPos = aPos - commandBuffer->iOriginalDisplayRect.iTl;
       
   759     
       
   760     iCanvasWsGc->SetPositionDelta( deltaPos );
       
   761     iWsCommandBufferReader->Init( des, bufLength );
       
   762     TInt offset = 0; 
       
   763     TInt command = 0;
       
   764     do
       
   765         {
       
   766         command = readerStream.ReadUint8L();
       
   767 #ifdef HUI_DEBUG_TRACK_DRAWING
       
   768         iCommandDebugger->SetDescription( command );
       
   769 #endif
       
   770 
       
   771 		// Command cases are ordered approximately in the order so that most common ones are at first
       
   772         switch ( command )
       
   773             {
       
   774             case EAlfFrameContainsUnsupportedCommands:
       
   775                 {
       
   776                 TUint8 containsUnsupportedCommands = iWsCommandBufferReader->Stream().ReadUint8L();
       
   777                 if (containsUnsupportedCommands )
       
   778                     {
       
   779                     // RDebug::Print(_L("Unsupported commands in this frame"));
       
   780                     }
       
   781                 break;
       
   782                 }
       
   783             case EAlfFrameFlags:
       
   784                 {
       
   785                 TInt flags;
       
   786                 iWsCommandBufferReader->ReadInt32L( flags );
       
   787                 if ( flags != 0 )
       
   788                     {
       
   789                     RDebug::Print(_L("FLAGS: %d"), flags );
       
   790                     }
       
   791                 break;
       
   792                 }
       
   793             case EAlfSetUpdateRegion: 
       
   794                 {
       
   795                 WsSetUpdateRegionL(aIndex);                    
       
   796                 break;
       
   797                 }               
       
   798             case EAlfSetShapeRegion: 
       
   799                 {
       
   800                 iTempRegion.Clear();                
       
   801                 iWsCommandBufferReader->ReadRegionL( iTempRegion );
       
   802                 break;
       
   803                 }               
       
   804             case EAlfSetBrushStyle:
       
   805                 {
       
   806                 WsSetBrushStyleL();                  
       
   807                 break;
       
   808                 }
       
   809             case EAlfSetOrigin:
       
   810                 {
       
   811                 WsSetOriginL();
       
   812                 break;
       
   813                 }
       
   814             case EAlfSetPenStyle:
       
   815                 {
       
   816                 WsSetPenStyleL();
       
   817                 break;
       
   818                 }
       
   819             case EAlfSetClippingRegion:
       
   820                 {        
       
   821                 WsSetClippingRegionL();
       
   822                 break;
       
   823                 }
       
   824             case EAlfResetClippingRegion:
       
   825                 {
       
   826                 WsResetClippingRegionL();
       
   827                 break;
       
   828                 }
       
   829             case EAlfSetBrushColor:
       
   830                 {
       
   831                 WsSetBrushColorL();
       
   832                 break;
       
   833                 }
       
   834             case EAlfBitBltMasked:
       
   835                 {
       
   836                 commandBuffer->SetStatusFlags(EHuiCanvasBufferContainsDrawing);
       
   837                 WsBitBltMaskedL();
       
   838                 break;
       
   839                 }
       
   840             case EAlfCombinedBitBlitMasked:
       
   841 				{
       
   842                 commandBuffer->SetStatusFlags(EHuiCanvasBufferContainsDrawing);
       
   843 				WsCombinedBitBlitMaskedL();
       
   844 				break;
       
   845 				}
       
   846             case EAlfReset:
       
   847                 {
       
   848                 WsResetL();
       
   849                 break;
       
   850                 }
       
   851             case EAlfSetPenColor:
       
   852                 {
       
   853                 WsSetPenColorL();
       
   854                 break;
       
   855                 }
       
   856             case EAlfBitBltRect:
       
   857                 {
       
   858                 commandBuffer->SetStatusFlags(EHuiCanvasBufferContainsDrawing);
       
   859                 WsBitBltRectL();
       
   860                 break;
       
   861                 }
       
   862             case EAlfSetDrawMode:
       
   863                 {
       
   864                 WsSetDrawModeL();
       
   865                 break;
       
   866                 }
       
   867             case EAlfSetCharJustification:
       
   868                 {
       
   869                 WsSetCharJustificationL();
       
   870                 break;
       
   871                 }
       
   872             case EAlfDrawBitmapMasked:
       
   873                 {
       
   874                 commandBuffer->SetStatusFlags(EHuiCanvasBufferContainsDrawing);
       
   875                 WsDrawBitmapMaskedL();
       
   876                 break;
       
   877                 }
       
   878             case EAlfSetUnderlineStyle:
       
   879                 {
       
   880                 WsSetUnderlineStyleL();
       
   881                 break;
       
   882                 }
       
   883             case EAlfResetFont:
       
   884                 {
       
   885                 WsResetFontL();
       
   886                 break;
       
   887                 }
       
   888             case EAlfSetStrikethroughStyle:
       
   889                 {
       
   890                 WsSetStrikethroughStyleL();
       
   891                 break;
       
   892                 }
       
   893             case EAlfBitBlt:
       
   894               	{
       
   895                 commandBuffer->SetStatusFlags(EHuiCanvasBufferContainsDrawing);
       
   896               	WsBitBltL();
       
   897                 break;
       
   898               	}
       
   899             case EAlfBitBltMaskedPoint:
       
   900                 {
       
   901                 commandBuffer->SetStatusFlags(EHuiCanvasBufferContainsDrawing);
       
   902                 WsBitBltMaskedPointL();
       
   903                 break;
       
   904                 }
       
   905             case EAlfClear:
       
   906                 {
       
   907                 commandBuffer->SetStatusFlags(EHuiCanvasBufferContainsDrawing);
       
   908                 WsClearL();
       
   909                 break;
       
   910                 }
       
   911             case EAlfClearRect:
       
   912                 {
       
   913                 commandBuffer->SetStatusFlags(EHuiCanvasBufferContainsDrawing);
       
   914                 WsClearRectL();
       
   915                 break;
       
   916                 }
       
   917             case EAlfResetBrushPattern:
       
   918                 {
       
   919                 WsResetBrushPatternL();
       
   920                 break;
       
   921                 }
       
   922             case EAlfDrawText1:
       
   923                 {
       
   924                 commandBuffer->SetStatusFlags(EHuiCanvasBufferContainsDrawing);
       
   925                 WsDrawText1L();
       
   926                 break;
       
   927                 }
       
   928             case EAlfDrawText2:
       
   929                 {
       
   930                 commandBuffer->SetStatusFlags(EHuiCanvasBufferContainsDrawing);
       
   931                 WsDrawText2L();
       
   932                 break;
       
   933                 }
       
   934             case EAlfDrawText3:
       
   935                 {
       
   936                 commandBuffer->SetStatusFlags(EHuiCanvasBufferContainsDrawing);
       
   937                 WsDrawText3L();
       
   938                 break;
       
   939                 }
       
   940             case EAlfDrawText4:
       
   941                 {
       
   942                 commandBuffer->SetStatusFlags(EHuiCanvasBufferContainsDrawing);
       
   943                 WsDrawText4L();
       
   944                 break;
       
   945                 }                
       
   946             case EAlfDrawText5:
       
   947                 {
       
   948                 commandBuffer->SetStatusFlags(EHuiCanvasBufferContainsDrawing);
       
   949                 WsDrawText5L();
       
   950                 break;
       
   951                  }
       
   952             case EAlfDrawArc:
       
   953                 {
       
   954                 commandBuffer->SetStatusFlags(EHuiCanvasBufferContainsDrawing);
       
   955                 WsDrawArcL();
       
   956                 break;
       
   957                 }
       
   958             case EAlfDrawPie:
       
   959                 {
       
   960                 commandBuffer->SetStatusFlags(EHuiCanvasBufferContainsDrawing);
       
   961                 WsDrawPieL();                    
       
   962                 break;
       
   963                 }
       
   964             case EAlfDrawBitmap1:
       
   965                 {
       
   966                 commandBuffer->SetStatusFlags(EHuiCanvasBufferContainsDrawing);
       
   967                 WsDrawBitmap1L();                    
       
   968                 break;
       
   969                 }
       
   970             case EAlfDrawBitmap2:
       
   971                 {
       
   972                 commandBuffer->SetStatusFlags(EHuiCanvasBufferContainsDrawing);
       
   973                 WsDrawBitmap2L();
       
   974                 break;
       
   975                 }
       
   976             case EAlfDrawBitmap3:
       
   977                 {
       
   978                 commandBuffer->SetStatusFlags(EHuiCanvasBufferContainsDrawing);
       
   979                 WsDrawBitmap3L();
       
   980                 break;
       
   981                 }
       
   982             case EAlfDrawRoundRect:
       
   983                 {
       
   984                 commandBuffer->SetStatusFlags(EHuiCanvasBufferContainsDrawing);
       
   985                 WsDrawRoundRectL();
       
   986                 break;
       
   987                 }
       
   988             case EAlfDrawPolyLine:
       
   989                 {
       
   990                 commandBuffer->SetStatusFlags(EHuiCanvasBufferContainsDrawing);
       
   991                 WsDrawPolyLineL();
       
   992                 break;
       
   993                 }
       
   994             case EAlfDrawPolyLineNoEndPoint:
       
   995                 {
       
   996                 commandBuffer->SetStatusFlags(EHuiCanvasBufferContainsDrawing);
       
   997                 WsDrawPolyLineNoEndPointL();
       
   998                 break;
       
   999                 }
       
  1000             case EAlfDrawPolygon:
       
  1001                 {
       
  1002                 commandBuffer->SetStatusFlags(EHuiCanvasBufferContainsDrawing);
       
  1003                 WsDrawPolygonL();                                     
       
  1004                 break;
       
  1005                 }
       
  1006             case EAlfDrawEllipse:
       
  1007                 {
       
  1008                 commandBuffer->SetStatusFlags(EHuiCanvasBufferContainsDrawing);
       
  1009                 WsDrawEllipseL();
       
  1010                 break;
       
  1011                 }
       
  1012             case EAlfDrawLine:
       
  1013                 {
       
  1014                 commandBuffer->SetStatusFlags(EHuiCanvasBufferContainsDrawing);
       
  1015                 WsDrawLineL();
       
  1016                 break;
       
  1017                 }
       
  1018             case EAlfDrawLineTo:
       
  1019                 {
       
  1020                 commandBuffer->SetStatusFlags(EHuiCanvasBufferContainsDrawing);
       
  1021                 WsDrawLineToL();
       
  1022                 break;
       
  1023                 }
       
  1024             case EAlfDrawLineBy:
       
  1025                 {
       
  1026                 commandBuffer->SetStatusFlags(EHuiCanvasBufferContainsDrawing);
       
  1027                 WsDrawLineByL();
       
  1028                 break;
       
  1029                 }
       
  1030             case EAlfDrawRect:
       
  1031                 {
       
  1032                 commandBuffer->SetStatusFlags(EHuiCanvasBufferContainsDrawing);
       
  1033                 WsDrawRectL();
       
  1034                 break;
       
  1035                 }
       
  1036             case EAlfDrawTextVertical1:
       
  1037                 {
       
  1038                 commandBuffer->SetStatusFlags(EHuiCanvasBufferContainsDrawing);
       
  1039                 WsDrawTextVertical1L();
       
  1040                 break;
       
  1041                 }
       
  1042             case EAlfDrawTextVertical2:
       
  1043                 {
       
  1044                 commandBuffer->SetStatusFlags(EHuiCanvasBufferContainsDrawing);
       
  1045                 WsDrawTextVertical2L();
       
  1046                 break;
       
  1047                 }                
       
  1048             case EAlfDrawTextVertical3:
       
  1049                 {
       
  1050                 commandBuffer->SetStatusFlags(EHuiCanvasBufferContainsDrawing);
       
  1051                 WsDrawTextVertical3L();                          
       
  1052                 break;
       
  1053                 } 
       
  1054             case EAlfDrawTextVertical4: 
       
  1055                 {
       
  1056                 commandBuffer->SetStatusFlags(EHuiCanvasBufferContainsDrawing);
       
  1057                 WsDrawTextVertical4L();
       
  1058                 break;
       
  1059                 }
       
  1060             case EAlfDrawTextVertical5:
       
  1061                 {
       
  1062                 commandBuffer->SetStatusFlags(EHuiCanvasBufferContainsDrawing);
       
  1063                 WsDrawTextVertical5L();
       
  1064                 break;
       
  1065                 }
       
  1066             case EAlfMoveTo:
       
  1067                 {
       
  1068                 WsMoveToL();
       
  1069                 break;
       
  1070                 }
       
  1071             case EAlfMoveBy:
       
  1072                 {
       
  1073                 WsMoveByL();
       
  1074                 break;
       
  1075                 }
       
  1076             case EAlfPlot:
       
  1077                 {
       
  1078                 commandBuffer->SetStatusFlags(EHuiCanvasBufferContainsDrawing);
       
  1079                 WsPlotL();
       
  1080                 break;
       
  1081                 }
       
  1082             case EAlfSetBrushOrigin:
       
  1083                 {
       
  1084                 WsSetBrushOriginL();
       
  1085                 break;
       
  1086                 }
       
  1087             case EAlfSetPenSize:
       
  1088                 WsSetPenSizeL();                
       
  1089                 break;
       
  1090             case EAlfSetTextShadowColor:
       
  1091                 {
       
  1092                 WsSetTextShadowColorL();
       
  1093                 break;
       
  1094                 }
       
  1095             case EAlfSetWordJustification:
       
  1096                 {
       
  1097                 WsSetWordJustificationL();
       
  1098                 break;
       
  1099                 }                
       
  1100             case EAlfSetBrushPattern:
       
  1101                 {
       
  1102                 WsSetBrushPatternL();
       
  1103                 break;
       
  1104                 }
       
  1105             case EAlfSetBrushPattern2:
       
  1106                 {
       
  1107                 WsSetBrushPatternL();
       
  1108                 break;
       
  1109                 }
       
  1110             case EAlfSetFont:
       
  1111                 {
       
  1112                 WsSetFontL();
       
  1113                 break;
       
  1114                 }
       
  1115             case EAlfContentTag:
       
  1116                 {
       
  1117                 WsContentTagL();
       
  1118                 break;
       
  1119                 }
       
  1120             case EAlfCopyRect:
       
  1121                 WsCopyRectL();
       
  1122                 break;
       
  1123             case EAlfUpdateJustification:
       
  1124                 {
       
  1125                 WsUpdateJustificationL();                  
       
  1126                 break;
       
  1127                 }
       
  1128             case EAlfUpdateJustificationVertical:
       
  1129                 {
       
  1130                 WsUpdateJustificationVerticalL();
       
  1131                 break;
       
  1132                 }
       
  1133             case EAlfSetFontNoDuplicate:
       
  1134                 {
       
  1135                 WsSetFontNoDuplicateL();
       
  1136                 break;
       
  1137                 }
       
  1138             case EAlfHasBrushPattern:
       
  1139             case EAlfHasFont:
       
  1140             case EAlfBrushColor:
       
  1141             case EAlfPenColor:
       
  1142             case EAlfTextShadowColor:
       
  1143                 {
       
  1144                 // these values are cached on client side, we dont do anything.
       
  1145                 break;
       
  1146                 }
       
  1147             case EAlfCopySettings:
       
  1148                 {
       
  1149                 WsCopySettingsL();                    
       
  1150                 break;    
       
  1151                 }
       
  1152             case EAlfSetClippingRect:
       
  1153                 {
       
  1154                 WsSetClippingRectL();
       
  1155                 break;
       
  1156                 }
       
  1157             case EAlfCancelClippingRect:
       
  1158                 {
       
  1159                 WsCancelClippingRectL();
       
  1160                 break;
       
  1161                 }
       
  1162             case EAlfSetFaded:
       
  1163                 {
       
  1164                 commandBuffer->SetStatusFlags(EHuiCanvasBufferContainsDrawing);
       
  1165                 WsSetFadedL();
       
  1166                 }
       
  1167                 break;
       
  1168             case EAlfSetFadingParameters:
       
  1169                 {
       
  1170                 WsSetFadingParametersL();
       
  1171                 break;
       
  1172                 }
       
  1173             case EAlfFadeArea: 
       
  1174                 {
       
  1175                 commandBuffer->SetStatusFlags(EHuiCanvasBufferContainsDrawing);
       
  1176                 WsFadeAreaL();
       
  1177                 break;
       
  1178                 }
       
  1179             case EAlfMapColors:
       
  1180                 // MapColors is not supported. Client should never supply this command.
       
  1181                 User::Leave( KErrNotSupported );
       
  1182                 break;
       
  1183             case EAlfSetUserDisplayMode:
       
  1184                 {
       
  1185                 WsSetUserDisplayModeL();
       
  1186                 break;
       
  1187                 }
       
  1188             case EAlfUseFont:
       
  1189                 {
       
  1190                 WsUseFontL();                    
       
  1191                 break;
       
  1192                 }
       
  1193             case EAlfSendSyncDataBlock:
       
  1194                 {
       
  1195                 break;
       
  1196                 }
       
  1197             case EAlfWindowInactivateWindow:
       
  1198                 {
       
  1199                 // Nothing to do
       
  1200                 break;
       
  1201                 }
       
  1202             case EAlfPacketPadding:
       
  1203                 {
       
  1204                 DoDigestPaddingL();
       
  1205 				break;
       
  1206                 }
       
  1207             case EAlfCommandIndexArrayHeader:
       
  1208                 {
       
  1209                 TInt tmp;
       
  1210                 iWsCommandBufferReader->ReadInt8L(); // padding
       
  1211                 iWsCommandBufferReader->ReadInt32L( tmp );
       
  1212                 iWsCommandBufferReader->ReadInt32L( tmp );
       
  1213                 break;
       
  1214                 }
       
  1215             case EAlfCommandIndexArray:
       
  1216                 {
       
  1217                 TUint8 a = iWsCommandBufferReader->ReadInt8L();
       
  1218                 iWsCommandBufferReader->ReadInt8L();
       
  1219                 iWsCommandBufferReader->ReadInt8L();
       
  1220                 TInt tmp;
       
  1221                 TRect tmp2;
       
  1222                 for(TUint8 i=0;i<a;i++)
       
  1223                     {
       
  1224                     iWsCommandBufferReader->ReadInt32L(tmp);
       
  1225                     iWsCommandBufferReader->ReadInt32L(tmp);
       
  1226                     iWsCommandBufferReader->ReadInt32L(tmp);
       
  1227                     iWsCommandBufferReader->ReadRectL(tmp2);
       
  1228                     }
       
  1229                 break;
       
  1230                 }
       
  1231               
       
  1232                 
       
  1233             default:
       
  1234                 {
       
  1235                 // We should never ever get here
       
  1236                     HUI_DEBUG1(_L("CHuiCanvasVisual::HandleWsBufferL. Error: Unknown command=%d"), command);
       
  1237                 break;
       
  1238                 }
       
  1239             }// end switch
       
  1240     		offset = readerStream.Source()->TellL( MStreamBuf::ERead ).Offset();
       
  1241        	
       
  1242         } while( offset < bufLength );
       
  1243 #ifdef HUI_DEBUG_TRACK_DRAWING
       
  1244     iCommandDebugger->EndFrame();
       
  1245 #endif    
       
  1246     }
       
  1247     
       
  1248     
       
  1249 void CHuiCanvasWsPainter::SetCommandSetL( const TDesC8& aCommands )
       
  1250     {
       
  1251 	CHuiCanvasPainter::SetCommandSetL(aCommands);  
       
  1252 
       
  1253     TInt latest = iCommandBuffers.Count() - 1;
       
  1254     DoPeekBufferL(latest);
       
  1255     SelectGcL();
       
  1256        
       
  1257     // If shape region has changed recalculate all update regions and remove redundant buffers
       
  1258     if (iShapeRegionClippingPending)
       
  1259         {
       
  1260         TInt bufferCount = iCommandBuffers.Count();
       
  1261         for (TInt cb = 0; cb < bufferCount; cb++)
       
  1262             {        
       
  1263             CHuiCanvasCommandBuffer* cmdbuffer = iCommandBuffers[cb];
       
  1264             cmdbuffer->iUpdateRegion.Copy(cmdbuffer->iOriginalUpdateRegion);                
       
  1265             cmdbuffer->iUpdateRegion.Intersect(iShapeRegion);
       
  1266             cmdbuffer->iUpdateRegion.Tidy();
       
  1267             }
       
  1268         iShapeRegionClippingPending = EFalse;       
       
  1269         RemoveRedundantBuffers();   
       
  1270         }    
       
  1271     
       
  1272 	// Release currently cached images. 
       
  1273     // They may still be taken into use after next HandleBuffferL call.
       
  1274     if (iCanvasVisual)
       
  1275         {
       
  1276         iCanvasVisual->Env().CanvasTextureCache().ReleaseAllCachedEntries(*iCanvasVisual);         
       
  1277         }    
       
  1278     }
       
  1279     
       
  1280 
       
  1281 void CHuiCanvasWsPainter::ClearCommandSet()
       
  1282     {
       
  1283 #ifdef HUI_DEBUG_PRINT_PERFORMANCE_INTERVAL
       
  1284         RDebug::Print(_L(">> CHuiCanvasWsPainter::ClearCommandSet this = %i"), this );
       
  1285         TTime startTime;
       
  1286         startTime.UniversalTime();
       
  1287 #endif
       
  1288 
       
  1289     CHuiCanvasPainter::ClearCommandSet();
       
  1290     // Release currently cached images. 
       
  1291     // They may still be taken into use after next HandleBuffferL call.
       
  1292     if (iCanvasVisual)
       
  1293         {
       
  1294         iCanvasVisual->Env().CanvasTextureCache().ReleaseAllCachedEntries(*iCanvasVisual); 
       
  1295         }
       
  1296 
       
  1297 #ifdef HUI_DEBUG_PRINT_PERFORMANCE_INTERVAL
       
  1298         TTime endTime;
       
  1299         endTime.UniversalTime();
       
  1300         TInt timeInMs =  endTime.MicroSecondsFrom( startTime ).Int64()/1000;           
       
  1301         RDebug::Print(_L(">> CHuiCanvasWsPainter::ClearCommandSet took %i ms"), timeInMs);
       
  1302 #endif
       
  1303     
       
  1304     }
       
  1305 
       
  1306 struct TArrayHeader
       
  1307     {
       
  1308     TInt32 iOffset;
       
  1309     TInt32 iSize;
       
  1310     };
       
  1311 
       
  1312 void CHuiCanvasWsPainter::AddCommandSetL( const TDesC8& aMoreCommands )
       
  1313     {    
       
  1314 #ifdef HUI_DEBUG_PRINT_PERFORMANCE_INTERVAL
       
  1315         RDebug::Print(_L(">> CHuiCanvasWsPainter::AddCommandSetL this = %i"), this );
       
  1316         TTime startTime;
       
  1317         startTime.UniversalTime();
       
  1318 #endif
       
  1319 
       
  1320     CHuiCanvasPainter::AddCommandSetL(aMoreCommands);
       
  1321     TInt latest = iCommandBuffers.Count() - 1;
       
  1322     DoPeekBufferL(latest);     
       
  1323     SelectGcL();
       
  1324     
       
  1325     // If shape region has changed recalculate all update regions
       
  1326     if (iShapeRegionClippingPending)
       
  1327         {
       
  1328         TInt bufferCount = iCommandBuffers.Count();
       
  1329         for (TInt cb = 0; cb < bufferCount; cb++)
       
  1330             {        
       
  1331             CHuiCanvasCommandBuffer* cmdbuffer = iCommandBuffers[cb];
       
  1332             cmdbuffer->iUpdateRegion.Copy(cmdbuffer->iOriginalUpdateRegion);                
       
  1333             cmdbuffer->iUpdateRegion.Intersect(iShapeRegion);
       
  1334             cmdbuffer->iUpdateRegion.Tidy();
       
  1335             }
       
  1336         iShapeRegionClippingPending = EFalse;       
       
  1337         }    
       
  1338     
       
  1339     RemoveRedundantBuffers();   
       
  1340     
       
  1341     // New command set may contain BitBlt commands
       
  1342     // and those cached images must be refreshed
       
  1343     if (iCanvasVisual)
       
  1344         {
       
  1345         // Release currently cached images. 
       
  1346         // They may still be taken into use after next HandleBufferL call.
       
  1347         iCanvasVisual->Env().CanvasTextureCache().ReleaseAllCachedEntries(*iCanvasVisual); 
       
  1348         }
       
  1349 
       
  1350 #ifdef HUI_DEBUG_PRINT_PERFORMANCE_INTERVAL
       
  1351         TTime endTime;
       
  1352         endTime.UniversalTime();
       
  1353         TInt timeInMs =  endTime.MicroSecondsFrom( startTime ).Int64()/1000;           
       
  1354         RDebug::Print(_L(">> CHuiCanvasWsPainter::AddCommandSetL took %i ms"), timeInMs);
       
  1355 #endif
       
  1356 
       
  1357 #ifdef HUI_ENABLE_SUBWINDOW_FX        
       
  1358     TInt count = NumBuffers();
       
  1359     if (!count) return;
       
  1360     const TDesC8 &more = At(count-1)->iCommands->Des();
       
  1361     //RDebug::Print(_L("MoreCommands: %x : %d"), aMoreCommands.Ptr(), aMoreCommands.Length());
       
  1362     TPtrC8 header = more.Mid(4, sizeof(TArrayHeader)); // the magic comes from CAlfRsSendBuffer::WriteFollowingFrameOffsetL.
       
  1363     TArrayHeader *ptr = (TArrayHeader*)header.Ptr();
       
  1364     //RDebug::Print(_L("Ptr: %d : %d"), ptr->iOffset, ptr->iSize);
       
  1365     TPtrC8 indexTable = more.Mid(ptr->iOffset, ptr->iSize);
       
  1366 
       
  1367     if (iCanvasVisual->Brushes() && iCanvasVisual)
       
  1368         {
       
  1369         ParseCmdBufferL(*iCanvasVisual->Brushes(), more, indexTable, CanvasGc(), *CanvasWsGc(), *iCanvasVisual, *this);
       
  1370         }
       
  1371 #endif
       
  1372     
       
  1373 #ifdef HUI_DEBUG_PRINT_PERFORMANCE_INTERVAL
       
  1374         TTime endTime2;
       
  1375         endTime2.UniversalTime();
       
  1376         TInt time2InMs =  endTime2.MicroSecondsFrom( startTime ).Int64()/1000;           
       
  1377         RDebug::Print(_L(">> CHuiCanvasWsPainter::AddCommandSetL including brush creation took %i ms"), time2InMs);
       
  1378 #endif
       
  1379 
       
  1380     }
       
  1381 
       
  1382 void CHuiCanvasWsPainter::AddPartialCommandSetL( const TDesC8& aMoreCommands, TBool aLastPart )
       
  1383     {
       
  1384     CHuiCanvasPainter::AddPartialCommandSetL(aMoreCommands,aLastPart); 
       
  1385     }
       
  1386 
       
  1387 #ifdef HUI_DEBUG_TRACK_DRAWING
       
  1388 void CHuiCanvasWsPainter::SetTrackCommandSet( TFileName& aFileName, TBool aTrack )
       
  1389     {
       
  1390     CHuiCanvasPainter::SetTrackCommandSet( aFileName, aTrack );
       
  1391     }
       
  1392 #endif
       
  1393 
       
  1394 void CHuiCanvasWsPainter::ClearCache()
       
  1395     {
       
  1396     if (iCanvasVisual && !iCacheCleared)
       
  1397         {
       
  1398 #ifdef HUI_DEBUG_PRINT_PERFORMANCE_INTERVAL
       
  1399         RDebug::Print(_L(">> CHuiCanvasWsPainter::ClearCache this = %i"), this );
       
  1400         TTime startTime;
       
  1401         startTime.UniversalTime();
       
  1402 #endif
       
  1403         TRAP_IGNORE(SelectGcL());
       
  1404         RenewAllBuffers();         
       
  1405         SetAllBuffersChanged(ETrue);
       
  1406         iCanvasWsGc->ClearCache();
       
  1407         iCanvasVisual->Env().CanvasTextureCache().ReleaseAllCachedEntries(*iCanvasVisual); 
       
  1408         iCacheCleared = ETrue;
       
  1409         
       
  1410 #ifdef HUI_DEBUG_PRINT_PERFORMANCE_INTERVAL
       
  1411         TTime endTime;
       
  1412         endTime.UniversalTime();
       
  1413         TInt timeInMs =  endTime.MicroSecondsFrom( startTime ).Int64()/1000;           
       
  1414         RDebug::Print(_L(">> CHuiCanvasWsPainter::ClearCache took %i ms"), timeInMs);
       
  1415 #endif
       
  1416 
       
  1417         }
       
  1418     }
       
  1419 
       
  1420 
       
  1421 void CHuiCanvasWsPainter::WsBitBltL()
       
  1422     {
       
  1423     TPoint point(0,0);
       
  1424     TInt bitmapHandle = 0;
       
  1425     iWsCommandBufferReader->ReadPointL( point );
       
  1426     iWsCommandBufferReader->ReadBitmapHandleL( bitmapHandle );
       
  1427    	iCanvasWsGc->WsBitBltL(bitmapHandle,point);         
       
  1428     }
       
  1429     
       
  1430 void CHuiCanvasWsPainter::WsBitBltRectL()
       
  1431     {
       
  1432     iWsCommandBufferReader->ReadL( (TUint8*)&iStructBitBlitRect, sizeof( TStructBitBlitRect ) );
       
  1433     iCanvasWsGc->WsBitBltRectL( 
       
  1434             iStructBitBlitRect.iBitmapHandle,
       
  1435             iStructBitBlitRect.iPoint,
       
  1436             iStructBitBlitRect.iRect);
       
  1437     }
       
  1438     
       
  1439 void CHuiCanvasWsPainter::WsBitBltMaskedL()
       
  1440     {
       
  1441     iWsCommandBufferReader->ReadL( (TUint8*)&iStructBitBlitMasked, sizeof( TStructBitBlitMasked ) );
       
  1442 	iCanvasWsGc->WsBitBltMaskedL( 
       
  1443 	        iStructBitBlitMasked.iBitmapHandle,
       
  1444 	        iStructBitBlitMasked.iMaskHandle,
       
  1445 	        iStructBitBlitMasked.iInvertMask,
       
  1446 	        iStructBitBlitMasked.iPoint,
       
  1447 	        iStructBitBlitMasked.iRect);         
       
  1448     }
       
  1449 
       
  1450 
       
  1451 void  CHuiCanvasWsPainter::WsCombinedBitBlitMaskedL()
       
  1452 	{
       
  1453 	TRect clipRect(0,0,0,0);
       
  1454 	TRect blitRect(0,0,0,0);
       
  1455 	TInt itemCount = iWsCommandBufferReader->ReadInt8L();
       
  1456 	iWsCommandBufferReader->ReadL( (TUint8*)&clipRect, sizeof( TRect ) );
       
  1457 	iWsCommandBufferReader->ReadL( (TUint8*)&blitRect, sizeof( TRect ) );
       
  1458 	    
       
  1459 	TInt index(0);
       
  1460 	
       
  1461 	RArray<THuiCachedCombinedImageParams> combinedBlitItems;
       
  1462 	THuiCachedCombinedImageParams combinedBlitItem;
       
  1463 	while( index++ < itemCount )
       
  1464 		{
       
  1465 		iWsCommandBufferReader->ReadL( (TUint8*)&combinedBlitItem, sizeof( THuiCachedCombinedImageParams ) );
       
  1466 		combinedBlitItems.Append(combinedBlitItem);
       
  1467 		}
       
  1468 	// clipping rects were optimized away by renderstage. it must be set now.
       
  1469 	// We use SetClippingRegion instead of SetClippingRect as they handle ws origin differently.
       
  1470 	iTempRegion.Clear();
       
  1471     iTempRegion.AddRect(clipRect);
       
  1472     iCanvasWsGc->WsSetClippingRegionL(iTempRegion);  
       
  1473 	iCanvasWsGc->WsCombinedBitBltMaskedL(blitRect, combinedBlitItems);
       
  1474     iCanvasWsGc->WsResetClippingRegionL();  
       
  1475 	combinedBlitItems.Close();
       
  1476 	}
       
  1477 
       
  1478 void CHuiCanvasWsPainter::WsBitBltMaskedPointL()
       
  1479     { 
       
  1480     TPoint point1(0,0);
       
  1481     TPoint point2(0,0);
       
  1482     TRect rect(0,0,0,0);
       
  1483     TInt bitmapHandle = 0;
       
  1484     TInt maskHandle = 0;
       
  1485     iWsCommandBufferReader->ReadPointL( point1 );
       
  1486     iWsCommandBufferReader->ReadBitmapHandleL( bitmapHandle );
       
  1487     iWsCommandBufferReader->ReadRectL( rect );
       
  1488     iWsCommandBufferReader->ReadBitmapHandleL( maskHandle );
       
  1489     iWsCommandBufferReader->ReadPointL( point2 );
       
  1490     iCanvasWsGc->WsBitBltMaskedPointL(bitmapHandle,maskHandle,point1,point2,rect);
       
  1491     }
       
  1492     
       
  1493 void CHuiCanvasWsPainter::WsResetClippingRegionL()
       
  1494     {    
       
  1495     iCanvasWsGc->WsResetClippingRegionL();
       
  1496     }
       
  1497     
       
  1498 void CHuiCanvasWsPainter::WsClearL()
       
  1499     {
       
  1500    	iCanvasWsGc->WsClearL();
       
  1501     }
       
  1502 
       
  1503 void CHuiCanvasWsPainter::WsClearRectL()
       
  1504     {
       
  1505     TRect tmpRect1(0,0,0,0);
       
  1506     iWsCommandBufferReader->ReadRectL( tmpRect1 );
       
  1507 	iCanvasWsGc->WsClearRectL(tmpRect1);
       
  1508     }
       
  1509 
       
  1510 void CHuiCanvasWsPainter::WsResetBrushPatternL()
       
  1511     {
       
  1512             
       
  1513     }
       
  1514 
       
  1515 void CHuiCanvasWsPainter::WsResetFontL()
       
  1516     {    
       
  1517     iCanvasWsGc->WsResetFontL();
       
  1518     }
       
  1519 
       
  1520 void CHuiCanvasWsPainter::WsDrawArcL()
       
  1521     {
       
  1522     TPoint point1(0,0);
       
  1523     TPoint point2(0,0);
       
  1524     TRect rect(0,0,0,0);
       
  1525     iWsCommandBufferReader->ReadRectL( rect );
       
  1526     iWsCommandBufferReader->ReadPointL( point1 );
       
  1527     iWsCommandBufferReader->ReadPointL( point2 );
       
  1528    	iCanvasWsGc->WsDrawArcL(point1,point2,rect);   
       
  1529     }
       
  1530 
       
  1531 void CHuiCanvasWsPainter::WsDrawPieL()
       
  1532     {
       
  1533     TPoint point1(0,0);
       
  1534     TPoint point2(0,0);
       
  1535     TRect rect(0,0,0,0);
       
  1536     iWsCommandBufferReader->ReadRectL( rect );
       
  1537     iWsCommandBufferReader->ReadPointL( point1 );
       
  1538     iWsCommandBufferReader->ReadPointL( point2 );
       
  1539     iCanvasWsGc->WsDrawPieL(point1,point2,rect);
       
  1540     }
       
  1541 
       
  1542 void CHuiCanvasWsPainter::WsDrawBitmap1L()
       
  1543     {
       
  1544     TRect rect(0,0,0,0);
       
  1545     TInt bitmapHandle = 0;
       
  1546     iWsCommandBufferReader->ReadRectL( rect );
       
  1547     iWsCommandBufferReader->ReadBitmapHandleL( bitmapHandle );
       
  1548     iCanvasWsGc->WsDrawBitmap1L(bitmapHandle,rect);
       
  1549     }
       
  1550 
       
  1551 void CHuiCanvasWsPainter::WsDrawBitmap2L()
       
  1552     {
       
  1553     TRect rect1(0,0,0,0);
       
  1554     TRect rect2(0,0,0,0);
       
  1555     TInt bitmapHandle = 0;
       
  1556     iWsCommandBufferReader->ReadRectL( rect1);
       
  1557     iWsCommandBufferReader->ReadBitmapHandleL( bitmapHandle );
       
  1558     iWsCommandBufferReader->ReadRectL( rect2);
       
  1559     iCanvasWsGc->WsDrawBitmap2L(bitmapHandle,rect1,rect2);
       
  1560     }
       
  1561 
       
  1562 void CHuiCanvasWsPainter::WsDrawBitmap3L()
       
  1563     {
       
  1564     TPoint point(0,0);
       
  1565     TInt bitmapHandle = 0;
       
  1566     iWsCommandBufferReader->ReadPointL( point );
       
  1567     iWsCommandBufferReader->ReadBitmapHandleL( bitmapHandle );   
       
  1568 	iCanvasWsGc->WsDrawBitmap3L(bitmapHandle,point);
       
  1569     }
       
  1570 
       
  1571 void CHuiCanvasWsPainter::WsDrawBitmapMaskedL()
       
  1572     {
       
  1573     iWsCommandBufferReader->ReadL( (TUint8*)&iStructDrawBitmapMasked, sizeof( TStructDrawBitmapMasked ) );
       
  1574     iCanvasWsGc->WsDrawBitmapMaskedL(
       
  1575             iStructDrawBitmapMasked.iBitmapHandle,
       
  1576             iStructDrawBitmapMasked.iMaskHandle,
       
  1577             iStructDrawBitmapMasked.iInvertMask,
       
  1578             iStructDrawBitmapMasked.iRect1,
       
  1579             iStructDrawBitmapMasked.iRect2);
       
  1580     }
       
  1581 
       
  1582 void CHuiCanvasWsPainter::WsDrawRoundRectL()
       
  1583     {
       
  1584     TPoint point(0,0);
       
  1585     TRect rect(0,0,0,0);        
       
  1586     iWsCommandBufferReader->ReadRectL( rect );
       
  1587     iWsCommandBufferReader->ReadPointL( point );    
       
  1588     iCanvasWsGc->WsDrawRoundRectL(point,rect);    
       
  1589     }
       
  1590 
       
  1591 void CHuiCanvasWsPainter::WsDrawPolyLineL()
       
  1592     {
       
  1593     CArrayFix<TPoint>* pointerArray = NULL;    
       
  1594     iWsCommandBufferReader->ReadPointArrayL( pointerArray );    
       
  1595     iCanvasWsGc->WsDrawPolyLineL(pointerArray);    
       
  1596     delete pointerArray;
       
  1597     }
       
  1598 
       
  1599 void CHuiCanvasWsPainter::WsDrawPolyLineNoEndPointL()
       
  1600     {
       
  1601     TPoint* pointerArray = NULL;
       
  1602     TInt count = 0;
       
  1603     iWsCommandBufferReader->ReadPointArrayL( pointerArray, count );
       
  1604     iCanvasWsGc->WsDrawPolyLineNoEndPointL(pointerArray,count);
       
  1605     pointerArray = NULL;
       
  1606     }
       
  1607 
       
  1608 void CHuiCanvasWsPainter::WsDrawPolygonL()
       
  1609     {
       
  1610     CArrayFix<TPoint>* pointerArray;
       
  1611     TInt fillRule = 0;
       
  1612     iWsCommandBufferReader->ReadPointArrayL( pointerArray );
       
  1613     iWsCommandBufferReader->ReadInt8L(); // command
       
  1614     iWsCommandBufferReader->ReadInt32L( fillRule ); 
       
  1615     iCanvasWsGc->WsDrawPolygonL(pointerArray,fillRule);    
       
  1616     delete pointerArray;
       
  1617     }
       
  1618 
       
  1619 void CHuiCanvasWsPainter::WsDrawEllipseL()
       
  1620     {
       
  1621     TRect rect(0,0,0,0);                        
       
  1622     iWsCommandBufferReader->ReadRectL( rect );    
       
  1623     iCanvasWsGc->WsDrawEllipseL(rect);    
       
  1624     }
       
  1625 
       
  1626 void CHuiCanvasWsPainter::WsDrawLineL()
       
  1627     {
       
  1628     TPoint start(0,0);
       
  1629     TPoint end(0,0);
       
  1630     iWsCommandBufferReader->ReadPointL( start );
       
  1631     iWsCommandBufferReader->ReadPointL( end );   
       
  1632     iCanvasWsGc->WsDrawLineL(start,end);    
       
  1633     }
       
  1634 
       
  1635 void CHuiCanvasWsPainter::WsDrawLineToL()
       
  1636     {
       
  1637     TPoint point(0,0);
       
  1638     iWsCommandBufferReader->ReadPointL( point );    
       
  1639     iCanvasWsGc->WsDrawLineToL(point);    
       
  1640     }
       
  1641 
       
  1642 void CHuiCanvasWsPainter::WsDrawLineByL()
       
  1643     {
       
  1644     TPoint point(0,0);
       
  1645     iWsCommandBufferReader->ReadPointL( point );    
       
  1646     iCanvasWsGc->WsDrawLineByL(point);    
       
  1647     }
       
  1648 
       
  1649 void CHuiCanvasWsPainter::WsDrawRectL()
       
  1650     {
       
  1651     TRect rect(0,0,0,0);                        
       
  1652     iWsCommandBufferReader->ReadRectL( rect );
       
  1653 
       
  1654 	// There is a bug that CScreen::DisplayMode() returns non-alpha display mode (TSW error: ??)
       
  1655 	// That is why WServ clears the window with the color that is opaque (0xFF000400) instead of transparent (0x00000000) 
       
  1656 	#ifdef __ALF_SYMBIAN_RWINDOW_CLEARING_BUG_WORKAROUND__
       
  1657 //	RDebug::Print(_L("HV: CHuiCanvasWsPainter::WsDrawRectL(). iTestBrushColor.Internal()=%x, iTestFullDisplayRect=(%d %d %d %d), rect=(%d %d %d %d) "),
       
  1658 //		iTestBrushColor.Internal(), iTestFullDisplayRect.iTl.iX, iTestFullDisplayRect.iTl.iY,iTestFullDisplayRect.iBr.iX, iTestFullDisplayRect.iBr.iY, 
       
  1659 //		rect.iTl.iX, rect.iTl.iY,rect.iBr.iX, rect.iBr.iY);
       
  1660 	if ( (rect ==  iTestFullDisplayRect) &&  	// Is full screen rect?
       
  1661 	     (iTestBrushColor.Internal() == 0xff000400))  	// Last set color is opaque dark green?
       
  1662 		{
       
  1663 	//	RDebug::Print(_L("HV: CHuiCanvasWsPainter::WsDrawRectL(). Change brush color to 0x00000000. "));
       
  1664 		iCanvasWsGc->WsSetBrushColorL(TRgb(0,0,0,0)); // Replace brush color with transparent black          	  	                            	
       
  1665 		}
       
  1666 	#endif
       
  1667     
       
  1668     iCanvasWsGc->WsDrawRectL(rect);    
       
  1669     }
       
  1670 
       
  1671 void CHuiCanvasWsPainter::WsDrawText1L()
       
  1672     {
       
  1673     TPtr textValue(0,0);
       
  1674     TBool success = iWsCommandBufferReader->ReadTextL( textValue, iTextParametersGeneral );
       
  1675     
       
  1676     if (textValue.Length() == 0 || !success )
       
  1677         {
       
  1678         return;   
       
  1679         }
       
  1680     
       
  1681     iCanvasWsGc->WsDrawText1L(textValue,iTextParametersGeneral);    
       
  1682     }
       
  1683     
       
  1684 void CHuiCanvasWsPainter::WsDrawText2L()
       
  1685     {
       
  1686     TPoint point(0,0);
       
  1687     TPtr textValue(0,0);
       
  1688     TBool success = iWsCommandBufferReader->ReadTextL( textValue, iTextParametersGeneral );
       
  1689     iWsCommandBufferReader->ReadPointL( point );
       
  1690     
       
  1691     if (textValue.Length() == 0 ||!success)
       
  1692         {
       
  1693         return;   
       
  1694         }
       
  1695 	
       
  1696     iCanvasWsGc->WsDrawText2L(textValue,point,iTextParametersGeneral);    
       
  1697     }
       
  1698 
       
  1699 void CHuiCanvasWsPainter::WsDrawText3L()
       
  1700     {
       
  1701     TRect rect(0,0,0,0);
       
  1702     TPtr textValue(0,0);
       
  1703     TBool success = iWsCommandBufferReader->ReadTextL( textValue, iTextParametersGeneral );
       
  1704     iWsCommandBufferReader->ReadRectL( rect );
       
  1705 
       
  1706     if (textValue.Length() == 0 || !success )
       
  1707         {
       
  1708         return;   
       
  1709         }
       
  1710 	
       
  1711     iCanvasWsGc->WsDrawText3L(textValue,rect,iTextParametersGeneral);    
       
  1712     }
       
  1713 
       
  1714 void CHuiCanvasWsPainter::WsDrawText4L()
       
  1715     {
       
  1716     TPtr textValue(0,0);
       
  1717     TBool success = iWsCommandBufferReader->ReadTextL( textValue, iTextParametersGeneral );
       
  1718     iWsCommandBufferReader->ReadL( (TUint8*)&iStructDrawTextGeneral, sizeof( TStructDrawTextGeneral ) - sizeof(TInt) );
       
  1719     
       
  1720     if (textValue.Length() == 0 || !success )
       
  1721             {
       
  1722             return;   
       
  1723             }
       
  1724 
       
  1725     iCanvasWsGc->WsDrawText4L(textValue,
       
  1726             iStructDrawTextGeneral.iRect,
       
  1727             iStructDrawTextGeneral.iValue1,  // textBaselineOffset
       
  1728             iStructDrawTextGeneral.iValue2, // textAlign
       
  1729             iStructDrawTextGeneral.iValue3, // textMargin,
       
  1730             iTextParametersGeneral);    
       
  1731     }
       
  1732 
       
  1733 void CHuiCanvasWsPainter::WsDrawText5L()
       
  1734     {
       
  1735     TPtr textValue(0,0);
       
  1736     TBool success = iWsCommandBufferReader->ReadTextL( textValue, iTextParametersGeneral );
       
  1737     iWsCommandBufferReader->ReadL( (TUint8*)&iStructDrawTextGeneral, sizeof( TStructDrawTextGeneral ) );
       
  1738     
       
  1739     if (textValue.Length() == 0 || !success )
       
  1740         {
       
  1741         return;   
       
  1742         }
       
  1743 
       
  1744 	iCanvasWsGc->WsDrawText5L(textValue,
       
  1745 	        iStructDrawTextGeneral.iRect,
       
  1746 	        iStructDrawTextGeneral.iValue1,  // textBaselineOffset
       
  1747 	        iStructDrawTextGeneral.iValue3, // textAlign
       
  1748 	        iStructDrawTextGeneral.iValue4, // textMargin,
       
  1749 	        iStructDrawTextGeneral.iValue2, // textWidth
       
  1750 	        iTextParametersGeneral);    
       
  1751     }
       
  1752 
       
  1753 void CHuiCanvasWsPainter::WsDrawTextVertical1L()
       
  1754     {
       
  1755     TInt textUp = 0;
       
  1756     TPtr textValue(0,0);
       
  1757     TBool success = iWsCommandBufferReader->ReadTextL( textValue, iTextParametersGeneral );
       
  1758     iWsCommandBufferReader->ReadInt32L( textUp );  
       
  1759     
       
  1760     if (textValue.Length() == 0 || !success )
       
  1761         {
       
  1762         return;   
       
  1763         }
       
  1764 
       
  1765 	iCanvasWsGc->WsDrawTextVertical1L(textValue,textUp,iTextParametersGeneral);    
       
  1766     }
       
  1767 
       
  1768 void CHuiCanvasWsPainter::WsDrawTextVertical2L()
       
  1769     {
       
  1770     TPoint point(0,0);
       
  1771     TInt textUp = 0;
       
  1772     TPtr textValue(0,0);
       
  1773     TBool success = iWsCommandBufferReader->ReadTextL( textValue, iTextParametersGeneral );
       
  1774     iWsCommandBufferReader->ReadPointL( point );
       
  1775     iWsCommandBufferReader->ReadInt32L( textUp );  
       
  1776 
       
  1777     if (textValue.Length() == 0 || !success )
       
  1778             {
       
  1779             return;   
       
  1780             }
       
  1781         
       
  1782 	iCanvasWsGc->WsDrawTextVertical2L(textValue,textUp,point,iTextParametersGeneral);    
       
  1783     }
       
  1784 
       
  1785 
       
  1786 void CHuiCanvasWsPainter::WsDrawTextVertical3L()
       
  1787     {
       
  1788     TRect rect(0,0,0,0);
       
  1789     TInt textUp = 0;
       
  1790     TPtr textValue(0,0);
       
  1791     TBool success = iWsCommandBufferReader->ReadTextL( textValue, iTextParametersGeneral);
       
  1792     iWsCommandBufferReader->ReadRectL( rect );
       
  1793     iWsCommandBufferReader->ReadInt32L( textUp ); 
       
  1794 
       
  1795     if (textValue.Length() == 0 || !success )
       
  1796             {
       
  1797             return;   
       
  1798             }
       
  1799     
       
  1800     iCanvasWsGc->WsDrawTextVertical3L(textValue,textUp,rect,iTextParametersGeneral);    
       
  1801     }
       
  1802 
       
  1803 void CHuiCanvasWsPainter::WsDrawTextVertical4L()
       
  1804     {
       
  1805     TRect rect(0,0,0,0);
       
  1806     TInt textBaselineOffset = 0;
       
  1807     TInt textUp = 0;
       
  1808     TInt textAlign = 0;
       
  1809     TInt textMargin = 0;
       
  1810     TPtr textValue(0,0);
       
  1811     
       
  1812     TBool success = iWsCommandBufferReader->ReadTextL( textValue, iTextParametersGeneral );
       
  1813     iWsCommandBufferReader->ReadRectL( rect );
       
  1814     iWsCommandBufferReader->ReadInt32L( textBaselineOffset );
       
  1815     iWsCommandBufferReader->ReadInt32L( textUp );
       
  1816     iWsCommandBufferReader->ReadInt32L( textAlign );
       
  1817     iWsCommandBufferReader->ReadInt32L( textMargin );
       
  1818 
       
  1819     if (textValue.Length() == 0 || !success )
       
  1820             {
       
  1821             return;   
       
  1822             }
       
  1823 
       
  1824     iCanvasWsGc->WsDrawTextVertical4L(textValue,rect,textBaselineOffset,textUp,textAlign,textMargin,iTextParametersGeneral);    
       
  1825     }
       
  1826 
       
  1827 void CHuiCanvasWsPainter::WsDrawTextVertical5L()
       
  1828     {
       
  1829     TRect rect(0,0,0,0);
       
  1830     TInt textBaselineOffset = 0;
       
  1831     TInt textWidth = 0;
       
  1832     TInt textUp = 0;
       
  1833     TInt textAlign = 0;
       
  1834     TInt textMargin = 0;
       
  1835     TPtr textValue(0,0);
       
  1836     
       
  1837     iWsCommandBufferReader->ReadTextL( textValue, iTextParametersGeneral );
       
  1838     iWsCommandBufferReader->ReadRectL( rect );
       
  1839     iWsCommandBufferReader->ReadInt32L( textBaselineOffset );
       
  1840     iWsCommandBufferReader->ReadInt32L( textWidth );
       
  1841     iWsCommandBufferReader->ReadInt32L( textUp );
       
  1842     iWsCommandBufferReader->ReadInt32L( textAlign );
       
  1843     iWsCommandBufferReader->ReadInt32L( textMargin );
       
  1844 
       
  1845     if (textValue.Length() == 0)
       
  1846             {
       
  1847             return;   
       
  1848             }
       
  1849 
       
  1850     iCanvasWsGc->WsDrawTextVertical5L(textValue,rect,textBaselineOffset,textUp,textAlign,textMargin,textWidth,iTextParametersGeneral);    
       
  1851     }
       
  1852 
       
  1853 void CHuiCanvasWsPainter::WsMoveToL()
       
  1854     {
       
  1855     TPoint point(0,0);        
       
  1856     iWsCommandBufferReader->ReadPointL( point );
       
  1857     iCanvasWsGc->WsMoveToL(point);
       
  1858     }
       
  1859 
       
  1860 void CHuiCanvasWsPainter::WsMoveByL()
       
  1861     {
       
  1862     TPoint point(0,0);        
       
  1863     iWsCommandBufferReader->ReadPointL( point );    
       
  1864     iCanvasWsGc->WsMoveByL(point);
       
  1865     }
       
  1866 
       
  1867 void CHuiCanvasWsPainter::WsPlotL()
       
  1868     {
       
  1869     TPoint point(0,0);        
       
  1870     iWsCommandBufferReader->ReadPointL( point );    
       
  1871     iCanvasWsGc->WsPlotL(point);               	  	                        
       
  1872     }
       
  1873 
       
  1874 void CHuiCanvasWsPainter::WsResetL()
       
  1875     {
       
  1876     iCanvasWsGc->WsResetL();               	  	                            
       
  1877 
       
  1878 	#ifdef __ALF_SYMBIAN_RWINDOW_CLEARING_BUG_WORKAROUND__
       
  1879 	iTestBrushColor.SetInternal(0);
       
  1880 	#endif	
       
  1881     }
       
  1882 
       
  1883 void CHuiCanvasWsPainter::WsSetBrushColorL()
       
  1884     {
       
  1885     TRgb color = 0;        
       
  1886     iWsCommandBufferReader->ReadColorL( color );
       
  1887 	iCanvasWsGc->WsSetBrushColorL(color);           	  	                            
       
  1888 
       
  1889 	#ifdef __ALF_SYMBIAN_RWINDOW_CLEARING_BUG_WORKAROUND__
       
  1890 	iTestBrushColor = color;    	  	                            	
       
  1891 	#endif
       
  1892     }
       
  1893 
       
  1894 void CHuiCanvasWsPainter::WsSetBrushOriginL()
       
  1895     {
       
  1896     TPoint point(0,0);        
       
  1897     iWsCommandBufferReader->ReadPointL( point );
       
  1898 	iCanvasWsGc->WsSetBrushOriginL(point);	
       
  1899     }
       
  1900 
       
  1901 void CHuiCanvasWsPainter::WsSetBrushStyleL()
       
  1902     {
       
  1903     TInt style = 0;
       
  1904     iWsCommandBufferReader->ReadInt32L( style );
       
  1905 	iCanvasWsGc->WsSetBrushStyleL(style);        
       
  1906     }
       
  1907 
       
  1908 void CHuiCanvasWsPainter::WsSetClippingRegionL()
       
  1909     {
       
  1910     iTempRegion.Clear();
       
  1911     iWsCommandBufferReader->ReadRegionL( iTempRegion );
       
  1912     iCanvasWsGc->WsSetClippingRegionL(iTempRegion);
       
  1913     }
       
  1914 
       
  1915 void CHuiCanvasWsPainter::WsSetDrawModeL()
       
  1916     {
       
  1917     TInt drawMode = 0;    
       
  1918     iWsCommandBufferReader->ReadInt32L( drawMode );
       
  1919 	iCanvasWsGc->WsSetDrawModeL(drawMode);
       
  1920     }
       
  1921 
       
  1922 void CHuiCanvasWsPainter::WsSetOriginL()
       
  1923     {
       
  1924     TPoint origin(0,0);        
       
  1925     iWsCommandBufferReader->ReadPointL(origin);
       
  1926    	iCanvasWsGc->WsSetOriginL(origin);
       
  1927     }
       
  1928 
       
  1929 void CHuiCanvasWsPainter::WsSetPenColorL()
       
  1930     {
       
  1931     TRgb color = 0;        
       
  1932     iWsCommandBufferReader->ReadColorL( color );
       
  1933 	iCanvasWsGc->WsSetPenColorL(color);    
       
  1934     }
       
  1935 
       
  1936 void CHuiCanvasWsPainter::WsSetPenStyleL()
       
  1937     {
       
  1938     TInt style = 0;    
       
  1939     iWsCommandBufferReader->ReadInt32L( style );
       
  1940 	iCanvasWsGc->WsSetPenStyleL(style);
       
  1941     }
       
  1942 
       
  1943 void CHuiCanvasWsPainter::WsSetPenSizeL()
       
  1944     {
       
  1945     TInt width = 0;    
       
  1946     TInt height = 0;    
       
  1947     iWsCommandBufferReader->ReadInt32L( width ); 
       
  1948     iWsCommandBufferReader->ReadInt32L( height ); 
       
  1949     iCanvasWsGc->WsSetPenSizeL(width,height);
       
  1950     //\todo: Separate pen width and height are not yet supported 	
       
  1951     }
       
  1952 
       
  1953 void CHuiCanvasWsPainter::WsSetTextShadowColorL()
       
  1954     {
       
  1955     TRgb color = 0;        
       
  1956     iWsCommandBufferReader->ReadColorL( color );
       
  1957     iCanvasWsGc->WsSetTextShadowColorL(color);
       
  1958     }
       
  1959 
       
  1960 void CHuiCanvasWsPainter::WsSetCharJustificationL()
       
  1961     {
       
  1962     TInt excessWidth = 0;
       
  1963     TInt numGaps = 0;
       
  1964     iWsCommandBufferReader->ReadInt32L( excessWidth );
       
  1965     iWsCommandBufferReader->ReadInt32L( numGaps ); // NumChars
       
  1966 	iCanvasWsGc->WsSetCharJustificationL(excessWidth,numGaps);
       
  1967     }
       
  1968 
       
  1969 void CHuiCanvasWsPainter::WsSetWordJustificationL()
       
  1970     {
       
  1971     TInt excessWidth = 0;
       
  1972     TInt numGaps = 0;
       
  1973     iWsCommandBufferReader->ReadInt32L( excessWidth );
       
  1974     iWsCommandBufferReader->ReadInt32L( numGaps ); // NumChars
       
  1975 	iCanvasWsGc->WsSetWordJustificationL(excessWidth,numGaps);        
       
  1976     }
       
  1977 
       
  1978 void CHuiCanvasWsPainter::WsSetUnderlineStyleL()
       
  1979     {
       
  1980     TInt value = 0;
       
  1981     iWsCommandBufferReader->ReadInt32L( value );
       
  1982     iCanvasWsGc->WsSetUnderlineStyleL(value);
       
  1983     }
       
  1984 
       
  1985 void CHuiCanvasWsPainter::WsSetStrikethroughStyleL()
       
  1986     {
       
  1987     TInt value = 0;
       
  1988     iWsCommandBufferReader->ReadInt32L( value );
       
  1989     // todo: is this magic 1000 safe offset?
       
  1990     iCanvasWsGc->WsSetUnderlineStyleL(value+1000);
       
  1991     }
       
  1992 
       
  1993 
       
  1994 void CHuiCanvasWsPainter::WsSetBrushPatternL()
       
  1995     {
       
  1996     TInt value = 0;        
       
  1997     iWsCommandBufferReader->ReadInt32L( value );
       
  1998 	iCanvasWsGc->WsSetBrushPatternL(value);
       
  1999     }
       
  2000 
       
  2001 void CHuiCanvasWsPainter::WsSetFontL()
       
  2002     {
       
  2003     TInt fontId = 0;
       
  2004     iWsCommandBufferReader->ReadInt32L( fontId );// Font type Uid
       
  2005     iCanvasWsGc->WsSetFontL(fontId);    
       
  2006     }
       
  2007 
       
  2008 void CHuiCanvasWsPainter::WsContentTagL()
       
  2009     {
       
  2010     TInt tag;
       
  2011     iWsCommandBufferReader->ReadInt32L( tag );
       
  2012     }
       
  2013 
       
  2014 void CHuiCanvasWsPainter::WsCopyRectL()
       
  2015     {
       
  2016     TPoint point(0,0);
       
  2017     TRect rect(0,0,0,0);
       
  2018     iWsCommandBufferReader->ReadPointL( point );
       
  2019     iWsCommandBufferReader->ReadRectL( rect );
       
  2020 	iCanvasWsGc->WsCopyRectL(point,rect);
       
  2021     }
       
  2022 
       
  2023 void CHuiCanvasWsPainter::WsUpdateJustificationL()
       
  2024     {
       
  2025     TPtr textValue(0,0);
       
  2026     iWsCommandBufferReader->ReadTextL( textValue, iTextParametersGeneral );	
       
  2027 	iCanvasWsGc->WsUpdateJustificationL(textValue);
       
  2028     }
       
  2029 
       
  2030 void CHuiCanvasWsPainter::WsUpdateJustificationVerticalL()
       
  2031     {
       
  2032     TPtr textValue(0,0);
       
  2033     TInt value = 0;
       
  2034 
       
  2035     iWsCommandBufferReader->ReadTextL( textValue, iTextParametersGeneral );
       
  2036     iWsCommandBufferReader->ReadInt32L( value );
       
  2037 	iCanvasWsGc->WsUpdateJustificationVerticalL(value,textValue);
       
  2038    }
       
  2039 
       
  2040 void CHuiCanvasWsPainter::WsSetFontNoDuplicateL()
       
  2041     {
       
  2042     TInt tempFont = 0;
       
  2043     iWsCommandBufferReader->ReadInt32L( tempFont );
       
  2044 	iCanvasWsGc->WsSetFontNoDuplicateL(tempFont);	    
       
  2045     }
       
  2046 
       
  2047 
       
  2048 void CHuiCanvasWsPainter::WsCopySettingsL()
       
  2049     {
       
  2050     iCanvasWsGc->WsCopySettingsL();	
       
  2051     }
       
  2052 
       
  2053 void CHuiCanvasWsPainter::WsSetClippingRectL()
       
  2054     {
       
  2055     TRect rect(0,0,0,0);
       
  2056     iWsCommandBufferReader->ReadRectL( rect );
       
  2057 	iCanvasWsGc->WsSetClippingRectL(rect);	                        
       
  2058     }
       
  2059 
       
  2060 void CHuiCanvasWsPainter::WsCancelClippingRectL()
       
  2061     {
       
  2062     iCanvasWsGc->WsCancelClippingRectL();
       
  2063     }
       
  2064 
       
  2065 void CHuiCanvasWsPainter::WsSetFadedL()
       
  2066     {
       
  2067     TInt faded = 0;
       
  2068     iWsCommandBufferReader->ReadInt32L( faded );
       
  2069 	iCanvasWsGc->WsSetFadedL(faded);	                        
       
  2070     }
       
  2071 
       
  2072 void CHuiCanvasWsPainter::WsSetFadingParametersL()
       
  2073     {
       
  2074     TInt blackMap = 0;        
       
  2075     TInt whiteMap = 0;        
       
  2076     iWsCommandBufferReader->ReadInt32L( blackMap );
       
  2077     iWsCommandBufferReader->ReadInt32L( whiteMap );
       
  2078 	iCanvasWsGc->WsSetFadingParametersL(blackMap,whiteMap);	                        
       
  2079     }
       
  2080 
       
  2081 void CHuiCanvasWsPainter::WsFadeAreaL()
       
  2082     {
       
  2083     iTempRegion.Clear();
       
  2084     iWsCommandBufferReader->ReadRegionL( iTempRegion );    
       
  2085 	iCanvasWsGc->WsFadeAreaL(iTempRegion);	                        
       
  2086     }
       
  2087 
       
  2088 void CHuiCanvasWsPainter::WsMapColorsL()
       
  2089     {
       
  2090     iCanvasWsGc->WsMapColorsL();	                        
       
  2091     }
       
  2092 
       
  2093 void CHuiCanvasWsPainter::WsSetUserDisplayModeL()
       
  2094     {
       
  2095     TInt mode = 0;
       
  2096     iWsCommandBufferReader->ReadInt32L( mode );
       
  2097 	iCanvasWsGc->WsSetUserDisplayModeL(mode);	                        
       
  2098         
       
  2099     }
       
  2100 
       
  2101 void CHuiCanvasWsPainter::WsUseFontL()
       
  2102     {
       
  2103 	TInt tempFont = 0;
       
  2104     iWsCommandBufferReader->ReadInt32L( tempFont );
       
  2105     iCanvasWsGc->WsUseFontL(tempFont);	                                
       
  2106     }       
       
  2107 
       
  2108 void CHuiCanvasWsPainter::WsSetUpdateRegionL(TInt aIndex)
       
  2109     {
       
  2110     iTempRegion.Clear();                
       
  2111     iWsCommandBufferReader->ReadRegionL( iTempRegion );
       
  2112     if (aIndex==-1) return; //TP
       
  2113     // Update region is modified when new buffers are added after this buffer, 
       
  2114     // so store the region only at first read. 
       
  2115     if (iCommandBuffers[aIndex]->iChanged && iCommandBuffers[aIndex]->iUpdateRegion.Count() == 0)
       
  2116         {
       
  2117         // Check first that the coordiates are not insane (sometimes thay are)
       
  2118         TInt count = iTempRegion.Count();                    
       
  2119         TRect displayRect = iCanvasVisual->DisplayRect();
       
  2120         for (TInt i=count-1; i>=0; i--)
       
  2121             {
       
  2122             TRect rect = iTempRegion[i];
       
  2123             TRect screen = iCanvasVisual->Display()->VisibleArea();
       
  2124             if (rect.Intersects(screen) || rect == screen)
       
  2125                 {
       
  2126                 // - Sometimes updateregion is outiside window (WSERV...why?!) 
       
  2127                 //   We clip it here to avoid ui probs.
       
  2128 				// - Lets remove this for now, this seems to break scrollbars again
       
  2129 				//   when window parent-child relations work..
       
  2130 				// - Hmm, should we add this anyway because now the idle softkeys are lost again in landscape mode ?
       
  2131 				// - Added again after WSERV fix in the window parent-child relations
       
  2132 #ifndef HUI_DISABLE_CANVAS_VISUAL_CLIPPING
       
  2133                 rect.Intersection(displayRect); 
       
  2134 #endif                
       
  2135                 iCommandBuffers[aIndex]->iUpdateRegion.AddRect(rect);    
       
  2136                 iCommandBuffers[aIndex]->iOriginalUpdateRegion.AddRect(rect);    
       
  2137                 }
       
  2138             else
       
  2139                 {
       
  2140 #ifdef _DEBUG
       
  2141                 RDebug::Print(_L("CHuiCanvasWsPainter::WsSetUpdateRegionL: Incorrect update region removed from buffer, this should not happen !"));
       
  2142 #endif
       
  2143                 }
       
  2144             }                
       
  2145         
       
  2146         // Combine areas that are next to each others
       
  2147         iCommandBuffers[aIndex]->iUpdateRegion.Tidy();                    
       
  2148         iCommandBuffers[aIndex]->iOriginalUpdateRegion.Tidy();                    
       
  2149 
       
  2150         // Subtract this buffers update area from previous buffers update areas to avoid overdraw
       
  2151 
       
  2152  // TODO: Subtraction is for now commented out because it seems to cause UI problems, especially
       
  2153  //       with lists with scrollbar. Try e.g. opening image from filebrowser, then press back and
       
  2154  //       scrollbar area is often corrupted. This happens (probaply) because first command buffer contains
       
  2155  //       real background drawing under scrollbar, but partial command buffers do not contain it although 
       
  2156  //       their update region extends below scrollbar.
       
  2157  //       
       
  2158  //       This issue should be fixed because leaving subration undone causes performance to be worse.
       
  2159  //       
       
  2160         
       
  2161  /*
       
  2162         if (aIndex > 0)
       
  2163             {
       
  2164             for (TInt i=aIndex; i>0; i--)
       
  2165                 {
       
  2166                 TInt previous = aIndex - 1;
       
  2167                 iCommandBuffers[previous]->iUpdateRegion.SubRegion(iCommandBuffers[aIndex]->iUpdateRegion);
       
  2168                 iCommandBuffers[previous]->iUpdateRegion.Tidy();                            
       
  2169                 }            
       
  2170             }
       
  2171 */            
       
  2172         }
       
  2173     }
       
  2174 
       
  2175 void CHuiCanvasWsPainter::WsSetShapeRegionL( TInt aIndex )
       
  2176     {
       
  2177     iTempRegion.Clear();                
       
  2178     iWsCommandBufferReader->ReadRegionL( iTempRegion );
       
  2179     
       
  2180 	
       
  2181     // If there is a shape region, get it only from the newest buffer. 
       
  2182     // This is the case when the buffer has just been added to the canvas visual.
       
  2183     
       
  2184     if(aIndex == iCommandBuffers.Count() - 1)
       
  2185         {
       
  2186         // Note: The "set shape" command looks to be used only if it really is different from
       
  2187         // the window rect. So there is no need to check if the shape region is relevant. 
       
  2188         iShapeRegion.Copy(iTempRegion);
       
  2189 
       
  2190         // note: iUpdateRegion will be updated later, set flags to indicate pending
       
  2191         iShapeRegionClearingPending = ETrue;
       
  2192         iShapeRegionClippingPending = ETrue;        
       
  2193        }
       
  2194     
       
  2195 	
       
  2196     #ifdef _DEBUG
       
  2197     if (iShapeRegion.Count() == 0 && iTempRegion.Count() > 0)
       
  2198         {
       
  2199         HUI_DEBUG(_L("CHuiCanvasWsPainter::WsSetShapeRegionL. Error: iShapeRegion not set by any command buffer! However, there exists at least one command buffer that has shape region command."));
       
  2200          }
       
  2201     #endif
       
  2202     }
       
  2203 
       
  2204 void CHuiCanvasWsPainter::DoDigestPaddingL()
       
  2205     {
       
  2206     TUint8 padding = iWsCommandBufferReader->ReadInt8L();
       
  2207     while( padding-- )
       
  2208         {
       
  2209 #ifdef _DEBUG
       
  2210         if ( iWsCommandBufferReader->ReadInt8L() != 0 )
       
  2211             {
       
  2212             RDebug::Print(_L("CHuiCanvasWsPainter::DigestPaddingL - Padding error"));
       
  2213             USER_INVARIANT();
       
  2214             }
       
  2215 #else
       
  2216         iWsCommandBufferReader->ReadInt8L();
       
  2217 #endif        
       
  2218         }
       
  2219     }
       
  2220 
       
  2221 void CHuiCanvasWsPainter::DestroyBuffer(TInt aIndex)
       
  2222     {
       
  2223     CHuiCanvasCommandBuffer* buffer = iCommandBuffers[aIndex];
       
  2224 
       
  2225     TTime now;
       
  2226     now.UniversalTime();    
       
  2227     TInt lifetimeInMs =  now.MicroSecondsFrom( buffer->iCreationTime ).Int64()/1000;                               
       
  2228     if (lifetimeInMs > 0 && lifetimeInMs < KHuiCanvasDisableRenderBufferHandleInterval)
       
  2229         {
       
  2230         /* Check and disable render buffer if needed */
       
  2231         if (iCommandBuffers.Count() == 2)
       
  2232             {
       
  2233             EnableRenderBufferIfNeeded(EFalse);
       
  2234             }
       
  2235         }
       
  2236     
       
  2237     iCommandBuffers.Remove(aIndex);
       
  2238     delete buffer;
       
  2239     }
       
  2240 
       
  2241 
       
  2242 TBool CHuiCanvasWsPainter::RemoveRedundantBuffers()
       
  2243     {
       
  2244     TBool didRemoveBuffers = EFalse;
       
  2245     TInt originalBufferCount = iCommandBuffers.Count();
       
  2246     
       
  2247     RemoveBuffersWithoutRealDrawing();
       
  2248     RemoveBuffersWithOldDisplayRect();
       
  2249     RemoveBuffersWithEmptyUpdateRegion();
       
  2250     RemoveBuffersWithOverlappingUpdateRegion();         
       
  2251     
       
  2252     didRemoveBuffers = (originalBufferCount != iCommandBuffers.Count());    
       
  2253     return didRemoveBuffers;
       
  2254     }
       
  2255 
       
  2256 void CHuiCanvasWsPainter::RemoveBuffersWithoutRealDrawing()
       
  2257     {
       
  2258     TInt bufferCount = iCommandBuffers.Count();
       
  2259     for (TInt cb = bufferCount - 1; cb >= 0; cb--)
       
  2260         {
       
  2261         CHuiCanvasCommandBuffer* buffer = iCommandBuffers[cb];
       
  2262         TInt flags = buffer->iStatusFlags;
       
  2263         if ((flags & EHuiCanvasBufferStatusScanned) && !(flags & EHuiCanvasBufferContainsDrawing))
       
  2264             {
       
  2265             DestroyBuffer(cb);
       
  2266             }
       
  2267         }        
       
  2268     }
       
  2269 
       
  2270 
       
  2271 void CHuiCanvasWsPainter::RemoveBuffersWithOldDisplayRect() 
       
  2272     {
       
  2273     TInt bufferCount = iCommandBuffers.Count();
       
  2274     for (TInt cb = bufferCount - 1; cb >= 0; cb--)
       
  2275         {
       
  2276         CHuiCanvasCommandBuffer* buffer = iCommandBuffers[cb];
       
  2277         if (buffer->iOriginalDisplayRect.Round() != iCanvasVisual->DisplayRect().Round())
       
  2278             {
       
  2279             DestroyBuffer(cb);
       
  2280             }
       
  2281         }    
       
  2282     }
       
  2283 
       
  2284 void CHuiCanvasWsPainter::RemoveBuffersWithEmptyUpdateRegion() 
       
  2285     {
       
  2286     TInt bufferCount = iCommandBuffers.Count();
       
  2287     for (TInt cb = bufferCount - 1; cb >= 0; cb--)
       
  2288         {
       
  2289         CHuiCanvasCommandBuffer* buffer = iCommandBuffers[cb];
       
  2290         if (buffer->iOriginalUpdateRegion.Count() == 0)
       
  2291             {        
       
  2292             DestroyBuffer(cb);
       
  2293             }
       
  2294         }    
       
  2295     }
       
  2296 
       
  2297 void CHuiCanvasWsPainter::RemoveBuffersWithOverlappingUpdateRegion() 
       
  2298     {
       
  2299     // Check possibly overlapping update regions
       
  2300     TBool arraysChanged = ETrue;  
       
  2301     while (arraysChanged)
       
  2302         {
       
  2303         arraysChanged = EFalse;
       
  2304         iTempRegion.Clear();
       
  2305         
       
  2306         // Loop all buffers                
       
  2307         TInt bufferCount = iCommandBuffers.Count();        
       
  2308         for (TInt cb = bufferCount - 1; cb >= 0; cb--)
       
  2309             {            
       
  2310             if (arraysChanged)
       
  2311                 {
       
  2312                 break;    
       
  2313                 }
       
  2314             
       
  2315             CHuiCanvasCommandBuffer* cmdbuffer = iCommandBuffers[cb];
       
  2316             for (TInt j=0; j < cmdbuffer->iOriginalUpdateRegion.Count();j++)
       
  2317                 {
       
  2318                 iTempRegion.AddRect(cmdbuffer->iOriginalUpdateRegion[j]);        
       
  2319                 }
       
  2320                        
       
  2321             // Check older buffers for overlapping regions against current buffer
       
  2322             if (cb > 0)
       
  2323                 {                   
       
  2324                 for (TInt i = cb - 1; i >= 0; i--)
       
  2325                     {
       
  2326                     if (arraysChanged)
       
  2327                         {
       
  2328                         break;    
       
  2329                         }
       
  2330 
       
  2331                     CHuiCanvasCommandBuffer* previousCommands = iCommandBuffers[i];            
       
  2332                     // Keep count how many subregions of the prevous command are contained inside current command buffer region
       
  2333                     TInt coveredRegionCount = 0;                    
       
  2334                     for (TInt k=0; k < previousCommands->iOriginalUpdateRegion.Count();k++)
       
  2335                         {
       
  2336                         iTempCurrentSubRegion.Clear();
       
  2337                         iTempIntersectingRegion.Clear();                                               
       
  2338                         iTempCurrentSubRegion.AddRect(previousCommands->iOriginalUpdateRegion[k]);                        
       
  2339                         iTempIntersectingRegion.Intersection(iTempRegion, iTempCurrentSubRegion);
       
  2340                         iTempIntersectingRegion.Tidy();
       
  2341                         
       
  2342                         if (iTempIntersectingRegion.Count() == 1)
       
  2343                             {
       
  2344                             if (iTempIntersectingRegion[0] == previousCommands->iOriginalUpdateRegion[k])
       
  2345                                 {
       
  2346                                 coveredRegionCount++;
       
  2347                                 // If all regions were overlapping agains current buffer, we can delete this.
       
  2348                                 if (coveredRegionCount == previousCommands->iOriginalUpdateRegion.Count())
       
  2349                                     {
       
  2350                                     DestroyBuffer(i);
       
  2351                                     arraysChanged = ETrue;
       
  2352                                     break;                                                                            
       
  2353                                     }
       
  2354                                 }
       
  2355                             else
       
  2356                                 {
       
  2357                                 // There is no reason to continue with this one if even one of its subregions
       
  2358                                 // is  outside overlapping region.
       
  2359                                 break;                                    
       
  2360                                 }
       
  2361                             }                        
       
  2362                         }
       
  2363                     }
       
  2364                 }
       
  2365             }
       
  2366         }
       
  2367     }
       
  2368 
       
  2369 CHuiCanvasGc& CHuiCanvasWsPainter::CanvasGc() const
       
  2370 	{
       
  2371 	return iCanvasWsGc->CanvasGc();
       
  2372 	}
       
  2373 
       
  2374 TInt CHuiCanvasWsPainter::PaintedAreaCount() const
       
  2375     {
       
  2376     TInt paintedAreaCount = 0;
       
  2377     TInt bufferCount = iCommandBuffers.Count();
       
  2378     for (TInt cb = 0; cb < bufferCount; cb++)
       
  2379         {        
       
  2380         paintedAreaCount += iCommandBuffers[cb]->iUpdateRegion.Count();
       
  2381         }
       
  2382     return paintedAreaCount;
       
  2383     }
       
  2384     
       
  2385 THuiCanvasPaintedArea CHuiCanvasWsPainter::PaintedArea(TInt aIndex)
       
  2386     {
       
  2387     THuiCanvasPaintedArea area;
       
  2388     area.iPaintType = EHuiCanvasPaintTypeOpaque;
       
  2389     area.iFlags = 0;    
       
  2390     
       
  2391     TInt firstIndexInCurrentBuffer = 0;
       
  2392     TInt lastIndexInCurrentBuffer = 0;
       
  2393     TInt indexCounter = 0;
       
  2394     
       
  2395     TInt bufferCount = iCommandBuffers.Count();
       
  2396     for (TInt cb = 0; cb < bufferCount; cb++)
       
  2397         {
       
  2398         TInt updateRegionCount = iCommandBuffers[cb]->iUpdateRegion.Count();
       
  2399         if (updateRegionCount)
       
  2400             {        
       
  2401             firstIndexInCurrentBuffer = indexCounter;
       
  2402             lastIndexInCurrentBuffer = firstIndexInCurrentBuffer + updateRegionCount - 1;
       
  2403             
       
  2404             if ((firstIndexInCurrentBuffer <= aIndex) && (aIndex <= lastIndexInCurrentBuffer))
       
  2405                 {
       
  2406                 TInt localIndex = aIndex - firstIndexInCurrentBuffer;
       
  2407                 area.iPaintedRect = iCommandBuffers[cb]->iUpdateRegion[localIndex];
       
  2408                 break;
       
  2409                 }        
       
  2410             indexCounter += updateRegionCount;        
       
  2411             }
       
  2412        }   
       
  2413     return area;
       
  2414     }
       
  2415 
       
  2416 TInt CHuiCanvasWsPainter::SetCapturingBufferL(CFbsBitmap* aTarget)
       
  2417     {
       
  2418     TInt result = iCanvasWsGc->SetCapturingBufferL(aTarget);
       
  2419         
       
  2420     if ( !aTarget )
       
  2421         {
       
  2422         // We may have switched to another GC - so to ensure that 
       
  2423         // all are released, we will send this request to all.
       
  2424         CHuiCanvasWsGc* gcs[] = 
       
  2425             { 
       
  2426             iCanvasWsBitGc, 
       
  2427             iCanvasWsSwGc, 
       
  2428             iCanvasWsHwGc 
       
  2429             };
       
  2430         TInt count = sizeof(gcs) / sizeof(CHuiCanvasWsGc*);
       
  2431         for ( TInt i = count - 1; i >= 0; --i )
       
  2432             {
       
  2433             if ( gcs[i] && gcs[i] != iCanvasWsGc )
       
  2434                 {
       
  2435                 gcs[i]->SetCapturingBufferL(NULL);
       
  2436                 }
       
  2437             }
       
  2438         }
       
  2439 
       
  2440     return result;
       
  2441     }
       
  2442 
       
  2443 TRect CHuiCanvasWsPainter::DirtyRect() const
       
  2444     {
       
  2445     iTempRegion.Clear();                
       
  2446     TInt bufferCount = iCommandBuffers.Count();
       
  2447     for (TInt cb = 0; cb < bufferCount; cb++)
       
  2448         {        
       
  2449         const CHuiCanvasCommandBuffer& cmdbuffer = *iCommandBuffers[cb];
       
  2450         
       
  2451         // Report only changed buffers. This should be ok as long as
       
  2452         // this method is only used when scanning visual tree and
       
  2453         // thus visual (and buffer) changed flags are in correct states.
       
  2454         if (cmdbuffer.iChanged)
       
  2455             {
       
  2456             iTempRegion.Union(cmdbuffer.iUpdateRegion);
       
  2457             }
       
  2458         }
       
  2459     return iTempRegion.BoundingRect();
       
  2460     }
       
  2461 
       
  2462 TBool CHuiCanvasWsPainter::IsBufferCompletelyOutisideClippingRegion(const CHuiCanvasCommandBuffer& aCommandbuffer) const
       
  2463     {
       
  2464     CHuiGc* gc = iCanvasWsGc->CanvasGc().Gc();
       
  2465     if (gc && gc->ClipRegion().Count())
       
  2466         {
       
  2467         // This is a bit tricky part, gc clipregion is in transformed coordinates but our update region is not.
       
  2468         // So we must transform our update region before we can compare it to gc clipping region and
       
  2469         // know if it falls comletely outside it or not.        
       
  2470         iTempRegion.Clear();
       
  2471         for (TInt i=0; i<aCommandbuffer.iUpdateRegion.Count();i++)
       
  2472             {
       
  2473             THuiRealRect transformed = aCommandbuffer.iUpdateRegion[i];
       
  2474             gc->TransformDirtyRect(transformed);
       
  2475             iTempRegion.AddRect(transformed.Round());            
       
  2476             }
       
  2477         
       
  2478         CHuiCanvasGc::TClipRectVisibility visibility = iCanvasWsGc->CanvasGc().IsClipped(iTempRegion, gc->ClipRegion());
       
  2479         
       
  2480         if (visibility == CHuiCanvasGc::EFullyOutside)
       
  2481             {
       
  2482             return ETrue;
       
  2483             }
       
  2484         }
       
  2485 
       
  2486     return EFalse;
       
  2487     }
       
  2488 
       
  2489 TInt CHuiCanvasWsPainter::EnableRenderBuffer(TBool aEnable)
       
  2490     {
       
  2491     if (aEnable != iCanvasWsGc->IsRenderBufferEnabled())
       
  2492         {
       
  2493         if (aEnable)
       
  2494             {
       
  2495             // Must redraw all buffers to render buffer at next frame
       
  2496             RenewAllBuffers();         
       
  2497             }        
       
  2498         return iCanvasWsGc->EnableRenderbuffer(aEnable);
       
  2499         }
       
  2500     else
       
  2501         {
       
  2502         return KErrNone;
       
  2503         }    
       
  2504     }
       
  2505 
       
  2506 void CHuiCanvasWsPainter::EnableRenderBufferIfNeeded(TBool aEnable)
       
  2507     {
       
  2508     if (!KHuiCanvasAutomaticRenderBufferUsage || !CHuiStatic::Renderer().Allows(EHuiRenderPluginAllowVisualPBufferSurfaces))
       
  2509         {
       
  2510         return;
       
  2511         }
       
  2512     
       
  2513     if (aEnable)
       
  2514         {
       
  2515         if (iAutomaticRenderBufferUsage && !iCanvasWsGc->IsRenderBufferEnabled() && HasOldCommandBuffers(KHuiCanvasEnableRenderBufferHandleInterval))
       
  2516             {
       
  2517             RDebug::Print(_L("CHuiCanvasWsPainter::EnableRenderBufferIfNeeded: Enabling renderbuffer"));
       
  2518             EnableRenderBuffer(ETrue);
       
  2519             iAutomaticRenderBufferUsage = ETrue;
       
  2520             }        
       
  2521         }
       
  2522     else
       
  2523         {
       
  2524         if (iCanvasWsGc->IsRenderBufferEnabled())
       
  2525             {
       
  2526             RDebug::Print(_L("CHuiCanvasWsPainter::EnableRenderBufferIfNeeded: Disabling renderbuffer"));
       
  2527             EnableRenderBuffer(EFalse);
       
  2528             iAutomaticRenderBufferUsage = ETrue;
       
  2529             }
       
  2530         }    
       
  2531     }
       
  2532 
       
  2533 void CHuiCanvasWsPainter::SelectGcL()
       
  2534     {
       
  2535     TBool hasUnsupportedCommands = EFalse;
       
  2536     TInt bufferCount = iCommandBuffers.Count();
       
  2537     for (TInt cb = 0; cb < bufferCount; cb++)
       
  2538         {        
       
  2539         const CHuiCanvasCommandBuffer& cmdbuffer = *iCommandBuffers[cb];
       
  2540         if (cmdbuffer.iContainsUnsupportedCommands)
       
  2541             {
       
  2542             hasUnsupportedCommands = ETrue;
       
  2543             break;
       
  2544             }
       
  2545         }
       
  2546         
       
  2547     THuiMemoryLevel memoryLevel;
       
  2548     if ( iCanvasVisual ) // in constructor, iCanvasVisual == NULL
       
  2549         {
       
  2550         memoryLevel = iCanvasVisual->Env().MemoryLevel();
       
  2551         }
       
  2552     else
       
  2553         {
       
  2554         memoryLevel = CHuiStatic::Env().MemoryLevel();
       
  2555         }
       
  2556 
       
  2557     CHuiCanvasWsGc* oldGc = iCanvasWsGc;
       
  2558 
       
  2559     if (memoryLevel <= EHuiMemoryLevelLowest)
       
  2560         {
       
  2561         if (!iCanvasWsGc || iCanvasWsGc != iCanvasWsBitGc)
       
  2562             {
       
  2563             // Fallback to the BIT GDI mode
       
  2564             if (!iCanvasWsBitGc)
       
  2565                 {
       
  2566                 iCanvasWsBitGc = CHuiCanvasWsBitGc::NewL();
       
  2567                 }        
       
  2568             iCanvasWsGc = iCanvasWsBitGc;
       
  2569             // Must redraw all buffers to render buffer at next frame
       
  2570             RenewAllBuffers();             
       
  2571             }
       
  2572         }
       
  2573     else if (hasUnsupportedCommands && (!iCanvasWsGc || 
       
  2574              iCanvasWsGc != iCanvasWsSwGc))
       
  2575         {
       
  2576         // Fallback to the SW mode
       
  2577         if (!iCanvasWsSwGc)
       
  2578             {
       
  2579             iCanvasWsSwGc = CHuiCanvasWsSwGc::NewL();     
       
  2580             }        
       
  2581         iCanvasWsGc = iCanvasWsSwGc;
       
  2582         // Must redraw all buffers to render buffer at next frame
       
  2583         RenewAllBuffers();         
       
  2584         }
       
  2585     else if (!hasUnsupportedCommands && (!iCanvasWsGc || 
       
  2586              iCanvasWsGc != iCanvasWsHwGc))
       
  2587         {
       
  2588         // Return to the HW accelerated mode
       
  2589         if (!iCanvasWsHwGc)
       
  2590             {
       
  2591             iCanvasWsHwGc = CHuiCanvasWsHwGc::NewL();     
       
  2592             }                
       
  2593         iCanvasWsGc = iCanvasWsHwGc;
       
  2594         // Must redraw all buffers to render buffer at next frame
       
  2595         RenewAllBuffers();         
       
  2596         }
       
  2597     else
       
  2598         {
       
  2599         // We are good
       
  2600         }        
       
  2601         
       
  2602     // Clear caches of non-used GCs
       
  2603     if ( oldGc && oldGc != iCanvasWsGc )
       
  2604         {
       
  2605         oldGc->ClearCache();
       
  2606         }
       
  2607 
       
  2608     #ifdef HUI_DEBUG_TRACK_DRAWING
       
  2609     CHuiCanvasWsGc* realGc = iCanvasWsGc;
       
  2610     iCanvasWsGc = CHuiCanvasDebugWsGc::NewL( realGc, *iCommandDebugger );
       
  2611     #endif
       
  2612     }
       
  2613 
       
  2614 void CHuiCanvasWsPainter::RenewAllBuffers()
       
  2615     {
       
  2616     ClearAllBufferStatusFlags(EHuiCanvasBufferStatusAll);
       
  2617     SetAllBufferStatusFlags(EHuiCanvasBufferStatusNew);                
       
  2618     
       
  2619     if (iCanvasVisual)
       
  2620         {
       
  2621         iCanvasVisual->SetChanged();
       
  2622         }    
       
  2623     }
       
  2624 	
       
  2625 void CHuiCanvasWsPainter::UpdateBufferUpdateRegions(TPoint aPos)
       
  2626 	{
       
  2627 	// iUpdateRegion is in screen coordinates. If visual moves position, iUpdateRegion 
       
  2628 	// should be updated as well. Otherwise visual will encounter clipping.
       
  2629     for (TInt cb = 0; cb < iCommandBuffers.Count(); cb++)
       
  2630         {
       
  2631 		if (iCommandBuffers[cb]->iPositionForUpdateRegion != aPos && !iCommandBuffers[cb]->iUpdateRegion.IsEmpty() )
       
  2632 			{
       
  2633 			TPoint deltaPos = aPos - iCommandBuffers[cb]->iPositionForUpdateRegion;
       
  2634 			iCommandBuffers[cb]->iUpdateRegion.Offset(deltaPos);
       
  2635 			iCommandBuffers[cb]->iPositionForUpdateRegion = aPos;
       
  2636 			iCommandBuffers[cb]->ClearStatusFlags(EHuiCanvasBufferStatusAll);
       
  2637 			iCommandBuffers[cb]->SetStatusFlags(EHuiCanvasBufferStatusNew);
       
  2638 			}
       
  2639         }
       
  2640 	}
       
  2641 
       
  2642 void CHuiCanvasWsPainter::SetMemoryLevel(THuiMemoryLevel /*aLevel*/)
       
  2643     {
       
  2644     TRAP_IGNORE(SelectGcL());
       
  2645     }
       
  2646