os/graphics/windowing/windowserver/test/t_stress/src/animatedwin.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_stress/src/animatedwin.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,388 @@
     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
    1.23 +*/
    1.24 +
    1.25 +#include "animatedwin.h"
    1.26 +#include "utils.h"
    1.27 +
    1.28 +#include "stressanimcmd.h"
    1.29 +
    1.30 +#include <hal.h>
    1.31 +
    1.32 +
    1.33 +//static configuration data, definitions and default assignments
    1.34 +TBool CAnimatedWin::iEnabled = ETrue;
    1.35 +TBool CAnimatedWin::iTransparent = ETrue;
    1.36 +TBool CAnimatedWin::iTransparentForegroundWindow = EFalse;
    1.37 +
    1.38 +const TInt sInvisibleFrame = 24;	//how much bigger the invisible window is
    1.39 +
    1.40 +CAnimatedWin* CAnimatedWin::NewLC(RWsSession& aWs, RWindowGroup* aGroup, CCompWin* aParent, CWindowGc& aGc)
    1.41 +	{
    1.42 +	CAnimatedWin* self = new (ELeave) CAnimatedWin( aWs, aGroup, aParent, aGc );
    1.43 +	CleanupStack::PushL( self );
    1.44 +	self->ConstructL();
    1.45 +	
    1.46 +	return self;
    1.47 +	}
    1.48 +
    1.49 +void CAnimatedWin::LoadConfiguration(const MTestStepConfigurationContext* aContext)
    1.50 +	{
    1.51 +	aContext->GetBool(KT_WservStressParamEnabled, iEnabled);
    1.52 +	aContext->GetBool(KT_WservStressParamTransparent, iTransparent);
    1.53 +	aContext->GetBool(KT_WservStressParamTransparentForegroundWindow, iTransparentForegroundWindow);
    1.54 +	}
    1.55 +
    1.56 +CAnimatedWin::~CAnimatedWin()
    1.57 +	{ 
    1.58 +	if (iForeWin)
    1.59 +		{
    1.60 +		iForeWin->Close();
    1.61 +		delete iForeWin;
    1.62 +		}
    1.63 +	
    1.64 +	if ( iAnim )
    1.65 +		{
    1.66 +		iAnim->Destroy();
    1.67 +		}
    1.68 +	iAnimDll.Close();
    1.69 +	
    1.70 +	TInt idx;
    1.71 +	for ( idx = 0; idx < ENofFrames; idx++)
    1.72 +		{
    1.73 +		delete iAnimCntDevice [idx];
    1.74 +		delete iAnimContent [idx]; 
    1.75 +		}
    1.76 +	
    1.77 +	delete iAnimMskDevice;
    1.78 +	delete iAnimMask;
    1.79 +	}
    1.80 +
    1.81 +	
    1.82 +void CAnimatedWin::Redraw(const TRect& aRect)
    1.83 +	{
    1.84 +	iWsGc.Activate(*iWindow);
    1.85 +	
    1.86 +	iRedrawWindow->BeginRedraw( aRect );
    1.87 +	
    1.88 +	iWsGc.Reset();
    1.89 +
    1.90 +	iWsGc.SetPenStyle( CGraphicsContext::ESolidPen );
    1.91 +	iWsGc.SetBrushStyle( CGraphicsContext::EDiamondCrossHatchBrush );
    1.92 +	iWsGc.SetBrushColor( iBgColor );
    1.93 +	iWsGc.SetPenColor( iBgColor );
    1.94 +	
    1.95 +	TRect drawRect( TPoint(0,0), iSize );
    1.96 +	
    1.97 +	iWsGc.DrawRect( drawRect );
    1.98 +	
    1.99 +	iRedrawWindow->EndRedraw();
   1.100 +	
   1.101 +	iWsGc.Deactivate();	
   1.102 +
   1.103 +	}
   1.104 +
   1.105 +void CAnimatedWin::AppendTime(TDes& aTimeText,const TTime& aTime) const
   1.106 +{
   1.107 +	_LIT(TimeFormat,"%:0%H%:1%T%:2%S");
   1.108 +	TRAPD(err,aTime.FormatL(aTimeText,TimeFormat));
   1.109 +	if (err!=KErrNone)
   1.110 +		{
   1.111 +		_LIT(DummyTime,"######");
   1.112 +		aTimeText.Append(DummyTime);
   1.113 +		}
   1.114 +}
   1.115 +
   1.116 +
   1.117 +void CAnimatedWin::DrawBitmap(CFbsBitGc* aGc, TRect& aClip, TPoint& aOrigin)
   1.118 +	{
   1.119 +	aGc->Reset();
   1.120 +	TPoint origin = iPos + aOrigin;
   1.121 +	aGc->SetOrigin(origin);
   1.122 +	TRect clip(origin, iSize);
   1.123 +	clip.Intersection(aClip);
   1.124 +	clip.Move(-origin);
   1.125 +	aGc->SetClippingRect(clip);
   1.126 +
   1.127 +	// draw win background
   1.128 +	aGc->SetPenStyle(CGraphicsContext::ESolidPen);
   1.129 +	aGc->SetBrushStyle(CGraphicsContext::EDiamondCrossHatchBrush);
   1.130 +	aGc->SetBrushColor( iBgColor );
   1.131 +	aGc->SetPenColor( iBgColor );
   1.132 +	aGc->DrawRect(TRect(TPoint(0,0), iSize));
   1.133 +	
   1.134 +	// draw text
   1.135 +	TBuf<128> timebuf;
   1.136 +	TUint64 elapsedMs = iAnimLastKnownAction * iKernelTicksPeriod;
   1.137 +	TTime restoredTime(elapsedMs);
   1.138 +	AppendTime( timebuf , restoredTime );
   1.139 +		
   1.140 +	TInt textWidth = iAnimFont->MeasureText( timebuf );
   1.141 +	TInt textHalf = textWidth / 2;
   1.142 +	
   1.143 +	TInt centerX = iSize.iWidth / 2;
   1.144 +	TInt centerY = iSize.iHeight / 2;
   1.145 +	
   1.146 +	TRect rect(centerX - textHalf, centerY - iAnimFont->AscentInPixels(),
   1.147 +			   centerX + textHalf, centerY - iAnimFont->AscentInPixels() + iAnimFont->HeightInPixels());
   1.148 +
   1.149 +	aGc->Reset();
   1.150 +
   1.151 +	origin = iPos + aOrigin;
   1.152 +	aGc->SetOrigin( origin );
   1.153 +	clip = TRect( origin, iSize );
   1.154 +	clip.Intersection( aClip );
   1.155 +	clip.Move(-origin);
   1.156 +	aGc->SetClippingRect(clip);
   1.157 +	
   1.158 +	aGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
   1.159 +	
   1.160 +	aGc->UseFont(iAnimFont);
   1.161 +	
   1.162 +	aGc->DrawText(timebuf, rect, iAnimFont->AscentInPixels());
   1.163 +
   1.164 +	rect.Move(0, iAnimFont->HeightInPixels());
   1.165 +	aGc->DrawText(timebuf, rect, iAnimFont->AscentInPixels());
   1.166 +
   1.167 +	// inherited
   1.168 +	CCompWin::DrawBitmap(aGc, aClip, aOrigin);	
   1.169 +	}
   1.170 +
   1.171 +void CAnimatedWin::SetSize(const TSize & aSize)
   1.172 +	{
   1.173 +	CCompWin::SetSize( aSize );
   1.174 +	if (iForeWin)
   1.175 +		{
   1.176 +		iForeWin->SetExtent(TPoint(iPos.iX-sInvisibleFrame, iPos.iY-sInvisibleFrame), 
   1.177 +				            TSize(iSize.iWidth+2*sInvisibleFrame, iSize.iHeight+2*sInvisibleFrame));
   1.178 +		}
   1.179 +	}
   1.180 +
   1.181 +void CAnimatedWin::SetPos(const TPoint & aPos)
   1.182 +	{
   1.183 +	CCompWin::SetPos( aPos );
   1.184 +	if (iForeWin)
   1.185 +		{
   1.186 +		iForeWin->SetPosition(TPoint(iPos.iX-sInvisibleFrame, iPos.iY-sInvisibleFrame));
   1.187 +		}
   1.188 +	}
   1.189 +
   1.190 +CAnimatedWin::CAnimatedWin(RWsSession& aWs, RWindowGroup* aGroup, CCompWin* aParent, CWindowGc& aGc):
   1.191 +	CCompWin( aWs, aGroup, aParent, aGc ), iAnimDll( aWs ), iForeWin(NULL)
   1.192 +	{
   1.193 +	iBgColor 	= TRnd::rnd(); 
   1.194 +	
   1.195 +	iFrameDuration = (TRnd::rnd( EFrameDurMaxTenthSec ) + 1) * EFrameDurMult;
   1.196 +
   1.197 +	HAL::Get( HAL::ENanoTickPeriod, iKernelTicksPeriod );	
   1.198 +	
   1.199 +	}
   1.200 +
   1.201 +void CAnimatedWin::ConstructL()
   1.202 +	{
   1.203 +	// prepare surface
   1.204 +	CCompWin::PreConstructL(iTransparent);
   1.205 +	
   1.206 +	TInt idx, err = KErrNone;
   1.207 +	TRect rect;
   1.208 +
   1.209 +	TPoint animPos( iSize.iWidth / 2 - EFrameSzXHalf, 
   1.210 +			iSize.iHeight / 2 - EFrameSzYHalf );
   1.211 +	
   1.212 +	// create anim frames & masks
   1.213 +	for ( idx = 0; idx < ENofFrames; idx++)
   1.214 +		{
   1.215 +		iAnimContent[idx]	= new (ELeave) CFbsBitmap();
   1.216 +
   1.217 +		err = iAnimContent[idx]->Create( TSize( EFrameSzX , EFrameSzY), EColor64K );
   1.218 +		User::LeaveIfError( err );
   1.219 +		
   1.220 +		iAnimCntDevice [idx] = CFbsBitmapDevice::NewL (iAnimContent[idx]);
   1.221 +		}
   1.222 +
   1.223 +	iAnimMask	= new (ELeave) CFbsBitmap();
   1.224 +
   1.225 +	err = iAnimMask->Create( TSize( EFrameSzX , EFrameSzY), EColor64K );
   1.226 +	User::LeaveIfError( err );
   1.227 +	
   1.228 +	iAnimMskDevice = CFbsBitmapDevice::NewL ( iAnimMask );
   1.229 +	
   1.230 +
   1.231 +	CGraphicsContext* gCtxAni = NULL;
   1.232 +	CGraphicsContext* gCtxMsk = NULL;
   1.233 +	// draw frame 1 and mask
   1.234 +	err = iAnimCntDevice [ EFrame1 ]->CreateContext( gCtxAni );
   1.235 +	User::LeaveIfError( err );
   1.236 +	CleanupStack::PushL( gCtxAni );
   1.237 +
   1.238 +	err = iAnimMskDevice->CreateContext( gCtxMsk );
   1.239 +	User::LeaveIfError( err );
   1.240 +	CleanupStack::PushL( gCtxMsk );
   1.241 +	
   1.242 +	
   1.243 +	gCtxAni->SetBrushColor(KRgbWhite);
   1.244 +	gCtxAni->SetPenColor(KRgbWhite);
   1.245 +	gCtxAni->SetBrushStyle( CGraphicsContext::ESolidBrush );
   1.246 +
   1.247 +	gCtxMsk->SetBrushColor(KRgbWhite);
   1.248 +	gCtxMsk->SetPenColor(KRgbWhite);
   1.249 +	gCtxMsk->SetBrushStyle( CGraphicsContext::ESolidBrush );
   1.250 +	
   1.251 +	rect.SetRect( EFrameSzXHalf - EFrameSzXEgt, 0, EFrameSzXHalf + EFrameSzXEgt, EFrameSzYHalf ); //lint !e656 Arithmetic operation uses (compatible) enum's 
   1.252 +	gCtxAni->DrawRect( rect );
   1.253 +	gCtxMsk->DrawRect( rect );
   1.254 +
   1.255 +	rect.SetRect( EFrameSzXHalf - EFrameSzXQtr, EFrameSzYHalf, EFrameSzXHalf + EFrameSzXQtr, EFrameSzY ); //lint !e656 Arithmetic operation uses (compatible) enum's
   1.256 +	gCtxAni->DrawRect( rect );
   1.257 +	gCtxMsk->DrawRect( rect );
   1.258 +
   1.259 +	gCtxAni->SetPenColor(KRgbBlack);
   1.260 +	gCtxAni->DrawLine( TPoint(EFrameSzXHalf,0), TPoint (EFrameSzXHalf,EFrameSzY) );
   1.261 +	
   1.262 +	
   1.263 +	CleanupStack::PopAndDestroy( gCtxMsk ); 
   1.264 +	CleanupStack::PopAndDestroy( gCtxAni ); 
   1.265 +
   1.266 +	// draw frame 2
   1.267 +	err = iAnimCntDevice [ EFrame2 ]->CreateContext( gCtxAni );
   1.268 +	User::LeaveIfError( err );
   1.269 +	CleanupStack::PushL( gCtxAni );
   1.270 +
   1.271 +	gCtxAni->SetPenColor(KRgbWhite);
   1.272 +	gCtxAni->DrawLine( TPoint(EFrameSzXHalf,0), TPoint (EFrameSzXHalf,EFrameSzY) );
   1.273 +
   1.274 +	CleanupStack::PopAndDestroy( gCtxAni ); 
   1.275 +	
   1.276 +	// init font
   1.277 +	err	= iAnimMskDevice->GetNearestFontInPixels( iAnimFont, TFontSpec( _L("Roman"), 16 ) );
   1.278 +	User::LeaveIfError( err );
   1.279 +
   1.280 +	// load anim DLL
   1.281 +	err = iAnimDll.Load( KAnimDllName );
   1.282 +	User::LeaveIfError( err );
   1.283 +	
   1.284 +	// construct server side anim
   1.285 +	TPckgBuf<TStressTestAnimParams> animParams;
   1.286 +	animParams().pos 		= animPos;
   1.287 +	animParams().interval = iFrameDuration.Int();
   1.288 +	animParams().bit1		= iAnimContent[ EFrame1 ]->Handle();
   1.289 +	animParams().bit2		= iAnimContent[ EFrame2 ]->Handle();
   1.290 +	animParams().mask		= iAnimMask->Handle();
   1.291 +	animParams().font		= iAnimFont->Handle();
   1.292 +
   1.293 +	iAnim = new (ELeave) CAnimatedWin::RStressAnim ( iAnimDll );
   1.294 +	
   1.295 +	err = iAnim->Construct( *iWindow, animParams );
   1.296 +	User::LeaveIfError( err );
   1.297 +
   1.298 +	// finally
   1.299 +	CCompWin::PostConstructL();	
   1.300 +
   1.301 +	// got time shot when we started
   1.302 +	iAnimStartup = User::NTickCount();
   1.303 +
   1.304 +	//Create a transparent foreground window, moving and resizing with the animation window
   1.305 +	if (iTransparentForegroundWindow)
   1.306 +		{
   1.307 +		iForeWin = new(ELeave) RBlankWindow(iWs);
   1.308 +		iForeWin->Construct(*iGroup,reinterpret_cast<TUint32>(iForeWin));
   1.309 +		iForeWin->SetColor(TRgb(0, 0, 0, 0));	//a transparent window
   1.310 +		iForeWin->SetExtent(TPoint(iPos.iX-sInvisibleFrame, iPos.iY-sInvisibleFrame), 
   1.311 +				            TSize(iSize.iWidth+2*sInvisibleFrame, iSize.iHeight+2*sInvisibleFrame));
   1.312 +		iForeWin->SetOrdinalPosition(0);
   1.313 +		iForeWin->Activate();
   1.314 +		}
   1.315 +	
   1.316 +	iConstructed = ETrue;
   1.317 +	}
   1.318 +
   1.319 +void CAnimatedWin::SetAnimPos(const TPoint& aPos)
   1.320 +	{
   1.321 +	TPckgBuf<TStressTestAnimParams> animParams;
   1.322 +	animParams().pos = aPos;
   1.323 +	iAnim->RequestAnimThis( EADllTextPos, animParams );
   1.324 +	}
   1.325 +
   1.326 +TBool CAnimatedWin::QueryReadyForVerification()
   1.327 +	{
   1.328 +
   1.329 +	TBool res;
   1.330 +	
   1.331 +	TInt32 curTicks = User::NTickCount();
   1.332 +
   1.333 +	iAnimLastKnownAction = (TUint32) iAnim->RequestAnimThis( EADllQuerySync ); 
   1.334 +	
   1.335 +	TUint64 elapsed = TTickUtils::CalcTickDelta( curTicks, iAnimLastKnownAction );
   1.336 +
   1.337 +	TUint64 elapsedMs = elapsed * iKernelTicksPeriod;
   1.338 +	
   1.339 +	res = ( elapsedMs < EWatchMatchGap );
   1.340 +	
   1.341 +	res = res && CCompWin::QueryReadyForVerification();
   1.342 +		
   1.343 +	return res;
   1.344 +	}
   1.345 +
   1.346 +CAnimatedWin::RStressAnim::RStressAnim (RAnimDll& aAnimDll):
   1.347 +	RAnim( aAnimDll )
   1.348 +	{ } // empty
   1.349 +
   1.350 +TInt CAnimatedWin::RStressAnim::Construct(const RWindowBase &aDevice, const TDesC8 &aParams)
   1.351 +	{
   1.352 +	return RAnim::Construct( aDevice, 0, aParams );
   1.353 +	}
   1.354 +
   1.355 +TInt CAnimatedWin::RStressAnim::RequestAnimThis(TInt aOpcode)
   1.356 +	{
   1.357 +	TInt res;
   1.358 +	
   1.359 +	TPckgC<TBool> params(ETrue);
   1.360 +	
   1.361 +	res = RequestAnimThis( aOpcode, params );
   1.362 +	
   1.363 +	return res;
   1.364 +	}
   1.365 +
   1.366 +TInt CAnimatedWin::RStressAnim::RequestAnimThis(TInt aOpcode, const TDesC8 &aParams)
   1.367 +	{
   1.368 +	TInt res;
   1.369 +	
   1.370 +	res = CommandReply( aOpcode, aParams );
   1.371 +	
   1.372 +	return res;	
   1.373 +	}
   1.374 +
   1.375 +void CAnimatedWin::DumpDetails(RFile& aFile, TInt aDepth)
   1.376 +	{
   1.377 +	TBuf8<256> buf;
   1.378 +	buf.SetLength(0);
   1.379 +	for (TInt d = 0; d < aDepth; ++d)
   1.380 +		{
   1.381 +		buf.Append(_L8("  "));
   1.382 +		}
   1.383 +	buf.Append(_L8("Transparent = ["));
   1.384 +	buf.AppendNum((TInt64)iTransparent);
   1.385 +	buf.Append(_L8("] transparent_foreground_window = ["));
   1.386 +	buf.AppendNum((TInt64)iTransparentForegroundWindow);
   1.387 +	buf.Append(_L8("] BgColor = ["));
   1.388 +	buf.AppendNum(iBgColor.Value());
   1.389 +	buf.Append(_L8("]\r\n"));
   1.390 +	aFile.Write(buf);
   1.391 +	}