Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 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 | |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 17 | #include "Extensions.h" |
| 18 | |
| 19 | #include "Debug.h" |
| 20 | #include "Properties.h" |
Romain Guy | e9bc11f | 2013-05-23 12:47:26 -0700 | [diff] [blame] | 21 | |
| 22 | #include <EGL/egl.h> |
| 23 | #include <EGL/eglext.h> |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 24 | #include <GLES2/gl2ext.h> |
Romain Guy | e9bc11f | 2013-05-23 12:47:26 -0700 | [diff] [blame] | 25 | #include <utils/Log.h> |
| 26 | |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 27 | namespace android { |
| 28 | |
| 29 | using namespace uirenderer; |
| 30 | ANDROID_SINGLETON_STATIC_INSTANCE(Extensions); |
| 31 | |
| 32 | namespace 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 | |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 49 | Extensions::Extensions() { |
Romain Guy | e9bc11f | 2013-05-23 12:47:26 -0700 | [diff] [blame] | 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"); |
Romain Guy | e9bc11f | 2013-05-23 12:47:26 -0700 | [diff] [blame] | 56 | mHasTiledRendering = hasGlExtension("GL_QCOM_tiled_rendering"); |
| 57 | mHas1BitStencil = hasGlExtension("GL_OES_stencil1"); |
| 58 | mHas4BitStencil = hasGlExtension("GL_OES_stencil4"); |
xiaozhengdong | d538d30 | 2015-08-04 16:55:35 +0800 | [diff] [blame] | 59 | mHasUnpackSubImage = hasGlExtension("GL_EXT_unpack_subimage"); |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 60 | |
Romain Guy | e9bc11f | 2013-05-23 12:47:26 -0700 | [diff] [blame] | 61 | // Query EGL extensions |
| 62 | findExtensions(eglQueryString(eglGetCurrentDisplay(), EGL_EXTENSIONS), mEglExtensionList); |
Romain Guy | 31e08e9 | 2013-06-18 15:53:53 -0700 | [diff] [blame] | 63 | |
| 64 | char property[PROPERTY_VALUE_MAX]; |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 65 | if (property_get(PROPERTY_DEBUG_NV_PROFILING, property, nullptr) > 0) { |
Romain Guy | 31e08e9 | 2013-06-18 15:53:53 -0700 | [diff] [blame] | 66 | mHasNvSystemTime = !strcmp(property, "true") && hasEglExtension("EGL_NV_system_time"); |
| 67 | } else { |
| 68 | mHasNvSystemTime = false; |
| 69 | } |
Romain Guy | df1dc28 | 2013-03-29 18:32:29 -0700 | [diff] [blame] | 70 | |
| 71 | const char* version = (const char*) glGetString(GL_VERSION); |
Romain Guy | df1dc28 | 2013-03-29 18:32:29 -0700 | [diff] [blame] | 72 | |
| 73 | // Section 6.1.5 of the OpenGL ES specification indicates the GL version |
| 74 | // string strictly follows this format: |
| 75 | // |
| 76 | // OpenGL<space>ES<space><version number><space><vendor-specific information> |
| 77 | // |
| 78 | // In addition section 6.1.5 describes the version number thusly: |
| 79 | // |
| 80 | // "The version number is either of the form major number.minor number or |
| 81 | // major number.minor number.release number, where the numbers all have one |
| 82 | // or more digits. The release number and vendor specific information are |
| 83 | // optional." |
| 84 | |
Romain Guy | 6cad757 | 2013-07-24 11:49:33 -0700 | [diff] [blame] | 85 | if (sscanf(version, "OpenGL ES %d.%d", &mVersionMajor, &mVersionMinor) != 2) { |
Romain Guy | df1dc28 | 2013-03-29 18:32:29 -0700 | [diff] [blame] | 86 | // If we cannot parse the version number, assume OpenGL ES 2.0 |
| 87 | mVersionMajor = 2; |
| 88 | mVersionMinor = 0; |
| 89 | } |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 90 | } |
| 91 | |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 92 | /////////////////////////////////////////////////////////////////////////////// |
| 93 | // Methods |
| 94 | /////////////////////////////////////////////////////////////////////////////// |
| 95 | |
Romain Guy | e9bc11f | 2013-05-23 12:47:26 -0700 | [diff] [blame] | 96 | bool Extensions::hasGlExtension(const char* extension) const { |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 97 | const String8 s(extension); |
Romain Guy | e9bc11f | 2013-05-23 12:47:26 -0700 | [diff] [blame] | 98 | return mGlExtensionList.indexOf(s) >= 0; |
| 99 | } |
| 100 | |
| 101 | bool Extensions::hasEglExtension(const char* extension) const { |
| 102 | const String8 s(extension); |
| 103 | return mEglExtensionList.indexOf(s) >= 0; |
| 104 | } |
| 105 | |
| 106 | void Extensions::findExtensions(const char* extensions, SortedVector<String8>& list) const { |
| 107 | const char* current = extensions; |
| 108 | const char* head = current; |
| 109 | EXT_LOGD("Available extensions:"); |
| 110 | do { |
| 111 | head = strchr(current, ' '); |
| 112 | String8 s(current, head ? head - current : strlen(current)); |
| 113 | if (s.length()) { |
| 114 | list.add(s); |
| 115 | EXT_LOGD(" %s", s.string()); |
| 116 | } |
| 117 | current = head + 1; |
| 118 | } while (head); |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | void Extensions::dump() const { |
Romain Guy | e9bc11f | 2013-05-23 12:47:26 -0700 | [diff] [blame] | 122 | ALOGD("%s", (const char*) glGetString(GL_VERSION)); |
| 123 | ALOGD("Supported GL extensions:\n%s", (const char*) glGetString(GL_EXTENSIONS)); |
| 124 | ALOGD("Supported EGL extensions:\n%s", eglQueryString(eglGetCurrentDisplay(), EGL_EXTENSIONS)); |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | }; // namespace uirenderer |
| 128 | }; // namespace android |