glxvndabi.h revision 25da500f
11b5d61b8Smrg/*
21b5d61b8Smrg * Copyright (c) 2016, NVIDIA CORPORATION.
31b5d61b8Smrg *
41b5d61b8Smrg * Permission is hereby granted, free of charge, to any person obtaining a
51b5d61b8Smrg * copy of this software and/or associated documentation files (the
61b5d61b8Smrg * "Materials"), to deal in the Materials without restriction, including
71b5d61b8Smrg * without limitation the rights to use, copy, modify, merge, publish,
81b5d61b8Smrg * distribute, sublicense, and/or sell copies of the Materials, and to
91b5d61b8Smrg * permit persons to whom the Materials are furnished to do so, subject to
101b5d61b8Smrg * the following conditions:
111b5d61b8Smrg *
121b5d61b8Smrg * The above copyright notice and this permission notice shall be included
131b5d61b8Smrg * unaltered in all copies or substantial portions of the Materials.
141b5d61b8Smrg * Any additions, deletions, or changes to the original source files
151b5d61b8Smrg * must be clearly indicated in accompanying documentation.
161b5d61b8Smrg *
171b5d61b8Smrg * If only executable code is distributed, then the accompanying
181b5d61b8Smrg * documentation must state that "this software is based in part on the
191b5d61b8Smrg * work of the Khronos Group."
201b5d61b8Smrg *
211b5d61b8Smrg * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
221b5d61b8Smrg * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
231b5d61b8Smrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
241b5d61b8Smrg * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
251b5d61b8Smrg * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
261b5d61b8Smrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
271b5d61b8Smrg * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
281b5d61b8Smrg */
291b5d61b8Smrg
301b5d61b8Smrg/**
311b5d61b8Smrg * \file
321b5d61b8Smrg *
331b5d61b8Smrg * Defines the interface between the libglvnd server module and a vendor
341b5d61b8Smrg * library.
351b5d61b8Smrg *
361b5d61b8Smrg * Each screen may have one vendor library assigned to it. The GLVND module
371b5d61b8Smrg * will examine each GLX request to determine which screen it goes to, and then
381b5d61b8Smrg * it will forward that request to whichever vendor is assigned to that screen.
391b5d61b8Smrg *
401b5d61b8Smrg * Each vendor library is represented by an opaque __GLXServerVendor handle.
411b5d61b8Smrg * Display drivers are responsible for creating handles for its GLX
421b5d61b8Smrg * implementations, and assigning those handles to each screen.
431b5d61b8Smrg *
441b5d61b8Smrg * The GLVND module keeps a list of callbacks, which are called from
451b5d61b8Smrg * InitExtensions. Drivers should use that callback to assign a vendor
461b5d61b8Smrg * handle to whichever screens they support.
471b5d61b8Smrg *
481b5d61b8Smrg * Additional notes about dispatching:
491b5d61b8Smrg * - If a request has one or more GLXContextTag values, then the dispatch stub
501b5d61b8Smrg *   must ensure that all of the tags belong to the vendor that it forwards the
511b5d61b8Smrg *   request to. Otherwise, if a vendor library tries to look up the private
521b5d61b8Smrg *   data for the tag, it could get the data from another vendor and crash.
531b5d61b8Smrg * - Following from the last point, if a request takes a GLXContextTag value,
541b5d61b8Smrg *   then the dispatch stub should use the tag to select a vendor. If the
551b5d61b8Smrg *   request takes two or more tags, then the vendor must ensure that they all
561b5d61b8Smrg *   map to the same vendor.
571b5d61b8Smrg */
581b5d61b8Smrg
591b5d61b8Smrg#ifndef GLXVENDORABI_H
601b5d61b8Smrg#define GLXVENDORABI_H
611b5d61b8Smrg
621b5d61b8Smrg#include <scrnintstr.h>
631b5d61b8Smrg#include <extnsionst.h>
641b5d61b8Smrg#include <GL/glxproto.h>
651b5d61b8Smrg
661b5d61b8Smrg/*!
671b5d61b8Smrg * Current version of the ABI.
681b5d61b8Smrg *
691b5d61b8Smrg * This version number contains a major number in the high-order 16 bits, and
701b5d61b8Smrg * a minor version number in the low-order 16 bits.
711b5d61b8Smrg *
721b5d61b8Smrg * The major version number is incremented when an interface change will break
731b5d61b8Smrg * backwards compatibility with existing vendor libraries. The minor version
741b5d61b8Smrg * number is incremented when there's a change but existing vendor libraries
751b5d61b8Smrg * will still work.
761b5d61b8Smrg */
771b5d61b8Smrg#define GLXSERVER_VENDOR_ABI_MAJOR_VERSION 0
7825da500fSmrg#define GLXSERVER_VENDOR_ABI_MINOR_VERSION 1
791b5d61b8Smrg
801b5d61b8Smrg#if defined(__cplusplus)
811b5d61b8Smrgextern "C" {
821b5d61b8Smrg#endif
831b5d61b8Smrg
841b5d61b8Smrg/**
851b5d61b8Smrg * An opaque pointer representing a vendor library.
861b5d61b8Smrg */
871b5d61b8Smrgtypedef struct GlxServerVendorRec GlxServerVendor;
881b5d61b8Smrg
891b5d61b8Smrgtypedef int (* GlxServerDispatchProc) (ClientPtr client);
901b5d61b8Smrg
911b5d61b8Smrgtypedef struct GlxServerImportsRec GlxServerImports;
921b5d61b8Smrg
931b5d61b8Smrg/**
941b5d61b8Smrg * Functions exported by libglvnd to the vendor library.
951b5d61b8Smrg */
961b5d61b8Smrgtypedef struct GlxServerExportsRec {
971b5d61b8Smrg    int majorVersion;
981b5d61b8Smrg    int minorVersion;
991b5d61b8Smrg
1001b5d61b8Smrg    /**
1011b5d61b8Smrg     * This callback is called during each server generation when the GLX
1021b5d61b8Smrg     * extension is initialized.
1031b5d61b8Smrg     *
1041b5d61b8Smrg     * Drivers may create a __GLXServerVendor handle at any time, but may only
1051b5d61b8Smrg     * assign a vendor to a screen from this callback.
1061b5d61b8Smrg     *
1071b5d61b8Smrg     * The callback is called with the ExtensionEntry pointer for the GLX
1081b5d61b8Smrg     * extension.
1091b5d61b8Smrg     */
1101b5d61b8Smrg    CallbackListPtr *extensionInitCallback;
1111b5d61b8Smrg
1121b5d61b8Smrg    /**
1131b5d61b8Smrg     * Allocates and zeroes a __GLXserverImports structure.
1141b5d61b8Smrg     *
1151b5d61b8Smrg     * Future versions of the GLVND interface may add optional members to the
1161b5d61b8Smrg     * end of the __GLXserverImports struct. Letting the GLVND layer allocate
1171b5d61b8Smrg     * the __GLXserverImports struct allows backward compatibility with
1181b5d61b8Smrg     * existing drivers.
1191b5d61b8Smrg     */
1201b5d61b8Smrg    GlxServerImports * (* allocateServerImports) (void);
1211b5d61b8Smrg
1221b5d61b8Smrg    /**
1231b5d61b8Smrg     * Frees a __GLXserverImports structure that was allocated with
1241b5d61b8Smrg     * \c allocateServerImports.
1251b5d61b8Smrg     */
1261b5d61b8Smrg    void (* freeServerImports) (GlxServerImports *imports);
1271b5d61b8Smrg
1281b5d61b8Smrg    /**
1291b5d61b8Smrg     * Creates a new vendor library handle.
1301b5d61b8Smrg     */
1311b5d61b8Smrg    GlxServerVendor * (* createVendor) (const GlxServerImports *imports);
1321b5d61b8Smrg
1331b5d61b8Smrg    /**
1341b5d61b8Smrg     * Destroys a vendor library handle.
1351b5d61b8Smrg     *
1361b5d61b8Smrg     * This function may not be called while the vendor handle is assigned to a
1371b5d61b8Smrg     * screen, but it may be called from the __GLXserverImports::extensionCloseDown
1381b5d61b8Smrg     * callback.
1391b5d61b8Smrg     */
1401b5d61b8Smrg    void (* destroyVendor) (GlxServerVendor *vendor);
1411b5d61b8Smrg
1421b5d61b8Smrg    /**
1431b5d61b8Smrg     * Sets the vendor library to use for a screen.
1441b5d61b8Smrg     *
1451b5d61b8Smrg     * This function should be called from the screen's CreateScreenResources
1461b5d61b8Smrg     * callback.
1471b5d61b8Smrg     */
1481b5d61b8Smrg    Bool (* setScreenVendor) (ScreenPtr screen, GlxServerVendor *vendor);
1491b5d61b8Smrg
1501b5d61b8Smrg
1511b5d61b8Smrg    /**
1521b5d61b8Smrg     * Adds an entry to the XID map.
1531b5d61b8Smrg     *
1541b5d61b8Smrg     * This mapping is used to dispatch requests based on an XID.
1551b5d61b8Smrg     *
1561b5d61b8Smrg     * Client-generated XID's (contexts, drawables, etc) must be added to the
1571b5d61b8Smrg     * map by the dispatch stub.
1581b5d61b8Smrg     *
1591b5d61b8Smrg     * XID's that are generated in the server should be added by the vendor
1601b5d61b8Smrg     * library.
1611b5d61b8Smrg     *
1621b5d61b8Smrg     * Vendor libraries are responsible for keeping track of any additional
1631b5d61b8Smrg     * data they need for the XID's.
1641b5d61b8Smrg     *
1651b5d61b8Smrg     * Note that adding GLXFBConfig ID's appears to be unnecessary -- every GLX
1661b5d61b8Smrg     * request I can find that takes a GLXFBConfig also takes a screen number.
1671b5d61b8Smrg     *
1681b5d61b8Smrg     * \param id The XID to add to the map. The XID must not already be in the
1691b5d61b8Smrg     *      map.
1701b5d61b8Smrg     * \param vendor The vendor library to associate with \p id.
1711b5d61b8Smrg     * \return True on success, or False on failure.
1721b5d61b8Smrg     */
1731b5d61b8Smrg    Bool (* addXIDMap) (XID id, GlxServerVendor *vendor);
1741b5d61b8Smrg
1751b5d61b8Smrg    /**
1761b5d61b8Smrg     * Returns the vendor and data for an XID, as added with \c addXIDMap.
1771b5d61b8Smrg     *
1781b5d61b8Smrg     * If \p id wasn't added with \c addXIDMap (for example, if it's a regular
1791b5d61b8Smrg     * X window), then libglvnd will try to look it up as a drawable and return
1801b5d61b8Smrg     * the vendor for whatever screen it's on.
1811b5d61b8Smrg     *
1821b5d61b8Smrg     * \param id The XID to look up.
1831b5d61b8Smrg     * \return The vendor that owns the XID, or \c NULL if no matching vendor
1841b5d61b8Smrg     * was found.
1851b5d61b8Smrg     */
1861b5d61b8Smrg    GlxServerVendor * (* getXIDMap) (XID id);
1871b5d61b8Smrg
1881b5d61b8Smrg    /**
1891b5d61b8Smrg     * Removes an entry from the XID map.
1901b5d61b8Smrg     */
1911b5d61b8Smrg    void (* removeXIDMap) (XID id);
1921b5d61b8Smrg
1931b5d61b8Smrg    /**
1941b5d61b8Smrg     * Looks up a context tag.
1951b5d61b8Smrg     *
1961b5d61b8Smrg     * Context tags are created and managed by libglvnd to ensure that they're
1971b5d61b8Smrg     * unique between vendors.
1981b5d61b8Smrg     *
1991b5d61b8Smrg     * \param client The client connection.
2001b5d61b8Smrg     * \param tag The context tag.
2011b5d61b8Smrg     * \return The vendor that owns the context tag, or \c NULL if the context
2021b5d61b8Smrg     * tag is invalid.
2031b5d61b8Smrg     */
2041b5d61b8Smrg    GlxServerVendor * (* getContextTag)(ClientPtr client, GLXContextTag tag);
2051b5d61b8Smrg
2061b5d61b8Smrg    /**
2071b5d61b8Smrg     * Assigns a pointer to vendor-private data for a context tag.
2081b5d61b8Smrg     *
2091b5d61b8Smrg     * Since the tag values are assigned by GLVND, vendors can use this
2101b5d61b8Smrg     * function to store any private data they need for a context tag.
2111b5d61b8Smrg     *
2121b5d61b8Smrg     * \param client The client connection.
2131b5d61b8Smrg     * \param tag The context tag.
2141b5d61b8Smrg     * \param data An arbitrary pointer value.
2151b5d61b8Smrg     */
2161b5d61b8Smrg    Bool (* setContextTagPrivate)(ClientPtr client, GLXContextTag tag, void *data);
2171b5d61b8Smrg
2181b5d61b8Smrg    /**
2191b5d61b8Smrg     * Returns the private data pointer that was assigned from
2201b5d61b8Smrg     * setContextTagPrivate.
2211b5d61b8Smrg     *
2221b5d61b8Smrg     * This function is safe to use in __GLXserverImports::makeCurrent to look
2231b5d61b8Smrg     * up the old context private pointer.
2241b5d61b8Smrg     *
2251b5d61b8Smrg     * However, this function is not safe to use from a ClientStateCallback,
2261b5d61b8Smrg     * because GLVND may have alraedy deleted the tag by that point.
2271b5d61b8Smrg     */
2281b5d61b8Smrg    void * (* getContextTagPrivate)(ClientPtr client, GLXContextTag tag);
2291b5d61b8Smrg
2301b5d61b8Smrg    GlxServerVendor * (* getVendorForScreen) (ClientPtr client, ScreenPtr screen);
2311b5d61b8Smrg
2321b5d61b8Smrg    /**
2331b5d61b8Smrg     * Forwards a request to a vendor library.
2341b5d61b8Smrg     *
2351b5d61b8Smrg     * \param vendor The vendor to send the request to.
2361b5d61b8Smrg     * \param client The client.
2371b5d61b8Smrg     */
2381b5d61b8Smrg    int (* forwardRequest) (GlxServerVendor *vendor, ClientPtr client);
23925da500fSmrg
24025da500fSmrg    /**
24125da500fSmrg     * Sets the vendor library to use for a screen for a specific client.
24225da500fSmrg     *
24325da500fSmrg     * This function changes which vendor should handle GLX requests for a
24425da500fSmrg     * screen. Unlike \c setScreenVendor, this function can be called at any
24525da500fSmrg     * time, and only applies to requests from a single client.
24625da500fSmrg     *
24725da500fSmrg     * This function is available in GLXVND version 0.1 or later.
24825da500fSmrg     */
24925da500fSmrg    Bool (* setClientScreenVendor) (ClientPtr client, ScreenPtr screen, GlxServerVendor *vendor);
2501b5d61b8Smrg} GlxServerExports;
2511b5d61b8Smrg
2521b5d61b8Smrgextern _X_EXPORT const GlxServerExports glxServer;
2531b5d61b8Smrg
2541b5d61b8Smrg/**
2551b5d61b8Smrg * Functions exported by the vendor library to libglvnd.
2561b5d61b8Smrg */
2571b5d61b8Smrgstruct GlxServerImportsRec {
2581b5d61b8Smrg    /**
2591b5d61b8Smrg     * Called on a server reset.
2601b5d61b8Smrg     *
2611b5d61b8Smrg     * This is called from the extension's CloseDown callback.
2621b5d61b8Smrg     *
2631b5d61b8Smrg     * Note that this is called after freeing all of GLVND's per-screen data,
2641b5d61b8Smrg     * so the callback may destroy any vendor handles.
2651b5d61b8Smrg     *
2661b5d61b8Smrg     * If the server is exiting, then GLVND will free any remaining vendor
2671b5d61b8Smrg     * handles after calling the extensionCloseDown callbacks.
2681b5d61b8Smrg     */
2691b5d61b8Smrg    void (* extensionCloseDown) (const ExtensionEntry *extEntry);
2701b5d61b8Smrg
2711b5d61b8Smrg    /**
2721b5d61b8Smrg     * Handles a GLX request.
2731b5d61b8Smrg     */
2741b5d61b8Smrg    int (* handleRequest) (ClientPtr client);
2751b5d61b8Smrg
2761b5d61b8Smrg    /**
2771b5d61b8Smrg     * Returns a dispatch function for a request.
2781b5d61b8Smrg     *
2791b5d61b8Smrg     * \param minorOpcode The minor opcode of the request.
2801b5d61b8Smrg     * \param vendorCode The vendor opcode, if \p minorOpcode
2811b5d61b8Smrg     *      is \c X_GLXVendorPrivate or \c X_GLXVendorPrivateWithReply.
2821b5d61b8Smrg     * \return A dispatch function, or NULL if the vendor doesn't support this
2831b5d61b8Smrg     *      request.
2841b5d61b8Smrg     */
2851b5d61b8Smrg    GlxServerDispatchProc (* getDispatchAddress) (CARD8 minorOpcode, CARD32 vendorCode);
2861b5d61b8Smrg
2871b5d61b8Smrg    /**
2881b5d61b8Smrg     * Handles a MakeCurrent request.
2891b5d61b8Smrg     *
2901b5d61b8Smrg     * This function is called to handle any MakeCurrent request. The vendor
2911b5d61b8Smrg     * library should deal with changing the current context. After the vendor
2921b5d61b8Smrg     * returns GLVND will send the reply.
2931b5d61b8Smrg     *
2941b5d61b8Smrg     * In addition, GLVND will call this function with any current contexts
2951b5d61b8Smrg     * when a client disconnects.
2961b5d61b8Smrg     *
2971b5d61b8Smrg     * To ensure that context tags are unique, libglvnd will select a context
2981b5d61b8Smrg     * tag and pass it to the vendor library.
2991b5d61b8Smrg     *
3001b5d61b8Smrg     * The vendor can use \c __GLXserverExports::getContextTagPrivate to look
3011b5d61b8Smrg     * up the private data pointer for \p oldContextTag.
3021b5d61b8Smrg     *
3031b5d61b8Smrg     * Likewise, the vendor can use \c __GLXserverExports::setContextTagPrivate
3041b5d61b8Smrg     * to assign a private data pointer to \p newContextTag.
3051b5d61b8Smrg     */
3061b5d61b8Smrg    int (* makeCurrent) (ClientPtr client,
3071b5d61b8Smrg        GLXContextTag oldContextTag,
3081b5d61b8Smrg        XID drawable,
3091b5d61b8Smrg        XID readdrawable,
3101b5d61b8Smrg        XID context,
3111b5d61b8Smrg        GLXContextTag newContextTag);
3121b5d61b8Smrg};
3131b5d61b8Smrg
3141b5d61b8Smrg#if defined(__cplusplus)
3151b5d61b8Smrg}
3161b5d61b8Smrg#endif
3171b5d61b8Smrg
3181b5d61b8Smrg#endif // GLXVENDORABI_H
319