windowing/windowserver/nonnga/remotegc/CommandBuffer.cpp
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "Graphics/WSGRAPHICMSGBUF.H"
       
    17 #include "DrawSection.h"
       
    18 #include "CommandBuffer.h"
       
    19 #include "BitmapCache.h"
       
    20 #include "FontsCache.h"
       
    21 
       
    22 const TInt KBufferSize = 1024;
       
    23 
       
    24 EXPORT_C CCommandBuffer* CCommandBuffer::NewL()
       
    25 	{
       
    26 	CCommandBuffer* buffer = new (ELeave) CCommandBuffer;
       
    27 	CleanupStack::PushL(buffer);
       
    28 	buffer->ConstructL();
       
    29 	CleanupStack::Pop(buffer);
       
    30 	return buffer;
       
    31 	}
       
    32 
       
    33 CCommandBuffer::CCommandBuffer()
       
    34 	{
       
    35 	}
       
    36 	
       
    37 EXPORT_C CCommandBuffer::~CCommandBuffer()
       
    38 	{	
       
    39 	iDrawSections.ResetAndDestroy();
       
    40 	iDrawSections.Close();
       
    41 	iBufReadStream.Close();
       
    42 	iClippingRegion.Close();
       
    43 	
       
    44 	iBufRead = NULL;
       
    45 	delete iRecordSegBuf;
       
    46 	delete iBitmapCache;
       
    47 	delete iFontCache;
       
    48 	}
       
    49 	
       
    50 void CCommandBuffer::ConstructL()
       
    51 	{
       
    52 	iBitmapCache = new (ELeave)	CBitmapCache;
       
    53 	iRecordSegBuf = CBufSeg::NewL(KBufferSize);
       
    54 	iFontCache =  new (ELeave) CFontsCache;
       
    55 	}
       
    56 
       
    57 /**
       
    58 Resets the entire commandbuffer.
       
    59 */
       
    60 void CCommandBuffer::Reset()
       
    61 	{
       
    62 	if(iRecordSegBuf)
       
    63 		iRecordSegBuf->Reset();
       
    64 	
       
    65 	iError =  KErrNone;	
       
    66 	iOrigin = TPoint(0,0);
       
    67 	iClippingRegion.Clear();
       
    68 	iDrawSections.ResetAndDestroy();	
       
    69 	}
       
    70 
       
    71 /**
       
    72 Externalizes commandbuffer sections into a format which makes it possible to send over IPC.
       
    73 If ETrue is sent as a parameter to this method, the entire commandbuffer will be externalized,
       
    74 otherwise only sections which has not been externalized before will be externalized. Note that if only
       
    75 not externalized sections is asked for, the flag will be reset on that section so next call
       
    76 to ExternalizeLC will not externalize that section.
       
    77 
       
    78 @param aMsgBuf A buffer used to externalize the commandbuffer to.
       
    79 @param aEntireBuffer If ETrue, the entire commandbuffer will be externalized, otherwise only sections which has not been externalized before.
       
    80 */
       
    81 void CCommandBuffer::ExternalizeL(RWsGraphicMsgBuf& aMsgBuf, TBool aEntireBuffer)
       
    82 	{
       
    83 	// Add drawsections to aMsgBuf
       
    84 	const TInt sectionCount = iDrawSections.Count();
       
    85 	for(TInt j = 0; j < sectionCount; j++)	
       
    86 		{
       
    87 		CDrawSection* section = iDrawSections[j];
       
    88 		if(aEntireBuffer || !section->HasBeenExternalized())
       
    89 			{
       
    90 			section->ExternalizeL(aMsgBuf);
       
    91 			section->SetHasBeenExternalized(ETrue);
       
    92 			}
       
    93 		}
       
    94 	}
       
    95 
       
    96 /**
       
    97 Internalizes the entire commandbuffer from buffer containing information about all drawsections and drawcommands.
       
    98 
       
    99 @param aBuf A buffer containing information about all drawsections and drawcommands.
       
   100 */
       
   101 EXPORT_C void CCommandBuffer::InternalizeL(const TDesC8& aBuf)
       
   102 	{
       
   103 	// Reset the commandbuffer
       
   104 	iRecordSegBuf->Reset();
       
   105 	InternalizeAppendL(aBuf);
       
   106 	}
       
   107 
       
   108 /**
       
   109 Internalizes and appends from a buffer containing information about some drawsections and drawcommands.
       
   110 
       
   111 @param aBuf A buffer containing information about some drawsections and drawcommands.
       
   112 */
       
   113 EXPORT_C void CCommandBuffer::InternalizeAppendL(const TDesC8& aBuf)
       
   114 	{
       
   115 	// Reset the commandbuffer
       
   116 	TWsGraphicMsgBufParser parser(aBuf);
       
   117 	
       
   118 	// Load drawsections
       
   119 	const TInt count = parser.Count();
       
   120 	for(TInt i = 0; i < count; i++)
       
   121 		{
       
   122 		CDrawSection* drawSection = CDrawSection::NewL();;
       
   123 		CleanupStack::PushL(drawSection);
       
   124 		User::LeaveIfError(drawSection->LoadL(parser, i));
       
   125 		iDrawSections.AppendL(drawSection);
       
   126 		CleanupStack::Pop(drawSection);
       
   127 		}
       
   128 	
       
   129 	// Tidy the iDrawSection array so completely blocked sections will be removed
       
   130 	Tidy();
       
   131 	}
       
   132 
       
   133 /**
       
   134 @return the current active clipping region of the commandbuffer.
       
   135 */	
       
   136 EXPORT_C const TRegion& CCommandBuffer::ClippingRegion() const
       
   137 	{
       
   138 	return *iActiveMasterClippingRegion;
       
   139 	}
       
   140 
       
   141 /**
       
   142 Prepares to record new drawcommands for a drawsection.
       
   143 This method is called from CRemoteGc::Activate().
       
   144 */
       
   145 void CCommandBuffer::Prepare(const TRect& aDrawRect)
       
   146 	{
       
   147 	iDrawSectionRect = aDrawRect;
       
   148 	iError = KErrNone;
       
   149   	if(iRecordSegBuf)
       
   150   		iRecordSegBuf->Delete(0, iRecordSegBuf->Size()); // Reset record buffer
       
   151   	else
       
   152   		TRAP(iError, iRecordSegBuf = CBufSeg::NewL(KBufferSize));
       
   153 	}
       
   154 	
       
   155 /**
       
   156 Finishes the recording of drawcommands for a drawsection. 
       
   157 This method is called from CRemoteGc::Deactivate().
       
   158 
       
   159 @param aDrawRect The drawrect of the recorded drawcommands.
       
   160 @param aBoundingRect The boundingrect of the recorded drawcommands.
       
   161 */
       
   162 TInt CCommandBuffer::Finish(const TRect& aDrawRect, const TRect& aBoundingRect, TBool aHasBitmapCommand)
       
   163 	{
       
   164 	// If some error occured during the recording of this section, dont add the section
       
   165 	if(!iError)
       
   166 		{
       
   167 		CDrawSection* drawSection = NULL;
       
   168 		TRAP(iError, drawSection = CDrawSection::NewL(aDrawRect, aBoundingRect, aHasBitmapCommand))
       
   169 		if(iError)
       
   170 			return iError;
       
   171 		
       
   172 		// If boundingRect is empty clear the drawcommands added
       
   173 		if(aBoundingRect.IsEmpty())
       
   174 			iRecordSegBuf->Delete(0, iRecordSegBuf->Size());
       
   175 		
       
   176 		iRecordSegBuf->Compress();
       
   177 		drawSection->SetBuffer(iRecordSegBuf); //Takes ownership of the memory allocated by iRecordSegBuf			
       
   178 		iRecordSegBuf = NULL;		
       
   179 		if(CheckForDuplicate(*drawSection))
       
   180 			{
       
   181 			delete drawSection;
       
   182 			return KErrAlreadyExists;
       
   183 			}
       
   184 		
       
   185 		iError = iDrawSections.Append(drawSection);
       
   186 		if(iError)
       
   187 			delete drawSection;
       
   188 		else
       
   189 			{
       
   190 			Tidy();
       
   191 			if(iDrawSections.Count() == 0 || AllSectionsExternalized())
       
   192 				return KErrGeneral;
       
   193 			}
       
   194 		}
       
   195 
       
   196 	return iError;
       
   197 	}
       
   198 
       
   199 /**
       
   200 Remove drawsections that is completely blocked by another drawsection. 
       
   201 */
       
   202 void CCommandBuffer::Tidy()
       
   203 	{
       
   204 	RRegion region;
       
   205 	TInt count = 0;
       
   206 	for(TInt i = 0; i < (count = iDrawSections.Count()); i++)
       
   207 		{		
       
   208 		TRect rect1 = iDrawSections[i]->DrawRect();
       
   209 		region.Clear();
       
   210 		region.AddRect(rect1);
       
   211 		for(TInt j = i + 1; j < count; j++)
       
   212 			{
       
   213 			TRect rect2 = iDrawSections[j]->DrawRect();
       
   214 			region.SubRect(rect2);
       
   215 			}
       
   216 			
       
   217 		if(region.IsEmpty())
       
   218 			{
       
   219 			delete iDrawSections[i];
       
   220 			iDrawSections.Remove(i--);
       
   221 			}
       
   222 		}
       
   223 	region.Close();
       
   224 	}
       
   225 
       
   226 /** 
       
   227 @return ETrue if all sections in the commandbuffer have been externalized, otherwise EFalse. 
       
   228 */ 
       
   229 TBool CCommandBuffer::AllSectionsExternalized() const 
       
   230 	{ 
       
   231 	const TInt count = iDrawSections.Count(); 
       
   232 	for(TInt i = 0; i < count; i++) 
       
   233 		{ 
       
   234 		if(!iDrawSections[i]->HasBeenExternalized()) 
       
   235 			return EFalse; 
       
   236 		} 
       
   237 	return ETrue; 
       
   238 	} 
       
   239 
       
   240 /**
       
   241 Checks if there exists any duplicate of aDrawSection already in the iDrawSection array.
       
   242 
       
   243 @param aDrawSection The drawsection to look for a duplicate of.
       
   244 @return ETrue if a duplicate was found, otherwise EFalse.
       
   245 */
       
   246 TBool CCommandBuffer::CheckForDuplicate(const CDrawSection& aDrawSection) const
       
   247 	{
       
   248 	const TInt count = iDrawSections.Count();
       
   249 	for(TInt i = 0; i < count; i++)
       
   250 		{
       
   251 		if(!iDrawSections[i]->IsIdentical(aDrawSection))
       
   252 			continue;
       
   253 		
       
   254 		// Check if there is some drawsection that overlaps the section we found identical, 
       
   255 		// if that is the case it is not a duplicate
       
   256 		for(TInt j = i + 1; j < count; j++)
       
   257 			{
       
   258 			TRect compareRect = iDrawSections[j]->DrawRect();
       
   259 			if(aDrawSection.DrawRect().Intersects(compareRect)) 
       
   260 				return EFalse; //Found a drawrect that overlapped, no duplicate exists then
       
   261 			}
       
   262 			
       
   263 		// Found duplicate
       
   264 		return ETrue;
       
   265 		}
       
   266 		
       
   267 	return EFalse;
       
   268 	}
       
   269 	
       
   270 /**
       
   271 Updates the clippingregion for a specific drawsection.
       
   272 
       
   273 @param aDrawSectionIndex The index in iDrawSections of the drawsection to update the clippingregion for.
       
   274 @param aBitmapContext The bitmapcontext to set the new clippingregion on.
       
   275 */
       
   276 void CCommandBuffer::UpdateClippingRegion(TInt aDrawSectionIndex)
       
   277 	{
       
   278 	__ASSERT_DEBUG(aDrawSectionIndex < iDrawSections.Count(), User::Invariant());
       
   279 	
       
   280 	iDrawSectionClippingRegion.Clear();
       
   281 	if (iMasterClippingRegion)
       
   282 		{
       
   283 		iDrawSectionClippingRegion.Copy(*iMasterClippingRegion);
       
   284 		}
       
   285 	else
       
   286 		{
       
   287 		TRect rect = iMasterClippingRect;
       
   288 		rect.Move(iMasterOrigin);
       
   289 		iDrawSectionClippingRegion.AddRect(rect);
       
   290 		}
       
   291 
       
   292 	const TInt count = iDrawSections.Count();
       
   293 	for(TInt i = aDrawSectionIndex + 1; i < count; ++i)
       
   294 		{
       
   295 		TRect rect = iDrawSections[i]->DrawRect();
       
   296 		rect.Move(iMasterOrigin);
       
   297 		iDrawSectionClippingRegion.SubRect(rect);
       
   298 		}
       
   299 	
       
   300 	if (iDrawSectionClippingRegion.CheckError())
       
   301 		iActiveMasterClippingRegion = iMasterClippingRegion;
       
   302 	else
       
   303 		iActiveMasterClippingRegion = &iDrawSectionClippingRegion;
       
   304 	}
       
   305 
       
   306 /**
       
   307 Writes data of a specific length to the recordbuffer.
       
   308 
       
   309 @param aPtr The data to write.
       
   310 @param aLength The length of the data to write.
       
   311 */
       
   312 void CCommandBuffer::Write(const TUint8* aPtr, TUint aLength)
       
   313 	{
       
   314 	if(iError)
       
   315 		return;
       
   316 	
       
   317 	TRAP(iError, iRecordSegBuf->InsertL(iRecordSegBuf->Size(), aPtr, aLength))
       
   318 	if(iError)
       
   319 		return;
       
   320 	}
       
   321 
       
   322 /**
       
   323 Writes text to the recordbuffer.
       
   324 
       
   325 @param aText The text to write to the recordbuffer.
       
   326 */
       
   327 void CCommandBuffer::WriteText(const TDesC8 &aText)
       
   328 	{
       
   329 	if(iError)
       
   330 		return;
       
   331 	
       
   332 	// Append the total size of the text
       
   333 	Write<TInt>(aText.Size());
       
   334 	if(iError)
       
   335 		return;			
       
   336 	
       
   337 	TRAP(iError, DoWriteTextL(aText));	
       
   338 	}
       
   339 
       
   340 /**
       
   341 Writes text to the recordbuffer.
       
   342 
       
   343 @param aText The text to write to the recordbuffer.
       
   344 */
       
   345 void CCommandBuffer::WriteText(const TDesC16 &aText)
       
   346 	{
       
   347 	if(iError)
       
   348 		return;
       
   349 	
       
   350 	// Append the total size of the text
       
   351 	Write<TInt>(aText.Size());
       
   352 	if(iError)
       
   353 		return;			
       
   354 	
       
   355 	TPtrC8 textPtr(reinterpret_cast<const TUint8*>(aText.Ptr()),aText.Size());
       
   356 	TRAP(iError, DoWriteTextL(textPtr));	
       
   357 	}
       
   358 
       
   359 /**
       
   360 Writes text to the recordbuffer.
       
   361 
       
   362 @param aText The text to write to the recordbuffer.
       
   363 */	
       
   364 void CCommandBuffer::DoWriteTextL(const TDesC8 &aText)
       
   365 	{
       
   366 	iRecordSegBuf->InsertL(iRecordSegBuf->Size(), aText, aText.Size());		
       
   367 	}
       
   368 
       
   369 /**
       
   370 Reads data with a specific length from iBufReadStream.
       
   371 
       
   372 @param aPtr The read data is written to this paramenter.
       
   373 @param aLength The length of the data to be read.
       
   374 */
       
   375 void CCommandBuffer::ReadL(TUint8* aPtr, TUint aLength)
       
   376 	{
       
   377 	iBufReadStream.ReadL(aPtr, aLength);
       
   378 	}
       
   379 
       
   380 /**
       
   381 Reads text from iBufReadStream.
       
   382 
       
   383 @param aText The read text is put into this 8-bit buffer.
       
   384 */	
       
   385 void CCommandBuffer::ReadTextLC(TPtrC8& aText)
       
   386 	{
       
   387 	DoReadTextLC(aText,EFalse);
       
   388 	}
       
   389 
       
   390 /**
       
   391 Reads text from iBufReadStream.
       
   392 
       
   393 @param aText The read text is put into this 16-bit buffer.
       
   394 */	
       
   395 void CCommandBuffer::ReadTextLC(TPtrC16& aText)
       
   396 	{
       
   397 	TPtrC8 text8;
       
   398 	DoReadTextLC(text8,ETrue);
       
   399 	aText.Set(reinterpret_cast<const TUint16*>(text8.Ptr()),text8.Size()/2);
       
   400 	}
       
   401 	
       
   402 /**
       
   403 Reads text from iBufReadStream; used by ReadTextLC
       
   404 
       
   405 @internalComponent
       
   406 */	
       
   407 void CCommandBuffer::DoReadTextLC(TPtrC8& aText,TBool a16Bit)
       
   408 	{
       
   409 	ASSERT(iBufRead);
       
   410 	
       
   411 	TInt textSize;
       
   412 	ReadL<TInt>(textSize); // Read the length of the text
       
   413 	if(0 > textSize)
       
   414 		{
       
   415 		User::Leave(KErrArgument);
       
   416 		}
       
   417 	
       
   418 	// attempt to do it inline
       
   419 	const TInt pos = iBufReadStream.Source()->TellL(MStreamBuf::ERead).Offset();
       
   420 	if(!a16Bit || !(pos & 1)) // check 16bit-aligned
       
   421 		{
       
   422 		const TPtrC8 remaining = iBufRead->Ptr(pos);
       
   423 		if(remaining.Size() >= textSize) // can do inline!
       
   424 			{
       
   425 			CleanupStack::PushL((TAny*)NULL); // have to push something
       
   426 			iBufReadStream.Source()->SeekL(MStreamBuf::ERead,textSize);
       
   427 			aText.Set(remaining.Ptr(),textSize);
       
   428 			return;
       
   429 			}
       
   430 		}
       
   431 		
       
   432 	// have to copy into a continuous segment
       
   433 	HBufC8* buf = HBufC8::NewLC(textSize);
       
   434 	TPtr8 textPtr8(buf->Des());
       
   435 	iBufReadStream.ReadL(textPtr8,textSize);
       
   436 	aText.Set(*buf);
       
   437 	}
       
   438 
       
   439 /**
       
   440 Compares the commands in one buffer to those in another
       
   441 @param aBuffer The buffer to compare to
       
   442 @return ETrue if they are an exact match, EFalse otherwise
       
   443 */
       
   444 EXPORT_C TBool CCommandBuffer::IsIdentical(const CCommandBuffer & aBuffer) const
       
   445 	{
       
   446 	for(TInt i = 0; i < iDrawSections.Count(); ++i)
       
   447 		{
       
   448 		if (!iDrawSections[i]->IsIdentical(*aBuffer.iDrawSections[i]))
       
   449 			return EFalse;
       
   450 		}
       
   451 	return ETrue;
       
   452 	}
       
   453 
       
   454 /**
       
   455 Draws drawcommands that are within a specific rect to a specific position.
       
   456 This function is deprecated use the other overload
       
   457 
       
   458 @param aPosition Draws the drawcommands to this position.
       
   459 @param aDrawRect Draws only drawcommands that are within this rect.
       
   460 @param aBitmapContext The bitmapcontext to draw to.
       
   461 @deprecated
       
   462 @publishedPartner
       
   463 */
       
   464 EXPORT_C TInt CCommandBuffer::Play(const TPoint& aPosition, const TRect& aDrawRect, const MWsGraphicResolver& aWsGraphicResolver, CBitmapContext& aContext)
       
   465 	{
       
   466 	iMasterOrigin = aPosition;
       
   467 	iOrigin = TPoint(0,0); // Need to save this to be able to make Reset not affect Origin beacuse that is how CWsGc works.
       
   468 	aContext.SetOrigin(iMasterOrigin);
       
   469 	iMasterClippingRect = aDrawRect;
       
   470 	iMasterClippingRegion=0;
       
   471 		
       
   472 	TRAPD(errMess, DoPlayL(aWsGraphicResolver, aContext));		
       
   473 	return errMess;
       
   474 	}
       
   475 
       
   476 /**
       
   477 Draws drawcommands that are within a specific rect to a specific position.
       
   478 
       
   479 @param aMasterOrigin The origin relative to which all draw commands will be drawn
       
   480 @param aMasterClippingRegion The region to which all draw commands are clipped
       
   481 @param aMasterClippingRect The rectangle to which all draw commands are clipped
       
   482 @param aWsGraphicResolver Any DrawWsGraphic commands will use this to draw themselves
       
   483 @param aContext The bitmap context to draw to
       
   484 @publishedPartner
       
   485 */
       
   486 EXPORT_C TInt CCommandBuffer::Play(const TPoint& aMasterOrigin, const TRegion * aMasterClippingRegion, const TRect& aMasterClippingRect, const MWsGraphicResolver& aWsGraphicResolver, CBitmapContext& aContext)
       
   487 	{
       
   488 	iMasterOrigin = aMasterOrigin;
       
   489 	iMasterClippingRegion = aMasterClippingRegion;
       
   490 	iMasterClippingRect = aMasterClippingRect;
       
   491 	
       
   492 	Reset(aContext);
       
   493 
       
   494 	TRAPD(errMess, DoPlayL(aWsGraphicResolver, aContext));		
       
   495 	return errMess;
       
   496 	}
       
   497 
       
   498 /**
       
   499 	@internalTechnology
       
   500 */
       
   501 EXPORT_C TInt CCommandBuffer::Play(const TPoint& /*aOffset*/, const TRegion* /*aClippingRegion*/, const TRect& /*aSourceRect*/, const MWsGraphicResolver& /*aWsGraphicResolver*/, MWsGraphicsContext& /*aGraphicsContext*/) //Stub implementation to maintain compatibility with NGA Window Server
       
   502 	{
       
   503 	ASSERT(0);
       
   504 	return KErrNotSupported;
       
   505 	}
       
   506 
       
   507 /**
       
   508 	@internalTechnology
       
   509 */
       
   510 EXPORT_C TInt CCommandBuffer::Play(const TPoint& /*aOffset*/, const TRegion* /*aClippingRegion*/, const TRect& /*aSourceRect*/, RWsSession& /*aWsSession*/, CWindowGc& /*aWindowGc*/) //Stub implementation to maintain compatibility with NGA Window Server
       
   511 	{
       
   512 	ASSERT(0);
       
   513 	return KErrNotSupported;
       
   514 	}
       
   515 
       
   516 /**
       
   517 Draws drawcommands that are within a specific rect.
       
   518 
       
   519 @param aDrawRect Draws only drawcommands that are within this rect.
       
   520 @param aBitmapContext The bitmapcontext to draw to.
       
   521 */
       
   522 void CCommandBuffer::DoPlayL(const MWsGraphicResolver& aWsGraphicResolver, CBitmapContext& aBitmapContext)
       
   523 	{
       
   524 	const TInt sections = iDrawSections.Count();
       
   525 	if(sections == 0)
       
   526 		User::Leave(KErrEof);
       
   527 	
       
   528 	iBitmapCache->BeginUpdate();
       
   529 	iFontCache->BeginUpdate();
       
   530 	for(TInt i = 0; i < sections; i++)
       
   531 		{
       
   532 		UpdateClippingRegion(i);
       
   533 		DrawSectionL(*iDrawSections[i], aWsGraphicResolver, aBitmapContext);		
       
   534 		}
       
   535 	iFontCache->EndUpdate();
       
   536 	iBitmapCache->EndUpdate();	
       
   537 	}
       
   538 
       
   539 /**
       
   540 Draws a specific drawsection.
       
   541 
       
   542 @param aDrawSection The drawsection to be drawn.
       
   543 @param aBitmapContext The bitmapcontext to draw to.
       
   544 */
       
   545 void CCommandBuffer::DrawSectionL(const CDrawSection& aDrawSection, const MWsGraphicResolver& aWsGraphicResolver, CBitmapContext& aBitmapContext)
       
   546 	{
       
   547 	iDrawSectionRect = aDrawSection.DrawRect();
       
   548 	Reset(aBitmapContext);
       
   549 
       
   550 	iBufRead = aDrawSection.Buffer();
       
   551 	iBufReadStream.Open(*iBufRead, 0);
       
   552 	
       
   553 	TDrawCode drawCode;
       
   554 	while(ETrue)
       
   555 		{		
       
   556 	   	TRAPD(err, ReadL<TDrawCode>(drawCode));
       
   557 	   	if(err == KErrEof)
       
   558 	   		return;
       
   559 	   	else if(err)
       
   560 	   		User::Leave(err);
       
   561    	
       
   562 		switch(drawCode)
       
   563 			{
       
   564 			case ECommandClear:
       
   565 				Clear(aBitmapContext);
       
   566 				break;			
       
   567 			case ECommandClearRect:
       
   568 				ClearRectL(aBitmapContext);
       
   569 				break;
       
   570 			case ECommandCopyRect:
       
   571 				CopyRectL(aBitmapContext);
       
   572 				break;
       
   573 			case ECommandBitBlt1:
       
   574 				BitBlt1L(aBitmapContext);
       
   575 				break;
       
   576 			case ECommandBitBlt2:
       
   577 				BitBlt2L(aBitmapContext);
       
   578 				break;
       
   579 			case ECommandBitBltMasked:
       
   580 				BitBltMaskedL(aBitmapContext);
       
   581 				break;
       
   582 			case ECommandSetFaded:
       
   583 				SetFadedL(aBitmapContext);
       
   584 				break;
       
   585 			case ECommandSetFadingParameters:
       
   586 				SetFadingParametersL(aBitmapContext);
       
   587 				break;
       
   588 			case ECommandAlphaBlendBitmaps:
       
   589 				AlphaBlendBitmapsL(aBitmapContext);
       
   590 				break;		
       
   591 			case ECommandSetOrigin:
       
   592 				SetOriginL(aBitmapContext);
       
   593 				break;
       
   594 			case ECommandSetDrawMode:
       
   595 				SetDrawModeL(aBitmapContext);
       
   596 				break;
       
   597 			case ECommandSetClippingRect:
       
   598 				SetClippingRectL(aBitmapContext);
       
   599 				break;
       
   600 			case ECommandCancelClippingRect:
       
   601 				CancelClippingRect(aBitmapContext);
       
   602 				break;
       
   603 			case ECommandReset:
       
   604 				Reset(aBitmapContext);
       
   605 				break;			
       
   606 			case ECommandUseFont:
       
   607 				UseFontL(aBitmapContext);
       
   608 				break;
       
   609 			case ECommandDiscardFont:
       
   610 				DiscardFont(aBitmapContext);
       
   611 				break;
       
   612 			case ECommandSetUnderlineStyle:
       
   613 				SetUnderlineStyleL(aBitmapContext);
       
   614 				break;
       
   615 			case ECommandSetStrikethroughStyle:
       
   616 				SetStrikethroughStyleL(aBitmapContext);
       
   617 				break;
       
   618 			case ECommandSetWordJustification:
       
   619 				SetWordJustificationL(aBitmapContext);
       
   620 				break;
       
   621 			case ECommandSetCharJustification:
       
   622 				SetCharJustificationL(aBitmapContext);
       
   623 				break;
       
   624 			case ECommandSetPenColor:
       
   625 				SetPenColorL(aBitmapContext);
       
   626 				break;
       
   627 			case ECommandSetPenStyle:
       
   628 				SetPenStyleL(aBitmapContext);
       
   629 				break;
       
   630 			case ECommandSetPenSize:
       
   631 				SetPenSizeL(aBitmapContext);
       
   632 				break;									
       
   633 			case ECommandSetBrushColor:
       
   634 				SetBrushColorL(aBitmapContext);
       
   635 				break;						
       
   636 			case ECommandSetBrushStyle:
       
   637 				SetBrushStyleL(aBitmapContext);
       
   638 				break;
       
   639 			case ECommandSetBrushOrigin:
       
   640 				SetBrushOriginL(aBitmapContext);
       
   641 				break;
       
   642 			case ECommandUseBrushPattern:
       
   643 				UseBrushPatternL(aBitmapContext);
       
   644 				break;
       
   645 			case ECommandDiscardBrushPattern:
       
   646 				DiscardBrushPattern(aBitmapContext);
       
   647 				break;
       
   648 			case ECommandMoveTo:
       
   649 				MoveToL(aBitmapContext);
       
   650 				break;
       
   651 			case ECommandMoveBy:
       
   652 				MoveByL(aBitmapContext);
       
   653 				break;
       
   654 			case ECommandPlot:
       
   655 				PlotL(aBitmapContext);
       
   656 				break;
       
   657 			case ECommandDrawArc:
       
   658 				DrawArcL(aBitmapContext);
       
   659 				break;
       
   660 			case ECommandDrawLine:
       
   661 				DrawLineL(aBitmapContext);
       
   662 				break;
       
   663 			case ECommandDrawLineTo:
       
   664 				DrawLineToL(aBitmapContext);
       
   665 				break;
       
   666 			case ECommandDrawLineBy:
       
   667 				DrawLineByL(aBitmapContext);
       
   668 				break;
       
   669 			case ECommandDrawPolyLine:
       
   670 				DrawPolyLineL(aBitmapContext);
       
   671 				break;
       
   672 			case ECommandDrawPie:
       
   673 				DrawPieL(aBitmapContext);
       
   674 				break;
       
   675 			case ECommandDrawEllipse:
       
   676 				DrawEllipseL(aBitmapContext);
       
   677 				break;	
       
   678 			case ECommandDrawRect:
       
   679 				DrawRectL(aBitmapContext);
       
   680 				break;
       
   681 			case ECommandDrawPolygon:
       
   682 				DrawPolygonL(aBitmapContext);
       
   683 				break;	
       
   684 			case ECommandDrawRoundRect:
       
   685 				DrawRoundRectL(aBitmapContext);
       
   686 				break;										
       
   687 			case ECommandDrawBitmap1:
       
   688 				DrawBitmap1L(aBitmapContext);
       
   689 				break;	
       
   690 			case ECommandDrawBitmap2:
       
   691 				DrawBitmap2L(aBitmapContext);
       
   692 				break;	
       
   693 			case ECommandDrawBitmap3:
       
   694 				DrawBitmap3L(aBitmapContext);
       
   695 				break;	
       
   696 			case ECommandDrawBitmapMasked:
       
   697 				DrawBitmapMaskedL(aBitmapContext);
       
   698 				break;
       
   699 			case ECommandDrawText1:
       
   700 				DrawText1L(aBitmapContext);
       
   701 				break;
       
   702 			case ECommandDrawText2:
       
   703 				DrawText2L(aBitmapContext);
       
   704 				break;
       
   705 			case ECommandDrawText3:
       
   706 				DrawText3L(aBitmapContext);
       
   707 				break;	
       
   708 			case ECommandMapColors:
       
   709 				MapColorsL(aBitmapContext);
       
   710 				break;					
       
   711 			case ECommandSetClippingRegion:
       
   712 				SetClippingRegionL(aBitmapContext);
       
   713 				break;
       
   714 			case ECommandCancelClippingRegion:
       
   715 				CancelClippingRegion(aBitmapContext);
       
   716 				break;
       
   717 			case ECommandDrawTextVertical1:
       
   718 				DrawTextVertical1L(aBitmapContext);
       
   719 				break;
       
   720 			case ECommandDrawTextVertical2:
       
   721 				DrawTextVertical2L(aBitmapContext);
       
   722 				break;						
       
   723 			case ECommandDrawWsGraphic1:
       
   724 				DrawWsGraphic1L(aWsGraphicResolver);
       
   725 				break;						
       
   726 			case ECommandDrawWsGraphic2:
       
   727 				DrawWsGraphic2L(aWsGraphicResolver);
       
   728 				break;						
       
   729 			case ECommandSetShadowColor:
       
   730 				SetShadowColorL(aBitmapContext);
       
   731 				break;
       
   732 			default:
       
   733 				User::LeaveIfError(KErrNotFound);
       
   734 				break;
       
   735 			}
       
   736 		}
       
   737 	}
       
   738 
       
   739 void CCommandBuffer::Clear(CBitmapContext& aBitmapContext) const
       
   740 	{
       
   741 	aBitmapContext.Clear();
       
   742 	}
       
   743 
       
   744 void CCommandBuffer::ClearRectL(CBitmapContext& aBitmapContext)
       
   745 	{
       
   746 	TRect rect;	
       
   747 	ReadL<TRect>(rect);
       
   748 	
       
   749 	aBitmapContext.Clear(rect);
       
   750 	}
       
   751 	
       
   752 void CCommandBuffer::CopyRectL(CBitmapContext& aBitmapContext)
       
   753 	{
       
   754 	TPoint point;
       
   755 	TRect rect;	
       
   756 	
       
   757 	ReadL<TPoint>(point);
       
   758 	ReadL<TRect>(rect);
       
   759 	
       
   760 	aBitmapContext.CopyRect(point, rect);
       
   761 	}
       
   762 
       
   763 void CCommandBuffer::BitBlt1L(CBitmapContext& aBitmapContext)
       
   764 	{	
       
   765 	TPoint point;
       
   766 	TInt handle;
       
   767 	
       
   768 	ReadL<TPoint>(point);
       
   769 	ReadL<TInt>(handle);
       
   770 			
       
   771 	if(!iBitmapCache->UseL(handle))
       
   772 		aBitmapContext.BitBlt(point, iBitmapCache->Resolve(handle));
       
   773 	}
       
   774 	
       
   775 void CCommandBuffer::BitBlt2L(CBitmapContext& aBitmapContext)
       
   776 	{
       
   777 	TPoint point;
       
   778 	TRect sourceRect;
       
   779 	TInt handle;
       
   780 	
       
   781 	ReadL<TPoint>(point);
       
   782 	ReadL<TInt>(handle);
       
   783 	ReadL<TRect>(sourceRect);
       
   784 	
       
   785 	if(!iBitmapCache->UseL(handle))
       
   786 		aBitmapContext.BitBlt(point, iBitmapCache->Resolve(handle), sourceRect);
       
   787 	}
       
   788 	
       
   789 void CCommandBuffer::BitBltMaskedL(CBitmapContext& aBitmapContext)
       
   790 	{
       
   791 	TPoint point;
       
   792 	TInt bitmapHandle;
       
   793 	TRect sourceRect;	
       
   794 	TInt maskHandle;
       
   795 	TBool invertedMask;
       
   796 	
       
   797 	ReadL<TPoint>(point);
       
   798 	ReadL<TInt>(bitmapHandle);
       
   799 	ReadL<TRect>(sourceRect);
       
   800 	ReadL<TInt>(maskHandle);
       
   801 	ReadL<TBool>(invertedMask);
       
   802 	
       
   803 	if(!iBitmapCache->UseL(bitmapHandle) && !iBitmapCache->UseL(maskHandle))
       
   804 		aBitmapContext.BitBltMasked(point, iBitmapCache->Resolve(bitmapHandle), sourceRect, iBitmapCache->Resolve(maskHandle), invertedMask);	
       
   805 	}
       
   806 	
       
   807 void CCommandBuffer::SetFadedL(CBitmapContext& aBitmapContext)
       
   808 	{
       
   809 	TBool faded;	
       
   810 	ReadL<TBool>(faded);
       
   811 
       
   812 	aBitmapContext.SetFaded(faded);
       
   813 	}
       
   814 	
       
   815 void CCommandBuffer::SetFadingParametersL(CBitmapContext& aBitmapContext)
       
   816 	{
       
   817 	TUint8 blackMap;
       
   818 	TUint8 whiteMap;
       
   819 	
       
   820 	ReadL<TUint8>(blackMap);
       
   821 	ReadL<TUint8>(whiteMap);
       
   822 	aBitmapContext.SetFadingParameters(blackMap, whiteMap);
       
   823 	}
       
   824 	
       
   825 void CCommandBuffer::AlphaBlendBitmapsL(CBitmapContext& aBitmapContext)
       
   826 	{
       
   827 	TPoint destPoint;
       
   828 	TInt srcHandle;
       
   829 	TRect sourceRect;
       
   830 	TInt alphaHandle;
       
   831 	TPoint alphaPoint;
       
   832 	
       
   833 	ReadL<TPoint>(destPoint);
       
   834 	ReadL<TInt>(srcHandle);
       
   835 	ReadL<TRect>(sourceRect);
       
   836 	ReadL<TInt>(alphaHandle);
       
   837 	ReadL<TPoint>(alphaPoint);
       
   838 	
       
   839 	if(!iBitmapCache->UseL(srcHandle) && !iBitmapCache->UseL(alphaHandle))
       
   840 		aBitmapContext.AlphaBlendBitmaps(destPoint, iBitmapCache->Resolve(srcHandle), sourceRect, iBitmapCache->Resolve(alphaHandle), alphaPoint);	
       
   841 	}
       
   842 	
       
   843 void CCommandBuffer::SetOriginL(CBitmapContext& aBitmapContext)
       
   844 	{
       
   845 	ReadL<TPoint>(iOrigin);
       
   846 	aBitmapContext.SetOrigin(iMasterOrigin + iOrigin);
       
   847 	
       
   848 	}
       
   849 	
       
   850 void CCommandBuffer::SetDrawModeL(CBitmapContext& aBitmapContext)
       
   851 	{
       
   852 	CGraphicsContext::TDrawMode drawMode;
       
   853 	ReadL<CGraphicsContext::TDrawMode>(drawMode);
       
   854 	aBitmapContext.SetDrawMode(drawMode);
       
   855 	}
       
   856 	
       
   857 void CCommandBuffer::SetClippingRectL(CBitmapContext& aBitmapContext)
       
   858 	{
       
   859 	TRect rect;
       
   860 	ReadL<TRect>(rect);
       
   861 	rect.Intersection(iMasterClippingRect);
       
   862 	rect.Intersection(iDrawSectionRect);
       
   863 	aBitmapContext.SetClippingRect(rect);
       
   864 	}
       
   865 	
       
   866 void CCommandBuffer::CancelClippingRect(CBitmapContext& aBitmapContext)
       
   867 	{
       
   868 	TRect rect = iMasterClippingRect;
       
   869 	rect.Intersection(iDrawSectionRect);
       
   870 	aBitmapContext.SetClippingRect(rect);
       
   871 	}
       
   872 
       
   873 	
       
   874 void CCommandBuffer::Reset(CBitmapContext& aBitmapContext)
       
   875 	{
       
   876 	aBitmapContext.Reset();
       
   877 
       
   878 	const TBool isFbsBitGc= aBitmapContext.IsFbsBitGc();
       
   879 	if (isFbsBitGc)
       
   880 		{
       
   881 		TRgb brushColor = KRgbWhite;
       
   882 		brushColor.SetAlpha(0); //make transparent
       
   883 		aBitmapContext.SetBrushColor(brushColor);
       
   884 		}
       
   885 	
       
   886 	aBitmapContext.SetOrigin(iMasterOrigin);
       
   887 	if(iActiveMasterClippingRegion)
       
   888 		aBitmapContext.SetClippingRegion(*iActiveMasterClippingRegion);
       
   889 	CancelClippingRect(aBitmapContext);
       
   890 	iOrigin = TPoint(0,0);
       
   891 	iClippingRegion.Clear();
       
   892 	iParsedClippingRegionIsSet = EFalse;
       
   893 	}
       
   894 
       
   895 void CCommandBuffer::UseFontL(CBitmapContext& aBitmapContext)
       
   896 	{
       
   897 	TInt fontHandle;
       
   898 	ReadL<TInt>(fontHandle);
       
   899 	if(iFontCache->UseL(fontHandle)) return;
       
   900 	aBitmapContext.UseFont(iFontCache->Resolve(fontHandle));
       
   901 	}
       
   902 	
       
   903 void CCommandBuffer::DiscardFont(CBitmapContext& aBitmapContext) const
       
   904 	{	
       
   905 	aBitmapContext.DiscardFont();
       
   906 	}
       
   907 	
       
   908 void CCommandBuffer::SetUnderlineStyleL(CBitmapContext& aBitmapContext)
       
   909 	{
       
   910 	TFontUnderline underlineStyle;
       
   911 	ReadL<TFontUnderline>(underlineStyle);
       
   912 	aBitmapContext.SetUnderlineStyle(underlineStyle);
       
   913 	}
       
   914 	
       
   915 void CCommandBuffer::SetStrikethroughStyleL(CBitmapContext& aBitmapContext)
       
   916 	{
       
   917 	TFontStrikethrough strikethroughStyle;
       
   918 	ReadL<TFontStrikethrough>(strikethroughStyle);
       
   919 	aBitmapContext.SetStrikethroughStyle(strikethroughStyle);		
       
   920 	}
       
   921 	
       
   922 void CCommandBuffer::SetWordJustificationL(CBitmapContext& aBitmapContext)
       
   923 	{
       
   924 	TInt excessWidth;
       
   925 	TInt numGaps;
       
   926 	
       
   927 	ReadL<TInt>(excessWidth);
       
   928 	ReadL<TInt>(numGaps);
       
   929 	aBitmapContext.SetWordJustification(excessWidth, numGaps);
       
   930 	}
       
   931 	
       
   932 void CCommandBuffer::SetCharJustificationL(CBitmapContext& aBitmapContext)
       
   933 	{
       
   934 	TInt excessWidth;
       
   935 	TInt numChars;
       
   936 	
       
   937 	ReadL<TInt>(excessWidth);
       
   938 	ReadL<TInt>(numChars);
       
   939 	aBitmapContext.SetCharJustification(excessWidth, numChars);
       
   940 	}
       
   941 
       
   942 void CCommandBuffer::SetPenColorL(CBitmapContext& aBitmapContext)
       
   943 	{
       
   944 	TRgb color;
       
   945 	ReadL<TRgb>(color);
       
   946 	
       
   947 	aBitmapContext.SetPenColor(color);
       
   948 	}
       
   949 
       
   950 void CCommandBuffer::SetPenStyleL(CBitmapContext& aBitmapContext)
       
   951 	{
       
   952 	CGraphicsContext::TPenStyle penStyle;
       
   953 	ReadL<CGraphicsContext::TPenStyle>(penStyle);
       
   954 	
       
   955 	aBitmapContext.SetPenStyle(penStyle);			
       
   956 	}
       
   957 	
       
   958 void CCommandBuffer::SetPenSizeL(CBitmapContext& aBitmapContext)
       
   959 	{
       
   960 	TSize size;
       
   961 	ReadL<TSize>(size);
       
   962 	
       
   963 	aBitmapContext.SetPenSize(size);			
       
   964 	}
       
   965 	
       
   966 void CCommandBuffer::SetBrushColorL(CBitmapContext& aBitmapContext)
       
   967 	{
       
   968 	TRgb color;
       
   969 	ReadL<TRgb>(color);
       
   970 	
       
   971 	aBitmapContext.SetBrushColor(color);
       
   972 	}
       
   973 
       
   974 void CCommandBuffer::SetBrushStyleL(CBitmapContext& aBitmapContext)
       
   975 	{
       
   976 	CGraphicsContext::TBrushStyle brushStyle;
       
   977 	ReadL<CGraphicsContext::TBrushStyle>(brushStyle);
       
   978 	
       
   979 	aBitmapContext.SetBrushStyle(brushStyle);		
       
   980 	}
       
   981 	
       
   982 void CCommandBuffer::SetBrushOriginL(CBitmapContext& aBitmapContext)
       
   983 	{
       
   984 	TPoint point;
       
   985 	ReadL<TPoint>(point);
       
   986 	
       
   987 	aBitmapContext.SetBrushOrigin(point);			
       
   988 	}
       
   989 	
       
   990 void CCommandBuffer::UseBrushPatternL(CBitmapContext& aBitmapContext)
       
   991 	{
       
   992 	TInt deviceHandle;
       
   993 	ReadL<TInt>(deviceHandle);
       
   994 	
       
   995 	if(iBitmapCache->UseL(deviceHandle)) return;
       
   996 	aBitmapContext.UseBrushPattern(iBitmapCache->Resolve(deviceHandle));
       
   997 	}
       
   998 	
       
   999 void CCommandBuffer::DiscardBrushPattern(CBitmapContext& aBitmapContext) const
       
  1000 	{
       
  1001 	aBitmapContext.DiscardBrushPattern();
       
  1002 	}
       
  1003 
       
  1004 void CCommandBuffer::MoveToL(CBitmapContext& aBitmapContext)
       
  1005 	{
       
  1006 	TPoint point;
       
  1007 	ReadL<TPoint>(point);
       
  1008 	
       
  1009 	aBitmapContext.MoveTo(point);
       
  1010 	}
       
  1011 	
       
  1012 void CCommandBuffer::MoveByL(CBitmapContext& aBitmapContext)
       
  1013 	{
       
  1014 	TPoint point;
       
  1015 	ReadL<TPoint>(point);
       
  1016 	
       
  1017 	aBitmapContext.MoveBy(point);
       
  1018 	}
       
  1019 	
       
  1020 void CCommandBuffer::PlotL(CBitmapContext& aBitmapContext)
       
  1021 	{
       
  1022 	TPoint point;
       
  1023 	ReadL<TPoint>(point);
       
  1024 	
       
  1025 	aBitmapContext.Plot(point);	
       
  1026 	}
       
  1027 	
       
  1028 void CCommandBuffer::DrawArcL(CBitmapContext& aBitmapContext)
       
  1029 	{
       
  1030 	TRect rect;
       
  1031 	TPoint start;
       
  1032 	TPoint end;
       
  1033 	ReadL<TRect>(rect);
       
  1034 	ReadL<TPoint>(start);
       
  1035 	ReadL<TPoint>(end);
       
  1036 	
       
  1037 	aBitmapContext.DrawArc(rect, start, end);
       
  1038 	}
       
  1039 	
       
  1040 void CCommandBuffer::DrawLineL(CBitmapContext& aBitmapContext)
       
  1041 	{
       
  1042 	TPoint point1;
       
  1043 	TPoint point2;
       
  1044 	ReadL<TPoint>(point1);
       
  1045 	ReadL<TPoint>(point2);
       
  1046 	
       
  1047 	aBitmapContext.DrawLine(point1, point2);
       
  1048 	}
       
  1049 	
       
  1050 void CCommandBuffer::DrawLineToL(CBitmapContext& aBitmapContext)
       
  1051 	{
       
  1052 	TPoint point;
       
  1053 	ReadL<TPoint>(point);
       
  1054 	
       
  1055 	aBitmapContext.DrawLineTo(point);
       
  1056 	}
       
  1057 	
       
  1058 void CCommandBuffer::DrawLineByL(CBitmapContext& aBitmapContext)
       
  1059 	{
       
  1060 	TPoint point;
       
  1061 	ReadL<TPoint>(point);
       
  1062 	
       
  1063 	aBitmapContext.DrawLineBy(point);			
       
  1064 	}
       
  1065 	
       
  1066 void CCommandBuffer::DrawPolyLineL(CBitmapContext& aBitmapContext)
       
  1067 	{	
       
  1068 	TInt nrOfPoints;
       
  1069 	ReadL<TInt>(nrOfPoints);
       
  1070 	
       
  1071 	CArrayFix<TPoint>* pointList = new (ELeave) CArrayFixFlat<TPoint>(5);
       
  1072 	CleanupStack::PushL(pointList);
       
  1073 	for(TInt i = 0; i < nrOfPoints; i++)
       
  1074 		{
       
  1075 		TPoint point;
       
  1076 		ReadL<TPoint>(point);
       
  1077 		pointList->AppendL(point);
       
  1078 		}
       
  1079 	
       
  1080 	aBitmapContext.DrawPolyLine(pointList);	
       
  1081 	CleanupStack::PopAndDestroy(pointList);
       
  1082 	}
       
  1083 	
       
  1084 void CCommandBuffer::DrawPieL(CBitmapContext& aBitmapContext)
       
  1085 	{
       
  1086 	TRect rect;
       
  1087 	TPoint start;
       
  1088 	TPoint end;
       
  1089 	ReadL<TRect>(rect);
       
  1090 	ReadL<TPoint>(start);
       
  1091 	ReadL<TPoint>(end);
       
  1092 	
       
  1093 	aBitmapContext.DrawPie(rect, start, end);
       
  1094 	}
       
  1095 	
       
  1096 void CCommandBuffer::DrawEllipseL(CBitmapContext& aBitmapContext)
       
  1097 	{
       
  1098 	TRect rect;
       
  1099 	ReadL<TRect>(rect);
       
  1100 	
       
  1101 	aBitmapContext.DrawEllipse(rect);
       
  1102 	}
       
  1103 	
       
  1104 void CCommandBuffer::DrawRectL(CBitmapContext& aBitmapContext)
       
  1105 	{
       
  1106 	TRect rect;
       
  1107 	ReadL<TRect>(rect);
       
  1108 	
       
  1109 	aBitmapContext.DrawRect(rect);
       
  1110 	}
       
  1111 	
       
  1112 void CCommandBuffer::DrawRoundRectL(CBitmapContext& aBitmapContext)
       
  1113 	{
       
  1114 	TRect rect;
       
  1115 	TSize ellipse;
       
  1116 	ReadL<TRect>(rect);
       
  1117 	ReadL<TSize>(ellipse);
       
  1118 	
       
  1119 	aBitmapContext.DrawRoundRect(rect, ellipse);
       
  1120 	}
       
  1121 	
       
  1122 void CCommandBuffer::DrawPolygonL(CBitmapContext& aBitmapContext)
       
  1123 	{
       
  1124 	TInt nrOfPoints;
       
  1125 	ReadL<TInt>(nrOfPoints);
       
  1126 	
       
  1127 	CArrayFix<TPoint>* pointList = new (ELeave) CArrayFixFlat<TPoint>(5);
       
  1128 	CleanupStack::PushL(pointList);
       
  1129 	for(TInt i = 0; i < nrOfPoints; i++)
       
  1130 		{
       
  1131 		TPoint point;
       
  1132 		ReadL<TPoint>(point);
       
  1133 		pointList->AppendL(point);
       
  1134 		}
       
  1135 		
       
  1136 	CGraphicsContext::TFillRule fillRule;
       
  1137 	ReadL<CGraphicsContext::TFillRule>(fillRule);
       
  1138 	aBitmapContext.DrawPolygon(pointList, fillRule);	
       
  1139 	CleanupStack::PopAndDestroy(pointList);
       
  1140 	}
       
  1141 	
       
  1142 void CCommandBuffer::DrawBitmap1L(CBitmapContext& aBitmapContext)
       
  1143 	{
       
  1144 	TPoint topLeft;
       
  1145 	TInt bitmapHandle;
       
  1146 	
       
  1147 	ReadL<TPoint>(topLeft);
       
  1148 	ReadL<TInt>(bitmapHandle);
       
  1149 	
       
  1150 	if(!iBitmapCache->UseL(bitmapHandle))
       
  1151 		aBitmapContext.DrawBitmap(topLeft, iBitmapCache->Resolve(bitmapHandle));
       
  1152 	}
       
  1153 	
       
  1154 void CCommandBuffer::DrawBitmap2L(CBitmapContext& aBitmapContext)
       
  1155 	{
       
  1156 	TRect destRect;
       
  1157 	TInt bitmapHandle;
       
  1158 	
       
  1159 	ReadL<TRect>(destRect);
       
  1160 	ReadL<TInt>(bitmapHandle);
       
  1161 	
       
  1162 	if(!iBitmapCache->UseL(bitmapHandle))
       
  1163 		aBitmapContext.DrawBitmap(destRect, iBitmapCache->Resolve(bitmapHandle));
       
  1164 	}
       
  1165 	
       
  1166 void CCommandBuffer::DrawBitmap3L(CBitmapContext& aBitmapContext)
       
  1167 	{
       
  1168 	TRect destRect;
       
  1169 	TRect sourceRect;
       
  1170 	TInt bitmapHandle;
       
  1171 	
       
  1172 	ReadL<TRect>(destRect);
       
  1173 	ReadL<TInt>(bitmapHandle);
       
  1174 	ReadL<TRect>(sourceRect);
       
  1175 	
       
  1176 	if(!iBitmapCache->UseL(bitmapHandle))
       
  1177 		aBitmapContext.DrawBitmap(destRect, iBitmapCache->Resolve(bitmapHandle), sourceRect);
       
  1178 	}
       
  1179 	
       
  1180 void CCommandBuffer::DrawBitmapMaskedL(CBitmapContext& aBitmapContext)
       
  1181 	{
       
  1182 	TRect destRect;
       
  1183 	TRect sourceRect;
       
  1184 	TInt bitmapHandle;
       
  1185 	TInt maskHandle;
       
  1186 	TBool invertedMask;
       
  1187 	
       
  1188 	ReadL<TRect>(destRect);
       
  1189 	ReadL<TInt>(bitmapHandle);
       
  1190 	ReadL<TRect>(sourceRect);
       
  1191 	ReadL<TInt>(maskHandle);
       
  1192 	ReadL<TBool>(invertedMask);
       
  1193 	
       
  1194 	if(!iBitmapCache->UseL(bitmapHandle) && !iBitmapCache->UseL(maskHandle))
       
  1195 		aBitmapContext.DrawBitmapMasked(destRect, iBitmapCache->Resolve(bitmapHandle), sourceRect, iBitmapCache->Resolve(maskHandle), invertedMask);
       
  1196 	}
       
  1197 
       
  1198 void CCommandBuffer::DrawText1L(CBitmapContext& aBitmapContext)
       
  1199 	{
       
  1200 	TPoint point;
       
  1201 
       
  1202 	TPtrC16 text;
       
  1203 	ReadTextLC(text);
       
  1204 
       
  1205 	ReadL<TPoint>(point);
       
  1206 	
       
  1207 	aBitmapContext.DrawText(text, point);
       
  1208 	CleanupStack::PopAndDestroy(); // ReadTextLC
       
  1209 	}
       
  1210 
       
  1211 void CCommandBuffer::DrawText2L(CBitmapContext& aBitmapContext)
       
  1212 	{
       
  1213 	TRect box;
       
  1214 	TInt baselineOffset;
       
  1215 	CGraphicsContext::TTextAlign horiz;
       
  1216 	TInt leftMargin;
       
  1217 	
       
  1218 	TPtrC16 text;
       
  1219 	ReadTextLC(text);
       
  1220 	
       
  1221 	ReadL<TRect>(box);
       
  1222 	ReadL<TInt>(baselineOffset);
       
  1223 	ReadL<CGraphicsContext::TTextAlign>(horiz);
       
  1224 	ReadL<TInt>(leftMargin);
       
  1225 	
       
  1226 	aBitmapContext.DrawText(text, box, baselineOffset, horiz, leftMargin);	
       
  1227 	CleanupStack::PopAndDestroy(); // ReadTextLC	
       
  1228 	}
       
  1229 	
       
  1230 void CCommandBuffer::DrawText3L(CBitmapContext& aBitmapContext)
       
  1231 	{	
       
  1232 	TPoint point;
       
  1233 	CGraphicsContext::TDrawTextParam param;
       
  1234 
       
  1235 	TPtrC16 text;
       
  1236 	ReadTextLC(text);
       
  1237 
       
  1238 	ReadL<TPoint>(point);
       
  1239 	ReadL<CGraphicsContext::TDrawTextParam>(param);
       
  1240 	
       
  1241 	aBitmapContext.DrawText(text, point, param);	
       
  1242 	CleanupStack::PopAndDestroy(); //ReadTextLC
       
  1243 	}
       
  1244 
       
  1245 void CCommandBuffer::MapColorsL(CBitmapContext& aBitmapContext)
       
  1246 	{
       
  1247 	TRect rect;
       
  1248 	TInt nrOfPairs;
       
  1249 	ReadL<TRect>(rect);
       
  1250 	ReadL<TInt>(nrOfPairs);
       
  1251 	
       
  1252 	TRgb* colorList = new (ELeave) TRgb [nrOfPairs*2]; // Every pair has two colors
       
  1253 	CleanupArrayDeletePushL(colorList);
       
  1254 	for(TInt i = 0; i < nrOfPairs; i++)
       
  1255 		{
       
  1256 		TRgb color;
       
  1257 		ReadL<TRgb>(color);
       
  1258 		colorList[i] = color;
       
  1259 		
       
  1260 		ReadL<TRgb>(color);
       
  1261 		colorList[i+1] = color;		
       
  1262 		}
       
  1263 		
       
  1264 	TBool mapForwards;
       
  1265 	ReadL<TBool>(mapForwards);		
       
  1266 	
       
  1267 	aBitmapContext.MapColors(rect, colorList, nrOfPairs, mapForwards);	
       
  1268 	CleanupStack::PopAndDestroy(colorList);
       
  1269 	}
       
  1270 
       
  1271 void CCommandBuffer::SetClippingRegionL(CBitmapContext& aBitmapContext)
       
  1272 	{
       
  1273 	TInt nrOfRects;
       
  1274 	ReadL<TInt>(nrOfRects);
       
  1275 	
       
  1276 	TRect rect;
       
  1277 	iClippingRegion.Clear();
       
  1278 	for(TInt i = 0; i < nrOfRects; i++)
       
  1279 		{		
       
  1280 		ReadL<TRect>(rect);
       
  1281 //		rect.Move(iMasterOrigin);
       
  1282 		iClippingRegion.AddRect(rect);
       
  1283 		}
       
  1284 	
       
  1285 	iParsedClippingRegionIsSet = ETrue;
       
  1286 	if(iActiveMasterClippingRegion)
       
  1287 		iClippingRegion.Intersect(*iActiveMasterClippingRegion);
       
  1288 	
       
  1289 	aBitmapContext.SetClippingRegion(iClippingRegion);
       
  1290 	}
       
  1291 	
       
  1292 void CCommandBuffer::CancelClippingRegion(CBitmapContext& aBitmapContext)
       
  1293 	{
       
  1294 	iClippingRegion.Clear();
       
  1295 	iParsedClippingRegionIsSet = EFalse;
       
  1296 	if(iActiveMasterClippingRegion)
       
  1297 		aBitmapContext.SetClippingRegion(*iActiveMasterClippingRegion);	
       
  1298 	else
       
  1299 		aBitmapContext.CancelClippingRegion();
       
  1300 	}
       
  1301 
       
  1302 void CCommandBuffer::DrawTextVertical1L(CBitmapContext& aBitmapContext)
       
  1303 	{
       
  1304 	TPoint point;
       
  1305 	TBool up;
       
  1306 
       
  1307 	TPtrC16 text;
       
  1308 	ReadTextLC(text);
       
  1309 
       
  1310 	ReadL<TPoint>(point);
       
  1311 	ReadL<TBool>(up);
       
  1312 	
       
  1313 	aBitmapContext.DrawTextVertical(text, point, up);	
       
  1314 	CleanupStack::PopAndDestroy(); // ReadTextLC
       
  1315 	}
       
  1316 	
       
  1317 void CCommandBuffer::DrawTextVertical2L(CBitmapContext& aBitmapContext)
       
  1318 	{
       
  1319 	TRect box;
       
  1320 	TInt baselineOffset;
       
  1321 	TBool up;
       
  1322 	CGraphicsContext::TTextAlign vertical;
       
  1323 	TInt margin;
       
  1324 
       
  1325 	TPtrC16 text;
       
  1326 	ReadTextLC(text);
       
  1327 
       
  1328 	ReadL<TRect>(box);
       
  1329 	ReadL<TInt>(baselineOffset);
       
  1330 	ReadL<TBool>(up);
       
  1331 	ReadL<CGraphicsContext::TTextAlign>(vertical);
       
  1332 	ReadL<TInt>(margin);
       
  1333 	
       
  1334 	aBitmapContext.DrawTextVertical(text, box, baselineOffset, up, vertical, margin);	
       
  1335 	CleanupStack::PopAndDestroy(); //ReadTextLC
       
  1336 	}
       
  1337 
       
  1338 void CCommandBuffer::DrawWsGraphic1L(const MWsGraphicResolver& aWsGraphicResolver)
       
  1339 	{
       
  1340 	TInt id;
       
  1341 	TBool isUid;
       
  1342 	TRect rect;
       
  1343 	
       
  1344 	ReadL<TInt>(id);
       
  1345 	ReadL<TBool>(isUid);
       
  1346 	ReadL<TRect>(rect);
       
  1347 	
       
  1348 	aWsGraphicResolver.DrawWsGraphic(id,isUid,rect,KNullDesC8());
       
  1349 	}
       
  1350 	
       
  1351 void CCommandBuffer::DrawWsGraphic2L(const MWsGraphicResolver& aWsGraphicResolver)
       
  1352 	{
       
  1353 	TInt id;
       
  1354 	TBool isUid;
       
  1355 	TRect rect;
       
  1356 	
       
  1357 	ReadL<TInt>(id);
       
  1358 	ReadL<TBool>(isUid);
       
  1359 	ReadL<TRect>(rect);	
       
  1360 	TPtrC8 text8;
       
  1361 	ReadTextLC(text8);
       
  1362 	
       
  1363 	aWsGraphicResolver.DrawWsGraphic(id,isUid,rect,text8);	
       
  1364 	CleanupStack::PopAndDestroy(); //ReadTextLC
       
  1365 	}
       
  1366 
       
  1367 void CCommandBuffer::SetShadowColorL(CBitmapContext& aBitmapContext)
       
  1368 	{
       
  1369 	TRgb shadowColor;
       
  1370 	ReadL<TRgb>(shadowColor);
       
  1371 
       
  1372 	aBitmapContext.SetShadowColor(shadowColor);
       
  1373 	}