Update contrib.
1 // Copyright (c) 2007-2010 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.
14 // Surface manager test code
21 @internalComponent - Internal Symbian test code
25 #include "tsurfacemanager.h"
32 #include <e32def_private.h>
33 #include <graphics/surface_hints.h>
35 using namespace surfaceHints;
37 const TInt KCountLimit = 10000;
39 CTSurfaceManager::CTSurfaceManager(CTestStep* aStep):
44 void CTSurfaceManager::ReAllocHintsArrayL(TUint aNumberOfHints)
48 User::Free(iHintsArray);
51 iHintsArray=static_cast<RSurfaceManager::THintPair*>(
52 User::AllocL(aNumberOfHints * sizeof(RSurfaceManager::THintPair)));
55 CTSurfaceManager::~CTSurfaceManager()
59 User::Free(iHintsArray);
63 void CTSurfaceManager::RunTestCaseL(TInt aCurTestCase)
66 TInt threadHandles1=0;
67 RThread().HandleCount(procHandles1, threadHandles1);
68 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
73 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0001
74 @SYMPREQ PREQ 1879,PREQ1007
75 @SYMREQ REQ8222,REQ8223
77 @SYMTestCaseDesc For each alignment conditions, create a Surface in a new shared chunk.
78 All the attributes are correct, no rounding is required.
79 @SYMTestStatus Implemented
80 @SYMTestActions For each alignment conditions, call CreateSurface() then SurfaceInfo().
81 @SYMTestExpectedResults If the return value is KErrNone , it has suceeded
84 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0001"));
85 TestCreateSurfaceNewChunk1L();
88 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0002-0001
89 @SYMPREQ PREQ 1879,PREQ1007
90 @SYMREQ REQ8222,REQ8223
92 @SYMTestCaseDesc For each alignment conditions, create a Surface in a new shared chunk.
93 Rounding is required for iOffsetToFirstBuffer and iOffsetBetweenBuffers.
94 @SYMTestStatus Implemented
95 @SYMTestActions Call CreateSurface(), SurfaceInfo()
96 @SYMTestExpectedResults If the return value is KErrNone , it has suceeded
99 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0002-0001"));
100 TestCreateSurfaceNewChunk2L();
103 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0002-0002
104 @SYMPREQ PREQ 1879,PREQ1007
105 @SYMREQ REQ8222,REQ8223
106 @SYMTestPriority High
107 @SYMTestCaseDesc This test creates a surface in an exisiting shared chunk
108 Find a valid shared chunk handle returned by a device driver.
109 Create a surface in this existing shared chunk
110 Map the surface in the current process to get a new shared chunk handle
111 @SYMTestStatus Implemented
112 @SYMTestActions Call CreateSurface(), MapSurface(), SurfaceInfo().
113 @SYMTestExpectedResults If the return value is KErrNone , it has suceeded
116 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0002-0002"));
117 TestCreateSurfaceExisitingChunkL();
120 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0003
121 @SYMPREQ PREQ 1879,PREQ1007
122 @SYMREQ REQ8222,REQ8223
123 @SYMTestPriority High
124 @SYMTestCaseDesc This test creates a surface with distinct creation attributes in an
125 exisiting shared chunk that already contains a surface.
126 Create a surface in a new shared chunk with valid creation attributes.
127 Map the surface in the current process to get the first chunk handle.
128 Create another surface (different attributes) in this existing chunk.
129 Check that two surfaceIDs are different.
130 Map the second surface in the current process to get the second chunk handle.
131 Check that two chunk handles are different but refer to the same shared chunk.
132 Write a number in the first buffer of the Second surface and read it from the first Surface (the surfaces share the chunk).
133 @SYMTestStatus Implemented
134 @SYMTestActions Call CreateSurface(), MapSurface() and SurfaceInfo().
135 @SYMTestExpectedResults If the return value is KErrNone , it has suceeded
138 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0003"));
139 TestCreateSurfaceExisitingChunk2L();
142 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0004
143 @SYMPREQ PREQ 1879,PREQ1007
144 @SYMREQ REQ8222,REQ8223
145 @SYMTestPriority High
146 @SYMTestCaseDesc This test creates a surface with identical creation attributes in an
147 exisiting shared chunk that already contains a surface.
148 @SYMTestStatus Implemented
149 @SYMTestActions Call CreateSurface(), MapSurface() and SurfaceInfo().
150 @SYMTestExpectedResults If the return value is KErrNone , it has suceeded
153 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0004"));
154 TestCreateSurfaceExisitingChunk3L();
157 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0005
158 @SYMPREQ PREQ 1879,PREQ1007
159 @SYMREQ REQ8222,REQ8223
160 @SYMTestPriority High
161 @SYMTestCaseDesc This test creates a surface with rotated orientations in an exisiting
162 shared chunk that already contains a surface at the same address.
163 @SYMTestStatus Implemented
164 @SYMTestActions Call CreateSurface(), MapSurface() and SurfaceInfo().
165 @SYMTestExpectedResults If the return value is KErrNone , it has suceeded
168 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0005"));
169 TestCreateSurfaceExisitingChunk4L();
172 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0006
173 @SYMPREQ PREQ 1879,PREQ1007
174 @SYMREQ REQ8222,REQ8223
175 @SYMTestPriority High
176 @SYMTestCaseDesc This test creates surfaces with Hint pairs (between 0 and the maximum allowed)
177 @SYMTestStatus Implemented
178 @SYMTestActions Call GetSurfaceManagerAttrib(), CreateSurface(), SurfaceInfo().
179 @SYMTestExpectedResults One surface can hold maximum of 8 hint pairs
182 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0006"));
183 TestCreateSurfaceAssociatedWithHintPairsL();
187 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0007
188 @SYMPREQ PREQ 1879,PREQ1007
189 @SYMREQ REQ8222,REQ8223
190 @SYMTestPriority High
191 @SYMTestCaseDesc This test creates surfaces with all type of alignment in contiguous
192 or fragmented memory.
193 @SYMTestStatus Implemented
194 @SYMTestActions Call CreateSurface().
195 @SYMTestExpectedResults If the return value is KErrNone , it has suceeded
198 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0007"));
199 TestCreateSurfaceAlignmentsMemoryTypeL();
203 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0008
204 @SYMPREQ PREQ 1879,PREQ1007
205 @SYMREQ REQ8222,REQ8223
206 @SYMTestPriority High
207 @SYMTestCaseDesc This test creates a surface and opens the surface
208 @SYMTestStatus Implemented
209 @SYMTestActions Call CreateSurface() and OpenSurface()
210 @SYMTestExpectedResults If the return value is KErrNone , it has suceeded
213 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0008"));
217 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0009
218 @SYMPREQ PREQ 1879,PREQ1007
219 @SYMREQ REQ8222,REQ8223
220 @SYMTestPriority High
221 @SYMTestCaseDesc This tests CloseSurface (correctly) decrements reference count
222 Create a surface (set the reference count to 1)
223 Get the SurfaceInfo for the Surface. (don't alter the ref count)
224 Close the Surface (ref count =0)
225 Open the Surface (Since the ref count is 0, OpenSurface should fail)
226 @SYMTestStatus Implemented
227 @SYMTestActions Call CreateSurface(), CloseSurface(), OpenSurface()
228 @SYMTestExpectedResults CloseSurface returns KErrNone, OpenSurface returns KErrArgument
231 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0009"));
232 TestClosingSurfaceDecrementsReferenceCountL();
235 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0010
236 @SYMPREQ PREQ 1879,PREQ1007
237 @SYMREQ REQ8222,REQ8223
238 @SYMTestPriority High
239 @SYMTestCaseDesc Test that the new CreateSurface()API create the surface and set its reference count to one
240 Create a surface in a new shared chunk with valid creation attributes.
241 Map the surface in the current process to get the chunk handle.
242 Create a new surface in the existing shared chunk with valid creation attributes (ref count is set to 1).
243 Close the second surface (decrement the ref count to 0, the surface is deleted)
244 Close the second surface again
245 Check the return value is KErrArgument as the second surface is already deleted.
246 @SYMTestStatus Implemented
247 @SYMTestActions Call CreateSurface(), MapSurface(), CloseSurface(), OpenSurface()
248 @SYMTestExpectedResults The new surface can be created successfully on the existing shared chunk, and the reference count is set to one.
251 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0010"));
252 TestCreateSurfaceSetReferenceCountL();
255 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0011
256 @SYMPREQ PREQ 1879,PREQ1007
257 @SYMREQ REQ8222,REQ8223
258 @SYMTestPriority High
259 @SYMTestCaseDesc Check reading from buffers
260 Set the ‘iBuffers’ of TSurfaceCreationAttributes to two.
261 Create the Surface in the new shared chunk with valid creation attributes
262 Map the Surface in the current process to get the shared chunk handle
263 Get the address of the pixel data and write a number to that.
264 Check that you can read what was written previously.
265 @SYMTestStatus Implemented
266 @SYMTestActions Call CreateSurface() and MapSurface()
267 @SYMTestExpectedResults Upon success, the buffer can be written with valid values
270 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0011"));
271 TestWriteToTwoBuffersL();
274 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0012
275 @SYMPREQ PREQ 1879,PREQ1007
276 @SYMREQ REQ8222,REQ8223
277 @SYMTestPriority High
278 @SYMTestCaseDesc This test gets SurfaceInfo of a Surface without mapping it
279 Store the attributes used to create the Surface.
280 Create a surface in a new shared chunk with those valid attributes
281 Call SurfaceInfo to get the attributes of the new Surface.
282 Check if the values are equal to the stored ones.
283 @SYMTestStatus Implemented
284 @SYMTestActions Call CreateSurface(), SurfaceInfo()
285 @SYMTestExpectedResults Upon success,the return values are equal to the stored values
288 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0012"));
289 TestQuerySurfaceInfoWithoutMappingL();
292 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0013
293 @SYMPREQ PREQ 1879,PREQ1007
294 @SYMREQ REQ8222,REQ8223
295 @SYMTestPriority High
296 @SYMTestCaseDesc This test queries SurfaceInfo after mapping it in a memory space
297 Store the attributes used to create the Surface.
300 Call SurfaceInfo to get the attributes of the Surface
301 Check if the values are equal to the stored ones.
302 @SYMTestStatus Implemented
303 @SYMTestActions Call CreateSurface(), MapSurface(), SurfaceInfo()
304 @SYMTestExpectedResults Upon success,the values are equal to the stored values.
307 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0013"));
308 TestQuerySurfaceInfoAfterMappingL();
311 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0014
312 @SYMPREQ PREQ 1879,PREQ1007
313 @SYMREQ REQ8222,REQ8223
314 @SYMTestPriority High
315 @SYMTestCaseDesc This tests the MapSurface method
316 Create a surface in a new shared chunk with valid attributes
317 Map the surface in the current process to get the chunk handle
318 Check that it returns KerrNone
319 @SYMTestStatus Implemented
320 @SYMTestActions Call CreateSurface(), MapSurface()
321 @SYMTestExpectedResults Upon success,the return value is KErrNone
324 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0014"));
328 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0015
329 @SYMPREQ PREQ 1879,PREQ1007
330 @SYMREQ REQ8222,REQ8223
331 @SYMTestPriority High
332 @SYMTestCaseDesc This tests the CloseSurface method
333 Create a surface in a new shared chunk with valid attributes
335 Check that this returns KErrNone
336 Call OpenSurface using the SurfaceID and check it returns KErrArgument as the surface is already deleted.
337 @SYMTestStatus Implemented
338 @SYMTestActions Call CreateSurface(), CloseSurface(), OpenSurface()
339 @SYMTestExpectedResults After closing the surface, Open the same surface again will cause a failure and return value is not KErrNone
342 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0015"));
343 TestClosingSurfaceL();
346 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0016
347 @SYMPREQ PREQ 1879,PREQ1007
348 @SYMREQ REQ8222,REQ8223
349 @SYMTestPriority High
350 @SYMTestCaseDesc This test checks the shared Chunk gets deleted after the surface and handle are both closed
351 Create a surface in a new shared chunk with valid attributes
352 Map the Surface in the current process to get the chunk handle
354 Check that KErrNone is returned
355 Call RChunk::Base() to check the chunk is not yet deleted, as the handle is still open
356 Close the chunk handle
357 @SYMTestStatus Implemented
358 @SYMTestActions Call CreateSurface(), CloseSurface(), MapSurface()
359 @SYMTestExpectedResults CloseSurface returns KErrNone, OpenSurface returns KErrArgument
362 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0016"));
363 TestSharedChunkClosedL();
367 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
368 // Obsolete since cr1649 (it was testing the capabilities of the Surface Manager driver)
371 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0018
372 @SYMPREQ PREQ 1879,PREQ1007
373 @SYMREQ REQ8222,REQ8223
374 @SYMTestPriority High
375 @SYMTestCaseDesc This test creates multiple channels to surface manager LDD in one process and accesses them individually
376 Open one channel called SurfaceManager1 to the surface manager LDD
377 Create SurfaceID using SurfaceManager1 (ref count is set to 1)
378 Then Open another channel called SurfaceManager2 to LDD in the same process
379 Open SurfaceID using SurfaceManager2 (ref count is incremented to 2)
380 Close SurfaceManager1
381 Call SurfaceInfo on SurfaceID and check it returns KErrNone, as SurfaceID is still open
382 Call CloseSurface on SurfaceID twice and then call SurfaceInfo to check it returns KErrArgument, as the surface is deleted after being closed twice.
383 Creating another surface using Surfacemanager2 and check that returns KErrNone too as SurfaceManager2 is still open.
384 @SYMTestStatus Implemented
385 @SYMTestActions Call CreateSurface(), OpenSurface(), SurfaceInfo(),CloseSurface()
386 @SYMTestExpectedResults If multiple connections are created to the driver, closing one surface manager channel will not affect other channels and the surfaces opened in the process.
389 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0018"));
390 TestMultipleChannelsL();
393 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0019
394 @SYMPREQ PREQ 1879,PREQ1007
395 @SYMREQ REQ8222,REQ8223
396 @SYMTestPriority High
397 @SYMTestCaseDesc This test checks the behaviour of closing driver channels
398 Open a channel called as SurfaceManager1 to the LDD by calling RSurfaceManager::Open()
399 Create one surface called as SurfaceID1 using SurfaceManager1
400 Then open another channel called as SurfaceManager2 to the LDD
401 Create another surface called as SurfaceID2 using SurfaceManager2
402 Open SurfaceID1 using both SurfaceManager1 and SurfaceManager2
403 Open SurfaceID2 using both SurfaceManager1 and SurfaceManager2
404 Close SurfaceManager1 and SurfaceManager2
405 Reopen a channel to the surface manger LDD
406 Call SurfaceInfo() to access both SurfaceID1 and SurfaceID2 and check both return KErrArgument, as both are deleted.
407 @SYMTestStatus Implemented
408 @SYMTestActions Call CreateSurface(), OpenSurface(), SurfaceInfo(),CloseSurface()
409 @SYMTestExpectedResults If multiple connections are created to the driver, closing one surface manager channel will not affect other channels and the surfaces opened in the process.
412 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0019"));
413 TestClosingChannelsL();
416 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0020
417 @SYMPREQ PREQ 1879,PREQ1007
418 @SYMREQ REQ8222,REQ8223
419 @SYMTestPriority High
420 @SYMTestCaseDesc Finding out the maximum number of surfaces to be created
421 Create a Surface till error occurs
422 Check the maximum number of surfaces created and the last error code
423 @SYMTestActions Call CreateSurface()
424 @SYMTestExpectedResults The maximum number varies between platforms(emulator and h4). The last error code is KErrNoMemory.
427 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0020"));
431 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0021
432 @SYMPREQ PREQ 1879,PREQ1007
433 @SYMREQ REQ8222,REQ8223
434 @SYMTestPriority High
435 @SYMTestCaseDesc Test the behaviour of SynchronizeCache()
436 Create the surface in a new shared chunk with valid creation attributes. The cache attribute is set to ECached.
437 Map the surface in the current process to get the chunk handle
438 Synchronise the cache before the hardware writes to the buffer. Pass TSyncOperation::ESyncBeforeHandwareWrite, valid buffer number and valid surfaceID in SynchronizeCache()
439 Synchronise again the cache after the hardware write the buffer. Pass TSyncOperation::ESyncAfterHandwareWrite, valid buffer number and valid surfaceID in SynchronizeCache()
440 Synchronise again the cache before the hardware reads the buffer. Pass TSyncOperation::ESyncBeforeHardwareRead, valid buffer number and valid surfaceID in SynchronizeCache()
441 Check each calls return KErrNone.
442 We can also visually check the result of SynchronizeCache() by investigating the MBX GCE tests.
443 @SYMTestActions Call CreateSurface(), SynchronizeCache()
444 @SYMTestExpectedResults The surface memory is synchronised properly with cached contents. All the synchronize operation returns KErrNone.
447 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0021"));
448 TestSynchronizeCacheL();
452 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0022
453 @SYMPREQ PREQ 1879,PREQ1007
454 @SYMREQ REQ8222,REQ8223
455 @SYMTestPriority High
456 @SYMTestCaseDesc Test that when two surfaces are created in the same shared chunk,
457 closing one surface and chunk handle will not cause the chunk to be deleted.
458 @SYMTestActions Call CreateSurface(), MapSurface(), CloseSurface()
459 @SYMTestExpectedResults If two surfaces are created on the same shared chunk. closing one surface and chunk handle will not cause the chunk to be deleted.
462 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0022"));
463 TestSharedChunkClosed2L();
467 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0023
468 @SYMPREQ PREQ 1879,PREQ1007
469 @SYMREQ REQ8222,REQ8223
470 @SYMTestPriority High
471 @SYMTestCaseDesc Test that GetSurfaceHint() behaves properly.
472 @SYMTestActions Call CreateSurface(), GetSurfaceHint()
473 @SYMTestExpectedResults GetSurfaceHint () returns KErrNone and retrieve THintPair value correctly
476 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0023"));
477 TestGetSurfaceHintL();
481 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0024
482 @SYMPREQ PREQ 1879,PREQ1007
483 @SYMREQ REQ8222,REQ8223
484 @SYMTestPriority High
485 @SYMTestCaseDesc Test that SetSurfaceHint() behaves properly
486 @SYMTestActions Call CreateSurface(), SetSurfaceHint()
487 @SYMTestExpectedResults SetSurfaceHint () can reset value in THintPair if iMutable is ETrue.
490 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0024"));
491 TestSetSurfaceHintL();
495 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0025
496 @SYMPREQ PREQ 1879,PREQ1007
497 @SYMREQ REQ8222,REQ8223
498 @SYMTestPriority High
499 @SYMTestCaseDesc Test that AddSurfaceHint() behaves properly
500 @SYMTestActions Call CreateSurface(), AddSurfaceHint()
501 @SYMTestExpectedResults AddSurfaceHint () can add a new surface hint value for the surface.
504 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0025"));
505 TestAddSurfaceHintL();
509 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0026
510 @SYMPREQ PREQ 1879,PREQ1007
511 @SYMREQ REQ8222,REQ8223
512 @SYMTestPriority High
513 @SYMTestCaseDesc This test creates a surface with invalid parameters in a new shared chunk
514 Set invalid values for the data members of TSurfaceCreationAttributes, which is used to create a Surface.
516 @SYMTestStatus Implemented
517 @SYMTestActions Call CreateSurface()
518 @SYMTestExpectedResults Check that CreateSurface() returns KErrArgument
521 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0026"));
522 TestCreateSurfaceInvalidParamsNewChunkL();
525 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0027
526 @SYMPREQ PREQ 1879,PREQ1007
527 @SYMREQ REQ8222,REQ8223
528 @SYMTestPriority High
529 @SYMTestCaseDesc This test creates a surface with invalid parameters in an exisiting shared chunk
530 Set invalid values for the data members of TSurfaceCreationAttributes, which is used to create a Surface.
531 Call CreateSurface and pass it the shared chunk handle.
532 @SYMTestStatus Implemented
533 @SYMTestActions Call CreateSurface()
534 @SYMTestExpectedResults Check that CreateSurface() returns KErrArgument
537 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0027"));
538 TestCreateSurfaceInvalidParamsExisitingChunkL();
541 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0028
542 @SYMPREQ PREQ 1879,PREQ1007
543 @SYMREQ REQ8222,REQ8223
544 @SYMTestPriority High
545 @SYMTestCaseDesc This test creates a surface with invalid parameters in an exisiting shared chunk which already contains a surface
546 Create a surface in a new shared chunk
547 Map the surface in the current process to get the shared chunk handle
548 Set invalid values for the data members of TSurfaceCreationAttributes, which is used to create a new Surface in the exising shared chunk.
549 Call CreateSurface and pass it the shared chunk handle.
550 @SYMTestStatus Implemented
551 @SYMTestActions Call CreateSurface()
552 @SYMTestExpectedResults Check that CreateSurface() returns KErrArgument
555 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0028"));
556 TestCreateSurfaceInvalidParamsExisitingChunk2L();
560 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0029
561 @SYMPREQ PREQ 1879,PREQ1007
562 @SYMREQ REQ8222,REQ8223
563 @SYMTestPriority High
564 @SYMTestCaseDesc Test that Hint keys can not be duplicated
565 @SYMTestStatus Implemented
566 @SYMTestActions Call CreateSurface()
567 @SYMTestExpectedResults Check that No duplicated Hint keys are allowed in the TSurfaceHints field
570 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0029"));
571 TestDuplicatedHintKeyL();
574 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0030
575 @SYMPREQ PREQ 1879,PREQ1007
576 @SYMREQ REQ8222,REQ8223
577 @SYMTestPriority High
578 @SYMTestCaseDesc This test checks that iContiguous is indeed ignored when creating the second surface on the existing shared chunk which already contains a surface
579 @SYMTestStatus Implemented
580 @SYMTestActions Call CreateSurface(), MapSurface(), CreateSurface(), SurfaceInfo()
581 @SYMTestExpectedResults Contiguous attribution in the surface info structure correctly reflects the Contiguous properties of the chunk used.
584 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0030"));
585 TestInvalidContiguousPropertyL();
589 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0031
590 @SYMPREQ PREQ 1879,PREQ1007
591 @SYMREQ REQ8222,REQ8223
592 @SYMTestPriority High
593 @SYMTestCaseDesc This test checks that iCacheAttrib is indeed ignored when creating the second surface on the existing shared chunk which already contains a surface
595 @SYMTestStatus Implemented
596 @SYMTestActions Call CreateSurface(), MapSurface, CreateSurface(), SurfaceInfo()
597 @SYMTestExpectedResults Cache attribution in the surface info structure correctly reflects the caching properties of the chunk used.
600 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0031"));
601 TestInvalidCachePropertyL();
605 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0032
606 @SYMPREQ PREQ 1879,PREQ1007
607 @SYMREQ REQ8222,REQ8223
608 @SYMTestPriority High
609 @SYMTestCaseDesc This test creates a Surface in an invalid chunk
610 @SYMTestStatus Implemented
611 @SYMTestActions Call CreateSurface(), Mapsurface, CloseSurface()
612 @SYMTestExpectedResults CreateSurface should return KErrBadHandle when the chunk handle is invalid
615 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0032"));
616 TestInvalidSharedChunkL();
619 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0033
621 @SYMREQ REQ8222,REQ8223
622 @SYMTestPriority High
623 @SYMTestCaseDesc This test create enough surfaces to cause KErrNoMemory
624 Set surface parameters to create a reasonably large (memory) surface
625 Create multiple surfaces using these parameters
626 @SYMTestStatus Implemented
627 @SYMTestActions Call CreateSurface()
628 @SYMTestExpectedResults Check that eventually that KErrNoMemory will be returned.
631 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0033"));
632 TestCreateVeryLargeSurfacesL();
635 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0034
637 @SYMREQ REQ8222,REQ8223
638 @SYMTestPriority High
639 @SYMTestCaseDesc This tests the MapSurface method with invalid surfaceId
642 1. making the Surface ID negative
643 2. converting the type of Surface ID to EInvalidSurface
644 MapSurface with new Surface ID
645 @SYMTestStatus Implemented
646 @SYMTestActions Call CreateSurface(), MapSurface()
647 @SYMTestExpectedResults Check that the return value of MapSurface() is KErrArgument
650 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0034"));
651 TestMapSurfaceInvalidParamsL();
654 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0035
656 @SYMREQ REQ8222,REQ8223
657 @SYMTestPriority High
658 @SYMTestCaseDesc This tests SurfaceInfo by passing invalid SurfaceID
660 Change the type of the SurfaceID
661 Call SurfaceInfo, pass the changed SurfaceID as a parameter
662 @SYMTestStatus Implemented
663 @SYMTestActions Call CreateSurface(), SurfaceInfo()
664 @SYMTestExpectedResults Check that the return value of SurfaceInfo() is KErrArgument.
667 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0035"));
668 TestSurfaceInfoChangedTypeL();
671 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0036
673 @SYMREQ REQ8222,REQ8223
674 @SYMTestPriority High
675 @SYMTestCaseDesc This tests the Closing surface method with invalid parameters
678 1. making the Surface ID negative
679 2. converting the type of the Surface ID to EInvalidSurface
680 Call CloseSurface with the new Surface ID
681 @SYMTestStatus Implemented
682 @SYMTestActions Call CreateSurface(), CloseSurface()
683 @SYMTestExpectedResults Check that CloseSurface() returns KErrArgument
686 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0036"));
687 TestCloseSurfaceInvalidParamsL();
690 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0037
692 @SYMREQ REQ8222,REQ8223
693 @SYMTestPriority High
694 @SYMTestCaseDesc Test that SynchronizeCache() reacts properly under false conditions
695 @SYMTestStatus Implemented
696 @SYMTestActions Call CreateSurface(), SynchronizeCache(), CloseSurface()
697 @SYMTestExpectedResults SynchronizeCache() returns KErrArgument under false conditions
700 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0037"));
701 TestSynchronizeCacheInvalidParamsL();
704 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0038
706 @SYMREQ REQ8222,REQ8223
707 @SYMTestPriority High
708 @SYMTestCaseDesc This tests closing a surface with the same ID twice
711 Close the surface again
712 @SYMTestStatus Implemented
713 @SYMTestActions Call CreateSurface(), CloseSurface()
714 @SYMTestExpectedResults Check that running CloseSurface() twice returns KErrArgument.
717 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0038"));
718 TestCloseSurfaceSameIDTwiceL();
721 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0039
723 @SYMREQ REQ8222,REQ8223
724 @SYMTestPriority High
725 @SYMTestCaseDesc Testing CreateSurface in out of memory conditions (for the debug mode only)
726 Open the surface manager
727 Call CreateSurface(), inducing a kernal alloc failure on each possible kernal alloc
728 @SYMTestStatus Implemented
729 @SYMTestActions Call CreateSurface()
730 @SYMTestExpectedResults Check that CreateSurface() returns KErrNoMemory.
733 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
735 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0039"));
736 TestCreateSurfaceOomL();
740 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0040
742 @SYMREQ REQ8222,REQ8223
743 @SYMTestPriority High
744 @SYMTestCaseDesc Testing that GetSurfaceHint()reacts properly under false conditions
745 Create the surface with valid creation attributes in a new shared chunk.
746 Find THintPair, Close the surface
747 Set false conditions and then call GetSurfaceHint()
748 @SYMTestStatus Implemented
749 @SYMTestActions Call CreateSurface(), GetSurfaceHint()
750 @SYMTestExpectedResults Check that GetSurfaceHint()returns KErrArgument under false conditions.
753 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0040"));
754 TestGetSurfaceHintInFalseConditionsL();
758 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0041
760 @SYMREQ REQ8222,REQ8223
761 @SYMTestPriority High
762 @SYMTestCaseDesc Testing that SetSurfaceHint()reacts properly under false conditions
763 Create the surface with valid creation attributes in a new shared chunk.
764 Set THintPair, Close the surface
765 Set false conditions and then call SetSurfaceHint()
766 @SYMTestStatus Implemented
767 @SYMTestActions Call CreateSurface(), SetSurfaceHint()
768 @SYMTestExpectedResults Check that SetSurfaceHint()returns KErrArgument under false conditions.
771 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0041"));
772 TestSetSurfaceHintInFalseConditionsL();
776 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0042
778 @SYMREQ REQ8222,REQ8223
779 @SYMTestPriority High
780 @SYMTestCaseDesc Testing that AddSurfaceHint()reacts properly under false conditions
781 Create the surface with valid creation attributes in a new shared chunk.
782 Set THintPair, Close the surface
783 Set false conditions and then call AddSurfaceHint()
784 @SYMTestStatus Implemented
785 @SYMTestActions Call CreateSurface(), AddSurfaceHint()
786 @SYMTestExpectedResults AddSurfaceHint () returns KErrArgument if the surface ID is invalid or not open in this process,
787 KErrAlreadyExists if duplicate hint key used, KErrOverflow if no space to add new pair.
790 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0042"));
791 TestAddSurfaceHintInFalseConditionsL();
795 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0043
797 @SYMREQ REQ8222,REQ8223
798 @SYMTestPriority High
799 @SYMTestCaseDesc Test AddSurfaceHint, SetSurfaceHint and SynchronizeCache performance
800 Calculate the average time:
801 - for setting surface hints at different location
802 - for adding hints at different location
803 - for synchronizing cache
805 @SYMTestStatus Implemented
806 @SYMTestActions Call CreateSurface(), AddSurfaceHint()and SetSurfaceHint
807 @SYMTestExpectedResults Performance is reasonable
810 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0043"));
811 TestPerformanceOfSurfaceHintAndCacheL();
815 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0044
817 @SYMREQ REQ8222,REQ8223
818 @SYMTestPriority High
819 @SYMTestCaseDesc Test CreateSurface() and CloseSurface() performance
820 Calculate the average time:
821 - for creating a surface in a new chunk
822 - for closing a surface
823 - for creating a surface in an existing chunk
825 @SYMTestStatus Implemented
826 @SYMTestActions Call CreateSurface() and CloseSurface()
827 @SYMTestExpectedResults Performance is reasonable
830 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0044"));
831 TestPerformanceOfSurfaceCreatingAndClosingL();
835 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0045
838 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0045"));
839 TestZerosInHintsArrayL();
843 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0082
846 @SYMTestPriority High
847 @SYMTestCaseDesc Test that Creating Surface with chunk that has "holes" works.
848 @SYMTestStatus Implemented
849 @SYMTestActions Call CreateSurface() with different sets of pages in the chunk.
850 @SYMTestExpectedResults Test should "pass" - this test has both positive and negative subtests.
853 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0082"));
854 TestCreateSurfaceChunkWithHolesL();
857 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0101
861 @SYMTestCaseDesc Test that Creating Surface with too many hints imply an error.
862 @SYMTestStatus Implemented
863 @SYMTestActions Call CreateSurface() with too many hints.
864 @SYMTestExpectedResults Negative test for CreateSurface.
867 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0101"));
868 TestCreateSurfaceWithTooManyHintsL();
872 @SYMTestCaseID GRAPHICS-SURFACEMANAGER-0102
876 @SYMTestCaseDesc Test that Creating Surface that is not mappable can then not be mapped.
877 @SYMTestStatus Implemented
878 @SYMTestActions Call CreateSurface() with attribute iMappable = EFalse,
879 then call MapSurface() and check that it is not successful.
880 same with GetBufferOffset
881 @SYMTestExpectedResults Negative test for MapSurface and GetBufferOffset.
884 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0102"));
885 TestCreateSurfaceUnMappableL();
889 ((CTSurfaceManagerStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
890 ((CTSurfaceManagerStep*)iStep)->CloseTMSGraphicsStep();
894 ((CTSurfaceManagerStep*)iStep)->RecordTestResultL();
895 TInt procHandles2 =0;
896 TInt threadHandles2=0;
897 RThread().HandleCount(procHandles2,threadHandles2);
898 if (threadHandles1 != threadHandles2)
900 User::Leave(KErrGeneral); // Thread-owned handles not closed
905 void CTSurfaceManager::TestPerformanceOfSurfaceCreatingAndClosingL()
907 INFO_PRINTF1(_L("Testing Surface Manager Performance\r\n"));
908 // Open the surface manager
909 User::LeaveIfError(iSurfaceManager.Open());
910 // Store the attributes used to create the Surface
911 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
912 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
914 attributes.iSize = TSize(100,100);
915 attributes.iBuffers = 1; // number of buffers in the surface
916 attributes.iPixelFormat = EUidPixelFormatYUV_422SemiPlanar;
917 attributes.iStride = 400; // Number of bytes between start of one line and start of next
918 attributes.iOffsetToFirstBuffer = 9; // way of reserving space before the surface pixel data
919 attributes.iAlignment = 1; // alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
920 RSurfaceManager::THintPair hints[2];
921 attributes.iHintCount=2;
922 hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
923 hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
924 attributes.iSurfaceHints = hints;
925 attributes.iOffsetBetweenBuffers = 50009;
926 attributes.iContiguous = ETrue;
927 attributes.iCacheAttrib = RSurfaceManager::ECached; // Cache attributes
928 attributes.iMappable = ETrue;
931 TSurfaceId surfaceId;
932 TUint32 timeBefore = 0;
933 TUint32 timeAfter = 0;
935 TReal measureTotal = 0;
938 RArray<TSurfaceId> surfaceIDArray;
940 User::LeaveIfError(HAL::Get(HALData::EFastCounterFrequency, iFreq));
941 // Scenario 1: measure the average time of creating
942 timeBefore = User::FastCounter();
949 timeBefore = User::FastCounter();
950 r = iSurfaceManager.CreateSurface(buf, surfaceId);
951 timeAfter = User::FastCounter();
952 measure= 1000000 * ((TReal)(timeAfter - timeBefore)) / ((TReal) iFreq);
953 // RDebug::Print(_L("Creating a surface [LOG]: \t%d \t%f "), index, measure);
954 measureTotal += measure;
955 surfaceIDArray.Insert(surfaceId,index++);
956 } while (r == KErrNone && index < 500);
958 TInt numberOfSurfaces = surfaceIDArray.Count();
959 INFO_PRINTF2(_L("the number of surface is %d\r\n"),numberOfSurfaces);
960 INFO_PRINTF2(_L("the average time for creating a surface is %f\r\n"),measureTotal/numberOfSurfaces);
963 while (index < numberOfSurfaces -1)
965 surfaceId = surfaceIDArray[index++];
967 // to delete the first surface being created
968 timeBefore = User::FastCounter();
969 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
970 timeAfter = User::FastCounter();
971 // 1000 for all the opeations, 1000000 for deletion only
972 measure = 1000000 * ((TReal)(timeAfter - timeBefore)) / ((TReal) iFreq);
973 measureTotal += measure;
974 // RDebug::Print(_L("Closing the surface [LOG]: \t%d \t%f "), index, measure);
977 INFO_PRINTF2(_L("the average time for Closing a surface is %f\r\n"),measureTotal/numberOfSurfaces);
979 surfaceIDArray.Close();
980 RArray<TSurfaceId> surfaceIDArray2;
982 // For CreateSurface in the existing chunk
983 TEST(KErrNone ==iSurfaceManager.CreateSurface(buf, surfaceId)) ;
984 //Map the surface in the current processs
986 TEST(KErrNone == iSurfaceManager.MapSurface(surfaceId,handle));
988 // Cache, Contiguous and Alignment attributes are ignored for the already existing chunks
989 RSurfaceManager::TSurfaceCreationAttributesBuf buff;
990 RSurfaceManager::TSurfaceCreationAttributes& attributesNew = buff();
992 attributesNew.iSize = TSize(480,16);
993 attributesNew.iBuffers = 2; // number of buffers in the surface
994 attributesNew.iPixelFormat = EUidPixelFormatYUV_422Reversed;
995 attributesNew.iStride = 1013; // Number of bytes between start of one line and start of next
996 attributesNew.iOffsetToFirstBuffer = 0; // way of reserving space before the surface pixel data
998 RSurfaceManager::THintPair hint;
999 attributesNew.iHintCount=1;
1000 hint.Set(TUid::Uid(0x124545), 50, EFalse);
1001 attributesNew.iSurfaceHints = &hint;
1002 attributesNew.iAlignment = RSurfaceManager::EPageAligned;
1003 attributesNew.iOffsetBetweenBuffers = 0;
1004 attributesNew.iMappable = ETrue;
1006 // Test create surface doesn't return an error
1007 TSurfaceId surfaceIdNew;
1014 TEST(KErrNone == r);
1015 timeBefore = User::FastCounter();
1016 r = iSurfaceManager.CreateSurface(buff, surfaceIdNew, handle);
1017 timeAfter = User::FastCounter();
1018 measure= 1000000 * ((TReal)(timeAfter - timeBefore)) / ((TReal) iFreq);
1019 // RDebug::Print(_L("CreateSurface in the existing chunk [LOG]: \t%d \t%f "), index, measure);
1020 measureTotal += measure;
1021 surfaceIDArray2.Insert(surfaceIdNew,index++);
1022 } while (r == KErrNone && index < 500);
1023 numberOfSurfaces = surfaceIDArray2.Count();
1025 INFO_PRINTF2(_L("the average time for Creating a surface in the existing chunk is %f\r\n"),measureTotal/numberOfSurfaces);
1028 while (index < numberOfSurfaces)
1030 surfaceIdNew = surfaceIDArray2[index++];
1031 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceIdNew));
1036 surfaceIDArray2.Close();
1037 iSurfaceManager.Close();
1040 void CTSurfaceManager::TestPerformanceOfSurfaceHintAndCacheL()
1042 INFO_PRINTF1(_L("Testing Surface Manager AddSurfaceHint, SetSurfaceHint, GetSurfaceHint and SynchronizeChace Performance\r\n"));
1043 // Open the surface manager
1044 User::LeaveIfError(iSurfaceManager.Open());
1045 // Store the attributes used to create the Surface
1046 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
1047 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
1049 TInt maxHintsPerSurface;
1050 iSurfaceManager.GetSurfaceManagerAttrib(RSurfaceManager::EMaxNumberOfHints,maxHintsPerSurface);
1051 // For SetSurfaceHint extreme search(binary search takes longest to locate the search if it is at the end)
1053 RArray<TInt32> uidArray;
1055 for (TInt i=0;i<maxHintsPerSurface-1;++i)
1057 uidArray.Append(0x237750+i);
1059 uidArray.Append(0x237778);
1061 attributes.iSize = TSize(1,1);
1062 attributes.iBuffers = 1;
1063 attributes.iPixelFormat = EUidPixelFormatYUV_422SemiPlanar; // 2bpp
1064 attributes.iStride = 1;
1065 attributes.iOffsetToFirstBuffer = 1;
1066 attributes.iAlignment = RSurfaceManager::EPageAligned;
1067 //Add 16 surface hints
1068 ReAllocHintsArrayL(maxHintsPerSurface);
1069 attributes.iHintCount=maxHintsPerSurface;
1070 for (i = 0; i<attributes.iHintCount; ++i)
1072 iHintsArray[i].Set(TUid::Uid(uidArray[i]), 25, ETrue);
1074 attributes.iSurfaceHints=iHintsArray;
1076 attributes.iOffsetBetweenBuffers = 0;
1077 attributes.iContiguous = ETrue;
1078 attributes.iCacheAttrib = RSurfaceManager::ECached; // Cache attributes
1079 attributes.iMappable = ETrue;
1082 TSurfaceId surfaceId;
1084 User::LeaveIfError(HAL::Get(HALData::EFastCounterFrequency, freq));
1085 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId));
1086 TUint32 timeBefore =0;
1087 TUint32 timeAfter= 0;
1090 TReal measureTotal = 0;
1091 const TInt numberOfCalculation = 500;
1093 RSurfaceManager::THintPair hintPair;
1094 RSurfaceManager::THintPair hintPair2;
1095 // Measure the average time of setting surface hints at different location
1096 for (i = 0; i<maxHintsPerSurface; ++i)
1099 for (TInt j = 0; j<numberOfCalculation; j++)
1101 hintPair.iKey.iUid = uidArray[i];
1102 hintPair.iValue = 300;
1103 hintPair.iMutable = ETrue;
1104 timeBefore = User::FastCounter();
1105 TEST(KErrNone == iSurfaceManager.SetSurfaceHint(surfaceId, hintPair));
1106 timeAfter = User::FastCounter();
1107 measure1 += 1000 * ((TReal)(timeAfter-timeBefore)) / ((TReal) freq);
1108 hintPair2.iKey.iUid = uidArray[i];
1109 TEST(KErrNone == iSurfaceManager.GetSurfaceHint(surfaceId, hintPair2));
1110 TEST(hintPair2.iValue == 300);
1111 TEST(hintPair2.iMutable == 1);
1113 // RDebug::Print(_L("[LOG]: \t%d \t%f "), i, measure1/numberOfCalculation);
1114 measureTotal +=measure1;
1116 INFO_PRINTF2(_L("the average time for SetSurfaceHint is %f\r\n"),measureTotal/8);
1118 RDebug::Print(_L("SetSurfaceHint Test finished"));
1119 iSurfaceManager.CloseSurface(surfaceId);
1120 // For AddSurfaceHint
1121 RSurfaceManager::TSurfaceCreationAttributesBuf bufNew;
1122 RSurfaceManager::TSurfaceCreationAttributes& attributesNew = bufNew();
1123 attributesNew.iSize = TSize(1,1);
1124 attributesNew.iBuffers = 1;
1125 attributesNew.iPixelFormat = EUidPixelFormatYUV_422SemiPlanar; // 2bpp
1126 attributesNew.iStride = 1;
1127 attributesNew.iOffsetToFirstBuffer = 1;
1128 attributesNew.iAlignment = RSurfaceManager::EPageAligned;
1129 attributesNew.iOffsetBetweenBuffers = 0;
1130 attributesNew.iContiguous = ETrue;
1131 attributesNew.iCacheAttrib = RSurfaceManager::ECached; // Cache attributes
1132 attributesNew.iMappable = ETrue;
1134 // Create a surface with no surface hints defined
1135 TSurfaceId surfaceIdNew;
1136 TInt err1 = iSurfaceManager.CreateSurface(bufNew, surfaceIdNew);
1137 TEST(KErrNone == err1);
1139 // Measure time of adding surface hint of different location
1140 for (i = 0; i<maxHintsPerSurface; ++i)
1142 hintPair.iKey.iUid = uidArray[i];
1143 hintPair.iValue = 300+i;
1144 hintPair.iMutable = ETrue;
1145 timeBefore = User::FastCounter();
1146 TEST(KErrNone == iSurfaceManager.AddSurfaceHint(surfaceIdNew, hintPair));
1147 timeAfter = User::FastCounter();
1148 measure1 = 1000 * ((TReal)(timeAfter-timeBefore)) / ((TReal) freq);
1149 measureTotal += measure1;
1150 // RDebug::Print(_L("AddSurfaceHint [LOG]: \t%d \t%f "), i, measure1);
1152 INFO_PRINTF2(_L("the average time for AddSurfaceHint is %f\r\n"),measureTotal/8);
1154 // Check all 8 hint pairs have the right values
1156 for (i = 0; i<maxHintsPerSurface; ++i)
1158 hintPair2.iKey.iUid = uidArray[i];
1159 timeBefore = User::FastCounter();
1160 TEST(KErrNone == iSurfaceManager.GetSurfaceHint(surfaceIdNew, hintPair2));
1161 timeAfter = User::FastCounter();
1162 measure1 = 1000 * ((TReal)(timeAfter-timeBefore)) / ((TReal) freq);
1163 measureTotal += measure1;
1164 // RDebug::Print(_L("GetSurfaceHint [LOG]: \t%d \t%f "), i, measure1);
1165 TEST(hintPair2.iValue == 300+i);
1166 TEST(hintPair2.iMutable == 1);
1168 INFO_PRINTF2(_L("the average time for GetSurfaceHint is %f\r\n"),measureTotal/8);
1170 iSurfaceManager.CloseSurface(surfaceIdNew);
1173 // For SynchronizeCache
1174 TEST(KErrNone == iSurfaceManager.CreateSurface(bufNew, surfaceIdNew));
1179 timeBefore = User::FastCounter();
1180 TEST(KErrNone == iSurfaceManager.SynchronizeCache(surfaceIdNew,0, RSurfaceManager::ESyncBeforeNonCPURead));
1181 timeAfter = User::FastCounter();
1182 measure1= 1000000 * ((TReal)(timeAfter - timeBefore)) / ((TReal) freq);
1183 // RDebug::Print(_L("SynchronizeCache [LOG]: \t%d \t%f "), index, measure1);
1184 measureTotal += measure1;
1185 } while ( index++ < numberOfCalculation);
1187 INFO_PRINTF2(_L("the average time for SynchronizeCache a surface is %f\r\n"),measureTotal/numberOfCalculation);
1189 iSurfaceManager.CloseSurface(surfaceIdNew);
1192 iSurfaceManager.Close();
1197 void CTSurfaceManager::TestCreateSurfaceNewChunk1L()
1199 INFO_PRINTF1(_L("Creating a Surface in a new shared chunk\r\n"));
1200 // Open the surface manager
1201 User::LeaveIfError(iSurfaceManager.Open());
1204 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
1205 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
1207 attributes.iSize = TSize(100,100);
1208 attributes.iBuffers = 1; // number of buffers in the surface
1209 attributes.iPixelFormat = EUidPixelFormatYUV_422SemiPlanar;
1210 attributes.iStride = 400; // Number of bytes between start of one line and start of next
1211 attributes.iAlignment = RSurfaceManager::EPageAligned; // alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
1213 RSurfaceManager::THintPair hints[2];
1214 attributes.iHintCount=2;
1215 hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
1216 hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
1217 attributes.iSurfaceHints = hints;
1218 attributes.iOffsetBetweenBuffers = 0;
1219 attributes.iContiguous = ETrue;
1220 attributes.iCacheAttrib = RSurfaceManager::ENotCached; // Cache attributes
1221 attributes.iMappable = ETrue;
1223 // Test create surface doesn't return an error
1224 SurfaceOperation(buf);
1226 //cache attribute is not valid on emulator
1228 TEST(iInfo.iCacheAttrib == attributes.iCacheAttrib);
1230 INFO_PRINTF1(_L("Cache attribute test is not valid on emulator\n"));
1233 //contiguous attribute is not valid on emulator
1235 TEST(iInfo.iContiguous == attributes.iContiguous);
1237 INFO_PRINTF1(_L("Contiguous attribute test is not valid on emulator\n"));
1240 TEST(KErrNone == iSurfaceManager.CloseSurface(iSurfaceId));
1242 //Test different contiguous attricutes
1243 attributes.iContiguous=EFalse;
1244 // Test create surface doesn't return an error
1245 SurfaceOperation(buf);
1247 //contiguous attribute is not valid on emulator
1249 if(attributes.iContiguous)
1250 TEST(iInfo.iContiguous == attributes.iContiguous);
1252 INFO_PRINTF1(_L("We didn't ask for contiguous memory so we don't care how it's going to be (can be contiguous or not)\n"));
1254 INFO_PRINTF1(_L("Contiguous attribute test is not valid on emulator\n"));
1257 TEST(KErrNone == iSurfaceManager.CloseSurface(iSurfaceId));
1259 // Test different cache attributes
1260 attributes.iCacheAttrib = RSurfaceManager::ENotCached; // Cache attributes
1261 // Test create surface doesn't return an error
1262 SurfaceOperation(buf);
1264 //cache attribute is not valid on emulator
1266 TEST(iInfo.iCacheAttrib == attributes.iCacheAttrib);
1268 INFO_PRINTF1(_L("Cache attribute test is not valid on emulator\n"));
1271 TEST(KErrNone == iSurfaceManager.CloseSurface(iSurfaceId));
1273 //Set different alignment for CPU cached and noncached, test create surface doesn't return an error
1274 ChangeAttributes(&attributes, (TInt)RSurfaceManager::EPageAligned, 4096, 53248, RSurfaceManager::ECached);
1275 SurfaceOperation(buf);
1276 CheckAttributesL(attributes);
1277 TEST(KErrNone == iSurfaceManager.CloseSurface(iSurfaceId));
1279 ChangeAttributes(&attributes, (TInt)RSurfaceManager::EPageAligned, 4096, 53248, RSurfaceManager::ENotCached);
1280 SurfaceOperation(buf);
1281 CheckAttributesL(attributes);
1282 TEST(KErrNone == iSurfaceManager.CloseSurface(iSurfaceId));
1284 ChangeAttributes(&attributes, 1, 32, 50016, RSurfaceManager::ECached);
1285 SurfaceOperation(buf);
1286 CheckAttributesL(attributes);
1287 TEST(KErrNone == iSurfaceManager.CloseSurface(iSurfaceId));
1289 ChangeAttributes(&attributes, 1, 10, 50010, RSurfaceManager::ENotCached);
1290 SurfaceOperation(buf);
1291 CheckAttributesL(attributes);
1292 TEST(KErrNone == iSurfaceManager.CloseSurface(iSurfaceId));
1294 ChangeAttributes(&attributes, 2, 32, 50016, RSurfaceManager::ECached);
1295 SurfaceOperation(buf);
1296 CheckAttributesL(attributes);
1297 TEST(KErrNone == iSurfaceManager.CloseSurface(iSurfaceId));
1299 ChangeAttributes(&attributes, 2, 10, 50010, RSurfaceManager::ENotCached);
1300 SurfaceOperation(buf);
1301 CheckAttributesL(attributes);
1302 TEST(KErrNone == iSurfaceManager.CloseSurface(iSurfaceId));
1304 ChangeAttributes(&attributes, 4, 32, 50016, RSurfaceManager::ECached);
1305 SurfaceOperation(buf);
1306 CheckAttributesL(attributes);
1307 TEST(KErrNone == iSurfaceManager.CloseSurface(iSurfaceId));
1309 ChangeAttributes(&attributes, 4, 12, 50012, RSurfaceManager::ENotCached);
1310 SurfaceOperation(buf);
1311 CheckAttributesL(attributes);
1312 TEST(KErrNone == iSurfaceManager.CloseSurface(iSurfaceId));
1314 ChangeAttributes(&attributes, 8, 32, 50016, RSurfaceManager::ECached);
1315 SurfaceOperation(buf);
1316 CheckAttributesL(attributes);
1317 TEST(KErrNone == iSurfaceManager.CloseSurface(iSurfaceId));
1319 ChangeAttributes(&attributes, 8, 16, 50016, RSurfaceManager::ENotCached);
1320 SurfaceOperation(buf);
1321 CheckAttributesL(attributes);
1322 TEST(KErrNone == iSurfaceManager.CloseSurface(iSurfaceId));
1324 ChangeAttributes(&attributes, 16, 32, 50016, RSurfaceManager::ECached);
1325 SurfaceOperation(buf);
1326 CheckAttributesL(attributes);
1327 TEST(KErrNone == iSurfaceManager.CloseSurface(iSurfaceId));
1329 ChangeAttributes(&attributes, 16, 16, 50016, RSurfaceManager::ENotCached);
1330 SurfaceOperation(buf);
1331 CheckAttributesL(attributes);
1332 TEST(KErrNone == iSurfaceManager.CloseSurface(iSurfaceId));
1334 ChangeAttributes(&attributes, 32, 32, 50016, RSurfaceManager::ECached);
1335 SurfaceOperation(buf);
1336 CheckAttributesL(attributes);
1337 TEST(KErrNone == iSurfaceManager.CloseSurface(iSurfaceId));
1339 ChangeAttributes(&attributes, 32, 32, 50016, RSurfaceManager::ENotCached);
1340 SurfaceOperation(buf);
1341 CheckAttributesL(attributes);
1342 TEST(KErrNone == iSurfaceManager.CloseSurface(iSurfaceId));
1344 ChangeAttributes(&attributes, 64, 64, 50048, RSurfaceManager::ECached);
1345 SurfaceOperation(buf);
1346 CheckAttributesL(attributes);
1347 TEST(KErrNone == iSurfaceManager.CloseSurface(iSurfaceId));
1349 ChangeAttributes(&attributes, 64, 64, 50048, RSurfaceManager::ENotCached);
1350 SurfaceOperation(buf);
1351 CheckAttributesL(attributes);
1352 TEST(KErrNone == iSurfaceManager.CloseSurface(iSurfaceId));
1354 // Close the surface manager
1355 iSurfaceManager.Close();
1358 void CTSurfaceManager::ChangeAttributes(RSurfaceManager::TSurfaceCreationAttributes* aAttributes, TInt aAlignment, TInt aOffsetToFirstBuffer, TInt aOffsetBetweenBuffers, RSurfaceManager::TCacheAttribute aCacheAttrib)
1360 aAttributes->iAlignment = aAlignment;
1361 aAttributes->iOffsetToFirstBuffer = aOffsetToFirstBuffer;
1362 aAttributes->iOffsetBetweenBuffers = aOffsetBetweenBuffers;
1363 aAttributes->iCacheAttrib = aCacheAttrib;
1366 void CTSurfaceManager::SurfaceOperation(RSurfaceManager::TSurfaceCreationAttributesBuf& aBuf)
1368 TEST(KErrNone == iSurfaceManager.CreateSurface(aBuf, iSurfaceId));
1369 TEST(KErrNone == iSurfaceManager.SurfaceInfo(iSurfaceId, iInfoBuf));
1373 void CTSurfaceManager::CheckAttributesL(RSurfaceManager::TSurfaceCreationAttributes& aAttributes)
1375 TEST(aAttributes.iSize==iInfo.iSize);
1376 TEST(aAttributes.iBuffers==iInfo.iBuffers);
1377 TEST(aAttributes.iPixelFormat==iInfo.iPixelFormat);
1378 TEST(aAttributes.iStride==iInfo.iStride);
1379 if(aAttributes.iContiguous)
1380 TEST(iInfo.iContiguous == aAttributes.iContiguous);
1382 INFO_PRINTF1(_L("We didn't ask for contiguous memory so we don't care how it's going to be (can be contiguous or not)\n"));
1383 TEST(aAttributes.iCacheAttrib==iInfo.iCacheAttrib);
1385 //Test the chunk size is big enough to hold the surface when we create it
1386 //with the offset between buffers
1387 if (aAttributes.iOffsetBetweenBuffers!=0)
1389 CheckSizeL(aAttributes.iOffsetToFirstBuffer, aAttributes.iOffsetBetweenBuffers);
1393 void CTSurfaceManager::CheckSizeL(TInt aOffsetToFirstBuffer, TInt aOffsetBetweenBuffers)
1395 TInt64 bufferSize = iInfo.iBuffers * aOffsetBetweenBuffers;
1396 TInt64 chunkSize = aOffsetToFirstBuffer + bufferSize;
1397 TESTL(KErrNone == iSurfaceManager.MapSurface(iSurfaceId,iHandle));
1398 TInt64 currChunkSize = iHandle.Size();
1399 TEST(currChunkSize >= chunkSize);
1403 void CTSurfaceManager::TestCreateSurfaceNewChunk2L()
1405 INFO_PRINTF1(_L("Creating a Surface in a new shared chunk\r\n"));
1406 // Open the surface manager
1407 User::LeaveIfError(iSurfaceManager.Open());
1410 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
1411 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
1413 attributes.iSize = TSize(100,100);
1414 attributes.iBuffers = 1; // number of buffers in the surface
1415 attributes.iPixelFormat = EUidPixelFormatYUV_422SemiPlanar;
1416 attributes.iStride = 400; // Number of bytes between start of one line and start of next
1417 attributes.iOffsetToFirstBuffer = 9; // way of reserving space before the surface pixel data
1418 attributes.iAlignment = 1; // alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
1420 RSurfaceManager::THintPair hints[2];
1421 attributes.iHintCount=2;
1422 hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
1423 hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
1424 attributes.iSurfaceHints = hints;
1426 attributes.iOffsetBetweenBuffers = 50009;
1427 attributes.iContiguous = ETrue;
1428 attributes.iCacheAttrib = RSurfaceManager::ECached; // Cache attributes
1429 attributes.iMappable = ETrue;
1431 //Test create surface doesn't return an error
1432 SurfaceOperation(buf);
1433 CheckSizeL(32, 50016);
1434 TEST(KErrNone == iSurfaceManager.CloseSurface(iSurfaceId));
1436 // Test different cache attributes
1437 attributes.iCacheAttrib = RSurfaceManager::ENotCached; // Cache attributes
1438 SurfaceOperation(buf);
1439 CheckSizeL(9, 50009);
1440 TEST(KErrNone == iSurfaceManager.CloseSurface(iSurfaceId));
1442 ChangeAttributes(&attributes, 2, 9, 50009, RSurfaceManager::ECached);
1443 SurfaceOperation(buf);
1444 CheckSizeL(32,50016);
1445 TEST(KErrNone == iSurfaceManager.CloseSurface(iSurfaceId));
1447 ChangeAttributes(&attributes, 2, 9, 50009, RSurfaceManager::ENotCached);
1448 SurfaceOperation(buf);
1449 CheckSizeL(10,50010);
1450 TEST(KErrNone == iSurfaceManager.CloseSurface(iSurfaceId));
1452 ChangeAttributes(&attributes, 4, 10, 50010, RSurfaceManager::ECached);
1453 SurfaceOperation(buf);
1454 CheckSizeL(32,50016);
1455 TEST(KErrNone == iSurfaceManager.CloseSurface(iSurfaceId));
1457 ChangeAttributes(&attributes, 4, 10, 50010, RSurfaceManager::ENotCached);
1458 SurfaceOperation(buf);
1459 CheckSizeL(12,50012);
1460 TEST(KErrNone == iSurfaceManager.CloseSurface(iSurfaceId));
1462 ChangeAttributes(&attributes, 8, 10, 50010, RSurfaceManager::ECached);
1463 SurfaceOperation(buf);
1464 CheckSizeL(32,50016);
1465 TEST(KErrNone == iSurfaceManager.CloseSurface(iSurfaceId));
1467 ChangeAttributes(&attributes, 8, 10, 50010, RSurfaceManager::ENotCached);
1468 SurfaceOperation(buf);
1469 CheckSizeL(16,50016);
1470 TEST(KErrNone == iSurfaceManager.CloseSurface(iSurfaceId));
1472 ChangeAttributes(&attributes, 16, 10, 50010, RSurfaceManager::ECached);
1473 SurfaceOperation(buf);
1474 CheckSizeL(32,50016);
1475 TEST(KErrNone == iSurfaceManager.CloseSurface(iSurfaceId));
1477 ChangeAttributes(&attributes, 16, 10, 50010, RSurfaceManager::ENotCached);
1478 SurfaceOperation(buf);
1479 CheckSizeL(16,50016);
1480 TEST(KErrNone == iSurfaceManager.CloseSurface(iSurfaceId));
1482 ChangeAttributes(&attributes, 32, 10, 50010, RSurfaceManager::ECached);
1483 SurfaceOperation(buf);
1484 CheckSizeL(32,50016);
1485 TEST(KErrNone == iSurfaceManager.CloseSurface(iSurfaceId));
1487 ChangeAttributes(&attributes, 32, 10, 50010, RSurfaceManager::ENotCached);
1488 SurfaceOperation(buf);
1489 CheckSizeL(32,50016);
1490 TEST(KErrNone == iSurfaceManager.CloseSurface(iSurfaceId));
1492 ChangeAttributes(&attributes, 64, 10, 50010, RSurfaceManager::ECached);
1493 SurfaceOperation(buf);
1494 CheckSizeL(64,50048);
1495 TEST(KErrNone == iSurfaceManager.CloseSurface(iSurfaceId));
1497 ChangeAttributes(&attributes, 64, 10, 50010, RSurfaceManager::ENotCached);
1498 SurfaceOperation(buf);
1499 CheckSizeL(64,50048);
1500 TEST(KErrNone == iSurfaceManager.CloseSurface(iSurfaceId));
1503 ChangeAttributes(&attributes, (TInt)RSurfaceManager::EPageAligned, 10, 50010, RSurfaceManager::ECached);
1504 SurfaceOperation(buf);
1505 CheckSizeL(4096,53248);
1506 TEST(KErrNone == iSurfaceManager.CloseSurface(iSurfaceId));
1508 ChangeAttributes(&attributes, (TInt)RSurfaceManager::EPageAligned, 10, 50010, RSurfaceManager::ENotCached);
1509 SurfaceOperation(buf);
1510 CheckSizeL(4096,53248);
1511 TEST(KErrNone == iSurfaceManager.CloseSurface(iSurfaceId));
1513 // Close the surface manager
1514 iSurfaceManager.Close();
1517 void CTSurfaceManager::TestCreateSurfaceExisitingChunkL()
1519 INFO_PRINTF1(_L("creating a surface in an exisiting shared chunk\r\n"));
1520 // Call another device driver to get a valid shared chunk handle
1521 RSharedChunkLdd device;
1523 TUint ChunkSize = 204800; // bottom 8 bits reserved space for other chunk creation attributes info
1524 TUint ChunkAttribs = ChunkSize|EMultiple|EOwnsMemory|ECached;
1525 TUint ContiguousAttrib = 1;
1526 GetSharedChunkHandleL(device, handle, ChunkSize, ChunkAttribs, ContiguousAttrib);
1528 INFO_PRINTF1(_L("Creating a Surface in an exisitng shared chunk\r\n"));
1529 // Open the surface manager
1530 User::LeaveIfError(iSurfaceManager.Open());
1533 // Cache, Contiguous and Alignment attributes are ignored for the already existing chunks
1534 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
1535 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
1537 attributes.iSize = TSize(100,100);
1538 attributes.iBuffers = 1; // number of buffers in the surface
1539 attributes.iPixelFormat = EUidPixelFormatYUV_422SemiPlanar;
1540 attributes.iStride = 400; // Number of bytes between start of one line and start of next
1541 attributes.iOffsetToFirstBuffer = 4096; // way of reserving space before the surface pixel data
1542 attributes.iAlignment = 4;
1544 RSurfaceManager::THintPair hints[2];
1545 attributes.iHintCount=2;
1546 hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
1547 hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
1548 attributes.iSurfaceHints = hints;
1550 attributes.iOffsetBetweenBuffers = 0;
1552 attributes.iMappable = ETrue;
1554 TSurfaceId surfaceId;
1555 // Test create surface doesn't return an error
1556 TInt err = iSurfaceManager.CreateSurface(buf, surfaceId, handle);
1557 TEST(KErrNone == err);
1559 RSurfaceManager::TInfoBuf infoBuf;
1560 RSurfaceManager::TSurfaceInfoV01& info = infoBuf();
1561 if (err == KErrNone)
1563 TEST(KErrNone == iSurfaceManager.SurfaceInfo(surfaceId, infoBuf));
1565 //cache attribute is not valid on emulator
1567 TEST(info.iCacheAttrib == device.GetCacheAttribute());
1569 INFO_PRINTF1(_L("Cache attribute test is not valid on emulator\n"));
1572 //contiguous attribute is not valid on emulator
1574 TEST(info.iContiguous == device.GetContiguousAttribute());
1576 INFO_PRINTF1(_L("Contiguous attribute test is not valid on emulator\n"));
1579 //Map the surface to get a new shared chunk handle
1581 TEST(KErrNone == iSurfaceManager.MapSurface(surfaceId,handle2));
1583 //Check the two handles are different but refer to the same shared chunk
1584 TEST(handle.Handle() != handle2.Handle());
1585 TEST(handle.Base() == handle2.Base());
1587 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
1592 //Reset iOffsetBetweenBuffers is 40960
1593 attributes.iOffsetBetweenBuffers = 40960;
1594 attributes.iAlignment = RSurfaceManager::EPageAligned;
1595 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId, handle));
1597 TEST(KErrNone == iSurfaceManager.SurfaceInfo(surfaceId, infoBuf));
1598 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
1600 //Test different iOffsetBetweenBuffers attributes
1601 attributes.iOffsetBetweenBuffers = 53248;
1603 // Test create surface doesn't return an error
1604 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId, handle));
1605 TEST(KErrNone == iSurfaceManager.MapSurface(surfaceId,handle3));
1606 TEST(KErrNone == iSurfaceManager.SurfaceInfo(surfaceId, infoBuf));
1608 //Test the chunk size is big enough to hold the surface
1609 TInt64 bufferSize= attributes.iBuffers * attributes.iOffsetBetweenBuffers;
1610 TInt64 chunkSize = attributes.iOffsetToFirstBuffer + bufferSize;
1611 TInt64 currChunkSize = handle3.Size();
1613 TEST(currChunkSize >= chunkSize);
1614 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
1616 //set iBuffer is equal to 2 and test iOffsetBetweenBuffers returns the right value, check the chunk size is big enough to hold the surface
1617 attributes.iBuffers = 2;
1619 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId, handle));
1620 TEST(KErrNone == iSurfaceManager.MapSurface(surfaceId,handle4));
1621 TEST(KErrNone == iSurfaceManager.SurfaceInfo(surfaceId, infoBuf));
1623 bufferSize = attributes.iBuffers * attributes.iOffsetBetweenBuffers;
1624 chunkSize = attributes.iOffsetToFirstBuffer + bufferSize;
1625 currChunkSize = handle4.Size();
1627 TInt offsetToFirstBuffer;
1628 TInt offsetBetweenBuffers;
1629 err=iSurfaceManager.GetBufferOffset(surfaceId, 0, offsetToFirstBuffer);
1630 err=iSurfaceManager.GetBufferOffset(surfaceId, 1, offsetBetweenBuffers);
1631 offsetBetweenBuffers-=offsetToFirstBuffer;
1632 TEST(offsetBetweenBuffers == attributes.iOffsetBetweenBuffers);
1633 TEST(currChunkSize >= chunkSize);
1634 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
1639 device.CloseChunkHandle(handle);
1640 // Close the surface manager
1641 iSurfaceManager.Close();
1642 device.CloseChunk();
1647 void CTSurfaceManager::TestCreateSurfaceChunkWithHolesL()
1649 INFO_PRINTF1(_L("creating a surface in an exisiting shared chunk with HOLES\r\n"));
1650 // Call another device driver to get a valid shared chunk handle
1651 RSharedChunkLdd device;
1653 TUint ChunkSize = 204800;
1654 TUint ChunkAttribs = ChunkSize|EMultiple|EOwnsMemory|ECached;
1655 TUint ContiguousAttrib = 0;
1656 // We use the same stride everywhere to make life easier.
1657 const TUint KStride = 64;
1660 INFO_PRINTF1(_L("Load Logical Device\r\n"));
1661 r=User::LoadLogicalDevice(KSharedChunkLddName);
1662 TEST(r==KErrNone || r==KErrAlreadyExists);
1664 INFO_PRINTF1(_L("Open Device"));
1665 User::LeaveIfError(device.Open());
1667 //Create shared chunk and commit the memory
1668 INFO_PRINTF1(_L("Test chunk create"));
1670 TEST(KErrNone==device.CreateChunk(ChunkAttribs));
1672 // Find size of a page.
1674 TEST(KErrNone == UserHal::PageSizeInBytes(pageSize));
1675 // Fill in one page's worth of memory.
1676 TEST(KErrNone==device.CommitMemory(0 | ContiguousAttrib, pageSize));
1678 //Get the chunk handle
1679 INFO_PRINTF1(_L("Open user handle"));
1680 TEST(KErrNone==device.GetChunkHandle(handle));
1682 INFO_PRINTF1(_L("Creating a Surface in an exisitng shared chunk with holes\r\n"));
1683 // Open the surface manager
1684 User::LeaveIfError(iSurfaceManager.Open());
1687 // Cache, Contiguous and Alignment attributes are ignored for the already existing chunks
1688 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
1689 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
1691 attributes.iSize = TSize(10,10);
1692 attributes.iBuffers = 2; // number of buffers in the surface
1693 attributes.iPixelFormat = EUidPixelFormatYUV_422SemiPlanar;
1694 attributes.iStride = KStride; // Number of bytes between start of one line and start of next
1695 attributes.iOffsetToFirstBuffer = pageSize; // Add this to the first address -> fails, since the actual content is
1696 // outside of the chunk.
1697 attributes.iOffsetBetweenBuffers = 0; // 0 => Let CreateSurface calculatet the size by itself.
1698 attributes.iAlignment = 4; // Need to have some alignment.
1699 attributes.iMappable = ETrue;
1701 TSurfaceId surfaceId;
1702 // This should FAIL.
1703 TInt err = iSurfaceManager.CreateSurface(buf, surfaceId, handle);
1704 TEST(KErrArgument == err);
1706 // Use a smaller "user area" so that it will fit.
1707 attributes.iSize = TSize(10,10);
1708 attributes.iOffsetToFirstBuffer = 100; // way of reserving space before the surface pixel data
1710 // This should PASS.
1711 err = iSurfaceManager.CreateSurface(buf, surfaceId, handle);
1712 TEST(KErrNone == err);
1713 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
1715 // Now add in another bit of memory 2*pagesize so that a second buffer fits in the page..
1716 TEST(KErrNone==device.CommitMemory(pageSize * 2 | ContiguousAttrib, pageSize));
1718 attributes.iSize = TSize(32,pageSize / KStride);
1719 attributes.iOffsetToFirstBuffer = 0; // way of reserving space before the surface pixel data
1720 attributes.iOffsetBetweenBuffers = pageSize * 2;
1722 // This should PASS.
1723 err = iSurfaceManager.CreateSurface(buf, surfaceId, handle);
1724 TEST(KErrNone == err);
1725 RSurfaceManager::TInfoBuf infoBuf;
1726 TEST(KErrNone == iSurfaceManager.SurfaceInfo(surfaceId, infoBuf));
1727 RSurfaceManager::TSurfaceInfoV01& info = infoBuf();
1728 // Check that we do NOT get a contiguous surface back - it isn't contiguous when
1729 // there is a hole in it!
1730 TEST(!info.iContiguous);
1731 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
1733 attributes.iSize = TSize(32,(pageSize + pageSize / 2) / KStride); // Use 1.5 pages worth.
1735 // This should FAIL.
1736 err = iSurfaceManager.CreateSurface(buf, surfaceId, handle);
1737 TEST(KErrArgument == err);
1739 attributes.iSize = TSize(32,(pageSize / 2) / KStride); // Half a page of buffer.
1740 attributes.iOffsetToFirstBuffer = pageSize / 2; // Half a page of "user data" at first buffer.
1742 // This should PASS.
1743 err = iSurfaceManager.CreateSurface(buf, surfaceId, handle);
1744 TEST(KErrNone == err);
1745 TEST(KErrNone == iSurfaceManager.SurfaceInfo(surfaceId, infoBuf));
1747 // Check that we do NOT get a contiguous surface back - it isn't contiguous when
1748 // there is a hole in it!
1749 TEST(!info.iContiguous);
1750 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
1752 attributes.iSize = TSize(32,((pageSize / 2) / KStride)-1); // Half a page of buffer - minus a tiny bit.
1753 attributes.iOffsetToFirstBuffer = KStride + pageSize / 2; // Half a page of "user data" at first buffer, plus a bit. .
1754 attributes.iAlignment = KStride;
1756 // This should PASS.
1757 err = iSurfaceManager.CreateSurface(buf, surfaceId, handle);
1758 TEST(KErrNone == err);
1759 TEST(KErrNone == iSurfaceManager.SurfaceInfo(surfaceId, infoBuf));
1761 // Check that we do NOT get a contiguous surface back - it isn't contiguous when
1762 // there is a hole in it!
1763 TEST(!info.iContiguous);
1764 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
1766 // Half a page of "user data" at first buffer, plus 2 strides to go over the edge
1767 attributes.iOffsetToFirstBuffer = 2 * KStride + pageSize / 2;
1768 attributes.iAlignment = 4;
1770 // This should FAIL.
1771 err = iSurfaceManager.CreateSurface(buf, surfaceId, handle);
1772 TEST(KErrArgument == err);
1774 // Ask for HUGE buffer with no actual memory there.
1775 attributes.iSize = TSize(32, pageSize * pageSize); // A page of pages * stride is several gigabytes at 4K/page.
1778 err = iSurfaceManager.CreateSurface(buf, surfaceId, handle);
1779 TEST(KErrArgument == err);
1781 device.CloseChunkHandle(handle);
1782 // Close the surface manager
1783 iSurfaceManager.Close();
1784 device.CloseChunk();
1788 void CTSurfaceManager::GetSharedChunkHandleL(RSharedChunkLdd& aDevice, RChunk& aHandle, TUint aChunkSize, TUint aChunkAttribs, TUint aContiguousAttrib)
1792 INFO_PRINTF1(_L("Load Logical Device\r\n"));
1793 r=User::LoadLogicalDevice(KSharedChunkLddName);
1794 TEST(r==KErrNone || r==KErrAlreadyExists);
1796 INFO_PRINTF1(_L("Open Device"));
1797 User::LeaveIfError(aDevice.Open());
1799 //Create shared chunk and commit the memory
1800 INFO_PRINTF1(_L("Test chunk create"));
1802 TEST(KErrNone==aDevice.CreateChunk(aChunkAttribs));
1803 TEST(KErrNone==aDevice.CommitMemory(aContiguousAttrib, aChunkSize));
1805 //Get the chunk handle
1806 INFO_PRINTF1(_L("Open user handle"));
1807 TEST(KErrNone==aDevice.GetChunkHandle(aHandle));
1810 void CTSurfaceManager::TestCreateSurfaceExisitingChunk2L()
1812 // Create a surface in a new shared chunk
1813 INFO_PRINTF1(_L("Creating a Surface with distinct creation attributes in an exisitng shared chunk which already contains a surface\r\n"));
1814 // Open the surface manager
1815 User::LeaveIfError(iSurfaceManager.Open());
1818 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
1819 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
1821 attributes.iSize = TSize(100,100);
1822 attributes.iBuffers = 1; // number of buffers in the surface
1823 attributes.iPixelFormat = EUidPixelFormatYUV_422SemiPlanar;
1824 attributes.iStride = 400; // Number of bytes between start of one line and start of next
1825 attributes.iOffsetToFirstBuffer = 0; // way of reserving space before the surface pixel data
1826 attributes.iAlignment = 2; // alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
1828 ReAllocHintsArrayL(2);
1829 attributes.iHintCount=2;
1830 iHintsArray[0].Set(TUid::Uid(0x124578), 25, ETrue);
1831 iHintsArray[1].Set(TUid::Uid(0x237755), 50, ETrue);
1832 attributes.iSurfaceHints = iHintsArray;
1834 attributes.iContiguous = ETrue;
1835 attributes.iCacheAttrib = RSurfaceManager::ECached;
1836 attributes.iOffsetBetweenBuffers = 0;
1837 attributes.iMappable = ETrue;
1839 // Test create surface doesn't return an error
1840 TSurfaceId surfaceId;
1842 // Test create surface doesn't return an error
1843 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId));
1845 //store all the attributes
1846 RSurfaceManager::TInfoBuf infoBuf;
1847 TEST(KErrNone == iSurfaceManager.SurfaceInfo(surfaceId, infoBuf));
1848 RSurfaceManager::TSurfaceInfoV01& info = infoBuf();
1850 //Map the surface in the current processs
1852 TEST(KErrNone == iSurfaceManager.MapSurface(surfaceId,handle));
1854 // Cache, Contiguous and Alignment attributes are ignored for the already existing chunks
1855 RSurfaceManager::TSurfaceCreationAttributesBuf buff;
1856 RSurfaceManager::TSurfaceCreationAttributes& attributesNew = buff();
1858 attributesNew.iSize = TSize(480,16);
1859 attributesNew.iBuffers = 2; // number of buffers in the surface
1860 attributesNew.iPixelFormat = EUidPixelFormatYUV_422Reversed;
1861 attributesNew.iStride = 1013; // Number of bytes between start of one line and start of next
1862 attributesNew.iOffsetToFirstBuffer = 0; // way of reserving space before the surface pixel data
1864 RSurfaceManager::THintPair hint;
1865 attributes.iHintCount=1;
1866 hint.Set(TUid::Uid(0x124545), 50, EFalse);
1867 attributes.iSurfaceHints = &hint;
1869 attributesNew.iAlignment = RSurfaceManager::EPageAligned;
1870 attributesNew.iOffsetBetweenBuffers = 0;
1871 attributesNew.iMappable = ETrue;
1873 // Test create surface doesn't return an error
1874 TSurfaceId surfaceIdNew;
1875 // Test create surface doesn't return an error
1876 TEST(KErrNone == iSurfaceManager.CreateSurface(buff, surfaceIdNew, handle));
1878 //Store all the attributes
1879 RSurfaceManager::TInfoBuf infoBufNew;
1880 TEST(KErrNone == iSurfaceManager.SurfaceInfo(surfaceIdNew, infoBufNew));
1881 RSurfaceManager::TSurfaceInfoV01& infoNew = infoBufNew();
1883 //Map the new surface in the current process
1885 TEST(KErrNone == iSurfaceManager.MapSurface(surfaceIdNew,handleNew));
1887 //cache attribute is not valid on emulator
1889 TEST(info.iCacheAttrib == infoNew.iCacheAttrib);
1891 INFO_PRINTF1(_L("Cache attribute test is not valid on emulator\n"));
1894 //contiguous attribute is not valid on emulator
1896 TEST(info.iContiguous == infoNew.iContiguous);
1898 INFO_PRINTF1(_L("Contiguous attribute test is not valid on emulator\n"));
1901 //two surfaceIds are different
1902 TEST(surfaceId != surfaceIdNew);
1904 //check the offset between buffers is valid
1905 TInt offsetToFirstBufferNew;
1906 TInt offsetBetweenBuffersNew;
1907 TInt err=iSurfaceManager.GetBufferOffset(surfaceIdNew, 0, offsetToFirstBufferNew);
1908 err=iSurfaceManager.GetBufferOffset(surfaceIdNew, 1, offsetBetweenBuffersNew);
1909 offsetBetweenBuffersNew-=offsetToFirstBufferNew;
1910 TEST(offsetBetweenBuffersNew >= attributesNew.iSize.iHeight*attributesNew.iStride);
1911 //check the two handles are different but refer to the same shared chunk
1912 TEST(handle.Handle() != handleNew.Handle());
1913 TEST(handle.Base() == handleNew.Base());
1915 // Get the adress of this chunk of memory
1916 TUint8* surfaceAddNew = handleNew.Base();
1917 TUint8* bufferAddNew = surfaceAddNew + attributes.iOffsetToFirstBuffer;
1919 // Write to the second surface's buffer, and test the value is written
1921 TInt temp = *bufferAddNew;
1924 //Read the value from the address of the pixel data for this first surface
1925 TUint8* surfaceAdd = handle.Base();
1926 TUint8* bufferAdd = surfaceAdd + attributes.iOffsetToFirstBuffer;
1927 TEST(*bufferAdd == 20);
1929 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
1930 // As the surface is not created properly, closing returns KErrArgument
1931 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceIdNew));
1933 //Reset iOffsetBetweenBuffers is 20480
1934 attributesNew.iOffsetBetweenBuffers = 20480;
1935 TEST(KErrNone == iSurfaceManager.CreateSurface(buff, surfaceIdNew, handle));
1937 TEST(KErrNone == iSurfaceManager.SurfaceInfo(surfaceIdNew, infoBufNew));
1939 //Test that the attribute is returned correctly
1940 err=iSurfaceManager.GetBufferOffset(surfaceIdNew, 0, offsetToFirstBufferNew);
1941 err=iSurfaceManager.GetBufferOffset(surfaceIdNew, 1, offsetBetweenBuffersNew);
1942 offsetBetweenBuffersNew-=offsetToFirstBufferNew;
1944 TEST(offsetBetweenBuffersNew == attributesNew.iOffsetBetweenBuffers);
1945 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceIdNew));
1949 // Close the surface manager
1950 iSurfaceManager.Close();
1953 void CTSurfaceManager::TestCreateSurfaceExisitingChunk3L()
1955 // Create a surface in a new shared chunk
1956 INFO_PRINTF1(_L("Creating a Surface with identical creation attributes in an exisitng shared chunk which already contains a surface\r\n"));
1957 // Open the surface manager
1958 User::LeaveIfError(iSurfaceManager.Open());
1961 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
1962 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
1964 attributes.iSize = TSize(480,16);
1965 attributes.iBuffers = 2; // number of buffers in the surface
1966 attributes.iPixelFormat = EUidPixelFormatYUV_422Reversed;
1967 attributes.iStride = 1013; // Number of bytes between start of one line and start of next
1968 attributes.iOffsetToFirstBuffer = 0; // way of reserving space before the surface pixel data
1969 attributes.iAlignment = 4; // alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
1971 RSurfaceManager::THintPair hints[2];
1972 attributes.iHintCount=2;
1973 hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
1974 hints[1].Set(TUid::Uid(0x237755), 50, EFalse);
1975 attributes.iSurfaceHints = hints;
1977 attributes.iContiguous = ETrue;
1978 attributes.iCacheAttrib = RSurfaceManager::ECached;
1979 attributes.iOffsetBetweenBuffers = 0;
1980 attributes.iMappable = ETrue;
1982 // Test create surface doesn't return an error
1983 TSurfaceId surfaceId;
1985 // Test create surface doesn't return an error
1986 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId));
1988 //store all the attributes
1989 RSurfaceManager::TInfoBuf infoBuf;
1990 TEST(KErrNone == iSurfaceManager.SurfaceInfo(surfaceId, infoBuf));
1991 RSurfaceManager::TSurfaceInfoV01& info = infoBuf();
1994 TEST(KErrNone == iSurfaceManager.MapSurface(surfaceId,handle));
1996 // Test create surface doesn't return an error
1997 TSurfaceId surfaceIdNew;
1998 // Test create surface doesn't return an error
1999 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceIdNew, handle));
2001 //Store all the attributes
2002 RSurfaceManager::TInfoBuf infoBufNew;
2003 TEST(KErrNone == iSurfaceManager.SurfaceInfo(surfaceIdNew, infoBufNew));
2004 RSurfaceManager::TSurfaceInfoV01& infoNew = infoBufNew();
2006 //Map the new surface in the current process
2008 TEST(KErrNone == iSurfaceManager.MapSurface(surfaceIdNew,handleNew));
2010 //test two sets of attributes are identical for two surfaces
2011 TEST(info.iSize.iHeight == infoNew.iSize.iHeight);
2012 TEST(info.iSize.iWidth == infoNew.iSize.iWidth);
2013 TEST(info.iBuffers == infoNew.iBuffers);
2014 TEST(info.iPixelFormat == infoNew.iPixelFormat);
2015 TEST(info.iStride == infoNew.iStride);
2018 TInt offsetToFirstBuffer, offsetToFirstBufferNew;
2019 TInt offsetBetweenBuffers, offsetBetweenBuffersNew;
2020 TInt err=iSurfaceManager.GetBufferOffset(surfaceId, 0, offsetToFirstBuffer);
2021 err=iSurfaceManager.GetBufferOffset(surfaceId, 1, offsetBetweenBuffers);
2022 offsetBetweenBuffers-=offsetToFirstBuffer;
2024 err=iSurfaceManager.GetBufferOffset(surfaceIdNew, 0, offsetToFirstBufferNew);
2025 err=iSurfaceManager.GetBufferOffset(surfaceIdNew, 1, offsetBetweenBuffersNew);
2026 offsetBetweenBuffersNew-=offsetToFirstBufferNew;
2029 TEST(offsetToFirstBuffer == offsetToFirstBufferNew);
2030 TEST(offsetBetweenBuffers == offsetBetweenBuffersNew);
2032 //cache attribute is not valid on emulator
2034 TEST(info.iCacheAttrib == infoNew.iCacheAttrib);
2036 INFO_PRINTF1(_L("Cache attribute test is not valid on emulator\n"));
2039 //contiguous attribute is not valid on emulator
2041 TEST(info.iContiguous == infoNew.iContiguous);
2043 INFO_PRINTF1(_L("Contiguous attribute test is not valid on emulator\n"));
2046 //check that two surfaceIds are different
2047 TEST(surfaceId != surfaceIdNew);
2049 //check the iOffsetBetweenBuffers return by SurfaceInfo() is valid
2050 TEST((offsetBetweenBuffers >= attributes.iSize.iHeight*attributes.iStride) && (offsetBetweenBuffers % attributes.iAlignment ==0));
2051 TEST((offsetBetweenBuffersNew >= attributes.iSize.iHeight*attributes.iStride) && (offsetBetweenBuffersNew % attributes.iAlignment ==0));
2053 //check the two handles are different but refer to the same shared chunk
2054 TEST(handle.Handle() != handleNew.Handle());
2055 TEST(handle.Base() == handleNew.Base());
2057 // Get the adress of this chunk of memory
2058 TUint8* surfaceAddNew = handleNew.Base();
2059 TUint8* bufferAddNew = surfaceAddNew + attributes.iOffsetToFirstBuffer;
2061 // Write to the second surface's buffer, and test the value is written
2063 TInt temp = *bufferAddNew;
2066 //Read the value from the address of the pixel data for this first surface
2067 TUint8* surfaceAdd = handle.Base();
2068 TUint8* bufferAdd = surfaceAdd + attributes.iOffsetToFirstBuffer;
2069 TEST(*bufferAdd == 20);
2071 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
2072 // As the surface is not created properly, closing returns KErrArgument
2073 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceIdNew));
2077 // Close the surface manager
2078 iSurfaceManager.Close();
2081 void CTSurfaceManager::TestCreateSurfaceExisitingChunk4L()
2083 // Create a surface in a new shared chunk
2084 INFO_PRINTF1(_L("Creating a Surface with rotated orientation in an exisitng shared chunk which already contains a surface\r\n"));
2085 // Open the surface manager
2086 User::LeaveIfError(iSurfaceManager.Open());
2089 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
2090 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
2092 attributes.iSize = TSize(480,16);
2093 attributes.iBuffers = 2; // number of buffers in the surface
2094 attributes.iPixelFormat = EUidPixelFormatYUV_422Reversed;
2095 attributes.iStride = 1200; // Number of bytes between start of one line and start of next
2096 attributes.iOffsetToFirstBuffer = 10; // way of reserving space before the surface pixel data
2097 attributes.iAlignment = 4; // alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
2099 RSurfaceManager::THintPair hints[2]; // two hint pairs specified
2100 attributes.iHintCount=2;
2101 hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
2102 hints[1].Set(TUid::Uid(0x237755), 50, EFalse);
2103 attributes.iSurfaceHints = hints;
2105 attributes.iContiguous = ETrue;
2106 attributes.iCacheAttrib = RSurfaceManager::ECached;
2107 attributes.iOffsetBetweenBuffers = 0;
2108 attributes.iMappable = ETrue;
2110 // Test create surface doesn't return an error
2111 TSurfaceId surfaceId;
2113 // Test create surface doesn't return an error
2114 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId));
2116 //store all the attributes
2117 RSurfaceManager::TInfoBuf infoBuf;
2118 TEST(KErrNone == iSurfaceManager.SurfaceInfo(surfaceId, infoBuf));
2119 RSurfaceManager::TSurfaceInfoV01& info = infoBuf();
2120 TInt offsetToFirstBuffer, offsetBetweenBuffers;
2121 TInt err=iSurfaceManager.GetBufferOffset(surfaceId, 0, offsetToFirstBuffer);
2122 err=iSurfaceManager.GetBufferOffset(surfaceId, 1, offsetBetweenBuffers);
2123 offsetBetweenBuffers-=offsetToFirstBuffer;
2125 //Map the surface in the current process to get the first chunk handle
2127 TEST(KErrNone == iSurfaceManager.MapSurface(surfaceId,handle));
2130 // Test create surface doesn't return an error
2131 TSurfaceId surfaceIdNew;
2133 // Cache, Contiguous and Alignment attributes are ignored for the already existing chunks
2134 RSurfaceManager::TSurfaceCreationAttributesBuf buff;
2135 RSurfaceManager::TSurfaceCreationAttributes& attributesNew = buff();
2137 attributesNew.iSize = TSize(16,480);
2138 attributesNew.iBuffers = 2; // number of buffers in the surface
2139 attributesNew.iPixelFormat =EUidPixelFormatYUV_422Reversed;
2140 attributesNew.iStride = 34; // Number of bytes between start of one line and start of next
2141 attributesNew.iOffsetToFirstBuffer = offsetToFirstBuffer; // way of reserving space before the surface pixel data
2143 RSurfaceManager::THintPair hint;
2144 attributes.iHintCount=1;
2145 hint.Set(TUid::Uid(0x124578),20,ETrue);
2146 attributesNew.iSurfaceHints = &hint;
2148 attributesNew.iAlignment = 4;
2149 attributesNew.iOffsetBetweenBuffers = offsetBetweenBuffers;
2150 attributesNew.iMappable = ETrue;
2152 // Test create surface doesn't return an error
2153 TEST(KErrNone == iSurfaceManager.CreateSurface(buff, surfaceIdNew, handle));
2155 //Store all the attributes
2156 RSurfaceManager::TInfoBuf infoBufNew;
2157 TEST(KErrNone == iSurfaceManager.SurfaceInfo(surfaceIdNew, infoBufNew));
2158 RSurfaceManager::TSurfaceInfoV01& infoNew = infoBufNew();
2159 TInt offsetToFirstBufferNew, offsetBetweenBuffersNew;
2160 err=iSurfaceManager.GetBufferOffset(surfaceIdNew, 0, offsetToFirstBufferNew);
2161 err=iSurfaceManager.GetBufferOffset(surfaceIdNew, 1, offsetBetweenBuffersNew);
2162 offsetBetweenBuffersNew-=offsetToFirstBufferNew;
2164 //Map the new surface in the current process
2166 TEST(KErrNone == iSurfaceManager.MapSurface(surfaceIdNew,handleNew));
2168 //cache attribute is not valid on emulator
2170 TEST(info.iCacheAttrib == infoNew.iCacheAttrib);
2172 INFO_PRINTF1(_L("Cache attribute test is not valid on emulator\n"));
2175 //contiguous attribute is not valid on emulator
2177 TEST(info.iContiguous == infoNew.iContiguous);
2179 INFO_PRINTF1(_L("Contiguous attribute test is not valid on emulator\n"));
2182 //check that two surfaceIds are different
2183 TEST(surfaceId != surfaceIdNew);
2185 TEST(info.iSize.iHeight == infoNew.iSize.iWidth);
2186 TEST(info.iSize.iWidth == infoNew.iSize.iHeight);
2187 TEST(offsetToFirstBuffer == offsetToFirstBufferNew);
2188 INFO_PRINTF2(_L("The offset to first Buffer is %d\n"),offsetToFirstBuffer);
2189 TEST(offsetBetweenBuffers == offsetBetweenBuffersNew);
2190 INFO_PRINTF2(_L("The offset between Buffers is %d \n"),offsetBetweenBuffers);
2192 TEST(info.iStride != infoNew.iStride);
2194 //check the iOffsetBetweenBuffers returned by SurfaceInfo() is valid
2195 TEST((offsetBetweenBuffers >= attributes.iSize.iHeight*attributes.iStride) && (offsetBetweenBuffers % attributes.iAlignment ==0));
2196 TEST((offsetBetweenBuffersNew >= attributesNew.iSize.iHeight*attributesNew.iStride) && (offsetBetweenBuffersNew % attributesNew.iAlignment ==0));
2198 //check the two handles are different but refer to the same shared chunk
2199 TEST(handle.Handle() != handleNew.Handle());
2200 TEST(handle.Base() == handleNew.Base());
2202 // Get the adress of this chunk of memory
2203 TUint8* surfaceAddNew = handleNew.Base();
2204 TUint8* bufferAddNew = surfaceAddNew + offsetToFirstBufferNew;
2206 // Write to the second surface's buffer, and test the value is written
2208 TInt temp = *bufferAddNew;
2211 //Read the value from the address of the pixel data for this first surface
2212 TUint8* surfaceAdd = handle.Base();
2213 TUint8* bufferAdd = surfaceAdd + offsetToFirstBuffer;
2214 TEST(*bufferAdd == 20);
2216 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
2217 // As the surface is not created properly, closing returns KErrArgument
2218 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceIdNew));
2222 // Close the surface manager
2223 iSurfaceManager.Close();
2226 void CTSurfaceManager::SetupAttributesL(RSurfaceManager::TSurfaceCreationAttributes& attributesParams)
2228 attributesParams.iSize = TSize(100,100);
2229 attributesParams.iBuffers = 1; // number of buffers in the surface
2230 attributesParams.iPixelFormat = EUidPixelFormatYUV_422SemiPlanar;
2231 attributesParams.iStride = 400; // Number of bytes between start of one line and start of next
2232 attributesParams.iOffsetToFirstBuffer = 0; // way of reserving space before the surface pixel data
2233 attributesParams.iAlignment = RSurfaceManager::EPageAligned; // alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
2234 attributesParams.iContiguous=ETrue;
2235 attributesParams.iCacheAttrib = RSurfaceManager::ECached; // Cache attributes
2236 attributesParams.iOffsetBetweenBuffers = 0;
2238 //Set iSurfaceHints.iHints[0]
2239 ReAllocHintsArrayL(1);
2240 attributesParams.iSurfaceHints = iHintsArray;
2241 attributesParams.iSurfaceHints[0].Set(TUid::Uid(0x124578), 20, ETrue);
2242 attributesParams.iHintCount = 1;
2243 attributesParams.iMappable = ETrue;
2245 void CTSurfaceManager::TestCreateSurfaceAssociatedWithHintPairsL()
2247 // Open the surface manager
2248 User::LeaveIfError(iSurfaceManager.Open());
2251 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
2252 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
2254 SetupAttributesL(attributes);
2255 TInt maxHintsPerSurface;
2256 iSurfaceManager.GetSurfaceManagerAttrib(RSurfaceManager::EMaxNumberOfHints,maxHintsPerSurface);
2258 // Create a surface in a new shared chunk
2259 INFO_PRINTF2(_L("Creating a Surface associated with 0 to a maximum of %i hint pairs\r\n"),maxHintsPerSurface);
2261 ReAllocHintsArrayL(maxHintsPerSurface);
2262 iHintsArray[0].Set(TUid::Uid(0x124578),20,ETrue);
2264 for (i=1;i<maxHintsPerSurface;++i)
2266 iHintsArray[i].Set(TUid::Uid(0x124512+i),20,ETrue);
2268 attributes.iSurfaceHints = iHintsArray;
2271 for (attributes.iHintCount=1;attributes.iHintCount<=maxHintsPerSurface;++attributes.iHintCount)
2273 TSurfaceId surfaceId;
2274 // Test create surface doesn't return an error
2275 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId));
2276 // Get the hint values and check them
2277 for (i=1;i<=attributes.iHintCount;++i)
2279 RSurfaceManager::THintPair hint;
2280 hint.iKey=iHintsArray[i-1].iKey;
2281 TEST(KErrNone == iSurfaceManager.GetSurfaceHint(surfaceId, hint));
2282 TEST(hint.iValue==iHintsArray[i-1].iValue);
2283 TEST(hint.iMutable==iHintsArray[i-1].iMutable);
2285 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
2287 iSurfaceManager.Close();
2290 void CTSurfaceManager::CheckAlignment(TSurfaceId& aId, TInt aAlign, RSurfaceManager::TCacheAttribute aCached)
2292 RSurfaceManager::TInfoBuf infoBuf;
2293 RSurfaceManager::TSurfaceInfoV01& info = infoBuf();
2295 //cached surfaces are aligned to minimum of cache line which is 32
2296 if (aCached == RSurfaceManager::ECached && aAlign < 32)
2298 // check the aligment is at least 32 for cached surfaces.
2302 TInt mask = (aAlign == RSurfaceManager::EPageAligned) ? 0xFFF : aAlign - 1;
2304 TInt offsetToFirstBuffer, offsetBetweenBuffers;
2305 TInt err=iSurfaceManager.GetBufferOffset(aId, 0, offsetToFirstBuffer);
2306 err=iSurfaceManager.GetBufferOffset(aId, 1, offsetBetweenBuffers);
2307 offsetBetweenBuffers-=offsetToFirstBuffer;
2309 TEST((offsetToFirstBuffer & mask) == 0);
2310 TEST((offsetBetweenBuffers & mask) == 0);
2315 void CTSurfaceManager::TestCreateSurfaceAlignmentsMemoryTypeL()
2317 INFO_PRINTF1(_L("Creating a Surface with all types of alignment in cached and none cached memory\r\n"));
2318 // Open the surface manager
2319 User::LeaveIfError(iSurfaceManager.Open());
2322 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
2323 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
2325 attributes.iSize = TSize(61,47);
2326 attributes.iBuffers = 2; // number of buffers in the surface
2327 attributes.iPixelFormat = EUidPixelFormatYUV_422SemiPlanar;
2328 attributes.iStride = 61; // Number of bytes between start of one line and start of next
2329 attributes.iOffsetToFirstBuffer = 1; // way of reserving space before the surface pixel data
2330 attributes.iContiguous=EFalse;
2331 attributes.iOffsetBetweenBuffers = 0;
2332 attributes.iMappable = ETrue;
2336 for (x = 0; x < 7; x++)
2338 attributes.iAlignment = 1 << x;
2340 attributes.iCacheAttrib = RSurfaceManager::ECached;
2341 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, sid));
2342 CheckAlignment(sid, attributes.iAlignment, attributes.iCacheAttrib);
2343 TEST(KErrNone == iSurfaceManager.CloseSurface(sid));
2345 attributes.iCacheAttrib = RSurfaceManager::ENotCached;
2346 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, sid));
2347 CheckAlignment(sid, attributes.iAlignment, attributes.iCacheAttrib);
2348 TEST(KErrNone == iSurfaceManager.CloseSurface(sid));
2351 attributes.iAlignment = RSurfaceManager::EPageAligned;
2353 attributes.iCacheAttrib = RSurfaceManager::ECached;
2354 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, sid));
2355 CheckAlignment(sid, attributes.iAlignment, attributes.iCacheAttrib);
2356 TEST(KErrNone == iSurfaceManager.CloseSurface(sid));
2358 attributes.iCacheAttrib = RSurfaceManager::ENotCached;
2359 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, sid));
2360 CheckAlignment(sid, attributes.iAlignment, attributes.iCacheAttrib);
2361 TEST(KErrNone == iSurfaceManager.CloseSurface(sid));
2363 // Close the surface manager
2364 iSurfaceManager.Close();
2370 void CTSurfaceManager::TestOpenSurfaceL()
2372 INFO_PRINTF1(_L("Test opening a surface\r\n"));
2373 // Open the surface manager
2374 User::LeaveIfError(iSurfaceManager.Open());
2377 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
2378 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
2380 SetupAttributesL(attributes);
2383 TSurfaceId surfaceId;
2384 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId));
2385 // Test OpenSurface returns KErrNone
2386 TEST(KErrNone == iSurfaceManager.OpenSurface(surfaceId));
2388 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
2389 iSurfaceManager.Close();
2392 void CTSurfaceManager::TestClosingSurfaceDecrementsReferenceCountL()
2394 INFO_PRINTF1(_L("CloseSurface (correctly) decrements reference count\r\n"));
2395 User::LeaveIfError(iSurfaceManager.Open());
2397 // Store the attributes used to create the Surface
2398 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
2399 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
2401 SetupAttributesL(attributes);
2403 // Create a surface - sets reference count to 1
2404 TSurfaceId surfaceId;
2405 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId));
2407 // Call SurfaceInfo - doesn't alter reference count
2408 RSurfaceManager::TInfoBuf infoBuf;
2409 TEST(KErrNone == iSurfaceManager.SurfaceInfo(surfaceId, infoBuf));
2411 // Check that CloseSurface returns KErrNone
2412 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
2414 // Check that OpenSurface fails (since ref count == 0)
2415 TEST(KErrArgument == iSurfaceManager.OpenSurface(surfaceId));
2417 // Close the manager
2418 iSurfaceManager.Close();
2421 void CTSurfaceManager::TestCreateSurfaceSetReferenceCountL()
2423 // Create a surface in a new shared chunk
2424 INFO_PRINTF1(_L("the new CreateSurface() API create the surface and set its reference count to one \r\n"));
2425 // Open the surface manager
2426 User::LeaveIfError(iSurfaceManager.Open());
2429 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
2430 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
2432 attributes.iSize = TSize(480,16);
2433 attributes.iBuffers = 2; // number of buffers in the surface
2434 attributes.iPixelFormat = EUidPixelFormatYUV_422Reversed;
2435 attributes.iStride = 1013; // Number of bytes between start of one line and start of next
2436 attributes.iOffsetToFirstBuffer = 0; // way of reserving space before the surface pixel data
2437 attributes.iAlignment = RSurfaceManager::EPageAligned; // alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
2439 RSurfaceManager::THintPair hints[2];
2440 attributes.iHintCount=2;
2441 hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
2442 hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
2443 attributes.iSurfaceHints = hints;
2445 attributes.iContiguous = ETrue;
2446 attributes.iCacheAttrib = RSurfaceManager::ECached;
2447 attributes.iOffsetBetweenBuffers = 0;
2448 attributes.iMappable = ETrue;
2450 // Test create surface doesn't return an error
2451 TSurfaceId surfaceId;
2453 // Test create surface doesn't return an error
2454 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId));
2456 //Map the new surface
2458 TEST(KErrNone == iSurfaceManager.MapSurface(surfaceId,handle));
2461 // Test create surface doesn't return an error
2462 TSurfaceId surfaceIdNew;
2464 // Cache, Contiguous and Alignment attributes are ignored for the already existing chunks
2465 RSurfaceManager::TSurfaceCreationAttributesBuf buff;
2466 RSurfaceManager::TSurfaceCreationAttributes& attributesNew = buff();
2468 attributesNew.iSize = TSize(16,480);
2469 attributesNew.iBuffers = 2; // number of buffers in the surface
2470 attributesNew.iPixelFormat =EUidPixelFormatYUV_422Reversed;
2471 attributesNew.iStride = 34; // Number of bytes between start of one line and start of next
2472 attributesNew.iOffsetToFirstBuffer = 0; // way of reserving space before the surface pixel data
2474 RSurfaceManager::THintPair hint; // one hint pairs specified
2475 attributes.iHintCount=1;
2476 hints[0].Set(TUid::Uid(0x124545), 50, EFalse);
2477 attributes.iSurfaceHints = &hint;
2479 attributesNew.iAlignment = RSurfaceManager::EPageAligned;
2480 attributesNew.iOffsetBetweenBuffers = 0;
2481 attributesNew.iMappable = ETrue;
2483 // Test create surface doesn't return an error
2484 TEST(KErrNone == iSurfaceManager.CreateSurface(buff, surfaceIdNew, handle));
2486 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
2488 // As the surface is not created properly, closing returns KErrArgument
2489 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceIdNew));
2491 TEST(KErrArgument == iSurfaceManager.CloseSurface(surfaceIdNew));
2494 // Close the surface manager
2495 iSurfaceManager.Close();
2499 void CTSurfaceManager::TestWriteToTwoBuffersL()
2501 INFO_PRINTF1(_L("Writing to two buffers\r\n"));
2502 // Open the surface manager
2504 User::LeaveIfError(iSurfaceManager.Open());
2506 // Setup attributes, setting iBuffers to 2
2507 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
2508 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
2509 attributes.iSize = TSize(12,80); // w > 0, h > 0
2510 attributes.iBuffers = 2; // > 0, <= 4
2511 attributes.iPixelFormat = EUidPixelFormatARGB_1555;
2512 attributes.iStride = 25; // > 0, > width * bpp
2513 attributes.iOffsetToFirstBuffer = 20; // > 0, divisible by alignment
2514 attributes.iAlignment = 4; // 1 || 2 || 4 || 8
2516 RSurfaceManager::THintPair hints[2]; // one hint pairs specified
2517 attributes.iHintCount=2;
2518 hints[0].Set(TUid::Uid(0x124578), 50, ETrue);
2519 hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
2520 attributes.iSurfaceHints = hints;
2522 attributes.iContiguous = ETrue;
2523 attributes.iCacheAttrib = RSurfaceManager::ECached;
2524 attributes.iOffsetBetweenBuffers = 0;
2525 attributes.iMappable = ETrue;
2527 // Create the surface
2528 TSurfaceId surfaceId;
2529 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId));
2531 // Map the surface to a chunk of memory
2533 TEST(KErrNone == iSurfaceManager.MapSurface(surfaceId, handle));
2535 // Get the adress of this chunk of memory
2536 TUint8* surfaceAdd = handle.Base();
2537 TUint8* bufferAdd = surfaceAdd + attributes.iOffsetToFirstBuffer;
2539 // Write to the first buffer, and test the value is written
2541 TInt temp = *bufferAdd;
2544 // Write to the second buffer and test the value is written
2545 RSurfaceManager::TInfoBuf infoBuf;
2546 TEST(KErrNone == iSurfaceManager.SurfaceInfo(surfaceId, infoBuf));
2547 RSurfaceManager::TSurfaceInfoV01& info = infoBuf();
2548 TInt offsetToFirstBuffer, offsetBetweenBuffers;
2549 TInt err=iSurfaceManager.GetBufferOffset(surfaceId, 0, offsetToFirstBuffer);
2550 err=iSurfaceManager.GetBufferOffset(surfaceId, 1, offsetBetweenBuffers);
2551 offsetBetweenBuffers-=offsetToFirstBuffer;
2552 bufferAdd += offsetBetweenBuffers;
2554 *(bufferAdd + 1) = 14;
2557 temp = *(bufferAdd + 1);
2560 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
2562 // Close the surface manager
2563 iSurfaceManager.Close();
2566 void CTSurfaceManager::TestQuerySurfaceInfoWithoutMappingL()
2568 INFO_PRINTF1(_L("Getting SurfaceInfo of a Surface without mapping it\r\n"));
2569 // Open the surface manager
2571 User::LeaveIfError(iSurfaceManager.Open());
2573 // Store the attributes used to create the Surface
2574 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
2575 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
2577 SetupAttributesL(attributes);
2580 TSurfaceId surfaceId;
2581 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId));
2584 // Call SurfaceInfo without mapping the surface
2585 RSurfaceManager::TInfoBuf infoBuf;
2586 TEST(KErrNone == iSurfaceManager.SurfaceInfo(surfaceId, infoBuf));
2587 RSurfaceManager::TSurfaceInfoV01& info = infoBuf();
2589 //Check if the values are equal to the stored ones
2590 TEST(info.iSize == attributes.iSize);
2591 TEST(info.iBuffers == attributes.iBuffers);
2592 TEST(info.iPixelFormat == attributes.iPixelFormat);
2593 TEST(info.iStride == attributes.iStride);
2594 TInt offsetToFirstBuffer;
2595 TInt err=iSurfaceManager.GetBufferOffset(surfaceId, 0, offsetToFirstBuffer);
2596 TEST(offsetToFirstBuffer == attributes.iOffsetToFirstBuffer);
2597 TEST(info.iContiguous == attributes.iContiguous);
2598 TEST(info.iCacheAttrib ==attributes.iCacheAttrib);
2600 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
2601 // Close the surface manager
2602 iSurfaceManager.Close();
2605 void CTSurfaceManager::TestQuerySurfaceInfoAfterMappingL()
2607 INFO_PRINTF1(_L("Getting SurfaceInfo of a Surface after mapping it\r\n"));
2608 // Open the surface manager
2610 User::LeaveIfError(iSurfaceManager.Open());
2612 // Store the attributes used to create the Surface
2613 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
2614 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
2616 SetupAttributesL(attributes);
2619 TSurfaceId surfaceId;
2620 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId));
2624 TEST(KErrNone == iSurfaceManager.MapSurface(surfaceId, handle));
2626 // Call SurfaceInfo to get the attributes of the Surface
2627 RSurfaceManager::TInfoBuf infoBuf;
2628 TEST(KErrNone == iSurfaceManager.SurfaceInfo(surfaceId, infoBuf));
2629 RSurfaceManager::TSurfaceInfoV01& info = infoBuf();
2631 // Test that the attributes are returned correctly
2632 TEST(info.iSize == attributes.iSize);
2633 TEST(info.iBuffers == attributes.iBuffers);
2634 TEST(info.iPixelFormat == attributes.iPixelFormat);
2635 TEST(info.iStride == attributes.iStride);
2636 TInt offsetToFirstBuffer;
2637 TInt err=iSurfaceManager.GetBufferOffset(surfaceId, 0, offsetToFirstBuffer);
2638 TEST(offsetToFirstBuffer == attributes.iOffsetToFirstBuffer);
2639 TEST(info.iContiguous == attributes.iContiguous);
2640 TEST(info.iCacheAttrib ==attributes.iCacheAttrib);
2642 // Close the surface manager
2644 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
2646 iSurfaceManager.Close();
2649 void CTSurfaceManager::TestMapSurfaceL()
2651 INFO_PRINTF1(_L("Basic test of the MapSurface() method\r\n"));
2652 // Open the surface manager
2653 User::LeaveIfError(iSurfaceManager.Open());
2655 // Store the attributes used to create the Surface
2656 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
2657 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
2659 SetupAttributesL(attributes);
2662 TSurfaceId surfaceId;
2663 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId));
2666 TEST(KErrNone == iSurfaceManager.MapSurface(surfaceId, handle));
2669 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
2670 iSurfaceManager.Close();
2673 void CTSurfaceManager::TestClosingSurfaceL()
2675 INFO_PRINTF1(_L("Closing a surface which cant be open again\r\n"));
2676 User::LeaveIfError(iSurfaceManager.Open());
2678 // Store the attributes used to create the Surface
2679 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
2680 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
2682 SetupAttributesL(attributes);
2685 TSurfaceId surfaceId;
2686 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId));
2687 // Close the surface
2688 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
2690 // Try to open the surface using the surface id - should fail
2691 TEST(KErrArgument == iSurfaceManager.OpenSurface(surfaceId));
2693 // Close the manager
2694 iSurfaceManager.Close();
2697 void CTSurfaceManager::TestSharedChunkClosedL()
2699 // Create a surface in a new shared chunk
2700 INFO_PRINTF1(_L("Checking the chunk gets deleted after the surface and handle are both closed\r\n"));
2701 // Open the surface manager
2702 User::LeaveIfError(iSurfaceManager.Open());
2705 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
2706 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
2708 SetupAttributesL(attributes);
2710 // Test create surface doesn't return an error
2711 TSurfaceId surfaceId;
2713 // Test create surface doesn't return an error
2714 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId));
2716 TEST(KErrNone == iSurfaceManager.MapSurface(surfaceId,handle));
2718 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
2720 // Get the adress of this chunk of memory
2721 TUint8* surfaceAdd = handle.Base();
2722 INFO_PRINTF2(_L("the base address of the chunk is : %x\r\n"),surfaceAdd);
2725 // Close the surface manager
2726 iSurfaceManager.Close();
2729 void CTSurfaceManager::TestMultipleChannelsL()
2731 INFO_PRINTF1(_L("Testing multiple channels to surface manager LDD in one process and accessing them individually\r\n"));
2732 // Open the surface manager
2733 User::LeaveIfError(iSurfaceManager.Open());
2734 // Store the attributes used to create the Surface
2735 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
2736 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
2738 SetupAttributesL(attributes);
2741 TSurfaceId surfaceId;
2742 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId));
2744 RSurfaceManager surfaceManagerTwo;
2745 User::LeaveIfError(surfaceManagerTwo.Open());
2747 TEST(KErrNone == surfaceManagerTwo.OpenSurface(surfaceId));
2748 iSurfaceManager.Close();
2750 // Call SurfaceInfo to get the attributes of the Surface
2751 RSurfaceManager::TInfoBuf infoBuf;
2752 // surfaceId is still accessible as surfaceManagerTwo is open
2753 TEST(KErrNone == surfaceManagerTwo.SurfaceInfo(surfaceId,infoBuf));
2755 TEST(KErrNone == surfaceManagerTwo.CloseSurface(surfaceId));
2756 TEST(KErrNone == surfaceManagerTwo.CloseSurface(surfaceId));
2757 TEST(KErrArgument == surfaceManagerTwo.SurfaceInfo(surfaceId,infoBuf));
2760 TSurfaceId surfaceIdNew;
2761 TEST(KErrNone == surfaceManagerTwo.CreateSurface(buf, surfaceIdNew));
2762 TEST(KErrNone == surfaceManagerTwo.CloseSurface(surfaceIdNew));
2764 surfaceManagerTwo.Close();
2768 void CTSurfaceManager::TestClosingChannelsL()
2770 INFO_PRINTF1(_L("Testing the behaviour of closing driver channels\r\n"));
2771 // Open the surface manager
2772 User::LeaveIfError(iSurfaceManager.Open());
2773 // Store the attributes used to create the Surface
2774 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
2775 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
2777 SetupAttributesL(attributes);
2780 TSurfaceId surfaceId;
2781 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId));
2783 RSurfaceManager surfaceManagerTwo;
2784 User::LeaveIfError(surfaceManagerTwo.Open());
2787 TSurfaceId surfaceIdNew;
2788 TEST(KErrNone == surfaceManagerTwo.CreateSurface(buf, surfaceIdNew));
2790 TEST(KErrNone == iSurfaceManager.OpenSurface(surfaceId));
2791 TEST(KErrNone == surfaceManagerTwo.OpenSurface(surfaceId));
2793 TEST(KErrNone == iSurfaceManager.OpenSurface(surfaceIdNew));
2794 TEST(KErrNone == surfaceManagerTwo.OpenSurface(surfaceIdNew));
2796 iSurfaceManager.Close();
2797 surfaceManagerTwo.Close();
2799 User::LeaveIfError(iSurfaceManager.Open());
2800 // Call SurfaceInfo to get the attributes of the Surface
2801 RSurfaceManager::TInfoBuf infoBuf;
2802 TEST(KErrArgument == iSurfaceManager.SurfaceInfo(surfaceId, infoBuf));
2804 RSurfaceManager::TInfoBuf infoBufNew;
2805 TEST(KErrArgument == iSurfaceManager.SurfaceInfo(surfaceIdNew, infoBuf));
2807 iSurfaceManager.Close();
2811 void CTSurfaceManager::TestSurfaceLimitL()
2813 INFO_PRINTF1(_L("Testing the number limit of surfaces\r\n"));
2814 // Open the surface manager
2815 User::LeaveIfError(iSurfaceManager.Open());
2817 // Store the attributes used to create the Surface
2818 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
2819 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
2821 attributes.iSize = TSize(1,1);
2822 attributes.iBuffers = 1;
2823 attributes.iPixelFormat = EUidPixelFormatYUV_422SemiPlanar;
2824 attributes.iStride = 1;
2825 attributes.iOffsetToFirstBuffer = 1;
2826 attributes.iAlignment = 1;
2828 RSurfaceManager::THintPair hints[2];
2829 attributes.iHintCount=2;
2830 hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
2831 hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
2832 attributes.iSurfaceHints = hints;
2834 attributes.iContiguous = ETrue;
2835 attributes.iCacheAttrib = RSurfaceManager::ECached;
2836 attributes.iOffsetBetweenBuffers = 0;
2837 attributes.iMappable = ETrue;
2840 RArray<TSurfaceId> surfaceIdArray;
2841 TSurfaceId surfaceId;
2843 while (iSurfaceManager.CreateSurface(buf, surfaceId)==KErrNone && count < KCountLimit)
2846 if(count == KCountLimit)
2848 INFO_PRINTF1(_L("Test hits the count, it is used to limit the number of surfaces used in this test"));
2850 surfaceIdArray.Append(surfaceId);
2852 INFO_PRINTF2(_L("the maximum number of surface created %d\r\n"),surfaceIdArray.Count());
2853 TInt err = iSurfaceManager.CreateSurface(buf, surfaceId);
2854 INFO_PRINTF2(_L("the final error result is %d\r\n"),err);
2856 for(TInt index = 0; index < surfaceIdArray.Count(); ++index)
2858 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceIdArray[index]));
2860 surfaceIdArray.Close();
2861 iSurfaceManager.Close();
2864 void CTSurfaceManager::TestSynchronizeCacheL()
2866 INFO_PRINTF1(_L("Test the behaviour of SynchronizeCache()\r\n"));
2867 // Open the surface manager
2868 User::LeaveIfError(iSurfaceManager.Open());
2870 // Store the attributes used to create the Surface
2871 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
2872 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
2874 SetupAttributesL(attributes);
2877 TSurfaceId surfaceId;
2878 // A surface made up of multiple pages
2879 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId));
2882 TEST(KErrNone == iSurfaceManager.MapSurface(surfaceId,handle));
2883 TEST(KErrNone == iSurfaceManager.SynchronizeCache(surfaceId,0,RSurfaceManager::ESyncBeforeNonCPUWrite));
2884 TEST(KErrNone == iSurfaceManager.SynchronizeCache(surfaceId,0,RSurfaceManager::ESyncAfterNonCPUWrite));
2885 TEST(KErrNone == iSurfaceManager.SynchronizeCache(surfaceId,0,RSurfaceManager::ESyncBeforeNonCPURead));
2886 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
2889 //SynchronizeCache when the memory is not contiguous
2890 attributes.iContiguous = EFalse;
2891 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId));
2892 TEST(KErrNone == iSurfaceManager.MapSurface(surfaceId,handle));
2893 TEST(KErrNone == iSurfaceManager.SynchronizeCache(surfaceId,0,RSurfaceManager::ESyncBeforeNonCPUWrite));
2894 TEST(KErrNone == iSurfaceManager.SynchronizeCache(surfaceId,0,RSurfaceManager::ESyncAfterNonCPUWrite));
2895 TEST(KErrNone == iSurfaceManager.SynchronizeCache(surfaceId,0,RSurfaceManager::ESyncBeforeNonCPURead));
2896 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
2899 // A surface made up of 1 page
2900 attributes.iContiguous = ETrue;
2901 attributes.iSize = TSize(100,10);
2902 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId));
2903 TEST(KErrNone == iSurfaceManager.MapSurface(surfaceId,handle));
2904 TEST(KErrNone == iSurfaceManager.SynchronizeCache(surfaceId,0,RSurfaceManager::ESyncBeforeNonCPUWrite));
2905 TEST(KErrNone == iSurfaceManager.SynchronizeCache(surfaceId,0,RSurfaceManager::ESyncAfterNonCPUWrite));
2906 TEST(KErrNone == iSurfaceManager.SynchronizeCache(surfaceId,0,RSurfaceManager::ESyncBeforeNonCPURead));
2907 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
2910 // Test SynchronizeCache to a non-cached surface
2911 attributes.iCacheAttrib = RSurfaceManager::ENotCached;
2912 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId));
2913 TEST(KErrNone == iSurfaceManager.SynchronizeCache(surfaceId,0,RSurfaceManager::ESyncBeforeNonCPUWrite));
2914 TEST(KErrNone == iSurfaceManager.SynchronizeCache(surfaceId,0,RSurfaceManager::ESyncAfterNonCPUWrite));
2915 TEST(KErrNone == iSurfaceManager.SynchronizeCache(surfaceId,0,RSurfaceManager::ESyncBeforeNonCPURead));
2916 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
2919 iSurfaceManager.Close();
2922 void CTSurfaceManager::TestSharedChunkClosed2L()
2924 INFO_PRINTF1(_L("Test that when two surfaces are created in the same shared chunk, closing one surface and chunk handle will not cause the chunk to be deleted.\r\n"));
2925 // Open the surface manager
2926 User::LeaveIfError(iSurfaceManager.Open());
2928 // Store the attributes used to create the Surface
2929 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
2930 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
2932 attributes.iSize = TSize(480,16);
2933 attributes.iBuffers = 2;
2934 attributes.iPixelFormat = EUidPixelFormatYUV_422Reversed;
2935 attributes.iStride = 1013;
2936 attributes.iOffsetToFirstBuffer = 1;
2937 attributes.iAlignment = RSurfaceManager::EPageAligned;
2939 RSurfaceManager::THintPair hints[2]; // two hint pairs specified
2940 attributes.iHintCount=2;
2941 hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
2942 hints[1].Set(TUid::Uid(0x124523), 50, ETrue);
2943 attributes.iSurfaceHints = hints;
2945 attributes.iContiguous = ETrue;
2946 attributes.iCacheAttrib = RSurfaceManager::ECached;
2947 attributes.iOffsetBetweenBuffers = 0;
2948 attributes.iMappable = ETrue;
2951 TSurfaceId surfaceId;
2952 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId));
2955 TEST(KErrNone == iSurfaceManager.MapSurface(surfaceId,handle));
2957 // Get the adress of this chunk of memory
2958 TUint8* surfaceAdd = handle.Base();
2960 // Cache, Contiguous and Alignment attributes are ignored for the already existing chunks
2961 RSurfaceManager::TSurfaceCreationAttributesBuf buff;
2962 RSurfaceManager::TSurfaceCreationAttributes& attributesNew = buff();
2964 attributesNew.iSize = TSize(480,10);
2965 attributesNew.iBuffers = 2; // number of buffers in the surface
2966 attributesNew.iPixelFormat = EUidPixelFormatYUV_422Reversed;
2967 attributesNew.iStride = 1013; // Number of bytes between start of one line and start of next
2968 attributesNew.iOffsetToFirstBuffer = 0; // way of reserving space before the surface pixel data
2970 RSurfaceManager::THintPair hint; // one hint pairs specified
2971 attributes.iHintCount=1;
2972 hints[0].Set(TUid::Uid(0x124545), 50, EFalse);
2973 attributes.iSurfaceHints = &hint;
2975 attributesNew.iAlignment = RSurfaceManager::EPageAligned;
2976 attributesNew.iOffsetBetweenBuffers = 0;
2977 attributesNew.iMappable = ETrue;
2979 // Test create surface doesn't return an error
2980 TSurfaceId surfaceIdNew;
2981 // Test create surface doesn't return an error
2982 // For the time being KErrArgument will be returned as the core codes are
2983 // not ready to check the passed in shared chunk handle.
2984 TEST(KErrNone == iSurfaceManager.CreateSurface(buff, surfaceIdNew, handle));
2987 // Close the first handle
2989 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
2992 TEST(KErrNone == iSurfaceManager.MapSurface(surfaceIdNew,handle2));
2993 // Get the adress of this chunk of memory
2994 TUint8* surfaceAddNew = handle2.Base();
2996 TEST(surfaceAddNew == surfaceAdd);
2998 // Close the second handle
3000 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceIdNew));
3001 iSurfaceManager.Close();
3004 void CTSurfaceManager::SetAttributesForHintTestL(RSurfaceManager::TSurfaceCreationAttributes& attributesParamsForHintTest)
3006 attributesParamsForHintTest.iSize = TSize(16,480);
3007 attributesParamsForHintTest.iBuffers = 2;
3008 attributesParamsForHintTest.iPixelFormat = EUidPixelFormatYUV_422Reversed;
3009 attributesParamsForHintTest.iStride = 50;
3010 attributesParamsForHintTest.iOffsetToFirstBuffer = 0;
3011 attributesParamsForHintTest.iAlignment = RSurfaceManager::EPageAligned;
3013 ReAllocHintsArrayL(2);
3014 attributesParamsForHintTest.iSurfaceHints = iHintsArray;
3015 attributesParamsForHintTest.iSurfaceHints[0].Set(TUid::Uid(0x124578), 20, ETrue);
3016 attributesParamsForHintTest.iSurfaceHints[1].Set(TUid::Uid(0x237755), 50, EFalse);
3017 attributesParamsForHintTest.iHintCount = 2;
3019 attributesParamsForHintTest.iContiguous = ETrue;
3020 attributesParamsForHintTest.iCacheAttrib = RSurfaceManager::ECached;
3021 attributesParamsForHintTest.iOffsetBetweenBuffers = 0;
3022 attributesParamsForHintTest.iMappable = ETrue;
3024 void CTSurfaceManager::TestGetSurfaceHintL()
3026 INFO_PRINTF1(_L("Test that GetSurfaceHint() behaves properly.\r\n"));
3027 // Open the surface manager
3028 User::LeaveIfError(iSurfaceManager.Open());
3029 // Store the attributes used to create the Surface
3030 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
3031 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
3033 SetAttributesForHintTestL(attributes);
3036 TSurfaceId surfaceId;
3037 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId));
3039 RSurfaceManager::THintPair hintPair;
3040 hintPair.iKey.iUid = 0x124578;
3041 TEST(KErrNone == iSurfaceManager.GetSurfaceHint(surfaceId, hintPair));
3042 TEST(hintPair.iValue == 20);
3043 TEST(hintPair.iMutable == 1);
3045 RSurfaceManager::THintPair hintPair2;
3046 hintPair2.iKey.iUid = 0x237755;
3047 TEST(KErrNone == iSurfaceManager.GetSurfaceHint(surfaceId, hintPair2));
3049 TEST(hintPair2.iValue == 50);
3050 TEST(hintPair2.iMutable == EFalse);
3052 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
3053 iSurfaceManager.Close();
3056 void CTSurfaceManager::TestSetSurfaceHintL()
3058 INFO_PRINTF1(_L("Test that SetSurfaceHint() behaves properly.\r\n"));
3059 // Open the surface manager
3060 User::LeaveIfError(iSurfaceManager.Open());
3061 // Store the attributes used to create the Surface
3062 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
3063 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
3065 SetAttributesForHintTestL(attributes);
3068 TSurfaceId surfaceId;
3069 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId));
3071 RSurfaceManager::THintPair hintPair;
3072 hintPair.iKey.iUid = 0x124578;
3073 hintPair.iValue = 300;
3074 hintPair.iMutable = ETrue;
3075 TEST(KErrNone == iSurfaceManager.SetSurfaceHint(surfaceId, hintPair));
3077 RSurfaceManager::THintPair hintPair2;
3078 hintPair2.iKey.iUid = 0x124578;
3079 TEST(KErrNone == iSurfaceManager.GetSurfaceHint(surfaceId, hintPair2));
3080 TEST(hintPair2.iValue == 300);
3081 TEST(hintPair2.iMutable == 1);
3082 // Check the other value unchanged
3083 hintPair2.iKey.iUid = 0x237755;
3084 TEST(KErrNone == iSurfaceManager.GetSurfaceHint(surfaceId, hintPair2));
3085 TEST(hintPair2.iValue == 50);
3086 TEST(hintPair2.iMutable == 0);
3087 // Add 5 more hint pairs, then set one of them to another value, check all 8 values
3088 RSurfaceManager::THintPair hintPair1;
3089 hintPair1.iKey.iUid = 0x124612;
3090 hintPair1.iValue = 100;
3091 hintPair1.iMutable = ETrue;
3092 TEST(KErrNone == iSurfaceManager.AddSurfaceHint(surfaceId, hintPair1));
3094 hintPair2.iKey.iUid = 0x124613;
3095 hintPair2.iValue = 200;
3096 hintPair2.iMutable = EFalse;
3097 TEST(KErrNone == iSurfaceManager.AddSurfaceHint(surfaceId, hintPair2));
3099 RSurfaceManager::THintPair hintPair3;
3100 hintPair3.iKey.iUid = 0x124614;
3101 hintPair3.iValue = 300;
3102 hintPair3.iMutable = ETrue;
3103 TEST(KErrNone == iSurfaceManager.AddSurfaceHint(surfaceId, hintPair3));
3105 RSurfaceManager::THintPair hintPair4;
3106 hintPair4.iKey.iUid = -0x124615;
3107 hintPair4.iValue = 400;
3108 hintPair4.iMutable = EFalse;
3109 TEST(KErrNone == iSurfaceManager.AddSurfaceHint(surfaceId, hintPair4));
3111 RSurfaceManager::THintPair hintPair5;
3112 hintPair5.iKey.iUid = 0x124616;
3113 hintPair5.iValue = 500;
3114 hintPair5.iMutable = ETrue;
3115 TEST(KErrNone == iSurfaceManager.AddSurfaceHint(surfaceId, hintPair5));
3116 // Set one of them to a new value
3117 hintPair.iKey.iUid = 0x124578;
3118 hintPair.iValue = 300;
3119 hintPair.iMutable = ETrue;
3120 TEST(KErrNone == iSurfaceManager.SetSurfaceHint(surfaceId, hintPair));
3122 // Check all 8 pairs
3123 hintPair2.iKey.iUid = 0x124578;
3124 TEST(KErrNone == iSurfaceManager.GetSurfaceHint(surfaceId, hintPair2));
3125 TEST(hintPair2.iValue == 300);
3126 TEST(hintPair2.iMutable == 1);
3127 // Check the other value unchanged
3128 hintPair2.iKey.iUid = 0x237755;
3129 TEST(KErrNone == iSurfaceManager.GetSurfaceHint(surfaceId, hintPair2));
3130 TEST(hintPair2.iValue == 50);
3131 TEST(hintPair2.iMutable == 0);
3133 hintPair2.iKey.iUid = 0x124612;
3134 TEST(KErrNone == iSurfaceManager.GetSurfaceHint(surfaceId, hintPair2));
3135 TEST(hintPair2.iValue == 100);
3136 TEST(hintPair2.iMutable == 1);
3138 hintPair2.iKey.iUid = 0x124613;
3139 TEST(KErrNone == iSurfaceManager.GetSurfaceHint(surfaceId, hintPair2));
3140 TEST(hintPair2.iValue == 200);
3141 TEST(hintPair2.iMutable == 0);
3143 hintPair2.iKey.iUid = 0x124614;
3144 TEST(KErrNone == iSurfaceManager.GetSurfaceHint(surfaceId, hintPair2));
3145 TEST(hintPair2.iValue == 300);
3146 TEST(hintPair2.iMutable == 1);
3148 hintPair2.iKey.iUid = -0x124615;
3149 TEST(KErrNone == iSurfaceManager.GetSurfaceHint(surfaceId, hintPair2));
3150 TEST(hintPair2.iValue == 400);
3151 TEST(hintPair2.iMutable == 0);
3153 hintPair2.iKey.iUid = 0x124616;
3154 TEST(KErrNone == iSurfaceManager.GetSurfaceHint(surfaceId, hintPair2));
3155 TEST(hintPair2.iValue == 500);
3156 TEST(hintPair2.iMutable == 1);
3158 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
3159 iSurfaceManager.Close();
3162 void CTSurfaceManager::CheckHintPair(TSurfaceId& aSurfaceId, RSurfaceManager::THintPair& aHintPairToCheck, RSurfaceManager::THintPair& aHintPairCompareWith)
3164 TEST(KErrNone == iSurfaceManager.GetSurfaceHint(aSurfaceId, aHintPairToCheck));
3165 TEST(aHintPairToCheck.iValue == aHintPairCompareWith.iValue);
3166 TEST(aHintPairToCheck.iMutable == aHintPairCompareWith.iMutable);
3168 void CTSurfaceManager::TestAddSurfaceHintL()
3170 INFO_PRINTF1(_L("Test that AddSurfaceHint behaves properly.\r\n"));
3172 // Open the surface manager
3173 User::LeaveIfError(iSurfaceManager.Open());
3175 // Store the attributes used to create the Surface
3176 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
3177 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
3178 attributes.iSize = TSize(16,480);
3179 attributes.iBuffers = 2;
3180 attributes.iPixelFormat = EUidPixelFormatYUV_422Reversed;
3181 attributes.iStride = 50;
3182 attributes.iOffsetToFirstBuffer = 0;
3183 attributes.iAlignment = RSurfaceManager::EPageAligned;
3184 attributes.iContiguous = ETrue;
3185 attributes.iCacheAttrib = RSurfaceManager::ECached;
3186 attributes.iOffsetBetweenBuffers = 0;
3187 attributes.iMappable = ETrue;
3190 TSurfaceId surfaceId;
3191 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId));
3194 RSurfaceManager::THintPair hintPair1;
3195 hintPair1.Set(TUid::Uid(KSurfaceContent), EStillImage, ETrue);
3196 TEST(KErrNone == iSurfaceManager.AddSurfaceHint(surfaceId, hintPair1));
3198 RSurfaceManager::THintPair hintPairCheck1;
3199 hintPairCheck1.iKey.iUid = KSurfaceContent;
3200 CheckHintPair(surfaceId, hintPairCheck1, hintPair1);
3203 RSurfaceManager::THintPair hintPair2;
3204 hintPair2.iKey.iUid = KSurfaceProtection;
3205 hintPair2.iValue = EAllowAnalog | EAllowDigital;
3206 hintPair2.iMutable = EFalse;
3207 TEST(KErrNone == iSurfaceManager.AddSurfaceHint(surfaceId, hintPair2));
3209 RSurfaceManager::THintPair hintPairCheck2;
3210 hintPairCheck2.iKey.iUid = KSurfaceProtection;
3211 CheckHintPair(surfaceId, hintPairCheck2, hintPair2);
3212 CheckHintPair(surfaceId, hintPairCheck1, hintPair1);
3215 RSurfaceManager::THintPair hintPair3;
3216 hintPair3.Set(TUid::Uid(KSurfaceCharacteristics), ENotPersistable, EFalse);
3217 TEST(KErrNone == iSurfaceManager.AddSurfaceHint(surfaceId, hintPair3));
3219 RSurfaceManager::THintPair hintPairCheck3;
3220 hintPairCheck3.iKey.iUid = KSurfaceCharacteristics;
3221 CheckHintPair(surfaceId, hintPairCheck3, hintPair3);
3222 CheckHintPair(surfaceId, hintPairCheck2, hintPair2);
3223 CheckHintPair(surfaceId, hintPairCheck1, hintPair1);
3226 RSurfaceManager::THintPair hintPair4;
3227 hintPair4.iKey.iUid = 0x125678;
3228 hintPair4.iValue = 150;
3229 hintPair4.iMutable = EFalse;
3230 TEST(KErrNone == iSurfaceManager.AddSurfaceHint(surfaceId, hintPair4));
3232 RSurfaceManager::THintPair hintPairCheck4;
3233 hintPairCheck4.iKey.iUid = 0x125678;
3234 CheckHintPair(surfaceId, hintPairCheck4, hintPair4);
3235 CheckHintPair(surfaceId, hintPairCheck3, hintPair3);
3236 CheckHintPair(surfaceId, hintPairCheck2, hintPair2);
3237 CheckHintPair(surfaceId, hintPairCheck1, hintPair1);
3240 RSurfaceManager::THintPair hintPair5;
3241 hintPair5.iKey.iUid = 0x233506;
3242 hintPair5.iValue = 270;
3243 hintPair5.iMutable = ETrue;
3244 TEST(KErrNone == iSurfaceManager.AddSurfaceHint(surfaceId, hintPair5));
3246 RSurfaceManager::THintPair hintPairCheck5;
3247 hintPairCheck5.iKey.iUid = 0x233506;
3248 CheckHintPair(surfaceId, hintPairCheck5, hintPair5);
3249 CheckHintPair(surfaceId, hintPairCheck4, hintPair4);
3250 CheckHintPair(surfaceId, hintPairCheck3, hintPair3);
3251 CheckHintPair(surfaceId, hintPairCheck2, hintPair2);
3252 CheckHintPair(surfaceId, hintPairCheck1, hintPair1);
3255 RSurfaceManager::THintPair hintPair6;
3256 hintPair6.iKey.iUid = -0x128899;
3257 hintPair6.iValue = 310;
3258 hintPair6.iMutable = ETrue;
3259 TEST(KErrNone == iSurfaceManager.AddSurfaceHint(surfaceId, hintPair6));
3261 RSurfaceManager::THintPair hintPairCheck6;
3262 hintPairCheck6.iKey.iUid = -0x128899;
3263 CheckHintPair(surfaceId, hintPairCheck6, hintPair6);
3264 CheckHintPair(surfaceId, hintPairCheck5, hintPair5);
3265 CheckHintPair(surfaceId, hintPairCheck4, hintPair4);
3266 CheckHintPair(surfaceId, hintPairCheck3, hintPair3);
3267 CheckHintPair(surfaceId, hintPairCheck2, hintPair2);
3268 CheckHintPair(surfaceId, hintPairCheck1, hintPair1);
3271 RSurfaceManager::THintPair hintPair7;
3272 hintPair7.iKey.iUid = 0x225377;
3273 hintPair7.iValue = 70;
3274 hintPair7.iMutable = ETrue;
3275 TEST(KErrNone == iSurfaceManager.AddSurfaceHint(surfaceId, hintPair7));
3277 RSurfaceManager::THintPair hintPairCheck7;
3278 hintPairCheck7.iKey.iUid = 0x225377;
3279 CheckHintPair(surfaceId, hintPairCheck7, hintPair7);
3280 CheckHintPair(surfaceId, hintPairCheck6, hintPair6);
3281 CheckHintPair(surfaceId, hintPairCheck5, hintPair5);
3282 CheckHintPair(surfaceId, hintPairCheck4, hintPair4);
3283 CheckHintPair(surfaceId, hintPairCheck3, hintPair3);
3284 CheckHintPair(surfaceId, hintPairCheck2, hintPair2);
3285 CheckHintPair(surfaceId, hintPairCheck1, hintPair1);
3288 RSurfaceManager::THintPair hintPair8;
3289 hintPair8.iKey.iUid = -0x257936;
3290 hintPair8.iValue = 560;
3291 hintPair8.iMutable = EFalse;
3292 TEST(KErrNone == iSurfaceManager.AddSurfaceHint(surfaceId, hintPair8));
3294 RSurfaceManager::THintPair hintPairCheck8;
3295 hintPairCheck8.iKey.iUid = -0x257936;
3296 CheckHintPair(surfaceId, hintPairCheck8, hintPair8);
3297 CheckHintPair(surfaceId, hintPairCheck7, hintPair7);
3298 CheckHintPair(surfaceId, hintPairCheck6, hintPair6);
3299 CheckHintPair(surfaceId, hintPairCheck5, hintPair5);
3300 CheckHintPair(surfaceId, hintPairCheck4, hintPair4);
3301 CheckHintPair(surfaceId, hintPairCheck3, hintPair3);
3302 CheckHintPair(surfaceId, hintPairCheck2, hintPair2);
3303 CheckHintPair(surfaceId, hintPairCheck1, hintPair1);
3306 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
3307 iSurfaceManager.Close();
3310 void CTSurfaceManager::SetupAttributesForNegativeTestL(RSurfaceManager::TSurfaceCreationAttributes& attributesForNegativeTest)
3312 attributesForNegativeTest.iSize = TSize(480,16);
3313 attributesForNegativeTest.iBuffers = 2; // number of buffers in the surface
3314 attributesForNegativeTest.iPixelFormat = EUidPixelFormatYUV_422Reversed; // 2bpp
3315 attributesForNegativeTest.iStride = 1013; // Number of bytes between start of one line and start of next
3316 attributesForNegativeTest.iOffsetToFirstBuffer = 0; // way of reserving space before the surface pixel data
3317 attributesForNegativeTest.iAlignment = 32;
3319 // two hint pairs specified
3320 ReAllocHintsArrayL(2);
3321 attributesForNegativeTest.iSurfaceHints = iHintsArray;
3322 attributesForNegativeTest.iHintCount=2;
3323 attributesForNegativeTest.iSurfaceHints[0].Set(TUid::Uid(0x124578), 25, ETrue);
3324 attributesForNegativeTest.iSurfaceHints[1].Set(TUid::Uid(0x124523), 30, EFalse);
3326 attributesForNegativeTest.iContiguous = ETrue;
3327 attributesForNegativeTest.iCacheAttrib = RSurfaceManager::ECached;
3328 attributesForNegativeTest.iOffsetBetweenBuffers = 0;
3329 attributesForNegativeTest.iMappable = ETrue;
3332 void CTSurfaceManager::TestCreateSurfaceInvalidParamsNewChunkL()
3334 INFO_PRINTF1(_L("Creating a surface with invalid parameters in a new shared chunk\r\n"));
3335 // Open the surface manager
3336 User::LeaveIfError(iSurfaceManager.Open());
3337 // Setup valid attributes initially
3338 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
3339 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
3341 SetupAttributesForNegativeTestL(attributes);
3343 TSurfaceId surfaceId;
3344 // Test create surface doesn't return an error
3345 TInt err = iSurfaceManager.CreateSurface(buf, surfaceId);
3346 TEST(KErrNone == err);
3347 if (err == KErrNone)
3349 // No need to close the surface as it is not created properly.
3350 // Test with negative width
3351 attributes.iSize.iWidth = -2;
3352 TEST(KErrArgument == iSurfaceManager.CreateSurface(buf, surfaceId));
3353 attributes.iSize.iWidth = 480; // reset width
3354 // Test with negative height
3355 attributes.iSize.iHeight = -56;
3356 TEST(KErrArgument == iSurfaceManager.CreateSurface(buf, surfaceId));
3357 attributes.iSize.iHeight = 16; // reset
3359 // Test with invalid buffers
3360 attributes.iBuffers = 0; // no buffers
3361 TEST(KErrArgument == iSurfaceManager.CreateSurface(buf, surfaceId));
3362 attributes.iBuffers = -5; // negative buffers
3363 TEST(KErrArgument == iSurfaceManager.CreateSurface(buf, surfaceId));
3364 attributes.iBuffers = 2; // reset
3366 // Test with invalid stride
3367 attributes.iStride = -200; // negative
3368 TEST(KErrArgument == iSurfaceManager.CreateSurface(buf, surfaceId));
3369 attributes.iStride = 0; //smaller than required
3370 TEST(KErrArgument == iSurfaceManager.CreateSurface(buf, surfaceId));
3371 attributes.iStride = 1013; //reset
3373 //Test with invalid offset
3374 attributes.iOffsetToFirstBuffer = -14; // negative
3375 TEST(KErrArgument == iSurfaceManager.CreateSurface(buf, surfaceId));
3377 attributes.iOffsetToFirstBuffer = 2147483647; // invalid offset
3378 TEST(KErrArgument == iSurfaceManager.CreateSurface(buf, surfaceId));
3379 attributes.iOffsetToFirstBuffer = 0; // restore
3381 // Test with invalid alignment (valid parameters: 1:2:4:8)
3382 attributes.iAlignment = 0;
3383 TEST(KErrArgument == iSurfaceManager.CreateSurface(buf, surfaceId));
3384 attributes.iAlignment = 3;
3385 TEST(KErrArgument == iSurfaceManager.CreateSurface(buf, surfaceId));
3386 attributes.iAlignment = 5;
3387 TEST(KErrArgument == iSurfaceManager.CreateSurface(buf, surfaceId));
3388 attributes.iAlignment = 12;
3389 TEST(KErrArgument == iSurfaceManager.CreateSurface(buf, surfaceId));
3390 attributes.iAlignment = -2;
3391 TEST(KErrArgument == iSurfaceManager.CreateSurface(buf, surfaceId));
3392 attributes.iAlignment = 32; // restore
3394 //Test with invalid iOffsetBetweenBuffers
3395 attributes.iOffsetBetweenBuffers = 50 ; //smaller than required
3396 TEST(KErrArgument == iSurfaceManager.CreateSurface(buf, surfaceId));
3398 attributes.iOffsetBetweenBuffers = -5; // negative offset
3399 TEST(KErrArgument == iSurfaceManager.CreateSurface(buf, surfaceId));
3400 attributes.iOffsetBetweenBuffers = 0;
3402 //Test invalid surface hint
3403 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId));
3404 RSurfaceManager::THintPair hintPair;
3405 hintPair.iKey.iUid = 0;
3406 hintPair.iValue = 30;
3407 hintPair.iMutable = ETrue;
3408 TEST(KErrArgument == iSurfaceManager.SetSurfaceHint(surfaceId, hintPair));
3410 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
3411 iSurfaceManager.Close();
3414 void CTSurfaceManager::TestCreateSurfaceInvalidParamsExisitingChunkL()
3416 INFO_PRINTF1(_L("Creating a surface with invalid parameters in the existing shared chunk\r\n"));
3418 // Call another device driver to get a valid shared chunk handle
3419 RSharedChunkLdd device;
3421 TUint ChunkSize = 40960; // bottom 8 bits reserved space for other chunk creation attributes info
3422 TUint ChunkAttribs = ChunkSize|EMultiple|EOwnsMemory;
3423 TUint ContiguousAttrib = 1;
3424 GetSharedChunkHandleL(device, handle, ChunkSize, ChunkAttribs, ContiguousAttrib);
3426 // Open the surface manager
3427 User::LeaveIfError(iSurfaceManager.Open());
3428 // Setup valid attributes initially
3429 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
3430 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
3432 SetupAttributesForNegativeTestL(attributes);
3434 TSurfaceId surfaceId;
3435 // Test create surface doesn't return an error
3436 TInt err = iSurfaceManager.CreateSurface(buf, surfaceId, handle);
3437 TEST(KErrNone == err);
3438 if (err == KErrNone)
3440 // No need to close the surface as it is not created properly.
3441 // Test with negative width
3442 attributes.iSize.iWidth = -2;
3443 TEST(KErrArgument == iSurfaceManager.CreateSurface(buf, surfaceId, handle));
3444 attributes.iSize.iWidth = 480; // reset width
3445 // 12.2: Test with negative height
3446 attributes.iSize.iHeight = -56;
3447 TEST(KErrArgument == iSurfaceManager.CreateSurface(buf, surfaceId, handle));
3448 attributes.iSize.iHeight = 16; // reset
3450 //Test with invalid buffers
3451 attributes.iBuffers = 0; // no buffers
3452 TEST(KErrArgument == iSurfaceManager.CreateSurface(buf, surfaceId, handle));
3453 attributes.iBuffers = -5; // negative buffers
3454 TEST(KErrArgument == iSurfaceManager.CreateSurface(buf, surfaceId, handle));
3455 attributes.iBuffers = 2; // reset
3457 //Test with invalid stride
3458 attributes.iStride = -200; // negative
3459 TEST(KErrArgument == iSurfaceManager.CreateSurface(buf, surfaceId, handle));
3460 attributes.iStride = 0; //smaller than required
3461 TEST(KErrArgument == iSurfaceManager.CreateSurface(buf, surfaceId, handle));
3462 attributes.iStride = 1013; //reset
3464 //Test with invalid offset
3465 attributes.iOffsetToFirstBuffer = -14; //negative offset
3466 TEST(KErrArgument == iSurfaceManager.CreateSurface(buf, surfaceId, handle));
3467 attributes.iOffsetToFirstBuffer = 5; //not divisable by iAlignment
3468 TEST(KErrArgument == iSurfaceManager.CreateSurface(buf, surfaceId, handle));
3469 attributes.iOffsetToFirstBuffer = 2147483647; //invalid setting
3470 TEST(KErrArgument == iSurfaceManager.CreateSurface(buf, surfaceId, handle));
3471 attributes.iOffsetToFirstBuffer = 0;
3473 //Test with invalid alignment (valid parameters: 1:2:4:8)
3474 attributes.iAlignment = 0;
3475 TEST(KErrArgument == iSurfaceManager.CreateSurface(buf, surfaceId, handle));
3476 attributes.iAlignment = 3;
3477 TEST(KErrArgument == iSurfaceManager.CreateSurface(buf, surfaceId, handle));
3478 attributes.iAlignment = 5;
3479 TEST(KErrArgument == iSurfaceManager.CreateSurface(buf, surfaceId, handle));
3480 attributes.iAlignment = 12;
3481 TEST(KErrArgument == iSurfaceManager.CreateSurface(buf, surfaceId, handle));
3482 attributes.iAlignment = -2;
3483 TEST(KErrArgument == iSurfaceManager.CreateSurface(buf, surfaceId, handle));
3484 attributes.iAlignment = 32; // restore
3486 attributes.iOffsetBetweenBuffers = attributes.iSize.iHeight*attributes.iStride -1 ; //smaller than required
3487 TEST(KErrArgument == iSurfaceManager.CreateSurface(buf, surfaceId,handle));
3488 attributes.iOffsetBetweenBuffers = 20010; // not devisible by alignment
3489 TEST(KErrArgument == iSurfaceManager.CreateSurface(buf, surfaceId, handle));
3490 attributes.iOffsetBetweenBuffers = -5; // negative offset
3491 TEST(KErrArgument == iSurfaceManager.CreateSurface(buf, surfaceId, handle));
3492 attributes.iOffsetBetweenBuffers = 50000; // iOffsetBetweenBuffers is too big
3493 TEST(KErrArgument == iSurfaceManager.CreateSurface(buf, surfaceId, handle));
3494 attributes.iOffsetBetweenBuffers = 0;
3496 //Test invalid surface hint
3497 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId, handle));
3498 RSurfaceManager::THintPair hintPair;
3499 hintPair.iKey.iUid = 0;
3500 hintPair.iValue = 30;
3501 hintPair.iMutable = ETrue;
3502 TEST(KErrArgument == iSurfaceManager.SetSurfaceHint(surfaceId, hintPair));
3504 //Reset the alignment is page aligned, if iOffsetToFirstBuffer or iOffsetBetweenBuffers is not page aligned, then the surface can't be created
3505 attributes.iAlignment = RSurfaceManager::EPageAligned;
3506 attributes.iOffsetToFirstBuffer = 4092;
3507 TEST(KErrArgument == iSurfaceManager.CreateSurface(buf, surfaceId, handle));
3509 attributes.iOffsetToFirstBuffer = 4096;
3510 attributes.iOffsetBetweenBuffers = 4092;
3511 TEST(KErrArgument == iSurfaceManager.CreateSurface(buf, surfaceId, handle));
3513 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
3514 device.CloseChunkHandle(handle);
3515 device.CloseChunk();
3516 iSurfaceManager.Close();
3520 void CTSurfaceManager::TestCreateSurfaceInvalidParamsExisitingChunk2L()
3522 INFO_PRINTF1(_L("Creating a surface with invalid parameters in the existing shared chunk which already contains a surface\r\n"));
3524 // Open the surface manager
3525 User::LeaveIfError(iSurfaceManager.Open());
3526 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
3527 RSurfaceManager::TSurfaceCreationAttributes& attributesOld = buf();
3529 SetupAttributesForNegativeTestL(attributesOld);
3531 TSurfaceId surfaceIdOld;
3532 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceIdOld));
3534 //Map the surface in the current process
3536 TEST(KErrNone == iSurfaceManager.MapSurface(surfaceIdOld,handle));
3538 // Setup valid attributes initially
3539 RSurfaceManager::TSurfaceCreationAttributesBuf buff;
3540 RSurfaceManager::TSurfaceCreationAttributes& attributes = buff();
3542 SetupAttributesForNegativeTestL(attributes);
3544 TSurfaceId surfaceId;
3545 // No need to close the surface as it is not created properly.
3546 // Test with negative width
3547 attributes.iSize.iWidth = -2;
3548 TEST(KErrArgument == iSurfaceManager.CreateSurface(buff, surfaceId,handle));
3549 attributes.iSize.iWidth = 480; // reset width
3550 // 12.2: Test with negative height
3551 attributes.iSize.iHeight = -56;
3552 TEST(KErrArgument == iSurfaceManager.CreateSurface(buff, surfaceId,handle));
3553 attributes.iSize.iHeight = 16; // reset
3555 //Test with invalid buffers
3556 attributes.iBuffers = 0; // no buffers
3557 TEST(KErrArgument == iSurfaceManager.CreateSurface(buff, surfaceId,handle));
3558 attributes.iBuffers = -5; // negative buffers
3559 TEST(KErrArgument == iSurfaceManager.CreateSurface(buff, surfaceId,handle));
3560 attributes.iBuffers = 1; // reset
3562 //Test with invalid stride
3563 attributes.iStride = -200; // negative
3564 TEST(KErrArgument == iSurfaceManager.CreateSurface(buff, surfaceId,handle));
3565 attributes.iStride = 1040; // restore
3567 //Test with invalid offset
3568 attributes.iOffsetToFirstBuffer = -14; // negative
3569 TEST(KErrArgument == iSurfaceManager.CreateSurface(buff, surfaceId,handle));
3570 attributes.iOffsetToFirstBuffer = 5; // not divisible by iAlignment
3571 TEST(KErrArgument == iSurfaceManager.CreateSurface(buff, surfaceId,handle));
3572 attributes.iOffsetToFirstBuffer = 2147483647; // invalid offset
3573 TEST(KErrArgument == iSurfaceManager.CreateSurface(buff, surfaceId,handle));
3574 attributes.iOffsetToFirstBuffer = 100; // restore
3576 //Test with invalid alignment (valid parameters: 1:2:4:8)
3577 attributes.iAlignment = 0;
3578 TEST(KErrArgument == iSurfaceManager.CreateSurface(buff, surfaceId,handle));
3579 attributes.iAlignment = 3;
3580 TEST(KErrArgument == iSurfaceManager.CreateSurface(buff, surfaceId,handle));
3581 attributes.iAlignment = 5;
3582 TEST(KErrArgument == iSurfaceManager.CreateSurface(buff, surfaceId,handle));
3583 attributes.iAlignment = 12;
3584 TEST(KErrArgument == iSurfaceManager.CreateSurface(buff, surfaceId,handle));
3585 attributes.iAlignment = -2;
3586 TEST(KErrArgument == iSurfaceManager.CreateSurface(buff, surfaceId,handle));
3587 attributes.iAlignment = 32; // restore
3589 //Test with invalid iOffsetBetweenBuffers
3590 attributes.iOffsetBetweenBuffers = attributes.iSize.iHeight*attributes.iStride -1 ; //smaller than required
3591 TEST(KErrArgument == iSurfaceManager.CreateSurface(buff, surfaceId,handle));
3592 attributes.iOffsetBetweenBuffers = attributes.iAlignment +1 ; // 1 (iAlignment must not be set to 1) // not devisible by alignment
3593 TEST(KErrArgument == iSurfaceManager.CreateSurface(buff, surfaceId,handle));
3594 attributes.iOffsetBetweenBuffers = -5; // negative offset
3595 TEST(KErrArgument == iSurfaceManager.CreateSurface(buff, surfaceId,handle));
3596 attributes.iOffsetBetweenBuffers = 0;
3598 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceIdOld));
3600 iSurfaceManager.Close();
3603 void CTSurfaceManager::TestDuplicatedHintKeyL()
3605 INFO_PRINTF1(_L("Test that Hint keys cant not be duplicated\r\n"));
3607 // Open the surface manager
3608 User::LeaveIfError(iSurfaceManager.Open());
3609 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
3610 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
3612 attributes.iSize = TSize(480,16);
3613 attributes.iBuffers = 2; // number of buffers in the surface
3614 attributes.iPixelFormat = EUidPixelFormatYUV_422Reversed; // 2bpp
3615 attributes.iStride = 1013; // Number of bytes between start of one line and start of next
3616 attributes.iOffsetToFirstBuffer = 0; // way of reserving space before the surface pixel data
3617 attributes.iAlignment = RSurfaceManager::EPageAligned; // alignment, 1,2,4,8 byte aligned
3618 attributes.iContiguous = ETrue;
3619 attributes.iCacheAttrib = RSurfaceManager::ECached;
3620 attributes.iOffsetBetweenBuffers = 0;
3621 attributes.iMappable = ETrue;
3623 //Set duplicated Hint keys
3624 RSurfaceManager::THintPair hints[2]; // two hint pairs specified
3625 attributes.iHintCount=2;
3626 hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
3627 hints[1].Set(TUid::Uid(0x124578), 50, ETrue);
3628 attributes.iSurfaceHints = hints;
3630 TSurfaceId surfaceId;
3631 TEST(KErrArgument == iSurfaceManager.CreateSurface(buf, surfaceId));
3632 iSurfaceManager.Close();
3634 void CTSurfaceManager::TestInvalidContiguousPropertyL()
3636 //This test is only valid on hardware
3637 INFO_PRINTF1(_L("Test that iContiguous is indeed ignored when creating the second surface on the existing shared chunk which already contains a surface\r\n"));
3639 // Open the surface manager
3640 User::LeaveIfError(iSurfaceManager.Open());
3641 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
3642 RSurfaceManager::TSurfaceCreationAttributes& attributesOld = buf();
3644 SetupAttributesForNegativeTestL(attributesOld);
3646 TSurfaceId surfaceIdOld;
3647 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceIdOld));
3649 TEST(KErrNone == iSurfaceManager.MapSurface(surfaceIdOld,handle));
3651 // Setup valid attributes initially
3652 RSurfaceManager::TSurfaceCreationAttributesBuf buff;
3653 RSurfaceManager::TSurfaceCreationAttributes& attributes = buff();
3655 SetupAttributesForNegativeTestL(attributes);
3657 attributes.iContiguous = EFalse;
3659 TSurfaceId surfaceId;
3660 TEST(KErrNone == iSurfaceManager.CreateSurface(buff, surfaceId,handle));
3661 RSurfaceManager::TInfoBuf infoBuf;
3662 TEST(KErrNone == iSurfaceManager.SurfaceInfo(surfaceId, infoBuf));
3663 RSurfaceManager::TSurfaceInfoV01& info = infoBuf();
3665 //Check the iContiguous is identical to that of the first surface info structure
3666 TEST(info.iContiguous == 1);
3668 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceIdOld));
3669 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
3671 iSurfaceManager.Close();
3674 void CTSurfaceManager::TestInvalidCachePropertyL()
3676 //This test is only valid on hardware
3677 INFO_PRINTF1(_L("Test that iCacheAttrib is indeed ignored when creating the second surface on the existing shared chunk which already contains a surface\r\n"));
3679 // Open the surface manager
3680 User::LeaveIfError(iSurfaceManager.Open());
3681 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
3682 RSurfaceManager::TSurfaceCreationAttributes& attributesOld = buf();
3684 SetupAttributesForNegativeTestL(attributesOld);
3686 TSurfaceId surfaceIdOld;
3687 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceIdOld));
3689 TEST(KErrNone == iSurfaceManager.MapSurface(surfaceIdOld,handle));
3691 // Setup valid attributes initially
3692 RSurfaceManager::TSurfaceCreationAttributesBuf buff;
3693 RSurfaceManager::TSurfaceCreationAttributes& attributes = buff();
3695 SetupAttributesForNegativeTestL(attributes);
3696 attributes.iCacheAttrib = RSurfaceManager::ENotCached;
3698 TSurfaceId surfaceId;
3699 TEST(KErrNone == iSurfaceManager.CreateSurface(buff, surfaceId,handle));
3700 RSurfaceManager::TInfoBuf infoBuf;
3701 TEST(KErrNone == iSurfaceManager.SurfaceInfo(surfaceId, infoBuf));
3702 RSurfaceManager::TSurfaceInfoV01& info = infoBuf();
3704 //cache attribute is not valid on the emulator
3705 INFO_PRINTF2(_L("cache attribute is: %d"), info.iCacheAttrib);
3707 TEST(info.iCacheAttrib == RSurfaceManager::ECached);
3708 INFO_PRINTF2(_L("cache attribute is: %d"), info.iCacheAttrib);
3711 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceIdOld));
3712 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
3714 iSurfaceManager.Close();
3717 void CTSurfaceManager::TestInvalidSharedChunkL()
3719 INFO_PRINTF1(_L("Creating a Surface in an invalid chunk\r\n"));
3721 // Open the surface manager
3722 User::LeaveIfError(iSurfaceManager.Open());
3723 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
3724 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
3726 attributes.iSize = TSize(480,16);
3727 attributes.iBuffers = 2; // number of buffers in the surface
3728 attributes.iPixelFormat = EUidPixelFormatYUV_422Reversed; // 2bpp
3729 attributes.iStride = 1013; // Number of bytes between start of one line and start of next
3730 attributes.iOffsetToFirstBuffer = 0; // way of reserving space before the surface pixel data
3731 attributes.iOffsetBetweenBuffers = 0;
3732 attributes.iAlignment = 4;
3733 attributes.iMappable = ETrue;
3735 ReAllocHintsArrayL(2);
3736 attributes.iHintCount=2;
3737 iHintsArray[0].Set(TUid::Uid(0x124578), 25, ETrue);
3738 iHintsArray[1].Set(TUid::Uid(0x124523), 30, EFalse);
3739 attributes.iSurfaceHints = iHintsArray;
3742 //Call another device driver to get another shared chunk handle
3744 TSurfaceId surfaceId;
3746 //Test when the chunk handle is NULL, the surface can't be created
3747 TEST(KErrBadHandle == iSurfaceManager.CreateSurface(buf, surfaceId,handle));
3750 //Test when the chunk is not shared chunk, the surface can't be created
3752 const TInt KCommitSize = 32768;
3753 const TInt KMaxSize = 40960;
3754 User::LeaveIfError(handle2.CreateLocal(KCommitSize, KMaxSize));
3755 TEST(KErrBadHandle == iSurfaceManager.CreateSurface(buf, surfaceId,handle2));
3758 //Test when the chunk is created by the device driver but has the chunk type ESharedKernelSingle, the surface can't be created
3759 RSharedChunkLdd device;
3761 TUint ChunkSize = 40960; // bottom 8 bits reserved space for other chunk creation attributes info
3762 TUint ChunkAttribs = ChunkSize|ESingle|EOwnsMemory;
3763 TUint ContiguousAttrib = 1;
3764 GetSharedChunkHandleL(device, handle3, ChunkSize, ChunkAttribs, ContiguousAttrib);
3765 TEST(KErrBadHandle == iSurfaceManager.CreateSurface(buf, surfaceId,handle3));
3766 device.CloseChunkHandle(handle3);
3767 device.CloseChunk();
3769 //Test when the chunk is created by the device driver but the chunk size in bytes is too small for the new surfaces, then the surface can't be created
3771 //The chunk size is too small for the new surface
3772 ChunkSize = 4096; // bottom 8 bits reserved space for other chunk creation attributes info
3773 ChunkAttribs = ChunkSize|EMultiple|EOwnsMemory;
3774 TEST(KErrNone==device.CreateChunk(ChunkAttribs));
3775 TEST(KErrNone==device.CommitMemory(0, ChunkSize));
3776 TEST(KErrNone==device.GetChunkHandle(handle4));
3778 TEST(KErrArgument == iSurfaceManager.CreateSurface(buf, surfaceId,handle4));
3779 device.CloseChunkHandle(handle4);
3780 device.CloseChunk();
3782 //Test when the chunk is created by the device driver but the chunk memory is not commited, then the surface can't be created
3784 ChunkSize = 40960; // bottom 8 bits reserved space for other chunk creation attributes info
3785 ChunkAttribs = ChunkSize|EMultiple|EOwnsMemory;
3786 TEST(KErrNone==device.CreateChunk(ChunkAttribs));
3787 TEST(KErrNone==device.GetChunkHandle(handle5));
3789 TEST(KErrArgument == iSurfaceManager.CreateSurface(buf, surfaceId,handle5));
3791 device.CloseChunkHandle(handle5);
3792 device.CloseChunk();
3793 iSurfaceManager.Close();
3797 void CTSurfaceManager::TestCreateVeryLargeSurfacesL()
3799 INFO_PRINTF1(_L("Creating lots of surfaces\r\n"));
3800 // Open the surface manager
3802 User::LeaveIfError(iSurfaceManager.Open());
3803 // Setup valid attributes initially
3804 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
3805 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
3807 TSurfaceId surfaceId;
3808 attributes.iSize = TSize(5000,5000); // w > 0, h > 0
3809 attributes.iBuffers = 5; // > 0
3810 attributes.iPixelFormat = EUidPixelFormatARGB_1555; // 2bpp
3811 attributes.iStride = 100000; // > 0, > width * bpp
3812 attributes.iOffsetToFirstBuffer = 1024; // > 0, divisible by alignment
3813 attributes.iAlignment = RSurfaceManager::EPageAligned; // 1 || 2 || 4 || 8
3814 attributes.iMappable = ETrue;
3816 RSurfaceManager::THintPair hints[2]; // two hint pairs specified
3817 attributes.iHintCount=2;
3818 hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
3819 hints[1].Set(TUid::Uid(0x124523), 30, EFalse);
3820 attributes.iSurfaceHints = hints;
3822 attributes.iContiguous = ETrue;
3823 attributes.iCacheAttrib = RSurfaceManager::ECached;
3824 attributes.iOffsetBetweenBuffers = 0;
3825 const TInt numAttempts = 10;
3827 TInt ret = KErrNone;
3830 ret = iSurfaceManager.CreateSurface(buf, surfaceId);
3834 while(ii < numAttempts);
3836 // If we create 10 surfaces, we should get KErrNoMemory
3837 TEST(ii != numAttempts);
3838 TEST(KErrArgument == ret);
3840 attributes.iSize = TSize(5000, 25000);
3841 TEST(KErrArgument == iSurfaceManager.CreateSurface(buf, surfaceId));
3843 attributes.iSize = TSize(5000, 4294);
3844 attributes.iOffsetToFirstBuffer = 483613;
3845 attributes.iAlignment = 32;
3846 TEST(KErrArgument == iSurfaceManager.CreateSurface(buf, surfaceId));
3848 iSurfaceManager.Close();
3851 void CTSurfaceManager::TestMapSurfaceInvalidParamsL()
3853 INFO_PRINTF1(_L("Testing the MapSurface method with invalid surfaceId\r\n"));
3854 // Open the surface manager
3855 User::LeaveIfError(iSurfaceManager.Open());
3856 // Store the attributes used to create the Surface
3857 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
3858 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
3860 SetupAttributesForNegativeTestL(attributes);
3863 TSurfaceId surfaceId;
3864 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId));
3866 // Set an invalid surfaceId
3867 TSurfaceId invalidSurfaceId = surfaceId;
3868 // Change the surfaceId type to EInvalidSurface
3869 invalidSurfaceId.iInternal[3] = (surfaceId.iInternal[3] & 0x00FFFFFF) | ( TSurfaceId::EInvalidSurface <<24 ) ;
3873 TEST(KErrArgument == iSurfaceManager.MapSurface(invalidSurfaceId, handle));
3875 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
3876 iSurfaceManager.Close();
3879 void CTSurfaceManager::TestSurfaceInfoChangedTypeL()
3881 INFO_PRINTF1(_L("Calling SurfaceInfo on surfaceId with a changed 'type'\r\n"));
3882 // Open the surface manager
3883 User::LeaveIfError(iSurfaceManager.Open());
3884 // Store the attributes used to create the Surface
3885 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
3886 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
3888 attributes.iSize = TSize(361,341); // w > 0, h > 0
3889 attributes.iBuffers = 4; // > 0, <= 4
3890 attributes.iPixelFormat = EUidPixelFormatYUV_422Planar; // 2bpp
3891 attributes.iStride = 1400; // > 0, width * bpp
3892 attributes.iOffsetToFirstBuffer = 184; // > 0, divisible by alignment
3893 attributes.iAlignment = 4; // 1 || 2 || 4 || 8
3894 attributes.iContiguous = EFalse;
3895 attributes.iMappable = ETrue;
3897 RSurfaceManager::THintPair hints[2]; // two hint pairs specified
3898 attributes.iHintCount=2;
3899 hints[0].Set(TUid::Uid(0x124578), 20, ETrue);
3900 hints[1].Set(TUid::Uid(0x237755), 50, EFalse);
3901 attributes.iSurfaceHints = hints;
3903 attributes.iOffsetBetweenBuffers = 0;
3906 TSurfaceId surfaceId;
3907 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId));
3911 TEST(KErrNone == iSurfaceManager.MapSurface(surfaceId, handle));
3914 TSurfaceId surfaceIdBackup = surfaceId;
3915 // Call SurfaceInfo to get the attributes of the Surface
3916 RSurfaceManager::TInfoBuf infoBuf;
3917 // Want to change the type - replace it with twice the value of the old type
3918 TInt shiftedType = surfaceId.Type() << 25;
3919 // Mask out the top 8 bits and replace with the new type
3920 surfaceId.iInternal[3] = (surfaceId.iInternal[3] & 0x00FFFFFF) + shiftedType;
3922 TEST(KErrArgument == iSurfaceManager.SurfaceInfo(surfaceId, infoBuf));
3924 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceIdBackup));
3925 // Close the surface manager
3926 iSurfaceManager.Close();
3929 void CTSurfaceManager::TestCloseSurfaceInvalidParamsL()
3931 INFO_PRINTF1(_L("Closing a surface with invalid parameters\r\n"));
3932 User::LeaveIfError(iSurfaceManager.Open());
3933 // Store the attributes used to create the Surface
3934 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
3935 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
3937 SetupAttributesForNegativeTestL(attributes);
3939 // Create a surface - increments reference count by 1
3940 TSurfaceId surfaceId;
3941 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId));
3942 // Set a negative surfaceId
3943 TSurfaceId invalidSurfaceId;
3944 invalidSurfaceId = surfaceId;
3945 // Change the surfaceId type to EInvalidSurface
3946 invalidSurfaceId.iInternal[3] = (surfaceId.iInternal[3] & 0x00FFFFFF) | ( TSurfaceId::EInvalidSurface <<24 ) ;
3947 TEST(KErrArgument == iSurfaceManager.CloseSurface(invalidSurfaceId));
3949 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
3950 iSurfaceManager.Close();
3954 void CTSurfaceManager::TestSynchronizeCacheInvalidParamsL()
3956 INFO_PRINTF1(_L("Test that SynchronizeCache() reacts properly under false conditions\r\n"));
3957 User::LeaveIfError(iSurfaceManager.Open());
3958 // Store the attributes used to create the Surface
3959 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
3960 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
3962 SetupAttributesForNegativeTestL(attributes); //2 buffers in this surface
3964 // Create a surface - increments reference count by 1
3965 TSurfaceId surfaceId;
3966 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId));
3969 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
3971 TEST(KErrArgument == iSurfaceManager.SynchronizeCache(surfaceId,1,RSurfaceManager::ESyncBeforeNonCPURead));
3973 TSurfaceId surfaceIdNew;
3974 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceIdNew));
3975 // Check invalid operation
3976 TEST(KErrArgument == iSurfaceManager.SynchronizeCache(surfaceIdNew,1,(RSurfaceManager::TSyncOperation)4));
3977 // Check invalid buffer number
3978 TEST(KErrArgument == iSurfaceManager.SynchronizeCache(surfaceIdNew, attributes.iBuffers, RSurfaceManager::ESyncBeforeNonCPURead));
3979 // Check invalid buffer number
3980 TEST(KErrArgument == iSurfaceManager.SynchronizeCache(surfaceIdNew,KMaxTInt,RSurfaceManager::ESyncBeforeNonCPURead));
3981 // Check negative buffer number
3982 TEST(KErrArgument == iSurfaceManager.SynchronizeCache(surfaceIdNew,-1,RSurfaceManager::ESyncBeforeNonCPURead));
3984 // Change the surfaceId type to EInvalidSurface
3985 TSurfaceId surfaceIdBackup = surfaceIdNew;
3986 surfaceIdNew.iInternal[3] = (surfaceId.iInternal[3] & 0x00FFFFFF) | ( TSurfaceId::EInvalidSurface <<24 ) ;
3987 TEST(KErrArgument == iSurfaceManager.SynchronizeCache(surfaceIdNew,1,RSurfaceManager::ESyncBeforeNonCPURead));
3989 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceIdBackup));
3990 iSurfaceManager.Close();
3993 void CTSurfaceManager::TestCloseSurfaceSameIDTwiceL()
3995 INFO_PRINTF1(_L("Closing a surface with the same ID twice\r\n"));
3996 User::LeaveIfError(iSurfaceManager.Open());
3997 // Store the attributes used to create the Surface
3998 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
3999 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
4001 attributes.iSize = TSize(150,412);
4002 attributes.iBuffers = 3;
4003 attributes.iPixelFormat = EUidPixelFormatARGB_1555; // 2bpp
4004 attributes.iStride = 301;
4005 attributes.iOffsetToFirstBuffer = 5;
4006 attributes.iAlignment = 1;
4007 attributes.iContiguous=EFalse;
4008 attributes.iMappable = ETrue;
4010 RSurfaceManager::THintPair hints[2]; // two hint pairs specified
4011 attributes.iHintCount=2;
4012 hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
4013 hints[1].Set(TUid::Uid(0x124523), 50, EFalse);
4014 attributes.iSurfaceHints = hints;
4016 attributes.iOffsetBetweenBuffers = 0;
4018 // Create a surface - increments reference count by 1
4019 TSurfaceId surfaceId;
4020 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId));
4022 // Close the same surface twice
4023 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
4024 TEST(KErrArgument == iSurfaceManager.CloseSurface(surfaceId));
4026 iSurfaceManager.Close();
4029 void CTSurfaceManager::TestCreateSurfaceOomL()
4031 INFO_PRINTF1(_L("Testing CreateSurface in out of memory conditions\r\n"));
4032 // Open the surface manager
4033 User::LeaveIfError(iSurfaceManager.Open());
4034 // Store the attributes used to create the Surface
4035 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
4036 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
4038 attributes.iSize = TSize(280,301);
4039 attributes.iBuffers = 3;
4040 attributes.iPixelFormat = EUidPixelFormatYUV_422SemiPlanar; // 2bpp
4041 attributes.iStride = 710;
4042 attributes.iOffsetToFirstBuffer = 4;
4043 attributes.iAlignment = 4;
4044 attributes.iContiguous=EFalse;
4045 attributes.iMappable = ETrue;
4047 RSurfaceManager::THintPair hints[2]; // two hint pairs specified
4048 attributes.iHintCount=2;
4049 hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
4050 hints[1].Set(TUid::Uid(0x124523), 50, EFalse);
4051 attributes.iSurfaceHints = hints;
4053 attributes.iOffsetBetweenBuffers = 0;
4054 attributes.iCacheAttrib = RSurfaceManager::ECached;
4056 TSurfaceId surfaceId;
4058 // There are 6 kernal allocs, so test that KErrNoMemory is returned if we fail at each
4059 const TInt numKernalAllocs = 6;
4060 for(TInt ii = numKernalAllocs; ii > 0; --ii)
4062 __KHEAP_SETFAIL(RHeap::EDeterministic, ii);
4063 TEST(KErrNoMemory == iSurfaceManager.CreateSurface(buf, surfaceId));
4067 // Test create surface doesn't return an error
4068 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId));
4070 //Map the surface in the current processs
4072 TEST(KErrNone == iSurfaceManager.MapSurface(surfaceId,handle));
4074 // Cache, Contiguous and Alignment attributes are ignored for the already existing chunks
4075 RSurfaceManager::TSurfaceCreationAttributesBuf buff;
4076 RSurfaceManager::TSurfaceCreationAttributes& attributesNew = buff();
4078 attributesNew.iSize = TSize(480,16);
4079 attributesNew.iBuffers = 2; // number of buffers in the surface
4080 attributesNew.iPixelFormat = EUidPixelFormatYUV_422Reversed; // 2bpp
4081 attributesNew.iStride = 1013; // Number of bytes between start of one line and start of next
4082 attributesNew.iOffsetToFirstBuffer = 0; // way of reserving space before the surface pixel data
4084 hints[0].Set(TUid::Uid(0x124545), 50, EFalse); // two hint pairs specified
4086 attributesNew.iAlignment = 8;
4087 attributesNew.iOffsetBetweenBuffers = 0;
4088 attributesNew.iMappable = ETrue;
4090 // Test create surface doesn't return an error
4091 TSurfaceId surfaceIdNew;
4093 __KHEAP_SETFAIL(RHeap::EDeterministic, 1);
4094 TEST(KErrNoMemory == iSurfaceManager.CreateSurface(buff, surfaceIdNew, handle));
4098 iSurfaceManager.Close();
4101 void CTSurfaceManager::SetAttributesForNegativeHintTestL(RSurfaceManager::TSurfaceCreationAttributes& attributesForNegativeHintTest)
4103 attributesForNegativeHintTest.iSize = TSize(16,480);
4104 attributesForNegativeHintTest.iBuffers = 2;
4105 attributesForNegativeHintTest.iPixelFormat = EUidPixelFormatYUV_422Reversed; // 2bpp
4106 attributesForNegativeHintTest.iStride = 50;
4107 attributesForNegativeHintTest.iOffsetToFirstBuffer = 0;
4108 attributesForNegativeHintTest.iAlignment = RSurfaceManager::EPageAligned;
4109 ReAllocHintsArrayL(2);
4110 attributesForNegativeHintTest.iSurfaceHints = iHintsArray;
4111 attributesForNegativeHintTest.iHintCount = 2;
4112 attributesForNegativeHintTest.iSurfaceHints[0].Set(TUid::Uid(0x124578),20, ETrue);
4113 attributesForNegativeHintTest.iSurfaceHints[1].Set(TUid::Uid(0x237755),50, EFalse);
4114 attributesForNegativeHintTest.iContiguous = ETrue;
4115 attributesForNegativeHintTest.iCacheAttrib = RSurfaceManager::ECached;
4116 attributesForNegativeHintTest.iOffsetBetweenBuffers = 0;
4117 attributesForNegativeHintTest.iMappable = ETrue;
4120 void CTSurfaceManager::TestGetSurfaceHintInFalseConditionsL()
4122 INFO_PRINTF1(_L("GetSurfaceHint()reacts properly under false conditions\r\n"));
4123 User::LeaveIfError(iSurfaceManager.Open());
4124 // Store the attributes used to create the Surface
4125 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
4126 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
4127 attributes.iSize = TSize(16,480);
4128 attributes.iBuffers = 2;
4129 attributes.iPixelFormat = EUidPixelFormatYUV_422Reversed;
4130 attributes.iStride = 50;
4131 attributes.iOffsetToFirstBuffer = 0;
4132 attributes.iAlignment = RSurfaceManager::EPageAligned;
4133 attributes.iContiguous = ETrue;
4134 attributes.iCacheAttrib = RSurfaceManager::ECached;
4135 attributes.iOffsetBetweenBuffers = 0;
4136 attributes.iMappable = ETrue;
4138 TSurfaceId surfaceId;
4139 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId));
4141 RSurfaceManager::THintPair hintPair2;
4142 hintPair2.iKey.iUid = 0x123257;
4143 TEST(KErrArgument == iSurfaceManager.GetSurfaceHint(surfaceId, hintPair2));
4146 SetAttributesForNegativeHintTestL(attributes);
4148 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId));
4150 RSurfaceManager::THintPair hintPair;
4151 //Test GetSurfaceHint() returns KErrArgument if the hint pair has 0 UID
4152 hintPair.iKey.iUid = 0;
4153 TEST(KErrArgument == iSurfaceManager.GetSurfaceHint(surfaceId, hintPair));
4155 hintPair.iKey.iUid = 0x124578;
4156 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
4157 TEST(KErrArgument == iSurfaceManager.GetSurfaceHint(surfaceId, hintPair));
4159 TSurfaceId surfaceIdNew;
4160 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceIdNew));
4162 //Convert the type of this surfaceId to EInvalidSurface
4163 TSurfaceId surfaceIdTemp;
4164 surfaceIdTemp = surfaceIdNew;
4165 // Change the surfaceId type to EInvalidSurface
4166 surfaceIdNew.iInternal[3] = (surfaceIdNew.iInternal[3] & 0x00FFFFFF) | ( TSurfaceId::EInvalidSurface <<24 ) ;
4167 TEST(KErrArgument == iSurfaceManager.GetSurfaceHint(surfaceIdNew, hintPair));
4169 //Change the surfaceId back to valid one and find a new THintPair with no keys defined
4170 hintPair2.iKey.iUid = 0x166778;
4171 surfaceIdNew = surfaceIdTemp;
4172 TEST(KErrArgument == iSurfaceManager.GetSurfaceHint(surfaceIdNew, hintPair2));
4174 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceIdNew));
4175 iSurfaceManager.Close();
4178 void CTSurfaceManager::TestSetSurfaceHintInFalseConditionsL()
4180 INFO_PRINTF1(_L("SetSurfaceHint()reacts properly under false conditions\r\n"));
4181 User::LeaveIfError(iSurfaceManager.Open());
4182 // Store the attributes used to create the Surface
4183 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
4184 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
4185 attributes.iSize = TSize(16,480);
4186 attributes.iBuffers = 2;
4187 attributes.iPixelFormat = EUidPixelFormatYUV_422Reversed;
4188 attributes.iStride = 50;
4189 attributes.iOffsetToFirstBuffer = 0;
4190 attributes.iAlignment = RSurfaceManager::EPageAligned;
4191 attributes.iContiguous = ETrue;
4192 attributes.iCacheAttrib = RSurfaceManager::ECached;
4193 attributes.iOffsetBetweenBuffers = 0;
4194 attributes.iMappable = ETrue;
4196 TSurfaceId surfaceId;
4197 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId));
4198 // No hint pair, Setting a null UID hint pair still returns KErrArgument
4199 RSurfaceManager::THintPair hintPair2;
4200 hintPair2.iKey.iUid = 0;
4201 TEST(KErrArgument == iSurfaceManager.SetSurfaceHint(surfaceId, hintPair2));
4204 SetAttributesForNegativeHintTestL(attributes);
4205 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId));
4207 //Set a THintPair with a key value set to 0x124578 and value set to 300
4208 RSurfaceManager::THintPair hintPair;
4209 hintPair.iKey.iUid = 0x124578;
4210 hintPair.iValue = 300;
4212 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
4214 TEST(KErrArgument == iSurfaceManager.SetSurfaceHint(surfaceId, hintPair));
4216 TSurfaceId surfaceIdNew;
4217 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceIdNew));
4219 //Convert the type of this surfaceId to EInvalidSurface
4220 TSurfaceId surfaceIdTemp;
4221 surfaceIdTemp = surfaceIdNew;
4222 // Change the surfaceId type to EInvalidSurface
4223 surfaceIdNew.iInternal[3] = (surfaceIdNew.iInternal[3] & 0x00FFFFFF) | ( TSurfaceId::EInvalidSurface <<24 ) ;
4224 TEST(KErrArgument == iSurfaceManager.SetSurfaceHint(surfaceIdNew, hintPair));
4226 //Change the surfaceId back to valid one and try to access a hint pair which is not mutable
4227 hintPair2.iKey.iUid = 0x237755;
4228 hintPair2.iValue = 300;
4229 surfaceIdNew = surfaceIdTemp;
4230 TEST(KErrNone == iSurfaceManager.OpenSurface(surfaceIdNew));
4231 TEST(KErrAccessDenied == iSurfaceManager.SetSurfaceHint(surfaceIdNew, hintPair2));
4233 //find a new THintPair with no keys defined
4234 RSurfaceManager::THintPair hintPair3;
4235 hintPair3.iValue = 300;
4236 TEST(KErrArgument == iSurfaceManager.SetSurfaceHint(surfaceIdNew, hintPair3));
4238 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceIdNew));
4239 iSurfaceManager.Close();
4242 void CTSurfaceManager::TestAddSurfaceHintInFalseConditionsL()
4244 INFO_PRINTF1(_L("AddSurfaceHint()reacts properly under false conditions\r\n"));
4246 User::LeaveIfError(iSurfaceManager.Open());
4247 // Store the attributes used to create the Surface
4248 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
4249 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
4250 attributes.iSize = TSize(16,480);
4251 attributes.iBuffers = 2;
4252 attributes.iPixelFormat = EUidPixelFormatYUV_422Reversed;
4253 attributes.iStride = 50;
4254 attributes.iOffsetToFirstBuffer = 0;
4255 attributes.iAlignment = RSurfaceManager::EPageAligned;
4256 attributes.iContiguous = ETrue;
4257 attributes.iCacheAttrib = RSurfaceManager::ECached;
4258 attributes.iOffsetBetweenBuffers = 0;
4259 attributes.iMappable = ETrue;
4261 TSurfaceId surfaceId;
4262 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId));
4263 // No hint pair, adding a null UID hint pair still returns KErrArgument
4264 RSurfaceManager::THintPair hintPair2;
4265 hintPair2.iKey.iUid = 0;
4266 TEST(KErrArgument == iSurfaceManager.AddSurfaceHint(surfaceId, hintPair2));
4269 SetAttributesForNegativeHintTestL(attributes);
4271 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId));
4273 //Set a THintPair with a key value set to 0x124578 and value set to 300
4274 RSurfaceManager::THintPair hintPair;
4276 //Test AddSurfaceHint() returns KErrArgument if the hint pair has 0 UID
4277 hintPair.iKey.iUid = 0;
4278 TEST(KErrArgument == iSurfaceManager.AddSurfaceHint(surfaceId, hintPair));
4279 hintPair.iKey.iUid = 0x124256; //restore
4281 //Test AddSurfaceHint () returns KErrArgument if the surface ID is not open in this process
4282 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
4283 TEST(KErrArgument == iSurfaceManager.AddSurfaceHint(surfaceId, hintPair));
4285 //Test AddSurfaceHint () returns KErrArgument if the surface ID is invalid
4286 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId));
4287 TSurfaceId surfaceIdTemp;
4288 surfaceIdTemp = surfaceId;
4289 surfaceId.iInternal[3] = (surfaceId.iInternal[3] & 0x00FFFFFF) | ( TSurfaceId::EInvalidSurface <<24 ) ;
4290 TEST(KErrArgument == iSurfaceManager.AddSurfaceHint(surfaceId, hintPair));
4292 //Test AddSurfaceHint () returns KErrAlreadyExists if duplicate hint key used
4293 surfaceId = surfaceIdTemp;
4294 TEST(KErrNone == iSurfaceManager.OpenSurface(surfaceId));
4295 RSurfaceManager::THintPair hintPairDup;
4296 hintPairDup.iKey.iUid = 0x124578;
4297 hintPairDup.iValue = 300;
4298 TEST(KErrAlreadyExists == iSurfaceManager.AddSurfaceHint(surfaceId, hintPairDup));
4300 //AddSurfaceHint () returns KErrOverflow if no space to add new pair.
4303 TInt maxHintsPerSurface;
4304 iSurfaceManager.GetSurfaceManagerAttrib(RSurfaceManager::EMaxNumberOfHints,maxHintsPerSurface);
4306 for (k=1;k<maxHintsPerSurface-1;++k)
4308 hintPair2.Set(TUid::Uid(0x124611+k),100*k,(k%2==0)?ETrue:EFalse);
4309 TEST(KErrNone == iSurfaceManager.AddSurfaceHint(surfaceId, hintPair2));
4312 hintPair2.Set(TUid::Uid(0x124611+k),100*k,(k%2==0)?ETrue:EFalse);
4313 TEST(KErrOverflow == iSurfaceManager.AddSurfaceHint(surfaceId, hintPair2));
4315 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
4316 iSurfaceManager.Close();
4320 void CTSurfaceManager::TestZerosInHintsArrayL()
4322 INFO_PRINTF1(_L("Creating a surface with only last hint set, then add hint\r\n"));
4323 User::LeaveIfError(iSurfaceManager.Open());
4325 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
4326 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
4328 attributes.iSize = TSize(100,100);
4329 attributes.iBuffers = 2;
4330 attributes.iPixelFormat = EUidPixelFormatARGB_8888;
4331 attributes.iStride = 400;
4332 attributes.iOffsetToFirstBuffer = 10;
4333 attributes.iAlignment = RSurfaceManager::EPageAligned;
4334 attributes.iOffsetBetweenBuffers = 0;
4335 attributes.iContiguous = ETrue;
4336 attributes.iCacheAttrib = RSurfaceManager::ECached;
4337 attributes.iMappable = ETrue;
4339 RSurfaceManager::THintPair hints[8]; // one hint pairs specified
4340 attributes.iHintCount=2;
4341 memclr(hints, sizeof(hints));
4342 hints[7].Set(TUid::Uid(3), 25, ETrue);
4343 attributes.iSurfaceHints = hints;
4345 TSurfaceId surfaceId;
4346 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId));
4348 RSurfaceManager::THintPair hintPair;
4349 hintPair.iKey.iUid = 0x124570;
4350 hintPair.iValue = 50;
4351 hintPair.iMutable = ETrue;
4352 TEST(KErrNone == iSurfaceManager.AddSurfaceHint(surfaceId,hintPair));
4353 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
4355 iSurfaceManager.Close();
4360 void CTSurfaceManager::TestCreateSurfaceWithTooManyHintsL()
4362 User::LeaveIfError(iSurfaceManager.Open());
4363 TInt maxHintsPerSurface;
4364 iSurfaceManager.GetSurfaceManagerAttrib(RSurfaceManager::EMaxNumberOfHints,maxHintsPerSurface);
4365 INFO_PRINTF2(_L("Creating a surface with more than the Maximum of Hints (%d)\r\n"),maxHintsPerSurface);
4367 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
4368 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
4370 attributes.iSize = TSize(100,100);
4371 attributes.iBuffers = 2;
4372 attributes.iPixelFormat = EUidPixelFormatARGB_8888;
4373 attributes.iStride = 400;
4374 attributes.iOffsetToFirstBuffer = 10;
4375 attributes.iAlignment = RSurfaceManager::EPageAligned;
4376 attributes.iOffsetBetweenBuffers = 0;
4377 attributes.iContiguous = ETrue;
4378 attributes.iCacheAttrib = RSurfaceManager::ECached;
4379 attributes.iMappable = ETrue;
4381 ReAllocHintsArrayL(maxHintsPerSurface+2);
4382 for (TInt k=0;k<maxHintsPerSurface+2;++k)
4384 iHintsArray[k].Set(TUid::Uid(0x124611+k),100*k,(k%2==0)?ETrue:EFalse);
4387 attributes.iSurfaceHints = iHintsArray;
4388 attributes.iHintCount=maxHintsPerSurface+2;
4390 TSurfaceId surfaceId;
4391 TEST(KErrArgument == iSurfaceManager.CreateSurface(buf, surfaceId));
4392 iSurfaceManager.Close();
4396 void CTSurfaceManager::TestCreateSurfaceUnMappableL()
4398 INFO_PRINTF1(_L("Create an UNmappable surface and try to map it or get the offset of the first buffer\r\n"));
4399 // Open the surface manager
4400 User::LeaveIfError(iSurfaceManager.Open());
4402 // Store the attributes used to create the Surface
4403 RSurfaceManager::TSurfaceCreationAttributesBuf buf;
4404 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
4405 SetupAttributesL(attributes);
4406 attributes.iMappable = EFalse;
4409 TSurfaceId surfaceId;
4410 TEST(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId));
4413 TEST(KErrNotSupported == iSurfaceManager.MapSurface(surfaceId, handle));
4416 TInt offsetToFirstBuffer;
4417 TEST(KErrNotSupported == iSurfaceManager.GetBufferOffset(surfaceId,0,offsetToFirstBuffer));
4419 TEST(KErrNone == iSurfaceManager.CloseSurface(surfaceId));
4420 iSurfaceManager.Close();
4425 __CONSTRUCT_STEP__(SurfaceManager)
4427 void CTSurfaceManagerStep::TestSetupL()
4431 void CTSurfaceManagerStep::TestClose()
4435 void CTSurfaceManager::testBooleanTrueL(TBool aCondition, const TText8* aFile, TInt aLine)
4438 testBooleanTrue(aCondition, aFile, aLine);
4440 User::Leave(TEST_ERROR_CODE); // leave with standard error code