os/graphics/egl/egltest/endpointtestsuite/automated/tsrc/egltest_endpointtearing_remote.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/egl/egltest/endpointtestsuite/automated/tsrc/egltest_endpointtearing_remote.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,181 @@
     1.4 +/*
     1.5 +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +/**
    1.23 + @file
    1.24 + @test
    1.25 + @internalComponent - Internal Symbian test code
    1.26 +*/
    1.27 +
    1.28 +
    1.29 +#include "egltest_endpointtearing.h"
    1.30 +#include "egltest_endpoint_images.h"
    1.31 +
    1.32 +
    1.33 +CEglTest_RemoteTestStep_EndpointTearing::CEglTest_RemoteTestStep_EndpointTearing() :
    1.34 +    CRemoteTestStepBase(ETestUidEndpointTearing)
    1.35 +    {
    1.36 +    }
    1.37 +
    1.38 +
    1.39 +CEglTest_RemoteTestStep_EndpointTearing::~CEglTest_RemoteTestStep_EndpointTearing()
    1.40 +    {
    1.41 +    }
    1.42 +
    1.43 +
    1.44 +TRemoteTestVerdict CEglTest_RemoteTestStep_EndpointTearing::DoStartRemoteTestStepL(const TRemoteTestParams& aMessageIn)
    1.45 +    {
    1.46 +    REMOTE_INFO_PRINTF1(_L("Starting Remote Test Step."));
    1.47 +    
    1.48 +    EglStartL();
    1.49 +    iDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
    1.50 +    
    1.51 +    TSurfaceId surface = aMessageIn.iEndpointTearing.iSurfaceId; 
    1.52 +    iEndpoint = EglEndpoint().CreateEndpoint(iDisplay, EGL_ENDPOINT_TYPE_CONSUMER_NOK, EGL_TSURFACEID_NOK, &surface, NULL);
    1.53 +    if(iEndpoint == EGL_NO_ENDPOINT_NOK)
    1.54 +        {
    1.55 +        REMOTE_ERR_PRINTF2(_L("Failed to create endpoint. err = %d"), eglGetError());
    1.56 +        User::Leave(KErrBadHandle);
    1.57 +        }
    1.58 +    REMOTE_INFO_PRINTF1(_L("Endpoint created."));
    1.59 +    
    1.60 +    return ERtvPass;
    1.61 +    }
    1.62 +
    1.63 +
    1.64 +TRemoteTestVerdict CEglTest_RemoteTestStep_EndpointTearing::DoEndRemoteTestStepL(const TRemoteTestParams& /*aMessageIn*/)
    1.65 +    {
    1.66 +    REMOTE_INFO_PRINTF1(_L("Ending Remote Test Step."));
    1.67 +    EglEndpoint().DestroyEndpoint(iDisplay, iEndpoint);
    1.68 +    EglEndL();
    1.69 +    return ERtvPass;
    1.70 +    }
    1.71 +
    1.72 +
    1.73 +TRemoteTestVerdict CEglTest_RemoteTestStep_EndpointTearing::DoRunRemoteTestCaseL(TInt aTestCase, const TRemoteTestParams& aParams)
    1.74 +    {
    1.75 +    switch(aTestCase)
    1.76 +        {
    1.77 +        case 0:     return TearingTestCaseL(aParams);
    1.78 +        default:    return ERtvAbort;
    1.79 +        }
    1.80 +    }
    1.81 +
    1.82 +
    1.83 +TRemoteTestVerdict CEglTest_RemoteTestStep_EndpointTearing::TearingTestCaseL(const TRemoteTestParams& /*aParams*/)
    1.84 +    {
    1.85 +    //Begin streaming.
    1.86 +    EGLBoolean result = EglEndpoint().EndpointBeginStreaming(iDisplay, iEndpoint);
    1.87 +    if(result == EGL_FALSE)
    1.88 +        {
    1.89 +        REMOTE_ERR_PRINTF2(_L("Failed to enter streaming block. err = %d"), eglGetError());
    1.90 +        User::Leave(KErrBadHandle);
    1.91 +        }
    1.92 +    
    1.93 +    //Create an EglWindowSurface so we have a current context for vg operations.
    1.94 +    CEglWindowSurface* surface = CEglWindowSurface::NewL();
    1.95 +    CleanupStack::PushL(surface);
    1.96 +    surface->CreateL(EStandardSurface, TPoint(0, 0));
    1.97 +    surface->ActivateL();
    1.98 +    
    1.99 +    REMOTE_INFO_PRINTF1(_L("Repeatedly acquiring images and checking for evidence of tearing."));
   1.100 +    
   1.101 +    //The test should run for 7 seconds so we use a timer 
   1.102 +    //and loop while the request status is KRequestPending.
   1.103 +    TRequestStatus notifyTimeDone;
   1.104 +    RTimer timer;
   1.105 +    User::LeaveIfError(timer.CreateLocal());
   1.106 +    CleanupClosePushL(timer);
   1.107 +    timer.After(notifyTimeDone, 7 * 1000000);
   1.108 +    
   1.109 +    //Acquire and check that image is solid colour in a loop while the timer has not fired.
   1.110 +    TRemoteTestVerdict retVal = ERtvPass;
   1.111 +    TInt numIters = 0;
   1.112 +    while(notifyTimeDone.Int() == KRequestPending)
   1.113 +        {
   1.114 +        TRAPD(err, retVal = AcquireAndCheckImageL());
   1.115 +        if(err != KErrNone)
   1.116 +            {
   1.117 +            //Cancel the timer, wait for the notification and re-leave.
   1.118 +            timer.Cancel();
   1.119 +            User::WaitForRequest(notifyTimeDone);
   1.120 +            User::Leave(err);
   1.121 +            }
   1.122 +        if(retVal != ERtvPass)
   1.123 +            {
   1.124 +            REMOTE_ERR_PRINTF2(_L("Detected tearing in aquired image number %d"), numIters);
   1.125 +            timer.Cancel();
   1.126 +            break;
   1.127 +            }
   1.128 +        ++numIters;
   1.129 +        }
   1.130 +    
   1.131 +    //Tidy up the thread semaphore.
   1.132 +    User::WaitForRequest(notifyTimeDone);
   1.133 +    
   1.134 +    REMOTE_ERR_PRINTF2(_L("Number of successful iterations: %d"), numIters);
   1.135 +    
   1.136 +    CleanupStack::PopAndDestroy(2, surface);
   1.137 +    EglEndpoint().EndpointEndStreaming(iDisplay, iEndpoint);
   1.138 +    return retVal;
   1.139 +    }
   1.140 +
   1.141 +
   1.142 +TRemoteTestVerdict CEglTest_RemoteTestStep_EndpointTearing::AcquireAndCheckImageL()
   1.143 +    {
   1.144 +    //Acquire an image from the endpoint.
   1.145 +    EGLImageKHR eglImage = EglEndpoint().AcquireImage(iDisplay, iEndpoint);
   1.146 +    if(eglImage == EGL_NO_IMAGE_KHR)
   1.147 +        {
   1.148 +        REMOTE_ERR_PRINTF2(_L("Failed to acquire image from endpoint. err = %d"), eglGetError());
   1.149 +        User::Leave(KErrBadHandle);
   1.150 +        }
   1.151 +    
   1.152 +    //Check the image. This bit can leave, so we trap it so we 
   1.153 +    //have an opportunity to release the image before re-leaving.
   1.154 +    TRemoteTestVerdict retVal = ERtvPass;
   1.155 +    TRAPD(err, retVal = CheckImageL(eglImage));
   1.156 +    
   1.157 +    //Release the image back to the endpoint.
   1.158 +    EGLBoolean err2 = EglEndpoint().ReleaseImage(iDisplay, iEndpoint, eglImage, EGL_OPENVG_API);
   1.159 +    
   1.160 +    //Report the 1st error.
   1.161 +    User::LeaveIfError(err);
   1.162 +    if(err2 == EGL_FALSE)
   1.163 +        {
   1.164 +        REMOTE_ERR_PRINTF2(_L("Failed to release image back to endpoint. err = %d"), eglGetError());
   1.165 +        User::Leave(KErrBadHandle);
   1.166 +        }
   1.167 +    
   1.168 +    return retVal;
   1.169 +    }
   1.170 +
   1.171 +
   1.172 +TRemoteTestVerdict CEglTest_RemoteTestStep_EndpointTearing::CheckImageL(EGLImageKHR aEglImage)
   1.173 +    {
   1.174 +    //Convert the image to a CTestVgEglImage
   1.175 +    CTestVgEglImage* vgEglImage = CTestVgEglImage::NewL(aEglImage);
   1.176 +    CleanupStack::PushL(vgEglImage);
   1.177 +    
   1.178 +    //Check the corners and center pixel are the same colour. 
   1.179 +    TBool retVal = vgEglImage->IsSolidColourL();
   1.180 +    
   1.181 +    CleanupStack::PopAndDestroy(vgEglImage);
   1.182 +    return retVal ? ERtvPass : ERtvFail;
   1.183 +    }
   1.184 +