gl: updated glxext.h to version 27
[mesa.git] / src / gallium / winsys / drm / radeon / python / radeon_hardpipe_winsys.c
1 /**************************************************************************
2 *
3 * Copyright 2009 VMware, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28
29 #include <stdio.h>
30 #include <string.h>
31 #include <stdlib.h>
32
33 #include <X11/X.h>
34 #include <X11/Xlib.h>
35 #include <drm/drm.h>
36
37 #include "pipe/p_screen.h"
38 #include "pipe/p_context.h"
39
40 #include "st_winsys.h"
41
42 #include "radeon_winsys.h"
43
44 #include "xf86dri.h"
45
46
47 /* XXX: Force init_gallium symbol to be linked */
48 extern void init_gallium(void);
49 void (*force_init_gallium_linkage)(void) = &init_gallium;
50
51
52 static struct pipe_screen *
53 radeon_hardpipe_screen_create(void)
54 {
55 Display *dpy;
56 Window rootWin;
57 XWindowAttributes winAttr;
58 int isCapable;
59 int screen;
60 char *driverName;
61 char *curBusID;
62 unsigned magic;
63 int ddxDriverMajor;
64 int ddxDriverMinor;
65 int ddxDriverPatch;
66 drm_handle_t sAreaOffset;
67 int ret;
68 int drmFD;
69 drm_context_t hHWContext;
70 XID id;
71
72 dpy = XOpenDisplay(":0");
73 if (!dpy) {
74 fprintf(stderr, "Open Display Failed\n");
75 return NULL;
76 }
77
78 screen = DefaultScreen(dpy);
79 rootWin = RootWindow(dpy, screen);
80 XGetWindowAttributes(dpy, rootWin, &winAttr);
81
82 ret = uniDRIQueryDirectRenderingCapable(dpy, screen, &isCapable);
83 if (!ret || !isCapable) {
84 fprintf(stderr, "No DRI on this display:sceen\n");
85 goto error;
86 }
87
88 if (!uniDRIOpenConnection(dpy, screen, &sAreaOffset,
89 &curBusID)) {
90 fprintf(stderr, "Could not open DRI connection.\n");
91 goto error;
92 }
93
94 if (!uniDRIGetClientDriverName(dpy, screen, &ddxDriverMajor,
95 &ddxDriverMinor, &ddxDriverPatch,
96 &driverName)) {
97 fprintf(stderr, "Could not get DRI driver name.\n");
98 goto error;
99 }
100
101 if ((drmFD = drmOpen(NULL, curBusID)) < 0) {
102 perror("DRM Device could not be opened");
103 goto error;
104 }
105
106 drmGetMagic(drmFD, &magic);
107 if (!uniDRIAuthConnection(dpy, screen, magic)) {
108 fprintf(stderr, "Could not get X server to authenticate us.\n");
109 goto error;
110 }
111
112 if (!uniDRICreateContext(dpy, screen, winAttr.visual,
113 &id, &hHWContext)) {
114 fprintf(stderr, "Could not create DRI context.\n");
115 goto error;
116 }
117
118 /* FIXME: create a radeon pipe_screen from drmFD and hHWContext */
119
120 return NULL;
121
122 error:
123 return NULL;
124 }
125
126
127
128
129 const struct st_winsys st_hardpipe_winsys = {
130 &radeon_hardpipe_screen_create,
131 };
132