blob: 1e2783fc989440fda29ae947e82c8fa3d2576849 [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
20#include <string>
21#include <unordered_map>
22#include <vector>
23
Dmytro Chystiakov3e4db842019-11-07 12:09:36 -080024#include <android/dlext.h>
25#include <dlfcn.h>
Cody Northrop629ce4e2018-10-15 07:22:09 -060026
Dmytro Chystiakov3e4db842019-11-07 12:09:36 -080027#include <EGL/egldefs.h>
Cody Northrop629ce4e2018-10-15 07:22:09 -060028#include "egl_platform_entries.h"
29
Dmytro Chystiakov3e4db842019-11-07 12:09:36 -080030#include <nativebridge/native_bridge.h>
31#include <nativeloader/native_loader.h>
32
Cody Northrop629ce4e2018-10-15 07:22:09 -060033typedef __eglMustCastToProperFunctionPointerType EGLFuncPointer;
34
35namespace android {
36
37class LayerLoader {
38public:
39 static LayerLoader& getInstance();
40 ~LayerLoader(){};
41
42 typedef void* (*PFNEGLGETNEXTLAYERPROCADDRESSPROC)(void*, const char*);
43 typedef EGLFuncPointer (*layer_init_func)(
44 const void* layer_id, PFNEGLGETNEXTLAYERPROCADDRESSPROC get_next_layer_proc_address);
45 typedef EGLFuncPointer (*layer_setup_func)(const char* name, EGLFuncPointer next);
46
47 void LoadLayers();
48 void InitLayers(egl_connection_t*);
49 void LayerPlatformEntries(layer_setup_func layer_setup, EGLFuncPointer*, char const* const*);
50 void LayerDriverEntries(layer_setup_func layer_setup, EGLFuncPointer*, char const* const*);
51 bool Initialized();
52 std::string GetDebugLayers();
53
54 EGLFuncPointer GetGpaNext(unsigned i);
55 EGLFuncPointer ApplyLayer(layer_setup_func layer_setup, const char* name, EGLFuncPointer next);
56 EGLFuncPointer ApplyLayers(const char* name, EGLFuncPointer next);
57
58 std::vector<layer_init_func> layer_init_;
59 std::vector<layer_setup_func> layer_setup_;
60
61private:
Dmytro Chystiakov3e4db842019-11-07 12:09:36 -080062 LayerLoader() : layers_loaded_(false), initialized_(false), current_layer_(0), dlhandle_(nullptr), native_bridge_(false){};
Cody Northrop629ce4e2018-10-15 07:22:09 -060063 bool layers_loaded_;
64 bool initialized_;
65 unsigned current_layer_;
Dmytro Chystiakov3e4db842019-11-07 12:09:36 -080066 void* dlhandle_;
67 bool native_bridge_;
68
69 template<typename Func = void*>
70 Func GetTrampoline(const char* name) const {
71 if (native_bridge_) {
72 return reinterpret_cast<Func>(android::NativeBridgeGetTrampoline(
73 dlhandle_, name, nullptr, 0));
74 }
75 return reinterpret_cast<Func>(dlsym(dlhandle_, name));
76 }
Cody Northrop629ce4e2018-10-15 07:22:09 -060077};
78
79}; // namespace android
80
81#endif // ANDROID_EGL_LAYERS_H