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