sl@0: // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // General utility functions that don't belong anywhere else sl@0: // sl@0: // sl@0: sl@0: #include "server.h" sl@0: #include "rootwin.h" sl@0: #include "wstop.h" sl@0: #include "panics.h" sl@0: sl@0: GLREF_D CDebugLogBase *wsDebugLog; sl@0: sl@0: GLDEF_C RWsRegion *GetRegionFromClientL(CWsClient *aClient, TInt aCount) sl@0: { sl@0: TInt bufSize=sizeof(TRect)*aCount; sl@0: TUint8* rectList=STATIC_CAST(TUint8*,User::Alloc(bufSize)); sl@0: User::LeaveIfNull(rectList); sl@0: CleanupStack::PushL(rectList); sl@0: TPtr8 rectBuf(rectList,bufSize); sl@0: aClient->RemoteRead(rectBuf,0); sl@0: RWsRegion* region=new(ELeave) RWsRegion(aCount,REINTERPRET_CAST(TRect*,rectList)); sl@0: CleanupStack::Pop(rectList); sl@0: return(region); sl@0: } sl@0: sl@0: GLDEF_C TInt ExternalizeRegionL(RWriteStream& aWriteStream, const RWsRegion& aRegion) sl@0: { sl@0: TInt dataLen = sizeof(TRect)*aRegion.Count(); sl@0: aWriteStream.WriteInt32L(aRegion.Count()); sl@0: aWriteStream.WriteL(REINTERPRET_CAST(const TUint8*,aRegion.RectangleList()),dataLen); sl@0: aWriteStream.CommitL(); sl@0: return sizeof(TInt32)+dataLen; sl@0: } sl@0: sl@0: GLDEF_C RWsRegion* InternalizeRegionL(RReadStream& aReadStream) sl@0: { sl@0: TInt numRects = aReadStream.ReadInt32L(); sl@0: TInt bufSize = sizeof(TRect)*numRects; sl@0: // Allocate buffer for list of clipping rectangles. We leave if we sl@0: // cannot create the buffer sl@0: TUint8* rectList = static_cast(User::AllocL(bufSize)); sl@0: CleanupStack::PushL(rectList); sl@0: // Read the list of rectangles into the buffer sl@0: aReadStream.ReadL(rectList,bufSize); sl@0: // Point member pointer to our new rectangle list buffer sl@0: RWsRegion* region = new(ELeave) RWsRegion(numRects,reinterpret_cast(rectList)); sl@0: CleanupStack::Pop(rectList); sl@0: return region; sl@0: } sl@0: sl@0: void Panic(TWservPanic aPanic) sl@0: { sl@0: if (wsDebugLog) sl@0: wsDebugLog->Panic(CDebugLogBase::EDummyConnectionId,aPanic); //Dummy value meaning WSERV sl@0: _LIT(KWSERVInternalPanicCategory,"WSERV-INTERNAL"); sl@0: User::Panic(KWSERVInternalPanicCategory,aPanic); sl@0: } sl@0: sl@0: _LIT(KWSERVPanicDesc1,"WServ internal Panic %S, in file %S @ line %i"); sl@0: _LIT(KWSERVPanicDesc2,"Assert condition = \"%S\""); sl@0: sl@0: void PanicWithInfo(TWservPanic aPanic, const TDesC& aFileName, const TDesC& aPanicName, TInt aLine) sl@0: { sl@0: TBuf<256> buf; sl@0: buf.Format(KWSERVPanicDesc1, &aPanicName, &aFileName, aLine); sl@0: RDebug::Print(buf); sl@0: if (wsDebugLog) sl@0: { sl@0: wsDebugLog->MiscMessage(CDebugLogBase::ELogImportant, buf); sl@0: } sl@0: Panic(aPanic); sl@0: } sl@0: sl@0: void PanicWithCondAndInfo(TWservPanic aPanic, const TDesC& aCondition, const TDesC& aFileName, const TDesC& aPanicName, TInt aLine) sl@0: { sl@0: TBuf<256> buf; sl@0: buf.Format(KWSERVPanicDesc1, &aPanicName, &aFileName, aLine); sl@0: RDebug::Print(buf); sl@0: if (wsDebugLog) sl@0: { sl@0: wsDebugLog->MiscMessage(CDebugLogBase::ELogImportant, buf); sl@0: } sl@0: buf.Format(KWSERVPanicDesc2, &aCondition); sl@0: RDebug::Print(buf); sl@0: if (wsDebugLog) sl@0: { sl@0: wsDebugLog->MiscMessage(CDebugLogBase::ELogImportant, buf); sl@0: } sl@0: Panic(aPanic); sl@0: } sl@0: sl@0: sl@0: GLDEF_C void StateDump() sl@0: { sl@0: CWsTop::StateDump(); sl@0: } sl@0: sl@0: GLDEF_C void StateDump(CWsRootWindow* aRootWindow) sl@0: { sl@0: TBool enabled=wsDebugLog!=NULL; sl@0: if (!enabled) sl@0: { sl@0: CWsTop::EnableLogging(); sl@0: if (!wsDebugLog) sl@0: return; // Failed to enable logging so give up sl@0: } sl@0: // sl@0: _LIT(LogLine,"==========="); sl@0: _LIT(KWSERVStateLogWindowTree,"Window tree"); sl@0: TBuf<128> buf; sl@0: wsDebugLog->MiscMessage(CDebugLogBase::ELogImportant,LogLine); sl@0: wsDebugLog->MiscMessage(CDebugLogBase::ELogImportant,KWSERVStateLogWindowTree); sl@0: wsDebugLog->MiscMessage(CDebugLogBase::ELogImportant,LogLine); sl@0: sl@0: CWsWindowBase *win=aRootWindow; sl@0: TInt inset=0; sl@0: _LIT(KWSERVStateInsetLevelValue,"%*p"); sl@0: FOREVER sl@0: { sl@0: buf.Format(KWSERVStateInsetLevelValue,Min(inset<<1,20)); sl@0: win->StatusDump(buf); sl@0: wsDebugLog->MiscMessage(CDebugLogBase::ELogImportant,buf); sl@0: if (win->BaseChild()) sl@0: { sl@0: ++inset; sl@0: win=win->BaseChild(); sl@0: continue; sl@0: } sl@0: while(!win->NextSibling() && win!=aRootWindow) sl@0: { sl@0: win=win->BaseParent(); sl@0: --inset; sl@0: } sl@0: if (win==aRootWindow) sl@0: break; //Will break here if there is only the root window or the tree walk has returned to it sl@0: win=win->NextSibling(); sl@0: } sl@0: wsDebugLog->MiscMessage(CDebugLogBase::ELogImportant,LogLine); sl@0: // sl@0: if (!enabled) sl@0: CWsTop::DisableLogging(); sl@0: } sl@0: sl@0: GLDEF_C void HeapDump() sl@0: { sl@0: TBool enabled=(wsDebugLog!=NULL); sl@0: if (!enabled) sl@0: CWsTop::EnableLogging(); sl@0: if (wsDebugLog) // Just in case enable failed sl@0: wsDebugLog->HeapDump(); sl@0: if (!enabled) sl@0: CWsTop::DisableLogging(); sl@0: } sl@0: sl@0: #if defined(_DEBUG) sl@0: //GLREF_C void ForceLog(TInt aPriority,const TDesC &aText,TInt aParam=0); sl@0: //ForceLog(CDebugLogBase::ELogImportant,_L("Value=%d"),345); sl@0: //TLogMessageText buf; sl@0: //_LIT(KLog,"Count=%d, Object=0x%x"); sl@0: //buf.Format(KLog,Count(),this); sl@0: //ForceLog(CDebugLogBase::ELogImportant,buf); sl@0: GLDEF_C void ForceLog(TInt aPriority,const TDesC &aText,TInt aParam=0) sl@0: { sl@0: TBool enabled=(wsDebugLog!=NULL); sl@0: if (!enabled) sl@0: CWsTop::EnableLogging(); sl@0: if (wsDebugLog) // Just in case enable failed sl@0: { sl@0: wsDebugLog->MiscMessage(aPriority,aText,aParam); sl@0: if (!enabled) sl@0: CWsTop::DisableLogging(); sl@0: } sl@0: } sl@0: #endif sl@0: sl@0: LOCAL_C TDisplayMode DisplayMode(TBool aIsColor,TInt aNumColors) sl@0: { sl@0: sl@0: if (aIsColor) sl@0: { sl@0: switch(aNumColors) sl@0: { sl@0: case 16: sl@0: return EColor16; sl@0: case 256: sl@0: return EColor256; sl@0: case 4096: sl@0: return EColor4K; sl@0: case 65536: sl@0: return EColor64K; sl@0: case 16777216: sl@0: return CFbsDevice::DisplayMode16M(); sl@0: default: sl@0: return ENone; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: switch(aNumColors) sl@0: { sl@0: case 2: sl@0: return EGray2; sl@0: case 4: sl@0: return EGray4; sl@0: case 16: sl@0: return EGray16; sl@0: case 256: sl@0: return EGray256; sl@0: default: sl@0: return ENone; sl@0: } sl@0: } sl@0: } sl@0: sl@0: GLDEF_C TDisplayMode ParseDisplayMode(const TDesC& aModeName) sl@0: { sl@0: // Not using _LIT because we only want the string temporarily, not permanently on the heap. sl@0: if (!aModeName.CompareF(_L("EColor16MAP"))) sl@0: return EColor16MAP; sl@0: else if (!aModeName.CompareF(_L("EColor16MA"))) sl@0: return EColor16MA; sl@0: else if (!aModeName.CompareF(_L("EColor16MU"))) sl@0: return EColor16MU; sl@0: else if (!aModeName.CompareF(_L("EColor64K"))) sl@0: return EColor64K; sl@0: else if (!aModeName.CompareF(_L("EColor4K"))) sl@0: return EColor4K; sl@0: else if (!aModeName.CompareF(_L("EColor256"))) sl@0: return EColor256; sl@0: else if (!aModeName.CompareF(_L("EColor16"))) sl@0: return EColor16; sl@0: else if (!aModeName.CompareF(_L("EGray256"))) sl@0: return EGray256; sl@0: else if (!aModeName.CompareF(_L("EGray16"))) sl@0: return EGray16; sl@0: else if (!aModeName.CompareF(_L("EGray4"))) sl@0: return EGray4; sl@0: else if (!aModeName.CompareF(_L("EGray2"))) sl@0: return EGray2; sl@0: else // old wserv magic sl@0: { // this code supports the old "ColorXXX" and "GrayXXX" formats etc sl@0: TPtrC ptr(aModeName); sl@0: TBool isColor=EFalse; sl@0: sl@0: if (ptr[0]=='C' || ptr[0]=='c') sl@0: isColor=ETrue; sl@0: else if (ptr[0]=='A' || ptr[0]=='a') sl@0: return EColor16MA; sl@0: else if (ptr[0]=='P' || ptr[0]=='p') sl@0: return EColor16MAP; sl@0: else if (ptr[0]!='G' && ptr[0]!='g') sl@0: return ENone; sl@0: sl@0: TInt pos=0; sl@0: while (!TChar(ptr[++pos]).IsDigit()) sl@0: {} sl@0: TLex lex(ptr.Mid(pos)); sl@0: TInt numCols; sl@0: if (lex.Val(numCols)!=KErrNone) sl@0: return ENone; sl@0: lex.SkipSpace(); sl@0: TChar units=lex.Get(); sl@0: if (units=='K' || units=='k') sl@0: numCols<<=10; sl@0: else if (units=='M' || units=='m') sl@0: numCols<<=20; sl@0: TDisplayMode mode = DisplayMode(isColor,numCols); sl@0: sl@0: #if defined(__WINS__) sl@0: //This is a special case for the emulator since the default sl@0: //screen packing can be overridden by the wsini.ini setting sl@0: sl@0: //This code does nothing is iDefaultDisplayMode is not sl@0: //EColor16M.- see graphics/screendriver/swins/scnew.cpp sl@0: //function CFbsDrawDevice::DisplayMode16M(). sl@0: if(mode==EColor16M) sl@0: { sl@0: TChar packed=lex.Get(); sl@0: if ((packed=='U')||(packed=='u')) sl@0: { sl@0: mode=EColor16MU; sl@0: } sl@0: } sl@0: sl@0: //However setting this will give four shades of grey since sl@0: //the code does not support 16MU and 16M at the same time. sl@0: #endif sl@0: return mode; sl@0: } sl@0: } sl@0: