blob: 32da303a92329af98b61b6b3171983f75593d844 [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
Chia-I Wu07975f52018-10-01 14:14:27 -070019#include <string>
20#include <unordered_set>
21
Mathias Agopian875d8e12013-06-07 15:35:48 -070022#include <stdint.h>
Chia-I Wub027f802017-11-29 14:00:52 -080023#include <stdio.h>
24#include <stdlib.h>
Mathias Agopian875d8e12013-06-07 15:35:48 -070025
Alec Mourie2b61c62023-08-15 19:04:54 +000026ANDROID_SINGLETON_STATIC_INSTANCE(android::renderengine::skia::GLExtensions)
Mathias Agopian875d8e12013-06-07 15:35:48 -070027
Peiyong Lin833074a2018-08-28 11:53:54 -070028namespace android {
29namespace renderengine {
Alec Mourie2b61c62023-08-15 19:04:54 +000030namespace skia {
Mathias Agopian875d8e12013-06-07 15:35:48 -070031
Chia-I Wu07975f52018-10-01 14:14:27 -070032namespace {
Chia-I Wu767d7c92017-11-30 13:22:48 -080033
Chia-I Wu07975f52018-10-01 14:14:27 -070034class ExtensionSet {
35public:
36 ExtensionSet(const char* extensions) {
37 char const* curr = extensions;
38 char const* head = curr;
39 do {
40 head = strchr(curr, ' ');
41 size_t len = head ? head - curr : strlen(curr);
42 if (len > 0) {
43 mExtensions.emplace(curr, len);
44 }
45 curr = head + 1;
46 } while (head);
47 }
Chia-I Wu767d7c92017-11-30 13:22:48 -080048
Chia-I Wu07975f52018-10-01 14:14:27 -070049 bool hasExtension(const char* extension) const { return mExtensions.count(extension) > 0; }
50
51private:
52 std::unordered_set<std::string> mExtensions;
53};
54
55} // anonymous namespace
Mathias Agopian875d8e12013-06-07 15:35:48 -070056
Chia-I Wub027f802017-11-29 14:00:52 -080057void GLExtensions::initWithGLStrings(GLubyte const* vendor, GLubyte const* renderer,
58 GLubyte const* version, GLubyte const* extensions) {
59 mVendor = (char const*)vendor;
60 mRenderer = (char const*)renderer;
61 mVersion = (char const*)version;
Mathias Agopian875d8e12013-06-07 15:35:48 -070062 mExtensions = (char const*)extensions;
Peiyong Linfb530cf2018-12-15 05:07:38 +000063
64 ExtensionSet extensionSet(mExtensions.c_str());
65 if (extensionSet.hasExtension("GL_EXT_protected_textures")) {
66 mHasProtectedTexture = true;
67 }
Mathias Agopian875d8e12013-06-07 15:35:48 -070068}
69
70char const* GLExtensions::getVendor() const {
71 return mVendor.string();
72}
73
74char const* GLExtensions::getRenderer() const {
75 return mRenderer.string();
76}
77
78char const* GLExtensions::getVersion() const {
79 return mVersion.string();
80}
81
Chia-I Wu767d7c92017-11-30 13:22:48 -080082char const* GLExtensions::getExtensions() const {
Mathias Agopian875d8e12013-06-07 15:35:48 -070083 return mExtensions.string();
84}
85
Chia-I Wu767d7c92017-11-30 13:22:48 -080086void GLExtensions::initWithEGLStrings(char const* eglVersion, char const* eglExtensions) {
87 mEGLVersion = eglVersion;
88 mEGLExtensions = eglExtensions;
Chia-I Wu07975f52018-10-01 14:14:27 -070089
90 ExtensionSet extensionSet(eglExtensions);
Chia-I Wu767d7c92017-11-30 13:22:48 -080091
92 // EGL_ANDROIDX_no_config_context is an experimental extension with no
93 // written specification. It will be replaced by something more formal.
94 // SurfaceFlinger is using it to allow a single EGLContext to render to
95 // both a 16-bit primary display framebuffer and a 32-bit virtual display
96 // framebuffer.
97 //
98 // EGL_KHR_no_config_context is official extension to allow creating a
99 // context that works with any surface of a display.
Chia-I Wu07975f52018-10-01 14:14:27 -0700100 if (extensionSet.hasExtension("EGL_ANDROIDX_no_config_context") ||
101 extensionSet.hasExtension("EGL_KHR_no_config_context")) {
Chia-I Wu767d7c92017-11-30 13:22:48 -0800102 mHasNoConfigContext = true;
103 }
Chia-I Wu767fcf72017-11-30 22:07:38 -0800104
Chia-I Wu07975f52018-10-01 14:14:27 -0700105 if (extensionSet.hasExtension("EGL_ANDROID_native_fence_sync")) {
Chia-I Wu767fcf72017-11-30 22:07:38 -0800106 mHasNativeFenceSync = true;
107 }
Chia-I Wu07975f52018-10-01 14:14:27 -0700108 if (extensionSet.hasExtension("EGL_KHR_fence_sync")) {
Chia-I Wu767fcf72017-11-30 22:07:38 -0800109 mHasFenceSync = true;
110 }
Chia-I Wu07975f52018-10-01 14:14:27 -0700111 if (extensionSet.hasExtension("EGL_KHR_wait_sync")) {
Chia-I Wu767fcf72017-11-30 22:07:38 -0800112 mHasWaitSync = true;
113 }
Chia-I Wu07975f52018-10-01 14:14:27 -0700114 if (extensionSet.hasExtension("EGL_EXT_protected_content")) {
Chia-I Wu401ef832017-12-01 10:52:22 -0800115 mHasProtectedContent = true;
116 }
Chia-I Wu07975f52018-10-01 14:14:27 -0700117 if (extensionSet.hasExtension("EGL_IMG_context_priority")) {
Jorim Jaggi5b15ef62018-01-17 18:31:39 +0100118 mHasContextPriority = true;
119 }
Peiyong Lina5e9f1b2018-11-27 22:49:37 -0800120 if (extensionSet.hasExtension("EGL_KHR_surfaceless_context")) {
121 mHasSurfacelessContext = true;
122 }
Alec Mourid6f09462020-12-07 11:18:17 -0800123
124 if (extensionSet.hasExtension("EGL_NV_context_priority_realtime")) {
125 mHasRealtimePriority = true;
126 }
Chia-I Wu767d7c92017-11-30 13:22:48 -0800127}
128
129char const* GLExtensions::getEGLVersion() const {
130 return mEGLVersion.string();
131}
132
133char const* GLExtensions::getEGLExtensions() const {
134 return mEGLExtensions.string();
135}
136
Alec Mourie2b61c62023-08-15 19:04:54 +0000137} // namespace skia
Peiyong Lin46080ef2018-10-26 18:43:14 -0700138} // namespace renderengine
139} // namespace android