os/graphics/egl/egltest/endpointtestsuite/automated/tsrc/egltest_releaseimagegles_remote.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/egl/egltest/endpointtestsuite/automated/tsrc/egltest_releaseimagegles_remote.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,184 @@
1.4 +#include "egltest_releaseimagegles.h"
1.5 +#include "eglendpointwrap.h"
1.6 +#include "egltest_surface.h"
1.7 +
1.8 +
1.9 +//Remote test step----------------------------------------------------------------
1.10 +
1.11 +CEglTest_RemoteTestStep_EndpointReleaseImageGles::CEglTest_RemoteTestStep_EndpointReleaseImageGles() :
1.12 + CRemoteTestStepBase(ETestUidEndpointReleaseImageGles)
1.13 + {
1.14 + }
1.15 +
1.16 +
1.17 +CEglTest_RemoteTestStep_EndpointReleaseImageGles::~CEglTest_RemoteTestStep_EndpointReleaseImageGles()
1.18 + {
1.19 + }
1.20 +
1.21 +
1.22 +TRemoteTestVerdict CEglTest_RemoteTestStep_EndpointReleaseImageGles::DoStartRemoteTestStepL(const TRemoteTestParams& /*aMessageIn*/)
1.23 + {
1.24 + REMOTE_INFO_PRINTF1(_L("Starting Remote Test Step."));
1.25 + EglStartL();
1.26 +
1.27 + iDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
1.28 +
1.29 + //Create a raw surface that will be encapsulated by the endpoint.
1.30 + iSurface = CRawSurface::NewL();
1.31 + iSurface->CreateL(EStandardSurface, TPoint(0, 0));
1.32 +
1.33 + TSurfaceId id = iSurface->SurfaceId();
1.34 + iEndpoint = EglEndpoint().CreateEndpoint(iDisplay, EGL_ENDPOINT_TYPE_CONSUMER_NOK, EGL_TSURFACEID_NOK, &id, NULL);
1.35 + if(iEndpoint == EGL_NO_ENDPOINT_NOK)
1.36 + {
1.37 + REMOTE_ERR_PRINTF1(_L("Failed to create endpoint."));
1.38 + User::Leave(KErrUnknown);
1.39 + }
1.40 +
1.41 + iSurface->DrawContentL(TRgb(128,128,128));
1.42 + User::LeaveIfError(iSurface->SubmitContent(EFalse));
1.43 + EGLBoolean ret = EglEndpoint().EndpointBeginStreaming(iDisplay, iEndpoint);
1.44 + if(!ret)
1.45 + {
1.46 + REMOTE_ERR_PRINTF1(_L("Failed to begin streaming from endpoint."));
1.47 + User::Leave(KErrUnknown);
1.48 + }
1.49 +
1.50 + return ERtvPass;
1.51 + }
1.52 +
1.53 +
1.54 +TRemoteTestVerdict CEglTest_RemoteTestStep_EndpointReleaseImageGles::DoEndRemoteTestStepL(const TRemoteTestParams& /*aMessageIn*/)
1.55 + {
1.56 + REMOTE_INFO_PRINTF1(_L("Ending Remote Test Step."));
1.57 + if(iEndpoint != EGL_NO_ENDPOINT_NOK)
1.58 + {
1.59 + EglEndpoint().EndpointEndStreaming(iDisplay, iEndpoint);
1.60 + EglEndpoint().DestroyEndpoint(iDisplay, iEndpoint);
1.61 + }
1.62 + delete iSurface;
1.63 + EglEndL();
1.64 + return ERtvPass;
1.65 + }
1.66 +
1.67 +
1.68 +TRemoteTestVerdict CEglTest_RemoteTestStep_EndpointReleaseImageGles::DoRunRemoteTestCaseL(TInt aTestCase, const TRemoteTestParams& aParams)
1.69 + {
1.70 + switch(aTestCase)
1.71 + {
1.72 + case 0: return GlesContextTestCaseL(aParams);
1.73 + default: return ERtvAbort;
1.74 + }
1.75 + }
1.76 +
1.77 +
1.78 +TRemoteTestVerdict CEglTest_RemoteTestStep_EndpointReleaseImageGles::GlesContextTestCaseL(const TRemoteTestParams& aParams)
1.79 + {
1.80 + //This test case acquires an image from an endpoint then attempts to
1.81 + //release the image, passing in EGL_OPENGL_ES_API as the API flag.
1.82 + //There are two configurations for the test, that is controlled by
1.83 + //a flag in aParams. The options are to have a valid GLES context
1.84 + //set current, or to have nothing current.
1.85 +
1.86 + EGLContext glesContext = EGL_NO_CONTEXT;
1.87 + EGLSurface glesSurface = EGL_NO_SURFACE;
1.88 +
1.89 + //Create GLES state and set it current if the test requires it.
1.90 + if(aParams.iEndpointReleaseImageGles.iUseValidGlesContext)
1.91 + {
1.92 + EGLConfig config;
1.93 + EGLint nConfigs = 0;
1.94 +
1.95 + static const EGLint KConfigAttribs[] =
1.96 + {
1.97 + EGL_BUFFER_SIZE, 32,
1.98 + EGL_RED_SIZE, 8,
1.99 + EGL_GREEN_SIZE, 8,
1.100 + EGL_BLUE_SIZE, 8,
1.101 + EGL_ALPHA_SIZE, 8,
1.102 + EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
1.103 + EGL_RENDERABLE_TYPE,EGL_OPENGL_ES_BIT,
1.104 + EGL_NONE
1.105 + };
1.106 +
1.107 + eglChooseConfig(iDisplay, KConfigAttribs, &config, 1, &nConfigs);
1.108 + if (!nConfigs)
1.109 + {
1.110 + RDebug::Printf("%s:%d: err = %d", __FILE__, __LINE__, eglGetError());
1.111 + User::Leave(KErrNotSupported);
1.112 + }
1.113 +
1.114 + if (!eglBindAPI(EGL_OPENGL_ES_API))
1.115 + {
1.116 + RDebug::Printf("%s:%d: err = %d", __FILE__, __LINE__, eglGetError());
1.117 + User::Leave(KErrNotSupported);
1.118 + }
1.119 +
1.120 + glesContext = eglCreateContext(iDisplay, config, 0, NULL);
1.121 + if (glesContext == EGL_NO_CONTEXT)
1.122 + {
1.123 + RDebug::Printf("%s:%d: err = %d", __FILE__, __LINE__, eglGetError());
1.124 + User::Leave(KErrNotSupported);
1.125 + }
1.126 +
1.127 + static const EGLint KPbufferAttribs[] =
1.128 + {
1.129 + EGL_WIDTH, 100,
1.130 + EGL_HEIGHT, 100,
1.131 + EGL_NONE,
1.132 + };
1.133 +
1.134 + glesSurface = eglCreatePbufferSurface(iDisplay, config, KPbufferAttribs);
1.135 + if (glesSurface == EGL_NO_SURFACE)
1.136 + {
1.137 + RDebug::Printf("%s:%d: err = %x", __FILE__, __LINE__, eglGetError());
1.138 + User::Leave(KErrNotSupported);
1.139 + }
1.140 +
1.141 + eglMakeCurrent(iDisplay, glesSurface, glesSurface, glesContext);
1.142 + }
1.143 +
1.144 + //Run the test case ansd trap to give us an opportunity to destroy the GLES state if it exists.
1.145 + TRemoteTestVerdict verdict = ERtvPass;
1.146 + TRAPD(err, verdict = DoGlesContextTestCaseL(aParams));
1.147 +
1.148 + //Destroy the GLES state if it exists.
1.149 + if(aParams.iEndpointReleaseImageGles.iUseValidGlesContext)
1.150 + {
1.151 + eglMakeCurrent(iDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
1.152 + eglDestroySurface(iDisplay, glesSurface);
1.153 + eglDestroyContext(iDisplay, glesContext);
1.154 + }
1.155 +
1.156 + //Releave if the test left or return the verdict.
1.157 + User::LeaveIfError(err);
1.158 + return verdict;
1.159 + }
1.160 +
1.161 +
1.162 +TRemoteTestVerdict CEglTest_RemoteTestStep_EndpointReleaseImageGles::DoGlesContextTestCaseL(const TRemoteTestParams& /*aParams*/)
1.163 + {
1.164 + //Draw to the surface and submit the update.
1.165 + iSurface->DrawContentL(TRgb(128,128,128));
1.166 + User::LeaveIfError(iSurface->SubmitContent(ETrue));
1.167 +
1.168 + //Acquire an image and check that it was successful.
1.169 + EGLImageKHR image = EglEndpoint().AcquireImage(iDisplay, iEndpoint);
1.170 + if(image == EGL_NO_IMAGE_KHR)
1.171 + {
1.172 + REMOTE_ERR_PRINTF2(_L("Failed to acquire image from endpoint with error = %d"), eglGetError());
1.173 + return ERtvFail;
1.174 + }
1.175 +
1.176 + //Attempt to release the image. This must always succeed regardless of whether there is a valid GLES context.
1.177 + EGLBoolean ret = EglEndpoint().ReleaseImage(iDisplay, iEndpoint, image, EGL_OPENGL_ES_API);
1.178 + if(!ret)
1.179 + {
1.180 + REMOTE_ERR_PRINTF2(_L("Failed to release image from endpoint with error = %d"), eglGetError());
1.181 + return ERtvFail;
1.182 + }
1.183 +
1.184 + return ERtvPass;
1.185 + }
1.186 +
1.187 +//--------------------------------------------------------------------------------