blob: edc90fbc80f0625fe820e90cdceb8973f5852a13 [file] [log] [blame]
Romain Guy3bbacf22013-02-06 16:51:04 -08001/*
2 * Copyright (C) 2013 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#include "Debug.h"
18#include "Extensions.h"
19
20namespace android {
21
22using namespace uirenderer;
23ANDROID_SINGLETON_STATIC_INSTANCE(Extensions);
24
25namespace uirenderer {
26
27///////////////////////////////////////////////////////////////////////////////
28// Defines
29///////////////////////////////////////////////////////////////////////////////
30
31// Debug
32#if DEBUG_EXTENSIONS
33 #define EXT_LOGD(...) ALOGD(__VA_ARGS__)
34#else
35 #define EXT_LOGD(...)
36#endif
37
38///////////////////////////////////////////////////////////////////////////////
39// Constructors
40///////////////////////////////////////////////////////////////////////////////
41
42Extensions::Extensions(): Singleton<Extensions>() {
43 const char* buffer = (const char*) glGetString(GL_EXTENSIONS);
44 const char* current = buffer;
45 const char* head = current;
46 EXT_LOGD("Available GL extensions:");
47 do {
48 head = strchr(current, ' ');
49 String8 s(current, head ? head - current : strlen(current));
50 if (s.length()) {
51 mExtensionList.add(s);
52 EXT_LOGD(" %s", s.string());
53 }
54 current = head + 1;
55 } while (head);
56
57 mHasNPot = hasExtension("GL_OES_texture_npot");
58 mHasFramebufferFetch = hasExtension("GL_NV_shader_framebuffer_fetch");
59 mHasDiscardFramebuffer = hasExtension("GL_EXT_discard_framebuffer");
60 mHasDebugMarker = hasExtension("GL_EXT_debug_marker");
61 mHasDebugLabel = hasExtension("GL_EXT_debug_label");
62 mHasTiledRendering = hasExtension("GL_QCOM_tiled_rendering");
63 mHas1BitStencil = hasExtension("GL_OES_stencil1");
64 mHas4BitStencil = hasExtension("GL_OES_stencil4");
65
66 mExtensions = strdup(buffer);
67}
68
69Extensions::~Extensions() {
70 free(mExtensions);
71}
72
73///////////////////////////////////////////////////////////////////////////////
74// Methods
75///////////////////////////////////////////////////////////////////////////////
76
77bool Extensions::hasExtension(const char* extension) const {
78 const String8 s(extension);
79 return mExtensionList.indexOf(s) >= 0;
80}
81
82void Extensions::dump() const {
83 ALOGD("Supported extensions:\n%s", mExtensions);
84}
85
86}; // namespace uirenderer
87}; // namespace android