uiacceltk/hitchcock/coretoolkit/src/huicanvaswshwgc.cpp
changeset 0 15bf7259bb7c
child 3 d8a3531bc6b8
child 13 8f67d927ea57
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     1 /*
       
     2 * Copyright (c) 2008-2009 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 CHuiCanvasWsHwGc.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "huicanvaswshwgc.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 "HuiRenderSurface.h"
       
    35 #include "huicanvastexturecache.h"
       
    36 #include "huicanvasbackground.h"
       
    37 #include <graphics/wsgraphicscontext.h>
       
    38 #include <e32cmn.h>
       
    39 #include <AknLayoutFont.h>
       
    40 #include <graphics/lookuptable.h>
       
    41 
       
    42 //#define HUI_DEBUG_PRINT_PERFORMANCE_INTERVAL
       
    43 
       
    44 CHuiCanvasWsHwGc* CHuiCanvasWsHwGc::NewL()
       
    45 	{
       
    46 	CHuiCanvasWsHwGc* self    = new ( ELeave ) CHuiCanvasWsHwGc;
       
    47     CleanupStack::PushL( self );
       
    48     self->ConstructL();
       
    49     CleanupStack::Pop();
       
    50 
       
    51     return self;
       
    52     }
       
    53 
       
    54 void CHuiCanvasWsHwGc::AdjustCoordinates(TPoint& aPoint, TBool aUseWsOrigin )
       
    55     {
       
    56     aPoint +=  iPosDelta;
       
    57     if ( aUseWsOrigin ) 
       
    58         {
       
    59         aPoint += iWsOrigin;
       
    60         }
       
    61     }
       
    62 
       
    63 void CHuiCanvasWsHwGc::AdjustCoordinates(TRect& aRect, TBool aUseWsOrigin )
       
    64     {
       
    65     aRect.Move( iPosDelta );
       
    66     if ( aUseWsOrigin )
       
    67         {
       
    68         aRect.Move( iWsOrigin );
       
    69         }
       
    70     }
       
    71 
       
    72 void CHuiCanvasWsHwGc::DrawTextBrush( THuiRealRect& aRect )
       
    73     {
       
    74     if( iWsBrushStyle == CGraphicsContext::ESolidBrush )
       
    75         {
       
    76         TRgb oldPenColor = iCanvasGc->PenColor();
       
    77         TReal32 oldOpacity = iCanvasGc->Opacity();
       
    78         THuiFillMode oldFillMode = iCanvasGc->PolygonDrawMode();
       
    79         
       
    80         iCanvasGc->SetPenColor(iWsBrushColor);
       
    81         iCanvasGc->SetOpacity(TReal32(iWsBrushColor.Alpha() / 255.f));   
       
    82         iCanvasGc->SetPolygonDrawMode(EHuiFillEvenOdd);
       
    83         
       
    84         RArray<THuiRealRect> rects;
       
    85         rects.Append(aRect);
       
    86         iCanvasGc->DrawRects(rects);
       
    87         rects.Close();
       
    88         
       
    89         iCanvasGc->SetPolygonDrawMode(oldFillMode);
       
    90         iCanvasGc->SetOpacity(oldOpacity);
       
    91         iCanvasGc->SetPenColor(oldPenColor);
       
    92         }
       
    93     }
       
    94 
       
    95 CHuiCanvasWsHwGc::CHuiCanvasWsHwGc()
       
    96     {
       
    97     }
       
    98 
       
    99 void CHuiCanvasWsHwGc::ConstructL()
       
   100 	{
       
   101     iCanvasGc = CHuiStatic::Renderer().CreateCanvasGcL();
       
   102 	
       
   103 	// Set delayed clipping mode, this is supposed to reduce unnecessary
       
   104 	// clipping which may cause bad performance on hw renderers 
       
   105 	iCanvasGc->SetClippingMode(EHuiCanvasClipModeDelayed);
       
   106 	WsResetL();
       
   107 #ifdef __WINS__	
       
   108 	iPushCount = 0;
       
   109 #endif
       
   110 	}
       
   111 
       
   112 CHuiCanvasWsHwGc::~CHuiCanvasWsHwGc()
       
   113     {
       
   114     if (iVisual)
       
   115         {
       
   116         iVisual->Env().CanvasTextureCache().ReleaseCachedRenderBuffer(*iVisual);
       
   117         }
       
   118                 
       
   119     iTempRegion.Close();
       
   120     iWsClipRegion.Close();
       
   121     delete iCanvasGc;
       
   122     iCanvasGc = NULL;
       
   123     }
       
   124     
       
   125 void CHuiCanvasWsHwGc::WsBitBltL(TInt aBitmapHandle, TPoint aPoint)
       
   126 	{
       
   127 	THuiCachedImageParams cachedImageParams;
       
   128     cachedImageParams.iBitmapHandle = aBitmapHandle;
       
   129     cachedImageParams.iGcParams = CachedGcParams();
       
   130      
       
   131     const CHuiCanvasGraphicImage* cachedImage = iVisual->Env().CanvasTextureCache().CreateCachedImageL(cachedImageParams,*iVisual);
       
   132 
       
   133     if (IsRenderingEnabled())
       
   134         {           
       
   135         const CHuiTexture* texture = cachedImage->Texture();
       
   136         if (texture)
       
   137             {
       
   138             AdjustCoordinates( aPoint );
       
   139             THuiRealRect destinationRect = TRect(aPoint, texture->Size());          
       
   140     
       
   141             THuiCanvasDrawMode oldDrawMode = iCanvasGc->DrawMode();
       
   142             iCanvasGc->SetDrawMode(SelectCanvasDrawMode(iWsDrawMode));        
       
   143             // Draw            
       
   144             iCanvasGc->DrawImage(*texture, destinationRect, TRect(TPoint(0,0), texture->Size()), CHuiGc::EStretchNone);
       
   145             iCanvasGc->SetDrawMode(oldDrawMode);
       
   146             }
       
   147         }
       
   148 	}
       
   149 
       
   150 
       
   151 
       
   152 
       
   153 void CHuiCanvasWsHwGc::WsBitBltRectL(TInt aBitmapHandle, TPoint aPoint, TRect aRect)
       
   154 	{
       
   155 	THuiCachedImageParams cachedImageParams;
       
   156     cachedImageParams.iBitmapHandle = aBitmapHandle;
       
   157     cachedImageParams.iGcParams = CachedGcParams();
       
   158      
       
   159     const CHuiCanvasGraphicImage* cachedImage = iVisual->Env().CanvasTextureCache().CreateCachedImageL(cachedImageParams,*iVisual);
       
   160 
       
   161     if (IsRenderingEnabled())
       
   162         {           
       
   163         const CHuiTexture* texture = cachedImage->Texture();
       
   164         if (texture)
       
   165             {
       
   166             AdjustCoordinates( aPoint );
       
   167             THuiRealRect destinationRect = TRect(aPoint, texture->Size());                
       
   168 
       
   169             THuiCanvasDrawMode oldDrawMode = iCanvasGc->DrawMode();
       
   170             iCanvasGc->SetDrawMode(SelectCanvasDrawMode(iWsDrawMode));        
       
   171 
       
   172             // Draw            
       
   173             iCanvasGc->DrawImage(*texture, destinationRect, aRect, CHuiGc::EStretchNone);
       
   174             iCanvasGc->SetDrawMode(oldDrawMode);
       
   175             }        
       
   176         }
       
   177 	}
       
   178 
       
   179 
       
   180 
       
   181 void CHuiCanvasWsHwGc::WsBitBltMaskedL(TInt aBitmapHandle, TInt aMaskHandle, TInt aInvertMask, TPoint aPoint, TRect aRect)
       
   182 	{
       
   183 	THuiCachedImageParams cachedImageParams;
       
   184     cachedImageParams.iBitmapHandle = aBitmapHandle;
       
   185     cachedImageParams.iMaskHandle = aMaskHandle;
       
   186     cachedImageParams.iInvertedMask = aInvertMask;
       
   187     cachedImageParams.iGcParams = CachedGcParams();
       
   188      
       
   189      
       
   190     const CHuiCanvasGraphicImage* cachedImage = iVisual->Env().CanvasTextureCache().CreateCachedImageL(cachedImageParams,*iVisual);
       
   191 
       
   192     if (IsRenderingEnabled())
       
   193         {           
       
   194         const CHuiTexture* texture = cachedImage->Texture();
       
   195         if (texture)
       
   196             {
       
   197             AdjustCoordinates( aPoint );
       
   198             THuiRealRect destinationRect = TRect(aPoint, texture->Size());                
       
   199             
       
   200             // Draw            
       
   201             iCanvasGc->DrawImage(*texture, destinationRect, aRect, CHuiGc::EStretchNone);
       
   202             }
       
   203         }
       
   204 	}
       
   205 
       
   206 
       
   207 void CHuiCanvasWsHwGc::WsCombinedBitBltMaskedL(TRect aDestinationRect, const RArray<THuiCachedCombinedImageParams>& aBlits )
       
   208 	{
       
   209 	THuiCachedCombinedImageParams cachedCombinedImageParams;	    
       
   210     THuiCachedGcParams gcParams = CachedGcParams();          
       
   211     TSize imageSize = aDestinationRect.Size();
       
   212     
       
   213     // Must convert points relative to the image itself
       
   214     RArray<THuiCachedCombinedImageParams> convertedBlits;
       
   215     for (TInt i=0; i<aBlits.Count();i++)
       
   216         {
       
   217         THuiCachedCombinedImageParams convertedParams;
       
   218         convertedParams = aBlits[i];
       
   219         convertedParams.iCombinedBitmapPoint -= aDestinationRect.iTl;
       
   220         convertedBlits.Append(convertedParams);
       
   221         }    
       
   222     
       
   223     const CHuiCanvasGraphicImage* cachedImage = iVisual->Env().CanvasTextureCache().CreateCombinedCachedImageL(
       
   224         convertedBlits, 
       
   225         gcParams,
       
   226         imageSize, 
       
   227         *iVisual);
       
   228 
       
   229     convertedBlits.Close();
       
   230 
       
   231     if (IsRenderingEnabled())
       
   232         {           
       
   233         const CHuiTexture* texture = cachedImage->Texture();        
       
   234         if (texture)
       
   235             {
       
   236             TPoint point = aDestinationRect.iTl;
       
   237             AdjustCoordinates( point );
       
   238             
       
   239             THuiRealRect destinationRect = TRect(point, texture->Size());                        
       
   240     
       
   241             // Draw            
       
   242             iCanvasGc->DrawImage(*texture, destinationRect, TRect(TPoint(0,0), texture->Size()),  CHuiGc::EStretchNone);
       
   243             }
       
   244         }
       
   245 	}
       
   246 
       
   247 
       
   248 void CHuiCanvasWsHwGc::WsBitBltMaskedPointL(TInt aBitmapHandle, TInt aMaskHandle, TPoint aPoint1, TPoint aPoint2, TRect aRect)
       
   249 	{
       
   250 	THuiCachedImageParams cachedImageParams;
       
   251     cachedImageParams.iBitmapHandle = aBitmapHandle;
       
   252     cachedImageParams.iMaskHandle = aMaskHandle;
       
   253     cachedImageParams.iMaskOriginPoint = aPoint2;
       
   254     cachedImageParams.iGcParams = CachedGcParams();
       
   255 
       
   256     const CHuiCanvasGraphicImage* cachedImage = iVisual->Env().CanvasTextureCache().CreateCachedImageL(cachedImageParams,*iVisual);
       
   257 
       
   258     if (IsRenderingEnabled())
       
   259         {           
       
   260         const CHuiTexture* texture = cachedImage->Texture();
       
   261         if (texture)
       
   262             {
       
   263             AdjustCoordinates( aPoint1 );
       
   264             THuiRealRect destinationRect = TRect(aPoint1, texture->Size());                
       
   265             
       
   266             // Draw            
       
   267             iCanvasGc->DrawImage(*texture, destinationRect, aRect, CHuiGc::EStretchNone);
       
   268             }             
       
   269         }
       
   270 	}
       
   271 
       
   272 void CHuiCanvasWsHwGc::WsResetClippingRegionL()
       
   273 	{
       
   274     if (IsRenderingEnabled())
       
   275         {
       
   276         // Reset clip region
       
   277         iWsClipRegion.Clear();
       
   278         iCanvasGc->CancelClipping();
       
   279         }
       
   280 	}
       
   281 
       
   282 void CHuiCanvasWsHwGc::WsClearL()
       
   283 	{		
       
   284     if (IsRenderingEnabled())
       
   285         {
       
   286         THuiRealRect rect(iVisual->DisplayRect());     
       
   287         DoWsClearRectL(rect);
       
   288         }
       
   289 	}
       
   290 
       
   291 void CHuiCanvasWsHwGc::WsClearRectL(TRect& aRect)
       
   292 	{		
       
   293     if (IsRenderingEnabled())
       
   294         {
       
   295         AdjustCoordinates( aRect );
       
   296         DoWsClearRectL(aRect);
       
   297         }
       
   298 	}
       
   299 
       
   300 
       
   301 void CHuiCanvasWsHwGc::DoWsClearRectL(const THuiRealRect& aRect )
       
   302 	{
       
   303     if (IsRenderingEnabled())
       
   304         {
       
   305         RArray<THuiRealRect> rects;
       
   306         rects.Append(aRect);
       
   307     
       
   308         // Store current gc params
       
   309         UseWsState();
       
   310         
       
   311         CHuiTexture* oldPolygonFillTexture = iCanvasGc->PolygonFillTexture(); 
       
   312         
       
   313         // Clear
       
   314         iCanvasGc->SetPolygonFillTexture(NULL);
       
   315         iCanvasGc->SetPolygonDrawMode(EHuiFillNonZero);
       
   316         iCanvasGc->SetPenWidth(1);           	  	        
       
   317         iCanvasGc->SetPenColor(iWsBrushColor);            
       
   318         iCanvasGc->SetOpacity(TReal32(iWsBrushColor.Alpha() / 255.f));   
       
   319         iCanvasGc->SetDrawMode(SelectCanvasDrawMode(iWsDrawMode));        
       
   320         iCanvasGc->DrawRects(rects);
       
   321     
       
   322         // Restore gc params etc.
       
   323         rects.Close();
       
   324         UseCanvasState();
       
   325         iCanvasGc->SetPolygonFillTexture(oldPolygonFillTexture);
       
   326         }
       
   327     }
       
   328 
       
   329 void CHuiCanvasWsHwGc::WsResetBrushPatternL()
       
   330 	{
       
   331 	iWsBrushPattern = 0;
       
   332 	}
       
   333 
       
   334 void CHuiCanvasWsHwGc::WsResetFontL()
       
   335 	{
       
   336     iWsCurrentFont = 0;
       
   337 	}
       
   338 
       
   339 void CHuiCanvasWsHwGc::WsDrawArcL(TPoint aPoint1, TPoint aPoint2, TRect aRect)
       
   340 	{
       
   341 	// If penstyle is ENullPen, then nothign is drawn
       
   342     if (!iWsPenStyle)
       
   343         {
       
   344         return;    
       
   345         }
       
   346 
       
   347     if (IsRenderingEnabled())
       
   348         {
       
   349         UseWsState();        
       
   350 
       
   351         AdjustCoordinates( aRect );
       
   352         AdjustCoordinates( aPoint1 );
       
   353         AdjustCoordinates( aPoint2 );
       
   354 
       
   355         iCanvasGc->DrawArc( THuiRealRect(aRect), THuiRealPoint(aPoint1), THuiRealPoint(aPoint2) );
       
   356         
       
   357         UseCanvasState();
       
   358         }
       
   359     }
       
   360 
       
   361 void CHuiCanvasWsHwGc::WsDrawPieL(TPoint aPoint1, TPoint aPoint2, TRect aRect)
       
   362 	{
       
   363 	// If penstyle is ENullPen, then nothign is drawn
       
   364     if (!iWsPenStyle && !iWsBrushStyle)
       
   365         {
       
   366         return;    
       
   367         }
       
   368 
       
   369     if (IsRenderingEnabled())
       
   370         {    
       
   371         UseWsState();
       
   372 
       
   373         AdjustCoordinates( aRect );
       
   374         AdjustCoordinates( aPoint1 );
       
   375         AdjustCoordinates( aPoint2 );
       
   376             
       
   377         if (iWsBrushStyle == MWsGraphicsContext::ENullBrush)
       
   378             {
       
   379             iCanvasGc->SetPolygonDrawMode( EHuiNoFill );
       
   380             iCanvasGc->SetPenColor(iWsPenColor);            
       
   381             iCanvasGc->SetOpacity(TReal32(iWsPenColor.Alpha() / 255.f));       
       
   382             iCanvasGc->DrawPie(THuiRealRect(aRect),THuiRealPoint(aPoint1),THuiRealPoint(aPoint2));  
       
   383             }    
       
   384         else if (iWsBrushStyle == MWsGraphicsContext::ESolidBrush)
       
   385             {
       
   386             iCanvasGc->SetPolygonDrawMode( EHuiFillEvenOdd );
       
   387             iCanvasGc->SetPenColor(iWsBrushColor);            
       
   388             iCanvasGc->SetOpacity(TReal32(iWsBrushColor.Alpha() / 255.f));            
       
   389             iCanvasGc->DrawPie(THuiRealRect(aRect),THuiRealPoint(aPoint1),THuiRealPoint(aPoint2));  
       
   390 
       
   391             // Border should be drawn if pencolor is different than solid fill
       
   392             if (IsDifferent(iWsBrushColor, iWsPenColor, ETrue) && iWsPenStyle && iWsPenSize.iHeight >= 1 && iWsPenSize.iWidth >= 1)
       
   393                 {
       
   394                 iCanvasGc->SetPolygonDrawMode( EHuiNoFill );
       
   395                 iCanvasGc->SetPenColor(iWsPenColor);                    
       
   396                 iCanvasGc->SetOpacity(TReal32(iWsPenColor.Alpha() / 255.f));       
       
   397                 iCanvasGc->DrawPie(THuiRealRect(aRect),THuiRealPoint(aPoint1),THuiRealPoint(aPoint2));  
       
   398                 }            
       
   399             }
       
   400         else if (iWsBrushStyle == MWsGraphicsContext::EPatternedBrush)
       
   401             {
       
   402             iCanvasGc->SetPolygonDrawMode( EHuiFillEvenOdd );
       
   403             iCanvasGc->SetPenColor(iWsPenColor);                    
       
   404             iCanvasGc->SetOpacity(TReal32(iWsPenColor.Alpha() / 255.f));       
       
   405             UseBrushPattern();
       
   406             iCanvasGc->SetDrawMode(SelectCanvasDrawMode(iWsDrawMode));        
       
   407             iCanvasGc->DrawPie(THuiRealRect(aRect),THuiRealPoint(aPoint1),THuiRealPoint(aPoint2));  
       
   408             DiscardBrushPattern();
       
   409 
       
   410             if (iWsPenStyle && iWsPenSize.iHeight >= 1 && iWsPenSize.iWidth >= 1)
       
   411                 {
       
   412                 iCanvasGc->SetPolygonDrawMode( EHuiNoFill );
       
   413                 iCanvasGc->SetPenColor(iWsPenColor);                    
       
   414                 iCanvasGc->SetOpacity(TReal32(iWsPenColor.Alpha() / 255.f));       
       
   415                 iCanvasGc->DrawPie(THuiRealRect(aRect),THuiRealPoint(aPoint1),THuiRealPoint(aPoint2));  
       
   416                 }
       
   417             }
       
   418         else
       
   419             {
       
   420             // We should never get here because fallbackmode should be used in this case !
       
   421             RDebug::Print(_L("CHuiCanvasWsHwGc::WsDrawPieL - Unsupported brush mode %i"), iWsBrushStyle);
       
   422             }
       
   423                 
       
   424         UseCanvasState();
       
   425         }
       
   426 	}
       
   427 
       
   428 void CHuiCanvasWsHwGc::WsDrawBitmap1L(TInt aBitmapHandle, TRect aRect)
       
   429 	{
       
   430 	THuiCachedImageParams cachedImageParams;
       
   431     cachedImageParams.iBitmapHandle = aBitmapHandle;
       
   432     cachedImageParams.iGcParams = CachedGcParams();
       
   433 
       
   434     const CHuiCanvasGraphicImage* cachedImage = iVisual->Env().CanvasTextureCache().CreateCachedImageL(cachedImageParams,*iVisual);
       
   435     if (IsRenderingEnabled())
       
   436         {           
       
   437         const CHuiTexture* texture = cachedImage->Texture();
       
   438         if (texture)
       
   439             {
       
   440             AdjustCoordinates( aRect );
       
   441             THuiRealRect destinationRect = aRect;                
       
   442             
       
   443             // Draw            
       
   444             // This should stretch !
       
   445             iCanvasGc->DrawImage(*texture, destinationRect, TRect(TPoint(0,0), texture->Size()), CHuiGc::EStretchFull); 
       
   446             }        	
       
   447         }
       
   448 	}
       
   449 
       
   450 void CHuiCanvasWsHwGc::WsDrawBitmap2L(TInt aBitmapHandle, TRect aRect1, TRect aRect2)
       
   451 	{
       
   452 	THuiCachedImageParams cachedImageParams;
       
   453     cachedImageParams.iBitmapHandle = aBitmapHandle;
       
   454     cachedImageParams.iGcParams = CachedGcParams();
       
   455 
       
   456     const CHuiCanvasGraphicImage* cachedImage = iVisual->Env().CanvasTextureCache().CreateCachedImageL(cachedImageParams,*iVisual);
       
   457 
       
   458     if (IsRenderingEnabled())
       
   459         {           
       
   460         const CHuiTexture* texture = cachedImage->Texture();
       
   461         if (texture)
       
   462             {
       
   463             AdjustCoordinates( aRect1 );
       
   464             THuiRealRect destinationRect = aRect1;                
       
   465             
       
   466             // Draw            
       
   467             iCanvasGc->DrawImage(*texture, destinationRect, aRect2, CHuiGc::EStretchFull); 
       
   468             }        
       
   469         }
       
   470 	}
       
   471 
       
   472 void CHuiCanvasWsHwGc::WsDrawBitmap3L(TInt aBitmapHandle, TPoint aPoint)
       
   473 	{
       
   474 	 THuiCachedImageParams cachedImageParams;
       
   475     cachedImageParams.iBitmapHandle = aBitmapHandle;
       
   476     cachedImageParams.iGcParams = CachedGcParams();
       
   477 
       
   478     const CHuiCanvasGraphicImage* cachedImage = iVisual->Env().CanvasTextureCache().CreateCachedImageL(cachedImageParams,*iVisual);
       
   479 
       
   480     if (IsRenderingEnabled())
       
   481         {           
       
   482         const CHuiTexture* texture = cachedImage->Texture();
       
   483         if (texture)
       
   484             {
       
   485             AdjustCoordinates( aPoint );
       
   486             THuiRealRect destinationRect = TRect(aPoint, texture->Size());                
       
   487        
       
   488             // Draw
       
   489             // TODO: Actually we should check the bitmap size in twips here are decide destinationRect based on that !            
       
   490             iCanvasGc->DrawImage(*texture, destinationRect, TRect(TPoint(0,0), texture->Size()), CHuiGc::EStretchNone);
       
   491             }        
       
   492         }
       
   493 	}
       
   494 
       
   495 void CHuiCanvasWsHwGc::WsDrawBitmapMaskedL(TInt aBitmapHandle, TInt aMaskHandle, TInt aInvertMask, TRect& aRect1, TRect& aRect2)
       
   496 	{
       
   497     THuiCachedImageParams cachedImageParams;
       
   498     cachedImageParams.iBitmapHandle = aBitmapHandle;
       
   499     cachedImageParams.iMaskHandle = aMaskHandle;
       
   500     cachedImageParams.iInvertedMask = aInvertMask;
       
   501     cachedImageParams.iGcParams = CachedGcParams();
       
   502     
       
   503     const CHuiCanvasGraphicImage* cachedImage = iVisual->Env().CanvasTextureCache().CreateCachedImageL(cachedImageParams,*iVisual);
       
   504 
       
   505     if (IsRenderingEnabled())
       
   506         {           
       
   507         const CHuiTexture* texture = cachedImage->Texture();
       
   508         if (texture)
       
   509             {
       
   510             AdjustCoordinates( aRect1 );
       
   511             THuiRealRect destinationRect = aRect1;              
       
   512     
       
   513             // Draw            
       
   514             iCanvasGc->DrawImage(*texture, destinationRect, aRect2, CHuiGc::EStretchFull);
       
   515             }        
       
   516         }
       
   517 	}
       
   518 
       
   519 void CHuiCanvasWsHwGc::WsDrawRoundRectL(TPoint aPoint, TRect& aRect)
       
   520 	{
       
   521 	// If penstyle is ENullPen, then nothign is drawn
       
   522     if (!iWsPenStyle && !iWsBrushStyle)
       
   523         {
       
   524         return;    
       
   525         }
       
   526 
       
   527     if (IsRenderingEnabled())
       
   528         {    
       
   529         UseWsState();
       
   530         
       
   531         AdjustCoordinates( aRect );
       
   532         iCanvasGc->SetDrawMode(SelectCanvasDrawMode(iWsDrawMode));        
       
   533         
       
   534         if (iWsBrushStyle == MWsGraphicsContext::ENullBrush)
       
   535             {
       
   536             iCanvasGc->SetPolygonDrawMode( EHuiNoFill );
       
   537             iCanvasGc->SetPenColor(iWsPenColor);            
       
   538             iCanvasGc->SetOpacity(TReal32(iWsPenColor.Alpha() / 255.f));       
       
   539             iCanvasGc->DrawRoundRect( THuiRealRect(aRect), THuiRealSize( aPoint.iX*2, aPoint.iY*2 ));
       
   540             }    
       
   541         else if (iWsBrushStyle == MWsGraphicsContext::ESolidBrush)
       
   542             {
       
   543             iCanvasGc->SetPolygonDrawMode( EHuiFillEvenOdd );
       
   544             iCanvasGc->SetPenColor(iWsBrushColor);            
       
   545             iCanvasGc->SetOpacity(TReal32(iWsBrushColor.Alpha() / 255.f));            
       
   546             iCanvasGc->DrawRoundRect( THuiRealRect(aRect), THuiRealSize( aPoint.iX*2, aPoint.iY*2 ));
       
   547 
       
   548             // Border should be drawn if pencolor is different than solid fill
       
   549             if (IsDifferent(iWsBrushColor,iWsPenColor, ETrue) && iWsPenStyle && iWsPenSize.iHeight >= 1 && iWsPenSize.iWidth >= 1)
       
   550                 {
       
   551                 iCanvasGc->SetPolygonDrawMode( EHuiNoFill );
       
   552                 iCanvasGc->SetPenColor(iWsPenColor);                    
       
   553                 iCanvasGc->SetOpacity(TReal32(iWsPenColor.Alpha() / 255.f));       
       
   554                 iCanvasGc->DrawRoundRect( THuiRealRect(aRect), THuiRealSize( aPoint.iX*2, aPoint.iY*2 ));
       
   555                 }            
       
   556             }
       
   557         else if (iWsBrushStyle == MWsGraphicsContext::EPatternedBrush)
       
   558             {
       
   559             iCanvasGc->SetPolygonDrawMode( EHuiFillEvenOdd );
       
   560             iCanvasGc->SetPenColor(iWsPenColor);                    
       
   561             iCanvasGc->SetOpacity(TReal32(iWsPenColor.Alpha() / 255.f));       
       
   562             UseBrushPattern();
       
   563             iCanvasGc->SetDrawMode(SelectCanvasDrawMode(iWsDrawMode));        
       
   564             iCanvasGc->DrawRoundRect( THuiRealRect(aRect), THuiRealSize( aPoint.iX*2, aPoint.iY*2 ));
       
   565             DiscardBrushPattern();
       
   566 
       
   567             if (iWsPenStyle && iWsPenSize.iHeight >= 1 && iWsPenSize.iWidth >= 1)
       
   568                 {
       
   569                 iCanvasGc->SetPolygonDrawMode( EHuiNoFill );
       
   570                 iCanvasGc->SetPenColor(iWsPenColor);                    
       
   571                 iCanvasGc->SetOpacity(TReal32(iWsPenColor.Alpha() / 255.f));       
       
   572                 iCanvasGc->DrawRoundRect( THuiRealRect(aRect), THuiRealSize( aPoint.iX*2, aPoint.iY*2 ));
       
   573                 }
       
   574             }
       
   575         else
       
   576             {
       
   577             // We should never get here because fallbackmode should be used in this case !
       
   578             RDebug::Print(_L("CHuiCanvasWsHwGc::WsDrawRoundRectL - Unsupported brush mode %i"), iWsBrushStyle);
       
   579             }
       
   580         UseCanvasState();        
       
   581         }
       
   582     }
       
   583 
       
   584 void CHuiCanvasWsHwGc::WsDrawPolyLineL(CArrayFix<TPoint>* aPointerArray)
       
   585 	{
       
   586 	// If penstyle is ENullPen, then nothign is drawn
       
   587     if (!iWsPenStyle)
       
   588         {
       
   589         return;    
       
   590         }
       
   591     
       
   592     if (IsRenderingEnabled())
       
   593         {    
       
   594         if ( aPointerArray )
       
   595             {
       
   596             UseWsState();
       
   597                 
       
   598             RArray<THuiRealLine> lines;
       
   599             TPoint finalDeltaPos = iWsOrigin + iPosDelta; 
       
   600             for(TInt j=0; j<aPointerArray->Count()-1; j++)
       
   601                 {    
       
   602                 THuiRealLine line(aPointerArray->At(j) + finalDeltaPos, aPointerArray->At(j+1) + finalDeltaPos);
       
   603                 lines.Append(line);        
       
   604                 }
       
   605             iCanvasGc->DrawLines(lines);
       
   606             lines.Close();  
       
   607             
       
   608             UseCanvasState();
       
   609             }
       
   610         }
       
   611     }
       
   612 
       
   613 void CHuiCanvasWsHwGc::WsDrawPolyLineNoEndPointL(TPoint* aPointerArray, TInt aCount)
       
   614 	{
       
   615 	// If penstyle is ENullPen, then nothign is drawn
       
   616     if (!iWsPenStyle)
       
   617         {
       
   618         return;    
       
   619         }
       
   620 	
       
   621     if (IsRenderingEnabled())
       
   622         {    
       
   623         if ( aPointerArray )
       
   624            {
       
   625            UseWsState();
       
   626            
       
   627            RArray<THuiRealLine> lines;
       
   628            TPoint finalDeltaPos = iWsOrigin + iPosDelta; 
       
   629            for(TInt j=0; j< aCount-1; j++)
       
   630                {          
       
   631                THuiRealLine line(aPointerArray[j] + finalDeltaPos, aPointerArray[j+1] + finalDeltaPos );// TODO: TEST
       
   632                lines.Append(line);         
       
   633                }
       
   634            iCanvasGc->DrawLines(lines);
       
   635     
       
   636            RArray<THuiRealRect> rects;
       
   637            THuiRealRect pointRect = THuiRealRect(aPointerArray[aCount],aPointerArray[aCount]);
       
   638            rects.AppendL(pointRect);
       
   639            iCanvasGc->SetPenWidth(0);
       
   640            iCanvasGc->DrawRects(rects);
       
   641            rects.Close();
       
   642            lines.Close();       
       
   643            
       
   644            UseCanvasState();
       
   645            }
       
   646        }      
       
   647     }
       
   648 
       
   649 void CHuiCanvasWsHwGc::WsDrawPolygonL(CArrayFix<TPoint>* aPointerArray, TInt aFillRule)
       
   650 	{
       
   651     if (IsRenderingEnabled())
       
   652         {    	
       
   653         RArray<THuiRealPoint> points;
       
   654         for(TInt j=0; j<aPointerArray->Count(); j++)
       
   655            {      
       
   656            points.Append( THuiRealPoint( aPointerArray->At(j) + iWsOrigin + iPosDelta) );        
       
   657            }
       
   658         UseWsState();
       
   659         
       
   660         if ( aFillRule == MWsGraphicsContext::EAlternate )
       
   661             {
       
   662             iCanvasGc->SetPolygonDrawMode( EHuiFillEvenOdd );
       
   663             }
       
   664         if ( aFillRule == MWsGraphicsContext::EWinding )
       
   665             {        
       
   666             iCanvasGc->SetPolygonDrawMode( EHuiFillNonZero );
       
   667             }
       
   668         iCanvasGc->SetPenColor(iWsPenColor);            
       
   669         iCanvasGc->SetOpacity(TReal32(iWsPenColor.Alpha() / 255.f));       
       
   670         iCanvasGc->SetDrawMode(SelectCanvasDrawMode(iWsDrawMode));        
       
   671             
       
   672         iCanvasGc->DrawPolygon( points );
       
   673     
       
   674         UseCanvasState();
       
   675     
       
   676         points.Close();        
       
   677         }	
       
   678 	}
       
   679 
       
   680 void CHuiCanvasWsHwGc::WsDrawEllipseL(TRect& aRect)
       
   681 	{
       
   682 	// If penstyle is ENullPen, then nothign is drawn
       
   683     if (!iWsPenStyle && !iWsBrushStyle)
       
   684         {
       
   685         return;    
       
   686         }
       
   687 
       
   688     if (IsRenderingEnabled())
       
   689         {        
       
   690         AdjustCoordinates( aRect );
       
   691         THuiRealRect destRect = aRect;
       
   692         UseWsState();
       
   693         
       
   694         if (iWsBrushStyle == MWsGraphicsContext::ENullBrush)
       
   695             {
       
   696             iCanvasGc->SetPolygonDrawMode( EHuiNoFill );
       
   697             iCanvasGc->SetPenColor(iWsPenColor);            
       
   698             iCanvasGc->SetOpacity(TReal32(iWsPenColor.Alpha() / 255.f));       
       
   699             iCanvasGc->DrawEllipse(destRect);
       
   700             }    
       
   701         else if (iWsBrushStyle == MWsGraphicsContext::ESolidBrush)
       
   702             {
       
   703             iCanvasGc->SetPolygonDrawMode( EHuiFillEvenOdd );
       
   704             iCanvasGc->SetPenColor(iWsBrushColor);            
       
   705             iCanvasGc->SetOpacity(TReal32(iWsBrushColor.Alpha() / 255.f));            
       
   706             iCanvasGc->DrawEllipse(destRect);
       
   707 
       
   708             // Border should be drawn if pencolor is different than solid fill
       
   709             if (IsDifferent(iWsBrushColor,iWsPenColor, ETrue) && iWsPenStyle && iWsPenSize.iHeight >= 1 && iWsPenSize.iWidth >= 1)
       
   710                 {
       
   711                 iCanvasGc->SetPolygonDrawMode( EHuiNoFill );
       
   712                 iCanvasGc->SetPenColor(iWsPenColor);                    
       
   713                 iCanvasGc->SetOpacity(TReal32(iWsPenColor.Alpha() / 255.f));       
       
   714                 iCanvasGc->DrawEllipse(destRect);
       
   715                 }            
       
   716             }
       
   717         else if (iWsBrushStyle == MWsGraphicsContext::EPatternedBrush)
       
   718             {
       
   719             iCanvasGc->SetPolygonDrawMode( EHuiFillEvenOdd );
       
   720             iCanvasGc->SetPenColor(iWsPenColor);                    
       
   721             iCanvasGc->SetOpacity(TReal32(iWsPenColor.Alpha() / 255.f));       
       
   722             UseBrushPattern();
       
   723             iCanvasGc->SetDrawMode(SelectCanvasDrawMode(iWsDrawMode));        
       
   724             iCanvasGc->DrawEllipse(destRect);
       
   725             DiscardBrushPattern();
       
   726 
       
   727             if (iWsPenStyle && iWsPenSize.iHeight >= 1 && iWsPenSize.iWidth >= 1)
       
   728                 {
       
   729                 iCanvasGc->SetPolygonDrawMode( EHuiNoFill );
       
   730                 iCanvasGc->SetPenColor(iWsPenColor);                    
       
   731                 iCanvasGc->SetOpacity(TReal32(iWsPenColor.Alpha() / 255.f));       
       
   732                 iCanvasGc->DrawEllipse(destRect);
       
   733                 }
       
   734             }
       
   735         else
       
   736             {
       
   737             // We should never get here because fallbackmode should be used in this case !
       
   738             RDebug::Print(_L("CHuiCanvasWsHwGc::WsDrawEllipseL - Unsupported brush mode %i"), iWsBrushStyle);
       
   739             }
       
   740     
       
   741         UseCanvasState();
       
   742         }
       
   743 	}
       
   744 
       
   745 void CHuiCanvasWsHwGc::WsDrawLineL(TPoint& aStart, TPoint& aEnd)
       
   746 	{
       
   747 	// If penstyle is ENullPen, then nothign is drawn
       
   748     if (!iWsPenStyle)
       
   749         {
       
   750         return;    
       
   751         }
       
   752 
       
   753     if (IsRenderingEnabled())
       
   754         {            
       
   755         AdjustCoordinates( aStart );
       
   756         AdjustCoordinates( aEnd );
       
   757         
       
   758         THuiRealLine line(aStart, aEnd);
       
   759         RArray<THuiRealLine> lines;
       
   760         lines.Append(line);        
       
   761     
       
   762         UseWsState();
       
   763     
       
   764         iCanvasGc->DrawLines( lines );
       
   765         lines.Close();
       
   766     
       
   767         UseCanvasState();
       
   768         }
       
   769     }
       
   770 
       
   771 void CHuiCanvasWsHwGc::WsDrawLineToL(TPoint& aPoint)
       
   772 	{
       
   773 	// If penstyle is ENullPen, then nothign is drawn
       
   774     if (!iWsPenStyle)
       
   775         {
       
   776         return;    
       
   777         }
       
   778 	
       
   779     if (IsRenderingEnabled())
       
   780         {            
       
   781         AdjustCoordinates( aPoint );
       
   782         TPoint currentPosition = iWsPenPosition;	
       
   783         THuiRealLine line(currentPosition, aPoint);
       
   784         RArray<THuiRealLine> lines;
       
   785         lines.Append(line);        
       
   786     
       
   787         UseWsState();
       
   788     
       
   789         iCanvasGc->DrawLines( lines );
       
   790             
       
   791         iWsPenPosition = aPoint;       
       
   792         lines.Close();        
       
   793     
       
   794         UseCanvasState();
       
   795         }
       
   796 	}
       
   797     
       
   798 void CHuiCanvasWsHwGc::WsDrawLineByL(TPoint& aPoint)
       
   799 	{
       
   800 	// If penstyle is ENullPen, then nothign is drawn
       
   801     if (!iWsPenStyle)
       
   802         {
       
   803         return;    
       
   804         }
       
   805 	
       
   806     if (IsRenderingEnabled())
       
   807         {            
       
   808         AdjustCoordinates( aPoint );
       
   809         TPoint currentPosition = iWsPenPosition;
       
   810         TPoint endPoint = currentPosition + aPoint;
       
   811         THuiRealLine line(currentPosition, endPoint);    
       
   812         RArray<THuiRealLine> lines;
       
   813         lines.Append(line);        
       
   814     
       
   815         UseWsState();
       
   816     
       
   817         iCanvasGc->DrawLines( lines );
       
   818     
       
   819         iWsPenPosition = endPoint;
       
   820         lines.Close();    
       
   821     
       
   822         UseCanvasState();
       
   823         }
       
   824 	}
       
   825     
       
   826 void CHuiCanvasWsHwGc::WsDrawRectL(TRect& aRect)
       
   827 	{
       
   828 	// If penstyle is ENullPen, then nothign is drawn
       
   829     if (!iWsPenStyle && !iWsBrushStyle)
       
   830         {
       
   831         return;    
       
   832         }
       
   833 
       
   834     if (IsRenderingEnabled())
       
   835         {                
       
   836         AdjustCoordinates( aRect );
       
   837         RArray<THuiRealRect> rects;
       
   838         rects.AppendL(aRect);        
       
   839         
       
   840         UseWsState();
       
   841    
       
   842         if (iWsBrushStyle == MWsGraphicsContext::ENullBrush)
       
   843             {
       
   844             iCanvasGc->SetPenColor(iWsPenColor);                    
       
   845             iCanvasGc->SetOpacity(TReal32(iWsPenColor.Alpha() / 255.f));       
       
   846             iCanvasGc->SetDrawMode(SelectCanvasDrawMode(iWsDrawMode));        
       
   847             iCanvasGc->DrawRects(rects);
       
   848             }    
       
   849         else if (iWsBrushStyle == MWsGraphicsContext::ESolidBrush)
       
   850             {
       
   851             iCanvasGc->SetPolygonDrawMode( EHuiFillEvenOdd );
       
   852             iCanvasGc->SetPenColor(iWsBrushColor);            
       
   853             iCanvasGc->SetOpacity(TReal32(iWsBrushColor.Alpha() / 255.f));            
       
   854             iCanvasGc->SetDrawMode(SelectCanvasDrawMode(iWsDrawMode));        
       
   855             iCanvasGc->DrawRects(rects);
       
   856 
       
   857             
       
   858             // Border should be drawn if pencolor is different than solid fill
       
   859             if (IsDifferent(iWsBrushColor,iWsPenColor, ETrue) && iWsPenStyle && iWsPenSize.iHeight >= 1 && iWsPenSize.iWidth >= 1)
       
   860                 {
       
   861                 iCanvasGc->SetPolygonDrawMode( EHuiNoFill );
       
   862                 iCanvasGc->SetPenColor(iWsPenColor);                    
       
   863                 iCanvasGc->SetOpacity(TReal32(iWsPenColor.Alpha() / 255.f));       
       
   864                 iCanvasGc->DrawRects(rects);                
       
   865                 }            
       
   866             }
       
   867         else if (iWsBrushStyle == MWsGraphicsContext::EPatternedBrush)
       
   868             {
       
   869             iCanvasGc->SetPolygonDrawMode( EHuiFillEvenOdd );
       
   870             iCanvasGc->SetPenColor(iWsPenColor);                    
       
   871             iCanvasGc->SetOpacity(TReal32(iWsPenColor.Alpha() / 255.f));       
       
   872             UseBrushPattern();
       
   873             iCanvasGc->SetDrawMode(SelectCanvasDrawMode(iWsDrawMode));        
       
   874             iCanvasGc->DrawRects(rects);
       
   875             DiscardBrushPattern();
       
   876 
       
   877             if (iWsPenStyle && iWsPenSize.iHeight >= 1 && iWsPenSize.iWidth >= 1)
       
   878                 {
       
   879                 iCanvasGc->SetPolygonDrawMode( EHuiNoFill );
       
   880                 iCanvasGc->SetPenColor(iWsPenColor);                    
       
   881                 iCanvasGc->SetOpacity(TReal32(iWsPenColor.Alpha() / 255.f));       
       
   882                 iCanvasGc->DrawRects(rects);                                
       
   883                 }
       
   884             }
       
   885         else
       
   886             {
       
   887             // We should never get here because fallbackmode should be used in this case !
       
   888             RDebug::Print(_L("CHuiCanvasWsHwGc::WsDrawRectL - Unsupported brush mode %i"), iWsBrushStyle);
       
   889             }
       
   890         
       
   891         rects.Close();
       
   892         
       
   893         UseCanvasState();
       
   894         }
       
   895     }
       
   896 	
       
   897 const TUint8 color_s_to_lin[256] = {
       
   898    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
       
   899    0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
       
   900    0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
       
   901    0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x03, 0x04,
       
   902    0x04, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x05,
       
   903    0x05, 0x06, 0x06, 0x06, 0x06, 0x07, 0x07, 0x07,
       
   904    0x08, 0x08, 0x08, 0x08, 0x09, 0x09, 0x09, 0x0a,
       
   905    0x0a, 0x0a, 0x0b, 0x0b, 0x0c, 0x0c, 0x0c, 0x0d,
       
   906    0x0d, 0x0e, 0x0e, 0x0e, 0x0f, 0x0f, 0x10, 0x10,
       
   907    0x11, 0x11, 0x12, 0x12, 0x12, 0x13, 0x13, 0x14,
       
   908    0x15, 0x15, 0x16, 0x16, 0x17, 0x17, 0x18, 0x18,
       
   909    0x19, 0x1a, 0x1a, 0x1b, 0x1b, 0x1c, 0x1d, 0x1d,
       
   910    0x1e, 0x1f, 0x1f, 0x20, 0x21, 0x21, 0x22, 0x23,
       
   911    0x23, 0x24, 0x25, 0x26, 0x26, 0x27, 0x28, 0x29,
       
   912    0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2d, 0x2e, 0x2f,
       
   913    0x30, 0x31, 0x32, 0x33, 0x33, 0x34, 0x35, 0x36,
       
   914    0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e,
       
   915    0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46,
       
   916    0x47, 0x48, 0x49, 0x4a, 0x4c, 0x4d, 0x4e, 0x4f,
       
   917    0x50, 0x51, 0x52, 0x54, 0x55, 0x56, 0x57, 0x58,
       
   918    0x5a, 0x5b, 0x5c, 0x5d, 0x5f, 0x60, 0x61, 0x63,
       
   919    0x64, 0x65, 0x67, 0x68, 0x69, 0x6b, 0x6c, 0x6d,
       
   920    0x6f, 0x70, 0x72, 0x73, 0x74, 0x76, 0x77, 0x79,
       
   921    0x7a, 0x7c, 0x7d, 0x7f, 0x80, 0x82, 0x83, 0x85,
       
   922    0x86, 0x88, 0x8a, 0x8b, 0x8d, 0x8e, 0x90, 0x92,
       
   923    0x93, 0x95, 0x97, 0x98, 0x9a, 0x9c, 0x9d, 0x9f,
       
   924    0xa1, 0xa3, 0xa4, 0xa6, 0xa8, 0xaa, 0xac, 0xad,
       
   925    0xaf, 0xb1, 0xb3, 0xb5, 0xb7, 0xb8, 0xba, 0xbc,
       
   926    0xbe, 0xc0, 0xc2, 0xc4, 0xc6, 0xc8, 0xca, 0xcc,
       
   927    0xce, 0xd0, 0xd2, 0xd4, 0xd6, 0xd8, 0xda, 0xdc,
       
   928    0xde, 0xe0, 0xe2, 0xe5, 0xe7, 0xe9, 0xeb, 0xed,
       
   929    0xef, 0xf2, 0xf4, 0xf6, 0xf8, 0xfa, 0xfd, 0xff };
       
   930 
       
   931 inline TRgb ConvertToLinear(TRgb aColor)
       
   932     {
       
   933     // perform sRGB->linear color conversion if the renderer is
       
   934     // openvg
       
   935     // NOTE: For emulator depending on the OpenVG SW version mapping may
       
   936     // be needed or not. Use/unuse ifdefs below if text colors are too dark/light.
       
   937 //#ifndef __WINSCW__
       
   938     if (CHuiStatic::Env().Renderer() == EHuiRendererVg10)
       
   939         {
       
   940         TUint32 color = aColor.Internal();
       
   941         return
       
   942             ((TUint32)color_s_to_lin[(color >> 0) & 0xff] << 16) |
       
   943             ((TUint32)color_s_to_lin[(color >> 8) & 0xff] << 8) |
       
   944             ((TUint32)color_s_to_lin[(color >> 16) & 0xff] << 0) |
       
   945             (color & 0xff000000);
       
   946         }
       
   947 //#endif    
       
   948     return aColor;
       
   949     }
       
   950 
       
   951 void CHuiCanvasWsHwGc::WsDrawText1L(TPtr& aTextValue, THuiCanvasTextParameters& aTextParameters)
       
   952 	{		
       
   953 	TPoint point = iWsPenPosition;
       
   954     AdjustCoordinates( point );
       
   955 	THuiCachedTextParams cachedtextParams;
       
   956     cachedtextParams.iFindTextPtr = &aTextValue;
       
   957     cachedtextParams.iFontHandle = iWsCurrentFont;
       
   958     cachedtextParams.iTextParams = aTextParameters;
       
   959     cachedtextParams.iGcParams = CachedGcParams();
       
   960 
       
   961     const CHuiCanvasTextImage* cachedImage = iVisual->Env().CanvasTextureCache().CreateCachedTextL(cachedtextParams,*iVisual); 
       
   962 
       
   963     if (IsRenderingEnabled())
       
   964         {           
       
   965         const CHuiTexture* texture = cachedImage->Texture();
       
   966         if (texture)
       
   967             {
       
   968             THuiRealRect destinationRect = TRect(point, texture->Size());                
       
   969             
       
   970             // Adjust destination rect according to the point where text was rasterised in the image
       
   971             TInt dx = cachedImage->iRasterizationOffset.iX;
       
   972             TInt dy = cachedImage->iRasterizationOffset.iY;        
       
   973             destinationRect.Move(-dx,-dy);
       
   974             
       
   975             TRgb oldPenColor = iCanvasGc->PenColor();
       
   976             if (cachedImage->iUseColorModulation)
       
   977                 {
       
   978                 iCanvasGc->SetPenColor(ConvertToLinear(iWsPenColor));    
       
   979                 }
       
   980             
       
   981             // Draw            
       
   982             iCanvasGc->DrawImage(*texture, destinationRect, TRect(TPoint(0,0), texture->Size()), CHuiGc::EStretchNone);
       
   983     
       
   984             if (cachedImage->iUseColorModulation)
       
   985                 {
       
   986                 iCanvasGc->SetPenColor(oldPenColor);                        
       
   987                 }
       
   988             }        
       
   989         }
       
   990 	}
       
   991 
       
   992 void CHuiCanvasWsHwGc::WsDrawText2L(TPtr& aTextValue, TPoint& aPoint,THuiCanvasTextParameters& aTextParameters)
       
   993 	{
       
   994 	THuiCachedTextParams cachedtextParams;
       
   995     cachedtextParams.iFindTextPtr = &aTextValue;
       
   996     cachedtextParams.iFontHandle = iWsCurrentFont;
       
   997     cachedtextParams.iTextParams = aTextParameters;
       
   998     cachedtextParams.iGcParams = CachedGcParams();
       
   999 
       
  1000     const CHuiCanvasTextImage* cachedImage = iVisual->Env().CanvasTextureCache().CreateCachedTextL(cachedtextParams,*iVisual); 
       
  1001 
       
  1002     if (IsRenderingEnabled())
       
  1003         {           
       
  1004         const CHuiTexture* texture = cachedImage->Texture();
       
  1005         if (texture)
       
  1006             {
       
  1007             AdjustCoordinates( aPoint );
       
  1008             THuiRealRect destinationRect = TRect(aPoint, texture->Size());                
       
  1009             
       
  1010             // Adjust destination rect according to the point where text was rasterised in the image
       
  1011             TInt dx = cachedImage->iRasterizationOffset.iX;
       
  1012             TInt dy = cachedImage->iRasterizationOffset.iY;        
       
  1013             destinationRect.Move(-dx,-dy);
       
  1014             
       
  1015             TRgb oldPenColor = iCanvasGc->PenColor();
       
  1016             if (cachedImage->iUseColorModulation)
       
  1017                 {
       
  1018                 iCanvasGc->SetPenColor(ConvertToLinear(iWsPenColor));    
       
  1019                 }
       
  1020             
       
  1021             // Draw            
       
  1022             iCanvasGc->DrawImage(*texture, destinationRect, TRect(TPoint(0,0), texture->Size()), CHuiGc::EStretchNone);
       
  1023     
       
  1024             if (cachedImage->iUseColorModulation)
       
  1025                 {
       
  1026                 iCanvasGc->SetPenColor(oldPenColor);                        
       
  1027                 }
       
  1028             }
       
  1029         }
       
  1030 	}
       
  1031 
       
  1032 void CHuiCanvasWsHwGc::WsDrawText3L(TPtr& aTextValue, TRect& aRect, THuiCanvasTextParameters& aTextParameters)
       
  1033 	{
       
  1034 	THuiCachedTextParams cachedtextParams;
       
  1035 	cachedtextParams.iFindTextPtr = &aTextValue;
       
  1036 	cachedtextParams.iFontHandle = iWsCurrentFont;
       
  1037     cachedtextParams.iTextParams = aTextParameters;
       
  1038     cachedtextParams.iTextBoxMaxSize = aRect.Size();
       
  1039     cachedtextParams.iGcParams = CachedGcParams();
       
  1040 
       
  1041     const CHuiCanvasTextImage* cachedImage = iVisual->Env().CanvasTextureCache().CreateCachedTextL(cachedtextParams,*iVisual); 
       
  1042 
       
  1043     if (IsRenderingEnabled())
       
  1044         {           
       
  1045         const CHuiTexture* texture = cachedImage->Texture();
       
  1046         if (texture)
       
  1047             {
       
  1048             AdjustCoordinates( aRect );
       
  1049             THuiRealRect destinationRect = aRect;                
       
  1050             
       
  1051             // Adjust destination rect according to the point where text was rasterised in the image
       
  1052             TInt dx = cachedImage->iRasterizationOffset.iX;
       
  1053             TInt dy = cachedImage->iRasterizationOffset.iY;        
       
  1054             destinationRect.Move(-dx,-dy);
       
  1055             
       
  1056             TRgb oldPenColor = iCanvasGc->PenColor();
       
  1057             if (cachedImage->iUseColorModulation)
       
  1058                 {
       
  1059                 DrawTextBrush( destinationRect );
       
  1060                 iCanvasGc->SetPenColor(ConvertToLinear(iWsPenColor));    
       
  1061                 }
       
  1062     
       
  1063             // Draw            
       
  1064             iCanvasGc->DrawImage(*texture, destinationRect, TRect(TPoint(0,0), texture->Size()), CHuiGc::EStretchNone);
       
  1065     
       
  1066             if (cachedImage->iUseColorModulation)
       
  1067                 {
       
  1068                 iCanvasGc->SetPenColor(oldPenColor);                        
       
  1069                 }
       
  1070             }
       
  1071         }
       
  1072 	}
       
  1073 
       
  1074 
       
  1075 void CHuiCanvasWsHwGc::WsDrawText4L(TPtr& aTextValue, TRect& aRect, TInt aBaselineOffset, TInt aTextAlign, TInt aTextMargin,THuiCanvasTextParameters& aTextParameters)
       
  1076     {
       
  1077 	THuiCachedTextParams cachedtextParams;
       
  1078 	cachedtextParams.iFindTextPtr = &aTextValue;
       
  1079     cachedtextParams.iFontHandle = iWsCurrentFont;
       
  1080     cachedtextParams.iTextParams = aTextParameters;
       
  1081     cachedtextParams.iTextBoxMaxSize = aRect.Size();
       
  1082     cachedtextParams.iBaseLineOffset = aBaselineOffset;
       
  1083     cachedtextParams.iTextAlign = aTextAlign;
       
  1084     cachedtextParams.iMargin = aTextMargin;
       
  1085     cachedtextParams.iGcParams = CachedGcParams();
       
  1086     
       
  1087     const CHuiCanvasTextImage* cachedImage = iVisual->Env().CanvasTextureCache().CreateCachedTextL(cachedtextParams,*iVisual); 
       
  1088 
       
  1089     if (IsRenderingEnabled())
       
  1090         {           
       
  1091         const CHuiTexture* texture = cachedImage->Texture();
       
  1092         if (texture)
       
  1093             {
       
  1094             AdjustCoordinates( aRect );
       
  1095             THuiRealRect destinationRect = aRect;                
       
  1096             
       
  1097             // Adjust destination rect according to the point where text was rasterised in the image
       
  1098             TInt dx = cachedImage->iRasterizationOffset.iX;
       
  1099             TInt dy = cachedImage->iRasterizationOffset.iY;        
       
  1100             destinationRect.Move(-dx,-dy);
       
  1101             
       
  1102             TRgb oldPenColor = iCanvasGc->PenColor();
       
  1103             if (cachedImage->iUseColorModulation)
       
  1104                 {
       
  1105                 DrawTextBrush( destinationRect );
       
  1106                 iCanvasGc->SetPenColor(ConvertToLinear(iWsPenColor));    
       
  1107                 }
       
  1108     
       
  1109             // Draw            
       
  1110             iCanvasGc->DrawImage(*texture, destinationRect, TRect(TPoint(0,0), texture->Size()), CHuiGc::EStretchNone);
       
  1111     
       
  1112             if (cachedImage->iUseColorModulation)
       
  1113                 {
       
  1114                 iCanvasGc->SetPenColor(oldPenColor);                        
       
  1115                 }
       
  1116             }    
       
  1117         }
       
  1118     }
       
  1119 
       
  1120 void CHuiCanvasWsHwGc::WsDrawText5L( TPtr& aTextValue, TRect& aRect, TInt aBaselineOffset, TInt aTextAlign, TInt aTextMargin,TInt aTextWidth, THuiCanvasTextParameters& aTextParameters)
       
  1121 	{	
       
  1122 	THuiCachedTextParams cachedtextParams;
       
  1123 	cachedtextParams.iFindTextPtr = &aTextValue;
       
  1124     cachedtextParams.iFontHandle = iWsCurrentFont;
       
  1125     cachedtextParams.iTextParams = aTextParameters;
       
  1126     cachedtextParams.iTextBoxMaxSize = aRect.Size();
       
  1127     cachedtextParams.iBaseLineOffset = aBaselineOffset;
       
  1128     cachedtextParams.iTextAlign = aTextAlign;
       
  1129     cachedtextParams.iMargin = aTextMargin;
       
  1130     cachedtextParams.iTextWidth = aTextWidth;
       
  1131     cachedtextParams.iGcParams = CachedGcParams();
       
  1132     
       
  1133     const CHuiCanvasTextImage* cachedImage = iVisual->Env().CanvasTextureCache().CreateCachedTextL(cachedtextParams,*iVisual); 
       
  1134 
       
  1135     if (IsRenderingEnabled())
       
  1136         {           
       
  1137         const CHuiTexture* texture = cachedImage->Texture();
       
  1138         if (texture)
       
  1139             {
       
  1140             AdjustCoordinates( aRect );
       
  1141             THuiRealRect destinationRect = aRect;                
       
  1142             
       
  1143             // Adjust destination rect according to the point where text was rasterised in the image
       
  1144             TInt dx = cachedImage->iRasterizationOffset.iX;
       
  1145             TInt dy = cachedImage->iRasterizationOffset.iY;        
       
  1146             destinationRect.Move(-dx,-dy);
       
  1147             
       
  1148             TRgb oldPenColor = iCanvasGc->PenColor();
       
  1149             if (cachedImage->iUseColorModulation)
       
  1150                 {
       
  1151                 DrawTextBrush( destinationRect );
       
  1152                 iCanvasGc->SetPenColor(ConvertToLinear(iWsPenColor));    
       
  1153                 }
       
  1154     
       
  1155             // Draw            
       
  1156             iCanvasGc->DrawImage(*texture, destinationRect, TRect(TPoint(0,0), texture->Size()), CHuiGc::EStretchNone);
       
  1157     
       
  1158             if (cachedImage->iUseColorModulation)
       
  1159                 {
       
  1160                 iCanvasGc->SetPenColor(oldPenColor);                        
       
  1161                 }
       
  1162             }    
       
  1163         }
       
  1164 	}
       
  1165 	
       
  1166 void CHuiCanvasWsHwGc::WsDrawTextVertical1L(TPtr& aTextValue, TInt aTextUp, THuiCanvasTextParameters& aTextParameters)	
       
  1167     {
       
  1168 	TPoint point = iWsPenPosition;
       
  1169     TInt angle = aTextUp ? -90 : 90;
       
  1170 
       
  1171     THuiCachedTextParams cachedtextParams;
       
  1172     cachedtextParams.iFindTextPtr = &aTextValue;
       
  1173     cachedtextParams.iFontHandle = iWsCurrentFont;
       
  1174     cachedtextParams.iTextParams = aTextParameters;
       
  1175     cachedtextParams.iAngle = angle;
       
  1176     cachedtextParams.iGcParams = CachedGcParams();
       
  1177 
       
  1178     const CHuiCanvasTextImage* cachedImage = iVisual->Env().CanvasTextureCache().CreateCachedTextL(cachedtextParams,*iVisual); 
       
  1179 
       
  1180     if (IsRenderingEnabled())
       
  1181         {           
       
  1182         const CHuiTexture* texture = cachedImage->Texture();
       
  1183         if (texture)
       
  1184             {
       
  1185             AdjustCoordinates( point );
       
  1186             THuiRealRect destinationRect = TRect(point, texture->Size());                
       
  1187             
       
  1188             // Adjust destination rect according to the point where text was rasterised in the image
       
  1189             TInt dx = cachedImage->iRasterizationOffset.iX;
       
  1190             TInt dy = cachedImage->iRasterizationOffset.iY;        
       
  1191             destinationRect.Move(-dx,-dy);
       
  1192             
       
  1193             TRgb oldPenColor = iCanvasGc->PenColor();
       
  1194             if (cachedImage->iUseColorModulation)
       
  1195                 {
       
  1196                 iCanvasGc->SetPenColor(ConvertToLinear(iWsPenColor));    
       
  1197                 }
       
  1198     
       
  1199             // Draw            
       
  1200             iCanvasGc->DrawImage(*texture, destinationRect, TRect(TPoint(0,0), texture->Size()), CHuiGc::EStretchNone);
       
  1201     
       
  1202             if (cachedImage->iUseColorModulation)
       
  1203                 {
       
  1204                 iCanvasGc->SetPenColor(oldPenColor);                        
       
  1205                 }
       
  1206             }    
       
  1207         }
       
  1208     }
       
  1209 
       
  1210 void CHuiCanvasWsHwGc::WsDrawTextVertical2L(TPtr& aTextValue, TInt aTextUp,TPoint& aPoint, THuiCanvasTextParameters& aTextParameters)	
       
  1211     {	 	                                       	
       
  1212     TInt angle = aTextUp ? -90 : 90;
       
  1213 
       
  1214     THuiCachedTextParams cachedtextParams;
       
  1215     cachedtextParams.iFindTextPtr = &aTextValue;
       
  1216     cachedtextParams.iFontHandle = iWsCurrentFont;
       
  1217     cachedtextParams.iTextParams = aTextParameters;
       
  1218     cachedtextParams.iAngle = angle;
       
  1219     cachedtextParams.iGcParams = CachedGcParams();
       
  1220 	
       
  1221     const CHuiCanvasTextImage* cachedImage = iVisual->Env().CanvasTextureCache().CreateCachedTextL(cachedtextParams,*iVisual); 
       
  1222 
       
  1223     if (IsRenderingEnabled())
       
  1224         {           
       
  1225         const CHuiTexture* texture = cachedImage->Texture();
       
  1226         if (texture)
       
  1227             {
       
  1228             AdjustCoordinates( aPoint );
       
  1229             THuiRealRect destinationRect = TRect(aPoint, texture->Size());                
       
  1230             
       
  1231             // Adjust destination rect according to the point where text was rasterised in the image
       
  1232             TInt dx = cachedImage->iRasterizationOffset.iX;
       
  1233             TInt dy = cachedImage->iRasterizationOffset.iY;        
       
  1234             destinationRect.Move(-dx,-dy);
       
  1235             
       
  1236             TRgb oldPenColor = iCanvasGc->PenColor();
       
  1237             if (cachedImage->iUseColorModulation)
       
  1238                 {
       
  1239                 iCanvasGc->SetPenColor(ConvertToLinear(iWsPenColor));    
       
  1240                 }
       
  1241     
       
  1242             // Draw            
       
  1243             iCanvasGc->DrawImage(*texture, destinationRect, TRect(TPoint(0,0), texture->Size()), CHuiGc::EStretchNone);
       
  1244     
       
  1245             if (cachedImage->iUseColorModulation)
       
  1246                 {
       
  1247                 iCanvasGc->SetPenColor(oldPenColor);                        
       
  1248                 }
       
  1249             }
       
  1250         }
       
  1251     }
       
  1252 
       
  1253 void CHuiCanvasWsHwGc::WsDrawTextVertical3L(TPtr& aTextValue, TInt aTextUp, TRect& aRect, THuiCanvasTextParameters& aTextParameters)	
       
  1254     {
       
  1255 	TInt angle = aTextUp ? -90 : 90;
       
  1256 
       
  1257     THuiCachedTextParams cachedtextParams;
       
  1258     cachedtextParams.iFindTextPtr = &aTextValue;
       
  1259     cachedtextParams.iFontHandle = iWsCurrentFont;
       
  1260     cachedtextParams.iTextParams = aTextParameters;
       
  1261     cachedtextParams.iTextBoxMaxSize = aRect.Size();
       
  1262     cachedtextParams.iAngle = angle;
       
  1263     cachedtextParams.iGcParams = CachedGcParams();
       
  1264 
       
  1265     const CHuiCanvasTextImage* cachedImage = iVisual->Env().CanvasTextureCache().CreateCachedTextL(cachedtextParams,*iVisual); 
       
  1266 
       
  1267     if (IsRenderingEnabled())
       
  1268         {           
       
  1269         const CHuiTexture* texture = cachedImage->Texture();
       
  1270         if (texture)
       
  1271             {
       
  1272             AdjustCoordinates( aRect );
       
  1273             THuiRealRect destinationRect = aRect;                
       
  1274             
       
  1275             // Adjust destination rect according to the point where text was rasterised in the image
       
  1276             TInt dx = cachedImage->iRasterizationOffset.iX;
       
  1277             TInt dy = cachedImage->iRasterizationOffset.iY;        
       
  1278             destinationRect.Move(-dx,-dy);
       
  1279             
       
  1280             TRgb oldPenColor = iCanvasGc->PenColor();
       
  1281             if (cachedImage->iUseColorModulation)
       
  1282                 {
       
  1283                 DrawTextBrush( destinationRect );
       
  1284                 iCanvasGc->SetPenColor(ConvertToLinear(iWsPenColor));    
       
  1285                 }
       
  1286     
       
  1287             // Draw            
       
  1288             iCanvasGc->DrawImage(*texture, destinationRect, TRect(TPoint(0,0), texture->Size()), CHuiGc::EStretchNone);
       
  1289     
       
  1290             if (cachedImage->iUseColorModulation)
       
  1291                 {
       
  1292                 iCanvasGc->SetPenColor(oldPenColor);                        
       
  1293                 }
       
  1294             }
       
  1295         }
       
  1296     }
       
  1297 
       
  1298 void CHuiCanvasWsHwGc::WsDrawTextVertical4L(TPtr& aTextValue, TRect& aRect, TInt aBaselineOffset, TInt aTextUp, TInt aTextAlign, TInt aTextMargin,THuiCanvasTextParameters& aTextParameters)
       
  1299     {
       
  1300     TInt angle = aTextUp ? -90 : 90;
       
  1301 
       
  1302 
       
  1303     THuiCachedTextParams cachedtextParams;
       
  1304     cachedtextParams.iFindTextPtr = &aTextValue;
       
  1305     cachedtextParams.iFontHandle = iWsCurrentFont;
       
  1306     cachedtextParams.iTextParams = aTextParameters;
       
  1307     cachedtextParams.iTextBoxMaxSize = aRect.Size();
       
  1308     cachedtextParams.iAngle = angle;
       
  1309     cachedtextParams.iBaseLineOffset = aBaselineOffset;
       
  1310     cachedtextParams.iTextAlign = aTextAlign;
       
  1311     cachedtextParams.iMargin = aTextMargin;
       
  1312     cachedtextParams.iGcParams = CachedGcParams();
       
  1313 
       
  1314     const CHuiCanvasTextImage* cachedImage = iVisual->Env().CanvasTextureCache().CreateCachedTextL(cachedtextParams,*iVisual); 
       
  1315 
       
  1316     if (IsRenderingEnabled())
       
  1317         {           
       
  1318         const CHuiTexture* texture = cachedImage->Texture();
       
  1319         if (texture)
       
  1320             {
       
  1321             AdjustCoordinates( aRect );
       
  1322             THuiRealRect destinationRect = aRect;                
       
  1323             
       
  1324             // Adjust destination rect according to the point where text was rasterised in the image
       
  1325             TInt dx = cachedImage->iRasterizationOffset.iX;
       
  1326             TInt dy = cachedImage->iRasterizationOffset.iY;        
       
  1327             destinationRect.Move(-dx,-dy);
       
  1328             
       
  1329             TRgb oldPenColor = iCanvasGc->PenColor();
       
  1330             if (cachedImage->iUseColorModulation)
       
  1331                 {
       
  1332                 DrawTextBrush( destinationRect );
       
  1333                 iCanvasGc->SetPenColor(ConvertToLinear(iWsPenColor));    
       
  1334                 }
       
  1335     
       
  1336             // Draw            
       
  1337             iCanvasGc->DrawImage(*texture, destinationRect, TRect(TPoint(0,0), texture->Size()), CHuiGc::EStretchNone);
       
  1338     
       
  1339             if (cachedImage->iUseColorModulation)
       
  1340                 {
       
  1341                 iCanvasGc->SetPenColor(oldPenColor);                        
       
  1342                 }
       
  1343             }
       
  1344         }
       
  1345     }
       
  1346 
       
  1347 void CHuiCanvasWsHwGc::WsDrawTextVertical5L(TPtr& aTextValue, TRect& aRect, TInt aBaselineOffset, TInt aTextUp, TInt aTextAlign, TInt aTextMargin, TInt aTextWidth, THuiCanvasTextParameters& aTextParameters)
       
  1348     {
       
  1349 	TInt angle = aTextUp ? -90 : 90;
       
  1350 
       
  1351     THuiCachedTextParams cachedtextParams;
       
  1352     cachedtextParams.iFindTextPtr = &aTextValue;
       
  1353     cachedtextParams.iFontHandle = iWsCurrentFont;
       
  1354     cachedtextParams.iTextParams = aTextParameters;
       
  1355     cachedtextParams.iTextBoxMaxSize = aRect.Size();
       
  1356     cachedtextParams.iAngle = angle;
       
  1357     cachedtextParams.iTextWidth = aTextWidth;
       
  1358     cachedtextParams.iBaseLineOffset = aBaselineOffset;
       
  1359     cachedtextParams.iTextAlign = aTextAlign;
       
  1360     cachedtextParams.iMargin = aTextMargin;
       
  1361     cachedtextParams.iGcParams = CachedGcParams();
       
  1362 
       
  1363     const CHuiCanvasTextImage* cachedImage = iVisual->Env().CanvasTextureCache().CreateCachedTextL(cachedtextParams,*iVisual); 
       
  1364 
       
  1365     if (IsRenderingEnabled())
       
  1366         {           
       
  1367         const CHuiTexture* texture = cachedImage->Texture();
       
  1368         if (texture)
       
  1369             {
       
  1370             AdjustCoordinates( aRect );
       
  1371             THuiRealRect destinationRect = aRect;                
       
  1372             
       
  1373             // Adjust destination rect according to the point where text was rasterised in the image
       
  1374             TInt dx = cachedImage->iRasterizationOffset.iX;
       
  1375             TInt dy = cachedImage->iRasterizationOffset.iY;        
       
  1376             destinationRect.Move(-dx,-dy);
       
  1377             
       
  1378             TRgb oldPenColor = iCanvasGc->PenColor();
       
  1379             if (cachedImage->iUseColorModulation)
       
  1380                 {
       
  1381                 DrawTextBrush( destinationRect );
       
  1382                 iCanvasGc->SetPenColor(ConvertToLinear(iWsPenColor));    
       
  1383                 }
       
  1384     
       
  1385             // Draw            
       
  1386             iCanvasGc->DrawImage(*texture, destinationRect, TRect(TPoint(0,0), texture->Size()), CHuiGc::EStretchNone);
       
  1387     
       
  1388             if (cachedImage->iUseColorModulation)
       
  1389                 {
       
  1390                 iCanvasGc->SetPenColor(oldPenColor);                        
       
  1391                 }
       
  1392             }
       
  1393         }
       
  1394     }
       
  1395 
       
  1396 void CHuiCanvasWsHwGc::WsMoveToL( TPoint& aPoint)
       
  1397     {
       
  1398     iWsPenPosition = aPoint;
       
  1399     }
       
  1400 
       
  1401 void CHuiCanvasWsHwGc::WsMoveByL( TPoint& aPoint)
       
  1402     {
       
  1403     iWsPenPosition += aPoint;
       
  1404     }
       
  1405     
       
  1406 void CHuiCanvasWsHwGc::WsPlotL(TPoint& aPoint)
       
  1407 	{
       
  1408     if (IsRenderingEnabled())
       
  1409     	{
       
  1410         AdjustCoordinates( aPoint );
       
  1411 	    UseWsState();        
       
  1412         // Draw  
       
  1413         RArray<THuiRealPoint> points;
       
  1414         CleanupClosePushL(points);  
       
  1415         points.AppendL(THuiRealPoint(aPoint));       
       
  1416         iCanvasGc->DrawPoints(points);
       
  1417         CleanupStack::PopAndDestroy();
       
  1418         UseCanvasState();
       
  1419         }
       
  1420     }
       
  1421 
       
  1422 void CHuiCanvasWsHwGc::WsResetL()
       
  1423 	{
       
  1424 	iWsClipRegion.Clear();
       
  1425 	iWsCurrentFont = 0;
       
  1426 	iWsOrigin = KHuiWsDefaultOrigin;
       
  1427     iWsPenSize = KHuiWsDefaultPenSize;
       
  1428 
       
  1429 	iWsPenPosition = TPoint(0,0);
       
  1430 	iWsFadeColor = KHuiWsDefaultFadeColor;
       
  1431 
       
  1432     iWsPenColor = KHuiWsDefaultPenColor;
       
  1433     iWsBrushColor = KHuiWsDefaultBrushColor;
       
  1434     iWsPenStyle = KHuiWsDefaultPenStyle;
       
  1435     iWsDrawMode = KHuiWsDefaultDrawMode;
       
  1436     iWsBrushStyle = KHuiWsDefaultBrushStyle;
       
  1437     iWsShadowMode = KHuiWsDefaultShadowMode;
       
  1438     iWsStrikethrough = KHuiWsDefaultStrikethrough;
       
  1439     iWsUnderline = KHuiWsDefaultUnderline; 
       
  1440     iWsUserDisplayMode = KHuiWsDefaultUserDisplayMode;
       
  1441     iWsShadowColor = KHuiWsDefaultShadowColor;
       
  1442     iWsBrushPattern = 0;
       
  1443     iWsBrushOrigin = TPoint(0,0);
       
  1444 
       
  1445 
       
  1446   	iCanvasGc->CancelClipping();
       
  1447   	iCanvasGc->SetPenColor(KRgbWhite); 
       
  1448     iCanvasGc->SetOpacity(1.0);
       
  1449 	iCanvasGc->SetPenWidth(1); 
       
  1450 	}
       
  1451 
       
  1452 
       
  1453 
       
  1454 void CHuiCanvasWsHwGc::WsSetBrushColorL( TRgb aColor)
       
  1455     {
       
  1456     iWsBrushColor = aColor;
       
  1457     }
       
  1458 
       
  1459 void CHuiCanvasWsHwGc::WsSetBrushOriginL( TPoint& aPoint)
       
  1460     {
       
  1461     iWsBrushOrigin = aPoint;
       
  1462     }
       
  1463 
       
  1464 void CHuiCanvasWsHwGc::WsSetBrushStyleL( TInt aStyle)
       
  1465     {
       
  1466     iWsBrushStyle = aStyle;        
       
  1467     }
       
  1468 
       
  1469 void CHuiCanvasWsHwGc::WsSetClippingRegionL( RRegion& aRegion)
       
  1470     {
       
  1471     if (IsRenderingEnabled())
       
  1472         {
       
  1473         iWsClipRegion.Clear();    
       
  1474         for (TInt i=0;i<aRegion.Count();i++)
       
  1475             {
       
  1476             TRect rect = aRegion[i];
       
  1477             AdjustCoordinates( rect, EFalse );
       
  1478             iWsClipRegion.AddRect(rect);
       
  1479             }    
       
  1480         
       
  1481         iCanvasGc->ClipRegion(iWsClipRegion);                
       
  1482         }
       
  1483     }
       
  1484     
       
  1485 void CHuiCanvasWsHwGc::WsSetDrawModeL( TInt aDrawMode)
       
  1486 	{
       
  1487 	iWsDrawMode = aDrawMode;	
       
  1488 	}
       
  1489 
       
  1490 void CHuiCanvasWsHwGc::WsSetOriginL( TPoint& aOrigin)
       
  1491 	{
       
  1492  	iWsOrigin = aOrigin;
       
  1493 	}
       
  1494 
       
  1495 void CHuiCanvasWsHwGc::WsSetPenColorL( TRgb aColor)
       
  1496 	{
       
  1497 	iWsPenColor = aColor;
       
  1498 	}
       
  1499 
       
  1500 void CHuiCanvasWsHwGc::WsSetPenStyleL( TInt aStyle)
       
  1501 	{
       
  1502     iWsPenStyle = aStyle;
       
  1503 	}
       
  1504 
       
  1505 void CHuiCanvasWsHwGc::WsSetPenSizeL( TInt aWidth, TInt aHeight)
       
  1506 	{
       
  1507     iWsPenSize.iWidth = aWidth;
       
  1508     // Note, that only width is supported by HW renderer. Canvas should be draw in fallback mode, if width and height are not the same
       
  1509     iWsPenSize.iHeight = aHeight; 
       
  1510 	}
       
  1511 
       
  1512 void CHuiCanvasWsHwGc::WsSetTextShadowColorL( TRgb aColor)
       
  1513 	{
       
  1514  	iWsShadowColor = aColor;
       
  1515 	}
       
  1516 
       
  1517 void CHuiCanvasWsHwGc::WsSetCharJustificationL( TInt /*aExcessiveWidth*/, TInt /*aNumGap*/)
       
  1518 	{
       
  1519     // This is not supported by this CHuiCanvasWsGc implementation
       
  1520 	iAllCommandsSupported = EFalse;
       
  1521 	}
       
  1522 
       
  1523 void CHuiCanvasWsHwGc::WsSetWordJustificationL( TInt /*aExcessiveWidth*/, TInt /*aNumGap*/)
       
  1524 	{
       
  1525     // This is not supported by this CHuiCanvasWsGc implementation
       
  1526 	iAllCommandsSupported = EFalse;
       
  1527 	}
       
  1528 
       
  1529 void CHuiCanvasWsHwGc::WsSetUnderlineStyleL( TInt aValue )
       
  1530 	{
       
  1531     if (aValue < 1000) // magic, we recycle the same function for both underline and strike through
       
  1532         {
       
  1533         iWsUnderline = aValue;
       
  1534         }
       
  1535     else
       
  1536         {
       
  1537         iWsStrikethrough=aValue-1000;
       
  1538         }
       
  1539 	}
       
  1540 
       
  1541 void CHuiCanvasWsHwGc::WsSetBrushPatternL( TInt aValue )
       
  1542 	{
       
  1543 	iWsBrushPattern = aValue;
       
  1544 	}
       
  1545 
       
  1546 void CHuiCanvasWsHwGc::WsSetFontL( TInt aFontId)
       
  1547 	{
       
  1548 	iWsCurrentFont = aFontId;
       
  1549 	}
       
  1550 
       
  1551 void CHuiCanvasWsHwGc::WsCopyRectL( TPoint& /*aPoint*/, TRect& /*aRect*/)
       
  1552 	{
       
  1553     // This is not supported by this CHuiCanvasWsGc implementation
       
  1554 	iAllCommandsSupported = EFalse;
       
  1555 	}
       
  1556 
       
  1557 void CHuiCanvasWsHwGc::WsUpdateJustificationL( TPtr& /*aTextValue*/)
       
  1558 	{
       
  1559     // This is not supported by this CHuiCanvasWsGc implementation
       
  1560 	iAllCommandsSupported = EFalse;
       
  1561 	}
       
  1562 
       
  1563 void CHuiCanvasWsHwGc::WsUpdateJustificationVerticalL( TInt /*aValue*/, TPtr& /*aTextValue*/)
       
  1564 	{
       
  1565     // This is not supported by this CHuiCanvasWsGc implementation
       
  1566 	iAllCommandsSupported = EFalse;
       
  1567 	}
       
  1568 
       
  1569 void CHuiCanvasWsHwGc::WsSetFontNoDuplicateL( TInt aCurrentFont)
       
  1570 	{
       
  1571 	iWsCurrentFont = aCurrentFont;
       
  1572 	}
       
  1573 
       
  1574 void CHuiCanvasWsHwGc::WsCopySettingsL()
       
  1575 	{
       
  1576     // This is not supported by this CHuiCanvasWsGc implementation
       
  1577 	iAllCommandsSupported = EFalse;
       
  1578 	}
       
  1579 
       
  1580 void CHuiCanvasWsHwGc::WsSetClippingRectL( TRect& aRect)
       
  1581     {    
       
  1582     if (IsRenderingEnabled())
       
  1583         {
       
  1584         // Symbian SetClippingRect takes ws origin into account, 
       
  1585         // but setClippingRegion does not.
       
  1586         AdjustCoordinates( aRect, ETrue );
       
  1587         iTempRegion.Clear();
       
  1588         iTempRegion.AddRect( aRect );
       
  1589         iCanvasGc->ClipRegion( iTempRegion );
       
  1590         }
       
  1591     }
       
  1592 
       
  1593 void CHuiCanvasWsHwGc::WsCancelClippingRectL()
       
  1594     {
       
  1595     if (IsRenderingEnabled())
       
  1596         {
       
  1597         WsResetClippingRegionL();
       
  1598         iCanvasGc->CancelClipping();
       
  1599         }
       
  1600     }
       
  1601 
       
  1602 void CHuiCanvasWsHwGc::WsSetFadedL( TInt& /*aFaded*/)
       
  1603     {
       
  1604 	// Nothing to do, we should get FadeArea commands if window is faded.
       
  1605     }
       
  1606 
       
  1607 void CHuiCanvasWsHwGc::WsSetFadingParametersL( TInt aBlackMap, TInt aWhiteMap)
       
  1608     {
       
  1609     if (IsRenderingEnabled())
       
  1610         {
       
  1611 		if (aBlackMap > aWhiteMap)
       
  1612             {
       
  1613             TInt oldMap = aBlackMap;
       
  1614             aBlackMap = aWhiteMap;
       
  1615             aWhiteMap = oldMap;
       
  1616             }
       
  1617 
       
  1618         const TUint16* lut = PtrTo16BitNormalisationTable();
       
  1619         
       
  1620         //CFbsBitGc::FadeArea() does the following per color component:
       
  1621         //   dst = dst * (aWhiteMap - aBlackMap) + aBlackMap;
       
  1622     
       
  1623         //To achieve the same effect using MWsGraphicsContext we draw a rectangle
       
  1624         //with specific intensity and alpha values:
       
  1625         //   dst = dst * (1 - alpha) + intensity * alpha;
       
  1626         //Thus:
       
  1627         //   alpha = 1 - aWhiteMap + aBlackMap;
       
  1628         //   intensity = aBlackMap / alpha;
       
  1629     
       
  1630         // alpha = 1 - aWhiteMap + aBlackMap;
       
  1631         TInt alpha = 255 - aWhiteMap + aBlackMap;
       
  1632         // intensity = aBlackMap / alpha;
       
  1633         TInt i = (aBlackMap * lut[alpha]) >> 8;
       
  1634     
       
  1635         iWsFadeColor.SetInternal(i << 16 | i << 8 | i | alpha << 24); 
       
  1636         }
       
  1637     }
       
  1638 
       
  1639 void CHuiCanvasWsHwGc::WsFadeAreaL( RRegion& aRegion)
       
  1640     {
       
  1641     if (IsRenderingEnabled())
       
  1642         {
       
  1643         RArray<THuiRealRect> realRects;
       
  1644         for (TInt i=0; i<aRegion.Count();i++)
       
  1645             {
       
  1646             realRects.Append(aRegion[i]);
       
  1647             }
       
  1648         UseWsState();
       
  1649         // Get real color & opacity from fading params
       
  1650         TRgb fadeColor = iWsFadeColor;
       
  1651         // Opacity is given separately, so set alpha of the color to 255.   
       
  1652         fadeColor.SetAlpha(255); 
       
  1653         TReal32 opacity = TReal32(TReal32(iWsFadeColor.Alpha() / 255.f));
       
  1654         
       
  1655         // Draw semi transparent rect(s) over the visual faded areas
       
  1656         iCanvasGc->SetPenColor(fadeColor);
       
  1657         iCanvasGc->SetOpacity(opacity);    
       
  1658         iCanvasGc->SetPolygonDrawMode(EHuiFillNonZero);    
       
  1659         iCanvasGc->SetDrawMode(SelectCanvasDrawMode(iWsDrawMode));        
       
  1660 
       
  1661         iCanvasGc->DrawRects(realRects);
       
  1662         
       
  1663         UseCanvasState();
       
  1664             
       
  1665         realRects.Close();    
       
  1666         aRegion.Close();    
       
  1667         }
       
  1668     }
       
  1669 
       
  1670 void CHuiCanvasWsHwGc::WsMapColorsL()
       
  1671     {
       
  1672     // This is not supported by this CHuiCanvasWsGc implementation
       
  1673 	iAllCommandsSupported = EFalse;
       
  1674     }
       
  1675 
       
  1676 void CHuiCanvasWsHwGc::WsSetUserDisplayModeL( TInt aMode )
       
  1677     {
       
  1678     iWsUserDisplayMode = aMode;
       
  1679     }
       
  1680 
       
  1681 void CHuiCanvasWsHwGc::WsUseFontL(TInt aCurrentFont)
       
  1682     {
       
  1683     iWsCurrentFont = aCurrentFont;
       
  1684     }       
       
  1685 
       
  1686 void CHuiCanvasWsHwGc::BeginActionL(TInt aAction, TRect aDisplayRect, const CHuiCanvasVisual& aUser, TBool aIsCachePrepared, const TRegion& aUpdateRegion)
       
  1687 	{
       
  1688     iAction = aAction;
       
  1689     iVisual = (CHuiCanvasVisual*)&aUser;
       
  1690     iAllCommandsSupported = ETrue;
       
  1691 
       
  1692     if (aAction == EDrawBuffer)
       
  1693 	    {
       
  1694 	    BeginDrawL(aDisplayRect, aUser, aIsCachePrepared, aUpdateRegion);
       
  1695 	    }
       
  1696 	else if (aAction == EScanBuffer)
       
  1697 	    {
       
  1698         BeginScanL(aDisplayRect, aUser, aIsCachePrepared, aUpdateRegion);	    
       
  1699 	    }
       
  1700 	else
       
  1701 	    {
       
  1702 	    // Should not happen
       
  1703 	    }
       
  1704 	}
       
  1705 
       
  1706 void CHuiCanvasWsHwGc::EndActionL(const TRegion& aUpdateRegion, TBool aUpdateDisplay)
       
  1707 	{
       
  1708     if (iAction == EDrawBuffer)
       
  1709         {
       
  1710         EndDrawL(aUpdateRegion, aUpdateDisplay);
       
  1711         }
       
  1712     else if (iAction == EScanBuffer)
       
  1713         {
       
  1714         EndScanL(aUpdateRegion, aUpdateDisplay);
       
  1715         }
       
  1716     else
       
  1717         {
       
  1718         // Should not happen
       
  1719         }
       
  1720 	}
       
  1721 
       
  1722 void CHuiCanvasWsHwGc::BeginDrawL(TRect aDisplayRect,const CHuiCanvasVisual& aUser, TBool aIsCachePrepared, const TRegion& aUpdateRegion)
       
  1723     {
       
  1724     CHuiCanvasRenderBuffer* renderbuffer = NULL;
       
  1725     TRect updatedRect = aUpdateRegion.BoundingRect();
       
  1726     TBool renderBufferCreated = EFalse;
       
  1727     
       
  1728     // Try to get render buffer if it has been enabled
       
  1729     if (iRenderBufferEnabled && updatedRect.Size() != TSize(0,0))
       
  1730         {
       
  1731         renderbuffer = iVisual->Env().CanvasTextureCache().FindCachedRenderBuffer(aUser);
       
  1732         if (!renderbuffer)
       
  1733             {        
       
  1734             renderbuffer = iVisual->Env().CanvasTextureCache().CreateCachedRenderBufferL(aUser, updatedRect.Size());
       
  1735             renderBufferCreated = ETrue;
       
  1736             }
       
  1737         }
       
  1738     
       
  1739     if (renderbuffer)
       
  1740         {
       
  1741         // If renderbuffer is not initialized, set the internal flag to EFalse. It will be set
       
  1742         // to ETrue after drawing has been done.
       
  1743         if (!renderbuffer->IsInitialized() || renderbuffer->Size() != updatedRect.Size() || renderBufferCreated)
       
  1744             {
       
  1745             iRenderBufferInitialized = EFalse;
       
  1746             }
       
  1747         
       
  1748         // We can access render buffer, mark it to be available.
       
  1749         iRenderBufferAvailable = ETrue;
       
  1750         
       
  1751         // Render buffer is prepared if caller says that cache is prepared and renderbuffer has been initialized.
       
  1752         iRenderBufferPrepared = aIsCachePrepared && iRenderBufferInitialized;
       
  1753         }
       
  1754     else
       
  1755         {
       
  1756         // We could not access render buffer, mark it to be unavailable.
       
  1757         iRenderBufferAvailable = EFalse;
       
  1758         }
       
  1759         
       
  1760     // If render buffer is not prepared, we must prepare it. We will set the flag at EndActionL when
       
  1761     // we really have prepared it.
       
  1762     if (IsRenderBufferUpdateOngoing())
       
  1763         {        
       
  1764         // Init render buffer (it only really initializes if needed)
       
  1765         renderbuffer->InitializeL(updatedRect.Size());
       
  1766 
       
  1767         // Bind render buffer
       
  1768         BindRenderBuffer(renderbuffer, aUpdateRegion);
       
  1769         }
       
  1770     iCanvasGc->RestoreFlaggedState();
       
  1771     }
       
  1772 
       
  1773 void CHuiCanvasWsHwGc::BeginScanL(TRect aDisplayRect,const CHuiCanvasVisual& aUser, TBool aIsCachePrepared, const TRegion& aUpdateRegion)
       
  1774     {
       
  1775     CHuiCanvasRenderBuffer* renderbuffer = NULL;
       
  1776     TRect updatedRect = aUpdateRegion.BoundingRect();
       
  1777     TBool renderBufferCreated = EFalse;
       
  1778     
       
  1779     // Try to get render buffer if it has been enabled
       
  1780     if (iRenderBufferEnabled && updatedRect.Size() != TSize(0,0))
       
  1781         {
       
  1782         renderbuffer = iVisual->Env().CanvasTextureCache().FindCachedRenderBuffer(aUser);
       
  1783         if (!renderbuffer)
       
  1784             {        
       
  1785             renderbuffer = iVisual->Env().CanvasTextureCache().CreateCachedRenderBufferL(aUser, updatedRect.Size());
       
  1786             renderBufferCreated = ETrue;
       
  1787             }
       
  1788         }
       
  1789     
       
  1790     if (renderbuffer)
       
  1791         {
       
  1792         // If renderbuffer is not initialized, set the internal flag to EFalse. It will be set
       
  1793         // to ETrue after drawing has been done.
       
  1794         if (!renderbuffer->IsInitialized() || renderbuffer->Size() != updatedRect.Size() || renderBufferCreated)
       
  1795             {
       
  1796             iRenderBufferInitialized = EFalse;
       
  1797             }
       
  1798         
       
  1799         // We can access render buffer, mark it to be available.
       
  1800         iRenderBufferAvailable = ETrue;
       
  1801         
       
  1802         // Render buffer is prepared if caller says that cache is prepared and renderbuffer has been initialized.
       
  1803         iRenderBufferPrepared = aIsCachePrepared && iRenderBufferInitialized;
       
  1804         }
       
  1805     else
       
  1806         {
       
  1807         // We could not access render buffer, mark it to be unavailable.
       
  1808         iRenderBufferAvailable = EFalse;
       
  1809         }
       
  1810         
       
  1811     // If render buffer is not prepared, we must prepare it. We will set the flag at EndActionL when
       
  1812     // we really have prepared it.
       
  1813     if (IsRenderBufferUpdateOngoing())
       
  1814         {        
       
  1815         // Init render buffer (it only really initializes if needed)
       
  1816         renderbuffer->InitializeL(updatedRect.Size());
       
  1817         }
       
  1818 
       
  1819     iCanvasGc->RestoreFlaggedState();
       
  1820 	}
       
  1821 
       
  1822 void CHuiCanvasWsHwGc::EndDrawL(const TRegion& aUpdateRegion, TBool aUpdateDisplay)
       
  1823     {
       
  1824     CHuiCanvasRenderBuffer* renderbuffer = NULL;
       
  1825 
       
  1826     // Check if we have cached render buffer available
       
  1827     if (IsRenderBufferEnabled())
       
  1828         {
       
  1829         renderbuffer = iVisual->Env().CanvasTextureCache().FindCachedRenderBuffer(*iVisual);
       
  1830         }
       
  1831     
       
  1832     if (renderbuffer)
       
  1833         {
       
  1834         // We can access render buffer, mark it to be available.
       
  1835         iRenderBufferAvailable = ETrue;
       
  1836         }
       
  1837     else
       
  1838         {
       
  1839         // We could not access render buffer, mark it to be unavailable.
       
  1840         iRenderBufferAvailable = EFalse;        
       
  1841         }
       
  1842 
       
  1843     // Are we updating into render buffer
       
  1844     if (IsRenderBufferUpdateOngoing())
       
  1845         {            
       
  1846         // Are we rendering
       
  1847         UnBindRenderBuffer(renderbuffer);
       
  1848         // If we really did draw to the renderbuffer, then set it "prepared".
       
  1849         if (iCanvasGc->Gc())
       
  1850             {
       
  1851             iRenderBufferInitialized = ETrue;
       
  1852             iRenderBufferPrepared = ETrue;
       
  1853             }    
       
  1854         }
       
  1855 
       
  1856     iCanvasGc->RestoreFlaggedState();
       
  1857     
       
  1858     // Cancel clipping if still active etc...
       
  1859     iCanvasGc->SetDefaults();    
       
  1860 
       
  1861     // If render buffer is used, draw its content to display here
       
  1862     if (aUpdateDisplay && renderbuffer && iCanvasGc->Gc())
       
  1863         {
       
  1864         THuiRealRect updatedRect = aUpdateRegion.BoundingRect();
       
  1865 
       
  1866         // Handle relative rotation
       
  1867         TRect displayArea = iVisual->Display()->VisibleArea();
       
  1868         TInt w = displayArea.Width();
       
  1869         TInt h = displayArea.Height();
       
  1870                 
       
  1871         // ...select right rotation...
       
  1872         if (iRelativeOrientation == CHuiGc::EOrientationCW90)
       
  1873             {
       
  1874             // Rotate around origo and move back to displayarea
       
  1875             iCanvasGc->Rotate(-90, 0, 0, 1.f);
       
  1876             iCanvasGc->Translate(-h, 0, 0);
       
  1877             }
       
  1878         else if (iRelativeOrientation == CHuiGc::EOrientationCCW90)
       
  1879             {
       
  1880             // Rotate around origo and move back to displayarea
       
  1881             iCanvasGc->Rotate(90, 0, 0, 1.f);
       
  1882             iCanvasGc->Translate(0, -w, 0);
       
  1883             }
       
  1884         else if (iRelativeOrientation == CHuiGc::EOrientation180)
       
  1885             {
       
  1886             // Rotate around origo and move back to displayarea
       
  1887             iCanvasGc->Rotate(180, 0, 0, 1.f);
       
  1888             iCanvasGc->Translate(-w, -h, 0);            
       
  1889             }
       
  1890         else
       
  1891             {
       
  1892             // Nothing
       
  1893             }            
       
  1894         
       
  1895         iCanvasGc->ClipRegion(aUpdateRegion);
       
  1896         THuiCanvasDrawMode dmode = iCanvasGc->DrawMode();
       
  1897         // blend only transparent windows
       
  1898         if ((iVisual->Flags() & EHuiVisualFlagOpaqueHint) && !(iVisual->EffectiveOpacity() < 1.0f))
       
  1899             {
       
  1900             iCanvasGc->SetDrawMode(EHuiCanvasDrawModeNormal);
       
  1901             }
       
  1902         else
       
  1903             {
       
  1904             iCanvasGc->SetDrawMode(EHuiCanvasDrawModeBlend);
       
  1905             }
       
  1906         
       
  1907         iCanvasGc->DrawImage(*renderbuffer, updatedRect.iTl);
       
  1908         iCanvasGc->CancelClipping();
       
  1909         iCanvasGc->SetDrawMode(dmode);
       
  1910         }    
       
  1911     }
       
  1912 
       
  1913 void CHuiCanvasWsHwGc::EndScanL(const TRegion& aUpdateRegion, TBool aUpdateDisplay)
       
  1914     {
       
  1915     CHuiCanvasRenderBuffer* renderbuffer = NULL;
       
  1916 
       
  1917     // Check if we have cached render buffer available
       
  1918     if (IsRenderBufferEnabled())
       
  1919         {
       
  1920         renderbuffer = iVisual->Env().CanvasTextureCache().FindCachedRenderBuffer(*iVisual);
       
  1921         }
       
  1922     
       
  1923     if (renderbuffer)
       
  1924         {
       
  1925         // We can access render buffer, mark it to be available.
       
  1926         iRenderBufferAvailable = ETrue;
       
  1927         }
       
  1928     else
       
  1929         {
       
  1930         // We could not access render buffer, mark it to be unavailable.
       
  1931         iRenderBufferAvailable = EFalse;        
       
  1932         }
       
  1933     
       
  1934     // Cancel clipping if still active etc...
       
  1935     iCanvasGc->RestoreFlaggedState();
       
  1936     iCanvasGc->SetDefaults();    
       
  1937     }
       
  1938 
       
  1939 
       
  1940 CHuiCanvasGc& CHuiCanvasWsHwGc::CanvasGc() const
       
  1941 	{
       
  1942 	return *iCanvasGc;	
       
  1943 	}
       
  1944 	
       
  1945 THuiCachedGcParams CHuiCanvasWsHwGc::CachedGcParams()
       
  1946     {
       
  1947     THuiCachedGcParams params;
       
  1948     params.iPenColor = iWsPenColor;    
       
  1949     params.iBrushColor = iWsBrushColor;
       
  1950     params.iPenStyle = iWsPenStyle;
       
  1951     params.iDrawMode = iWsDrawMode;
       
  1952     params.iBrushColor = iWsBrushColor;
       
  1953     params.iBrushStyle = iWsBrushStyle;
       
  1954     params.iShadowMode = iWsShadowMode;
       
  1955     params.iStrikethrough = iWsStrikethrough;
       
  1956     params.iUnderline = iWsUnderline;
       
  1957     params.iUserDisplayMode = iWsUserDisplayMode;
       
  1958     params.iShadowColor = iWsShadowColor;
       
  1959     return params;        
       
  1960     }
       
  1961 
       
  1962 TInt CHuiCanvasWsHwGc::SetCapturingBufferL(CFbsBitmap* /*aTarget*/)
       
  1963     {
       
  1964     // This implementation does not support capturing
       
  1965     return KErrNotSupported;    
       
  1966     }
       
  1967 
       
  1968 void CHuiCanvasWsHwGc::SetPositionDelta( TPoint& aPoint )
       
  1969     {
       
  1970     iPosDelta = aPoint;
       
  1971     }
       
  1972 
       
  1973 TRect CHuiCanvasWsHwGc::RoundedDisplayRect()
       
  1974     {
       
  1975     if (iVisual)
       
  1976         {
       
  1977         return iVisual->DisplayRect().Round();    
       
  1978         }
       
  1979     else
       
  1980         {
       
  1981         return TRect(0,0,0,0);    
       
  1982         }            
       
  1983     }
       
  1984 
       
  1985 void CHuiCanvasWsHwGc::ClearCache()
       
  1986     {
       
  1987     if (iVisual)
       
  1988         {
       
  1989         iVisual->Env().CanvasTextureCache().ReleaseCachedRenderBuffer(*iVisual);
       
  1990         }
       
  1991     }    
       
  1992 
       
  1993 TBool CHuiCanvasWsHwGc::IsRenderBufferEnabled() const
       
  1994     {
       
  1995     return iRenderBufferEnabled && iRenderBufferAvailable;
       
  1996     }
       
  1997 
       
  1998 TBool CHuiCanvasWsHwGc::IsRenderBufferPrepared() const
       
  1999     {
       
  2000     return iRenderBufferEnabled && iRenderBufferAvailable && iRenderBufferPrepared;    
       
  2001     }
       
  2002 
       
  2003 TBool CHuiCanvasWsHwGc::IsRenderBufferInitialized() const
       
  2004     {
       
  2005     return iRenderBufferEnabled && iRenderBufferAvailable && iRenderBufferInitialized;    
       
  2006     }
       
  2007 
       
  2008 
       
  2009 TBool CHuiCanvasWsHwGc::IsRenderingEnabled() const
       
  2010     {
       
  2011     if (iAction == EDrawBuffer)
       
  2012         {
       
  2013         return ETrue;
       
  2014         }
       
  2015     else if (iAction == EScanBuffer)
       
  2016         {
       
  2017         return EFalse;
       
  2018         }
       
  2019     else
       
  2020         {
       
  2021         return EFalse;
       
  2022         }
       
  2023     }
       
  2024 
       
  2025 TBool CHuiCanvasWsHwGc::IsRenderBufferUpdateOngoing() const
       
  2026     {
       
  2027     return iRenderBufferEnabled && iRenderBufferAvailable && !iRenderBufferPrepared;
       
  2028     }
       
  2029 
       
  2030 
       
  2031 TInt CHuiCanvasWsHwGc::EnableRenderbuffer(TBool aEnable)
       
  2032     {
       
  2033     // TODO: Some renderers should return KErrNotSupported
       
  2034     TInt retVal = KErrNone;
       
  2035     iRenderBufferEnabled = aEnable;
       
  2036     return retVal;
       
  2037     }
       
  2038 
       
  2039 THuiCanvasWsGcType CHuiCanvasWsHwGc::Type() const
       
  2040     {
       
  2041     return EHuiCanvasWsHw;
       
  2042     }
       
  2043 
       
  2044 THuiCanvasDrawMode CHuiCanvasWsHwGc::SelectCanvasDrawMode(TInt aWsDrawMode)
       
  2045     {
       
  2046     if (aWsDrawMode == MWsGraphicsContext::EDrawModeWriteAlpha)
       
  2047         {
       
  2048         return EHuiCanvasDrawModeNormal;            
       
  2049         }
       
  2050     else
       
  2051         {
       
  2052          return EHuiCanvasDrawModeBlend;
       
  2053         }    
       
  2054     }
       
  2055 
       
  2056 void CHuiCanvasWsHwGc::EnableUpdateRegion(const TRegion& aUpdateRegion, TBool aClear)
       
  2057     {
       
  2058     CHuiGc* gc = iCanvasGc->Gc(); 
       
  2059     if (gc && IsRenderingEnabled())
       
  2060         {
       
  2061         gc->Enable(CHuiGc::EFeatureClipping);
       
  2062         gc->PushClip();
       
  2063         gc->Clip(aUpdateRegion);
       
  2064         if (aClear)
       
  2065             {
       
  2066             TInt oldAlpha = gc->PenAlpha();
       
  2067             TRgb oldColor = gc->PenColor();            
       
  2068             gc->SetPenAlpha(0);
       
  2069             gc->SetPenColor(KRgbBlue);
       
  2070             gc->Clear(); 
       
  2071             gc->SetPenAlpha(oldAlpha);
       
  2072             gc->SetPenColor(oldColor);
       
  2073             }
       
  2074         }
       
  2075     }
       
  2076 
       
  2077 void CHuiCanvasWsHwGc::DisableUpdateRegion()
       
  2078     {
       
  2079     CHuiGc* gc = iCanvasGc->Gc(); 
       
  2080     if (gc && IsRenderingEnabled())
       
  2081         {    
       
  2082         gc->PopClip();
       
  2083         }
       
  2084     }
       
  2085 
       
  2086 void CHuiCanvasWsHwGc::BindRenderBuffer(CHuiCanvasRenderBuffer* aRenderbuffer, const TRegion& aUpdateRegion)
       
  2087     {
       
  2088     // Disable effective opacity when rendering to a buffer
       
  2089     iCanvasGc->EnableEffectiveOpacity(EFalse);
       
  2090     
       
  2091     THuiRealRect updatedRect = aUpdateRegion.BoundingRect();
       
  2092 
       
  2093     // Bind render buffer as rendering target (further drawing will be redirected to render buffer)
       
  2094     aRenderbuffer->Bind();
       
  2095 
       
  2096     // Restore gc state after render target bind/unbind ops
       
  2097     iCanvasGc->RestoreState();
       
  2098 
       
  2099     // Translation values
       
  2100     TReal32 x = -updatedRect.iTl.iX;
       
  2101     TReal32 y = -updatedRect.iTl.iY;  
       
  2102     
       
  2103     // Push clipping so that we can restore it after we have done drawing into render buffer.
       
  2104     iCanvasGc->Gc()->PushClip();
       
  2105     
       
  2106     // Set new clipping region which does not clip anything. 
       
  2107     // We want always draw aUpdateRegion fully to the aRenderbuffer. 
       
  2108     TRect displayArea = iCanvasGc->Gc()->DisplayArea(); 
       
  2109     iCanvasGc->Gc()->SetClip(displayArea); // this call does not transform region anymore
       
  2110     
       
  2111     // We use translation to get screen coordinates to match render buffer coordinates
       
  2112     iCanvasGc->PushTransformationMatrix();
       
  2113     iCanvasGc->Translate(x, y, 0.f);
       
  2114         
       
  2115     // Handle relative rotation
       
  2116     TInt w = displayArea.Width();
       
  2117     TInt h = displayArea.Height();
       
  2118     
       
  2119     // ...select right rotation...
       
  2120     if (iRelativeOrientation == CHuiGc::EOrientationCW90)
       
  2121         {
       
  2122         // Rotate around origo and move back to displayarea
       
  2123         iCanvasGc->Rotate(-90, 0, 0, 1.f);
       
  2124         iCanvasGc->Translate(-h, 0, 0);
       
  2125         }
       
  2126     else if (iRelativeOrientation == CHuiGc::EOrientationCCW90)
       
  2127         {
       
  2128         // Rotate around origo and move back to displayarea
       
  2129         iCanvasGc->Rotate(90, 0, 0, 1.f);
       
  2130         iCanvasGc->Translate(0, -w, 0);
       
  2131         }
       
  2132     else if (iRelativeOrientation == CHuiGc::EOrientation180)
       
  2133         {
       
  2134         // Rotate around origo and move back to displayarea
       
  2135         iCanvasGc->Rotate(180, 0, 0, 1.f);
       
  2136         iCanvasGc->Translate(-w, -h, 0);            
       
  2137         }
       
  2138     else
       
  2139         {
       
  2140         // Nothing
       
  2141         }            
       
  2142         
       
  2143     // Set needed clip region
       
  2144     iCanvasGc->Gc()->Clip(aUpdateRegion);
       
  2145     }
       
  2146 
       
  2147 void CHuiCanvasWsHwGc::UnBindRenderBuffer(CHuiCanvasRenderBuffer* aRenderbuffer)
       
  2148     {
       
  2149     // Enable effective opacity again when no more rendering to buffer
       
  2150     iCanvasGc->EnableEffectiveOpacity(ETrue);
       
  2151 
       
  2152     // Restore translation (screen coordinates to match render buffer coordinates)
       
  2153     iCanvasGc->PopTransformationMatrix();
       
  2154 
       
  2155     // Restore clipping 
       
  2156     iCanvasGc->Gc()->PopClip();
       
  2157             
       
  2158     // Unbind render buffer as rendering target (further drawing will be done to display normally) 
       
  2159     aRenderbuffer->UnBind();
       
  2160     
       
  2161     // Restore gc state after render target bind/unbind ops
       
  2162     iCanvasGc->RestoreState();
       
  2163     }
       
  2164 
       
  2165 void CHuiCanvasWsHwGc::SetRelativeOrientation(CHuiGc::TOrientation aOrientation)
       
  2166     {
       
  2167     iRelativeOrientation = aOrientation;
       
  2168     }
       
  2169 
       
  2170 
       
  2171 void CHuiCanvasWsHwGc::UseBrushPattern()
       
  2172     {
       
  2173     THuiCachedImageParams cachedImageParams;
       
  2174     cachedImageParams.iBitmapHandle = iWsBrushPattern;
       
  2175     cachedImageParams.iGcParams = CachedGcParams();    
       
  2176 
       
  2177     const CHuiCanvasGraphicImage* cachedImage = iVisual->Env().CanvasTextureCache().CreateCachedImageL(cachedImageParams,*iVisual);    
       
  2178     if (IsRenderingEnabled())
       
  2179         {
       
  2180         iCanvasGc->SetPolygonFillTexture(cachedImage->Texture());
       
  2181         // Symbian implementation for CWindowGc is different from CFbsBitGc. Latter
       
  2182         // adds iWsOrigin to iWsBrushOrigin, but because we are implementing
       
  2183         // CWindowGc, we do not take iWsOrigin into account here.
       
  2184         iCanvasGc->SetPolygonFillTextureOrigin(iWsBrushOrigin); 
       
  2185         }
       
  2186     }
       
  2187 
       
  2188 void CHuiCanvasWsHwGc::DiscardBrushPattern()
       
  2189     {
       
  2190     if (IsRenderingEnabled())
       
  2191         {
       
  2192         iCanvasGc->SetPolygonFillTexture(NULL);
       
  2193         iCanvasGc->SetPolygonFillTextureOrigin(TPoint(0,0));
       
  2194         }
       
  2195     }
       
  2196 
       
  2197 TBool CHuiCanvasWsHwGc::IsDifferent(const TRgb& aFirst, const TRgb& aSecond, TBool aIgnoreAlpha)
       
  2198     {
       
  2199     if (aIgnoreAlpha)
       
  2200         {
       
  2201         const TUint32 mask = 0x00FFFFFF;
       
  2202         return ((aFirst.Internal() & mask) != (aSecond.Internal() & mask));
       
  2203         }
       
  2204     else
       
  2205         {
       
  2206         return (aFirst.Internal() != aSecond.Internal());
       
  2207         }    
       
  2208     }
       
  2209 
       
  2210 void CHuiCanvasWsHwGc::UseWsState()
       
  2211     {
       
  2212 #ifdef __WINS__
       
  2213     iPushCount++;
       
  2214     if(iPushCount>1)
       
  2215         {
       
  2216         // This function cannot be called recursively. Fix your code.
       
  2217         USER_INVARIANT();
       
  2218         }
       
  2219 #endif    
       
  2220     iOldColor = iCanvasGc->PenColor();            
       
  2221     iOldOpacity = iCanvasGc->Opacity();
       
  2222     iOldDrawMode = iCanvasGc->DrawMode();
       
  2223     iOldPenWidth = iCanvasGc->PenWidth(); 
       
  2224     iOldPolygonDrawMode = iCanvasGc->PolygonDrawMode();
       
  2225     
       
  2226     iCanvasGc->SetPenColor(iWsPenColor);
       
  2227     iCanvasGc->SetOpacity(TReal32(iWsPenColor.Alpha() / 255.f));
       
  2228     iCanvasGc->SetDrawMode(SelectCanvasDrawMode(iWsDrawMode));
       
  2229     iCanvasGc->SetPenWidth(iWsPenSize.iWidth);
       
  2230     iCanvasGc->PolygonDrawMode();
       
  2231     }
       
  2232 
       
  2233 void CHuiCanvasWsHwGc::UseCanvasState()
       
  2234     {
       
  2235 #ifdef __WINS__
       
  2236     iPushCount--;
       
  2237     if(iPushCount!=0)
       
  2238         {
       
  2239         // This function cannot be called recursively. Fix your code.
       
  2240         USER_INVARIANT();
       
  2241         }
       
  2242 #endif
       
  2243     iCanvasGc->SetPenColor(iOldColor);            
       
  2244     iCanvasGc->SetOpacity(iOldOpacity);
       
  2245     iCanvasGc->SetDrawMode(iOldDrawMode);
       
  2246     iCanvasGc->SetPenWidth(iOldPenWidth);
       
  2247     iCanvasGc->SetPolygonDrawMode(iOldPolygonDrawMode);
       
  2248     }