os/graphics/windowing/windowserver/nga/CLIENT/RDirect.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/windowing/windowserver/nga/CLIENT/RDirect.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,569 @@
     1.4 +// Copyright (c) 2000-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 +// Client side classes for handling direct screen access
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <e32std.h>
    1.22 +#include <e32base.h>
    1.23 +#include "../SERVER/w32cmd.h"
    1.24 +#include "CLIENT.H"
    1.25 +#include "w32comm.h"
    1.26 +#include <e32msgqueue.h>
    1.27 +
    1.28 +
    1.29 +NONSHARABLE_CLASS(CDsaMsgQueue) : public CActive
    1.30 +{
    1.31 +	public:
    1.32 +		CDsaMsgQueue();
    1.33 +		~CDsaMsgQueue();
    1.34 +		void Request(TRequestStatus* aClientRequest);
    1.35 +		TBool Started() { return iStarted;}
    1.36 +		TBool Completed();
    1.37 +		void OpenRecQueue(TInt aHandle);
    1.38 +		void OpenSendQueue(TInt aHandle);
    1.39 +		TInt Send(TInt aData);
    1.40 +		RMsgQueueBase& SendQueue() {return iSendQueue; }
    1.41 +		RMsgQueueBase& Queue() { return iRecQueue; }
    1.42 +		TRequestStatus* Status() { return &iStatus; }
    1.43 +		TBool RequestStarted() { return iStarted;}
    1.44 +	private:
    1.45 +		void DoCancel();
    1.46 +		void RunL();
    1.47 +		void Listen();
    1.48 +		
    1.49 +	private:
    1.50 +		RMsgQueueBase iRecQueue;
    1.51 +		RMsgQueueBase iSendQueue;
    1.52 +		TRequestStatus* iClientRequest;
    1.53 +		TBool iStarted;
    1.54 +		RThread* iServer;
    1.55 +};
    1.56 +
    1.57 +//
    1.58 +CDsaMsgQueue::CDsaMsgQueue() : CActive(RDirectScreenAccess::EPriorityVeryHigh)
    1.59 +	{
    1.60 +	CActiveScheduler::Add(this);
    1.61 +	}
    1.62 +
    1.63 +CDsaMsgQueue::~CDsaMsgQueue()
    1.64 +	{
    1.65 +	Cancel();
    1.66 +	iRecQueue.Close();
    1.67 +	iSendQueue.Close();
    1.68 +	}
    1.69 +
    1.70 +TInt CDsaMsgQueue::Send(TInt aData)
    1.71 +	{
    1.72 +	return iSendQueue.Send(&aData,sizeof(TInt));
    1.73 +	}
    1.74 +
    1.75 +void CDsaMsgQueue::OpenRecQueue(TInt aHandle)
    1.76 +	{
    1.77 +	iRecQueue.SetHandle(aHandle);
    1.78 +// With RmessagePtr2 compelete using an RHandle the returned handle is already duplicated
    1.79 +	}
    1.80 +
    1.81 +void CDsaMsgQueue::OpenSendQueue(TInt aHandle)
    1.82 +	{
    1.83 +	iSendQueue.SetHandle(aHandle);
    1.84 +// With RmessagePtr2 compelete using an RHandle the returned handle is already duplicated
    1.85 +	}
    1.86 +
    1.87 +void CDsaMsgQueue::DoCancel()
    1.88 +	{
    1.89 +	iRecQueue.CancelDataAvailable();
    1.90 +	TInt ret = KErrNone;
    1.91 +	do
    1.92 +		{
    1.93 +		TInt data = 0;
    1.94 +		ret = iRecQueue.Receive(&data,sizeof(TInt));
    1.95 +		}while(ret == KErrNone);
    1.96 +	if(iClientRequest)
    1.97 +		{
    1.98 +		RThread().RequestComplete(iClientRequest,KErrCancel);
    1.99 +		}
   1.100 +	}
   1.101 +	
   1.102 +void CDsaMsgQueue::RunL()
   1.103 +	{
   1.104 +	// get the data from the msg queue
   1.105 +	TInt reason = 0;
   1.106 +	iRecQueue.Receive(&reason,sizeof(TInt));
   1.107 +	
   1.108 +	if(iClientRequest)
   1.109 +		{
   1.110 +		// if there is an outstanding client request, complete and pass on the abort reason
   1.111 +		User::RequestComplete(iClientRequest,reason);
   1.112 +		iClientRequest = NULL;
   1.113 +		}
   1.114 +	}
   1.115 +
   1.116 +void CDsaMsgQueue::Listen()
   1.117 +	{
   1.118 +	if(!IsActive())
   1.119 +		{
   1.120 +		SetActive();	
   1.121 +		iRecQueue.NotifyDataAvailable(iStatus);
   1.122 +		}
   1.123 +	}
   1.124 +
   1.125 +void CDsaMsgQueue::Request(TRequestStatus* aClientRequest)
   1.126 +	{
   1.127 +	__ASSERT_ALWAYS(!IsActive(),User::Invariant());
   1.128 +	iClientRequest = aClientRequest;
   1.129 +	iStarted = ETrue;
   1.130 +	Listen();
   1.131 +	}
   1.132 +
   1.133 +TBool CDsaMsgQueue::Completed()
   1.134 +	{
   1.135 +	if(iStarted)
   1.136 +		{
   1.137 +		Send(KErrNone);
   1.138 +		iStarted = EFalse;
   1.139 +		return ETrue;
   1.140 +		}
   1.141 +	return EFalse;
   1.142 +	}
   1.143 +
   1.144 +
   1.145 +LOCAL_C inline TDeviceOrientation Graphics2DeviceOrientation(CFbsBitGc::TGraphicsOrientation aGraphicsOrientation)
   1.146 +    {
   1.147 +    return ((TDeviceOrientation)(1 << aGraphicsOrientation));
   1.148 +    }
   1.149 +
   1.150 +//
   1.151 +// RDirectScreenAccess
   1.152 +//
   1.153 +
   1.154 +EXPORT_C RDirectScreenAccess::RDirectScreenAccess()
   1.155 +/** Default constructor.
   1.156 +
   1.157 +Developers should use the other constructor overload instead. */
   1.158 +	{
   1.159 +	}
   1.160 +
   1.161 +EXPORT_C RDirectScreenAccess::RDirectScreenAccess(RWsSession& aWs) : MWsClientClass(aWs.iBuffer), iWs(&aWs), iMsgQueue(NULL)
   1.162 +/** C++ constructor with a connected window server session.
   1.163 +
   1.164 +Construct() must be called to complete construction.
   1.165 +
   1.166 +@param aWs Connected session with the window server. */
   1.167 +	{
   1.168 +	}
   1.169 +
   1.170 +EXPORT_C TInt RDirectScreenAccess::Construct()
   1.171 +/** Second phase constructor.
   1.172 +
   1.173 +Creates the server side resource and initialises the client's handle to it.
   1.174 +
   1.175 +This function always causes a flush of the window server buffer.
   1.176 +
   1.177 +@return KErrNone if successful, otherwise one of the system wide error codes. 
   1.178 +@panic TW32Panic 17 in debug builds if called on an already constructed object.*/
   1.179 +	{
   1.180 +	__ASSERT_DEBUG(iWsHandle == KNullHandle, Panic(EW32PanicGraphicDoubleConstruction));
   1.181 +	return Construct(EFalse);
   1.182 +	}
   1.183 +
   1.184 +EXPORT_C TInt RDirectScreenAccess::Construct(TBool aRegionTrackingOnly)
   1.185 +/** Second phase constructor.
   1.186 +
   1.187 +Creates the server side resource and initialises the client's handle to it.
   1.188 +
   1.189 +This function always causes a flush of the window server buffer.
   1.190 +
   1.191 +@param aRegionTrackingOnly ETrue if the DSA is intended to be used for region tracking purposes only,
   1.192 +EFalse if the DSA will be used to perform actual drawing.
   1.193 +@return KErrNone if successful, otherwise one of the system wide error codes. 
   1.194 +@panic TW32Panic 17 in debug builds if called on an already constructed object.*/
   1.195 +	{
   1.196 +	__ASSERT_DEBUG(iWsHandle == KNullHandle, Panic(EW32PanicGraphicDoubleConstruction));
   1.197 +	TInt ret = KErrNone;
   1.198 +	TWsClientOpcodes requestedOpCode = aRegionTrackingOnly? EWsClOpCreateDirectScreenAccessRegionTrackingOnly : EWsClOpCreateDirectScreenAccess;
   1.199 +	
   1.200 +	if ((ret = iBuffer->WriteReplyWs(requestedOpCode)) >= 0)
   1.201 +		{
   1.202 +		iWsHandle = ret;
   1.203 +		TRAP(ret,iMsgQueue = new (ELeave)CDsaMsgQueue);
   1.204 +		if(ret == KErrNone)
   1.205 +			{
   1.206 +			// the servers send queue is the client receive queue
   1.207 +			TInt h = WriteReply(EWsDirectOpGetSendQueue);
   1.208 +			iMsgQueue->OpenRecQueue(h);	
   1.209 +		
   1.210 +			// servers receive queue is the clients send queue
   1.211 +			h = WriteReply(EWsDirectOpGetRecQueue);
   1.212 +			iMsgQueue->OpenSendQueue(h);	
   1.213 +			}
   1.214 +		else
   1.215 +			{
   1.216 +			Close();
   1.217 +			}
   1.218 +		}
   1.219 +	return(ret);
   1.220 +	}
   1.221 +
   1.222 +EXPORT_C TInt RDirectScreenAccess::Request(RRegion*& aRegion,TRequestStatus& aStatus,const RWindowBase& aWindow)
   1.223 +/** Issues a request to the window server for permission to perform direct screen 
   1.224 +access on a window.
   1.225 +
   1.226 +Direct access to the screen may be refused due to lack of memory or if the 
   1.227 +target window is completely obscured.
   1.228 +
   1.229 +If direct access is allowed, the function passes back a clipping region which 
   1.230 +is the part of the screen the caller can draw to. 
   1.231 +
   1.232 +When direct screen access must stop, for instance because a dialog is to be 
   1.233 +displayed in front of the region where direct screen access is taking place, 
   1.234 +the window server completes the request. The recommended way to check for 
   1.235 +this is for aStatus to be the request status of an active object that will 
   1.236 +be run when the request completes, i.e. if Request() returns KErrNone, call 
   1.237 +SetActive(), and in the object's RunL(), you should immediately abort direct 
   1.238 +screen access.
   1.239 +
   1.240 +While the DSA is in operation, it is strongly advised that the client should 
   1.241 +not make any call to WSERV that will affect the visible area of the window in 
   1.242 +which the DSA is taking place. 
   1.243 +
   1.244 +When WSERV tells the client that it needs to abort its DSA, it waits to receive
   1.245 +the acknowledgment from the client that it has done so. However, it doesn't wait 
   1.246 +for ever, since the client may have entered some long running calculation or even
   1.247 +an infinite loop. So WSERV also waits on a timer: if the timer expires before the
   1.248 +client acknowledges, then WSERV continues; if, later on, WSERV gets notification
   1.249 +from the client that it has aborted the DSA, then WSERV will invalidate the region
   1.250 +in which the DSA was taking place, just in case there had been a conflict between
   1.251 +the DSA and another client.
   1.252 +
   1.253 +
   1.254 +This function always causes a flush of the window server buffer.
   1.255 +
   1.256 +@param aRegion On return, the clipping region that the caller can draw to. 
   1.257 +NULL if the function was not successful.
   1.258 +If the target window is invisible or completely covered by other windows
   1.259 +then the region will be empty.
   1.260 +@param aStatus A request status that is set to a completion code by the window 
   1.261 +server when direct screen access must stop.
   1.262 +@param aWindow The window that you want to perform the direct screen access 
   1.263 +on.
   1.264 +@return KErrNone if the request was successful, KErrNone with empty region if 
   1.265 +none of the window is currently visible, otherwise one of the system wide error codes,
   1.266 +e.g. KErrNoMemory if out of memory. */
   1.267 +	{
   1.268 +	__ASSERT_ALWAYS(iMsgQueue,Panic(EW32PanicDirectMisuse));
   1.269 +
   1.270 +	aRegion = NULL;
   1.271 +
   1.272 +	// Allocate the memory for the RRegion here so it is simple to back out
   1.273 +	// in case of failure
   1.274 +	TAny* regionMem = User::Alloc (sizeof (RRegion));
   1.275 +	if (!regionMem)
   1.276 +		{
   1.277 +		return KErrNoMemory;
   1.278 +		}
   1.279 +
   1.280 +	TInt ret = WriteReplyInt(aWindow.WsHandle(),EWsDirectOpRequest);
   1.281 +	if (ret<KErrNone)
   1.282 +		{
   1.283 +		User::Free (regionMem);
   1.284 +		return ret;
   1.285 +		}
   1.286 +	TRect* rectList = NULL;
   1.287 +	TRect* newRectList;
   1.288 +	TInt numRect;
   1.289 +
   1.290 +	do
   1.291 +		{
   1.292 +		numRect = ret;
   1.293 +		newRectList = STATIC_CAST(TRect*,User::ReAlloc(rectList,numRect*sizeof(TRect)));
   1.294 +		if (!newRectList)
   1.295 +			{
   1.296 +			Write(EWsDirectOpInitFailed);
   1.297 +			User::Free (regionMem);
   1.298 +			delete rectList;
   1.299 +			return KErrNoMemory;
   1.300 +			}
   1.301 +		rectList = newRectList;
   1.302 +		TPtr8 ptr(REINTERPRET_CAST(TUint8*,rectList),ret*sizeof(TRect));
   1.303 +		ret = WriteReplyIntP(ret,&ptr,EWsDirectOpGetRegion);
   1.304 +		} while(ret >=0 && ret != KMaxTInt);
   1.305 +	if (ret<0)
   1.306 +		{
   1.307 +		User::Free (regionMem);
   1.308 +		delete rectList;
   1.309 +		return ret;
   1.310 +		}
   1.311 +
   1.312 +	aRegion = new (regionMem) RRegion (numRect, rectList);
   1.313 +	aStatus = KRequestPending;
   1.314 +	iMsgQueue->Request(&aStatus);
   1.315 +	iWs->DirectAcessActivation(ETrue);
   1.316 +	return KErrNone;
   1.317 +	}
   1.318 +
   1.319 +EXPORT_C void RDirectScreenAccess::Completed()
   1.320 +/** Indicates to the window server that you have responded to the completion of 
   1.321 +the request status passed to Request(), by stopping direct screen access. */
   1.322 +	{
   1.323 +	__ASSERT_ALWAYS(iMsgQueue->Started(),Panic(EW32PanicDirectMisuse));
   1.324 +	if(iMsgQueue->Completed())
   1.325 +		{
   1.326 +		iWs->DirectAcessActivation(EFalse);
   1.327 +		}
   1.328 +	}
   1.329 +
   1.330 +EXPORT_C void RDirectScreenAccess::Cancel()
   1.331 +/** Indicates to the window server that you have finished performing direct screen 
   1.332 +access. */
   1.333 +	{
   1.334 +	if(iMsgQueue->Started())
   1.335 +		{
   1.336 +		Completed();
   1.337 +		}
   1.338 +	TInt ret = WriteReply(EWsDirectOpCancel);
   1.339 +	if(ret != 0) // the server is sending us some data.
   1.340 +		{
   1.341 +		iMsgQueue->Queue().CancelDataAvailable();
   1.342 +		TInt data = 0;
   1.343 +		iMsgQueue->Queue().ReceiveBlocking(&data,sizeof(TInt));
   1.344 +		}
   1.345 +	iMsgQueue->Cancel();
   1.346 +	}
   1.347 +
   1.348 +EXPORT_C void RDirectScreenAccess::Close()
   1.349 +/** Calls Completed() then deletes the server side resource and sets the client's 
   1.350 +handle to it to NULL. */
   1.351 +	{
   1.352 +	if (iBuffer && iWsHandle)
   1.353 +		{
   1.354 +		if(iMsgQueue && iMsgQueue->Started())
   1.355 +			{
   1.356 +			Completed();
   1.357 +			}
   1.358 +		Write(EWsDirectOpFree);
   1.359 +		delete iMsgQueue;
   1.360 +		iMsgQueue = NULL;
   1.361 +		}
   1.362 +	iWsHandle = NULL;
   1.363 +	}
   1.364 +
   1.365 +//
   1.366 +// CDirectScreenAccess
   1.367 +//
   1.368 +
   1.369 +EXPORT_C CDirectScreenAccess* CDirectScreenAccess::NewL(RWsSession& aWs,CWsScreenDevice& aScreenDevice,RWindowBase& aWin,MDirectScreenAccess& aAbort)
   1.370 +/** Allocates and constructs the object and adds it to the current active scheduler.
   1.371 +
   1.372 +This function always causes a flush of the window server buffer.
   1.373 +
   1.374 +@param aWs A session with the window server.
   1.375 +@param aScreenDevice Specifies the characteristics of the screen device to 
   1.376 +draw to.
   1.377 +@param aWin The window to draw to directly.
   1.378 +@param aAbort Defines an AbortNow() and a Restart() function which are both 
   1.379 +called on aborting, as part of the RunL(). Restart() is called from an idle 
   1.380 +time active object (CIdle).
   1.381 +@return The newly constructed object. */
   1.382 +	{
   1.383 +	return CDirectScreenAccess::NewL(aWs,aScreenDevice,aWin,aAbort,EFalse);
   1.384 +	}
   1.385 +
   1.386 +EXPORT_C CDirectScreenAccess* CDirectScreenAccess::NewL(RWsSession& aWs,CWsScreenDevice& aScreenDevice,RWindowBase& aWin,MDirectScreenAccess& aAbort,TBool aRegionTrackingOnly)
   1.387 +/** Allocates and constructs the object and adds it to the current active scheduler.
   1.388 +
   1.389 +This function always causes a flush of the window server buffer.
   1.390 +
   1.391 +@param aWs A session with the window server.
   1.392 +@param aScreenDevice Specifies the characteristics of the screen device to 
   1.393 +draw to.
   1.394 +@param aWin The window to draw to directly.
   1.395 +@param aAbort Defines an AbortNow() and a Restart() function which are both 
   1.396 +called on aborting, as part of the RunL(). Restart() is called from an idle 
   1.397 +time active object (CIdle).
   1.398 +@param aRegionTrackingOnly The screen device and GC are allocated if this is EFalse,
   1.399 +but not if it is ETrue. Only the DSA region data and updates to that are
   1.400 +available in the latter case. Creating the screen device will trigger the dsa
   1.401 +buffer allocationand it is an operation that could fail, should this happen
   1.402 +the function will leave.
   1.403 +@return The newly constructed object. */
   1.404 +	{
   1.405 +	CDirectScreenAccess* self = new(ELeave) CDirectScreenAccess(aWs,&aScreenDevice,aWin,aAbort);
   1.406 +	CleanupStack::PushL(self);
   1.407 +	self->ConstructL(aWs,aRegionTrackingOnly);
   1.408 +	CleanupStack::Pop(self);
   1.409 +	return self;
   1.410 +	}
   1.411 +
   1.412 +CDirectScreenAccess::~CDirectScreenAccess()
   1.413 +	{
   1.414 +	__ASSERT_ALWAYS(!iAborting,Panic(EW32PanicDirectMisuse));
   1.415 +	Cancel();
   1.416 +	delete iGc;
   1.417 +	delete iScreenDevice;
   1.418 +	if (iDrawingRegion)
   1.419 +		iDrawingRegion->Destroy();
   1.420 +	iDirectAccess.Close();
   1.421 +	delete iRestart;
   1.422 +	}
   1.423 +
   1.424 +void CDirectScreenAccess::ConstructL(RWsSession& aWs,TBool aRegionTrackingOnly)
   1.425 +	{
   1.426 +	iScreenNumber = iWsScreenDevice->GetScreenNumber();
   1.427 +	
   1.428 +	if(aRegionTrackingOnly)
   1.429 +		{
   1.430 +		iFlags |= EDirectRegionTrackingOnly;
   1.431 +		}
   1.432 +	User::LeaveIfError(iDirectAccess.Construct(aRegionTrackingOnly));
   1.433 +	
   1.434 +	iRestart = CIdle::NewL(RDirectScreenAccess::EPriorityVeryHigh-5);
   1.435 +	CActiveScheduler::Add(this);
   1.436 +	if (aWs.GetColorModeList(NULL)>1)
   1.437 +		iFlags |= EDirectCheckModeChange;
   1.438 +	if (iWsScreenDevice->NumScreenModes() == 1)
   1.439 +		{
   1.440 +		if ((iWsScreenDevice->GetRotationsList(0,NULL) == 1) && !aRegionTrackingOnly)
   1.441 +			{
   1.442 +			return;
   1.443 +			}
   1.444 +		}
   1.445 +	iFlags |= EDirectCheckSizeModeChange;
   1.446 +	}
   1.447 +
   1.448 +void CDirectScreenAccess::CreateScreenObjectsL(TDisplayMode aCurrentMode)
   1.449 +	{
   1.450 +	__ASSERT_DEBUG(!(iFlags&EDirectRegionTrackingOnly),Panic(EW32PanicDirectMisuse));
   1.451 +	delete iScreenDevice;
   1.452 +	iScreenDevice = NULL;
   1.453 +	
   1.454 +	iScreenDevice = CFbsScreenDevice::NewL(iScreenNumber,aCurrentMode);
   1.455 +	
   1.456 +	if (iGc)
   1.457 +		{
   1.458 +		iGc->Activate(iScreenDevice);
   1.459 +		}
   1.460 +	else
   1.461 +		{
   1.462 +		User::LeaveIfError(iScreenDevice->CreateContext(iGc));
   1.463 +		if (!(iFlags&EDirectCheckSizeModeChange))
   1.464 +			UpdateSizeAndRotation(iGc);
   1.465 +		}
   1.466 +	}
   1.467 +
   1.468 +EXPORT_C void CDirectScreenAccess::StartL()
   1.469 +/** Informs the window server that you are going to start direct screen access 
   1.470 +and sets up a graphics context with which you can draw to the screen.
   1.471 +
   1.472 +It should also be called to restart direct screen access after Cancel() has 
   1.473 +been called to stop it. 
   1.474 +
   1.475 +While the DSA is in operation, it is strongly advised that the client should 
   1.476 +not make any call to WSERV that will affect the visible area of the window in 
   1.477 +which the DSA is taking place. 
   1.478 +
   1.479 +When WSERV tells the client that it needs to abort its DSA, it waits to receive
   1.480 +the acknowledgment from the client that it has done so. However, it doesn't wait
   1.481 +for ever, since the client may have entered some long running calculation or even
   1.482 +an infinite loop. So WSERV also waits on a timer: if the timer expires before the
   1.483 +client acknowledges, then WSERV continues; if, later on, WSERV gets notification
   1.484 +from the client that it has aborted the DSA, then WSERV will invalidate the region
   1.485 +in which the DSA was taking place, just in case there had been a conflict between
   1.486 +the DSA and another client.
   1.487 +
   1.488 +
   1.489 +This function always causes a flush of the window server buffer. */
   1.490 +	{
   1.491 +	if (iDrawingRegion)
   1.492 +		iDrawingRegion->Destroy();
   1.493 +	User::LeaveIfError(iDirectAccess.Request(iDrawingRegion,iStatus,iWindow));
   1.494 +	SetActive();
   1.495 +	if(!(iFlags&EDirectRegionTrackingOnly))
   1.496 +		{
   1.497 +		if((iFlags&EDirectCheckModeChange) || iScreenDevice == NULL)
   1.498 +			{
   1.499 +			TDisplayMode currentDisplayMode = iWsScreenDevice->DisplayMode();
   1.500 +			if (iScreenDevice == NULL || currentDisplayMode != iScreenDevice->DisplayMode())
   1.501 +				{
   1.502 +				TRAPD(err,CreateScreenObjectsL(currentDisplayMode));
   1.503 +				if (err != KErrNone)
   1.504 +					{
   1.505 +					Cancel();
   1.506 +					User::Leave(err);
   1.507 +					}
   1.508 +				}
   1.509 +			}
   1.510 +		if (iFlags&EDirectCheckSizeModeChange)
   1.511 +			{
   1.512 +			UpdateSizeAndRotation(iGc);
   1.513 +			}
   1.514 +		iGc->SetOrigin(iWindow.AbsPosition());
   1.515 +		}
   1.516 +	iDrawingRegion->ClipRect(iScreenSize);
   1.517 +	if(!(iFlags&EDirectRegionTrackingOnly))
   1.518 +			{
   1.519 +			iGc->SetClippingRegion(iDrawingRegion);
   1.520 +			}
   1.521 +	}
   1.522 +
   1.523 +TInt CDirectScreenAccess::Restart(TAny* aDirect)		//static
   1.524 +	{
   1.525 +	STATIC_CAST(CDirectScreenAccess*,aDirect)->Restart();
   1.526 +	return(KErrNone);
   1.527 +	}
   1.528 +
   1.529 +void CDirectScreenAccess::Restart()
   1.530 +	{
   1.531 +	iAbort.Restart(iReason);
   1.532 +	}
   1.533 +
   1.534 +void CDirectScreenAccess::UpdateSizeAndRotation(CFbsBitGc* aGc)
   1.535 +	{
   1.536 +	TPixelsAndRotation sizeAndRotation;
   1.537 +	iWsScreenDevice->GetDefaultScreenSizeAndRotation(sizeAndRotation);
   1.538 +	iScreenSize = sizeAndRotation.iPixelSize;
   1.539 +	__ASSERT_ALWAYS(iScreenDevice,Panic(EW32PanicDirectMisuse));
   1.540 +	iScreenDevice->SetDeviceOrientation(Graphics2DeviceOrientation(sizeAndRotation.iRotation));
   1.541 +	MDisplayMapping* interface = static_cast<MDisplayMapping*>
   1.542 +				(iWsScreenDevice->GetInterface(MDisplayMapping::ETypeId));
   1.543 +	
   1.544 +	if(interface)
   1.545 +		{
   1.546 +		TRect appAreaInDsa;
   1.547 +		interface->MapCoordinates(EApplicationSpace, iScreenSize, EDirectScreenAccessSpace, appAreaInDsa);
   1.548 +		if(!iDrawingRegion->BoundingRect().IsEmpty())
   1.549 +			{
   1.550 +			//no point to set draw origin if draw region is empty
   1.551 +			//this also indicates the place to draw might be outside DSA buffer
   1.552 +			iScreenDevice->SetDrawDeviceOffset(appAreaInDsa.iTl);
   1.553 +			}
   1.554 +		}
   1.555 +	
   1.556 +	aGc->Activate(iScreenDevice);
   1.557 +	}
   1.558 +
   1.559 +void CDirectScreenAccess::RunL()
   1.560 +	{
   1.561 +	iAborting = ETrue;
   1.562 +	iReason = REINTERPRET_CAST(RDirectScreenAccess::TTerminationReasons&,iStatus);
   1.563 +	iAbort.AbortNow(iReason);
   1.564 +	iAborting = EFalse;
   1.565 +	iDirectAccess.Completed();
   1.566 +	iRestart->Start(TCallBack(CDirectScreenAccess::Restart,this));
   1.567 +	}
   1.568 +
   1.569 +void CDirectScreenAccess::DoCancel()
   1.570 +	{
   1.571 +	iDirectAccess.Cancel();
   1.572 +	}