• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
28 namespace android {
29 namespace 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 #define VENDOR_IMG "Imagination Technologies"
44 
45 ///////////////////////////////////////////////////////////////////////////////
46 // Classes
47 ///////////////////////////////////////////////////////////////////////////////
48 
49 class Extensions {
50 public:
Extensions()51     Extensions() {
52         const char* buffer = (const char*) glGetString(GL_EXTENSIONS);
53         const char* current = buffer;
54         const char* head = current;
55         EXT_LOGD("Available GL extensions:");
56         do {
57             head = strchr(current, ' ');
58             String8 s(current, head ? head - current : strlen(current));
59             if (s.length()) {
60                 mExtensionList.add(s);
61                 EXT_LOGD("  %s", s.string());
62             }
63             current = head + 1;
64         } while (head);
65 
66         mHasNPot = hasExtension("GL_OES_texture_npot");
67         mHasFramebufferFetch = hasExtension("GL_NV_shader_framebuffer_fetch");
68         mHasDiscardFramebuffer = hasExtension("GL_EXT_discard_framebuffer");
69         mHasDebugMarker = hasExtension("GL_EXT_debug_marker");
70         mHasDebugLabel = hasExtension("GL_EXT_debug_label");
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 
hasNPot()82     inline bool hasNPot() const { return mHasNPot; }
hasFramebufferFetch()83     inline bool hasFramebufferFetch() const { return mHasFramebufferFetch; }
needsHighpTexCoords()84     inline bool needsHighpTexCoords() const { return mNeedsHighpTexCoords; }
hasDiscardFramebuffer()85     inline bool hasDiscardFramebuffer() const { return mHasDiscardFramebuffer; }
hasDebugMarker()86     inline bool hasDebugMarker() const { return mHasDebugMarker; }
hasDebugLabel()87     inline bool hasDebugLabel() const { return mHasDebugLabel; }
88 
hasExtension(const char * extension)89     bool hasExtension(const char* extension) const {
90         const String8 s(extension);
91         return mExtensionList.indexOf(s) >= 0;
92     }
93 
dump()94     void dump() {
95         ALOGD("Supported extensions:\n%s", mExtensions);
96     }
97 
98 private:
99     SortedVector<String8> mExtensionList;
100 
101     const char* mExtensions;
102 
103     bool mHasNPot;
104     bool mNeedsHighpTexCoords;
105     bool mHasFramebufferFetch;
106     bool mHasDiscardFramebuffer;
107     bool mHasDebugMarker;
108     bool mHasDebugLabel;
109 }; // class Extensions
110 
111 }; // namespace uirenderer
112 }; // namespace android
113 
114 #endif // ANDROID_HWUI_EXTENSIONS_H
115