sl@0: // Copyright (c) 2007-2010 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: @file sl@0: @test sl@0: */ sl@0: sl@0: #include "egltestcommonsession.h" sl@0: #include "egltestcommonutils.h" sl@0: #include "egltestcommonsgimageinfo.h" sl@0: sl@0: #include sl@0: #include sl@0: #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE sl@0: #include sl@0: #else sl@0: #include sl@0: #include sl@0: #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE sl@0: #include sl@0: #include sl@0: sl@0: sl@0: #define CHECK_EXPECTED_ERROR(aFunctionReturnValue) \ sl@0: if(!(CheckExpectedError(aFunctionReturnValue))) \ sl@0: { \ sl@0: ERR_PRINTF2(_L("thread %d: Unexpected EGL error information"), iThreadIdx); \ sl@0: User::Leave(KErrTEFUnitFail); \ sl@0: } sl@0: sl@0: const TMapEglConfigToPixelFormat KMapEglConfigToPixelFormat[] = sl@0: { sl@0: {16, 0, 5,6,5, 0, EGL_RGB_BUFFER, EUidPixelFormatRGB_565, EColor64K}, sl@0: {32, 0, 8,8,8, 0, EGL_RGB_BUFFER, EUidPixelFormatXRGB_8888, EColor16MU}, sl@0: {32, 8, 8,8,8, EGL_VG_ALPHA_FORMAT_NONPRE, EGL_RGB_BUFFER, EUidPixelFormatARGB_8888, EColor16MA}, sl@0: {32, 8, 8,8,8, EGL_VG_ALPHA_FORMAT_PRE, EGL_RGB_BUFFER, EUidPixelFormatARGB_8888_PRE, EColor16MAP} sl@0: }; sl@0: sl@0: EXPORT_C CTestEglSession::CTestEglSession(CTestExecuteLogger& aLogger, EGLDisplay& aDisplay, TInt aThreadIdx) sl@0: : iLogger(aLogger), iThreadIdx(aThreadIdx), iExtensionGroupCached(EIsUndefined), iDisplay(aDisplay), iExpectedErrorCode(EGL_SUCCESS) sl@0: {} sl@0: sl@0: EXPORT_C CTestEglSession* CTestEglSession::NewLC(CTestExecuteLogger& aLogger, EGLDisplay& aDisplay, TInt aThreadIdx) sl@0: { sl@0: CTestEglSession* self = new (ELeave) CTestEglSession(aLogger, aDisplay, aThreadIdx); sl@0: CleanupStack::PushL(self); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CTestEglSession* CTestEglSession::NewL(CTestExecuteLogger& aLogger, EGLDisplay& aDisplay, TInt aThreadIdx) sl@0: { sl@0: CTestEglSession* self = CTestEglSession::NewLC(aLogger, aDisplay, aThreadIdx); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CTestEglSession::~CTestEglSession() sl@0: { sl@0: iExtensionStrings.Reset(); sl@0: EGLBoolean ret; sl@0: if (iDisplay != EGL_NO_DISPLAY) sl@0: { sl@0: // Unbind and destroy context only if we successfuly created it sl@0: if (iContext != EGL_NO_CONTEXT) sl@0: { sl@0: INFO_PRINTF2(_L("thread %d: Calling eglMakeCurrent(NULL values) from ~CTestEglSession..."), iThreadIdx); sl@0: ret = eglMakeCurrent(iDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); sl@0: if(ret == EGL_FALSE) sl@0: { sl@0: WARN_PRINTF3(_L("thread %d: eglMakeCurrent returned error = %x ~CTestEglSession..."), iThreadIdx, eglGetError()); sl@0: } sl@0: sl@0: // Warn because this should be done by the test, rather than relying on the d'tor sl@0: // which may not leave if there is an error (so no CHECK_EXPECTED_ERROR) sl@0: WARN_PRINTF2(_L("thread %d: Calling eglDestroyContext() from ~CTestEglSession..."), iThreadIdx); sl@0: ret = eglDestroyContext(iDisplay, iContext); sl@0: if(ret == EGL_FALSE) sl@0: { sl@0: WARN_PRINTF3(_L("thread %d: eglDestroyContext returned error = %x ~CTestEglSession..."), iThreadIdx, eglGetError()); sl@0: } sl@0: } sl@0: sl@0: if (iSurface != EGL_NO_SURFACE) sl@0: { sl@0: // Warn because this should be done by the test, rather than relying on the d'tor sl@0: // which may not leave if there is an error (so no CHECK_EXPECTED_ERROR) sl@0: WARN_PRINTF2(_L("thread %d: Calling eglDestroySurface() from ~CTestEglSession..."), iThreadIdx); sl@0: ret = eglDestroySurface(iDisplay, iSurface); sl@0: if(ret == EGL_FALSE) sl@0: { sl@0: WARN_PRINTF3(_L("thread %d: eglDestroySurface returned error = %x ~CTestEglSession..."), iThreadIdx, eglGetError()); sl@0: } sl@0: } sl@0: sl@0: if (iTerminateDisplay) sl@0: { sl@0: INFO_PRINTF1(_L("Calling eglTerminate...")); sl@0: ret = eglTerminate(iDisplay); sl@0: iDisplay = EGL_NO_DISPLAY; sl@0: if(ret == EGL_FALSE) sl@0: { sl@0: WARN_PRINTF3(_L("thread %d: eglTerminate returned error = %x ~CTestEglSession..."), iThreadIdx, eglGetError()); sl@0: } sl@0: } sl@0: } sl@0: sl@0: // Only destroy native resource after the surface and context that wraps it has been destroyed. sl@0: delete iFbsBitmap; sl@0: CloseFbsSession(); sl@0: sl@0: iSgImage.Close(); sl@0: CloseSgDriver(); sl@0: } sl@0: sl@0: EXPORT_C void CTestEglSession::SetExpectedError(EGLint aExpectedErrorCode) sl@0: { sl@0: VERBOSE_INFO_PRINTF3(_L("thread %d: Setting the expected error code for the next EGL call to %x"), iThreadIdx, aExpectedErrorCode); sl@0: { sl@0: iExpectedErrorCode = aExpectedErrorCode; sl@0: } sl@0: } sl@0: sl@0: EXPORT_C void CTestEglSession::ResetExpectedError() sl@0: { sl@0: iExpectedErrorCode = EGL_SUCCESS; sl@0: } sl@0: sl@0: /** sl@0: Checks whether the call to an EGL method returned the correct error information. sl@0: The method checks whether eglGetError() returns the expected error value as specified by calling SetExpectedError() sl@0: It also checks that the value returned by the EGL method was appropriate for the expected error value. sl@0: @param aFunctionReturnValue Pass in the value retured from the EGL method sl@0: @return Whether the expected error information was returned from a call to an EGL method. sl@0: */ sl@0: EXPORT_C TBool CTestEglSession::CheckExpectedError(EGLint aFunctionReturnValue) sl@0: { sl@0: TBool isExpectedError = ETrue; sl@0: EGLint eglErr = eglGetError(); sl@0: sl@0: // First check that we got the correct return value sl@0: if ((iExpectedErrorCode == EGL_SUCCESS) && !aFunctionReturnValue) sl@0: { sl@0: ERR_PRINTF3(_L("thread %d: Wrong function return value: %d"), iThreadIdx, aFunctionReturnValue); sl@0: isExpectedError = EFalse; sl@0: } sl@0: // Also check that we got the sl@0: if (eglErr != iExpectedErrorCode) sl@0: { sl@0: ERR_PRINTF4(_L("thread %d: eglGetError() returned %x, but expected %x"), iThreadIdx, eglErr, iExpectedErrorCode); sl@0: isExpectedError = EFalse; sl@0: } sl@0: else if (eglErr != EGL_SUCCESS) sl@0: { sl@0: VERBOSE_INFO_PRINTF3(_L("thread %d: eglGetError() returned %x, as expected"), iThreadIdx, eglErr); sl@0: } sl@0: sl@0: // Reset the expected error sl@0: ResetExpectedError(); sl@0: sl@0: return isExpectedError; sl@0: } sl@0: sl@0: EXPORT_C void CTestEglSession::CheckExpectedErrorL(EGLint aExpectedErrorCode) sl@0: { sl@0: EGLint eglErr = eglGetError(); sl@0: // check that we got the expected error sl@0: if (eglErr != aExpectedErrorCode) sl@0: { sl@0: ERR_PRINTF4(_L("thread %d: eglGetError() returned %x, but expected %x"), iThreadIdx, eglErr, aExpectedErrorCode); sl@0: User::Leave(KErrTEFUnitFail); sl@0: } sl@0: } sl@0: sl@0: void CTestEglSession::QueryExtensionsL(TExtensionsGroups aExtensionBelongsTo) sl@0: { sl@0: // reset the cached extensions sl@0: iExtensionStrings.Reset(); sl@0: sl@0: const char* extensionsString = NULL; sl@0: if(aExtensionBelongsTo == EIsEGL) sl@0: { sl@0: INFO_PRINTF2(_L("thread %d: Calling eglQueryString for EGL_EXTENSIONS)"), iThreadIdx); sl@0: extensionsString = eglQueryString(iDisplay, EGL_EXTENSIONS); sl@0: } sl@0: else if(aExtensionBelongsTo == EIsVG) sl@0: { sl@0: INFO_PRINTF2(_L("thread %d: Calling vgGetString for VG_EXTENSIONS)"), iThreadIdx); sl@0: sl@0: // OpenVG needs a current VG context before it will allow the call to vgGetString sl@0: // The created surface will remain un-used, hence we create it with an arbitrary pixel format sl@0: EGLConfig currentConfig = GetConfigExactMatchL(EPBufferAttribsColor64K); sl@0: CreatePbufferSurfaceAndMakeCurrentL(currentConfig, TSize(1,1), EGL_OPENVG_API); sl@0: sl@0: extensionsString = (const char*) vgGetString(VG_EXTENSIONS); sl@0: sl@0: //cleanup the context & surface sl@0: CleanupSurfaceSgImageL(); sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF2(_L("CTestEglSession::QueryExtensionsL() - Unknown extension group provided (%d)."), aExtensionBelongsTo); sl@0: User::Leave(KErrArgument); sl@0: } sl@0: CHECK_EXPECTED_ERROR(extensionsString!=NULL); sl@0: sl@0: TPtrC8 ptrExtensions((const TUint8 *) extensionsString ); sl@0: sl@0: RBuf buffer; sl@0: buffer.CreateL(ptrExtensions.Length()); sl@0: buffer.CleanupClosePushL(); sl@0: buffer.Copy(ptrExtensions); sl@0: INFO_PRINTF3(_L("thread %d: QueryExtensionsL: \"%S\""), iThreadIdx, &buffer); sl@0: CleanupStack::PopAndDestroy(&buffer); sl@0: sl@0: TInt posSpace=1; sl@0: while (posSpace > 0 && ptrExtensions.Length() > 0) sl@0: { sl@0: posSpace = ptrExtensions.Locate(' '); // strictly looking for a single space sl@0: ASSERT_FALSE(posSpace==0); // Would imply extension starting with a space or with 2 spaces in a row sl@0: if (posSpace > 0) sl@0: { sl@0: iExtensionStrings.Append(ptrExtensions.Left(posSpace)); sl@0: if (posSpace <= ptrExtensions.Length()) sl@0: { sl@0: ptrExtensions.Set(ptrExtensions.Mid(posSpace+1)); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: iExtensionStrings.Append(ptrExtensions); sl@0: } sl@0: } sl@0: } sl@0: sl@0: TBool CTestEglSession::FindExtensionStringL(TExtensionsGroups aExtensionBelongsTo, const TDesC8& aExtensionString) sl@0: { sl@0: //Load the extensions for this group if not already cached sl@0: if (iExtensionGroupCached != aExtensionBelongsTo) sl@0: { sl@0: QueryExtensionsL(aExtensionBelongsTo); // Load extension info sl@0: iExtensionGroupCached = aExtensionBelongsTo; sl@0: } sl@0: sl@0: TInt countExtensionStrings = iExtensionStrings.Count(); sl@0: for(TUint i=0; i bufMissingExtension16; sl@0: bufMissingExtension16.Copy(aExtensionString.Left(KBufLenMissingExtension)); sl@0: sl@0: WARN_PRINTF2(_L("EGL extension missing: [%S]"), &bufMissingExtension16); sl@0: return EFalse; sl@0: } sl@0: sl@0: /** sl@0: Converts from TRgb space to Vg floating point colour sl@0: */ sl@0: EXPORT_C void CTestEglSession::ConvertColor(const TRgb& aSource, VGfloat* aTarget) sl@0: //static sl@0: { sl@0: aTarget[0] = (VGfloat)aSource.Red() / 255.f; sl@0: aTarget[1] = (VGfloat)aSource.Green() / 255.f; sl@0: aTarget[2] = (VGfloat)aSource.Blue() / 255.f; sl@0: aTarget[3] = (VGfloat)aSource.Alpha() / 255.f; sl@0: } sl@0: sl@0: /** Breakpoint to manually view available configs while debugging */ sl@0: EXPORT_C void CTestEglSession::ViewConfigsL() sl@0: { sl@0: EGLConfig configs[KMaxEglConfigs]; sl@0: EGLint numConfigs=0; sl@0: sl@0: // Query number of configs available sl@0: INFO_PRINTF1(_L("Calling eglGetConfigs to get the number of configs available...")); sl@0: CHECK_EXPECTED_ERROR(eglGetConfigs(iDisplay, NULL, KMaxTInt, &numConfigs)); sl@0: sl@0: INFO_PRINTF1(_L("Checking number of configs...")); sl@0: ASSERT_TRUE(numConfigs >= 1); sl@0: INFO_PRINTF2(_L("Found %d configs"), numConfigs); sl@0: sl@0: // Get the configs sl@0: INFO_PRINTF1(_L("Calling eglGetConfigs to get configs...")); sl@0: CHECK_EXPECTED_ERROR(eglGetConfigs(iDisplay, configs, KMaxEglConfigs, &numConfigs)); sl@0: sl@0: for(TUint index = 0; index < numConfigs; index++) sl@0: { sl@0: EGLint EGL_BUFFER_SIZE_value; sl@0: EGLint EGL_ALPHA_SIZE_value; sl@0: EGLint EGL_BLUE_SIZE_value; sl@0: EGLint EGL_GREEN_SIZE_value; sl@0: EGLint EGL_RED_SIZE_value; sl@0: #ifdef PRINT_ALL_CONFIGS_DETAILS sl@0: EGLint EGL_DEPTH_SIZE_value; sl@0: EGLint EGL_STENCIL_SIZE_value; sl@0: EGLint EGL_CONFIG_CAVEAT_value; sl@0: EGLint EGL_CONFIG_ID_value; sl@0: EGLint EGL_LEVEL_value; sl@0: EGLint EGL_MAX_PBUFFER_HEIGHT_value; sl@0: EGLint EGL_MAX_PBUFFER_PIXELS_value; sl@0: EGLint EGL_MAX_PBUFFER_WIDTH_value; sl@0: EGLint EGL_NATIVE_RENDERABLE_value; sl@0: EGLint EGL_NATIVE_VISUAL_ID_value; sl@0: EGLint EGL_NATIVE_VISUAL_TYPE_value; sl@0: EGLint EGL_SAMPLES_value; sl@0: EGLint EGL_SAMPLE_BUFFERS_value; sl@0: #endif sl@0: EGLint EGL_SURFACE_TYPE_value; sl@0: #ifdef PRINT_ALL_CONFIGS_DETAILS sl@0: EGLint EGL_TRANSPARENT_TYPE_value; sl@0: EGLint EGL_TRANSPARENT_BLUE_VALUE_value; sl@0: EGLint EGL_TRANSPARENT_GREEN_VALUE_value; sl@0: EGLint EGL_TRANSPARENT_RED_VALUE_value; sl@0: EGLint EGL_BIND_TO_TEXTURE_RGB_value; sl@0: EGLint EGL_BIND_TO_TEXTURE_RGBA_value; sl@0: EGLint EGL_MIN_SWAP_INTERVAL_value; sl@0: EGLint EGL_MAX_SWAP_INTERVAL_value; sl@0: EGLint EGL_LUMINANCE_SIZE_value; sl@0: EGLint EGL_ALPHA_MASK_SIZE_value; sl@0: EGLint EGL_COLOR_BUFFER_TYPE_value; sl@0: #endif sl@0: EGLint EGL_RENDERABLE_TYPE_value; sl@0: sl@0: eglGetConfigAttrib(iDisplay, configs[index], EGL_BUFFER_SIZE, &EGL_BUFFER_SIZE_value); sl@0: eglGetConfigAttrib(iDisplay, configs[index], EGL_ALPHA_SIZE, &EGL_ALPHA_SIZE_value); sl@0: eglGetConfigAttrib(iDisplay, configs[index], EGL_BLUE_SIZE, &EGL_BLUE_SIZE_value); sl@0: eglGetConfigAttrib(iDisplay, configs[index], EGL_GREEN_SIZE, &EGL_GREEN_SIZE_value); sl@0: eglGetConfigAttrib(iDisplay, configs[index], EGL_RED_SIZE, &EGL_RED_SIZE_value); sl@0: #ifdef PRINT_ALL_CONFIGS_DETAILS sl@0: eglGetConfigAttrib(iDisplay, configs[index], EGL_DEPTH_SIZE, &EGL_DEPTH_SIZE_value); sl@0: eglGetConfigAttrib(iDisplay, configs[index], EGL_STENCIL_SIZE, &EGL_STENCIL_SIZE_value); sl@0: eglGetConfigAttrib(iDisplay, configs[index], EGL_CONFIG_CAVEAT, &EGL_CONFIG_CAVEAT_value); sl@0: eglGetConfigAttrib(iDisplay, configs[index], EGL_CONFIG_ID, &EGL_CONFIG_ID_value); sl@0: eglGetConfigAttrib(iDisplay, configs[index], EGL_LEVEL, &EGL_LEVEL_value); sl@0: eglGetConfigAttrib(iDisplay, configs[index], EGL_MAX_PBUFFER_HEIGHT, &EGL_MAX_PBUFFER_HEIGHT_value); sl@0: eglGetConfigAttrib(iDisplay, configs[index], EGL_MAX_PBUFFER_PIXELS, &EGL_MAX_PBUFFER_PIXELS_value); sl@0: eglGetConfigAttrib(iDisplay, configs[index], EGL_MAX_PBUFFER_WIDTH, &EGL_MAX_PBUFFER_WIDTH_value); sl@0: eglGetConfigAttrib(iDisplay, configs[index], EGL_NATIVE_RENDERABLE, &EGL_NATIVE_RENDERABLE_value); sl@0: eglGetConfigAttrib(iDisplay, configs[index], EGL_NATIVE_VISUAL_ID, &EGL_NATIVE_VISUAL_ID_value); sl@0: eglGetConfigAttrib(iDisplay, configs[index], EGL_NATIVE_VISUAL_TYPE, &EGL_NATIVE_VISUAL_TYPE_value); sl@0: eglGetConfigAttrib(iDisplay, configs[index], EGL_SAMPLES, &EGL_SAMPLES_value); sl@0: eglGetConfigAttrib(iDisplay, configs[index], EGL_SAMPLE_BUFFERS, &EGL_SAMPLE_BUFFERS_value); sl@0: #endif sl@0: eglGetConfigAttrib(iDisplay, configs[index], EGL_SURFACE_TYPE, &EGL_SURFACE_TYPE_value); sl@0: #ifdef PRINT_ALL_CONFIGS_DETAILS sl@0: eglGetConfigAttrib(iDisplay, configs[index], EGL_TRANSPARENT_TYPE, &EGL_TRANSPARENT_TYPE_value); sl@0: eglGetConfigAttrib(iDisplay, configs[index], EGL_TRANSPARENT_BLUE_VALUE, &EGL_TRANSPARENT_BLUE_VALUE_value); sl@0: eglGetConfigAttrib(iDisplay, configs[index], EGL_TRANSPARENT_GREEN_VALUE, &EGL_TRANSPARENT_GREEN_VALUE_value); sl@0: eglGetConfigAttrib(iDisplay, configs[index], EGL_TRANSPARENT_RED_VALUE, &EGL_TRANSPARENT_RED_VALUE_value); sl@0: eglGetConfigAttrib(iDisplay, configs[index], EGL_BIND_TO_TEXTURE_RGB, &EGL_BIND_TO_TEXTURE_RGB_value); sl@0: eglGetConfigAttrib(iDisplay, configs[index], EGL_BIND_TO_TEXTURE_RGBA, &EGL_BIND_TO_TEXTURE_RGBA_value); sl@0: eglGetConfigAttrib(iDisplay, configs[index], EGL_MIN_SWAP_INTERVAL, &EGL_MIN_SWAP_INTERVAL_value); sl@0: eglGetConfigAttrib(iDisplay, configs[index], EGL_MAX_SWAP_INTERVAL, &EGL_MAX_SWAP_INTERVAL_value); sl@0: eglGetConfigAttrib(iDisplay, configs[index], EGL_LUMINANCE_SIZE, &EGL_LUMINANCE_SIZE_value); sl@0: eglGetConfigAttrib(iDisplay, configs[index], EGL_ALPHA_MASK_SIZE, &EGL_ALPHA_MASK_SIZE_value); sl@0: eglGetConfigAttrib(iDisplay, configs[index], EGL_COLOR_BUFFER_TYPE, &EGL_COLOR_BUFFER_TYPE_value); sl@0: #endif sl@0: eglGetConfigAttrib(iDisplay, configs[index], EGL_RENDERABLE_TYPE, &EGL_RENDERABLE_TYPE_value); sl@0: sl@0: TBool good = ETrue; sl@0: sl@0: INFO_PRINTF7(_L("(idx: %3d) RGBA=(%2d) %2d,%2d,%2d,%2d"), index, EGL_BUFFER_SIZE_value, sl@0: EGL_RED_SIZE_value, EGL_GREEN_SIZE_value, EGL_BLUE_SIZE_value, sl@0: EGL_ALPHA_SIZE_value); sl@0: if (!(EGL_RED_SIZE_value == 8 && EGL_GREEN_SIZE_value == 8 && EGL_BLUE_SIZE_value == 8 && EGL_ALPHA_SIZE_value == 0)) sl@0: { sl@0: continue; sl@0: } sl@0: sl@0: INFO_PRINTF2(_L("\n\n^^^^^^ CONFIG [%d] VALUES ******"), index); sl@0: if (EGL_SURFACE_TYPE_value & EGL_PIXMAP_BIT) sl@0: { sl@0: INFO_PRINTF2(_L("EGL_SURFACE_TYPE=%d. <<< Has EGL_PIXMAP_BIT"), EGL_SURFACE_TYPE_value); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF2(_L("EGL_SURFACE_TYPE=%d. <<< BAD (not pixmap)"), EGL_SURFACE_TYPE_value); sl@0: good = EFalse; sl@0: } sl@0: sl@0: if (EGL_RENDERABLE_TYPE_value & EGL_OPENVG_BIT) sl@0: { sl@0: INFO_PRINTF2(_L("EGL_RENDERABLE_TYPE=%d. <<< Has EGL_OPENVG_BIT"), EGL_RENDERABLE_TYPE_value); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF2(_L("EGL_RENDERABLE_TYPE=%d. <<< BAD (not open vg)"), EGL_RENDERABLE_TYPE_value); sl@0: good = EFalse; sl@0: } sl@0: sl@0: if (good) sl@0: { sl@0: INFO_PRINTF1(_L("^^^^^^^ GOOD ^^^^^^^")); sl@0: } sl@0: sl@0: #ifdef PRINT_ALL_CONFIGS_DETAILS sl@0: INFO_PRINTF2(_L("\n\n***** CONFIG [%d] VALUES ******"), index); sl@0: INFO_PRINTF2(_L("EGL_BUFFER_SIZE=%d."), EGL_BUFFER_SIZE_value); sl@0: INFO_PRINTF2(_L("EGL_ALPHA_SIZE=%d."), EGL_ALPHA_SIZE_value); sl@0: INFO_PRINTF2(_L("EGL_BLUE_SIZE=%d."), EGL_BLUE_SIZE_value); sl@0: INFO_PRINTF2(_L("EGL_GREEN_SIZE=%d."), EGL_GREEN_SIZE_value); sl@0: INFO_PRINTF2(_L("EGL_RED_SIZE=%d."), EGL_RED_SIZE_value); sl@0: INFO_PRINTF2(_L("EGL_DEPTH_SIZE=%d."), EGL_DEPTH_SIZE_value); sl@0: INFO_PRINTF2(_L("EGL_STENCIL_SIZE=%d."), EGL_STENCIL_SIZE_value); sl@0: INFO_PRINTF2(_L("EGL_CONFIG_CAVEAT=%d."), EGL_CONFIG_CAVEAT_value); sl@0: INFO_PRINTF2(_L("EGL_CONFIG_ID=%d."), EGL_CONFIG_ID_value); sl@0: INFO_PRINTF2(_L("EGL_LEVEL=%d."), EGL_LEVEL_value); sl@0: INFO_PRINTF2(_L("EGL_MAX_PBUFFER_HEIGHT=%d."), EGL_MAX_PBUFFER_HEIGHT_value); sl@0: INFO_PRINTF2(_L("EGL_MAX_PBUFFER_PIXELS=%d."), EGL_MAX_PBUFFER_PIXELS_value); sl@0: INFO_PRINTF2(_L("EGL_MAX_PBUFFER_WIDTH=%d."), EGL_MAX_PBUFFER_WIDTH_value); sl@0: INFO_PRINTF2(_L("EGL_NATIVE_RENDERABLE=%d."), EGL_NATIVE_RENDERABLE_value); sl@0: INFO_PRINTF2(_L("EGL_NATIVE_VISUAL_ID=%d."), EGL_NATIVE_VISUAL_ID_value); sl@0: INFO_PRINTF2(_L("EGL_NATIVE_VISUAL_TYPE=%d."), EGL_NATIVE_VISUAL_TYPE_value); sl@0: INFO_PRINTF2(_L("EGL_SAMPLES=%d."), EGL_SAMPLES_value); sl@0: INFO_PRINTF2(_L("EGL_SAMPLE_BUFFERS=%d."), EGL_SAMPLE_BUFFERS_value); sl@0: INFO_PRINTF2(_L("EGL_SURFACE_TYPE=%d."), EGL_SURFACE_TYPE_value); sl@0: INFO_PRINTF2(_L("EGL_TRANSPARENT_TYPE=%d."), EGL_TRANSPARENT_TYPE_value); sl@0: INFO_PRINTF2(_L("EGL_TRANSPARENT_BLUE_VALUE=%d."), EGL_TRANSPARENT_BLUE_VALUE_value); sl@0: INFO_PRINTF2(_L("EGL_TRANSPARENT_GREEN_VALUE=%d."), EGL_TRANSPARENT_GREEN_VALUE_value); sl@0: INFO_PRINTF2(_L("EGL_TRANSPARENT_RED_VALUE=%d."), EGL_TRANSPARENT_RED_VALUE_value); sl@0: INFO_PRINTF2(_L("EGL_BIND_TO_TEXTURE_RGB=%d."), EGL_BIND_TO_TEXTURE_RGB_value); sl@0: INFO_PRINTF2(_L("EGL_BIND_TO_TEXTURE_RGBA=%d."), EGL_BIND_TO_TEXTURE_RGBA_value); sl@0: INFO_PRINTF2(_L("EGL_MIN_SWAP_INTERVAL=%d."), EGL_MIN_SWAP_INTERVAL_value); sl@0: INFO_PRINTF2(_L("EGL_MAX_SWAP_INTERVAL=%d."), EGL_MAX_SWAP_INTERVAL_value); sl@0: INFO_PRINTF2(_L("EGL_LUMINANCE_SIZE=%d."), EGL_LUMINANCE_SIZE_value); sl@0: INFO_PRINTF2(_L("EGL_ALPHA_MASK_SIZE=%d."), EGL_ALPHA_MASK_SIZE_value); sl@0: INFO_PRINTF2(_L("EGL_COLOR_BUFFER_TYPE=%d."), EGL_COLOR_BUFFER_TYPE_value); sl@0: INFO_PRINTF2(_L("EGL_RENDERABLE_TYPE=%d."), EGL_RENDERABLE_TYPE_value); sl@0: INFO_PRINTF2(_L("\n*********************************\n\n"), index); sl@0: #endif sl@0: } sl@0: } sl@0: sl@0: LOCAL_C TEglConfigMatchType GetMatchType(EGLint aAttrib, TEglConfigMatchRule aMatchRule) sl@0: { sl@0: const TConfigMatchRuleItem* curMatchRuleItem = KConfigMatchRules[aMatchRule]; sl@0: sl@0: while(curMatchRuleItem->iAttrib != EGL_NONE) sl@0: { sl@0: if (aAttrib == curMatchRuleItem->iAttrib) sl@0: { sl@0: return curMatchRuleItem->iMatchType; sl@0: } sl@0: curMatchRuleItem++; sl@0: } sl@0: sl@0: RDebug::Printf("Unknown attrib %x", aAttrib); sl@0: return eMatchUnknown; sl@0: } sl@0: sl@0: /** sl@0: Returns the first index of a config that matches the requested config extactly sl@0: */ sl@0: TInt CTestEglSession::GetFullMatchConfigIndex(EGLDisplay aDisplay, EGLConfig *aConfigs, TInt aNumConfigs, sl@0: const EGLint aWantedAttribs[], TEglConfigMatchRule aMatchRule) sl@0: { sl@0: EGLint value=0; sl@0: for(TUint idxConfig=0; idxConfig="! sl@0: { sl@0: match = EFalse; sl@0: } sl@0: break; sl@0: case eMatchBitMask: sl@0: if ((value & curAttrib[1]) != curAttrib[1]) sl@0: { sl@0: match = EFalse; sl@0: } sl@0: break; sl@0: case eMatchAlways: sl@0: break; sl@0: sl@0: default: sl@0: // We should not get here. sl@0: ASSERT(FALSE); sl@0: break; sl@0: } sl@0: curAttrib += 2; sl@0: } sl@0: sl@0: // If we get here with match set, we have matched all attributes, and have found a match. sl@0: if (match) sl@0: { sl@0: return idxConfig; sl@0: } sl@0: } sl@0: return KErrNotFound; sl@0: } sl@0: sl@0: TInt CTestEglSession::ConfigToPixelFormatTableLength() const sl@0: { sl@0: return sizeof(KMapEglConfigToPixelFormat) / sizeof(TMapEglConfigToPixelFormat); sl@0: } sl@0: sl@0: const TMapEglConfigToPixelFormat& CTestEglSession::ConfigToPixelFormatTable(TInt aIndex) const sl@0: { sl@0: return KMapEglConfigToPixelFormat[aIndex]; sl@0: } sl@0: sl@0: /** sl@0: Returns pixel format inforamtion for a given EGL config. sl@0: @param aConfig The EGL config for which pixel format information will be returned. sl@0: @return A pointer to the pixel format information for the given EGL config. sl@0: Tf the config cannot be mapped, then NULL is returned. sl@0: */ sl@0: EXPORT_C const TMapEglConfigToPixelFormat* CTestEglSession::GetPixelFormatFromEglConfigL(EGLConfig aConfig) sl@0: { sl@0: EGLint bufferSize=0; sl@0: EGLint alphaSize=0; sl@0: EGLint redSize=0; sl@0: EGLint greenSize=0; sl@0: EGLint blueSize=0; sl@0: EGLint colorBufferType=0; sl@0: EGLint surfaceType = 0; sl@0: sl@0: CHECK_EXPECTED_ERROR(eglGetConfigAttrib(iDisplay, aConfig, EGL_BUFFER_SIZE, &bufferSize)); sl@0: CHECK_EXPECTED_ERROR(eglGetConfigAttrib(iDisplay, aConfig, EGL_ALPHA_SIZE, &alphaSize)); sl@0: CHECK_EXPECTED_ERROR(eglGetConfigAttrib(iDisplay, aConfig, EGL_RED_SIZE, &redSize)); sl@0: CHECK_EXPECTED_ERROR(eglGetConfigAttrib(iDisplay, aConfig, EGL_GREEN_SIZE, &greenSize)); sl@0: CHECK_EXPECTED_ERROR(eglGetConfigAttrib(iDisplay, aConfig, EGL_BLUE_SIZE, &blueSize)); sl@0: CHECK_EXPECTED_ERROR(eglGetConfigAttrib(iDisplay, aConfig, EGL_COLOR_BUFFER_TYPE, &colorBufferType)); sl@0: CHECK_EXPECTED_ERROR(eglGetConfigAttrib(iDisplay, aConfig, EGL_SURFACE_TYPE, &surfaceType)); sl@0: sl@0: INFO_PRINTF7(_L(">>>>> Config info: %d, %d, %d,%d,%d, 0x%x"), bufferSize, alphaSize, redSize, greenSize, blueSize, colorBufferType); sl@0: sl@0: for(TUint i=0; i= EEglTestConfigMax ) sl@0: { sl@0: ERR_PRINTF1(_L("Attribute index out of range, please check the INI file")); sl@0: User::Leave(KErrArgument); sl@0: } sl@0: sl@0: EGLConfig configs[KMaxEglConfigs]; sl@0: EGLint numConfigs=0; sl@0: ASSERT_EGL_TRUE(eglChooseConfig(iDisplay, KConfigAttribs[aConfigAttribIndex], configs, KMaxEglConfigs, &numConfigs)); sl@0: if (numConfigs <= 0) sl@0: { sl@0: // we just WARN, as we don't know if this is expected yet (if it is, then catch the leaving error) sl@0: WARN_PRINTF1(_L("GetConfigExactMatchL - Could not find a matching config, eglChooseConfig returned 0 configs!")); sl@0: User::Leave(KTestNoMatchingConfig); sl@0: } sl@0: sl@0: // Check that any of the configs returned matches the desired attributes sl@0: TInt match = GetFullMatchConfigIndex(iDisplay, configs, numConfigs, KConfigAttribs[aConfigAttribIndex], aMatchRule); sl@0: if (match == KErrNotFound) sl@0: { sl@0: // we just WARN, as we don't know if this is expected yet (if it is, then catch the leaving error) sl@0: WARN_PRINTF1(_L("GetConfigExactMatchL - Could not find a matching config amongst those returned by eglChooseConfig!")); sl@0: User::Leave(KTestNoMatchingConfig); sl@0: } sl@0: return configs[match]; sl@0: } sl@0: sl@0: /** sl@0: Creates a pixmap surface from a CFbsBitmap, draws to it and checks that the drawing operation succeeded. sl@0: */ sl@0: EXPORT_C void CTestEglSession::TryUsePixmapCFbsBitmapL() sl@0: { sl@0: INFO_PRINTF2(_L("thread %d: TryUsePixmapCFbsBitmapL"), iThreadIdx); sl@0: EGLConfig currentConfig = GetConfigExactMatchL(EPixmapAttribsColor64K); sl@0: TryUsePixmapCFbsBitmapOpenVgL(currentConfig, KPixmapSize, EColor64K); sl@0: } sl@0: sl@0: /** sl@0: Creates a pixmap surface from a CFbsBitmap, draws to it and checks that the drawing operation succeeded. sl@0: */ sl@0: EXPORT_C void CTestEglSession::TryUsePixmapCFbsBitmapOpenVgL(EGLConfig aConfig, const TSize& aSize, TDisplayMode aDisplayMode) sl@0: { sl@0: CreatePixmapSurfaceAndMakeCurrentL(aConfig, aSize, aDisplayMode); sl@0: DrawOpenVgL(); sl@0: sl@0: // Wait for the drawing to complete sl@0: eglWaitClient(); sl@0: sl@0: CheckImageDataL(iFbsBitmap); sl@0: CheckImageDataVgL(VG_sRGB_565); sl@0: CleanupSurfaceFbsBitmapL(); sl@0: CloseFbsSession(); sl@0: } sl@0: sl@0: /** sl@0: Creates a pixmap surface from a CFbsBitmap, draws to it and checks that the drawing operation succeeded. sl@0: */ sl@0: EXPORT_C void CTestEglSession::TryUsePixmapCFbsBitmapOpenGlesL(EGLConfig aConfig, const TSize& aSize, TDisplayMode aDisplayMode, TInt aRenderVersion) sl@0: { sl@0: CreatePixmapSurfaceAndMakeCurrentL(aConfig, aSize, aDisplayMode,EGL_OPENGL_ES_API, aRenderVersion); sl@0: DrawOpenGLesL(); sl@0: sl@0: // Wait for the drawing to complete sl@0: eglWaitClient(); sl@0: sl@0: CheckImageDataFullRedishL(iFbsBitmap); sl@0: CleanupSurfaceFbsBitmapL(); sl@0: CloseFbsSession(); sl@0: } sl@0: sl@0: /** sl@0: Creates a pixmap surface from a RSgImage, draws to it and checks that the drawing operation succeeded. sl@0: */ sl@0: EXPORT_C void CTestEglSession::TryUsePixmapRSgImageL() sl@0: { sl@0: INFO_PRINTF2(_L("thread %d: TryUsePixmapRSgImageL"), iThreadIdx); sl@0: TSgImageInfo imageInfo; sl@0: imageInfo.iSizeInPixels = KPixmapSize; sl@0: imageInfo.iPixelFormat = EUidPixelFormatXRGB_8888; sl@0: // will draw to and read from the image using OpenVg sl@0: #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE sl@0: imageInfo.iUsage = ESgUsageBitOpenVgSurface | ESgUsageBitOpenVgImage; sl@0: #else sl@0: // will also read from the image using DirectGdi sl@0: imageInfo.iUsage = ESgUsageOpenVgTarget | ESgUsageDirectGdiSource; sl@0: imageInfo.iShareable = EFalse; sl@0: imageInfo.iCpuAccess = ESgCpuAccessNone; sl@0: imageInfo.iScreenId = KSgScreenIdMain; sl@0: imageInfo.iUserAttributes = NULL; sl@0: imageInfo.iUserAttributeCount=0; sl@0: #endif sl@0: CreatePixmapSurfaceAndMakeCurrentAndMatchL(imageInfo, EResourceCloseSgImageLate); sl@0: DrawOpenVgL(); sl@0: sl@0: // Wait for the drawing to complete sl@0: eglWaitClient(); sl@0: sl@0: //we can't retrieve data directly from the SgImage as sl@0: //non-unified architecture doesn't allow readback from the GPU sl@0: CheckImageDataVgL(VG_sXRGB_8888); sl@0: CleanupSurfaceSgImageL(); sl@0: CloseSgDriver(); sl@0: } sl@0: sl@0: EXPORT_C TBool CTestEglSession::TryUsePixmapRSgImageOpenGlesL(EGLConfig aConfig, const TSgImageInfo& aImageInfo, TResourceCloseRule aResourceCloseRule, TInt aRenderVersion) sl@0: { sl@0: CreatePixmapSurfaceAndMakeCurrentL(aConfig, aImageInfo, aResourceCloseRule ,EGL_OPENGL_ES_API, aRenderVersion); sl@0: sl@0: DrawOpenGLesL(); sl@0: sl@0: // Wait for the drawing to complete sl@0: eglWaitClient(); sl@0: sl@0: //we can't retrieve data directly from SgImage as non-unified sl@0: //architecture doesn't allow readback from the GPU sl@0: sl@0: if (aImageInfo.iPixelFormat == EUidPixelFormatXRGB_8888 || sl@0: aImageInfo.iPixelFormat == EUidPixelFormatARGB_8888_PRE) sl@0: { sl@0: CheckImageDataGLesL(); sl@0: } sl@0: sl@0: CleanupSurfaceSgImageL(); sl@0: CloseSgDriver(); sl@0: return ETrue; sl@0: } sl@0: sl@0: /** sl@0: Compound operation that constructs an RSgImage and uses it to create a pixmap suface. sl@0: It then draws to the surface using OpenVG and checks whether the drawing succeeded. sl@0: It cleans up the pixmap surface it destroyed. sl@0: @param aConfig The EGL config to be used when creating the pixmap surface sl@0: @param aImageInfo Used to create the RSgImage pixmap sl@0: @param aCloseNativeImageEarly When ETrue, the RSgImage is closed as soon as the pixmap surface has been sl@0: created. Otherwise, the RSgImage is closed during cleanup, when the pixmap surface is destroyed. sl@0: @return Whether it was possible to create an iSgImage for the given aImageInfo sl@0: */ sl@0: EXPORT_C TBool CTestEglSession::TryUsePixmapRSgImageOpenVgL(EGLConfig aConfig, const TSgImageInfo& aImageInfo, TResourceCloseRule aResourceCloseRule) sl@0: { sl@0: CreatePixmapSurfaceAndMakeCurrentL(aConfig, aImageInfo, aResourceCloseRule); sl@0: sl@0: DrawOpenVgL(); sl@0: sl@0: // Wait for the drawing to complete sl@0: eglWaitClient(); sl@0: sl@0: //we can't retrieve data directly from the SgImage as sl@0: //non-unified architecture doesn't allow readback from the GPU sl@0: CheckImageDataVgL(VG_sXRGB_8888); sl@0: CleanupSurfaceSgImageL(); sl@0: CloseSgDriver(); sl@0: return ETrue; sl@0: } sl@0: sl@0: EXPORT_C void CTestEglSession::CreateWindowSurfaceAndMakeCurrentL(EGLConfig aConfig, RWindow& aWindow, TBool aVgAlphaFormatPre, EGLenum aBindAPI, TInt aRenderVersionNumber, EGLint* aAttribList) sl@0: { sl@0: ASSERT_EQUALS(iSurface, EGL_NO_SURFACE); sl@0: ASSERT_EQUALS(iContext, EGL_NO_CONTEXT); sl@0: sl@0: ASSERT_EGL_TRUE(eglBindAPI(aBindAPI)); sl@0: sl@0: // Create a Window surface from the native image sl@0: const EGLint* windowAttribs = aAttribList; sl@0: if(!windowAttribs) sl@0: { sl@0: windowAttribs = (aVgAlphaFormatPre && aBindAPI == EGL_OPENVG_API) ? KPixmapAttribsVgAlphaFormatPre : KPixmapAttribsNone; sl@0: } sl@0: iSurface = eglCreateWindowSurface(iDisplay, aConfig, &aWindow, windowAttribs); sl@0: ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE); sl@0: sl@0: // Create a context for drawing to/reading from the pixmap surface and make it current sl@0: const EGLint KAttribsListCtxNone[] = { EGL_NONE }; sl@0: const EGLint KAttribsListCtxGles2[] = { EGL_CONTEXT_CLIENT_VERSION, aRenderVersionNumber, EGL_NONE }; sl@0: const EGLint* attrib_list_ctx = (aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber == 2) ? KAttribsListCtxGles2 : KAttribsListCtxNone; sl@0: iContext = eglCreateContext(iDisplay, aConfig, EGL_NO_CONTEXT, attrib_list_ctx); sl@0: ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT); sl@0: ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext)); sl@0: } sl@0: sl@0: sl@0: EXPORT_C TBool CTestEglSession::CongfigSupportsOpenVgL(EGLConfig aConfig) sl@0: { sl@0: EGLint EGL_RENDERABLE_TYPE_value = 0; sl@0: ASSERT_EGL_TRUE(eglGetConfigAttrib(iDisplay, aConfig, EGL_RENDERABLE_TYPE, &EGL_RENDERABLE_TYPE_value)); sl@0: return (EGL_RENDERABLE_TYPE_value&EGL_OPENVG_BIT)>0; sl@0: } sl@0: sl@0: EXPORT_C void CTestEglSession::CreatePixmapSurfaceAndMakeCurrentAndMatchL(const TSgImageInfo& aImageInfo, TResourceCloseRule aResourceCloseRule, EGLenum aBindAPI, TInt aRenderVersionNumber) sl@0: { sl@0: ASSERT_EQUALS(iSurface, EGL_NO_SURFACE); sl@0: ASSERT_EQUALS(iContext, EGL_NO_CONTEXT); sl@0: sl@0: OpenSgDriverL(); sl@0: ASSERT_EQUALS(iSgImage.Create(aImageInfo, NULL, 0), KErrNone); sl@0: sl@0: EGLint renderableType = 0; sl@0: if(aBindAPI == EGL_OPENVG_API) sl@0: { sl@0: renderableType = EGL_OPENVG_BIT; sl@0: } sl@0: else if(aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber==1) sl@0: { sl@0: renderableType = EGL_OPENGL_ES_BIT; sl@0: } sl@0: else if(aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber==2) sl@0: { sl@0: renderableType = EGL_OPENGL_ES2_BIT; sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF1(_L("CreatePixmapSurfaceAndMakeCurrentAndMatchL - Unkown API requested!")); sl@0: User::Leave(KErrArgument); sl@0: } sl@0: EGLint attrib_list[] = { sl@0: EGL_MATCH_NATIVE_PIXMAP,(TInt)&iSgImage, sl@0: EGL_RENDERABLE_TYPE,renderableType, sl@0: EGL_SURFACE_TYPE,EGL_PIXMAP_BIT, sl@0: EGL_NONE}; sl@0: sl@0: ASSERT_EGL_TRUE(eglBindAPI(aBindAPI)); sl@0: sl@0: EGLConfig config; sl@0: EGLint numConfigs; sl@0: ASSERT_EGL_TRUE(eglChooseConfig(iDisplay,attrib_list,&config,1,&numConfigs)); sl@0: if (numConfigs <= 0) sl@0: { sl@0: // we just WARN, as we don't know if this is expected yet (if it is, then catch the leaving error) sl@0: WARN_PRINTF1(_L("CreatePixmapSurfaceAndMakeCurrentAndMatchL - Could not find a matching config!")); sl@0: iSgImage.Close(); sl@0: CloseSgDriver(); sl@0: // Leave with a unique knonwn error code - useful to catch this error in negative tests sl@0: User::Leave(KTestNoMatchingConfig); sl@0: } sl@0: sl@0: // Create a pixmap surface from the native image sl@0: EGLint EGL_RENDERABLE_TYPE_value = 0; sl@0: ASSERT_EGL_TRUE(eglGetConfigAttrib(iDisplay, config, EGL_RENDERABLE_TYPE, &EGL_RENDERABLE_TYPE_value)); sl@0: const EGLint* pixmapAttribs = ((aImageInfo.iPixelFormat == EUidPixelFormatARGB_8888_PRE) && (EGL_RENDERABLE_TYPE_value & EGL_OPENVG_BIT)) ? KPixmapAttribsVgAlphaFormatPre : KPixmapAttribsNone; sl@0: iSurface = eglCreatePixmapSurface(iDisplay, config, &iSgImage, pixmapAttribs); sl@0: ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE); sl@0: sl@0: if (aResourceCloseRule == EResourceCloseSgImageEarly) sl@0: { sl@0: // EGL should have taken its own reference to the SgImage, so it should be able to continue sl@0: // to use the underlying data after this local image has been closed. sl@0: iSgImage.Close(); sl@0: } sl@0: sl@0: if (aResourceCloseRule == EResourceCloseSgDriverAndImageEarly) sl@0: { sl@0: // EGL should have taken its own reference to the SgDriver, so it should be able to continue sl@0: // to use its reference to the image resource after this local reference to the driver has sl@0: // been closed. sl@0: iSgImage.Close(); sl@0: CloseSgDriver(); sl@0: } sl@0: sl@0: // Create a context for drawing to/reading from the pixmap surface and make it current sl@0: const EGLint KAttribsListCtxNone[] = { EGL_NONE }; sl@0: const EGLint KAttribsListCtxGles2[] = { EGL_CONTEXT_CLIENT_VERSION, aRenderVersionNumber, EGL_NONE }; sl@0: const EGLint* attrib_list_ctx = (aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber == 2) ? KAttribsListCtxGles2 : KAttribsListCtxNone; sl@0: iContext = eglCreateContext(iDisplay, config, EGL_NO_CONTEXT, attrib_list_ctx); sl@0: ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT); sl@0: ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext)); sl@0: } sl@0: sl@0: /** sl@0: Compound operation that constructs an RSgImage and uses it to create a pixmap suface. sl@0: It then makes it current to the thread. sl@0: @param aConfig The EGL config to be used when creating the pixmap surface sl@0: @param aImageInfo Used to create the RSgImage pixmap sl@0: @param aCloseNativeImageEarly When ETrue, the RSgImage is closed as soon as the pixmap surface has been sl@0: created. Otherwise, the RSgImage is left to be destroyed later by some other method sl@0: - e.g at the same time as destroying the surface. sl@0: @return Whether it was possible to create an iSgImage for the given aImageInfo sl@0: */ sl@0: EXPORT_C void CTestEglSession::CreatePixmapSurfaceAndMakeCurrentL(EGLConfig aConfig, const TSgImageInfo& aImageInfo, TResourceCloseRule aResourceCloseRule, EGLenum aBindAPI, TInt aRenderVersionNumber) sl@0: { sl@0: ASSERT_EQUALS(iSurface, EGL_NO_SURFACE); sl@0: ASSERT_EQUALS(iContext, EGL_NO_CONTEXT); sl@0: sl@0: OpenSgDriverL(); sl@0: ASSERT_EQUALS(iSgImage.Create(aImageInfo, NULL, 0), KErrNone); sl@0: sl@0: ASSERT_EGL_TRUE(eglBindAPI(aBindAPI)); sl@0: sl@0: // Create a pixmap surface from the native image sl@0: EGLint EGL_RENDERABLE_TYPE_value = 0; sl@0: ASSERT_EGL_TRUE(eglGetConfigAttrib(iDisplay, aConfig, EGL_RENDERABLE_TYPE, &EGL_RENDERABLE_TYPE_value)); sl@0: const EGLint* pixmapAttribs = ((aImageInfo.iPixelFormat == EUidPixelFormatARGB_8888_PRE) && (EGL_RENDERABLE_TYPE_value & EGL_OPENVG_BIT)) ? KPixmapAttribsVgAlphaFormatPre : KPixmapAttribsNone; sl@0: iSurface = eglCreatePixmapSurface(iDisplay, aConfig, &iSgImage, pixmapAttribs); sl@0: ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE); sl@0: sl@0: if (aResourceCloseRule == EResourceCloseSgImageEarly) sl@0: { sl@0: // EGL should have taken its own reference to the SgImage, so it should be able to continue sl@0: // to use the underlying data after this local image has been closed. sl@0: iSgImage.Close(); sl@0: } sl@0: if (aResourceCloseRule == EResourceCloseSgDriverAndImageEarly) sl@0: { sl@0: // EGL should have taken its own reference to the SgDriver, so it should be able to continue sl@0: // to use its reference to the image resource after this local reference to the driver has sl@0: // been closed. sl@0: iSgImage.Close(); sl@0: CloseSgDriver(); sl@0: } sl@0: sl@0: // Create a context for drawing to/reading from the pixmap surface and make it current sl@0: const EGLint KAttribsListCtxNone[] = { EGL_NONE }; sl@0: const EGLint KAttribsListCtxGles2[] = { EGL_CONTEXT_CLIENT_VERSION, aRenderVersionNumber, EGL_NONE }; sl@0: const EGLint* attrib_list_ctx = (aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber == 2) ? KAttribsListCtxGles2 : KAttribsListCtxNone; sl@0: iContext = eglCreateContext(iDisplay, aConfig, EGL_NO_CONTEXT, attrib_list_ctx); sl@0: ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT); sl@0: ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext)); sl@0: } sl@0: sl@0: EXPORT_C TInt CTestEglSession::CreateBitmap(CFbsBitmap* aFbsBitmap, const TSize& aSize, TDisplayMode aDisplayMode) sl@0: { sl@0: //Fist try with CreateHardwareBitmap to check whether we are on hardware sl@0: TInt result = aFbsBitmap->CreateHardwareBitmap(aSize, aDisplayMode, KUidEglTestServer); sl@0: sl@0: if(result == KErrNotSupported) sl@0: { sl@0: //we are not on hardware sl@0: result = aFbsBitmap->Create(aSize, aDisplayMode); sl@0: } sl@0: return result; sl@0: } sl@0: sl@0: EXPORT_C void CTestEglSession::CreatePixmapSurfaceAndMakeCurrentL(EGLConfig aConfig, const TSize& aSize, TDisplayMode displayMode, EGLenum aBindAPI, TInt aRenderVersionNumber) sl@0: { sl@0: ASSERT_EQUALS(iSurface, EGL_NO_SURFACE); sl@0: ASSERT_EQUALS(iContext, EGL_NO_CONTEXT); sl@0: sl@0: // Create an empty native CFbsBitmap sl@0: OpenFbsSessionL(); sl@0: iFbsBitmap = new(ELeave)CFbsBitmap; sl@0: ASSERT_EQUALS(CreateBitmap(iFbsBitmap, aSize, displayMode), KErrNone); sl@0: sl@0: const EGLint* attrib_list = NULL; sl@0: if(aBindAPI == EGL_OPENVG_API) sl@0: { sl@0: // no attribs to modify sl@0: } sl@0: else if(aBindAPI == EGL_OPENGL_ES_API) sl@0: { sl@0: // no attribs to modify sl@0: } sl@0: else if(aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber==2) sl@0: { sl@0: const EGLint KAttribGLES2[] = {EGL_CONTEXT_CLIENT_VERSION, aRenderVersionNumber, EGL_NONE}; sl@0: attrib_list=KAttribGLES2; sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF1(_L("CreatePixmapSurfaceAndMakeCurrentL - Unkown API requested!")); sl@0: User::Leave(KErrArgument); sl@0: } sl@0: ASSERT_EGL_TRUE(eglBindAPI(aBindAPI)); sl@0: sl@0: // Create a pixmap surface from the native image sl@0: EGLint EGL_RENDERABLE_TYPE_value = 0; sl@0: ASSERT_EGL_TRUE(eglGetConfigAttrib(iDisplay, aConfig, EGL_RENDERABLE_TYPE, &EGL_RENDERABLE_TYPE_value)); sl@0: const EGLint* pixmapAttribs = ((displayMode == EColor16MAP) && (EGL_RENDERABLE_TYPE_value & EGL_OPENVG_BIT)) ? KPixmapAttribsVgAlphaFormatPre : KPixmapAttribsNone; sl@0: iSurface = eglCreatePixmapSurface(iDisplay, aConfig, iFbsBitmap, pixmapAttribs); sl@0: ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE); sl@0: sl@0: // Create a context for drawing to/reading from the pixmap surface and make it current sl@0: iContext = eglCreateContext(iDisplay, aConfig, EGL_NO_CONTEXT, attrib_list); sl@0: ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT); sl@0: ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext)); sl@0: } sl@0: sl@0: EXPORT_C void CTestEglSession::CreatePixmapSurfaceAndMakeCurrentAndMatchL(const TSize& aSize, TDisplayMode aDisplayMode, EGLenum aBindAPI, TInt aRenderVersionNumber) sl@0: { sl@0: ASSERT_EQUALS(iSurface, EGL_NO_SURFACE); sl@0: ASSERT_EQUALS(iContext, EGL_NO_CONTEXT); sl@0: sl@0: OpenFbsSessionL(); sl@0: iFbsBitmap = new(ELeave)CFbsBitmap; sl@0: ASSERT_EQUALS(CreateBitmap(iFbsBitmap, aSize, aDisplayMode), KErrNone); sl@0: sl@0: EGLint renderableType = 0; sl@0: if(aBindAPI == EGL_OPENVG_API) sl@0: { sl@0: renderableType = EGL_OPENVG_BIT; sl@0: } sl@0: else if(aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber==1) sl@0: { sl@0: renderableType = EGL_OPENGL_ES_BIT; sl@0: } sl@0: else if(aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber==2) sl@0: { sl@0: renderableType = EGL_OPENGL_ES2_BIT; sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF1(_L("CreatePixmapSurfaceAndMakeCurrentAndMatchL - Unkown API requested!")); sl@0: User::Leave(KErrArgument); sl@0: } sl@0: EGLint attrib_list[] = { sl@0: EGL_MATCH_NATIVE_PIXMAP,(TInt)iFbsBitmap, sl@0: EGL_RENDERABLE_TYPE,renderableType, sl@0: EGL_SURFACE_TYPE,EGL_PIXMAP_BIT, sl@0: EGL_NONE}; sl@0: sl@0: ASSERT_EGL_TRUE(eglBindAPI(aBindAPI)); sl@0: sl@0: EGLConfig config; sl@0: EGLint numConfigs; sl@0: ASSERT_EGL_TRUE(eglChooseConfig(iDisplay,attrib_list,&config,1,&numConfigs)); sl@0: if (numConfigs <= 0) sl@0: { sl@0: // we just WARN, as we don't know if this is expected yet (if it is, then catch the leaving error) sl@0: WARN_PRINTF1(_L("CreatePixmapSurfaceAndMakeCurrentAndMatchL - Could not find a matching config!")); sl@0: iSgImage.Close(); sl@0: CloseSgDriver(); sl@0: // Leave with a unique knonwn error code - useful to catch this error in negative tests sl@0: User::Leave(KTestNoMatchingConfig); sl@0: } sl@0: sl@0: // Create a pixmap surface from the native image sl@0: const EGLint* pixmapAttribs = (aDisplayMode == EColor16MAP && aBindAPI == EGL_OPENVG_API) ? KPixmapAttribsVgAlphaFormatPre : KPixmapAttribsNone; sl@0: iSurface = eglCreatePixmapSurface(iDisplay, config, iFbsBitmap, pixmapAttribs); sl@0: ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE); sl@0: sl@0: // Create a context for drawing to/reading from the pixmap surface and make it current sl@0: const EGLint KAttribsListCtxNone[] = { EGL_NONE }; sl@0: const EGLint KAttribsListCtxGles2[] = { EGL_CONTEXT_CLIENT_VERSION, aRenderVersionNumber, EGL_NONE }; sl@0: const EGLint* attrib_list_ctx = (aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber == 2) ? KAttribsListCtxGles2 : KAttribsListCtxNone; sl@0: iContext = eglCreateContext(iDisplay, config, EGL_NO_CONTEXT, attrib_list_ctx); sl@0: ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT); sl@0: ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext)); sl@0: } sl@0: sl@0: EXPORT_C void CTestEglSession::CreatePbufferSurfaceAndMakeCurrentL(EGLConfig aConfig, const TSize& aSize, EGLenum aBindAPI, TInt aRenderVersionNumber) sl@0: { sl@0: ASSERT_EQUALS(iSurface, EGL_NO_SURFACE); sl@0: ASSERT_EQUALS(iContext, EGL_NO_CONTEXT); sl@0: sl@0: ASSERT_EQUALS(iSurface, EGL_NO_SURFACE); sl@0: ASSERT_EQUALS(iContext, EGL_NO_CONTEXT); sl@0: sl@0: ASSERT_EGL_TRUE(eglBindAPI(aBindAPI)); sl@0: sl@0: // PBuffer attribs options are: sl@0: // EGL_WIDTH, EGL_HEIGHT, EGL_LARGEST_PBUFFER, sl@0: // EGL_TEXTURE_FORMAT, EGL_TEXTURE_TARGET, EGL_MIPMAP_TEXTURE, sl@0: // EGL_VG_COLORSPACE, and EGL_VG_ALPHA_FORMAT sl@0: // Create a pbuffer surface of the given size sl@0: const EGLint KPbufferAttribs[] = { sl@0: EGL_WIDTH, aSize.iWidth, sl@0: EGL_HEIGHT, aSize.iHeight, sl@0: EGL_NONE }; sl@0: iSurface = eglCreatePbufferSurface(iDisplay, aConfig, KPbufferAttribs); sl@0: ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE); sl@0: sl@0: // Create a context for drawing to/reading from the pixmap surface and make it current sl@0: const EGLint KAttribsListCtxNone[] = { EGL_NONE }; sl@0: const EGLint KAttribsListCtxGles2[] = { EGL_CONTEXT_CLIENT_VERSION, aRenderVersionNumber, EGL_NONE }; sl@0: const EGLint* attrib_list_ctx = (aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber == 2) ? KAttribsListCtxGles2 : KAttribsListCtxNone; sl@0: iContext = eglCreateContext(iDisplay, aConfig, EGL_NO_CONTEXT, attrib_list_ctx); sl@0: ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT); sl@0: ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext)); sl@0: } sl@0: sl@0: EXPORT_C void CTestEglSession::DrawOpenVgL() sl@0: { sl@0: ASSERT_TRUE(iSurface != EGL_NO_SURFACE); sl@0: ASSERT_TRUE(iContext != EGL_NO_CONTEXT); sl@0: sl@0: // Draw to the pixmap surface sl@0: // Clear it: redish sl@0: VGfloat colorBackground[4]; sl@0: ConvertColor(KRgbReddish, colorBackground); sl@0: vgSetfv(VG_CLEAR_COLOR, 4, colorBackground); sl@0: vgClear(0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight); sl@0: sl@0: // And add a square: greenish sl@0: VGfloat colorSquare[4]; sl@0: ConvertColor(KRgbGreenish, colorSquare); sl@0: vgSetfv(VG_CLEAR_COLOR, 4, colorSquare); sl@0: vgClear(KPixmapSquare.iTl.iX, KPixmapSquare.iTl.iX, KPixmapSquare.Width(), KPixmapSquare.Height()); sl@0: } sl@0: sl@0: EXPORT_C void CTestEglSession::DrawOpenGLesL() sl@0: { sl@0: ASSERT_TRUE(iSurface != EGL_NO_SURFACE); sl@0: ASSERT_TRUE(iContext != EGL_NO_CONTEXT); sl@0: //GreenishRGB 0x46, 0xDC, 0x78 sl@0: const GLfloat glRed = KRgbReddish.Red(); sl@0: const GLfloat glGreen = KRgbReddish.Green(); sl@0: const GLfloat glBlue = KRgbReddish.Blue(); sl@0: const GLfloat glAlpha = KRgbReddish.Alpha(); sl@0: const GLfloat glRedBits = 255.f; sl@0: const GLfloat glGreenBits = 255.f; sl@0: const GLfloat glBlueBits = 255.f; sl@0: const GLfloat glAlphaBits = 255.f; sl@0: sl@0: // Disable cdither - when using exact comparison to reference bitmap sl@0: // because reference bitmap cannot be created to match dither exactly sl@0: glDisable(GL_DITHER); sl@0: // Clear the surface to the colour specified sl@0: glClearColor((glRed)/glRedBits, (glGreen)/glGreenBits, (glBlue)/glBlueBits, glAlpha/glAlphaBits); sl@0: sl@0: //glColor3f(KRgbGreenish.Red(),KRgbGreenish.Green(),KRgbGreenish.Blue()); sl@0: //glRectf(KPixmapSquare.iTl.iX, KPixmapSquare.iTl.iY,KPixmapSquare.iTl.iX + KPixmapSquare.Width(),KPixmapSquare.iTl.iY + KPixmapSquare.Height()); sl@0: sl@0: glClear(GL_COLOR_BUFFER_BIT); sl@0: } sl@0: sl@0: EXPORT_C void CTestEglSession::CheckImageDataL(CFbsBitmap* aFbsBitmap) sl@0: { sl@0: // Use native API's to check pixel values in the surface - note that this is not an OpenVG test, so no boundary pixels are tested sl@0: TRgb rgbPixelSample; sl@0: // Outside the square sl@0: aFbsBitmap->GetPixel(rgbPixelSample, TPoint(10,10)); sl@0: ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse)); sl@0: aFbsBitmap->GetPixel(rgbPixelSample, TPoint(90,90)); sl@0: ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse)); sl@0: sl@0: // Inside the square sl@0: aFbsBitmap->GetPixel(rgbPixelSample, TPoint(30,30)); sl@0: ASSERT_TRUE(PixelsMatch(KRgbGreenish, rgbPixelSample, EFalse)); sl@0: aFbsBitmap->GetPixel(rgbPixelSample, TPoint(70,70)); sl@0: ASSERT_TRUE(PixelsMatch(KRgbGreenish, rgbPixelSample, EFalse)); sl@0: } sl@0: sl@0: EXPORT_C void CTestEglSession::CheckImageDataFullRedishL(CFbsBitmap* aFbsBitmap) sl@0: { sl@0: // Use native API's to check pixel values in the surface - note that this is not an OpenVG test, so no boundary pixels are tested sl@0: TRgb rgbPixelSample; sl@0: // Outside the square sl@0: aFbsBitmap->GetPixel(rgbPixelSample, TPoint(10,10)); sl@0: ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse)); sl@0: aFbsBitmap->GetPixel(rgbPixelSample, TPoint(90,90)); sl@0: ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse)); sl@0: sl@0: // Inside the square sl@0: aFbsBitmap->GetPixel(rgbPixelSample, TPoint(30,30)); sl@0: ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse)); sl@0: aFbsBitmap->GetPixel(rgbPixelSample, TPoint(70,70)); sl@0: ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse)); sl@0: } sl@0: sl@0: /** sl@0: Use OpenVG to check pixel values sl@0: @param aDataFormat The VG image data format of the current surface sl@0: */ sl@0: EXPORT_C void CTestEglSession::CheckImageDataVgL(VGImageFormat aDataFormat) sl@0: { sl@0: switch(aDataFormat) sl@0: { sl@0: case VG_sRGB_565: sl@0: { sl@0: TUint16 intPixelSample=0; sl@0: sl@0: // Outside the square sl@0: vgReadPixels(&intPixelSample, 1, aDataFormat, 10,10, 1,1); sl@0: ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color64K(intPixelSample), EFalse)); sl@0: vgReadPixels(&intPixelSample, 1, aDataFormat, 90,90, 1,1); sl@0: ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color64K(intPixelSample), EFalse)); sl@0: sl@0: // Inside the square sl@0: vgReadPixels(&intPixelSample, 1, aDataFormat, 30,30, 1,1); sl@0: ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color64K(intPixelSample), EFalse)); sl@0: vgReadPixels(&intPixelSample, 1, aDataFormat, 70,70, 1,1); sl@0: ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color64K(intPixelSample), EFalse)); sl@0: break; sl@0: } sl@0: case VG_sXRGB_8888: sl@0: { sl@0: TUint32 intPixelSample=0; sl@0: sl@0: // Outside the square sl@0: vgReadPixels(&intPixelSample, 1, aDataFormat, 10,10, 1,1); sl@0: ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MU(intPixelSample), EFalse)); sl@0: vgReadPixels(&intPixelSample, 1, aDataFormat, 90,90, 1,1); sl@0: ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MU(intPixelSample), EFalse)); sl@0: sl@0: // Inside the square sl@0: vgReadPixels(&intPixelSample, 1, aDataFormat, 30,30, 1,1); sl@0: ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color16MU(intPixelSample), EFalse)); sl@0: vgReadPixels(&intPixelSample, 1, aDataFormat, 70,70, 1,1); sl@0: ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color16MU(intPixelSample), EFalse)); sl@0: break; sl@0: } sl@0: case VG_sARGB_8888: sl@0: { sl@0: TUint32 intPixelSample=0; sl@0: sl@0: // Outside the square sl@0: vgReadPixels(&intPixelSample, 1, aDataFormat, 10,10, 1,1); sl@0: ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MA(intPixelSample), EFalse)); sl@0: vgReadPixels(&intPixelSample, 1, aDataFormat, 90,90, 1,1); sl@0: ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MA(intPixelSample), EFalse)); sl@0: sl@0: // Inside the square sl@0: vgReadPixels(&intPixelSample, 1, aDataFormat, 30,30, 1,1); sl@0: ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color16MA(intPixelSample), EFalse)); sl@0: vgReadPixels(&intPixelSample, 1, aDataFormat, 70,70, 1,1); sl@0: ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color16MA(intPixelSample), EFalse)); sl@0: break; sl@0: } sl@0: default: sl@0: WARN_PRINTF2(_L("Unexpected image data format %d in CTestEglSession::CheckImageDataVgL"), aDataFormat); sl@0: ASSERT_TRUE(EFalse); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: Use OpenGLes to check pixel values sl@0: @param aDataFormat The VG image data format of the current surface sl@0: */ sl@0: EXPORT_C void CTestEglSession::CheckImageDataGLesL() sl@0: { sl@0: TUint32 intPixelSample; sl@0: glReadPixels(10,10,1,1,GL_RGBA,GL_UNSIGNED_BYTE ,&intPixelSample); sl@0: SwapChannels(intPixelSample); sl@0: ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MU(intPixelSample), EFalse)); sl@0: sl@0: glReadPixels(45,45,1,1,GL_RGBA,GL_UNSIGNED_BYTE ,&intPixelSample); sl@0: SwapChannels(intPixelSample); sl@0: ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MU(intPixelSample), EFalse)); sl@0: sl@0: glReadPixels(55,55,1,1,GL_RGBA,GL_UNSIGNED_BYTE ,&intPixelSample); sl@0: SwapChannels(intPixelSample); sl@0: ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MU(intPixelSample), EFalse)); sl@0: sl@0: glReadPixels(99,99,1,1,GL_RGBA,GL_UNSIGNED_BYTE ,&intPixelSample); sl@0: SwapChannels(intPixelSample); sl@0: ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MU(intPixelSample), EFalse)); sl@0: sl@0: } sl@0: sl@0: EXPORT_C void CTestEglSession::SwapChannels(TUint32 &aSwapMe) sl@0: { sl@0: TUint32 buff = aSwapMe; sl@0: sl@0: aSwapMe = 0; sl@0: aSwapMe |= (buff & 0x000000FF) << 16; sl@0: aSwapMe |= (buff & 0x0000FF00); sl@0: aSwapMe |= (buff & 0x00FF0000) >> 16; sl@0: aSwapMe |= (buff & 0xFF000000); sl@0: } sl@0: sl@0: /** sl@0: Destroys the surface and underlying RSgImage object. sl@0: Nulls the current context. sl@0: */ sl@0: EXPORT_C void CTestEglSession::CleanupSurfaceSgImageL() sl@0: { sl@0: CleanupSurfaceAndContextL(); sl@0: sl@0: iSgImage.Close(); sl@0: } sl@0: sl@0: /** sl@0: Resets the internal surface and context handles without destroying them. sl@0: Also closes the internal RSgImage handled that is associated to the surface. sl@0: sl@0: EGL destroys all surface and context handles associated with a display when sl@0: eglTerminate() is called. sl@0: */ sl@0: EXPORT_C void CTestEglSession::ResetSurfaceAndContextSgImageL() sl@0: { sl@0: INFO_PRINTF1(_L("CTestEglSession::ResetSurfaceAndContextSgImageL()")); sl@0: sl@0: iContext = EGL_NO_CONTEXT; sl@0: iSurface = EGL_NO_SURFACE; sl@0: iSgImage.Close(); sl@0: } sl@0: sl@0: /** sl@0: Check that the pixel values match within a predefined tolerance sl@0: @param aExpected the expected pixel colour vaule sl@0: @param aActual the actual pixel colour value sl@0: @param aCheckAlpha Whether to check the alpha channel value sl@0: @return Whether the pixel values match - within the allowed tolerance sl@0: */ sl@0: EXPORT_C TBool CTestEglSession::PixelsMatch(const TRgb& aExpected, const TRgb& aActual, TBool aCheckAlpha) sl@0: { sl@0: // This value has been carefully selected. If it is too high it could be hidding genuine pixel value sl@0: // differences, while too low will be too strict to allow for pixel conversions, i.e. from 16bpp to 32bpp sl@0: const TInt KPixelTolerance = 8; sl@0: sl@0: if (aCheckAlpha && aExpected.Alpha()== 0 && sl@0: aActual.Red() == 0 && sl@0: aActual.Green() == 0 && sl@0: aActual.Blue() == 0 && sl@0: aActual.Alpha() == 0) sl@0: { sl@0: // if the expected value for alpha is 0, all actual values should be 0 sl@0: return ETrue; sl@0: } sl@0: else if (Abs(aExpected.Red() - aActual.Red()) > KPixelTolerance || sl@0: Abs(aExpected.Green() - aActual.Green()) > KPixelTolerance || sl@0: Abs(aExpected.Blue() - aActual.Blue()) > KPixelTolerance || sl@0: aCheckAlpha && Abs(aExpected.Alpha() - aActual.Alpha()) > KPixelTolerance) sl@0: { sl@0: // one or more of the actual values differ by more than the allowed tolerance sl@0: ERR_PRINTF6(_L("thread %d: Expected r:%d g:%d b:%d a:%d"), iThreadIdx, aExpected.Red(), aExpected.Green(), aExpected.Blue(), aExpected.Alpha()); sl@0: ERR_PRINTF6(_L("thread %d: Actual r:%d g:%d b:%d a:%d"), iThreadIdx, aActual.Red(), aActual.Green(), aActual.Blue(), aActual.Alpha()); sl@0: ERR_PRINTF6(_L("thread %d: diff r:%d g:%d b:%d a:%d"), iThreadIdx, Abs(aExpected.Red() - aActual.Red()), Abs(aExpected.Green() - aActual.Green()), Abs(aExpected.Blue() - aActual.Blue()), Abs(aExpected.Alpha() - aActual.Alpha())); sl@0: return EFalse; sl@0: } sl@0: return ETrue; sl@0: } sl@0: sl@0: EXPORT_C void CTestEglSession::InitializeL(TBool aTerminateDisplay) sl@0: { sl@0: // Initialize display object sl@0: INFO_PRINTF2(_L("thread %d: Calling eglInitialize..."), iThreadIdx); sl@0: EGLint major=0; sl@0: EGLint minor=0; sl@0: CHECK_EXPECTED_ERROR(eglInitialize(iDisplay, &major, &minor)); sl@0: // Remember if the user wants us to terminate the display. sl@0: iTerminateDisplay = aTerminateDisplay; sl@0: sl@0: INFO_PRINTF4(_L("thread %d: Initialised: EGL Version %d.%d"), iThreadIdx, major, minor); sl@0: } sl@0: sl@0: sl@0: EXPORT_C void CTestEglSession::TerminateDisplayL() sl@0: { sl@0: if (iSurface != EGL_NO_SURFACE) sl@0: { sl@0: WARN_PRINTF2(_L("thread %d: iSurface has not been destoroyed in TerminateDisplayL..."), iThreadIdx); sl@0: } sl@0: if (iContext != EGL_NO_CONTEXT) sl@0: { sl@0: WARN_PRINTF2(_L("thread %d: iContext has not been destoroyed in TerminateDisplayL..."), iThreadIdx); sl@0: } sl@0: if (iDisplay != EGL_NO_DISPLAY) sl@0: { sl@0: INFO_PRINTF2(_L("thread %d: Calling eglMakeCurrent(NULL values) from TerminateDisplayL..."), iThreadIdx); sl@0: sl@0: ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)); sl@0: sl@0: INFO_PRINTF1(_L("Calling eglTerminate...")); sl@0: ASSERT_EGL_TRUE(eglTerminate(iDisplay)); sl@0: iDisplay = EGL_NO_DISPLAY; sl@0: } sl@0: iTerminateDisplay = EFalse; sl@0: } sl@0: sl@0: EXPORT_C void CTestEglSession::OpenSgDriverL() sl@0: { sl@0: if (!iSgDriverOpen) sl@0: { sl@0: VERBOSE_INFO_PRINTF2(_L("CTestEglSession<0x%08x> Opening SgDriver"), this); sl@0: #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE sl@0: TInt ret=iSgDriver.Open(); sl@0: #else sl@0: TInt ret=SgDriver::Open(); sl@0: #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE sl@0: ASSERT_EQUALS(ret, KErrNone); sl@0: iSgDriverOpen = ETrue; sl@0: } sl@0: } sl@0: sl@0: EXPORT_C void CTestEglSession::CloseSgDriver() sl@0: { sl@0: if (iSgDriverOpen) sl@0: { sl@0: VERBOSE_INFO_PRINTF2(_L("CTestEglSession<0x%08x> Closing SgDriver"), this); sl@0: #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE sl@0: iSgDriver.Close(); sl@0: #else sl@0: SgDriver::Close(); sl@0: #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE sl@0: iSgDriverOpen = EFalse; sl@0: } sl@0: } sl@0: sl@0: EXPORT_C void CTestEglSession::OpenFbsSessionL() sl@0: { sl@0: if (!iFbsSessionOpen) sl@0: { sl@0: INFO_PRINTF2(_L("CTestEglSession<0x%08x> Opening FbsSession"), this); sl@0: TInt ret=RFbsSession::Connect(); sl@0: ASSERT_EQUALS(ret, KErrNone); sl@0: iFbsSessionOpen = ETrue; sl@0: } sl@0: } sl@0: sl@0: EXPORT_C void CTestEglSession::CloseFbsSession() sl@0: { sl@0: if (iFbsSessionOpen) sl@0: { sl@0: INFO_PRINTF2(_L("CTestEglSession<0x%08x> Closing FbsSession"), this); sl@0: RFbsSession::Disconnect(); sl@0: iFbsSessionOpen = EFalse; sl@0: } sl@0: } sl@0: sl@0: EXPORT_C TBool CTestEglSession::FetchProcEglCreateImageKhr() sl@0: { sl@0: if (!ipfnEglCreateImageKHR) sl@0: { sl@0: INFO_PRINTF2(_L("thread %d: Calling eglGetProcAddress(\"eglCreateImageKHR\")"), iThreadIdx); sl@0: ipfnEglCreateImageKHR = reinterpret_cast(eglGetProcAddress("eglCreateImageKHR")); sl@0: if (ipfnEglCreateImageKHR==NULL) sl@0: { sl@0: EGLint eglError = eglGetError(); sl@0: WARN_PRINTF2(_L("eglCreateImageKHR() not found - EGL Error: 0x%x"), eglError); sl@0: } sl@0: } sl@0: return (ipfnEglCreateImageKHR!=NULL); sl@0: } sl@0: sl@0: EXPORT_C EGLImageKHR CTestEglSession::eglCreateImageKhrL(EGLDisplay aDisplay,EGLContext aContext,EGLenum aTarget,RSgImage* aSgImage,const EGLint *aAttr_List) sl@0: { sl@0: TBool bSuccess = FetchProcEglCreateImageKhr(); sl@0: ASSERT_TRUE(bSuccess); sl@0: VERBOSE_INFO_PRINTF2(_L("thread %d: Calling eglCreateImageKHR"), iThreadIdx); sl@0: EGLImageKHR eglImage = ipfnEglCreateImageKHR(aDisplay,aContext,aTarget,reinterpret_cast(aSgImage),const_cast(aAttr_List)); sl@0: return eglImage; sl@0: } sl@0: sl@0: EXPORT_C EGLImageKHR CTestEglSession::eglCreateImageKhrL(EGLDisplay aDisplay,EGLContext aContext,EGLenum aTarget,CFbsBitmap &aCFbsBitmap, const EGLint *aAttr_List) sl@0: { sl@0: TBool bSuccess = FetchProcEglCreateImageKhr(); sl@0: ASSERT_TRUE(bSuccess); sl@0: INFO_PRINTF2(_L("thread %d: Calling eglCreateImageKHR, with CFBsBitmap)"), iThreadIdx); sl@0: //the following call to eglCreateImageKHR MUST fail, error handling is made outside sl@0: EGLImageKHR eglImage = ipfnEglCreateImageKHR(aDisplay,aContext,aTarget,reinterpret_cast(&aCFbsBitmap),const_cast(aAttr_List)); sl@0: return eglImage; sl@0: } sl@0: sl@0: EXPORT_C TBool CTestEglSession::FetchProcEglDestroyImageKhr() sl@0: { sl@0: if (!ipfnEglDestroyImageKHR) sl@0: { sl@0: INFO_PRINTF2(_L("thread %d: Calling eglGetProcAddress(\"eglDestroyImageKHR\")"), iThreadIdx); sl@0: ipfnEglDestroyImageKHR = reinterpret_cast(eglGetProcAddress("eglDestroyImageKHR")); sl@0: if (ipfnEglDestroyImageKHR==NULL) sl@0: { sl@0: EGLint eglError = eglGetError(); sl@0: WARN_PRINTF2(_L("eglDestroyImageKHR() not found - EGL Error: 0x%x"), eglError); sl@0: } sl@0: } sl@0: return (ipfnEglDestroyImageKHR!=NULL); sl@0: } sl@0: sl@0: EXPORT_C TBool CTestEglSession::DestroyEGLImage(EGLDisplay aDisplay, EGLImageKHR aEGLImageKHR) sl@0: { sl@0: TBool bSuccess = FetchProcEglDestroyImageKhr(); sl@0: ASSERT_TRUE(bSuccess); sl@0: VERBOSE_INFO_PRINTF2(_L("thread %d: Calling eglDestroyImageKHR"), iThreadIdx); sl@0: return ipfnEglDestroyImageKHR(aDisplay,aEGLImageKHR); sl@0: } sl@0: sl@0: EXPORT_C TBool CTestEglSession::FetchProcvgCreateImageTargetKhr() sl@0: { sl@0: if (!ipfnvgCreateImageTargetKHR) sl@0: { sl@0: INFO_PRINTF2(_L("thread %d: Calling eglGetProcAddress (\"vgCreateEGLImageTargetKHR\")"), iThreadIdx); sl@0: ipfnvgCreateImageTargetKHR = reinterpret_cast(eglGetProcAddress("vgCreateEGLImageTargetKHR")); sl@0: if (ipfnvgCreateImageTargetKHR==NULL) sl@0: { sl@0: EGLint eglError = eglGetError(); sl@0: WARN_PRINTF2(_L("vgCreateImageTargetKHR() not found - EGL Error: 0x%x"), eglError); sl@0: } sl@0: } sl@0: return (ipfnvgCreateImageTargetKHR!=NULL); sl@0: } sl@0: sl@0: EXPORT_C VGImage CTestEglSession::vgCreateImageTargetKHR(VGeglImageKHR aImage) sl@0: { sl@0: TBool bSuccess = FetchProcvgCreateImageTargetKhr(); sl@0: ASSERT_TRUE(bSuccess); sl@0: VERBOSE_INFO_PRINTF2(_L("thread %d: Calling vgCreateEGLImageTargetKHR"), iThreadIdx); sl@0: return ipfnvgCreateImageTargetKHR(aImage); sl@0: } sl@0: sl@0: EXPORT_C TBool CTestEglSession::IsACompatibleConfig(EGLConfig aConfig,RSgImage& aImage,TBool aLog) sl@0: { sl@0: EGLint EGL_BUFFER_SIZE_value; sl@0: EGLint EGL_ALPHA_SIZE_value; sl@0: EGLint EGL_BLUE_SIZE_value; sl@0: EGLint EGL_GREEN_SIZE_value; sl@0: EGLint EGL_RED_SIZE_value; sl@0: EGLint EGL_SURFACE_TYPE_value; sl@0: EGLint EGL_RENDERABLE_TYPE_value; sl@0: EGLint EGL_CONFIG_ID_value; sl@0: sl@0: eglGetConfigAttrib(iDisplay, aConfig, EGL_CONFIG_ID, &EGL_CONFIG_ID_value); sl@0: eglGetConfigAttrib(iDisplay, aConfig, EGL_BUFFER_SIZE, &EGL_BUFFER_SIZE_value); sl@0: eglGetConfigAttrib(iDisplay, aConfig, EGL_ALPHA_SIZE, &EGL_ALPHA_SIZE_value); sl@0: eglGetConfigAttrib(iDisplay, aConfig, EGL_BLUE_SIZE, &EGL_BLUE_SIZE_value); sl@0: eglGetConfigAttrib(iDisplay, aConfig, EGL_GREEN_SIZE, &EGL_GREEN_SIZE_value); sl@0: eglGetConfigAttrib(iDisplay, aConfig, EGL_RED_SIZE, &EGL_RED_SIZE_value); sl@0: eglGetConfigAttrib(iDisplay, aConfig, EGL_SURFACE_TYPE, &EGL_SURFACE_TYPE_value); sl@0: eglGetConfigAttrib(iDisplay, aConfig, EGL_RENDERABLE_TYPE, &EGL_RENDERABLE_TYPE_value); sl@0: #ifdef PRINTG_CONFIGS_LOG sl@0: INFO_PRINTF7(_L("(Config: %3d) RGBA=(%2d) %2d,%2d,%2d,%2d"), EGL_CONFIG_ID_value, EGL_BUFFER_SIZE_value, sl@0: EGL_RED_SIZE_value, EGL_GREEN_SIZE_value, EGL_BLUE_SIZE_value, sl@0: EGL_ALPHA_SIZE_value); sl@0: INFO_PRINTF2(_L("RENDERABLE_TYPE %d"),EGL_RENDERABLE_TYPE_value); sl@0: #endif sl@0: sl@0: if(!(EGL_SURFACE_TYPE_value & EGL_PIXMAP_BIT)) sl@0: { sl@0: return EFalse; sl@0: } sl@0: sl@0: TBool good = ETrue; sl@0: //requested usage bits sl@0: TSgImageInfo requestedImageInfo; sl@0: aImage.GetInfo(requestedImageInfo); sl@0: sl@0: #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE sl@0: //potential usage bits sl@0: RSgImage potential; sl@0: potential.Open(aImage.Id(),ESgDoNotRestrictUsage); sl@0: TSgImageInfo potentialImageInfo; sl@0: potential.GetInfo(potentialImageInfo); sl@0: potential.Close(); sl@0: #endif sl@0: sl@0: switch(requestedImageInfo.iPixelFormat) sl@0: { sl@0: case EUidPixelFormatRGB_565: sl@0: if (!(EGL_RED_SIZE_value == 5 && EGL_GREEN_SIZE_value == 6 && EGL_BLUE_SIZE_value == 5 && EGL_ALPHA_SIZE_value == 0)) sl@0: { sl@0: good = EFalse; sl@0: } sl@0: break; sl@0: case EUidPixelFormatXRGB_8888: sl@0: if (!(EGL_RED_SIZE_value == 8 && EGL_GREEN_SIZE_value == 8 && EGL_BLUE_SIZE_value == 8 && EGL_ALPHA_SIZE_value == 0)) sl@0: { sl@0: good = EFalse; sl@0: } sl@0: break; sl@0: case EUidPixelFormatARGB_8888_PRE: sl@0: if (!(EGL_RED_SIZE_value == 8 && EGL_GREEN_SIZE_value == 8 && EGL_BLUE_SIZE_value == 8 && EGL_ALPHA_SIZE_value == 8)) sl@0: { sl@0: good = EFalse; sl@0: } sl@0: //just OVG cares about the premultiplied alpha sl@0: if(EGL_RENDERABLE_TYPE_value& EGL_OPENVG_BIT) sl@0: //if(requestedImageInfo.iUsage & ESgUsageBitOpenVgSurface) sl@0: { sl@0: if(!(EGL_SURFACE_TYPE_value & EGL_VG_ALPHA_FORMAT_PRE_BIT)) sl@0: { sl@0: if(aLog) sl@0: { sl@0: WARN_PRINTF2(_L("This Config can't be used with Pre-multipliedAlpha becasue EGL_SURFACE_TYPE has the wrong bits = %x"), EGL_SURFACE_TYPE_value); sl@0: } sl@0: good = EFalse; sl@0: } sl@0: } sl@0: break; sl@0: default: sl@0: if(aLog) sl@0: { sl@0: ERR_PRINTF2(_L("Wrong PixelFormat for a target, %x"), requestedImageInfo.iPixelFormat); sl@0: } sl@0: good = EFalse; sl@0: } sl@0: if(!good) sl@0: { sl@0: return EFalse; sl@0: } sl@0: sl@0: #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE sl@0: // sl@0: //Check if strict matching requirements are met: sl@0: //- All the supported APIs included in the EGL_RENDERABLE_TYPE of the sl@0: // EGLConfig must be matched by the corresponding iUsage of RSgImage sl@0: //- The following usages included in the iUsage of the RSgImage must be sl@0: // matched by the corresponding API in EGL_RENDERABLE_TYPE of the EGLConfig: sl@0: // ESgUsageBitOpenGlSurface-> EGL_OPENGL_BIT sl@0: // ESgUsageBitOpenGlesSurface-> EGL_OPENGL_ES_BIT sl@0: // ESgUsageBitOpenGles2Surface-> EGL_OPENGL_ES2_BIT sl@0: // ESgUsageBitOpenVgSurface->EGL_OPENVG_BIT sl@0: sl@0: EGLint usageBitsMask = 0; sl@0: if(requestedImageInfo.iUsage & ESgUsageBitOpenVgSurface) sl@0: { sl@0: usageBitsMask |= EGL_OPENVG_BIT; sl@0: } sl@0: if(requestedImageInfo.iUsage & ESgUsageBitOpenGles2Surface) sl@0: { sl@0: usageBitsMask |= EGL_OPENGL_ES2_BIT; sl@0: } sl@0: if(requestedImageInfo.iUsage & ESgUsageBitOpenGlesSurface) sl@0: { sl@0: usageBitsMask |= EGL_OPENGL_ES_BIT; sl@0: } sl@0: if(requestedImageInfo.iUsage & ESgUsageBitOpenGlSurface) sl@0: { sl@0: usageBitsMask |= EGL_OPENGL_BIT; sl@0: } sl@0: sl@0: if(usageBitsMask != EGL_RENDERABLE_TYPE_value) sl@0: { sl@0: return EFalse; sl@0: } sl@0: #else sl@0: // requested usage & RENDERABLE_TYPE > 0 sl@0: EGLint usageBitsMask = 0; sl@0: if(requestedImageInfo.iUsage & ESgUsageOpenVgTarget) sl@0: { sl@0: usageBitsMask |= EGL_OPENVG_BIT; sl@0: } sl@0: if(requestedImageInfo.iUsage & ESgUsageOpenGlesTarget) sl@0: { sl@0: usageBitsMask |= EGL_OPENGL_ES_BIT; sl@0: } sl@0: if(requestedImageInfo.iUsage & ESgUsageOpenGles2Target) sl@0: { sl@0: usageBitsMask |= EGL_OPENGL_ES2_BIT; sl@0: } sl@0: if(!(usageBitsMask & EGL_RENDERABLE_TYPE_value)) sl@0: { sl@0: return EFalse; sl@0: } sl@0: sl@0: // potential usage >= RENDERABLE_TYPE sl@0: sl@0: EGLint potentialUsageBitsMask = 0; sl@0: if(potentialImageInfo.iUsage & ESgUsageOpenVgTarget) sl@0: { sl@0: potentialUsageBitsMask |= EGL_OPENVG_BIT; sl@0: } sl@0: if(potentialImageInfo.iUsage & ESgUsageOpenGlesTarget) sl@0: { sl@0: potentialUsageBitsMask |= EGL_OPENGL_ES_BIT; sl@0: } sl@0: if(potentialImageInfo.iUsage & ESgUsageOpenGles2Target) sl@0: { sl@0: potentialUsageBitsMask |= EGL_OPENGL_ES2_BIT; sl@0: } sl@0: sl@0: potentialUsageBitsMask = EGL_RENDERABLE_TYPE_value &~ potentialUsageBitsMask; sl@0: if(potentialUsageBitsMask) sl@0: { sl@0: return EFalse; sl@0: } sl@0: #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE sl@0: return good; sl@0: } sl@0: sl@0: EXPORT_C TBool CTestEglSession::CheckNeededExtensionL(TInt aExtension, const TDesC& aExtensionName) sl@0: { sl@0: TBuf8<128> extensionName; sl@0: extensionName.Copy(aExtensionName); sl@0: if(aExtension & KEGL_RSgimage || extensionName.Compare(KEglRSgImage)==0) sl@0: { sl@0: TBool bFoundExtensionEGL_NOK_pixmap_type_rsgimage = FindExtensionStringL(EIsEGL,KEglRSgImage); sl@0: if (!bFoundExtensionEGL_NOK_pixmap_type_rsgimage) sl@0: { sl@0: // The extension is not supported sl@0: return EFalse; sl@0: } sl@0: } sl@0: if(aExtension & KEGL_KHR_image_base || extensionName.Compare(KEglKhrImageBase)==0) sl@0: { sl@0: TBool bFoundExtensionEGL_KHR_image = FindExtensionStringL(EIsEGL,KEglKhrImageBase); sl@0: if (!bFoundExtensionEGL_KHR_image) sl@0: { sl@0: // The extension is not supported sl@0: return EFalse; sl@0: } sl@0: } sl@0: if(aExtension & KEGL_KHR_image_pixmap || extensionName.Compare(KEglKhrImagePixmap)==0) sl@0: { sl@0: TBool bFoundExtensionEGL_KHR_image = FindExtensionStringL(EIsEGL,KEglKhrImagePixmap); sl@0: if (!bFoundExtensionEGL_KHR_image) sl@0: { sl@0: // The extension is not supported sl@0: return EFalse; sl@0: } sl@0: } sl@0: if(aExtension & KVG_KHR_EGL_image || extensionName.Compare(KVgKhrEglImage)==0) sl@0: { sl@0: TBool bFoundExtensionVG_KHR_EGL_image = FindExtensionStringL(EIsVG,KVgKhrEglImage); sl@0: if (!bFoundExtensionVG_KHR_EGL_image) sl@0: { sl@0: // The extension is not supported sl@0: return EFalse; sl@0: } sl@0: } sl@0: if(aExtension & KEGL_KHR_reusable_sync || extensionName.Compare(KEglKhrReusableSync)==0) sl@0: { sl@0: TBool bFoundExtensionEGL_KHR_reusable_sync = FindExtensionStringL(EIsEGL,KEglKhrReusableSync); sl@0: if (!bFoundExtensionEGL_KHR_reusable_sync) sl@0: { sl@0: // The extension is not supported sl@0: return EFalse; sl@0: } sl@0: } sl@0: if(aExtension & KEGL_NOK__private__signal_sync || extensionName.Compare(KEglNokPrivateSignalSync)==0) sl@0: { sl@0: TBool bFoundExtensionEGL_NOK__private__signal_sync = FindExtensionStringL(EIsEGL,KEglNokPrivateSignalSync); sl@0: if (!bFoundExtensionEGL_NOK__private__signal_sync) sl@0: { sl@0: // The extension is not supported sl@0: return EFalse; sl@0: } sl@0: } sl@0: if(aExtension & KEGL_NOKIA_swap_buffers || extensionName.Compare(KEglNokiaSwapBuffers)==0) sl@0: { sl@0: TBool bFoundExtensionEGL_NOKIA_swap_buffer = FindExtensionStringL(EIsEGL,KEglNokiaSwapBuffers); sl@0: if (!bFoundExtensionEGL_NOKIA_swap_buffer) sl@0: { sl@0: // The extension is not supported sl@0: return EFalse; sl@0: } sl@0: } sl@0: #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE sl@0: if(aExtension & KEGL_SYMBIAN_image_preserved || extensionName.Compare(KEglSymbianImagePreserved) sl@0: { sl@0: TBool bFoundExtensionEGL_SYMBIAN_image_preserved = FindExtensionStringL(EIsEGL,KEglSymbianImagePreserved); sl@0: if (!bFoundExtensionEGL_SYMBIAN_image_preserved) sl@0: { sl@0: // The extension is not supported sl@0: return EFalse; sl@0: } sl@0: } sl@0: #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE sl@0: if(aExtension & KEGL_NOK_image_endpoint || extensionName.Compare(KEglNokiaImageEndpoint)==0) sl@0: { sl@0: TBool bFoundExtensionEGL_NOK_image_endpoint = FindExtensionStringL(EIsEGL,KEglNokiaImageEndpoint); sl@0: if (!bFoundExtensionEGL_NOK_image_endpoint) sl@0: { sl@0: // The extension is not supported sl@0: return EFalse; sl@0: } sl@0: } sl@0: if(aExtension & KEGL_NOK_surface_scaling || extensionName.Compare(KEglNokiaSurfaceScaling)==0) sl@0: { sl@0: TBool bFoundExtensionEGL_NOK_surface_scaling = FindExtensionStringL(EIsEGL,KEglNokiaSurfaceScaling); sl@0: if (!bFoundExtensionEGL_NOK_surface_scaling) sl@0: { sl@0: // The extension is not supported sl@0: return EFalse; sl@0: } sl@0: } sl@0: return ETrue; sl@0: } sl@0: sl@0: EXPORT_C CFbsBitmap* CTestEglSession::CreateReferenceBitmapL(TDisplayMode aMode) sl@0: { sl@0: if(aMode == ENone ) sl@0: { sl@0: ERR_PRINTF1(_L("Queried Reference Bitmap dispaly mode equal to ENone")); sl@0: User::Leave(KErrTEFUnitFail); sl@0: } sl@0: return CreateReferenceBitmapL(aMode,KRgbGreenish); sl@0: } sl@0: sl@0: EXPORT_C CFbsBitmap* CTestEglSession::CreateReferenceBitmapL(TDisplayMode aMode,const TRgb& aColour) sl@0: { sl@0: OpenFbsSessionL(); sl@0: CFbsBitmap* bitmap = new(ELeave) CFbsBitmap(); sl@0: CleanupStack::PushL(bitmap); sl@0: if(bitmap->Create(KPixmapSize,aMode) != KErrNone) sl@0: { sl@0: return NULL; sl@0: } sl@0: CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(bitmap); sl@0: CleanupStack::PushL(bitmapDevice); sl@0: CFbsBitGc* fbsBitGc = CFbsBitGc::NewL(); sl@0: CleanupStack::PushL(fbsBitGc); sl@0: fbsBitGc->Activate(bitmapDevice); sl@0: fbsBitGc->SetBrushColor(aColour); sl@0: fbsBitGc->Clear(); sl@0: CleanupStack::PopAndDestroy(2,bitmapDevice); sl@0: CleanupStack::Pop(bitmap); sl@0: return bitmap; sl@0: } sl@0: sl@0: EXPORT_C CFbsBitmap* CTestEglSession::CreateReferenceMaskedBitmapL(TDisplayMode aRefBitmapMode, const TRgb& aPenBitmapColor, const CFbsBitmap* aMaskBitmap) sl@0: { sl@0: OpenFbsSessionL(); sl@0: sl@0: // create the refBitmat (same size as the mask bitmap) sl@0: // Note that we clear it to 'opaque black' as we assume the target surface has been cleared to 'opaque black' too sl@0: // If either the surface or the refBitmap are cleared to another colour, update the other accordingly sl@0: CFbsBitmap* refBitmap = new(ELeave) CFbsBitmap(); sl@0: CleanupStack::PushL(refBitmap); sl@0: User::LeaveIfError(refBitmap->Create(aMaskBitmap->SizeInPixels(), aRefBitmapMode)); sl@0: CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(refBitmap); sl@0: CleanupStack::PushL(bitmapDevice); sl@0: CFbsBitGc* fbsBitGc = CFbsBitGc::NewL(); sl@0: CleanupStack::PushL(fbsBitGc); sl@0: fbsBitGc->Activate(bitmapDevice); sl@0: fbsBitGc->SetBrushColor(KRgbBlack); sl@0: fbsBitGc->Clear(); sl@0: sl@0: // create the penBitmap (same size as the mask bitmap) sl@0: CFbsBitmap* penBitmap = new(ELeave) CFbsBitmap(); sl@0: CleanupStack::PushL(penBitmap); sl@0: User::LeaveIfError(penBitmap->Create(aMaskBitmap->SizeInPixels(), aRefBitmapMode)); sl@0: CFbsBitmapDevice* penbitmapDevice = CFbsBitmapDevice::NewL(penBitmap); sl@0: CleanupStack::PushL(penbitmapDevice); sl@0: CFbsBitGc* penBitGc = CFbsBitGc::NewL(); sl@0: CleanupStack::PushL(penBitGc); sl@0: penBitGc->Activate(penbitmapDevice); sl@0: penBitGc->SetBrushColor(aPenBitmapColor); sl@0: penBitGc->Clear(); sl@0: sl@0: // perform a masked bitmap transfer to the active refBitmap sl@0: TRect bmpRect(TPoint(0, 0), refBitmap->SizeInPixels()); sl@0: fbsBitGc->Activate(bitmapDevice); sl@0: fbsBitGc->BitBltMasked(TPoint(0, 0), penBitmap, bmpRect, aMaskBitmap, EFalse); sl@0: sl@0: CleanupStack::PopAndDestroy(5, bitmapDevice); sl@0: CleanupStack::Pop(refBitmap); sl@0: return refBitmap; sl@0: } sl@0: sl@0: sl@0: EXPORT_C CFbsBitmap* CTestEglSession::CreateReferenceBitmapL(TDisplayMode aMode, const TSize &aSize, const TInt aIndex) sl@0: { sl@0: OpenFbsSessionL(); sl@0: CFbsBitmap* bitmap = new(ELeave) CFbsBitmap(); sl@0: CleanupStack::PushL(bitmap); sl@0: User::LeaveIfError(bitmap->Create(aSize,aMode)); sl@0: sl@0: TInt height = bitmap->SizeInPixels().iHeight; sl@0: TInt width = bitmap->SizeInPixels().iWidth; sl@0: sl@0: // Initialise colour values to a random value (guarantees pixel uniqueness if update is done accordingly) sl@0: TInt red=0; sl@0: TInt green=127; sl@0: TInt blue=127; sl@0: TInt alpha=255; sl@0: sl@0: TBitmapUtil bmpUtil(bitmap); sl@0: bmpUtil.Begin(TPoint(0,0)); sl@0: for (TInt colIndex = 0; colIndex < width; ++colIndex) sl@0: { sl@0: bmpUtil.SetPos(TPoint(colIndex, 0)); sl@0: for (TInt rowIndex =0; rowIndex < height; ++rowIndex) sl@0: { sl@0: TRgb rgb(red, green, blue, alpha); sl@0: switch(bitmap->DisplayMode()) sl@0: { sl@0: case EColor64K: sl@0: { sl@0: bmpUtil.SetPixel(rgb.Color64K()); sl@0: break; sl@0: } sl@0: case EColor16MU: sl@0: { sl@0: bmpUtil.SetPixel(rgb.Color16MU()); sl@0: break; sl@0: } sl@0: case EColor16MA: sl@0: { sl@0: bmpUtil.SetPixel(rgb.Color16MA()); sl@0: break; sl@0: } sl@0: case EColor16MAP: sl@0: { sl@0: bmpUtil.SetPixel(rgb.Color16MAP()); sl@0: break; sl@0: } sl@0: case EGray256: sl@0: { sl@0: bmpUtil.SetPixel(rgb.Gray256()); sl@0: break; sl@0: } sl@0: default: sl@0: { sl@0: // We should not get here - colour mode not supported by these tests sl@0: ERR_PRINTF1(_L("CTestEglSession::CreateReferenceBitmapL - Colour mode not supported!")); sl@0: ASSERT(FALSE); sl@0: } sl@0: } sl@0: bmpUtil.IncYPos(); sl@0: sl@0: // Update red bit sl@0: red = ++red + aIndex; sl@0: if (red>255) sl@0: red = red - 256; sl@0: sl@0: // Update green bit sl@0: green = --green - aIndex; sl@0: if (green<0) sl@0: green = green + 256; sl@0: sl@0: // Update blue bit sl@0: blue = ++blue + aIndex; sl@0: if (blue>255) sl@0: blue = blue - 256; sl@0: sl@0: // Update alpha bit sl@0: alpha = --alpha - aIndex; sl@0: if (alpha<0) sl@0: alpha = alpha + 256; sl@0: } sl@0: } sl@0: bmpUtil.End(); sl@0: CleanupStack::Pop(bitmap); sl@0: return bitmap; sl@0: } sl@0: sl@0: EXPORT_C void CTestEglSession::CheckVgDrawingL(VGImageFormat aDataFormat, const CFbsBitmap* aReferenceBitmap) sl@0: { sl@0: TRgb refPixel; sl@0: TInt height = aReferenceBitmap->SizeInPixels().iHeight; sl@0: TInt width = aReferenceBitmap->SizeInPixels().iWidth; sl@0: sl@0: switch(aDataFormat) sl@0: { sl@0: case VG_sRGB_565: sl@0: { sl@0: TUint16* vgPixel = new(ELeave) TUint16[width]; sl@0: CleanupArrayDeletePushL(vgPixel); sl@0: for (TInt y=0; y < height; y++) sl@0: { sl@0: // Mind the fact that CFbsBitmap and VGImages use different coordinates origin! sl@0: vgReadPixels(vgPixel, 1, aDataFormat, 0,height-y-1, width,1); sl@0: sl@0: for (TInt x=0; x < width; x++) sl@0: { sl@0: aReferenceBitmap->GetPixel(refPixel, TPoint(x,y)); sl@0: if(!PixelsMatch(refPixel, TRgb::Color64K(vgPixel[x]), EFalse)) sl@0: { sl@0: User::Leave(KErrTEFUnitFail); sl@0: } sl@0: } sl@0: } sl@0: CleanupStack::PopAndDestroy(vgPixel); sl@0: break; sl@0: } sl@0: sl@0: case VG_sXRGB_8888: sl@0: { sl@0: TUint32* vgPixel = new(ELeave) TUint32[width]; sl@0: CleanupArrayDeletePushL(vgPixel); sl@0: for (TInt y=0; y < height; y++) sl@0: { sl@0: // Mind the fact that CFbsBitmap and VGImages use different coordinates origin! sl@0: vgReadPixels(vgPixel, 1, aDataFormat, 0,height-y-1, width,1); sl@0: sl@0: for (TInt x=0; x < width; x++) sl@0: { sl@0: aReferenceBitmap->GetPixel(refPixel, TPoint(x,y)); sl@0: if(!PixelsMatch(refPixel, TRgb::Color16MU(vgPixel[x]), EFalse)) sl@0: { sl@0: User::Leave(KErrTEFUnitFail); sl@0: } sl@0: } sl@0: } sl@0: CleanupStack::PopAndDestroy(vgPixel); sl@0: break; sl@0: } sl@0: sl@0: case VG_sARGB_8888: sl@0: { sl@0: TUint32* vgPixel = new(ELeave) TUint32[width]; sl@0: CleanupArrayDeletePushL(vgPixel); sl@0: for (TInt y=0; y < height; y++) sl@0: { sl@0: // Mind the fact that CFbsBitmap and VGImages use different coordinates origin! sl@0: vgReadPixels(vgPixel, 1, aDataFormat, 0,height-y-1, width,1); sl@0: sl@0: for (TInt x=0; x < width; x++) sl@0: { sl@0: aReferenceBitmap->GetPixel(refPixel, TPoint(x,y)); sl@0: if(!PixelsMatch(refPixel, TRgb::Color16MA(vgPixel[x]), ETrue)) sl@0: { sl@0: User::Leave(KErrTEFUnitFail); sl@0: } sl@0: } sl@0: } sl@0: CleanupStack::PopAndDestroy(vgPixel); sl@0: break; sl@0: } sl@0: sl@0: case VG_sARGB_8888_PRE: sl@0: { sl@0: TUint32* vgPixel = new(ELeave) TUint32[width]; sl@0: CleanupArrayDeletePushL(vgPixel); sl@0: for (TInt y=0; y < height; y++) sl@0: { sl@0: // Mind the fact that CFbsBitmap and VGImages use different coordinates origin! sl@0: vgReadPixels(vgPixel, 1, aDataFormat, 0,height-y-1, width,1); sl@0: sl@0: for (TInt x=0; x < width; x++) sl@0: { sl@0: aReferenceBitmap->GetPixel(refPixel, TPoint(x,y)); sl@0: if(!PixelsMatch(refPixel, TRgb::Color16MAP(vgPixel[x]), ETrue)) sl@0: { sl@0: User::Leave(KErrTEFUnitFail); sl@0: } sl@0: } sl@0: } sl@0: CleanupStack::PopAndDestroy(vgPixel); sl@0: break; sl@0: } sl@0: sl@0: default: sl@0: // We should not get here - colour mode not supported by these tests sl@0: ERR_PRINTF1(_L("CTestEglSession::CheckVgDrawingL - Colour mode not supported!")); sl@0: ASSERT(FALSE); sl@0: break; sl@0: } sl@0: } sl@0: sl@0: EXPORT_C TBool CTestEglSession::IsOpenGLESSupported() sl@0: { sl@0: if(!iIsSupportedRenderInitialized) sl@0: { sl@0: CheckAllAvailableRenders(); sl@0: } sl@0: return iIsOpenGLESSupported; sl@0: } sl@0: sl@0: EXPORT_C TBool CTestEglSession::IsOpenGLES2Supported() sl@0: { sl@0: if(!iIsSupportedRenderInitialized) sl@0: { sl@0: CheckAllAvailableRenders(); sl@0: } sl@0: return iIsOpenGLES2Supported; sl@0: } sl@0: EXPORT_C TBool CTestEglSession::IsOpenVGSupported() sl@0: { sl@0: if(!iIsSupportedRenderInitialized) sl@0: { sl@0: CheckAllAvailableRenders(); sl@0: } sl@0: return iIsOpenVGSupported; sl@0: } sl@0: sl@0: void CTestEglSession::CheckAllAvailableRenders() sl@0: { sl@0: ASSERT_EGL_TRUE(iDisplay != EGL_NO_DISPLAY); sl@0: TPtrC8 ptrEglClientApis((const TText8 *)eglQueryString(iDisplay, EGL_CLIENT_APIS)); sl@0: _LIT8(KOpenGLES, "OpenGL_ES"); sl@0: EGLint numConfigs= 0; sl@0: EGLConfig config; sl@0: if(ptrEglClientApis.Find(KOpenGLES) != KErrNotFound) sl@0: { sl@0: //check GLES2 sl@0: const EGLint KAttrib_list_gles2[] = { EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, sl@0: EGL_NONE }; sl@0: EGLBoolean eglRes = eglChooseConfig(iDisplay, KAttrib_list_gles2, &config,1, &numConfigs); sl@0: ASSERT_EGL_TRUE(eglRes == EGL_TRUE); sl@0: if(numConfigs > 0) sl@0: { sl@0: iIsOpenGLES2Supported = ETrue; sl@0: } sl@0: //check GLES sl@0: numConfigs = 0; sl@0: const EGLint KAttrib_list_gles[] = { EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT, sl@0: EGL_NONE }; sl@0: eglRes = eglChooseConfig(iDisplay, KAttrib_list_gles, &config,1, &numConfigs); sl@0: ASSERT_EGL_TRUE(eglRes == EGL_TRUE); sl@0: if(numConfigs > 0) sl@0: { sl@0: iIsOpenGLESSupported = ETrue; sl@0: } sl@0: } sl@0: _LIT8(KOpenVG, "OpenVG"); sl@0: if(ptrEglClientApis.Find(KOpenVG) != KErrNotFound) sl@0: { sl@0: numConfigs= 0; sl@0: //check VG sl@0: const EGLint KAttrib_list_vg[] = { EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT, sl@0: EGL_NONE }; sl@0: EGLBoolean eglRes = eglChooseConfig(iDisplay, KAttrib_list_vg, &config,1, &numConfigs); sl@0: ASSERT_EGL_TRUE(eglRes == EGL_TRUE); sl@0: if(numConfigs > 0) sl@0: { sl@0: iIsOpenVGSupported = ETrue; sl@0: } sl@0: } sl@0: iIsSupportedRenderInitialized = ETrue; sl@0: } sl@0: sl@0: