os/graphics/windowing/windowserver/test/t_stress/src/spritewin.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 "spritewin.h"
sl@0
    23
#include "utils.h"
sl@0
    24
sl@0
    25
#include <hal.h>
sl@0
    26
sl@0
    27
sl@0
    28
//common configuration parameter names
sl@0
    29
_LIT(KT_WservStressParamRandomizeDrawMode, "randomize_draw_mode");
sl@0
    30
_LIT(KT_WservStressParamMaxRandomStepX, "max_random_step_x");
sl@0
    31
_LIT(KT_WservStressParamMaxRandomStepY, "max_random_step_y");
sl@0
    32
_LIT(KT_WservStressParamMaxRandomOffsetX, "max_random_offset_x");
sl@0
    33
_LIT(KT_WservStressParamMaxRandomOffsetY, "max_random_offset_y");
sl@0
    34
sl@0
    35
//static configuration data, definitions and default assignments
sl@0
    36
TBool CSpritedWin::iEnabled = ETrue;
sl@0
    37
TBool CSpritedWin::iTransparent = ETrue;
sl@0
    38
TBool CSpritedWin::iRandomizePenStyle = EFalse;
sl@0
    39
TBool CSpritedWin::iRandomizeBrushStyle = EFalse;
sl@0
    40
TBool CSpritedWin::iRandomizeDrawMode = EFalse;
sl@0
    41
TBool CSpritedWin::iTransparentForegroundWindow = EFalse;
sl@0
    42
TInt CSpritedWin::iMaxRandomStepX = 0;
sl@0
    43
TInt CSpritedWin::iMaxRandomStepY = 0;
sl@0
    44
TInt CSpritedWin::iMaxRandomOffsetX = 0;
sl@0
    45
TInt CSpritedWin::iMaxRandomOffsetY = 0;
sl@0
    46
sl@0
    47
const TInt sInvisibleFrame = 24;	//how much bigger the invisible window is
sl@0
    48
sl@0
    49
sl@0
    50
CSpritedWin* CSpritedWin::NewLC(RWsSession& aWs, RWindowGroup* aGroup, CCompWin* aParent, CWindowGc& aGc)
sl@0
    51
	{
sl@0
    52
	CSpritedWin* self = new (ELeave) CSpritedWin( aWs, aGroup, aParent, aGc );
sl@0
    53
	CleanupStack::PushL( self );
sl@0
    54
	self->ConstructL();
sl@0
    55
	
sl@0
    56
	return self;
sl@0
    57
	}
sl@0
    58
sl@0
    59
void CSpritedWin::LoadConfiguration(const MTestStepConfigurationContext* aContext)
sl@0
    60
	{
sl@0
    61
	aContext->GetBool(KT_WservStressParamEnabled, iEnabled);
sl@0
    62
	aContext->GetBool(KT_WservStressParamTransparent, iTransparent);
sl@0
    63
	aContext->GetBool(KT_WservStressParamRandomizePenStyle, iRandomizePenStyle);
sl@0
    64
	aContext->GetBool(KT_WservStressParamRandomizeBrushStyle, iRandomizeBrushStyle);
sl@0
    65
	aContext->GetBool(KT_WservStressParamRandomizeDrawMode, iRandomizeDrawMode);
sl@0
    66
	aContext->GetBool(KT_WservStressParamTransparentForegroundWindow, iTransparentForegroundWindow);
sl@0
    67
sl@0
    68
	aContext->GetInt(KT_WservStressParamMaxRandomStepX, iMaxRandomStepX);
sl@0
    69
	aContext->GetInt(KT_WservStressParamMaxRandomStepY, iMaxRandomStepY);
sl@0
    70
	aContext->GetInt(KT_WservStressParamMaxRandomOffsetX, iMaxRandomOffsetX);
sl@0
    71
	aContext->GetInt(KT_WservStressParamMaxRandomOffsetY, iMaxRandomOffsetY);
sl@0
    72
	}
sl@0
    73
sl@0
    74
