blob: 705525d857a1e0ac17fba881cdaa144f24d464c5 [file] [log] [blame]
Cody Northrop629ce4e2018-10-15 07:22:09 -06001/*
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 Zhang8af03062020-08-12 21:28:15 -070020#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 Northrop629ce4e2018-10-15 07:22:09 -060026#include <string>
27#include <unordered_map>
28#include <vector>
29
Cody Northrop629ce4e2018-10-15 07:22:09 -060030#include "egl_platform_entries.h"
31
32typedef __eglMustCastToProperFunctionPointerType EGLFuncPointer;
33
34namespace android {
35
36class LayerLoader {
37public:
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 Zhang8af03062020-08-12 21:28:15 -070048 void LayerPlatformEntries(layer_setup_func layer_setup, EGLFuncPointer*, const char* const*);
49 void LayerDriverEntries(layer_setup_func layer_setup, EGLFuncPointer*, const char* const*);
Cody Northrop629ce4e2018-10-15 07:22:09 -060050 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
60private:
Yiwei Zhang8af03062020-08-12 21:28:15 -070061 LayerLoader()
62 : layers_loaded_(false),
63 initialized_(false),
64 current_layer_(0),
65 dlhandle_(nullptr),
66 native_bridge_(false){};
Cody Northrop629ce4e2018-10-15 07:22:09 -060067 bool layers_loaded_;
68 bool initialized_;
69 unsigned current_layer_;
Dmytro Chystiakov3e4db842019-11-07 12:09:36 -080070 void* dlhandle_;
71 bool native_bridge_;
72
Yiwei Zhang8af03062020-08-12 21:28:15 -070073 template <typename Func = void*>
Dmytro Chystiakov3e4db842019-11-07 12:09:36 -080074 Func GetTrampoline(const char* name) const {
75 if (native_bridge_) {
Yiwei Zhang8af03062020-08-12 21:28:15 -070076 return reinterpret_cast<Func>(
77 android::NativeBridgeGetTrampoline(dlhandle_, name, nullptr, 0));
Dmytro Chystiakov3e4db842019-11-07 12:09:36 -080078 }
79 return reinterpret_cast<Func>(dlsym(dlhandle_, name));
80 }
Cody Northrop629ce4e2018-10-15 07:22:09 -060081};
82
83}; // namespace android
84
85#endif // ANDROID_EGL_LAYERS_H