uiacceltk/hitchcock/coretoolkit/src/huicanvaswsbitgc.cpp
changeset 0 15bf7259bb7c
child 8 10534483575f
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 CHuiCanvasWsBitGc.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "huicanvaswsbitgc.h"
       
    21 #include "uiacceltk/HuiCanvasVisual.h"
       
    22 #include <graphics/wsgraphicscontext.h>
       
    23 #include <e32cmn.h>
       
    24 #include <AknLayoutFont.h>
       
    25 #include <gdi.h>
       
    26 
       
    27 
       
    28 
       
    29 CHuiCanvasWsBitGc* CHuiCanvasWsBitGc::NewL()
       
    30 	{
       
    31 	CHuiCanvasWsBitGc* self    = new ( ELeave ) CHuiCanvasWsBitGc;
       
    32     CleanupStack::PushL( self );
       
    33     self->ConstructL();
       
    34     CleanupStack::Pop();
       
    35 
       
    36     return self;
       
    37     }
       
    38 
       
    39 
       
    40 CHuiCanvasWsBitGc::CHuiCanvasWsBitGc()
       
    41     {
       
    42     
       
    43     }
       
    44 
       
    45 void CHuiCanvasWsBitGc::ConstructL()
       
    46 	{
       
    47 	CHuiCanvasWsSwGc::ConstructL();
       
    48 	}
       
    49 
       
    50 CHuiCanvasWsBitGc::~CHuiCanvasWsBitGc()
       
    51     {
       
    52     }
       
    53     
       
    54 
       
    55 void CHuiCanvasWsBitGc::BeginActionL(TInt aAction, TRect /*aDisplayRect*/, const CHuiCanvasVisual& aUser, TBool aIsCachePrepared, const TRegion& aUpdateRegion)
       
    56 	{
       
    57 	iAction = aAction;
       
    58 	iVisual = &aUser;
       
    59 
       
    60     if (!iVisual)
       
    61         {
       
    62         return;    
       
    63         }        
       
    64 
       
    65     // Update area is in screen coordinates so we must convert it 
       
    66     iDefaultClipRegion.Clear();
       
    67     for (TInt i=0; i < aUpdateRegion.Count(); i++)
       
    68         {
       
    69         iDefaultClipRegion.AddRect(AdjustCoordinates(aUpdateRegion[i]));   
       
    70         }
       
    71     
       
    72     TSize size = RoundedDisplayRect().Size();	
       
    73 
       
    74     // We create buffer only in drawing phase to reduce memory consumption.
       
    75     TBool recreateBackbuffer = 
       
    76         ( iAction == EDrawBuffer ) && 
       
    77         ( !iBitGc || ( iBitBitmap && iBitBitmap->SizeInPixels() != size ) );
       
    78     
       
    79     // If this is first draw or size has changed, re-create backbuffer
       
    80 	if (recreateBackbuffer)
       
    81 		{				    	
       
    82 		iBitmapInitialized = EFalse;
       
    83 		
       
    84 		if (!iBitBitmap)
       
    85             {
       
    86             iBitBitmap = new (ELeave) CFbsBitmap;
       
    87             iBitBitmap->Create(size, SelectDisplayMode());  
       
    88             }
       
    89         else
       
    90             {
       
    91             iBitBitmap->Resize(size);    
       
    92             }    
       
    93 	    
       
    94         if (!iBitDevice)
       
    95             {
       
    96             iBitDevice = CFbsBitmapDevice::NewL(iBitBitmap);        
       
    97             }
       
    98         else
       
    99             {
       
   100             iBitDevice->Resize(size);    
       
   101             }    
       
   102 
       
   103 	    delete iBitGc;
       
   104 	    iBitGc = NULL;
       
   105 	    User::LeaveIfError(iBitDevice->CreateContext(iBitGc));
       
   106         
       
   107         TRgb clearColor = KRgbWhite;
       
   108 	    clearColor.SetAlpha(0x0);
       
   109         
       
   110 	    iBitGc->SetDrawMode(CGraphicsContext::EDrawModeWriteAlpha);
       
   111         iBitGc->SetPenColor(clearColor);
       
   112         iBitGc->SetBrushColor(clearColor);
       
   113         iBitGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   114   	    iBitGc->Clear();
       
   115   	    iBitGc->Reset();    	  
       
   116   	    
       
   117   	    iIsReallyDirty = EFalse;
       
   118 		}
       
   119 	
       
   120     if (iBitGc)
       
   121         {
       
   122         iBitGc->Reset();
       
   123         }
       
   124     
       
   125     iBitmapPrepared = aIsCachePrepared && iBitmapInitialized;
       
   126 	}
       
   127 
       
   128 // Note that for perfomance reasons we keep iBitBitmap alive in this method   
       
   129 void CHuiCanvasWsBitGc::EndActionL(const TRegion& aUpdateRegion, TBool aUpdateDisplay)
       
   130 	{
       
   131     if (!iBitBitmap || !iVisual)
       
   132         {
       
   133         return;    
       
   134         }        
       
   135 
       
   136     // Update internal state - drawing finished
       
   137     if ( iAction == EDrawBuffer )
       
   138         {
       
   139         iBitmapInitialized = ETrue;
       
   140         iBitmapPrepared = ETrue;
       
   141         }
       
   142 
       
   143     // If capturing is used, then copy content from bitmap.
       
   144     if (iCapturingBitGc && aUpdateDisplay && iIsReallyDirty && iAction == EDrawBuffer)
       
   145         {
       
   146         iCapturingBitGc->Reset();
       
   147         
       
   148         // blend only transparent windows
       
   149         if (iVisual->Flags() & EHuiVisualFlagOpaqueHint)
       
   150             {
       
   151             iCapturingBitGc->SetDrawMode(CGraphicsContext::EDrawModeWriteAlpha);
       
   152             }
       
   153         else
       
   154             {
       
   155             iCapturingBitGc->SetDrawMode(CGraphicsContext::EDrawModePEN);
       
   156             }
       
   157         
       
   158         iCapturingBitGc->SetClippingRegion(aUpdateRegion);
       
   159         
       
   160         TSize visualSize = iVisual->DisplayRect().Size().Round();        
       
   161         if (iCapturingBitBitmap->SizeInPixels() != visualSize)
       
   162             {       
       
   163             iCapturingBitGc->BitBlt(iVisual->DisplayRect().iTl.Round(), iBitBitmap);
       
   164             }
       
   165         else
       
   166             {
       
   167             // Old capturing functionality, althoug not really used we support that as well
       
   168             iCapturingBitGc->BitBlt(TPoint(0,0), iBitBitmap);
       
   169             }
       
   170         
       
   171         iCapturingBitGc->CancelClippingRegion();
       
   172         }
       
   173 
       
   174     // Content is not drawn anywhere (except to to capturing bitgc)
       
   175 	}
       
   176 
       
   177 	
       
   178 THuiCanvasWsGcType CHuiCanvasWsBitGc::Type() const
       
   179     {
       
   180     return EHuiCanvasWsBit;
       
   181     }
       
   182 
       
   183 
       
   184 void CHuiCanvasWsBitGc::ClearCache()
       
   185     {
       
   186     // ClearCache is called when we can release,
       
   187     // e.g. when window is hidden by another opaque window.
       
   188     // So now we must release bitmaps in order to free
       
   189     // memory.
       
   190     iBitmapPrepared = EFalse; 
       
   191     iBitmapInitialized = EFalse;
       
   192 
       
   193     delete iBitGc;
       
   194     iBitGc = NULL;
       
   195     
       
   196     delete iBitDevice;
       
   197     iBitDevice = NULL;
       
   198     
       
   199     delete iBitBitmap;
       
   200     iBitBitmap = NULL;
       
   201     }
       
   202 
       
   203 
       
   204 TBool CHuiCanvasWsBitGc::IsRenderBufferEnabled() const
       
   205     {
       
   206     return ETrue;
       
   207     }