| 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 |  | 
| Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 19 | #include <stdint.h> | 
| Chia-I Wu | b027f80 | 2017-11-29 14:00:52 -0800 | [diff] [blame] | 20 | #include <stdio.h> | 
|  | 21 | #include <stdlib.h> | 
| Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 22 |  | 
| Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 23 | ANDROID_SINGLETON_STATIC_INSTANCE(android::renderengine::gl::GLExtensions) | 
| Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 24 |  | 
| Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 25 | namespace android { | 
|  | 26 | namespace renderengine { | 
|  | 27 | namespace gl { | 
| Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 28 |  | 
| Chia-I Wu | 767d7c9 | 2017-11-30 13:22:48 -0800 | [diff] [blame] | 29 | SortedVector<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 Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 45 |  | 
| Chia-I Wu | b027f80 | 2017-11-29 14:00:52 -0800 | [diff] [blame] | 46 | void 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 Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 51 | mExtensions = (char const*)extensions; | 
| Chia-I Wu | 767d7c9 | 2017-11-30 13:22:48 -0800 | [diff] [blame] | 52 | mExtensionList = parseExtensionString(mExtensions); | 
| Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 53 | } | 
|  | 54 |  | 
| Chia-I Wu | b027f80 | 2017-11-29 14:00:52 -0800 | [diff] [blame] | 55 | bool GLExtensions::hasExtension(char const* extension) const { | 
| Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 56 | const String8 s(extension); | 
|  | 57 | return mExtensionList.indexOf(s) >= 0; | 
|  | 58 | } | 
|  | 59 |  | 
|  | 60 | char const* GLExtensions::getVendor() const { | 
|  | 61 | return mVendor.string(); | 
|  | 62 | } | 
|  | 63 |  | 
|  | 64 | char const* GLExtensions::getRenderer() const { | 
|  | 65 | return mRenderer.string(); | 
|  | 66 | } | 
|  | 67 |  | 
|  | 68 | char const* GLExtensions::getVersion() const { | 
|  | 69 | return mVersion.string(); | 
|  | 70 | } | 
|  | 71 |  | 
| Chia-I Wu | 767d7c9 | 2017-11-30 13:22:48 -0800 | [diff] [blame] | 72 | char const* GLExtensions::getExtensions() const { | 
| Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 73 | return mExtensions.string(); | 
|  | 74 | } | 
|  | 75 |  | 
| Chia-I Wu | 767d7c9 | 2017-11-30 13:22:48 -0800 | [diff] [blame] | 76 | void 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 Wu | 767fcf7 | 2017-11-30 22:07:38 -0800 | [diff] [blame] | 93 |  | 
|  | 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 Wu | 401ef83 | 2017-12-01 10:52:22 -0800 | [diff] [blame] | 103 | if (hasEGLExtension("EGL_EXT_protected_content")) { | 
|  | 104 | mHasProtectedContent = true; | 
|  | 105 | } | 
| Jorim Jaggi | 5b15ef6 | 2018-01-17 18:31:39 +0100 | [diff] [blame] | 106 | if (hasEGLExtension("EGL_IMG_context_priority")) { | 
|  | 107 | mHasContextPriority = true; | 
|  | 108 | } | 
| Chia-I Wu | 767d7c9 | 2017-11-30 13:22:48 -0800 | [diff] [blame] | 109 | } | 
|  | 110 |  | 
|  | 111 | char const* GLExtensions::getEGLVersion() const { | 
|  | 112 | return mEGLVersion.string(); | 
|  | 113 | } | 
|  | 114 |  | 
|  | 115 | char const* GLExtensions::getEGLExtensions() const { | 
|  | 116 | return mEGLExtensions.string(); | 
|  | 117 | } | 
|  | 118 |  | 
|  | 119 | bool GLExtensions::hasEGLExtension(char const* extension) const { | 
|  | 120 | const String8 s(extension); | 
|  | 121 | return mEGLExtensionList.indexOf(s) >= 0; | 
|  | 122 | } | 
|  | 123 |  | 
| Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 124 | }  // namespace gl | 
|  | 125 | }  // namespace renderengine | 
|  | 126 | }  // namespace android |