1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/windowing/windowserver/stdgraphic/TESTGRAPHICDRAWER.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,109 @@
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 +//
1.18 +
1.19 +#include "wsgraphicdrawercontext.h"
1.20 +#include "stdgraphictestdrawer.h"
1.21 +
1.22 +CWsGraphicDrawerTestFrameRate* CWsGraphicDrawerTestFrameRate::CreateL()
1.23 + {
1.24 + return new(ELeave) CWsGraphicDrawerTestFrameRate;
1.25 + }
1.26 +
1.27 +CWsGraphicDrawerTestFrameRate::CWsGraphicDrawerTestFrameRate()
1.28 + {
1.29 + }
1.30 +
1.31 +CWsGraphicDrawerTestFrameRate::~CWsGraphicDrawerTestFrameRate()
1.32 + {
1.33 + if (iContext)
1.34 + {
1.35 + iContext->Destroy();
1.36 + iContext = NULL;
1.37 + }
1.38 + }
1.39 +
1.40 +void CWsGraphicDrawerTestFrameRate::ConstructL(MWsGraphicDrawerEnvironment& aEnv,const TGraphicDrawerId& aId,MWsClient& aOwner,const TDesC8& /*aData*/)
1.41 + {
1.42 + BaseConstructL(aEnv,aId,aOwner);
1.43 + if (!(aEnv.Screen(0)->ResolveObjectInterface(KMWsCompositionContext) || aEnv.Screen(0)->ResolveObjectInterface(KMWsScene)))
1.44 + {
1.45 + iContext = CWsGraphicDrawerNonNgaContext::NewL();
1.46 + }
1.47 + else
1.48 + {
1.49 + iContext = CWsGraphicDrawerNgaContext::NewL();
1.50 + }
1.51 + }
1.52 +
1.53 +void CWsGraphicDrawerTestFrameRate::DoDraw(MWsGc& aGc,const TRect& aRect,const TDesC8& /*aData*/) const
1.54 + {
1.55 + if (KErrNone != iContext->Push(aGc))
1.56 + {
1.57 + return;
1.58 + }
1.59 + //Simplification: treats all screens the same
1.60 + iContext->DrawFrameRate(aGc, aRect, iFps);
1.61 + //Count this draw
1.62 + iFps.Sample();
1.63 + //Schedule a redraw
1.64 + iContext->ScheduleAnimation(aGc,aRect,0); // as fast as possible
1.65 + iContext->Pop(aGc);
1.66 + }
1.67 +
1.68 +void CWsGraphicDrawerTestFrameRate::HandleMessage(const TDesC8& /*aData*/)
1.69 + {
1.70 + }
1.71 +
1.72 +TInt CFrameRate::Fps() const
1.73 + {
1.74 + if(iNumSamples > 1)
1.75 + {
1.76 + const TUint count = Min(iNumSamples,KMaxSamples);
1.77 + TInt64 earliest = iSamples[0];
1.78 + TInt64 latest = earliest;
1.79 + for(TInt i=1; i<count; i++)
1.80 + {
1.81 + const TInt64 sample = iSamples[i];
1.82 + earliest = Min(earliest,sample);
1.83 + latest = Max(latest,sample);
1.84 + }
1.85 + const TInt64 duration = latest - earliest;
1.86 + const TInt microspf = (duration / count);
1.87 + if(microspf)
1.88 + {
1.89 + const TInt millispf = (microspf / 1000);
1.90 + if(millispf)
1.91 + {
1.92 + const TInt fps = (1000 / millispf);
1.93 + return fps;
1.94 + }
1.95 + }
1.96 + }
1.97 + return 0;
1.98 + }
1.99 +
1.100 +TInt CFrameRate::CountSamples() const
1.101 + {
1.102 + return iNumSamples;
1.103 + }
1.104 +
1.105 +void CFrameRate::Sample() const
1.106 + {
1.107 + //Add the current tick to the stats for next time
1.108 + TTime now;
1.109 + now.UniversalTime();
1.110 + iSamples[iNumSamples % KMaxSamples] = now.Int64();
1.111 + iNumSamples++;
1.112 + }