os/graphics/windowing/windowserver/test/t_stress/tstressanim/src/stressanim.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
/**
sl@0
    17
 @file
sl@0
    18
 @test
sl@0
    19
 @internalComponent
sl@0
    20
*/
sl@0
    21
sl@0
    22
#include "stressanim.h"
sl@0
    23
#include "stressanimcmd.h"
sl@0
    24
#include "panic.h"
sl@0
    25
#include <hal.h>
sl@0
    26
sl@0
    27
EXPORT_C CAnimDll *CreateCAnimDllL() //lint -e714 Suppress 'not referenced' 
sl@0
    28
sl@0
    29
	{
sl@0
    30
	return new (ELeave) CStressAnimDll();
sl@0
    31
	}
sl@0
    32
sl@0
    33
CAnim *CStressAnimDll::CreateInstanceL(TInt /*aType*/)
sl@0
    34
	{
sl@0
    35
	return new (ELeave) CStressWindowAnim();
sl@0
    36
	}
sl@0
    37
sl@0
    38
void CStressWindowAnim::Animate(TDateTime *)
sl@0
    39
	{
sl@0
    40
	if (!iDoAnimation)
sl@0
    41
		{
sl@0
    42
		return;
sl@0
    43
		}
sl@0
    44
	iLastAnimShot = User::NTickCount();
sl@0
    45
	if (!iWindowFunctions->IsHidden())
sl@0
    46
		{
sl@0
    47
		iWindowFunctions->ActivateGc();
sl@0
    48
		if (iPolyList)
sl@0
    49
			{
sl@0
    50
			DrawPolyLine();
sl@0
    51
			}
sl@0
    52
		}
sl@0
    53
	if (iPolyList)	
sl@0
    54
		{
sl@0
    55
		iPolyState=(iPolyState+1)%4;
sl@0
    56
		TweakPolyList(iPolyState);
sl@0
    57
		}
sl@0
    58
	if (!iWindowFunctions->IsHidden())
sl@0
    59
		{
sl@0
    60
		if (iPolyList)
sl@0
    61
			{
sl@0
    62
			DrawPolyLine();
sl@0
    63
			}
sl@0
    64
		DrawText();
sl@0
    65
		}
sl@0
    66
	iColor=(iColor+16)&0xFF;
sl@0
    67
	iDoAnimation = EFalse;
sl@0
    68
	}
sl@0
    69
sl@0
    70
void CStressWindowAnim::DrawPolyLine()
sl@0
    71
	{
sl@0
    72
	iGc->SetDrawMode(CGraphicsContext::EDrawModeXOR);
sl@0
    73
	iGc->SetPenColor(TRgb(255,255,255));
sl@0
    74
	iGc->DrawPolyLine(static_cast<CArrayFix<TPoint>*>(iPolyList));
sl@0
    75
	iGc->SetDrawMode(CGraphicsContext::EDrawModePEN);
sl@0
    76
	iGc->SetPenColor(TRgb(0,0,0));
sl@0
    77
	}
sl@0
    78
sl@0
    79
void CStressWindowAnim::DrawBitmap()
sl@0
    80
	{
sl@0
    81
	iGc->SetClippingRegion(TRegionFix<1>(TRect(iPos,iSize)));
sl@0
    82
	CFbsBitmap *bitmap=iFunctions->FlashStateOn() ? &iBitmap1 : &iBitmap2;
sl@0
    83
	if (iMasked)
sl@0
    84
		{
sl@0
    85
		iGc->BitBltMasked(iPos,bitmap, TRect(iSize), &iMask,EFalse);
sl@0
    86
		}
sl@0
    87
	else
sl@0
    88
		{
sl@0
    89
		iGc->BitBlt(iPos,bitmap);
sl@0
    90
		}
sl@0
    91
	iGc->CancelClippingRegion();
sl@0
    92
	}
sl@0
    93
sl@0
    94
void CStressWindowAnim::AppendTime(TDes& aTimeText,const TTime& aTime) const
sl@0
    95
	{
sl@0
    96
	_LIT(TimeFormat,"%:0%H%:1%T%:2%S");
sl@0
    97
	TRAPD(err,aTime.FormatL(aTimeText,TimeFormat));
sl@0
    98
	if (err!=KErrNone)
sl@0
    99
		{
sl@0
   100
		_LIT(DummyTime,"######");
sl@0
   101
		aTimeText.Append(DummyTime);
sl@0
   102
		}
sl@0
   103
	}
