1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "GLESVersionDetector.h" 18 19 #include "DispatchTables.h" 20 21 #include "emugl/common/feature_control.h" 22 23 #include <algorithm> 24 calcMaxVersionFromDispatch()25GLESDispatchMaxVersion calcMaxVersionFromDispatch() { 26 // Detect the proper OpenGL ES version to advertise to the system. 27 // 28 // If the underlying glesv2 library also is on top of system OpenGL, 29 // we assume existence of a function called "gl_dispatch_get_max_version" 30 // which matches the return type of gles2_dispatch_get_max_version, 31 // and allows us to scale back if the underlying host machine 32 // doesn't actually suppport a particular GLES version. 33 if (!emugl_feature_is_enabled(android::featurecontrol::GLESDynamicVersion)) 34 return GLES_DISPATCH_MAX_VERSION_2; 35 36 GLESDispatchMaxVersion underlying_gles2_lib_max = 37 gles2_dispatch_get_max_version(); 38 if (s_gles2.gl_dispatch_get_max_version) { 39 GLESDispatchMaxVersion underlying_gl_lib_max = 40 (GLESDispatchMaxVersion)s_gles2.gl_dispatch_get_max_version(); 41 return std::min(underlying_gl_lib_max, underlying_gles2_lib_max); 42 } else { 43 return underlying_gles2_lib_max; 44 } 45 46 return GLES_DISPATCH_MAX_VERSION_2; 47 } 48