os/graphics/windowing/windowserver/test/t_stress/tstressanim/src/stressanim.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/tstressanim/src/stressanim.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,316 @@
     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 "stressanim.h"
    1.26 +#include "stressanimcmd.h"
    1.27 +#include "panic.h"
    1.28 +#include <hal.h>
    1.29 +
    1.30 +EXPORT_C CAnimDll *CreateCAnimDllL() //lint -e714 Suppress 'not referenced' 
    1.31 +
    1.32 +	{
    1.33 +	return new (ELeave) CStressAnimDll();
    1.34 +	}
    1.35 +
    1.36 +CAnim *CStressAnimDll::CreateInstanceL(TInt /*aType*/)
    1.37 +	{
    1.38 +	return new (ELeave) CStressWindowAnim();
    1.39 +	}
    1.40 +
    1.41 +void CStressWindowAnim::Animate(TDateTime *)
    1.42 +	{
    1.43 +	if (!iDoAnimation)
    1.44 +		{
    1.45 +		return;
    1.46 +		}
    1.47 +	iLastAnimShot = User::NTickCount();
    1.48 +	if (!iWindowFunctions->IsHidden())
    1.49 +		{
    1.50 +		iWindowFunctions->ActivateGc();
    1.51 +		if (iPolyList)
    1.52 +			{
    1.53 +			DrawPolyLine();
    1.54 +			}
    1.55 +		}
    1.56 +	if (iPolyList)	
    1.57 +		{
    1.58 +		iPolyState=(iPolyState+1)%4;
    1.59 +		TweakPolyList(iPolyState);
    1.60 +		}
    1.61 +	if (!iWindowFunctions->IsHidden())
    1.62 +		{
    1.63 +		if (iPolyList)
    1.64 +			{
    1.65 +			DrawPolyLine();
    1.66 +			}
    1.67 +		DrawText();
    1.68 +		}
    1.69 +	iColor=(iColor+16)&0xFF;
    1.70 +	iDoAnimation = EFalse;
    1.71 +	}
    1.72 +
    1.73 +void CStressWindowAnim::DrawPolyLine()
    1.74 +	{
    1.75 +	iGc->SetDrawMode(CGraphicsContext::EDrawModeXOR);
    1.76 +	iGc->SetPenColor(TRgb(255,255,255));
    1.77 +	iGc->DrawPolyLine(static_cast<CArrayFix<TPoint>*>(iPolyList));
    1.78 +	iGc->SetDrawMode(CGraphicsContext::EDrawModePEN);
    1.79 +	iGc->SetPenColor(TRgb(0,0,0));
    1.80 +	}
    1.81 +
    1.82 +void CStressWindowAnim::DrawBitmap()
    1.83 +	{
    1.84 +	iGc->SetClippingRegion(TRegionFix<1>(TRect(iPos,iSize)));
    1.85 +	CFbsBitmap *bitmap=iFunctions->FlashStateOn() ? &iBitmap1 : &iBitmap2;
    1.86 +	if (iMasked)
    1.87 +		{
    1.88 +		iGc->BitBltMasked(iPos,bitmap, TRect(iSize), &iMask,EFalse);
    1.89 +		}
    1.90 +	else
    1.91 +		{
    1.92 +		iGc->BitBlt(iPos,bitmap);
    1.93 +		}
    1.94 +	iGc->CancelClippingRegion();
    1.95 +	}
    1.96 +
    1.97 +void CStressWindowAnim::AppendTime(TDes& aTimeText,const TTime& aTime) const
    1.98 +	{
    1.99 +	_LIT(TimeFormat,"%:0%H%:1%T%:2%S");
   1.100 +	TRAPD(err,aTime.FormatL(aTimeText,TimeFormat));
   1.101 +	if (err!=KErrNone)
   1.102 +		{
   1.103 +		_LIT(DummyTime,"######");
   1.104 +		aTimeText.Append(DummyTime);
   1.105 +		}
   1.106 +	}
   1.107 +
   1.108 +void CStressWindowAnim::DrawText()
   1.109 +	{
   1.110 +	if (iHasFocus)
   1.111 +		{
   1.112 +		iGc->UseFont(iFont);
   1.113 +		TBuf<0x20> timebuf;
   1.114 +		TUint64 elapsedMs = iLastAnimShot * iKernelTicksPeriod;
   1.115 +		TTime time(elapsedMs);
   1.116 +
   1.117 +		AppendTime( timebuf , time );
   1.118 +		
   1.119 +		TSize winSize = iWindowFunctions->WindowSize();
   1.120 +		
   1.121 +		TInt textWidth = iFont->MeasureText( timebuf );
   1.122 +		
   1.123 +		TInt textHalf = textWidth / 2;
   1.124 +		
   1.125 +		TInt centerX = winSize.iWidth / 2;
   1.126 +		TInt centerY = winSize.iHeight / 2;
   1.127 +		
   1.128 +		TRect rect(centerX - textHalf, centerY - iFont->AscentInPixels(),
   1.129 +				   centerX + textHalf, centerY - iFont->AscentInPixels() + iFont->HeightInPixels());
   1.130 +
   1.131 +		
   1.132 +		iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
   1.133 +		iGc->DrawText(timebuf,rect,iFont->AscentInPixels());
   1.134 +		rect.Move(0,iFont->HeightInPixels());
   1.135 +		iGc->DrawText(timebuf,rect,iFont->AscentInPixels());
   1.136 +		}
   1.137 +	}
   1.138 +
   1.139 +void CStressWindowAnim::Redraw()
   1.140 +	{
   1.141 +	DrawText();
   1.142 +	if (iPolyList)
   1.143 +		{
   1.144 +		DrawPolyLine();
   1.145 +		}
   1.146 +	}
   1.147 +
   1.148 +void CStressWindowAnim::ConstructL(TAny *aArgs, TBool aHasFocus)
   1.149 +	{
   1.150 +	iHasFocus=aHasFocus;
   1.151 +	iPos=((TStressTestAnimParams *)aArgs)->pos;
   1.152 +	iFunctions->SetInterval(((TStressTestAnimParams *)aArgs)->interval);
   1.153 +	if (iBitmap1.Duplicate(((TStressTestAnimParams *)aArgs)->bit1)!=KErrNone || 
   1.154 +		iBitmap2.Duplicate(((TStressTestAnimParams *)aArgs)->bit2)!=KErrNone ||
   1.155 +		iMask.Duplicate(((TStressTestAnimParams *)aArgs)->mask)!=KErrNone)
   1.156 +		{
   1.157 +		iFunctions->Panic();
   1.158 +		}
   1.159 +	iSize.iWidth=Min(iBitmap1.SizeInPixels().iWidth,iBitmap2.SizeInPixels().iWidth);
   1.160 +	iSize.iHeight=Min(iBitmap1.SizeInPixels().iHeight,iBitmap2.SizeInPixels().iHeight);
   1.161 +	iWiggleSize=10;
   1.162 +	iFont=iFunctions->DuplicateFontL(((TStressTestAnimParams *)aArgs)->font);
   1.163 +	iDoAnimation = ETrue;
   1.164 +	HAL::Get( HAL::ENanoTickPeriod, iKernelTicksPeriod );	
   1.165 +	iFunctions->SetSync( MAnimGeneralFunctions::ESyncSecond );
   1.166 +	}
   1.167 +
   1.168 +void CStressWindowAnim::SetPolyList(const TRect &aRect)
   1.169 +	{
   1.170 +	iPolyRect=aRect;
   1.171 +	TSize halfsize=aRect.Size();
   1.172 +	__ASSERT_ALWAYS(halfsize.iWidth >= 0, Panic(EPanic10));
   1.173 +	__ASSERT_ALWAYS(halfsize.iHeight >= 0, Panic(EPanic11));
   1.174 +	halfsize.iWidth>>=1;	//lint !e702 Shift right of signed quantity (int)
   1.175 +	halfsize.iHeight>>=1;	//lint !e702 Shift right of signed quantity (int)
   1.176 +	(*iPolyList)[0]=aRect.iTl;
   1.177 +	(*iPolyList)[1]=TPoint(aRect.iTl.iX+iWiggleSize,aRect.iTl.iY+halfsize.iHeight);
   1.178 +	(*iPolyList)[2]=TPoint(aRect.iTl.iX,aRect.iBr.iY);
   1.179 +	(*iPolyList)[3]=TPoint(aRect.iTl.iX+halfsize.iWidth,aRect.iBr.iY-iWiggleSize);
   1.180 +	(*iPolyList)[4]=aRect.iBr;
   1.181 +	(*iPolyList)[5]=TPoint(aRect.iBr.iX-iWiggleSize,aRect.iTl.iY+halfsize.iHeight);
   1.182 +	(*iPolyList)[6]=TPoint(aRect.iBr.iX,aRect.iTl.iY);
   1.183 +	(*iPolyList)[7]=TPoint(aRect.iTl.iX+halfsize.iWidth,aRect.iTl.iY+iWiggleSize);
   1.184 +	(*iPolyList)[8]=aRect.iTl;
   1.185 +	TweakPolyList(iPolyState);
   1.186 +	}
   1.187 +
   1.188 +void CStressWindowAnim::TweakPolyList(TInt aState)
   1.189 +	{
   1.190 +	TSize halfsize=iPolyRect.Size();
   1.191 +	__ASSERT_ALWAYS(halfsize.iWidth >= 0, Panic(EPanic12));
   1.192 +	__ASSERT_ALWAYS(halfsize.iHeight >= 0, Panic(EPanic13));
   1.193 +	halfsize.iWidth>>=1;	//lint !e702 Shift right of signed quantity (int)
   1.194 +	halfsize.iHeight>>=1;	//lint !e702 Shift right of signed quantity (int)
   1.195 +	switch(aState)
   1.196 +		{
   1.197 +		case 0:
   1.198 +			(*iPolyList)[7]=TPoint(iPolyRect.iTl.iX+halfsize.iWidth,iPolyRect.iTl.iY+iWiggleSize);
   1.199 +			(*iPolyList)[1]=TPoint(iPolyRect.iTl.iX,iPolyRect.iTl.iY+halfsize.iHeight);
   1.200 +			break;
   1.201 +		case 1:
   1.202 +			(*iPolyList)[1]=TPoint(iPolyRect.iTl.iX+iWiggleSize,iPolyRect.iTl.iY+halfsize.iHeight);
   1.203 +			(*iPolyList)[3]=TPoint(iPolyRect.iTl.iX+halfsize.iWidth,iPolyRect.iBr.iY);
   1.204 +			break;
   1.205 +		case 2:
   1.206 +			(*iPolyList)[3]=TPoint(iPolyRect.iTl.iX+halfsize.iWidth,iPolyRect.iBr.iY-iWiggleSize);
   1.207 +			(*iPolyList)[5]=TPoint(iPolyRect.iBr.iX,iPolyRect.iTl.iY+halfsize.iHeight);
   1.208 +			break;
   1.209 +		case 3:
   1.210 +			(*iPolyList)[5]=TPoint(iPolyRect.iBr.iX-iWiggleSize,iPolyRect.iTl.iY+halfsize.iHeight);
   1.211 +			(*iPolyList)[7]=TPoint(iPolyRect.iTl.iX+halfsize.iWidth,iPolyRect.iTl.iY);
   1.212 +			break;
   1.213 +		default:
   1.214 +			__ASSERT_ALWAYS(EFalse, Panic(EPanic14));
   1.215 +			break;
   1.216 +		}
   1.217 +	}
   1.218 +
   1.219 +void CStressWindowAnim::InvalidateText()
   1.220 +	{
   1.221 +	TRect invalidate;
   1.222 +	invalidate.iTl.iX=iTextPos.iX;
   1.223 +	invalidate.iTl.iY=iTextPos.iY-iFont->AscentInPixels();
   1.224 +	invalidate.iBr.iX=iTextPos.iX+iFont->TextWidthInPixels(_L("Overstressed ANIM"));
   1.225 +	invalidate.iBr.iY=iTextPos.iY+iFont->DescentInPixels();
   1.226 +	iWindowFunctions->Invalidate(invalidate);
   1.227 +	}
   1.228 +
   1.229 +void CStressWindowAnim::InvalidateBitmap()
   1.230 +	{
   1.231 +	iWindowFunctions->Invalidate(TRect(iPos,iSize));
   1.232 +	}
   1.233 +
   1.234 +void CStressWindowAnim::Command(TInt aOpcode, TAny *aArgs)
   1.235 +	{
   1.236 +	switch(aOpcode)
   1.237 +		{
   1.238 +		case EADllOpcodeMove:
   1.239 +			{
   1.240 +			InvalidateBitmap();
   1.241 +			iPos=((TStressTestAnimParams *)aArgs)->pos;
   1.242 +			iWindowFunctions->ActivateGc();
   1.243 +			DrawBitmap();
   1.244 +			iFunctions->SetInterval(((TStressTestAnimParams *)aArgs)->interval);
   1.245 +			}
   1.246 +			break;
   1.247 +		case EADllTextPos:
   1.248 +			{
   1.249 +			InvalidateText();
   1.250 +			iTextPos=((TStressTestAnimParams *)aArgs)->pos;
   1.251 +			iWindowFunctions->ActivateGc();
   1.252 +			DrawText();
   1.253 +			}
   1.254 +			break;
   1.255 +		case EADllToggleBitmapMask:
   1.256 +			iMasked=!iMasked;
   1.257 +			InvalidateBitmap();
   1.258 +			break;
   1.259 +		default:
   1.260 +			__ASSERT_ALWAYS(EFalse, Panic(EPanic15));
   1.261 +			break;
   1.262 +		}
   1.263 +	}
   1.264 +
   1.265 +TInt CStressWindowAnim::CommandReplyL(TInt aOpcode, TAny *aArgs)
   1.266 +	{
   1.267 +	
   1.268 +	TInt res = KErrNone;
   1.269 +	
   1.270 +	switch(aOpcode)
   1.271 +		{
   1.272 +		case EADllOpcodePolyLineRect:
   1.273 +			iWindowFunctions->ActivateGc();
   1.274 +			if (!iPolyList)
   1.275 +				{
   1.276 +				iPolyList=new(ELeave) CArrayFixFlat<TPoint>(ENumPolyPoints);
   1.277 +				TPoint zeropoint;
   1.278 +				for(TInt i=0;i<ENumPolyPoints;i++)
   1.279 +					{
   1.280 +					iPolyList->AppendL(zeropoint);
   1.281 +					}
   1.282 +				}
   1.283 +			else
   1.284 +				{
   1.285 +				DrawPolyLine();
   1.286 +				}
   1.287 +			SetPolyList(*((TRect *)aArgs));
   1.288 +			DrawPolyLine();
   1.289 +			break;
   1.290 +			
   1.291 +		case EADllQuerySync:
   1.292 +			res = iLastAnimShot;
   1.293 +			iDoAnimation = ETrue;
   1.294 +			break;
   1.295 +			
   1.296 +		default:
   1.297 +			iFunctions->Panic();
   1.298 +		}
   1.299 +	
   1.300 +	return res;
   1.301 +	}
   1.302 +
   1.303 +CStressWindowAnim::~CStressWindowAnim()
   1.304 +	{
   1.305 +	delete iPolyList;
   1.306 +	iFunctions->CloseFont(iFont);
   1.307 +	}
   1.308 +
   1.309 +void CStressWindowAnim::FocusChanged(TBool aNewState)
   1.310 +	{
   1.311 +	iHasFocus=aNewState;
   1.312 +	InvalidateText();
   1.313 +	InvalidateBitmap();
   1.314 +	}
   1.315 +
   1.316 +TBool CStressWindowAnim::OfferRawEvent(const TRawEvent &/*aRawEvent*/)
   1.317 +	{
   1.318 +	return EFalse;
   1.319 +	}