1 /*
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 #define LOG_TAG "OpenGLRenderer"
18
19 #include "Extensions.h"
20
21 #include "Debug.h"
22 #include "Properties.h"
23
24 #include <EGL/egl.h>
25 #include <EGL/eglext.h>
26 #include <GLES2/gl2ext.h>
27 #include <utils/Log.h>
28
29 namespace android {
30
31 using namespace uirenderer;
32 ANDROID_SINGLETON_STATIC_INSTANCE(Extensions);
33
34 namespace uirenderer {
35
36 ///////////////////////////////////////////////////////////////////////////////
37 // Defines
38 ///////////////////////////////////////////////////////////////////////////////
39
40 // Debug
41 #if DEBUG_EXTENSIONS
42 #define EXT_LOGD(...) ALOGD(__VA_ARGS__)
43 #else
44 #define EXT_LOGD(...)
45 #endif
46
47 ///////////////////////////////////////////////////////////////////////////////
48 // Constructors
49 ///////////////////////////////////////////////////////////////////////////////
50
Extensions()51 Extensions::Extensions() {
52 // Query GL extensions
53 findExtensions((const char*) glGetString(GL_EXTENSIONS), mGlExtensionList);
54 mHasNPot = hasGlExtension("GL_OES_texture_npot");
55 mHasFramebufferFetch = hasGlExtension("GL_NV_shader_framebuffer_fetch");
56 mHasDiscardFramebuffer = hasGlExtension("GL_EXT_discard_framebuffer");
57 mHasDebugMarker = hasGlExtension("GL_EXT_debug_marker");
58 mHasTiledRendering = hasGlExtension("GL_QCOM_tiled_rendering");
59 mHas1BitStencil = hasGlExtension("GL_OES_stencil1");
60 mHas4BitStencil = hasGlExtension("GL_OES_stencil4");
61
62 // Query EGL extensions
63 findExtensions(eglQueryString(eglGetCurrentDisplay(), EGL_EXTENSIONS), mEglExtensionList);
64
65 char property[PROPERTY_VALUE_MAX];
66 if (property_get(PROPERTY_DEBUG_NV_PROFILING, property, nullptr) > 0) {
67 mHasNvSystemTime = !strcmp(property, "true") && hasEglExtension("EGL_NV_system_time");
68 } else {
69 mHasNvSystemTime = false;
70 }
71
72 const char* version = (const char*) glGetString(GL_VERSION);
73
74 // Section 6.1.5 of the OpenGL ES specification indicates the GL version
75 // string strictly follows this format:
76 //
77 // OpenGL<space>ES<space><version number><space><vendor-specific information>
78 //
79 // In addition section 6.1.5 describes the version number thusly:
80 //
81 // "The version number is either of the form major number.minor number or
82 // major number.minor number.release number, where the numbers all have one
83 // or more digits. The release number and vendor specific information are
84 // optional."
85
86 if (sscanf(version, "OpenGL ES %d.%d", &mVersionMajor, &mVersionMinor) != 2) {
87 // If we cannot parse the version number, assume OpenGL ES 2.0
88 mVersionMajor = 2;
89 mVersionMinor = 0;
90 }
91 }
92
93 ///////////////////////////////////////////////////////////////////////////////
94 // Methods
95 ///////////////////////////////////////////////////////////////////////////////
96
hasGlExtension(const char * extension) const97 bool Extensions::hasGlExtension(const char* extension) const {
98 const String8 s(extension);
99 return mGlExtensionList.indexOf(s) >= 0;
100 }
101
hasEglExtension(const char * extension) const102 bool Extensions::hasEglExtension(const char* extension) const {
103 const String8 s(extension);
104 return mEglExtensionList.indexOf(s) >= 0;
105 }
106
findExtensions(const char * extensions,SortedVector<String8> & list) const107 void Extensions::findExtensions(const char* extensions, SortedVector<String8>& list) const {
108 const char* current = extensions;
109 const char* head = current;
110 EXT_LOGD("Available extensions:");
111 do {
112 head = strchr(current, ' ');
113 String8 s(current, head ? head - current : strlen(current));
114 if (s.length()) {
115 list.add(s);
116 EXT_LOGD(" %s", s.string());
117 }
118 current = head + 1;
119 } while (head);
120 }
121
dump() const122 void Extensions::dump() const {
123 ALOGD("%s", (const char*) glGetString(GL_VERSION));
124 ALOGD("Supported GL extensions:\n%s", (const char*) glGetString(GL_EXTENSIONS));
125 ALOGD("Supported EGL extensions:\n%s", eglQueryString(eglGetCurrentDisplay(), EGL_EXTENSIONS));
126 }
127
128 }; // namespace uirenderer
129 }; // namespace android
130