os/graphics/egl/egltest/endpointtestsuite/automated/tsrc/egltest_endpointtearing_remote.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *
    16 */
    17 
    18 
    19 /**
    20  @file
    21  @test
    22  @internalComponent - Internal Symbian test code
    23 */
    24 
    25 
    26 #include "egltest_endpointtearing.h"
    27 #include "egltest_endpoint_images.h"
    28 
    29 
    30 CEglTest_RemoteTestStep_EndpointTearing::CEglTest_RemoteTestStep_EndpointTearing() :
    31     CRemoteTestStepBase(ETestUidEndpointTearing)
    32     {
    33     }
    34 
    35 
    36 CEglTest_RemoteTestStep_EndpointTearing::~CEglTest_RemoteTestStep_EndpointTearing()
    37     {
    38     }
    39 
    40 
    41 TRemoteTestVerdict CEglTest_RemoteTestStep_EndpointTearing::DoStartRemoteTestStepL(const TRemoteTestParams& aMessageIn)
    42     {
    43     REMOTE_INFO_PRINTF1(_L("Starting Remote Test Step."));
    44     
    45     EglStartL();
    46     iDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
    47     
    48     TSurfaceId surface = aMessageIn.iEndpointTearing.iSurfaceId; 
    49     iEndpoint = EglEndpoint().CreateEndpoint(iDisplay, EGL_ENDPOINT_TYPE_CONSUMER_NOK, EGL_TSURFACEID_NOK, &surface, NULL);
    50     if(iEndpoint == EGL_NO_ENDPOINT_NOK)
    51         {
    52         REMOTE_ERR_PRINTF2(_L("Failed to create endpoint. err = %d"), eglGetError());
    53         User::Leave(KErrBadHandle);
    54         }
    55     REMOTE_INFO_PRINTF1(_L("Endpoint created."));
    56     
    57     return ERtvPass;
    58     }
    59 
    60 
    61 TRemoteTestVerdict CEglTest_RemoteTestStep_EndpointTearing::DoEndRemoteTestStepL(const TRemoteTestParams& /*aMessageIn*/)
    62     {
    63     REMOTE_INFO_PRINTF1(_L("Ending Remote Test Step."));
    64     EglEndpoint().DestroyEndpoint(iDisplay, iEndpoint);
    65     EglEndL();
    66     return ERtvPass;
    67     }
    68 
    69 
    70 TRemoteTestVerdict CEglTest_RemoteTestStep_EndpointTearing::DoRunRemoteTestCaseL(TInt aTestCase, const TRemoteTestParams& aParams)
    71     {
    72     switch(aTestCase)
    73         {
    74         case 0:     return TearingTestCaseL(aParams);
    75         default:    return ERtvAbort;
    76         }
    77     }
    78 
    79 
    80 TRemoteTestVerdict CEglTest_RemoteTestStep_EndpointTearing::TearingTestCaseL(const TRemoteTestParams& /*aParams*/)
    81     {
    82     //Begin streaming.
    83     EGLBoolean result = EglEndpoint().EndpointBeginStreaming(iDisplay, iEndpoint);
    84     if(result == EGL_FALSE)
    85         {
    86         REMOTE_ERR_PRINTF2(_L("Failed to enter streaming block. err = %d"), eglGetError());
    87         User::Leave(KErrBadHandle);
    88         }
    89     
    90     //Create an EglWindowSurface so we have a current context for vg operations.
    91     CEglWindowSurface* surface = CEglWindowSurface::NewL();
    92     CleanupStack::PushL(surface);
    93     surface->CreateL(EStandardSurface, TPoint(0, 0));
    94     surface->ActivateL();
    95     
    96     REMOTE_INFO_PRINTF1(_L("Repeatedly acquiring images and checking for evidence of tearing."));
    97     
    98     //The test should run for 7 seconds so we use a timer 
    99     //and loop while the request status is KRequestPending.
   100     TRequestStatus notifyTimeDone;
   101     RTimer timer;
   102     User::LeaveIfError(timer.CreateLocal());
   103     CleanupClosePushL(timer);
   104     timer.After(notifyTimeDone, 7 * 1000000);
   105     
   106     //Acquire and check that image is solid colour in a loop while the timer has not fired.
   107     TRemoteTestVerdict retVal = ERtvPass;
   108     TInt numIters = 0;
   109     while(notifyTimeDone.Int() == KRequestPending)
   110         {
   111         TRAPD(err, retVal = AcquireAndCheckImageL());
   112         if(err != KErrNone)
   113             {
   114             //Cancel the timer, wait for the notification and re-leave.
   115             timer.Cancel();
   116             User::WaitForRequest(notifyTimeDone);
   117             User::Leave(err);
   118             }
   119         if(retVal != ERtvPass)
   120             {
   121             REMOTE_ERR_PRINTF2(_L("Detected tearing in aquired image number %d"), numIters);
   122             timer.Cancel();
   123             break;
   124             }
   125         ++numIters;
   126         }
   127     
   128     //Tidy up the thread semaphore.
   129     User::WaitForRequest(notifyTimeDone);
   130     
   131     REMOTE_ERR_PRINTF2(_L("Number of successful iterations: %d"), numIters);
   132     
   133     CleanupStack::PopAndDestroy(2, surface);
   134     EglEndpoint().EndpointEndStreaming(iDisplay, iEndpoint);
   135     return retVal;
   136     }
   137 
   138 
   139 TRemoteTestVerdict CEglTest_RemoteTestStep_EndpointTearing::AcquireAndCheckImageL()
   140     {
   141     //Acquire an image from the endpoint.
   142     EGLImageKHR eglImage = EglEndpoint().AcquireImage(iDisplay, iEndpoint);
   143     if(eglImage == EGL_NO_IMAGE_KHR)
   144         {
   145         REMOTE_ERR_PRINTF2(_L("Failed to acquire image from endpoint. err = %d"), eglGetError());
   146         User::Leave(KErrBadHandle);
   147         }
   148     
   149     //Check the image. This bit can leave, so we trap it so we 
   150     //have an opportunity to release the image before re-leaving.
   151     TRemoteTestVerdict retVal = ERtvPass;
   152     TRAPD(err, retVal = CheckImageL(eglImage));
   153     
   154     //Release the image back to the endpoint.
   155     EGLBoolean err2 = EglEndpoint().ReleaseImage(iDisplay, iEndpoint, eglImage, EGL_OPENVG_API);
   156     
   157     //Report the 1st error.
   158     User::LeaveIfError(err);
   159     if(err2 == EGL_FALSE)
   160         {
   161         REMOTE_ERR_PRINTF2(_L("Failed to release image back to endpoint. err = %d"), eglGetError());
   162         User::Leave(KErrBadHandle);
   163         }
   164     
   165     return retVal;
   166     }
   167 
   168 
   169 TRemoteTestVerdict CEglTest_RemoteTestStep_EndpointTearing::CheckImageL(EGLImageKHR aEglImage)
   170     {
   171     //Convert the image to a CTestVgEglImage
   172     CTestVgEglImage* vgEglImage = CTestVgEglImage::NewL(aEglImage);
   173     CleanupStack::PushL(vgEglImage);
   174     
   175     //Check the corners and center pixel are the same colour. 
   176     TBool retVal = vgEglImage->IsSolidColourL();
   177     
   178     CleanupStack::PopAndDestroy(vgEglImage);
   179     return retVal ? ERtvPass : ERtvFail;
   180     }
   181