os/graphics/windowing/windowserver/nonnga/SERVER/UTILS.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/windowing/windowserver/nonnga/SERVER/UTILS.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,303 @@
     1.4 +// Copyright (c) 1995-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 +// General utility functions that don't belong anywhere else
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include "server.h"
    1.22 +#include "rootwin.h"
    1.23 +#include "wstop.h"
    1.24 +#include "panics.h"
    1.25 +
    1.26 +GLREF_D CDebugLogBase *wsDebugLog;
    1.27 +
    1.28 +GLDEF_C RWsRegion *GetRegionFromClientL(CWsClient *aClient, TInt aCount)
    1.29 +	{
    1.30 +	TInt bufSize=sizeof(TRect)*aCount;
    1.31 +	TUint8* rectList=STATIC_CAST(TUint8*,User::Alloc(bufSize));
    1.32 +	User::LeaveIfNull(rectList);
    1.33 +	CleanupStack::PushL(rectList);
    1.34 +	TPtr8 rectBuf(rectList,bufSize);
    1.35 +	aClient->RemoteRead(rectBuf,0);
    1.36 +	RWsRegion* region=new(ELeave) RWsRegion(aCount,REINTERPRET_CAST(TRect*,rectList));
    1.37 +	CleanupStack::Pop(rectList);
    1.38 +	return(region);
    1.39 +	}
    1.40 +
    1.41 +GLDEF_C TInt ExternalizeRegionL(RWriteStream& aWriteStream, const RWsRegion& aRegion)
    1.42 +	{
    1.43 +	TInt dataLen = sizeof(TRect)*aRegion.Count();
    1.44 +	aWriteStream.WriteInt32L(aRegion.Count());
    1.45 +	aWriteStream.WriteL(REINTERPRET_CAST(const TUint8*,aRegion.RectangleList()),dataLen);
    1.46 +	aWriteStream.CommitL();
    1.47 +	return sizeof(TInt32)+dataLen;
    1.48 +	}
    1.49 +
    1.50 +GLDEF_C RWsRegion* InternalizeRegionL(RReadStream& aReadStream)
    1.51 +	{
    1.52 +	TInt numRects = aReadStream.ReadInt32L();
    1.53 +	TInt bufSize = sizeof(TRect)*numRects;
    1.54 +	// Allocate buffer for list of clipping rectangles. We leave if we 
    1.55 +	// cannot create the buffer
    1.56 +	TUint8* rectList = static_cast<TUint8*>(User::AllocL(bufSize));
    1.57 +	CleanupStack::PushL(rectList);
    1.58 +	// Read the list of rectangles into the buffer
    1.59 +	aReadStream.ReadL(rectList,bufSize);
    1.60 +	// Point member pointer to our new rectangle list buffer
    1.61 +	RWsRegion* region = new(ELeave) RWsRegion(numRects,reinterpret_cast<TRect*>(rectList));
    1.62 +	CleanupStack::Pop(rectList);
    1.63 +	return region;
    1.64 +	}
    1.65 +
    1.66 +void Panic(TWservPanic aPanic)
    1.67 +	{
    1.68 +	if (wsDebugLog)
    1.69 +		wsDebugLog->Panic(CDebugLogBase::EDummyConnectionId,aPanic);		//Dummy value meaning WSERV
    1.70 +	_LIT(KWSERVInternalPanicCategory,"WSERV-INTERNAL");
    1.71 +	User::Panic(KWSERVInternalPanicCategory,aPanic);
    1.72 +	}
    1.73 +
    1.74 +_LIT(KWSERVPanicDesc1,"WServ internal Panic %S, in file %S @ line %i");
    1.75 +_LIT(KWSERVPanicDesc2,"Assert condition = \"%S\"");
    1.76 +
    1.77 +void PanicWithInfo(TWservPanic aPanic, const TDesC& aFileName, const TDesC& aPanicName, TInt aLine)
    1.78 +	{
    1.79 +	TBuf<256> buf;
    1.80 +	buf.Format(KWSERVPanicDesc1, &aPanicName, &aFileName, aLine);
    1.81 +	RDebug::Print(buf);
    1.82 +	if (wsDebugLog)
    1.83 +		{
    1.84 +		wsDebugLog->MiscMessage(CDebugLogBase::ELogImportant, buf);
    1.85 +		}
    1.86 +	Panic(aPanic);
    1.87 +	}
    1.88 +
    1.89 +void PanicWithCondAndInfo(TWservPanic aPanic, const TDesC& aCondition, const TDesC& aFileName, const TDesC& aPanicName, TInt aLine)
    1.90 +	{
    1.91 +	TBuf<256> buf;
    1.92 +	buf.Format(KWSERVPanicDesc1, &aPanicName, &aFileName, aLine);
    1.93 +	RDebug::Print(buf);
    1.94 +	if (wsDebugLog)
    1.95 +		{
    1.96 +		wsDebugLog->MiscMessage(CDebugLogBase::ELogImportant, buf);
    1.97 +		}
    1.98 +	buf.Format(KWSERVPanicDesc2, &aCondition);
    1.99 +	RDebug::Print(buf);
   1.100 +	if (wsDebugLog)
   1.101 +		{
   1.102 +		wsDebugLog->MiscMessage(CDebugLogBase::ELogImportant, buf);
   1.103 +		}
   1.104 +	Panic(aPanic);
   1.105 +	}
   1.106 +
   1.107 +
   1.108 +GLDEF_C void StateDump()
   1.109 +	{
   1.110 +	CWsTop::StateDump();
   1.111 +	}
   1.112 +
   1.113 +GLDEF_C void StateDump(CWsRootWindow* aRootWindow)
   1.114 +	{
   1.115 +	TBool enabled=wsDebugLog!=NULL;
   1.116 +	if (!enabled)
   1.117 +		{
   1.118 +		CWsTop::EnableLogging();
   1.119 +		if (!wsDebugLog)
   1.120 +			return;	//	Failed to enable logging so give up
   1.121 +		}
   1.122 +//
   1.123 +	_LIT(LogLine,"===========");
   1.124 +	_LIT(KWSERVStateLogWindowTree,"Window tree");
   1.125 +	TBuf<128> buf;
   1.126 +	wsDebugLog->MiscMessage(CDebugLogBase::ELogImportant,LogLine);
   1.127 +	wsDebugLog->MiscMessage(CDebugLogBase::ELogImportant,KWSERVStateLogWindowTree);
   1.128 +	wsDebugLog->MiscMessage(CDebugLogBase::ELogImportant,LogLine);
   1.129 +
   1.130 +	CWsWindowBase *win=aRootWindow;
   1.131 +	TInt inset=0;
   1.132 +	_LIT(KWSERVStateInsetLevelValue,"%*p");
   1.133 +	FOREVER
   1.134 +		{
   1.135 +		buf.Format(KWSERVStateInsetLevelValue,Min(inset<<1,20));
   1.136 +		win->StatusDump(buf);
   1.137 +		wsDebugLog->MiscMessage(CDebugLogBase::ELogImportant,buf);
   1.138 +		if (win->BaseChild())
   1.139 +			{
   1.140 +			++inset;
   1.141 +			win=win->BaseChild();
   1.142 +			continue;
   1.143 +			}
   1.144 +		while(!win->NextSibling() && win!=aRootWindow)
   1.145 +			{
   1.146 +			win=win->BaseParent();
   1.147 +			--inset;
   1.148 +			}
   1.149 +		if (win==aRootWindow)
   1.150 +			break;		//Will break here if there is only the root window or the tree walk has returned to it
   1.151 +		win=win->NextSibling();
   1.152 +		}
   1.153 +	wsDebugLog->MiscMessage(CDebugLogBase::ELogImportant,LogLine);
   1.154 +//
   1.155 +	if (!enabled)
   1.156 +		CWsTop::DisableLogging();
   1.157 +	}
   1.158 +
   1.159 +GLDEF_C void HeapDump()
   1.160 +	{
   1.161 +	TBool enabled=(wsDebugLog!=NULL);
   1.162 +	if (!enabled)
   1.163 +		CWsTop::EnableLogging();
   1.164 +	if (wsDebugLog)	// Just in case enable failed
   1.165 +		wsDebugLog->HeapDump();
   1.166 +	if (!enabled)
   1.167 +		CWsTop::DisableLogging();
   1.168 +	}
   1.169 +
   1.170 +#if defined(_DEBUG)
   1.171 +//GLREF_C void ForceLog(TInt aPriority,const TDesC &aText,TInt aParam=0);
   1.172 +//ForceLog(CDebugLogBase::ELogImportant,_L("Value=%d"),345);
   1.173 +//TLogMessageText buf;
   1.174 +//_LIT(KLog,"Count=%d, Object=0x%x");
   1.175 +//buf.Format(KLog,Count(),this);
   1.176 +//ForceLog(CDebugLogBase::ELogImportant,buf);
   1.177 +GLDEF_C void ForceLog(TInt aPriority,const TDesC &aText,TInt aParam=0)
   1.178 +	{
   1.179 +	TBool enabled=(wsDebugLog!=NULL);
   1.180 +	if (!enabled)
   1.181 +		CWsTop::EnableLogging();
   1.182 +	if (wsDebugLog)	// Just in case enable failed
   1.183 +		{
   1.184 +		wsDebugLog->MiscMessage(aPriority,aText,aParam);
   1.185 +		if (!enabled)
   1.186 +			CWsTop::DisableLogging();
   1.187 +		}
   1.188 +	}
   1.189 +#endif
   1.190 +
   1.191 +LOCAL_C TDisplayMode DisplayMode(TBool aIsColor,TInt aNumColors)
   1.192 +	{
   1.193 +
   1.194 +	if (aIsColor)
   1.195 +		{
   1.196 +		switch(aNumColors)
   1.197 +			{
   1.198 +		case 16:
   1.199 +			return EColor16;
   1.200 +		case 256:
   1.201 +			return EColor256;
   1.202 +		case 4096:
   1.203 +			return EColor4K;
   1.204 +		case 65536:
   1.205 +			return EColor64K;
   1.206 +		case 16777216:
   1.207 +			return CFbsDevice::DisplayMode16M();
   1.208 +		default:
   1.209 +			return ENone;
   1.210 +			}
   1.211 +		}
   1.212 +	else
   1.213 +		{
   1.214 +		switch(aNumColors)
   1.215 +			{
   1.216 +		case 2:
   1.217 +			return EGray2;
   1.218 +		case 4:
   1.219 +			return EGray4;
   1.220 +		case 16:
   1.221 +			return EGray16;
   1.222 +		case 256:
   1.223 +			return EGray256;
   1.224 +		default:
   1.225 +			return ENone;
   1.226 +			}
   1.227 +		}
   1.228 +	}
   1.229 +
   1.230 +GLDEF_C TDisplayMode ParseDisplayMode(const TDesC& aModeName)
   1.231 +	{
   1.232 +	// Not using _LIT because we only want the string temporarily, not permanently on the heap.
   1.233 +	if (!aModeName.CompareF(_L("EColor16MAP")))
   1.234 +		return EColor16MAP;
   1.235 +	else if (!aModeName.CompareF(_L("EColor16MA")))
   1.236 +		return EColor16MA;
   1.237 +	else if (!aModeName.CompareF(_L("EColor16MU")))
   1.238 +		return EColor16MU;
   1.239 +	else if (!aModeName.CompareF(_L("EColor64K")))
   1.240 +		return EColor64K;
   1.241 +	else if (!aModeName.CompareF(_L("EColor4K")))
   1.242 +		return EColor4K;
   1.243 +	else if (!aModeName.CompareF(_L("EColor256")))
   1.244 +		return EColor256;
   1.245 +	else if (!aModeName.CompareF(_L("EColor16")))
   1.246 +		return EColor16;
   1.247 +	else if (!aModeName.CompareF(_L("EGray256")))
   1.248 +		return EGray256;
   1.249 +	else if (!aModeName.CompareF(_L("EGray16")))
   1.250 +		return EGray16;
   1.251 +	else if (!aModeName.CompareF(_L("EGray4")))
   1.252 +		return EGray4;
   1.253 +	else if (!aModeName.CompareF(_L("EGray2")))
   1.254 +		return EGray2;
   1.255 +	else	// old wserv magic
   1.256 +		{	// this code supports the old "ColorXXX" and "GrayXXX" formats etc
   1.257 +		TPtrC ptr(aModeName);
   1.258 +		TBool isColor=EFalse;
   1.259 +
   1.260 +		if (ptr[0]=='C' || ptr[0]=='c')
   1.261 +			isColor=ETrue;
   1.262 +		else if (ptr[0]=='A' || ptr[0]=='a')
   1.263 +			return EColor16MA;
   1.264 +		else if (ptr[0]=='P' || ptr[0]=='p')
   1.265 +			return EColor16MAP;
   1.266 +		else if (ptr[0]!='G' && ptr[0]!='g')
   1.267 +			return ENone;
   1.268 +		
   1.269 +		TInt pos=0;
   1.270 +		while (!TChar(ptr[++pos]).IsDigit())
   1.271 +			{}
   1.272 +		TLex lex(ptr.Mid(pos));
   1.273 +		TInt numCols;
   1.274 +		if (lex.Val(numCols)!=KErrNone)
   1.275 +			return ENone;
   1.276 +		lex.SkipSpace();
   1.277 +		TChar units=lex.Get();
   1.278 +		if (units=='K' || units=='k')
   1.279 +			numCols<<=10;
   1.280 +		else if (units=='M' || units=='m')
   1.281 +			numCols<<=20;
   1.282 +		TDisplayMode mode = DisplayMode(isColor,numCols);
   1.283 +
   1.284 +		#if defined(__WINS__)
   1.285 +			//This is a special case for the emulator since the default
   1.286 +			//screen packing can be overridden by the wsini.ini setting
   1.287 +
   1.288 +			//This code does nothing is iDefaultDisplayMode is not
   1.289 +			//EColor16M.- see graphics/screendriver/swins/scnew.cpp
   1.290 +			//function CFbsDrawDevice::DisplayMode16M().
   1.291 +			if(mode==EColor16M)
   1.292 +				{
   1.293 +				TChar packed=lex.Get();
   1.294 +				if ((packed=='U')||(packed=='u'))
   1.295 +					{
   1.296 +					mode=EColor16MU;
   1.297 +					}
   1.298 +				}
   1.299 +
   1.300 +			//However setting this will give four shades of grey since
   1.301 +			//the code does not support 16MU and 16M at the same time.
   1.302 +		#endif
   1.303 +		return mode;
   1.304 +		}
   1.305 +	}
   1.306 +