uiacceltk/hitchcock/coretoolkit/src/HuiCanvasCmdBufferReader.cpp
changeset 0 15bf7259bb7c
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     1 /*
       
     2 * Copyright (c) 2006-2008 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "uiacceltk/HuiCanvasCmdBufferReader.h"
       
    21 #include "uiacceltk/HuiUtil.h"
       
    22 
       
    23 // ---------------------------------------------------------------------------
       
    24 // Constructor
       
    25 // ---------------------------------------------------------------------------
       
    26 //
       
    27 CHuiCanvasCmdBufferReader::CHuiCanvasCmdBufferReader()
       
    28     {	    
       
    29     }
       
    30 
       
    31 // ---------------------------------------------------------------------------
       
    32 // Destructor
       
    33 // ---------------------------------------------------------------------------
       
    34 //
       
    35 CHuiCanvasCmdBufferReader::~CHuiCanvasCmdBufferReader()
       
    36     {
       
    37     iStream.Close();	
       
    38     
       
    39     delete iCachedText;
       
    40     }
       
    41     
       
    42 // ---------------------------------------------------------------------------
       
    43 // InitL
       
    44 // ---------------------------------------------------------------------------
       
    45 //
       
    46 void CHuiCanvasCmdBufferReader::Init( TPtr8& aDes,TInt aLength)
       
    47     {
       
    48     iStream.Close();
       
    49     if (aDes.Ptr())
       
    50         {
       
    51         iStream.Open( aDes.Ptr(), aLength );
       
    52 		delete iCachedText;
       
    53         iCachedText = NULL;
       
    54         iBasePtr = &aDes;
       
    55 #ifdef _DEBUG
       
    56         iBufferIndex = 0;
       
    57         iBufferLength = aLength;
       
    58 #endif
       
    59         }
       
    60     }
       
    61 
       
    62 // ---------------------------------------------------------------------------
       
    63 // ReadInt32L
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 void CHuiCanvasCmdBufferReader::ReadInt32L( TInt& aValue )
       
    67         {
       
    68         aValue = iStream.ReadInt32L();
       
    69 #ifdef _DEBUG
       
    70     iBufferIndex += sizeof(TInt32);
       
    71 #endif
       
    72         }
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // ReadPointL
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 void CHuiCanvasCmdBufferReader::ReadPointL( TPoint& aPoint )
       
    79     {
       
    80     iStream.ReadL( (TUint8*)&(aPoint.iX), sizeof( TInt32 ) * 2 );
       
    81     }
       
    82 // ---------------------------------------------------------------------------
       
    83 // ReadRectL
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 void CHuiCanvasCmdBufferReader::ReadRectL( TRect& aRect )
       
    87     {
       
    88     iStream.ReadL( (TUint8*)&(aRect.iTl.iX), sizeof( TInt32) * 4 );
       
    89     }
       
    90 
       
    91 // ---------------------------------------------------------------------------
       
    92 // ReadBitmapLC
       
    93 // ---------------------------------------------------------------------------
       
    94 //
       
    95 void CHuiCanvasCmdBufferReader::ReadBitmapLC( CFbsBitmap*& aBitmap )
       
    96     {
       
    97     TInt uid;
       
    98     ReadInt32L( uid );
       
    99     aBitmap = new(ELeave)CFbsBitmap;
       
   100     CleanupStack::PushL( aBitmap );
       
   101     
       
   102     //TODO:Bitmap cache, check if bitmap is already in cache. Avoid call to Duplicate
       
   103     //TODO: Cache needs to remove stuff, if not used.
       
   104     
       
   105     aBitmap->Duplicate( uid );
       
   106     }
       
   107 
       
   108 // ---------------------------------------------------------------------------
       
   109 // ReadBitmapHandleL
       
   110 // ---------------------------------------------------------------------------
       
   111 //
       
   112 void CHuiCanvasCmdBufferReader::ReadBitmapHandleL( TInt& aBitmapHandle  )
       
   113     {
       
   114     aBitmapHandle = iStream.ReadInt32L();        
       
   115     }
       
   116      
       
   117 // ---------------------------------------------------------------------------
       
   118 // ReadTextL
       
   119 // ---------------------------------------------------------------------------
       
   120 //
       
   121 TBool CHuiCanvasCmdBufferReader::ReadTextL( TPtr& aText , THuiCanvasTextParameters& aTextParameters )
       
   122     {
       
   123     TInt length = 0;
       
   124     TBool useCachedText = iStream.ReadInt8L();
       
   125     if ( !useCachedText )
       
   126         {
       
   127         length = iStream.ReadInt32L() / 2 ;
       
   128         TInt startPadding = iStream.ReadInt8L();
       
   129         TInt endPadding = iStream.ReadInt8L();
       
   130 
       
   131         TInt offset = iStream.Source()->TellL( MStreamBuf::ERead ).Offset() + startPadding;
       
   132         TPtr16 ptr = TPtr16( (TUint16*)( (TInt)iBasePtr->Ptr() + offset ), length, length );
       
   133         aText.Set( ptr );
       
   134 
       
   135         iStream.Source()->SeekL( MStreamBuf::ERead, TStreamPos( offset + length * 2 + endPadding ));
       
   136         if ( !iCachedText )
       
   137             {
       
   138             iCachedText = new(ELeave)TPtr16( ptr );
       
   139             }
       
   140         else
       
   141             {
       
   142             iCachedText->Set( ptr );
       
   143             }
       
   144         }
       
   145     else 
       
   146         {
       
   147         aText.Set( *iCachedText );
       
   148         }
       
   149     TInt8 textParameters = iStream.ReadInt8L();
       
   150     switch ( textParameters )
       
   151         {
       
   152         case 1:
       
   153             {
       
   154             // Is there text parameters
       
   155             aTextParameters.iStart = iStream.ReadInt32L();
       
   156             aTextParameters.iEnd = iStream.ReadInt32L();
       
   157             aTextParameters.iFlags = iStream.ReadUint16L();
       
   158             if ( aTextParameters.iStart >= aTextParameters.iEnd )
       
   159                 {
       
   160                 return EFalse;
       
   161                 }
       
   162             break;
       
   163             }
       
   164         case 2:
       
   165             {
       
   166             aTextParameters.iStart = 0;
       
   167             aTextParameters.iEnd = length / 2;
       
   168             aTextParameters.iFlags = 0;
       
   169             break;
       
   170             }
       
   171         default: // 0
       
   172             {
       
   173             aTextParameters.iStart = 0;
       
   174             aTextParameters.iEnd = KMaxTInt;
       
   175             aTextParameters.iFlags = 0;
       
   176             break;
       
   177             }
       
   178         }
       
   179     return ETrue;
       
   180     }
       
   181 
       
   182 // ---------------------------------------------------------------------------
       
   183 // ReadPointArrayL, NOT TESTED
       
   184 // ---------------------------------------------------------------------------
       
   185 //
       
   186 void CHuiCanvasCmdBufferReader::ReadPointArrayL( CArrayFix<TPoint>*& aPointArray )
       
   187     {
       
   188     TInt count = iStream.ReadInt32L();
       
   189     TInt index = 0;
       
   190     aPointArray = new(ELeave)CArrayFixFlat<TPoint>(count);
       
   191     CleanupStack::PushL( aPointArray );
       
   192     while( index < count )
       
   193         {
       
   194         TPoint point = TPoint(0,0);
       
   195         ReadPointL( point );
       
   196         aPointArray->AppendL( point );
       
   197         index++;
       
   198         }
       
   199     CleanupStack::Pop( aPointArray );
       
   200     }
       
   201 
       
   202 // ---------------------------------------------------------------------------
       
   203 // ReadPointArrayL, NOT TESTED
       
   204 // ---------------------------------------------------------------------------
       
   205 //
       
   206 void CHuiCanvasCmdBufferReader::ReadPointArrayL( TPoint*& aPointArray, TInt& aNumPoints )
       
   207     {
       
   208     ReadInt32L( aNumPoints );
       
   209     TInt index = 0;
       
   210     aPointArray = new(ELeave)TPoint[aNumPoints];
       
   211     CleanupStack::PushL( aPointArray );
       
   212         
       
   213     while( index < aNumPoints )
       
   214         {
       
   215         TPoint* point = new(ELeave)TPoint();
       
   216         CleanupStack::PushL( point );
       
   217         ReadPointL( *point );
       
   218         aPointArray[index]= *point;
       
   219         CleanupStack::Pop( point );
       
   220         index++;
       
   221         }
       
   222     CleanupStack::Pop( aPointArray );
       
   223     }
       
   224 
       
   225 // ---------------------------------------------------------------------------
       
   226 // ReadPointArrayL - NOT TESTED
       
   227 // ---------------------------------------------------------------------------
       
   228 //
       
   229 void CHuiCanvasCmdBufferReader::DeletePointArrayL( TPoint*& aPointArray, TInt& aNumPoints )
       
   230     {
       
   231     TInt index = 0;
       
   232     while( index < aNumPoints )
       
   233         {
       
   234         delete &(aPointArray[index]);
       
   235         index++;
       
   236         }
       
   237     delete aPointArray;
       
   238     aPointArray = NULL;
       
   239     }
       
   240 
       
   241 // ---------------------------------------------------------------------------
       
   242 // ReadRegionL
       
   243 // ---------------------------------------------------------------------------
       
   244 //
       
   245 void CHuiCanvasCmdBufferReader::ReadRegionL( RRegion& aRegion )
       
   246     {
       
   247     aRegion.Clear();
       
   248     TRect rect;
       
   249     TInt count;
       
   250     ReadInt32L( count );// rect count
       
   251     for (TInt i = 0 ; i < count ; i++ )
       
   252         {
       
   253         ReadRectL( rect );
       
   254         aRegion.AddRect( rect );
       
   255         }
       
   256     }
       
   257 
       
   258 // ---------------------------------------------------------------------------
       
   259 // ReadColorL
       
   260 // ---------------------------------------------------------------------------
       
   261 //
       
   262 void CHuiCanvasCmdBufferReader::ReadColorL( TRgb& aColor )
       
   263     {
       
   264     aColor.SetInternal( iStream.ReadUint32L());
       
   265     }
       
   266 
       
   267 // ---------------------------------------------------------------------------
       
   268 // Stream
       
   269 // ---------------------------------------------------------------------------
       
   270 //
       
   271 RMemReadStream& CHuiCanvasCmdBufferReader::Stream()
       
   272     {
       
   273     return iStream;    
       
   274     }
       
   275