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