Extensions.h revision 13631f3da855f200a151e7837ed9f6b079622b58
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 17#ifndef ANDROID_HWUI_EXTENSIONS_H 18#define ANDROID_HWUI_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#include "Debug.h" 27 28namespace android { 29namespace uirenderer { 30 31/////////////////////////////////////////////////////////////////////////////// 32// Defines 33/////////////////////////////////////////////////////////////////////////////// 34 35// Debug 36#if DEBUG_EXTENSIONS 37 #define EXT_LOGD(...) ALOGD(__VA_ARGS__) 38#else 39 #define EXT_LOGD(...) 40#endif 41 42// Vendor strings 43 44#define VENDOR_IMG "Imagination Technologies" 45 46/////////////////////////////////////////////////////////////////////////////// 47// Classes 48/////////////////////////////////////////////////////////////////////////////// 49 50class Extensions { 51public: 52 Extensions() { 53 const char* buffer = (const char*) glGetString(GL_EXTENSIONS); 54 const char* current = buffer; 55 const char* head = current; 56 EXT_LOGD("Available GL extensions:"); 57 do { 58 head = strchr(current, ' '); 59 String8 s(current, head ? head - current : strlen(current)); 60 if (s.length()) { 61 mExtensionList.add(s); 62 EXT_LOGD(" %s", s.string()); 63 } 64 current = head + 1; 65 } while (head); 66 67 mHasNPot = hasExtension("GL_OES_texture_npot"); 68 mHasFramebufferFetch = hasExtension("GL_NV_shader_framebuffer_fetch"); 69 mHasDiscardFramebuffer = hasExtension("GL_EXT_discard_framebuffer"); 70 mHasDebugMarker = hasExtension("GL_EXT_debug_marker"); 71 72 const char* vendor = (const char*) glGetString(GL_VENDOR); 73 EXT_LOGD("Vendor: %s", vendor); 74 mNeedsHighpTexCoords = strcmp(vendor, VENDOR_IMG) == 0; 75 76 // We don't need to copy the string, the OpenGL ES spec 77 // guarantees the result of glGetString to point to a 78 // static string as long as our OpenGL context is valid 79 mExtensions = buffer; 80 } 81 82 inline bool hasNPot() const { return mHasNPot; } 83 inline bool hasFramebufferFetch() const { return mHasFramebufferFetch; } 84 inline bool needsHighpTexCoords() const { return mNeedsHighpTexCoords; } 85 inline bool hasDiscardFramebuffer() const { return mHasDiscardFramebuffer; } 86 inline bool hasDebugMarker() const { return mHasDebugMarker; } 87 88 bool hasExtension(const char* extension) const { 89 const String8 s(extension); 90 return mExtensionList.indexOf(s) >= 0; 91 } 92 93 void dump() { 94 ALOGD("Supported extensions:\n%s", mExtensions); 95 } 96 97private: 98 SortedVector<String8> mExtensionList; 99 100 const char* mExtensions; 101 102 bool mHasNPot; 103 bool mNeedsHighpTexCoords; 104 bool mHasFramebufferFetch; 105 bool mHasDiscardFramebuffer; 106 bool mHasDebugMarker; 107}; // class Extensions 108 109}; // namespace uirenderer 110}; // namespace android 111 112#endif // ANDROID_HWUI_EXTENSIONS_H 113