sl@0: // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @test sl@0: @internalComponent sl@0: */ sl@0: sl@0: #include "spritewin.h" sl@0: #include "utils.h" sl@0: sl@0: #include sl@0: sl@0: sl@0: //common configuration parameter names sl@0: _LIT(KT_WservStressParamRandomizeDrawMode, "randomize_draw_mode"); sl@0: _LIT(KT_WservStressParamMaxRandomStepX, "max_random_step_x"); sl@0: _LIT(KT_WservStressParamMaxRandomStepY, "max_random_step_y"); sl@0: _LIT(KT_WservStressParamMaxRandomOffsetX, "max_random_offset_x"); sl@0: _LIT(KT_WservStressParamMaxRandomOffsetY, "max_random_offset_y"); sl@0: sl@0: //static configuration data, definitions and default assignments sl@0: TBool CSpritedWin::iEnabled = ETrue; sl@0: TBool CSpritedWin::iTransparent = ETrue; sl@0: TBool CSpritedWin::iRandomizePenStyle = EFalse; sl@0: TBool CSpritedWin::iRandomizeBrushStyle = EFalse; sl@0: TBool CSpritedWin::iRandomizeDrawMode = EFalse; sl@0: TBool CSpritedWin::iTransparentForegroundWindow = EFalse; sl@0: TInt CSpritedWin::iMaxRandomStepX = 0; sl@0: TInt CSpritedWin::iMaxRandomStepY = 0; sl@0: TInt CSpritedWin::iMaxRandomOffsetX = 0; sl@0: TInt CSpritedWin::iMaxRandomOffsetY = 0; sl@0: sl@0: const TInt sInvisibleFrame = 24; //how much bigger the invisible window is sl@0: sl@0: sl@0: CSpritedWin* CSpritedWin::NewLC(RWsSession& aWs, RWindowGroup* aGroup, CCompWin* aParent, CWindowGc& aGc) sl@0: { sl@0: CSpritedWin* self = new (ELeave) CSpritedWin( aWs, aGroup, aParent, aGc ); sl@0: CleanupStack::PushL( self ); sl@0: self->ConstructL(); sl@0: sl@0: return self; sl@0: } sl@0: sl@0: void CSpritedWin::LoadConfiguration(const MTestStepConfigurationContext* aContext) sl@0: { sl@0: aContext->GetBool(KT_WservStressParamEnabled, iEnabled); sl@0: aContext->GetBool(KT_WservStressParamTransparent, iTransparent); sl@0: aContext->GetBool(KT_WservStressParamRandomizePenStyle, iRandomizePenStyle); sl@0: aContext->GetBool(KT_WservStressParamRandomizeBrushStyle, iRandomizeBrushStyle); sl@0: aContext->GetBool(KT_WservStressParamRandomizeDrawMode, iRandomizeDrawMode); sl@0: aContext->GetBool(KT_WservStressParamTransparentForegroundWindow, iTransparentForegroundWindow); sl@0: sl@0: aContext->GetInt(KT_WservStressParamMaxRandomStepX, iMaxRandomStepX); sl@0: aContext->GetInt(KT_WservStressParamMaxRandomStepY, iMaxRandomStepY); sl@0: aContext->GetInt(KT_WservStressParamMaxRandomOffsetX, iMaxRandomOffsetX); sl@0: aContext->GetInt(KT_WservStressParamMaxRandomOffsetY, iMaxRandomOffsetY); sl@0: } sl@0: sl@0: CSpritedWin::~CSpritedWin() sl@0: { sl@0: if (iForeWin) sl@0: { sl@0: iForeWin->Close(); sl@0: delete iForeWin; sl@0: } sl@0: sl@0: iSprite.Close(); sl@0: sl@0: TInt idx; sl@0: for ( idx = 0; idx < ENofSlides; idx++) sl@0: { sl@0: delete iSpriteCntDevice [idx]; sl@0: delete iSpriteMskDevice [idx]; sl@0: sl@0: delete iSpriteContent[idx]; sl@0: delete iSpriteMask[idx]; sl@0: } sl@0: } sl@0: sl@0: void CSpritedWin::Redraw(const TRect& aRect) sl@0: { sl@0: if (iSpriteStartup == 0) sl@0: { sl@0: //first time getting here should be very close to the sprite activation time sl@0: iSpriteStartup = User::NTickCount(); sl@0: } sl@0: iWsGc.Activate(*iWindow); sl@0: sl@0: iRedrawWindow->BeginRedraw( aRect ); sl@0: sl@0: iWsGc.Reset(); sl@0: sl@0: //draw rectangle filling window area sl@0: iWsGc.SetPenStyle( iPenStyle ); sl@0: iWsGc.SetBrushStyle( iBrushStyle ); sl@0: iWsGc.SetBrushColor( iBgColor ); sl@0: iWsGc.SetPenColor( iBgColor ); sl@0: iWsGc.SetDrawMode(iDrawMode); sl@0: sl@0: TRect drawRect( TPoint(0,0), iSize ); sl@0: sl@0: iWsGc.DrawRect( drawRect ); sl@0: sl@0: iRedrawWindow->EndRedraw(); sl@0: sl@0: iWsGc.Deactivate(); sl@0: } sl@0: sl@0: void CSpritedWin::DrawBitmap(CFbsBitGc* aGc, TRect& aClip, TPoint& aOrigin) sl@0: { sl@0: if (iSpriteStartup == 0) sl@0: { sl@0: //although bitmap drawing requested, sprite was not yet rendered - skip sl@0: return; sl@0: } sl@0: aGc->Reset(); sl@0: TPoint origin = iPos + aOrigin; sl@0: aGc->SetOrigin(origin); sl@0: TRect clip(origin, iSize); sl@0: clip.Intersection(aClip); sl@0: clip.Move(-origin); sl@0: aGc->SetClippingRect(clip); sl@0: sl@0: // draw win sl@0: aGc->SetPenStyle(iPenStyle); sl@0: aGc->SetBrushStyle(iBrushStyle); sl@0: aGc->SetBrushColor( iBgColor ); sl@0: aGc->SetPenColor( iBgColor ); sl@0: aGc->SetDrawMode(iDrawMode); sl@0: aGc->DrawRect(TRect(TPoint(0,0), iSize)); sl@0: sl@0: // emulate sprite, cur frame sl@0: // time (in ticks) passed since sprite activation sl@0: TUint64 delta = TTickUtils::CalcTickDelta( iVerifyTick, iSpriteStartup ); sl@0: // time for a single slide (in microseconds) sl@0: TUint slideDur = iSlideDuration.Int(); sl@0: sl@0: TInt slideNo = TUint32( ( (delta * iKernelTicksPeriod ) / slideDur ) % ENofSlides ); sl@0: sl@0: TPoint spritePos( iSize.iWidth / 2 - ESpriteSzXHalf, sl@0: iSize.iHeight / 2 - ESpriteSzYHalf ); sl@0: sl@0: TSize spriteSize(ESpriteSzX, ESpriteSzY); sl@0: sl@0: TRect spriteRect ( TPoint(0,0), spriteSize ); sl@0: sl@0: TRect destRect( spritePos, spriteSize ); sl@0: destRect.Move(iSpriteDef[slideNo].iOffset); sl@0: sl@0: aGc->DrawBitmapMasked( destRect, sl@0: iSpriteContent[slideNo], sl@0: spriteRect, sl@0: iSpriteMask[slideNo], sl@0: EFalse); sl@0: sl@0: // inherited sl@0: CCompWin::DrawBitmap(aGc, aClip, aOrigin); sl@0: } sl@0: sl@0: void CSpritedWin::ClearBitmapBackground(CFbsBitGc* aGc, TRect& aClip, TPoint& aOrigin) sl@0: { sl@0: if (iSpriteStartup == 0) sl@0: { sl@0: //although bitmap drawing requested, sprite was not yet rendered - skip sl@0: return; sl@0: } sl@0: CCompWin::ClearBitmapBackground(aGc, aClip, aOrigin); sl@0: } sl@0: sl@0: void CSpritedWin::SetSize(const TSize & aSize) sl@0: { sl@0: CCompWin::SetSize( aSize ); sl@0: sl@0: if ( iConstructed ) sl@0: { sl@0: TPoint spritePos( iSize.iWidth / 2 - ESpriteSzXHalf, sl@0: iSize.iHeight / 2 - ESpriteSzYHalf ); sl@0: sl@0: iSprite.SetPosition( spritePos ); sl@0: } sl@0: if (iForeWin) sl@0: { sl@0: iForeWin->SetExtent(TPoint(iPos.iX-sInvisibleFrame, iPos.iY-sInvisibleFrame), sl@0: TSize(iSize.iWidth+2*sInvisibleFrame, iSize.iHeight+2*sInvisibleFrame)); sl@0: } sl@0: } sl@0: sl@0: void CSpritedWin::SetPos(const TPoint & aPos) sl@0: { sl@0: CCompWin::SetPos( aPos ); sl@0: if (iForeWin) sl@0: { sl@0: iForeWin->SetPosition(TPoint(iPos.iX-sInvisibleFrame, iPos.iY-sInvisibleFrame)); sl@0: } sl@0: } sl@0: sl@0: CSpritedWin::CSpritedWin(RWsSession& aWs, RWindowGroup* aGroup, CCompWin* aParent, CWindowGc& aGc): sl@0: CCompWin( aWs, aGroup, aParent, aGc ), iSprite ( aWs ), iForeWin(NULL) sl@0: { sl@0: iBgColor = TRnd::rnd(); sl@0: if (!iTransparent) sl@0: { sl@0: iBgColor.SetAlpha(255); sl@0: } sl@0: iSlideDuration = (TRnd::rnd( ESlideDurMaxTenthSec ) + 1) * ESlideDurMult; sl@0: sl@0: HAL::Get( HAL::ENanoTickPeriod, iKernelTicksPeriod ); sl@0: sl@0: } sl@0: sl@0: void CSpritedWin::ConstructL() sl@0: { sl@0: // prepare surface sl@0: CCompWin::PreConstructL(iTransparent); sl@0: sl@0: TInt idx, err = KErrNone; sl@0: TRect rect; sl@0: CGraphicsContext* gCtxSpr = NULL; sl@0: CGraphicsContext* gCtxMsk = NULL; sl@0: sl@0: // init sprite handles sl@0: TPoint spritePos( iSize.iWidth / 2 - ESpriteSzXHalf, sl@0: iSize.iHeight / 2 - ESpriteSzYHalf ); sl@0: err = iSprite.Construct( *iWindow, spritePos, ESpriteNoChildClip ); sl@0: User::LeaveIfError( err ); sl@0: sl@0: iPenStyle = iRandomizePenStyle ? GetRandomPenStyle() : CGraphicsContext::ESolidPen; sl@0: iBrushStyle = iRandomizeBrushStyle ? GetRandomBrushStyle() : CGraphicsContext::ESolidBrush; sl@0: iDrawMode = iRandomizeDrawMode ? GetRandomDrawMode() : CGraphicsContext::EDrawModePEN; sl@0: sl@0: TInt stepx = iMaxRandomStepX > 0 ? TRnd::rnd(2*iMaxRandomStepX) - iMaxRandomStepX : 0; sl@0: TInt stepy = iMaxRandomStepY > 0 ? TRnd::rnd(2*iMaxRandomStepY) - iMaxRandomStepY : 0; sl@0: TInt offsetx = iMaxRandomOffsetX > 0 ? TRnd::rnd(2*iMaxRandomOffsetX) - iMaxRandomOffsetX : 0; sl@0: TInt offsety = iMaxRandomOffsetY > 0 ? TRnd::rnd(2*iMaxRandomOffsetY) - iMaxRandomOffsetY : 0; sl@0: sl@0: // create sprites & masks sl@0: for ( idx = 0; idx < ENofSlides; idx++) sl@0: { sl@0: iSpriteContent[idx] = new (ELeave) CFbsBitmap(); sl@0: iSpriteMask[idx] = new (ELeave) CFbsBitmap();; sl@0: sl@0: err = iSpriteContent[idx]->Create(TSize(ESpriteSzX,ESpriteSzY), EColor64K); sl@0: User::LeaveIfError( err ); sl@0: sl@0: err = iSpriteMask[idx]->Create(TSize(ESpriteSzX,ESpriteSzY), EColor64K); sl@0: User::LeaveIfError( err ); sl@0: sl@0: iSpriteCntDevice [idx] = CFbsBitmapDevice::NewL (iSpriteContent[idx]); sl@0: iSpriteMskDevice [idx] = CFbsBitmapDevice::NewL (iSpriteMask[idx]); sl@0: sl@0: sl@0: // draw sprite content sl@0: err = iSpriteCntDevice[idx]->CreateContext( gCtxSpr ); sl@0: User::LeaveIfError( err ); sl@0: CleanupStack::PushL( gCtxSpr ); sl@0: sl@0: err = iSpriteMskDevice[idx]->CreateContext( gCtxMsk ); sl@0: User::LeaveIfError( err ); sl@0: CleanupStack::PushL( gCtxMsk ); sl@0: sl@0: gCtxSpr->SetPenStyle(CGraphicsContext::ESolidPen); sl@0: gCtxSpr->SetPenColor(KRgbWhite); sl@0: gCtxSpr->SetBrushColor(KRgbWhite); sl@0: gCtxSpr->SetBrushStyle( iBrushStyle ); sl@0: sl@0: gCtxMsk->SetPenStyle(CGraphicsContext::ESolidPen); sl@0: gCtxMsk->SetPenColor(KRgbBlack); sl@0: gCtxMsk->SetBrushColor(KRgbBlack); sl@0: gCtxMsk->SetBrushStyle( CGraphicsContext::ESolidBrush ); sl@0: sl@0: rect.SetRect( 0, 0, ESpriteSzX, ESpriteSzY ); sl@0: gCtxSpr->DrawRect( rect ); sl@0: gCtxMsk->DrawRect( rect ); sl@0: sl@0: // cross mask sl@0: gCtxMsk->SetBrushColor(KRgbWhite); sl@0: gCtxMsk->SetPenColor(KRgbWhite); sl@0: rect.SetRect( ESpriteSzXHalf - EStepWidth * (idx + 1), 0, sl@0: ESpriteSzXHalf + EStepWidth * (idx + 1), ESpriteSzY ); sl@0: gCtxMsk->DrawRect( rect ); sl@0: rect.SetRect( 0, ESpriteSzYHalf - EStepHeight * (idx + 1), sl@0: ESpriteSzX, ESpriteSzYHalf + EStepHeight * (idx + 1) ); sl@0: gCtxMsk->DrawRect( rect ); sl@0: sl@0: CleanupStack::PopAndDestroy( gCtxMsk ); sl@0: CleanupStack::PopAndDestroy( gCtxSpr ); sl@0: sl@0: // make sprite sl@0: iSpriteDef[idx].iBitmap = iSpriteContent[idx]; sl@0: iSpriteDef[idx].iMaskBitmap = iSpriteMask[idx]; sl@0: iSpriteDef[idx].iOffset = TPoint( offsetx+idx*stepx, offsety+idx*stepy ); sl@0: iSpriteDef[idx].iDrawMode = CGraphicsContext::EDrawModeAND; sl@0: iSpriteDef[idx].iInvertMask = EFalse; sl@0: iSpriteDef[idx].iInterval = iSlideDuration; sl@0: sl@0: err = iSprite.AppendMember( iSpriteDef[idx] ); sl@0: User::LeaveIfError( err ); sl@0: } sl@0: sl@0: //Create a transparent foreground window, moving and resizing with the sprite window sl@0: if (iTransparentForegroundWindow) sl@0: { sl@0: iForeWin = new(ELeave) RBlankWindow(iWs); sl@0: iForeWin->Construct(*iGroup,reinterpret_cast(iForeWin)); sl@0: iForeWin->SetColor(TRgb(0, 0, 0, 0)); //a transparent window sl@0: iForeWin->SetExtent(TPoint(iPos.iX-sInvisibleFrame, iPos.iY-sInvisibleFrame), sl@0: TSize(iSize.iWidth+2*sInvisibleFrame, iSize.iHeight+2*sInvisibleFrame)); sl@0: iForeWin->SetOrdinalPosition(0); sl@0: iForeWin->Activate(); sl@0: } sl@0: sl@0: // finally sl@0: CCompWin::PostConstructL(); sl@0: sl@0: iSpriteStartup = 0; sl@0: // show up the sprite sl@0: err = iSprite.Activate(); sl@0: User::LeaveIfError( err ); sl@0: sl@0: iConstructed = ETrue; sl@0: } sl@0: sl@0: TBool CSpritedWin::QueryReadyForVerification() sl@0: { sl@0: sl@0: TBool res; sl@0: sl@0: // time (in ticks) passed since sprite activation sl@0: TUint64 delta = TTickUtils::CalcTickDelta( iVerifyTick, iSpriteStartup ); sl@0: // time for a single slide (in microseconds) sl@0: TUint slideDur = iSlideDuration.Int(); sl@0: // time for all sprite slides (in microseconds) sl@0: TUint spriteDur = slideDur * ENofSlides; sl@0: // time passed since begining of sprite sequence (in microseconds) sl@0: TUint64 sense = (delta * iKernelTicksPeriod ) % spriteDur; // microsec sl@0: sl@0: res = (sense >= EFrameBorderSenseMs); sl@0: sl@0: res = res && CCompWin::QueryReadyForVerification(); sl@0: sl@0: return res; sl@0: } sl@0: sl@0: void CSpritedWin::DumpDetails(RFile& aFile, TInt aDepth) sl@0: { sl@0: TBuf8<256> buf; sl@0: buf.SetLength(0); sl@0: for (TInt d = 0; d < aDepth; ++d) sl@0: { sl@0: buf.Append(_L8(" ")); sl@0: } sl@0: buf.Append(_L8("Transparent = [")); sl@0: buf.AppendNum((TInt64)iTransparent); sl@0: buf.Append(_L8("] pen_style = [")); sl@0: buf.AppendNum((TInt64)iPenStyle); sl@0: buf.Append(_L8("] brush_style = [")); sl@0: buf.AppendNum((TInt64)iBrushStyle); sl@0: buf.Append(_L8("] draw_mode = [")); sl@0: buf.AppendNum((TInt64)iDrawMode); sl@0: buf.Append(_L8("] transparent_foreground_window = [")); sl@0: buf.AppendNum((TInt64)iTransparentForegroundWindow); sl@0: buf.Append(_L8("] max_random_step_x = [")); sl@0: buf.AppendNum((TInt64)iMaxRandomStepX); sl@0: buf.Append(_L8("] max_random_step_y = [")); sl@0: buf.AppendNum((TInt64)iMaxRandomStepY); sl@0: buf.Append(_L8("] max_random_offset_x = [")); sl@0: buf.AppendNum((TInt64)iMaxRandomOffsetX); sl@0: buf.Append(_L8("] max_random_offset_y = [")); sl@0: buf.AppendNum((TInt64)iMaxRandomOffsetY); sl@0: buf.Append(_L8("]\r\n")); sl@0: aFile.Write(buf); sl@0: }