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