Update contrib.
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "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 // This test should not depend on any external data files and should work with
15 // the default (empty) epoc.ini file.
16 // The test should be run without the Graphics GCE enabled but with the Base GCE
17 // driver enabled. On the emulator this can be done by launcing with -Dtextshell --
18 // and on the H4 build a textshell ROM with -DSYMBIAN_BASE_USE_GCE but NOT
19 // -DSYMBIAN_GRAPHICS_USE_GCE
20 // In the visual tests some flickering may occur due to updates to the console. On
21 // the emulator it is possible to configure a second screen so that the console updates
22 // will only happen on one screen. The test automatically runs on every screen available.
26 #define __E32TEST_EXTENSION__
28 #include <dispchannel.h>
30 #include <e32std_private.h>
32 #include <e32def_private.h>
35 #include <pixelformats.h>
38 RTest test(_L("Display Channel device driver unit tests"));
40 /** Maximum probable pixel resolution width or height */
41 static const TInt KMaxExpectedPixelRes = 10000;
43 /** Unlikely to ever have a > 1000 Hz refresh rate */
44 static const TInt KMaxExpectedRefreshRate = 1000;
46 /** Time (in microseconds) for each visual test */
47 static const TInt KDrawWaitTime = 1000000;
49 /** Array of supported rotations */
50 static const RDisplayChannel::TDisplayRotation KRotations[] = {
51 RDisplayChannel::ERotationNormal,
52 RDisplayChannel::ERotation90CW,
53 RDisplayChannel::ERotation180,
54 RDisplayChannel::ERotation270CW};
55 static const TInt KNumRotations = sizeof(KRotations) / sizeof(RDisplayChannel::TDisplayRotation);
57 /** Array of pixel formats to try for visual test */
58 static const RDisplayChannel::TPixelFormat KPixelFormats[] = {
59 EUidPixelFormatYUV_422Interleaved16bit, // not supported on emulator but should not be a fatal error
60 EUidPixelFormatXRGB_4444,
61 EUidPixelFormatARGB_4444,
62 EUidPixelFormatRGB_565,
63 EUidPixelFormatXRGB_8888,
64 EUidPixelFormatARGB_8888,
65 EUidPixelFormatARGB_8888_PRE
67 static const TInt KNumPixelFormats = sizeof(KPixelFormats) / sizeof(RDisplayChannel::TPixelFormat);
70 Encapsulates display related HAL information.
88 TInt iOffsetBetweenLines;
89 TInt iOffsetToFirstPixel;
90 TBool iIsPixelOrderRGB;
91 TBool iIsPixelOrderLandscape;
95 Helper class that waits for RDisplayChannel asynchronous requests and
96 can cancel them if necessary. The purpose of this class is so that the main
97 test class can create an asynchronous request and also simulate the completion
98 of that request e.g. faking a display change event.
100 class CAsyncHelper : public CActive
103 inline CAsyncHelper(RDisplayChannel& aDisp);
104 inline ~CAsyncHelper();
105 inline TRequestStatus& Status();
106 void WaitForOperation(TInt* aResult);
109 inline void DoCancel();
112 RDisplayChannel& iDisp;
116 inline CAsyncHelper::CAsyncHelper(RDisplayChannel& aDisp) : CActive(EPriorityHigh), iDisp(aDisp) {CActiveScheduler::Add(this);}
117 inline CAsyncHelper::~CAsyncHelper() {Deque();}
118 inline TRequestStatus& CAsyncHelper::Status() {return iStatus;}
119 // Writes the iStatus.Int() to the address defined by the client of this AO
120 inline void CAsyncHelper::RunL() {*iResult = iStatus.Int();}
122 void CAsyncHelper::WaitForOperation(TInt* aResult)
124 Invokes SetActive() to wait for the asynchronous operation to complete. The completion
125 code is copied to the aResult when RunL is invoked.
126 @param aResult out parameter that will be set to iStatus.Int()
130 // Set the result to default value that is unlikely to be returned by the real API
135 void CAsyncHelper::DoCancel()
137 // Driver should fail if cancel is called when there is not standing request
138 // so cancel just attempts to cancel everything.
139 iDisp.CancelGetCompositionBuffer();
140 iDisp.CancelPostUserBuffer();
141 iDisp.CancelWaitForPost();
142 iDisp.NotifyOnDisplayChangeCancel();
146 Class to test device driver for RDisplayChannel
148 class CDisplayChannelTest : public CActive
152 ETestCompositionBuffers,
156 ETestDisplayChangeDoCancel,
157 ETestDisplayChangeCheckCancel,
158 ETestGetCompositionBufferDoCancel,
159 ETestGetCompositionBufferCheckCancel,
160 ETestWaitForPostDoCancel,
161 ETestWaitForPostCheckCancel,
168 ETestBufferTransitions,
173 static CDisplayChannelTest* NewLC(TInt aScreenId);
175 ~CDisplayChannelTest();
180 TInt RunError(TInt aError);
184 CDisplayChannelTest(TInt aScreenId);
185 void CompleteSelf(TTestState aNextState);
188 void CheckDisplayInfo();
189 void CheckResolutions();
190 void CheckPixelFormats();
191 void CheckDisplayChange();
192 void CheckCompositionBuffers();
193 void CheckBufferFormat();
194 void CheckUserBuffers();
195 void CheckRotations();
196 TBool IsValidRotation(RDisplayChannel::TDisplayRotation aRotation);
197 TBool IsValidPixelFormat(RDisplayChannel::TPixelFormat aPixelFormat);
198 void CheckSetRotation(TUint aSupported, RDisplayChannel::TDisplayRotation aNewRotation);
199 void CheckV11inV10();
201 void DrawLegacyBuffer(TInt aStep);
202 void DrawFillToMemory(TUint8* aFirstPixelAddr, TInt aOffsetBetweenLines,
203 RDisplayChannel::TPixelFormat aPixelFormat, TInt aWidth, TInt aHeight, TInt aStep);
204 void DrawCompositionBuffer(
205 RDisplayChannel::TPostCount& aPostCount,
206 RDisplayChannel::TBufferFormat aBufferFormat,
207 RDisplayChannel::TDisplayRotation aRotation, TInt aStep);
208 void GetHalDisplayInfo();
209 void CheckSecondHandle();
210 void TestBufferTransitions();
213 RDisplayChannel iDisp; /// handle to display channel device driver
214 TVersion iVersion; /// version number of disp channel driver interface
215 THalDisplayInfo iHalInfo; /// info about legacy buffer from HAL
216 TInt iScreenId; /// run tests on each screen
217 TTestState iState; /// the current test
218 CAsyncHelper *iAsyncHelper;
219 TInt iAsyncHelperResult; /// set to iAyncHelper::iStatus.Int()
220 RArray<RDisplayChannel::TResolution> iResolutions;
221 RArray<RDisplayChannel::TPixelFormat> iPixelFormats;
222 TInt iVisualTestFormatIndex; /// index of the current pixel format in visual test
223 TInt iVisualTestRotationIndex; /// index of the current rotation in the visual test
224 TUint iDummyCompositionBuffer; /// dummy var used to test cancel of GetCompositionBuffer
225 RDisplayChannel::TPostCount iDummyPostCount; /// dummy var used to test CancelWaitForPost
228 // Gets a HAL value, logs the result and errors if HAL::Get failed
229 #define DBG_HAL(DEVICE, ATT, VAL, ERR, IN) \
232 ERR = HAL::Get(DEVICE, ATT, VAL); \
233 test.Printf(_L(#ATT)); \
234 test.Printf(_L(" device %d err = %d, val = %d\n"), DEVICE, ERR, VAL); \
235 test_KErrNone(ERR); \
238 void CDisplayChannelTest::GetHalDisplayInfo()
240 Retrieves display related HAL settings. This also initialises the legacy buffer by retrieving
241 HAL::EDisplayMemoryAddress
244 TInt err = KErrNotSupported;
246 DBG_HAL(iScreenId, HAL::EDisplayMemoryAddress, iHalInfo.iMemoryAddress, err, 0);
248 iHalInfo.iMemoryHandle = 0;
249 err = HAL::Get(iScreenId, HAL::EDisplayMemoryHandle, iHalInfo.iMemoryHandle);
250 test(err == KErrNone || err == KErrNotSupported);
251 test.Printf(_L("HAL::EDisplayMemoryHandle returned err %d\n"), err);
254 // Handle is not needed so don't leak it
256 h.SetHandle(iHalInfo.iMemoryHandle);
260 // This is mostly for information purposes to ensure the legacy buffer is sane.
261 DBG_HAL(iScreenId, HAL::EDisplayState, iHalInfo.iState, err, 0);
262 DBG_HAL(iScreenId, HAL::EDisplayColors, iHalInfo.iColors, err, 0);
263 DBG_HAL(iScreenId, HAL::EDisplayXPixels, iHalInfo.iXPixels, err, 0);
264 DBG_HAL(iScreenId, HAL::EDisplayYPixels, iHalInfo.iYPixels, err, 0);
265 DBG_HAL(iScreenId, HAL::EDisplayXTwips, iHalInfo.iXTwips, err, 0);
266 DBG_HAL(iScreenId, HAL::EDisplayYTwips, iHalInfo.iYTwips, err, 0);
267 DBG_HAL(iScreenId, HAL::EDisplayIsPixelOrderRGB, iHalInfo.iIsPixelOrderRGB, err, 0);
268 DBG_HAL(iScreenId, HAL::EDisplayIsPixelOrderLandscape, iHalInfo.iIsPixelOrderLandscape, err, 0);
270 DBG_HAL(iScreenId, HAL::EDisplayNumModes, iHalInfo.iNumModes, err, 0);
271 DBG_HAL(iScreenId, HAL::EDisplayMode, iHalInfo.iMode, err, 0);
273 // Get info for current display mode
274 DBG_HAL(iScreenId, HAL::EDisplayIsMono, iHalInfo.iIsMono, err, iHalInfo.iMode);
275 DBG_HAL(iScreenId, HAL::EDisplayBitsPerPixel, iHalInfo.iBitsPerPixel, err, iHalInfo.iMode);
276 DBG_HAL(iScreenId, HAL::EDisplayOffsetBetweenLines, iHalInfo.iOffsetBetweenLines, err, iHalInfo.iMode);
277 DBG_HAL(iScreenId, HAL::EDisplayOffsetToFirstPixel, iHalInfo.iOffsetToFirstPixel, err, iHalInfo.iMode);
278 DBG_HAL(iScreenId, HAL::EDisplayIsPalettized, iHalInfo.iIsPalettized, err, iHalInfo.iMode);
281 CDisplayChannelTest::CDisplayChannelTest(TInt aScreenId)
284 @param aScreenId the screen number to run the test on
286 : CActive(EPriorityStandard), iScreenId(aScreenId)
288 TVersion versionRequired = iDisp.VersionRequired();
289 test.Printf(_L("*** Opening display channel for screen %d. Test compiled against version %d.%d.%d ***\n"),
290 iScreenId, versionRequired.iMajor, versionRequired.iMinor, versionRequired.iBuild);
291 TInt err = iDisp.Open(iScreenId);
294 test.Printf(_L("Successfully opened display channel for screen %d\n"), iScreenId);
296 // This test should be updated if a change to the driver requires a version change
297 err = iDisp.Version(iVersion);
298 if (err == KErrNotSupported)
300 test.Printf(_L("Version API not supported. Assuming v1.0.0\n"));
307 test.Printf(_L("Display channel driver version %d.%d.%d\n"),
308 iVersion.iMajor, iVersion.iMinor, iVersion.iBuild);
311 test(iVersion.iMajor >= 1 && iVersion.iMinor >= 0);
313 CActiveScheduler::Add(this);
315 iAsyncHelper = new CAsyncHelper(iDisp);
316 test_NotNull(iAsyncHelper);
319 CDisplayChannelTest::~CDisplayChannelTest()
326 iPixelFormats.Close();
327 iResolutions.Close();
331 CDisplayChannelTest* CDisplayChannelTest::NewLC(TInt aScreenId)
333 Factory method that creates a new instance of the screen
334 display channel unit test object and places a pointer to this on the cleanup stack
336 @param aScreenId the screen number to run the test on
337 @return a pointer to the new CDisplayTest object.
340 CDisplayChannelTest* self = new(ELeave) CDisplayChannelTest(aScreenId);
341 CleanupStack::PushL(self);
345 void CDisplayChannelTest::CheckDisplayInfo()
347 Check the values returned by CheckDisplayInfo
350 test.Next(_L("Test GetDisplayInfo"));
351 TPckgBuf<RDisplayChannel::TDisplayInfo> infoPkg;
353 test_KErrNone(iDisp.GetDisplayInfo(infoPkg));
355 // This test only works with 24 and 32 BPP displays and crashes otherwise. Test for this and display
356 // a nice human readable message rather than just crashing
357 if ((infoPkg().iBitsPerPixel != 24) && (infoPkg().iBitsPerPixel != 32))
361 message.Format(_L("*** Error! %d bits per pixel displays are not supported. ***\n*** Please configure your ROM to use 24 or 32 bits per pixel. ***\n"), infoPkg().iBitsPerPixel);
362 test.Printf(message);
364 // And fail the test for the benefit of automated ONB tests
365 test_Equal(infoPkg().iBitsPerPixel, 24);
368 test_Compare(infoPkg().iBitsPerPixel, >=, 1);
369 test_Compare(infoPkg().iAvailableRotations, !=, 0);
371 // check for invalid rotations i.e. those not defined by TRotation
372 test((infoPkg().iAvailableRotations & 0xFFF0) == 0);
374 // Check that the refresh rate field isn't garbage
375 test_Compare(infoPkg().iRefreshRateHz, >=, 1);
376 test_Compare(infoPkg().iRefreshRateHz, <=, KMaxExpectedRefreshRate);
378 // Should always be at least one composition buffer
379 test_Compare(infoPkg().iNumCompositionBuffers, >=, 1);
382 void CDisplayChannelTest::CheckResolutions()
384 Validate that the APIs to get / set resolutions.
387 NumberOfResolutions, GetResolutions, GetResolution, GetRotation
390 test.Next(_L("Test NumberOfResolutions, GetResolutions, GetResolution, GetRotation"));
392 // Get and reserve space for expected number of resolutions
393 TInt n = iDisp.NumberOfResolutions();
394 test_Compare(n, >=, 1);
396 iResolutions.Reset();
397 test_KErrNone(iResolutions.Reserve(n));
398 for (TInt i = 0; i < n; ++i)
400 test_KErrNone(iResolutions.Append(RDisplayChannel::TResolution(TSize(0,0), TSize(0,0), 0)));
403 // Retrieve the resolutions and make sure the number of resolutions returned matches the
404 // expected number. It is assumed that the display state won't be changed during the execution
406 TInt actualResolutions = 0;
407 TPtr8 resPtr(reinterpret_cast<TUint8*>(&iResolutions[0]),
408 sizeof(RDisplayChannel::TResolution) * n, sizeof(RDisplayChannel::TResolution) * n);
409 test_KErrNone(iDisp.GetResolutions(resPtr, actualResolutions));
410 test_Equal(n, actualResolutions);
412 test.Printf(_L("Supported resolutions"));
413 for (TInt res = 0; res < n; ++res)
415 RDisplayChannel::TResolution& r = iResolutions[res];
416 test.Printf(_L("pixelX = %d heightX = %d twipsX = %d twipsY = %d flags = 0x%08x\n"),
417 r.iPixelSize.iWidth, r.iPixelSize.iHeight, r.iTwipsSize.iWidth, r.iTwipsSize.iHeight, r.iFlags);
419 // If either pixel height or pixel width is zero then both must be zero
420 // If either pixel height or pixel width is non-zero then both must be positive
421 test((r.iPixelSize.iHeight == 0 && r.iPixelSize.iWidth == 0) ||
422 (r.iPixelSize.iHeight > 0 && r.iPixelSize.iWidth > 0));
424 // Test resolutions are sane
425 test(r.iPixelSize.iHeight <= KMaxExpectedPixelRes && r.iPixelSize.iWidth <= KMaxExpectedPixelRes);
427 // If either twips height or pixel width is zero then both must be zero
428 // If either twips height or pixel width is non-zero then both must be positive
429 test((r.iTwipsSize.iHeight == 0 && r.iTwipsSize.iWidth == 0) ||
430 (r.iTwipsSize.iHeight > 0 && r.iTwipsSize.iWidth > 0));
432 // twips resolution can be zero iff pixel resolution is also zero
433 test((r.iPixelSize.iHeight == 0 && r.iTwipsSize.iHeight == 0) ||
434 (r.iPixelSize.iHeight > 0 && r.iTwipsSize.iHeight > 0));
436 // At least one rotation must be supported. Ignore other bits in the flags field
437 test(r.iFlags & RDisplayChannel::ERotationAll != 0);
440 // Get current resolution in pixels
441 TSize currentResolution;
442 test_KErrNone(iDisp.GetResolution(currentResolution));
444 // Get current resolution in twips
446 test_KErrNone(iDisp.GetTwips(currentTwips));
448 RDisplayChannel::TDisplayRotation currentRotation = iDisp.CurrentRotation();
449 test(IsValidRotation(currentRotation));
451 // The current resolution and rotation must be in the list of supported resolutions
452 TBool foundCurrentRes = EFalse;
453 for (TInt j = iResolutions.Count() - 1; j >= 0; --j)
455 if (iResolutions[j].iPixelSize == currentResolution &&
456 iResolutions[j].iTwipsSize == currentTwips &&
457 iResolutions[j].iFlags & currentRotation)
459 foundCurrentRes = ETrue;
463 test(foundCurrentRes);
465 // Now and try every supported resolution
467 for (TInt k = iResolutions.Count() - 1; k >= 0; --k)
469 err = iDisp.SetResolution(iResolutions[k].iPixelSize);
470 test(err == KErrNone || err == KErrNotSupported);
472 // attempt to set back to original resolution, this could fail
473 err = iDisp.SetResolution(currentResolution);
474 test(err == KErrNone || err == KErrNotSupported);
477 void CDisplayChannelTest::CheckPixelFormats()
479 Validates that the pixel format APIs are sane/consistent.
481 In version 1.1 the APIs are just stubs that return KErrNotSupported
484 test.Next(_L("Test NumberOfPixelFormats, GetPixelFormats"));
486 // At least one pixel format must be supported
487 TInt n = iDisp.NumberOfPixelFormats();
489 if (iVersion.iMajor == 1 && iVersion.iMinor <= 1)
491 test_Compare(n, ==, KErrNotSupported);
492 n = 1; // Override return to test stub for GetPixelFormats
496 test_Compare(n, >=, 1);
499 TInt err = iPixelFormats.Reserve(n);
501 for (TInt i = 0; i < n; ++i)
503 test_KErrNone(iPixelFormats.Append(-1));
505 TPtr8 pixelFormatsPtr(reinterpret_cast<TUint8*>(&iPixelFormats[0]),
506 sizeof(RDisplayChannel::TPixelFormat) * n, sizeof(RDisplayChannel::TPixelFormat) * n);
508 TInt actualFormats = -1;
509 if (iVersion.iMajor == 1 && iVersion.iMinor <= 1)
511 test_Compare(iDisp.GetPixelFormats(pixelFormatsPtr, actualFormats), ==, KErrNotSupported);
515 test_KErrNone(iDisp.GetPixelFormats(pixelFormatsPtr, actualFormats));
517 // The number of formats shouldn't have changed whilst this test is running
518 test_Equal(n, actualFormats);
519 RArray<RDisplayChannel::TPixelFormat> pixelFormatsArray(
520 reinterpret_cast<RDisplayChannel::TPixelFormat*>(&pixelFormatsPtr[0]), actualFormats);
522 // Check the pixel formats returned are all valid
523 for (TInt pf = pixelFormatsArray.Count() - 1; pf >= 0; --pf)
525 IsValidPixelFormat(pixelFormatsArray[pf]);
530 void CDisplayChannelTest::CheckDisplayChange()
532 Register for display change notification then immediately cancel.
535 test.Next(_L("Test NotifyOnDisplayChange, NotifyOnDisplayChangeCancel"));
536 // Cancel should be allowed even if NotifyOnyDisplayChange has not been called
537 iDisp.NotifyOnDisplayChangeCancel();
539 iDisp.NotifyOnDisplayChange(iAsyncHelper->Status());
540 iAsyncHelper->WaitForOperation(&iAsyncHelperResult);
543 void CDisplayChannelTest::DrawFillToMemory(
544 TUint8* aFirstPixelAddr,
545 TInt aOffsetBetweenLines,
546 RDisplayChannel::TPixelFormat aPixelFormat,
551 Draws a shaded fill to a memory region
552 @param aFirstPixelAddr the address of the first pixel in the buffer.
553 @param aOffsetBetweenLines offset between pixels at the start of each line
554 @param aBpp bits per pixel
555 @param aWidth width of the region in pixels
556 @param aHeight height of the region in pixels
557 @aStep aStep integer >= 1 to vary the pattern by test number
559 test.Printf(_L("DrawFileToMemory\npixelformat = 0x%08x offsetbetweenlines = %d pixel address = 0x%08x width=%d height = %d\n"),
560 aPixelFormat, aOffsetBetweenLines, aFirstPixelAddr, aWidth, aHeight);
563 TInt xShadeMax = 0xFF;
564 TInt yShadeMax = 0xFF;
566 if (aPixelFormat == EUidPixelFormatRGB_565)
568 xShadeMax = 0x3F; // 6 bits for green
571 else if (aPixelFormat == EUidPixelFormatARGB_4444 || aPixelFormat == EUidPixelFormatXRGB_4444)
577 aStep = Max(1, aStep);
578 TUint8* lineAddr = aFirstPixelAddr;
579 for (TInt y = 0; y < aHeight; ++y)
581 TInt yShade = (y * yShadeMax) / aHeight;
582 TUint8* pixelAddr = lineAddr;
583 for (TInt x = 0; x < aWidth; ++x)
585 TInt xShade = (x * xShadeMax) / aWidth;
590 if ( aStep == 0 || y > aStep * 10)
592 // Green top left, blue bottom right
593 green = static_cast<TUint8>(xShadeMax - xShade);
594 blue = static_cast<TUint8>(yShade);
598 // The size of the red band indicates different test steps
599 red = static_cast<TUint8>((yShadeMax * x) / aWidth);
602 if (aPixelFormat == EUidPixelFormatRGB_565)
604 *pixelAddr++ = static_cast<TUint8>(blue | (green << 5));
605 *pixelAddr++ = static_cast<TUint8>((green >> 3) | (red << 3));
607 else if (aPixelFormat == EUidPixelFormatARGB_4444 || aPixelFormat == EUidPixelFormatXRGB_4444)
609 *pixelAddr++ = static_cast<TUint8>(blue | (green << 4));
612 else if (aPixelFormat == EUidPixelFormatXRGB_8888 || aPixelFormat == EUidPixelFormatARGB_8888
613 || aPixelFormat == EUidPixelFormatARGB_8888)
616 *pixelAddr++ = green;
618 *pixelAddr++ = 0xFF; // unused
621 lineAddr += aOffsetBetweenLines;
625 void CDisplayChannelTest::DrawLegacyBuffer(TInt aStep)
627 test.Printf(_L("DrawLegacyBuffer\n"));
630 err = HAL::Get(iScreenId, HAL::EDisplayMode, oldMode);
631 for (TInt i = 0; i < iHalInfo.iNumModes; ++i)
633 // Attempt to set the legacy buffer to a mode supporting 32bit (RGBA or RGBX)
635 err = HAL::Get(iScreenId, HAL::EDisplayBitsPerPixel, modeBpp);
638 if ((modeBpp == 24 || modeBpp == 32))
641 err = HAL::Set(iScreenId, HAL::EDisplayMode, newMode);
647 err = HAL::Set(iScreenId, HAL::EDisplayMode, oldMode);
648 TUint8* firstPixelAddr = reinterpret_cast<TUint8*>(iHalInfo.iMemoryAddress + iHalInfo.iOffsetToFirstPixel);
649 TInt offsetBetweenLines = iHalInfo.iOffsetBetweenLines;
650 TInt width = iHalInfo.iXPixels;
651 TInt height = iHalInfo.iYPixels;
653 if ((! iHalInfo.iIsPalettized) && iHalInfo.iIsPixelOrderRGB)
655 DrawFillToMemory(firstPixelAddr, offsetBetweenLines,
656 EUidPixelFormatXRGB_8888, width, height, aStep);
660 void CDisplayChannelTest::DrawCompositionBuffer(
661 RDisplayChannel::TPostCount& aPostCount,
662 RDisplayChannel::TBufferFormat aBufferFormat,
663 RDisplayChannel::TDisplayRotation aRotation, TInt aStep)
665 Attempts to set the requested buffer format and rotation then draws a shaded fill
666 to the buffer returned by RDisplayChannel::GetCompositionBuffer.
667 If it is not possible to set the desired buffer format then the actual buffer format
670 @param aPostCount out parameter that is set to the post count returned by PostCompositionBuffer
671 @param aBufferFormat the buffer format to use for this test step
672 @param aRotation the rotation to set for this test step
673 @param aStep test step number
676 test.Printf(_L("DrawCompositionBuffer\n"));
681 RDisplayChannel::TBufferFormat actualBufferFormat(TSize(0,0),0);
682 if (iVersion.iMajor > 1 || iVersion.iMinor > 0)
684 // It should be possible to set the rotation and the buffer format in either order.
685 // To test this the order is swapped every test step
688 test_KErrNone(iDisp.SetRotation(aRotation, configChanged));
689 err = iDisp.SetBufferFormat(aBufferFormat);
693 err = iDisp.SetBufferFormat(aBufferFormat);
694 test_KErrNone(iDisp.SetRotation(aRotation, configChanged));
698 test.Printf(_L("Unable to set buffer format 0x%08x width %d height %d"),
699 aBufferFormat.iPixelFormat, aBufferFormat.iSize.iWidth, aBufferFormat.iSize.iHeight);
701 test_KErrNone(iDisp.GetBufferFormat(actualBufferFormat));
705 // buffer format not switched in v1.1 so test just validates post / wait for post
706 TPckgBuf<RDisplayChannel::TDisplayInfo> infoPkg;
707 test_KErrNone(iDisp.GetDisplayInfo(infoPkg));
709 err = iDisp.SetRotation(aRotation, configChanged);
710 TInt expectedErr = KErrNone;
711 if ((!IsValidRotation(aRotation)) || ((infoPkg().iAvailableRotations & aRotation) == 0))
713 expectedErr = KErrArgument;
715 test(err == expectedErr);
717 actualBufferFormat = aBufferFormat;
720 // Get the composition buffer index
722 TRequestStatus status;
723 iDisp.GetCompositionBuffer(bufferIndex, status);
724 User::WaitForRequest(status);
725 test(status == KErrNone);
727 // Now get access to the composition buffer
730 err = iDisp.GetCompositionBufferInfo(bufferIndex, compChunk, offset);
733 TUint8* baseAddr = compChunk.Base();
734 TPckgBuf<RDisplayChannel::TDisplayInfo> infoPkg;
735 err = iDisp.GetDisplayInfo(infoPkg);
738 test.Printf(_L("DrawCompositionBuffer::GetCompositionBufferInfo index = 0x%08x base = 0x%08x offset = 0x%08x\n"),
739 bufferIndex, baseAddr, offset);
741 // Find out structure of the buffer
742 TUint8* firstPixelAddr = baseAddr + offset;
744 // Find out current display dimensions
747 RDisplayChannel::TDisplayRotation currentRotation = iDisp.CurrentRotation();
748 test(IsValidRotation(currentRotation));
749 if (currentRotation == RDisplayChannel::ERotationNormal ||
750 currentRotation == RDisplayChannel::ERotation180)
752 width = actualBufferFormat.iSize.iWidth;
753 height = actualBufferFormat.iSize.iHeight;
757 height = actualBufferFormat.iSize.iWidth;
758 width = actualBufferFormat.iSize.iHeight;
761 TInt offsetBetweenLines;
762 if (iVersion.iMajor > 1 || iVersion.iMinor > 0)
764 offsetBetweenLines = iDisp.NextLineOffset(actualBufferFormat, 0);
768 // NextLineOffset not supported in v1.0 and displayinfo offset doesn't work on H4
769 offsetBetweenLines = 4 * width;
771 DrawFillToMemory(firstPixelAddr, offsetBetweenLines, actualBufferFormat.iPixelFormat,
772 width, height, aStep);
774 err = iDisp.PostCompositionBuffer(NULL, aPostCount);
776 User::After(KDrawWaitTime);
781 void CDisplayChannelTest::CheckCompositionBuffers()
783 Retrieves the current composition buffer index and checks the information about
787 test.Next(_L("Test GetCompositionBuffer, CancelGetCompositionBuffer, GetCompositionBufferInfo, PostLegacyBuffer"));
789 iDisp.CancelGetCompositionBuffer(); // Test cancel without an outstanding call
792 TRequestStatus status;
793 // Get with immediate cancel
794 iDisp.GetCompositionBuffer(bufferIndex, status);
795 iDisp.CancelGetCompositionBuffer();
796 test(status == KErrNone || status == KErrCancel);
798 iDisp.GetCompositionBuffer(bufferIndex, status); // Get, no cancel
799 User::WaitForRequest(status);
800 test(status == KErrNone);
804 test_KErrNone(iDisp.GetCompositionBufferInfo(bufferIndex, compChunk, offset));
806 // client must be able to read and write to the chunk
807 test(compChunk.IsReadable());
808 test(compChunk.IsWritable());
809 test_Compare(offset, >=, 0);
811 RDisplayChannel::TPostCount postCountA;
812 RDisplayChannel::TPostCount postCountB;
813 test_KErrNone(iDisp.PostCompositionBuffer(NULL, postCountA));
814 test_KErrNone(iDisp.PostCompositionBuffer(NULL, postCountB));
815 test_Compare(postCountB - postCountA, >=, 1);
817 // Wait for first postcount value
818 iDisp.WaitForPost(postCountA, status);
819 User::WaitForRequest(status);
820 test(status == KErrNone);
822 // It should be possible to wait again on postCountA
823 // and this should complete immediately with KErrNone. However, there
824 // there is bug in the emulator causes this to wait forever.
828 // Legacy buffer should have been initialised by retrieval of HAL::EDisplayMemoryAddress
829 test_KErrNone(iDisp.PostLegacyBuffer(NULL, postCountA));
830 test_Compare(postCountA - postCountB, >=, 1);
833 void CDisplayChannelTest::VisualTest()
835 Iterates over the arrays of pixel formats and rotations attempting to
836 draw a shaded fill to the composition buffer
839 test.Next(_L("Visual test"));
841 RDisplayChannel::TPostCount postCount;
842 if (iVisualTestFormatIndex < KNumPixelFormats)
844 RDisplayChannel::TBufferFormat bufferFormat(TSize(0,0), 0);
845 if (iVersion.iMajor == 1 && iVersion.iMinor == 0)
847 // only one format supported in v1.0 so only one loop needed
848 bufferFormat.iPixelFormat = EUidPixelFormatXRGB_8888;
849 iVisualTestFormatIndex = KNumPixelFormats - 1;
850 TPckgBuf<RDisplayChannel::TDisplayInfo> infoPkg;
851 iDisp.GetDisplayInfo(infoPkg);
852 bufferFormat.iSize.iWidth = infoPkg().iNormal.iWidth;
853 bufferFormat.iSize.iHeight = infoPkg().iNormal.iHeight;
857 test_KErrNone(iDisp.GetBufferFormat(bufferFormat));
858 bufferFormat.iPixelFormat = KPixelFormats[iVisualTestFormatIndex];
860 DrawCompositionBuffer(postCount, bufferFormat, KRotations[iVisualTestRotationIndex], iVisualTestRotationIndex);
861 iVisualTestRotationIndex++;
862 if (iVisualTestRotationIndex >= KNumRotations)
864 iVisualTestRotationIndex = 0;
865 iVisualTestFormatIndex++;
867 iDisp.WaitForPost(postCount, iStatus);
872 // Test drawing to the legacy buffer
873 test.Printf(_L("Drawing to legacy buffer\n"));
876 iDisp.SetRotation(KRotations[0], configChanged);
877 DrawLegacyBuffer(20); // Make legacy buffer obviously different
878 test_KErrNone(iDisp.PostLegacyBuffer(NULL, postCount));
879 CompleteSelf(ETestSecondHandle);
880 User::After(KDrawWaitTime);
884 void CDisplayChannelTest::CheckBufferFormat()
886 Tests the APIs for getting and setting the buffer format.
887 In version 1.1 these APIs are only stubs that return KErrNotSupported
889 @pre CheckResolutions must have called prior to calling this method
890 @pre CheckPixelFormats must have been called prior to calling this method.
893 test.Next(_L("Test GetBufferFormat, SetBufferFormat, NextLineOffset, NextPlaneOffset"));
895 RDisplayChannel::TBufferFormat bufferFormat(TSize(0,0), 0);
896 TInt err = iDisp.GetBufferFormat(bufferFormat);
897 if (iVersion.iMajor == 1 && iVersion.iMinor <= 1)
899 test_Compare(err, ==, KErrNotSupported);
903 test(IsValidPixelFormat(bufferFormat.iPixelFormat));
904 test(bufferFormat.iSize.iHeight > 0 && bufferFormat.iSize.iHeight > 0);
905 // Check that the buffer is at least as large as the current pixel resolution
907 test_KErrNone(iDisp.GetResolution(resSize));
908 test(bufferFormat.iSize.iHeight >= resSize.iHeight && bufferFormat.iSize.iWidth >= resSize.iWidth);
911 RDisplayChannel::TBufferFormat newBufferFormat(TSize(iHalInfo.iXPixels, iHalInfo.iYPixels), 0);
912 if (iVersion.iMajor == 1 && iVersion.iMinor <= 1)
914 // API not support in 1.1
915 test_Compare(iDisp.SetBufferFormat(newBufferFormat), ==, KErrNotSupported);
919 // Tests assumes that 32bpp XRGB888 is supported on most hardware
920 RDisplayChannel::TBufferFormat newBufferFormat(TSize(0,0), EUidPixelFormatXRGB_8888);
921 test_Compare(iDisp.SetBufferFormat(newBufferFormat), ==, KErrArgument); // buffer must be large enough for resolution
923 // Should be able to current buffer format
924 test_KErrNone(iDisp.SetBufferFormat(bufferFormat));
927 // Get current information and check this against new APIs that give
928 // line and plane information for any mode.
929 TSize currentPixelRes;
930 TSize currentTwipRes;
931 RDisplayChannel::TDisplayRotation currentRotation = iDisp.CurrentRotation();
932 RDisplayChannel::TBufferFormat currentBufferFormat(TSize(0,0), 0);
934 test_KErrNone(iDisp.GetResolution(currentPixelRes));
935 test_KErrNone(iDisp.GetTwips(currentTwipRes));
936 test_KErrNone(iDisp.GetBufferFormat(currentBufferFormat));
937 RDisplayChannel::TResolution res(currentPixelRes, currentTwipRes, currentRotation);
939 TInt planeOffset = iDisp.NextPlaneOffset(currentBufferFormat, 0);
940 if (iVersion.iMajor == 1 && iVersion.iMinor <= 1)
942 test_Compare(planeOffset, ==, KErrNotSupported);
947 test_Compare(planeOffset, >=, 0);
949 if (iVersion.iMajor > 1 || iVersion.iMinor > 1)
951 // Extended API in v1.2
952 test.Printf(_L("Check that planeoffset APIs match"));
953 TInt planeOffset2 = iDisp.NextPlaneOffset(currentBufferFormat, res, currentRotation, 0);
954 test_Compare(planeOffset, ==, planeOffset2);
956 // check that invalid buffer formats are rejected
957 RDisplayChannel::TBufferFormat badBufferFormat(currentBufferFormat);
958 badBufferFormat.iPixelFormat = -1;
959 test(iDisp.NextPlaneOffset(badBufferFormat, res, currentRotation, 0) == KErrArgument);
963 TInt lineOffset = iDisp.NextLineOffset(currentBufferFormat, 0);
964 if (iVersion.iMajor == 1 && iVersion.iMinor <= 1)
966 test_Compare(lineOffset, ==, KErrNotSupported);
970 test_Compare(lineOffset, >, 0); // supported in v1.1
972 if (iVersion.iMajor > 1 || iVersion.iMinor > 1)
974 // Extended API in v1.2
975 test.Printf(_L("Check that lineoffset APIs match"));
976 TInt lineOffset2 = iDisp.NextLineOffset(currentBufferFormat, res, currentRotation, 0);
977 // stride values must be the same and > 0 for any non-zero resolution and the current
978 // resolution should not be zero in size.
980 test_Compare(lineOffset, ==, lineOffset2);
981 // check that invalid buffer formats are rejected
982 RDisplayChannel::TBufferFormat badBufferFormat(currentBufferFormat);
983 badBufferFormat.iPixelFormat = -1;
984 test(iDisp.NextLineOffset(badBufferFormat, res, currentRotation, 0) == KErrArgument);
989 void CDisplayChannelTest::CheckUserBuffers()
991 Test APIs that manage user composition buffers. Since this unit test doesn't
992 have access to the real surfaces the tests are mostly robustness tests.
995 test.Next(_L("Test WaitForPost, DeRegisterUserBuffer"));
997 // Cancel should not fail even if WaitForPost has not been called
998 iDisp.CancelWaitForPost();
1000 // Check that cancelling a non-existent post request doesn't fail
1001 iDisp.CancelPostUserBuffer();
1003 // Make sure wait immediately followed by cancel doesn't crash
1004 TRequestStatus status;
1005 RDisplayChannel::TPostCount postCount = 0;
1006 iDisp.WaitForPost(postCount, status);
1007 iDisp.CancelWaitForPost();
1008 test(status == KErrNone || status == KErrCancel);
1010 // De-register a non-existent buffer id
1011 RDisplayChannel::TBufferId badBufferId(42);
1012 TInt err = iDisp.DeregisterUserBuffer(badBufferId);
1013 // emulator KErrArugment but on H4 KErrNotFound
1014 test(err == KErrArgument || err == KErrNotFound);
1016 // Create and use a new buffer, should fail because chunk must be a SHARED chunk
1018 const TInt chunkSize = 320 * 200 * 4; // actual size is not important because this should fail
1019 err = myChunk.CreateGlobal(KNullDesC, chunkSize, chunkSize, EOwnerProcess);
1020 test_KErrNone(err); // Allocation should not fail under normal conditions
1021 RDisplayChannel::TBufferId myBufferId;
1022 err = iDisp.RegisterUserBuffer(myBufferId, myChunk, 0);
1023 // emulator KErrBadHandle but on H4 KErrArgument
1024 test(err == KErrBadHandle || err == KErrArgument);
1027 // Try to post a request from a bad buffer id
1028 iDisp.PostUserBuffer(badBufferId, status, NULL, postCount);
1029 User::WaitForRequest(status);
1030 // Emulator KErrArgument H4 KErrNotFound
1031 test(status.Int() == KErrArgument || status.Int() == KErrNotFound);
1033 // Attempt to register an already existing buffer as a user buffer
1035 iDisp.GetCompositionBuffer(compId, status);
1036 User::WaitForRequest(status);
1039 test_KErrNone(iDisp.GetCompositionBufferInfo(compId, compChunk, offset));
1040 test_KErrNone(iDisp.RegisterUserBuffer(myBufferId, compChunk, offset));
1041 err = iDisp.DeregisterUserBuffer(myBufferId);
1042 test(err == KErrNone || err == KErrInUse);
1046 TBool CDisplayChannelTest::IsValidPixelFormat(RDisplayChannel::TPixelFormat aPixelFormat)
1048 Validates whether the value of aPixelFormat corresponds to a valid enum in TUidPixelFormat
1049 @param aPixelFormat the pixel format value to test
1050 @return ETrue if aPixelFormat is valid; otherwise, EFalse is returned.
1053 switch (aPixelFormat)
1055 case EUidPixelFormatUnknown:
1056 case EUidPixelFormatXRGB_8888:
1057 case EUidPixelFormatBGRX_8888:
1058 case EUidPixelFormatXBGR_8888:
1059 case EUidPixelFormatBGRA_8888:
1060 case EUidPixelFormatARGB_8888:
1061 case EUidPixelFormatABGR_8888:
1062 case EUidPixelFormatARGB_8888_PRE:
1063 case EUidPixelFormatABGR_8888_PRE:
1064 case EUidPixelFormatBGRA_8888_PRE:
1065 case EUidPixelFormatARGB_2101010:
1066 case EUidPixelFormatABGR_2101010:
1067 case EUidPixelFormatBGR_888:
1068 case EUidPixelFormatRGB_888:
1069 case EUidPixelFormatRGB_565:
1070 case EUidPixelFormatBGR_565:
1071 case EUidPixelFormatARGB_1555:
1072 case EUidPixelFormatXRGB_1555:
1073 case EUidPixelFormatARGB_4444:
1074 case EUidPixelFormatARGB_8332:
1075 case EUidPixelFormatBGRX_5551:
1076 case EUidPixelFormatBGRA_5551:
1077 case EUidPixelFormatBGRA_4444:
1078 case EUidPixelFormatBGRX_4444:
1079 case EUidPixelFormatAP_88:
1080 case EUidPixelFormatXRGB_4444:
1081 case EUidPixelFormatXBGR_4444:
1082 case EUidPixelFormatRGB_332:
1083 case EUidPixelFormatA_8:
1084 case EUidPixelFormatBGR_332:
1085 case EUidPixelFormatP_8:
1086 case EUidPixelFormatP_4:
1087 case EUidPixelFormatP_2:
1088 case EUidPixelFormatP_1:
1089 case EUidPixelFormatYUV_420Interleaved:
1090 case EUidPixelFormatYUV_420Planar:
1091 case EUidPixelFormatYUV_420PlanarReversed:
1092 case EUidPixelFormatYUV_420SemiPlanar:
1093 case EUidPixelFormatYUV_422Interleaved:
1094 case EUidPixelFormatYUV_422Planar:
1095 case EUidPixelFormatYUV_422Reversed:
1096 case EUidPixelFormatYUV_422SemiPlanar:
1097 case EUidPixelFormatYUV_422InterleavedReversed:
1098 case EUidPixelFormatYUV_422Interleaved16bit:
1099 case EUidPixelFormatYUV_444Interleaved:
1100 case EUidPixelFormatYUV_444Planar:
1101 case EUidPixelFormatL_8:
1102 case EUidPixelFormatL_4:
1103 case EUidPixelFormatL_2:
1104 case EUidPixelFormatL_1:
1105 case EUidPixelFormatSpeedTaggedJPEG:
1106 case EUidPixelFormatJPEG:
1113 TBool CDisplayChannelTest::IsValidRotation(RDisplayChannel::TDisplayRotation aRotation)
1115 Checks whether the supplied rotation is a valid rotation. <br>
1116 N.B. Only single rotations are accepted so EFalse is returned for ERotationAll.
1117 @param aRotation the rotation to validate
1118 @return ETrue if the supplied rotation is valid; otherwise, EFalse is returned.
1123 case RDisplayChannel::ERotationNormal:
1124 case RDisplayChannel::ERotation90CW:
1125 case RDisplayChannel::ERotation180:
1126 case RDisplayChannel::ERotation270CW:
1133 void CDisplayChannelTest::CheckSetRotation(TUint aSupported, RDisplayChannel::TDisplayRotation aNewRotation)
1135 Tests the SetRotation API attempting to set the requested resolution. If the resolution is supported
1136 then SetRotation should succeed and the CurrentRotation should change. Otherwise, SetResolution should
1137 fail and the current rotation should be unchanged.
1139 @param aSupported The set of supported resolutions for TDisplayInfo
1140 @param aNewRotation The new rotation to set
1143 RDisplayChannel::TDisplayRotation currentRotation = iDisp.CurrentRotation();
1144 test(IsValidRotation(currentRotation));
1146 TBool displayConfigChanged = EFalse;
1147 TInt err = iDisp.SetRotation(aNewRotation, displayConfigChanged);
1148 TInt expectedErr = KErrNone;
1149 if ((!IsValidRotation(aNewRotation)) || ((aSupported & aNewRotation) == 0))
1151 expectedErr = KErrArgument;
1153 test(err == expectedErr);
1155 // Check whether the rotation should / shouldn't have changed
1156 test (iDisp.CurrentRotation() == (err == KErrNone ? aNewRotation : currentRotation));
1159 void CDisplayChannelTest::CheckRotations()
1161 Tests the SetRotation and GetRotation APIs by attempting to set each valid rotation
1162 plus some invalid rotation values.
1163 If a rotation is valid but not supported then KErrNotSupported should be returned.
1166 test.Next(_L("Test CurrentRotation, SetRotation"));
1168 // Find out supported resolutions
1169 TPckgBuf<RDisplayChannel::TDisplayInfo> infoPkg;
1170 test_KErrNone(iDisp.GetDisplayInfo(infoPkg));
1172 CheckSetRotation(infoPkg().iAvailableRotations, RDisplayChannel::ERotationNormal);
1173 CheckSetRotation(infoPkg().iAvailableRotations, RDisplayChannel::ERotation90CW);
1174 CheckSetRotation(infoPkg().iAvailableRotations, RDisplayChannel::ERotation180);
1175 CheckSetRotation(infoPkg().iAvailableRotations, RDisplayChannel::ERotation270CW);
1176 CheckSetRotation(infoPkg().iAvailableRotations, RDisplayChannel::ERotationNormal);
1177 CheckSetRotation(infoPkg().iAvailableRotations, static_cast<RDisplayChannel::TDisplayRotation>(-1));
1178 CheckSetRotation(infoPkg().iAvailableRotations, static_cast<RDisplayChannel::TDisplayRotation>(0));
1181 void CDisplayChannelTest::CheckV11inV10()
1183 The purpose of this test is to verify that v1.0 of the display channel driver
1184 returns KErrNotSupported for methods that only exist in newer versions as opposed
1186 To run this test for real t_display needs to be built against v1.1 and then copied
1187 to a v1.0 environment.
1189 If the version number is > 1.0 then this method does nothing.
1192 if (iVersion.iMajor > 1 || iVersion.iMinor > 0)
1197 test.Next(_L("Test check v1.1 functions fail gracefully in v1.0"));
1199 // APIs should fail before evaluating parameters
1205 test.Printf(_L("Testing display change APIs\n"));
1206 iDisp.NotifyOnDisplayChangeCancel();
1207 TRequestStatus status;
1208 iDisp.NotifyOnDisplayChange(status);
1209 test(status == KErrNotSupported);
1211 err = iDisp.NumberOfResolutions();
1212 test(err == KErrNotSupported);
1214 err = iDisp.GetResolutions(buf, intDummy);
1215 test(err == KErrNotSupported);
1217 err = iDisp.GetResolution(size);
1218 test(err == KErrNotSupported);
1220 err = iDisp.GetTwips(size);
1221 test(err == KErrNotSupported);
1223 err = iDisp.NumberOfPixelFormats();
1224 test(err == KErrNotSupported);
1226 err = iDisp.GetPixelFormats(buf, intDummy);
1227 test(err == KErrNotSupported);
1229 RDisplayChannel::TBufferFormat bufferFormat(TSize(0,0),0);
1230 err = iDisp.GetBufferFormat(bufferFormat);
1231 test(err == KErrNotSupported);
1233 err = iDisp.SetBufferFormat(bufferFormat);
1234 test(err == KErrNotSupported);
1236 err = iDisp.NextPlaneOffset(bufferFormat, 0);
1237 test(err == KErrNotSupported);
1239 err = iDisp.NextLineOffset(bufferFormat, 0);
1240 test(err == KErrNotSupported);
1243 void CDisplayChannelTest::CheckSecondHandle()
1245 Opens a second RDisplayChannel.
1246 The driver may not support this but must not crash.
1249 test.Next(_L("Open a second handle"));
1250 RDisplayChannel disp2;
1251 TInt err = disp2.Open(iScreenId);
1252 test(err == KErrNone || err == KErrInUse);
1256 void CDisplayChannelTest::TestBufferTransitions()
1258 Because different buffer types (ie. composition, legacy and user) complete differently, we must test
1259 switching between those different types of buffers to ensure that this is taken into account.
1262 // The support code required for this test exists only in the separated GCE display LDD, not in the
1263 // legacy monolithic WINSCW LDD
1264 #if defined(_DEBUG) && !defined(__WINS__)
1265 test.Next(_L("Test transitions between buffer types"));
1267 TPckgBuf<RDisplayChannel::TDisplayInfo> displayInfo;
1268 test_KErrNone(iDisp.GetDisplayInfo(displayInfo));
1271 RDisplayChannel::TBufferFormat bufferFormat(TSize(iHalInfo.iXPixels, iHalInfo.iYPixels), displayInfo().iPixelFormat);
1273 test.Next(_L("Get the LDD to create a user buffer"));
1274 TInt err = iDisp.CreateUserBuffer(bufferFormat, chunk);
1277 test.Next(_L("Register a user buffer"));
1278 RDisplayChannel::TBufferId bufferId;
1279 err = iDisp.RegisterUserBuffer(bufferId, chunk, 0);
1282 test.Next(_L("Post a user buffer"));
1283 TRequestStatus status;
1284 RDisplayChannel::TPostCount postCount;
1285 iDisp.PostUserBuffer(bufferId, status, NULL, postCount);
1286 iDisp.PostLegacyBuffer(NULL, postCount);
1288 test.Printf(_L("Waiting for user buffer\n"));
1289 User::WaitForRequest(status);
1290 test(status.Int() == KErrNone || status.Int() == KErrCancel);
1291 test.Printf(_L("Waiting for legacy buffer\n"));
1292 iDisp.WaitForPost(postCount, status);
1293 User::WaitForRequest(status);
1294 test_KErrNone(status.Int());
1296 test.Printf(_L("Getting composition buffer\n"));
1298 iDisp.GetCompositionBuffer(bufferIndex, status);
1299 User::WaitForRequest(status);
1300 test_KErrNone(status.Int());
1302 iDisp.PostUserBuffer(bufferId, status, NULL, postCount);
1303 iDisp.PostCompositionBuffer(NULL, postCount);
1305 test.Printf(_L("Waiting for user buffer\n"));
1306 User::WaitForRequest(status);
1307 test(status.Int() == KErrNone || status.Int() == KErrCancel);
1308 test.Printf(_L("Waiting for composition buffer\n"));
1309 iDisp.WaitForPost(postCount, status);
1310 User::WaitForRequest(status);
1311 test_KErrNone(status.Int());
1313 test.Printf(_L("Deregistering user buffers\n"));
1314 err = iDisp.DeregisterUserBuffer(bufferId);
1317 test.Printf(_L("Done, closing shared chunk\n"));
1319 #endif // defined(_DEBUG) && !defined(__WINS__)
1322 void CDisplayChannelTest::Start()
1324 Run all of the test cases
1327 CompleteSelf(ETestDisplayInfo);
1330 void CDisplayChannelTest::CompleteSelf(TTestState aNextState)
1332 Advances to the next test state for test steps that don't invoke
1333 asynchronous requests on this AO.
1336 iState = aNextState;
1337 TRequestStatus* status = &iStatus;
1339 User::RequestComplete(status, KErrNone);
1342 void CDisplayChannelTest::DoCancel()
1344 iAsyncHelper->Cancel();
1347 TInt CDisplayChannelTest::RunError(TInt aError)
1349 test_KErrNone(aError);
1353 void CDisplayChannelTest::RunL()
1355 Run all of the tests where the API is defined for that version.
1358 test_KErrNone(iStatus.Int());
1360 test.Printf(_L("Test state %d\n"), iState);
1363 case ETestDisplayInfo:
1365 CompleteSelf(ETestCompositionBuffers);
1367 case ETestCompositionBuffers:
1368 CheckCompositionBuffers();
1369 CompleteSelf(ETestUserBuffers);
1371 case ETestUserBuffers:
1373 CompleteSelf(ETestRotations);
1375 case ETestRotations:
1377 CompleteSelf(ETestWaitForPostDoCancel);
1379 case ETestWaitForPostDoCancel:
1380 // Post the composition buffer, register wait and cancel wait.
1381 iDisp.PostCompositionBuffer(NULL, iDummyPostCount);
1382 iDisp.WaitForPost(iDummyPostCount, iAsyncHelper->Status());
1383 iAsyncHelper->WaitForOperation(&iAsyncHelperResult);
1384 iDisp.CancelWaitForPost();
1385 CompleteSelf(ETestWaitForPostCheckCancel);
1387 case ETestWaitForPostCheckCancel:
1388 test(iAsyncHelperResult == KErrCancel || iAsyncHelperResult == KErrNone);
1389 CompleteSelf(ETestGetCompositionBufferDoCancel);
1391 case ETestGetCompositionBufferDoCancel:
1392 iDisp.GetCompositionBuffer(iDummyCompositionBuffer, iAsyncHelper->Status());
1393 iAsyncHelper->WaitForOperation(&iAsyncHelperResult);
1394 iDisp.CancelGetCompositionBuffer();
1395 CompleteSelf(ETestGetCompositionBufferCheckCancel);
1397 case ETestGetCompositionBufferCheckCancel:
1398 test(iAsyncHelperResult == KErrCancel || iAsyncHelperResult == KErrNone);
1400 if (iVersion.iMajor == 1 && iVersion.iMinor == 0)
1402 CompleteSelf(ETestV11inV10);
1406 CompleteSelf(ETestDisplayChange);
1409 case ETestDisplayChange: // API in v1.1 +
1410 CheckDisplayChange();
1411 CompleteSelf(ETestDisplayChangeDoCancel);
1413 case ETestDisplayChangeDoCancel: // API in v1.1 +
1414 iDisp.NotifyOnDisplayChangeCancel();
1415 CompleteSelf(ETestDisplayChangeCheckCancel);
1417 case ETestDisplayChangeCheckCancel: // API in v1.1 +
1418 test(iAsyncHelperResult == KErrCancel); // display should not have changed
1419 CompleteSelf(ETestResolutions);
1421 case ETestResolutions: // API in v1.1 +
1423 CompleteSelf(ETestPixelFormats);
1425 case ETestPixelFormats: // API in v1.1 +
1426 CheckPixelFormats();
1427 CompleteSelf(ETestBufferFormats);
1429 case ETestBufferFormats: // API in v1.1 +
1430 CheckBufferFormat();
1431 CompleteSelf(EVisualTest);
1435 CompleteSelf(EVisualTest);
1438 VisualTest(); // visual test is async because of WaitForPost
1440 case ETestSecondHandle:
1441 CheckSecondHandle();
1442 CompleteSelf(ETestBufferTransitions);
1444 case ETestBufferTransitions:
1445 TestBufferTransitions();
1446 CompleteSelf(ETestFinished);
1449 CActiveScheduler::Stop();
1458 Initialise RTest and run the tests
1461 test.Start(_L("Testing display channel driver"));
1463 // If the device driver does not exist then this is considered a pass
1464 // because the display channel is not a mandatory part of the base port
1465 _LIT(KLdd, "display0.ldd");
1466 test.Printf(_L("Loading logical %S\n"), &KLdd);
1467 TInt err = User::LoadLogicalDevice(KLdd);
1468 test(err == KErrNone || err == KErrAlreadyExists || err == KErrNotFound);
1470 // Only test for kenel memory leaks for non WINSCW builds as the WINSCW LDD is obsolete and would
1471 // take forever to debug
1474 #endif // ! __WINS__
1476 if (err == KErrNone || err == KErrAlreadyExists)
1478 TInt numberOfScreens;
1479 User::LeaveIfError(HAL::Get(HAL::EDisplayNumberOfScreens, numberOfScreens));
1480 for (TInt screenNum = 0; screenNum < numberOfScreens; ++screenNum)
1482 CActiveScheduler* s = new(ELeave) CActiveScheduler();
1483 CActiveScheduler::Install(s);
1484 CleanupStack::PushL(s);
1485 CDisplayChannelTest* displayTest = CDisplayChannelTest::NewLC(screenNum);
1486 displayTest->Start();
1488 CleanupStack::PopAndDestroy(2, s); // s, displayTest
1493 test.Printf(_L("display0.ldd not present. Finishing test.\n"));
1498 #endif // ! __WINS__
1505 Create cleanup stack, initialise memory checks and run the tests.
1508 CTrapCleanup* cleanup = CTrapCleanup::New();
1511 return KErrNoMemory;
1515 TRAPD(err, MainL());