Update contrib.
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
22 #include "spritewin.h"
28 //common configuration parameter names
29 _LIT(KT_WservStressParamRandomizeDrawMode, "randomize_draw_mode");
30 _LIT(KT_WservStressParamMaxRandomStepX, "max_random_step_x");
31 _LIT(KT_WservStressParamMaxRandomStepY, "max_random_step_y");
32 _LIT(KT_WservStressParamMaxRandomOffsetX, "max_random_offset_x");
33 _LIT(KT_WservStressParamMaxRandomOffsetY, "max_random_offset_y");
35 //static configuration data, definitions and default assignments
36 TBool CSpritedWin::iEnabled = ETrue;
37 TBool CSpritedWin::iTransparent = ETrue;
38 TBool CSpritedWin::iRandomizePenStyle = EFalse;
39 TBool CSpritedWin::iRandomizeBrushStyle = EFalse;
40 TBool CSpritedWin::iRandomizeDrawMode = EFalse;
41 TBool CSpritedWin::iTransparentForegroundWindow = EFalse;
42 TInt CSpritedWin::iMaxRandomStepX = 0;
43 TInt CSpritedWin::iMaxRandomStepY = 0;
44 TInt CSpritedWin::iMaxRandomOffsetX = 0;
45 TInt CSpritedWin::iMaxRandomOffsetY = 0;
47 const TInt sInvisibleFrame = 24; //how much bigger the invisible window is
50 CSpritedWin* CSpritedWin::NewLC(RWsSession& aWs, RWindowGroup* aGroup, CCompWin* aParent, CWindowGc& aGc)
52 CSpritedWin* self = new (ELeave) CSpritedWin( aWs, aGroup, aParent, aGc );
53 CleanupStack::PushL( self );
59 void CSpritedWin::LoadConfiguration(const MTestStepConfigurationContext* aContext)
61 aContext->GetBool(KT_WservStressParamEnabled, iEnabled);
62 aContext->GetBool(KT_WservStressParamTransparent, iTransparent);
63 aContext->GetBool(KT_WservStressParamRandomizePenStyle, iRandomizePenStyle);
64 aContext->GetBool(KT_WservStressParamRandomizeBrushStyle, iRandomizeBrushStyle);
65 aContext->GetBool(KT_WservStressParamRandomizeDrawMode, iRandomizeDrawMode);
66 aContext->GetBool(KT_WservStressParamTransparentForegroundWindow, iTransparentForegroundWindow);
68 aContext->GetInt(KT_WservStressParamMaxRandomStepX, iMaxRandomStepX);
69 aContext->GetInt(KT_WservStressParamMaxRandomStepY, iMaxRandomStepY);
70 aContext->GetInt(KT_WservStressParamMaxRandomOffsetX, iMaxRandomOffsetX);
71 aContext->GetInt(KT_WservStressParamMaxRandomOffsetY, iMaxRandomOffsetY);
74 CSpritedWin::~CSpritedWin()
85 for ( idx = 0; idx < ENofSlides; idx++)
87 delete iSpriteCntDevice [idx];
88 delete iSpriteMskDevice [idx];
90 delete iSpriteContent[idx];
91 delete iSpriteMask[idx];
95 void CSpritedWin::Redraw(const TRect& aRect)
97 if (iSpriteStartup == 0)
99 //first time getting here should be very close to the sprite activation time
100 iSpriteStartup = User::NTickCount();
102 iWsGc.Activate(*iWindow);
104 iRedrawWindow->BeginRedraw( aRect );
108 //draw rectangle filling window area
109 iWsGc.SetPenStyle( iPenStyle );
110 iWsGc.SetBrushStyle( iBrushStyle );
111 iWsGc.SetBrushColor( iBgColor );
112 iWsGc.SetPenColor( iBgColor );
113 iWsGc.SetDrawMode(iDrawMode);
115 TRect drawRect( TPoint(0,0), iSize );
117 iWsGc.DrawRect( drawRect );
119 iRedrawWindow->EndRedraw();
124 void CSpritedWin::DrawBitmap(CFbsBitGc* aGc, TRect& aClip, TPoint& aOrigin)
126 if (iSpriteStartup == 0)
128 //although bitmap drawing requested, sprite was not yet rendered - skip
132 TPoint origin = iPos + aOrigin;
133 aGc->SetOrigin(origin);
134 TRect clip(origin, iSize);
135 clip.Intersection(aClip);
137 aGc->SetClippingRect(clip);
140 aGc->SetPenStyle(iPenStyle);
141 aGc->SetBrushStyle(iBrushStyle);
142 aGc->SetBrushColor( iBgColor );
143 aGc->SetPenColor( iBgColor );
144 aGc->SetDrawMode(iDrawMode);
145 aGc->DrawRect(TRect(TPoint(0,0), iSize));
147 // emulate sprite, cur frame
148 // time (in ticks) passed since sprite activation
149 TUint64 delta = TTickUtils::CalcTickDelta( iVerifyTick, iSpriteStartup );
150 // time for a single slide (in microseconds)
151 TUint slideDur = iSlideDuration.Int();
153 TInt slideNo = TUint32( ( (delta * iKernelTicksPeriod ) / slideDur ) % ENofSlides );
155 TPoint spritePos( iSize.iWidth / 2 - ESpriteSzXHalf,
156 iSize.iHeight / 2 - ESpriteSzYHalf );
158 TSize spriteSize(ESpriteSzX, ESpriteSzY);
160 TRect spriteRect ( TPoint(0,0), spriteSize );
162 TRect destRect( spritePos, spriteSize );
163 destRect.Move(iSpriteDef[slideNo].iOffset);
165 aGc->DrawBitmapMasked( destRect,
166 iSpriteContent[slideNo],
168 iSpriteMask[slideNo],
172 CCompWin::DrawBitmap(aGc, aClip, aOrigin);
175 void CSpritedWin::ClearBitmapBackground(CFbsBitGc* aGc, TRect& aClip, TPoint& aOrigin)
177 if (iSpriteStartup == 0)
179 //although bitmap drawing requested, sprite was not yet rendered - skip
182 CCompWin::ClearBitmapBackground(aGc, aClip, aOrigin);
185 void CSpritedWin::SetSize(const TSize & aSize)
187 CCompWin::SetSize( aSize );
191 TPoint spritePos( iSize.iWidth / 2 - ESpriteSzXHalf,
192 iSize.iHeight / 2 - ESpriteSzYHalf );
194 iSprite.SetPosition( spritePos );
198 iForeWin->SetExtent(TPoint(iPos.iX-sInvisibleFrame, iPos.iY-sInvisibleFrame),
199 TSize(iSize.iWidth+2*sInvisibleFrame, iSize.iHeight+2*sInvisibleFrame));
203 void CSpritedWin::SetPos(const TPoint & aPos)
205 CCompWin::SetPos( aPos );
208 iForeWin->SetPosition(TPoint(iPos.iX-sInvisibleFrame, iPos.iY-sInvisibleFrame));
212 CSpritedWin::CSpritedWin(RWsSession& aWs, RWindowGroup* aGroup, CCompWin* aParent, CWindowGc& aGc):
213 CCompWin( aWs, aGroup, aParent, aGc ), iSprite ( aWs ), iForeWin(NULL)
215 iBgColor = TRnd::rnd();
218 iBgColor.SetAlpha(255);
220 iSlideDuration = (TRnd::rnd( ESlideDurMaxTenthSec ) + 1) * ESlideDurMult;
222 HAL::Get( HAL::ENanoTickPeriod, iKernelTicksPeriod );
226 void CSpritedWin::ConstructL()
229 CCompWin::PreConstructL(iTransparent);
231 TInt idx, err = KErrNone;
233 CGraphicsContext* gCtxSpr = NULL;
234 CGraphicsContext* gCtxMsk = NULL;
236 // init sprite handles
237 TPoint spritePos( iSize.iWidth / 2 - ESpriteSzXHalf,
238 iSize.iHeight / 2 - ESpriteSzYHalf );
239 err = iSprite.Construct( *iWindow, spritePos, ESpriteNoChildClip );
240 User::LeaveIfError( err );
242 iPenStyle = iRandomizePenStyle ? GetRandomPenStyle() : CGraphicsContext::ESolidPen;
243 iBrushStyle = iRandomizeBrushStyle ? GetRandomBrushStyle() : CGraphicsContext::ESolidBrush;
244 iDrawMode = iRandomizeDrawMode ? GetRandomDrawMode() : CGraphicsContext::EDrawModePEN;
246 TInt stepx = iMaxRandomStepX > 0 ? TRnd::rnd(2*iMaxRandomStepX) - iMaxRandomStepX : 0;
247 TInt stepy = iMaxRandomStepY > 0 ? TRnd::rnd(2*iMaxRandomStepY) - iMaxRandomStepY : 0;
248 TInt offsetx = iMaxRandomOffsetX > 0 ? TRnd::rnd(2*iMaxRandomOffsetX) - iMaxRandomOffsetX : 0;
249 TInt offsety = iMaxRandomOffsetY > 0 ? TRnd::rnd(2*iMaxRandomOffsetY) - iMaxRandomOffsetY : 0;
251 // create sprites & masks
252 for ( idx = 0; idx < ENofSlides; idx++)
254 iSpriteContent[idx] = new (ELeave) CFbsBitmap();
255 iSpriteMask[idx] = new (ELeave) CFbsBitmap();;
257 err = iSpriteContent[idx]->Create(TSize(ESpriteSzX,ESpriteSzY), EColor64K);
258 User::LeaveIfError( err );
260 err = iSpriteMask[idx]->Create(TSize(ESpriteSzX,ESpriteSzY), EColor64K);
261 User::LeaveIfError( err );
263 iSpriteCntDevice [idx] = CFbsBitmapDevice::NewL (iSpriteContent[idx]);
264 iSpriteMskDevice [idx] = CFbsBitmapDevice::NewL (iSpriteMask[idx]);
267 // draw sprite content
268 err = iSpriteCntDevice[idx]->CreateContext( gCtxSpr );
269 User::LeaveIfError( err );
270 CleanupStack::PushL( gCtxSpr );
272 err = iSpriteMskDevice[idx]->CreateContext( gCtxMsk );
273 User::LeaveIfError( err );
274 CleanupStack::PushL( gCtxMsk );
276 gCtxSpr->SetPenStyle(CGraphicsContext::ESolidPen);
277 gCtxSpr->SetPenColor(KRgbWhite);
278 gCtxSpr->SetBrushColor(KRgbWhite);
279 gCtxSpr->SetBrushStyle( iBrushStyle );
281 gCtxMsk->SetPenStyle(CGraphicsContext::ESolidPen);
282 gCtxMsk->SetPenColor(KRgbBlack);
283 gCtxMsk->SetBrushColor(KRgbBlack);
284 gCtxMsk->SetBrushStyle( CGraphicsContext::ESolidBrush );
286 rect.SetRect( 0, 0, ESpriteSzX, ESpriteSzY );
287 gCtxSpr->DrawRect( rect );
288 gCtxMsk->DrawRect( rect );
291 gCtxMsk->SetBrushColor(KRgbWhite);
292 gCtxMsk->SetPenColor(KRgbWhite);
293 rect.SetRect( ESpriteSzXHalf - EStepWidth * (idx + 1), 0,
294 ESpriteSzXHalf + EStepWidth * (idx + 1), ESpriteSzY );
295 gCtxMsk->DrawRect( rect );
296 rect.SetRect( 0, ESpriteSzYHalf - EStepHeight * (idx + 1),
297 ESpriteSzX, ESpriteSzYHalf + EStepHeight * (idx + 1) );
298 gCtxMsk->DrawRect( rect );
300 CleanupStack::PopAndDestroy( gCtxMsk );
301 CleanupStack::PopAndDestroy( gCtxSpr );
304 iSpriteDef[idx].iBitmap = iSpriteContent[idx];
305 iSpriteDef[idx].iMaskBitmap = iSpriteMask[idx];
306 iSpriteDef[idx].iOffset = TPoint( offsetx+idx*stepx, offsety+idx*stepy );
307 iSpriteDef[idx].iDrawMode = CGraphicsContext::EDrawModeAND;
308 iSpriteDef[idx].iInvertMask = EFalse;
309 iSpriteDef[idx].iInterval = iSlideDuration;
311 err = iSprite.AppendMember( iSpriteDef[idx] );
312 User::LeaveIfError( err );
315 //Create a transparent foreground window, moving and resizing with the sprite window
316 if (iTransparentForegroundWindow)
318 iForeWin = new(ELeave) RBlankWindow(iWs);
319 iForeWin->Construct(*iGroup,reinterpret_cast<TUint32>(iForeWin));
320 iForeWin->SetColor(TRgb(0, 0, 0, 0)); //a transparent window
321 iForeWin->SetExtent(TPoint(iPos.iX-sInvisibleFrame, iPos.iY-sInvisibleFrame),
322 TSize(iSize.iWidth+2*sInvisibleFrame, iSize.iHeight+2*sInvisibleFrame));
323 iForeWin->SetOrdinalPosition(0);
324 iForeWin->Activate();
328 CCompWin::PostConstructL();
331 // show up the sprite
332 err = iSprite.Activate();
333 User::LeaveIfError( err );
335 iConstructed = ETrue;
338 TBool CSpritedWin::QueryReadyForVerification()
343 // time (in ticks) passed since sprite activation
344 TUint64 delta = TTickUtils::CalcTickDelta( iVerifyTick, iSpriteStartup );
345 // time for a single slide (in microseconds)
346 TUint slideDur = iSlideDuration.Int();
347 // time for all sprite slides (in microseconds)
348 TUint spriteDur = slideDur * ENofSlides;
349 // time passed since begining of sprite sequence (in microseconds)
350 TUint64 sense = (delta * iKernelTicksPeriod ) % spriteDur; // microsec
352 res = (sense >= EFrameBorderSenseMs);
354 res = res && CCompWin::QueryReadyForVerification();
359 void CSpritedWin::DumpDetails(RFile& aFile, TInt aDepth)
363 for (TInt d = 0; d < aDepth; ++d)
365 buf.Append(_L8(" "));
367 buf.Append(_L8("Transparent = ["));
368 buf.AppendNum((TInt64)iTransparent);
369 buf.Append(_L8("] pen_style = ["));
370 buf.AppendNum((TInt64)iPenStyle);
371 buf.Append(_L8("] brush_style = ["));
372 buf.AppendNum((TInt64)iBrushStyle);
373 buf.Append(_L8("] draw_mode = ["));
374 buf.AppendNum((TInt64)iDrawMode);
375 buf.Append(_L8("] transparent_foreground_window = ["));
376 buf.AppendNum((TInt64)iTransparentForegroundWindow);
377 buf.Append(_L8("] max_random_step_x = ["));
378 buf.AppendNum((TInt64)iMaxRandomStepX);
379 buf.Append(_L8("] max_random_step_y = ["));
380 buf.AppendNum((TInt64)iMaxRandomStepY);
381 buf.Append(_L8("] max_random_offset_x = ["));
382 buf.AppendNum((TInt64)iMaxRandomOffsetX);
383 buf.Append(_L8("] max_random_offset_y = ["));
384 buf.AppendNum((TInt64)iMaxRandomOffsetY);
385 buf.Append(_L8("]\r\n"));