blob: eceb5c1cb0dff533645877849091b1c4a01e3c60 [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
26namespace android {
27namespace uirenderer {
28
Romain Guya5aed0d2010-09-09 14:42:43 -070029///////////////////////////////////////////////////////////////////////////////
30// Defines
31///////////////////////////////////////////////////////////////////////////////
32
33// Debug
34#define DEBUG_EXTENSIONS 0
35
36// Debug
37#if DEBUG_EXTENSIONS
38 #define EXT_LOGD(...) LOGD(__VA_ARGS__)
39#else
40 #define EXT_LOGD(...)
41#endif
42
Romain Guybd0e6aa2010-07-22 18:50:12 -070043class Extensions {
44public:
45 Extensions() {
46 const char* buffer = (const char*) glGetString(GL_EXTENSIONS);
47 const char* current = buffer;
48 const char* head = current;
Romain Guya5aed0d2010-09-09 14:42:43 -070049 EXT_LOGD("Available GL extensions:");
Romain Guybd0e6aa2010-07-22 18:50:12 -070050 do {
51 head = strchr(current, ' ');
52 String8 s(current, head ? head - current : strlen(current));
53 if (s.length()) {
54 mExtensionList.add(s);
Romain Guya5aed0d2010-09-09 14:42:43 -070055 EXT_LOGD(" %s", s.string());
Romain Guybd0e6aa2010-07-22 18:50:12 -070056 }
57 current = head + 1;
58 } while (head);
59
60 mHasNPot = hasExtension("GL_OES_texture_npot");
Romain Guy51769a62010-07-23 00:28:00 -070061 mHasDrawPath = hasExtension("GL_NV_draw_path");
62 mHasCoverageSample = hasExtension("GL_NV_coverage_sample");
Romain Guya5aed0d2010-09-09 14:42:43 -070063 mHasFramebufferFetch = hasExtension("GL_NV_shader_framebuffer_fetch");
Romain Guy51769a62010-07-23 00:28:00 -070064
65 mExtensions = buffer;
Romain Guybd0e6aa2010-07-22 18:50:12 -070066 }
67
68 inline bool hasNPot() const { return mHasNPot; }
Romain Guy51769a62010-07-23 00:28:00 -070069 inline bool hasDrawPath() const { return mHasDrawPath; }
70 inline bool hasCoverageSample() const { return mHasCoverageSample; }
Romain Guya5aed0d2010-09-09 14:42:43 -070071 inline bool hasFramebufferFetch() const { return mHasFramebufferFetch; }
Romain Guybd0e6aa2010-07-22 18:50:12 -070072
73 bool hasExtension(const char* extension) const {
74 const String8 s(extension);
75 return mExtensionList.indexOf(s) >= 0;
76 }
77
Romain Guy51769a62010-07-23 00:28:00 -070078 void dump() {
79 LOGD("Supported extensions:\n%s", mExtensions);
80 }
81
Romain Guybd0e6aa2010-07-22 18:50:12 -070082private:
83 SortedVector<String8> mExtensionList;
84
Romain Guy51769a62010-07-23 00:28:00 -070085 const char* mExtensions;
86
Romain Guybd0e6aa2010-07-22 18:50:12 -070087 bool mHasNPot;
Romain Guy51769a62010-07-23 00:28:00 -070088 bool mHasDrawPath;
89 bool mHasCoverageSample;
Romain Guya5aed0d2010-09-09 14:42:43 -070090 bool mHasFramebufferFetch;
Romain Guybd0e6aa2010-07-22 18:50:12 -070091}; // class Extensions
92
93}; // namespace uirenderer
94}; // namespace android
95
Romain Guy5b3b3522010-10-27 18:57:51 -070096#endif // ANDROID_HWUI_EXTENSIONS_H