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 "animatedwin.h" sl@0: #include "utils.h" sl@0: sl@0: #include "stressanimcmd.h" sl@0: sl@0: #include sl@0: sl@0: sl@0: //static configuration data, definitions and default assignments sl@0: TBool CAnimatedWin::iEnabled = ETrue; sl@0: TBool CAnimatedWin::iTransparent = ETrue; sl@0: TBool CAnimatedWin::iTransparentForegroundWindow = EFalse; sl@0: sl@0: const TInt sInvisibleFrame = 24; //how much bigger the invisible window is sl@0: sl@0: CAnimatedWin* CAnimatedWin::NewLC(RWsSession& aWs, RWindowGroup* aGroup, CCompWin* aParent, CWindowGc& aGc) sl@0: { sl@0: CAnimatedWin* self = new (ELeave) CAnimatedWin( 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 CAnimatedWin::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_WservStressParamTransparentForegroundWindow, iTransparentForegroundWindow); sl@0: } sl@0: sl@0: CAnimatedWin::~CAnimatedWin() sl@0: { sl@0: if (iForeWin) sl@0: { sl@0: iForeWin->Close(); sl@0: delete iForeWin; sl@0: } sl@0: sl@0: if ( iAnim ) sl@0: { sl@0: iAnim->Destroy(); sl@0: } sl@0: iAnimDll.Close(); sl@0: sl@0: TInt idx; sl@0: for ( idx = 0; idx < ENofFrames; idx++) sl@0: { sl@0: delete iAnimCntDevice [idx]; sl@0: delete iAnimContent [idx]; sl@0: } sl@0: sl@0: delete iAnimMskDevice; sl@0: delete iAnimMask; sl@0: } sl@0: sl@0: sl@0: void CAnimatedWin::Redraw(const TRect& aRect) sl@0: { sl@0: iWsGc.Activate(*iWindow); sl@0: sl@0: iRedrawWindow->BeginRedraw( aRect ); sl@0: sl@0: iWsGc.Reset(); sl@0: sl@0: iWsGc.SetPenStyle( CGraphicsContext::ESolidPen ); sl@0: iWsGc.SetBrushStyle( CGraphicsContext::EDiamondCrossHatchBrush ); sl@0: iWsGc.SetBrushColor( iBgColor ); sl@0: iWsGc.SetPenColor( iBgColor ); 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: sl@0: void CAnimatedWin::AppendTime(TDes& aTimeText,const TTime& aTime) const sl@0: { sl@0: _LIT(TimeFormat,"%:0%H%:1%T%:2%S"); sl@0: TRAPD(err,aTime.FormatL(aTimeText,TimeFormat)); sl@0: if (err!=KErrNone) sl@0: { sl@0: _LIT(DummyTime,"######"); sl@0: aTimeText.Append(DummyTime); sl@0: } sl@0: } sl@0: sl@0: sl@0: void CAnimatedWin::DrawBitmap(CFbsBitGc* aGc, TRect& aClip, TPoint& aOrigin) 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 background sl@0: aGc->SetPenStyle(CGraphicsContext::ESolidPen); sl@0: aGc->SetBrushStyle(CGraphicsContext::EDiamondCrossHatchBrush); sl@0: aGc->SetBrushColor( iBgColor ); sl@0: aGc->SetPenColor( iBgColor ); sl@0: aGc->DrawRect(TRect(TPoint(0,0), iSize)); sl@0: sl@0: // draw text sl@0: TBuf<128> timebuf; sl@0: TUint64 elapsedMs = iAnimLastKnownAction * iKernelTicksPeriod; sl@0: TTime restoredTime(elapsedMs); sl@0: AppendTime( timebuf , restoredTime ); sl@0: sl@0: TInt textWidth = iAnimFont->MeasureText( timebuf ); sl@0: TInt textHalf = textWidth / 2; sl@0: sl@0: TInt centerX = iSize.iWidth / 2; sl@0: TInt centerY = iSize.iHeight / 2; sl@0: sl@0: TRect rect(centerX - textHalf, centerY - iAnimFont->AscentInPixels(), sl@0: centerX + textHalf, centerY - iAnimFont->AscentInPixels() + iAnimFont->HeightInPixels()); sl@0: sl@0: aGc->Reset(); sl@0: sl@0: origin = iPos + aOrigin; sl@0: aGc->SetOrigin( origin ); sl@0: clip = TRect( origin, iSize ); sl@0: clip.Intersection( aClip ); sl@0: clip.Move(-origin); sl@0: aGc->SetClippingRect(clip); sl@0: sl@0: aGc->SetBrushStyle(CGraphicsContext::ESolidBrush); sl@0: sl@0: aGc->UseFont(iAnimFont); sl@0: sl@0: aGc->DrawText(timebuf, rect, iAnimFont->AscentInPixels()); sl@0: sl@0: rect.Move(0, iAnimFont->HeightInPixels()); sl@0: aGc->DrawText(timebuf, rect, iAnimFont->AscentInPixels()); sl@0: sl@0: // inherited sl@0: CCompWin::DrawBitmap(aGc, aClip, aOrigin); sl@0: } sl@0: sl@0: void CAnimatedWin::SetSize(const TSize & aSize) sl@0: { sl@0: CCompWin::SetSize( aSize ); 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 CAnimatedWin::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: CAnimatedWin::CAnimatedWin(RWsSession& aWs, RWindowGroup* aGroup, CCompWin* aParent, CWindowGc& aGc): sl@0: CCompWin( aWs, aGroup, aParent, aGc ), iAnimDll( aWs ), iForeWin(NULL) sl@0: { sl@0: iBgColor = TRnd::rnd(); sl@0: sl@0: iFrameDuration = (TRnd::rnd( EFrameDurMaxTenthSec ) + 1) * EFrameDurMult; sl@0: sl@0: HAL::Get( HAL::ENanoTickPeriod, iKernelTicksPeriod ); sl@0: sl@0: } sl@0: sl@0: void CAnimatedWin::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: sl@0: TPoint animPos( iSize.iWidth / 2 - EFrameSzXHalf, sl@0: iSize.iHeight / 2 - EFrameSzYHalf ); sl@0: sl@0: // create anim frames & masks sl@0: for ( idx = 0; idx < ENofFrames; idx++) sl@0: { sl@0: iAnimContent[idx] = new (ELeave) CFbsBitmap(); sl@0: sl@0: err = iAnimContent[idx]->Create( TSize( EFrameSzX , EFrameSzY), EColor64K ); sl@0: User::LeaveIfError( err ); sl@0: sl@0: iAnimCntDevice [idx] = CFbsBitmapDevice::NewL (iAnimContent[idx]); sl@0: } sl@0: sl@0: iAnimMask = new (ELeave) CFbsBitmap(); sl@0: sl@0: err = iAnimMask->Create( TSize( EFrameSzX , EFrameSzY), EColor64K ); sl@0: User::LeaveIfError( err ); sl@0: sl@0: iAnimMskDevice = CFbsBitmapDevice::NewL ( iAnimMask ); sl@0: sl@0: sl@0: CGraphicsContext* gCtxAni = NULL; sl@0: CGraphicsContext* gCtxMsk = NULL; sl@0: // draw frame 1 and mask sl@0: err = iAnimCntDevice [ EFrame1 ]->CreateContext( gCtxAni ); sl@0: User::LeaveIfError( err ); sl@0: CleanupStack::PushL( gCtxAni ); sl@0: sl@0: err = iAnimMskDevice->CreateContext( gCtxMsk ); sl@0: User::LeaveIfError( err ); sl@0: CleanupStack::PushL( gCtxMsk ); sl@0: sl@0: sl@0: gCtxAni->SetBrushColor(KRgbWhite); sl@0: gCtxAni->SetPenColor(KRgbWhite); sl@0: gCtxAni->SetBrushStyle( CGraphicsContext::ESolidBrush ); sl@0: sl@0: gCtxMsk->SetBrushColor(KRgbWhite); sl@0: gCtxMsk->SetPenColor(KRgbWhite); sl@0: gCtxMsk->SetBrushStyle( CGraphicsContext::ESolidBrush ); sl@0: sl@0: rect.SetRect( EFrameSzXHalf - EFrameSzXEgt, 0, EFrameSzXHalf + EFrameSzXEgt, EFrameSzYHalf ); //lint !e656 Arithmetic operation uses (compatible) enum's sl@0: gCtxAni->DrawRect( rect ); sl@0: gCtxMsk->DrawRect( rect ); sl@0: sl@0: rect.SetRect( EFrameSzXHalf - EFrameSzXQtr, EFrameSzYHalf, EFrameSzXHalf + EFrameSzXQtr, EFrameSzY ); //lint !e656 Arithmetic operation uses (compatible) enum's sl@0: gCtxAni->DrawRect( rect ); sl@0: gCtxMsk->DrawRect( rect ); sl@0: sl@0: gCtxAni->SetPenColor(KRgbBlack); sl@0: gCtxAni->DrawLine( TPoint(EFrameSzXHalf,0), TPoint (EFrameSzXHalf,EFrameSzY) ); sl@0: sl@0: sl@0: CleanupStack::PopAndDestroy( gCtxMsk ); sl@0: CleanupStack::PopAndDestroy( gCtxAni ); sl@0: sl@0: // draw frame 2 sl@0: err = iAnimCntDevice [ EFrame2 ]->CreateContext( gCtxAni ); sl@0: User::LeaveIfError( err ); sl@0: CleanupStack::PushL( gCtxAni ); sl@0: sl@0: gCtxAni->SetPenColor(KRgbWhite); sl@0: gCtxAni->DrawLine( TPoint(EFrameSzXHalf,0), TPoint (EFrameSzXHalf,EFrameSzY) ); sl@0: sl@0: CleanupStack::PopAndDestroy( gCtxAni ); sl@0: sl@0: // init font sl@0: err = iAnimMskDevice->GetNearestFontInPixels( iAnimFont, TFontSpec( _L("Roman"), 16 ) ); sl@0: User::LeaveIfError( err ); sl@0: sl@0: // load anim DLL sl@0: err = iAnimDll.Load( KAnimDllName ); sl@0: User::LeaveIfError( err ); sl@0: sl@0: // construct server side anim sl@0: TPckgBuf animParams; sl@0: animParams().pos = animPos; sl@0: animParams().interval = iFrameDuration.Int(); sl@0: animParams().bit1 = iAnimContent[ EFrame1 ]->Handle(); sl@0: animParams().bit2 = iAnimContent[ EFrame2 ]->Handle(); sl@0: animParams().mask = iAnimMask->Handle(); sl@0: animParams().font = iAnimFont->Handle(); sl@0: sl@0: iAnim = new (ELeave) CAnimatedWin::RStressAnim ( iAnimDll ); sl@0: sl@0: err = iAnim->Construct( *iWindow, animParams ); sl@0: User::LeaveIfError( err ); sl@0: sl@0: // finally sl@0: CCompWin::PostConstructL(); sl@0: sl@0: // got time shot when we started sl@0: iAnimStartup = User::NTickCount(); sl@0: sl@0: //Create a transparent foreground window, moving and resizing with the animation 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: iConstructed = ETrue; sl@0: } sl@0: sl@0: void CAnimatedWin::SetAnimPos(const TPoint& aPos) sl@0: { sl@0: TPckgBuf animParams; sl@0: animParams().pos = aPos; sl@0: iAnim->RequestAnimThis( EADllTextPos, animParams ); sl@0: } sl@0: sl@0: TBool CAnimatedWin::QueryReadyForVerification() sl@0: { sl@0: sl@0: TBool res; sl@0: sl@0: TInt32 curTicks = User::NTickCount(); sl@0: sl@0: iAnimLastKnownAction = (TUint32) iAnim->RequestAnimThis( EADllQuerySync ); sl@0: sl@0: TUint64 elapsed = TTickUtils::CalcTickDelta( curTicks, iAnimLastKnownAction ); sl@0: sl@0: TUint64 elapsedMs = elapsed * iKernelTicksPeriod; sl@0: sl@0: res = ( elapsedMs < EWatchMatchGap ); sl@0: sl@0: res = res && CCompWin::QueryReadyForVerification(); sl@0: sl@0: return res; sl@0: } sl@0: sl@0: CAnimatedWin::RStressAnim::RStressAnim (RAnimDll& aAnimDll): sl@0: RAnim( aAnimDll ) sl@0: { } // empty sl@0: sl@0: TInt CAnimatedWin::RStressAnim::Construct(const RWindowBase &aDevice, const TDesC8 &aParams) sl@0: { sl@0: return RAnim::Construct( aDevice, 0, aParams ); sl@0: } sl@0: sl@0: TInt CAnimatedWin::RStressAnim::RequestAnimThis(TInt aOpcode) sl@0: { sl@0: TInt res; sl@0: sl@0: TPckgC params(ETrue); sl@0: sl@0: res = RequestAnimThis( aOpcode, params ); sl@0: sl@0: return res; sl@0: } sl@0: sl@0: TInt CAnimatedWin::RStressAnim::RequestAnimThis(TInt aOpcode, const TDesC8 &aParams) sl@0: { sl@0: TInt res; sl@0: sl@0: res = CommandReply( aOpcode, aParams ); sl@0: sl@0: return res; sl@0: } sl@0: sl@0: void CAnimatedWin::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("] transparent_foreground_window = [")); sl@0: buf.AppendNum((TInt64)iTransparentForegroundWindow); sl@0: buf.Append(_L8("] BgColor = [")); sl@0: buf.AppendNum(iBgColor.Value()); sl@0: buf.Append(_L8("]\r\n")); sl@0: aFile.Write(buf); sl@0: }