xref: /aosp_15_r20/external/deqp/framework/egl/wrapper/eglwLibrary.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program EGL Utilities
3  * ------------------------------------------
4  *
5  * Copyright 2014 The Android Open Source Project
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief EGL API Library.
22  *//*--------------------------------------------------------------------*/
23 
24 #include "eglwLibrary.hpp"
25 #include "tcuFunctionLibrary.hpp"
26 #include "deDynamicLibrary.hpp"
27 
28 #if defined(DEQP_EGL_DIRECT_LINK)
29 #include <EGL/egl.h>
30 #endif
31 
32 namespace eglw
33 {
34 
FuncPtrLibrary(void)35 FuncPtrLibrary::FuncPtrLibrary(void)
36 {
37 }
38 
~FuncPtrLibrary(void)39 FuncPtrLibrary::~FuncPtrLibrary(void)
40 {
41 }
42 
43 #include "eglwFuncPtrLibraryImpl.inl"
44 
45 namespace
46 {
47 
createStaticLibrary(void)48 tcu::FunctionLibrary *createStaticLibrary(void)
49 {
50 #if defined(DEQP_EGL_DIRECT_LINK)
51     static tcu::StaticFunctionLibrary::Entry s_staticEntries[] = {
52 #if defined(EGL_VERSION_1_5)
53 #include "eglwStaticLibrary15.inl"
54 #elif defined(EGL_VERSION_1_4)
55 #include "eglwStaticLibrary14.inl"
56 #endif
57     };
58     return new tcu::StaticFunctionLibrary(s_staticEntries, DE_LENGTH_OF_ARRAY(s_staticEntries));
59 #else
60     return new tcu::StaticFunctionLibrary(DE_NULL, 0);
61 #endif
62 }
63 
64 class CoreLoader : public FunctionLoader
65 {
66 public:
CoreLoader(const de::DynamicLibrary * dynLib)67     CoreLoader(const de::DynamicLibrary *dynLib)
68         : m_staticLib(createStaticLibrary())
69         , m_dynLib(dynLib)
70         , m_getProcAddress(DE_NULL)
71     {
72         // Try to obtain eglGetProcAddress
73         m_getProcAddress = (eglGetProcAddressFunc)m_staticLib->getFunction("eglGetProcAddress");
74 
75         if (!m_getProcAddress && m_dynLib)
76             m_getProcAddress = (eglGetProcAddressFunc)m_dynLib->getFunction("eglGetProcAddress");
77     }
78 
~CoreLoader(void)79     ~CoreLoader(void)
80     {
81         delete m_staticLib;
82     }
83 
get(const char * name) const84     GenericFuncType get(const char *name) const
85     {
86         GenericFuncType res = (GenericFuncType)DE_NULL;
87 
88         res = (GenericFuncType)m_staticLib->getFunction(name);
89 
90         if (!res && m_dynLib)
91             res = (GenericFuncType)m_dynLib->getFunction(name);
92 
93         if (!res && m_getProcAddress)
94             res = (GenericFuncType)m_getProcAddress(name);
95 
96         return res;
97     }
98 
99 protected:
100     tcu::FunctionLibrary *const m_staticLib;
101     const de::DynamicLibrary *m_dynLib;
102     eglGetProcAddressFunc m_getProcAddress;
103 };
104 
105 class ExtLoader : public FunctionLoader
106 {
107 public:
ExtLoader(const eglGetProcAddressFunc getProcAddress)108     ExtLoader(const eglGetProcAddressFunc getProcAddress) : m_getProcAddress(getProcAddress)
109     {
110     }
111 
get(const char * name) const112     GenericFuncType get(const char *name) const
113     {
114         return (GenericFuncType)m_getProcAddress(name);
115     }
116 
117 protected:
118     const eglGetProcAddressFunc m_getProcAddress;
119 };
120 
121 } // namespace
122 
DefaultLibrary(const char * dynamicLibraryName)123 DefaultLibrary::DefaultLibrary(const char *dynamicLibraryName) : m_dynLib(DE_NULL)
124 {
125     if (dynamicLibraryName)
126         m_dynLib = new de::DynamicLibrary(dynamicLibraryName);
127 
128     {
129         const CoreLoader loader(m_dynLib);
130         initCore(&m_egl, &loader);
131     }
132 
133     if (m_egl.getProcAddress)
134     {
135         const ExtLoader loader(m_egl.getProcAddress);
136         initExtensions(&m_egl, &loader);
137     }
138 }
139 
~DefaultLibrary(void)140 DefaultLibrary::~DefaultLibrary(void)
141 {
142     delete m_dynLib;
143 }
144 
getLibraryFileName(void)145 const char *DefaultLibrary::getLibraryFileName(void)
146 {
147 #if (DE_OS == DE_OS_ANDROID) || (DE_OS == DE_OS_UNIX)
148     return "libEGL.so";
149 #elif (DE_OS == DE_OS_WIN32)
150     return "libEGL.dll";
151 #else
152     return DE_NULL;
153 #endif
154 }
155 
156 } // namespace eglw
157