windowing/windowserver/tauto/directgdigcwrapper.cpp
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 2008-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 "directgdigcwrapper.h"
       
    17 #include "mwsgraphicscontexttodirectgdimappings.h"
       
    18 #include <s32mem.h>
       
    19 #include "stdpanic.h"
       
    20 #include <graphics/lookuptable.h>
       
    21 #include <graphics/directgdidriver.h>
       
    22 #include <graphics/directgdidrawablesource.h>
       
    23 
       
    24 void Panic(TStdPluginPanic aPanic)
       
    25 	{
       
    26 	_LIT(KStdPanicCategory, "WSERV-TEST-PLUGIN");
       
    27 	User::Panic(KStdPanicCategory, aPanic);
       
    28 	}
       
    29 
       
    30 CDirectGdiGcWrapper* CDirectGdiGcWrapper::NewL(RDirectGdiImageTarget& aTarget)
       
    31 	{
       
    32 	CDirectGdiGcWrapper* self = new(ELeave) CDirectGdiGcWrapper;
       
    33 	CleanupStack::PushL(self);
       
    34 	CDirectGdiDriver* driver = CDirectGdiDriver::Static();
       
    35 	User::LeaveIfNull(driver);
       
    36 	self->iContext = CDirectGdiContext::NewL(*driver);
       
    37 	TInt err = self->iContext->Activate(aTarget);
       
    38 	User::LeaveIfError(err);
       
    39 	self->iErrorCode = KErrNone;
       
    40 	self->iGcBuf = CBufSeg::NewL(512);
       
    41 	//MWsFader
       
    42 	//Default in BitGdi was 128 for the blackMap and 255 for the whiteMap
       
    43 	//SetFadingParameters shows how the fade color is computed
       
    44 	self->iFadeColor.SetInternal(0x80FFFFFF);
       
    45 	
       
    46 	self->iLut = PtrTo16BitNormalisationTable();
       
    47 	CleanupStack::Pop(self);
       
    48 	return self;
       
    49 	}
       
    50 
       
    51 CDirectGdiGcWrapper::~CDirectGdiGcWrapper()
       
    52 	{
       
    53 	delete iContext;
       
    54 	delete iGcBuf;
       
    55 	iClippingRegion.Close();
       
    56 	}
       
    57 
       
    58 void CDirectGdiGcWrapper::BitBlt(const TPoint& aDestPos, const CFbsBitmap& aSourceBitmap)
       
    59 	{
       
    60 	iContext->BitBlt(aDestPos, aSourceBitmap);
       
    61 	}
       
    62 
       
    63 void CDirectGdiGcWrapper::BitBlt(const TPoint& aDestPos, const CFbsBitmap& aSourceBitmap, const TRect& aSourceRect)
       
    64 	{
       
    65 	iContext->BitBlt(aDestPos, aSourceBitmap, aSourceRect);
       
    66 	}
       
    67 
       
    68 void CDirectGdiGcWrapper::BitBltMasked(const TPoint& aDestPos,	const CFbsBitmap& aSourceBitmap, const TRect& aSourceRect, const CFbsBitmap& aMaskBitmap, TBool aInvertMask)
       
    69 	{
       
    70 	iContext->BitBltMasked(aDestPos, aSourceBitmap, aSourceRect, aMaskBitmap, aInvertMask);
       
    71 	}
       
    72 
       
    73 void CDirectGdiGcWrapper::BitBltMasked(const TPoint& aDestPos, const CFbsBitmap& aSourceBitmap, const TRect& aSourceRect, const CFbsBitmap& aMaskBitmap, const TPoint& aMaskPos)
       
    74 	{
       
    75 	iContext->BitBltMasked(aDestPos, aSourceBitmap, aSourceRect, aMaskBitmap, aMaskPos);
       
    76 	}
       
    77 
       
    78 void CDirectGdiGcWrapper::ResetClippingRegion()
       
    79 	{
       
    80 	iContext->ResetClippingRegion();
       
    81 	}
       
    82 
       
    83 void CDirectGdiGcWrapper::Clear()
       
    84 	{
       
    85 	iContext->Clear();
       
    86 	}
       
    87 
       
    88 void CDirectGdiGcWrapper::Clear(const TRect& aRect)
       
    89 	{
       
    90 	iContext->Clear(aRect);
       
    91 	}
       
    92 
       
    93 void CDirectGdiGcWrapper::ResetBrushPattern()
       
    94 	{
       
    95 	iContext->ResetBrushPattern();
       
    96 	}
       
    97 
       
    98 void CDirectGdiGcWrapper::ResetFont()
       
    99 	{
       
   100 	iContext->ResetFont();
       
   101 	}
       
   102 
       
   103 void CDirectGdiGcWrapper::DrawArc(const TRect& aRect, const TPoint& aStart, const TPoint& aEnd)
       
   104 	{
       
   105 	iContext->DrawArc(aRect, aStart, aEnd);
       
   106 	}
       
   107 
       
   108 void CDirectGdiGcWrapper::DrawPie(const TRect& aRect, const TPoint& aStart, const TPoint& aEnd)
       
   109 	{
       
   110 	iContext->DrawPie(aRect, aStart, aEnd);
       
   111 	}
       
   112 
       
   113 void CDirectGdiGcWrapper::DrawBitmap(const TRect& aDestRect, const CFbsBitmap& aSourceBitmap)
       
   114 	{
       
   115 	iContext->DrawBitmap(aDestRect, aSourceBitmap);
       
   116 	}
       
   117 
       
   118 void CDirectGdiGcWrapper::DrawBitmap(const TRect& aDestRect, const CFbsBitmap& aSourceBitmap, const TRect& aSourceRect)
       
   119 	{
       
   120 	iContext->DrawBitmap(aDestRect,	aSourceBitmap, aSourceRect);
       
   121 	}
       
   122 
       
   123 void CDirectGdiGcWrapper::DrawBitmapMasked(const TRect& aDestRect, const CFbsBitmap& aSourceBitmap, const TRect& aSourceRect, const CFbsBitmap& aMaskBitmap, TBool aInvertMask)
       
   124 	{
       
   125 	iContext->DrawBitmapMasked(aDestRect, aSourceBitmap, aSourceRect, aMaskBitmap, aInvertMask);
       
   126 	}
       
   127 
       
   128 void CDirectGdiGcWrapper::DrawRoundRect(const TRect& aRect, const TSize& aEllipse)
       
   129 	{
       
   130 	iContext->DrawRoundRect(aRect, aEllipse);
       
   131 	}
       
   132 
       
   133 void CDirectGdiGcWrapper::DrawPolyLine(const TArray<TPoint>& aPointList)
       
   134 	{
       
   135 	iContext->DrawPolyLine(aPointList);
       
   136 	}
       
   137 
       
   138 void CDirectGdiGcWrapper::DrawPolyLineNoEndPoint(const TArray<TPoint>& aPointList)
       
   139 	{
       
   140 	iContext->DrawPolyLineNoEndPoint(aPointList);
       
   141 	}
       
   142 
       
   143 void CDirectGdiGcWrapper::DrawPolygon(const TArray<TPoint>& aPointList, TFillRule aFillRule)
       
   144 	{
       
   145 	iContext->DrawPolygon(aPointList, MWsGraphicsContextToDirectGdiMappings::Convert(aFillRule));
       
   146 	}
       
   147 
       
   148 void CDirectGdiGcWrapper::DrawEllipse(const TRect& aRect)
       
   149 	{
       
   150 	iContext->DrawEllipse(aRect);
       
   151 	}
       
   152 
       
   153 void CDirectGdiGcWrapper::DrawLine(const TPoint& aStart, const TPoint& aEnd)
       
   154 	{
       
   155 	iContext->DrawLine(aStart, aEnd);
       
   156 	}
       
   157 
       
   158 void CDirectGdiGcWrapper::DrawLineTo(const TPoint& aPoint)
       
   159 	{
       
   160 	iContext->DrawLineTo(aPoint);
       
   161 	}
       
   162 
       
   163 void CDirectGdiGcWrapper::DrawLineBy(const TPoint& aVector)
       
   164 	{
       
   165 	iContext->DrawLineBy(aVector);
       
   166 	}
       
   167 
       
   168 void CDirectGdiGcWrapper::DrawRect(const TRect& aRect)
       
   169 	{
       
   170 	iContext->DrawRect(aRect);
       
   171 	}
       
   172 
       
   173 void CDirectGdiGcWrapper::DrawText(const TDesC& aText,const TTextParameters* aParam)
       
   174 	{
       
   175 	iContext->DrawText(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam));
       
   176 	}
       
   177 
       
   178 void CDirectGdiGcWrapper::DrawText(const TDesC& aText,const TTextParameters* aParam,const TPoint& aPosition)
       
   179 	{
       
   180 	iContext->DrawText(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam), aPosition);
       
   181 	}
       
   182 
       
   183 void CDirectGdiGcWrapper::DrawText(const TDesC& aText,const TTextParameters* aParam,const TRect& aClipRect)
       
   184 	{
       
   185 	iContext->DrawText(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam), aClipRect);
       
   186 	}
       
   187 
       
   188 void CDirectGdiGcWrapper::DrawText(const TDesC& aText,const TTextParameters* aParam,const TRect& aClipFillRect,TInt aBaselineOffset, TTextAlign aHrz,TInt aMargin)
       
   189 	{
       
   190 	iContext->DrawText(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam), aClipFillRect, aBaselineOffset, MWsGraphicsContextToDirectGdiMappings::Convert(aHrz), aMargin);
       
   191 	}
       
   192 
       
   193 void CDirectGdiGcWrapper::DrawTextVertical(const TDesC& aText,const TTextParameters* aParam,TBool aUp)
       
   194 	{
       
   195 	iContext->DrawTextVertical(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam), aUp);
       
   196 	}
       
   197 
       
   198 void CDirectGdiGcWrapper::DrawTextVertical(const TDesC& aText,const TTextParameters* aParam,const TPoint& aPosition,TBool aUp)
       
   199 	{
       
   200 	iContext->DrawTextVertical(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam), aPosition, aUp);
       
   201 	}
       
   202 
       
   203 void CDirectGdiGcWrapper::DrawTextVertical(const TDesC& aText,const TTextParameters* aParam,const TRect& aClipRect,TBool aUp)
       
   204 	{
       
   205 	iContext->DrawTextVertical(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam), aClipRect, aUp);
       
   206 	}
       
   207 
       
   208 void CDirectGdiGcWrapper::DrawTextVertical(const TDesC& aText,const TTextParameters* aParam,const TRect& aClipRect,TInt aBaselineOffset,TBool aUp,TTextAlign aVert,TInt aMargin)
       
   209 	{
       
   210 	iContext->DrawTextVertical(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam), aClipRect, aBaselineOffset, aUp, MWsGraphicsContextToDirectGdiMappings::Convert(aVert), aMargin);
       
   211 	}
       
   212 
       
   213 void CDirectGdiGcWrapper::DrawTextVertical(const TDesC& aText,const TTextParameters* aParam,const TRect& aClipRect,TInt aBaselineOffset,TInt aTextWidth,TBool aUp,TTextAlign aVert,TInt aMargin)
       
   214 	{
       
   215 	iContext->DrawTextVertical(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam), aClipRect, aBaselineOffset, aTextWidth, aUp, MWsGraphicsContextToDirectGdiMappings::Convert(aVert), aMargin);
       
   216 	}
       
   217 
       
   218 void CDirectGdiGcWrapper::MoveTo(const TPoint& aPoint)
       
   219 	{
       
   220 	iContext->MoveTo(aPoint);
       
   221 	}
       
   222 
       
   223 void CDirectGdiGcWrapper::MoveBy(const TPoint& aVector)
       
   224 	{
       
   225 	iContext->MoveBy(aVector);
       
   226 	}
       
   227 
       
   228 void CDirectGdiGcWrapper::Plot(const TPoint& aPoint)
       
   229 	{
       
   230 	iContext->Plot(aPoint);
       
   231 	}
       
   232 
       
   233 void CDirectGdiGcWrapper::Reset()
       
   234 	{
       
   235 	iContext->Reset();
       
   236 	}
       
   237 
       
   238 void CDirectGdiGcWrapper::SetBrushColor(const TRgb& aColor)
       
   239 	{
       
   240 	iContext->SetBrushColor(aColor);
       
   241 	}
       
   242 
       
   243 void CDirectGdiGcWrapper::SetBrushOrigin(const TPoint& aOrigin)
       
   244 	{
       
   245 	iContext->SetBrushOrigin(aOrigin);
       
   246 	}
       
   247 
       
   248 void CDirectGdiGcWrapper::SetBrushStyle(TBrushStyle aBrushStyle)
       
   249 	{
       
   250 	iContext->SetBrushStyle(MWsGraphicsContextToDirectGdiMappings::Convert(aBrushStyle));
       
   251 	}
       
   252 
       
   253 void CDirectGdiGcWrapper::SetClippingRegion(const TRegion& aRegion)
       
   254 	{
       
   255 	CDirectGdiDriver* driver = CDirectGdiDriver::Static();
       
   256 	driver->GetError(); //make sure that an error has been received 
       
   257 	iContext->SetClippingRegion(aRegion);
       
   258 	TInt err = driver->GetError();
       
   259 	SetError(err);
       
   260 	if(err == KErrNone)
       
   261 		{
       
   262 		iClippingRegion.Copy(aRegion);
       
   263 		}
       
   264 	}
       
   265 
       
   266 void CDirectGdiGcWrapper::SetDrawMode(TDrawMode aDrawMode)
       
   267 	{
       
   268 	iContext->SetDrawMode(MWsGraphicsContextToDirectGdiMappings::LossyConvert(aDrawMode));
       
   269 	}
       
   270 
       
   271 void CDirectGdiGcWrapper::SetOrigin(const TPoint& aPoint)
       
   272 	{
       
   273 	iContext->SetOrigin(aPoint);
       
   274 	iOrigin = aPoint;
       
   275 	}
       
   276 
       
   277 void CDirectGdiGcWrapper::SetPenColor(const TRgb& aColor)
       
   278 	{
       
   279 	iContext->SetPenColor(aColor);
       
   280 	}
       
   281 
       
   282 void CDirectGdiGcWrapper::SetPenStyle(TPenStyle aPenStyle)
       
   283 	{
       
   284 	iContext->SetPenStyle(MWsGraphicsContextToDirectGdiMappings::Convert(aPenStyle));
       
   285 	}
       
   286 
       
   287 void CDirectGdiGcWrapper::SetPenSize(const TSize& aSize)
       
   288 	{
       
   289 	iContext->SetPenSize(aSize);
       
   290 	}
       
   291 
       
   292 void CDirectGdiGcWrapper::SetTextShadowColor(const TRgb& aColor)
       
   293 	{
       
   294 	iContext->SetTextShadowColor(aColor);
       
   295 	}
       
   296 
       
   297 void CDirectGdiGcWrapper::SetCharJustification(TInt aExcessWidth, TInt aNumChars)
       
   298 	{
       
   299 	iContext->SetCharJustification(aExcessWidth, aNumChars);
       
   300 	}
       
   301 
       
   302 void CDirectGdiGcWrapper::SetWordJustification(TInt aExcessWidth, TInt aNumGaps)
       
   303 	{
       
   304 	iContext->SetWordJustification(aExcessWidth, aNumGaps);
       
   305 	}
       
   306 
       
   307 void CDirectGdiGcWrapper::SetUnderlineStyle(TFontUnderline aUnderlineStyle)
       
   308 	{
       
   309 	iContext->SetUnderlineStyle(MWsGraphicsContextToDirectGdiMappings::Convert(aUnderlineStyle));
       
   310 	}
       
   311 
       
   312 void CDirectGdiGcWrapper::SetStrikethroughStyle(TFontStrikethrough aStrikethroughStyle)
       
   313 	{
       
   314 	iContext->SetStrikethroughStyle(MWsGraphicsContextToDirectGdiMappings::Convert(aStrikethroughStyle));
       
   315 	}
       
   316 
       
   317 void CDirectGdiGcWrapper::SetBrushPattern(const CFbsBitmap& aBitmap)
       
   318 	{
       
   319 	iContext->SetBrushPattern(aBitmap);
       
   320 	}
       
   321 
       
   322 void CDirectGdiGcWrapper::SetBrushPattern(TInt aFbsBitmapHandle)
       
   323 	{
       
   324 	iContext->SetBrushPattern(aFbsBitmapHandle);
       
   325 	}
       
   326 
       
   327 void CDirectGdiGcWrapper::SetFont(const CFont* aFont)
       
   328 	{
       
   329 	iContext->SetFont(aFont);
       
   330 	}
       
   331 
       
   332 void CDirectGdiGcWrapper::CopyRect(const TPoint& aOffset, const TRect& aRect)
       
   333 	{
       
   334 	iContext->CopyRect(aOffset, aRect);
       
   335 	}
       
   336 
       
   337 void CDirectGdiGcWrapper::UpdateJustification(const TDesC& aText,const TTextParameters* aParam)
       
   338 	{
       
   339 	iContext->UpdateJustification(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam));
       
   340 	}
       
   341 
       
   342 void CDirectGdiGcWrapper::UpdateJustificationVertical(const TDesC& aText,const TTextParameters* aParam,TBool aUp)
       
   343 	{
       
   344 	iContext->UpdateJustificationVertical(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam), aUp);
       
   345 	}
       
   346 
       
   347 void CDirectGdiGcWrapper::SetFontNoDuplicate(const CFont* aFont)
       
   348 	{
       
   349 	iContext->SetFontNoDuplicate(static_cast<const CDirectGdiFont*>(aFont));
       
   350 	}
       
   351 
       
   352 TBool CDirectGdiGcWrapper::HasBrushPattern() const
       
   353 	{
       
   354 	return iContext->HasBrushPattern();
       
   355 	}
       
   356 
       
   357 TBool CDirectGdiGcWrapper::HasFont() const
       
   358 	{
       
   359 	return iContext->HasFont();
       
   360 	}
       
   361 
       
   362 TRgb CDirectGdiGcWrapper::BrushColor() const
       
   363 	{
       
   364 	return iContext->BrushColor();
       
   365 	}
       
   366 
       
   367 TRgb CDirectGdiGcWrapper::PenColor() const
       
   368 	{
       
   369 	return iContext->PenColor();
       
   370 	}
       
   371 
       
   372 TRgb CDirectGdiGcWrapper::TextShadowColor() const
       
   373 	{
       
   374 	return iContext->TextShadowColor();
       
   375 	}
       
   376 
       
   377 TAny* CDirectGdiGcWrapper::ResolveObjectInterface(TUint /*aTypeId*/)
       
   378 	{
       
   379 	return NULL;
       
   380 	}
       
   381 
       
   382 /**
       
   383 Sets the error code. If the error code is already set to a value other
       
   384 than KErrNone, the error code will not be modified.
       
   385 
       
   386 @param  aErr The error code to set.
       
   387 
       
   388 @post 	The error code has been set.
       
   389 */
       
   390 void CDirectGdiGcWrapper::SetError(TInt aError)
       
   391 	{
       
   392 	if (aError != KErrNone && iErrorCode == KErrNone)
       
   393 		{
       
   394 		iErrorCode = aError;
       
   395 		}
       
   396 	}
       
   397 
       
   398 /**
       
   399 Returns the first error code (set as the result of calling some CDirectGdiGcWrapper API), if any,
       
   400 since the last call to this function or, if it has not previously been called, since
       
   401 the CDirectGdiGcWrapper was constructed. Calling this function clears the error code.
       
   402 
       
   403 @post 	The error code has been reset after being read.
       
   404 
       
   405 @return The first error code, if any, since the last call to this function or, 
       
   406 		if it has not previously been called, since the CDirectGdiGcWrapper was constructed. 
       
   407 		KErrNone will indicate that no such error has occurred.
       
   408 */
       
   409 TInt CDirectGdiGcWrapper::GetError()
       
   410 	{
       
   411 	TInt err = iErrorCode;
       
   412 	iErrorCode = KErrNone;
       
   413 	return err;
       
   414 	}
       
   415 
       
   416 TPoint CDirectGdiGcWrapper::Origin() const
       
   417 	{
       
   418 	return iOrigin;
       
   419 	}
       
   420 
       
   421 const TRegion& CDirectGdiGcWrapper::ClippingRegion()
       
   422 	{
       
   423 	return iClippingRegion;
       
   424 	}
       
   425 
       
   426 TInt CDirectGdiGcWrapper::Push()
       
   427 	{
       
   428 	// the buf format is len+data where data is written by the GC's ExternalizeL()
       
   429 	iGcBuf->Reset();
       
   430 	CBufBase& buf = *iGcBuf;
       
   431 	const TInt start = buf.Size();
       
   432 	RBufWriteStream out(buf,start);
       
   433 	TRAPD(err,out.WriteInt32L(0));
       
   434 	if(!err)
       
   435 		{
       
   436 		TRAP(err,iContext->ExternalizeL(out));
       
   437 		}
       
   438 	if(err) //rollback addition
       
   439 		{
       
   440 		buf.Delete(start,buf.Size()-start);
       
   441 		}
       
   442 	else //fixup len
       
   443 		{
       
   444 		TRAP_IGNORE(out.CommitL();) // can't see this failing
       
   445 		TPckgBuf<TInt32> pckg(buf.Size()-sizeof(TInt32)-start);
       
   446 		buf.Write(start,pckg);
       
   447 		}
       
   448 	return err;
       
   449 	}
       
   450 
       
   451 void CDirectGdiGcWrapper::Pop()
       
   452 	{
       
   453 	CBufBase& buf = *iGcBuf;
       
   454 	TInt ofs = 0;
       
   455 	FOREVER
       
   456 		{
       
   457 		TInt chunk = 0;
       
   458 		RBufReadStream in(buf,ofs);
       
   459 		TRAPD(err,chunk = in.ReadInt32L());
       
   460 		if(err)
       
   461 			{
       
   462 			STD_ASSERT_DEBUG(err != 0, EStdPanicPopGcSettings);
       
   463 			return;
       
   464 			}
       
   465 		if(ofs+sizeof(TInt32)+chunk >= buf.Size()) // the last chunk?
       
   466 			{
       
   467 			TRAP_IGNORE(iContext->InternalizeL(in));
       
   468 			buf.Delete(ofs,buf.Size()-ofs);
       
   469 			return;
       
   470 			}
       
   471 		ofs += chunk + sizeof(TInt32);
       
   472 		}
       
   473 	}
       
   474 
       
   475 //Default method of fading simply uses bitgdi to perform fading
       
   476 void CDirectGdiGcWrapper::FadeArea(const TRegion& aRegion)
       
   477 	{
       
   478 	if (!&aRegion || aRegion.CheckError())
       
   479 		return;
       
   480 
       
   481 	iContext->Reset();
       
   482 	iContext->SetClippingRegion(aRegion);
       
   483 	iContext->SetPenStyle(DirectGdi::ENullPen);
       
   484 	iContext->SetBrushStyle(DirectGdi::ESolidBrush);
       
   485 	iContext->SetBrushColor(iFadeColor);
       
   486 	iContext->DrawRect(aRegion.BoundingRect());
       
   487 	}
       
   488 	
       
   489 //Default method of fading expects two TUint8's describing the black/white map 
       
   490 //as possible fading parameters
       
   491 void CDirectGdiGcWrapper::SetFadingParameters(const TDesC8& aData)
       
   492   	{
       
   493 	TPckgBuf<TFadingParams> buf;
       
   494 	buf.Copy(aData);
       
   495 	TFadingParams parameters = buf();
       
   496 
       
   497 	//Situations where blackMap > whiteMap are NOT supported
       
   498 	if (parameters.blackMap > parameters.whiteMap)
       
   499 		{
       
   500 		TUint8 oldMap = parameters.blackMap;
       
   501 		parameters.blackMap = parameters.whiteMap;
       
   502 		parameters.whiteMap = oldMap;
       
   503 		}
       
   504 	
       
   505 	//CFbsBitGc::FadeArea() does the following per color component:
       
   506 	//   dst = dst * (whiteMap - blackMap) + blackMap;
       
   507 
       
   508 	//To achieve the same effect using MWsGraphicsContext we draw a rectangle
       
   509 	//with specific intensity and alpha values:
       
   510 	//   dst = dst * (1 - alpha) + intensity * alpha;
       
   511 	//Thus:
       
   512 	//   alpha = 1 - whiteMap + blackMap;
       
   513 	//   intensity = blackMap / alpha;
       
   514 
       
   515 	// alpha = 1 - whiteMap + blackMap;
       
   516 	TInt alpha = 255 - parameters.whiteMap + parameters.blackMap;
       
   517 	// intensity = blackMap / alpha;
       
   518 	TInt i = (parameters.blackMap * iLut[alpha]) >> 8;
       
   519 
       
   520 	iFadeColor.SetInternal(i << 16 | i << 8 | i | alpha << 24);
       
   521   	}