Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 1 | /* |
| 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 Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 17 | #include "GLExtensions.h" |
Peiyong Lin | cbc184f | 2018-08-22 13:24:10 -0700 | [diff] [blame] | 18 | |
Chia-I Wu | 07975f5 | 2018-10-01 14:14:27 -0700 | [diff] [blame] | 19 | #include <string> |
| 20 | #include <unordered_set> |
| 21 | |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 22 | #include <stdint.h> |
Chia-I Wu | b027f80 | 2017-11-29 14:00:52 -0800 | [diff] [blame] | 23 | #include <stdio.h> |
| 24 | #include <stdlib.h> |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 25 | |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 26 | ANDROID_SINGLETON_STATIC_INSTANCE(android::renderengine::gl::GLExtensions) |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 27 | |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 28 | namespace android { |
| 29 | namespace renderengine { |
| 30 | namespace gl { |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 31 | |
Chia-I Wu | 07975f5 | 2018-10-01 14:14:27 -0700 | [diff] [blame] | 32 | namespace { |
Chia-I Wu | 767d7c9 | 2017-11-30 13:22:48 -0800 | [diff] [blame] | 33 | |
Chia-I Wu | 07975f5 | 2018-10-01 14:14:27 -0700 | [diff] [blame] | 34 | class ExtensionSet { |
| 35 | public: |
| 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 Wu | 767d7c9 | 2017-11-30 13:22:48 -0800 | [diff] [blame] | 48 | |
Chia-I Wu | 07975f5 | 2018-10-01 14:14:27 -0700 | [diff] [blame] | 49 | bool hasExtension(const char* extension) const { return mExtensions.count(extension) > 0; } |
| 50 | |
| 51 | private: |
| 52 | std::unordered_set<std::string> mExtensions; |
| 53 | }; |
| 54 | |
| 55 | } // anonymous namespace |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 56 | |
Chia-I Wu | b027f80 | 2017-11-29 14:00:52 -0800 | [diff] [blame] | 57 | void 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 Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 62 | mExtensions = (char const*)extensions; |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | char const* GLExtensions::getVendor() const { |
| 66 | return mVendor.string(); |
| 67 | } |
| 68 | |
| 69 | char const* GLExtensions::getRenderer() const { |
| 70 | return mRenderer.string(); |
| 71 | } |
| 72 | |
| 73 | char const* GLExtensions::getVersion() const { |
| 74 | return mVersion.string(); |
| 75 | } |
| 76 | |
Chia-I Wu | 767d7c9 | 2017-11-30 13:22:48 -0800 | [diff] [blame] | 77 | char const* GLExtensions::getExtensions() const { |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 78 | return mExtensions.string(); |
| 79 | } |
| 80 | |
Chia-I Wu | 767d7c9 | 2017-11-30 13:22:48 -0800 | [diff] [blame] | 81 | void GLExtensions::initWithEGLStrings(char const* eglVersion, char const* eglExtensions) { |
| 82 | mEGLVersion = eglVersion; |
| 83 | mEGLExtensions = eglExtensions; |
Chia-I Wu | 07975f5 | 2018-10-01 14:14:27 -0700 | [diff] [blame] | 84 | |
| 85 | ExtensionSet extensionSet(eglExtensions); |
Chia-I Wu | 767d7c9 | 2017-11-30 13:22:48 -0800 | [diff] [blame] | 86 | |
| 87 | // EGL_ANDROIDX_no_config_context is an experimental extension with no |
| 88 | // written specification. It will be replaced by something more formal. |
| 89 | // SurfaceFlinger is using it to allow a single EGLContext to render to |
| 90 | // both a 16-bit primary display framebuffer and a 32-bit virtual display |
| 91 | // framebuffer. |
| 92 | // |
| 93 | // EGL_KHR_no_config_context is official extension to allow creating a |
| 94 | // context that works with any surface of a display. |
Chia-I Wu | 07975f5 | 2018-10-01 14:14:27 -0700 | [diff] [blame] | 95 | if (extensionSet.hasExtension("EGL_ANDROIDX_no_config_context") || |
| 96 | extensionSet.hasExtension("EGL_KHR_no_config_context")) { |
Chia-I Wu | 767d7c9 | 2017-11-30 13:22:48 -0800 | [diff] [blame] | 97 | mHasNoConfigContext = true; |
| 98 | } |
Chia-I Wu | 767fcf7 | 2017-11-30 22:07:38 -0800 | [diff] [blame] | 99 | |
Chia-I Wu | 07975f5 | 2018-10-01 14:14:27 -0700 | [diff] [blame] | 100 | if (extensionSet.hasExtension("EGL_ANDROID_native_fence_sync")) { |
Chia-I Wu | 767fcf7 | 2017-11-30 22:07:38 -0800 | [diff] [blame] | 101 | mHasNativeFenceSync = true; |
| 102 | } |
Chia-I Wu | 07975f5 | 2018-10-01 14:14:27 -0700 | [diff] [blame] | 103 | if (extensionSet.hasExtension("EGL_KHR_fence_sync")) { |
Chia-I Wu | 767fcf7 | 2017-11-30 22:07:38 -0800 | [diff] [blame] | 104 | mHasFenceSync = true; |
| 105 | } |
Chia-I Wu | 07975f5 | 2018-10-01 14:14:27 -0700 | [diff] [blame] | 106 | if (extensionSet.hasExtension("EGL_KHR_wait_sync")) { |
Chia-I Wu | 767fcf7 | 2017-11-30 22:07:38 -0800 | [diff] [blame] | 107 | mHasWaitSync = true; |
| 108 | } |
Chia-I Wu | 07975f5 | 2018-10-01 14:14:27 -0700 | [diff] [blame] | 109 | if (extensionSet.hasExtension("EGL_EXT_protected_content")) { |
Chia-I Wu | 401ef83 | 2017-12-01 10:52:22 -0800 | [diff] [blame] | 110 | mHasProtectedContent = true; |
| 111 | } |
Chia-I Wu | 07975f5 | 2018-10-01 14:14:27 -0700 | [diff] [blame] | 112 | if (extensionSet.hasExtension("EGL_IMG_context_priority")) { |
Jorim Jaggi | 5b15ef6 | 2018-01-17 18:31:39 +0100 | [diff] [blame] | 113 | mHasContextPriority = true; |
| 114 | } |
Peiyong Lin | a5e9f1b | 2018-11-27 22:49:37 -0800 | [diff] [blame] | 115 | if (extensionSet.hasExtension("EGL_KHR_surfaceless_context")) { |
| 116 | mHasSurfacelessContext = true; |
| 117 | } |
Chia-I Wu | 767d7c9 | 2017-11-30 13:22:48 -0800 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | char const* GLExtensions::getEGLVersion() const { |
| 121 | return mEGLVersion.string(); |
| 122 | } |
| 123 | |
| 124 | char const* GLExtensions::getEGLExtensions() const { |
| 125 | return mEGLExtensions.string(); |
| 126 | } |
| 127 | |
Peiyong Lin | 46080ef | 2018-10-26 18:43:14 -0700 | [diff] [blame] | 128 | } // namespace gl |
| 129 | } // namespace renderengine |
| 130 | } // namespace android |