aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/hw/xwin/glx/glshim.c
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2013-12-22 13:12:15 +0100
committermarha <marha@users.sourceforge.net>2013-12-22 13:16:58 +0100
commit1d03b6f684ab1ea6772f00058605a9ebb2910628 (patch)
tree8b393bd59900eba6aa9010cab9e714922cac2536 /xorg-server/hw/xwin/glx/glshim.c
parent5567cf1befbda64f2dc6fae1d337567cd984b46e (diff)
parentc81020559f329a516191927222b3698ba7370aca (diff)
downloadvcxsrv-1d03b6f684ab1ea6772f00058605a9ebb2910628.tar.gz
vcxsrv-1d03b6f684ab1ea6772f00058605a9ebb2910628.tar.bz2
vcxsrv-1d03b6f684ab1ea6772f00058605a9ebb2910628.zip
Merge remote-tracking branch 'origin/released'
* origin/released: libxtrans fontconfig glproto libX11 libxcb xcbproto mesa xserver pixman xkeyboard-config git update 22 Dec 2013 Conflicts: mesalib/include/GL/glext.h mesalib/src/mesa/drivers/dri/common/dri_util.c mesalib/src/mesa/drivers/dri/swrast/swrast.c xorg-server/damageext/damageext.c xorg-server/dix/dispatch.c xorg-server/glx/glxdriswrast.c xorg-server/glx/indirect_dispatch.c xorg-server/glx/indirect_dispatch_swap.c xorg-server/glx/indirect_program.c xorg-server/glx/render2.c xorg-server/glx/render2swap.c xorg-server/hw/xwin/glx/gen_gl_wrappers.py xorg-server/hw/xwin/glx/glthunk.c xorg-server/hw/xwin/glx/indirect.c xorg-server/include/os.h xorg-server/present/present_request.c
Diffstat (limited to 'xorg-server/hw/xwin/glx/glshim.c')
-rw-r--r--xorg-server/hw/xwin/glx/glshim.c124
1 files changed, 124 insertions, 0 deletions
diff --git a/xorg-server/hw/xwin/glx/glshim.c b/xorg-server/hw/xwin/glx/glshim.c
new file mode 100644
index 000000000..7109196c0
--- /dev/null
+++ b/xorg-server/hw/xwin/glx/glshim.c
@@ -0,0 +1,124 @@
+/*
+ * File: glshim.c
+ * Purpose: GL shim which redirects to a specified DLL
+ *
+ * Copyright (c) Jon TURNEY 2013
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ A GL shim which redirects to a specified DLL
+
+ XWin is statically linked with this, rather than the system libGL, so that
+ GL calls can be directed to mesa cygGL-1.dll, or cygnativeGLthunk.dll
+ (which contains cdecl-to-stdcall thunks to the native openGL32.dll)
+*/
+
+#ifdef HAVE_XWIN_CONFIG_H
+#include <xwin-config.h>
+#endif
+
+#define GL_GLEXT_LEGACY
+#include <GL/gl.h>
+#undef GL_ARB_imaging
+#undef GL_VERSION_1_3
+#include <GL/glext.h>
+
+#include <X11/Xwindows.h>
+#include <os.h>
+#include "glwindows.h"
+#include <glx/glxserver.h>
+
+static HMODULE hMod = NULL;
+
+/*
+ Implement the __glGetProcAddress function by just using GetProcAddress() on the selected DLL
+*/
+void *glXGetProcAddressARB(const char *symbol)
+{
+ void *proc;
+
+ /* Default to the mesa GL implementation if one hasn't been selected yet */
+ if (!hMod)
+ glWinSelectImplementation(0);
+
+ proc = GetProcAddress(hMod, symbol);
+
+ if (glxWinDebugSettings.enableGLcallTrace)
+ ErrorF("glXGetProcAddressARB: Resolved '%s' in %p to %p\n", symbol, hMod, proc);
+
+ return proc;
+}
+
+/*
+ Select a GL implementation DLL
+*/
+int glWinSelectImplementation(int native)
+{
+ const char *dllname;
+
+ if (native) {
+ dllname = "cygnativeGLthunk.dll";
+ }
+ else {
+ dllname = "cygGL-1.dll";
+ }
+
+ hMod = LoadLibraryEx(dllname, NULL, 0);
+ if (hMod == NULL) {
+ ErrorF("glWinSelectGLimplementation: Could not load '%s'\n", dllname);
+ return -1;
+ }
+
+ ErrorF("glWinSelectGLimplementation: Loaded '%s'\n", dllname);
+
+ /* Connect __glGetProcAddress() to our implementation of glXGetProcAddressARB() above */
+ __glXsetGetProcAddress((glx_gpa_proc)glXGetProcAddressARB);
+
+ return 0;
+}
+
+#define RESOLVE_RET(proctype, symbol, retval) \
+ proctype proc = (proctype)glXGetProcAddressARB(symbol); \
+ if (proc == NULL) return retval;
+
+#define RESOLVE(proctype, symbol) RESOLVE_RET(proctype, symbol,)
+#define RESOLVED_PROC proc
+
+/* Include generated shims for direct linkage to GL functions which are in the ABI */
+#include "generated_gl_shim.c"
+
+/*
+ Special wrapper for glAddSwapHintRectWIN for copySubBuffers
+
+ Only used with native GL if the GL_WIN_swap_hint extension is present, so we enable
+ GLX_MESA_copy_sub_buffer
+*/
+typedef void (__stdcall * PFNGLADDSWAPHINTRECTWIN) (GLint x, GLint y,
+ GLsizei width,
+ GLsizei height);
+
+void
+glAddSwapHintRectWINWrapper(GLint x, GLint y, GLsizei width,
+ GLsizei height)
+{
+ RESOLVE(PFNGLADDSWAPHINTRECTWIN, "glAddSwapHintRectWIN");
+ RESOLVED_PROC(x, y, width, height);
+}