1 /*
2  ** Copyright 2009, 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_LOADER_H
18 #define ANDROID_EGL_LOADER_H
19 
20 #include <EGL/egl.h>
21 #include <stdint.h>
22 
23 namespace android {
24 
25 struct egl_connection_t;
26 
27 class Loader {
28     typedef __eglMustCastToProperFunctionPointerType (* getProcAddressType)(const char*);
29 
30     enum {
31         EGL         = 0x01,
32         GLESv1_CM   = 0x02,
33         GLESv2      = 0x04,
34         PLATFORM    = 0x08
35     };
36     struct driver_t {
37         explicit driver_t(void* gles);
38         ~driver_t();
39         // returns -errno
40         int set(void* hnd, int32_t api);
41         void* dso[3];
42     };
43 
44     getProcAddressType getProcAddress;
45 
46 public:
47     static Loader& getInstance();
48     ~Loader();
49 
50     void* open(egl_connection_t* cnx);
51     void close(egl_connection_t* cnx);
52 
53 private:
54     Loader();
55     driver_t* attempt_to_load_angle(egl_connection_t* cnx);
56     driver_t* attempt_to_load_updated_driver(egl_connection_t* cnx);
57     driver_t* attempt_to_load_system_driver(egl_connection_t* cnx, const char* suffix, const bool exact);
58     void unload_system_driver(egl_connection_t* cnx);
59     void initialize_api(void* dso, egl_connection_t* cnx, uint32_t mask);
60     void attempt_to_init_angle_backend(void* dso, egl_connection_t* cnx);
61 
62     static __attribute__((noinline)) void init_api(void* dso, const char* const* api,
63                                                    const char* const* ref_api,
64                                                    __eglMustCastToProperFunctionPointerType* curr,
65                                                    getProcAddressType getProcAddress);
66 };
67 
68 }; // namespace android
69 
70 #endif /* ANDROID_EGL_LOADER_H */
71