os/graphics/windowing/windowserver/test/t_stress/src/animatedwin.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
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 "animatedwin.h"
sl@0
    23
#include "utils.h"
sl@0
    24
sl@0
    25
#include "stressanimcmd.h"
sl@0
    26
sl@0
    27
#include <hal.h>
sl@0
    28
sl@0
    29
sl@0
    30
//static configuration data, definitions and default assignments
sl@0
    31
TBool CAnimatedWin::iEnabled = ETrue;
sl@0
    32
TBool CAnimatedWin::iTransparent = ETrue;
sl@0
    33
TBool CAnimatedWin::iTransparentForegroundWindow = EFalse;
sl@0
    34
sl@0
    35
const TInt sInvisibleFrame = 24;	//how much bigger the invisible window is
sl@0
    36
sl@0
    37
CAnimatedWin* CAnimatedWin::NewLC(RWsSession& aWs, RWindowGroup* aGroup, CCompWin* aParent, CWindowGc& aGc)
sl@0
    38
	{
sl@0
    39
	CAnimatedWin* self = new (ELeave) CAnimatedWin( aWs, aGroup, aParent, aGc );
sl@0
    40
	CleanupStack::PushL( self );
sl@0
    41
	self->ConstructL();
sl@0
    42
	
sl@0
    43
	return self;
sl@0
    44
	}
sl@0
    45
sl@0
    46
void CAnimatedWin::LoadConfiguration(const MTestStepConfigurationContext* aContext)
sl@0
    47
	{
sl@0
    48
	aContext->GetBool(KT_WservStressParamEnabled, iEnabled);
sl@0
    49
	aContext->GetBool(KT_WservStressParamTransparent, iTransparent);
sl@0
    50
	aContext->GetBool(KT_WservStressParamTransparentForegroundWindow, iTransparentForegroundWindow);
sl@0
    51
	}
sl@0
    52
sl@0
    53
CAnimatedWin::~CAnimatedWin()
sl@0
    54
	{ 
sl@0
    55
	if (iForeWin)
sl@0
    56
		{
sl@0
    57
		iForeWin->Close();
sl@0
    58
		delete iForeWin;
sl@0
    59
		}
sl@0
    60
	
sl@0
    61
	if ( iAnim )
sl@0
    62
		{
sl@0
    63
		iAnim->Destroy();
sl@0
    64
		}
sl@0
    65
	iAnimDll.Close();
sl@0
    66
	
sl@0
    67
	TInt idx;
sl@0
    68
	for ( idx = 0; idx < ENofFrames; idx++)
sl@0
    69
		{
sl@0
    70
		delete iAnimCntDevice [idx];
sl@0
    71
		delete iAnimContent [idx]; 
sl@0
    72
		}
sl@0
    73
	
sl@0
    74
	delete iAnimMskDevice;
sl@0
    75
	delete iAnimMask;
sl@0
    76
	}
sl@0
    77
sl@0
    78
	
sl@0
    79
void CAnimatedWin::Redraw(const TRect& aRect)
sl@0
    80
	{
sl@0
    81
	iWsGc.Activate(*iWindow);
sl@0
    82
	
sl@0
    83
	iRedrawWindow->BeginRedraw( aRect );
sl@0
    84
	
sl@0
    85
	iWsGc.Reset();
sl@0
    86
sl@0
    87
	iWsGc.SetPenStyle( CGraphicsContext::ESolidPen );
sl@0
    88
	iWsGc.SetBrushStyle( CGraphicsContext::EDiamondCrossHatchBrush );
sl@0
    89
	iWsGc.SetBrushColor( iBgColor );
sl@0
    90
	iWsGc.SetPenColor( iBgColor );
sl@0
    91
	
sl@0
    92
	TRect drawRect( TPoint(0,0), iSize );
sl@0
    93
	
sl@0
    94
	iWsGc.DrawRect( drawRect );
sl@0
    95
	
sl@0
    96
	iRedrawWindow->EndRedraw();
sl@0
    97
	
sl@0
    98
	iWsGc.Deactivate();	
sl@0
    99
sl@0
   100
	}
sl@0
   101
sl@0
   102
