sl@0: /* sl@0: * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @test sl@0: @internalComponent - Internal Symbian test code sl@0: */ sl@0: sl@0: sl@0: #include "egltest_endpointtearing.h" sl@0: #include "egltest_endpoint_images.h" sl@0: sl@0: sl@0: CEglTest_RemoteTestStep_EndpointTearing::CEglTest_RemoteTestStep_EndpointTearing() : sl@0: CRemoteTestStepBase(ETestUidEndpointTearing) sl@0: { sl@0: } sl@0: sl@0: sl@0: CEglTest_RemoteTestStep_EndpointTearing::~CEglTest_RemoteTestStep_EndpointTearing() sl@0: { sl@0: } sl@0: sl@0: sl@0: TRemoteTestVerdict CEglTest_RemoteTestStep_EndpointTearing::DoStartRemoteTestStepL(const TRemoteTestParams& aMessageIn) sl@0: { sl@0: REMOTE_INFO_PRINTF1(_L("Starting Remote Test Step.")); sl@0: sl@0: EglStartL(); sl@0: iDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); sl@0: sl@0: TSurfaceId surface = aMessageIn.iEndpointTearing.iSurfaceId; sl@0: iEndpoint = EglEndpoint().CreateEndpoint(iDisplay, EGL_ENDPOINT_TYPE_CONSUMER_NOK, EGL_TSURFACEID_NOK, &surface, NULL); sl@0: if(iEndpoint == EGL_NO_ENDPOINT_NOK) sl@0: { sl@0: REMOTE_ERR_PRINTF2(_L("Failed to create endpoint. err = %d"), eglGetError()); sl@0: User::Leave(KErrBadHandle); sl@0: } sl@0: REMOTE_INFO_PRINTF1(_L("Endpoint created.")); sl@0: sl@0: return ERtvPass; sl@0: } sl@0: sl@0: sl@0: TRemoteTestVerdict CEglTest_RemoteTestStep_EndpointTearing::DoEndRemoteTestStepL(const TRemoteTestParams& /*aMessageIn*/) sl@0: { sl@0: REMOTE_INFO_PRINTF1(_L("Ending Remote Test Step.")); sl@0: EglEndpoint().DestroyEndpoint(iDisplay, iEndpoint); sl@0: EglEndL(); sl@0: return ERtvPass; sl@0: } sl@0: sl@0: sl@0: TRemoteTestVerdict CEglTest_RemoteTestStep_EndpointTearing::DoRunRemoteTestCaseL(TInt aTestCase, const TRemoteTestParams& aParams) sl@0: { sl@0: switch(aTestCase) sl@0: { sl@0: case 0: return TearingTestCaseL(aParams); sl@0: default: return ERtvAbort; sl@0: } sl@0: } sl@0: sl@0: sl@0: TRemoteTestVerdict CEglTest_RemoteTestStep_EndpointTearing::TearingTestCaseL(const TRemoteTestParams& /*aParams*/) sl@0: { sl@0: //Begin streaming. sl@0: EGLBoolean result = EglEndpoint().EndpointBeginStreaming(iDisplay, iEndpoint); sl@0: if(result == EGL_FALSE) sl@0: { sl@0: REMOTE_ERR_PRINTF2(_L("Failed to enter streaming block. err = %d"), eglGetError()); sl@0: User::Leave(KErrBadHandle); sl@0: } sl@0: sl@0: //Create an EglWindowSurface so we have a current context for vg operations. sl@0: CEglWindowSurface* surface = CEglWindowSurface::NewL(); sl@0: CleanupStack::PushL(surface); sl@0: surface->CreateL(EStandardSurface, TPoint(0, 0)); sl@0: surface->ActivateL(); sl@0: sl@0: REMOTE_INFO_PRINTF1(_L("Repeatedly acquiring images and checking for evidence of tearing.")); sl@0: sl@0: //The test should run for 7 seconds so we use a timer sl@0: //and loop while the request status is KRequestPending. sl@0: TRequestStatus notifyTimeDone; sl@0: RTimer timer; sl@0: User::LeaveIfError(timer.CreateLocal()); sl@0: CleanupClosePushL(timer); sl@0: timer.After(notifyTimeDone, 7 * 1000000); sl@0: sl@0: //Acquire and check that image is solid colour in a loop while the timer has not fired. sl@0: TRemoteTestVerdict retVal = ERtvPass; sl@0: TInt numIters = 0; sl@0: while(notifyTimeDone.Int() == KRequestPending) sl@0: { sl@0: TRAPD(err, retVal = AcquireAndCheckImageL()); sl@0: if(err != KErrNone) sl@0: { sl@0: //Cancel the timer, wait for the notification and re-leave. sl@0: timer.Cancel(); sl@0: User::WaitForRequest(notifyTimeDone); sl@0: User::Leave(err); sl@0: } sl@0: if(retVal != ERtvPass) sl@0: { sl@0: REMOTE_ERR_PRINTF2(_L("Detected tearing in aquired image number %d"), numIters); sl@0: timer.Cancel(); sl@0: break; sl@0: } sl@0: ++numIters; sl@0: } sl@0: sl@0: //Tidy up the thread semaphore. sl@0: User::WaitForRequest(notifyTimeDone); sl@0: sl@0: REMOTE_ERR_PRINTF2(_L("Number of successful iterations: %d"), numIters); sl@0: sl@0: CleanupStack::PopAndDestroy(2, surface); sl@0: EglEndpoint().EndpointEndStreaming(iDisplay, iEndpoint); sl@0: return retVal; sl@0: } sl@0: sl@0: sl@0: TRemoteTestVerdict CEglTest_RemoteTestStep_EndpointTearing::AcquireAndCheckImageL() sl@0: { sl@0: //Acquire an image from the endpoint. sl@0: EGLImageKHR eglImage = EglEndpoint().AcquireImage(iDisplay, iEndpoint); sl@0: if(eglImage == EGL_NO_IMAGE_KHR) sl@0: { sl@0: REMOTE_ERR_PRINTF2(_L("Failed to acquire image from endpoint. err = %d"), eglGetError()); sl@0: User::Leave(KErrBadHandle); sl@0: } sl@0: sl@0: //Check the image. This bit can leave, so we trap it so we sl@0: //have an opportunity to release the image before re-leaving. sl@0: TRemoteTestVerdict retVal = ERtvPass; sl@0: TRAPD(err, retVal = CheckImageL(eglImage)); sl@0: sl@0: //Release the image back to the endpoint. sl@0: EGLBoolean err2 = EglEndpoint().ReleaseImage(iDisplay, iEndpoint, eglImage, EGL_OPENVG_API); sl@0: sl@0: //Report the 1st error. sl@0: User::LeaveIfError(err); sl@0: if(err2 == EGL_FALSE) sl@0: { sl@0: REMOTE_ERR_PRINTF2(_L("Failed to release image back to endpoint. err = %d"), eglGetError()); sl@0: User::Leave(KErrBadHandle); sl@0: } sl@0: sl@0: return retVal; sl@0: } sl@0: sl@0: sl@0: TRemoteTestVerdict CEglTest_RemoteTestStep_EndpointTearing::CheckImageL(EGLImageKHR aEglImage) sl@0: { sl@0: //Convert the image to a CTestVgEglImage sl@0: CTestVgEglImage* vgEglImage = CTestVgEglImage::NewL(aEglImage); sl@0: CleanupStack::PushL(vgEglImage); sl@0: sl@0: //Check the corners and center pixel are the same colour. sl@0: TBool retVal = vgEglImage->IsSolidColourL(); sl@0: sl@0: CleanupStack::PopAndDestroy(vgEglImage); sl@0: return retVal ? ERtvPass : ERtvFail; sl@0: } sl@0: