os/graphics/egl/egltest/endpointtestsuite/automated/tsrc/egltest_releaseimagegles_remote.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
#include "egltest_releaseimagegles.h"
sl@0
     2
#include "eglendpointwrap.h"
sl@0
     3
#include "egltest_surface.h"
sl@0
     4
sl@0
     5
sl@0
     6
//Remote test step----------------------------------------------------------------
sl@0
     7
sl@0
     8
CEglTest_RemoteTestStep_EndpointReleaseImageGles::CEglTest_RemoteTestStep_EndpointReleaseImageGles() :
sl@0
     9
    CRemoteTestStepBase(ETestUidEndpointReleaseImageGles)
sl@0
    10
    {
sl@0
    11
    }
sl@0
    12
sl@0
    13
sl@0
    14
CEglTest_RemoteTestStep_EndpointReleaseImageGles::~CEglTest_RemoteTestStep_EndpointReleaseImageGles()
sl@0
    15
    {
sl@0
    16
    }
sl@0
    17
sl@0
    18
sl@0
    19
TRemoteTestVerdict CEglTest_RemoteTestStep_EndpointReleaseImageGles::DoStartRemoteTestStepL(const TRemoteTestParams& /*aMessageIn*/)
sl@0
    20
    {
sl@0
    21
    REMOTE_INFO_PRINTF1(_L("Starting Remote Test Step."));
sl@0
    22
    EglStartL();
sl@0
    23
    
sl@0
    24
    iDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
sl@0
    25
    
sl@0
    26
    //Create a raw surface that will be encapsulated by the endpoint.
sl@0
    27
    iSurface = CRawSurface::NewL();
sl@0
    28
    iSurface->CreateL(EStandardSurface, TPoint(0, 0));
sl@0
    29
sl@0
    30
    TSurfaceId id = iSurface->SurfaceId();
sl@0
    31
    iEndpoint = EglEndpoint().CreateEndpoint(iDisplay, EGL_ENDPOINT_TYPE_CONSUMER_NOK, EGL_TSURFACEID_NOK, &id, NULL);
sl@0
    32
    if(iEndpoint == EGL_NO_ENDPOINT_NOK)
sl@0
    33
        {
sl@0
    34
        REMOTE_ERR_PRINTF1(_L("Failed to create endpoint."));
sl@0
    35
        User::Leave(KErrUnknown);
sl@0
    36
        }
sl@0
    37
    
sl@0
    38
    iSurface->DrawContentL(TRgb(128,128,128));
sl@0
    39
    User::LeaveIfError(iSurface->SubmitContent(EFalse));
sl@0
    40
    EGLBoolean ret = EglEndpoint().EndpointBeginStreaming(iDisplay, iEndpoint);
sl@0
    41
    if(!ret)
sl@0
    42
        {
sl@0
    43
        REMOTE_ERR_PRINTF1(_L("Failed to begin streaming from endpoint."));
sl@0
    44
        User::Leave(KErrUnknown);
sl@0
    45
        }
sl@0
    46
    
sl@0
    47
    return ERtvPass;
sl@0
    48
    }
sl@0
    49
sl@0
    50
sl@0
    51
TRemoteTestVerdict CEglTest_RemoteTestStep_EndpointReleaseImageGles::DoEndRemoteTestStepL(const TRemoteTestParams& /*aMessageIn*/)
sl@0
    52
    {
sl@0
    53
    REMOTE_INFO_PRINTF1(_L("Ending Remote Test Step."));
sl@0
    54
    if(iEndpoint != EGL_NO_ENDPOINT_NOK)
sl@0
    55
        {
sl@0
    56
        EglEndpoint().EndpointEndStreaming(iDisplay, iEndpoint);
sl@0
    57
        EglEndpoint().DestroyEndpoint(iDisplay, iEndpoint);
sl@0
    58
        }
sl@0
    59
    delete iSurface;
sl@0
    60
    EglEndL();
sl@0
    61
    return ERtvPass;
sl@0
    62
    }
sl@0
    63
sl@0
    64
sl@0
    65
TRemoteTestVerdict CEglTest_RemoteTestStep_EndpointReleaseImageGles::DoRunRemoteTestCaseL(TInt aTestCase, const TRemoteTestParams& aParams)
sl@0
    66
    {
sl@0
    67
    switch(aTestCase)
sl@0
    68
        {
sl@0
    69
        case 0:     return GlesContextTestCaseL(aParams);
sl@0
    70
        default:    return ERtvAbort;
sl@0
    71
        }
sl@0
    72
    }
sl@0
    73
sl@0
    74
sl@0
    75
