Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 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 | |
Mathias Agopian | 311b479 | 2017-02-28 15:00:49 -0800 | [diff] [blame] | 20 | #include <stdint.h> |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 21 | |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 22 | #include <EGL/egl.h> |
| 23 | |
| 24 | // ---------------------------------------------------------------------------- |
| 25 | namespace android { |
| 26 | // ---------------------------------------------------------------------------- |
| 27 | |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 28 | struct egl_connection_t; |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 29 | |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 30 | class Loader { |
Mathias Agopian | 311b479 | 2017-02-28 15:00:49 -0800 | [diff] [blame] | 31 | typedef __eglMustCastToProperFunctionPointerType (* getProcAddressType)(const char*); |
Yiwei Zhang | 7cc5892 | 2018-10-10 11:37:43 -0700 | [diff] [blame] | 32 | |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 33 | enum { |
| 34 | EGL = 0x01, |
| 35 | GLESv1_CM = 0x02, |
Cody Northrop | 68d1035 | 2018-10-15 07:22:09 -0600 | [diff] [blame] | 36 | GLESv2 = 0x04, |
| 37 | PLATFORM = 0x08 |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 38 | }; |
| 39 | struct driver_t { |
Chih-Hung Hsieh | e8761d6 | 2016-09-01 11:26:34 -0700 | [diff] [blame] | 40 | explicit driver_t(void* gles); |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 41 | ~driver_t(); |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 42 | // returns -errno |
| 43 | int set(void* hnd, int32_t api); |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 44 | void* dso[3]; |
| 45 | }; |
Yiwei Zhang | 7cc5892 | 2018-10-10 11:37:43 -0700 | [diff] [blame] | 46 | |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 47 | getProcAddressType getProcAddress; |
Jesse Hall | 7a8d83e | 2016-12-20 15:24:28 -0800 | [diff] [blame] | 48 | |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 49 | public: |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 50 | static Loader& getInstance(); |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 51 | ~Loader(); |
Yiwei Zhang | 7cc5892 | 2018-10-10 11:37:43 -0700 | [diff] [blame] | 52 | |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 53 | void* open(egl_connection_t* cnx); |
Courtney Goeltzenleuchter | ee768c2 | 2018-10-25 11:43:52 -0600 | [diff] [blame] | 54 | void close(egl_connection_t* cnx); |
Yiwei Zhang | 7cc5892 | 2018-10-10 11:37:43 -0700 | [diff] [blame] | 55 | |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 56 | private: |
| 57 | Loader(); |
Peiyong Lin | 8cd204d | 2019-04-19 14:05:17 -0700 | [diff] [blame] | 58 | driver_t* attempt_to_load_angle(egl_connection_t* cnx); |
| 59 | driver_t* attempt_to_load_updated_driver(egl_connection_t* cnx); |
Peiyong Lin | 0d10b25 | 2019-04-30 18:03:04 -0700 | [diff] [blame] | 60 | driver_t* attempt_to_load_system_driver(egl_connection_t* cnx, const char* suffix, const bool exact); |
Yiwei Zhang | 5e21eb3 | 2019-06-05 00:26:03 -0700 | [diff] [blame] | 61 | void unload_system_driver(egl_connection_t* cnx); |
Peiyong Lin | e83b868 | 2019-04-18 17:23:02 -0700 | [diff] [blame] | 62 | void initialize_api(void* dso, egl_connection_t* cnx, uint32_t mask); |
Courtney Goeltzenleuchter | c1a1a86 | 2020-04-23 08:19:11 -0600 | [diff] [blame] | 63 | void init_angle_backend(void* dso, egl_connection_t* cnx); |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 64 | |
| 65 | static __attribute__((noinline)) |
Yiwei Zhang | 7cc5892 | 2018-10-10 11:37:43 -0700 | [diff] [blame] | 66 | void init_api(void* dso, |
| 67 | char const * const * api, |
| 68 | char const * const * ref_api, |
| 69 | __eglMustCastToProperFunctionPointerType* curr, |
| 70 | getProcAddressType getProcAddress); |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | // ---------------------------------------------------------------------------- |
| 74 | }; // namespace android |
| 75 | // ---------------------------------------------------------------------------- |
| 76 | |
| 77 | #endif /* ANDROID_EGL_LOADER_H */ |