1/*------------------------------------------------------------------------- 2 * drawElements Quality Program EGL Module 3 * --------------------------------------- 4 * 5 * Copyright 2014 The Android Open Source Project 6 * 7 * Licensed under the Apache License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 * 19 *//*! 20 * \file 21 * \brief EGL_KHR_surfaceless_context extension tests 22 *//*--------------------------------------------------------------------*/ 23 24#include "teglSurfacelessContextTests.hpp" 25#include "teglSimpleConfigCase.hpp" 26#include "egluStrUtil.hpp" 27#include "tcuTestLog.hpp" 28 29#include <EGL/eglext.h> 30 31#include <string> 32#include <vector> 33#include <algorithm> 34 35#if !defined(EGL_OPENGL_ES3_BIT_KHR) 36# define EGL_OPENGL_ES3_BIT_KHR 0x0040 37#endif 38#if !defined(EGL_CONTEXT_MAJOR_VERSION_KHR) 39# define EGL_CONTEXT_MAJOR_VERSION_KHR EGL_CONTEXT_CLIENT_VERSION 40#endif 41 42using std::vector; 43using std::string; 44using tcu::TestLog; 45 46namespace deqp 47{ 48namespace egl 49{ 50namespace 51{ 52 53class SurfacelessContextCase : public SimpleConfigCase 54{ 55public: 56 SurfacelessContextCase (EglTestContext& eglTestCtx, const char* name, const char* description, const vector<EGLint>& configIds); 57 ~SurfacelessContextCase (void); 58 59 void executeForConfig (tcu::egl::Display& display, EGLConfig config); 60}; 61 62SurfacelessContextCase::SurfacelessContextCase (EglTestContext& eglTestCtx, const char* name, const char* description, const vector<EGLint>& configIds) 63 : SimpleConfigCase(eglTestCtx, name, description, configIds) 64{ 65} 66 67SurfacelessContextCase::~SurfacelessContextCase (void) 68{ 69} 70 71void SurfacelessContextCase::executeForConfig (tcu::egl::Display& display, EGLConfig config) 72{ 73 TestLog& log = m_testCtx.getLog(); 74 const EGLint id = display.getConfigAttrib(config, EGL_CONFIG_ID); 75 const EGLint apiBits = display.getConfigAttrib(config, EGL_RENDERABLE_TYPE); 76 77 static const EGLint es1Attrs[] = { EGL_CONTEXT_CLIENT_VERSION, 1, EGL_NONE }; 78 static const EGLint es2Attrs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; 79 static const EGLint es3Attrs[] = { EGL_CONTEXT_MAJOR_VERSION_KHR, 3, EGL_NONE }; 80 81 static const struct 82 { 83 const char* name; 84 EGLenum api; 85 EGLint apiBit; 86 const EGLint* ctxAttrs; 87 } apis[] = 88 { 89 { "OpenGL", EGL_OPENGL_API, EGL_OPENGL_BIT, DE_NULL }, 90 { "OpenGL ES 1", EGL_OPENGL_ES_API, EGL_OPENGL_ES_BIT, es1Attrs }, 91 { "OpenGL ES 2", EGL_OPENGL_ES_API, EGL_OPENGL_ES2_BIT, es2Attrs }, 92 { "OpenGL ES 3", EGL_OPENGL_ES_API, EGL_OPENGL_ES3_BIT_KHR, es3Attrs }, 93 { "OpenVG", EGL_OPENVG_API, EGL_OPENVG_BIT, DE_NULL } 94 }; 95 96 { 97 vector<string> extensions; 98 display.getExtensions(extensions); 99 100 if (std::find(extensions.begin(), extensions.end(), string("EGL_KHR_surfaceless_context")) == extensions.end()) 101 throw tcu::NotSupportedError("EGL_KHR_surfaceless_context not supported", "", __FILE__, __LINE__); 102 } 103 104 for (int apiNdx = 0; apiNdx < (int)DE_LENGTH_OF_ARRAY(apis); apiNdx++) 105 { 106 if ((apiBits & apis[apiNdx].apiBit) == 0) 107 continue; // Not supported API 108 109 log << TestLog::Message << "Creating " << apis[apiNdx].name << " context with config ID " << id << TestLog::EndMessage; 110 TCU_CHECK_EGL(); 111 112 TCU_CHECK_EGL_CALL(eglBindAPI(apis[apiNdx].api)); 113 114 EGLContext context = eglCreateContext(display.getEGLDisplay(), config, EGL_NO_CONTEXT, apis[apiNdx].ctxAttrs); 115 TCU_CHECK_EGL(); 116 117 if (!eglMakeCurrent(display.getEGLDisplay(), EGL_NO_SURFACE, EGL_NO_SURFACE, context)) 118 { 119 const EGLenum err = eglGetError(); 120 121 if (err == EGL_BAD_MATCH) 122 { 123 log << TestLog::Message << " eglMakeCurrent() failed with EGL_BAD_MATCH. Context doesn't support surfaceless mode." << TestLog::EndMessage; 124 TCU_CHECK_EGL_CALL(eglDestroyContext(display.getEGLDisplay(), context)); 125 continue; 126 } 127 else 128 { 129 log << TestLog::Message << " Fail, context: " << tcu::toHex(context) << ", error: " << eglu::getErrorName(err) << TestLog::EndMessage; 130 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Failed to make context current"); 131 continue; 132 } 133 } 134 135 TCU_CHECK_EGL_CALL(eglMakeCurrent(display.getEGLDisplay(), EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)); 136 137 // Destroy 138 TCU_CHECK_EGL_CALL(eglDestroyContext(display.getEGLDisplay(), context)); 139 log << TestLog::Message << " Pass" << TestLog::EndMessage; 140 } 141} 142 143 144 145} // anonymous 146 147SurfacelessContextTests::SurfacelessContextTests (EglTestContext& eglTestCtx) 148 : TestCaseGroup (eglTestCtx, "surfaceless_context", "EGL_KHR_surfaceless_context extension tests") 149{ 150} 151 152void SurfacelessContextTests::init (void) 153{ 154 vector<NamedConfigIdSet> configIdSets; 155 eglu::FilterList filters; 156 NamedConfigIdSet::getDefaultSets(configIdSets, m_eglTestCtx.getConfigs(), filters); 157 158 for (vector<NamedConfigIdSet>::const_iterator i = configIdSets.begin(); i != configIdSets.end(); i++) 159 addChild(new SurfacelessContextCase(m_eglTestCtx, i->getName(), i->getDescription(), i->getConfigIds())); 160} 161 162} // egl 163} // deqp 164