sl@0
   104
sl@0
   105
void CStressWindowAnim::DrawText()
sl@0
   106
	{
sl@0
   107
	if (iHasFocus)
sl@0
   108
		{
sl@0
   109
		iGc->UseFont(iFont);
sl@0
   110
		TBuf<0x20> timebuf;
sl@0
   111
		TUint64 elapsedMs = iLastAnimShot * iKernelTicksPeriod;
sl@0
   112
		TTime time(elapsedMs);
sl@0
   113
sl@0
   114
		AppendTime( timebuf , time );
sl@0
   115
		
sl@0
   116
		TSize winSize = iWindowFunctions->WindowSize();
sl@0
   117
		
sl@0
   118
		TInt textWidth = iFont->MeasureText( timebuf );
sl@0
   119
		
sl@0
   120
		TInt textHalf = textWidth / 2;
sl@0
   121
		
sl@0
   122
		TInt centerX = winSize.iWidth / 2;
sl@0
   123
		TInt centerY = winSize.iHeight / 2;
sl@0
   124
		
sl@0
   125
		TRect rect(centerX - textHalf, centerY - iFont->AscentInPixels(),
sl@0
   126
				   centerX + textHalf, centerY - iFont->AscentInPixels() + iFont->HeightInPixels());
sl@0
   127
sl@0
   128
		
sl@0
   129
		iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
sl@0
   130
		iGc->DrawText(timebuf,rect,iFont->AscentInPixels());
sl@0
   131
		rect.Move(0,iFont->HeightInPixels());
sl@0
   132
		iGc->DrawText(timebuf,rect,iFont->AscentInPixels());
sl@0
   133
		}
sl@0
   134
	}
sl@0
   135
sl@0
   136
void CStressWindowAnim::Redraw()
sl@0
   137
	{
sl@0
   138
	DrawText();
sl@0
   139
	if (iPolyList)
sl@0
   140
		{
sl@0
   141
		DrawPolyLine();
sl@0
   142
		}
sl@0
   143
	}
sl@0
   144
sl@0
   145
void CStressWindowAnim::ConstructL(TAny *aArgs, TBool aHasFocus)
sl@0
   146
	{
sl@0
   147
	iHasFocus=aHasFocus;
sl@0
   148
	iPos=((TStressTestAnimParams *)aArgs)->pos;
sl@0
   149
	iFunctions->SetInterval(((TStressTestAnimParams *)aArgs)->interval);
sl@0
   150
	if (iBitmap1.Duplicate(((TStressTestAnimParams *)aArgs)->bit1)!=KErrNone || 
sl@0
   151
		iBitmap2.Duplicate(((TStressTestAnimParams *)aArgs)->bit2)!=KErrNone ||
sl@0
   152
		iMask.Duplicate(((TStressTestAnimParams *)aArgs)->mask)!=KErrNone)
sl@0
   153
		{
sl@0
   154
		iFunctions->Panic();
sl@0
   155
		}
sl@0
   156
	iSize.iWidth=Min(iBitmap1.SizeInPixels().iWidth,iBitmap2.SizeInPixels().iWidth);
sl@0
   157
	iSize.iHeight=Min(iBitmap1.SizeInPixels().iHeight,iBitmap2.SizeInPixels().iHeight);
sl@0
   158
	iWiggleSize=10;
sl@0
   159
	iFont=iFunctions->DuplicateFontL(((TStressTestAnimParams *)aArgs)->font);
sl@0
   160
	iDoAnimation = ETrue;
sl@0
   161
	HAL::Get( HAL::ENanoTickPeriod, iKernelTicksPeriod );	
sl@0
   162
	iFunctions->SetSync( MAnimGeneralFunctions::ESyncSecond );
sl@0
   163
	}
sl@0
   164
sl@0
   165
