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 #include "vndservervendor.h"
31*4882a593Smuzhiyun
32*4882a593Smuzhiyun struct xorg_list GlxVendorList = { &GlxVendorList, &GlxVendorList };
33*4882a593Smuzhiyun
GlxCreateVendor(const GlxServerImports * imports)34*4882a593Smuzhiyun GlxServerVendor *GlxCreateVendor(const GlxServerImports *imports)
35*4882a593Smuzhiyun {
36*4882a593Smuzhiyun GlxServerVendor *vendor = NULL;
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun if (imports == NULL) {
39*4882a593Smuzhiyun ErrorF("GLX: Vendor library did not provide an imports table\n");
40*4882a593Smuzhiyun return NULL;
41*4882a593Smuzhiyun }
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun if (imports->extensionCloseDown == NULL
44*4882a593Smuzhiyun || imports->handleRequest == NULL
45*4882a593Smuzhiyun || imports->getDispatchAddress == NULL
46*4882a593Smuzhiyun || imports->makeCurrent == NULL) {
47*4882a593Smuzhiyun ErrorF("GLX: Vendor library is missing required callback functions.\n");
48*4882a593Smuzhiyun return NULL;
49*4882a593Smuzhiyun }
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun vendor = (GlxServerVendor *) calloc(1, sizeof(GlxServerVendor));
52*4882a593Smuzhiyun if (vendor == NULL) {
53*4882a593Smuzhiyun ErrorF("GLX: Can't allocate vendor library.\n");
54*4882a593Smuzhiyun return NULL;
55*4882a593Smuzhiyun }
56*4882a593Smuzhiyun memcpy(&vendor->glxvc, imports, sizeof(GlxServerImports));
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun xorg_list_append(&vendor->entry, &GlxVendorList);
59*4882a593Smuzhiyun return vendor;
60*4882a593Smuzhiyun }
61*4882a593Smuzhiyun
GlxDestroyVendor(GlxServerVendor * vendor)62*4882a593Smuzhiyun void GlxDestroyVendor(GlxServerVendor *vendor)
63*4882a593Smuzhiyun {
64*4882a593Smuzhiyun if (vendor != NULL) {
65*4882a593Smuzhiyun xorg_list_del(&vendor->entry);
66*4882a593Smuzhiyun free(vendor);
67*4882a593Smuzhiyun }
68*4882a593Smuzhiyun }
69*4882a593Smuzhiyun
GlxVendorExtensionReset(const ExtensionEntry * extEntry)70*4882a593Smuzhiyun void GlxVendorExtensionReset(const ExtensionEntry *extEntry)
71*4882a593Smuzhiyun {
72*4882a593Smuzhiyun GlxServerVendor *vendor, *tempVendor;
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun // TODO: Do we allow the driver to destroy a vendor library handle from
75*4882a593Smuzhiyun // here?
76*4882a593Smuzhiyun xorg_list_for_each_entry_safe(vendor, tempVendor, &GlxVendorList, entry) {
77*4882a593Smuzhiyun if (vendor->glxvc.extensionCloseDown != NULL) {
78*4882a593Smuzhiyun vendor->glxvc.extensionCloseDown(extEntry);
79*4882a593Smuzhiyun }
80*4882a593Smuzhiyun }
81*4882a593Smuzhiyun
82*4882a593Smuzhiyun // If the server is exiting instead of starting a new generation, then
83*4882a593Smuzhiyun // free the remaining GlxServerVendor structs.
84*4882a593Smuzhiyun //
85*4882a593Smuzhiyun // XXX this used to be conditional on xf86ServerIsExiting, but it's
86*4882a593Smuzhiyun // cleaner to just always create the vendor struct on every generation,
87*4882a593Smuzhiyun // if nothing else so all ddxes get the same behavior.
88*4882a593Smuzhiyun xorg_list_for_each_entry_safe(vendor, tempVendor, &GlxVendorList, entry) {
89*4882a593Smuzhiyun GlxDestroyVendor(vendor);
90*4882a593Smuzhiyun }
91*4882a593Smuzhiyun }
92