Skip to content

Commit 16149d7

Browse files
committed
Customize the libepoxy vcpkg port
- Resolve multithreading issues - Enable building as a static library Unfortunately, using it as a static library causes linking errors, so we're keeping the line that forces it to be a dynamic library on Windows. Ref: anholt/libepoxy#265
1 parent 8e01ce9 commit 16149d7

File tree

3 files changed

+233
-0
lines changed

3 files changed

+233
-0
lines changed

Scripts/Ports/libepoxy/portfile.cmake

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