Skip to content

Commit 4bdf553

Browse files
committed
Customize the libepoxy vcpkg port
- Resolve multithreading issues - Enable building as a static library Ref: anholt/libepoxy#265
1 parent 5e4bba1 commit 4bdf553

File tree

3 files changed

+226
-0
lines changed

3 files changed

+226
-0
lines changed

Scripts/Ports/libepoxy/portfile.cmake

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
if(VCPKG_TARGET_IS_LINUX AND NOT EXISTS "/usr/share/doc/libgles2/copyright")
2+
message(STATUS "libgles2-mesa-dev must be installed before libepoxy can build. Install it with \"apt-get install libgles2-mesa-dev\".")
3+
endif()
4+
5+
vcpkg_from_github(
6+
OUT_SOURCE_PATH SOURCE_PATH
7+
REPO anholt/libepoxy
8+
REF 1.5.10
9+
SHA512 6786f31c6e2865e68a90eb912900a86bf56fd3df4d78a477356886ac3b6ef52ac887b9c7a77aa027525f868ae9e88b12e5927ba56069c2e115acd631fca3abee
10+
HEAD_REF master
11+
PATCHES
12+
threading.patch
13+
)
14+
15+
# TODO: Enable EGL on Windows
16+
if (VCPKG_TARGET_IS_WINDOWS OR VCPKG_TARGET_IS_OSX)
17+
set(OPTIONS -Dglx=no -Degl=no -Dx11=false)
18+
else()
19+
set(OPTIONS -Dglx=yes -Degl=yes -Dx11=true)
20+
endif()
21+
if(VCPKG_TARGET_IS_WINDOWS)
22+
list(APPEND OPTIONS -Dc_std=c99)
23+
endif()
24+
25+
vcpkg_configure_meson(
26+
SOURCE_PATH "${SOURCE_PATH}"
27+
OPTIONS
28+
${OPTIONS}
29+
-Dtests=false
30+
)
31+
vcpkg_install_meson()
32+
vcpkg_copy_pdbs()
33+
34+
vcpkg_fixup_pkgconfig()
35+
36+
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/share/pkgconfig")
37+
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share/pkgconfig")
38+
39+
file(INSTALL "${SOURCE_PATH}/COPYING" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
diff --git a/src/dispatch_common.h b/src/dispatch_common.h
2+
index a136943..3449b22 100644
3+
--- a/src/dispatch_common.h
4+
+++ b/src/dispatch_common.h
5+
@@ -23,12 +23,18 @@
6+
7+
#include "config.h"
8+
9+
+#ifdef __GNUC__
10+
+#define EPOXY_THREADLOCAL __thread
11+
+#elif defined (_MSC_VER)
12+
+#define EPOXY_THREADLOCAL __declspec(thread)
13+
+#endif
14+
+
15+
#ifdef _WIN32
16+
#define PLATFORM_HAS_EGL ENABLE_EGL
17+
#define PLATFORM_HAS_GLX ENABLE_GLX
18+
#define PLATFORM_HAS_WGL 1
19+
#elif defined(__APPLE__)
20+
-#define PLATFORM_HAS_EGL 0
21+
+#define PLATFORM_HAS_EGL 0
22+
#define PLATFORM_HAS_GLX ENABLE_GLX
23+
#define PLATFORM_HAS_WGL 0
24+
#elif defined(ANDROID)
25+
diff --git a/src/dispatch_wgl.c b/src/dispatch_wgl.c
26+
index 7baf130..dc1b0c4 100644
27+
--- a/src/dispatch_wgl.c
28+
+++ b/src/dispatch_wgl.c
29+
@@ -27,9 +27,6 @@
30+
31+
#include "dispatch_common.h"
32+
33+
-static bool first_context_current = false;
34+
-static bool already_switched_to_dispatch_table = false;
35+
-
36+
/**
37+
* If we can determine the WGL extension support from the current
38+
* context, then return that, otherwise give the answer that will just
39+
@@ -75,71 +72,10 @@
40+
void
41+
epoxy_handle_external_wglMakeCurrent(void)
42+
{
43+
- if (!first_context_current) {
44+
- first_context_current = true;
45+
- } else {
46+
- if (!already_switched_to_dispatch_table) {
47+
- already_switched_to_dispatch_table = true;
48+
- gl_switch_to_dispatch_table();
49+
- wgl_switch_to_dispatch_table();
50+
- }
51+
-
52+
- gl_init_dispatch_table();
53+
- wgl_init_dispatch_table();
54+
- }
55+
+ gl_init_dispatch_table();
56+
+ wgl_init_dispatch_table();
57+
}
58+
59+
-/**
60+
- * This global symbol is apparently looked up by Windows when loading
61+
- * a DLL, but it doesn't declare the prototype.
62+
- */
63+
-BOOL WINAPI
64+
-DllMain(HINSTANCE dll, DWORD reason, LPVOID reserved);
65+
-
66+
-BOOL WINAPI
67+
-DllMain(HINSTANCE dll, DWORD reason, LPVOID reserved)
68+
-{
69+
- void *data;
70+
-
71+
- switch (reason) {
72+
- case DLL_PROCESS_ATTACH:
73+
- gl_tls_index = TlsAlloc();
74+
- if (gl_tls_index == TLS_OUT_OF_INDEXES)
75+
- return FALSE;
76+
- wgl_tls_index = TlsAlloc();
77+
- if (wgl_tls_index == TLS_OUT_OF_INDEXES)
78+
- return FALSE;
79+
-
80+
- first_context_current = false;
81+
-
82+
- /* FALLTHROUGH */
83+
-
84+
- case DLL_THREAD_ATTACH:
85+
- data = LocalAlloc(LPTR, gl_tls_size);
86+
- TlsSetValue(gl_tls_index, data);
87+
-
88+
- data = LocalAlloc(LPTR, wgl_tls_size);
89+
- TlsSetValue(wgl_tls_index, data);
90+
-
91+
- break;
92+
-
93+
- case DLL_THREAD_DETACH:
94+
- case DLL_PROCESS_DETACH:
95+
- data = TlsGetValue(gl_tls_index);
96+
- LocalFree(data);
97+
-
98+
- data = TlsGetValue(wgl_tls_index);
99+
- LocalFree(data);
100+
-
101+
- if (reason == DLL_PROCESS_DETACH) {
102+
- TlsFree(gl_tls_index);
103+
- TlsFree(wgl_tls_index);
104+
- }
105+
- break;
106+
- }
107+
-
108+
- return TRUE;
109+
-}
110+
111+
WRAPPER_VISIBILITY (BOOL)
112+
WRAPPER(epoxy_wglMakeCurrent)(HDC hdc, HGLRC hglrc)
113+
diff --git a/src/gen_dispatch.py b/src/gen_dispatch.py
114+
index 3daad84..ed0fb95 100755
115+
--- a/src/gen_dispatch.py
116+
+++ b/src/gen_dispatch.py
117+
@@ -639,7 +639,7 @@
118+
func.args_list))
119+
120+
def write_function_pointer(self, func):
121+
- self.outln('{0} epoxy_{1} = epoxy_{1}_global_rewrite_ptr;'.format(func.ptr_type, func.wrapped_name))
122+
+ self.outln('{0} epoxy_{1} = EPOXY_DISPATCH_PTR(epoxy_{1});'.format(func.ptr_type, func.wrapped_name))
123+
self.outln('')
124+
125+
def write_provider_enums(self):
126+
@@ -816,7 +816,11 @@
127+
self.write_thunks(func)
128+
self.outln('')
129+
130+
+ self.outln('#define EPOXY_DISPATCH_PTR(name) name##_global_rewrite_ptr')
131+
+
132+
self.outln('#if USING_DISPATCH_TABLE')
133+
+ self.outln('#undef EPOXY_DISPATCH_PTR')
134+
+ self.outln('#define EPOXY_DISPATCH_PTR(name) name##_dispatch_table_thunk')
135+
136+
self.outln('static struct dispatch_table resolver_table = {')
137+
for func in self.sorted_functions:
138+
@@ -824,14 +828,15 @@
139+
self.outln('};')
140+
self.outln('')
141+
142+
- self.outln('uint32_t {0}_tls_index;'.format(self.target))
143+
- self.outln('uint32_t {0}_tls_size = sizeof(struct dispatch_table);'.format(self.target))
144+
- self.outln('')
145+
+ self.outln('EPOXY_THREADLOCAL struct dispatch_table {0}_tls_data = {{'.format(self.target))
146+
+ for func in self.sorted_functions:
147+
+ self.outln(' epoxy_{0}_dispatch_table_rewrite_ptr, /* {0} */'.format(func.wrapped_name))
148+
+ self.outln('};')
149+
150+
self.outln('static inline struct dispatch_table *')
151+
self.outln('get_dispatch_table(void)')
152+
self.outln('{')
153+
- self.outln(' return TlsGetValue({0}_tls_index);'.format(self.target))
154+
+ self.outln(' return &{0}_tls_data;'.format(self.target))
155+
self.outln('}')
156+
self.outln('')
157+
158+
@@ -843,16 +848,6 @@
159+
self.outln('}')
160+
self.outln('')
161+
162+
- self.outln('void')
163+
- self.outln('{0}_switch_to_dispatch_table(void)'.format(self.target))
164+
- self.outln('{')
165+
-
166+
- for func in self.sorted_functions:
167+
- self.outln(' epoxy_{0} = epoxy_{0}_dispatch_table_thunk;'.format(func.wrapped_name))
168+
-
169+
- self.outln('}')
170+
- self.outln('')
171+
-
172+
self.outln('#endif /* !USING_DISPATCH_TABLE */')
173+
174+
for func in self.sorted_functions:

Scripts/Ports/libepoxy/vcpkg.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "libepoxy",
3+
"version-semver": "1.5.10",
4+
"port-version": 1,
5+
"description": "Epoxy is a library for handling OpenGL function pointer management for you",
6+
"homepage": "https://github.com/anholt/libepoxy",
7+
"dependencies": [
8+
{
9+
"name": "vcpkg-tool-meson",
10+
"host": true
11+
}
12+
]
13+
}

0 commit comments

Comments
 (0)