os/graphics/windowing/windowserver/test/t_integ/src/t_pseudoappeglbase.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 /**
    17  @file
    18  @test
    19  @internalComponent
    20 */
    21 
    22 #include <e32debug.h>
    23 #include "t_pseudoappeglbase.h"
    24 
    25 const TInt KMaxConfigs = 1024;
    26 
    27 CEglBase::CEglBase(const TDisplayMode& aMode,const TSize& aSurfaceSz, const TInt aHRate, const TInt aVRate)
    28 			: CTestAnimation(),iDispMode(aMode)
    29 	{
    30 	iSurfaceSize=aSurfaceSz;
    31 	iHorizontalRate=aHRate;
    32 	iVerticalRate=aVRate;
    33 	}
    34 
    35 void CEglBase::BaseConstructL(RWindow* aWin)
    36 	{
    37 	// eglGetDisplay
    38 	iDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
    39 	TestL(iDisplay!=EGL_NO_DISPLAY, _L("eglGetDisplay failed"));
    40 
    41 	// eglInitialize
    42 	TInt ret = eglInitialize(iDisplay, NULL, NULL);
    43 	TestL(ret, _L("eglInitialize failed"));
    44 
    45 	// eglGetConfigs
    46 	EGLint numConfigs;
    47 	EGLConfig configs[KMaxConfigs];
    48 	ret = eglGetConfigs(iDisplay, configs, KMaxConfigs, &numConfigs);
    49 	TestL(ret, _L("eglGetConfigs failed"));
    50 	TestL(numConfigs>0, _L("eglGetConfigs returned no configs"));
    51 
    52 	const EGLint* attribList = NULL;
    53 
    54 	// Select attribs based on current display mode
    55 	switch (iDispMode)
    56 		{
    57 		case EColor4K:	attribList = KColor4KAttribList;	break;
    58 		case EColor64K:	attribList = KColor64KAttribList;	break;
    59 		case EColor16M:	attribList = KColor16MAttribList;	break;
    60 		case EColor16MA:attribList = KColor16MAAttribList;	break;
    61 		default: 		User::Panic(_L("CEglBase"), KErrArgument);
    62 		}
    63 	
    64 	RDebug::Print(_L("Display Mode: %d"), iDispMode );
    65 
    66 	// eglChooseConfig
    67 	ret=eglChooseConfig(iDisplay, attribList, configs, KMaxConfigs, &numConfigs);
    68 	TestL(ret, _L("eglChooseConfig failed"));
    69 	TestL(numConfigs>0, _L("eglChooseConfig returned no configs"));
    70  
    71     if (attribList)
    72     	{
    73     	TInt configIndex = GetSuitableConfig(configs, numConfigs, attribList);
    74 		TestL(configIndex!=KErrNotFound, _L("No suitable configuration found") );
    75 		iUseConfig = configs[configIndex];	
    76     	}
    77 
    78 	// eglCreateWindowSurface
    79 	iSurface = eglCreateWindowSurface(iDisplay, iUseConfig, aWin, NULL);
    80 	TestL(iSurface!=EGL_NO_SURFACE, _L("eglCreateWindowSurface failed") );
    81 	}
    82 
    83 CEglBase::~CEglBase()
    84 	{
    85 	// Clean everything allocated.
    86 	eglMakeCurrent(iDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
    87 	eglDestroyContext(iDisplay, iContext);
    88 	eglDestroySurface(iDisplay, iSurface);
    89 	eglTerminate(iDisplay);
    90 	}
    91 
    92 TInt CEglBase::GetSuitableConfig(const EGLConfig* aConfigs, EGLint aNumConfigs, const EGLint* attribs)
    93 	{
    94 	TInt configIndex = KErrNotFound;
    95 	for (TInt i=0; i<aNumConfigs; i++)
    96 		{
    97 		EGLConfig config = aConfigs[i];
    98 		EGLint value;
    99 
   100 		TInt ret=eglGetConfigAttrib(iDisplay, config, attribs[0], &value);
   101 		RDebug::Print(_L("eglGetConfigAttrib returned %d"), ret );
   102 		if (ret && value != attribs[1])
   103 			{
   104 			continue;
   105 			}
   106 		ret=eglGetConfigAttrib(iDisplay, config, attribs[2], &value);
   107 		if (ret && value != attribs[3])
   108 			{
   109 			continue;
   110 			}
   111 		ret=eglGetConfigAttrib(iDisplay, config, attribs[4], &value);
   112 		if (ret && value != attribs[5])
   113 			{
   114 			continue;
   115 			}
   116 		ret=eglGetConfigAttrib(iDisplay, config, attribs[6], &value);
   117 		if (ret && value != attribs[7])
   118 			{
   119 			continue;
   120 			}
   121 		ret=eglGetConfigAttrib(iDisplay, config, attribs[8], &value);
   122 		if (ret && value != attribs[9])
   123 			{
   124 			continue;
   125 			}
   126 
   127 		// Success
   128 		configIndex = i;
   129 		break;
   130 		}
   131 
   132 	return configIndex;
   133 	}
   134 
   135 void CEglBase::TestL(const TInt aRet, const TDesC& aMessage)
   136 	{
   137 	if (!aRet)
   138 		{
   139 		RDebug::Print(_L("Error: %d - %S"), aRet, &aMessage);
   140 		User::Leave(KErrUnknown);
   141 		}
   142 	}
   143