Extensions.cpp revision b47ea9b2ed24f8eb6fc8b338555ff0d8825d8565
1/* 2 * Copyright (C) 2013 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#define LOG_TAG "OpenGLRenderer" 18 19#include "Extensions.h" 20 21#include "Debug.h" 22#include "Properties.h" 23 24#include <EGL/egl.h> 25#include <EGL/eglext.h> 26#include <GLES2/gl2ext.h> 27#include <utils/Log.h> 28 29namespace android { 30 31using namespace uirenderer; 32ANDROID_SINGLETON_STATIC_INSTANCE(Extensions); 33 34namespace uirenderer { 35 36/////////////////////////////////////////////////////////////////////////////// 37// Defines 38/////////////////////////////////////////////////////////////////////////////// 39 40// Debug 41#if DEBUG_EXTENSIONS 42 #define EXT_LOGD(...) ALOGD(__VA_ARGS__) 43#else 44 #define EXT_LOGD(...) 45#endif 46 47/////////////////////////////////////////////////////////////////////////////// 48// Constructors 49/////////////////////////////////////////////////////////////////////////////// 50 51Extensions::Extensions() { 52 // Query GL extensions 53 findExtensions((const char*) glGetString(GL_EXTENSIONS), mGlExtensionList); 54 mHasNPot = hasGlExtension("GL_OES_texture_npot"); 55 mHasFramebufferFetch = hasGlExtension("GL_NV_shader_framebuffer_fetch"); 56 mHasDiscardFramebuffer = hasGlExtension("GL_EXT_discard_framebuffer"); 57 mHasDebugMarker = hasGlExtension("GL_EXT_debug_marker"); 58 mHasTiledRendering = hasGlExtension("GL_QCOM_tiled_rendering"); 59 mHas1BitStencil = hasGlExtension("GL_OES_stencil1"); 60 mHas4BitStencil = hasGlExtension("GL_OES_stencil4"); 61 mHasUnpackSubImage = hasGlExtension("GL_EXT_unpack_subimage"); 62 63 // Query EGL extensions 64 findExtensions(eglQueryString(eglGetCurrentDisplay(), EGL_EXTENSIONS), mEglExtensionList); 65 66 char property[PROPERTY_VALUE_MAX]; 67 if (property_get(PROPERTY_DEBUG_NV_PROFILING, property, nullptr) > 0) { 68 mHasNvSystemTime = !strcmp(property, "true") && hasEglExtension("EGL_NV_system_time"); 69 } else { 70 mHasNvSystemTime = false; 71 } 72 73 const char* version = (const char*) glGetString(GL_VERSION); 74 75 // Section 6.1.5 of the OpenGL ES specification indicates the GL version 76 // string strictly follows this format: 77 // 78 // OpenGL<space>ES<space><version number><space><vendor-specific information> 79 // 80 // In addition section 6.1.5 describes the version number thusly: 81 // 82 // "The version number is either of the form major number.minor number or 83 // major number.minor number.release number, where the numbers all have one 84 // or more digits. The release number and vendor specific information are 85 // optional." 86 87 if (sscanf(version, "OpenGL ES %d.%d", &mVersionMajor, &mVersionMinor) != 2) { 88 // If we cannot parse the version number, assume OpenGL ES 2.0 89 mVersionMajor = 2; 90 mVersionMinor = 0; 91 } 92} 93 94/////////////////////////////////////////////////////////////////////////////// 95// Methods 96/////////////////////////////////////////////////////////////////////////////// 97 98bool Extensions::hasGlExtension(const char* extension) const { 99 const String8 s(extension); 100 return mGlExtensionList.indexOf(s) >= 0; 101} 102 103bool Extensions::hasEglExtension(const char* extension) const { 104 const String8 s(extension); 105 return mEglExtensionList.indexOf(s) >= 0; 106} 107 108void Extensions::findExtensions(const char* extensions, SortedVector<String8>& list) const { 109 const char* current = extensions; 110 const char* head = current; 111 EXT_LOGD("Available extensions:"); 112 do { 113 head = strchr(current, ' '); 114 String8 s(current, head ? head - current : strlen(current)); 115 if (s.length()) { 116 list.add(s); 117 EXT_LOGD(" %s", s.string()); 118 } 119 current = head + 1; 120 } while (head); 121} 122 123void Extensions::dump() const { 124 ALOGD("%s", (const char*) glGetString(GL_VERSION)); 125 ALOGD("Supported GL extensions:\n%s", (const char*) glGetString(GL_EXTENSIONS)); 126 ALOGD("Supported EGL extensions:\n%s", eglQueryString(eglGetCurrentDisplay(), EGL_EXTENSIONS)); 127} 128 129}; // namespace uirenderer 130}; // namespace android 131