void CAnimatedWin::AppendTime(TDes& aTimeText,const TTime& aTime) const
sl@0
   103
{
sl@0
   104
	_LIT(TimeFormat,"%:0%H%:1%T%:2%S");
sl@0
   105
	TRAPD(err,aTime.FormatL(aTimeText,TimeFormat));
sl@0
   106
	if (err!=KErrNone)
sl@0
   107
		{
sl@0
   108
		_LIT(DummyTime,"######");
sl@0
   109
		aTimeText.Append(DummyTime);
sl@0
   110
		}
sl@0
   111
}
sl@0
   112
sl@0
   113
sl@0
   114
void CAnimatedWin::DrawBitmap(CFbsBitGc* aGc, TRect& aClip, TPoint& aOrigin)
sl@0
   115
	{
sl@0
   116
	aGc->Reset();
sl@0
   117
	TPoint origin = iPos + aOrigin;
sl@0
   118
	aGc->SetOrigin(origin);
sl@0
   119
	TRect clip(origin, iSize);
sl@0
   120
	clip.Intersection(aClip);
sl@0
   121
	clip.Move(-origin);
sl@0
   122
	aGc->SetClippingRect(clip);
sl@0
   123
sl@0
   124
	// draw win background
sl@0
   125
	aGc->SetPenStyle(CGraphicsContext::ESolidPen);
sl@0
   126
	aGc->SetBrushStyle(CGraphicsContext::EDiamondCrossHatchBrush);
sl@0
   127
	aGc->SetBrushColor( iBgColor );
sl@0
   128
	aGc->SetPenColor( iBgColor );
sl@0
   129
	aGc->DrawRect(TRect(TPoint(0,0), iSize));
sl@0
   130
	
sl@0
   131
	// draw text
sl@0
   132
	TBuf<128> timebuf;
sl@0
   133
	TUint64 elapsedMs = iAnimLastKnownAction * iKernelTicksPeriod;
sl@0
   134
	TTime restoredTime(elapsedMs);
sl@0
   135
	AppendTime( timebuf , restoredTime );
sl@0
   136
		
sl@0
   137
	TInt textWidth = iAnimFont->MeasureText( timebuf );
sl@0
   138
	TInt textHalf = textWidth / 2;
sl@0
   139
	
sl@0
   140
	TInt centerX = iSize.iWidth / 2;
sl@0
   141
	TInt centerY = iSize.iHeight / 2;
sl@0
   142
	
sl@0
   143
	TRect rect(centerX - textHalf, centerY - iAnimFont->AscentInPixels(),
sl@0
   144
			   centerX + textHalf, centerY - iAnimFont->AscentInPixels() + iAnimFont->HeightInPixels());
sl@0
   145
sl@0
   146
	aGc->Reset();
sl@0
   147
sl@0
   148
	origin = iPos + aOrigin;
sl@0
   149
	aGc->SetOrigin( origin );
sl@0
   150
	clip = TRect( origin, iSize );
sl@0
   151
	clip.Intersection( aClip );
sl@0
   152
	clip.Move(-origin);
sl@0
   153
	aGc->SetClippingRect(clip);
sl@0
   154
	
sl@0
   155
	aGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
sl@0
   156
	
sl@0
   157
	aGc->UseFont(iAnimFont);
sl@0
   158
	
sl@0
   159
	aGc->DrawText(timebuf, rect, iAnimFont->AscentInPixels());
sl@0
   160
sl@0
   161
	rect.Move(0, iAnimFont->HeightInPixels());
sl@0
   162
	aGc->DrawText(timebuf, rect, iAnimFont->AscentInPixels());
sl@0
   163
sl@0
   164
	// inherited
sl@0
   165
	CCompWin::DrawBitmap(aGc, aClip, aOrigin);	
sl@0
   166
	}
sl@0
   167
sl@0
   168
void CAnimatedWin::SetSize(const TSize & aSize)
sl@0
   169
	{
sl@0
   170
	CCompWin::SetSize( aSize );
sl@0
   171
	if (iForeWin)
sl@0
   172
		{
sl@0
   173
		iForeWin->SetExtent(TPoint(iPos.iX-sInvisibleFrame, iPos.iY-sInvisibleFrame), 
sl@0
   174
				            TSize(iSize.iWidth+2*sInvisibleFrame, iSize.iHeight+2*sInvisibleFrame));
sl@0
   175
		}
sl@0
   176
	}
sl@0
   177
