blob: 2a82216eb145dfcb0c3ebb65ada49acdb6d371b0 [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");
Romain Guye9bc11f2013-05-23 12:47:26 -070058 mHasTiledRendering = hasGlExtension("GL_QCOM_tiled_rendering");
59 mHas1BitStencil = hasGlExtension("GL_OES_stencil1");
60 mHas4BitStencil = hasGlExtension("GL_OES_stencil4");
Romain Guy3bbacf22013-02-06 16:51:04 -080061
Romain Guye9bc11f2013-05-23 12:47:26 -070062 // Query EGL extensions
63 findExtensions(eglQueryString(eglGetCurrentDisplay(), EGL_EXTENSIONS), mEglExtensionList);
Romain Guy31e08e92013-06-18 15:53:53 -070064
65 char property[PROPERTY_VALUE_MAX];
Chris Craikd41c4d82015-01-05 15:51:13 -080066 if (property_get(PROPERTY_DEBUG_NV_PROFILING, property, nullptr) > 0) {
Romain Guy31e08e92013-06-18 15:53:53 -070067 mHasNvSystemTime = !strcmp(property, "true") && hasEglExtension("EGL_NV_system_time");
68 } else {
69 mHasNvSystemTime = false;
70 }
Romain Guydf1dc282013-03-29 18:32:29 -070071
72 const char* version = (const char*) glGetString(GL_VERSION);
Romain Guydf1dc282013-03-29 18:32:29 -070073
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
Romain Guy6cad7572013-07-24 11:49:33 -070086 if (sscanf(version, "OpenGL ES %d.%d", &mVersionMajor, &mVersionMinor) != 2) {
Romain Guydf1dc282013-03-29 18:32:29 -070087 // If we cannot parse the version number, assume OpenGL ES 2.0
88 mVersionMajor = 2;
89 mVersionMinor = 0;
90 }
Romain Guy3bbacf22013-02-06 16:51:04 -080091}
92
Romain Guy3bbacf22013-02-06 16:51:04 -080093///////////////////////////////////////////////////////////////////////////////
94// Methods
95///////////////////////////////////////////////////////////////////////////////
96
Romain Guye9bc11f2013-05-23 12:47:26 -070097bool Extensions::hasGlExtension(const char* extension) const {
Romain Guy3bbacf22013-02-06 16:51:04 -080098 const String8 s(extension);
Romain Guye9bc11f2013-05-23 12:47:26 -070099 return mGlExtensionList.indexOf(s) >= 0;
100}
101
102bool Extensions::hasEglExtension(const char* extension) const {
103 const String8 s(extension);
104 return mEglExtensionList.indexOf(s) >= 0;
105}
106
107void 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);
Romain Guy3bbacf22013-02-06 16:51:04 -0800120}
121
122void Extensions::dump() const {
Romain Guye9bc11f2013-05-23 12:47:26 -0700123 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));
Romain Guy3bbacf22013-02-06 16:51:04 -0800126}
127
128}; // namespace uirenderer
129}; // namespace android