Romain Guy | bd0e6aa | 2010-07-22 18:50:12 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | |
Romain Guy | bd0e6aa | 2010-07-22 18:50:12 -0700 | [diff] [blame] | 17 | #ifndef ANDROID_UI_EXTENSIONS_H |
| 18 | #define ANDROID_UI_EXTENSIONS_H |
| 19 | |
| 20 | #include <utils/SortedVector.h> |
| 21 | #include <utils/String8.h> |
| 22 | |
| 23 | #include <GLES2/gl2.h> |
| 24 | #include <GLES2/gl2ext.h> |
| 25 | |
| 26 | namespace android { |
| 27 | namespace uirenderer { |
| 28 | |
| 29 | class Extensions { |
| 30 | public: |
| 31 | Extensions() { |
| 32 | const char* buffer = (const char*) glGetString(GL_EXTENSIONS); |
| 33 | const char* current = buffer; |
| 34 | const char* head = current; |
| 35 | do { |
| 36 | head = strchr(current, ' '); |
| 37 | String8 s(current, head ? head - current : strlen(current)); |
| 38 | if (s.length()) { |
| 39 | mExtensionList.add(s); |
| 40 | } |
| 41 | current = head + 1; |
| 42 | } while (head); |
| 43 | |
| 44 | mHasNPot = hasExtension("GL_OES_texture_npot"); |
Romain Guy | 51769a6 | 2010-07-23 00:28:00 -0700 | [diff] [blame] | 45 | mHasDrawPath = hasExtension("GL_NV_draw_path"); |
| 46 | mHasCoverageSample = hasExtension("GL_NV_coverage_sample"); |
| 47 | |
| 48 | mExtensions = buffer; |
Romain Guy | bd0e6aa | 2010-07-22 18:50:12 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | inline bool hasNPot() const { return mHasNPot; } |
Romain Guy | 51769a6 | 2010-07-23 00:28:00 -0700 | [diff] [blame] | 52 | inline bool hasDrawPath() const { return mHasDrawPath; } |
| 53 | inline bool hasCoverageSample() const { return mHasCoverageSample; } |
Romain Guy | bd0e6aa | 2010-07-22 18:50:12 -0700 | [diff] [blame] | 54 | |
| 55 | bool hasExtension(const char* extension) const { |
| 56 | const String8 s(extension); |
| 57 | return mExtensionList.indexOf(s) >= 0; |
| 58 | } |
| 59 | |
Romain Guy | 51769a6 | 2010-07-23 00:28:00 -0700 | [diff] [blame] | 60 | void dump() { |
| 61 | LOGD("Supported extensions:\n%s", mExtensions); |
| 62 | } |
| 63 | |
Romain Guy | bd0e6aa | 2010-07-22 18:50:12 -0700 | [diff] [blame] | 64 | private: |
| 65 | SortedVector<String8> mExtensionList; |
| 66 | |
Romain Guy | 51769a6 | 2010-07-23 00:28:00 -0700 | [diff] [blame] | 67 | const char* mExtensions; |
| 68 | |
Romain Guy | bd0e6aa | 2010-07-22 18:50:12 -0700 | [diff] [blame] | 69 | bool mHasNPot; |
Romain Guy | 51769a6 | 2010-07-23 00:28:00 -0700 | [diff] [blame] | 70 | bool mHasDrawPath; |
| 71 | bool mHasCoverageSample; |
Romain Guy | bd0e6aa | 2010-07-22 18:50:12 -0700 | [diff] [blame] | 72 | }; // class Extensions |
| 73 | |
| 74 | }; // namespace uirenderer |
| 75 | }; // namespace android |
| 76 | |
| 77 | #endif // ANDROID_UI_EXTENSIONS_H |