sl@0
   178
void CAnimatedWin::SetPos(const TPoint & aPos)
sl@0
   179
	{
sl@0
   180
	CCompWin::SetPos( aPos );
sl@0
   181
	if (iForeWin)
sl@0
   182
		{
sl@0
   183
		iForeWin->SetPosition(TPoint(iPos.iX-sInvisibleFrame, iPos.iY-sInvisibleFrame));
sl@0
   184
		}
sl@0
   185
	}
sl@0
   186
sl@0
   187
CAnimatedWin::CAnimatedWin(RWsSession& aWs, RWindowGroup* aGroup, CCompWin* aParent, CWindowGc& aGc):
sl@0
   188
	CCompWin( aWs, aGroup, aParent, aGc ), iAnimDll( aWs ), iForeWin(NULL)
sl@0
   189
	{
sl@0
   190
	iBgColor 	= TRnd::rnd(); 
sl@0
   191
	
sl@0
   192
	iFrameDuration = (TRnd::rnd( EFrameDurMaxTenthSec ) + 1) * EFrameDurMult;
sl@0
   193
sl@0
   194
	HAL::Get( HAL::ENanoTickPeriod, iKernelTicksPeriod );	
sl@0
   195
	
sl@0
   196
	}
sl@0
   197
sl@0
   198