void CStressWindowAnim::SetPolyList(const TRect &aRect)
sl@0
   166
	{
sl@0
   167
	iPolyRect=aRect;
sl@0
   168
	TSize halfsize=aRect.Size();
sl@0
   169
	__ASSERT_ALWAYS(halfsize.iWidth >= 0, Panic(EPanic10));
sl@0
   170
	__ASSERT_ALWAYS(halfsize.iHeight >= 0, Panic(EPanic11));
sl@0
   171
	halfsize.iWidth>>=1;	//lint !e702 Shift right of signed quantity (int)
sl@0
   172
	halfsize.iHeight>>=1;	//lint !e702 Shift right of signed quantity (int)
sl@0
   173
	(*iPolyList)[0]=aRect.iTl;
sl@0
   174
	(*iPolyList)[1]=TPoint(aRect.iTl.iX+iWiggleSize,aRect.iTl.iY+halfsize.iHeight);
sl@0
   175
	(*iPolyList)[2]=TPoint(aRect.iTl.iX,aRect.iBr.iY);
sl@0
   176
	(*iPolyList)[3]=TPoint(aRect.iTl.iX+halfsize.iWidth,aRect.iBr.iY-iWiggleSize);
sl@0
   177
	(*iPolyList)[4]=aRect.iBr;
sl@0
   178
	(*iPolyList)[5]=TPoint(aRect.iBr.iX-iWiggleSize,aRect.iTl.iY+halfsize.iHeight);
sl@0
   179
	(*iPolyList)[6]=TPoint(aRect.iBr.iX,aRect.iTl.iY);
sl@0
   180
	(*iPolyList)[7]=TPoint(aRect.iTl.iX+halfsize.iWidth,aRect.iTl.iY+iWiggleSize);
sl@0
   181
	(*iPolyList)[8]=aRect.iTl;
sl@0
   182
	TweakPolyList(iPolyState);
sl@0
   183
	}
sl@0
   184
sl@0
   185
void CStressWindowAnim::TweakPolyList(TInt aState)
sl@0
   186
	{
sl@0
   187
	TSize halfsize=iPolyRect.Size();
sl@0
   188
	__ASSERT_ALWAYS(halfsize.iWidth >= 0, Panic(EPanic12));
sl@0
   189
	__ASSERT_ALWAYS(halfsize.iHeight >= 0, Panic(EPanic13));
sl@0
   190
	halfsize.iWidth>>=1;	//lint !e702 Shift right of signed quantity (int)
sl@0
   191
	halfsize.iHeight>>=1;	//lint !e702 Shift right of signed quantity (int)
sl@0
   192
	switch(aState)
sl@0
   193
		{
sl@0
   194
		case 0:
sl@0
   195
			(*iPolyList)[7]=TPoint(iPolyRect.iTl.iX+halfsize.iWidth,iPolyRect.iTl.iY+iWiggleSize);
sl@0
   196
			(*iPolyList)[1]=TPoint(iPolyRect.iTl.iX,iPolyRect.iTl.iY+halfsize.iHeight);
sl@0
   197
			break;
sl@0
   198
		case 1:
sl@0
   199
			(*iPolyList)[1]=TPoint(iPolyRect.iTl.iX+iWiggleSize,iPolyRect.iTl.iY+halfsize.iHeight);
sl@0
   200
			(*iPolyList)[3]=TPoint(iPolyRect.iTl.iX+halfsize.iWidth,iPolyRect.iBr.iY);
sl@0
   201
			break;
sl@0
   202
		case 2:
sl@0
   203
			(*iPolyList)[3]=TPoint(iPolyRect.iTl.iX+halfsize.iWidth,iPolyRect.iBr.iY-iWiggleSize);
sl@0
   204
			(*iPolyList)[5]=TPoint(iPolyRect.iBr.iX,iPolyRect.iTl.iY+halfsize.iHeight);
sl@0
   205
			break;
sl@0
   206
		case 3:
sl@0
   207
			(*iPolyList)[5]=TPoint(iPolyRect.iBr.iX-iWiggleSize,iPolyRect.iTl.iY+halfsize.iHeight);
sl@0
   208
			(*iPolyList)[7]=TPoint(iPolyRect.iTl.iX+halfsize.iWidth,iPolyRect.iTl.iY);
sl@0
   209
			break;
sl@0
   210
		default:
sl@0
   211
			__ASSERT_ALWAYS(EFalse, Panic(EPanic14));
sl@0
   212
			break;
sl@0
   213
		}
sl@0
   214
	}
sl@0
   215
sl@0
   216
void CStressWindowAnim::InvalidateText()
sl@0
   217
	{
sl@0
   218
	TRect invalidate;
sl@0
   219
	invalidate.iTl.iX=iTextPos.iX;
sl@0
   220
	invalidate.iTl.iY=iTextPos.iY-iFont->AscentInPixels();
sl@0
   221
	invalidate.iBr.iX=iTextPos.iX+iFont->TextWidthInPixels(_L("Overstressed ANIM"));
sl@0
   222
	invalidate.iBr.iY=iTextPos.iY+iFont->DescentInPixels();
sl@0
   223
	iWindowFunctions->Invalidate(invalidate);
sl@0
   224
	}