CSpritedWin::~CSpritedWin()
sl@0
    75
	{ 
sl@0
    76
	if (iForeWin)
sl@0
    77
		{
sl@0
    78
		iForeWin->Close();
sl@0
    79
		delete iForeWin;
sl@0
    80
		}
sl@0
    81
sl@0
    82
	iSprite.Close();
sl@0
    83
	
sl@0
    84
	TInt idx;
sl@0
    85
	for ( idx = 0; idx < ENofSlides; idx++)
sl@0
    86
		{
sl@0
    87
		delete iSpriteCntDevice [idx];
sl@0
    88
		delete iSpriteMskDevice [idx]; 
sl@0
    89
		
sl@0
    90
		delete iSpriteContent[idx];
sl@0
    91
		delete iSpriteMask[idx];
sl@0
    92
		}
sl@0
    93
	}
sl@0
    94
	
sl@0
    95
void CSpritedWin::Redraw(const TRect& aRect)
sl@0
    96
	{
sl@0
    97
	if (iSpriteStartup == 0)
sl@0
    98
		{
sl@0
    99
		//first time getting here should be very close to the sprite activation time
sl@0
   100
		iSpriteStartup = User::NTickCount();
sl@0
   101
		}
sl@0
   102
	iWsGc.Activate(*iWindow);
sl@0
   103
sl@0
   104
	iRedrawWindow->BeginRedraw( aRect );
sl@0
   105
sl@0
   106
	iWsGc.Reset();
sl@0
   107
sl@0
   108
	//draw rectangle filling window area
sl@0
   109
	iWsGc.SetPenStyle( iPenStyle );
sl@0
   110
	iWsGc.SetBrushStyle( iBrushStyle );
sl@0
   111
	iWsGc.SetBrushColor( iBgColor );
sl@0
   112
	iWsGc.SetPenColor( iBgColor );
sl@0
   113
	iWsGc.SetDrawMode(iDrawMode);
sl@0
   114
	
sl@0
   115
	TRect drawRect( TPoint(0,0), iSize );
sl@0
   116
	
sl@0
   117
	iWsGc.DrawRect( drawRect );
sl@0
   118
	
sl@0
   119
	iRedrawWindow->EndRedraw();
sl@0
   120
	
sl@0
   121
	iWsGc.Deactivate();	
sl@0
   122
	}
sl@0
   123
sl@0
   124
void CSpritedWin::DrawBitmap(CFbsBitGc* aGc, TRect& aClip, TPoint& aOrigin)
sl@0
   125
	{
sl@0
   126
	if (iSpriteStartup == 0)
sl@0
   127
		{
sl@0
   128
		//although bitmap drawing requested, sprite was not yet rendered - skip
sl@0
   129
		return;
sl@0
   130
		}
sl@0
   131
	aGc->Reset();
sl@0
   132
	TPoint origin = iPos + aOrigin;
sl@0
   133
	aGc->SetOrigin(origin);
sl@0
   134
	TRect clip(origin, iSize);
sl@0
   135
	clip.Intersection(aClip);
sl@0
   136
	clip.Move(-origin);
sl@0
   137
	aGc->SetClippingRect(clip);
sl@0
   138
sl@0
   139
	// draw win
sl@0
   140
	aGc->SetPenStyle(iPenStyle);
sl@0
   141
	aGc->SetBrushStyle(iBrushStyle);
sl@0
   142
	aGc->SetBrushColor( iBgColor );
sl@0
   143
	aGc->SetPenColor( iBgColor );
sl@0
   144
	aGc->SetDrawMode(iDrawMode);
sl@0
   145
	aGc->DrawRect(TRect(TPoint(0,0), iSize));
sl@0
   146
	
sl@0
   147
	// emulate sprite, cur frame
sl@0
   148
	// time (in ticks) passed since sprite activation
sl@0
   149
	TUint64 delta = TTickUtils::CalcTickDelta( iVerifyTick, iSpriteStartup );
sl@0
   150
	// time for a single slide (in microseconds)
sl@0
   151
	TUint slideDur  = iSlideDuration.Int();
sl@0
   152
	
sl@0
   153
	TInt slideNo = TUint32( ( (delta * iKernelTicksPeriod ) / slideDur ) % ENofSlides );
sl@0
   154
	
sl@0
   155
	TPoint spritePos( iSize.iWidth / 2 - ESpriteSzXHalf, 
sl@0
   156
			iSize.iHeight / 2 - ESpriteSzYHalf );
sl@0
   157
	
sl@0
   158
	TSize spriteSize(ESpriteSzX, ESpriteSzY);
sl@0
   159
	
sl@0
   160
	TRect	spriteRect ( TPoint(0,0), spriteSize );
sl@0
   161
	
sl@0
   162
	TRect   destRect( spritePos, spriteSize );
sl@0
   163
	destRect.Move(iSpriteDef[slideNo].iOffset);
sl@0
   164
	
sl@0
   165
	aGc->DrawBitmapMasked( destRect, 
sl@0
   166
						   iSpriteContent[slideNo], 
sl@0
   167
						   spriteRect, 
sl@0
   168
						   iSpriteMask[slideNo],
sl@0
   169
						   EFalse);
sl@0
   170
	
sl@0
   171
	// inherited
sl@0
   172
	CCompWin::DrawBitmap(aGc, aClip, aOrigin);	
sl@0
   173
	}