void CAnimatedWin::ConstructL()
sl@0
   199
	{
sl@0
   200
	// prepare surface
sl@0
   201
	CCompWin::PreConstructL(iTransparent);
sl@0
   202
	
sl@0
   203
	TInt idx, err = KErrNone;
sl@0
   204
	TRect rect;
sl@0
   205
sl@0
   206
	TPoint animPos( iSize.iWidth / 2 - EFrameSzXHalf, 
sl@0
   207
			iSize.iHeight / 2 - EFrameSzYHalf );
sl@0
   208
	
sl@0
   209
	// create anim frames & masks
sl@0
   210
	for ( idx = 0; idx < ENofFrames; idx++)
sl@0
   211
		{
sl@0
   212
		iAnimContent[idx]	= new (ELeave) CFbsBitmap();
sl@0
   213
sl@0
   214
		err = iAnimContent[idx]->Create( TSize( EFrameSzX , EFrameSzY), EColor64K );
sl@0
   215
		User::LeaveIfError( err );
sl@0
   216
		
sl@0
   217
		iAnimCntDevice [idx] = CFbsBitmapDevice::NewL (iAnimContent[idx]);
sl@0
   218
		}
sl@0
   219
sl@0
   220
	iAnimMask	= new (ELeave) CFbsBitmap();
sl@0
   221
sl@0
   222
	err = iAnimMask->Create( TSize( EFrameSzX , EFrameSzY), EColor64K );
sl@0
   223
	User::LeaveIfError( err );
sl@0
   224
	
sl@0
   225
	iAnimMskDevice = CFbsBitmapDevice::NewL ( iAnimMask );
sl@0
   226
	
sl@0
   227
sl@0
   228
	CGraphicsContext* gCtxAni = NULL;
sl@0
   229
	CGraphicsContext* gCtxMsk = NULL;
sl@0
   230
	// draw frame 1 and mask
sl@0
   231
	err = iAnimCntDevice [ EFrame1 ]->CreateContext( gCtxAni );
sl@0
   232
	User::LeaveIfError( err );
sl@0
   233
	CleanupStack::PushL( gCtxAni );
sl@0
   234
sl@0
   235
	err = iAnimMskDevice->CreateContext( gCtxMsk );
sl@0
   236
	User::LeaveIfError( err );
sl@0
   237
	CleanupStack::PushL( gCtxMsk );
sl@0
   238
	
sl@0
   239
	
sl@0
   240
	gCtxAni->SetBrushColor(KRgbWhite);
sl@0
   241
	gCtxAni->SetPenColor(KRgbWhite);
sl@0
   242
	gCtxAni->SetBrushStyle( CGraphicsContext::ESolidBrush );
sl@0
   243
sl@0
   244
	gCtxMsk->SetBrushColor(KRgbWhite);
sl@0
   245
	gCtxMsk->SetPenColor(KRgbWhite);
sl@0
   246
	gCtxMsk->SetBrushStyle( CGraphicsContext::ESolidBrush );
sl@0
   247
	
sl@0
   248
	rect.SetRect( EFrameSzXHalf - EFrameSzXEgt, 0, EFrameSzXHalf + EFrameSzXEgt, EFrameSzYHalf ); //lint !e656 Arithmetic operation uses (compatible) enum's 
sl@0
   249
	gCtxAni->DrawRect( rect );
sl@0
   250
	gCtxMsk->DrawRect( rect );
sl@0
   251
sl@0
   252
	rect.SetRect( EFrameSzXHalf - EFrameSzXQtr, EFrameSzYHalf, EFrameSzXHalf + EFrameSzXQtr, EFrameSzY ); //lint !e656 Arithmetic operation uses (compatible) enum's
sl@0
   253
	gCtxAni->DrawRect( rect );
sl@0
   254
	gCtxMsk->DrawRect( rect );
sl@0
   255
sl@0
   256
	gCtxAni->SetPenColor(KRgbBlack);
sl@0
   257
	gCtxAni->DrawLine( TPoint(EFrameSzXHalf,0), TPoint (EFrameSzXHalf,EFrameSzY) );
sl@0
   258
	
sl@0
   259
	
sl@0
   260
	CleanupStack::PopAndDestroy( gCtxMsk ); 
sl@0
   261
	CleanupStack::PopAndDestroy( gCtxAni ); 
sl@0
   262
sl@0
   263
	// draw frame 2
sl@0
   264
	err = iAnimCntDevice [ EFrame2 ]->CreateContext( gCtxAni );
sl@0
   265
	User::LeaveIfError( err );
sl@0
   266
	CleanupStack::PushL( gCtxAni );
sl@0
   267
sl@0
   268
	gCtxAni->SetPenColor(KRgbWhite);
sl@0
   269
	gCtxAni->DrawLine( TPoint(EFrameSzXHalf,0), TPoint (EFrameSzXHalf,EFrameSzY) );
sl@0
   270
sl@0
   271
	CleanupStack::PopAndDestroy( gCtxAni ); 
sl@0
   272
	
sl@0
   273
	// init font
sl@0
   274
	err	= iAnimMskDevice->GetNearestFontInPixels( iAnimFont, TFontSpec( _L("Roman"), 16 ) );
sl@0
   275
	User::LeaveIfError( err );
sl@0
   276
sl@0
   277
	// load anim DLL
sl@0
   278
	err = iAnimDll.Load( KAnimDllName );
sl@0
   279
	User::LeaveIfError( err );
sl@0
   280
	
sl@0
   281
	// construct server side anim
sl@0
   282
	TPckgBuf<TStressTestAnimParams> animParams;
sl@0
   283
	animParams().pos 		= animPos;
sl@0
   284
	animParams().interval = iFrameDuration.Int();
sl@0
   285
	animParams().bit1		= iAnimContent[ EFrame1 ]->Handle();
sl@0
   286
	animParams().bit2		= iAnimContent[ EFrame2 ]->Handle();
sl@0
   287
	animParams().mask		= iAnimMask->Handle();
sl@0
   288
	animParams().font		= iAnimFont->Handle();
sl@0
   289
sl@0
   290
	iAnim = new (ELeave) CAnimatedWin::RStressAnim ( iAnimDll );
sl@0
   291
	
sl@0
   292
	err = iAnim->Construct( *iWindow, animParams );
sl@0
   293
	User::LeaveIfError( err );
sl@0
   294
sl@0
   295
	// finally
sl@0
   296
	CCompWin::PostConstructL();	
sl@0
   297
sl@0
   298
	// got time shot when we started
sl@0
   299
	iAnimStartup = User::NTickCount();
sl@0
   300
sl@0
   301
	//Create a transparent foreground window, moving and resizing with the animation window
sl@0
   302
	if (iTransparentForegroundWindow)
sl@0
   303
		{
sl@0
   304
		iForeWin = new(ELeave) RBlankWindow(iWs);
sl@0
   305
		iForeWin->Construct(*iGroup,reinterpret_cast<TUint32>(iForeWin));
sl@0
   306
		iForeWin->SetColor(TRgb(0, 0, 0, 0));	//a transparent window
sl@0
   307
		iForeWin->SetExtent(TPoint(iPos.iX-sInvisibleFrame, iPos.iY-sInvisibleFrame), 
sl@0
   308
				            TSize(iSize.iWidth+2*sInvisibleFrame, iSize.iHeight+2*sInvisibleFrame));
sl@0
   309
		iForeWin->SetOrdinalPosition(0);
sl@0
   310
		iForeWin->Activate();
sl@0
   311
		}
sl@0
   312
	
sl@0
   313
	iConstructed = ETrue;
sl@0
   314
	}
