os/graphics/windowing/windowserver/test/t_ratelimiter/tratelimitdrawer/ratelimitdrawer.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/windowing/windowserver/test/t_ratelimiter/tratelimitdrawer/ratelimitdrawer.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,161 @@
     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 + @test
    1.22 + @internalComponent - Internal Symbian test code
    1.23 +*/
    1.24 +
    1.25 +#include <bitstd.h>
    1.26 +#include <graphics/wsgraphicdrawer.h>
    1.27 +#include "ratelimitdrawer.h"
    1.28 +#include "wsratelimitdrawer.h"
    1.29 +#include <graphics/wsgraphicscontext.h>
    1.30 +
    1.31 +//Constant message handle, which is used to send count value between client and plug-in
    1.32 +const TUint8 KCmdCount=0;
    1.33 +// First Frame
    1.34 +const TInt KFirstFrame = 0;
    1.35 +
    1.36 +/**
    1.37 +Creates new test framerate object.
    1.38 +*/
    1.39 +CWsRateLimitGraphicDrawer* CWsRateLimitGraphicDrawer::NewL()
    1.40 +	{
    1.41 +	return new(ELeave) CWsRateLimitGraphicDrawer;
    1.42 +	}
    1.43 +
    1.44 +CWsRateLimitGraphicDrawer::CWsRateLimitGraphicDrawer()
    1.45 +	{
    1.46 +	InitialiseMembers();
    1.47 +	}
    1.48 +
    1.49 +void CWsRateLimitGraphicDrawer::InitialiseMembers()
    1.50 +	{
    1.51 +	iColors[0] = TRgb(0x000000);
    1.52 +	iColors[1] = TRgb(0x555555);
    1.53 +	iColors[2] = TRgb(0x000080);
    1.54 +	iColors[3] = TRgb(0x008000);
    1.55 +	iColors[4] = TRgb(0x008080);
    1.56 +	iColors[5] = TRgb(0x800000);
    1.57 +	iColors[6] = TRgb(0x800080);
    1.58 +	iColors[7] = TRgb(0x808000);
    1.59 +	iColors[8] = TRgb(0x0000ff);
    1.60 +	iColors[9] = TRgb(0x00ff00);
    1.61 +	iColors[10] = TRgb(0x000000);
    1.62 +	iColors[11] = TRgb(0x555555);
    1.63 +	iColors[12] = TRgb(0x000080);
    1.64 +	iColors[13] = TRgb(0x008000);
    1.65 +	iColors[14] = TRgb(0x008080);
    1.66 +	iColors[15] = TRgb(0x800000);
    1.67 +	iColors[16] = TRgb(0x800080);
    1.68 +	iColors[17] = TRgb(0x808000);
    1.69 +	iColors[18] = TRgb(0x0000ff);
    1.70 +	iColors[19] = TRgb(0x00ff00);
    1.71 +	iColors[20] = TRgb(0x000000);
    1.72 +	iColors[21] = TRgb(0x555555);
    1.73 +	iColors[22] = TRgb(0x000080);
    1.74 +	iColors[23] = TRgb(0x008000);
    1.75 +	iColors[24] = TRgb(0x008080);
    1.76 +	iColors[25] = TRgb(0x800000);
    1.77 +	iColors[26] = TRgb(0x800080);
    1.78 +	iColors[27] = TRgb(0x808000);
    1.79 +	iColors[28] = TRgb(0x0000ff);
    1.80 +	iColors[29] = TRgb(0x00ff00);
    1.81 +	iColors[30] = TRgb(0x000000);
    1.82 +	iColors[31] = TRgb(0x555555);
    1.83 +	iColors[32] = TRgb(0x000080);
    1.84 +	iColors[33] = TRgb(0x008000);
    1.85 +	iColors[34] = TRgb(0x008080);
    1.86 +	iColors[35] = TRgb(0x800000);
    1.87 +	iColors[36] = TRgb(0x800080);
    1.88 +	iColors[37] = TRgb(0x808000);
    1.89 +	iColors[38] = TRgb(0x0000ff);
    1.90 +	iColors[39] = TRgb(0x00ff00);
    1.91 +	
    1.92 +	iFrameRate = 0.0;
    1.93 +	}
    1.94 +
    1.95 +
    1.96 +CWsRateLimitGraphicDrawer::~CWsRateLimitGraphicDrawer()
    1.97 +	{
    1.98 +	}
    1.99 +
   1.100 +void CWsRateLimitGraphicDrawer::ConstructL(MWsGraphicDrawerEnvironment& aEnv,const TGraphicDrawerId& aId,MWsClient& aOwner,const TDesC8& /*aData*/)
   1.101 +	{
   1.102 +	BaseConstructL(aEnv,aId,aOwner);
   1.103 +	}
   1.104 +
   1.105 +/**	
   1.106 +Simulate two animations of different frame rate with their respective schedule.
   1.107 +
   1.108 +@param MWsGc Window server graphic context to draw the animation
   1.109 +@param TRect Rectangle are required to draw the animation
   1.110 +@param TDesC Parameter value to use inside this function.
   1.111 +*/
   1.112 +void CWsRateLimitGraphicDrawer::DoDraw(MWsGc& aGc,const TRect& aRect,const TDesC8& /*aData*/) const
   1.113 +	{
   1.114 +	TPoint KWinPos = aRect.iTl + TPoint(10,10);
   1.115 +	const TSize KWinSize(100,100);
   1.116 +	const TRect KWinRect(KWinPos,KWinSize);
   1.117 +	
   1.118 +	MWsGraphicsContext* context = static_cast<MWsGraphicsContext*>(aGc.ResolveObjectInterface(KMWsGraphicsContext));
   1.119 +	
   1.120 +	//Get the time the animation starts
   1.121 +	if(iFrame == KFirstFrame)
   1.122 +		{
   1.123 +		iStartTime = aGc.Now();
   1.124 +		}
   1.125 +	
   1.126 +	//Draw a filled rect with the chosen color
   1.127 +	context->Push();
   1.128 +	context->SetBrushStyle(MWsGraphicsContext::ESolidBrush);
   1.129 +	context->SetBrushColor(iColors[iFrame]);
   1.130 +	context->DrawRect(KWinRect);
   1.131 +	context->Pop();
   1.132 +	
   1.133 +	if(iFrame < KMaxFrames)
   1.134 +		{
   1.135 +		aGc.ScheduleAnimation(KWinRect,0);
   1.136 +		}
   1.137 +	else
   1.138 +		{
   1.139 +		TTimeIntervalMicroSeconds animLength = aGc.Now().MicroSecondsFrom(iStartTime);
   1.140 +		
   1.141 +		iFrameRate = static_cast<TReal>(KMaxFrames)/(static_cast<TReal>(animLength.Int64())/KOneSecondInMicroSecs);
   1.142 +		}
   1.143 +
   1.144 +	iFrame++;
   1.145 +	}
   1.146 +
   1.147 +/**	
   1.148 +Handles message between client and plug-in.
   1.149 +
   1.150 +@param TDesC Constant message command.
   1.151 +*/
   1.152 +void CWsRateLimitGraphicDrawer::HandleMessage(const TDesC8& aData)
   1.153 +	{
   1.154 +	switch (aData[0])
   1.155 +		{
   1.156 +		case KCmdCount:
   1.157 +			TPckgBuf<TAnimData> buf;
   1.158 +			buf().iFrameRate = iFrameRate;
   1.159 +			TInt err = SendMessage(buf);
   1.160 +			__ASSERT_DEBUG(err>=KErrNone, User::Invariant());
   1.161 +			break;
   1.162 +		}
   1.163 +	}
   1.164 +