blob: 25004b69c496e1c143a9cea4aedbb3e607265678 [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
19#include <GLES2/gl2.h>
20#include <GLES2/gl2ext.h>
21
22#include <EGL/egl.h>
23#include <EGL/eglext.h>
24
25#include <utils/Log.h>
26
Romain Guy3bbacf22013-02-06 16:51:04 -080027#include "Debug.h"
28#include "Extensions.h"
Romain Guy31e08e92013-06-18 15:53:53 -070029#include "Properties.h"
Romain Guy3bbacf22013-02-06 16:51:04 -080030
31namespace android {
32
33using namespace uirenderer;
34ANDROID_SINGLETON_STATIC_INSTANCE(Extensions);
35
36namespace uirenderer {
37
38///////////////////////////////////////////////////////////////////////////////
39// Defines
40///////////////////////////////////////////////////////////////////////////////
41
42// Debug
43#if DEBUG_EXTENSIONS
44 #define EXT_LOGD(...) ALOGD(__VA_ARGS__)
45#else
46 #define EXT_LOGD(...)
47#endif
48
49///////////////////////////////////////////////////////////////////////////////
50// Constructors
51///////////////////////////////////////////////////////////////////////////////
52
53Extensions::Extensions(): Singleton<Extensions>() {
Romain Guye9bc11f2013-05-23 12:47:26 -070054 // Query GL extensions
55 findExtensions((const char*) glGetString(GL_EXTENSIONS), mGlExtensionList);
56 mHasNPot = hasGlExtension("GL_OES_texture_npot");
57 mHasFramebufferFetch = hasGlExtension("GL_NV_shader_framebuffer_fetch");
58 mHasDiscardFramebuffer = hasGlExtension("GL_EXT_discard_framebuffer");
59 mHasDebugMarker = hasGlExtension("GL_EXT_debug_marker");
60 mHasDebugLabel = hasGlExtension("GL_EXT_debug_label");
61 mHasTiledRendering = hasGlExtension("GL_QCOM_tiled_rendering");
62 mHas1BitStencil = hasGlExtension("GL_OES_stencil1");
63 mHas4BitStencil = hasGlExtension("GL_OES_stencil4");
xiaozhengdongd538d302015-08-04 16:55:35 +080064 mHasUnpackSubImage = hasGlExtension("GL_EXT_unpack_subimage");
Romain Guy3bbacf22013-02-06 16:51:04 -080065
Romain Guye9bc11f2013-05-23 12:47:26 -070066 // Query EGL extensions
67 findExtensions(eglQueryString(eglGetCurrentDisplay(), EGL_EXTENSIONS), mEglExtensionList);
Romain Guy31e08e92013-06-18 15:53:53 -070068
69 char property[PROPERTY_VALUE_MAX];
70 if (property_get(PROPERTY_DEBUG_NV_PROFILING, property, NULL) > 0) {
71 mHasNvSystemTime = !strcmp(property, "true") && hasEglExtension("EGL_NV_system_time");
72 } else {
73 mHasNvSystemTime = false;
74 }
Romain Guydf1dc282013-03-29 18:32:29 -070075
76 const char* version = (const char*) glGetString(GL_VERSION);
Romain Guydf1dc282013-03-29 18:32:29 -070077
78 // Section 6.1.5 of the OpenGL ES specification indicates the GL version
79 // string strictly follows this format:
80 //
81 // OpenGL<space>ES<space><version number><space><vendor-specific information>
82 //
83 // In addition section 6.1.5 describes the version number thusly:
84 //
85 // "The version number is either of the form major number.minor number or
86 // major number.minor number.release number, where the numbers all have one
87 // or more digits. The release number and vendor specific information are
88 // optional."
89
Romain Guy6cad7572013-07-24 11:49:33 -070090 if (sscanf(version, "OpenGL ES %d.%d", &mVersionMajor, &mVersionMinor) != 2) {
Romain Guydf1dc282013-03-29 18:32:29 -070091 // If we cannot parse the version number, assume OpenGL ES 2.0
92 mVersionMajor = 2;
93 mVersionMinor = 0;
94 }
Romain Guy3bbacf22013-02-06 16:51:04 -080095}
96
97Extensions::~Extensions() {
Romain Guy3bbacf22013-02-06 16:51:04 -080098}
99
100///////////////////////////////////////////////////////////////////////////////
101// Methods
102///////////////////////////////////////////////////////////////////////////////
103
Romain Guye9bc11f2013-05-23 12:47:26 -0700104bool Extensions::hasGlExtension(const char* extension) const {
Romain Guy3bbacf22013-02-06 16:51:04 -0800105 const String8 s(extension);
Romain Guye9bc11f2013-05-23 12:47:26 -0700106 return mGlExtensionList.indexOf(s) >= 0;
107}
108
109bool Extensions::hasEglExtension(const char* extension) const {
110 const String8 s(extension);
111 return mEglExtensionList.indexOf(s) >= 0;
112}
113
114void Extensions::findExtensions(const char* extensions, SortedVector<String8>& list) const {
115 const char* current = extensions;
116 const char* head = current;
117 EXT_LOGD("Available extensions:");
118 do {
119 head = strchr(current, ' ');
120 String8 s(current, head ? head - current : strlen(current));
121 if (s.length()) {
122 list.add(s);
123 EXT_LOGD(" %s", s.string());
124 }
125 current = head + 1;
126 } while (head);
Romain Guy3bbacf22013-02-06 16:51:04 -0800127}
128
129void Extensions::dump() const {
Romain Guye9bc11f2013-05-23 12:47:26 -0700130 ALOGD("%s", (const char*) glGetString(GL_VERSION));
131 ALOGD("Supported GL extensions:\n%s", (const char*) glGetString(GL_EXTENSIONS));
132 ALOGD("Supported EGL extensions:\n%s", eglQueryString(eglGetCurrentDisplay(), EGL_EXTENSIONS));
Romain Guy3bbacf22013-02-06 16:51:04 -0800133}
134
135}; // namespace uirenderer
136}; // namespace android