sl@0
   225
sl@0
   226
void CStressWindowAnim::InvalidateBitmap()
sl@0
   227
	{
sl@0
   228
	iWindowFunctions->Invalidate(TRect(iPos,iSize));
sl@0
   229
	}
sl@0
   230
sl@0
   231
void CStressWindowAnim::Command(TInt aOpcode, TAny *aArgs)
sl@0
   232
	{
sl@0
   233
	switch(aOpcode)
sl@0
   234
		{
sl@0
   235
		case EADllOpcodeMove:
sl@0
   236
			{
sl@0
   237
			InvalidateBitmap();
sl@0
   238
			iPos=((TStressTestAnimParams *)aArgs)->pos;
sl@0
   239
			iWindowFunctions->ActivateGc();
sl@0
   240
			DrawBitmap();
sl@0
   241
			iFunctions->SetInterval(((TStressTestAnimParams *)aArgs)->interval);
sl@0
   242
			}
sl@0
   243
			break;
sl@0
   244
		case EADllTextPos:
sl@0
   245
			{
sl@0
   246
			InvalidateText();
sl@0
   247
			iTextPos=((TStressTestAnimParams *)aArgs)->pos;
sl@0
   248
			iWindowFunctions->ActivateGc();
sl@0
   249
			DrawText();
sl@0
   250
			}
sl@0
   251
			break;
sl@0
   252
		case EADllToggleBitmapMask:
sl@0
   253
			iMasked=!iMasked;
sl@0
   254
			InvalidateBitmap();
sl@0
   255
			break;
sl@0
   256
		default:
sl@0
   257
			__ASSERT_ALWAYS(EFalse, Panic(EPanic15));
sl@0
   258
			break;
sl@0
   259
		}
sl@0
   260
	}
sl@0
   261
sl@0
   262
TInt CStressWindowAnim::CommandReplyL(TInt aOpcode, TAny *aArgs)
sl@0
   263
	{
sl@0
   264
	
sl@0
   265
	TInt res = KErrNone;
sl@0
   266
	
sl@0
   267
	switch(aOpcode)
sl@0
   268
		{
sl@0
   269
		case EADllOpcodePolyLineRect:
sl@0
   270
			iWindowFunctions->ActivateGc();
sl@0
   271
			if (!iPolyList)
sl@0
   272
				{
sl@0
   273
				iPolyList=new(ELeave) CArrayFixFlat<TPoint>(ENumPolyPoints);
sl@0
   274
				TPoint zeropoint;
sl@0
   275
				for(TInt i=0;i<ENumPolyPoints;i++)
sl@0
   276
					{
sl@0
   277
					iPolyList->AppendL(zeropoint);
sl@0
   278
					}
sl@0
   279
				}
sl@0
   280
			else
sl@0
   281
				{
sl@0
   282
				DrawPolyLine();
sl@0
   283
				}
sl@0
   284
			SetPolyList(*((TRect *)aArgs));
sl@0
   285
			DrawPolyLine();
sl@0
   286
			break;
sl@0
   287
			
sl@0
   288
		case EADllQuerySync:
sl@0
   289
			res = iLastAnimShot;
sl@0
   290
			iDoAnimation = ETrue;
sl@0
   291
			break;
sl@0
   292
			
sl@0
   293
		default:
sl@0
   294
			iFunctions->Panic();
sl@0
   295
		}
sl@0
   296
	
sl@0
   297
	return res;
sl@0
   298
	}
sl@0
   299
sl@0
   300
CStressWindowAnim::~CStressWindowAnim()
sl@0
   301
	{
sl@0
   302
	delete iPolyList;
sl@0
   303
	iFunctions->CloseFont(iFont);
sl@0
   304
	}
sl@0
   305
sl@0
   306
void CStressWindowAnim::FocusChanged(TBool aNewState)
sl@0
   307
	{
sl@0
   308
	iHasFocus=aNewState;
sl@0
   309
	InvalidateText();
sl@0
   310
	InvalidateBitmap();
sl@0
   311
	}
sl@0
   312
sl@0
   313
TBool CStressWindowAnim::OfferRawEvent(const TRawEvent &/*aRawEvent*/)
sl@0
   314
	{
sl@0
   315
	return EFalse;
sl@0
   316
	}