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