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 | |
| 17 | #include "Debug.h" |
| 18 | #include "Extensions.h" |
| 19 | |
| 20 | namespace android { |
| 21 | |
| 22 | using namespace uirenderer; |
| 23 | ANDROID_SINGLETON_STATIC_INSTANCE(Extensions); |
| 24 | |
| 25 | namespace uirenderer { |
| 26 | |
| 27 | /////////////////////////////////////////////////////////////////////////////// |
| 28 | // Defines |
| 29 | /////////////////////////////////////////////////////////////////////////////// |
| 30 | |
| 31 | // Debug |
| 32 | #if DEBUG_EXTENSIONS |
| 33 | #define EXT_LOGD(...) ALOGD(__VA_ARGS__) |
| 34 | #else |
| 35 | #define EXT_LOGD(...) |
| 36 | #endif |
| 37 | |
| 38 | /////////////////////////////////////////////////////////////////////////////// |
| 39 | // Constructors |
| 40 | /////////////////////////////////////////////////////////////////////////////// |
| 41 | |
| 42 | Extensions::Extensions(): Singleton<Extensions>() { |
| 43 | const char* buffer = (const char*) glGetString(GL_EXTENSIONS); |
| 44 | const char* current = buffer; |
| 45 | const char* head = current; |
| 46 | EXT_LOGD("Available GL extensions:"); |
| 47 | do { |
| 48 | head = strchr(current, ' '); |
| 49 | String8 s(current, head ? head - current : strlen(current)); |
| 50 | if (s.length()) { |
| 51 | mExtensionList.add(s); |
| 52 | EXT_LOGD(" %s", s.string()); |
| 53 | } |
| 54 | current = head + 1; |
| 55 | } while (head); |
| 56 | |
| 57 | mHasNPot = hasExtension("GL_OES_texture_npot"); |
| 58 | mHasFramebufferFetch = hasExtension("GL_NV_shader_framebuffer_fetch"); |
| 59 | mHasDiscardFramebuffer = hasExtension("GL_EXT_discard_framebuffer"); |
| 60 | mHasDebugMarker = hasExtension("GL_EXT_debug_marker"); |
| 61 | mHasDebugLabel = hasExtension("GL_EXT_debug_label"); |
| 62 | mHasTiledRendering = hasExtension("GL_QCOM_tiled_rendering"); |
| 63 | mHas1BitStencil = hasExtension("GL_OES_stencil1"); |
| 64 | mHas4BitStencil = hasExtension("GL_OES_stencil4"); |
| 65 | |
| 66 | mExtensions = strdup(buffer); |
Romain Guy | df1dc28 | 2013-03-29 18:32:29 -0700 | [diff] [blame^] | 67 | |
| 68 | const char* version = (const char*) glGetString(GL_VERSION); |
| 69 | mVersion = strdup(version); |
| 70 | |
| 71 | // Section 6.1.5 of the OpenGL ES specification indicates the GL version |
| 72 | // string strictly follows this format: |
| 73 | // |
| 74 | // OpenGL<space>ES<space><version number><space><vendor-specific information> |
| 75 | // |
| 76 | // In addition section 6.1.5 describes the version number thusly: |
| 77 | // |
| 78 | // "The version number is either of the form major number.minor number or |
| 79 | // major number.minor number.release number, where the numbers all have one |
| 80 | // or more digits. The release number and vendor specific information are |
| 81 | // optional." |
| 82 | |
| 83 | if (sscanf(version, "OpenGL ES %d.%d", &mVersionMajor, &mVersionMinor) !=2) { |
| 84 | // If we cannot parse the version number, assume OpenGL ES 2.0 |
| 85 | mVersionMajor = 2; |
| 86 | mVersionMinor = 0; |
| 87 | } |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | Extensions::~Extensions() { |
| 91 | free(mExtensions); |
Romain Guy | df1dc28 | 2013-03-29 18:32:29 -0700 | [diff] [blame^] | 92 | free(mVersion); |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | /////////////////////////////////////////////////////////////////////////////// |
| 96 | // Methods |
| 97 | /////////////////////////////////////////////////////////////////////////////// |
| 98 | |
| 99 | bool Extensions::hasExtension(const char* extension) const { |
| 100 | const String8 s(extension); |
| 101 | return mExtensionList.indexOf(s) >= 0; |
| 102 | } |
| 103 | |
| 104 | void Extensions::dump() const { |
Romain Guy | df1dc28 | 2013-03-29 18:32:29 -0700 | [diff] [blame^] | 105 | ALOGD("%s", mVersion); |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 106 | ALOGD("Supported extensions:\n%s", mExtensions); |
| 107 | } |
| 108 | |
| 109 | }; // namespace uirenderer |
| 110 | }; // namespace android |