os/graphics/windowing/windowserverplugins/openwfc/src/directgdigcwrapper.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/windowing/windowserverplugins/openwfc/src/directgdigcwrapper.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,705 @@
     1.4 +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include "directgdigcwrapper.h"
    1.20 +#include <s32mem.h>
    1.21 +#include <graphics/lookuptable.h>
    1.22 +#include <graphics/directgdidriver.h>
    1.23 +#include <graphics/directgdidrawablesource.h>
    1.24 +#include <graphics/sgresourceinternal.h>
    1.25 +#include "mwsgraphicscontexttodirectgdimappings.h"
    1.26 +#include "panic.h"
    1.27 +
    1.28 +CDirectGdiGcWrapper* CDirectGdiGcWrapper::NewL()
    1.29 +	{
    1.30 +	CDirectGdiGcWrapper* self = new(ELeave) CDirectGdiGcWrapper;
    1.31 +	CleanupStack::PushL(self);
    1.32 +	CDirectGdiDriver* driver = CDirectGdiDriver::Static();
    1.33 +	User::LeaveIfNull(driver);
    1.34 +	self->iContext = CDirectGdiContext::NewL(*driver);
    1.35 +	self->iErrorCode = KErrNone;
    1.36 +	self->iGcBuf = CBufSeg::NewL(512);
    1.37 +	//MWsFader
    1.38 +	//Default in BitGdi was 128 for the blackMap and 255 for the whiteMap
    1.39 +	//SetFadingParameters shows how the fade color is computed
    1.40 +	self->iFadeColor.SetInternal(0x80FFFFFF);
    1.41 +	
    1.42 +	self->iLut = PtrTo16BitNormalisationTable();
    1.43 +	CleanupStack::Pop(self);
    1.44 +	return self;
    1.45 +	}
    1.46 +
    1.47 +CDirectGdiGcWrapper::~CDirectGdiGcWrapper()
    1.48 +	{
    1.49 +	delete iContext;
    1.50 +	delete iGcBuf;
    1.51 +	for (TInt i = 0; i < iDrawableSources.Count(); ++i)
    1.52 +		{
    1.53 +		iDrawableSources[i]->Close();
    1.54 +		}
    1.55 +	iDrawableSources.ResetAndDestroy();
    1.56 +	iClippingRegion.Close();
    1.57 +	}
    1.58 +
    1.59 +TAny* CDirectGdiGcWrapper::ResolveObjectInterface(TUint aTypeId)
    1.60 +	{
    1.61 +	switch(aTypeId)
    1.62 +		{
    1.63 +	case MWsGraphicsContext::EWsObjectInterfaceId:
    1.64 +		return static_cast<MWsGraphicsContext*>(this);
    1.65 +	case MWsFader::EWsObjectInterfaceId:
    1.66 +		return static_cast<MWsFader*>(this);
    1.67 +	case MWsDrawableSourceProvider::EWsObjectInterfaceId:
    1.68 +		return static_cast<MWsDrawableSourceProvider*>(this);
    1.69 +	case MWsTextCursor::EWsObjectInterfaceId:
    1.70 +		return static_cast<MWsTextCursor*>(this);
    1.71 +		}
    1.72 +	return NULL;
    1.73 +	}
    1.74 +
    1.75 +void CDirectGdiGcWrapper::BitBlt(const TPoint& aDestPos, const CFbsBitmap& aSourceBitmap)
    1.76 +	{
    1.77 +	iContext->BitBlt(aDestPos, aSourceBitmap);
    1.78 +	}
    1.79 +
    1.80 +void CDirectGdiGcWrapper::BitBlt(const TPoint& aDestPos, const CFbsBitmap& aSourceBitmap, const TRect& aSourceRect)
    1.81 +	{
    1.82 +	iContext->BitBlt(aDestPos, aSourceBitmap, aSourceRect);
    1.83 +	}
    1.84 +
    1.85 +void CDirectGdiGcWrapper::BitBltMasked(const TPoint& aDestPos,	const CFbsBitmap& aSourceBitmap, const TRect& aSourceRect, const CFbsBitmap& aMaskBitmap, TBool aInvertMask)
    1.86 +	{
    1.87 +	iContext->BitBltMasked(aDestPos, aSourceBitmap, aSourceRect, aMaskBitmap, aInvertMask);
    1.88 +	}
    1.89 +
    1.90 +void CDirectGdiGcWrapper::BitBltMasked(const TPoint& aDestPos, const CFbsBitmap& aSourceBitmap, const TRect& aSourceRect, const CFbsBitmap& aMaskBitmap, const TPoint& aMaskPos)
    1.91 +	{
    1.92 +	iContext->BitBltMasked(aDestPos, aSourceBitmap, aSourceRect, aMaskBitmap, aMaskPos);
    1.93 +	}
    1.94 +
    1.95 +void CDirectGdiGcWrapper::ResetClippingRegion()
    1.96 +	{
    1.97 +	iContext->ResetClippingRegion();
    1.98 +	}
    1.99 +
   1.100 +void CDirectGdiGcWrapper::Clear()
   1.101 +	{
   1.102 +	iContext->Clear();
   1.103 +	}
   1.104 +
   1.105 +void CDirectGdiGcWrapper::Clear(const TRect& aRect)
   1.106 +	{
   1.107 +	iContext->Clear(aRect);
   1.108 +	}
   1.109 +
   1.110 +void CDirectGdiGcWrapper::ResetBrushPattern()
   1.111 +	{
   1.112 +	iContext->ResetBrushPattern();
   1.113 +	}
   1.114 +
   1.115 +void CDirectGdiGcWrapper::ResetFont()
   1.116 +	{
   1.117 +	iContext->ResetFont();
   1.118 +	}
   1.119 +
   1.120 +void CDirectGdiGcWrapper::DrawArc(const TRect& aRect, const TPoint& aStart, const TPoint& aEnd)
   1.121 +	{
   1.122 +	iContext->DrawArc(aRect, aStart, aEnd);
   1.123 +	}
   1.124 +
   1.125 +void CDirectGdiGcWrapper::DrawPie(const TRect& aRect, const TPoint& aStart, const TPoint& aEnd)
   1.126 +	{
   1.127 +	iContext->DrawPie(aRect, aStart, aEnd);
   1.128 +	}
   1.129 +
   1.130 +void CDirectGdiGcWrapper::DrawBitmap(const TRect& aDestRect, const CFbsBitmap& aSourceBitmap)
   1.131 +	{
   1.132 +	iContext->DrawBitmap(aDestRect, aSourceBitmap);
   1.133 +	}
   1.134 +
   1.135 +void CDirectGdiGcWrapper::DrawBitmap(const TRect& aDestRect, const CFbsBitmap& aSourceBitmap, const TRect& aSourceRect)
   1.136 +	{
   1.137 +	iContext->DrawBitmap(aDestRect,	aSourceBitmap, aSourceRect);
   1.138 +	}
   1.139 +
   1.140 +void CDirectGdiGcWrapper::DrawBitmapMasked(const TRect& aDestRect, const CFbsBitmap& aSourceBitmap, const TRect& aSourceRect, const CFbsBitmap& aMaskBitmap, TBool aInvertMask)
   1.141 +	{
   1.142 +	iContext->DrawBitmapMasked(aDestRect, aSourceBitmap, aSourceRect, aMaskBitmap, aInvertMask);
   1.143 +	}
   1.144 +
   1.145 +void CDirectGdiGcWrapper::DrawRoundRect(const TRect& aRect, const TSize& aEllipse)
   1.146 +	{
   1.147 +	iContext->DrawRoundRect(aRect, aEllipse);
   1.148 +	}
   1.149 +
   1.150 +void CDirectGdiGcWrapper::DrawPolyLine(const TArray<TPoint>& aPointList)
   1.151 +	{
   1.152 +	iContext->DrawPolyLine(aPointList);
   1.153 +	}
   1.154 +
   1.155 +void CDirectGdiGcWrapper::DrawPolyLineNoEndPoint(const TArray<TPoint>& aPointList)
   1.156 +	{
   1.157 +	iContext->DrawPolyLineNoEndPoint(aPointList);
   1.158 +	}
   1.159 +
   1.160 +void CDirectGdiGcWrapper::DrawPolygon(const TArray<TPoint>& aPointList, TFillRule aFillRule)
   1.161 +	{
   1.162 +	iContext->DrawPolygon(aPointList, MWsGraphicsContextToDirectGdiMappings::Convert(aFillRule));
   1.163 +	}
   1.164 +
   1.165 +void CDirectGdiGcWrapper::DrawEllipse(const TRect& aRect)
   1.166 +	{
   1.167 +	iContext->DrawEllipse(aRect);
   1.168 +	}
   1.169 +
   1.170 +void CDirectGdiGcWrapper::DrawLine(const TPoint& aStart, const TPoint& aEnd)
   1.171 +	{
   1.172 +	iContext->DrawLine(aStart, aEnd);
   1.173 +	}
   1.174 +
   1.175 +void CDirectGdiGcWrapper::DrawLineTo(const TPoint& aPoint)
   1.176 +	{
   1.177 +	iContext->DrawLineTo(aPoint);
   1.178 +	}
   1.179 +
   1.180 +void CDirectGdiGcWrapper::DrawLineBy(const TPoint& aVector)
   1.181 +	{
   1.182 +	iContext->DrawLineBy(aVector);
   1.183 +	}
   1.184 +
   1.185 +void CDirectGdiGcWrapper::DrawRect(const TRect& aRect)
   1.186 +	{
   1.187 +	iContext->DrawRect(aRect);
   1.188 +	}
   1.189 +
   1.190 +void CDirectGdiGcWrapper::DrawText(const TDesC& aText, const TTextParameters* aParam)
   1.191 +	{
   1.192 +	iContext->DrawText(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam));
   1.193 +	}
   1.194 +
   1.195 +void CDirectGdiGcWrapper::DrawText(const TDesC& aText, const TTextParameters* aParam, const TPoint& aPosition)
   1.196 +	{
   1.197 +	iContext->DrawText(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam), aPosition);
   1.198 +	}
   1.199 +
   1.200 +void CDirectGdiGcWrapper::DrawText(const TDesC& aText, const TTextParameters* aParam, const TRect& aClipRect)
   1.201 +	{
   1.202 +	iContext->DrawText(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam), aClipRect);
   1.203 +	}
   1.204 +
   1.205 +void CDirectGdiGcWrapper::DrawText(const TDesC& aText, const TTextParameters* aParam, const TRect& aClipFillRect, TInt aBaselineOffset, TTextAlign aHrz, TInt aMargin)
   1.206 +	{
   1.207 +	iContext->DrawText(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam), aClipFillRect, aBaselineOffset, MWsGraphicsContextToDirectGdiMappings::Convert(aHrz), aMargin);
   1.208 +	}
   1.209 +
   1.210 +void CDirectGdiGcWrapper::DrawTextVertical(const TDesC& aText, const TTextParameters* aParam, TBool aUp)
   1.211 +	{
   1.212 +	iContext->DrawTextVertical(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam), aUp);
   1.213 +	}
   1.214 +
   1.215 +void CDirectGdiGcWrapper::DrawTextVertical(const TDesC& aText, const TTextParameters* aParam, const TPoint& aPosition, TBool aUp)
   1.216 +	{
   1.217 +	iContext->DrawTextVertical(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam), aPosition, aUp);
   1.218 +	}
   1.219 +
   1.220 +void CDirectGdiGcWrapper::DrawTextVertical(const TDesC& aText, const TTextParameters* aParam, const TRect& aClipRect, TBool aUp)
   1.221 +	{
   1.222 +	iContext->DrawTextVertical(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam), aClipRect, aUp);
   1.223 +	}
   1.224 +
   1.225 +void CDirectGdiGcWrapper::DrawTextVertical(const TDesC& aText, const TTextParameters* aParam, const TRect& aClipRect, TInt aBaselineOffset, TBool aUp, TTextAlign aVert, TInt aMargin)
   1.226 +	{
   1.227 +	iContext->DrawTextVertical(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam), aClipRect, aBaselineOffset, aUp, MWsGraphicsContextToDirectGdiMappings::Convert(aVert), aMargin);
   1.228 +	}
   1.229 +
   1.230 +void CDirectGdiGcWrapper::DrawTextVertical(const TDesC& aText, const TTextParameters* aParam, const TRect& aClipRect, TInt aBaselineOffset, TInt aTextWidth, TBool aUp, TTextAlign aVert, TInt aMargin)
   1.231 +	{
   1.232 +	iContext->DrawTextVertical(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam), aClipRect, aBaselineOffset, aTextWidth, aUp, MWsGraphicsContextToDirectGdiMappings::Convert(aVert), aMargin);
   1.233 +	}
   1.234 +
   1.235 +void CDirectGdiGcWrapper::MoveTo(const TPoint& aPoint)
   1.236 +	{
   1.237 +	iContext->MoveTo(aPoint);
   1.238 +	}
   1.239 +
   1.240 +void CDirectGdiGcWrapper::MoveBy(const TPoint& aVector)
   1.241 +	{
   1.242 +	iContext->MoveBy(aVector);
   1.243 +	}
   1.244 +
   1.245 +void CDirectGdiGcWrapper::Plot(const TPoint& aPoint)
   1.246 +	{
   1.247 +	iContext->Plot(aPoint);
   1.248 +	}
   1.249 +
   1.250 +void CDirectGdiGcWrapper::Reset()
   1.251 +	{
   1.252 +	iContext->Reset();
   1.253 +	}
   1.254 +
   1.255 +void CDirectGdiGcWrapper::SetBrushColor(const TRgb& aColor)
   1.256 +	{
   1.257 +	iContext->SetBrushColor(aColor);
   1.258 +	}
   1.259 +
   1.260 +void CDirectGdiGcWrapper::SetBrushOrigin(const TPoint& aOrigin)
   1.261 +	{
   1.262 +	iContext->SetBrushOrigin(aOrigin);
   1.263 +	}
   1.264 +
   1.265 +void CDirectGdiGcWrapper::SetBrushStyle(TBrushStyle aBrushStyle)
   1.266 +	{
   1.267 +	iContext->SetBrushStyle(MWsGraphicsContextToDirectGdiMappings::Convert(aBrushStyle));
   1.268 +	}
   1.269 +
   1.270 +void CDirectGdiGcWrapper::SetClippingRegion(const TRegion& aRegion)
   1.271 +	{
   1.272 +	CDirectGdiDriver* driver = CDirectGdiDriver::Static();
   1.273 +	driver->GetError(); //make sure that an error has been received 
   1.274 +	iContext->SetClippingRegion(aRegion);
   1.275 +	TInt err = driver->GetError();
   1.276 +	SetError(err);
   1.277 +	if(err == KErrNone)
   1.278 +		{
   1.279 +		iClippingRegion.Copy(aRegion);
   1.280 +		}
   1.281 +	}
   1.282 +
   1.283 +void CDirectGdiGcWrapper::SetDrawMode(TDrawMode aDrawMode)
   1.284 +	{
   1.285 +	iContext->SetDrawMode(MWsGraphicsContextToDirectGdiMappings::LossyConvert(aDrawMode));
   1.286 +	}
   1.287 +
   1.288 +void CDirectGdiGcWrapper::SetOrigin(const TPoint& aPoint)
   1.289 +	{
   1.290 +	iContext->SetOrigin(aPoint);
   1.291 +	iOrigin = aPoint;
   1.292 +	}
   1.293 +
   1.294 +void CDirectGdiGcWrapper::SetPenColor(const TRgb& aColor)
   1.295 +	{
   1.296 +	iContext->SetPenColor(aColor);
   1.297 +	}
   1.298 +
   1.299 +void CDirectGdiGcWrapper::SetPenStyle(TPenStyle aPenStyle)
   1.300 +	{
   1.301 +	iContext->SetPenStyle(MWsGraphicsContextToDirectGdiMappings::Convert(aPenStyle));
   1.302 +	}
   1.303 +
   1.304 +void CDirectGdiGcWrapper::SetPenSize(const TSize& aSize)
   1.305 +	{
   1.306 +	iContext->SetPenSize(aSize);
   1.307 +	}
   1.308 +
   1.309 +void CDirectGdiGcWrapper::SetTextShadowColor(const TRgb& aColor)
   1.310 +	{
   1.311 +	iContext->SetTextShadowColor(aColor);
   1.312 +	}
   1.313 +
   1.314 +void CDirectGdiGcWrapper::SetCharJustification(TInt aExcessWidth, TInt aNumChars)
   1.315 +	{
   1.316 +	iContext->SetCharJustification(aExcessWidth, aNumChars);
   1.317 +	}
   1.318 +
   1.319 +void CDirectGdiGcWrapper::SetWordJustification(TInt aExcessWidth, TInt aNumGaps)
   1.320 +	{
   1.321 +	iContext->SetWordJustification(aExcessWidth, aNumGaps);
   1.322 +	}
   1.323 +
   1.324 +void CDirectGdiGcWrapper::SetUnderlineStyle(TFontUnderline aUnderlineStyle)
   1.325 +	{
   1.326 +	iContext->SetUnderlineStyle(MWsGraphicsContextToDirectGdiMappings::Convert(aUnderlineStyle));
   1.327 +	}
   1.328 +
   1.329 +void CDirectGdiGcWrapper::SetStrikethroughStyle(TFontStrikethrough aStrikethroughStyle)
   1.330 +	{
   1.331 +	iContext->SetStrikethroughStyle(MWsGraphicsContextToDirectGdiMappings::Convert(aStrikethroughStyle));
   1.332 +	}
   1.333 +
   1.334 +void CDirectGdiGcWrapper::SetBrushPattern(const CFbsBitmap& aBitmap)
   1.335 +	{
   1.336 +	iContext->SetBrushPattern(aBitmap);
   1.337 +	}
   1.338 +
   1.339 +void CDirectGdiGcWrapper::SetBrushPattern(TInt aFbsBitmapHandle)
   1.340 +	{
   1.341 +	iContext->SetBrushPattern(aFbsBitmapHandle);
   1.342 +	}
   1.343 +
   1.344 +void CDirectGdiGcWrapper::SetFont(const CFont* aFont)
   1.345 +	{
   1.346 +	iContext->SetFont(aFont);
   1.347 +	}
   1.348 +
   1.349 +void CDirectGdiGcWrapper::CopyRect(const TPoint& aOffset, const TRect& aRect)
   1.350 +	{
   1.351 +	iContext->CopyRect(aOffset, aRect);
   1.352 +	}
   1.353 +
   1.354 +void CDirectGdiGcWrapper::UpdateJustification(const TDesC& aText, const TTextParameters* aParam)
   1.355 +	{
   1.356 +	iContext->UpdateJustification(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam));
   1.357 +	}
   1.358 +
   1.359 +void CDirectGdiGcWrapper::UpdateJustificationVertical(const TDesC& aText, const TTextParameters* aParam, TBool aUp)
   1.360 +	{
   1.361 +	iContext->UpdateJustificationVertical(aText, MWsGraphicsContextToDirectGdiMappings::Convert(aParam), aUp);
   1.362 +	}
   1.363 +
   1.364 +void CDirectGdiGcWrapper::SetFontNoDuplicate(const CFont* aFont)
   1.365 +	{
   1.366 +	iContext->SetFontNoDuplicate(static_cast<const CDirectGdiFont*>(aFont));
   1.367 +	}
   1.368 +
   1.369 +TBool CDirectGdiGcWrapper::HasBrushPattern() const
   1.370 +	{
   1.371 +	return iContext->HasBrushPattern();
   1.372 +	}
   1.373 +
   1.374 +TBool CDirectGdiGcWrapper::HasFont() const
   1.375 +	{
   1.376 +	return iContext->HasFont();
   1.377 +	}
   1.378 +
   1.379 +TRgb CDirectGdiGcWrapper::BrushColor() const
   1.380 +	{
   1.381 +	return iContext->BrushColor();
   1.382 +	}
   1.383 +
   1.384 +TRgb CDirectGdiGcWrapper::PenColor() const
   1.385 +	{
   1.386 +	return iContext->PenColor();
   1.387 +	}
   1.388 +
   1.389 +TRgb CDirectGdiGcWrapper::TextShadowColor() const
   1.390 +	{
   1.391 +	return iContext->TextShadowColor();
   1.392 +	}
   1.393 +
   1.394 +TInt CDirectGdiGcWrapper::CreateDrawableSource(const TSgDrawableId& aDrawableId, TAny*& aSource)
   1.395 +	{
   1.396 +	CDirectGdiDriver* driver = CDirectGdiDriver::Static();
   1.397 +	if (!driver)
   1.398 +		{
   1.399 +		return KErrNotReady;
   1.400 +		}
   1.401 +	RDirectGdiDrawableSource* drawableSource = new RDirectGdiDrawableSource(*driver);
   1.402 +	if (!drawableSource)
   1.403 +		{
   1.404 +		return KErrNoMemory;
   1.405 +		}
   1.406 +
   1.407 +	//check usage flags if the drawable is an RSgImage
   1.408 +	RSgImage image;
   1.409 +	TInt res = image.Open(aDrawableId);
   1.410 +	if (res == KErrNone)
   1.411 +		{
   1.412 +		TSgImageInfo info;
   1.413 +		res = image.GetInfo(info);
   1.414 +		image.Close();
   1.415 +		if (res == KErrNone && !(info.iUsage & ESgUsageWindowGcSource))
   1.416 +			{
   1.417 +			res = KErrNotSupported;
   1.418 +			}
   1.419 +
   1.420 +		if (res != KErrNone)
   1.421 +			{
   1.422 +			delete drawableSource;
   1.423 +			return res;
   1.424 +			}
   1.425 +		}
   1.426 +
   1.427 +	RSgDrawable drawable;
   1.428 +	res = drawable.Open(aDrawableId, ESgDoNotRestrictUsage);
   1.429 +	if (res != KErrNone)
   1.430 +		{
   1.431 +		delete drawableSource;
   1.432 +		return res;
   1.433 +		}
   1.434 +	res = drawableSource->Create(drawable);
   1.435 +	drawable.Close();
   1.436 +	if (res != KErrNone)
   1.437 +		{
   1.438 +		delete drawableSource;
   1.439 +		return res;
   1.440 +		}
   1.441 +	res = iDrawableSources.InsertInAddressOrder(drawableSource);
   1.442 +	if (res != KErrNone)
   1.443 +		{
   1.444 +		drawableSource->Close();
   1.445 +		delete drawableSource;
   1.446 +		return res;
   1.447 +		}
   1.448 +	aSource = drawableSource;
   1.449 +	return KErrNone;
   1.450 +	}
   1.451 +
   1.452 +void CDirectGdiGcWrapper::CloseDrawableSource(TAny* aSource)
   1.453 +	{
   1.454 +	RDirectGdiDrawableSource* drawableSource = static_cast<RDirectGdiDrawableSource*>(aSource);
   1.455 +	TInt index = iDrawableSources.FindInAddressOrder(drawableSource);
   1.456 +	if (index != KErrNotFound)
   1.457 +		{
   1.458 +		drawableSource->Close();
   1.459 +		delete drawableSource;
   1.460 +		iDrawableSources.Remove(index);
   1.461 +		}
   1.462 +	}
   1.463 +
   1.464 +void CDirectGdiGcWrapper::DrawResource(const TAny* aSource, const TPoint& aPos, CWindowGc::TGraphicsRotation aRotation)
   1.465 +	{
   1.466 +	const RDirectGdiDrawableSource* drawableSource = static_cast<const RDirectGdiDrawableSource*>(aSource);
   1.467 +	TInt index = iDrawableSources.FindInAddressOrder(drawableSource);
   1.468 +	if (index == KErrNotFound)
   1.469 +		{
   1.470 +		STD_ASSERT_DEBUG(0, EPluginPanicInvalidDrawableSource);
   1.471 +		return;
   1.472 +		}
   1.473 +	iContext->DrawResource(aPos, *drawableSource, (DirectGdi::TGraphicsRotation)aRotation);
   1.474 +	}
   1.475 +
   1.476 +void CDirectGdiGcWrapper::DrawResource(const TAny* aSource, const TRect& aRect, CWindowGc::TGraphicsRotation aRotation)
   1.477 +	{
   1.478 +	const RDirectGdiDrawableSource* drawableSource = static_cast<const RDirectGdiDrawableSource*>(aSource);
   1.479 +	TInt index = iDrawableSources.FindInAddressOrder(drawableSource);
   1.480 +	if (index == KErrNotFound)
   1.481 +		{
   1.482 +		STD_ASSERT_DEBUG(0, EPluginPanicInvalidDrawableSource);
   1.483 +		return;
   1.484 +		}
   1.485 +	iContext->DrawResource(aRect, *drawableSource, (DirectGdi::TGraphicsRotation)aRotation);
   1.486 +	}
   1.487 +
   1.488 +void CDirectGdiGcWrapper::DrawResource(const TAny* aSource, const TRect& aRectDest, const TRect& aRectSrc, CWindowGc::TGraphicsRotation aRotation)
   1.489 +	{
   1.490 +	const RDirectGdiDrawableSource* drawableSource = static_cast<const RDirectGdiDrawableSource*>(aSource);
   1.491 +	TInt index = iDrawableSources.FindInAddressOrder(drawableSource);
   1.492 +	if (index == KErrNotFound)
   1.493 +		{
   1.494 +		STD_ASSERT_DEBUG(0, EPluginPanicInvalidDrawableSource);
   1.495 +		return;
   1.496 +		}
   1.497 +	iContext->DrawResource(aRectDest, *drawableSource, aRectSrc, (DirectGdi::TGraphicsRotation)aRotation);
   1.498 +	}
   1.499 +
   1.500 +void CDirectGdiGcWrapper::DrawResource(const TAny* aSource, const TRect& aRect, const TDesC8& aDes)
   1.501 +	{
   1.502 +	const RDirectGdiDrawableSource* drawableSource = static_cast<const RDirectGdiDrawableSource*>(aSource);
   1.503 +	TInt index = iDrawableSources.FindInAddressOrder(drawableSource);
   1.504 +	if (index == KErrNotFound)
   1.505 +		{
   1.506 +		STD_ASSERT_DEBUG(0, EPluginPanicInvalidDrawableSource);
   1.507 +		return;
   1.508 +		}
   1.509 +	iContext->DrawResource(aRect, *drawableSource, aDes);
   1.510 +	}
   1.511 +
   1.512 +/**
   1.513 +Sets the error code. If the error code is already set to a value other
   1.514 +than KErrNone, the error code will not be modified.
   1.515 +
   1.516 +@param  aErr The error code to set.
   1.517 +
   1.518 +@post 	The error code has been set.
   1.519 +*/
   1.520 +void CDirectGdiGcWrapper::SetError(TInt aError)
   1.521 +	{
   1.522 +	if (aError != KErrNone && iErrorCode == KErrNone)
   1.523 +		{
   1.524 +		iErrorCode = aError;
   1.525 +		}
   1.526 +	}
   1.527 +
   1.528 +/**
   1.529 +Returns the first error code (set as the result of calling some CDirectGdiGcWrapper API), if any,
   1.530 +since the last call to this function or, if it has not previously been called, since
   1.531 +the CDirectGdiGcWrapper was constructed. Calling this function clears the error code.
   1.532 +
   1.533 +@post 	The error code has been reset after being read.
   1.534 +
   1.535 +@return The first error code, if any, since the last call to this function or, 
   1.536 +		if it has not previously been called, since the CDirectGdiGcWrapper was constructed. 
   1.537 +		KErrNone will indicate that no such error has occurred.
   1.538 +*/
   1.539 +TInt CDirectGdiGcWrapper::GetError()
   1.540 +	{
   1.541 +	TInt err = iErrorCode;
   1.542 +	iErrorCode = KErrNone;
   1.543 +	return err;
   1.544 +	}
   1.545 +
   1.546 +TPoint CDirectGdiGcWrapper::Origin() const
   1.547 +	{
   1.548 +	return iOrigin;
   1.549 +	}
   1.550 +
   1.551 +const TRegion& CDirectGdiGcWrapper::ClippingRegion()
   1.552 +	{
   1.553 +	return iClippingRegion;
   1.554 +	}
   1.555 +
   1.556 +TInt CDirectGdiGcWrapper::Push()
   1.557 +	{
   1.558 +	// the buf format is len+data where data is written by the GC's ExternalizeL()
   1.559 +	iGcBuf->Reset();
   1.560 +	CBufBase& buf = *iGcBuf;
   1.561 +	const TInt start = buf.Size();
   1.562 +	RBufWriteStream out(buf,start);
   1.563 +	TRAPD(err,out.WriteInt32L(0));
   1.564 +	if(!err)
   1.565 +		{
   1.566 +		TRAP(err,iContext->ExternalizeL(out));
   1.567 +		}
   1.568 +	if(err) //rollback addition
   1.569 +		{
   1.570 +		buf.Delete(start,buf.Size()-start);
   1.571 +		}
   1.572 +	else //fixup len
   1.573 +		{
   1.574 +		TRAP_IGNORE(out.CommitL();) // can't see this failing
   1.575 +		TPckgBuf<TInt32> pckg(buf.Size()-sizeof(TInt32)-start);
   1.576 +		buf.Write(start,pckg);
   1.577 +		}
   1.578 +	return err;
   1.579 +	}
   1.580 +
   1.581 +void CDirectGdiGcWrapper::Pop()
   1.582 +	{
   1.583 +	CBufBase& buf = *iGcBuf;
   1.584 +	TInt ofs = 0;
   1.585 +	FOREVER
   1.586 +		{
   1.587 +		TInt chunk = 0;
   1.588 +		RBufReadStream in(buf,ofs);
   1.589 +		TRAPD(err,chunk = in.ReadInt32L());
   1.590 +		if(err)
   1.591 +			{
   1.592 +			STD_ASSERT_DEBUG(err != 0, EPluginPanicPopGcSettings);
   1.593 +			return;
   1.594 +			}
   1.595 +		if(ofs+sizeof(TInt32)+chunk >= buf.Size()) // the last chunk?
   1.596 +			{
   1.597 +			TRAP_IGNORE(iContext->InternalizeL(in));
   1.598 +			buf.Delete(ofs,buf.Size()-ofs);
   1.599 +			return;
   1.600 +			}
   1.601 +		ofs += chunk + sizeof(TInt32);
   1.602 +		}
   1.603 +	}
   1.604 +
   1.605 +//Default method of fading simply uses bitgdi to perform fading
   1.606 +void CDirectGdiGcWrapper::FadeArea(const TRegion& aRegion)
   1.607 +	{
   1.608 +	if (!&aRegion || aRegion.CheckError())
   1.609 +		return;
   1.610 +
   1.611 +	iContext->Reset();
   1.612 +	iContext->SetClippingRegion(aRegion);
   1.613 +	iContext->SetPenStyle(DirectGdi::ENullPen);
   1.614 +	iContext->SetBrushStyle(DirectGdi::ESolidBrush);
   1.615 +	iContext->SetBrushColor(iFadeColor);
   1.616 +	iContext->DrawRect(aRegion.BoundingRect());
   1.617 +	}
   1.618 +	
   1.619 +//Default method of fading expects two TUint8's describing the black/white map 
   1.620 +//as possible fading parameters
   1.621 +void CDirectGdiGcWrapper::SetFadingParameters(const TDesC8& aData)
   1.622 +  	{
   1.623 +	TPckgBuf<TFadingParams> buf;
   1.624 +	buf.Copy(aData);
   1.625 +	TFadingParams parameters = buf();
   1.626 +
   1.627 +	//Situations where blackMap > whiteMap are NOT supported
   1.628 +	if (parameters.blackMap > parameters.whiteMap)
   1.629 +		{
   1.630 +		TUint8 oldMap = parameters.blackMap;
   1.631 +		parameters.blackMap = parameters.whiteMap;
   1.632 +		parameters.whiteMap = oldMap;
   1.633 +		}
   1.634 +	
   1.635 +	//CFbsBitGc::FadeArea() does the following per color component:
   1.636 +	//   dst = dst * (whiteMap - blackMap) + blackMap;
   1.637 +
   1.638 +	//To achieve the same effect using MWsGraphicsContext we draw a rectangle
   1.639 +	//with specific intensity and alpha values:
   1.640 +	//   dst = dst * (1 - alpha) + intensity * alpha;
   1.641 +	//Thus:
   1.642 +	//   alpha = 1 - whiteMap + blackMap;
   1.643 +	//   intensity = blackMap / alpha;
   1.644 +
   1.645 +	// alpha = 1 - whiteMap + blackMap;
   1.646 +	TInt alpha = 255 - parameters.whiteMap + parameters.blackMap;
   1.647 +	// intensity = blackMap / alpha;
   1.648 +	TInt i = (parameters.blackMap * iLut[alpha]) >> 8;
   1.649 +
   1.650 +	iFadeColor.SetInternal(i << 16 | i << 8 | i | alpha << 24);
   1.651 +  	}
   1.652 +
   1.653 +void CDirectGdiGcWrapper::DrawTextCursor(const TTextCursorInfo& aTextCursorInfo)
   1.654 +	{
   1.655 +	/*
   1.656 +	 * This function is written with the following assumption:
   1.657 +	 * The UI Toolkit uses text entry windows with a white background
   1.658 +	 * and black text, but always requests a white text cursor.
   1.659 +	 * 
   1.660 +	 * We therefore ignore the KRgbWhite text cursor cursor supplied
   1.661 +	 * and use a Black overprinting strategy instead.
   1.662 +	 */
   1.663 +	STD_ASSERT_ALWAYS(
   1.664 +		aTextCursorInfo.iTextCursorType == TTextCursor::ETypeRectangle ||
   1.665 +		aTextCursorInfo.iTextCursorType == TTextCursor::ETypeHollowRectangle,
   1.666 +		EPluginPanicInvalidCursorType
   1.667 +	);
   1.668 +
   1.669 +	TRegionFix<1> fullWindowRegion;
   1.670 +	const TRegion* clippingRegion = &aTextCursorInfo.iRegion;
   1.671 +	if (aTextCursorInfo.iRegion.CheckError())
   1.672 +		{
   1.673 +		fullWindowRegion.AddRect(aTextCursorInfo.iWindow->AbsRect());
   1.674 +		clippingRegion = &fullWindowRegion;
   1.675 +		}
   1.676 +
   1.677 +	if (clippingRegion->IsEmpty())
   1.678 +		{
   1.679 +		return;
   1.680 +		}
   1.681 +
   1.682 +	iContext->SetDrawMode(DirectGdi::EDrawModePEN);
   1.683 +	switch (aTextCursorInfo.iTextCursorType)
   1.684 +		{
   1.685 +	case TTextCursor::ETypeRectangle:
   1.686 +		{
   1.687 +		iContext->SetBrushStyle(DirectGdi::ESolidBrush);
   1.688 +		iContext->SetPenStyle(DirectGdi::ENullPen);
   1.689 +		iContext->SetBrushColor(KRgbBlack);
   1.690 +		}
   1.691 +		break;
   1.692 +	case TTextCursor::ETypeHollowRectangle:
   1.693 +		{
   1.694 +		iContext->SetBrushStyle(DirectGdi::ENullBrush);
   1.695 +		iContext->SetPenStyle(DirectGdi::ESolidPen);
   1.696 +		iContext->SetPenColor(KRgbBlack);
   1.697 +		}
   1.698 +		break;
   1.699 +		}
   1.700 +	iContext->SetClippingRegion(*clippingRegion);
   1.701 +	/*
   1.702 +	 * During Sprite drawing, the GC gets reset.  Possibly other code could
   1.703 +	 * have done this also.  So make sure we setup the origin so that window-relative
   1.704 +	 * co-ordinates work as expected; iCursorRect is in window co-ordinates.
   1.705 +	 */
   1.706 +	iContext->SetOrigin(aTextCursorInfo.iWindow->Origin());
   1.707 +	iContext->DrawRect(aTextCursorInfo.iCursorRect);
   1.708 +	}