blob: dc09a376bbde999eade73c5b63308cfe12c1b2e7 [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
Mathias Agopian875d8e12013-06-07 15:35:48 -070017#include <stdint.h>
Chia-I Wub027f802017-11-29 14:00:52 -080018#include <stdio.h>
19#include <stdlib.h>
Mathias Agopian875d8e12013-06-07 15:35:48 -070020
21#include "GLExtensions.h"
22
23namespace android {
24// ---------------------------------------------------------------------------
25
Chia-I Wub027f802017-11-29 14:00:52 -080026ANDROID_SINGLETON_STATIC_INSTANCE(GLExtensions)
Mathias Agopian875d8e12013-06-07 15:35:48 -070027
Chia-I Wu767d7c92017-11-30 13:22:48 -080028SortedVector<String8> GLExtensions::parseExtensionString(char const* extensions) {
29 SortedVector<String8> list;
30
31 char const* curr = extensions;
32 char const* head = curr;
33 do {
34 head = strchr(curr, ' ');
35 String8 s(curr, head ? head - curr : strlen(curr));
36 if (s.length()) {
37 list.add(s);
38 }
39 curr = head + 1;
40 } while (head);
41
42 return list;
43}
Mathias Agopian875d8e12013-06-07 15:35:48 -070044
Chia-I Wub027f802017-11-29 14:00:52 -080045void GLExtensions::initWithGLStrings(GLubyte const* vendor, GLubyte const* renderer,
46 GLubyte const* version, GLubyte const* extensions) {
47 mVendor = (char const*)vendor;
48 mRenderer = (char const*)renderer;
49 mVersion = (char const*)version;
Mathias Agopian875d8e12013-06-07 15:35:48 -070050 mExtensions = (char const*)extensions;
Chia-I Wu767d7c92017-11-30 13:22:48 -080051 mExtensionList = parseExtensionString(mExtensions);
Mathias Agopian875d8e12013-06-07 15:35:48 -070052}
53
Chia-I Wub027f802017-11-29 14:00:52 -080054bool GLExtensions::hasExtension(char const* extension) const {
Mathias Agopian875d8e12013-06-07 15:35:48 -070055 const String8 s(extension);
56 return mExtensionList.indexOf(s) >= 0;
57}
58
59char const* GLExtensions::getVendor() const {
60 return mVendor.string();
61}
62
63char const* GLExtensions::getRenderer() const {
64 return mRenderer.string();
65}
66
67char const* GLExtensions::getVersion() const {
68 return mVersion.string();
69}
70
Chia-I Wu767d7c92017-11-30 13:22:48 -080071char const* GLExtensions::getExtensions() const {
Mathias Agopian875d8e12013-06-07 15:35:48 -070072 return mExtensions.string();
73}
74
Chia-I Wu767d7c92017-11-30 13:22:48 -080075void GLExtensions::initWithEGLStrings(char const* eglVersion, char const* eglExtensions) {
76 mEGLVersion = eglVersion;
77 mEGLExtensions = eglExtensions;
78 mEGLExtensionList = parseExtensionString(mEGLExtensions);
79
80 // EGL_ANDROIDX_no_config_context is an experimental extension with no
81 // written specification. It will be replaced by something more formal.
82 // SurfaceFlinger is using it to allow a single EGLContext to render to
83 // both a 16-bit primary display framebuffer and a 32-bit virtual display
84 // framebuffer.
85 //
86 // EGL_KHR_no_config_context is official extension to allow creating a
87 // context that works with any surface of a display.
88 if (hasEGLExtension("EGL_ANDROIDX_no_config_context") ||
89 hasEGLExtension("EGL_KHR_no_config_context")) {
90 mHasNoConfigContext = true;
91 }
Chia-I Wu767fcf72017-11-30 22:07:38 -080092
93 if (hasEGLExtension("EGL_ANDROID_native_fence_sync")) {
94 mHasNativeFenceSync = true;
95 }
96 if (hasEGLExtension("EGL_KHR_fence_sync")) {
97 mHasFenceSync = true;
98 }
99 if (hasEGLExtension("EGL_KHR_wait_sync")) {
100 mHasWaitSync = true;
101 }
Chia-I Wu401ef832017-12-01 10:52:22 -0800102
103 if (hasEGLExtension("EGL_ANDROID_image_crop")) {
104 mHasImageCrop = true;
105 }
106 if (hasEGLExtension("EGL_EXT_protected_content")) {
107 mHasProtectedContent = true;
108 }
Jorim Jaggi5b15ef62018-01-17 18:31:39 +0100109 if (hasEGLExtension("EGL_IMG_context_priority")) {
110 mHasContextPriority = true;
111 }
Chia-I Wu767d7c92017-11-30 13:22:48 -0800112}
113
114char const* GLExtensions::getEGLVersion() const {
115 return mEGLVersion.string();
116}
117
118char const* GLExtensions::getEGLExtensions() const {
119 return mEGLExtensions.string();
120}
121
122bool GLExtensions::hasEGLExtension(char const* extension) const {
123 const String8 s(extension);
124 return mEGLExtensionList.indexOf(s) >= 0;
125}
126
Mathias Agopian875d8e12013-06-07 15:35:48 -0700127// ---------------------------------------------------------------------------
128}; // namespace android