|
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 @test |
|
19 @internalComponent - Internal Symbian test code |
|
20 */ |
|
21 |
|
22 #include "tdrawresource.h" |
|
23 #include <graphics/sgimage.h> |
|
24 #include <graphics/sgutils.h> |
|
25 #include <graphics/directgdidrawablesource.h> |
|
26 #include <graphics/sgresourceinternal.h> |
|
27 #include <graphics/wsdrawresource.h> |
|
28 |
|
29 |
|
30 __WS_CONSTRUCT_STEP__(DrawResource); |
|
31 |
|
32 |
|
33 #if defined(__X86GCC__) |
|
34 extern "C" TInt atexit(void (*function)(void)) |
|
35 { |
|
36 return KErrNone; |
|
37 } |
|
38 #endif |
|
39 |
|
40 // |
|
41 // class CTestWsGraphicsContext |
|
42 // |
|
43 CTestWsGraphicsContext* CTestWsGraphicsContext::NewL(RDirectGdiImageTarget& aTarget) |
|
44 { |
|
45 CTestWsGraphicsContext* self = new(ELeave) CTestWsGraphicsContext; |
|
46 CleanupStack::PushL(self); |
|
47 self->ConstructL(aTarget); |
|
48 CleanupStack::Pop(self); |
|
49 return self; |
|
50 } |
|
51 |
|
52 void CTestWsGraphicsContext::ConstructL(RDirectGdiImageTarget& aTarget) |
|
53 { |
|
54 CDirectGdiDriver* driver = CDirectGdiDriver::Static(); |
|
55 User::LeaveIfNull(driver); |
|
56 iContext = CDirectGdiContext::NewL(*driver); |
|
57 TInt err = iContext->Activate(aTarget); |
|
58 User::LeaveIfError(err); |
|
59 } |
|
60 |
|
61 CTestWsGraphicsContext::~CTestWsGraphicsContext() |
|
62 { |
|
63 delete iContext; |
|
64 } |
|
65 |
|
66 TAny* CTestWsGraphicsContext::ResolveObjectInterface(TUint aTypeId) |
|
67 { |
|
68 switch(aTypeId) |
|
69 { |
|
70 case MWsDrawableSourceProvider::EWsObjectInterfaceId: |
|
71 return static_cast<MWsDrawableSourceProvider*>(this); |
|
72 } |
|
73 return NULL; |
|
74 |
|
75 } |
|
76 |
|
77 TInt CTestWsGraphicsContext::CreateDrawableSource(const TSgDrawableId& aDrawableId, TAny*& aSource) |
|
78 { |
|
79 TRAPD(err, DoCreateDrawableSourceL(aDrawableId, aSource)); |
|
80 return err; |
|
81 } |
|
82 |
|
83 void CTestWsGraphicsContext::DoCreateDrawableSourceL(const TSgDrawableId& aDrawableId, TAny*& aSource) |
|
84 { |
|
85 CDirectGdiDriver* driver = CDirectGdiDriver::Static(); |
|
86 if (!driver) |
|
87 { |
|
88 User::Leave(KErrNotReady); |
|
89 } |
|
90 RDirectGdiDrawableSource* drawableSource = new(ELeave) RDirectGdiDrawableSource(*driver); |
|
91 CleanupStack::PushL(drawableSource); |
|
92 RSgDrawable drawable; |
|
93 User::LeaveIfError(drawable.Open(aDrawableId, ESgDoNotRestrictUsage)); |
|
94 CleanupClosePushL(drawable); |
|
95 User::LeaveIfError(drawableSource->Create(drawable)); |
|
96 CleanupStack::PopAndDestroy(); |
|
97 CleanupStack::Pop(drawableSource); |
|
98 aSource = drawableSource; |
|
99 } |
|
100 |
|
101 void CTestWsGraphicsContext::CloseDrawableSource(TAny* aSource) |
|
102 { |
|
103 RDirectGdiDrawableSource* drawableSource = static_cast<RDirectGdiDrawableSource*>(aSource); |
|
104 drawableSource->Close(); |
|
105 delete drawableSource; |
|
106 } |
|
107 |
|
108 void CTestWsGraphicsContext::DrawResource(const TAny* aSource, const TPoint& aPos, CWindowGc::TGraphicsRotation aRotation) |
|
109 { |
|
110 const RDirectGdiDrawableSource* drawableSource = static_cast<const RDirectGdiDrawableSource*>(aSource); |
|
111 iContext->DrawResource(aPos, *drawableSource, (DirectGdi::TGraphicsRotation)aRotation); |
|
112 iPos = aPos; |
|
113 iRotation = (DirectGdi::TGraphicsRotation)aRotation; |
|
114 } |
|
115 |
|
116 void CTestWsGraphicsContext::DrawResource(const TAny* aSource, const TRect& aRect, CWindowGc::TGraphicsRotation aRotation) |
|
117 { |
|
118 const RDirectGdiDrawableSource* drawableSource = static_cast<const RDirectGdiDrawableSource*>(aSource); |
|
119 iContext->DrawResource(aRect, *drawableSource, (DirectGdi::TGraphicsRotation)aRotation); |
|
120 iDestRect = aRect; |
|
121 iRotation = (DirectGdi::TGraphicsRotation)aRotation; |
|
122 } |
|
123 |
|
124 void CTestWsGraphicsContext::DrawResource(const TAny* aSource, const TRect& aRectDest, const TRect& aRectSrc, CWindowGc::TGraphicsRotation aRotation) |
|
125 { |
|
126 const RDirectGdiDrawableSource* drawableSource = static_cast<const RDirectGdiDrawableSource*>(aSource); |
|
127 iContext->DrawResource(aRectDest, *drawableSource, aRectSrc, (DirectGdi::TGraphicsRotation)aRotation); |
|
128 iDestRect = aRectDest; |
|
129 iSrcRect = aRectSrc; |
|
130 iRotation = (DirectGdi::TGraphicsRotation)aRotation; |
|
131 } |
|
132 |
|
133 void CTestWsGraphicsContext::DrawResource(const TAny* aSource, const TRect& aRect, const TDesC8& aParam) |
|
134 { |
|
135 const RDirectGdiDrawableSource* drawableSource = static_cast<const RDirectGdiDrawableSource*>(aSource); |
|
136 iContext->DrawResource(aRect, *drawableSource, aParam); |
|
137 iDestRect = aRect; |
|
138 } |
|
139 |
|
140 |
|
141 void CTestWsGraphicsContext::Clear() |
|
142 { |
|
143 iContext->Clear(); |
|
144 } |
|
145 |
|
146 // |
|
147 // class CTDrawResource |
|
148 // |
|
149 |
|
150 CTDrawResource::CTDrawResource(CTestStep* aStep) |
|
151 : CTWsGraphicsBase(aStep) |
|
152 { |
|
153 } |
|
154 |
|
155 CTDrawResource::~CTDrawResource() |
|
156 { |
|
157 iWindow.Close(); |
|
158 delete iRefBitmap; |
|
159 delete iRotatedRefBitmap; |
|
160 delete iScaledBitmap; |
|
161 delete iScaledCroppedBitmap; |
|
162 delete iCopyBitmap; |
|
163 delete iBitmapWrongScreenNumber; |
|
164 |
|
165 delete iWsGrapicResolver; |
|
166 delete iGraphicsCon; |
|
167 |
|
168 iWsDrawableSource.Close(); |
|
169 iImage.Close(); |
|
170 iImageTarget.Close(); |
|
171 iImageCollection.Close(); |
|
172 |
|
173 CDirectGdiDriver* dGdiDriver = CDirectGdiDriver::Static(); |
|
174 if(dGdiDriver) |
|
175 { |
|
176 dGdiDriver->Close(); |
|
177 } |
|
178 SgDriver::Close(); |
|
179 } |
|
180 |
|
181 void CTDrawResource::ConstructL() |
|
182 { |
|
183 //Constrcut and setup window to be drawn to |
|
184 iWindow = RWindow(TheClient->iWs); |
|
185 User::LeaveIfError(iWindow.Construct(*TheClient->iGroup->GroupWin(),ENullWsHandle)); |
|
186 TSize iWinSize=TSize(TheClient->iScreen->SizeInPixels()); |
|
187 iWindow.SetExtent(TPoint(0,0),iWinSize); |
|
188 iWindow.Activate(); |
|
189 iWindow.BeginRedraw(); |
|
190 iWindow.EndRedraw(); |
|
191 |
|
192 //Creates all reference and copy bitmaps required for all tests |
|
193 CreateReferenceAndCopyBitmapsL(); |
|
194 |
|
195 TInt err = CDirectGdiDriver::Open(); |
|
196 User::LeaveIfError(err); |
|
197 err = SgDriver::Open(); |
|
198 User::LeaveIfError(err); |
|
199 |
|
200 //create image target |
|
201 CDirectGdiDriver* theDGdiDriver = CDirectGdiDriver::Static(); |
|
202 if(!theDGdiDriver) |
|
203 { |
|
204 User::Leave(KErrNotReady); |
|
205 } |
|
206 TSgImageInfo info; |
|
207 info.iUsage = ESgUsageDirectGdiTarget | ESgUsageDirectGdiSource | ESgUsageCompositionSource; |
|
208 info.iPixelFormat = EUidPixelFormatRGB_565; |
|
209 info.iSizeInPixels = TSize(200, 200); |
|
210 info.iShareable = ETrue; |
|
211 const TInt KImageCount = 1; |
|
212 err = iImageCollection.Create(info, KImageCount); |
|
213 User::LeaveIfError(err); |
|
214 |
|
215 err = iImageCollection.OpenImage(0, iImage); |
|
216 User::LeaveIfError(err); |
|
217 iImageTarget = RDirectGdiImageTarget(*theDGdiDriver); |
|
218 err = iImageTarget.Create(iImage); |
|
219 User::LeaveIfError(err); |
|
220 |
|
221 // construction of image source |
|
222 RSgImage sgImage; |
|
223 CreateSgImageFromBitmapL(sgImage); |
|
224 CleanupClosePushL(sgImage); |
|
225 iWsDrawableSource = RWsDrawableSource(TheClient->iWs); |
|
226 User::LeaveIfError(iWsDrawableSource.Create(sgImage, TheClient->iScreen->GetScreenNumber())); |
|
227 |
|
228 //Create dummy MWsGraphicResolver - required RemoteGc testing |
|
229 iWsGrapicResolver = new (ELeave) CWSGraphicsRes(); |
|
230 |
|
231 //Create dummy MWsGraphicsContext - required RemoteGc testing |
|
232 iGraphicsCon = CTestWsGraphicsContext::NewL(iImageTarget); |
|
233 |
|
234 CleanupStack::PopAndDestroy(&sgImage); |
|
235 } |
|
236 |
|
237 void CTDrawResource::RunTestCaseL(TInt aCurTestCase) |
|
238 { |
|
239 ((CTDrawResourceStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName); |
|
240 switch(aCurTestCase) |
|
241 { |
|
242 case 1: |
|
243 ((CTDrawResourceStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-DRAWRESOURCE-0001")); |
|
244 INFO_PRINTF1(_L("DrawResourcePos Test")); |
|
245 TestDrawResourcePos(); |
|
246 break; |
|
247 case 2: |
|
248 ((CTDrawResourceStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-DRAWRESOURCE-0002")); |
|
249 INFO_PRINTF1(_L("DrawResourceRect Test")); |
|
250 TestDrawResourceRect(); |
|
251 break; |
|
252 case 3: |
|
253 ((CTDrawResourceStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-DRAWRESOURCE-0003")); |
|
254 INFO_PRINTF1(_L("DrawResourceScale Test")); |
|
255 TestDrawResourceScale(); |
|
256 break; |
|
257 case 4: |
|
258 ((CTDrawResourceStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-DRAWRESOURCE-0004")); |
|
259 INFO_PRINTF1(_L("RWsDrawableSource Reference Counting Test")); |
|
260 TestRWsDrawableSourceReferenceCountingL(); |
|
261 break; |
|
262 case 5: |
|
263 ((CTDrawResourceStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-DRAWRESOURCE-0005")); |
|
264 INFO_PRINTF1(_L("RemoteGcDrawResourcePos Test")); |
|
265 TestRemoteGcDrawResourcePosL(); |
|
266 break; |
|
267 case 6: |
|
268 ((CTDrawResourceStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-DRAWRESOURCE-0006")); |
|
269 INFO_PRINTF1(_L("RemoteGcDrawResourceRect Test")); |
|
270 TestRemoteGcDrawResourceRectL(); |
|
271 break; |
|
272 case 7: |
|
273 ((CTDrawResourceStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-DRAWRESOURCE-0007")); |
|
274 INFO_PRINTF1(_L("RemoteGcDrawResourceScale Test")); |
|
275 TestRemoteGcDrawResourceScaleL(); |
|
276 break; |
|
277 case 8: |
|
278 ((CTDrawResourceStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-DRAWRESOURCE-0008")); |
|
279 INFO_PRINTF1(_L("DrawResourceScreens Test")); |
|
280 TestDrawResourceScreensL(); |
|
281 break; |
|
282 case 9: |
|
283 ((CTDrawResourceStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-TestCopyScreenToBitmapWithDifferentDisplayModes-0001")); |
|
284 INFO_PRINTF1(_L("CopyScreenToBitmapWithDifferentDisplayModes Test\n")); |
|
285 TestCopyScreenToBitmapWithDifferentDisplayModesL(); |
|
286 break; |
|
287 case 10: |
|
288 ((CTDrawResourceStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName); |
|
289 ((CTDrawResourceStep*)iStep)->CloseTMSGraphicsStep(); |
|
290 INFO_PRINTF1(_L("Test complete\n")); |
|
291 TestComplete(); |
|
292 break; |
|
293 } |
|
294 ((CTDrawResourceStep*)iStep)->RecordTestResultL(); |
|
295 } |
|
296 |
|
297 /** |
|
298 @SYMTestCaseID GRAPHICS-WSERV-DRAWRESOURCE-0001 |
|
299 @SYMPREQ PREQ2095 |
|
300 @SYMTestPriority High |
|
301 @SYMTestCaseDesc Draw RSgImage using DrawResource(const TPoint&, const RWsDrawableSource&, TGraphicsRotation) |
|
302 @SYMTestActions Draw to position (0,0) with default rotation (none) |
|
303 Draw to position (10,10) with 90 degrees rotation |
|
304 @SYMTestExpectedResults Drawn images should match reference CFbsBitmap |
|
305 */ |
|
306 void CTDrawResource::TestDrawResourcePos() |
|
307 { |
|
308 // Draw to TPoint(0,0) with EGraphicsRotationNone |
|
309 iWindow.BeginRedraw(); |
|
310 TheGc->Activate(iWindow); |
|
311 TheGc->Clear(); |
|
312 MWsDrawResource* dr = static_cast<MWsDrawResource*>(TheGc->Interface(KMWsDrawResourceInterfaceUid)); |
|
313 TEST(dr != NULL); |
|
314 dr->DrawResource(KDestPoint, iWsDrawableSource, CWindowGc::EGraphicsRotationNone); |
|
315 TheGc->Deactivate(); |
|
316 iWindow.EndRedraw(); |
|
317 TheClient->iWs.Finish(); |
|
318 TheClient->WaitForRedrawsToFinish(); |
|
319 |
|
320 //Copy the screen to the copy bitmap |
|
321 TheClient->iScreen->CopyScreenToBitmap(iCopyBitmap, KCopyTestRect); |
|
322 |
|
323 //Compare the bitmaps |
|
324 INFO_PRINTF1(_L("Draw to TPoint(0,0) with EGraphicsRotationNone")); |
|
325 TBool compRes = CompareBitmapsByPixel(iCopyBitmap, iRefBitmap); |
|
326 TEST(compRes); |
|
327 |
|
328 /*** Draw to position (10,10) with 90 degrees rotation ***/ |
|
329 TPoint const KDestPoint2(10,10); |
|
330 iWindow.BeginRedraw(); |
|
331 TheGc->Activate(iWindow); |
|
332 TheGc->Clear(); |
|
333 dr->DrawResource(KDestPoint2, iWsDrawableSource, KTestRotation); |
|
334 TheGc->Deactivate(); |
|
335 iWindow.EndRedraw(); |
|
336 TheClient->iWs.Finish(); |
|
337 TheClient->WaitForRedrawsToFinish(); |
|
338 |
|
339 //Copy the screen to the copy bitmap |
|
340 TheClient->iScreen->CopyScreenToBitmap(iCopyBitmap, TRect(KDestPoint2, KSourceSize)); |
|
341 |
|
342 //Compare the bitmaps |
|
343 INFO_PRINTF1(_L("Draw to position (10,10) with 90 degrees rotation")); |
|
344 compRes = CompareBitmapsByPixel(iCopyBitmap, iRotatedRefBitmap); |
|
345 TEST(compRes); |
|
346 } |
|
347 |
|
348 /** |
|
349 @SYMTestCaseID GRAPHICS-WSERV-DRAWRESOURCE-0002 |
|
350 @SYMPREQ PREQ2095 |
|
351 @SYMTestPriority High |
|
352 @SYMTestCaseDesc Draw RSgImage using DrawResource(const TRect& , const RWsDrawableSource&, TGraphicsRotation aRotation) |
|
353 @SYMTestActions Draw to rect pos (10,10), rect size (60,60) with 90 degrees rotation |
|
354 @SYMTestExpectedResults Drawn images should match the reference CFbsBitmap |
|
355 */ |
|
356 void CTDrawResource::TestDrawResourceRect() |
|
357 { |
|
358 //Use DrawResource |
|
359 iWindow.BeginRedraw(); |
|
360 TheGc->Activate(iWindow); |
|
361 TheGc->Clear(); |
|
362 MWsDrawResource* dr = static_cast<MWsDrawResource*>(TheGc->Interface(KMWsDrawResourceInterfaceUid)); |
|
363 TEST(dr != NULL); |
|
364 dr->DrawResource(KDestRect, iWsDrawableSource, KTestRotation); |
|
365 TheGc->Deactivate(); |
|
366 iWindow.EndRedraw(); |
|
367 TheClient->iWs.Finish(); |
|
368 TheClient->WaitForRedrawsToFinish(); |
|
369 |
|
370 //Copy the screen to the copy bitmap |
|
371 TheClient->iScreen->CopyScreenToBitmap(iCopyBitmap, KCopyTestRect); |
|
372 |
|
373 //Compare the bitmaps |
|
374 INFO_PRINTF1(_L("Draw to rect pos (10,10), rect size (60,60) with 90 degrees rotation")); |
|
375 TInt compRes = CompareBitmapsByPixel(iCopyBitmap, iScaledBitmap); |
|
376 TEST(compRes); |
|
377 } |
|
378 |
|
379 /** |
|
380 @SYMTestCaseID GRAPHICS-WSERV-DRAWRESOURCE-0003 |
|
381 @SYMPREQ PREQ2095 |
|
382 @SYMTestPriority High |
|
383 @SYMTestCaseDesc Draw RSgImage using DrawResource(const TRect& , const RWsDrawableSource&, const TRect&, TGraphicsRotation aRotation) |
|
384 @SYMTestActions Draw the part of the source image (rect Pos (0,0), rect size(50,50)) |
|
385 to rect pos(10,10), rect size(60,60) and and 90 degrees rotation |
|
386 @SYMTestExpectedResults Drawn images should match the reference CFbsBitmap |
|
387 */ |
|
388 void CTDrawResource::TestDrawResourceScale() |
|
389 { |
|
390 //Use DrawResource |
|
391 iWindow.BeginRedraw(); |
|
392 TheGc->Activate(iWindow); |
|
393 TheGc->Clear(); |
|
394 MWsDrawResource* dr = static_cast<MWsDrawResource*>(TheGc->Interface(KMWsDrawResourceInterfaceUid)); |
|
395 TEST(dr != NULL); |
|
396 dr->DrawResource(KDestRect, iWsDrawableSource, KSourceRect, KTestRotation); |
|
397 TheGc->Deactivate(); |
|
398 iWindow.EndRedraw(); |
|
399 TheClient->iWs.Finish(); |
|
400 TheClient->WaitForRedrawsToFinish(); |
|
401 |
|
402 //Copy the screen to the copy bitmap |
|
403 TheClient->iScreen->CopyScreenToBitmap(iCopyBitmap, KCopyTestRect); |
|
404 |
|
405 //Compare the bitmaps |
|
406 INFO_PRINTF1(_L("Draw the part of the source image to rect pos(10,10), rect size(60,60) and and 90 degrees rotation")); |
|
407 TInt compRes = CompareBitmapsByPixel(iCopyBitmap, iScaledCroppedBitmap); |
|
408 TEST(compRes); |
|
409 } |
|
410 |
|
411 /** |
|
412 @SYMTestCaseID GRAPHICS-WSERV-DRAWRESOURCE-0004 |
|
413 @SYMPREQ PREQ2095 |
|
414 @SYMTestPriority High |
|
415 @SYMTestCaseDesc Draw RSgImage using DrawResource(const TPoint&, const RWsDrawableSource&, TGraphicsRotation) after closing the image source |
|
416 @SYMTestActions Draw to position (0,0) with default rotation (none) after closing the image source |
|
417 @SYMTestExpectedResults Drawn image should match reference CFbsBitmap |
|
418 */ |
|
419 void CTDrawResource::TestRWsDrawableSourceReferenceCountingL() |
|
420 { |
|
421 // construction of image source |
|
422 RSgImage sgImage; |
|
423 CreateSgImageFromBitmapL(sgImage); |
|
424 CleanupClosePushL(sgImage); |
|
425 RWsDrawableSource drawableSource(TheClient->iWs); |
|
426 CleanupClosePushL(drawableSource); |
|
427 User::LeaveIfError(drawableSource.Create(sgImage, TheClient->iScreen->GetScreenNumber())); |
|
428 |
|
429 //Draw using DrawResource |
|
430 iWindow.BeginRedraw(); |
|
431 TheGc->Activate(iWindow); |
|
432 TheGc->Clear(); |
|
433 MWsDrawResource* dr = static_cast<MWsDrawResource*>(TheGc->Interface(KMWsDrawResourceInterfaceUid)); |
|
434 TEST(dr != NULL); |
|
435 dr->DrawResource(KDestPoint, drawableSource, CWindowGc::EGraphicsRotationNone); |
|
436 TheGc->Deactivate(); |
|
437 iWindow.EndRedraw(); |
|
438 |
|
439 //Close the image source but this should not stop the source from being drawn |
|
440 drawableSource.Close(); |
|
441 TheClient->iWs.Finish(); |
|
442 TheClient->WaitForRedrawsToFinish(); |
|
443 |
|
444 //Copy the screen to the copy bitmap |
|
445 TheClient->iScreen->CopyScreenToBitmap(iCopyBitmap, KCopyTestRect); |
|
446 |
|
447 //Compare the bitmaps |
|
448 INFO_PRINTF1(_L("Draw to TPoint(0,0) with EGraphicsRotationNone")); |
|
449 TBool compRes = CompareBitmapsByPixel(iCopyBitmap, iRefBitmap); |
|
450 TEST(compRes); |
|
451 |
|
452 CleanupStack::PopAndDestroy(2, &sgImage); |
|
453 } |
|
454 |
|
455 /** |
|
456 @SYMTestCaseID GRAPHICS-WSERV-DRAWRESOURCE-0005 |
|
457 @SYMPREQ PREQ2095 |
|
458 @SYMTestPriority High |
|
459 @SYMTestCaseDesc Draw RSgImage using RemotGc->DrawResource(const TPoint&, const RWsDrawableSource&, TGraphicsRotation) |
|
460 @SYMTestActions Record the draw resource commands using CRemoteGc and play the recorded commands on a window using |
|
461 Play(const TPoint&, const TRect&, RWsSession&, CWindowGc&) and then play the recorded commands using . |
|
462 Play(const TPoint&, const TRect&, const MWsGraphicResolver&, MWsGraphicsContext&). |
|
463 @SYMTestExpectedResults Drawn images should match reference CFbsBitmap and also values received by MWsGraphicsContext should |
|
464 match what was originally sent to DrawResource. |
|
465 */ |
|
466 void CTDrawResource::TestRemoteGcDrawResourcePosL() |
|
467 { |
|
468 const TRect KRemotGcSourceRect(0, 0, iWindow.Size().iWidth, iWindow.Size().iHeight); |
|
469 const TRegionFix<1> KClippingRegion(KRemotGcSourceRect); |
|
470 CWindowGc::TGraphicsRotation testRotation= CWindowGc::EGraphicsRotationNone; |
|
471 |
|
472 //Create remote gc - required RemoteGc testing |
|
473 CRemoteGc* remoteGc = CRemoteGc::NewL(TheClient->iScreen); |
|
474 CleanupStack::PushL(remoteGc); |
|
475 |
|
476 //Record draw messages |
|
477 remoteGc->ResetCommandBuffer(); |
|
478 remoteGc->BeginDraw(KRemotGcSourceRect); |
|
479 MWsDrawResource* dr = static_cast<MWsDrawResource*>(remoteGc->Interface(KMWsDrawResourceInterfaceUid)); |
|
480 TEST(dr != NULL); |
|
481 dr->DrawResource(KDestPoint, iWsDrawableSource, CWindowGc::EGraphicsRotationNone); |
|
482 remoteGc->EndDraw(); |
|
483 |
|
484 RWsGraphicMsgBuf msgBuf; |
|
485 CleanupClosePushL(msgBuf); |
|
486 //Externalize the captured commands from remote gc in to a buffer |
|
487 remoteGc->ExternalizeL(msgBuf, ETrue); |
|
488 //Create command buffer - required RemoteGc testing |
|
489 CCommandBuffer* cmdBuffer = CCommandBuffer::NewL(); |
|
490 CleanupStack::PushL(cmdBuffer); |
|
491 //Internalize the buffer with captured commands (from CRemoteGC) in to CCommandBuffer |
|
492 cmdBuffer->InternalizeL(msgBuf.Pckg()); |
|
493 |
|
494 // Play stored commands using Play(const TPoint&, const TRect&, RWsSession&, CWindowGc&) |
|
495 remoteGc->ResetCommandBuffer(); |
|
496 iWindow.Invalidate(); |
|
497 iWindow.BeginRedraw(); |
|
498 TheGc->Activate(iWindow); |
|
499 TheGc->Clear(); |
|
500 cmdBuffer->Play(KPlayOffset, &KClippingRegion, KRemotGcSourceRect, TheClient->iWs, *TheGc); |
|
501 TheGc->Deactivate(); |
|
502 iWindow.EndRedraw(); |
|
503 TheClient->iWs.Finish(); |
|
504 TheClient->WaitForRedrawsToFinish(); |
|
505 |
|
506 //Copy the screen to the copy bitmap |
|
507 TheClient->iScreen->CopyScreenToBitmap(iCopyBitmap, KCopyTestRect); |
|
508 |
|
509 //Compare the bitmaps |
|
510 INFO_PRINTF1(_L("Using Play(const TPoint&, const TRect&, RWsSession&, CWindowGc&)")); |
|
511 TBool compRes = CompareBitmapsByPixel(iCopyBitmap, iRefBitmap); |
|
512 TEST(compRes); |
|
513 |
|
514 // Play stored commands using Play(const TPoint&, const TRect&, const MWsGraphicResolver&, MWsGraphicsContext&) |
|
515 remoteGc->ResetCommandBuffer(); |
|
516 iWindow.Invalidate(); |
|
517 iWindow.BeginRedraw(); |
|
518 TheGc->Activate(iWindow); |
|
519 TheGc->Clear(); |
|
520 cmdBuffer->Play(KPlayOffset,&KClippingRegion,KRemotGcSourceRect,*iWsGrapicResolver,*iGraphicsCon); |
|
521 TheGc->Deactivate(); |
|
522 iWindow.EndRedraw(); |
|
523 TheClient->iWs.Finish(); |
|
524 |
|
525 //Compare the values received by CTestWsGraphicsContext and the values sent to it |
|
526 INFO_PRINTF1(_L("Using Play(const TPoint&, const TRect&, const MWsGraphicResolver&, MWsGraphicsContext&)")); |
|
527 TBool valuesSame = EFalse; |
|
528 CFbsBitmap* bmp; |
|
529 BitmapLC(bmp); |
|
530 compRes = CompareBitmapsByPixel(bmp, iRefBitmap); |
|
531 CleanupStack::PopAndDestroy(bmp); |
|
532 |
|
533 if((iGraphicsCon->iPos == KDestPoint) && (compRes) |
|
534 && (reinterpret_cast<TInt&>(iGraphicsCon->iRotation)==reinterpret_cast<TInt&>(testRotation))) |
|
535 valuesSame = ETrue; |
|
536 TEST(valuesSame); |
|
537 CleanupStack::PopAndDestroy(3, remoteGc); |
|
538 } |
|
539 |
|
540 /** |
|
541 @SYMTestCaseID GRAPHICS-WSERV-DRAWRESOURCE-0006 |
|
542 @SYMPREQ PREQ2095 |
|
543 @SYMTestPriority High |
|
544 @SYMTestCaseDesc Draw RSgImage using RemotGc->DrawResource(const TRect&, const RWsDrawableSource&, TGraphicsRotation) |
|
545 @SYMTestActions Record the draw resource commands using CRemoteGc and play the recorded commands on a window using |
|
546 Play(const TPoint&, const TRect&, RWsSession&, CWindowGc&) and then play the recorded commands using . |
|
547 Play(const TPoint&, const TRect&, const MWsGraphicResolver&, MWsGraphicsContext&). |
|
548 @SYMTestExpectedResults Drawn images should match reference CFbsBitmap and also values received by MWsGraphicsContext should |
|
549 match what was originally sent to DrawResource. |
|
550 */ |
|
551 void CTDrawResource::TestRemoteGcDrawResourceRectL() |
|
552 { |
|
553 const TRect KRemotGcSourceRect(0, 0, iWindow.Size().iWidth, iWindow.Size().iHeight); |
|
554 const TRegionFix<1> KClippingRegion(KRemotGcSourceRect); |
|
555 |
|
556 //Create remote gc - required RemoteGc testing |
|
557 CRemoteGc* remoteGc = CRemoteGc::NewL(TheClient->iScreen); |
|
558 CleanupStack::PushL(remoteGc); |
|
559 |
|
560 //Record draw messages |
|
561 remoteGc->BeginDraw(KRemotGcSourceRect); |
|
562 MWsDrawResource* dr = static_cast<MWsDrawResource*>(remoteGc->Interface(KMWsDrawResourceInterfaceUid)); |
|
563 TEST(dr != NULL); |
|
564 dr->DrawResource(KDestRect, iWsDrawableSource, KTestRotation); |
|
565 remoteGc->EndDraw(); |
|
566 |
|
567 RWsGraphicMsgBuf msgBuf; |
|
568 CleanupClosePushL(msgBuf); |
|
569 //Externalize the captured commands from remote gc in to a buffer |
|
570 remoteGc->ExternalizeL(msgBuf, ETrue); |
|
571 |
|
572 //Create command buffer - required RemoteGc testing |
|
573 CCommandBuffer* cmdBuffer = CCommandBuffer::NewL(); |
|
574 CleanupStack::PushL(cmdBuffer); |
|
575 //Internalize the buffer with captured commands (from CRemoteGC) in to CCommandBuffer |
|
576 cmdBuffer->InternalizeL(msgBuf.Pckg()); |
|
577 |
|
578 // Play stored commands using Play(const TRect&, const TRect&, RWsSession&, CWindowGc&) |
|
579 iWindow.Invalidate(); |
|
580 iWindow.BeginRedraw(); |
|
581 TheGc->Activate(iWindow); |
|
582 TheGc->Clear(); |
|
583 cmdBuffer->Play(KPlayOffset, &KClippingRegion, KRemotGcSourceRect, TheClient->iWs, *TheGc); |
|
584 TheGc->Deactivate(); |
|
585 iWindow.EndRedraw(); |
|
586 TheClient->iWs.Finish(); |
|
587 TheClient->WaitForRedrawsToFinish(); |
|
588 |
|
589 //Copy the screen to the copy bitmap |
|
590 TheClient->iScreen->CopyScreenToBitmap(iCopyBitmap, KCopyTestRect); |
|
591 |
|
592 //Compare the bitmaps |
|
593 INFO_PRINTF1(_L("Using Play(const TPoint&, const TRect&, RWsSession&, CWindowGc&)")); |
|
594 TBool compRes = CompareBitmapsByPixel(iCopyBitmap, iScaledBitmap); |
|
595 TEST(compRes); |
|
596 |
|
597 // Play stored commands using Play(const TPoint&, const TRect&, const MWsGraphicResolver&, MWsGraphicsContext&) |
|
598 iWindow.Invalidate(); |
|
599 iWindow.BeginRedraw(); |
|
600 TheGc->Activate(iWindow); |
|
601 TheGc->Clear(); |
|
602 iGraphicsCon->Clear(); |
|
603 cmdBuffer->Play(KPlayOffset,&KClippingRegion,KRemotGcSourceRect,*iWsGrapicResolver,*iGraphicsCon); |
|
604 TheGc->Deactivate(); |
|
605 iWindow.EndRedraw(); |
|
606 TheClient->iWs.Finish(); |
|
607 TheClient->WaitForRedrawsToFinish(); |
|
608 |
|
609 //Compare the values received by CTestWsGraphicsContext and the values sent to it |
|
610 INFO_PRINTF1(_L("Using Play(const TPoint&, const TRect&, const MWsGraphicResolver&, MWsGraphicsContext&)")); |
|
611 TBool valuesSame = EFalse; |
|
612 |
|
613 CFbsBitmap* bmp; |
|
614 BitmapLC(bmp); |
|
615 compRes = CompareBitmapsByPixel(bmp, iScaledBitmap); |
|
616 CleanupStack::PopAndDestroy(bmp); |
|
617 |
|
618 if((iGraphicsCon->iDestRect == KDestRect) && (compRes) |
|
619 && (reinterpret_cast<TInt&>(iGraphicsCon->iRotation)==reinterpret_cast<const TInt&>(KTestRotation))) |
|
620 valuesSame = ETrue; |
|
621 TEST(valuesSame); |
|
622 CleanupStack::PopAndDestroy(3, remoteGc); |
|
623 } |
|
624 |
|
625 /** |
|
626 @SYMTestCaseID GRAPHICS-WSERV-DRAWRESOURCE-0007 |
|
627 @SYMPREQ PREQ2095 |
|
628 @SYMTestPriority High |
|
629 @SYMTestCaseDesc Draw RSgImage using RemotGc->DrawResource(const TRect&, const RWsDrawableSource&, const TRect&, TGraphicsRotation) |
|
630 @SYMTestActions Record the draw resource commands using CRemoteGc and play the recorded commands on a window using |
|
631 Play(const TPoint&, const TRect&, RWsSession&, CWindowGc&) and then play the recorded commands using . |
|
632 Play(const TPoint&, const TRect&, const MWsGraphicResolver&, MWsGraphicsContext&). |
|
633 @SYMTestExpectedResults Drawn images should match reference CFbsBitmap and also values received by MWsGraphicsContext should |
|
634 match what was originally sent to DrawResource. |
|
635 */ |
|
636 void CTDrawResource::TestRemoteGcDrawResourceScaleL() |
|
637 { |
|
638 const TRect KRemotGcSourceRect(0, 0, iWindow.Size().iWidth, iWindow.Size().iHeight); |
|
639 const TRegionFix<1> KClippingRegion(KRemotGcSourceRect); |
|
640 |
|
641 //Create remote gc - required RemoteGc testing |
|
642 CRemoteGc* remoteGc = CRemoteGc::NewL(TheClient->iScreen); |
|
643 CleanupStack::PushL(remoteGc); |
|
644 |
|
645 //Record draw messages |
|
646 remoteGc->BeginDraw(KRemotGcSourceRect); |
|
647 MWsDrawResource* dr = static_cast<MWsDrawResource*>(remoteGc->Interface(KMWsDrawResourceInterfaceUid)); |
|
648 TEST(dr != NULL); |
|
649 dr->DrawResource(KDestRect, iWsDrawableSource, KSourceRect, KTestRotation); |
|
650 remoteGc->EndDraw(); |
|
651 |
|
652 RWsGraphicMsgBuf msgBuf; |
|
653 CleanupClosePushL(msgBuf); |
|
654 //Externalize the captured commands from remote gc in to a buffer |
|
655 remoteGc->ExternalizeL(msgBuf, ETrue); |
|
656 |
|
657 //Create command buffer - required RemoteGc testing |
|
658 CCommandBuffer* cmdBuffer = CCommandBuffer::NewL(); |
|
659 CleanupStack::PushL(cmdBuffer); |
|
660 //Internalize the buffer with captured commands (from CRemoteGC) in to CCommandBuffer |
|
661 cmdBuffer->InternalizeL(msgBuf.Pckg()); |
|
662 |
|
663 // Play the stored commands using Play(const TRect&, const TRect&, RWsSession&, CWindowGc&) |
|
664 remoteGc->ResetCommandBuffer(); |
|
665 iWindow.Invalidate(); |
|
666 iWindow.BeginRedraw(); |
|
667 TheGc->Activate(iWindow); |
|
668 TheGc->Clear(); |
|
669 cmdBuffer->Play(KPlayOffset, &KClippingRegion, KRemotGcSourceRect, TheClient->iWs, *TheGc); |
|
670 TheGc->Deactivate(); |
|
671 iWindow.EndRedraw(); |
|
672 TheClient->iWs.Finish(); |
|
673 TheClient->WaitForRedrawsToFinish(); |
|
674 //Copy the screen to the copy bitmap |
|
675 TheClient->iScreen->CopyScreenToBitmap(iCopyBitmap, KCopyTestRect); |
|
676 |
|
677 //Compare the bitmaps |
|
678 INFO_PRINTF1(_L("Using Play(const TPoint&, const TRect&, RWsSession&, CWindowGc&)")); |
|
679 TBool compRes = CompareBitmapsByPixel(iCopyBitmap, iScaledCroppedBitmap); |
|
680 TEST(compRes); |
|
681 |
|
682 // Play the stored commands using Play(const TPoint&, const TRect&, const MWsGraphicResolver&, MWsGraphicsContext&) |
|
683 iWindow.Invalidate(); |
|
684 iWindow.BeginRedraw(); |
|
685 TheGc->Activate(iWindow); |
|
686 TheGc->Clear(); |
|
687 iGraphicsCon->Clear(); |
|
688 cmdBuffer->Play(KPlayOffset,&KClippingRegion,KRemotGcSourceRect,*iWsGrapicResolver,*iGraphicsCon); |
|
689 TheGc->Deactivate(); |
|
690 iWindow.EndRedraw(); |
|
691 TheClient->iWs.Finish(); |
|
692 TheClient->WaitForRedrawsToFinish(); |
|
693 |
|
694 //Compare the values received by CTestWsGraphicsContext and the values sent to it |
|
695 INFO_PRINTF1(_L("Using Play(const TPoint&, const TRect&, const MWsGraphicResolver&, MWsGraphicsContext&)")); |
|
696 TBool valuesSame = EFalse; |
|
697 |
|
698 CFbsBitmap* bmp; |
|
699 BitmapLC(bmp); |
|
700 compRes = CompareBitmapsByPixel(bmp, iScaledCroppedBitmap); |
|
701 CleanupStack::PopAndDestroy(bmp); |
|
702 |
|
703 if((iGraphicsCon->iDestRect == KDestRect) && (compRes) && (iGraphicsCon->iSrcRect == KSourceRect) |
|
704 && (reinterpret_cast<TInt&>(iGraphicsCon->iRotation)==reinterpret_cast<const TInt&>(KTestRotation))) |
|
705 valuesSame = ETrue; |
|
706 TEST(valuesSame); |
|
707 CleanupStack::PopAndDestroy(3, remoteGc); |
|
708 } |
|
709 |
|
710 /** |
|
711 @SYMTestCaseID GRAPHICS-WSERV-DRAWRESOURCE-0008 |
|
712 @SYMPREQ PREQ2095 |
|
713 @SYMTestPriority High |
|
714 @SYMTestCaseDesc Negative testing. Draw graphics recourses which associated with different screens. |
|
715 @SYMTestActions Open RWsDrawableSource associated with the screen which doesn’ exist. |
|
716 Open RWsDrawableSource associated with the screen which exists but differes from drawing target. |
|
717 Draw Rectangle and Resource to the screen via CWindowGc |
|
718 Draw Rectangle and Resource to the screen via CRemoteGc |
|
719 @SYMTestExpectedResults Opening drawable resource on the screen which doesn’t exist must fail with error code KErrArgument |
|
720 Drawing primitives will result only rectangles be drawn as drawable recourses get associated with different screen |
|
721 */ |
|
722 void CTDrawResource::TestDrawResourceScreensL() |
|
723 { |
|
724 TInt numOfScreens = TheClient->iWs.NumberOfScreens(); |
|
725 if(numOfScreens < 2) |
|
726 { |
|
727 INFO_PRINTF2(_L("This test case will be running if the number of available screens more than 1, current number is %d"), numOfScreens); |
|
728 return; |
|
729 } |
|
730 TInt screenNumber = TheClient->iScreen->GetScreenNumber(); |
|
731 TInt differentScreen = (screenNumber == 0) ? 1 : 0; |
|
732 |
|
733 RSgImage sgImage; |
|
734 CreateSgImageFromBitmapL(sgImage); |
|
735 CleanupClosePushL(sgImage); |
|
736 |
|
737 RWsDrawableSource drawableSource(TheClient->iWs); |
|
738 TInt res = drawableSource.Create(sgImage, differentScreen + 200); //wrong screen number |
|
739 TEST(res == KErrArgument); |
|
740 |
|
741 res = drawableSource.Create(iImage, differentScreen); |
|
742 TEST(res == KErrNotSupported); //in order to succeed the image must be created with flag usage ESgUsageWindowGcSource |
|
743 |
|
744 TSgImageInfo info; |
|
745 User::LeaveIfError(sgImage.GetInfo(info)); |
|
746 |
|
747 res = drawableSource.Create(sgImage, differentScreen); |
|
748 if(res == KErrNotSupported) |
|
749 { |
|
750 INFO_PRINTF1(_L("The second screen is not supports drawable source. This test case terminates now.")); |
|
751 CleanupStack::PopAndDestroy(&sgImage); |
|
752 return; |
|
753 } |
|
754 TEST(res == KErrNone); |
|
755 User::LeaveIfError(res); |
|
756 CleanupClosePushL(drawableSource); |
|
757 |
|
758 iWindow.BeginRedraw(); |
|
759 TheGc->Activate(iWindow); |
|
760 TheGc->Clear(); |
|
761 TheGc->SetBrushStyle(CFbsBitGc::ESolidBrush); |
|
762 TheGc->SetPenStyle(CFbsBitGc::ENullPen); |
|
763 TheGc->SetBrushColor(KRgbGreen); |
|
764 TheGc->DrawRect(TRect(KDestPoint, info.iSizeInPixels)); |
|
765 // Draw to TPoint(0,0) with EGraphicsRotationNone but to the different screen |
|
766 MWsDrawResource* winDr = static_cast<MWsDrawResource*>(TheGc->Interface(KMWsDrawResourceInterfaceUid)); |
|
767 TEST(winDr != NULL); |
|
768 winDr->DrawResource(KDestPoint, drawableSource, CWindowGc::EGraphicsRotationNone); |
|
769 TheGc->Deactivate(); |
|
770 iWindow.EndRedraw(); |
|
771 TheClient->iWs.Finish(); |
|
772 TheClient->WaitForRedrawsToFinish(); |
|
773 |
|
774 //Copy the screen to the copy bitmap |
|
775 TheClient->iScreen->CopyScreenToBitmap(iCopyBitmap, KCopyTestRect); |
|
776 |
|
777 //Compare the bitmaps |
|
778 INFO_PRINTF1(_L("Draw to TPoint(0,0) with EGraphicsRotationNone but to different screen")); |
|
779 TBool compRes = CompareBitmapsByPixel(iCopyBitmap, iBitmapWrongScreenNumber); |
|
780 TEST(compRes); |
|
781 |
|
782 //--------------------------- remoteGc |
|
783 const TRect KRemotGcSourceRect(0, 0, iWindow.Size().iWidth, iWindow.Size().iHeight); |
|
784 const TRegionFix<1> KClippingRegion(KRemotGcSourceRect); |
|
785 |
|
786 //Create remote gc - required RemoteGc testing |
|
787 CRemoteGc* remoteGc = CRemoteGc::NewL(TheClient->iScreen); |
|
788 CleanupStack::PushL(remoteGc); |
|
789 |
|
790 //Record draw messages |
|
791 remoteGc->BeginDraw(KRemotGcSourceRect); |
|
792 remoteGc->SetBrushStyle(CFbsBitGc::ESolidBrush); |
|
793 remoteGc->SetPenStyle(CFbsBitGc::ENullPen); |
|
794 remoteGc->SetBrushColor(KRgbGreen); |
|
795 remoteGc->DrawRect(TRect(KDestPoint, info.iSizeInPixels)); |
|
796 MWsDrawResource* remDr = static_cast<MWsDrawResource*>(remoteGc->Interface(KMWsDrawResourceInterfaceUid)); |
|
797 TEST(remDr != NULL); |
|
798 remDr->DrawResource(KDestRect, drawableSource, CWindowGc::EGraphicsRotationNone); |
|
799 remoteGc->EndDraw(); |
|
800 |
|
801 RWsGraphicMsgBuf msgBuf; |
|
802 CleanupClosePushL(msgBuf); |
|
803 //Externalize the captured commands from remote gc in to a buffer |
|
804 remoteGc->ExternalizeL(msgBuf, ETrue); |
|
805 |
|
806 //Create command buffer - required RemoteGc testing |
|
807 CCommandBuffer* cmdBuffer = CCommandBuffer::NewL(); |
|
808 CleanupStack::PushL(cmdBuffer); |
|
809 //Internalize the buffer with captured commands (from CRemoteGC) in to CCommandBuffer |
|
810 cmdBuffer->InternalizeL(msgBuf.Pckg()); |
|
811 |
|
812 // Play stored commands using Play(const TRect&, const TRect&, RWsSession&, CWindowGc&) |
|
813 iWindow.Invalidate(); |
|
814 iWindow.BeginRedraw(); |
|
815 TheGc->Activate(iWindow); |
|
816 TheGc->Clear(); |
|
817 cmdBuffer->Play(KPlayOffset, &KClippingRegion, KRemotGcSourceRect, TheClient->iWs, *TheGc); |
|
818 TheGc->Deactivate(); |
|
819 iWindow.EndRedraw(); |
|
820 TheClient->iWs.Finish(); |
|
821 TheClient->WaitForRedrawsToFinish(); |
|
822 |
|
823 //Copy the screen to the copy bitmap |
|
824 TheClient->iScreen->CopyScreenToBitmap(iCopyBitmap, KCopyTestRect); |
|
825 |
|
826 INFO_PRINTF1(_L("Draw to TPoint(0,0) with EGraphicsRotationNone but to different screen")); |
|
827 TBool compRes1 = CompareBitmapsByPixel(iCopyBitmap, iBitmapWrongScreenNumber); |
|
828 TEST(compRes1); |
|
829 |
|
830 CleanupStack::PopAndDestroy(5, &sgImage); |
|
831 } |
|
832 |
|
833 /** |
|
834 @SYMTestCaseID GRAPHICS-WSERV-TestCopyScreenToBitmapWithDifferentDisplayModes-0001 |
|
835 @SYMPREQ PREQ2095 |
|
836 @SYMTestPriority High |
|
837 @SYMTestCaseDesc Get bitmap and scanline from the screen. |
|
838 @SYMTestActions Draw bitmap in various display modes to the screen. |
|
839 Retrieve scan line and bitmap from the screen using standard WSERV API. |
|
840 |
|
841 @SYMTestExpectedResults Checks that obtained bitmap matches with the reference bitmap. |
|
842 */ |
|
843 void CTDrawResource::TestCopyScreenToBitmapWithDifferentDisplayModesL() |
|
844 { |
|
845 TDisplayMode mode = TheClient->iScreen->DisplayMode(); |
|
846 INFO_PRINTF2(_L("Screen display mode %d"), mode); |
|
847 CFbsBitmap* bitmap = NULL; |
|
848 |
|
849 TSize bitmapSize(163, 120); |
|
850 CreateBitmapLC(bitmap, bitmapSize, mode); |
|
851 |
|
852 iWindow.BeginRedraw(); |
|
853 TheGc->Activate(iWindow); |
|
854 TheGc->SetBrushStyle(CWindowGc::ESolidBrush); |
|
855 TheGc->SetBrushColor(KRgbYellow); |
|
856 TheGc->Clear(); |
|
857 const TPoint ptOffset(10, 15); |
|
858 TheGc->BitBlt(KDestPoint + ptOffset, bitmap); |
|
859 |
|
860 TheGc->Deactivate(); |
|
861 iWindow.EndRedraw(); |
|
862 TheClient->iWs.Finish(); |
|
863 TheClient->WaitForRedrawsToFinish(); |
|
864 |
|
865 const TInt length = bitmapSize.iWidth; |
|
866 const TInt height = bitmapSize.iHeight; |
|
867 const TInt buffersSize = length * 4; |
|
868 TUint8 *screenData = (TUint8*) User::AllocL(buffersSize); |
|
869 CleanupStack::PushL(screenData); |
|
870 TUint8 *bitmapData = (TUint8*) User::AllocL(buffersSize); |
|
871 CleanupStack::PushL(bitmapData); |
|
872 TPtr8 ptrScreen (screenData, buffersSize, buffersSize); |
|
873 TPtr8 ptrBitmap (bitmapData, buffersSize, buffersSize); |
|
874 |
|
875 //EGray mode uses dithering in BitGdi, wserv doesnt support this, thus skipping the first mode |
|
876 for(TInt ii =2; ; ii++) |
|
877 { |
|
878 TDisplayMode dispMode = (TDisplayMode)ii; |
|
879 if(dispMode >= EColorLast) |
|
880 break; |
|
881 if(dispMode == ERgb) |
|
882 continue; |
|
883 |
|
884 INFO_PRINTF2(_L("Copy Screen to bitmap, destination mode %d"), dispMode); |
|
885 |
|
886 CFbsBitmap *bmp = new (ELeave) CFbsBitmap; |
|
887 CleanupStack::PushL(bmp); |
|
888 User::LeaveIfError(bmp->Create(bitmapSize, dispMode)); |
|
889 TUidPixelFormat pixelFormat = SgUtils::DisplayModeToPixelFormat(dispMode); |
|
890 const TInt minStride = SgUtils::MinDataStride(length, pixelFormat); |
|
891 const TInt bitmapStride = bmp->DataStride(); |
|
892 TEST(minStride <= bitmapStride); |
|
893 |
|
894 //Copy the screen to the copy bitmap |
|
895 TRect rc = bitmapSize; |
|
896 rc.Move(ptOffset); |
|
897 TheClient->iScreen->CopyScreenToBitmap(bmp, rc); |
|
898 CFbsBitmap *bmpRef = NULL; |
|
899 CreateReferenceBitmapLC(bmpRef, bitmap, dispMode); |
|
900 TEST(bmpRef->DisplayMode() == dispMode); |
|
901 |
|
902 //Compare the bitmaps |
|
903 TBool compRes = CompareBitmapsByPixel(bmp, bmpRef); |
|
904 TEST(compRes); |
|
905 |
|
906 for(TInt jj = 0; jj < height; jj++) |
|
907 { |
|
908 TPoint pt(0, jj); |
|
909 TPoint ptScreen = pt + ptOffset; |
|
910 |
|
911 Mem::Fill(screenData, bitmapStride, 0xff); |
|
912 Mem::Fill(bitmapData, bitmapStride, 0xff); |
|
913 |
|
914 TheClient->iScreen->GetScanLine(ptrScreen, ptScreen, length, dispMode); |
|
915 bitmap->GetScanLine(ptrBitmap, pt, length, dispMode); |
|
916 TInt length1 = ptrScreen.Length(); |
|
917 |
|
918 TInt res = Mem::Compare(screenData, length1, bitmapData, length1); |
|
919 TEST(res == 0); |
|
920 } |
|
921 CleanupStack::PopAndDestroy(2, bmp); |
|
922 }//screen modes; |
|
923 |
|
924 CleanupStack::PopAndDestroy(3, bitmap); |
|
925 } |
|
926 |
|
927 //Helper function: Creates reference bitmap with specified display mode |
|
928 void CTDrawResource::CreateReferenceBitmapLC(CFbsBitmap*& aBmpTarget, CFbsBitmap* aBmpSrc, TDisplayMode aDestMode) |
|
929 { |
|
930 TSize size = aBmpSrc->SizeInPixels(); |
|
931 aBmpTarget = new (ELeave) CFbsBitmap; |
|
932 CleanupStack::PushL(aBmpTarget); |
|
933 User::LeaveIfError(aBmpTarget->Create(size, aDestMode)); |
|
934 CFbsBitmapDevice *refBitmapDev = CFbsBitmapDevice::NewL(aBmpTarget); |
|
935 CleanupStack::PushL(refBitmapDev); |
|
936 CFbsBitGc *originalBitGc; |
|
937 User::LeaveIfError(refBitmapDev->CreateContext(originalBitGc)); |
|
938 CleanupStack::PushL(originalBitGc); |
|
939 originalBitGc->BitBlt(TPoint(0,0), aBmpSrc); |
|
940 CleanupStack::PopAndDestroy(2, refBitmapDev); |
|
941 } |
|
942 |
|
943 //Helper function: Creates reference bitmap with specified display mode |
|
944 void CTDrawResource::CreateBitmapLC(CFbsBitmap*& aBmpTarget, const TSize& aSize, TDisplayMode aDispMode) const |
|
945 { |
|
946 aBmpTarget = new (ELeave) CFbsBitmap; |
|
947 CleanupStack::PushL(aBmpTarget); |
|
948 User::LeaveIfError(aBmpTarget->Create(aSize, aDispMode)); |
|
949 CFbsBitmapDevice *refBitmapDev = CFbsBitmapDevice::NewL(aBmpTarget); |
|
950 CleanupStack::PushL(refBitmapDev); |
|
951 CFbsBitGc *originalBitGc; |
|
952 User::LeaveIfError(refBitmapDev->CreateContext(originalBitGc)); |
|
953 CleanupStack::PushL(originalBitGc); |
|
954 |
|
955 TRect rect = TRect(aSize); |
|
956 rect.Shrink(21, 15); |
|
957 |
|
958 originalBitGc->SetBrushStyle(CFbsBitGc::ESolidBrush); |
|
959 originalBitGc->SetBrushColor(TRgb(0,150,150)); |
|
960 originalBitGc->DrawRect(TRect(TPoint(0,0), TSize(aSize.iWidth, aSize.iHeight / 2))); |
|
961 originalBitGc->SetBrushColor(TRgb(150,100,150)); |
|
962 originalBitGc->DrawRect(TRect(TPoint(0,aSize.iHeight / 2), TSize(aSize.iWidth, aSize.iHeight))); |
|
963 |
|
964 originalBitGc->SetBrushColor(TRgb(0,0,128)); |
|
965 originalBitGc->DrawRect(rect); |
|
966 |
|
967 |
|
968 CleanupStack::PopAndDestroy(2, refBitmapDev); |
|
969 } |
|
970 |
|
971 //Helper function: Creates a RSgImage from a bitmap |
|
972 void CTDrawResource::CreateSgImageFromBitmapL(RSgImage& aSgImage) |
|
973 { |
|
974 TUint32* data = iRefBitmap->DataAddress(); |
|
975 TInt stride = iRefBitmap->DataStride(); |
|
976 TSize size = iRefBitmap->SizeInPixels(); |
|
977 |
|
978 TSgImageInfo info; |
|
979 info.iSizeInPixels = size; |
|
980 info.iScreenId = TheClient->iScreen->CurrentScreenMode(); |
|
981 info.iShareable = ETrue; //must be shareable since wserv is in other process |
|
982 info.iUsage = ESgUsageWindowGcSource; |
|
983 info.iPixelFormat = SgUtils::DisplayModeToPixelFormat(iRefBitmap->DisplayMode()); |
|
984 |
|
985 User::LeaveIfError(aSgImage.Create(info, data, stride)); |
|
986 } |
|
987 |
|
988 //Helper function: Creates all reference bitmaps required for all tests |
|
989 void CTDrawResource::CreateReferenceAndCopyBitmapsL() |
|
990 { |
|
991 //Create reference bitmap |
|
992 iRefBitmap = new (ELeave) CFbsBitmap(); |
|
993 User::LeaveIfError(iRefBitmap->Create(TSize(160,120),EColor64K)); |
|
994 |
|
995 //Setup to draw to original reference bitmap |
|
996 CFbsBitmapDevice *refBitmapDev = CFbsBitmapDevice::NewL(iRefBitmap); |
|
997 CleanupStack::PushL(refBitmapDev); |
|
998 CFbsBitGc *originalBitGc; |
|
999 User::LeaveIfError(refBitmapDev->CreateContext(originalBitGc)); |
|
1000 CleanupStack::PushL(originalBitGc); |
|
1001 |
|
1002 //Draw to reference bitmap |
|
1003 originalBitGc->SetBrushStyle(CFbsBitGc::ESolidBrush); |
|
1004 originalBitGc->SetBrushColor(TRgb(0,150,150)); |
|
1005 originalBitGc->DrawRect(TRect(TPoint(0,0), TSize(160,60))); |
|
1006 originalBitGc->SetBrushColor(TRgb(150,100,150)); |
|
1007 originalBitGc->DrawRect(TRect(TPoint(0,60), TSize(160,60))); |
|
1008 |
|
1009 //create a rotated version of the reference bitmap |
|
1010 iRotatedRefBitmap = new (ELeave) CFbsBitmap(); |
|
1011 User::LeaveIfError(iRotatedRefBitmap->Create(TSize(120,160),EColor64K)); |
|
1012 |
|
1013 //Setup to draw to rotated reference bitmap |
|
1014 CFbsBitmapDevice *rotRefBitmapDev = CFbsBitmapDevice::NewL(iRotatedRefBitmap); |
|
1015 CleanupStack::PushL(rotRefBitmapDev); |
|
1016 CFbsBitGc *rotatedBitGc; |
|
1017 User::LeaveIfError(rotRefBitmapDev->CreateContext(rotatedBitGc)); |
|
1018 CleanupStack::PushL(rotatedBitGc); |
|
1019 |
|
1020 //Draw to rotated reference bitmap |
|
1021 rotatedBitGc->SetBrushStyle(CFbsBitGc::ESolidBrush); |
|
1022 rotatedBitGc->SetBrushColor(TRgb(0,150,150)); |
|
1023 rotatedBitGc->DrawRect(TRect(TPoint(60,0), TSize(60,160))); |
|
1024 rotatedBitGc->SetBrushColor(TRgb(150,100,150)); |
|
1025 rotatedBitGc->DrawRect(TRect(TPoint(0,0), TSize(60,160))); |
|
1026 |
|
1027 //Prepare a scaled version of the rotated reference bitmap to later compare against |
|
1028 iScaledBitmap = new (ELeave) CFbsBitmap(); |
|
1029 User::LeaveIfError(iScaledBitmap->Create(TSize(160,120),EColor64K)); |
|
1030 //Setup to draw to bitmap |
|
1031 CFbsBitmapDevice *scaledBitDev = CFbsBitmapDevice::NewL(iScaledBitmap); |
|
1032 CleanupStack::PushL(scaledBitDev); |
|
1033 CFbsBitGc *scaledBitGc; |
|
1034 User::LeaveIfError(scaledBitDev->CreateContext(scaledBitGc)); |
|
1035 CleanupStack::PushL(scaledBitGc); |
|
1036 //Draw the rotated reference bitmap scaled |
|
1037 scaledBitGc->DrawBitmap(KDestRect, iRotatedRefBitmap); |
|
1038 |
|
1039 //Prepare a scaled version of the rotated reference bitmap to later compare against |
|
1040 iScaledCroppedBitmap = new (ELeave) CFbsBitmap(); |
|
1041 User::LeaveIfError(iScaledCroppedBitmap->Create(TSize(160,120),EColor64K)); |
|
1042 |
|
1043 //Setup to draw to bitmap |
|
1044 CFbsBitmapDevice *scaledCroppedBitDev = CFbsBitmapDevice::NewL(iScaledCroppedBitmap); |
|
1045 CleanupStack::PushL(scaledCroppedBitDev); |
|
1046 CFbsBitGc *scaledCroppedBitGc; |
|
1047 User::LeaveIfError(scaledCroppedBitDev->CreateContext(scaledCroppedBitGc)); |
|
1048 CleanupStack::PushL(scaledCroppedBitGc); |
|
1049 |
|
1050 //Draw the rotated reference bitmap scaled |
|
1051 TInt width = iRotatedRefBitmap->SizeInPixels().iWidth; |
|
1052 TInt height = iRotatedRefBitmap->SizeInPixels().iHeight; |
|
1053 |
|
1054 TRect rectSrc; |
|
1055 rectSrc.iTl.iX= width - KSourceRect.Height(); |
|
1056 rectSrc.iTl.iY= 0; |
|
1057 rectSrc.iBr.iX= width; |
|
1058 rectSrc.iBr.iY= KSourceRect.Width(); |
|
1059 |
|
1060 scaledCroppedBitGc->DrawBitmap(KDestRect, iRotatedRefBitmap, rectSrc); |
|
1061 |
|
1062 //Prepare bitmap for testing drawable which opened with different screen number |
|
1063 iBitmapWrongScreenNumber = new (ELeave) CFbsBitmap(); |
|
1064 User::LeaveIfError(iBitmapWrongScreenNumber->Create(TSize(160,120),EColor64K)); |
|
1065 //Setup to draw to bitmap |
|
1066 CFbsBitmapDevice *wrongScreenNumberBitDev = CFbsBitmapDevice::NewL(iBitmapWrongScreenNumber); |
|
1067 CleanupStack::PushL(wrongScreenNumberBitDev); |
|
1068 CFbsBitGc *wrongScreenNumberBitGc; |
|
1069 User::LeaveIfError(wrongScreenNumberBitDev->CreateContext(wrongScreenNumberBitGc)); |
|
1070 CleanupStack::PushL(wrongScreenNumberBitGc); |
|
1071 //Draw the rotated reference bitmap scaled |
|
1072 wrongScreenNumberBitGc->SetBrushColor(KRgbGreen); |
|
1073 wrongScreenNumberBitGc->SetBrushStyle(CFbsBitGc::ESolidBrush); |
|
1074 wrongScreenNumberBitGc->SetPenStyle(CFbsBitGc::ENullPen); |
|
1075 wrongScreenNumberBitGc->DrawRect(TRect(0, 0, 160, 120)); // |
|
1076 |
|
1077 //Create a bitmap to copy to with the same display mode as the reference bitmap |
|
1078 iCopyBitmap = new (ELeave) CFbsBitmap(); |
|
1079 User::LeaveIfError(iCopyBitmap->Create(TSize(640,240),EColor64K)); |
|
1080 |
|
1081 CleanupStack::PopAndDestroy(10, refBitmapDev); |
|
1082 } |
|
1083 |
|
1084 //Helper function: This function compares two bitmaps on a pixel by pixel basis */ |
|
1085 TBool CTDrawResource::CompareBitmapsByPixel(CFbsBitmap* aCandidateBitmap, CFbsBitmap* aReferenceBitmap) |
|
1086 { |
|
1087 TBool result = ETrue; |
|
1088 |
|
1089 TSize candidateSize = aCandidateBitmap->SizeInPixels(); |
|
1090 TSize referenceSize = aReferenceBitmap->SizeInPixels(); |
|
1091 |
|
1092 TInt mismatchedPixels = 0; |
|
1093 |
|
1094 TRgb nativePixel; |
|
1095 TRgb referencePixel; |
|
1096 for (TInt x = 0; x < referenceSize.iWidth; x++) |
|
1097 { |
|
1098 for (TInt y = 0; y < referenceSize.iHeight; y++) |
|
1099 { |
|
1100 TPoint point(x,y); |
|
1101 nativePixel = TRgb(0,0,0,0); |
|
1102 referencePixel = TRgb(0,0,0,0); |
|
1103 aCandidateBitmap->GetPixel(nativePixel, point); |
|
1104 aReferenceBitmap->GetPixel(referencePixel, point); |
|
1105 |
|
1106 if (nativePixel != referencePixel) |
|
1107 { |
|
1108 mismatchedPixels++; |
|
1109 result = EFalse; |
|
1110 } |
|
1111 } |
|
1112 } |
|
1113 |
|
1114 INFO_PRINTF2(_L("Number of different pixels: %i"), mismatchedPixels); |
|
1115 return result; |
|
1116 } |
|
1117 //Helper function: This function extracts content of the image associated with the image target and copies it into bitmap |
|
1118 void CTDrawResource::BitmapLC(CFbsBitmap*& aBmp) |
|
1119 { |
|
1120 aBmp = new(ELeave) CFbsBitmap; |
|
1121 CleanupStack::PushL(aBmp); |
|
1122 |
|
1123 TSgImageInfo info; |
|
1124 TInt res = iImage.GetInfo(info); |
|
1125 User::LeaveIfError(res); |
|
1126 |
|
1127 res = aBmp ->Create(info.iSizeInPixels, SgUtils::PixelFormatToDisplayMode(info.iPixelFormat)); |
|
1128 User::LeaveIfError(res); |
|
1129 TUint32* dataAddressDest = aBmp->DataAddress(); |
|
1130 |
|
1131 RSgImage image; |
|
1132 info.iUsage = ESgUsageNone; |
|
1133 info.iCpuAccess = ESgCpuAccessReadOnly; |
|
1134 res = image.Create(info, iImage); |
|
1135 User::LeaveIfError(res); |
|
1136 CleanupClosePushL(image); |
|
1137 const TAny* dataAddress = NULL; |
|
1138 TInt dataStride; |
|
1139 res = image.MapReadOnly(dataAddress, dataStride); |
|
1140 User::LeaveIfError(res); |
|
1141 Mem::Copy(dataAddressDest, dataAddress, dataStride * info.iSizeInPixels.iHeight); |
|
1142 image.Unmap(); |
|
1143 CleanupStack::PopAndDestroy(&image); |
|
1144 } |