101e04c3fSmrg/* 201e04c3fSmrg * Copyright © 2014 Jon Turney 301e04c3fSmrg * 401e04c3fSmrg * Permission is hereby granted, free of charge, to any person obtaining a 501e04c3fSmrg * copy of this software and associated documentation files (the "Software"), 601e04c3fSmrg * to deal in the Software without restriction, including without limitation 701e04c3fSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 801e04c3fSmrg * and/or sell copies of the Software, and to permit persons to whom the 901e04c3fSmrg * Software is furnished to do so, subject to the following conditions: 1001e04c3fSmrg * 1101e04c3fSmrg * The above copyright notice and this permission notice (including the next 1201e04c3fSmrg * paragraph) shall be included in all copies or substantial portions of the 1301e04c3fSmrg * Software. 1401e04c3fSmrg * 1501e04c3fSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1601e04c3fSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1701e04c3fSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 1801e04c3fSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 1901e04c3fSmrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 2001e04c3fSmrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 2101e04c3fSmrg * IN THE SOFTWARE. 2201e04c3fSmrg */ 2301e04c3fSmrg 2401e04c3fSmrg/* THIS IS NOT AN X CONSORTIUM STANDARD */ 2501e04c3fSmrg 2601e04c3fSmrg#include <X11/Xlibint.h> 2701e04c3fSmrg#include <X11/extensions/Xext.h> 2801e04c3fSmrg#include <X11/extensions/extutil.h> 2901e04c3fSmrg#include "windowsdristr.h" 3001e04c3fSmrg#include "xwindowsdri.h" 3101e04c3fSmrg#include <stdio.h> 3201e04c3fSmrg 3301e04c3fSmrgstatic XExtensionInfo _windowsdri_info_data; 3401e04c3fSmrgstatic XExtensionInfo *windowsdri_info = &_windowsdri_info_data; 3501e04c3fSmrgstatic char *windowsdri_extension_name = WINDOWSDRINAME; 3601e04c3fSmrg 3701e04c3fSmrg#define WindowsDRICheckExtension(dpy,i,val) \ 3801e04c3fSmrg XextCheckExtension (dpy, i, windowsdri_extension_name, val) 3901e04c3fSmrg 4001e04c3fSmrg/***************************************************************************** 4101e04c3fSmrg * * 4201e04c3fSmrg * private utility routines * 4301e04c3fSmrg * * 4401e04c3fSmrg *****************************************************************************/ 4501e04c3fSmrg 4601e04c3fSmrgstatic int close_display(Display * dpy, XExtCodes * extCodes); 4701e04c3fSmrg 4801e04c3fSmrgstatic /* const */ XExtensionHooks windowsdri_extension_hooks = { 4901e04c3fSmrg NULL, /* create_gc */ 5001e04c3fSmrg NULL, /* copy_gc */ 5101e04c3fSmrg NULL, /* flush_gc */ 5201e04c3fSmrg NULL, /* free_gc */ 5301e04c3fSmrg NULL, /* create_font */ 5401e04c3fSmrg NULL, /* free_font */ 5501e04c3fSmrg close_display, /* close_display */ 5601e04c3fSmrg NULL, /* wire_to_event */ 5701e04c3fSmrg NULL, /* event_to_wire */ 5801e04c3fSmrg NULL, /* error */ 5901e04c3fSmrg NULL, /* error_string */ 6001e04c3fSmrg}; 6101e04c3fSmrg 6201e04c3fSmrgstatic 6301e04c3fSmrgXEXT_GENERATE_FIND_DISPLAY(find_display, windowsdri_info, 6401e04c3fSmrg windowsdri_extension_name, 6501e04c3fSmrg &windowsdri_extension_hooks, 6601e04c3fSmrg WindowsDRINumberEvents, NULL) 6701e04c3fSmrg 6801e04c3fSmrgstatic 6901e04c3fSmrgXEXT_GENERATE_CLOSE_DISPLAY(close_display, windowsdri_info) 7001e04c3fSmrg 7101e04c3fSmrg/***************************************************************************** 7201e04c3fSmrg * * 7301e04c3fSmrg * public Windows-DRI Extension routines * 7401e04c3fSmrg * * 7501e04c3fSmrg *****************************************************************************/ 7601e04c3fSmrg 7701e04c3fSmrg#if 0 7801e04c3fSmrg#include <stdio.h> 7901e04c3fSmrg#define TRACE(msg, ...) fprintf(stderr, "WindowsDRI" msg "\n", ##__VA_ARGS__); 8001e04c3fSmrg#else 8101e04c3fSmrg#define TRACE(msg, ...) 8201e04c3fSmrg#endif 8301e04c3fSmrg 8401e04c3fSmrgBool 8501e04c3fSmrgXWindowsDRIQueryExtension(dpy, event_basep, error_basep) 8601e04c3fSmrg Display *dpy; 8701e04c3fSmrg int *event_basep, *error_basep; 8801e04c3fSmrg{ 8901e04c3fSmrg XExtDisplayInfo *info = find_display(dpy); 9001e04c3fSmrg 9101e04c3fSmrg TRACE("QueryExtension:"); 9201e04c3fSmrg if (XextHasExtension(info)) { 9301e04c3fSmrg *event_basep = info->codes->first_event; 9401e04c3fSmrg *error_basep = info->codes->first_error; 9501e04c3fSmrg TRACE("QueryExtension: return True"); 9601e04c3fSmrg return True; 9701e04c3fSmrg } 9801e04c3fSmrg else { 9901e04c3fSmrg TRACE("QueryExtension: return False"); 10001e04c3fSmrg return False; 10101e04c3fSmrg } 10201e04c3fSmrg} 10301e04c3fSmrg 10401e04c3fSmrgBool 10501e04c3fSmrgXWindowsDRIQueryVersion(dpy, majorVersion, minorVersion, patchVersion) 10601e04c3fSmrg Display *dpy; 10701e04c3fSmrg int *majorVersion; 10801e04c3fSmrg int *minorVersion; 10901e04c3fSmrg int *patchVersion; 11001e04c3fSmrg{ 11101e04c3fSmrg XExtDisplayInfo *info = find_display(dpy); 11201e04c3fSmrg xWindowsDRIQueryVersionReply rep; 11301e04c3fSmrg xWindowsDRIQueryVersionReq *req; 11401e04c3fSmrg 11501e04c3fSmrg TRACE("QueryVersion:"); 11601e04c3fSmrg WindowsDRICheckExtension(dpy, info, False); 11701e04c3fSmrg 11801e04c3fSmrg LockDisplay(dpy); 11901e04c3fSmrg GetReq(WindowsDRIQueryVersion, req); 12001e04c3fSmrg req->reqType = info->codes->major_opcode; 12101e04c3fSmrg req->driReqType = X_WindowsDRIQueryVersion; 12201e04c3fSmrg if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) { 12301e04c3fSmrg UnlockDisplay(dpy); 12401e04c3fSmrg SyncHandle(); 12501e04c3fSmrg TRACE("QueryVersion: return False"); 12601e04c3fSmrg return False; 12701e04c3fSmrg } 12801e04c3fSmrg *majorVersion = rep.majorVersion; 12901e04c3fSmrg *minorVersion = rep.minorVersion; 13001e04c3fSmrg *patchVersion = rep.patchVersion; 13101e04c3fSmrg UnlockDisplay(dpy); 13201e04c3fSmrg SyncHandle(); 13301e04c3fSmrg TRACE("QueryVersion: %d.%d.%d", *majorVersion, *minorVersion, *patchVersion); 13401e04c3fSmrg return True; 13501e04c3fSmrg} 13601e04c3fSmrg 13701e04c3fSmrgBool 13801e04c3fSmrgXWindowsDRIQueryDirectRenderingCapable(dpy, screen, isCapable) 13901e04c3fSmrg Display *dpy; 14001e04c3fSmrg int screen; 14101e04c3fSmrg Bool *isCapable; 14201e04c3fSmrg{ 14301e04c3fSmrg XExtDisplayInfo *info = find_display(dpy); 14401e04c3fSmrg xWindowsDRIQueryDirectRenderingCapableReply rep; 14501e04c3fSmrg xWindowsDRIQueryDirectRenderingCapableReq *req; 14601e04c3fSmrg 14701e04c3fSmrg TRACE("QueryDirectRenderingCapable:"); 14801e04c3fSmrg WindowsDRICheckExtension(dpy, info, False); 14901e04c3fSmrg 15001e04c3fSmrg LockDisplay(dpy); 15101e04c3fSmrg GetReq(WindowsDRIQueryDirectRenderingCapable, req); 15201e04c3fSmrg req->reqType = info->codes->major_opcode; 15301e04c3fSmrg req->driReqType = X_WindowsDRIQueryDirectRenderingCapable; 15401e04c3fSmrg req->screen = screen; 15501e04c3fSmrg if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) { 15601e04c3fSmrg UnlockDisplay(dpy); 15701e04c3fSmrg SyncHandle(); 15801e04c3fSmrg TRACE("QueryDirectRenderingCapable: return False"); 15901e04c3fSmrg return False; 16001e04c3fSmrg } 16101e04c3fSmrg *isCapable = rep.isCapable; 16201e04c3fSmrg UnlockDisplay(dpy); 16301e04c3fSmrg SyncHandle(); 16401e04c3fSmrg TRACE("QueryDirectRenderingCapable:return True"); 16501e04c3fSmrg return True; 16601e04c3fSmrg} 16701e04c3fSmrg 16801e04c3fSmrgBool 16901e04c3fSmrgXWindowsDRIQueryDrawable(Display *dpy, int screen, Drawable drawable, 17001e04c3fSmrg unsigned int * type, void ** handle) 17101e04c3fSmrg{ 17201e04c3fSmrg XExtDisplayInfo *info = find_display(dpy); 17301e04c3fSmrg xWindowsDRIQueryDrawableReply rep; 17401e04c3fSmrg xWindowsDRIQueryDrawableReq *req; 17501e04c3fSmrg 17601e04c3fSmrg TRACE("QueryDrawable: XID %lx", drawable); 17701e04c3fSmrg WindowsDRICheckExtension(dpy, info, False); 17801e04c3fSmrg 17901e04c3fSmrg LockDisplay(dpy); 18001e04c3fSmrg GetReq(WindowsDRIQueryDrawable, req); 18101e04c3fSmrg req->reqType = info->codes->major_opcode; 18201e04c3fSmrg req->driReqType = X_WindowsDRIQueryDrawable; 18301e04c3fSmrg req->screen = screen; 18401e04c3fSmrg req->drawable = drawable; 18501e04c3fSmrg 18601e04c3fSmrg if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) { 18701e04c3fSmrg UnlockDisplay(dpy); 18801e04c3fSmrg SyncHandle(); 18901e04c3fSmrg TRACE("QueryDrawable: return False"); 19001e04c3fSmrg return False; 19101e04c3fSmrg } 19201e04c3fSmrg 19301e04c3fSmrg *type = rep.drawable_type; 19401e04c3fSmrg 19501e04c3fSmrg // Note that despite being a derived type of void *, HANDLEs are defined to 19601e04c3fSmrg // be a sign-extended 32 bit value (so they can be passed to 32-bit 19701e04c3fSmrg // processes safely) 19801e04c3fSmrg *handle = (void *)(intptr_t)rep.handle; 19901e04c3fSmrg 20001e04c3fSmrg UnlockDisplay(dpy); 20101e04c3fSmrg SyncHandle(); 20201e04c3fSmrg TRACE("QueryDrawable: type %d, handle %p", *type, *handle); 20301e04c3fSmrg return True; 20401e04c3fSmrg} 20501e04c3fSmrg 20601e04c3fSmrgBool 20701e04c3fSmrgXWindowsDRIFBConfigToPixelFormat(Display *dpy, int screen, int fbConfigID, 20801e04c3fSmrg int *pxfi) 20901e04c3fSmrg{ 21001e04c3fSmrg XExtDisplayInfo *info = find_display(dpy); 21101e04c3fSmrg xWindowsDRIFBConfigToPixelFormatReply rep; 21201e04c3fSmrg xWindowsDRIFBConfigToPixelFormatReq *req; 21301e04c3fSmrg 21401e04c3fSmrg TRACE("FBConfigToPixelFormat: fbConfigID 0x%x", fbConfigID); 21501e04c3fSmrg WindowsDRICheckExtension(dpy, info, False); 21601e04c3fSmrg 21701e04c3fSmrg LockDisplay(dpy); 21801e04c3fSmrg GetReq(WindowsDRIFBConfigToPixelFormat, req); 21901e04c3fSmrg req->reqType = info->codes->major_opcode; 22001e04c3fSmrg req->driReqType = X_WindowsDRIFBConfigToPixelFormat; 22101e04c3fSmrg req->screen = screen; 22201e04c3fSmrg req->fbConfigID = fbConfigID; 22301e04c3fSmrg 22401e04c3fSmrg if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) { 22501e04c3fSmrg UnlockDisplay(dpy); 22601e04c3fSmrg SyncHandle(); 22701e04c3fSmrg TRACE("FBConfigToPixelFormat: return False"); 22801e04c3fSmrg return False; 22901e04c3fSmrg } 23001e04c3fSmrg 23101e04c3fSmrg *pxfi = rep.pixelFormatIndex; 23201e04c3fSmrg 23301e04c3fSmrg UnlockDisplay(dpy); 23401e04c3fSmrg SyncHandle(); 23501e04c3fSmrg TRACE("FBConfigToPixelFormat: pixelformatindex %d", *pxfi); 23601e04c3fSmrg return True; 23701e04c3fSmrg} 238