2 * Copyright © 2014 Jon Turney
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 /* THIS IS NOT AN X CONSORTIUM STANDARD */
26 #include <X11/Xlibint.h>
27 #include <X11/extensions/Xext.h>
28 #include <X11/extensions/extutil.h>
29 #include "windowsdristr.h"
30 #include "xwindowsdri.h"
33 static XExtensionInfo _windowsdri_info_data
;
34 static XExtensionInfo
*windowsdri_info
= &_windowsdri_info_data
;
35 static char *windowsdri_extension_name
= WINDOWSDRINAME
;
37 #define WindowsDRICheckExtension(dpy,i,val) \
38 XextCheckExtension (dpy, i, windowsdri_extension_name, val)
40 /*****************************************************************************
42 * private utility routines *
44 *****************************************************************************/
46 static int close_display(Display
* dpy
, XExtCodes
* extCodes
);
48 static /* const */ XExtensionHooks windowsdri_extension_hooks
= {
53 NULL
, /* create_font */
55 close_display
, /* close_display */
56 NULL
, /* wire_to_event */
57 NULL
, /* event_to_wire */
59 NULL
, /* error_string */
63 XEXT_GENERATE_FIND_DISPLAY(find_display
, windowsdri_info
,
64 windowsdri_extension_name
,
65 &windowsdri_extension_hooks
,
66 WindowsDRINumberEvents
, NULL
)
69 XEXT_GENERATE_CLOSE_DISPLAY(close_display
, windowsdri_info
)
71 /*****************************************************************************
73 * public Windows-DRI Extension routines *
75 *****************************************************************************/
79 #define TRACE(msg, ...) fprintf(stderr, "WindowsDRI" msg "\n", ##__VA_ARGS__);
81 #define TRACE(msg, ...)
85 XWindowsDRIQueryExtension(dpy
, event_basep
, error_basep
)
87 int *event_basep
, *error_basep
;
89 XExtDisplayInfo
*info
= find_display(dpy
);
91 TRACE("QueryExtension:");
92 if (XextHasExtension(info
)) {
93 *event_basep
= info
->codes
->first_event
;
94 *error_basep
= info
->codes
->first_error
;
95 TRACE("QueryExtension: return True");
99 TRACE("QueryExtension: return False");
105 XWindowsDRIQueryVersion(dpy
, majorVersion
, minorVersion
, patchVersion
)
111 XExtDisplayInfo
*info
= find_display(dpy
);
112 xWindowsDRIQueryVersionReply rep
;
113 xWindowsDRIQueryVersionReq
*req
;
115 TRACE("QueryVersion:");
116 WindowsDRICheckExtension(dpy
, info
, False
);
119 GetReq(WindowsDRIQueryVersion
, req
);
120 req
->reqType
= info
->codes
->major_opcode
;
121 req
->driReqType
= X_WindowsDRIQueryVersion
;
122 if (!_XReply(dpy
, (xReply
*) & rep
, 0, xFalse
)) {
125 TRACE("QueryVersion: return False");
128 *majorVersion
= rep
.majorVersion
;
129 *minorVersion
= rep
.minorVersion
;
130 *patchVersion
= rep
.patchVersion
;
133 TRACE("QueryVersion: %d.%d.%d", *majorVersion
, *minorVersion
, *patchVersion
);
138 XWindowsDRIQueryDirectRenderingCapable(dpy
, screen
, isCapable
)
143 XExtDisplayInfo
*info
= find_display(dpy
);
144 xWindowsDRIQueryDirectRenderingCapableReply rep
;
145 xWindowsDRIQueryDirectRenderingCapableReq
*req
;
147 TRACE("QueryDirectRenderingCapable:");
148 WindowsDRICheckExtension(dpy
, info
, False
);
151 GetReq(WindowsDRIQueryDirectRenderingCapable
, req
);
152 req
->reqType
= info
->codes
->major_opcode
;
153 req
->driReqType
= X_WindowsDRIQueryDirectRenderingCapable
;
154 req
->screen
= screen
;
155 if (!_XReply(dpy
, (xReply
*) & rep
, 0, xFalse
)) {
158 TRACE("QueryDirectRenderingCapable: return False");
161 *isCapable
= rep
.isCapable
;
164 TRACE("QueryDirectRenderingCapable:return True");
169 XWindowsDRIQueryDrawable(Display
*dpy
, int screen
, Drawable drawable
,
170 unsigned int * type
, void ** handle
)
172 XExtDisplayInfo
*info
= find_display(dpy
);
173 xWindowsDRIQueryDrawableReply rep
;
174 xWindowsDRIQueryDrawableReq
*req
;
176 TRACE("QueryDrawable: XID %lx", drawable
);
177 WindowsDRICheckExtension(dpy
, info
, False
);
180 GetReq(WindowsDRIQueryDrawable
, req
);
181 req
->reqType
= info
->codes
->major_opcode
;
182 req
->driReqType
= X_WindowsDRIQueryDrawable
;
183 req
->screen
= screen
;
184 req
->drawable
= drawable
;
186 if (!_XReply(dpy
, (xReply
*) & rep
, 0, xFalse
)) {
189 TRACE("QueryDrawable: return False");
193 *type
= rep
.drawable_type
;
195 // Note that despite being a derived type of void *, HANDLEs are defined to
196 // be a sign-extended 32 bit value (so they can be passed to 32-bit
198 *handle
= (void *)(intptr_t)rep
.handle
;
202 TRACE("QueryDrawable: type %d, handle %p", *type
, *handle
);
207 XWindowsDRIFBConfigToPixelFormat(Display
*dpy
, int screen
, int fbConfigID
,
210 XExtDisplayInfo
*info
= find_display(dpy
);
211 xWindowsDRIFBConfigToPixelFormatReply rep
;
212 xWindowsDRIFBConfigToPixelFormatReq
*req
;
214 TRACE("FBConfigToPixelFormat: fbConfigID 0x%x", fbConfigID
);
215 WindowsDRICheckExtension(dpy
, info
, False
);
218 GetReq(WindowsDRIFBConfigToPixelFormat
, req
);
219 req
->reqType
= info
->codes
->major_opcode
;
220 req
->driReqType
= X_WindowsDRIFBConfigToPixelFormat
;
221 req
->screen
= screen
;
222 req
->fbConfigID
= fbConfigID
;
224 if (!_XReply(dpy
, (xReply
*) & rep
, 0, xFalse
)) {
227 TRACE("FBConfigToPixelFormat: return False");
231 *pxfi
= rep
.pixelFormatIndex
;
235 TRACE("FBConfigToPixelFormat: pixelformatindex %d", *pxfi
);