Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1 | /************************************************************************** |
| 2 | |
| 3 | Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. |
| 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 PRECISION INSIGHT 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 | **************************************************************************/ |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 27 | |
| 28 | /* |
| 29 | * Authors: |
| 30 | * Kevin E. Martin <kevin@precisioninsight.com> |
| 31 | * Brian Paul <brian@precisioninsight.com> |
| 32 | * |
| 33 | */ |
| 34 | |
Jeremy Huddleston | 80b280d | 2010-04-02 01:35:19 -0700 | [diff] [blame^] | 35 | #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 36 | |
Alan Hourihane | 6497d50 | 2008-04-23 15:59:23 +0100 | [diff] [blame] | 37 | #include <X11/Xlib.h> |
Xiang, Haihao | 42c279a | 2008-03-14 15:27:15 +0800 | [diff] [blame] | 38 | #include <X11/extensions/Xfixes.h> |
| 39 | #include <X11/extensions/Xdamage.h> |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 40 | #include "glxclient.h" |
| 41 | #include "xf86dri.h" |
Adam Jackson | a3c3c1f | 2009-04-14 17:56:29 -0400 | [diff] [blame] | 42 | #include "dri2.h" |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 43 | #include "sarea.h" |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 44 | #include <dlfcn.h> |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 45 | #include <sys/types.h> |
Kristian Høgsberg | 890d44e | 2008-03-07 00:45:54 -0500 | [diff] [blame] | 46 | #include <sys/mman.h> |
| 47 | #include "xf86drm.h" |
George Sapountzis | 0793457 | 2008-06-09 17:47:09 +0300 | [diff] [blame] | 48 | #include "dri_common.h" |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 49 | |
Kristian Høgsberg | 425f9ed | 2008-03-08 19:02:10 -0500 | [diff] [blame] | 50 | typedef struct __GLXDRIdisplayPrivateRec __GLXDRIdisplayPrivate; |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 51 | typedef struct __GLXDRIcontextPrivateRec __GLXDRIcontextPrivate; |
| 52 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 53 | struct __GLXDRIdisplayPrivateRec |
| 54 | { |
| 55 | __GLXDRIdisplay base; |
Kristian Høgsberg | 425f9ed | 2008-03-08 19:02:10 -0500 | [diff] [blame] | 56 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 57 | /* |
Kristian Høgsberg | 425f9ed | 2008-03-08 19:02:10 -0500 | [diff] [blame] | 58 | ** XFree86-DRI version information |
| 59 | */ |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 60 | int driMajor; |
| 61 | int driMinor; |
| 62 | int driPatch; |
Kristian Høgsberg | 425f9ed | 2008-03-08 19:02:10 -0500 | [diff] [blame] | 63 | }; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 64 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 65 | struct __GLXDRIcontextPrivateRec |
| 66 | { |
| 67 | __GLXDRIcontext base; |
| 68 | __DRIcontext *driContext; |
| 69 | XID hwContextID; |
| 70 | __GLXscreenConfigs *psc; |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 71 | }; |
| 72 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 73 | /* |
| 74 | * Given a display pointer and screen number, determine the name of |
| 75 | * the DRI driver for the screen. (I.e. "r128", "tdfx", etc). |
| 76 | * Return True for success, False for failure. |
| 77 | */ |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 78 | static Bool |
| 79 | driGetDriverName(Display * dpy, int scrNum, char **driverName) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 80 | { |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 81 | int directCapable; |
| 82 | Bool b; |
| 83 | int event, error; |
| 84 | int driverMajor, driverMinor, driverPatch; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 85 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 86 | *driverName = NULL; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 87 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 88 | if (XF86DRIQueryExtension(dpy, &event, &error)) { /* DRI1 */ |
| 89 | if (!XF86DRIQueryDirectRenderingCapable(dpy, scrNum, &directCapable)) { |
| 90 | ErrorMessageF("XF86DRIQueryDirectRenderingCapable failed\n"); |
| 91 | return False; |
| 92 | } |
| 93 | if (!directCapable) { |
| 94 | ErrorMessageF("XF86DRIQueryDirectRenderingCapable returned false\n"); |
| 95 | return False; |
| 96 | } |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 97 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 98 | b = XF86DRIGetClientDriverName(dpy, scrNum, &driverMajor, &driverMinor, |
| 99 | &driverPatch, driverName); |
| 100 | if (!b) { |
| 101 | ErrorMessageF("Cannot determine driver name for screen %d\n", |
| 102 | scrNum); |
| 103 | return False; |
| 104 | } |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 105 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 106 | InfoMessageF("XF86DRIGetClientDriverName: %d.%d.%d %s (screen %d)\n", |
| 107 | driverMajor, driverMinor, driverPatch, *driverName, |
| 108 | scrNum); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 109 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 110 | return True; |
| 111 | } |
| 112 | else if (DRI2QueryExtension(dpy, &event, &error)) { /* DRI2 */ |
| 113 | char *dev; |
| 114 | Bool ret = DRI2Connect(dpy, RootWindow(dpy, scrNum), driverName, &dev); |
Adam Jackson | a3c3c1f | 2009-04-14 17:56:29 -0400 | [diff] [blame] | 115 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 116 | if (ret) |
| 117 | Xfree(dev); |
Adam Jackson | a3c3c1f | 2009-04-14 17:56:29 -0400 | [diff] [blame] | 118 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 119 | return ret; |
| 120 | } |
Adam Jackson | a3c3c1f | 2009-04-14 17:56:29 -0400 | [diff] [blame] | 121 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 122 | return False; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 125 | /* |
| 126 | * Exported function for querying the DRI driver for a given screen. |
| 127 | * |
| 128 | * The returned char pointer points to a static array that will be |
| 129 | * overwritten by subsequent calls. |
| 130 | */ |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 131 | PUBLIC const char * |
| 132 | glXGetScreenDriver(Display * dpy, int scrNum) |
| 133 | { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 134 | static char ret[32]; |
| 135 | char *driverName; |
George Sapountzis | 0793457 | 2008-06-09 17:47:09 +0300 | [diff] [blame] | 136 | if (driGetDriverName(dpy, scrNum, &driverName)) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 137 | int len; |
| 138 | if (!driverName) |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 139 | return NULL; |
| 140 | len = strlen(driverName); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 141 | if (len >= 31) |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 142 | return NULL; |
| 143 | memcpy(ret, driverName, len + 1); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 144 | Xfree(driverName); |
| 145 | return ret; |
| 146 | } |
| 147 | return NULL; |
| 148 | } |
| 149 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 150 | /* |
| 151 | * Exported function for obtaining a driver's option list (UTF-8 encoded XML). |
| 152 | * |
| 153 | * The returned char pointer points directly into the driver. Therefore |
| 154 | * it should be treated as a constant. |
| 155 | * |
| 156 | * If the driver was not found or does not support configuration NULL is |
| 157 | * returned. |
| 158 | * |
| 159 | * Note: The driver remains opened after this function returns. |
| 160 | */ |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 161 | PUBLIC const char * |
| 162 | glXGetDriverConfig(const char *driverName) |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 163 | { |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 164 | void *handle = driOpenDriver(driverName); |
Kristian Høgsberg | 0f2723c | 2008-03-07 01:37:08 -0500 | [diff] [blame] | 165 | if (handle) |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 166 | return dlsym(handle, "__driConfigOptions"); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 167 | else |
| 168 | return NULL; |
| 169 | } |
| 170 | |
Kristian Høgsberg | 890d44e | 2008-03-07 00:45:54 -0500 | [diff] [blame] | 171 | #ifdef XDAMAGE_1_1_INTERFACE |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 172 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 173 | static GLboolean |
| 174 | has_damage_post(Display * dpy) |
Kristian Høgsberg | 890d44e | 2008-03-07 00:45:54 -0500 | [diff] [blame] | 175 | { |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 176 | static GLboolean inited = GL_FALSE; |
| 177 | static GLboolean has_damage; |
Kristian Høgsberg | 890d44e | 2008-03-07 00:45:54 -0500 | [diff] [blame] | 178 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 179 | if (!inited) { |
| 180 | int major, minor; |
Kristian Høgsberg | 890d44e | 2008-03-07 00:45:54 -0500 | [diff] [blame] | 181 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 182 | if (XDamageQueryVersion(dpy, &major, &minor) && |
| 183 | major == 1 && minor >= 1) { |
| 184 | has_damage = GL_TRUE; |
| 185 | } |
| 186 | else { |
| 187 | has_damage = GL_FALSE; |
| 188 | } |
| 189 | inited = GL_TRUE; |
| 190 | } |
Kristian Høgsberg | 890d44e | 2008-03-07 00:45:54 -0500 | [diff] [blame] | 191 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 192 | return has_damage; |
Kristian Høgsberg | 890d44e | 2008-03-07 00:45:54 -0500 | [diff] [blame] | 193 | } |
Kristian Høgsberg | 890d44e | 2008-03-07 00:45:54 -0500 | [diff] [blame] | 194 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 195 | static void |
| 196 | __glXReportDamage(__DRIdrawable * driDraw, |
| 197 | int x, int y, |
| 198 | drm_clip_rect_t * rects, int num_rects, |
| 199 | GLboolean front_buffer, void *loaderPrivate) |
Kristian Høgsberg | 890d44e | 2008-03-07 00:45:54 -0500 | [diff] [blame] | 200 | { |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 201 | XRectangle *xrects; |
| 202 | XserverRegion region; |
| 203 | int i; |
| 204 | int x_off, y_off; |
| 205 | __GLXDRIdrawable *glxDraw = loaderPrivate; |
| 206 | __GLXscreenConfigs *psc = glxDraw->psc; |
| 207 | Display *dpy = psc->dpy; |
| 208 | Drawable drawable; |
Kristian Høgsberg | 890d44e | 2008-03-07 00:45:54 -0500 | [diff] [blame] | 209 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 210 | if (!has_damage_post(dpy)) |
| 211 | return; |
Kristian Høgsberg | 890d44e | 2008-03-07 00:45:54 -0500 | [diff] [blame] | 212 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 213 | if (front_buffer) { |
| 214 | x_off = x; |
| 215 | y_off = y; |
| 216 | drawable = RootWindow(dpy, psc->scr); |
| 217 | } |
| 218 | else { |
| 219 | x_off = 0; |
| 220 | y_off = 0; |
| 221 | drawable = glxDraw->xDrawable; |
| 222 | } |
Kristian Høgsberg | 890d44e | 2008-03-07 00:45:54 -0500 | [diff] [blame] | 223 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 224 | xrects = malloc(sizeof(XRectangle) * num_rects); |
| 225 | if (xrects == NULL) |
| 226 | return; |
Kristian Høgsberg | 890d44e | 2008-03-07 00:45:54 -0500 | [diff] [blame] | 227 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 228 | for (i = 0; i < num_rects; i++) { |
| 229 | xrects[i].x = rects[i].x1 + x_off; |
| 230 | xrects[i].y = rects[i].y1 + y_off; |
| 231 | xrects[i].width = rects[i].x2 - rects[i].x1; |
| 232 | xrects[i].height = rects[i].y2 - rects[i].y1; |
| 233 | } |
| 234 | region = XFixesCreateRegion(dpy, xrects, num_rects); |
| 235 | free(xrects); |
| 236 | XDamageAdd(dpy, drawable, region); |
| 237 | XFixesDestroyRegion(dpy, region); |
Kristian Høgsberg | 890d44e | 2008-03-07 00:45:54 -0500 | [diff] [blame] | 238 | } |
| 239 | |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 240 | static const __DRIdamageExtension damageExtension = { |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 241 | {__DRI_DAMAGE, __DRI_DAMAGE_VERSION}, |
| 242 | __glXReportDamage, |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 243 | }; |
| 244 | |
| 245 | #endif |
| 246 | |
Kristian Høgsberg | 890d44e | 2008-03-07 00:45:54 -0500 | [diff] [blame] | 247 | static GLboolean |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 248 | __glXDRIGetDrawableInfo(__DRIdrawable * drawable, |
| 249 | unsigned int *index, unsigned int *stamp, |
| 250 | int *X, int *Y, int *W, int *H, |
| 251 | int *numClipRects, drm_clip_rect_t ** pClipRects, |
| 252 | int *backX, int *backY, |
| 253 | int *numBackClipRects, |
| 254 | drm_clip_rect_t ** pBackClipRects, |
| 255 | void *loaderPrivate) |
Kristian Høgsberg | 890d44e | 2008-03-07 00:45:54 -0500 | [diff] [blame] | 256 | { |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 257 | __GLXDRIdrawable *glxDraw = loaderPrivate; |
| 258 | __GLXscreenConfigs *psc = glxDraw->psc; |
| 259 | Display *dpy = psc->dpy; |
Kristian Høgsberg | 890d44e | 2008-03-07 00:45:54 -0500 | [diff] [blame] | 260 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 261 | return XF86DRIGetDrawableInfo(dpy, psc->scr, glxDraw->drawable, |
| 262 | index, stamp, X, Y, W, H, |
| 263 | numClipRects, pClipRects, |
| 264 | backX, backY, |
| 265 | numBackClipRects, pBackClipRects); |
Kristian Høgsberg | 890d44e | 2008-03-07 00:45:54 -0500 | [diff] [blame] | 266 | } |
| 267 | |
Kristian Høgsberg | 890d44e | 2008-03-07 00:45:54 -0500 | [diff] [blame] | 268 | static const __DRIgetDrawableInfoExtension getDrawableInfoExtension = { |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 269 | {__DRI_GET_DRAWABLE_INFO, __DRI_GET_DRAWABLE_INFO_VERSION}, |
| 270 | __glXDRIGetDrawableInfo |
Kristian Høgsberg | 890d44e | 2008-03-07 00:45:54 -0500 | [diff] [blame] | 271 | }; |
| 272 | |
Kristian Høgsberg | 890d44e | 2008-03-07 00:45:54 -0500 | [diff] [blame] | 273 | static const __DRIextension *loader_extensions[] = { |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 274 | &systemTimeExtension.base, |
| 275 | &getDrawableInfoExtension.base, |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 276 | #ifdef XDAMAGE_1_1_INTERFACE |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 277 | &damageExtension.base, |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 278 | #endif |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 279 | NULL |
Kristian Høgsberg | 890d44e | 2008-03-07 00:45:54 -0500 | [diff] [blame] | 280 | }; |
| 281 | |
Kristian Høgsberg | 890d44e | 2008-03-07 00:45:54 -0500 | [diff] [blame] | 282 | /** |
| 283 | * Perform the required libGL-side initialization and call the client-side |
| 284 | * driver's \c __driCreateNewScreen function. |
| 285 | * |
| 286 | * \param dpy Display pointer. |
| 287 | * \param scrn Screen number on the display. |
| 288 | * \param psc DRI screen information. |
| 289 | * \param driDpy DRI display information. |
| 290 | * \param createNewScreen Pointer to the client-side driver's |
| 291 | * \c __driCreateNewScreen function. |
Kristian Høgsberg | d61f073 | 2010-01-01 17:09:12 -0500 | [diff] [blame] | 292 | * \returns A pointer to the \c __DRIscreen structure returned by |
Kristian Høgsberg | 890d44e | 2008-03-07 00:45:54 -0500 | [diff] [blame] | 293 | * the client-side driver on success, or \c NULL on failure. |
Kristian Høgsberg | 890d44e | 2008-03-07 00:45:54 -0500 | [diff] [blame] | 294 | */ |
| 295 | static void * |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 296 | CallCreateNewScreen(Display * dpy, int scrn, __GLXscreenConfigs * psc, |
| 297 | __GLXDRIdisplayPrivate * driDpy) |
Kristian Høgsberg | 890d44e | 2008-03-07 00:45:54 -0500 | [diff] [blame] | 298 | { |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 299 | void *psp = NULL; |
| 300 | drm_handle_t hSAREA; |
| 301 | drmAddress pSAREA = MAP_FAILED; |
| 302 | char *BusID; |
| 303 | __DRIversion ddx_version; |
| 304 | __DRIversion dri_version; |
| 305 | __DRIversion drm_version; |
| 306 | __DRIframebuffer framebuffer; |
| 307 | int fd = -1; |
| 308 | int status; |
George Sapountzis | 906e189 | 2008-06-09 17:47:49 +0300 | [diff] [blame] | 309 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 310 | drm_magic_t magic; |
| 311 | drmVersionPtr version; |
| 312 | int newlyopened; |
| 313 | char *driverName; |
| 314 | drm_handle_t hFB; |
| 315 | int junk; |
| 316 | const __DRIconfig **driver_configs; |
| 317 | __GLcontextModes *visual; |
Kristian Høgsberg | 890d44e | 2008-03-07 00:45:54 -0500 | [diff] [blame] | 318 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 319 | /* DRI protocol version. */ |
| 320 | dri_version.major = driDpy->driMajor; |
| 321 | dri_version.minor = driDpy->driMinor; |
| 322 | dri_version.patch = driDpy->driPatch; |
Kristian Høgsberg | 890d44e | 2008-03-07 00:45:54 -0500 | [diff] [blame] | 323 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 324 | framebuffer.base = MAP_FAILED; |
| 325 | framebuffer.dev_priv = NULL; |
Vinson Lee | 86d98fa | 2010-02-14 21:02:18 -0800 | [diff] [blame] | 326 | framebuffer.size = 0; |
Kristian Høgsberg | 890d44e | 2008-03-07 00:45:54 -0500 | [diff] [blame] | 327 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 328 | if (!XF86DRIOpenConnection(dpy, scrn, &hSAREA, &BusID)) { |
| 329 | ErrorMessageF("XF86DRIOpenConnection failed\n"); |
| 330 | goto handle_error; |
| 331 | } |
Kristian Høgsberg | 890d44e | 2008-03-07 00:45:54 -0500 | [diff] [blame] | 332 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 333 | fd = drmOpenOnce(NULL, BusID, &newlyopened); |
Kristian Høgsberg | 890d44e | 2008-03-07 00:45:54 -0500 | [diff] [blame] | 334 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 335 | Xfree(BusID); /* No longer needed */ |
Kristian Høgsberg | 890d44e | 2008-03-07 00:45:54 -0500 | [diff] [blame] | 336 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 337 | if (fd < 0) { |
| 338 | ErrorMessageF("drmOpenOnce failed (%s)\n", strerror(-fd)); |
| 339 | goto handle_error; |
| 340 | } |
George Sapountzis | 906e189 | 2008-06-09 17:47:49 +0300 | [diff] [blame] | 341 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 342 | if (drmGetMagic(fd, &magic)) { |
| 343 | ErrorMessageF("drmGetMagic failed\n"); |
| 344 | goto handle_error; |
| 345 | } |
George Sapountzis | 906e189 | 2008-06-09 17:47:49 +0300 | [diff] [blame] | 346 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 347 | version = drmGetVersion(fd); |
| 348 | if (version) { |
| 349 | drm_version.major = version->version_major; |
| 350 | drm_version.minor = version->version_minor; |
| 351 | drm_version.patch = version->version_patchlevel; |
| 352 | drmFreeVersion(version); |
| 353 | } |
| 354 | else { |
| 355 | drm_version.major = -1; |
| 356 | drm_version.minor = -1; |
| 357 | drm_version.patch = -1; |
| 358 | } |
George Sapountzis | 906e189 | 2008-06-09 17:47:49 +0300 | [diff] [blame] | 359 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 360 | if (newlyopened && !XF86DRIAuthConnection(dpy, scrn, magic)) { |
| 361 | ErrorMessageF("XF86DRIAuthConnection failed\n"); |
| 362 | goto handle_error; |
| 363 | } |
George Sapountzis | 906e189 | 2008-06-09 17:47:49 +0300 | [diff] [blame] | 364 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 365 | /* Get device name (like "tdfx") and the ddx version numbers. |
| 366 | * We'll check the version in each DRI driver's "createNewScreen" |
| 367 | * function. */ |
| 368 | if (!XF86DRIGetClientDriverName(dpy, scrn, |
| 369 | &ddx_version.major, |
| 370 | &ddx_version.minor, |
| 371 | &ddx_version.patch, &driverName)) { |
| 372 | ErrorMessageF("XF86DRIGetClientDriverName failed\n"); |
| 373 | goto handle_error; |
| 374 | } |
George Sapountzis | 906e189 | 2008-06-09 17:47:49 +0300 | [diff] [blame] | 375 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 376 | Xfree(driverName); /* No longer needed. */ |
George Sapountzis | 906e189 | 2008-06-09 17:47:49 +0300 | [diff] [blame] | 377 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 378 | /* |
| 379 | * Get device-specific info. pDevPriv will point to a struct |
| 380 | * (such as DRIRADEONRec in xfree86/driver/ati/radeon_dri.h) that |
| 381 | * has information about the screen size, depth, pitch, ancilliary |
| 382 | * buffers, DRM mmap handles, etc. |
| 383 | */ |
| 384 | if (!XF86DRIGetDeviceInfo(dpy, scrn, &hFB, &junk, |
| 385 | &framebuffer.size, &framebuffer.stride, |
| 386 | &framebuffer.dev_priv_size, |
| 387 | &framebuffer.dev_priv)) { |
| 388 | ErrorMessageF("XF86DRIGetDeviceInfo failed"); |
| 389 | goto handle_error; |
| 390 | } |
George Sapountzis | 906e189 | 2008-06-09 17:47:49 +0300 | [diff] [blame] | 391 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 392 | framebuffer.width = DisplayWidth(dpy, scrn); |
| 393 | framebuffer.height = DisplayHeight(dpy, scrn); |
George Sapountzis | 906e189 | 2008-06-09 17:47:49 +0300 | [diff] [blame] | 394 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 395 | /* Map the framebuffer region. */ |
| 396 | status = drmMap(fd, hFB, framebuffer.size, |
| 397 | (drmAddressPtr) & framebuffer.base); |
| 398 | if (status != 0) { |
| 399 | ErrorMessageF("drmMap of framebuffer failed (%s)", strerror(-status)); |
| 400 | goto handle_error; |
| 401 | } |
George Sapountzis | 906e189 | 2008-06-09 17:47:49 +0300 | [diff] [blame] | 402 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 403 | /* Map the SAREA region. Further mmap regions may be setup in |
| 404 | * each DRI driver's "createNewScreen" function. |
| 405 | */ |
| 406 | status = drmMap(fd, hSAREA, SAREA_MAX, &pSAREA); |
| 407 | if (status != 0) { |
| 408 | ErrorMessageF("drmMap of SAREA failed (%s)", strerror(-status)); |
| 409 | goto handle_error; |
| 410 | } |
George Sapountzis | 906e189 | 2008-06-09 17:47:49 +0300 | [diff] [blame] | 411 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 412 | psp = (*psc->legacy->createNewScreen) (scrn, |
| 413 | &ddx_version, |
| 414 | &dri_version, |
| 415 | &drm_version, |
| 416 | &framebuffer, |
| 417 | pSAREA, |
| 418 | fd, |
| 419 | loader_extensions, |
| 420 | &driver_configs, psc); |
George Sapountzis | 906e189 | 2008-06-09 17:47:49 +0300 | [diff] [blame] | 421 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 422 | if (psp == NULL) { |
| 423 | ErrorMessageF("Calling driver entry point failed"); |
| 424 | goto handle_error; |
| 425 | } |
George Sapountzis | 906e189 | 2008-06-09 17:47:49 +0300 | [diff] [blame] | 426 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 427 | psc->configs = driConvertConfigs(psc->core, psc->configs, driver_configs); |
| 428 | psc->visuals = driConvertConfigs(psc->core, psc->visuals, driver_configs); |
Kristian Høgsberg | 890d44e | 2008-03-07 00:45:54 -0500 | [diff] [blame] | 429 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 430 | psc->driver_configs = driver_configs; |
RALOVICH, Kristóf | d090ba9 | 2009-07-23 17:05:50 +0200 | [diff] [blame] | 431 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 432 | /* Visuals with depth != screen depth are subject to automatic compositing |
| 433 | * in the X server, so DRI1 can't render to them properly. Mark them as |
| 434 | * non-conformant to prevent apps from picking them up accidentally. |
| 435 | */ |
| 436 | for (visual = psc->visuals; visual; visual = visual->next) { |
| 437 | XVisualInfo template; |
| 438 | XVisualInfo *visuals; |
| 439 | int num_visuals; |
| 440 | long mask; |
Michel Dänzer | 25b492b | 2009-07-07 13:52:35 +0200 | [diff] [blame] | 441 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 442 | template.visualid = visual->visualID; |
| 443 | mask = VisualIDMask; |
| 444 | visuals = XGetVisualInfo(dpy, mask, &template, &num_visuals); |
Michel Dänzer | 25b492b | 2009-07-07 13:52:35 +0200 | [diff] [blame] | 445 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 446 | if (visuals) { |
| 447 | if (num_visuals > 0 && visuals->depth != DefaultDepth(dpy, scrn)) |
| 448 | visual->visualRating = GLX_NON_CONFORMANT_CONFIG; |
Michel Dänzer | 25b492b | 2009-07-07 13:52:35 +0200 | [diff] [blame] | 449 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 450 | XFree(visuals); |
| 451 | } |
| 452 | } |
Michel Dänzer | 25b492b | 2009-07-07 13:52:35 +0200 | [diff] [blame] | 453 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 454 | return psp; |
George Sapountzis | 906e189 | 2008-06-09 17:47:49 +0300 | [diff] [blame] | 455 | |
| 456 | handle_error: |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 457 | if (pSAREA != MAP_FAILED) |
| 458 | drmUnmap(pSAREA, SAREA_MAX); |
George Sapountzis | 906e189 | 2008-06-09 17:47:49 +0300 | [diff] [blame] | 459 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 460 | if (framebuffer.base != MAP_FAILED) |
| 461 | drmUnmap((drmAddress) framebuffer.base, framebuffer.size); |
George Sapountzis | 906e189 | 2008-06-09 17:47:49 +0300 | [diff] [blame] | 462 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 463 | if (framebuffer.dev_priv != NULL) |
| 464 | Xfree(framebuffer.dev_priv); |
George Sapountzis | 906e189 | 2008-06-09 17:47:49 +0300 | [diff] [blame] | 465 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 466 | if (fd >= 0) |
| 467 | drmCloseOnce(fd); |
George Sapountzis | 906e189 | 2008-06-09 17:47:49 +0300 | [diff] [blame] | 468 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 469 | XF86DRICloseConnection(dpy, scrn); |
George Sapountzis | 906e189 | 2008-06-09 17:47:49 +0300 | [diff] [blame] | 470 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 471 | ErrorMessageF("reverting to software direct rendering\n"); |
George Sapountzis | 906e189 | 2008-06-09 17:47:49 +0300 | [diff] [blame] | 472 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 473 | return NULL; |
Kristian Høgsberg | 890d44e | 2008-03-07 00:45:54 -0500 | [diff] [blame] | 474 | } |
| 475 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 476 | static void |
| 477 | driDestroyContext(__GLXDRIcontext * context, |
| 478 | __GLXscreenConfigs * psc, Display * dpy) |
Kristian Høgsberg | 53dc863 | 2008-03-08 20:02:22 -0500 | [diff] [blame] | 479 | { |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 480 | __GLXDRIcontextPrivate *pcp = (__GLXDRIcontextPrivate *) context; |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 481 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 482 | (*psc->core->destroyContext) (pcp->driContext); |
| 483 | |
| 484 | XF86DRIDestroyContext(psc->dpy, psc->scr, pcp->hwContextID); |
| 485 | Xfree(pcp); |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 486 | } |
| 487 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 488 | static Bool |
| 489 | driBindContext(__GLXDRIcontext * context, |
| 490 | __GLXDRIdrawable * draw, __GLXDRIdrawable * read) |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 491 | { |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 492 | __GLXDRIcontextPrivate *pcp = (__GLXDRIcontextPrivate *) context; |
| 493 | const __DRIcoreExtension *core = pcp->psc->core; |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 494 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 495 | return (*core->bindContext) (pcp->driContext, |
| 496 | draw->driDrawable, read->driDrawable); |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 497 | } |
| 498 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 499 | static void |
| 500 | driUnbindContext(__GLXDRIcontext * context) |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 501 | { |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 502 | __GLXDRIcontextPrivate *pcp = (__GLXDRIcontextPrivate *) context; |
| 503 | const __DRIcoreExtension *core = pcp->psc->core; |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 504 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 505 | (*core->unbindContext) (pcp->driContext); |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 506 | } |
| 507 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 508 | static __GLXDRIcontext * |
| 509 | driCreateContext(__GLXscreenConfigs * psc, |
| 510 | const __GLcontextModes * mode, |
| 511 | GLXContext gc, GLXContext shareList, int renderType) |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 512 | { |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 513 | __GLXDRIcontextPrivate *pcp, *pcp_shared; |
| 514 | drm_context_t hwContext; |
| 515 | __DRIcontext *shared = NULL; |
| 516 | __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) mode; |
Kristian Høgsberg | 53dc863 | 2008-03-08 20:02:22 -0500 | [diff] [blame] | 517 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 518 | if (!psc || !psc->driScreen) |
| 519 | return NULL; |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 520 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 521 | if (shareList) { |
| 522 | pcp_shared = (__GLXDRIcontextPrivate *) shareList->driContext; |
| 523 | shared = pcp_shared->driContext; |
| 524 | } |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 525 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 526 | pcp = Xmalloc(sizeof *pcp); |
| 527 | if (pcp == NULL) |
| 528 | return NULL; |
George Sapountzis | 0793457 | 2008-06-09 17:47:09 +0300 | [diff] [blame] | 529 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 530 | pcp->psc = psc; |
| 531 | if (!XF86DRICreateContextWithConfig(psc->dpy, psc->scr, |
| 532 | mode->visualID, |
| 533 | &pcp->hwContextID, &hwContext)) { |
| 534 | Xfree(pcp); |
| 535 | return NULL; |
| 536 | } |
George Sapountzis | 0793457 | 2008-06-09 17:47:09 +0300 | [diff] [blame] | 537 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 538 | pcp->driContext = |
| 539 | (*psc->legacy->createNewContext) (psc->__driScreen, |
| 540 | config->driConfig, |
| 541 | renderType, shared, hwContext, pcp); |
| 542 | if (pcp->driContext == NULL) { |
| 543 | XF86DRIDestroyContext(psc->dpy, psc->scr, pcp->hwContextID); |
| 544 | Xfree(pcp); |
| 545 | return NULL; |
| 546 | } |
George Sapountzis | 0793457 | 2008-06-09 17:47:09 +0300 | [diff] [blame] | 547 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 548 | pcp->base.destroyContext = driDestroyContext; |
| 549 | pcp->base.bindContext = driBindContext; |
| 550 | pcp->base.unbindContext = driUnbindContext; |
George Sapountzis | 0793457 | 2008-06-09 17:47:09 +0300 | [diff] [blame] | 551 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 552 | return &pcp->base; |
Kristian Høgsberg | 53dc863 | 2008-03-08 20:02:22 -0500 | [diff] [blame] | 553 | } |
| 554 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 555 | static void |
| 556 | driDestroyDrawable(__GLXDRIdrawable * pdraw) |
Kristian Høgsberg | 9110425 | 2008-03-12 02:18:12 -0400 | [diff] [blame] | 557 | { |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 558 | __GLXscreenConfigs *psc = pdraw->psc; |
Kristian Høgsberg | 9110425 | 2008-03-12 02:18:12 -0400 | [diff] [blame] | 559 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 560 | (*psc->core->destroyDrawable) (pdraw->driDrawable); |
| 561 | XF86DRIDestroyDrawable(psc->dpy, psc->scr, pdraw->drawable); |
| 562 | Xfree(pdraw); |
Kristian Høgsberg | 9110425 | 2008-03-12 02:18:12 -0400 | [diff] [blame] | 563 | } |
Kristian Høgsberg | 20b9230 | 2008-03-08 21:02:23 -0500 | [diff] [blame] | 564 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 565 | static __GLXDRIdrawable * |
| 566 | driCreateDrawable(__GLXscreenConfigs * psc, |
| 567 | XID xDrawable, |
| 568 | GLXDrawable drawable, const __GLcontextModes * modes) |
Kristian Høgsberg | 20b9230 | 2008-03-08 21:02:23 -0500 | [diff] [blame] | 569 | { |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 570 | __GLXDRIdrawable *pdraw; |
| 571 | drm_drawable_t hwDrawable; |
| 572 | void *empty_attribute_list = NULL; |
| 573 | __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) modes; |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 574 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 575 | /* Old dri can't handle GLX 1.3+ drawable constructors. */ |
| 576 | if (xDrawable != drawable) |
| 577 | return NULL; |
Kristian Høgsberg | 20b9230 | 2008-03-08 21:02:23 -0500 | [diff] [blame] | 578 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 579 | pdraw = Xmalloc(sizeof(*pdraw)); |
| 580 | if (!pdraw) |
| 581 | return NULL; |
Kristian Høgsberg | 20b9230 | 2008-03-08 21:02:23 -0500 | [diff] [blame] | 582 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 583 | pdraw->drawable = drawable; |
| 584 | pdraw->psc = psc; |
Kristian Høgsberg | 20b9230 | 2008-03-08 21:02:23 -0500 | [diff] [blame] | 585 | |
Vinson Lee | e055665 | 2009-11-02 12:35:47 -0700 | [diff] [blame] | 586 | if (!XF86DRICreateDrawable(psc->dpy, psc->scr, drawable, &hwDrawable)) { |
| 587 | Xfree(pdraw); |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 588 | return NULL; |
Vinson Lee | e055665 | 2009-11-02 12:35:47 -0700 | [diff] [blame] | 589 | } |
Kristian Høgsberg | 20b9230 | 2008-03-08 21:02:23 -0500 | [diff] [blame] | 590 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 591 | /* Create a new drawable */ |
| 592 | pdraw->driDrawable = |
| 593 | (*psc->legacy->createNewDrawable) (psc->__driScreen, |
| 594 | config->driConfig, |
| 595 | hwDrawable, |
| 596 | GLX_WINDOW_BIT, |
| 597 | empty_attribute_list, pdraw); |
Kristian Høgsberg | 20b9230 | 2008-03-08 21:02:23 -0500 | [diff] [blame] | 598 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 599 | if (!pdraw->driDrawable) { |
| 600 | XF86DRIDestroyDrawable(psc->dpy, psc->scr, drawable); |
| 601 | Xfree(pdraw); |
| 602 | return NULL; |
| 603 | } |
Kristian Høgsberg | 20b9230 | 2008-03-08 21:02:23 -0500 | [diff] [blame] | 604 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 605 | pdraw->destroyDrawable = driDestroyDrawable; |
Kristian Høgsberg | 20b9230 | 2008-03-08 21:02:23 -0500 | [diff] [blame] | 606 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 607 | return pdraw; |
Kristian Høgsberg | 20b9230 | 2008-03-08 21:02:23 -0500 | [diff] [blame] | 608 | } |
| 609 | |
Jesse Barnes | daf7fe6 | 2009-09-15 23:23:09 -0700 | [diff] [blame] | 610 | static int64_t |
| 611 | driSwapBuffers(__GLXDRIdrawable * pdraw, int64_t unused1, int64_t unused2, |
| 612 | int64_t unused3) |
Kristian Høgsberg | f56b569 | 2008-08-13 11:46:25 -0400 | [diff] [blame] | 613 | { |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 614 | (*pdraw->psc->core->swapBuffers) (pdraw->driDrawable); |
Jesse Barnes | daf7fe6 | 2009-09-15 23:23:09 -0700 | [diff] [blame] | 615 | return 0; |
Kristian Høgsberg | f56b569 | 2008-08-13 11:46:25 -0400 | [diff] [blame] | 616 | } |
| 617 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 618 | static void |
| 619 | driCopySubBuffer(__GLXDRIdrawable * pdraw, |
| 620 | int x, int y, int width, int height) |
Kristian Høgsberg | 4830809 | 2008-10-11 20:41:14 -0400 | [diff] [blame] | 621 | { |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 622 | (*pdraw->psc->driCopySubBuffer->copySubBuffer) (pdraw->driDrawable, |
| 623 | x, y, width, height); |
Kristian Høgsberg | 4830809 | 2008-10-11 20:41:14 -0400 | [diff] [blame] | 624 | } |
| 625 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 626 | static void |
| 627 | driDestroyScreen(__GLXscreenConfigs * psc) |
Kristian Høgsberg | a1ea6f6 | 2008-03-08 19:15:50 -0500 | [diff] [blame] | 628 | { |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 629 | /* Free the direct rendering per screen data */ |
| 630 | if (psc->__driScreen) |
| 631 | (*psc->core->destroyScreen) (psc->__driScreen); |
| 632 | psc->__driScreen = NULL; |
| 633 | if (psc->driver) |
| 634 | dlclose(psc->driver); |
Kristian Høgsberg | a1ea6f6 | 2008-03-08 19:15:50 -0500 | [diff] [blame] | 635 | } |
| 636 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 637 | static __GLXDRIscreen * |
| 638 | driCreateScreen(__GLXscreenConfigs * psc, int screen, |
| 639 | __GLXdisplayPrivate * priv) |
Kristian Høgsberg | 890d44e | 2008-03-07 00:45:54 -0500 | [diff] [blame] | 640 | { |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 641 | __GLXDRIdisplayPrivate *pdp; |
| 642 | __GLXDRIscreen *psp; |
| 643 | const __DRIextension **extensions; |
| 644 | char *driverName; |
| 645 | int i; |
Kristian Høgsberg | 0f2723c | 2008-03-07 01:37:08 -0500 | [diff] [blame] | 646 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 647 | psp = Xcalloc(1, sizeof *psp); |
| 648 | if (psp == NULL) |
| 649 | return NULL; |
Kristian Høgsberg | 0f2723c | 2008-03-07 01:37:08 -0500 | [diff] [blame] | 650 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 651 | if (!driGetDriverName(priv->dpy, screen, &driverName)) { |
| 652 | Xfree(psp); |
| 653 | return NULL; |
| 654 | } |
George Sapountzis | 0793457 | 2008-06-09 17:47:09 +0300 | [diff] [blame] | 655 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 656 | psc->driver = driOpenDriver(driverName); |
| 657 | Xfree(driverName); |
| 658 | if (psc->driver == NULL) { |
| 659 | Xfree(psp); |
| 660 | return NULL; |
| 661 | } |
Kristian Høgsberg | 0f2723c | 2008-03-07 01:37:08 -0500 | [diff] [blame] | 662 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 663 | extensions = dlsym(psc->driver, __DRI_DRIVER_EXTENSIONS); |
| 664 | if (extensions == NULL) { |
| 665 | ErrorMessageF("driver exports no extensions (%s)\n", dlerror()); |
| 666 | Xfree(psp); |
| 667 | return NULL; |
| 668 | } |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 669 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 670 | for (i = 0; extensions[i]; i++) { |
| 671 | if (strcmp(extensions[i]->name, __DRI_CORE) == 0) |
Jesse Barnes | daf7fe6 | 2009-09-15 23:23:09 -0700 | [diff] [blame] | 672 | psc->core = (__DRIcoreExtension *) extensions[i]; |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 673 | if (strcmp(extensions[i]->name, __DRI_LEGACY) == 0) |
Jesse Barnes | daf7fe6 | 2009-09-15 23:23:09 -0700 | [diff] [blame] | 674 | psc->legacy = (__DRIlegacyExtension *) extensions[i]; |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 675 | } |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 676 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 677 | if (psc->core == NULL || psc->legacy == NULL) { |
| 678 | Xfree(psp); |
| 679 | return NULL; |
| 680 | } |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 681 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 682 | pdp = (__GLXDRIdisplayPrivate *) priv->driDisplay; |
| 683 | psc->__driScreen = CallCreateNewScreen(psc->dpy, screen, psc, pdp); |
| 684 | if (psc->__driScreen == NULL) { |
| 685 | dlclose(psc->driver); |
| 686 | Xfree(psp); |
| 687 | return NULL; |
| 688 | } |
Kristian Høgsberg | 0f2723c | 2008-03-07 01:37:08 -0500 | [diff] [blame] | 689 | |
Jesse Barnes | daf7fe6 | 2009-09-15 23:23:09 -0700 | [diff] [blame] | 690 | driBindExtensions(psc); |
| 691 | driBindCommonExtensions(psc); |
| 692 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 693 | if (psc->driCopySubBuffer) |
| 694 | psp->copySubBuffer = driCopySubBuffer; |
Kristian Høgsberg | 92d2a78 | 2008-03-08 20:34:24 -0500 | [diff] [blame] | 695 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 696 | psp->destroyScreen = driDestroyScreen; |
| 697 | psp->createContext = driCreateContext; |
| 698 | psp->createDrawable = driCreateDrawable; |
| 699 | psp->swapBuffers = driSwapBuffers; |
| 700 | psp->waitX = NULL; |
| 701 | psp->waitGL = NULL; |
| 702 | |
| 703 | return psp; |
Kristian Høgsberg | 890d44e | 2008-03-07 00:45:54 -0500 | [diff] [blame] | 704 | } |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 705 | |
Michel Dänzer | 8628b38 | 2007-02-01 10:45:51 +0100 | [diff] [blame] | 706 | /* Called from __glXFreeDisplayPrivate. |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 707 | */ |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 708 | static void |
| 709 | driDestroyDisplay(__GLXDRIdisplay * dpy) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 710 | { |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 711 | Xfree(dpy); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 712 | } |
| 713 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 714 | /* |
| 715 | * Allocate, initialize and return a __DRIdisplayPrivate object. |
| 716 | * This is called from __glXInitialize() when we are given a new |
| 717 | * display pointer. |
| 718 | */ |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 719 | _X_HIDDEN __GLXDRIdisplay * |
| 720 | driCreateDisplay(Display * dpy) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 721 | { |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 722 | __GLXDRIdisplayPrivate *pdpyp; |
| 723 | int eventBase, errorBase; |
| 724 | int major, minor, patch; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 725 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 726 | if (!XF86DRIQueryExtension(dpy, &eventBase, &errorBase)) { |
| 727 | return NULL; |
| 728 | } |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 729 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 730 | if (!XF86DRIQueryVersion(dpy, &major, &minor, &patch)) { |
| 731 | return NULL; |
| 732 | } |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 733 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 734 | pdpyp = Xmalloc(sizeof *pdpyp); |
| 735 | if (!pdpyp) { |
| 736 | return NULL; |
| 737 | } |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 738 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 739 | pdpyp->driMajor = major; |
| 740 | pdpyp->driMinor = minor; |
| 741 | pdpyp->driPatch = patch; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 742 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 743 | pdpyp->base.destroyDisplay = driDestroyDisplay; |
| 744 | pdpyp->base.createScreen = driCreateScreen; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 745 | |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 746 | return &pdpyp->base; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | #endif /* GLX_DIRECT_RENDERING */ |