windowing/windowserver/nonnga/SERVER/debugbar.cpp
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Debug bar
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "debugbar.h"
       
    19 #include <bitstd.h>
       
    20 #include "screen.h"
       
    21 #include "wstop.h"
       
    22 #include <e32cmn.h>
       
    23 
       
    24 
       
    25 CDebugBar* CDebugBar::NewL(CScreen * aScreen,const TRect& aScreenRect,TTimeIntervalMicroSeconds32 aRefreshInterval)
       
    26 	{
       
    27 	CDebugBar* self = new(ELeave) CDebugBar(aScreen,aScreenRect);
       
    28 	CleanupStack::PushL(self);
       
    29 	self->ConstructL(aRefreshInterval);
       
    30 	CleanupStack::Pop(self);
       
    31 	return self;
       
    32 	}
       
    33 
       
    34 CDebugBar::~CDebugBar()
       
    35 	{
       
    36 	iScreen->ScreenDevice()->ReleaseFont(iFont);
       
    37 	delete iTimer;
       
    38 	}
       
    39 	
       
    40 CDebugBar::CDebugBar(CScreen * aScreen,const TRect& aScreenRect) : iScreen(aScreen), iScreenRect(aScreenRect)
       
    41 	{
       
    42 	}
       
    43 	
       
    44 void CDebugBar::ConstructL(TTimeIntervalMicroSeconds32 aRefreshInterval)
       
    45 	{
       
    46 	iTimer = CPeriodic::NewL(EPriorityNormal);
       
    47 	iTimer->Start(TTimeIntervalMicroSeconds32(3000000),aRefreshInterval,TCallBack(RedrawDebugBarCallback, this));
       
    48 	TFontSpec fspec(_L("DejaVu Sans Condensed"),9);
       
    49 	User::LeaveIfError(iScreen->ScreenDevice()->GetNearestFontToDesignHeightInPixels(iFont, fspec));
       
    50 	iBaseline = (iFont->BaselineOffsetInPixels() + iFont->AscentInPixels());
       
    51 	}
       
    52 	
       
    53 const TRect& CDebugBar::Rect() const
       
    54 	{
       
    55 	return iScreenRect;
       
    56 	}
       
    57 
       
    58 TBool CDebugBar::RedrawDebugBarCallback(TAny * aAny)
       
    59 	{
       
    60 	CDebugBar* self = reinterpret_cast<CDebugBar *>(aAny);
       
    61 	self->iPolls++; //minus-out the events which cause this debug-bar to 'tick'
       
    62 	self->RedrawDebugBar();
       
    63 	self->iScreen->Update(TRegionFix<1>(self->iScreenRect));
       
    64 	return ETrue;
       
    65 	}
       
    66 	
       
    67 #include "walkwindowtree.h"	
       
    68 #include "rootwin.h"
       
    69 void CDebugBar::RedrawDebugBar() const
       
    70 	{
       
    71 	_LIT(KLine1Format, "KeyEvents %d; %Ld; WServ %.1f%%; Drawing %.1f%%; Reclaimed %.1f%%");
       
    72 	_LIT(KLine2Format, "RedrawStore size %d3B; updates %d/s, pixels %d/s"); 
       
    73 	CWsActiveScheduler* scheduler = CWsActiveScheduler::Static();
       
    74 	TInt updatesPerSecond;
       
    75 	TInt64 pixelsPerSecond;
       
    76 	scheduler->DrawStats(updatesPerSecond,pixelsPerSecond,2);
       
    77 	CFbsBitGc *gc = iScreen->ScreenGdi();
       
    78 	gc->Reset();
       
    79 	gc->SetDrawMode(CGraphicsContext::EDrawModePEN);
       
    80 	gc->SetPenColor(KRgbWhite);
       
    81 	gc->SetPenStyle(CGraphicsContext::ESolidPen);
       
    82 	gc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
    83 	gc->SetBrushColor(KRgbBlack);
       
    84 	gc->DrawRect(iScreenRect);
       
    85 	gc->UseFont(iFont);
       
    86 	
       
    87 	TInt64 wserv = scheduler->Total() - iLastTotal;
       
    88 	TInt64 nonwserv = scheduler->Idle() - iLastIdle;
       
    89 	TInt64 drawing = scheduler->Drawing() - iLastDrawing;
       
    90 	TInt64 reclaimed = scheduler->ReclaimedIdleTime() - iLastReclaimedIdleTime;
       
    91 	TReal wservPercent =  wserv+nonwserv? ((TReal)wserv / (TReal)(wserv + nonwserv)) * 100.0 : 0.0 ;
       
    92 	TReal drawingPercent = wserv? ((TReal)drawing / (TReal)wserv) * 100.0: 0 ;
       
    93 	TReal reclaimedPercent = wserv+nonwserv? ((TReal)reclaimed / (TReal)(wserv + nonwserv)) * 100.0: 100.0 ;
       
    94 	
       
    95 	TWalkWindowTreeRedrawStoreSize redrawStoreWalker;
       
    96 	iScreen->RootWindow()->WalkWindowTree(redrawStoreWalker, EWalkChildrenAndBehind);
       
    97 	
       
    98 	TRect textRect(iScreenRect);
       
    99 	textRect.SetHeight(textRect.Height() / 2);
       
   100 	iBuf.Format(KLine1Format,iKeyEvents,scheduler->Requests()-iPolls,wservPercent,drawingPercent,reclaimedPercent);
       
   101 	gc->DrawText(iBuf,textRect,iBaseline);
       
   102 	
       
   103 	textRect.Move(TPoint(0,textRect.Height()));
       
   104 	iBuf.Format(KLine2Format,redrawStoreWalker.iTotalSize, updatesPerSecond, pixelsPerSecond);
       
   105 	gc->DrawText(iBuf,textRect,iBaseline);
       
   106 	
       
   107 	gc->DiscardFont();
       
   108 	
       
   109 	iLastTotal=scheduler->Total();
       
   110 	iLastIdle=scheduler->Idle();
       
   111 	iLastDrawing=scheduler->Drawing();
       
   112 	iLastReclaimedIdleTime=scheduler->ReclaimedIdleTime();
       
   113 	}
       
   114 
       
   115 void CDebugBar::OnKeyEvent()
       
   116 	{
       
   117 	iKeyEvents++;
       
   118 	RedrawDebugBar();
       
   119 	iScreen->Update(TRegionFix<1>(iScreenRect));
       
   120 	}
       
   121