blob: bdaa3cc06aa8710d06b6b7fb36c1acab85515e18 [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///////////////////////////////////////////////////////////////////////////////
43// Classes
44///////////////////////////////////////////////////////////////////////////////
45
Romain Guybd0e6aa2010-07-22 18:50:12 -070046class Extensions {
47public:
48 Extensions() {
49 const char* buffer = (const char*) glGetString(GL_EXTENSIONS);
50 const char* current = buffer;
51 const char* head = current;
Romain Guya5aed0d2010-09-09 14:42:43 -070052 EXT_LOGD("Available GL extensions:");
Romain Guybd0e6aa2010-07-22 18:50:12 -070053 do {
54 head = strchr(current, ' ');
55 String8 s(current, head ? head - current : strlen(current));
56 if (s.length()) {
57 mExtensionList.add(s);
Romain Guya5aed0d2010-09-09 14:42:43 -070058 EXT_LOGD(" %s", s.string());
Romain Guybd0e6aa2010-07-22 18:50:12 -070059 }
60 current = head + 1;
61 } while (head);
62
63 mHasNPot = hasExtension("GL_OES_texture_npot");
Romain Guya5aed0d2010-09-09 14:42:43 -070064 mHasFramebufferFetch = hasExtension("GL_NV_shader_framebuffer_fetch");
Romain Guy9c4b79a2011-11-10 19:23:58 -080065 mHasDiscardFramebuffer = hasExtension("GL_EXT_discard_framebuffer");
Romain Guy13631f32012-01-30 17:41:55 -080066 mHasDebugMarker = hasExtension("GL_EXT_debug_marker");
Romain Guydfa10462012-05-12 16:18:58 -070067 mHasDebugLabel = hasExtension("GL_EXT_debug_label");
Romain Guy85ef80d2012-09-13 20:26:50 -070068 mHasTiledRendering = hasExtension("GL_QCOM_tiled_rendering");
Romain Guy51769a62010-07-23 00:28:00 -070069
Romain Guy85ef80d2012-09-13 20:26:50 -070070 mExtensions = strdup(buffer);
71 }
72
73 ~Extensions() {
74 free(mExtensions);
Romain Guybd0e6aa2010-07-22 18:50:12 -070075 }
76
77 inline bool hasNPot() const { return mHasNPot; }
Romain Guya5aed0d2010-09-09 14:42:43 -070078 inline bool hasFramebufferFetch() const { return mHasFramebufferFetch; }
Romain Guy9c4b79a2011-11-10 19:23:58 -080079 inline bool hasDiscardFramebuffer() const { return mHasDiscardFramebuffer; }
Romain Guy13631f32012-01-30 17:41:55 -080080 inline bool hasDebugMarker() const { return mHasDebugMarker; }
Romain Guydfa10462012-05-12 16:18:58 -070081 inline bool hasDebugLabel() const { return mHasDebugLabel; }
Romain Guy85ef80d2012-09-13 20:26:50 -070082 inline bool hasTiledRendering() const { return mHasTiledRendering; }
Romain Guybd0e6aa2010-07-22 18:50:12 -070083
84 bool hasExtension(const char* extension) const {
85 const String8 s(extension);
86 return mExtensionList.indexOf(s) >= 0;
87 }
88
Romain Guy51769a62010-07-23 00:28:00 -070089 void dump() {
Steve Block5baa3a62011-12-20 16:23:08 +000090 ALOGD("Supported extensions:\n%s", mExtensions);
Romain Guy51769a62010-07-23 00:28:00 -070091 }
92
Romain Guybd0e6aa2010-07-22 18:50:12 -070093private:
94 SortedVector<String8> mExtensionList;
95
Romain Guy85ef80d2012-09-13 20:26:50 -070096 char* mExtensions;
Romain Guy51769a62010-07-23 00:28:00 -070097
Romain Guybd0e6aa2010-07-22 18:50:12 -070098 bool mHasNPot;
Romain Guya5aed0d2010-09-09 14:42:43 -070099 bool mHasFramebufferFetch;
Romain Guy9c4b79a2011-11-10 19:23:58 -0800100 bool mHasDiscardFramebuffer;
Romain Guy13631f32012-01-30 17:41:55 -0800101 bool mHasDebugMarker;
Romain Guydfa10462012-05-12 16:18:58 -0700102 bool mHasDebugLabel;
Romain Guy85ef80d2012-09-13 20:26:50 -0700103 bool mHasTiledRendering;
Romain Guybd0e6aa2010-07-22 18:50:12 -0700104}; // class Extensions
105
106}; // namespace uirenderer
107}; // namespace android
108
Romain Guy5b3b3522010-10-27 18:57:51 -0700109#endif // ANDROID_HWUI_EXTENSIONS_H