os/graphics/windowing/windowserver/test/tdynamicres/src/wsgcedebugsession.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/windowing/windowserver/test/tdynamicres/src/wsgcedebugsession.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,177 @@
     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 +/**
    1.20 + @file
    1.21 +*/
    1.22 +
    1.23 +#include "wsgcedebugsession.h"
    1.24 +
    1.25 +RWsDebugSession::RWsDebugSession(TInt aScreenNo /*= -1*/):
    1.26 +	iScreenNo(aScreenNo),
    1.27 +	iSurfaceUpdateSerial(-1)
    1.28 +	{
    1.29 +	iSurfaceListBuffer.CreateMax(48);
    1.30 +	}
    1.31 +
    1.32 +RWsDebugSession::~RWsDebugSession()
    1.33 +	{
    1.34 +	iSurfaceListBuffer.Close();
    1.35 +	
    1.36 +	}
    1.37 +
    1.38 +TBool RWsDebugSession::ResetUpdated()
    1.39 +	{
    1.40 +	TInt surfaceUpdateSerial=DebugInfo(EWsDebugSerialSurfacesUpdated,iScreenNo);
    1.41 +	TBool retVal=(iSurfaceUpdateSerial!=surfaceUpdateSerial);
    1.42 +	iSurfaceUpdateSerial=surfaceUpdateSerial;
    1.43 +	return retVal;
    1.44 +	}
    1.45 +
    1.46 +TInt RWsDebugSession::ResetUpdatedAndGetSurfaceWindowList(const TWsDebugWindowId * & aWinList)
    1.47 +	{
    1.48 +	iSurfaceUpdateSerial=DebugInfo(EWsDebugSerialSurfacesUpdated,iScreenNo);
    1.49 +	TInt reqSize=DebugInfo(EWsDebugSurfaceWindowList,iSurfaceListBuffer,iScreenNo);
    1.50 +	while (reqSize>iSurfaceListBuffer.MaxLength())
    1.51 +		{
    1.52 +		iSurfaceListBuffer.Close();
    1.53 +		iSurfaceListBuffer.CreateMax(reqSize);
    1.54 +		iSurfaceUpdateSerial=DebugInfo(EWsDebugSerialSurfacesUpdated,iScreenNo);
    1.55 +		reqSize=DebugInfo(EWsDebugSurfaceWindowList,iSurfaceListBuffer,iScreenNo);
    1.56 +		}
    1.57 +	if (reqSize==KErrCancel)
    1.58 +		{
    1.59 +		aWinList=NULL;
    1.60 +		return 0;
    1.61 +		}
    1.62 +	else
    1.63 +		{
    1.64 +		aWinList=(TWsDebugWindowId*)iSurfaceListBuffer.Ptr();
    1.65 +		return reqSize/sizeof(TWsDebugWindowId);
    1.66 +		}
    1.67 +	}
    1.68 +/**
    1.69 + * Stream data into the provided buffer and point the return object pointer to it.
    1.70 + * The pointer is left null if the method returns an error code or the buffer is too small.
    1.71 + * The ret5urn code reports 
    1.72 + * 
    1.73 + **/
    1.74 +TInt	RWsDebugSession::DebugInfo(TWsDebugInfoFunc aFunction, TInt aParam, TDes8& aHostBuffer,const void*&aReturnedObject,TInt aObjectSize)const
    1.75 +	{
    1.76 +	aHostBuffer.SetMax();
    1.77 +	TInt reqSize=DebugInfo(aFunction,aHostBuffer,aParam);
    1.78 +	aReturnedObject=NULL;
    1.79 +	if (reqSize<0)
    1.80 +		{
    1.81 +		return reqSize;	//Error code is transmitted unmolested
    1.82 +		}
    1.83 +	if (reqSize==0)		//Size 0 is transformed to max
    1.84 +		reqSize=aHostBuffer.MaxLength();
    1.85 +	if ((reqSize%aObjectSize)!=0)
    1.86 +		{				//Size not multiple of object --> error
    1.87 +		return KErrCorrupt;
    1.88 +		}
    1.89 +	if (reqSize<=aHostBuffer.MaxLength())
    1.90 +		{		//Pointer is only set if data fits buffer
    1.91 +		aReturnedObject=(const void*)aHostBuffer.Ptr();
    1.92 +		}
    1.93 +	reqSize/=aObjectSize;	//Return the exact number of objects filled
    1.94 +	return reqSize;
    1.95 +	}
    1.96 +/**
    1.97 + * Stream the reply data via the buffer associated with the region.
    1.98 + * Some protected accessor optimisation used to manage the reported size of the region after streaming.
    1.99 + * 
   1.100 + **/
   1.101 +TInt	RWsDebugSession::DebugInfo(TWsDebugInfoFunc aFunction, TInt aParam, TRegion& aPreAllocatedReturnedRegion)const
   1.102 +	{
   1.103 +	//Attempt to fit the received data in the preexisting region buffer...
   1.104 +	class XRegion:public TRegion
   1.105 +		{
   1.106 +		public:
   1.107 +			using TRegion::AppendRect;
   1.108 +		//	using TRegion::SetListSize;
   1.109 +			using TRegion::RectangleListW;
   1.110 +			TInt MaxSize()				
   1.111 +				{ return iAllocedRects;	}
   1.112 +			void  SetListSize(TInt aNewSize)	//DANGER no error checking!!!				
   1.113 +				{ iCount=aNewSize;	}
   1.114 +		}& preAllocatedReturnedRegion=(XRegion&)aPreAllocatedReturnedRegion;
   1.115 +	typedef TRect TElt;
   1.116 +	TInt reqSize=preAllocatedReturnedRegion.MaxSize();
   1.117 +	const TElt* elements=preAllocatedReturnedRegion.RectangleListW();
   1.118 +	TInt lenBytes=reqSize*sizeof(TElt);
   1.119 +	TPtr8 pBuff((TUint8*)elements,lenBytes,lenBytes);
   1.120 +	reqSize=DebugInfo(aFunction,aParam,pBuff,elements);
   1.121 +	
   1.122 +	if (elements)
   1.123 +		{
   1.124 +		if (reqSize==0)
   1.125 +			{
   1.126 +			reqSize=preAllocatedReturnedRegion.MaxSize();
   1.127 +			}
   1.128 +		preAllocatedReturnedRegion.SetListSize(reqSize);
   1.129 +		return reqSize;
   1.130 +		}
   1.131 +	//If data does not fit in preexisting buffer
   1.132 +	//Use a temp array instead
   1.133 +	//Still try to block copy into the existing capacity
   1.134 +	//I think this use of region copy is more efficient than appending,
   1.135 +	//and definitely better than unioning the elements.
   1.136 +	if (reqSize>=0)
   1.137 +		{
   1.138 +		TInt breakLoop=10;
   1.139 +		do	{
   1.140 +			TElt* tempbuff=new TElt[reqSize];
   1.141 +			if (tempbuff==NULL)
   1.142 +				{
   1.143 +				reqSize=KErrNoMemory;
   1.144 +				break;
   1.145 +				}
   1.146 +			elements=tempbuff;
   1.147 +			TInt lenBytes=reqSize*sizeof(TElt);
   1.148 +			TPtr8 pBuff((TUint8*)elements,lenBytes,lenBytes);
   1.149 +			TInt reqSize2=DebugInfo(aFunction,aParam,pBuff,elements);
   1.150 +			if (reqSize2!=0)
   1.151 +				reqSize=reqSize2;
   1.152 +			if (elements)
   1.153 +				{
   1.154 +				RRegion r(reqSize,tempbuff);	//note this region does not own its memory so should not be closed!
   1.155 +				aPreAllocatedReturnedRegion.Copy(r);
   1.156 +				if (aPreAllocatedReturnedRegion.CheckError())
   1.157 +					reqSize=KErrNoMemory;
   1.158 +				}
   1.159 +			delete[] tempbuff;
   1.160 +			}while (reqSize>0 && elements==NULL && --breakLoop);
   1.161 +		}
   1.162 +	if (reqSize>=0 && elements==NULL)
   1.163 +		{
   1.164 +		preAllocatedReturnedRegion.ForceError();
   1.165 +		reqSize=KErrTimedOut;
   1.166 +		}
   1.167 +	if (reqSize<0)
   1.168 +		{
   1.169 +		if (reqSize==KErrCancel)
   1.170 +			{
   1.171 +			preAllocatedReturnedRegion.Clear();
   1.172 +			}
   1.173 +		else
   1.174 +			{
   1.175 +			preAllocatedReturnedRegion.ForceError();
   1.176 +			}
   1.177 +	
   1.178 +		}
   1.179 +	return reqSize;
   1.180 +	}