sl@0
   174
sl@0
   175
void CSpritedWin::ClearBitmapBackground(CFbsBitGc* aGc, TRect& aClip, TPoint& aOrigin)
sl@0
   176
	{
sl@0
   177
	if (iSpriteStartup == 0)
sl@0
   178
		{
sl@0
   179
		//although bitmap drawing requested, sprite was not yet rendered - skip
sl@0
   180
		return;
sl@0
   181
		}
sl@0
   182
	CCompWin::ClearBitmapBackground(aGc, aClip, aOrigin);
sl@0
   183
	}
sl@0
   184
sl@0
   185
void CSpritedWin::SetSize(const TSize & aSize)
sl@0
   186
	{
sl@0
   187
	CCompWin::SetSize( aSize );
sl@0
   188
sl@0
   189
	if ( iConstructed )
sl@0
   190
		{		
sl@0
   191
		TPoint spritePos( iSize.iWidth / 2 - ESpriteSzXHalf, 
sl@0
   192
				iSize.iHeight / 2 - ESpriteSzYHalf );
sl@0
   193
		
sl@0
   194
		iSprite.SetPosition( spritePos );
sl@0
   195
		}
sl@0
   196
	if (iForeWin)
sl@0
   197
		{
sl@0
   198
		iForeWin->SetExtent(TPoint(iPos.iX-sInvisibleFrame, iPos.iY-sInvisibleFrame), 
sl@0
   199
	            TSize(iSize.iWidth+2*sInvisibleFrame, iSize.iHeight+2*sInvisibleFrame));
sl@0
   200
		}
sl@0
   201
	}
sl@0
   202
sl@0
   203
void CSpritedWin::SetPos(const TPoint & aPos)
sl@0
   204
	{
sl@0
   205
	CCompWin::SetPos( aPos );
sl@0
   206
	if (iForeWin)
sl@0
   207
		{
sl@0
   208
		iForeWin->SetPosition(TPoint(iPos.iX-sInvisibleFrame, iPos.iY-sInvisibleFrame));
sl@0
   209
		}
sl@0
   210
	}
sl@0
   211
sl@0
   212
CSpritedWin::CSpritedWin(RWsSession& aWs, RWindowGroup* aGroup, CCompWin* aParent, CWindowGc& aGc):
sl@0
   213
	CCompWin( aWs, aGroup, aParent, aGc ), iSprite ( aWs ), iForeWin(NULL)
