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 | |
Alec Mouri | e2b61c6 | 2023-08-15 19:04:54 +0000 | [diff] [blame] | 26 | ANDROID_SINGLETON_STATIC_INSTANCE(android::renderengine::skia::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 { |
Alec Mouri | e2b61c6 | 2023-08-15 19:04:54 +0000 | [diff] [blame] | 30 | namespace skia { |
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; |
Peiyong Lin | fb530cf | 2018-12-15 05:07:38 +0000 | [diff] [blame] | 63 | |
| 64 | ExtensionSet extensionSet(mExtensions.c_str()); |
| 65 | if (extensionSet.hasExtension("GL_EXT_protected_textures")) { |
| 66 | mHasProtectedTexture = true; |
| 67 | } |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | char const* GLExtensions::getVendor() const { |
| 71 | return mVendor.string(); |
| 72 | } |
| 73 | |
| 74 | char const* GLExtensions::getRenderer() const { |
| 75 | return mRenderer.string(); |
| 76 | } |
| 77 | |
| 78 | char const* GLExtensions::getVersion() const { |
| 79 | return mVersion.string(); |
| 80 | } |
| 81 | |
Chia-I Wu | 767d7c9 | 2017-11-30 13:22:48 -0800 | [diff] [blame] | 82 | char const* GLExtensions::getExtensions() const { |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 83 | return mExtensions.string(); |
| 84 | } |
| 85 | |
Chia-I Wu | 767d7c9 | 2017-11-30 13:22:48 -0800 | [diff] [blame] | 86 | void GLExtensions::initWithEGLStrings(char const* eglVersion, char const* eglExtensions) { |
| 87 | mEGLVersion = eglVersion; |
| 88 | mEGLExtensions = eglExtensions; |
Chia-I Wu | 07975f5 | 2018-10-01 14:14:27 -0700 | [diff] [blame] | 89 | |
| 90 | ExtensionSet extensionSet(eglExtensions); |
Chia-I Wu | 767d7c9 | 2017-11-30 13:22:48 -0800 | [diff] [blame] | 91 | |
| 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 Wu | 07975f5 | 2018-10-01 14:14:27 -0700 | [diff] [blame] | 100 | if (extensionSet.hasExtension("EGL_ANDROIDX_no_config_context") || |
| 101 | extensionSet.hasExtension("EGL_KHR_no_config_context")) { |
Chia-I Wu | 767d7c9 | 2017-11-30 13:22:48 -0800 | [diff] [blame] | 102 | mHasNoConfigContext = true; |
| 103 | } |
Chia-I Wu | 767fcf7 | 2017-11-30 22:07:38 -0800 | [diff] [blame] | 104 | |
Chia-I Wu | 07975f5 | 2018-10-01 14:14:27 -0700 | [diff] [blame] | 105 | if (extensionSet.hasExtension("EGL_ANDROID_native_fence_sync")) { |
Chia-I Wu | 767fcf7 | 2017-11-30 22:07:38 -0800 | [diff] [blame] | 106 | mHasNativeFenceSync = true; |
| 107 | } |
Chia-I Wu | 07975f5 | 2018-10-01 14:14:27 -0700 | [diff] [blame] | 108 | if (extensionSet.hasExtension("EGL_KHR_fence_sync")) { |
Chia-I Wu | 767fcf7 | 2017-11-30 22:07:38 -0800 | [diff] [blame] | 109 | mHasFenceSync = true; |
| 110 | } |
Chia-I Wu | 07975f5 | 2018-10-01 14:14:27 -0700 | [diff] [blame] | 111 | if (extensionSet.hasExtension("EGL_KHR_wait_sync")) { |
Chia-I Wu | 767fcf7 | 2017-11-30 22:07:38 -0800 | [diff] [blame] | 112 | mHasWaitSync = true; |
| 113 | } |
Chia-I Wu | 07975f5 | 2018-10-01 14:14:27 -0700 | [diff] [blame] | 114 | if (extensionSet.hasExtension("EGL_EXT_protected_content")) { |
Chia-I Wu | 401ef83 | 2017-12-01 10:52:22 -0800 | [diff] [blame] | 115 | mHasProtectedContent = true; |
| 116 | } |
Chia-I Wu | 07975f5 | 2018-10-01 14:14:27 -0700 | [diff] [blame] | 117 | if (extensionSet.hasExtension("EGL_IMG_context_priority")) { |
Jorim Jaggi | 5b15ef6 | 2018-01-17 18:31:39 +0100 | [diff] [blame] | 118 | mHasContextPriority = true; |
| 119 | } |
Peiyong Lin | a5e9f1b | 2018-11-27 22:49:37 -0800 | [diff] [blame] | 120 | if (extensionSet.hasExtension("EGL_KHR_surfaceless_context")) { |
| 121 | mHasSurfacelessContext = true; |
| 122 | } |
Alec Mouri | d6f0946 | 2020-12-07 11:18:17 -0800 | [diff] [blame] | 123 | |
| 124 | if (extensionSet.hasExtension("EGL_NV_context_priority_realtime")) { |
| 125 | mHasRealtimePriority = true; |
| 126 | } |
Chia-I Wu | 767d7c9 | 2017-11-30 13:22:48 -0800 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | char const* GLExtensions::getEGLVersion() const { |
| 130 | return mEGLVersion.string(); |
| 131 | } |
| 132 | |
| 133 | char const* GLExtensions::getEGLExtensions() const { |
| 134 | return mEGLExtensions.string(); |
| 135 | } |
| 136 | |
Alec Mouri | e2b61c6 | 2023-08-15 19:04:54 +0000 | [diff] [blame] | 137 | } // namespace skia |
Peiyong Lin | 46080ef | 2018-10-26 18:43:14 -0700 | [diff] [blame] | 138 | } // namespace renderengine |
| 139 | } // namespace android |