sl@0
   315
sl@0
   316
void CAnimatedWin::SetAnimPos(const TPoint& aPos)
sl@0
   317
	{
sl@0
   318
	TPckgBuf<TStressTestAnimParams> animParams;
sl@0
   319
	animParams().pos = aPos;
sl@0
   320
	iAnim->RequestAnimThis( EADllTextPos, animParams );
sl@0
   321
	}
sl@0
   322
sl@0
   323
TBool CAnimatedWin::QueryReadyForVerification()
sl@0
   324
	{
sl@0
   325
sl@0
   326
	TBool res;
sl@0
   327
	
sl@0
   328
	TInt32 curTicks = User::NTickCount();
sl@0
   329
sl@0
   330
	iAnimLastKnownAction = (TUint32) iAnim->RequestAnimThis( EADllQuerySync ); 
sl@0
   331
	
sl@0
   332
	TUint64 elapsed = TTickUtils::CalcTickDelta( curTicks, iAnimLastKnownAction );
sl@0
   333
sl@0
   334
	TUint64 elapsedMs = elapsed * iKernelTicksPeriod;
sl@0
   335
	
sl@0
   336
	res = ( elapsedMs < EWatchMatchGap );
sl@0
   337
	
sl@0
   338
	res = res && CCompWin::QueryReadyForVerification();
sl@0
   339
		
sl@0
   340
	return res;
sl@0
   341
	}
sl@0
   342
sl@0
   343
CAnimatedWin::RStressAnim::RStressAnim (RAnimDll& aAnimDll):
sl@0
   344
	RAnim( aAnimDll )
sl@0
   345
	{ } // empty
sl@0
   346
sl@0
   347
TInt CAnimatedWin::RStressAnim::Construct(const RWindowBase &aDevice, const TDesC8 &aParams)
sl@0
   348
	{
sl@0
   349
	return RAnim::Construct( aDevice, 0, aParams );
sl@0
   350
	}
sl@0
   351
sl@0
   352
TInt CAnimatedWin::RStressAnim::RequestAnimThis(TInt aOpcode)
sl@0
   353
	{
sl@0
   354
	TInt res;
sl@0
   355
	
sl@0
   356
	TPckgC<TBool> params(ETrue);
sl@0
   357
	
sl@0
   358
	res = RequestAnimThis( aOpcode, params );
sl@0
   359
	
sl@0
   360
	return res;
sl@0
   361
	}
sl@0
   362
sl@0
   363
TInt CAnimatedWin::RStressAnim::RequestAnimThis(TInt aOpcode, const TDesC8 &aParams)
sl@0
   364
	{
sl@0
   365
	TInt res;
sl@0
   366
	
sl@0
   367
	res = CommandReply( aOpcode, aParams );
sl@0
   368
	
sl@0
   369
	return res;	
sl@0
   370
	}
sl@0
   371
sl@0
   372
void CAnimatedWin::DumpDetails(RFile& aFile, TInt aDepth)
sl@0
   373
	{
sl@0
   374
	TBuf8<256> buf;
sl@0
   375
	buf.SetLength(0);
sl@0
   376
	for (TInt d = 0; d < aDepth; ++d)
sl@0
   377
		{
sl@0
   378
		buf.Append(_L8("  "));
sl@0
   379
		}
sl@0
   380
	buf.Append(_L8("Transparent = ["));
sl@0
   381
	buf.AppendNum((TInt64)iTransparent);
sl@0
   382
	buf.Append(_L8("] transparent_foreground_window = ["));
sl@0
   383
	buf.AppendNum((TInt64)iTransparentForegroundWindow);
sl@0
   384
	buf.Append(_L8("] BgColor = ["));
sl@0
   385
	buf.AppendNum(iBgColor.Value());
sl@0
   386
	buf.Append(_L8("]\r\n"));
sl@0
   387
	aFile.Write(buf);
sl@0
   388
	}