1*4882a593Smuzhiyun /* 2*4882a593Smuzhiyun * Copyright (c) 2016, NVIDIA CORPORATION. 3*4882a593Smuzhiyun * 4*4882a593Smuzhiyun * Permission is hereby granted, free of charge, to any person obtaining a 5*4882a593Smuzhiyun * copy of this software and/or associated documentation files (the 6*4882a593Smuzhiyun * "Materials"), to deal in the Materials without restriction, including 7*4882a593Smuzhiyun * without limitation the rights to use, copy, modify, merge, publish, 8*4882a593Smuzhiyun * distribute, sublicense, and/or sell copies of the Materials, and to 9*4882a593Smuzhiyun * permit persons to whom the Materials are furnished to do so, subject to 10*4882a593Smuzhiyun * the following conditions: 11*4882a593Smuzhiyun * 12*4882a593Smuzhiyun * The above copyright notice and this permission notice shall be included 13*4882a593Smuzhiyun * unaltered in all copies or substantial portions of the Materials. 14*4882a593Smuzhiyun * Any additions, deletions, or changes to the original source files 15*4882a593Smuzhiyun * must be clearly indicated in accompanying documentation. 16*4882a593Smuzhiyun * 17*4882a593Smuzhiyun * If only executable code is distributed, then the accompanying 18*4882a593Smuzhiyun * documentation must state that "this software is based in part on the 19*4882a593Smuzhiyun * work of the Khronos Group." 20*4882a593Smuzhiyun * 21*4882a593Smuzhiyun * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 22*4882a593Smuzhiyun * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23*4882a593Smuzhiyun * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 24*4882a593Smuzhiyun * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 25*4882a593Smuzhiyun * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 26*4882a593Smuzhiyun * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 27*4882a593Smuzhiyun * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 28*4882a593Smuzhiyun */ 29*4882a593Smuzhiyun 30*4882a593Smuzhiyun /** 31*4882a593Smuzhiyun * \file 32*4882a593Smuzhiyun * 33*4882a593Smuzhiyun * Defines the interface between the libglvnd server module and a vendor 34*4882a593Smuzhiyun * library. 35*4882a593Smuzhiyun * 36*4882a593Smuzhiyun * Each screen may have one vendor library assigned to it. The GLVND module 37*4882a593Smuzhiyun * will examine each GLX request to determine which screen it goes to, and then 38*4882a593Smuzhiyun * it will forward that request to whichever vendor is assigned to that screen. 39*4882a593Smuzhiyun * 40*4882a593Smuzhiyun * Each vendor library is represented by an opaque __GLXServerVendor handle. 41*4882a593Smuzhiyun * Display drivers are responsible for creating handles for its GLX 42*4882a593Smuzhiyun * implementations, and assigning those handles to each screen. 43*4882a593Smuzhiyun * 44*4882a593Smuzhiyun * The GLVND module keeps a list of callbacks, which are called from 45*4882a593Smuzhiyun * InitExtensions. Drivers should use that callback to assign a vendor 46*4882a593Smuzhiyun * handle to whichever screens they support. 47*4882a593Smuzhiyun * 48*4882a593Smuzhiyun * Additional notes about dispatching: 49*4882a593Smuzhiyun * - If a request has one or more GLXContextTag values, then the dispatch stub 50*4882a593Smuzhiyun * must ensure that all of the tags belong to the vendor that it forwards the 51*4882a593Smuzhiyun * request to. Otherwise, if a vendor library tries to look up the private 52*4882a593Smuzhiyun * data for the tag, it could get the data from another vendor and crash. 53*4882a593Smuzhiyun * - Following from the last point, if a request takes a GLXContextTag value, 54*4882a593Smuzhiyun * then the dispatch stub should use the tag to select a vendor. If the 55*4882a593Smuzhiyun * request takes two or more tags, then the vendor must ensure that they all 56*4882a593Smuzhiyun * map to the same vendor. 57*4882a593Smuzhiyun */ 58*4882a593Smuzhiyun 59*4882a593Smuzhiyun #ifndef GLXVENDORABI_H 60*4882a593Smuzhiyun #define GLXVENDORABI_H 61*4882a593Smuzhiyun 62*4882a593Smuzhiyun #include <scrnintstr.h> 63*4882a593Smuzhiyun #include <extnsionst.h> 64*4882a593Smuzhiyun #include <GL/glxproto.h> 65*4882a593Smuzhiyun 66*4882a593Smuzhiyun /*! 67*4882a593Smuzhiyun * Current version of the ABI. 68*4882a593Smuzhiyun * 69*4882a593Smuzhiyun * This version number contains a major number in the high-order 16 bits, and 70*4882a593Smuzhiyun * a minor version number in the low-order 16 bits. 71*4882a593Smuzhiyun * 72*4882a593Smuzhiyun * The major version number is incremented when an interface change will break 73*4882a593Smuzhiyun * backwards compatibility with existing vendor libraries. The minor version 74*4882a593Smuzhiyun * number is incremented when there's a change but existing vendor libraries 75*4882a593Smuzhiyun * will still work. 76*4882a593Smuzhiyun */ 77*4882a593Smuzhiyun #define GLXSERVER_VENDOR_ABI_MAJOR_VERSION 0 78*4882a593Smuzhiyun #define GLXSERVER_VENDOR_ABI_MINOR_VERSION 1 79*4882a593Smuzhiyun 80*4882a593Smuzhiyun #if defined(__cplusplus) 81*4882a593Smuzhiyun extern "C" { 82*4882a593Smuzhiyun #endif 83*4882a593Smuzhiyun 84*4882a593Smuzhiyun /** 85*4882a593Smuzhiyun * An opaque pointer representing a vendor library. 86*4882a593Smuzhiyun */ 87*4882a593Smuzhiyun typedef struct GlxServerVendorRec GlxServerVendor; 88*4882a593Smuzhiyun 89*4882a593Smuzhiyun typedef int (* GlxServerDispatchProc) (ClientPtr client); 90*4882a593Smuzhiyun 91*4882a593Smuzhiyun typedef struct GlxServerImportsRec GlxServerImports; 92*4882a593Smuzhiyun 93*4882a593Smuzhiyun /** 94*4882a593Smuzhiyun * Functions exported by libglvnd to the vendor library. 95*4882a593Smuzhiyun */ 96*4882a593Smuzhiyun typedef struct GlxServerExportsRec { 97*4882a593Smuzhiyun int majorVersion; 98*4882a593Smuzhiyun int minorVersion; 99*4882a593Smuzhiyun 100*4882a593Smuzhiyun /** 101*4882a593Smuzhiyun * This callback is called during each server generation when the GLX 102*4882a593Smuzhiyun * extension is initialized. 103*4882a593Smuzhiyun * 104*4882a593Smuzhiyun * Drivers may create a __GLXServerVendor handle at any time, but may only 105*4882a593Smuzhiyun * assign a vendor to a screen from this callback. 106*4882a593Smuzhiyun * 107*4882a593Smuzhiyun * The callback is called with the ExtensionEntry pointer for the GLX 108*4882a593Smuzhiyun * extension. 109*4882a593Smuzhiyun */ 110*4882a593Smuzhiyun CallbackListPtr *extensionInitCallback; 111*4882a593Smuzhiyun 112*4882a593Smuzhiyun /** 113*4882a593Smuzhiyun * Allocates and zeroes a __GLXserverImports structure. 114*4882a593Smuzhiyun * 115*4882a593Smuzhiyun * Future versions of the GLVND interface may add optional members to the 116*4882a593Smuzhiyun * end of the __GLXserverImports struct. Letting the GLVND layer allocate 117*4882a593Smuzhiyun * the __GLXserverImports struct allows backward compatibility with 118*4882a593Smuzhiyun * existing drivers. 119*4882a593Smuzhiyun */ 120*4882a593Smuzhiyun GlxServerImports * (* allocateServerImports) (void); 121*4882a593Smuzhiyun 122*4882a593Smuzhiyun /** 123*4882a593Smuzhiyun * Frees a __GLXserverImports structure that was allocated with 124*4882a593Smuzhiyun * \c allocateServerImports. 125*4882a593Smuzhiyun */ 126*4882a593Smuzhiyun void (* freeServerImports) (GlxServerImports *imports); 127*4882a593Smuzhiyun 128*4882a593Smuzhiyun /** 129*4882a593Smuzhiyun * Creates a new vendor library handle. 130*4882a593Smuzhiyun */ 131*4882a593Smuzhiyun GlxServerVendor * (* createVendor) (const GlxServerImports *imports); 132*4882a593Smuzhiyun 133*4882a593Smuzhiyun /** 134*4882a593Smuzhiyun * Destroys a vendor library handle. 135*4882a593Smuzhiyun * 136*4882a593Smuzhiyun * This function may not be called while the vendor handle is assigned to a 137*4882a593Smuzhiyun * screen, but it may be called from the __GLXserverImports::extensionCloseDown 138*4882a593Smuzhiyun * callback. 139*4882a593Smuzhiyun */ 140*4882a593Smuzhiyun void (* destroyVendor) (GlxServerVendor *vendor); 141*4882a593Smuzhiyun 142*4882a593Smuzhiyun /** 143*4882a593Smuzhiyun * Sets the vendor library to use for a screen. 144*4882a593Smuzhiyun * 145*4882a593Smuzhiyun * This function should be called from the screen's CreateScreenResources 146*4882a593Smuzhiyun * callback. 147*4882a593Smuzhiyun */ 148*4882a593Smuzhiyun Bool (* setScreenVendor) (ScreenPtr screen, GlxServerVendor *vendor); 149*4882a593Smuzhiyun 150*4882a593Smuzhiyun 151*4882a593Smuzhiyun /** 152*4882a593Smuzhiyun * Adds an entry to the XID map. 153*4882a593Smuzhiyun * 154*4882a593Smuzhiyun * This mapping is used to dispatch requests based on an XID. 155*4882a593Smuzhiyun * 156*4882a593Smuzhiyun * Client-generated XID's (contexts, drawables, etc) must be added to the 157*4882a593Smuzhiyun * map by the dispatch stub. 158*4882a593Smuzhiyun * 159*4882a593Smuzhiyun * XID's that are generated in the server should be added by the vendor 160*4882a593Smuzhiyun * library. 161*4882a593Smuzhiyun * 162*4882a593Smuzhiyun * Vendor libraries are responsible for keeping track of any additional 163*4882a593Smuzhiyun * data they need for the XID's. 164*4882a593Smuzhiyun * 165*4882a593Smuzhiyun * Note that adding GLXFBConfig ID's appears to be unnecessary -- every GLX 166*4882a593Smuzhiyun * request I can find that takes a GLXFBConfig also takes a screen number. 167*4882a593Smuzhiyun * 168*4882a593Smuzhiyun * \param id The XID to add to the map. The XID must not already be in the 169*4882a593Smuzhiyun * map. 170*4882a593Smuzhiyun * \param vendor The vendor library to associate with \p id. 171*4882a593Smuzhiyun * \return True on success, or False on failure. 172*4882a593Smuzhiyun */ 173*4882a593Smuzhiyun Bool (* addXIDMap) (XID id, GlxServerVendor *vendor); 174*4882a593Smuzhiyun 175*4882a593Smuzhiyun /** 176*4882a593Smuzhiyun * Returns the vendor and data for an XID, as added with \c addXIDMap. 177*4882a593Smuzhiyun * 178*4882a593Smuzhiyun * If \p id wasn't added with \c addXIDMap (for example, if it's a regular 179*4882a593Smuzhiyun * X window), then libglvnd will try to look it up as a drawable and return 180*4882a593Smuzhiyun * the vendor for whatever screen it's on. 181*4882a593Smuzhiyun * 182*4882a593Smuzhiyun * \param id The XID to look up. 183*4882a593Smuzhiyun * \return The vendor that owns the XID, or \c NULL if no matching vendor 184*4882a593Smuzhiyun * was found. 185*4882a593Smuzhiyun */ 186*4882a593Smuzhiyun GlxServerVendor * (* getXIDMap) (XID id); 187*4882a593Smuzhiyun 188*4882a593Smuzhiyun /** 189*4882a593Smuzhiyun * Removes an entry from the XID map. 190*4882a593Smuzhiyun */ 191*4882a593Smuzhiyun void (* removeXIDMap) (XID id); 192*4882a593Smuzhiyun 193*4882a593Smuzhiyun /** 194*4882a593Smuzhiyun * Looks up a context tag. 195*4882a593Smuzhiyun * 196*4882a593Smuzhiyun * Context tags are created and managed by libglvnd to ensure that they're 197*4882a593Smuzhiyun * unique between vendors. 198*4882a593Smuzhiyun * 199*4882a593Smuzhiyun * \param client The client connection. 200*4882a593Smuzhiyun * \param tag The context tag. 201*4882a593Smuzhiyun * \return The vendor that owns the context tag, or \c NULL if the context 202*4882a593Smuzhiyun * tag is invalid. 203*4882a593Smuzhiyun */ 204*4882a593Smuzhiyun GlxServerVendor * (* getContextTag)(ClientPtr client, GLXContextTag tag); 205*4882a593Smuzhiyun 206*4882a593Smuzhiyun /** 207*4882a593Smuzhiyun * Assigns a pointer to vendor-private data for a context tag. 208*4882a593Smuzhiyun * 209*4882a593Smuzhiyun * Since the tag values are assigned by GLVND, vendors can use this 210*4882a593Smuzhiyun * function to store any private data they need for a context tag. 211*4882a593Smuzhiyun * 212*4882a593Smuzhiyun * \param client The client connection. 213*4882a593Smuzhiyun * \param tag The context tag. 214*4882a593Smuzhiyun * \param data An arbitrary pointer value. 215*4882a593Smuzhiyun */ 216*4882a593Smuzhiyun Bool (* setContextTagPrivate)(ClientPtr client, GLXContextTag tag, void *data); 217*4882a593Smuzhiyun 218*4882a593Smuzhiyun /** 219*4882a593Smuzhiyun * Returns the private data pointer that was assigned from 220*4882a593Smuzhiyun * setContextTagPrivate. 221*4882a593Smuzhiyun * 222*4882a593Smuzhiyun * This function is safe to use in __GLXserverImports::makeCurrent to look 223*4882a593Smuzhiyun * up the old context private pointer. 224*4882a593Smuzhiyun * 225*4882a593Smuzhiyun * However, this function is not safe to use from a ClientStateCallback, 226*4882a593Smuzhiyun * because GLVND may have alraedy deleted the tag by that point. 227*4882a593Smuzhiyun */ 228*4882a593Smuzhiyun void * (* getContextTagPrivate)(ClientPtr client, GLXContextTag tag); 229*4882a593Smuzhiyun 230*4882a593Smuzhiyun GlxServerVendor * (* getVendorForScreen) (ClientPtr client, ScreenPtr screen); 231*4882a593Smuzhiyun 232*4882a593Smuzhiyun /** 233*4882a593Smuzhiyun * Forwards a request to a vendor library. 234*4882a593Smuzhiyun * 235*4882a593Smuzhiyun * \param vendor The vendor to send the request to. 236*4882a593Smuzhiyun * \param client The client. 237*4882a593Smuzhiyun */ 238*4882a593Smuzhiyun int (* forwardRequest) (GlxServerVendor *vendor, ClientPtr client); 239*4882a593Smuzhiyun 240*4882a593Smuzhiyun /** 241*4882a593Smuzhiyun * Sets the vendor library to use for a screen for a specific client. 242*4882a593Smuzhiyun * 243*4882a593Smuzhiyun * This function changes which vendor should handle GLX requests for a 244*4882a593Smuzhiyun * screen. Unlike \c setScreenVendor, this function can be called at any 245*4882a593Smuzhiyun * time, and only applies to requests from a single client. 246*4882a593Smuzhiyun * 247*4882a593Smuzhiyun * This function is available in GLXVND version 0.1 or later. 248*4882a593Smuzhiyun */ 249*4882a593Smuzhiyun Bool (* setClientScreenVendor) (ClientPtr client, ScreenPtr screen, GlxServerVendor *vendor); 250*4882a593Smuzhiyun } GlxServerExports; 251*4882a593Smuzhiyun 252*4882a593Smuzhiyun extern _X_EXPORT const GlxServerExports glxServer; 253*4882a593Smuzhiyun 254*4882a593Smuzhiyun /** 255*4882a593Smuzhiyun * Functions exported by the vendor library to libglvnd. 256*4882a593Smuzhiyun */ 257*4882a593Smuzhiyun struct GlxServerImportsRec { 258*4882a593Smuzhiyun /** 259*4882a593Smuzhiyun * Called on a server reset. 260*4882a593Smuzhiyun * 261*4882a593Smuzhiyun * This is called from the extension's CloseDown callback. 262*4882a593Smuzhiyun * 263*4882a593Smuzhiyun * Note that this is called after freeing all of GLVND's per-screen data, 264*4882a593Smuzhiyun * so the callback may destroy any vendor handles. 265*4882a593Smuzhiyun * 266*4882a593Smuzhiyun * If the server is exiting, then GLVND will free any remaining vendor 267*4882a593Smuzhiyun * handles after calling the extensionCloseDown callbacks. 268*4882a593Smuzhiyun */ 269*4882a593Smuzhiyun void (* extensionCloseDown) (const ExtensionEntry *extEntry); 270*4882a593Smuzhiyun 271*4882a593Smuzhiyun /** 272*4882a593Smuzhiyun * Handles a GLX request. 273*4882a593Smuzhiyun */ 274*4882a593Smuzhiyun int (* handleRequest) (ClientPtr client); 275*4882a593Smuzhiyun 276*4882a593Smuzhiyun /** 277*4882a593Smuzhiyun * Returns a dispatch function for a request. 278*4882a593Smuzhiyun * 279*4882a593Smuzhiyun * \param minorOpcode The minor opcode of the request. 280*4882a593Smuzhiyun * \param vendorCode The vendor opcode, if \p minorOpcode 281*4882a593Smuzhiyun * is \c X_GLXVendorPrivate or \c X_GLXVendorPrivateWithReply. 282*4882a593Smuzhiyun * \return A dispatch function, or NULL if the vendor doesn't support this 283*4882a593Smuzhiyun * request. 284*4882a593Smuzhiyun */ 285*4882a593Smuzhiyun GlxServerDispatchProc (* getDispatchAddress) (CARD8 minorOpcode, CARD32 vendorCode); 286*4882a593Smuzhiyun 287*4882a593Smuzhiyun /** 288*4882a593Smuzhiyun * Handles a MakeCurrent request. 289*4882a593Smuzhiyun * 290*4882a593Smuzhiyun * This function is called to handle any MakeCurrent request. The vendor 291*4882a593Smuzhiyun * library should deal with changing the current context. After the vendor 292*4882a593Smuzhiyun * returns GLVND will send the reply. 293*4882a593Smuzhiyun * 294*4882a593Smuzhiyun * In addition, GLVND will call this function with any current contexts 295*4882a593Smuzhiyun * when a client disconnects. 296*4882a593Smuzhiyun * 297*4882a593Smuzhiyun * To ensure that context tags are unique, libglvnd will select a context 298*4882a593Smuzhiyun * tag and pass it to the vendor library. 299*4882a593Smuzhiyun * 300*4882a593Smuzhiyun * The vendor can use \c __GLXserverExports::getContextTagPrivate to look 301*4882a593Smuzhiyun * up the private data pointer for \p oldContextTag. 302*4882a593Smuzhiyun * 303*4882a593Smuzhiyun * Likewise, the vendor can use \c __GLXserverExports::setContextTagPrivate 304*4882a593Smuzhiyun * to assign a private data pointer to \p newContextTag. 305*4882a593Smuzhiyun */ 306*4882a593Smuzhiyun int (* makeCurrent) (ClientPtr client, 307*4882a593Smuzhiyun GLXContextTag oldContextTag, 308*4882a593Smuzhiyun XID drawable, 309*4882a593Smuzhiyun XID readdrawable, 310*4882a593Smuzhiyun XID context, 311*4882a593Smuzhiyun GLXContextTag newContextTag); 312*4882a593Smuzhiyun }; 313*4882a593Smuzhiyun 314*4882a593Smuzhiyun #if defined(__cplusplus) 315*4882a593Smuzhiyun } 316*4882a593Smuzhiyun #endif 317*4882a593Smuzhiyun 318*4882a593Smuzhiyun #endif // GLXVENDORABI_H 319