1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/windowing/windowserver/test/t_integ/src/t_pseudoappeglbase.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,143 @@
1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +/**
1.20 + @file
1.21 + @test
1.22 + @internalComponent
1.23 +*/
1.24 +
1.25 +#include <e32debug.h>
1.26 +#include "t_pseudoappeglbase.h"
1.27 +
1.28 +const TInt KMaxConfigs = 1024;
1.29 +
1.30 +CEglBase::CEglBase(const TDisplayMode& aMode,const TSize& aSurfaceSz, const TInt aHRate, const TInt aVRate)
1.31 + : CTestAnimation(),iDispMode(aMode)
1.32 + {
1.33 + iSurfaceSize=aSurfaceSz;
1.34 + iHorizontalRate=aHRate;
1.35 + iVerticalRate=aVRate;
1.36 + }
1.37 +
1.38 +void CEglBase::BaseConstructL(RWindow* aWin)
1.39 + {
1.40 + // eglGetDisplay
1.41 + iDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
1.42 + TestL(iDisplay!=EGL_NO_DISPLAY, _L("eglGetDisplay failed"));
1.43 +
1.44 + // eglInitialize
1.45 + TInt ret = eglInitialize(iDisplay, NULL, NULL);
1.46 + TestL(ret, _L("eglInitialize failed"));
1.47 +
1.48 + // eglGetConfigs
1.49 + EGLint numConfigs;
1.50 + EGLConfig configs[KMaxConfigs];
1.51 + ret = eglGetConfigs(iDisplay, configs, KMaxConfigs, &numConfigs);
1.52 + TestL(ret, _L("eglGetConfigs failed"));
1.53 + TestL(numConfigs>0, _L("eglGetConfigs returned no configs"));
1.54 +
1.55 + const EGLint* attribList = NULL;
1.56 +
1.57 + // Select attribs based on current display mode
1.58 + switch (iDispMode)
1.59 + {
1.60 + case EColor4K: attribList = KColor4KAttribList; break;
1.61 + case EColor64K: attribList = KColor64KAttribList; break;
1.62 + case EColor16M: attribList = KColor16MAttribList; break;
1.63 + case EColor16MA:attribList = KColor16MAAttribList; break;
1.64 + default: User::Panic(_L("CEglBase"), KErrArgument);
1.65 + }
1.66 +
1.67 + RDebug::Print(_L("Display Mode: %d"), iDispMode );
1.68 +
1.69 + // eglChooseConfig
1.70 + ret=eglChooseConfig(iDisplay, attribList, configs, KMaxConfigs, &numConfigs);
1.71 + TestL(ret, _L("eglChooseConfig failed"));
1.72 + TestL(numConfigs>0, _L("eglChooseConfig returned no configs"));
1.73 +
1.74 + if (attribList)
1.75 + {
1.76 + TInt configIndex = GetSuitableConfig(configs, numConfigs, attribList);
1.77 + TestL(configIndex!=KErrNotFound, _L("No suitable configuration found") );
1.78 + iUseConfig = configs[configIndex];
1.79 + }
1.80 +
1.81 + // eglCreateWindowSurface
1.82 + iSurface = eglCreateWindowSurface(iDisplay, iUseConfig, aWin, NULL);
1.83 + TestL(iSurface!=EGL_NO_SURFACE, _L("eglCreateWindowSurface failed") );
1.84 + }
1.85 +
1.86 +CEglBase::~CEglBase()
1.87 + {
1.88 + // Clean everything allocated.
1.89 + eglMakeCurrent(iDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
1.90 + eglDestroyContext(iDisplay, iContext);
1.91 + eglDestroySurface(iDisplay, iSurface);
1.92 + eglTerminate(iDisplay);
1.93 + }
1.94 +
1.95 +TInt CEglBase::GetSuitableConfig(const EGLConfig* aConfigs, EGLint aNumConfigs, const EGLint* attribs)
1.96 + {
1.97 + TInt configIndex = KErrNotFound;
1.98 + for (TInt i=0; i<aNumConfigs; i++)
1.99 + {
1.100 + EGLConfig config = aConfigs[i];
1.101 + EGLint value;
1.102 +
1.103 + TInt ret=eglGetConfigAttrib(iDisplay, config, attribs[0], &value);
1.104 + RDebug::Print(_L("eglGetConfigAttrib returned %d"), ret );
1.105 + if (ret && value != attribs[1])
1.106 + {
1.107 + continue;
1.108 + }
1.109 + ret=eglGetConfigAttrib(iDisplay, config, attribs[2], &value);
1.110 + if (ret && value != attribs[3])
1.111 + {
1.112 + continue;
1.113 + }
1.114 + ret=eglGetConfigAttrib(iDisplay, config, attribs[4], &value);
1.115 + if (ret && value != attribs[5])
1.116 + {
1.117 + continue;
1.118 + }
1.119 + ret=eglGetConfigAttrib(iDisplay, config, attribs[6], &value);
1.120 + if (ret && value != attribs[7])
1.121 + {
1.122 + continue;
1.123 + }
1.124 + ret=eglGetConfigAttrib(iDisplay, config, attribs[8], &value);
1.125 + if (ret && value != attribs[9])
1.126 + {
1.127 + continue;
1.128 + }
1.129 +
1.130 + // Success
1.131 + configIndex = i;
1.132 + break;
1.133 + }
1.134 +
1.135 + return configIndex;
1.136 + }
1.137 +
1.138 +void CEglBase::TestL(const TInt aRet, const TDesC& aMessage)
1.139 + {
1.140 + if (!aRet)
1.141 + {
1.142 + RDebug::Print(_L("Error: %d - %S"), aRet, &aMessage);
1.143 + User::Leave(KErrUnknown);
1.144 + }
1.145 + }
1.146 +