blob: 6f50ea7df251c19149df7341c316835ab6f637d0 [file] [log] [blame]
Mathias Agopian875d8e12013-06-07 15:35:48 -07001/*
2 * Copyright (C) 2010 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
Peiyong Lin833074a2018-08-28 11:53:54 -070017#include "GLExtensions.h"
Peiyong Lincbc184f2018-08-22 13:24:10 -070018
Mathias Agopian875d8e12013-06-07 15:35:48 -070019#include <stdint.h>
Chia-I Wub027f802017-11-29 14:00:52 -080020#include <stdio.h>
21#include <stdlib.h>
Mathias Agopian875d8e12013-06-07 15:35:48 -070022
Peiyong Lin833074a2018-08-28 11:53:54 -070023ANDROID_SINGLETON_STATIC_INSTANCE(android::renderengine::gl::GLExtensions)
Mathias Agopian875d8e12013-06-07 15:35:48 -070024
Peiyong Lin833074a2018-08-28 11:53:54 -070025namespace android {
26namespace renderengine {
27namespace gl {
Mathias Agopian875d8e12013-06-07 15:35:48 -070028
Chia-I Wu767d7c92017-11-30 13:22:48 -080029SortedVector<String8> GLExtensions::parseExtensionString(char const* extensions) {
30 SortedVector<String8> list;
31
32 char const* curr = extensions;
33 char const* head = curr;
34 do {
35 head = strchr(curr, ' ');
36 String8 s(curr, head ? head - curr : strlen(curr));
37 if (s.length()) {
38 list.add(s);
39 }
40 curr = head + 1;
41 } while (head);
42
43 return list;
44}
Mathias Agopian875d8e12013-06-07 15:35:48 -070045
Chia-I Wub027f802017-11-29 14:00:52 -080046void GLExtensions::initWithGLStrings(GLubyte const* vendor, GLubyte const* renderer,
47 GLubyte const* version, GLubyte const* extensions) {
48 mVendor = (char const*)vendor;
49 mRenderer = (char const*)renderer;
50 mVersion = (char const*)version;
Mathias Agopian875d8e12013-06-07 15:35:48 -070051 mExtensions = (char const*)extensions;
Chia-I Wu767d7c92017-11-30 13:22:48 -080052 mExtensionList = parseExtensionString(mExtensions);
Mathias Agopian875d8e12013-06-07 15:35:48 -070053}
54
Chia-I Wub027f802017-11-29 14:00:52 -080055bool GLExtensions::hasExtension(char const* extension) const {
Mathias Agopian875d8e12013-06-07 15:35:48 -070056 const String8 s(extension);
57 return mExtensionList.indexOf(s) >= 0;
58}
59
60char const* GLExtensions::getVendor() const {
61 return mVendor.string();
62}
63
64char const* GLExtensions::getRenderer() const {
65 return mRenderer.string();
66}
67
68char const* GLExtensions::getVersion() const {
69 return mVersion.string();
70}
71
Chia-I Wu767d7c92017-11-30 13:22:48 -080072char const* GLExtensions::getExtensions() const {
Mathias Agopian875d8e12013-06-07 15:35:48 -070073 return mExtensions.string();
74}
75
Chia-I Wu767d7c92017-11-30 13:22:48 -080076void GLExtensions::initWithEGLStrings(char const* eglVersion, char const* eglExtensions) {
77 mEGLVersion = eglVersion;
78 mEGLExtensions = eglExtensions;
79 mEGLExtensionList = parseExtensionString(mEGLExtensions);
80
81 // EGL_ANDROIDX_no_config_context is an experimental extension with no
82 // written specification. It will be replaced by something more formal.
83 // SurfaceFlinger is using it to allow a single EGLContext to render to
84 // both a 16-bit primary display framebuffer and a 32-bit virtual display
85 // framebuffer.
86 //
87 // EGL_KHR_no_config_context is official extension to allow creating a
88 // context that works with any surface of a display.
89 if (hasEGLExtension("EGL_ANDROIDX_no_config_context") ||
90 hasEGLExtension("EGL_KHR_no_config_context")) {
91 mHasNoConfigContext = true;
92 }
Chia-I Wu767fcf72017-11-30 22:07:38 -080093
94 if (hasEGLExtension("EGL_ANDROID_native_fence_sync")) {
95 mHasNativeFenceSync = true;
96 }
97 if (hasEGLExtension("EGL_KHR_fence_sync")) {
98 mHasFenceSync = true;
99 }
100 if (hasEGLExtension("EGL_KHR_wait_sync")) {
101 mHasWaitSync = true;
102 }
Chia-I Wu401ef832017-12-01 10:52:22 -0800103 if (hasEGLExtension("EGL_EXT_protected_content")) {
104 mHasProtectedContent = true;
105 }
Jorim Jaggi5b15ef62018-01-17 18:31:39 +0100106 if (hasEGLExtension("EGL_IMG_context_priority")) {
107 mHasContextPriority = true;
108 }
Chia-I Wu767d7c92017-11-30 13:22:48 -0800109}
110
111char const* GLExtensions::getEGLVersion() const {
112 return mEGLVersion.string();
113}
114
115char const* GLExtensions::getEGLExtensions() const {
116 return mEGLExtensions.string();
117}
118
119bool GLExtensions::hasEGLExtension(char const* extension) const {
120 const String8 s(extension);
121 return mEGLExtensionList.indexOf(s) >= 0;
122}
123
Peiyong Lin833074a2018-08-28 11:53:54 -0700124} // namespace gl
125} // namespace renderengine
126} // namespace android