sl@0
   214
	{
sl@0
   215
	iBgColor 	= TRnd::rnd();
sl@0
   216
	if (!iTransparent)
sl@0
   217
		{
sl@0
   218
		iBgColor.SetAlpha(255);
sl@0
   219
		}
sl@0
   220
	iSlideDuration = (TRnd::rnd( ESlideDurMaxTenthSec ) + 1) * ESlideDurMult;
sl@0
   221
sl@0
   222
	HAL::Get( HAL::ENanoTickPeriod, iKernelTicksPeriod );	
sl@0
   223
	
sl@0
   224
	}
sl@0
   225
sl@0
   226
void CSpritedWin::ConstructL()
sl@0
   227
	{
sl@0
   228
	// prepare surface
sl@0
   229
	CCompWin::PreConstructL(iTransparent);
sl@0
   230
	
sl@0
   231
	TInt idx, err = KErrNone;
sl@0
   232
	TRect rect;
sl@0
   233
	CGraphicsContext* gCtxSpr = NULL;
sl@0
   234
	CGraphicsContext* gCtxMsk = NULL;
sl@0
   235
sl@0
   236
	// init sprite handles
sl@0
   237
	TPoint spritePos( iSize.iWidth / 2 - ESpriteSzXHalf, 
sl@0
   238
			iSize.iHeight / 2 - ESpriteSzYHalf );
sl@0
   239
	err = iSprite.Construct( *iWindow, spritePos, ESpriteNoChildClip  );
sl@0
   240
	User::LeaveIfError( err );
sl@0
   241
	
sl@0
   242
	iPenStyle = iRandomizePenStyle ? GetRandomPenStyle() : CGraphicsContext::ESolidPen;
sl@0
   243
	iBrushStyle = iRandomizeBrushStyle ? GetRandomBrushStyle() : CGraphicsContext::ESolidBrush;
sl@0
   244
	iDrawMode = iRandomizeDrawMode ? GetRandomDrawMode() : CGraphicsContext::EDrawModePEN;
sl@0
   245
	
sl@0
   246
	TInt stepx = iMaxRandomStepX > 0 ? TRnd::rnd(2*iMaxRandomStepX) - iMaxRandomStepX : 0;
sl@0
   247
	TInt stepy = iMaxRandomStepY > 0 ? TRnd::rnd(2*iMaxRandomStepY) - iMaxRandomStepY : 0;
sl@0
   248
	TInt offsetx = iMaxRandomOffsetX > 0 ? TRnd::rnd(2*iMaxRandomOffsetX) - iMaxRandomOffsetX : 0;
sl@0
   249
	TInt offsety = iMaxRandomOffsetY > 0 ? TRnd::rnd(2*iMaxRandomOffsetY) - iMaxRandomOffsetY : 0;
sl@0
   250
	
sl@0
   251
	// create sprites & masks
sl@0
   252
	for ( idx = 0; idx < ENofSlides; idx++)
sl@0
   253
		{
sl@0
   254
		iSpriteContent[idx] = new (ELeave) CFbsBitmap();
sl@0
   255
		iSpriteMask[idx]	= new (ELeave) CFbsBitmap();;
sl@0
   256
sl@0
   257
		err = iSpriteContent[idx]->Create(TSize(ESpriteSzX,ESpriteSzY), EColor64K);
sl@0
   258
		User::LeaveIfError( err );
sl@0
   259
		
sl@0
   260
		err = iSpriteMask[idx]->Create(TSize(ESpriteSzX,ESpriteSzY), EColor64K);
sl@0
   261
		User::LeaveIfError( err );
sl@0
   262
		
sl@0
   263
		iSpriteCntDevice [idx] = CFbsBitmapDevice::NewL (iSpriteContent[idx]);
sl@0
   264
		iSpriteMskDevice [idx] = CFbsBitmapDevice::NewL (iSpriteMask[idx]);
sl@0
   265
		
sl@0
   266
	
sl@0
   267
		// draw sprite content
sl@0
   268
		err = iSpriteCntDevice[idx]->CreateContext( gCtxSpr );
sl@0
   269
		User::LeaveIfError( err );
sl@0
   270
		CleanupStack::PushL( gCtxSpr );
sl@0
   271
sl@0
   272
		err = iSpriteMskDevice[idx]->CreateContext( gCtxMsk );
sl@0
   273
		User::LeaveIfError( err );
sl@0
   274
		CleanupStack::PushL( gCtxMsk );
sl@0
   275
sl@0
   276
		gCtxSpr->SetPenStyle(CGraphicsContext::ESolidPen);
sl@0
   277
		gCtxSpr->SetPenColor(KRgbWhite);
sl@0
   278
		gCtxSpr->SetBrushColor(KRgbWhite);
sl@0
   279
		gCtxSpr->SetBrushStyle( iBrushStyle );
sl@0
   280
sl@0
   281
		gCtxMsk->SetPenStyle(CGraphicsContext::ESolidPen);
sl@0
   282
		gCtxMsk->SetPenColor(KRgbBlack);
sl@0
   283
		gCtxMsk->SetBrushColor(KRgbBlack);
sl@0
   284
		gCtxMsk->SetBrushStyle( CGraphicsContext::ESolidBrush );
sl@0
   285
		
sl@0
   286
		rect.SetRect( 0, 0, ESpriteSzX, ESpriteSzY );
sl@0
   287
		gCtxSpr->DrawRect( rect );
sl@0
   288
		gCtxMsk->DrawRect( rect );
sl@0
   289
sl@0
   290
		// cross mask
sl@0
   291
		gCtxMsk->SetBrushColor(KRgbWhite);
sl@0
   292
		gCtxMsk->SetPenColor(KRgbWhite);
sl@0
   293
		rect.SetRect( ESpriteSzXHalf - EStepWidth * (idx + 1), 0, 
sl@0
   294
					  ESpriteSzXHalf + EStepWidth * (idx + 1), ESpriteSzY );
sl@0
   295
		gCtxMsk->DrawRect( rect );
sl@0
   296
		rect.SetRect( 0, ESpriteSzYHalf - EStepHeight * (idx + 1),
sl@0
   297
				      ESpriteSzX, ESpriteSzYHalf + EStepHeight * (idx + 1) );
sl@0
   298
		gCtxMsk->DrawRect( rect );
sl@0
   299
sl@0
   300
		CleanupStack::PopAndDestroy( gCtxMsk );		
sl@0
   301
		CleanupStack::PopAndDestroy( gCtxSpr );		
sl@0
   302
		
sl@0
   303
		// make sprite
sl@0
   304
		iSpriteDef[idx].iBitmap 		= iSpriteContent[idx];
sl@0
   305
		iSpriteDef[idx].iMaskBitmap	= iSpriteMask[idx];
sl@0
   306
		iSpriteDef[idx].iOffset		= TPoint( offsetx+idx*stepx, offsety+idx*stepy );
sl@0
   307
		iSpriteDef[idx].iDrawMode		= CGraphicsContext::EDrawModeAND;
sl@0
   308
		iSpriteDef[idx].iInvertMask	= EFalse;
sl@0
   309
		iSpriteDef[idx].iInterval		= iSlideDuration;
sl@0
   310
		
sl@0
   311
		err = iSprite.AppendMember( iSpriteDef[idx] );
sl@0
   312
		User::LeaveIfError( err );
sl@0
   313
		}
sl@0
   314
sl@0
   315
	//Create a transparent foreground window, moving and resizing with the sprite window
sl@0
   316
	if (iTransparentForegroundWindow)
sl@0
   317
		{
sl@0
   318
		iForeWin = new(ELeave) RBlankWindow(iWs);
sl@0
   319
		iForeWin->Construct(*iGroup,reinterpret_cast<TUint32>(iForeWin));
sl@0
   320
		iForeWin->SetColor(TRgb(0, 0, 0, 0));	//a transparent window
sl@0
   321
		iForeWin->SetExtent(TPoint(iPos.iX-sInvisibleFrame, iPos.iY-sInvisibleFrame), 
sl@0
   322
				            TSize(iSize.iWidth+2*sInvisibleFrame, iSize.iHeight+2*sInvisibleFrame));
sl@0
   323
		iForeWin->SetOrdinalPosition(0);
sl@0
   324
		iForeWin->Activate();
sl@0
   325
		}
sl@0
   326
	
sl@0
   327
	// finally
sl@0
   328
	CCompWin::PostConstructL();	
sl@0
   329
sl@0
   330
	iSpriteStartup = 0;
sl@0
   331
	// show up the sprite
sl@0
   332
	err = iSprite.Activate();
sl@0
   333
	User::LeaveIfError( err );
sl@0
   334
	
sl@0
   335
	iConstructed = ETrue;
sl@0
   336
	}
