blob: c68822b0401100ee8f30025cb8a268ac64621411 [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
Romain Guye9bc11f2013-05-23 12:47:26 -070017#define LOG_TAG "OpenGLRenderer"
18
Chris Craik117bdbc2015-02-05 10:12:38 -080019#include "Extensions.h"
20
21#include "Debug.h"
22#include "Properties.h"
Romain Guye9bc11f2013-05-23 12:47:26 -070023
24#include <EGL/egl.h>
25#include <EGL/eglext.h>
Chris Craik117bdbc2015-02-05 10:12:38 -080026#include <GLES2/gl2ext.h>
Romain Guye9bc11f2013-05-23 12:47:26 -070027#include <utils/Log.h>
28
Romain Guy3bbacf22013-02-06 16:51:04 -080029namespace android {
30
31using namespace uirenderer;
32ANDROID_SINGLETON_STATIC_INSTANCE(Extensions);
33
34namespace 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
Chris Craik117bdbc2015-02-05 10:12:38 -080051Extensions::Extensions() {
Romain Guye9bc11f2013-05-23 12:47:26 -070052 // 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 mHasDebugLabel = hasGlExtension("GL_EXT_debug_label");
59 mHasTiledRendering = hasGlExtension("GL_QCOM_tiled_rendering");
60 mHas1BitStencil = hasGlExtension("GL_OES_stencil1");
61 mHas4BitStencil = hasGlExtension("GL_OES_stencil4");
Romain Guy3bbacf22013-02-06 16:51:04 -080062
Romain Guye9bc11f2013-05-23 12:47:26 -070063 // Query EGL extensions
64 findExtensions(eglQueryString(eglGetCurrentDisplay(), EGL_EXTENSIONS), mEglExtensionList);
Romain Guy31e08e92013-06-18 15:53:53 -070065
66 char property[PROPERTY_VALUE_MAX];
Chris Craikd41c4d82015-01-05 15:51:13 -080067 if (property_get(PROPERTY_DEBUG_NV_PROFILING, property, nullptr) > 0) {
Romain Guy31e08e92013-06-18 15:53:53 -070068 mHasNvSystemTime = !strcmp(property, "true") && hasEglExtension("EGL_NV_system_time");
69 } else {
70 mHasNvSystemTime = false;
71 }
Romain Guydf1dc282013-03-29 18:32:29 -070072
73 const char* version = (const char*) glGetString(GL_VERSION);
Romain Guydf1dc282013-03-29 18:32:29 -070074
75 // Section 6.1.5 of the OpenGL ES specification indicates the GL version
76 // string strictly follows this format:
77 //
78 // OpenGL<space>ES<space><version number><space><vendor-specific information>
79 //
80 // In addition section 6.1.5 describes the version number thusly:
81 //
82 // "The version number is either of the form major number.minor number or
83 // major number.minor number.release number, where the numbers all have one
84 // or more digits. The release number and vendor specific information are
85 // optional."
86
Romain Guy6cad7572013-07-24 11:49:33 -070087 if (sscanf(version, "OpenGL ES %d.%d", &mVersionMajor, &mVersionMinor) != 2) {
Romain Guydf1dc282013-03-29 18:32:29 -070088 // If we cannot parse the version number, assume OpenGL ES 2.0
89 mVersionMajor = 2;
90 mVersionMinor = 0;
91 }
Romain Guy3bbacf22013-02-06 16:51:04 -080092}
93
Romain Guy3bbacf22013-02-06 16:51:04 -080094///////////////////////////////////////////////////////////////////////////////
95// Methods
96///////////////////////////////////////////////////////////////////////////////
97
Romain Guye9bc11f2013-05-23 12:47:26 -070098bool Extensions::hasGlExtension(const char* extension) const {
Romain Guy3bbacf22013-02-06 16:51:04 -080099 const String8 s(extension);
Romain Guye9bc11f2013-05-23 12:47:26 -0700100 return mGlExtensionList.indexOf(s) >= 0;
101}
102
103bool Extensions::hasEglExtension(const char* extension) const {
104 const String8 s(extension);
105 return mEglExtensionList.indexOf(s) >= 0;
106}
107
108void Extensions::findExtensions(const char* extensions, SortedVector<String8>& list) const {
109 const char* current = extensions;
110 const char* head = current;
111 EXT_LOGD("Available extensions:");
112 do {
113 head = strchr(current, ' ');
114 String8 s(current, head ? head - current : strlen(current));
115 if (s.length()) {
116 list.add(s);
117 EXT_LOGD(" %s", s.string());
118 }
119 current = head + 1;
120 } while (head);
Romain Guy3bbacf22013-02-06 16:51:04 -0800121}
122
123void Extensions::dump() const {
Romain Guye9bc11f2013-05-23 12:47:26 -0700124 ALOGD("%s", (const char*) glGetString(GL_VERSION));
125 ALOGD("Supported GL extensions:\n%s", (const char*) glGetString(GL_EXTENSIONS));
126 ALOGD("Supported EGL extensions:\n%s", eglQueryString(eglGetCurrentDisplay(), EGL_EXTENSIONS));
Romain Guy3bbacf22013-02-06 16:51:04 -0800127}
128
129}; // namespace uirenderer
130}; // namespace android