|
1 // Copyright (c) 1997-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 #include <bitdev.h> |
|
17 #include <hal.h> |
|
18 #include "TBMP.H" |
|
19 #include "tswitch.h" |
|
20 #include <graphics/fbsdefs.h> |
|
21 |
|
22 |
|
23 CTSwitch::CTSwitch(CTestStep* aStep): |
|
24 CTGraphicsBase(aStep), |
|
25 iBitmap(NULL), |
|
26 iDevice(NULL), |
|
27 iGc(NULL), |
|
28 iAltDevice(NULL), |
|
29 iAltGc(NULL), |
|
30 iSrceBuffer(NULL), |
|
31 iDestBuffer(NULL) |
|
32 { |
|
33 INFO_PRINTF1(_L("")); |
|
34 } |
|
35 |
|
36 CTSwitch::~CTSwitch() |
|
37 { |
|
38 delete iBitmap; |
|
39 delete iDevice; |
|
40 delete iGc; |
|
41 delete iAltDevice; |
|
42 delete iAltGc; |
|
43 delete[] iSrceBuffer; |
|
44 delete[] iDestBuffer; |
|
45 } |
|
46 |
|
47 void CTSwitch::RunTestCaseL(TInt aCurTestCase) |
|
48 { |
|
49 ((CTSwitchStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName); |
|
50 switch(aCurTestCase) |
|
51 { |
|
52 case 1: |
|
53 ((CTSwitchStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0065")); |
|
54 TestL(); |
|
55 break; |
|
56 case 2: |
|
57 ((CTSwitchStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName); |
|
58 ((CTSwitchStep*)iStep)->CloseTMSGraphicsStep(); |
|
59 TestComplete(); |
|
60 break; |
|
61 } |
|
62 ((CTSwitchStep*)iStep)->RecordTestResultL(); |
|
63 } |
|
64 |
|
65 |
|
66 /** |
|
67 @SYMTestCaseID GRAPHICS-BITGDI-0065 |
|
68 |
|
69 @SYMDEF |
|
70 |
|
71 @SYMTestCaseDesc Tests display mode switching |
|
72 |
|
73 @SYMTestPriority normal |
|
74 |
|
75 @SYMTestStatus Implemented |
|
76 |
|
77 @SYMTestActions Creates a bitmap then switches between displaymodes and checks bitmap is not corrupted |
|
78 |
|
79 @SYMTestExpectedResults Test should perform graphics operations succesfully. |
|
80 */ |
|
81 void CTSwitch::TestL() |
|
82 { |
|
83 INFO_PRINTF1(_L("Testing display mode switching")); |
|
84 const TInt KNumDispModes = 12; |
|
85 |
|
86 TDisplayMode displayModeArray[KNumDispModes] = |
|
87 { |
|
88 EGray2, EGray4, EGray16, EGray256, |
|
89 EColor16, EColor256, EColor4K, EColor64K, EColor16M, |
|
90 EColor16MU, EColor16MA, EColor16MAP |
|
91 }; |
|
92 |
|
93 const TPtrC displayModeNameArray[KNumDispModes] = |
|
94 { |
|
95 _L("EGray2"), _L("EGray4"), _L("EGray16"), _L("EGray256"), |
|
96 _L("EColor16"), _L("EColor256"), _L("EColor4K"), _L("EColor64K"), _L("EColor16M"), |
|
97 _L("EColor16MU"), _L("EColor16MA"), _L("EColor16MAP") |
|
98 }; |
|
99 |
|
100 iBitmap = new(ELeave) CFbsBitmap; |
|
101 TInt ret = iBitmap->Load(_L("z:\\system\\data\\tbmp.mbm"),EMbmTbmpTcolor,EFalse); |
|
102 User::LeaveIfError(ret); |
|
103 |
|
104 iSrceBuffer = new(ELeave) TRgb[iBitmap->SizeInPixels().iWidth]; |
|
105 iDestBuffer = new(ELeave) TRgb[iBitmap->SizeInPixels().iWidth]; |
|
106 |
|
107 for (TInt dispModeIndex = 0; dispModeIndex < KNumDispModes; dispModeIndex++) |
|
108 { |
|
109 TDisplayMode dispMode = displayModeArray[dispModeIndex]; |
|
110 if (!SetModeL(dispMode)) |
|
111 continue; |
|
112 |
|
113 INFO_PRINTF1(displayModeNameArray[dispModeIndex]); |
|
114 |
|
115 for (TInt altDispModeIndex = 0; altDispModeIndex < KNumDispModes; altDispModeIndex++) |
|
116 { |
|
117 if (dispModeIndex == altDispModeIndex) |
|
118 continue; |
|
119 |
|
120 FillScreen(); |
|
121 |
|
122 TDisplayMode altDispMode = displayModeArray[altDispModeIndex]; |
|
123 if (SwitchModeL(altDispMode)) |
|
124 { |
|
125 INFO_PRINTF1(displayModeNameArray[altDispModeIndex]); |
|
126 INFO_PRINTF1(_L(" ")); |
|
127 CheckSwitch(dispMode,altDispMode); |
|
128 } |
|
129 else |
|
130 WARN_PRINTF1(_L("Not supported")); |
|
131 } |
|
132 |
|
133 INFO_PRINTF1(_L("\r\n")); |
|
134 } |
|
135 } |
|
136 |
|
137 TBool CTSwitch::SetModeL(TDisplayMode aDispMode) |
|
138 { |
|
139 delete iDevice; |
|
140 iDevice = NULL; |
|
141 delete iGc; |
|
142 iGc = NULL; |
|
143 |
|
144 TRAPD(err,iDevice = CFbsScreenDevice::NewL(_L("scdv"),aDispMode)); |
|
145 if (err == KErrNotSupported) |
|
146 return EFalse; |
|
147 User::LeaveIfError(err); |
|
148 |
|
149 User::LeaveIfError(iDevice->CreateContext((CGraphicsContext*&)iGc)); |
|
150 iDevice->ChangeScreenDevice(NULL); |
|
151 iDevice->SetAutoUpdate(ETrue); |
|
152 |
|
153 return ETrue; |
|
154 } |
|
155 |
|
156 void CTSwitch::FillScreen() |
|
157 { |
|
158 TSize size = iDevice->SizeInPixels(); |
|
159 TSize bmpSize = iBitmap->SizeInPixels(); |
|
160 |
|
161 for (TInt height = 0; height < size.iHeight; height += bmpSize.iHeight) |
|
162 for (TInt width = 0; width < size.iWidth; width += bmpSize.iWidth) |
|
163 iGc->BitBlt(TPoint(width,height),iBitmap); |
|
164 } |
|
165 |
|
166 TBool CTSwitch::SwitchModeL(TDisplayMode aDispMode) |
|
167 { |
|
168 delete iAltDevice; |
|
169 iAltDevice = NULL; |
|
170 delete iAltGc; |
|
171 iAltGc = NULL; |
|
172 |
|
173 TRAPD(err,iAltDevice = CFbsScreenDevice::NewL(_L("scdv"),aDispMode)); |
|
174 if (err == KErrNotSupported) |
|
175 return EFalse; |
|
176 User::LeaveIfError(err); |
|
177 |
|
178 User::LeaveIfError(iAltDevice->CreateContext((CGraphicsContext*&)iAltGc)); |
|
179 iAltDevice->SetAutoUpdate(ETrue); |
|
180 |
|
181 iAltDevice->ChangeScreenDevice(iDevice); |
|
182 |
|
183 return ETrue; |
|
184 } |
|
185 |
|
186 void CTSwitch::CheckSwitch(TDisplayMode aOldDispMode,TDisplayMode aNewDispMode) |
|
187 { |
|
188 TSize size = iDevice->SizeInPixels(); |
|
189 TSize bmpSize = iBitmap->SizeInPixels(); |
|
190 TPtr8 srce((TUint8*)iSrceBuffer,bmpSize.iWidth * sizeof(TRgb),bmpSize.iWidth * sizeof(TRgb)); |
|
191 TPtr8 dest((TUint8*)iDestBuffer,bmpSize.iWidth * sizeof(TRgb),bmpSize.iWidth * sizeof(TRgb)); |
|
192 |
|
193 for (TInt yy = 0; yy < size.iHeight; yy++) |
|
194 { |
|
195 |
|
196 for (TInt xx = 0; xx < size.iWidth; xx += bmpSize.iWidth) |
|
197 { |
|
198 // Width for scanline as wide as bitmap or remaining width of screen, whichever smallest |
|
199 TUint lineWidth = Min(bmpSize.iWidth,size.iWidth - xx); |
|
200 |
|
201 // yy%bmpSize.iHeight used if screen height greater than bitmap |
|
202 // as it is tessellated across the screen |
|
203 iBitmap->GetScanLine(srce,TPoint(00,yy%bmpSize.iHeight),lineWidth,ERgb); |
|
204 iAltDevice->GetScanLine(dest,TPoint(xx,yy),lineWidth,ERgb); |
|
205 CheckBuffers(aOldDispMode,aNewDispMode,lineWidth,(yy * 2 + xx) & 3); // Last parameter is aDitherOffset |
|
206 } |
|
207 } |
|
208 } |
|
209 |
|
210 void CTSwitch::CheckBuffers(TDisplayMode aOldDispMode, TDisplayMode aNewDispMode, TUint aLineWidth,TInt aDitherOffset) |
|
211 { |
|
212 TRgb* srcePtr = iSrceBuffer; |
|
213 TRgb* destPtr = iDestBuffer; |
|
214 |
|
215 for (TUint count = 0; count < aLineWidth; count++) |
|
216 { |
|
217 TRgb srce = *srcePtr++; |
|
218 TRgb dest = *destPtr++; |
|
219 CheckRgbs(aOldDispMode,srce,aNewDispMode,dest,aDitherOffset ^ (count & 1)); |
|
220 } |
|
221 } |
|
222 |
|
223 void CTSwitch::CheckRgbs(TDisplayMode aOldDispMode,TRgb aSrceRgb,TDisplayMode aNewDispMode,TRgb aDestRgb,TInt aDitherOffset) |
|
224 { |
|
225 ConvertRgb(aSrceRgb,aOldDispMode,aDitherOffset); |
|
226 ConvertRgb(aSrceRgb,aNewDispMode,1); // 1 suppresses dithering in EGray2 mode |
|
227 TEST(aSrceRgb == aDestRgb); |
|
228 } |
|
229 |
|
230 void CTSwitch::ConvertRgb(TRgb& aRgb,TDisplayMode aDispMode,TInt aDitherOffset) |
|
231 { |
|
232 switch (aDispMode) |
|
233 { |
|
234 case EGray2: |
|
235 { |
|
236 TInt gray4 = aRgb.Gray4(); |
|
237 if (gray4 == 0) |
|
238 aRgb = KRgbBlack; |
|
239 else if (gray4 == 1) |
|
240 { |
|
241 if (aDitherOffset == 1 || aDitherOffset == 2) |
|
242 aRgb = KRgbBlack; |
|
243 else |
|
244 aRgb = KRgbWhite; |
|
245 } |
|
246 else if (gray4 == 2) |
|
247 { |
|
248 if (aDitherOffset == 3) |
|
249 aRgb = KRgbBlack; |
|
250 else |
|
251 aRgb = KRgbWhite; |
|
252 } |
|
253 else if (gray4 == 3) |
|
254 aRgb = KRgbWhite; |
|
255 } |
|
256 break; |
|
257 case EGray4: |
|
258 aRgb = TRgb::Gray4(aRgb.Gray4()); |
|
259 break; |
|
260 case EGray16: |
|
261 aRgb = TRgb::Gray16(aRgb.Gray16()); |
|
262 break; |
|
263 case EGray256: |
|
264 aRgb = TRgb::Gray256(aRgb.Gray256()); |
|
265 break; |
|
266 case EColor16: |
|
267 aRgb = TRgb::Color16(aRgb.Color16()); |
|
268 break; |
|
269 case EColor256: |
|
270 aRgb = TRgb::Color256(aRgb.Color256()); |
|
271 break; |
|
272 case EColor4K: |
|
273 aRgb = TRgb::Color4K(aRgb.Color4K()); |
|
274 break; |
|
275 case EColor64K: |
|
276 aRgb = TRgb::Color64K(aRgb.Color64K()); |
|
277 break; |
|
278 default: |
|
279 break; |
|
280 } |
|
281 } |
|
282 |
|
283 //-------------- |
|
284 __CONSTRUCT_STEP__(Switch) |
|
285 |
|
286 void CTSwitchStep::TestSetupL() |
|
287 { |
|
288 FbsStartup(); |
|
289 User::LeaveIfError(RFbsSession::Connect()); |
|
290 } |
|
291 |
|
292 void CTSwitchStep::TestClose() |
|
293 { |
|
294 RFbsSession::Disconnect(); |
|
295 } |