TRemoteTestVerdict CEglTest_RemoteTestStep_EndpointReleaseImageGles::GlesContextTestCaseL(const TRemoteTestParams& aParams)
sl@0
    76
    {
sl@0
    77
    //This test case acquires an image from an endpoint then attempts to 
sl@0
    78
    //release the image, passing in EGL_OPENGL_ES_API as the API flag.
sl@0
    79
    //There are two configurations for the test, that is controlled by
sl@0
    80
    //a flag in aParams. The options are to have a valid GLES context 
sl@0
    81
    //set current, or to have nothing current.
sl@0
    82
    
sl@0
    83
    EGLContext glesContext = EGL_NO_CONTEXT;
sl@0
    84
    EGLSurface glesSurface = EGL_NO_SURFACE;
sl@0
    85
    
sl@0
    86
    //Create GLES state and set it current if the test requires it.
sl@0
    87
    if(aParams.iEndpointReleaseImageGles.iUseValidGlesContext)
sl@0
    88
        {
sl@0
    89
        EGLConfig config;
sl@0
    90
        EGLint nConfigs = 0;
sl@0
    91
        
sl@0
    92
        static const EGLint KConfigAttribs[] =
sl@0
    93
        {
sl@0
    94
            EGL_BUFFER_SIZE,    32,
sl@0
    95
            EGL_RED_SIZE,       8,
sl@0
    96
            EGL_GREEN_SIZE,     8,
sl@0
    97
            EGL_BLUE_SIZE,      8,
sl@0
    98
            EGL_ALPHA_SIZE,     8,
sl@0
    99
            EGL_SURFACE_TYPE,   EGL_PBUFFER_BIT,
sl@0
   100
            EGL_RENDERABLE_TYPE,EGL_OPENGL_ES_BIT,
sl@0
   101
            EGL_NONE
sl@0
   102
        };
sl@0
   103
sl@0
   104
        eglChooseConfig(iDisplay, KConfigAttribs, &config, 1, &nConfigs);
sl@0
   105
        if (!nConfigs)
sl@0
   106
            {
sl@0
   107
            RDebug::Printf("%s:%d: err = %d", __FILE__, __LINE__, eglGetError());
sl@0
   108
            User::Leave(KErrNotSupported);
sl@0
   109
            }
sl@0
   110
    
sl@0
   111
        if (!eglBindAPI(EGL_OPENGL_ES_API))
sl@0
   112
            {
sl@0
   113
            RDebug::Printf("%s:%d: err = %d", __FILE__, __LINE__, eglGetError());
sl@0
   114
            User::Leave(KErrNotSupported);
sl@0
   115
            }
sl@0
   116
        
sl@0
   117
        glesContext = eglCreateContext(iDisplay, config, 0, NULL);
sl@0
   118
        if (glesContext == EGL_NO_CONTEXT)
sl@0
   119
            {
sl@0
   120
            RDebug::Printf("%s:%d: err = %d", __FILE__, __LINE__, eglGetError());
sl@0
   121
            User::Leave(KErrNotSupported);
sl@0
   122
            }
sl@0
   123
        
sl@0
   124
        static const EGLint KPbufferAttribs[] =
sl@0
   125
            {
sl@0
   126
            EGL_WIDTH, 100,
sl@0
   127
            EGL_HEIGHT, 100,
sl@0
   128
            EGL_NONE,
sl@0
   129
            };
sl@0
   130
        
sl@0
   131
        glesSurface = eglCreatePbufferSurface(iDisplay, config, KPbufferAttribs);
sl@0
   132
        if (glesSurface == EGL_NO_SURFACE)
sl@0
   133
            {
sl@0
   134
            RDebug::Printf("%s:%d: err = %x", __FILE__, __LINE__, eglGetError());
sl@0
   135
            User::Leave(KErrNotSupported);
sl@0
   136
            }
sl@0
   137
        
sl@0
   138
        eglMakeCurrent(iDisplay, glesSurface, glesSurface, glesContext);
sl@0
   139
        }
sl@0
   140
    
sl@0
   141
    //Run the test case ansd trap to give us an opportunity to destroy the GLES state if it exists.
sl@0
   142
    TRemoteTestVerdict verdict = ERtvPass;
sl@0
   143
    TRAPD(err, verdict = DoGlesContextTestCaseL(aParams));
sl@0
   144
    
sl@0
   145
    //Destroy the GLES state if it exists.
sl@0
   146
    if(aParams.iEndpointReleaseImageGles.iUseValidGlesContext)
sl@0
   147
        {
sl@0
   148
        eglMakeCurrent(iDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
sl@0
   149
        eglDestroySurface(iDisplay, glesSurface);
sl@0
   150
        eglDestroyContext(iDisplay, glesContext);
sl@0
   151
        }
sl@0
   152
    
sl@0
   153
    //Releave if the test left or return the verdict.
sl@0
   154
    User::LeaveIfError(err);
sl@0
   155
    return verdict;
sl@0
   156
    }
sl@0
   157
sl@0
   158
sl@0
   159
TRemoteTestVerdict CEglTest_RemoteTestStep_EndpointReleaseImageGles::DoGlesContextTestCaseL(const TRemoteTestParams& /*aParams*/)
sl@0
   160
    {
sl@0
   161
    //Draw to the surface and submit the update.
sl@0
   162
    iSurface->DrawContentL(TRgb(128,128,128));
sl@0
   163
    User::LeaveIfError(iSurface->SubmitContent(ETrue));
sl@0
   164
    
sl@0
   165
    //Acquire an image and check that it was successful.
sl@0
   166
    EGLImageKHR image = EglEndpoint().AcquireImage(iDisplay, iEndpoint);
sl@0
   167
    if(image == EGL_NO_IMAGE_KHR)
sl@0
   168
        {
sl@0
   169
        REMOTE_ERR_PRINTF2(_L("Failed to acquire image from endpoint with error = %d"), eglGetError());
sl@0
   170
        return ERtvFail;
sl@0
   171
        }
sl@0
   172
    
sl@0
   173
    //Attempt to release the image. This must always succeed regardless of whether there is a valid GLES context.
sl@0
   174
    EGLBoolean ret = EglEndpoint().ReleaseImage(iDisplay, iEndpoint, image, EGL_OPENGL_ES_API);
sl@0
   175
    if(!ret)
sl@0
   176
        {
sl@0
   177
        REMOTE_ERR_PRINTF2(_L("Failed to release image from endpoint with error = %d"), eglGetError());
sl@0
   178
        return ERtvFail;
sl@0
   179
        }
sl@0
   180
    
sl@0
   181
    return ERtvPass;
sl@0
   182
    }
sl@0
   183
sl@0
   184
//--------------------------------------------------------------------------------