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 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 26 #include <string> 27 #include <unordered_map> 28 #include <vector> 29 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(); ~LayerLoader()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*); 48 void LayerPlatformEntries(layer_setup_func layer_setup, EGLFuncPointer*, const char* const*); 49 void LayerDriverEntries(layer_setup_func layer_setup, EGLFuncPointer*, const char* const*); 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: LayerLoader()61 LayerLoader() 62 : layers_loaded_(false), 63 initialized_(false), 64 current_layer_(0), 65 dlhandle_(nullptr), 66 native_bridge_(false){}; 67 bool layers_loaded_; 68 bool initialized_; 69 unsigned current_layer_; 70 void* dlhandle_; 71 bool native_bridge_; 72 73 template <typename Func = void*> GetTrampoline(const char * name)74 Func GetTrampoline(const char* name) const { 75 if (native_bridge_) { 76 return reinterpret_cast<Func>( 77 android::NativeBridgeGetTrampoline(dlhandle_, name, nullptr, 0)); 78 } 79 return reinterpret_cast<Func>(dlsym(dlhandle_, name)); 80 } 81 }; 82 83 }; // namespace android 84 85 #endif // ANDROID_EGL_LAYERS_H 86