diff options
author | Jon Turney <[email protected]> | 2016-07-11 21:38:16 +0100 |
---|---|---|
committer | Jon Turney <[email protected]> | 2016-09-15 13:14:43 +0100 |
commit | 533b3530c1292a39ea12437d1376c77bc7e584b9 (patch) | |
tree | 9eb840d793ee592449eb6d356a10be201bca1e02 /src/glx/windows | |
parent | 2ac09ac5a52b133934c2d96683eab40b9555fdb1 (diff) |
direct-to-native-GL for GLX clients on Cygwin ("Windows-DRI")
Structurally, this is very similar to the existing Apple-DRI code, except I
have chosen to implement this using the __GLXDRIdisplay, etc. vtables (as
suggested originally in [1]), rather than a maze of ifdefs. This also means
that LIBGL_ALWAYS_SOFTWARE and LIBGL_ALWAYS_INDIRECT work as expected.
[1] https://lists.freedesktop.org/archives/mesa-dev/2010-May/000756.html
This adds:
* the Windows-DRI extension protocol headers and the windowsdriproto.pc
file, for use in building the Windows-DRI extension for the X server
* a Windows-DRI extension helper client library
* a Windows-specific DRI implementation for GLX clients
The server is queried for Windows-DRI extension support on the screen before
using it (to detect the case where WGL is disabled or can't be activated).
The server is queried for fbconfigID to pixelformatindex mapping, which is
used to augment glx_config.
The server is queried for a native handle for the drawable (which is of a
different type for windows, pixmaps and pbuffers), which is used to augment
__GLXDRIdrawable.
Various GLX extensions are enabled depending on if the equivalent WGL
extension is available.
Diffstat (limited to 'src/glx/windows')
-rw-r--r-- | src/glx/windows/Makefile.am | 31 | ||||
-rw-r--r-- | src/glx/windows/wgl.c | 108 | ||||
-rw-r--r-- | src/glx/windows/wgl.h | 44 | ||||
-rw-r--r-- | src/glx/windows/windows_drawable.c | 192 | ||||
-rw-r--r-- | src/glx/windows/windowsdriconst.h | 45 | ||||
-rw-r--r-- | src/glx/windows/windowsdriproto.pc.in | 9 | ||||
-rw-r--r-- | src/glx/windows/windowsdristr.h | 152 | ||||
-rw-r--r-- | src/glx/windows/windowsgl.c | 403 | ||||
-rw-r--r-- | src/glx/windows/windowsgl.h | 52 | ||||
-rw-r--r-- | src/glx/windows/windowsgl_internal.h | 67 | ||||
-rw-r--r-- | src/glx/windows/xwindowsdri.c | 237 | ||||
-rw-r--r-- | src/glx/windows/xwindowsdri.h | 59 |
12 files changed, 1399 insertions, 0 deletions
diff --git a/src/glx/windows/Makefile.am b/src/glx/windows/Makefile.am new file mode 100644 index 00000000000..c76af8156a2 --- /dev/null +++ b/src/glx/windows/Makefile.am @@ -0,0 +1,31 @@ +noinst_LTLIBRARIES = libwindowsdri.la libwindowsglx.la + +# protocol defines for the Windows-DRI server extension +windowsdriincludedir = $(includedir)/X11/extensions +windowsdriinclude_HEADERS = windowsdriconst.h windowsdristr.h + +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = windowsdriproto.pc + +# library for using the Windows-DRI server extension +libwindowsdri_la_SOURCES = xwindowsdri.c xwindowsdri.h + +# native rendering GL for windows +libwindowsglx_la_SOURCES = \ + windowsgl.c \ + windowsgl.h \ + windowsgl_internal.h \ + windows_drawable.c \ + wgl.c + +libwindowsglx_la_CFLAGS = \ + -I$(top_srcdir)/include \ + -I$(top_srcdir)/src \ + -I$(top_srcdir)/src/glx \ + -I$(top_srcdir)/src/mapi \ + -I$(top_srcdir)/src/mapi/glapi \ + -I$(top_builddir)/src/mapi/glapi \ + $(VISIBILITY_CFLAGS) \ + $(SHARED_GLAPI_CFLAGS) \ + $(DEFINES) \ + $(X11_INCLUDES) diff --git a/src/glx/windows/wgl.c b/src/glx/windows/wgl.c new file mode 100644 index 00000000000..ffc97675072 --- /dev/null +++ b/src/glx/windows/wgl.c @@ -0,0 +1,108 @@ +/* + * Copyright © 2014 Jon Turney + * + * 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 (including the next + * paragraph) 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 AUTHORS OR COPYRIGHT HOLDERS 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. + */ + +/* + Wrapper functions for calling WGL extension functions + */ + +#include "wgl.h" + +#include <stdio.h> + +#define RESOLVE_DECL(type) \ + static type type##proc = NULL; + +#define PRERESOLVE(type, symbol) \ + type##proc = (type)wglGetProcAddress(symbol); \ + if (type##proc == NULL) \ + printf("Can't resolve \"%s\"\n", symbol); + +#define CHECK_RESOLVED(type, retval) \ + if (type##proc == NULL) { \ + return retval; \ + } + +#define RESOLVED_PROC(type) type##proc + +RESOLVE_DECL(PFNWGLGETEXTENSIONSSTRINGARBPROC); +RESOLVE_DECL(PFNWGLCREATECONTEXTATTRIBSARBPROC); +RESOLVE_DECL(PFNWGLMAKECONTEXTCURRENTARBPROC); +RESOLVE_DECL(PFNWGLCREATEPBUFFERARBPROC); +RESOLVE_DECL(PFNWGLGETPBUFFERDCARBPROC); +RESOLVE_DECL(PFNWGLRELEASEPBUFFERDCARBPROC); +RESOLVE_DECL(PFNWGLDESTROYPBUFFERARBPROC); + +void wglResolveExtensionProcs(void) +{ + PRERESOLVE(PFNWGLGETEXTENSIONSSTRINGARBPROC, "wglGetExtensionsStringARB"); + PRERESOLVE(PFNWGLCREATECONTEXTATTRIBSARBPROC, "wglCreateContextAttribsARB"); + PRERESOLVE(PFNWGLMAKECONTEXTCURRENTARBPROC, "wglMakeContextCurrentARB"); + PRERESOLVE(PFNWGLCREATEPBUFFERARBPROC, "wglCreatePbufferARB"); + PRERESOLVE(PFNWGLGETPBUFFERDCARBPROC, "wglGetPbufferDCARB"); + PRERESOLVE(PFNWGLRELEASEPBUFFERDCARBPROC, "wglReleasePbufferDCARB"); + PRERESOLVE(PFNWGLDESTROYPBUFFERARBPROC, "wglDestroyPbufferARB"); +} + +const char *wglGetExtensionsStringARB(HDC hdc_) +{ + CHECK_RESOLVED(PFNWGLGETEXTENSIONSSTRINGARBPROC, ""); + return RESOLVED_PROC(PFNWGLGETEXTENSIONSSTRINGARBPROC)(hdc_); +} + +HGLRC wglCreateContextAttribsARB(HDC hdc_, HGLRC hShareContext_, + const int *attribList_) +{ + CHECK_RESOLVED(PFNWGLCREATECONTEXTATTRIBSARBPROC, NULL); + return RESOLVED_PROC(PFNWGLCREATECONTEXTATTRIBSARBPROC)(hdc_, hShareContext_, attribList_); +} + +BOOL wglMakeContextCurrentARB(HDC hDrawDC_, HDC hReadDC_, HGLRC hglrc_) +{ + CHECK_RESOLVED(PFNWGLMAKECONTEXTCURRENTARBPROC, FALSE); + return RESOLVED_PROC(PFNWGLMAKECONTEXTCURRENTARBPROC)(hDrawDC_, hReadDC_, hglrc_); +} + +HPBUFFERARB wglCreatePbufferARB(HDC hDC_, int iPixelFormat_, int iWidth_, + int iHeight_, const int *piAttribList_) +{ + CHECK_RESOLVED(PFNWGLCREATEPBUFFERARBPROC, NULL); + return RESOLVED_PROC(PFNWGLCREATEPBUFFERARBPROC)(hDC_, iPixelFormat_, iWidth_, iHeight_, piAttribList_); +} + +HDC wglGetPbufferDCARB(HPBUFFERARB hPbuffer_) +{ + CHECK_RESOLVED(PFNWGLGETPBUFFERDCARBPROC, NULL); + return RESOLVED_PROC(PFNWGLGETPBUFFERDCARBPROC)(hPbuffer_); +} + +int wglReleasePbufferDCARB(HPBUFFERARB hPbuffer_, HDC hDC_) +{ + CHECK_RESOLVED(PFNWGLRELEASEPBUFFERDCARBPROC, 0) + return RESOLVED_PROC(PFNWGLRELEASEPBUFFERDCARBPROC)(hPbuffer_, hDC_); +} + +BOOL wglDestroyPbufferARB(HPBUFFERARB hPbuffer_) +{ + CHECK_RESOLVED(PFNWGLDESTROYPBUFFERARBPROC, FALSE); + return RESOLVED_PROC(PFNWGLDESTROYPBUFFERARBPROC)(hPbuffer_); +} diff --git a/src/glx/windows/wgl.h b/src/glx/windows/wgl.h new file mode 100644 index 00000000000..b4cb2fcbd70 --- /dev/null +++ b/src/glx/windows/wgl.h @@ -0,0 +1,44 @@ +/* + * Copyright © 2014 Jon Turney + * + * 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 (including the next + * paragraph) 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 AUTHORS OR COPYRIGHT HOLDERS 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. + */ + +#ifndef wgl_h +#define wgl_h + +#include <X11/Xmd.h> // for BOOL +#include <X11/Xwindows.h> // as this doesn't provide one +#include <GL/gl.h> +#include <GL/wglext.h> + +void wglResolveExtensionProcs(void); + +const char *wglGetExtensionsStringARB(HDC hdc_); +HGLRC wglCreateContextAttribsARB(HDC hdc_, HGLRC hShareContext_, + const int *attribList_); +BOOL wglMakeContextCurrentARB(HDC hDrawDC_, HDC hReadDC_, HGLRC hglrc_); +HPBUFFERARB wglCreatePbufferARB(HDC hDC_, int iPixelFormat_, int iWidth_, + int iHeight_, const int *piAttribList_); +HDC wglGetPbufferDCARB(HPBUFFERARB hPbuffer_); +int wglReleasePbufferDCARB(HPBUFFERARB hPbuffer_, HDC hDC_); +BOOL wglDestroyPbufferARB(HPBUFFERARB hPbuffer_); + +#endif /* wgl_h */ diff --git a/src/glx/windows/windows_drawable.c b/src/glx/windows/windows_drawable.c new file mode 100644 index 00000000000..3d8227d3b7d --- /dev/null +++ b/src/glx/windows/windows_drawable.c @@ -0,0 +1,192 @@ +/* + * Copyright © 2014 Jon Turney + * + * 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 (including the next + * paragraph) 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 AUTHORS OR COPYRIGHT HOLDERS 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. + */ + +#include "windowsgl.h" +#include "windowsgl_internal.h" +#include "windowsdriconst.h" +#include "wgl.h" + +#include <stdio.h> + +/* + * Window drawable + */ + +static +HDC window_getdc(windowsDrawable *d) +{ + return GetDC(d->hWnd); +} + +static +void window_releasedc(windowsDrawable *d, HDC dc) +{ + ReleaseDC(d->hWnd, dc); +} + +static struct windowsdrawable_callbacks window_callbacks = { + .type = WindowsDRIDrawableWindow, + .getdc = window_getdc, + .releasedc = window_releasedc +}; + +/* + * Pixmap drawable + */ + +static +HDC pixmap_getdc(windowsDrawable *d) +{ + return d->dibDC; +} + +static +void pixmap_releasedc(windowsDrawable *d, HDC dc) +{ + GdiFlush(); +} + +static struct windowsdrawable_callbacks pixmap_callbacks = { + .type = WindowsDRIDrawablePixmap, + .getdc = pixmap_getdc, + .releasedc = pixmap_releasedc +}; + +/* + * Pbuffer drawable + */ + +static +HDC pbuffer_getdc(windowsDrawable *d) +{ + return wglGetPbufferDCARB(d->hPbuffer); +} + +static +void pbuffer_releasedc(windowsDrawable *d, HDC dc) +{ + wglReleasePbufferDCARB(d->hPbuffer, dc); +} + +static struct windowsdrawable_callbacks pbuffer_callbacks = { + .type = WindowsDRIDrawablePbuffer, + .getdc = pbuffer_getdc, + .releasedc = pbuffer_releasedc +}; + +/* + * + */ + +windowsDrawable * +windows_create_drawable(int type, void *handle) +{ + windowsDrawable *d; + + d = calloc(1, sizeof *d); + if (d == NULL) + return NULL; + + switch (type) + { + case WindowsDRIDrawableWindow: + d->hWnd = handle; + d->callbacks = &window_callbacks; + break; + + case WindowsDRIDrawablePixmap: + { + BITMAPINFOHEADER *pBmpHeader; + void *pBits; + + char name[MAX_PATH]; + + d->callbacks = &pixmap_callbacks; + + // Access file mapping object by a name + snprintf(name, sizeof(name), "Local\\CYGWINX_WINDOWSDRI_%08lx", (uintptr_t)handle); + d->hSection = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, name); + if (!d->hSection) + printf("OpenFileMapping failed %x\n", GetLastError()); + + // Create a screen-compatible DC + d->dibDC = CreateCompatibleDC(NULL); + + // Map the shared memory section to access the BITMAPINFOHEADER + pBmpHeader = (BITMAPINFOHEADER *)MapViewOfFile(d->hSection, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(BITMAPINFOHEADER)); + if (!pBmpHeader) + printf("MapViewOfFile failed %x\n", GetLastError()); + + // Create a DIB using the file mapping + d->hDIB = CreateDIBSection(d->dibDC, (BITMAPINFO *) pBmpHeader, + DIB_RGB_COLORS, &pBits, d->hSection, + sizeof(BITMAPINFOHEADER)); + + // Done with the BITMAPINFOHEADER + UnmapViewOfFile(pBmpHeader); + + // Select the DIB into the DC + d->hOldDIB = SelectObject(d->dibDC, d->hDIB); + } + break; + + case WindowsDRIDrawablePbuffer: + d->hPbuffer = handle; + d->callbacks = &pbuffer_callbacks; + break; + } + + return d; +} + +void +windows_destroy_drawable(windowsDrawable *drawable) +{ + switch (drawable->callbacks->type) + { + case WindowsDRIDrawableWindow: + break; + + case WindowsDRIDrawablePixmap: + { + // Select the default DIB into the DC + SelectObject(drawable->dibDC, drawable->hOldDIB); + + // delete the screen-compatible DC + DeleteDC(drawable->dibDC); + + // Delete the DIB + DeleteObject(drawable->hDIB); + + // Close the file mapping object + CloseHandle(drawable->hSection); + } + break; + + case WindowsDRIDrawablePbuffer: + + break; + } + + free(drawable); +} diff --git a/src/glx/windows/windowsdriconst.h b/src/glx/windows/windowsdriconst.h new file mode 100644 index 00000000000..b9b28226fe2 --- /dev/null +++ b/src/glx/windows/windowsdriconst.h @@ -0,0 +1,45 @@ +/* + * Copyright © 2014 Jon Turney + * + * 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 (including the next + * paragraph) 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 AUTHORS OR COPYRIGHT HOLDERS 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. + */ + +#ifndef WINDOWSDRICONST_H +#define WINDOWSDRICONST_H + +/* Requests */ +#define X_WindowsDRIQueryVersion 0 +#define X_WindowsDRIQueryDirectRenderingCapable 1 +#define X_WindowsDRIQueryDrawable 9 +#define X_WindowsDRIFBConfigToPixelFormat 10 + +/* Events */ +#define WindowsDRINumberEvents 0 + +/* Errors */ +#define WindowsDRIClientNotLocal 0 +#define WindowsDRINumberErrors (WindowsDRIClientNotLocal + 1) + +/* Kinds of Drawables */ +#define WindowsDRIDrawableWindow 0 +#define WindowsDRIDrawablePixmap 1 +#define WindowsDRIDrawablePbuffer 2 + +#endif /* WINDOWSDRICONST_H */ diff --git a/src/glx/windows/windowsdriproto.pc.in b/src/glx/windows/windowsdriproto.pc.in new file mode 100644 index 00000000000..224923d1fcb --- /dev/null +++ b/src/glx/windows/windowsdriproto.pc.in @@ -0,0 +1,9 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: windowsdriproto +Description: Windows-DRI extension headers +Version: 1.0.0 +Cflags: -I${includedir} diff --git a/src/glx/windows/windowsdristr.h b/src/glx/windows/windowsdristr.h new file mode 100644 index 00000000000..07ab2310c82 --- /dev/null +++ b/src/glx/windows/windowsdristr.h @@ -0,0 +1,152 @@ +/* + * Copyright © 2014 Jon Turney + * + * 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 (including the next + * paragraph) 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 AUTHORS OR COPYRIGHT HOLDERS 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. + */ + +#ifndef WINDOWSDRISTR_H +#define WINDOWSDRISTR_H + +#include "windowsdriconst.h" + +#define WINDOWSDRINAME "Windows-DRI" + +#define WINDOWS_DRI_MAJOR_VERSION 1 /* current version numbers */ +#define WINDOWS_DRI_MINOR_VERSION 0 +#define WINDOWS_DRI_PATCH_VERSION 0 + +typedef struct _WindowsDRIQueryVersion +{ + CARD8 reqType; /* always DRIReqCode */ + CARD8 driReqType; /* always X_DRIQueryVersion */ + CARD16 length B16; +} xWindowsDRIQueryVersionReq; +#define sz_xWindowsDRIQueryVersionReq 4 + +typedef struct +{ + BYTE type; /* X_Reply */ + BOOL pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD16 majorVersion B16; /* major version of DRI protocol */ + CARD16 minorVersion B16; /* minor version of DRI protocol */ + CARD32 patchVersion B32; /* patch version of DRI protocol */ + CARD32 pad3 B32; + CARD32 pad4 B32; + CARD32 pad5 B32; + CARD32 pad6 B32; +} xWindowsDRIQueryVersionReply; +#define sz_xWindowsDRIQueryVersionReply 32 + +typedef struct _WindowsDRIQueryDirectRenderingCapable +{ + CARD8 reqType; /* always DRIReqCode */ + CARD8 driReqType; /* X_DRIQueryDirectRenderingCapable */ + CARD16 length B16; + CARD32 screen B32; +} xWindowsDRIQueryDirectRenderingCapableReq; +#define sz_xWindowsDRIQueryDirectRenderingCapableReq 8 + +typedef struct +{ + BYTE type; /* X_Reply */ + BOOL pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + BOOL isCapable; + BOOL pad2; + BOOL pad3; + BOOL pad4; + CARD32 pad5 B32; + CARD32 pad6 B32; + CARD32 pad7 B32; + CARD32 pad8 B32; + CARD32 pad9 B32; +} xWindowsDRIQueryDirectRenderingCapableReply; +#define sz_xWindowsDRIQueryDirectRenderingCapableReply 32 + +typedef struct _WindowsDRINotify +{ + BYTE type; /* always eventBase + event type */ + BYTE kind; + CARD16 sequenceNumber B16; + CARD32 time B32; /* time of change */ + CARD32 pad1 B32; + CARD32 pad2 B32; + CARD32 pad3 B32; + CARD32 pad4 B32; + CARD32 pad5 B32; + CARD32 pad6 B32; +} xWindowsDRINotifyEvent; +#define sz_xWindowsDRINotifyEvent 32 + +typedef struct _WindowsDRIQueryDrawable +{ + CARD8 reqType; /* always DRIReqCode */ + CARD8 driReqType; /* always X_DRIQueryDrawable */ + CARD16 length B16; + CARD32 screen B32; + CARD32 drawable B32; +} xWindowsDRIQueryDrawableReq; +#define sz_xWindowsDRIQueryDrawableReq 12 + +typedef struct +{ + BYTE type; /* X_Reply */ + BOOL pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 drawable_type B32; + CARD32 handle B32; + CARD32 pad3 B32; + CARD32 pad4 B32; + CARD32 pad5 B32; + CARD32 pad6 B32; +} xWindowsDRIQueryDrawableReply; +#define sz_xWindowsDRIQueryDrawableReply 32 + +typedef struct _WindowsDRIFBConfigToPixelFormat +{ + CARD8 reqType; /* always DRIReqCode */ + CARD8 driReqType; /* always X_DRIFBConfigToPixelFormat */ + CARD16 length B16; + CARD32 screen B32; + CARD32 fbConfigID B32; +} xWindowsDRIFBConfigToPixelFormatReq; + +#define sz_xWindowsDRIFBConfigToPixelFormatReq 12 + +typedef struct +{ + BYTE type; /* X_Reply */ + BOOL pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 pixelFormatIndex B32; + CARD32 pad2 B32; + CARD32 pad3 B32; + CARD32 pad4 B32; + CARD32 pad5 B32; + CARD32 pad6 B32; +} xWindowsDRIFBConfigToPixelFormatReply; +#define sz_xWindowsDRIFBConfigToPixelFormatReply 32 + +#endif /* WINDOWSDRISTR_H */ diff --git a/src/glx/windows/windowsgl.c b/src/glx/windows/windowsgl.c new file mode 100644 index 00000000000..56849da8371 --- /dev/null +++ b/src/glx/windows/windowsgl.c @@ -0,0 +1,403 @@ +/* + * Copyright © 2014 Jon Turney + * + * 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 (including the next + * paragraph) 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 AUTHORS OR COPYRIGHT HOLDERS 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. + */ + +#include "windowsgl.h" +#include "windowsgl_internal.h" + +#include "glapi.h" +#include "wgl.h" + +#include <dlfcn.h> +#include <assert.h> +#include <stdio.h> +#include <strings.h> + +static struct _glapi_table *windows_api = NULL; + +static void * +windows_get_dl_handle(void) +{ + static void *dl_handle = NULL; + + if (!dl_handle) + dl_handle = dlopen("cygnativeGLthunk.dll", RTLD_NOW); + + return dl_handle; +} + +static void +windows_glapi_create_table(void) +{ + if (windows_api) + return; + + windows_api = _glapi_create_table_from_handle(windows_get_dl_handle(), "gl"); + assert(windows_api); +} + +static void windows_glapi_set_dispatch(void) +{ + windows_glapi_create_table(); + _glapi_set_dispatch(windows_api); +} + +windowsContext * +windows_create_context(int pxfi, windowsContext *shared) +{ + windowsContext *gc; + + gc = calloc(1, sizeof *gc); + if (gc == NULL) + return NULL; + + // create a temporary, invisible window +#define GL_TEMP_WINDOW_CLASS "glTempWndClass" + { + static wATOM glTempWndClass = 0; + + if (glTempWndClass == 0) { + WNDCLASSEX wc; + wc.cbSize = sizeof(WNDCLASSEX); + wc.style = CS_HREDRAW | CS_VREDRAW; + wc.lpfnWndProc = DefWindowProc; + wc.cbClsExtra = 0; + wc.cbWndExtra = 0; + wc.hInstance = GetModuleHandle(NULL); + wc.hIcon = 0; + wc.hCursor = 0; + wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); + wc.lpszMenuName = NULL; + wc.lpszClassName = GL_TEMP_WINDOW_CLASS; + wc.hIconSm = 0; + RegisterClassEx(&wc); + } + } + + HWND hwnd = CreateWindowExA(0, + GL_TEMP_WINDOW_CLASS, + "glWindow", + 0, + 0, 0, 0, 0, + NULL, NULL, GetModuleHandle(NULL), NULL); + HDC hdc = GetDC(hwnd); + + // We must set the windows pixel format before we can create a WGL context + gc->pxfi = pxfi; + SetPixelFormat(hdc, gc->pxfi, NULL); + + gc->ctx = wglCreateContext(hdc); + + if (shared && gc->ctx) + wglShareLists(shared->ctx, gc->ctx); + + ReleaseDC(hwnd, hdc); + DestroyWindow(hwnd); + + if (!gc->ctx) + { + free(gc); + return NULL; + } + + return gc; +} + +windowsContext * +windows_create_context_attribs(int pxfi, windowsContext *shared, const int *attribList) +{ + windowsContext *gc; + + gc = calloc(1, sizeof *gc); + if (gc == NULL) + return NULL; + + // create a temporary, invisible window +#define GL_TEMP_WINDOW_CLASS "glTempWndClass" + { + static wATOM glTempWndClass = 0; + + if (glTempWndClass == 0) { + WNDCLASSEX wc; + wc.cbSize = sizeof(WNDCLASSEX); + wc.style = CS_HREDRAW | CS_VREDRAW; + wc.lpfnWndProc = DefWindowProc; + wc.cbClsExtra = 0; + wc.cbWndExtra = 0; + wc.hInstance = GetModuleHandle(NULL); + wc.hIcon = 0; + wc.hCursor = 0; + wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); + wc.lpszMenuName = NULL; + wc.lpszClassName = GL_TEMP_WINDOW_CLASS; + wc.hIconSm = 0; + RegisterClassEx(&wc); + } + } + + HWND hwnd = CreateWindowExA(0, + GL_TEMP_WINDOW_CLASS, + "glWindow", + 0, + 0, 0, 0, 0, + NULL, NULL, GetModuleHandle(NULL), NULL); + HDC hdc = GetDC(hwnd); + HGLRC shareContext = NULL; + if (shared) + shareContext = shared->ctx; + + // We must set the windows pixel format before we can create a WGL context + gc->pxfi = pxfi; + SetPixelFormat(hdc, gc->pxfi, NULL); + + gc->ctx = wglCreateContextAttribsARB(hdc, shareContext, attribList); + + ReleaseDC(hwnd, hdc); + DestroyWindow(hwnd); + + if (!gc->ctx) + { + free(gc); + return NULL; + } + + return gc; +} + +void +windows_destroy_context(windowsContext *context) +{ + wglDeleteContext(context->ctx); + context->ctx = NULL; + free(context); +} + +int windows_bind_context(windowsContext *context, windowsDrawable *draw, windowsDrawable *read) +{ + HDC drawDc = draw->callbacks->getdc(draw); + + if (!draw->pxfi) + { + SetPixelFormat(drawDc, context->pxfi, NULL); + draw->pxfi = context->pxfi; + } + + if ((read != NULL) && (read != draw)) + { + /* + If there is a separate read drawable, create a separate read DC, and + use the wglMakeContextCurrent extension to make the context current + drawing to one DC and reading from the other + + Should only occur when WGL_ARB_make_current_read extension is present + */ + HDC readDc = read->callbacks->getdc(read); + + BOOL ret = wglMakeContextCurrentARB(drawDc, readDc, context->ctx); + + read->callbacks->releasedc(read, readDc); + + if (!ret) { + printf("wglMakeContextCurrentARB error: %08x\n", GetLastError()); + return FALSE; + } + } + else + { + /* Otherwise, just use wglMakeCurrent */ + BOOL ret = wglMakeCurrent(drawDc, context->ctx); + if (!ret) { + printf("wglMakeCurrent error: %08x\n", GetLastError()); + return FALSE; + } + } + + draw->callbacks->releasedc(draw, drawDc); + + windows_glapi_set_dispatch(); + + return TRUE; +} + +void windows_unbind_context(windowsContext * context) +{ + wglMakeCurrent(NULL, NULL); +} + +/* + * + */ + +void +windows_swap_buffers(windowsDrawable *draw) +{ + HDC drawDc = GetDC(draw->hWnd); + SwapBuffers(drawDc); + ReleaseDC(draw->hWnd, drawDc); +} + + +typedef void (__stdcall * PFNGLADDSWAPHINTRECTWIN) (GLint x, GLint y, + GLsizei width, + GLsizei height); + +static void +glAddSwapHintRectWIN(GLint x, GLint y, GLsizei width, + GLsizei height) +{ + PFNGLADDSWAPHINTRECTWIN proc = (PFNGLADDSWAPHINTRECTWIN)wglGetProcAddress("glAddSwapHintRectWIN"); + if (proc) + proc(x, y, width, height); +} + +void +windows_copy_subbuffer(windowsDrawable *draw, + int x, int y, int width, int height) +{ + glAddSwapHintRectWIN(x, y, width, height); + windows_swap_buffers(draw); +} + +/* + * Helper function for calling a test function on an initial context + */ +static void +windows_call_with_context(void (*proc)(HDC, void *), void *args) +{ + // create window class +#define WIN_GL_TEST_WINDOW_CLASS "GLTest" + { + static wATOM glTestWndClass = 0; + + if (glTestWndClass == 0) { + WNDCLASSEX wc; + + wc.cbSize = sizeof(WNDCLASSEX); + wc.style = CS_HREDRAW | CS_VREDRAW; + wc.lpfnWndProc = DefWindowProc; + wc.cbClsExtra = 0; + wc.cbWndExtra = 0; + wc.hInstance = GetModuleHandle(NULL); + wc.hIcon = 0; + wc.hCursor = 0; + wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); + wc.lpszMenuName = NULL; + wc.lpszClassName = WIN_GL_TEST_WINDOW_CLASS; + wc.hIconSm = 0; + glTestWndClass = RegisterClassEx(&wc); + } + } + + // create an invisible window for a scratch DC + HWND hwnd = CreateWindowExA(0, + WIN_GL_TEST_WINDOW_CLASS, + "GL Renderer Capabilities Test Window", + 0, 0, 0, 0, 0, NULL, NULL, GetModuleHandle(NULL), + NULL); + if (hwnd) { + HDC hdc = GetDC(hwnd); + + // we must set a pixel format before we can create a context, just use the first one... + SetPixelFormat(hdc, 1, NULL); + HGLRC hglrc = wglCreateContext(hdc); + wglMakeCurrent(hdc, hglrc); + + // call the test function + proc(hdc, args); + + // clean up + wglMakeCurrent(NULL, NULL); + wglDeleteContext(hglrc); + ReleaseDC(hwnd, hdc); + DestroyWindow(hwnd); + } +} + +static void +windows_check_render_test(HDC hdc, void *args) +{ + int *result = (int *)args; + + /* Rather than play linkage games using stdcall to ensure we get + glGetString from opengl32.dll here, use dlsym */ + void *dlhandle = windows_get_dl_handle(); + const char *(*proc)(int) = dlsym(dlhandle, "glGetString"); + const char *gl_renderer = (const char *)proc(GL_RENDERER); + + if ((!gl_renderer) || (strcasecmp(gl_renderer, "GDI Generic") == 0)) + *result = FALSE; + else + *result = TRUE; +} + +int +windows_check_renderer(void) +{ + int result; + windows_call_with_context(windows_check_render_test, &result); + return result; +} + +typedef struct { + char *gl_extensions; + char *wgl_extensions; +} windows_extensions_result; + +static void +windows_extensions_test(HDC hdc, void *args) +{ + windows_extensions_result *r = (windows_extensions_result *)args; + + void *dlhandle = windows_get_dl_handle(); + const char *(*proc)(int) = dlsym(dlhandle, "glGetString"); + + r->gl_extensions = strdup(proc(GL_EXTENSIONS)); + + wglResolveExtensionProcs(); + r->wgl_extensions = strdup(wglGetExtensionsStringARB(hdc)); +} + +void +windows_extensions(char **gl_extensions, char **wgl_extensions) +{ + windows_extensions_result result; + + *gl_extensions = ""; + *wgl_extensions = ""; + + windows_call_with_context(windows_extensions_test, &result); + + *gl_extensions = result.gl_extensions; + *wgl_extensions = result.wgl_extensions; +} + +void windows_setTexBuffer(windowsContext *context, int textureTarget, + int textureFormat, windowsDrawable *drawable) +{ + // not yet implemented +} + +void windows_releaseTexBuffer(windowsContext *context, int textureTarget, + windowsDrawable *drawable) +{ + // not yet implemented +} diff --git a/src/glx/windows/windowsgl.h b/src/glx/windows/windowsgl.h new file mode 100644 index 00000000000..bb30f1a391f --- /dev/null +++ b/src/glx/windows/windowsgl.h @@ -0,0 +1,52 @@ +/* + * Copyright © 2014 Jon Turney + * + * 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 (including the next + * paragraph) 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 AUTHORS OR COPYRIGHT HOLDERS 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. + */ + +#ifndef windowsgl_h +#define windowsgh_h + +struct _windowsContext; +struct _windowsDrawable; + +typedef struct _windowsContext windowsContext; +typedef struct _windowsDrawable windowsDrawable; + +windowsContext *windows_create_context(int pxfi, windowsContext *shared); +windowsContext *windows_create_context_attribs(int pxfi, windowsContext *shared, const int *attribList); +void windows_destroy_context(windowsContext *contex); +int windows_bind_context(windowsContext *context, windowsDrawable *, windowsDrawable *); +void windows_unbind_context(windowsContext *context); + +windowsDrawable *windows_create_drawable(int type, void *handle); +void windows_destroy_drawable(windowsDrawable *); +void windows_swap_buffers(windowsDrawable *); +void windows_copy_subbuffer(windowsDrawable *windowsDrawable, int x, int y, int width, int height); + +int windows_check_renderer(void); +void windows_extensions(char **gl_extensions, char **wgl_extensions); + +void windows_setTexBuffer(windowsContext *context, int textureTarget, + int textureFormat, windowsDrawable *drawable); +void windows_releaseTexBuffer(windowsContext *context, int textureTarget, + windowsDrawable *drawable); + +#endif /* windowsgl_h */ diff --git a/src/glx/windows/windowsgl_internal.h b/src/glx/windows/windowsgl_internal.h new file mode 100644 index 00000000000..89ed53efe9b --- /dev/null +++ b/src/glx/windows/windowsgl_internal.h @@ -0,0 +1,67 @@ +/* + * Copyright © 2014 Jon Turney + * + * 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 (including the next + * paragraph) 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 AUTHORS OR COPYRIGHT HOLDERS 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. + */ + +#ifndef windowsgl_internal_h +#define windowsgl_internal_h + +#include "windowsgl.h" + +#include <X11/Xmd.h> // for BOOL +#include <X11/Xwindows.h> // as this doesn't provide one +#include <GL/gl.h> +#include <GL/wglext.h> + +struct _windowsContext +{ + struct glx_config *config; + windowsContext *shareContext; + HGLRC ctx; + int pxfi; +}; + +struct windowsdrawable_callbacks +{ + int type; // WINDOW, PIXMAP, PBUFFER + HDC (*getdc) (windowsDrawable *d); + void (*releasedc) (windowsDrawable *d, HDC dc); +}; + +struct _windowsDrawable +{ + int pxfi; // 0 if not yet set + struct windowsdrawable_callbacks *callbacks; + + // for type WINDOW + HWND hWnd; + + // for type PIXMAP + HANDLE hSection; + HDC dibDC; + HBITMAP hDIB; + HBITMAP hOldDIB; + + // for type PBUFFER + HPBUFFERARB hPbuffer; +}; + +#endif /* windowsgl_internal_h */ diff --git a/src/glx/windows/xwindowsdri.c b/src/glx/windows/xwindowsdri.c new file mode 100644 index 00000000000..90884fa6a17 --- /dev/null +++ b/src/glx/windows/xwindowsdri.c @@ -0,0 +1,237 @@ +/* + * Copyright © 2014 Jon Turney + * + * 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 (including the next + * paragraph) 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 AUTHORS OR COPYRIGHT HOLDERS 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. + */ + +/* THIS IS NOT AN X CONSORTIUM STANDARD */ + +#include <X11/Xlibint.h> +#include <X11/extensions/Xext.h> +#include <X11/extensions/extutil.h> +#include "windowsdristr.h" +#include "xwindowsdri.h" +#include <stdio.h> + +static XExtensionInfo _windowsdri_info_data; +static XExtensionInfo *windowsdri_info = &_windowsdri_info_data; +static char *windowsdri_extension_name = WINDOWSDRINAME; + +#define WindowsDRICheckExtension(dpy,i,val) \ + XextCheckExtension (dpy, i, windowsdri_extension_name, val) + +/***************************************************************************** + * * + * private utility routines * + * * + *****************************************************************************/ + +static int close_display(Display * dpy, XExtCodes * extCodes); + +static /* const */ XExtensionHooks windowsdri_extension_hooks = { + NULL, /* create_gc */ + NULL, /* copy_gc */ + NULL, /* flush_gc */ + NULL, /* free_gc */ + NULL, /* create_font */ + NULL, /* free_font */ + close_display, /* close_display */ + NULL, /* wire_to_event */ + NULL, /* event_to_wire */ + NULL, /* error */ + NULL, /* error_string */ +}; + +static +XEXT_GENERATE_FIND_DISPLAY(find_display, windowsdri_info, + windowsdri_extension_name, + &windowsdri_extension_hooks, + WindowsDRINumberEvents, NULL) + +static +XEXT_GENERATE_CLOSE_DISPLAY(close_display, windowsdri_info) + +/***************************************************************************** + * * + * public Windows-DRI Extension routines * + * * + *****************************************************************************/ + +#if 0 +#include <stdio.h> +#define TRACE(msg, ...) fprintf(stderr, "WindowsDRI" msg "\n", ##__VA_ARGS__); +#else +#define TRACE(msg, ...) +#endif + +Bool +XWindowsDRIQueryExtension(dpy, event_basep, error_basep) + Display *dpy; + int *event_basep, *error_basep; +{ + XExtDisplayInfo *info = find_display(dpy); + + TRACE("QueryExtension:"); + if (XextHasExtension(info)) { + *event_basep = info->codes->first_event; + *error_basep = info->codes->first_error; + TRACE("QueryExtension: return True"); + return True; + } + else { + TRACE("QueryExtension: return False"); + return False; + } +} + +Bool +XWindowsDRIQueryVersion(dpy, majorVersion, minorVersion, patchVersion) + Display *dpy; + int *majorVersion; + int *minorVersion; + int *patchVersion; +{ + XExtDisplayInfo *info = find_display(dpy); + xWindowsDRIQueryVersionReply rep; + xWindowsDRIQueryVersionReq *req; + + TRACE("QueryVersion:"); + WindowsDRICheckExtension(dpy, info, False); + + LockDisplay(dpy); + GetReq(WindowsDRIQueryVersion, req); + req->reqType = info->codes->major_opcode; + req->driReqType = X_WindowsDRIQueryVersion; + if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + TRACE("QueryVersion: return False"); + return False; + } + *majorVersion = rep.majorVersion; + *minorVersion = rep.minorVersion; + *patchVersion = rep.patchVersion; + UnlockDisplay(dpy); + SyncHandle(); + TRACE("QueryVersion: %d.%d.%d", *majorVersion, *minorVersion, *patchVersion); + return True; +} + +Bool +XWindowsDRIQueryDirectRenderingCapable(dpy, screen, isCapable) + Display *dpy; + int screen; + Bool *isCapable; +{ + XExtDisplayInfo *info = find_display(dpy); + xWindowsDRIQueryDirectRenderingCapableReply rep; + xWindowsDRIQueryDirectRenderingCapableReq *req; + + TRACE("QueryDirectRenderingCapable:"); + WindowsDRICheckExtension(dpy, info, False); + + LockDisplay(dpy); + GetReq(WindowsDRIQueryDirectRenderingCapable, req); + req->reqType = info->codes->major_opcode; + req->driReqType = X_WindowsDRIQueryDirectRenderingCapable; + req->screen = screen; + if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + TRACE("QueryDirectRenderingCapable: return False"); + return False; + } + *isCapable = rep.isCapable; + UnlockDisplay(dpy); + SyncHandle(); + TRACE("QueryDirectRenderingCapable:return True"); + return True; +} + +Bool +XWindowsDRIQueryDrawable(Display *dpy, int screen, Drawable drawable, + unsigned int * type, void ** handle) +{ + XExtDisplayInfo *info = find_display(dpy); + xWindowsDRIQueryDrawableReply rep; + xWindowsDRIQueryDrawableReq *req; + + TRACE("QueryDrawable: XID %lx", drawable); + WindowsDRICheckExtension(dpy, info, False); + + LockDisplay(dpy); + GetReq(WindowsDRIQueryDrawable, req); + req->reqType = info->codes->major_opcode; + req->driReqType = X_WindowsDRIQueryDrawable; + req->screen = screen; + req->drawable = drawable; + + if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + TRACE("QueryDrawable: return False"); + return False; + } + + *type = rep.drawable_type; + + // Note that despite being a derived type of void *, HANDLEs are defined to + // be a sign-extended 32 bit value (so they can be passed to 32-bit + // processes safely) + *handle = (void *)(intptr_t)rep.handle; + + UnlockDisplay(dpy); + SyncHandle(); + TRACE("QueryDrawable: type %d, handle %p", *type, *handle); + return True; +} + +Bool +XWindowsDRIFBConfigToPixelFormat(Display *dpy, int screen, int fbConfigID, + int *pxfi) +{ + XExtDisplayInfo *info = find_display(dpy); + xWindowsDRIFBConfigToPixelFormatReply rep; + xWindowsDRIFBConfigToPixelFormatReq *req; + + TRACE("FBConfigToPixelFormat: fbConfigID 0x%x", fbConfigID); + WindowsDRICheckExtension(dpy, info, False); + + LockDisplay(dpy); + GetReq(WindowsDRIFBConfigToPixelFormat, req); + req->reqType = info->codes->major_opcode; + req->driReqType = X_WindowsDRIFBConfigToPixelFormat; + req->screen = screen; + req->fbConfigID = fbConfigID; + + if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + TRACE("FBConfigToPixelFormat: return False"); + return False; + } + + *pxfi = rep.pixelFormatIndex; + + UnlockDisplay(dpy); + SyncHandle(); + TRACE("FBConfigToPixelFormat: pixelformatindex %d", *pxfi); + return True; +} diff --git a/src/glx/windows/xwindowsdri.h b/src/glx/windows/xwindowsdri.h new file mode 100644 index 00000000000..499af26de7a --- /dev/null +++ b/src/glx/windows/xwindowsdri.h @@ -0,0 +1,59 @@ +/* + * Copyright © 2014 Jon Turney + * + * 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 (including the next + * paragraph) 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 AUTHORS OR COPYRIGHT HOLDERS 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. + */ + +#ifndef XWINDOWSDRI_H +#define XWINDOWSDRI_H + +#include <X11/Xfuncproto.h> +#include <X11/Xlib.h> + +typedef struct +{ + int type; /* of event */ + unsigned long serial; /* # of last request processed by server */ + Bool send_event; /* true if this came frome a SendEvent request */ + Display *display; /* Display the event was read from */ + Window window; /* window of event */ + Time time; /* server timestamp when event happened */ + int kind; /* subtype of event */ + int arg; +} XWindowsDRINotifyEvent; + +_XFUNCPROTOBEGIN +Bool XWindowsDRIQueryExtension(Display * dpy, int *event_base, + int *error_base); + +Bool XWindowsDRIQueryVersion(Display * dpy, int *majorVersion, + int *minorVersion, int *patchVersion); + +Bool XWindowsDRIQueryDirectRenderingCapable(Display * dpy, int screen, + Bool *isCapable); + +Bool XWindowsDRIQueryDrawable(Display * dpy, int screen, Drawable drawable, + unsigned int *type, void ** handle); + +Bool XWindowsDRIFBConfigToPixelFormat(Display *dpy, int screen, int fbConfigID, + int *pxfi); +_XFUNCPROTOEND + +#endif /* XWINDOWSDRI_H */ |