xref: /aosp_15_r20/external/deqp/modules/egl/teglSurfacelessContextTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
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 
27 #include "egluStrUtil.hpp"
28 #include "egluUtil.hpp"
29 #include "egluUnique.hpp"
30 
31 #include "tcuTestLog.hpp"
32 
33 #include "eglwLibrary.hpp"
34 #include "eglwEnums.hpp"
35 
36 #include "deSTLUtil.hpp"
37 
38 #include <string>
39 #include <vector>
40 #include <algorithm>
41 
42 using std::string;
43 using std::vector;
44 using tcu::TestLog;
45 
46 using namespace eglw;
47 
48 namespace deqp
49 {
50 namespace egl
51 {
52 namespace
53 {
54 
55 class SurfacelessContextCase : public SimpleConfigCase
56 {
57 public:
58     SurfacelessContextCase(EglTestContext &eglTestCtx, const char *name, const char *description,
59                            const eglu::FilterList &filters);
60     ~SurfacelessContextCase(void);
61 
62     void executeForConfig(EGLDisplay display, EGLConfig config);
63 };
64 
SurfacelessContextCase(EglTestContext & eglTestCtx,const char * name,const char * description,const eglu::FilterList & filters)65 SurfacelessContextCase::SurfacelessContextCase(EglTestContext &eglTestCtx, const char *name, const char *description,
66                                                const eglu::FilterList &filters)
67     : SimpleConfigCase(eglTestCtx, name, description, filters)
68 {
69 }
70 
~SurfacelessContextCase(void)71 SurfacelessContextCase::~SurfacelessContextCase(void)
72 {
73 }
74 
executeForConfig(EGLDisplay display,EGLConfig config)75 void SurfacelessContextCase::executeForConfig(EGLDisplay display, EGLConfig config)
76 {
77     const Library &egl   = m_eglTestCtx.getLibrary();
78     TestLog &log         = m_testCtx.getLog();
79     const EGLint id      = eglu::getConfigAttribInt(egl, display, config, EGL_CONFIG_ID);
80     const EGLint apiBits = eglu::getConfigAttribInt(egl, display, config, EGL_RENDERABLE_TYPE);
81 
82     static const EGLint es1Attrs[] = {EGL_CONTEXT_CLIENT_VERSION, 1, EGL_NONE};
83     static const EGLint es2Attrs[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
84     static const EGLint es3Attrs[] = {EGL_CONTEXT_MAJOR_VERSION_KHR, 3, EGL_NONE};
85 
86     static const struct
87     {
88         const char *name;
89         EGLenum api;
90         EGLint apiBit;
91         const EGLint *ctxAttrs;
92     } apis[] = {{"OpenGL", EGL_OPENGL_API, EGL_OPENGL_BIT, DE_NULL},
93                 {"OpenGL ES 1", EGL_OPENGL_ES_API, EGL_OPENGL_ES_BIT, es1Attrs},
94                 {"OpenGL ES 2", EGL_OPENGL_ES_API, EGL_OPENGL_ES2_BIT, es2Attrs},
95                 {"OpenGL ES 3", EGL_OPENGL_ES_API, EGL_OPENGL_ES3_BIT_KHR, es3Attrs},
96                 {"OpenVG", EGL_OPENVG_API, EGL_OPENVG_BIT, DE_NULL}};
97 
98     if (!eglu::hasExtension(egl, display, "EGL_KHR_surfaceless_context"))
99         TCU_THROW(NotSupportedError, "EGL_KHR_surfaceless_context not supported");
100 
101     for (int apiNdx = 0; apiNdx < (int)DE_LENGTH_OF_ARRAY(apis); apiNdx++)
102     {
103         if ((apiBits & apis[apiNdx].apiBit) == 0)
104             continue; // Not supported API
105 
106         log << TestLog::Message << "Creating " << apis[apiNdx].name << " context with config ID " << id
107             << TestLog::EndMessage;
108 
109         EGLU_CHECK_CALL(egl, bindAPI(apis[apiNdx].api));
110 
111         eglu::UniqueContext context(egl, display,
112                                     egl.createContext(display, config, EGL_NO_CONTEXT, apis[apiNdx].ctxAttrs));
113         EGLU_CHECK_MSG(egl, "eglCreateContext()");
114 
115         if (!egl.makeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, *context))
116         {
117             const EGLenum err = egl.getError();
118 
119             if (err == EGL_BAD_MATCH)
120             {
121                 log << TestLog::Message
122                     << "  eglMakeCurrent() failed with EGL_BAD_MATCH. Context doesn't support surfaceless mode."
123                     << TestLog::EndMessage;
124                 continue;
125             }
126             else
127             {
128                 log << TestLog::Message << "  Fail, context: " << tcu::toHex(*context)
129                     << ", 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         EGLU_CHECK_CALL(egl, makeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
136 
137         log << TestLog::Message << "  Pass" << TestLog::EndMessage;
138     }
139 }
140 
141 } // namespace
142 
SurfacelessContextTests(EglTestContext & eglTestCtx)143 SurfacelessContextTests::SurfacelessContextTests(EglTestContext &eglTestCtx)
144     : TestCaseGroup(eglTestCtx, "surfaceless_context", "EGL_KHR_surfaceless_context extension tests")
145 {
146 }
147 
init(void)148 void SurfacelessContextTests::init(void)
149 {
150     vector<NamedFilterList> filterLists;
151     getDefaultFilterLists(filterLists, eglu::FilterList());
152 
153     for (vector<NamedFilterList>::const_iterator i = filterLists.begin(); i != filterLists.end(); i++)
154         addChild(new SurfacelessContextCase(m_eglTestCtx, i->getName(), i->getDescription(), *i));
155 }
156 
157 } // namespace egl
158 } // namespace deqp
159