| Cody Northrop | 629ce4e | 2018-10-15 07:22:09 -0600 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2018 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 |  | 
|  | 17 | #ifndef ANDROID_EGL_LAYERS_H | 
|  | 18 | #define ANDROID_EGL_LAYERS_H | 
|  | 19 |  | 
| Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame] | 20 | #include <EGL/egldefs.h> | 
|  | 21 | #include <android/dlext.h> | 
|  | 22 | #include <dlfcn.h> | 
|  | 23 | #include <nativebridge/native_bridge.h> | 
|  | 24 | #include <nativeloader/native_loader.h> | 
|  | 25 |  | 
| Cody Northrop | 629ce4e | 2018-10-15 07:22:09 -0600 | [diff] [blame] | 26 | #include <string> | 
|  | 27 | #include <unordered_map> | 
|  | 28 | #include <vector> | 
|  | 29 |  | 
| Cody Northrop | 629ce4e | 2018-10-15 07:22:09 -0600 | [diff] [blame] | 30 | #include "egl_platform_entries.h" | 
|  | 31 |  | 
|  | 32 | typedef __eglMustCastToProperFunctionPointerType EGLFuncPointer; | 
|  | 33 |  | 
|  | 34 | namespace android { | 
|  | 35 |  | 
|  | 36 | class LayerLoader { | 
|  | 37 | public: | 
|  | 38 | static LayerLoader& getInstance(); | 
|  | 39 | ~LayerLoader(){}; | 
|  | 40 |  | 
|  | 41 | typedef void* (*PFNEGLGETNEXTLAYERPROCADDRESSPROC)(void*, const char*); | 
|  | 42 | typedef EGLFuncPointer (*layer_init_func)( | 
|  | 43 | const void* layer_id, PFNEGLGETNEXTLAYERPROCADDRESSPROC get_next_layer_proc_address); | 
|  | 44 | typedef EGLFuncPointer (*layer_setup_func)(const char* name, EGLFuncPointer next); | 
|  | 45 |  | 
|  | 46 | void LoadLayers(); | 
|  | 47 | void InitLayers(egl_connection_t*); | 
| Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame] | 48 | void LayerPlatformEntries(layer_setup_func layer_setup, EGLFuncPointer*, const char* const*); | 
|  | 49 | void LayerDriverEntries(layer_setup_func layer_setup, EGLFuncPointer*, const char* const*); | 
| Cody Northrop | 629ce4e | 2018-10-15 07:22:09 -0600 | [diff] [blame] | 50 | bool Initialized(); | 
|  | 51 | std::string GetDebugLayers(); | 
|  | 52 |  | 
|  | 53 | EGLFuncPointer GetGpaNext(unsigned i); | 
|  | 54 | EGLFuncPointer ApplyLayer(layer_setup_func layer_setup, const char* name, EGLFuncPointer next); | 
|  | 55 | EGLFuncPointer ApplyLayers(const char* name, EGLFuncPointer next); | 
|  | 56 |  | 
|  | 57 | std::vector<layer_init_func> layer_init_; | 
|  | 58 | std::vector<layer_setup_func> layer_setup_; | 
|  | 59 |  | 
|  | 60 | private: | 
| Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame] | 61 | LayerLoader() | 
|  | 62 | : layers_loaded_(false), | 
|  | 63 | initialized_(false), | 
|  | 64 | current_layer_(0), | 
|  | 65 | dlhandle_(nullptr), | 
|  | 66 | native_bridge_(false){}; | 
| Cody Northrop | 629ce4e | 2018-10-15 07:22:09 -0600 | [diff] [blame] | 67 | bool layers_loaded_; | 
|  | 68 | bool initialized_; | 
|  | 69 | unsigned current_layer_; | 
| Dmytro Chystiakov | 3e4db84 | 2019-11-07 12:09:36 -0800 | [diff] [blame] | 70 | void* dlhandle_; | 
|  | 71 | bool native_bridge_; | 
|  | 72 |  | 
| Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame] | 73 | template <typename Func = void*> | 
| Dmytro Chystiakov | 3e4db84 | 2019-11-07 12:09:36 -0800 | [diff] [blame] | 74 | Func GetTrampoline(const char* name) const { | 
|  | 75 | if (native_bridge_) { | 
| Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame] | 76 | return reinterpret_cast<Func>( | 
|  | 77 | android::NativeBridgeGetTrampoline(dlhandle_, name, nullptr, 0)); | 
| Dmytro Chystiakov | 3e4db84 | 2019-11-07 12:09:36 -0800 | [diff] [blame] | 78 | } | 
|  | 79 | return reinterpret_cast<Func>(dlsym(dlhandle_, name)); | 
|  | 80 | } | 
| Cody Northrop | 629ce4e | 2018-10-15 07:22:09 -0600 | [diff] [blame] | 81 | }; | 
|  | 82 |  | 
|  | 83 | }; // namespace android | 
|  | 84 |  | 
|  | 85 | #endif // ANDROID_EGL_LAYERS_H |