blob: f11fecc7ae9c186f696c3e42305c8f5eb8e089c6 [file] [log] [blame]
Romain Guybd0e6aa2010-07-22 18:50:12 -07001/*
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 Guy5b3b3522010-10-27 18:57:51 -070017#ifndef ANDROID_HWUI_EXTENSIONS_H
18#define ANDROID_HWUI_EXTENSIONS_H
Romain Guybd0e6aa2010-07-22 18:50:12 -070019
20#include <utils/SortedVector.h>
21#include <utils/String8.h>
22
23#include <GLES2/gl2.h>
24#include <GLES2/gl2ext.h>
25
Romain Guya60c3882011-08-01 15:28:16 -070026#include "Debug.h"
27
Romain Guybd0e6aa2010-07-22 18:50:12 -070028namespace android {
29namespace uirenderer {
30
Romain Guya5aed0d2010-09-09 14:42:43 -070031///////////////////////////////////////////////////////////////////////////////
32// Defines
33///////////////////////////////////////////////////////////////////////////////
34
35// Debug
Romain Guya5aed0d2010-09-09 14:42:43 -070036#if DEBUG_EXTENSIONS
Steve Block5baa3a62011-12-20 16:23:08 +000037 #define EXT_LOGD(...) ALOGD(__VA_ARGS__)
Romain Guya5aed0d2010-09-09 14:42:43 -070038#else
39 #define EXT_LOGD(...)
40#endif
41
Romain Guya60c3882011-08-01 15:28:16 -070042// Vendor strings
43
44#define VENDOR_IMG "Imagination Technologies"
45
46///////////////////////////////////////////////////////////////////////////////
47// Classes
48///////////////////////////////////////////////////////////////////////////////
49
Romain Guybd0e6aa2010-07-22 18:50:12 -070050class Extensions {
51public:
52 Extensions() {
53 const char* buffer = (const char*) glGetString(GL_EXTENSIONS);
54 const char* current = buffer;
55 const char* head = current;
Romain Guya5aed0d2010-09-09 14:42:43 -070056 EXT_LOGD("Available GL extensions:");
Romain Guybd0e6aa2010-07-22 18:50:12 -070057 do {
58 head = strchr(current, ' ');
59 String8 s(current, head ? head - current : strlen(current));
60 if (s.length()) {
61 mExtensionList.add(s);
Romain Guya5aed0d2010-09-09 14:42:43 -070062 EXT_LOGD(" %s", s.string());
Romain Guybd0e6aa2010-07-22 18:50:12 -070063 }
64 current = head + 1;
65 } while (head);
66
67 mHasNPot = hasExtension("GL_OES_texture_npot");
Romain Guya5aed0d2010-09-09 14:42:43 -070068 mHasFramebufferFetch = hasExtension("GL_NV_shader_framebuffer_fetch");
Romain Guy9c4b79a2011-11-10 19:23:58 -080069 mHasDiscardFramebuffer = hasExtension("GL_EXT_discard_framebuffer");
Romain Guy13631f32012-01-30 17:41:55 -080070 mHasDebugMarker = hasExtension("GL_EXT_debug_marker");
Romain Guy51769a62010-07-23 00:28:00 -070071
Romain Guya60c3882011-08-01 15:28:16 -070072 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
Romain Guy51769a62010-07-23 00:28:00 -070079 mExtensions = buffer;
Romain Guybd0e6aa2010-07-22 18:50:12 -070080 }
81
82 inline bool hasNPot() const { return mHasNPot; }
Romain Guya5aed0d2010-09-09 14:42:43 -070083 inline bool hasFramebufferFetch() const { return mHasFramebufferFetch; }
Romain Guya60c3882011-08-01 15:28:16 -070084 inline bool needsHighpTexCoords() const { return mNeedsHighpTexCoords; }
Romain Guy9c4b79a2011-11-10 19:23:58 -080085 inline bool hasDiscardFramebuffer() const { return mHasDiscardFramebuffer; }
Romain Guy13631f32012-01-30 17:41:55 -080086 inline bool hasDebugMarker() const { return mHasDebugMarker; }
Romain Guybd0e6aa2010-07-22 18:50:12 -070087
88 bool hasExtension(const char* extension) const {
89 const String8 s(extension);
90 return mExtensionList.indexOf(s) >= 0;
91 }
92
Romain Guy51769a62010-07-23 00:28:00 -070093 void dump() {
Steve Block5baa3a62011-12-20 16:23:08 +000094 ALOGD("Supported extensions:\n%s", mExtensions);
Romain Guy51769a62010-07-23 00:28:00 -070095 }
96
Romain Guybd0e6aa2010-07-22 18:50:12 -070097private:
98 SortedVector<String8> mExtensionList;
99
Romain Guy51769a62010-07-23 00:28:00 -0700100 const char* mExtensions;
101
Romain Guybd0e6aa2010-07-22 18:50:12 -0700102 bool mHasNPot;
Romain Guya60c3882011-08-01 15:28:16 -0700103 bool mNeedsHighpTexCoords;
Romain Guya5aed0d2010-09-09 14:42:43 -0700104 bool mHasFramebufferFetch;
Romain Guy9c4b79a2011-11-10 19:23:58 -0800105 bool mHasDiscardFramebuffer;
Romain Guy13631f32012-01-30 17:41:55 -0800106 bool mHasDebugMarker;
Romain Guybd0e6aa2010-07-22 18:50:12 -0700107}; // class Extensions
108
109}; // namespace uirenderer
110}; // namespace android
111
Romain Guy5b3b3522010-10-27 18:57:51 -0700112#endif // ANDROID_HWUI_EXTENSIONS_H