1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program Platform Utilites
3 * ----------------------------------------------
5 * Copyright 2015 The Android Open Source Project
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * \brief Android platform capability query JNI component
22 *//*--------------------------------------------------------------------*/
24 #include "tcuDefs.hpp"
26 #include "tcuCommandLine.hpp"
27 #include "gluRenderConfig.hpp"
28 #include "gluRenderContext.hpp"
29 #include "eglwLibrary.hpp"
30 #include "eglwEnums.hpp"
31 #include "egluUtil.hpp"
32 #include "egluGLUtil.hpp"
41 DE_DECLARE_COMMAND_LINE_OPT(GLMajorVersion, int);
42 DE_DECLARE_COMMAND_LINE_OPT(GLMinorVersion, int);
46 class GLConfigParser : public tcu::CommandLine
49 GLConfigParser (const std::string& argString);
51 bool hasGLMajorVersion (void) const;
52 bool hasGLMinorVersion (void) const;
53 int getGLMajorVersion (void) const;
54 int getGLMinorVersion (void) const;
57 virtual void registerExtendedOptions (de::cmdline::Parser& parser);
60 GLConfigParser::GLConfigParser (const std::string& argString)
62 const std::string execString = "fakebinaryname " + argString; // convert argument list to full command line
64 if (!parse(execString))
66 tcu::print("failed to parse command line");
67 TCU_THROW(Exception, "failed to parse command line");
71 bool GLConfigParser::hasGLMajorVersion (void) const
73 return getCommandLine().hasOption<opt::GLMajorVersion>();
76 bool GLConfigParser::hasGLMinorVersion (void) const
78 return getCommandLine().hasOption<opt::GLMinorVersion>();
81 int GLConfigParser::getGLMajorVersion (void) const
83 DE_ASSERT(hasGLMajorVersion());
84 return getCommandLine().getOption<opt::GLMajorVersion>();
87 int GLConfigParser::getGLMinorVersion (void) const
89 DE_ASSERT(hasGLMinorVersion());
90 return getCommandLine().getOption<opt::GLMinorVersion>();
93 void GLConfigParser::registerExtendedOptions (de::cmdline::Parser& parser)
95 using de::cmdline::Option;
98 << Option<opt::GLMajorVersion> (DE_NULL, "deqp-gl-major-version", "OpenGL ES Major version")
99 << Option<opt::GLMinorVersion> (DE_NULL, "deqp-gl-minor-version", "OpenGL ES Minor version");
102 glu::RenderConfig parseRenderConfig (const std::string& argsStr)
104 const GLConfigParser parsedCommandLine (argsStr);
106 if (!parsedCommandLine.hasGLMajorVersion() ||
107 !parsedCommandLine.hasGLMinorVersion())
109 tcu::print("minor and major version must be supplied");
110 TCU_THROW(Exception, "minor and major version must be supplied");
114 const glu::ContextType testContextType (glu::ApiType::es(parsedCommandLine.getGLMajorVersion(), parsedCommandLine.getGLMinorVersion()));
115 glu::RenderConfig renderConfig (testContextType);
117 glu::parseRenderConfig(&renderConfig, parsedCommandLine);
123 bool isRenderConfigSupported (const std::string& cmdLineStr)
125 const glu::RenderConfig renderConfig = parseRenderConfig(cmdLineStr);
126 const eglw::DefaultLibrary egl;
127 const eglw::EGLDisplay display = egl.getDisplay(EGL_DEFAULT_DISPLAY);
128 eglw::EGLint eglMajor = -1;
129 eglw::EGLint eglMinor = -1;
131 if (display == EGL_NO_DISPLAY)
133 tcu::print("could not get default display");
134 TCU_THROW(Exception, "could not get default display");
137 if (egl.initialize(display, &eglMajor, &eglMinor) != EGL_TRUE)
139 tcu::print("failed to initialize egl");
140 TCU_THROW(Exception, "failed to initialize egl");
142 tcu::print("EGL initialized, major=%d, minor=%d", eglMajor, eglMinor);
146 // ignoring return value
147 (void)eglu::chooseConfig(egl, display, renderConfig);
149 catch (const tcu::NotSupportedError&)
151 tcu::print("No matching config");
152 egl.terminate(display);
157 egl.terminate(display);
160 egl.terminate(display);
170 JNIEXPORT jint JNICALL Java_com_drawelements_deqp_platformutil_DeqpPlatformCapabilityQueryInstrumentation_nativeRenderConfigSupportedQuery (JNIEnv* env, jclass, jstring jCmdLine)
174 CONFIGQUERYRESULT_SUPPORTED = 0,
175 CONFIGQUERYRESULT_NOT_SUPPORTED = 1,
176 CONFIGQUERYRESULT_GENERIC_ERROR = -1,
180 const char* const cmdLineBytes = env->GetStringUTFChars(jCmdLine, DE_NULL);
182 if (cmdLineBytes == DE_NULL)
184 // no command line is not executable
185 tcu::print("no command line supplied");
186 return CONFIGQUERYRESULT_GENERIC_ERROR;
191 // try to copy to local buffer
192 cmdLine = std::string(cmdLineBytes);
194 catch (const std::bad_alloc&)
196 env->ReleaseStringUTFChars(jCmdLine, cmdLineBytes);
197 tcu::print("failed to copy cmdLine");
198 return CONFIGQUERYRESULT_GENERIC_ERROR;
200 env->ReleaseStringUTFChars(jCmdLine, cmdLineBytes);
204 const bool isSupported = isRenderConfigSupported(cmdLine);
206 return (isSupported) ? (CONFIGQUERYRESULT_SUPPORTED)
207 : (CONFIGQUERYRESULT_NOT_SUPPORTED);
209 catch (const std::exception& ex)
211 // don't bother forwarding the exception to the caller. They cannot do anything with the exception anyway.
212 tcu::print("Error: %s", ex.what());
213 return CONFIGQUERYRESULT_GENERIC_ERROR;