blob: 3d350c98892b3325b8a9e58a69eb791d4fa8993d [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
Chris Craik117bdbc2015-02-05 10:12:38 -080017#include "Extensions.h"
18
19#include "Debug.h"
20#include "Properties.h"
Romain Guye9bc11f2013-05-23 12:47:26 -070021
22#include <EGL/egl.h>
23#include <EGL/eglext.h>
Chris Craik117bdbc2015-02-05 10:12:38 -080024#include <GLES2/gl2ext.h>
Romain Guye9bc11f2013-05-23 12:47:26 -070025#include <utils/Log.h>
26
Romain Guy3bbacf22013-02-06 16:51:04 -080027namespace android {
28
29using namespace uirenderer;
30ANDROID_SINGLETON_STATIC_INSTANCE(Extensions);
31
32namespace uirenderer {
33
34///////////////////////////////////////////////////////////////////////////////
35// Defines
36///////////////////////////////////////////////////////////////////////////////
37
38// Debug
39#if DEBUG_EXTENSIONS
40 #define EXT_LOGD(...) ALOGD(__VA_ARGS__)
41#else
42 #define EXT_LOGD(...)
43#endif
44
45///////////////////////////////////////////////////////////////////////////////
46// Constructors
47///////////////////////////////////////////////////////////////////////////////
48
Chris Craik117bdbc2015-02-05 10:12:38 -080049Extensions::Extensions() {
Romain Guye9bc11f2013-05-23 12:47:26 -070050 // Query GL extensions
51 findExtensions((const char*) glGetString(GL_EXTENSIONS), mGlExtensionList);
52 mHasNPot = hasGlExtension("GL_OES_texture_npot");
53 mHasFramebufferFetch = hasGlExtension("GL_NV_shader_framebuffer_fetch");
54 mHasDiscardFramebuffer = hasGlExtension("GL_EXT_discard_framebuffer");
55 mHasDebugMarker = hasGlExtension("GL_EXT_debug_marker");
Romain Guye9bc11f2013-05-23 12:47:26 -070056 mHas1BitStencil = hasGlExtension("GL_OES_stencil1");
57 mHas4BitStencil = hasGlExtension("GL_OES_stencil4");
xiaozhengdongd538d302015-08-04 16:55:35 +080058 mHasUnpackSubImage = hasGlExtension("GL_EXT_unpack_subimage");
Romain Guy3bbacf22013-02-06 16:51:04 -080059
Romain Guydf1dc282013-03-29 18:32:29 -070060 const char* version = (const char*) glGetString(GL_VERSION);
Romain Guydf1dc282013-03-29 18:32:29 -070061
62 // Section 6.1.5 of the OpenGL ES specification indicates the GL version
63 // string strictly follows this format:
64 //
65 // OpenGL<space>ES<space><version number><space><vendor-specific information>
66 //
67 // In addition section 6.1.5 describes the version number thusly:
68 //
69 // "The version number is either of the form major number.minor number or
70 // major number.minor number.release number, where the numbers all have one
71 // or more digits. The release number and vendor specific information are
72 // optional."
73
Romain Guy6cad7572013-07-24 11:49:33 -070074 if (sscanf(version, "OpenGL ES %d.%d", &mVersionMajor, &mVersionMinor) != 2) {
Romain Guydf1dc282013-03-29 18:32:29 -070075 // If we cannot parse the version number, assume OpenGL ES 2.0
76 mVersionMajor = 2;
77 mVersionMinor = 0;
78 }
Romain Guy3bbacf22013-02-06 16:51:04 -080079}
80
Romain Guy3bbacf22013-02-06 16:51:04 -080081///////////////////////////////////////////////////////////////////////////////
82// Methods
83///////////////////////////////////////////////////////////////////////////////
84
Romain Guye9bc11f2013-05-23 12:47:26 -070085bool Extensions::hasGlExtension(const char* extension) const {
Romain Guy3bbacf22013-02-06 16:51:04 -080086 const String8 s(extension);
Romain Guye9bc11f2013-05-23 12:47:26 -070087 return mGlExtensionList.indexOf(s) >= 0;
88}
89
90bool Extensions::hasEglExtension(const char* extension) const {
91 const String8 s(extension);
92 return mEglExtensionList.indexOf(s) >= 0;
93}
94
95void Extensions::findExtensions(const char* extensions, SortedVector<String8>& list) const {
96 const char* current = extensions;
97 const char* head = current;
98 EXT_LOGD("Available extensions:");
99 do {
100 head = strchr(current, ' ');
101 String8 s(current, head ? head - current : strlen(current));
102 if (s.length()) {
103 list.add(s);
104 EXT_LOGD(" %s", s.string());
105 }
106 current = head + 1;
107 } while (head);
Romain Guy3bbacf22013-02-06 16:51:04 -0800108}
109
110void Extensions::dump() const {
Romain Guye9bc11f2013-05-23 12:47:26 -0700111 ALOGD("%s", (const char*) glGetString(GL_VERSION));
112 ALOGD("Supported GL extensions:\n%s", (const char*) glGetString(GL_EXTENSIONS));
113 ALOGD("Supported EGL extensions:\n%s", eglQueryString(eglGetCurrentDisplay(), EGL_EXTENSIONS));
Romain Guy3bbacf22013-02-06 16:51:04 -0800114}
115
116}; // namespace uirenderer
117}; // namespace android