Mathias Agopian | 9d17c05 | 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 | |
| 20 | #include <ctype.h> |
| 21 | #include <string.h> |
| 22 | #include <errno.h> |
| 23 | |
| 24 | #include <utils/Errors.h> |
| 25 | #include <utils/Singleton.h> |
| 26 | #include <utils/String8.h> |
| 27 | #include <utils/Vector.h> |
| 28 | |
| 29 | #include <EGL/egl.h> |
| 30 | |
| 31 | // ---------------------------------------------------------------------------- |
| 32 | namespace android { |
| 33 | // ---------------------------------------------------------------------------- |
| 34 | |
Mathias Agopian | 6fc5699 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 35 | struct egl_connection_t; |
Mathias Agopian | 9d17c05 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 36 | |
| 37 | class Loader : public Singleton<Loader> |
| 38 | { |
| 39 | friend class Singleton<Loader>; |
| 40 | |
| 41 | typedef __eglMustCastToProperFunctionPointerType (*getProcAddressType)( |
| 42 | const char*); |
| 43 | |
| 44 | enum { |
| 45 | EGL = 0x01, |
| 46 | GLESv1_CM = 0x02, |
| 47 | GLESv2 = 0x04 |
| 48 | }; |
| 49 | struct driver_t { |
| 50 | driver_t(void* gles); |
| 51 | ~driver_t(); |
| 52 | status_t set(void* hnd, int32_t api); |
| 53 | void* dso[3]; |
| 54 | }; |
| 55 | |
| 56 | struct entry_t { |
| 57 | entry_t() { } |
| 58 | entry_t(int dpy, int impl, const char* tag); |
| 59 | int dpy; |
| 60 | int impl; |
| 61 | String8 tag; |
| 62 | }; |
| 63 | |
| 64 | Vector<entry_t> gConfig; |
| 65 | getProcAddressType getProcAddress; |
| 66 | |
| 67 | const char* getTag(int dpy, int impl); |
| 68 | |
| 69 | public: |
| 70 | ~Loader(); |
| 71 | |
Mathias Agopian | 6fc5699 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 72 | void* open(EGLNativeDisplayType display, int impl, egl_connection_t* cnx); |
Mathias Agopian | 9d17c05 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 73 | status_t close(void* driver); |
| 74 | |
| 75 | private: |
| 76 | Loader(); |
Brian Swetland | a21c200 | 2010-09-20 12:58:15 -0700 | [diff] [blame] | 77 | void *load_driver(const char* kind, const char *tag, egl_connection_t* cnx, uint32_t mask); |
Mathias Agopian | 9d17c05 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 78 | |
| 79 | static __attribute__((noinline)) |
| 80 | void init_api(void* dso, |
| 81 | char const * const * api, |
| 82 | __eglMustCastToProperFunctionPointerType* curr, |
| 83 | getProcAddressType getProcAddress); |
| 84 | }; |
| 85 | |
| 86 | // ---------------------------------------------------------------------------- |
| 87 | }; // namespace android |
| 88 | // ---------------------------------------------------------------------------- |
| 89 | |
| 90 | #endif /* ANDROID_EGL_LOADER_H */ |