1 /* |
|
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 /** |
|
19 @test |
|
20 @internalComponent |
|
21 |
|
22 This contains CT_DataGraphicsContext |
|
23 */ |
|
24 |
|
25 #include "T_DataBitmapContext.h" |
|
26 #include "T_GraphicsUtil.h" |
|
27 |
|
28 /*@{*/ |
|
29 /// Commands |
|
30 _LIT(KCmdAlphaBlendBitmaps, "AlphaBlendBitmaps"); |
|
31 _LIT(KCmdBitBlt, "BitBlt"); |
|
32 _LIT(KCmdBitBltMasked, "BitBltMasked"); |
|
33 _LIT(KCmdClear, "Clear"); |
|
34 _LIT(KCmdCopyRect, "CopyRect"); |
|
35 _LIT(KCmdSetFaded, "SetFaded"); |
|
36 _LIT(KCmdSetFadingParameters, "SetFadingParameters"); |
|
37 |
|
38 /// Fields |
|
39 _LIT(KFldAlphaBmp, "alphabmp"); |
|
40 _LIT(KFldAlphaPt, "alphapt"); |
|
41 _LIT(KFldBitmap, "bitmap"); |
|
42 _LIT(KFldBlackMap, "blackmap"); |
|
43 _LIT(KFldDestination, "destination"); |
|
44 _LIT(KFldDestPt, "destpt"); |
|
45 _LIT(KFldFaded, "faded"); |
|
46 _LIT(KFldInvertMask, "invertmask"); |
|
47 _LIT(KFldMaskBitmap, "maskbitmap"); |
|
48 _LIT(KFldOffset, "offset"); |
|
49 _LIT(KFldPoint, "point"); |
|
50 _LIT(KFldRect, "rect"); |
|
51 _LIT(KFldSource, "source"); |
|
52 _LIT(KFldSourceRect, "sourcerect"); |
|
53 _LIT(KFldSrcBmp, "srcbmp"); |
|
54 _LIT(KFldSrcRect, "srcrect"); |
|
55 _LIT(KFldSrcWsBmp, "srcwsbmp"); |
|
56 _LIT(KFldWhiteMap, "whitemap"); |
|
57 |
|
58 /// Logging |
|
59 _LIT(KLogError, "Error=%d"); |
|
60 _LIT(KLogMissingParameter, "Missing parameter '%S'"); |
|
61 /*@}*/ |
|
62 |
|
63 /** |
|
64 * Constructor. First phase construction |
|
65 */ |
|
66 CT_DataBitmapContext::CT_DataBitmapContext() |
|
67 : CT_DataGraphicsContext() |
|
68 { |
|
69 } |
|
70 |
|
71 /** |
|
72 * Process a command read from the ini file |
|
73 * |
|
74 * @param aDataWrapper test step requiring command to be processed |
|
75 * @param aCommand the command to process |
|
76 * @param aSection the entry in the ini file requiring the command to be processed |
|
77 * |
|
78 * @return ETrue if the command is processed |
|
79 */ |
|
80 TBool CT_DataBitmapContext::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex) |
|
81 { |
|
82 TBool ret=ETrue; |
|
83 if ( aCommand==KCmdAlphaBlendBitmaps ) |
|
84 { |
|
85 DoCmdAlphaBlendBitmapsL(aSection); |
|
86 } |
|
87 else if ( aCommand==KCmdBitBlt ) |
|
88 { |
|
89 DoCmdBitBltL(aSection); |
|
90 } |
|
91 else if ( aCommand==KCmdBitBltMasked ) |
|
92 { |
|
93 DoCmdBitBltMaskedL(aSection); |
|
94 } |
|
95 else if ( aCommand==KCmdClear ) |
|
96 { |
|
97 DoCmdClear(aSection); |
|
98 } |
|
99 else if ( aCommand==KCmdCopyRect ) |
|
100 { |
|
101 DoCmdCopyRect(aSection); |
|
102 } |
|
103 else if ( aCommand==KCmdSetFaded ) |
|
104 { |
|
105 DoCmdSetFaded(aSection); |
|
106 } |
|
107 else if ( aCommand==KCmdSetFadingParameters ) |
|
108 { |
|
109 DoCmdSetFadingParameters(aSection); |
|
110 } |
|
111 else |
|
112 { |
|
113 ret=CT_DataGraphicsContext::DoCommandL(aCommand, aSection, aAsyncErrorIndex); |
|
114 } |
|
115 |
|
116 return ret; |
|
117 } |
|
118 |
|
119 void CT_DataBitmapContext::DoCmdAlphaBlendBitmapsL(const TDesC& aSection) |
|
120 { |
|
121 TBool dataOk=ETrue; |
|
122 |
|
123 TPoint destinationPoint; |
|
124 if ( !GetPointFromConfig(aSection, KFldDestPt, destinationPoint) ) |
|
125 { |
|
126 dataOk=EFalse; |
|
127 ERR_PRINTF2(KLogMissingParameter, &KFldDestPt()); |
|
128 SetBlockResult(EFail); |
|
129 } |
|
130 |
|
131 TRect sourceRect; |
|
132 if ( !GetRectFromConfig(aSection, KFldSrcRect, sourceRect) ) |
|
133 { |
|
134 dataOk=EFalse; |
|
135 ERR_PRINTF2(KLogMissingParameter, &KFldSrcRect()); |
|
136 SetBlockResult(EFail); |
|
137 } |
|
138 |
|
139 TPoint alphaPoint; |
|
140 if ( !GetPointFromConfig(aSection, KFldAlphaPt, alphaPoint) ) |
|
141 { |
|
142 dataOk=EFalse; |
|
143 ERR_PRINTF2(KLogMissingParameter, &KFldAlphaPt()); |
|
144 SetBlockResult(EFail); |
|
145 } |
|
146 |
|
147 if ( dataOk ) |
|
148 { |
|
149 TInt err=KErrNone; |
|
150 |
|
151 CWsBitmap* wsBitmap=NULL; |
|
152 if ( CT_GraphicsUtil::GetWsBitmapL(*this, aSection, KFldSrcWsBmp, wsBitmap) ) |
|
153 { |
|
154 CWsBitmap* alphaBitmap=NULL; |
|
155 if ( !CT_GraphicsUtil::GetWsBitmapL(*this, aSection, KFldAlphaBmp, alphaBitmap) ) |
|
156 { |
|
157 ERR_PRINTF2(KLogMissingParameter, &KFldAlphaBmp()); |
|
158 SetBlockResult(EFail); |
|
159 } |
|
160 else |
|
161 { |
|
162 INFO_PRINTF1(_L("execute AlphaBlendBitmaps(TPoint, CWsBitmap*, TRect, CWsBitmap*, TPoint)")); |
|
163 err=GetBitmapContext()->AlphaBlendBitmaps(destinationPoint, wsBitmap, sourceRect, alphaBitmap, alphaPoint); |
|
164 } |
|
165 } |
|
166 else |
|
167 { |
|
168 CFbsBitmap* fbsBitmap=NULL; |
|
169 if ( CT_GraphicsUtil::GetFbsBitmapL(*this, aSection, KFldSrcBmp, fbsBitmap) ) |
|
170 { |
|
171 CFbsBitmap* alphaBitmap=NULL; |
|
172 if ( !CT_GraphicsUtil::GetFbsBitmapL(*this, aSection, KFldAlphaBmp, alphaBitmap) ) |
|
173 { |
|
174 ERR_PRINTF2(KLogMissingParameter, &KFldAlphaBmp()); |
|
175 SetBlockResult(EFail); |
|
176 } |
|
177 else |
|
178 { |
|
179 INFO_PRINTF1(_L("execute AlphaBlendBitmaps(TPoint, CFbsBitmap*, TRect, CFbsBitmap*, TPoint)")); |
|
180 err=GetBitmapContext()->AlphaBlendBitmaps(destinationPoint, fbsBitmap, sourceRect, alphaBitmap, alphaPoint); |
|
181 } |
|
182 } |
|
183 else |
|
184 { |
|
185 ERR_PRINTF2(KLogMissingParameter, &KFldSrcWsBmp()); |
|
186 ERR_PRINTF2(KLogMissingParameter, &KFldSrcBmp()); |
|
187 SetBlockResult(EFail); |
|
188 } |
|
189 } |
|
190 if ( err!=KErrNone ) |
|
191 { |
|
192 ERR_PRINTF2(KLogError, err); |
|
193 SetError(err); |
|
194 } |
|
195 } |
|
196 } |
|
197 |
|
198 void CT_DataBitmapContext::DoCmdBitBltL(const TDesC& aSection) |
|
199 { |
|
200 TBool dataOk=ETrue; |
|
201 |
|
202 CFbsBitmap* bitmap=NULL; |
|
203 if ( !CT_GraphicsUtil::GetFbsBitmapL(*this, aSection, KFldBitmap, bitmap) ) |
|
204 { |
|
205 dataOk=EFalse; |
|
206 ERR_PRINTF2(KLogMissingParameter, &KFldBitmap()); |
|
207 SetBlockResult(EFail); |
|
208 } |
|
209 |
|
210 TPoint point; |
|
211 if ( GetPointFromConfig(aSection, KFldPoint, point) ) |
|
212 { |
|
213 if ( dataOk ) |
|
214 { |
|
215 // Execute command and log parameters |
|
216 INFO_PRINTF1(_L("execute BitBlt(TPoint, CFbsBitmap*)")); |
|
217 GetBitmapContext()->BitBlt(point, bitmap); |
|
218 } |
|
219 } |
|
220 else |
|
221 { |
|
222 TPoint destination; |
|
223 if ( !GetPointFromConfig(aSection, KFldDestination, destination) ) |
|
224 { |
|
225 dataOk=EFalse; |
|
226 ERR_PRINTF2(KLogMissingParameter, &KFldDestination()); |
|
227 SetBlockResult(EFail); |
|
228 } |
|
229 |
|
230 TRect source; |
|
231 if ( !GetRectFromConfig(aSection, KFldSource, source) ) |
|
232 { |
|
233 dataOk=EFalse; |
|
234 ERR_PRINTF2(KLogMissingParameter, &KFldSource()); |
|
235 SetBlockResult(EFail); |
|
236 } |
|
237 |
|
238 if ( dataOk ) |
|
239 { |
|
240 // Execute command and log parameters |
|
241 INFO_PRINTF1(_L("execute BitBlt(TRect, CFbsBitmap*, TRect)")); |
|
242 GetBitmapContext()->BitBlt(destination, bitmap, source); |
|
243 } |
|
244 } |
|
245 } |
|
246 |
|
247 void CT_DataBitmapContext::DoCmdBitBltMaskedL(const TDesC& aSection) |
|
248 { |
|
249 TBool dataOk=ETrue; |
|
250 |
|
251 // Get test data for command input parameter(s) |
|
252 TPoint point; |
|
253 if ( !GetPointFromConfig(aSection, KFldPoint, point) ) |
|
254 { |
|
255 dataOk=EFalse; |
|
256 ERR_PRINTF2(KLogMissingParameter, &KFldPoint()); |
|
257 SetBlockResult(EFail); |
|
258 } |
|
259 |
|
260 TRect sourceRect; |
|
261 if ( !GetRectFromConfig(aSection, KFldSourceRect, sourceRect) ) |
|
262 { |
|
263 dataOk=EFalse; |
|
264 ERR_PRINTF2(KLogMissingParameter, &KFldSourceRect()); |
|
265 SetBlockResult(EFail); |
|
266 } |
|
267 |
|
268 TBool invertMask; |
|
269 if ( !GetBoolFromConfig(aSection, KFldInvertMask, invertMask) ) |
|
270 { |
|
271 dataOk=EFalse; |
|
272 ERR_PRINTF2(KLogMissingParameter, &KFldInvertMask()); |
|
273 SetBlockResult(EFail); |
|
274 } |
|
275 |
|
276 CFbsBitmap* bitmap=NULL; |
|
277 if ( !CT_GraphicsUtil::GetFbsBitmapL(*this, aSection, KFldBitmap, bitmap) ) |
|
278 { |
|
279 dataOk=EFalse; |
|
280 ERR_PRINTF2(KLogMissingParameter, &KFldBitmap()); |
|
281 SetBlockResult(EFail); |
|
282 } |
|
283 |
|
284 if ( dataOk ) |
|
285 { |
|
286 CFbsBitmap* maskBitmap=NULL; |
|
287 CT_GraphicsUtil::GetFbsBitmapL(*this, aSection, KFldMaskBitmap, maskBitmap); |
|
288 |
|
289 // Execute command and log parameters |
|
290 INFO_PRINTF1(_L("execute BitBltMasked(TPoint, CFbsBitmap*, TRect, CFbsBitmap*, TBool)")); |
|
291 GetBitmapContext()->BitBltMasked(point, bitmap, sourceRect, maskBitmap, invertMask); |
|
292 } |
|
293 } |
|
294 |
|
295 void CT_DataBitmapContext::DoCmdClear(const TDesC& aSection) |
|
296 { |
|
297 // Get test data for command input parameter(s) |
|
298 TRect rect; |
|
299 if ( GetRectFromConfig(aSection, KFldRect, rect) ) |
|
300 { |
|
301 // Execute command and log parameters |
|
302 INFO_PRINTF1(_L("execute Clear(TRect)")); |
|
303 GetBitmapContext()->Clear(rect); |
|
304 } |
|
305 else |
|
306 { |
|
307 // Execute command and log parameters |
|
308 INFO_PRINTF1(_L("execute Clear()")); |
|
309 GetBitmapContext()->Clear(); |
|
310 } |
|
311 } |
|
312 |
|
313 void CT_DataBitmapContext::DoCmdCopyRect(const TDesC& aSection) |
|
314 { |
|
315 TBool dataOk=ETrue; |
|
316 |
|
317 // Get test data for command input parameter(s) |
|
318 TPoint offset; |
|
319 if ( !GetPointFromConfig(aSection, KFldOffset, offset) ) |
|
320 { |
|
321 dataOk=EFalse; |
|
322 ERR_PRINTF2(KLogMissingParameter, &KFldOffset()); |
|
323 SetBlockResult(EFail); |
|
324 } |
|
325 |
|
326 TRect rect; |
|
327 if ( !GetRectFromConfig(aSection, KFldRect, rect) ) |
|
328 { |
|
329 dataOk=EFalse; |
|
330 ERR_PRINTF2(KLogMissingParameter, &KFldRect()); |
|
331 SetBlockResult(EFail); |
|
332 } |
|
333 |
|
334 if ( dataOk ) |
|
335 { |
|
336 // Execute command and log parameters |
|
337 INFO_PRINTF1(_L("execute CopyRect(TPoint, TRect)")); |
|
338 GetBitmapContext()->CopyRect(offset, rect); |
|
339 } |
|
340 } |
|
341 |
|
342 void CT_DataBitmapContext::DoCmdSetFaded(const TDesC& aSection) |
|
343 { |
|
344 TBool faded=ETrue; |
|
345 if( !GetBoolFromConfig(aSection, KFldFaded(), faded)) |
|
346 { |
|
347 ERR_PRINTF2(KLogMissingParameter, &KFldFaded()); |
|
348 SetBlockResult(EFail); |
|
349 } |
|
350 else |
|
351 { |
|
352 // Execute command and log parameters |
|
353 INFO_PRINTF1(_L("execute SetFaded(TBool)")); |
|
354 GetBitmapContext()->SetFaded(faded); |
|
355 } |
|
356 } |
|
357 |
|
358 void CT_DataBitmapContext::DoCmdSetFadingParameters(const TDesC& aSection) |
|
359 { |
|
360 TBool dataOk=ETrue; |
|
361 |
|
362 TInt blackMap=0; |
|
363 if( !GetIntFromConfig(aSection, KFldBlackMap(), blackMap) ) |
|
364 { |
|
365 dataOk=EFalse; |
|
366 ERR_PRINTF2(KLogMissingParameter, &KFldBlackMap()); |
|
367 SetBlockResult(EFail); |
|
368 } |
|
369 |
|
370 TInt whiteMap=255; |
|
371 if( !GetIntFromConfig(aSection, KFldWhiteMap(), whiteMap) ) |
|
372 { |
|
373 dataOk=EFalse; |
|
374 ERR_PRINTF2(KLogMissingParameter, &KFldWhiteMap()); |
|
375 SetBlockResult(EFail); |
|
376 } |
|
377 |
|
378 if ( dataOk ) |
|
379 { |
|
380 // Execute command and log parameters |
|
381 INFO_PRINTF1(_L("execute SetFadingParameters(TUint8, TUint8)")); |
|
382 GetBitmapContext()->SetFadingParameters((TUint8)blackMap, (TUint8)whiteMap); |
|
383 } |
|
384 } |
|