sl@0
   337
sl@0
   338
TBool CSpritedWin::QueryReadyForVerification()
sl@0
   339
	{
sl@0
   340
sl@0
   341
	TBool res;
sl@0
   342
sl@0
   343
	// time (in ticks) passed since sprite activation
sl@0
   344
	TUint64 delta = TTickUtils::CalcTickDelta( iVerifyTick, iSpriteStartup );
sl@0
   345
	// time for a single slide (in microseconds)
sl@0
   346
	TUint slideDur  = iSlideDuration.Int();
sl@0
   347
	// time for all sprite slides (in microseconds)
sl@0
   348
	TUint spriteDur = slideDur * ENofSlides;
sl@0
   349
	// time passed since begining of sprite sequence (in microseconds)
sl@0
   350
	TUint64 sense = (delta * iKernelTicksPeriod ) % spriteDur; // microsec
sl@0
   351
	
sl@0
   352
	res = (sense >= EFrameBorderSenseMs);
sl@0
   353
	
sl@0
   354
	res = res && CCompWin::QueryReadyForVerification();
sl@0
   355
		
sl@0
   356
	return res;
sl@0
   357
	}
sl@0
   358
sl@0
   359
void CSpritedWin::DumpDetails(RFile& aFile, TInt aDepth)
sl@0
   360
	{
sl@0
   361
	TBuf8<256> buf;
sl@0
   362
	buf.SetLength(0);
sl@0
   363
	for (TInt d = 0; d < aDepth; ++d)
sl@0
   364
		{
sl@0
   365
		buf.Append(_L8("  "));
sl@0
   366
		}
sl@0
   367
	buf.Append(_L8("Transparent = ["));
sl@0
   368
	buf.AppendNum((TInt64)iTransparent);
sl@0
   369
	buf.Append(_L8("] pen_style = ["));
sl@0
   370
	buf.AppendNum((TInt64)iPenStyle);
sl@0
   371
	buf.Append(_L8("] brush_style = ["));
sl@0
   372
	buf.AppendNum((TInt64)iBrushStyle);
sl@0
   373
	buf.Append(_L8("] draw_mode = ["));
sl@0
   374
	buf.AppendNum((TInt64)iDrawMode);
sl@0
   375
	buf.Append(_L8("] transparent_foreground_window = ["));
sl@0
   376
	buf.AppendNum((TInt64)iTransparentForegroundWindow);
sl@0
   377
	buf.Append(_L8("] max_random_step_x = ["));
sl@0
   378
	buf.AppendNum((TInt64)iMaxRandomStepX);
sl@0
   379
	buf.Append(_L8("] max_random_step_y = ["));
sl@0
   380
	buf.AppendNum((TInt64)iMaxRandomStepY);
sl@0
   381
	buf.Append(_L8("] max_random_offset_x = ["));
sl@0
   382
	buf.AppendNum((TInt64)iMaxRandomOffsetX);
sl@0
   383
	buf.Append(_L8("] max_random_offset_y = ["));
sl@0
   384
	buf.AppendNum((TInt64)iMaxRandomOffsetY);
sl@0
   385
	buf.Append(_L8("]\r\n"));
sl@0
   386
	aFile.Write(buf);
sl@0
   387
	}