|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @internalComponent - Internal Symbian test code |
|
19 */ |
|
20 |
|
21 |
|
22 #include <e32base.h> |
|
23 #include <charconv.h> |
|
24 |
|
25 #include "TestWindows.h" |
|
26 #include "TestEventHandler.h" |
|
27 #include "TestRedrawHandler.h" |
|
28 #include "ActiveWait.h" |
|
29 #include "AnimationTestStep.h" |
|
30 #include "AnimationConfig.h" |
|
31 |
|
32 const TInt KFontHeight = 17; |
|
33 |
|
34 // |
|
35 // Windows: |
|
36 // |
|
37 // Backdrop window: |
|
38 CAnimBackdropWindow::CAnimBackdropWindow(RWsSession& aWsSession, CTestWindowGroup& aGroup, CWindowGc& aGc) : CTestWindow(aWsSession, aGroup, aGc) |
|
39 { |
|
40 } |
|
41 |
|
42 // Output window: |
|
43 CAnimationTestWindow::CAnimationTestWindow(RWsSession& aWsSession, CTestWindowGroup& aGroup, CWindowGc& aGc, CWsScreenDevice& aScreen) : |
|
44 CTestWindow(aWsSession, aGroup, aGc), |
|
45 iScreen(aScreen) |
|
46 { |
|
47 } |
|
48 |
|
49 CAnimationTestWindow::~CAnimationTestWindow() |
|
50 { |
|
51 } |
|
52 |
|
53 void CAnimationTestWindow::DrawL() |
|
54 { |
|
55 if(!iFont) |
|
56 { |
|
57 TFontSpec fspec(_L("Arial"),KFontHeight); |
|
58 User::LeaveIfError(iScreen.GetNearestFontInPixels((CFont *&)iFont, fspec)); |
|
59 } |
|
60 iGc.UseFont(iFont); |
|
61 iGc.SetPenColor(KRgbBlack); |
|
62 TSize size = Window()->Size(); |
|
63 for (TInt i = 0; i < iNumLines; ++i) |
|
64 { |
|
65 iGc.DrawText(iText[(iFirstLine + i) % KMaxLogWinLines], TRect(TPoint(0,i * KFontHeight), size), KFontHeight); |
|
66 } |
|
67 } |
|
68 |
|
69 void CAnimationTestWindow::AppendText(const TDesC& aText) |
|
70 { |
|
71 TInt line = (iFirstLine + iNumLines) % KMaxLogWinLines; |
|
72 if (iNumLines < KMaxLogWinLines) |
|
73 ++iNumLines; |
|
74 else |
|
75 iFirstLine = (iFirstLine + 1) % KMaxLogWinLines; |
|
76 |
|
77 iText[line].Copy(aText.Left(iText[line].MaxLength())); |
|
78 Window()->Invalidate(); |
|
79 } |
|
80 |
|
81 void CAnimationTestWindow::Clear() |
|
82 { |
|
83 iNumLines = 0; |
|
84 Window()->Invalidate(); |
|
85 } |
|
86 |
|
87 // |
|
88 // The test: |
|
89 // |
|
90 CAnimationTestStep::CAnimationTestStep(): |
|
91 iBackgroundColor1(TRgb(0xFF8080)), |
|
92 iBackgroundColor2(TRgb(0xFF0000)) |
|
93 { |
|
94 } |
|
95 |
|
96 CAnimationTestStep::~CAnimationTestStep() |
|
97 { |
|
98 if (iWaiter) |
|
99 { |
|
100 iWaiter->Cancel(); |
|
101 delete iWaiter; |
|
102 } |
|
103 delete iRedrawHandler; |
|
104 delete iEventHandler; |
|
105 delete iAnimTestWin; |
|
106 delete iAnimBackdropWin; |
|
107 delete iGroupWin; |
|
108 delete iGc; |
|
109 iFs.Close(); |
|
110 iWs.Close(); |
|
111 delete iConverter; |
|
112 iColors.Close(); |
|
113 } |
|
114 |
|
115 void CAnimationTestStep::InitialiseL() |
|
116 { |
|
117 iWaiter = CActiveWait::NewL(); |
|
118 |
|
119 User::LeaveIfError(iWs.Connect()); |
|
120 User::LeaveIfError(iFs.Connect()); |
|
121 iScreen = new (ELeave) CWsScreenDevice(iWs); |
|
122 User::LeaveIfError(iScreen->Construct()); |
|
123 iDisplayMode = iScreen->DisplayMode(); |
|
124 iGc = new (ELeave) CWindowGc(iScreen); |
|
125 User::LeaveIfError(iGc->Construct()); |
|
126 |
|
127 iConverter = CCnvCharacterSetConverter::NewL(); |
|
128 iConverterState = CCnvCharacterSetConverter::KStateDefault; |
|
129 iConverter->PrepareToConvertToOrFromL(KCharacterSetIdentifierAscii, iFs); |
|
130 |
|
131 iEventHandler = new (ELeave) CTestEventHandler(iWs); |
|
132 iEventHandler->Start(); |
|
133 iRedrawHandler = new (ELeave) CTestRedrawHandler(iWs); |
|
134 iRedrawHandler->Start(); |
|
135 |
|
136 iGroupWin = new (ELeave) CTestWindowGroup(iWs); |
|
137 |
|
138 // EColor64K is 16bpp in RGB 5-6-5 format, some color might be truncated during conversion |
|
139 // from TRgb to TUint16 |
|
140 // The solution is to convert RGB to RGB565 and back to RGB to allow direct color comparison |
|
141 // with value of drawn pixel on the screen |
|
142 if (iScreen->DisplayMode()==EColor64K) |
|
143 { |
|
144 iBackgroundColor1 = TRgb::Color64K(iBackgroundColor1.Color64K()); |
|
145 iBackgroundColor2 = TRgb::Color64K(iBackgroundColor2.Color64K()); |
|
146 } |
|
147 |
|
148 iStepWinSize = iScreen->SizeInPixels(); |
|
149 iStepWinSize.iWidth /= 2; |
|
150 iAnimTestWin = new (ELeave) CAnimationTestWindow(iWs, *iGroupWin, *iGc, *iScreen); |
|
151 iAnimTestWin->Window()->SetRequiredDisplayMode(EGray2); |
|
152 iAnimTestWin->Window()->SetExtent(TPoint(0,0), iStepWinSize); |
|
153 iAnimTestWin->Window()->SetBackgroundColor(KRgbWhite); |
|
154 iAnimTestWin->Window()->SetVisible(ETrue); |
|
155 iAnimTestWin->Window()->Activate(); |
|
156 |
|
157 iAnimBackdropWin = new (ELeave) CAnimBackdropWindow(iWs, *iGroupWin, *iGc); |
|
158 iAnimBackdropWin->Window()->SetRequiredDisplayMode(EGray2); |
|
159 iAnimBackdropWin->Window()->SetExtent(TPoint(iStepWinSize.iWidth,0), iStepWinSize); |
|
160 iAnimBackdropWin->Window()->SetBackgroundColor(KRgbBlack); |
|
161 iAnimBackdropWin->Window()->SetVisible(ETrue); |
|
162 iAnimBackdropWin->Window()->Activate(); |
|
163 } |
|
164 |
|
165 // This is not a completely safe function, but then this is only a test harness |
|
166 void CAnimationTestStep::Log(const TDesC& aText) |
|
167 { |
|
168 iAnimTestWin->AppendText(aText); |
|
169 } |
|
170 |
|
171 void CAnimationTestStep::ClearLog() |
|
172 { |
|
173 iAnimTestWin->Clear(); |
|
174 } |
|
175 |
|
176 void CAnimationTestStep::Wait(TInt aDelay) |
|
177 { |
|
178 iWaiter->Wait(aDelay); |
|
179 } |
|
180 |
|
181 TBool CAnimationTestStep::RectCompare(const TRect& a, const TRect& b) |
|
182 { |
|
183 if(iScreen->RectCompare(a,b,CWsScreenDevice::EIncludeSprite)) |
|
184 { |
|
185 return ETrue; |
|
186 } |
|
187 else |
|
188 { |
|
189 return EFalse; // This is a good place for a break point |
|
190 } |
|
191 } |
|
192 |
|
193 TInt CAnimationTestStep::CountColorsL(const TRect& aRect, TInt aMin, TInt aMax) |
|
194 { |
|
195 TDisplayMode displayMode = iScreen->DisplayMode(); |
|
196 TInt width = CFbsBitmap::ScanLineLength(aRect.Width(),displayMode); |
|
197 HBufC8* buf=HBufC8::NewMaxLC(width); |
|
198 TPtr8 ptr=buf->Des(); |
|
199 iColors.Reset(); |
|
200 TInt inc = width/aRect.Width(); |
|
201 for (TInt row = aRect.iTl.iY; row < aRect.iBr.iY; ++row) |
|
202 { |
|
203 ptr.SetLength(0); |
|
204 iScreen->GetScanLine(ptr,TPoint(aRect.iTl.iX,row),aRect.Width(),displayMode); |
|
205 for (TInt col = 0; col < ptr.Length(); col+=inc) |
|
206 { |
|
207 TUint clr = ptr[col]; |
|
208 // Pixel buffer represented in block of bytes, if color mode is 8bpp (1byte) we can |
|
209 // simply access the buffer sequentially eg clr = ptr[col], however if the color mode |
|
210 // is 16bpp or more, access must be adjusted accordingly. |
|
211 // The "inc" variable indicates how many bytes each pixel's colour takes |
|
212 // and could be any value from 1 to 4 depending on the color mode. |
|
213 for (TInt byteNumber = 1; byteNumber < inc; byteNumber++) |
|
214 { |
|
215 clr = clr << 8; |
|
216 clr += ptr[col + byteNumber]; |
|
217 } |
|
218 if (iColors.Find(clr) == KErrNotFound) |
|
219 { |
|
220 iColors.Append(clr); |
|
221 } |
|
222 } |
|
223 } |
|
224 TInt count = iColors.Count(); |
|
225 CleanupStack::PopAndDestroy(buf); |
|
226 |
|
227 if (count < aMin) |
|
228 { |
|
229 return (count - aMin); // This is a good place for a break point |
|
230 } |
|
231 else if (count > aMax) |
|
232 { |
|
233 return (count - aMax); // This is a good place for a break point |
|
234 } |
|
235 else |
|
236 { |
|
237 return 0; |
|
238 } |
|
239 |
|
240 } |
|
241 |
|
242 // |
|
243 // Wait till redraws finished // |
|
244 // |
|
245 |
|
246 class CStopTheScheduler : public CAsyncOneShot |
|
247 { |
|
248 public: |
|
249 CStopTheScheduler(TInt aPriority); |
|
250 static CStopTheScheduler* NewL(TInt aPriority); |
|
251 void RunL(); |
|
252 }; |
|
253 |
|
254 CStopTheScheduler* CStopTheScheduler::NewL(TInt aPriority) |
|
255 { |
|
256 return new(ELeave)CStopTheScheduler(aPriority); |
|
257 } |
|
258 |
|
259 CStopTheScheduler::CStopTheScheduler(TInt aPriority) |
|
260 :CAsyncOneShot(aPriority) |
|
261 { |
|
262 } |
|
263 |
|
264 void CStopTheScheduler::RunL() |
|
265 { |
|
266 CActiveScheduler::Stop(); |
|
267 } |
|
268 |
|
269 void CAnimationTestStep::WaitForRedrawsToFinish() |
|
270 { |
|
271 CStopTheScheduler* ps=new CStopTheScheduler(-11); |
|
272 if(ps) |
|
273 { |
|
274 ps->Call(); |
|
275 CActiveScheduler::Start(); |
|
276 delete ps; |
|
277 } |
|
278 } |
|
279 |