blob: 81742ab9ae00a0aab10ed9993711124011a4d2cb [file] [log] [blame]
Yiwei Zhang8af03062020-08-12 21:28:15 -07001/*
Mathias Agopiande586972009-05-28 17:39:03 -07002 ** Copyright 2009, The Android Open Source Project
3 **
Yiwei Zhang8af03062020-08-12 21:28:15 -07004 ** 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
Mathias Agopiande586972009-05-28 17:39:03 -07007 **
Yiwei Zhang8af03062020-08-12 21:28:15 -07008 ** http://www.apache.org/licenses/LICENSE-2.0
Mathias Agopiande586972009-05-28 17:39:03 -07009 **
Yiwei Zhang8af03062020-08-12 21:28:15 -070010 ** 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
Mathias Agopiande586972009-05-28 17:39:03 -070014 ** limitations under the License.
15 */
16
17#ifndef ANDROID_EGL_LOADER_H
18#define ANDROID_EGL_LOADER_H
19
Yiwei Zhang8af03062020-08-12 21:28:15 -070020#include <EGL/egl.h>
Mathias Agopian311b4792017-02-28 15:00:49 -080021#include <stdint.h>
Mathias Agopiande586972009-05-28 17:39:03 -070022
Mathias Agopiande586972009-05-28 17:39:03 -070023namespace android {
Mathias Agopiande586972009-05-28 17:39:03 -070024
Mathias Agopian618fa102009-10-14 02:06:37 -070025struct egl_connection_t;
Mathias Agopiande586972009-05-28 17:39:03 -070026
Mathias Agopian65421432017-03-08 11:49:05 -080027class Loader {
Mathias Agopian311b4792017-02-28 15:00:49 -080028 typedef __eglMustCastToProperFunctionPointerType (* getProcAddressType)(const char*);
Yiwei Zhang7cc58922018-10-10 11:37:43 -070029
Mathias Agopiande586972009-05-28 17:39:03 -070030 enum {
31 EGL = 0x01,
32 GLESv1_CM = 0x02,
Cody Northrop68d10352018-10-15 07:22:09 -060033 GLESv2 = 0x04,
34 PLATFORM = 0x08
Mathias Agopiande586972009-05-28 17:39:03 -070035 };
36 struct driver_t {
Chih-Hung Hsiehe8761d62016-09-01 11:26:34 -070037 explicit driver_t(void* gles);
Mathias Agopiande586972009-05-28 17:39:03 -070038 ~driver_t();
Mathias Agopian65421432017-03-08 11:49:05 -080039 // returns -errno
40 int set(void* hnd, int32_t api);
Mathias Agopiande586972009-05-28 17:39:03 -070041 void* dso[3];
42 };
Yiwei Zhang7cc58922018-10-10 11:37:43 -070043
Mathias Agopiande586972009-05-28 17:39:03 -070044 getProcAddressType getProcAddress;
Jesse Hall7a8d83e2016-12-20 15:24:28 -080045
Mathias Agopiande586972009-05-28 17:39:03 -070046public:
Mathias Agopian65421432017-03-08 11:49:05 -080047 static Loader& getInstance();
Mathias Agopiande586972009-05-28 17:39:03 -070048 ~Loader();
Yiwei Zhang7cc58922018-10-10 11:37:43 -070049
Mathias Agopianada798b2012-02-13 17:09:30 -080050 void* open(egl_connection_t* cnx);
Courtney Goeltzenleuchteree768c22018-10-25 11:43:52 -060051 void close(egl_connection_t* cnx);
Yiwei Zhang7cc58922018-10-10 11:37:43 -070052
Mathias Agopiande586972009-05-28 17:39:03 -070053private:
54 Loader();
Peiyong Lin8cd204d2019-04-19 14:05:17 -070055 driver_t* attempt_to_load_angle(egl_connection_t* cnx);
56 driver_t* attempt_to_load_updated_driver(egl_connection_t* cnx);
Peiyong Lin0d10b252019-04-30 18:03:04 -070057 driver_t* attempt_to_load_system_driver(egl_connection_t* cnx, const char* suffix, const bool exact);
Yiwei Zhang5e21eb32019-06-05 00:26:03 -070058 void unload_system_driver(egl_connection_t* cnx);
Peiyong Line83b8682019-04-18 17:23:02 -070059 void initialize_api(void* dso, egl_connection_t* cnx, uint32_t mask);
Courtney Goeltzenleuchterd1646cf2020-04-23 08:19:11 -060060 void init_angle_backend(void* dso, egl_connection_t* cnx);
Mathias Agopiande586972009-05-28 17:39:03 -070061
Yiwei Zhang8af03062020-08-12 21:28:15 -070062 static __attribute__((noinline)) void init_api(void* dso, const char* const* api,
63 const char* const* ref_api,
64 __eglMustCastToProperFunctionPointerType* curr,
65 getProcAddressType getProcAddress);
Mathias Agopiande586972009-05-28 17:39:03 -070066};
67
Mathias Agopiande586972009-05-28 17:39:03 -070068}; // namespace android
Mathias Agopiande586972009-05-28 17:39:03 -070069
70#endif /* ANDROID_EGL_LOADER_H */