• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 	{
53 #	if defined(EGL_VERSION_1_5)
54 #		include "eglwStaticLibrary15.inl"
55 #	elif defined(EGL_VERSION_1_4)
56 #		include "eglwStaticLibrary14.inl"
57 #	endif
58 	};
59 	return new tcu::StaticFunctionLibrary(s_staticEntries, DE_LENGTH_OF_ARRAY(s_staticEntries));
60 #else
61 	return new tcu::StaticFunctionLibrary(DE_NULL, 0);
62 #endif
63 }
64 
65 class CoreLoader : public FunctionLoader
66 {
67 public:
CoreLoader(const de::DynamicLibrary * dynLib)68 	CoreLoader (const de::DynamicLibrary* dynLib)
69 		: m_staticLib		(createStaticLibrary())
70 		, m_dynLib			(dynLib)
71 		, m_getProcAddress	(DE_NULL)
72 	{
73 		// Try to obtain eglGetProcAddress
74 		m_getProcAddress = (eglGetProcAddressFunc)m_staticLib->getFunction("eglGetProcAddress");
75 
76 		if (!m_getProcAddress && m_dynLib)
77 			m_getProcAddress = (eglGetProcAddressFunc)m_dynLib->getFunction("eglGetProcAddress");
78 	}
79 
~CoreLoader(void)80 	~CoreLoader (void)
81 	{
82 		delete m_staticLib;
83 	}
84 
get(const char * name) const85 	GenericFuncType get (const char* name) const
86 	{
87 		GenericFuncType res = (GenericFuncType)DE_NULL;
88 
89 		res = (GenericFuncType)m_staticLib->getFunction(name);
90 
91 		if (!res && m_dynLib)
92 			res = (GenericFuncType)m_dynLib->getFunction(name);
93 
94 		if (!res && m_getProcAddress)
95 			res = (GenericFuncType)m_getProcAddress(name);
96 
97 		return res;
98 	}
99 
100 protected:
101 	tcu::FunctionLibrary* const		m_staticLib;
102 	const de::DynamicLibrary*		m_dynLib;
103 	eglGetProcAddressFunc			m_getProcAddress;
104 };
105 
106 class ExtLoader : public FunctionLoader
107 {
108 public:
ExtLoader(const eglGetProcAddressFunc getProcAddress)109 	ExtLoader (const eglGetProcAddressFunc getProcAddress)
110 		: m_getProcAddress(getProcAddress)
111 	{
112 	}
113 
get(const char * name) const114 	GenericFuncType get (const char* name) const
115 	{
116 		return (GenericFuncType)m_getProcAddress(name);
117 	}
118 
119 protected:
120 	const eglGetProcAddressFunc			m_getProcAddress;
121 };
122 
123 } // anonymous
124 
DefaultLibrary(const char * dynamicLibraryName)125 DefaultLibrary::DefaultLibrary (const char* dynamicLibraryName)
126 	: m_dynLib(DE_NULL)
127 {
128 	if (dynamicLibraryName)
129 		m_dynLib = new de::DynamicLibrary(dynamicLibraryName);
130 
131 	{
132 		const CoreLoader loader(m_dynLib);
133 		initCore(&m_egl, &loader);
134 	}
135 
136 	if (m_egl.getProcAddress)
137 	{
138 		const ExtLoader loader(m_egl.getProcAddress);
139 		initExtensions(&m_egl, &loader);
140 	}
141 }
142 
~DefaultLibrary(void)143 DefaultLibrary::~DefaultLibrary (void)
144 {
145 	delete m_dynLib;
146 }
147 
getLibraryFileName(void)148 const char* DefaultLibrary::getLibraryFileName (void)
149 {
150 #if (DE_OS == DE_OS_ANDROID) || (DE_OS == DE_OS_UNIX)
151 	return "libEGL.so";
152 #elif (DE_OS == DE_OS_WIN32)
153 	return "libEGL.dll";
154 #else
155 	return DE_NULL;
156 #endif
157 }
158 
159 } // eglw
160