Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2010 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
| 19 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 | * DEALINGS IN THE SOFTWARE. |
| 23 | * |
| 24 | * Authors: |
| 25 | * Kristian Høgsberg <krh@bitplanet.net> |
| 26 | */ |
| 27 | |
| 28 | #include <stdlib.h> |
| 29 | #include <string.h> |
| 30 | #include <stdio.h> |
| 31 | #include <limits.h> |
| 32 | #include <dlfcn.h> |
| 33 | #include <fcntl.h> |
| 34 | #include <errno.h> |
| 35 | #include <unistd.h> |
| 36 | #include <xf86drm.h> |
| 37 | #include <GL/gl.h> |
| 38 | #include <GL/internal/dri_interface.h> |
| 39 | #include <xcb/xcb.h> |
| 40 | #include <xcb/dri2.h> |
| 41 | #include <xcb/xfixes.h> |
| 42 | #include <X11/Xlib-xcb.h> |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 43 | #include <sys/types.h> |
| 44 | #include <sys/stat.h> |
| 45 | |
| 46 | #ifdef HAVE_LIBUDEV |
| 47 | #include <libudev.h> |
| 48 | #endif |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 49 | |
| 50 | #include <glapi/glapi.h> |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 51 | #include "eglconfig.h" |
| 52 | #include "eglcontext.h" |
| 53 | #include "egldisplay.h" |
| 54 | #include "egldriver.h" |
| 55 | #include "eglcurrent.h" |
| 56 | #include "egllog.h" |
| 57 | #include "eglsurface.h" |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 58 | #include "eglimage.h" |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 59 | |
Kristian Høgsberg | 52c554a | 2010-05-06 22:01:35 -0400 | [diff] [blame] | 60 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) |
| 61 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 62 | struct dri2_egl_driver |
| 63 | { |
| 64 | _EGLDriver base; |
Chia-I Wu | d18d0fd | 2010-04-06 19:52:39 +0800 | [diff] [blame] | 65 | |
| 66 | void (*glFlush)(void); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | struct dri2_egl_display |
| 70 | { |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 71 | xcb_connection_t *conn; |
| 72 | int dri2_major; |
| 73 | int dri2_minor; |
| 74 | __DRIscreen *dri_screen; |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 75 | const __DRIconfig **driver_configs; |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 76 | void *driver; |
| 77 | __DRIcoreExtension *core; |
| 78 | __DRIdri2Extension *dri2; |
| 79 | __DRI2flushExtension *flush; |
| 80 | __DRItexBufferExtension *tex_buffer; |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 81 | __DRIimageExtension *image; |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 82 | int fd; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 83 | |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 84 | char *device_name; |
| 85 | char *driver_name; |
| 86 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 87 | __DRIdri2LoaderExtension loader_extension; |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 88 | const __DRIextension *extensions[3]; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | struct dri2_egl_context |
| 92 | { |
| 93 | _EGLContext base; |
| 94 | __DRIcontext *dri_context; |
| 95 | }; |
| 96 | |
| 97 | struct dri2_egl_surface |
| 98 | { |
| 99 | _EGLSurface base; |
| 100 | __DRIdrawable *dri_drawable; |
| 101 | xcb_drawable_t drawable; |
| 102 | __DRIbuffer buffers[5]; |
| 103 | int buffer_count; |
| 104 | xcb_xfixes_region_t region; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 105 | int have_fake_front; |
| 106 | int swap_interval; |
| 107 | }; |
| 108 | |
| 109 | struct dri2_egl_config |
| 110 | { |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 111 | _EGLConfig base; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 112 | const __DRIconfig *dri_config; |
| 113 | }; |
| 114 | |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 115 | struct dri2_egl_image |
| 116 | { |
| 117 | _EGLImage base; |
| 118 | __DRIimage *dri_image; |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 119 | }; |
| 120 | |
Chia-I Wu | a35e633 | 2010-02-05 11:38:34 +0800 | [diff] [blame] | 121 | /* standard typecasts */ |
| 122 | _EGL_DRIVER_STANDARD_TYPECASTS(dri2_egl) |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 123 | _EGL_DRIVER_TYPECAST(dri2_egl_image, _EGLImage, obj) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 124 | |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 125 | static const __DRIuseInvalidateExtension use_invalidate = { |
| 126 | { __DRI_USE_INVALIDATE, 1 } |
| 127 | }; |
| 128 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 129 | EGLint dri2_to_egl_attribute_map[] = { |
| 130 | 0, |
| 131 | EGL_BUFFER_SIZE, /* __DRI_ATTRIB_BUFFER_SIZE */ |
| 132 | EGL_LEVEL, /* __DRI_ATTRIB_LEVEL */ |
| 133 | EGL_RED_SIZE, /* __DRI_ATTRIB_RED_SIZE */ |
| 134 | EGL_GREEN_SIZE, /* __DRI_ATTRIB_GREEN_SIZE */ |
| 135 | EGL_BLUE_SIZE, /* __DRI_ATTRIB_BLUE_SIZE */ |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 136 | EGL_LUMINANCE_SIZE, /* __DRI_ATTRIB_LUMINANCE_SIZE */ |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 137 | EGL_ALPHA_SIZE, /* __DRI_ATTRIB_ALPHA_SIZE */ |
| 138 | 0, /* __DRI_ATTRIB_ALPHA_MASK_SIZE */ |
| 139 | EGL_DEPTH_SIZE, /* __DRI_ATTRIB_DEPTH_SIZE */ |
| 140 | EGL_STENCIL_SIZE, /* __DRI_ATTRIB_STENCIL_SIZE */ |
| 141 | 0, /* __DRI_ATTRIB_ACCUM_RED_SIZE */ |
| 142 | 0, /* __DRI_ATTRIB_ACCUM_GREEN_SIZE */ |
| 143 | 0, /* __DRI_ATTRIB_ACCUM_BLUE_SIZE */ |
| 144 | 0, /* __DRI_ATTRIB_ACCUM_ALPHA_SIZE */ |
| 145 | EGL_SAMPLE_BUFFERS, /* __DRI_ATTRIB_SAMPLE_BUFFERS */ |
| 146 | EGL_SAMPLES, /* __DRI_ATTRIB_SAMPLES */ |
| 147 | 0, /* __DRI_ATTRIB_RENDER_TYPE, */ |
| 148 | 0, /* __DRI_ATTRIB_CONFIG_CAVEAT */ |
| 149 | 0, /* __DRI_ATTRIB_CONFORMANT */ |
| 150 | 0, /* __DRI_ATTRIB_DOUBLE_BUFFER */ |
| 151 | 0, /* __DRI_ATTRIB_STEREO */ |
| 152 | 0, /* __DRI_ATTRIB_AUX_BUFFERS */ |
| 153 | 0, /* __DRI_ATTRIB_TRANSPARENT_TYPE */ |
| 154 | 0, /* __DRI_ATTRIB_TRANSPARENT_INDEX_VALUE */ |
| 155 | 0, /* __DRI_ATTRIB_TRANSPARENT_RED_VALUE */ |
| 156 | 0, /* __DRI_ATTRIB_TRANSPARENT_GREEN_VALUE */ |
| 157 | 0, /* __DRI_ATTRIB_TRANSPARENT_BLUE_VALUE */ |
| 158 | 0, /* __DRI_ATTRIB_TRANSPARENT_ALPHA_VALUE */ |
| 159 | 0, /* __DRI_ATTRIB_FLOAT_MODE */ |
| 160 | 0, /* __DRI_ATTRIB_RED_MASK */ |
| 161 | 0, /* __DRI_ATTRIB_GREEN_MASK */ |
| 162 | 0, /* __DRI_ATTRIB_BLUE_MASK */ |
| 163 | 0, /* __DRI_ATTRIB_ALPHA_MASK */ |
| 164 | EGL_MAX_PBUFFER_WIDTH, /* __DRI_ATTRIB_MAX_PBUFFER_WIDTH */ |
| 165 | EGL_MAX_PBUFFER_HEIGHT, /* __DRI_ATTRIB_MAX_PBUFFER_HEIGHT */ |
| 166 | EGL_MAX_PBUFFER_PIXELS, /* __DRI_ATTRIB_MAX_PBUFFER_PIXELS */ |
| 167 | 0, /* __DRI_ATTRIB_OPTIMAL_PBUFFER_WIDTH */ |
| 168 | 0, /* __DRI_ATTRIB_OPTIMAL_PBUFFER_HEIGHT */ |
| 169 | 0, /* __DRI_ATTRIB_VISUAL_SELECT_GROUP */ |
| 170 | 0, /* __DRI_ATTRIB_SWAP_METHOD */ |
| 171 | EGL_MAX_SWAP_INTERVAL, /* __DRI_ATTRIB_MAX_SWAP_INTERVAL */ |
| 172 | EGL_MIN_SWAP_INTERVAL, /* __DRI_ATTRIB_MIN_SWAP_INTERVAL */ |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 173 | 0, /* __DRI_ATTRIB_BIND_TO_TEXTURE_RGB */ |
| 174 | 0, /* __DRI_ATTRIB_BIND_TO_TEXTURE_RGBA */ |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 175 | 0, /* __DRI_ATTRIB_BIND_TO_MIPMAP_TEXTURE */ |
| 176 | 0, /* __DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS */ |
Kristian Høgsberg | 5dc0f49 | 2010-05-06 22:40:25 -0400 | [diff] [blame] | 177 | EGL_Y_INVERTED_NOK, /* __DRI_ATTRIB_YINVERTED */ |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 178 | }; |
| 179 | |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 180 | static struct dri2_egl_config * |
Kristian Høgsberg | c3c1a7e | 2010-02-09 20:49:40 -0500 | [diff] [blame] | 181 | dri2_add_config(_EGLDisplay *disp, const __DRIconfig *dri_config, int id, |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 182 | int depth, EGLint surface_type) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 183 | { |
| 184 | struct dri2_egl_config *conf; |
| 185 | struct dri2_egl_display *dri2_dpy; |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 186 | _EGLConfig base; |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 187 | unsigned int attrib, value, double_buffer; |
| 188 | EGLint key, bind_to_texture_rgb, bind_to_texture_rgba; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 189 | int i; |
| 190 | |
| 191 | dri2_dpy = disp->DriverData; |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 192 | _eglInitConfig(&base, disp, id); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 193 | |
| 194 | i = 0; |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 195 | double_buffer = 0; |
| 196 | bind_to_texture_rgb = 0; |
| 197 | bind_to_texture_rgba = 0; |
| 198 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 199 | while (dri2_dpy->core->indexConfigAttrib(dri_config, i++, &attrib, &value)) { |
| 200 | switch (attrib) { |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 201 | case __DRI_ATTRIB_RENDER_TYPE: |
| 202 | if (value & __DRI_ATTRIB_RGBA_BIT) |
| 203 | value = EGL_RGB_BUFFER; |
| 204 | else if (value & __DRI_ATTRIB_LUMINANCE_BIT) |
| 205 | value = EGL_LUMINANCE_BUFFER; |
| 206 | else |
| 207 | /* not valid */; |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 208 | _eglSetConfigKey(&base, EGL_COLOR_BUFFER_TYPE, value); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 209 | break; |
| 210 | |
| 211 | case __DRI_ATTRIB_CONFIG_CAVEAT: |
| 212 | if (value & __DRI_ATTRIB_NON_CONFORMANT_CONFIG) |
| 213 | value = EGL_NON_CONFORMANT_CONFIG; |
| 214 | else if (value & __DRI_ATTRIB_SLOW_BIT) |
| 215 | value = EGL_SLOW_CONFIG; |
| 216 | else |
| 217 | value = EGL_NONE; |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 218 | _eglSetConfigKey(&base, EGL_CONFIG_CAVEAT, value); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 219 | break; |
| 220 | |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 221 | case __DRI_ATTRIB_BIND_TO_TEXTURE_RGB: |
| 222 | bind_to_texture_rgb = value; |
| 223 | break; |
| 224 | |
| 225 | case __DRI_ATTRIB_BIND_TO_TEXTURE_RGBA: |
| 226 | bind_to_texture_rgba = value; |
| 227 | break; |
| 228 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 229 | case __DRI_ATTRIB_DOUBLE_BUFFER: |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 230 | double_buffer = value; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 231 | break; |
| 232 | |
| 233 | default: |
| 234 | key = dri2_to_egl_attribute_map[attrib]; |
| 235 | if (key != 0) |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 236 | _eglSetConfigKey(&base, key, value); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 237 | break; |
| 238 | } |
| 239 | } |
| 240 | |
Kristian Høgsberg | c3c1a7e | 2010-02-09 20:49:40 -0500 | [diff] [blame] | 241 | /* In EGL, double buffer or not isn't a config attribute. Pixmaps |
| 242 | * surfaces are always single buffered, pbuffer surfaces are always |
| 243 | * back buffers and windows can be either, selected by passing an |
| 244 | * attribute at window surface construction time. To support this |
| 245 | * we ignore all double buffer configs and manipulate the buffer we |
| 246 | * return in the getBuffer callback to get the behaviour we want. */ |
| 247 | |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 248 | if (double_buffer) |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 249 | return NULL; |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 250 | |
Chia-I Wu | b67f729 | 2010-10-22 15:03:11 +0800 | [diff] [blame] | 251 | if (depth > 0 && depth != base.BufferSize) |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 252 | return NULL; |
Kristian Høgsberg | c3c1a7e | 2010-02-09 20:49:40 -0500 | [diff] [blame] | 253 | |
Chia-I Wu | b67f729 | 2010-10-22 15:03:11 +0800 | [diff] [blame] | 254 | base.NativeRenderable = EGL_TRUE; |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 255 | |
Chia-I Wu | b67f729 | 2010-10-22 15:03:11 +0800 | [diff] [blame] | 256 | base.SurfaceType = surface_type; |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 257 | if (surface_type & (EGL_PIXMAP_BIT | EGL_PBUFFER_BIT)) { |
Chia-I Wu | b67f729 | 2010-10-22 15:03:11 +0800 | [diff] [blame] | 258 | base.BindToTextureRGB = bind_to_texture_rgb; |
| 259 | if (base.AlphaSize > 0) |
| 260 | base.BindToTextureRGBA = bind_to_texture_rgba; |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 261 | } |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 262 | |
Chia-I Wu | b67f729 | 2010-10-22 15:03:11 +0800 | [diff] [blame] | 263 | base.RenderableType = disp->ClientAPIsMask; |
| 264 | base.Conformant = disp->ClientAPIsMask; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 265 | |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 266 | if (!_eglValidateConfig(&base, EGL_FALSE)) { |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 267 | _eglLog(_EGL_DEBUG, "DRI2: failed to validate config %d", id); |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 268 | return NULL; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 269 | } |
| 270 | |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 271 | conf = malloc(sizeof *conf); |
| 272 | if (conf != NULL) { |
| 273 | memcpy(&conf->base, &base, sizeof base); |
| 274 | conf->dri_config = dri_config; |
Chia-I Wu | 8a6bdf3 | 2010-10-23 00:47:22 +0800 | [diff] [blame] | 275 | _eglLinkConfig(&conf->base); |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 276 | } |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 277 | |
| 278 | return conf; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | /** |
| 282 | * Process list of buffer received from the server |
| 283 | * |
| 284 | * Processes the list of buffers received in a reply from the server to either |
| 285 | * \c DRI2GetBuffers or \c DRI2GetBuffersWithFormat. |
| 286 | */ |
| 287 | static void |
| 288 | dri2_process_buffers(struct dri2_egl_surface *dri2_surf, |
| 289 | xcb_dri2_dri2_buffer_t *buffers, unsigned count) |
| 290 | { |
| 291 | struct dri2_egl_display *dri2_dpy = |
| 292 | dri2_egl_display(dri2_surf->base.Resource.Display); |
| 293 | xcb_rectangle_t rectangle; |
Ian Romanick | e4bd50c | 2010-09-24 10:54:28 -0700 | [diff] [blame] | 294 | unsigned i; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 295 | |
| 296 | dri2_surf->buffer_count = count; |
| 297 | dri2_surf->have_fake_front = 0; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 298 | |
| 299 | /* This assumes the DRI2 buffer attachment tokens matches the |
| 300 | * __DRIbuffer tokens. */ |
| 301 | for (i = 0; i < count; i++) { |
| 302 | dri2_surf->buffers[i].attachment = buffers[i].attachment; |
| 303 | dri2_surf->buffers[i].name = buffers[i].name; |
| 304 | dri2_surf->buffers[i].pitch = buffers[i].pitch; |
| 305 | dri2_surf->buffers[i].cpp = buffers[i].cpp; |
| 306 | dri2_surf->buffers[i].flags = buffers[i].flags; |
Kristian Høgsberg | c3c1a7e | 2010-02-09 20:49:40 -0500 | [diff] [blame] | 307 | |
| 308 | /* We only use the DRI drivers single buffer configs. This |
| 309 | * means that if we try to render to a window, DRI2 will give us |
| 310 | * the fake front buffer, which we'll use as a back buffer. |
| 311 | * Note that EGL doesn't require that several clients rendering |
| 312 | * to the same window must see the same aux buffers. */ |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 313 | if (dri2_surf->buffers[i].attachment == __DRI_BUFFER_FAKE_FRONT_LEFT) |
| 314 | dri2_surf->have_fake_front = 1; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | if (dri2_surf->region != XCB_NONE) |
| 318 | xcb_xfixes_destroy_region(dri2_dpy->conn, dri2_surf->region); |
| 319 | |
| 320 | rectangle.x = 0; |
| 321 | rectangle.y = 0; |
| 322 | rectangle.width = dri2_surf->base.Width; |
| 323 | rectangle.height = dri2_surf->base.Height; |
| 324 | dri2_surf->region = xcb_generate_id(dri2_dpy->conn); |
| 325 | xcb_xfixes_create_region(dri2_dpy->conn, dri2_surf->region, 1, &rectangle); |
| 326 | } |
| 327 | |
| 328 | static __DRIbuffer * |
| 329 | dri2_get_buffers(__DRIdrawable * driDrawable, |
| 330 | int *width, int *height, |
| 331 | unsigned int *attachments, int count, |
| 332 | int *out_count, void *loaderPrivate) |
| 333 | { |
| 334 | struct dri2_egl_surface *dri2_surf = loaderPrivate; |
| 335 | struct dri2_egl_display *dri2_dpy = |
| 336 | dri2_egl_display(dri2_surf->base.Resource.Display); |
| 337 | xcb_dri2_dri2_buffer_t *buffers; |
| 338 | xcb_dri2_get_buffers_reply_t *reply; |
| 339 | xcb_dri2_get_buffers_cookie_t cookie; |
| 340 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 341 | (void) driDrawable; |
| 342 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 343 | cookie = xcb_dri2_get_buffers_unchecked (dri2_dpy->conn, |
| 344 | dri2_surf->drawable, |
| 345 | count, count, attachments); |
| 346 | reply = xcb_dri2_get_buffers_reply (dri2_dpy->conn, cookie, NULL); |
| 347 | buffers = xcb_dri2_get_buffers_buffers (reply); |
| 348 | if (buffers == NULL) |
| 349 | return NULL; |
| 350 | |
| 351 | *out_count = reply->count; |
| 352 | dri2_surf->base.Width = *width = reply->width; |
| 353 | dri2_surf->base.Height = *height = reply->height; |
| 354 | dri2_process_buffers(dri2_surf, buffers, *out_count); |
| 355 | |
| 356 | free(reply); |
| 357 | |
| 358 | return dri2_surf->buffers; |
| 359 | } |
| 360 | |
| 361 | static void |
| 362 | dri2_flush_front_buffer(__DRIdrawable * driDrawable, void *loaderPrivate) |
| 363 | { |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 364 | (void) driDrawable; |
| 365 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 366 | /* FIXME: Does EGL support front buffer rendering at all? */ |
| 367 | |
| 368 | #if 0 |
| 369 | struct dri2_egl_surface *dri2_surf = loaderPrivate; |
| 370 | |
| 371 | dri2WaitGL(dri2_surf); |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 372 | #else |
| 373 | (void) loaderPrivate; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 374 | #endif |
| 375 | } |
| 376 | |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 377 | static __DRIimage * |
Kristian Høgsberg | 17eace5 | 2010-09-22 22:01:17 -0400 | [diff] [blame] | 378 | dri2_lookup_egl_image(__DRIscreen *screen, void *image, void *data) |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 379 | { |
Kristian Høgsberg | 17eace5 | 2010-09-22 22:01:17 -0400 | [diff] [blame] | 380 | _EGLDisplay *disp = data; |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 381 | struct dri2_egl_image *dri2_img; |
| 382 | _EGLImage *img; |
| 383 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 384 | (void) screen; |
| 385 | |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 386 | img = _eglLookupImage(image, disp); |
| 387 | if (img == NULL) { |
| 388 | _eglError(EGL_BAD_PARAMETER, "dri2_lookup_egl_image"); |
| 389 | return NULL; |
| 390 | } |
| 391 | |
| 392 | dri2_img = dri2_egl_image(image); |
| 393 | |
| 394 | return dri2_img->dri_image; |
| 395 | } |
| 396 | |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 397 | static const __DRIimageLookupExtension image_lookup_extension = { |
| 398 | { __DRI_IMAGE_LOOKUP, 1 }, |
| 399 | dri2_lookup_egl_image |
| 400 | }; |
| 401 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 402 | static __DRIbuffer * |
| 403 | dri2_get_buffers_with_format(__DRIdrawable * driDrawable, |
| 404 | int *width, int *height, |
| 405 | unsigned int *attachments, int count, |
| 406 | int *out_count, void *loaderPrivate) |
| 407 | { |
| 408 | struct dri2_egl_surface *dri2_surf = loaderPrivate; |
| 409 | struct dri2_egl_display *dri2_dpy = |
| 410 | dri2_egl_display(dri2_surf->base.Resource.Display); |
| 411 | xcb_dri2_dri2_buffer_t *buffers; |
| 412 | xcb_dri2_get_buffers_with_format_reply_t *reply; |
| 413 | xcb_dri2_get_buffers_with_format_cookie_t cookie; |
| 414 | xcb_dri2_attach_format_t *format_attachments; |
| 415 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 416 | (void) driDrawable; |
| 417 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 418 | format_attachments = (xcb_dri2_attach_format_t *) attachments; |
| 419 | cookie = xcb_dri2_get_buffers_with_format_unchecked (dri2_dpy->conn, |
| 420 | dri2_surf->drawable, |
| 421 | count, count, |
| 422 | format_attachments); |
| 423 | |
| 424 | reply = xcb_dri2_get_buffers_with_format_reply (dri2_dpy->conn, |
| 425 | cookie, NULL); |
| 426 | if (reply == NULL) |
| 427 | return NULL; |
| 428 | |
| 429 | buffers = xcb_dri2_get_buffers_with_format_buffers (reply); |
| 430 | dri2_surf->base.Width = *width = reply->width; |
| 431 | dri2_surf->base.Height = *height = reply->height; |
| 432 | *out_count = reply->count; |
| 433 | dri2_process_buffers(dri2_surf, buffers, *out_count); |
| 434 | |
| 435 | free(reply); |
| 436 | |
| 437 | return dri2_surf->buffers; |
| 438 | } |
| 439 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 440 | static const char dri_driver_path[] = DEFAULT_DRIVER_DIR; |
| 441 | |
Kristian Høgsberg | 8c593d3 | 2010-02-09 10:57:43 -0500 | [diff] [blame] | 442 | struct dri2_extension_match { |
| 443 | const char *name; |
| 444 | int version; |
| 445 | int offset; |
| 446 | }; |
| 447 | |
| 448 | static struct dri2_extension_match dri2_driver_extensions[] = { |
| 449 | { __DRI_CORE, 1, offsetof(struct dri2_egl_display, core) }, |
| 450 | { __DRI_DRI2, 1, offsetof(struct dri2_egl_display, dri2) }, |
Ian Romanick | 137fce2 | 2010-09-23 09:40:58 -0700 | [diff] [blame] | 451 | { NULL, 0, 0 } |
Kristian Høgsberg | 8c593d3 | 2010-02-09 10:57:43 -0500 | [diff] [blame] | 452 | }; |
| 453 | |
| 454 | static struct dri2_extension_match dri2_core_extensions[] = { |
| 455 | { __DRI2_FLUSH, 1, offsetof(struct dri2_egl_display, flush) }, |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 456 | { __DRI_TEX_BUFFER, 2, offsetof(struct dri2_egl_display, tex_buffer) }, |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 457 | { __DRI_IMAGE, 1, offsetof(struct dri2_egl_display, image) }, |
Ian Romanick | 137fce2 | 2010-09-23 09:40:58 -0700 | [diff] [blame] | 458 | { NULL, 0, 0 } |
Kristian Høgsberg | 8c593d3 | 2010-02-09 10:57:43 -0500 | [diff] [blame] | 459 | }; |
| 460 | |
| 461 | static EGLBoolean |
| 462 | dri2_bind_extensions(struct dri2_egl_display *dri2_dpy, |
| 463 | struct dri2_extension_match *matches, |
| 464 | const __DRIextension **extensions) |
| 465 | { |
| 466 | int i, j, ret = EGL_TRUE; |
| 467 | void *field; |
| 468 | |
| 469 | for (i = 0; extensions[i]; i++) { |
| 470 | _eglLog(_EGL_DEBUG, "DRI2: found extension `%s'", extensions[i]->name); |
| 471 | for (j = 0; matches[j].name; j++) { |
| 472 | if (strcmp(extensions[i]->name, matches[j].name) == 0 && |
| 473 | extensions[i]->version >= matches[j].version) { |
| 474 | field = ((char *) dri2_dpy + matches[j].offset); |
| 475 | *(const __DRIextension **) field = extensions[i]; |
| 476 | _eglLog(_EGL_INFO, "DRI2: found extension %s version %d", |
| 477 | extensions[i]->name, extensions[i]->version); |
| 478 | } |
| 479 | } |
| 480 | } |
| 481 | |
| 482 | for (j = 0; matches[j].name; j++) { |
| 483 | field = ((char *) dri2_dpy + matches[j].offset); |
| 484 | if (*(const __DRIextension **) field == NULL) { |
| 485 | _eglLog(_EGL_FATAL, "DRI2: did not find extension %s version %d", |
| 486 | matches[j].name, matches[j].version); |
| 487 | ret = EGL_FALSE; |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | return ret; |
| 492 | } |
| 493 | |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 494 | static char * |
| 495 | dri2_strndup(const char *s, int length) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 496 | { |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 497 | char *d; |
| 498 | |
| 499 | d = malloc(length + 1); |
| 500 | if (d == NULL) |
| 501 | return NULL; |
| 502 | |
| 503 | memcpy(d, s, length); |
| 504 | d[length] = '\0'; |
| 505 | |
| 506 | return d; |
| 507 | } |
| 508 | |
| 509 | static EGLBoolean |
| 510 | dri2_connect(struct dri2_egl_display *dri2_dpy) |
| 511 | { |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 512 | xcb_xfixes_query_version_reply_t *xfixes_query; |
| 513 | xcb_xfixes_query_version_cookie_t xfixes_query_cookie; |
| 514 | xcb_dri2_query_version_reply_t *dri2_query; |
| 515 | xcb_dri2_query_version_cookie_t dri2_query_cookie; |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 516 | xcb_dri2_connect_reply_t *connect; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 517 | xcb_dri2_connect_cookie_t connect_cookie; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 518 | xcb_generic_error_t *error; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 519 | xcb_screen_iterator_t s; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 520 | |
| 521 | xcb_prefetch_extension_data (dri2_dpy->conn, &xcb_xfixes_id); |
| 522 | xcb_prefetch_extension_data (dri2_dpy->conn, &xcb_dri2_id); |
| 523 | |
| 524 | xfixes_query_cookie = xcb_xfixes_query_version(dri2_dpy->conn, |
| 525 | XCB_XFIXES_MAJOR_VERSION, |
| 526 | XCB_XFIXES_MINOR_VERSION); |
| 527 | |
| 528 | dri2_query_cookie = xcb_dri2_query_version (dri2_dpy->conn, |
| 529 | XCB_DRI2_MAJOR_VERSION, |
| 530 | XCB_DRI2_MINOR_VERSION); |
| 531 | |
| 532 | s = xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy->conn)); |
| 533 | connect_cookie = xcb_dri2_connect_unchecked (dri2_dpy->conn, |
| 534 | s.data->root, |
| 535 | XCB_DRI2_DRIVER_TYPE_DRI); |
| 536 | |
| 537 | xfixes_query = |
| 538 | xcb_xfixes_query_version_reply (dri2_dpy->conn, |
| 539 | xfixes_query_cookie, &error); |
| 540 | if (xfixes_query == NULL || |
| 541 | error != NULL || xfixes_query->major_version < 2) { |
| 542 | _eglLog(_EGL_FATAL, "DRI2: failed to query xfixes version"); |
| 543 | free(error); |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 544 | return EGL_FALSE; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 545 | } |
| 546 | free(xfixes_query); |
| 547 | |
| 548 | dri2_query = |
| 549 | xcb_dri2_query_version_reply (dri2_dpy->conn, dri2_query_cookie, &error); |
| 550 | if (dri2_query == NULL || error != NULL) { |
| 551 | _eglLog(_EGL_FATAL, "DRI2: failed to query version"); |
| 552 | free(error); |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 553 | return EGL_FALSE; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 554 | } |
| 555 | dri2_dpy->dri2_major = dri2_query->major_version; |
| 556 | dri2_dpy->dri2_minor = dri2_query->minor_version; |
| 557 | free(dri2_query); |
| 558 | |
| 559 | connect = xcb_dri2_connect_reply (dri2_dpy->conn, connect_cookie, NULL); |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 560 | if (connect == NULL || |
| 561 | connect->driver_name_length + connect->device_name_length == 0) { |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 562 | _eglLog(_EGL_FATAL, "DRI2: failed to authenticate"); |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 563 | return EGL_FALSE; |
| 564 | } |
| 565 | |
| 566 | dri2_dpy->device_name = |
| 567 | dri2_strndup(xcb_dri2_connect_device_name (connect), |
| 568 | xcb_dri2_connect_device_name_length (connect)); |
| 569 | |
| 570 | dri2_dpy->driver_name = |
| 571 | dri2_strndup(xcb_dri2_connect_driver_name (connect), |
| 572 | xcb_dri2_connect_driver_name_length (connect)); |
| 573 | |
| 574 | if (dri2_dpy->device_name == NULL || dri2_dpy->driver_name == NULL) { |
| 575 | free(dri2_dpy->device_name); |
| 576 | free(dri2_dpy->driver_name); |
| 577 | free(connect); |
| 578 | return EGL_FALSE; |
| 579 | } |
| 580 | free(connect); |
| 581 | |
| 582 | return EGL_TRUE; |
| 583 | } |
| 584 | |
| 585 | static EGLBoolean |
| 586 | dri2_authenticate(struct dri2_egl_display *dri2_dpy) |
| 587 | { |
| 588 | xcb_dri2_authenticate_reply_t *authenticate; |
| 589 | xcb_dri2_authenticate_cookie_t authenticate_cookie; |
| 590 | xcb_screen_iterator_t s; |
| 591 | drm_magic_t magic; |
| 592 | |
| 593 | if (drmGetMagic(dri2_dpy->fd, &magic)) { |
| 594 | _eglLog(_EGL_FATAL, "DRI2: failed to get drm magic"); |
| 595 | return EGL_FALSE; |
| 596 | } |
| 597 | |
| 598 | s = xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy->conn)); |
| 599 | authenticate_cookie = |
| 600 | xcb_dri2_authenticate_unchecked(dri2_dpy->conn, s.data->root, magic); |
| 601 | authenticate = |
| 602 | xcb_dri2_authenticate_reply(dri2_dpy->conn, authenticate_cookie, NULL); |
| 603 | if (authenticate == NULL || !authenticate->authenticated) { |
| 604 | _eglLog(_EGL_FATAL, "DRI2: failed to authenticate"); |
| 605 | free(authenticate); |
| 606 | return EGL_FALSE; |
| 607 | } |
| 608 | |
| 609 | free(authenticate); |
| 610 | |
| 611 | return EGL_TRUE; |
| 612 | } |
| 613 | |
| 614 | static EGLBoolean |
| 615 | dri2_add_configs_for_visuals(struct dri2_egl_display *dri2_dpy, |
| 616 | _EGLDisplay *disp) |
| 617 | { |
| 618 | xcb_screen_iterator_t s; |
| 619 | xcb_depth_iterator_t d; |
| 620 | xcb_visualtype_t *visuals; |
| 621 | int i, j, id; |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 622 | struct dri2_egl_config *conf; |
| 623 | EGLint surface_type; |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 624 | |
| 625 | s = xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy->conn)); |
| 626 | d = xcb_screen_allowed_depths_iterator(s.data); |
| 627 | id = 1; |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 628 | |
| 629 | surface_type = |
| 630 | EGL_WINDOW_BIT | |
| 631 | EGL_PIXMAP_BIT | |
| 632 | EGL_PBUFFER_BIT | |
| 633 | EGL_SWAP_BEHAVIOR_PRESERVED_BIT; |
| 634 | |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 635 | while (d.rem > 0) { |
| 636 | EGLBoolean class_added[6] = { 0, }; |
| 637 | |
| 638 | visuals = xcb_depth_visuals(d.data); |
| 639 | for (i = 0; i < xcb_depth_visuals_length(d.data); i++) { |
| 640 | if (class_added[visuals[i]._class]) |
| 641 | continue; |
| 642 | |
| 643 | class_added[visuals[i]._class] = EGL_TRUE; |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 644 | for (j = 0; dri2_dpy->driver_configs[j]; j++) { |
| 645 | conf = dri2_add_config(disp, dri2_dpy->driver_configs[j], |
| 646 | id++, d.data->depth, surface_type); |
| 647 | if (conf == NULL) |
| 648 | continue; |
| 649 | _eglSetConfigKey(&conf->base, |
| 650 | EGL_NATIVE_VISUAL_ID, visuals[i].visual_id); |
| 651 | _eglSetConfigKey(&conf->base, |
| 652 | EGL_NATIVE_VISUAL_TYPE, visuals[i]._class); |
| 653 | } |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | xcb_depth_next(&d); |
| 657 | } |
| 658 | |
Chia-I Wu | 6717a31 | 2010-06-30 17:10:10 +0800 | [diff] [blame] | 659 | if (!_eglGetArraySize(disp->Configs)) { |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 660 | _eglLog(_EGL_WARNING, "DRI2: failed to create any config"); |
| 661 | return EGL_FALSE; |
| 662 | } |
| 663 | |
| 664 | return EGL_TRUE; |
| 665 | } |
| 666 | |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 667 | static EGLBoolean |
Kristian Høgsberg | 0defc25 | 2010-05-28 16:16:12 -0400 | [diff] [blame] | 668 | dri2_load_driver(_EGLDisplay *disp) |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 669 | { |
Kristian Høgsberg | 0defc25 | 2010-05-28 16:16:12 -0400 | [diff] [blame] | 670 | struct dri2_egl_display *dri2_dpy = disp->DriverData; |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 671 | const __DRIextension **extensions; |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 672 | char path[PATH_MAX], *search_paths, *p, *next, *end; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 673 | |
| 674 | search_paths = NULL; |
| 675 | if (geteuid() == getuid()) { |
| 676 | /* don't allow setuid apps to use LIBGL_DRIVERS_PATH */ |
| 677 | search_paths = getenv("LIBGL_DRIVERS_PATH"); |
| 678 | } |
| 679 | if (search_paths == NULL) |
| 680 | search_paths = DEFAULT_DRIVER_DIR; |
| 681 | |
| 682 | dri2_dpy->driver = NULL; |
| 683 | end = search_paths + strlen(search_paths); |
| 684 | for (p = search_paths; p < end && dri2_dpy->driver == NULL; p = next + 1) { |
Eric Anholt | 6f77b75 | 2010-05-20 14:44:43 -0700 | [diff] [blame] | 685 | int len; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 686 | next = strchr(p, ':'); |
| 687 | if (next == NULL) |
| 688 | next = end; |
| 689 | |
Eric Anholt | 6f77b75 | 2010-05-20 14:44:43 -0700 | [diff] [blame] | 690 | len = next - p; |
| 691 | #if GLX_USE_TLS |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 692 | snprintf(path, sizeof path, |
Eric Anholt | 6f77b75 | 2010-05-20 14:44:43 -0700 | [diff] [blame] | 693 | "%.*s/tls/%s_dri.so", len, p, dri2_dpy->driver_name); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 694 | dri2_dpy->driver = dlopen(path, RTLD_NOW | RTLD_GLOBAL); |
Eric Anholt | 6f77b75 | 2010-05-20 14:44:43 -0700 | [diff] [blame] | 695 | #endif |
| 696 | if (dri2_dpy->driver == NULL) { |
| 697 | snprintf(path, sizeof path, |
| 698 | "%.*s/%s_dri.so", len, p, dri2_dpy->driver_name); |
| 699 | dri2_dpy->driver = dlopen(path, RTLD_NOW | RTLD_GLOBAL); |
| 700 | if (dri2_dpy->driver == NULL) |
| 701 | _eglLog(_EGL_DEBUG, "failed to open %s: %s\n", path, dlerror()); |
| 702 | } |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | if (dri2_dpy->driver == NULL) { |
Kristian Høgsberg | 7413d9a | 2010-05-13 15:42:51 -0400 | [diff] [blame] | 706 | _eglLog(_EGL_WARNING, |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 707 | "DRI2: failed to open any driver (search paths %s)", |
| 708 | search_paths); |
Kristian Høgsberg | 0defc25 | 2010-05-28 16:16:12 -0400 | [diff] [blame] | 709 | return EGL_FALSE; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | _eglLog(_EGL_DEBUG, "DRI2: dlopen(%s)", path); |
| 713 | extensions = dlsym(dri2_dpy->driver, __DRI_DRIVER_EXTENSIONS); |
| 714 | if (extensions == NULL) { |
Kristian Høgsberg | 7413d9a | 2010-05-13 15:42:51 -0400 | [diff] [blame] | 715 | _eglLog(_EGL_WARNING, |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 716 | "DRI2: driver exports no extensions (%s)", dlerror()); |
Kristian Høgsberg | 0defc25 | 2010-05-28 16:16:12 -0400 | [diff] [blame] | 717 | dlclose(dri2_dpy->driver); |
| 718 | return EGL_FALSE; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 719 | } |
| 720 | |
Kristian Høgsberg | 0defc25 | 2010-05-28 16:16:12 -0400 | [diff] [blame] | 721 | if (!dri2_bind_extensions(dri2_dpy, dri2_driver_extensions, extensions)) { |
| 722 | dlclose(dri2_dpy->driver); |
| 723 | return EGL_FALSE; |
| 724 | } |
| 725 | |
| 726 | return EGL_TRUE; |
| 727 | } |
| 728 | |
Kristian Høgsberg | 0defc25 | 2010-05-28 16:16:12 -0400 | [diff] [blame] | 729 | static EGLBoolean |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 730 | dri2_create_screen(_EGLDisplay *disp) |
Kristian Høgsberg | 0defc25 | 2010-05-28 16:16:12 -0400 | [diff] [blame] | 731 | { |
| 732 | const __DRIextension **extensions; |
| 733 | struct dri2_egl_display *dri2_dpy; |
| 734 | unsigned int api_mask; |
| 735 | |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 736 | dri2_dpy = disp->DriverData; |
| 737 | dri2_dpy->dri_screen = |
| 738 | dri2_dpy->dri2->createNewScreen(0, dri2_dpy->fd, dri2_dpy->extensions, |
Kristian Høgsberg | 17eace5 | 2010-09-22 22:01:17 -0400 | [diff] [blame] | 739 | &dri2_dpy->driver_configs, disp); |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 740 | |
| 741 | if (dri2_dpy->dri_screen == NULL) { |
| 742 | _eglLog(_EGL_WARNING, "DRI2: failed to create dri screen"); |
Chia-I Wu | f22665d | 2010-06-17 17:14:03 +0800 | [diff] [blame] | 743 | return EGL_FALSE; |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | extensions = dri2_dpy->core->getExtensions(dri2_dpy->dri_screen); |
| 747 | if (!dri2_bind_extensions(dri2_dpy, dri2_core_extensions, extensions)) |
| 748 | goto cleanup_dri_screen; |
| 749 | |
| 750 | if (dri2_dpy->dri2->base.version >= 2) |
| 751 | api_mask = dri2_dpy->dri2->getAPIMask(dri2_dpy->dri_screen); |
| 752 | else |
Chia-I Wu | aa139a1 | 2010-11-10 23:54:45 +0800 | [diff] [blame] | 753 | api_mask = 1 << __DRI_API_OPENGL; |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 754 | |
| 755 | disp->ClientAPIsMask = 0; |
| 756 | if (api_mask & (1 <<__DRI_API_OPENGL)) |
| 757 | disp->ClientAPIsMask |= EGL_OPENGL_BIT; |
| 758 | if (api_mask & (1 <<__DRI_API_GLES)) |
| 759 | disp->ClientAPIsMask |= EGL_OPENGL_ES_BIT; |
| 760 | if (api_mask & (1 << __DRI_API_GLES2)) |
| 761 | disp->ClientAPIsMask |= EGL_OPENGL_ES2_BIT; |
| 762 | |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 763 | if (dri2_dpy->dri2->base.version >= 2) { |
| 764 | disp->Extensions.KHR_surfaceless_gles1 = EGL_TRUE; |
| 765 | disp->Extensions.KHR_surfaceless_gles2 = EGL_TRUE; |
| 766 | disp->Extensions.KHR_surfaceless_opengl = EGL_TRUE; |
| 767 | } |
| 768 | |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 769 | return EGL_TRUE; |
| 770 | |
| 771 | cleanup_dri_screen: |
| 772 | dri2_dpy->core->destroyScreen(dri2_dpy->dri_screen); |
| 773 | |
| 774 | return EGL_FALSE; |
| 775 | } |
| 776 | |
| 777 | static EGLBoolean |
| 778 | dri2_initialize_x11(_EGLDriver *drv, _EGLDisplay *disp, |
| 779 | EGLint *major, EGLint *minor) |
| 780 | { |
| 781 | struct dri2_egl_display *dri2_dpy; |
Chia-I Wu | f22665d | 2010-06-17 17:14:03 +0800 | [diff] [blame] | 782 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 783 | (void) drv; |
| 784 | |
Kristian Høgsberg | 0defc25 | 2010-05-28 16:16:12 -0400 | [diff] [blame] | 785 | dri2_dpy = malloc(sizeof *dri2_dpy); |
| 786 | if (!dri2_dpy) |
| 787 | return _eglError(EGL_BAD_ALLOC, "eglInitialize"); |
| 788 | |
| 789 | disp->DriverData = (void *) dri2_dpy; |
Chia-I Wu | f22665d | 2010-06-17 17:14:03 +0800 | [diff] [blame] | 790 | if (disp->PlatformDisplay == NULL) { |
Kristian Høgsberg | 0defc25 | 2010-05-28 16:16:12 -0400 | [diff] [blame] | 791 | dri2_dpy->conn = xcb_connect(0, 0); |
| 792 | } else { |
Chia-I Wu | f22665d | 2010-06-17 17:14:03 +0800 | [diff] [blame] | 793 | dri2_dpy->conn = XGetXCBConnection((Display *) disp->PlatformDisplay); |
Kristian Høgsberg | 0defc25 | 2010-05-28 16:16:12 -0400 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | if (xcb_connection_has_error(dri2_dpy->conn)) { |
| 797 | _eglLog(_EGL_WARNING, "DRI2: xcb_connect failed"); |
| 798 | goto cleanup_dpy; |
| 799 | } |
| 800 | |
| 801 | if (dri2_dpy->conn) { |
| 802 | if (!dri2_connect(dri2_dpy)) |
| 803 | goto cleanup_conn; |
| 804 | } |
| 805 | |
| 806 | if (!dri2_load_driver(disp)) |
| 807 | goto cleanup_conn; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 808 | |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 809 | dri2_dpy->fd = open(dri2_dpy->device_name, O_RDWR); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 810 | if (dri2_dpy->fd == -1) { |
Kristian Høgsberg | 7413d9a | 2010-05-13 15:42:51 -0400 | [diff] [blame] | 811 | _eglLog(_EGL_WARNING, |
Micah Fedke | 9cfaaa2 | 2010-04-28 07:25:58 -0600 | [diff] [blame] | 812 | "DRI2: could not open %s (%s)", dri2_dpy->device_name, |
| 813 | strerror(errno)); |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 814 | goto cleanup_driver; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 815 | } |
| 816 | |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 817 | if (dri2_dpy->conn) { |
| 818 | if (!dri2_authenticate(dri2_dpy)) |
| 819 | goto cleanup_fd; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 820 | } |
| 821 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 822 | if (dri2_dpy->dri2_minor >= 1) { |
| 823 | dri2_dpy->loader_extension.base.name = __DRI_DRI2_LOADER; |
| 824 | dri2_dpy->loader_extension.base.version = 3; |
| 825 | dri2_dpy->loader_extension.getBuffers = dri2_get_buffers; |
| 826 | dri2_dpy->loader_extension.flushFrontBuffer = dri2_flush_front_buffer; |
| 827 | dri2_dpy->loader_extension.getBuffersWithFormat = |
| 828 | dri2_get_buffers_with_format; |
| 829 | } else { |
| 830 | dri2_dpy->loader_extension.base.name = __DRI_DRI2_LOADER; |
| 831 | dri2_dpy->loader_extension.base.version = 2; |
| 832 | dri2_dpy->loader_extension.getBuffers = dri2_get_buffers; |
| 833 | dri2_dpy->loader_extension.flushFrontBuffer = dri2_flush_front_buffer; |
| 834 | dri2_dpy->loader_extension.getBuffersWithFormat = NULL; |
| 835 | } |
| 836 | |
| 837 | dri2_dpy->extensions[0] = &dri2_dpy->loader_extension.base; |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 838 | dri2_dpy->extensions[1] = &image_lookup_extension.base; |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 839 | dri2_dpy->extensions[2] = NULL; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 840 | |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 841 | if (!dri2_create_screen(disp)) |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 842 | goto cleanup_fd; |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 843 | |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 844 | if (dri2_dpy->conn) { |
| 845 | if (!dri2_add_configs_for_visuals(dri2_dpy, disp)) |
| 846 | goto cleanup_configs; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 847 | } |
| 848 | |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 849 | disp->Extensions.MESA_drm_image = EGL_TRUE; |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 850 | disp->Extensions.KHR_image_base = EGL_TRUE; |
| 851 | disp->Extensions.KHR_image_pixmap = EGL_TRUE; |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 852 | disp->Extensions.KHR_gl_renderbuffer_image = EGL_TRUE; |
Kristian Høgsberg | 3a82c8c | 2010-04-14 16:22:27 -0400 | [diff] [blame] | 853 | disp->Extensions.KHR_gl_texture_2D_image = EGL_TRUE; |
Kristian Høgsberg | 52c554a | 2010-05-06 22:01:35 -0400 | [diff] [blame] | 854 | disp->Extensions.NOK_swap_region = EGL_TRUE; |
Kristian Høgsberg | 5dc0f49 | 2010-05-06 22:40:25 -0400 | [diff] [blame] | 855 | disp->Extensions.NOK_texture_from_pixmap = EGL_TRUE; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 856 | |
| 857 | /* we're supporting EGL 1.4 */ |
| 858 | *major = 1; |
| 859 | *minor = 4; |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 860 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 861 | return EGL_TRUE; |
| 862 | |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 863 | cleanup_configs: |
| 864 | _eglCleanupDisplay(disp); |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 865 | dri2_dpy->core->destroyScreen(dri2_dpy->dri_screen); |
| 866 | cleanup_fd: |
| 867 | close(dri2_dpy->fd); |
| 868 | cleanup_driver: |
| 869 | dlclose(dri2_dpy->driver); |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 870 | cleanup_conn: |
Chia-I Wu | f22665d | 2010-06-17 17:14:03 +0800 | [diff] [blame] | 871 | if (disp->PlatformDisplay == NULL) |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 872 | xcb_disconnect(dri2_dpy->conn); |
| 873 | cleanup_dpy: |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 874 | free(dri2_dpy); |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 875 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 876 | return EGL_FALSE; |
| 877 | } |
| 878 | |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 879 | #ifdef HAVE_LIBUDEV |
| 880 | |
| 881 | struct dri2_driver_map { |
| 882 | int vendor_id; |
| 883 | const char *driver; |
| 884 | const int *chip_ids; |
| 885 | int num_chips_ids; |
| 886 | }; |
| 887 | |
| 888 | const int i915_chip_ids[] = { |
| 889 | 0x3577, /* PCI_CHIP_I830_M */ |
| 890 | 0x2562, /* PCI_CHIP_845_G */ |
| 891 | 0x3582, /* PCI_CHIP_I855_GM */ |
| 892 | 0x2572, /* PCI_CHIP_I865_G */ |
| 893 | 0x2582, /* PCI_CHIP_I915_G */ |
| 894 | 0x258a, /* PCI_CHIP_E7221_G */ |
| 895 | 0x2592, /* PCI_CHIP_I915_GM */ |
| 896 | 0x2772, /* PCI_CHIP_I945_G */ |
| 897 | 0x27a2, /* PCI_CHIP_I945_GM */ |
| 898 | 0x27ae, /* PCI_CHIP_I945_GME */ |
| 899 | 0x29b2, /* PCI_CHIP_Q35_G */ |
| 900 | 0x29c2, /* PCI_CHIP_G33_G */ |
| 901 | 0x29d2, /* PCI_CHIP_Q33_G */ |
Robert Hooker | 7789170 | 2010-11-16 15:10:20 -0500 | [diff] [blame] | 902 | 0xa001, /* PCI_CHIP_IGD_G */ |
Jesse Barnes | e7eff0c | 2010-09-13 10:55:16 -0700 | [diff] [blame] | 903 | 0xa011, /* Pineview */ |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 904 | }; |
| 905 | |
| 906 | const int i965_chip_ids[] = { |
Robert Hooker | 7789170 | 2010-11-16 15:10:20 -0500 | [diff] [blame] | 907 | 0x0042, /* PCI_CHIP_ILD_G */ |
| 908 | 0x0046, /* PCI_CHIP_ILM_G */ |
| 909 | 0x0102, /* PCI_CHIP_SANDYBRIDGE_GT1 */ |
| 910 | 0x0106, /* PCI_CHIP_SANDYBRIDGE_M_GT1 */ |
| 911 | 0x010a, /* PCI_CHIP_SANDYBRIDGE_S */ |
| 912 | 0x0112, /* PCI_CHIP_SANDYBRIDGE_GT2 */ |
| 913 | 0x0116, /* PCI_CHIP_SANDYBRIDGE_M_GT2 */ |
| 914 | 0x0122, /* PCI_CHIP_SANDYBRIDGE_GT2_PLUS */ |
| 915 | 0x0126, /* PCI_CHIP_SANDYBRIDGE_M_GT2_PLUS */ |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 916 | 0x29a2, /* PCI_CHIP_I965_G */ |
| 917 | 0x2992, /* PCI_CHIP_I965_Q */ |
| 918 | 0x2982, /* PCI_CHIP_I965_G_1 */ |
| 919 | 0x2972, /* PCI_CHIP_I946_GZ */ |
| 920 | 0x2a02, /* PCI_CHIP_I965_GM */ |
| 921 | 0x2a12, /* PCI_CHIP_I965_GME */ |
| 922 | 0x2a42, /* PCI_CHIP_GM45_GM */ |
| 923 | 0x2e02, /* PCI_CHIP_IGD_E_G */ |
| 924 | 0x2e12, /* PCI_CHIP_Q45_G */ |
| 925 | 0x2e22, /* PCI_CHIP_G45_G */ |
| 926 | 0x2e32, /* PCI_CHIP_G41_G */ |
Robert Hooker | 7789170 | 2010-11-16 15:10:20 -0500 | [diff] [blame] | 927 | 0x2e42, /* PCI_CHIP_B43_G */ |
| 928 | 0x2e92, /* PCI_CHIP_B43_G1 */ |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 929 | }; |
| 930 | |
Alex Deucher | 4990b77 | 2010-11-08 14:25:38 -0500 | [diff] [blame] | 931 | const int r100_chip_ids[] = { |
| 932 | 0x4C57, /* PCI_CHIP_RADEON_LW */ |
| 933 | 0x4C58, /* PCI_CHIP_RADEON_LX */ |
| 934 | 0x4C59, /* PCI_CHIP_RADEON_LY */ |
| 935 | 0x4C5A, /* PCI_CHIP_RADEON_LZ */ |
| 936 | 0x5144, /* PCI_CHIP_RADEON_QD */ |
| 937 | 0x5145, /* PCI_CHIP_RADEON_QE */ |
| 938 | 0x5146, /* PCI_CHIP_RADEON_QF */ |
| 939 | 0x5147, /* PCI_CHIP_RADEON_QG */ |
| 940 | 0x5159, /* PCI_CHIP_RADEON_QY */ |
| 941 | 0x515A, /* PCI_CHIP_RADEON_QZ */ |
| 942 | 0x5157, /* PCI_CHIP_RV200_QW */ |
| 943 | 0x5158, /* PCI_CHIP_RV200_QX */ |
| 944 | 0x515E, /* PCI_CHIP_RN50_515E */ |
| 945 | 0x5969, /* PCI_CHIP_RN50_5969 */ |
| 946 | 0x4136, /* PCI_CHIP_RS100_4136 */ |
| 947 | 0x4336, /* PCI_CHIP_RS100_4336 */ |
| 948 | 0x4137, /* PCI_CHIP_RS200_4137 */ |
| 949 | 0x4337, /* PCI_CHIP_RS200_4337 */ |
| 950 | 0x4237, /* PCI_CHIP_RS250_4237 */ |
| 951 | 0x4437, /* PCI_CHIP_RS250_4437 */ |
| 952 | }; |
| 953 | |
| 954 | const int r200_chip_ids[] = { |
| 955 | 0x5148, /* PCI_CHIP_R200_QH */ |
| 956 | 0x514C, /* PCI_CHIP_R200_QL */ |
| 957 | 0x514D, /* PCI_CHIP_R200_QM */ |
| 958 | 0x4242, /* PCI_CHIP_R200_BB */ |
| 959 | 0x4243, /* PCI_CHIP_R200_BC */ |
| 960 | 0x4966, /* PCI_CHIP_RV250_If */ |
| 961 | 0x4967, /* PCI_CHIP_RV250_Ig */ |
| 962 | 0x4C64, /* PCI_CHIP_RV250_Ld */ |
| 963 | 0x4C66, /* PCI_CHIP_RV250_Lf */ |
| 964 | 0x4C67, /* PCI_CHIP_RV250_Lg */ |
| 965 | 0x5960, /* PCI_CHIP_RV280_5960 */ |
| 966 | 0x5961, /* PCI_CHIP_RV280_5961 */ |
| 967 | 0x5962, /* PCI_CHIP_RV280_5962 */ |
| 968 | 0x5964, /* PCI_CHIP_RV280_5964 */ |
| 969 | 0x5965, /* PCI_CHIP_RV280_5965 */ |
| 970 | 0x5C61, /* PCI_CHIP_RV280_5C61 */ |
| 971 | 0x5C63, /* PCI_CHIP_RV280_5C63 */ |
| 972 | 0x5834, /* PCI_CHIP_RS300_5834 */ |
| 973 | 0x5835, /* PCI_CHIP_RS300_5835 */ |
| 974 | 0x7834, /* PCI_CHIP_RS350_7834 */ |
| 975 | 0x7835, /* PCI_CHIP_RS350_7835 */ |
| 976 | }; |
| 977 | |
| 978 | const int r300_chip_ids[] = { |
| 979 | 0x4144, /* PCI_CHIP_R300_AD */ |
| 980 | 0x4145, /* PCI_CHIP_R300_AE */ |
| 981 | 0x4146, /* PCI_CHIP_R300_AF */ |
| 982 | 0x4147, /* PCI_CHIP_R300_AG */ |
| 983 | 0x4E44, /* PCI_CHIP_R300_ND */ |
| 984 | 0x4E45, /* PCI_CHIP_R300_NE */ |
| 985 | 0x4E46, /* PCI_CHIP_R300_NF */ |
| 986 | 0x4E47, /* PCI_CHIP_R300_NG */ |
| 987 | 0x4E48, /* PCI_CHIP_R350_NH */ |
| 988 | 0x4E49, /* PCI_CHIP_R350_NI */ |
| 989 | 0x4E4B, /* PCI_CHIP_R350_NK */ |
| 990 | 0x4148, /* PCI_CHIP_R350_AH */ |
| 991 | 0x4149, /* PCI_CHIP_R350_AI */ |
| 992 | 0x414A, /* PCI_CHIP_R350_AJ */ |
| 993 | 0x414B, /* PCI_CHIP_R350_AK */ |
| 994 | 0x4E4A, /* PCI_CHIP_R360_NJ */ |
| 995 | 0x4150, /* PCI_CHIP_RV350_AP */ |
| 996 | 0x4151, /* PCI_CHIP_RV350_AQ */ |
| 997 | 0x4152, /* PCI_CHIP_RV350_AR */ |
| 998 | 0x4153, /* PCI_CHIP_RV350_AS */ |
| 999 | 0x4154, /* PCI_CHIP_RV350_AT */ |
| 1000 | 0x4155, /* PCI_CHIP_RV350_AU */ |
| 1001 | 0x4156, /* PCI_CHIP_RV350_AV */ |
| 1002 | 0x4E50, /* PCI_CHIP_RV350_NP */ |
| 1003 | 0x4E51, /* PCI_CHIP_RV350_NQ */ |
| 1004 | 0x4E52, /* PCI_CHIP_RV350_NR */ |
| 1005 | 0x4E53, /* PCI_CHIP_RV350_NS */ |
| 1006 | 0x4E54, /* PCI_CHIP_RV350_NT */ |
| 1007 | 0x4E56, /* PCI_CHIP_RV350_NV */ |
| 1008 | 0x5460, /* PCI_CHIP_RV370_5460 */ |
| 1009 | 0x5462, /* PCI_CHIP_RV370_5462 */ |
| 1010 | 0x5464, /* PCI_CHIP_RV370_5464 */ |
| 1011 | 0x5B60, /* PCI_CHIP_RV370_5B60 */ |
| 1012 | 0x5B62, /* PCI_CHIP_RV370_5B62 */ |
| 1013 | 0x5B63, /* PCI_CHIP_RV370_5B63 */ |
| 1014 | 0x5B64, /* PCI_CHIP_RV370_5B64 */ |
| 1015 | 0x5B65, /* PCI_CHIP_RV370_5B65 */ |
| 1016 | 0x3150, /* PCI_CHIP_RV380_3150 */ |
| 1017 | 0x3152, /* PCI_CHIP_RV380_3152 */ |
| 1018 | 0x3154, /* PCI_CHIP_RV380_3154 */ |
| 1019 | 0x3155, /* PCI_CHIP_RV380_3155 */ |
| 1020 | 0x3E50, /* PCI_CHIP_RV380_3E50 */ |
| 1021 | 0x3E54, /* PCI_CHIP_RV380_3E54 */ |
| 1022 | 0x4A48, /* PCI_CHIP_R420_JH */ |
| 1023 | 0x4A49, /* PCI_CHIP_R420_JI */ |
| 1024 | 0x4A4A, /* PCI_CHIP_R420_JJ */ |
| 1025 | 0x4A4B, /* PCI_CHIP_R420_JK */ |
| 1026 | 0x4A4C, /* PCI_CHIP_R420_JL */ |
| 1027 | 0x4A4D, /* PCI_CHIP_R420_JM */ |
| 1028 | 0x4A4E, /* PCI_CHIP_R420_JN */ |
| 1029 | 0x4A4F, /* PCI_CHIP_R420_JO */ |
| 1030 | 0x4A50, /* PCI_CHIP_R420_JP */ |
| 1031 | 0x4A54, /* PCI_CHIP_R420_JT */ |
| 1032 | 0x5548, /* PCI_CHIP_R423_UH */ |
| 1033 | 0x5549, /* PCI_CHIP_R423_UI */ |
| 1034 | 0x554A, /* PCI_CHIP_R423_UJ */ |
| 1035 | 0x554B, /* PCI_CHIP_R423_UK */ |
| 1036 | 0x5550, /* PCI_CHIP_R423_5550 */ |
| 1037 | 0x5551, /* PCI_CHIP_R423_UQ */ |
| 1038 | 0x5552, /* PCI_CHIP_R423_UR */ |
| 1039 | 0x5554, /* PCI_CHIP_R423_UT */ |
| 1040 | 0x5D57, /* PCI_CHIP_R423_5D57 */ |
| 1041 | 0x554C, /* PCI_CHIP_R430_554C */ |
| 1042 | 0x554D, /* PCI_CHIP_R430_554D */ |
| 1043 | 0x554E, /* PCI_CHIP_R430_554E */ |
| 1044 | 0x554F, /* PCI_CHIP_R430_554F */ |
| 1045 | 0x5D48, /* PCI_CHIP_R430_5D48 */ |
| 1046 | 0x5D49, /* PCI_CHIP_R430_5D49 */ |
| 1047 | 0x5D4A, /* PCI_CHIP_R430_5D4A */ |
| 1048 | 0x5D4C, /* PCI_CHIP_R480_5D4C */ |
| 1049 | 0x5D4D, /* PCI_CHIP_R480_5D4D */ |
| 1050 | 0x5D4E, /* PCI_CHIP_R480_5D4E */ |
| 1051 | 0x5D4F, /* PCI_CHIP_R480_5D4F */ |
| 1052 | 0x5D50, /* PCI_CHIP_R480_5D50 */ |
| 1053 | 0x5D52, /* PCI_CHIP_R480_5D52 */ |
| 1054 | 0x4B49, /* PCI_CHIP_R481_4B49 */ |
| 1055 | 0x4B4A, /* PCI_CHIP_R481_4B4A */ |
| 1056 | 0x4B4B, /* PCI_CHIP_R481_4B4B */ |
| 1057 | 0x4B4C, /* PCI_CHIP_R481_4B4C */ |
| 1058 | 0x564A, /* PCI_CHIP_RV410_564A */ |
| 1059 | 0x564B, /* PCI_CHIP_RV410_564B */ |
| 1060 | 0x564F, /* PCI_CHIP_RV410_564F */ |
| 1061 | 0x5652, /* PCI_CHIP_RV410_5652 */ |
| 1062 | 0x5653, /* PCI_CHIP_RV410_5653 */ |
| 1063 | 0x5657, /* PCI_CHIP_RV410_5657 */ |
| 1064 | 0x5E48, /* PCI_CHIP_RV410_5E48 */ |
| 1065 | 0x5E4A, /* PCI_CHIP_RV410_5E4A */ |
| 1066 | 0x5E4B, /* PCI_CHIP_RV410_5E4B */ |
| 1067 | 0x5E4C, /* PCI_CHIP_RV410_5E4C */ |
| 1068 | 0x5E4D, /* PCI_CHIP_RV410_5E4D */ |
| 1069 | 0x5E4F, /* PCI_CHIP_RV410_5E4F */ |
| 1070 | 0x5A41, /* PCI_CHIP_RS400_5A41 */ |
| 1071 | 0x5A42, /* PCI_CHIP_RS400_5A42 */ |
| 1072 | 0x5A61, /* PCI_CHIP_RC410_5A61 */ |
| 1073 | 0x5A62, /* PCI_CHIP_RC410_5A62 */ |
| 1074 | 0x5954, /* PCI_CHIP_RS480_5954 */ |
| 1075 | 0x5955, /* PCI_CHIP_RS480_5955 */ |
| 1076 | 0x5974, /* PCI_CHIP_RS482_5974 */ |
| 1077 | 0x5975, /* PCI_CHIP_RS482_5975 */ |
| 1078 | 0x7100, /* PCI_CHIP_R520_7100 */ |
| 1079 | 0x7101, /* PCI_CHIP_R520_7101 */ |
| 1080 | 0x7102, /* PCI_CHIP_R520_7102 */ |
| 1081 | 0x7103, /* PCI_CHIP_R520_7103 */ |
| 1082 | 0x7104, /* PCI_CHIP_R520_7104 */ |
| 1083 | 0x7105, /* PCI_CHIP_R520_7105 */ |
| 1084 | 0x7106, /* PCI_CHIP_R520_7106 */ |
| 1085 | 0x7108, /* PCI_CHIP_R520_7108 */ |
| 1086 | 0x7109, /* PCI_CHIP_R520_7109 */ |
| 1087 | 0x710A, /* PCI_CHIP_R520_710A */ |
| 1088 | 0x710B, /* PCI_CHIP_R520_710B */ |
| 1089 | 0x710C, /* PCI_CHIP_R520_710C */ |
| 1090 | 0x710E, /* PCI_CHIP_R520_710E */ |
| 1091 | 0x710F, /* PCI_CHIP_R520_710F */ |
| 1092 | 0x7140, /* PCI_CHIP_RV515_7140 */ |
| 1093 | 0x7141, /* PCI_CHIP_RV515_7141 */ |
| 1094 | 0x7142, /* PCI_CHIP_RV515_7142 */ |
| 1095 | 0x7143, /* PCI_CHIP_RV515_7143 */ |
| 1096 | 0x7144, /* PCI_CHIP_RV515_7144 */ |
| 1097 | 0x7145, /* PCI_CHIP_RV515_7145 */ |
| 1098 | 0x7146, /* PCI_CHIP_RV515_7146 */ |
| 1099 | 0x7147, /* PCI_CHIP_RV515_7147 */ |
| 1100 | 0x7149, /* PCI_CHIP_RV515_7149 */ |
| 1101 | 0x714A, /* PCI_CHIP_RV515_714A */ |
| 1102 | 0x714B, /* PCI_CHIP_RV515_714B */ |
| 1103 | 0x714C, /* PCI_CHIP_RV515_714C */ |
| 1104 | 0x714D, /* PCI_CHIP_RV515_714D */ |
| 1105 | 0x714E, /* PCI_CHIP_RV515_714E */ |
| 1106 | 0x714F, /* PCI_CHIP_RV515_714F */ |
| 1107 | 0x7151, /* PCI_CHIP_RV515_7151 */ |
| 1108 | 0x7152, /* PCI_CHIP_RV515_7152 */ |
| 1109 | 0x7153, /* PCI_CHIP_RV515_7153 */ |
| 1110 | 0x715E, /* PCI_CHIP_RV515_715E */ |
| 1111 | 0x715F, /* PCI_CHIP_RV515_715F */ |
| 1112 | 0x7180, /* PCI_CHIP_RV515_7180 */ |
| 1113 | 0x7181, /* PCI_CHIP_RV515_7181 */ |
| 1114 | 0x7183, /* PCI_CHIP_RV515_7183 */ |
| 1115 | 0x7186, /* PCI_CHIP_RV515_7186 */ |
| 1116 | 0x7187, /* PCI_CHIP_RV515_7187 */ |
| 1117 | 0x7188, /* PCI_CHIP_RV515_7188 */ |
| 1118 | 0x718A, /* PCI_CHIP_RV515_718A */ |
| 1119 | 0x718B, /* PCI_CHIP_RV515_718B */ |
| 1120 | 0x718C, /* PCI_CHIP_RV515_718C */ |
| 1121 | 0x718D, /* PCI_CHIP_RV515_718D */ |
| 1122 | 0x718F, /* PCI_CHIP_RV515_718F */ |
| 1123 | 0x7193, /* PCI_CHIP_RV515_7193 */ |
| 1124 | 0x7196, /* PCI_CHIP_RV515_7196 */ |
| 1125 | 0x719B, /* PCI_CHIP_RV515_719B */ |
| 1126 | 0x719F, /* PCI_CHIP_RV515_719F */ |
| 1127 | 0x7200, /* PCI_CHIP_RV515_7200 */ |
| 1128 | 0x7210, /* PCI_CHIP_RV515_7210 */ |
| 1129 | 0x7211, /* PCI_CHIP_RV515_7211 */ |
| 1130 | 0x71C0, /* PCI_CHIP_RV530_71C0 */ |
| 1131 | 0x71C1, /* PCI_CHIP_RV530_71C1 */ |
| 1132 | 0x71C2, /* PCI_CHIP_RV530_71C2 */ |
| 1133 | 0x71C3, /* PCI_CHIP_RV530_71C3 */ |
| 1134 | 0x71C4, /* PCI_CHIP_RV530_71C4 */ |
| 1135 | 0x71C5, /* PCI_CHIP_RV530_71C5 */ |
| 1136 | 0x71C6, /* PCI_CHIP_RV530_71C6 */ |
| 1137 | 0x71C7, /* PCI_CHIP_RV530_71C7 */ |
| 1138 | 0x71CD, /* PCI_CHIP_RV530_71CD */ |
| 1139 | 0x71CE, /* PCI_CHIP_RV530_71CE */ |
| 1140 | 0x71D2, /* PCI_CHIP_RV530_71D2 */ |
| 1141 | 0x71D4, /* PCI_CHIP_RV530_71D4 */ |
| 1142 | 0x71D5, /* PCI_CHIP_RV530_71D5 */ |
| 1143 | 0x71D6, /* PCI_CHIP_RV530_71D6 */ |
| 1144 | 0x71DA, /* PCI_CHIP_RV530_71DA */ |
| 1145 | 0x71DE, /* PCI_CHIP_RV530_71DE */ |
| 1146 | 0x7281, /* PCI_CHIP_RV560_7281 */ |
| 1147 | 0x7283, /* PCI_CHIP_RV560_7283 */ |
| 1148 | 0x7287, /* PCI_CHIP_RV560_7287 */ |
| 1149 | 0x7290, /* PCI_CHIP_RV560_7290 */ |
| 1150 | 0x7291, /* PCI_CHIP_RV560_7291 */ |
| 1151 | 0x7293, /* PCI_CHIP_RV560_7293 */ |
| 1152 | 0x7297, /* PCI_CHIP_RV560_7297 */ |
| 1153 | 0x7280, /* PCI_CHIP_RV570_7280 */ |
| 1154 | 0x7288, /* PCI_CHIP_RV570_7288 */ |
| 1155 | 0x7289, /* PCI_CHIP_RV570_7289 */ |
| 1156 | 0x728B, /* PCI_CHIP_RV570_728B */ |
| 1157 | 0x728C, /* PCI_CHIP_RV570_728C */ |
| 1158 | 0x7240, /* PCI_CHIP_R580_7240 */ |
| 1159 | 0x7243, /* PCI_CHIP_R580_7243 */ |
| 1160 | 0x7244, /* PCI_CHIP_R580_7244 */ |
| 1161 | 0x7245, /* PCI_CHIP_R580_7245 */ |
| 1162 | 0x7246, /* PCI_CHIP_R580_7246 */ |
| 1163 | 0x7247, /* PCI_CHIP_R580_7247 */ |
| 1164 | 0x7248, /* PCI_CHIP_R580_7248 */ |
| 1165 | 0x7249, /* PCI_CHIP_R580_7249 */ |
| 1166 | 0x724A, /* PCI_CHIP_R580_724A */ |
| 1167 | 0x724B, /* PCI_CHIP_R580_724B */ |
| 1168 | 0x724C, /* PCI_CHIP_R580_724C */ |
| 1169 | 0x724D, /* PCI_CHIP_R580_724D */ |
| 1170 | 0x724E, /* PCI_CHIP_R580_724E */ |
| 1171 | 0x724F, /* PCI_CHIP_R580_724F */ |
| 1172 | 0x7284, /* PCI_CHIP_R580_7284 */ |
| 1173 | 0x793F, /* PCI_CHIP_RS600_793F */ |
| 1174 | 0x7941, /* PCI_CHIP_RS600_7941 */ |
| 1175 | 0x7942, /* PCI_CHIP_RS600_7942 */ |
| 1176 | 0x791E, /* PCI_CHIP_RS690_791E */ |
| 1177 | 0x791F, /* PCI_CHIP_RS690_791F */ |
| 1178 | 0x796C, /* PCI_CHIP_RS740_796C */ |
| 1179 | 0x796D, /* PCI_CHIP_RS740_796D */ |
| 1180 | 0x796E, /* PCI_CHIP_RS740_796E */ |
| 1181 | 0x796F, /* PCI_CHIP_RS740_796F */ |
| 1182 | }; |
| 1183 | |
| 1184 | const int r600_chip_ids[] = { |
| 1185 | 0x9400, /* PCI_CHIP_R600_9400 */ |
| 1186 | 0x9401, /* PCI_CHIP_R600_9401 */ |
| 1187 | 0x9402, /* PCI_CHIP_R600_9402 */ |
| 1188 | 0x9403, /* PCI_CHIP_R600_9403 */ |
| 1189 | 0x9405, /* PCI_CHIP_R600_9405 */ |
| 1190 | 0x940A, /* PCI_CHIP_R600_940A */ |
| 1191 | 0x940B, /* PCI_CHIP_R600_940B */ |
| 1192 | 0x940F, /* PCI_CHIP_R600_940F */ |
| 1193 | 0x94C0, /* PCI_CHIP_RV610_94C0 */ |
| 1194 | 0x94C1, /* PCI_CHIP_RV610_94C1 */ |
| 1195 | 0x94C3, /* PCI_CHIP_RV610_94C3 */ |
| 1196 | 0x94C4, /* PCI_CHIP_RV610_94C4 */ |
| 1197 | 0x94C5, /* PCI_CHIP_RV610_94C5 */ |
| 1198 | 0x94C6, /* PCI_CHIP_RV610_94C6 */ |
| 1199 | 0x94C7, /* PCI_CHIP_RV610_94C7 */ |
| 1200 | 0x94C8, /* PCI_CHIP_RV610_94C8 */ |
| 1201 | 0x94C9, /* PCI_CHIP_RV610_94C9 */ |
| 1202 | 0x94CB, /* PCI_CHIP_RV610_94CB */ |
| 1203 | 0x94CC, /* PCI_CHIP_RV610_94CC */ |
| 1204 | 0x94CD, /* PCI_CHIP_RV610_94CD */ |
| 1205 | 0x9580, /* PCI_CHIP_RV630_9580 */ |
| 1206 | 0x9581, /* PCI_CHIP_RV630_9581 */ |
| 1207 | 0x9583, /* PCI_CHIP_RV630_9583 */ |
| 1208 | 0x9586, /* PCI_CHIP_RV630_9586 */ |
| 1209 | 0x9587, /* PCI_CHIP_RV630_9587 */ |
| 1210 | 0x9588, /* PCI_CHIP_RV630_9588 */ |
| 1211 | 0x9589, /* PCI_CHIP_RV630_9589 */ |
| 1212 | 0x958A, /* PCI_CHIP_RV630_958A */ |
| 1213 | 0x958B, /* PCI_CHIP_RV630_958B */ |
| 1214 | 0x958C, /* PCI_CHIP_RV630_958C */ |
| 1215 | 0x958D, /* PCI_CHIP_RV630_958D */ |
| 1216 | 0x958E, /* PCI_CHIP_RV630_958E */ |
| 1217 | 0x958F, /* PCI_CHIP_RV630_958F */ |
| 1218 | 0x9500, /* PCI_CHIP_RV670_9500 */ |
| 1219 | 0x9501, /* PCI_CHIP_RV670_9501 */ |
| 1220 | 0x9504, /* PCI_CHIP_RV670_9504 */ |
| 1221 | 0x9505, /* PCI_CHIP_RV670_9505 */ |
| 1222 | 0x9506, /* PCI_CHIP_RV670_9506 */ |
| 1223 | 0x9507, /* PCI_CHIP_RV670_9507 */ |
| 1224 | 0x9508, /* PCI_CHIP_RV670_9508 */ |
| 1225 | 0x9509, /* PCI_CHIP_RV670_9509 */ |
| 1226 | 0x950F, /* PCI_CHIP_RV670_950F */ |
| 1227 | 0x9511, /* PCI_CHIP_RV670_9511 */ |
| 1228 | 0x9515, /* PCI_CHIP_RV670_9515 */ |
| 1229 | 0x9517, /* PCI_CHIP_RV670_9517 */ |
| 1230 | 0x9519, /* PCI_CHIP_RV670_9519 */ |
| 1231 | 0x95C0, /* PCI_CHIP_RV620_95C0 */ |
| 1232 | 0x95C2, /* PCI_CHIP_RV620_95C2 */ |
| 1233 | 0x95C4, /* PCI_CHIP_RV620_95C4 */ |
| 1234 | 0x95C5, /* PCI_CHIP_RV620_95C5 */ |
| 1235 | 0x95C6, /* PCI_CHIP_RV620_95C6 */ |
| 1236 | 0x95C7, /* PCI_CHIP_RV620_95C7 */ |
| 1237 | 0x95C9, /* PCI_CHIP_RV620_95C9 */ |
| 1238 | 0x95CC, /* PCI_CHIP_RV620_95CC */ |
| 1239 | 0x95CD, /* PCI_CHIP_RV620_95CD */ |
| 1240 | 0x95CE, /* PCI_CHIP_RV620_95CE */ |
| 1241 | 0x95CF, /* PCI_CHIP_RV620_95CF */ |
| 1242 | 0x9590, /* PCI_CHIP_RV635_9590 */ |
| 1243 | 0x9591, /* PCI_CHIP_RV635_9591 */ |
| 1244 | 0x9593, /* PCI_CHIP_RV635_9593 */ |
| 1245 | 0x9595, /* PCI_CHIP_RV635_9595 */ |
| 1246 | 0x9596, /* PCI_CHIP_RV635_9596 */ |
| 1247 | 0x9597, /* PCI_CHIP_RV635_9597 */ |
| 1248 | 0x9598, /* PCI_CHIP_RV635_9598 */ |
| 1249 | 0x9599, /* PCI_CHIP_RV635_9599 */ |
| 1250 | 0x959B, /* PCI_CHIP_RV635_959B */ |
| 1251 | 0x9610, /* PCI_CHIP_RS780_9610 */ |
| 1252 | 0x9611, /* PCI_CHIP_RS780_9611 */ |
| 1253 | 0x9612, /* PCI_CHIP_RS780_9612 */ |
| 1254 | 0x9613, /* PCI_CHIP_RS780_9613 */ |
| 1255 | 0x9614, /* PCI_CHIP_RS780_9614 */ |
| 1256 | 0x9615, /* PCI_CHIP_RS780_9615 */ |
| 1257 | 0x9616, /* PCI_CHIP_RS780_9616 */ |
| 1258 | 0x9710, /* PCI_CHIP_RS880_9710 */ |
| 1259 | 0x9711, /* PCI_CHIP_RS880_9711 */ |
| 1260 | 0x9712, /* PCI_CHIP_RS880_9712 */ |
| 1261 | 0x9713, /* PCI_CHIP_RS880_9713 */ |
| 1262 | 0x9714, /* PCI_CHIP_RS880_9714 */ |
| 1263 | 0x9715, /* PCI_CHIP_RS880_9715 */ |
| 1264 | 0x9440, /* PCI_CHIP_RV770_9440 */ |
| 1265 | 0x9441, /* PCI_CHIP_RV770_9441 */ |
| 1266 | 0x9442, /* PCI_CHIP_RV770_9442 */ |
| 1267 | 0x9443, /* PCI_CHIP_RV770_9443 */ |
| 1268 | 0x9444, /* PCI_CHIP_RV770_9444 */ |
| 1269 | 0x9446, /* PCI_CHIP_RV770_9446 */ |
| 1270 | 0x944A, /* PCI_CHIP_RV770_944A */ |
| 1271 | 0x944B, /* PCI_CHIP_RV770_944B */ |
| 1272 | 0x944C, /* PCI_CHIP_RV770_944C */ |
| 1273 | 0x944E, /* PCI_CHIP_RV770_944E */ |
| 1274 | 0x9450, /* PCI_CHIP_RV770_9450 */ |
| 1275 | 0x9452, /* PCI_CHIP_RV770_9452 */ |
| 1276 | 0x9456, /* PCI_CHIP_RV770_9456 */ |
| 1277 | 0x945A, /* PCI_CHIP_RV770_945A */ |
| 1278 | 0x945B, /* PCI_CHIP_RV770_945B */ |
| 1279 | 0x945E, /* PCI_CHIP_RV770_945E */ |
| 1280 | 0x9460, /* PCI_CHIP_RV790_9460 */ |
| 1281 | 0x9462, /* PCI_CHIP_RV790_9462 */ |
| 1282 | 0x946A, /* PCI_CHIP_RV770_946A */ |
| 1283 | 0x946B, /* PCI_CHIP_RV770_946B */ |
| 1284 | 0x947A, /* PCI_CHIP_RV770_947A */ |
| 1285 | 0x947B, /* PCI_CHIP_RV770_947B */ |
| 1286 | 0x9480, /* PCI_CHIP_RV730_9480 */ |
| 1287 | 0x9487, /* PCI_CHIP_RV730_9487 */ |
| 1288 | 0x9488, /* PCI_CHIP_RV730_9488 */ |
| 1289 | 0x9489, /* PCI_CHIP_RV730_9489 */ |
| 1290 | 0x948A, /* PCI_CHIP_RV730_948A */ |
| 1291 | 0x948F, /* PCI_CHIP_RV730_948F */ |
| 1292 | 0x9490, /* PCI_CHIP_RV730_9490 */ |
| 1293 | 0x9491, /* PCI_CHIP_RV730_9491 */ |
| 1294 | 0x9495, /* PCI_CHIP_RV730_9495 */ |
| 1295 | 0x9498, /* PCI_CHIP_RV730_9498 */ |
| 1296 | 0x949C, /* PCI_CHIP_RV730_949C */ |
| 1297 | 0x949E, /* PCI_CHIP_RV730_949E */ |
| 1298 | 0x949F, /* PCI_CHIP_RV730_949F */ |
| 1299 | 0x9540, /* PCI_CHIP_RV710_9540 */ |
| 1300 | 0x9541, /* PCI_CHIP_RV710_9541 */ |
| 1301 | 0x9542, /* PCI_CHIP_RV710_9542 */ |
| 1302 | 0x954E, /* PCI_CHIP_RV710_954E */ |
| 1303 | 0x954F, /* PCI_CHIP_RV710_954F */ |
| 1304 | 0x9552, /* PCI_CHIP_RV710_9552 */ |
| 1305 | 0x9553, /* PCI_CHIP_RV710_9553 */ |
| 1306 | 0x9555, /* PCI_CHIP_RV710_9555 */ |
| 1307 | 0x9557, /* PCI_CHIP_RV710_9557 */ |
| 1308 | 0x955F, /* PCI_CHIP_RV710_955F */ |
| 1309 | 0x94A0, /* PCI_CHIP_RV740_94A0 */ |
| 1310 | 0x94A1, /* PCI_CHIP_RV740_94A1 */ |
| 1311 | 0x94A3, /* PCI_CHIP_RV740_94A3 */ |
| 1312 | 0x94B1, /* PCI_CHIP_RV740_94B1 */ |
| 1313 | 0x94B3, /* PCI_CHIP_RV740_94B3 */ |
| 1314 | 0x94B4, /* PCI_CHIP_RV740_94B4 */ |
| 1315 | 0x94B5, /* PCI_CHIP_RV740_94B5 */ |
| 1316 | 0x94B9, /* PCI_CHIP_RV740_94B9 */ |
| 1317 | 0x68E0, /* PCI_CHIP_CEDAR_68E0 */ |
| 1318 | 0x68E1, /* PCI_CHIP_CEDAR_68E1 */ |
| 1319 | 0x68E4, /* PCI_CHIP_CEDAR_68E4 */ |
| 1320 | 0x68E5, /* PCI_CHIP_CEDAR_68E5 */ |
| 1321 | 0x68E8, /* PCI_CHIP_CEDAR_68E8 */ |
| 1322 | 0x68E9, /* PCI_CHIP_CEDAR_68E9 */ |
| 1323 | 0x68F1, /* PCI_CHIP_CEDAR_68F1 */ |
| 1324 | 0x68F8, /* PCI_CHIP_CEDAR_68F8 */ |
| 1325 | 0x68F9, /* PCI_CHIP_CEDAR_68F9 */ |
| 1326 | 0x68FE, /* PCI_CHIP_CEDAR_68FE */ |
| 1327 | 0x68C0, /* PCI_CHIP_REDWOOD_68C0 */ |
| 1328 | 0x68C1, /* PCI_CHIP_REDWOOD_68C1 */ |
| 1329 | 0x68C8, /* PCI_CHIP_REDWOOD_68C8 */ |
| 1330 | 0x68C9, /* PCI_CHIP_REDWOOD_68C9 */ |
| 1331 | 0x68D8, /* PCI_CHIP_REDWOOD_68D8 */ |
| 1332 | 0x68D9, /* PCI_CHIP_REDWOOD_68D9 */ |
| 1333 | 0x68DA, /* PCI_CHIP_REDWOOD_68DA */ |
| 1334 | 0x68DE, /* PCI_CHIP_REDWOOD_68DE */ |
| 1335 | 0x68A0, /* PCI_CHIP_JUNIPER_68A0 */ |
| 1336 | 0x68A1, /* PCI_CHIP_JUNIPER_68A1 */ |
| 1337 | 0x68A8, /* PCI_CHIP_JUNIPER_68A8 */ |
| 1338 | 0x68A9, /* PCI_CHIP_JUNIPER_68A9 */ |
| 1339 | 0x68B0, /* PCI_CHIP_JUNIPER_68B0 */ |
| 1340 | 0x68B8, /* PCI_CHIP_JUNIPER_68B8 */ |
| 1341 | 0x68B9, /* PCI_CHIP_JUNIPER_68B9 */ |
| 1342 | 0x68BE, /* PCI_CHIP_JUNIPER_68BE */ |
| 1343 | 0x6880, /* PCI_CHIP_CYPRESS_6880 */ |
| 1344 | 0x6888, /* PCI_CHIP_CYPRESS_6888 */ |
| 1345 | 0x6889, /* PCI_CHIP_CYPRESS_6889 */ |
| 1346 | 0x688A, /* PCI_CHIP_CYPRESS_688A */ |
| 1347 | 0x6898, /* PCI_CHIP_CYPRESS_6898 */ |
| 1348 | 0x6899, /* PCI_CHIP_CYPRESS_6899 */ |
| 1349 | 0x689E, /* PCI_CHIP_CYPRESS_689E */ |
| 1350 | 0x689C, /* PCI_CHIP_HEMLOCK_689C */ |
| 1351 | 0x689D, /* PCI_CHIP_HEMLOCK_689D */ |
| 1352 | }; |
| 1353 | |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 1354 | const struct dri2_driver_map driver_map[] = { |
| 1355 | { 0x8086, "i915", i915_chip_ids, ARRAY_SIZE(i915_chip_ids) }, |
| 1356 | { 0x8086, "i965", i965_chip_ids, ARRAY_SIZE(i965_chip_ids) }, |
Alex Deucher | 4990b77 | 2010-11-08 14:25:38 -0500 | [diff] [blame] | 1357 | { 0x1002, "radeon", r100_chip_ids, ARRAY_SIZE(r100_chip_ids) }, |
| 1358 | { 0x1002, "r200", r200_chip_ids, ARRAY_SIZE(r200_chip_ids) }, |
| 1359 | { 0x1002, "r300", r300_chip_ids, ARRAY_SIZE(r300_chip_ids) }, |
| 1360 | { 0x1002, "r600", r600_chip_ids, ARRAY_SIZE(r600_chip_ids) }, |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 1361 | }; |
| 1362 | |
| 1363 | static char * |
| 1364 | dri2_get_driver_for_fd(int fd) |
| 1365 | { |
| 1366 | struct udev *udev; |
| 1367 | struct udev_device *device, *parent; |
| 1368 | struct stat buf; |
| 1369 | const char *pci_id; |
| 1370 | char *driver = NULL; |
| 1371 | int vendor_id, chip_id, i, j; |
| 1372 | |
| 1373 | udev = udev_new(); |
| 1374 | if (fstat(fd, &buf) < 0) { |
| 1375 | _eglLog(_EGL_WARNING, "EGL-DRI2: failed to stat fd %d", fd); |
| 1376 | goto out; |
| 1377 | } |
| 1378 | |
| 1379 | device = udev_device_new_from_devnum(udev, 'c', buf.st_rdev); |
| 1380 | if (device == NULL) { |
| 1381 | _eglLog(_EGL_WARNING, |
| 1382 | "EGL-DRI2: could not create udev device for fd %d", fd); |
| 1383 | goto out; |
| 1384 | } |
| 1385 | |
| 1386 | parent = udev_device_get_parent(device); |
| 1387 | if (parent == NULL) { |
| 1388 | _eglLog(_EGL_WARNING, "DRI2: could not get parent device"); |
| 1389 | goto out; |
| 1390 | } |
| 1391 | |
| 1392 | pci_id = udev_device_get_property_value(parent, "PCI_ID"); |
| 1393 | if (pci_id == NULL || sscanf(pci_id, "%x:%x", &vendor_id, &chip_id) != 2) { |
| 1394 | _eglLog(_EGL_WARNING, "EGL-DRI2: malformed or no PCI ID"); |
| 1395 | goto out; |
| 1396 | } |
| 1397 | |
| 1398 | for (i = 0; i < ARRAY_SIZE(driver_map); i++) { |
| 1399 | if (vendor_id != driver_map[i].vendor_id) |
| 1400 | continue; |
| 1401 | for (j = 0; j < driver_map[i].num_chips_ids; j++) |
| 1402 | if (driver_map[i].chip_ids[j] == chip_id) { |
| 1403 | driver = strdup(driver_map[i].driver); |
| 1404 | _eglLog(_EGL_DEBUG, "pci id for %d: %04x:%04x, driver %s", |
| 1405 | fd, vendor_id, chip_id, driver); |
| 1406 | goto out; |
| 1407 | } |
| 1408 | } |
| 1409 | |
| 1410 | out: |
| 1411 | udev_device_unref(device); |
| 1412 | udev_unref(udev); |
| 1413 | |
| 1414 | return driver; |
| 1415 | } |
| 1416 | |
| 1417 | static EGLBoolean |
| 1418 | dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp, |
| 1419 | EGLint *major, EGLint *minor) |
| 1420 | { |
| 1421 | struct dri2_egl_display *dri2_dpy; |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 1422 | int i; |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 1423 | |
| 1424 | dri2_dpy = malloc(sizeof *dri2_dpy); |
| 1425 | if (!dri2_dpy) |
| 1426 | return _eglError(EGL_BAD_ALLOC, "eglInitialize"); |
| 1427 | |
| 1428 | disp->DriverData = (void *) dri2_dpy; |
| 1429 | dri2_dpy->fd = (int) disp->PlatformDisplay; |
| 1430 | |
| 1431 | dri2_dpy->driver_name = dri2_get_driver_for_fd(dri2_dpy->fd); |
| 1432 | if (dri2_dpy->driver_name == NULL) |
| 1433 | return _eglError(EGL_BAD_ALLOC, "DRI2: failed to get driver name"); |
| 1434 | |
| 1435 | if (!dri2_load_driver(disp)) |
| 1436 | goto cleanup_driver_name; |
| 1437 | |
| 1438 | dri2_dpy->extensions[0] = &image_lookup_extension.base; |
| 1439 | dri2_dpy->extensions[1] = &use_invalidate.base; |
| 1440 | dri2_dpy->extensions[2] = NULL; |
| 1441 | |
| 1442 | if (!dri2_create_screen(disp)) |
| 1443 | goto cleanup_driver; |
| 1444 | |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 1445 | for (i = 0; dri2_dpy->driver_configs[i]; i++) |
| 1446 | dri2_add_config(disp, dri2_dpy->driver_configs[i], i + 1, 0, 0); |
| 1447 | |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1448 | disp->Extensions.MESA_drm_image = EGL_TRUE; |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 1449 | disp->Extensions.KHR_image_base = EGL_TRUE; |
| 1450 | disp->Extensions.KHR_gl_renderbuffer_image = EGL_TRUE; |
| 1451 | disp->Extensions.KHR_gl_texture_2D_image = EGL_TRUE; |
| 1452 | |
Kristian Høgsberg | e8a7246 | 2010-07-29 14:26:34 -0400 | [diff] [blame] | 1453 | /* we're supporting EGL 1.4 */ |
| 1454 | *major = 1; |
| 1455 | *minor = 4; |
| 1456 | |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 1457 | return EGL_TRUE; |
| 1458 | |
| 1459 | cleanup_driver: |
| 1460 | dlclose(dri2_dpy->driver); |
| 1461 | cleanup_driver_name: |
| 1462 | free(dri2_dpy->driver_name); |
| 1463 | |
| 1464 | return EGL_FALSE; |
| 1465 | } |
| 1466 | |
| 1467 | #endif |
| 1468 | |
| 1469 | /** |
| 1470 | * Called via eglInitialize(), GLX_drv->API.Initialize(). |
| 1471 | */ |
| 1472 | static EGLBoolean |
| 1473 | dri2_initialize(_EGLDriver *drv, _EGLDisplay *disp, |
| 1474 | EGLint *major, EGLint *minor) |
| 1475 | { |
| 1476 | switch (disp->Platform) { |
| 1477 | case _EGL_PLATFORM_X11: |
| 1478 | return dri2_initialize_x11(drv, disp, major, minor); |
| 1479 | |
| 1480 | #ifdef HAVE_LIBUDEV |
| 1481 | case _EGL_PLATFORM_DRM: |
| 1482 | return dri2_initialize_drm(drv, disp, major, minor); |
| 1483 | #endif |
| 1484 | |
| 1485 | default: |
| 1486 | return EGL_FALSE; |
| 1487 | } |
| 1488 | } |
| 1489 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1490 | /** |
| 1491 | * Called via eglTerminate(), drv->API.Terminate(). |
| 1492 | */ |
| 1493 | static EGLBoolean |
| 1494 | dri2_terminate(_EGLDriver *drv, _EGLDisplay *disp) |
| 1495 | { |
| 1496 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1497 | |
| 1498 | _eglReleaseDisplayResources(drv, disp); |
| 1499 | _eglCleanupDisplay(disp); |
| 1500 | |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 1501 | dri2_dpy->core->destroyScreen(dri2_dpy->dri_screen); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1502 | close(dri2_dpy->fd); |
| 1503 | dlclose(dri2_dpy->driver); |
Chia-I Wu | f22665d | 2010-06-17 17:14:03 +0800 | [diff] [blame] | 1504 | if (disp->PlatformDisplay == NULL) |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 1505 | xcb_disconnect(dri2_dpy->conn); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1506 | free(dri2_dpy); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1507 | disp->DriverData = NULL; |
| 1508 | |
| 1509 | return EGL_TRUE; |
| 1510 | } |
| 1511 | |
| 1512 | |
| 1513 | /** |
| 1514 | * Called via eglCreateContext(), drv->API.CreateContext(). |
| 1515 | */ |
| 1516 | static _EGLContext * |
| 1517 | dri2_create_context(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf, |
| 1518 | _EGLContext *share_list, const EGLint *attrib_list) |
| 1519 | { |
| 1520 | struct dri2_egl_context *dri2_ctx; |
| 1521 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1522 | struct dri2_egl_context *dri2_ctx_shared = dri2_egl_context(share_list); |
| 1523 | struct dri2_egl_config *dri2_config = dri2_egl_config(conf); |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 1524 | const __DRIconfig *dri_config; |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 1525 | int api; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1526 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 1527 | (void) drv; |
| 1528 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1529 | dri2_ctx = malloc(sizeof *dri2_ctx); |
| 1530 | if (!dri2_ctx) { |
| 1531 | _eglError(EGL_BAD_ALLOC, "eglCreateContext"); |
| 1532 | return NULL; |
| 1533 | } |
| 1534 | |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 1535 | if (!_eglInitContext(&dri2_ctx->base, disp, conf, attrib_list)) |
| 1536 | goto cleanup; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1537 | |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 1538 | switch (dri2_ctx->base.ClientAPI) { |
| 1539 | case EGL_OPENGL_ES_API: |
| 1540 | switch (dri2_ctx->base.ClientVersion) { |
| 1541 | case 1: |
| 1542 | api = __DRI_API_GLES; |
| 1543 | break; |
| 1544 | case 2: |
| 1545 | api = __DRI_API_GLES2; |
| 1546 | break; |
| 1547 | default: |
| 1548 | _eglError(EGL_BAD_PARAMETER, "eglCreateContext"); |
| 1549 | return NULL; |
| 1550 | } |
| 1551 | break; |
| 1552 | case EGL_OPENGL_API: |
| 1553 | api = __DRI_API_OPENGL; |
| 1554 | break; |
| 1555 | default: |
| 1556 | _eglError(EGL_BAD_PARAMETER, "eglCreateContext"); |
| 1557 | return NULL; |
| 1558 | } |
| 1559 | |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 1560 | if (conf != NULL) |
| 1561 | dri_config = dri2_config->dri_config; |
| 1562 | else |
| 1563 | dri_config = NULL; |
| 1564 | |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 1565 | if (dri2_dpy->dri2->base.version >= 2) { |
| 1566 | dri2_ctx->dri_context = |
| 1567 | dri2_dpy->dri2->createNewContextForAPI(dri2_dpy->dri_screen, |
| 1568 | api, |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 1569 | dri_config, |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 1570 | dri2_ctx_shared ? |
| 1571 | dri2_ctx_shared->dri_context : NULL, |
| 1572 | dri2_ctx); |
| 1573 | } else if (api == __DRI_API_OPENGL) { |
| 1574 | dri2_ctx->dri_context = |
| 1575 | dri2_dpy->dri2->createNewContext(dri2_dpy->dri_screen, |
| 1576 | dri2_config->dri_config, |
| 1577 | dri2_ctx_shared ? |
| 1578 | dri2_ctx_shared->dri_context : NULL, |
| 1579 | dri2_ctx); |
| 1580 | } else { |
| 1581 | /* fail */ |
| 1582 | } |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1583 | |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 1584 | if (!dri2_ctx->dri_context) |
| 1585 | goto cleanup; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1586 | |
| 1587 | return &dri2_ctx->base; |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 1588 | |
| 1589 | cleanup: |
| 1590 | free(dri2_ctx); |
| 1591 | return NULL; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1592 | } |
| 1593 | |
| 1594 | static EGLBoolean |
| 1595 | dri2_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf) |
| 1596 | { |
| 1597 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1598 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); |
| 1599 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 1600 | (void) drv; |
| 1601 | |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 1602 | if (!_eglPutSurface(surf)) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1603 | return EGL_TRUE; |
| 1604 | |
| 1605 | (*dri2_dpy->core->destroyDrawable)(dri2_surf->dri_drawable); |
| 1606 | |
| 1607 | xcb_dri2_destroy_drawable (dri2_dpy->conn, dri2_surf->drawable); |
| 1608 | |
| 1609 | if (surf->Type == EGL_PBUFFER_BIT) |
| 1610 | xcb_free_pixmap (dri2_dpy->conn, dri2_surf->drawable); |
| 1611 | |
| 1612 | free(surf); |
| 1613 | |
| 1614 | return EGL_TRUE; |
| 1615 | } |
| 1616 | |
| 1617 | /** |
| 1618 | * Called via eglMakeCurrent(), drv->API.MakeCurrent(). |
| 1619 | */ |
| 1620 | static EGLBoolean |
| 1621 | dri2_make_current(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *dsurf, |
| 1622 | _EGLSurface *rsurf, _EGLContext *ctx) |
| 1623 | { |
Chia-I Wu | d18d0fd | 2010-04-06 19:52:39 +0800 | [diff] [blame] | 1624 | struct dri2_egl_driver *dri2_drv = dri2_egl_driver(drv); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1625 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1626 | struct dri2_egl_surface *dri2_dsurf = dri2_egl_surface(dsurf); |
| 1627 | struct dri2_egl_surface *dri2_rsurf = dri2_egl_surface(rsurf); |
| 1628 | struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 1629 | _EGLContext *old_ctx; |
| 1630 | _EGLSurface *old_dsurf, *old_rsurf; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1631 | __DRIdrawable *ddraw, *rdraw; |
| 1632 | __DRIcontext *cctx; |
| 1633 | |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 1634 | /* make new bindings */ |
| 1635 | if (!_eglBindContext(ctx, dsurf, rsurf, &old_ctx, &old_dsurf, &old_rsurf)) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1636 | return EGL_FALSE; |
| 1637 | |
Chia-I Wu | d18d0fd | 2010-04-06 19:52:39 +0800 | [diff] [blame] | 1638 | /* flush before context switch */ |
Chia-I Wu | 547e761 | 2010-10-26 15:00:56 +0800 | [diff] [blame] | 1639 | if (old_ctx && dri2_drv->glFlush) |
Chia-I Wu | d18d0fd | 2010-04-06 19:52:39 +0800 | [diff] [blame] | 1640 | dri2_drv->glFlush(); |
| 1641 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1642 | ddraw = (dri2_dsurf) ? dri2_dsurf->dri_drawable : NULL; |
| 1643 | rdraw = (dri2_rsurf) ? dri2_rsurf->dri_drawable : NULL; |
| 1644 | cctx = (dri2_ctx) ? dri2_ctx->dri_context : NULL; |
| 1645 | |
| 1646 | if ((cctx == NULL && ddraw == NULL && rdraw == NULL) || |
| 1647 | dri2_dpy->core->bindContext(cctx, ddraw, rdraw)) { |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 1648 | dri2_destroy_surface(drv, disp, old_dsurf); |
| 1649 | dri2_destroy_surface(drv, disp, old_rsurf); |
| 1650 | if (old_ctx) { |
Chia-I Wu | 1f4c551 | 2010-11-24 13:42:06 +0800 | [diff] [blame] | 1651 | /* unbind the old context only when there is no new context bound */ |
| 1652 | if (!ctx) { |
| 1653 | __DRIcontext *old_cctx = dri2_egl_context(old_ctx)->dri_context; |
| 1654 | dri2_dpy->core->unbindContext(old_cctx); |
| 1655 | } |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 1656 | /* no destroy? */ |
| 1657 | _eglPutContext(old_ctx); |
| 1658 | } |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1659 | |
| 1660 | return EGL_TRUE; |
| 1661 | } else { |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 1662 | /* undo the previous _eglBindContext */ |
| 1663 | _eglBindContext(old_ctx, old_dsurf, old_rsurf, &ctx, &dsurf, &rsurf); |
| 1664 | assert(&dri2_ctx->base == ctx && |
| 1665 | &dri2_dsurf->base == dsurf && |
| 1666 | &dri2_rsurf->base == rsurf); |
| 1667 | |
| 1668 | _eglPutSurface(dsurf); |
| 1669 | _eglPutSurface(rsurf); |
| 1670 | _eglPutContext(ctx); |
| 1671 | |
| 1672 | _eglPutSurface(old_dsurf); |
| 1673 | _eglPutSurface(old_rsurf); |
| 1674 | _eglPutContext(old_ctx); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1675 | |
| 1676 | return EGL_FALSE; |
| 1677 | } |
| 1678 | } |
| 1679 | |
| 1680 | /** |
| 1681 | * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface(). |
| 1682 | */ |
| 1683 | static _EGLSurface * |
| 1684 | dri2_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type, |
| 1685 | _EGLConfig *conf, EGLNativeWindowType window, |
| 1686 | const EGLint *attrib_list) |
| 1687 | { |
| 1688 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1689 | struct dri2_egl_config *dri2_conf = dri2_egl_config(conf); |
| 1690 | struct dri2_egl_surface *dri2_surf; |
| 1691 | xcb_get_geometry_cookie_t cookie; |
| 1692 | xcb_get_geometry_reply_t *reply; |
| 1693 | xcb_screen_iterator_t s; |
| 1694 | xcb_generic_error_t *error; |
| 1695 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 1696 | (void) drv; |
| 1697 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1698 | dri2_surf = malloc(sizeof *dri2_surf); |
| 1699 | if (!dri2_surf) { |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 1700 | _eglError(EGL_BAD_ALLOC, "dri2_create_surface"); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1701 | return NULL; |
| 1702 | } |
| 1703 | |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 1704 | if (!_eglInitSurface(&dri2_surf->base, disp, type, conf, attrib_list)) |
| 1705 | goto cleanup_surf; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1706 | |
| 1707 | dri2_surf->region = XCB_NONE; |
| 1708 | if (type == EGL_PBUFFER_BIT) { |
| 1709 | dri2_surf->drawable = xcb_generate_id(dri2_dpy->conn); |
| 1710 | s = xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy->conn)); |
Chia-I Wu | b67f729 | 2010-10-22 15:03:11 +0800 | [diff] [blame] | 1711 | xcb_create_pixmap(dri2_dpy->conn, conf->BufferSize, |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1712 | dri2_surf->drawable, s.data->root, |
| 1713 | dri2_surf->base.Width, dri2_surf->base.Height); |
| 1714 | } else { |
| 1715 | dri2_surf->drawable = window; |
| 1716 | } |
| 1717 | |
| 1718 | dri2_surf->dri_drawable = |
| 1719 | (*dri2_dpy->dri2->createNewDrawable) (dri2_dpy->dri_screen, |
| 1720 | dri2_conf->dri_config, dri2_surf); |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 1721 | if (dri2_surf->dri_drawable == NULL) { |
| 1722 | _eglError(EGL_BAD_ALLOC, "dri2->createNewDrawable"); |
| 1723 | goto cleanup_pixmap; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1724 | } |
| 1725 | |
| 1726 | xcb_dri2_create_drawable (dri2_dpy->conn, dri2_surf->drawable); |
| 1727 | |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 1728 | if (type != EGL_PBUFFER_BIT) { |
| 1729 | cookie = xcb_get_geometry (dri2_dpy->conn, dri2_surf->drawable); |
| 1730 | reply = xcb_get_geometry_reply (dri2_dpy->conn, cookie, &error); |
| 1731 | if (reply == NULL || error != NULL) { |
| 1732 | _eglError(EGL_BAD_ALLOC, "xcb_get_geometry"); |
| 1733 | free(error); |
| 1734 | goto cleanup_dri_drawable; |
| 1735 | } |
| 1736 | |
| 1737 | dri2_surf->base.Width = reply->width; |
| 1738 | dri2_surf->base.Height = reply->height; |
| 1739 | free(reply); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1740 | } |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1741 | |
| 1742 | return &dri2_surf->base; |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 1743 | |
| 1744 | cleanup_dri_drawable: |
| 1745 | dri2_dpy->core->destroyDrawable(dri2_surf->dri_drawable); |
| 1746 | cleanup_pixmap: |
| 1747 | if (type == EGL_PBUFFER_BIT) |
| 1748 | xcb_free_pixmap(dri2_dpy->conn, dri2_surf->drawable); |
| 1749 | cleanup_surf: |
| 1750 | free(dri2_surf); |
| 1751 | |
| 1752 | return NULL; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1753 | } |
| 1754 | |
| 1755 | /** |
| 1756 | * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface(). |
| 1757 | */ |
| 1758 | static _EGLSurface * |
| 1759 | dri2_create_window_surface(_EGLDriver *drv, _EGLDisplay *disp, |
| 1760 | _EGLConfig *conf, EGLNativeWindowType window, |
| 1761 | const EGLint *attrib_list) |
| 1762 | { |
| 1763 | return dri2_create_surface(drv, disp, EGL_WINDOW_BIT, conf, |
| 1764 | window, attrib_list); |
| 1765 | } |
| 1766 | |
| 1767 | static _EGLSurface * |
| 1768 | dri2_create_pixmap_surface(_EGLDriver *drv, _EGLDisplay *disp, |
| 1769 | _EGLConfig *conf, EGLNativePixmapType pixmap, |
| 1770 | const EGLint *attrib_list) |
| 1771 | { |
| 1772 | return dri2_create_surface(drv, disp, EGL_PIXMAP_BIT, conf, |
| 1773 | pixmap, attrib_list); |
| 1774 | } |
| 1775 | |
| 1776 | static _EGLSurface * |
| 1777 | dri2_create_pbuffer_surface(_EGLDriver *drv, _EGLDisplay *disp, |
| 1778 | _EGLConfig *conf, const EGLint *attrib_list) |
| 1779 | { |
| 1780 | return dri2_create_surface(drv, disp, EGL_PBUFFER_BIT, conf, |
| 1781 | XCB_WINDOW_NONE, attrib_list); |
| 1782 | } |
| 1783 | |
| 1784 | static EGLBoolean |
Kristian Høgsberg | 52c554a | 2010-05-06 22:01:35 -0400 | [diff] [blame] | 1785 | dri2_copy_region(_EGLDriver *drv, _EGLDisplay *disp, |
| 1786 | _EGLSurface *draw, xcb_xfixes_region_t region) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1787 | { |
Chia-I Wu | d18d0fd | 2010-04-06 19:52:39 +0800 | [diff] [blame] | 1788 | struct dri2_egl_driver *dri2_drv = dri2_egl_driver(drv); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1789 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1790 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(draw); |
Chia-I Wu | d18d0fd | 2010-04-06 19:52:39 +0800 | [diff] [blame] | 1791 | _EGLContext *ctx; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1792 | xcb_dri2_copy_region_cookie_t cookie; |
| 1793 | |
Chia-I Wu | d18d0fd | 2010-04-06 19:52:39 +0800 | [diff] [blame] | 1794 | if (dri2_drv->glFlush) { |
| 1795 | ctx = _eglGetCurrentContext(); |
| 1796 | if (ctx && ctx->DrawSurface == &dri2_surf->base) |
| 1797 | dri2_drv->glFlush(); |
| 1798 | } |
| 1799 | |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 1800 | (*dri2_dpy->flush->flush)(dri2_surf->dri_drawable); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1801 | |
| 1802 | #if 0 |
| 1803 | /* FIXME: Add support for dri swapbuffers, that'll give us swap |
| 1804 | * interval and page flipping (at least for fullscreen windows) as |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 1805 | * well as the page flip event. Unless surface->SwapBehavior is |
| 1806 | * EGL_BUFFER_PRESERVED. */ |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1807 | #if __DRI2_FLUSH_VERSION >= 2 |
| 1808 | if (pdraw->psc->f) |
| 1809 | (*pdraw->psc->f->flushInvalidate)(pdraw->driDrawable); |
| 1810 | #endif |
| 1811 | #endif |
| 1812 | |
Kristian Høgsberg | c3c1a7e | 2010-02-09 20:49:40 -0500 | [diff] [blame] | 1813 | if (!dri2_surf->have_fake_front) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1814 | return EGL_TRUE; |
| 1815 | |
| 1816 | cookie = xcb_dri2_copy_region_unchecked(dri2_dpy->conn, |
| 1817 | dri2_surf->drawable, |
Kristian Høgsberg | 52c554a | 2010-05-06 22:01:35 -0400 | [diff] [blame] | 1818 | region, |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1819 | XCB_DRI2_ATTACHMENT_BUFFER_FRONT_LEFT, |
Kristian Høgsberg | c3c1a7e | 2010-02-09 20:49:40 -0500 | [diff] [blame] | 1820 | XCB_DRI2_ATTACHMENT_BUFFER_FAKE_FRONT_LEFT); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1821 | free(xcb_dri2_copy_region_reply(dri2_dpy->conn, cookie, NULL)); |
| 1822 | |
| 1823 | return EGL_TRUE; |
| 1824 | } |
| 1825 | |
Kristian Høgsberg | 52c554a | 2010-05-06 22:01:35 -0400 | [diff] [blame] | 1826 | static EGLBoolean |
| 1827 | dri2_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw) |
| 1828 | { |
| 1829 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(draw); |
| 1830 | |
| 1831 | return dri2_copy_region(drv, disp, draw, dri2_surf->region); |
| 1832 | } |
| 1833 | |
| 1834 | static EGLBoolean |
| 1835 | dri2_swap_buffers_region(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw, |
| 1836 | EGLint numRects, const EGLint *rects) |
| 1837 | { |
| 1838 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1839 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(draw); |
| 1840 | EGLBoolean ret; |
| 1841 | xcb_xfixes_region_t region; |
| 1842 | xcb_rectangle_t rectangles[16]; |
| 1843 | int i; |
| 1844 | |
Ian Romanick | e4bd50c | 2010-09-24 10:54:28 -0700 | [diff] [blame] | 1845 | if (numRects > (int)ARRAY_SIZE(rectangles)) |
Kristian Høgsberg | 52c554a | 2010-05-06 22:01:35 -0400 | [diff] [blame] | 1846 | return dri2_copy_region(drv, disp, draw, dri2_surf->region); |
| 1847 | |
| 1848 | /* FIXME: Invert y here? */ |
| 1849 | for (i = 0; i < numRects; i++) { |
| 1850 | rectangles[i].x = rects[i * 4]; |
| 1851 | rectangles[i].y = rects[i * 4 + 1]; |
| 1852 | rectangles[i].width = rects[i * 4 + 2]; |
| 1853 | rectangles[i].height = rects[i * 4 + 3]; |
| 1854 | } |
| 1855 | |
| 1856 | region = xcb_generate_id(dri2_dpy->conn); |
| 1857 | xcb_xfixes_create_region(dri2_dpy->conn, region, numRects, rectangles); |
| 1858 | ret = dri2_copy_region(drv, disp, draw, region); |
| 1859 | xcb_xfixes_destroy_region(dri2_dpy->conn, region); |
| 1860 | |
| 1861 | return ret; |
| 1862 | } |
| 1863 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1864 | /* |
| 1865 | * Called from eglGetProcAddress() via drv->API.GetProcAddress(). |
| 1866 | */ |
| 1867 | static _EGLProc |
| 1868 | dri2_get_proc_address(_EGLDriver *drv, const char *procname) |
| 1869 | { |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 1870 | (void) drv; |
| 1871 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1872 | /* FIXME: Do we need to support lookup of EGL symbols too? */ |
| 1873 | |
| 1874 | return (_EGLProc) _glapi_get_proc_address(procname); |
| 1875 | } |
| 1876 | |
| 1877 | static EGLBoolean |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 1878 | dri2_wait_client(_EGLDriver *drv, _EGLDisplay *disp, _EGLContext *ctx) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1879 | { |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 1880 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1881 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(ctx->DrawSurface); |
| 1882 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 1883 | (void) drv; |
| 1884 | |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 1885 | /* FIXME: If EGL allows frontbuffer rendering for window surfaces, |
| 1886 | * we need to copy fake to real here.*/ |
| 1887 | |
| 1888 | (*dri2_dpy->flush->flush)(dri2_surf->dri_drawable); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1889 | |
| 1890 | return EGL_TRUE; |
| 1891 | } |
| 1892 | |
| 1893 | static EGLBoolean |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 1894 | dri2_wait_native(_EGLDriver *drv, _EGLDisplay *disp, EGLint engine) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1895 | { |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 1896 | (void) drv; |
| 1897 | (void) disp; |
| 1898 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1899 | if (engine != EGL_CORE_NATIVE_ENGINE) |
| 1900 | return _eglError(EGL_BAD_PARAMETER, "eglWaitNative"); |
| 1901 | /* glXWaitX(); */ |
| 1902 | |
| 1903 | return EGL_TRUE; |
| 1904 | } |
| 1905 | |
| 1906 | static void |
| 1907 | dri2_unload(_EGLDriver *drv) |
| 1908 | { |
| 1909 | struct dri2_egl_driver *dri2_drv = dri2_egl_driver(drv); |
| 1910 | free(dri2_drv); |
| 1911 | } |
| 1912 | |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 1913 | static EGLBoolean |
| 1914 | dri2_copy_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf, |
| 1915 | EGLNativePixmapType target) |
| 1916 | { |
| 1917 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1918 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); |
| 1919 | xcb_gcontext_t gc; |
| 1920 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 1921 | (void) drv; |
| 1922 | |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 1923 | (*dri2_dpy->flush->flush)(dri2_surf->dri_drawable); |
| 1924 | |
| 1925 | gc = xcb_generate_id(dri2_dpy->conn); |
| 1926 | xcb_create_gc(dri2_dpy->conn, gc, target, 0, NULL); |
| 1927 | xcb_copy_area(dri2_dpy->conn, |
| 1928 | dri2_surf->drawable, |
| 1929 | target, |
| 1930 | gc, |
| 1931 | 0, 0, |
| 1932 | 0, 0, |
| 1933 | dri2_surf->base.Width, |
| 1934 | dri2_surf->base.Height); |
| 1935 | xcb_free_gc(dri2_dpy->conn, gc); |
| 1936 | |
| 1937 | return EGL_TRUE; |
| 1938 | } |
| 1939 | |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1940 | static EGLBoolean |
| 1941 | dri2_bind_tex_image(_EGLDriver *drv, |
| 1942 | _EGLDisplay *disp, _EGLSurface *surf, EGLint buffer) |
| 1943 | { |
| 1944 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1945 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); |
| 1946 | struct dri2_egl_context *dri2_ctx; |
| 1947 | _EGLContext *ctx; |
| 1948 | GLint format, target; |
| 1949 | |
| 1950 | ctx = _eglGetCurrentContext(); |
| 1951 | dri2_ctx = dri2_egl_context(ctx); |
| 1952 | |
Kristian Høgsberg | 5dc0f49 | 2010-05-06 22:40:25 -0400 | [diff] [blame] | 1953 | if (!_eglBindTexImage(drv, disp, surf, buffer)) |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1954 | return EGL_FALSE; |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1955 | |
| 1956 | switch (dri2_surf->base.TextureFormat) { |
| 1957 | case EGL_TEXTURE_RGB: |
| 1958 | format = __DRI_TEXTURE_FORMAT_RGB; |
| 1959 | break; |
| 1960 | case EGL_TEXTURE_RGBA: |
| 1961 | format = __DRI_TEXTURE_FORMAT_RGBA; |
| 1962 | break; |
| 1963 | default: |
Kristian Høgsberg | 5dc0f49 | 2010-05-06 22:40:25 -0400 | [diff] [blame] | 1964 | assert(0); |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1965 | } |
| 1966 | |
| 1967 | switch (dri2_surf->base.TextureTarget) { |
| 1968 | case EGL_TEXTURE_2D: |
| 1969 | target = GL_TEXTURE_2D; |
| 1970 | break; |
| 1971 | default: |
Kristian Høgsberg | 5dc0f49 | 2010-05-06 22:40:25 -0400 | [diff] [blame] | 1972 | assert(0); |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1973 | } |
| 1974 | |
| 1975 | (*dri2_dpy->tex_buffer->setTexBuffer2)(dri2_ctx->dri_context, |
| 1976 | target, format, |
| 1977 | dri2_surf->dri_drawable); |
| 1978 | |
Kristian Høgsberg | 5dc0f49 | 2010-05-06 22:40:25 -0400 | [diff] [blame] | 1979 | return EGL_TRUE; |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1980 | } |
| 1981 | |
| 1982 | static EGLBoolean |
| 1983 | dri2_release_tex_image(_EGLDriver *drv, |
| 1984 | _EGLDisplay *disp, _EGLSurface *surf, EGLint buffer) |
| 1985 | { |
Juan Zhao | e59fa4c | 2011-01-09 12:03:02 -0500 | [diff] [blame^] | 1986 | #if __DRI_TEX_BUFFER_VERSION >= 3 |
| 1987 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1988 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); |
| 1989 | struct dri2_egl_context *dri2_ctx; |
| 1990 | _EGLContext *ctx; |
| 1991 | GLint target; |
| 1992 | |
| 1993 | ctx = _eglGetCurrentContext(); |
| 1994 | dri2_ctx = dri2_egl_context(ctx); |
| 1995 | |
| 1996 | if (!_eglReleaseTexImage(drv, disp, surf, buffer)) |
| 1997 | return EGL_FALSE; |
| 1998 | |
| 1999 | switch (dri2_surf->base.TextureTarget) { |
| 2000 | case EGL_TEXTURE_2D: |
| 2001 | target = GL_TEXTURE_2D; |
| 2002 | break; |
| 2003 | default: |
| 2004 | assert(0); |
| 2005 | } |
| 2006 | if (dri2_dpy->tex_buffer->releaseTexBuffer!=NULL) |
| 2007 | (*dri2_dpy->tex_buffer->releaseTexBuffer)(dri2_ctx->dri_context, |
| 2008 | target, |
| 2009 | dri2_surf->dri_drawable); |
| 2010 | #endif |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 2011 | |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 2012 | return EGL_TRUE; |
| 2013 | } |
| 2014 | |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 2015 | static _EGLImage * |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 2016 | dri2_create_image_khr_pixmap(_EGLDisplay *disp, _EGLContext *ctx, |
| 2017 | EGLClientBuffer buffer, const EGLint *attr_list) |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 2018 | { |
| 2019 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 2020 | struct dri2_egl_image *dri2_img; |
| 2021 | unsigned int attachments[1]; |
| 2022 | xcb_drawable_t drawable; |
| 2023 | xcb_dri2_get_buffers_cookie_t buffers_cookie; |
| 2024 | xcb_dri2_get_buffers_reply_t *buffers_reply; |
| 2025 | xcb_dri2_dri2_buffer_t *buffers; |
| 2026 | xcb_get_geometry_cookie_t geometry_cookie; |
| 2027 | xcb_get_geometry_reply_t *geometry_reply; |
| 2028 | xcb_generic_error_t *error; |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 2029 | int stride, format; |
| 2030 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 2031 | (void) ctx; |
| 2032 | |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 2033 | drawable = (xcb_drawable_t) buffer; |
| 2034 | xcb_dri2_create_drawable (dri2_dpy->conn, drawable); |
| 2035 | attachments[0] = XCB_DRI2_ATTACHMENT_BUFFER_FRONT_LEFT; |
| 2036 | buffers_cookie = |
| 2037 | xcb_dri2_get_buffers_unchecked (dri2_dpy->conn, |
| 2038 | drawable, 1, 1, attachments); |
| 2039 | geometry_cookie = xcb_get_geometry (dri2_dpy->conn, drawable); |
| 2040 | buffers_reply = xcb_dri2_get_buffers_reply (dri2_dpy->conn, |
| 2041 | buffers_cookie, NULL); |
| 2042 | buffers = xcb_dri2_get_buffers_buffers (buffers_reply); |
| 2043 | if (buffers == NULL) { |
| 2044 | return NULL; |
| 2045 | } |
| 2046 | |
| 2047 | geometry_reply = xcb_get_geometry_reply (dri2_dpy->conn, |
| 2048 | geometry_cookie, &error); |
| 2049 | if (geometry_reply == NULL || error != NULL) { |
| 2050 | _eglError(EGL_BAD_ALLOC, "xcb_get_geometry"); |
| 2051 | free(error); |
| 2052 | free(buffers_reply); |
| 2053 | } |
| 2054 | |
| 2055 | switch (geometry_reply->depth) { |
| 2056 | case 16: |
| 2057 | format = __DRI_IMAGE_FORMAT_RGB565; |
| 2058 | break; |
| 2059 | case 24: |
| 2060 | format = __DRI_IMAGE_FORMAT_XRGB8888; |
| 2061 | break; |
| 2062 | case 32: |
| 2063 | format = __DRI_IMAGE_FORMAT_ARGB8888; |
| 2064 | break; |
| 2065 | default: |
| 2066 | _eglError(EGL_BAD_PARAMETER, |
| 2067 | "dri2_create_image_khr: unsupported pixmap depth"); |
| 2068 | free(buffers_reply); |
| 2069 | free(geometry_reply); |
| 2070 | return NULL; |
| 2071 | } |
| 2072 | |
| 2073 | dri2_img = malloc(sizeof *dri2_img); |
| 2074 | if (!dri2_img) { |
| 2075 | free(buffers_reply); |
| 2076 | free(geometry_reply); |
| 2077 | _eglError(EGL_BAD_ALLOC, "dri2_create_image_khr"); |
| 2078 | return EGL_NO_IMAGE_KHR; |
| 2079 | } |
| 2080 | |
Chia-I Wu | 713c873 | 2010-10-22 16:36:47 +0800 | [diff] [blame] | 2081 | if (!_eglInitImage(&dri2_img->base, disp)) { |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 2082 | free(buffers_reply); |
| 2083 | free(geometry_reply); |
| 2084 | return EGL_NO_IMAGE_KHR; |
| 2085 | } |
| 2086 | |
| 2087 | stride = buffers[0].pitch / buffers[0].cpp; |
| 2088 | dri2_img->dri_image = |
Kristian Høgsberg | 9ec0b2a | 2010-09-22 15:07:15 -0400 | [diff] [blame] | 2089 | dri2_dpy->image->createImageFromName(dri2_dpy->dri_screen, |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 2090 | buffers_reply->width, |
| 2091 | buffers_reply->height, |
| 2092 | format, |
| 2093 | buffers[0].name, |
| 2094 | stride, |
| 2095 | dri2_img); |
| 2096 | |
| 2097 | free(buffers_reply); |
| 2098 | free(geometry_reply); |
| 2099 | |
| 2100 | return &dri2_img->base; |
| 2101 | } |
| 2102 | |
| 2103 | static _EGLImage * |
| 2104 | dri2_create_image_khr_renderbuffer(_EGLDisplay *disp, _EGLContext *ctx, |
| 2105 | EGLClientBuffer buffer, |
| 2106 | const EGLint *attr_list) |
| 2107 | { |
| 2108 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 2109 | struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); |
| 2110 | struct dri2_egl_image *dri2_img; |
| 2111 | GLuint renderbuffer = (GLuint) buffer; |
| 2112 | |
| 2113 | if (renderbuffer == 0) { |
| 2114 | _eglError(EGL_BAD_PARAMETER, "dri2_create_image_khr"); |
| 2115 | return EGL_NO_IMAGE_KHR; |
| 2116 | } |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 2117 | |
| 2118 | dri2_img = malloc(sizeof *dri2_img); |
| 2119 | if (!dri2_img) { |
| 2120 | _eglError(EGL_BAD_ALLOC, "dri2_create_image_khr"); |
| 2121 | return EGL_NO_IMAGE_KHR; |
| 2122 | } |
| 2123 | |
Chia-I Wu | 713c873 | 2010-10-22 16:36:47 +0800 | [diff] [blame] | 2124 | if (!_eglInitImage(&dri2_img->base, disp)) |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 2125 | return EGL_NO_IMAGE_KHR; |
| 2126 | |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 2127 | dri2_img->dri_image = |
| 2128 | dri2_dpy->image->createImageFromRenderbuffer(dri2_ctx->dri_context, |
| 2129 | renderbuffer, |
| 2130 | dri2_img); |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 2131 | |
| 2132 | return &dri2_img->base; |
| 2133 | } |
| 2134 | |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 2135 | static _EGLImage * |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2136 | dri2_create_image_mesa_drm_buffer(_EGLDisplay *disp, _EGLContext *ctx, |
| 2137 | EGLClientBuffer buffer, const EGLint *attr_list) |
| 2138 | { |
| 2139 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2140 | struct dri2_egl_image *dri2_img; |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 2141 | EGLint format, name, pitch, err; |
| 2142 | _EGLImageAttribs attrs; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2143 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 2144 | (void) ctx; |
| 2145 | |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2146 | name = (EGLint) buffer; |
| 2147 | |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 2148 | err = _eglParseImageAttribList(&attrs, disp, attr_list); |
| 2149 | if (err != EGL_SUCCESS) |
| 2150 | return NULL; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2151 | |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 2152 | if (attrs.Width <= 0 || attrs.Height <= 0 || |
| 2153 | attrs.DRMBufferStrideMESA <= 0) { |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2154 | _eglError(EGL_BAD_PARAMETER, |
| 2155 | "bad width, height or stride"); |
| 2156 | return NULL; |
| 2157 | } |
| 2158 | |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 2159 | switch (attrs.DRMBufferFormatMESA) { |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2160 | case EGL_DRM_BUFFER_FORMAT_ARGB32_MESA: |
| 2161 | format = __DRI_IMAGE_FORMAT_ARGB8888; |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 2162 | pitch = attrs.DRMBufferStrideMESA; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2163 | break; |
| 2164 | default: |
| 2165 | _eglError(EGL_BAD_PARAMETER, |
| 2166 | "dri2_create_image_khr: unsupported pixmap depth"); |
| 2167 | return NULL; |
| 2168 | } |
| 2169 | |
| 2170 | dri2_img = malloc(sizeof *dri2_img); |
| 2171 | if (!dri2_img) { |
| 2172 | _eglError(EGL_BAD_ALLOC, "dri2_create_image_mesa_drm"); |
| 2173 | return NULL; |
| 2174 | } |
| 2175 | |
Chia-I Wu | 713c873 | 2010-10-22 16:36:47 +0800 | [diff] [blame] | 2176 | if (!_eglInitImage(&dri2_img->base, disp)) { |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2177 | free(dri2_img); |
| 2178 | return NULL; |
| 2179 | } |
| 2180 | |
| 2181 | dri2_img->dri_image = |
Kristian Høgsberg | 9ec0b2a | 2010-09-22 15:07:15 -0400 | [diff] [blame] | 2182 | dri2_dpy->image->createImageFromName(dri2_dpy->dri_screen, |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 2183 | attrs.Width, |
| 2184 | attrs.Height, |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2185 | format, |
| 2186 | name, |
| 2187 | pitch, |
| 2188 | dri2_img); |
| 2189 | if (dri2_img->dri_image == NULL) { |
| 2190 | free(dri2_img); |
| 2191 | _eglError(EGL_BAD_ALLOC, "dri2_create_image_mesa_drm"); |
| 2192 | return NULL; |
| 2193 | } |
| 2194 | |
| 2195 | return &dri2_img->base; |
| 2196 | } |
| 2197 | |
| 2198 | static _EGLImage * |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 2199 | dri2_create_image_khr(_EGLDriver *drv, _EGLDisplay *disp, |
| 2200 | _EGLContext *ctx, EGLenum target, |
| 2201 | EGLClientBuffer buffer, const EGLint *attr_list) |
| 2202 | { |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 2203 | (void) drv; |
| 2204 | |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 2205 | switch (target) { |
| 2206 | case EGL_NATIVE_PIXMAP_KHR: |
| 2207 | return dri2_create_image_khr_pixmap(disp, ctx, buffer, attr_list); |
| 2208 | case EGL_GL_RENDERBUFFER_KHR: |
| 2209 | return dri2_create_image_khr_renderbuffer(disp, ctx, buffer, attr_list); |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2210 | case EGL_DRM_BUFFER_MESA: |
| 2211 | return dri2_create_image_mesa_drm_buffer(disp, ctx, buffer, attr_list); |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 2212 | default: |
| 2213 | _eglError(EGL_BAD_PARAMETER, "dri2_create_image_khr"); |
| 2214 | return EGL_NO_IMAGE_KHR; |
| 2215 | } |
| 2216 | } |
| 2217 | |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 2218 | static EGLBoolean |
| 2219 | dri2_destroy_image_khr(_EGLDriver *drv, _EGLDisplay *disp, _EGLImage *image) |
| 2220 | { |
| 2221 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 2222 | struct dri2_egl_image *dri2_img = dri2_egl_image(image); |
| 2223 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 2224 | (void) drv; |
| 2225 | |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 2226 | dri2_dpy->image->destroyImage(dri2_img->dri_image); |
| 2227 | free(dri2_img); |
| 2228 | |
| 2229 | return EGL_TRUE; |
| 2230 | } |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 2231 | |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2232 | static _EGLImage * |
| 2233 | dri2_create_drm_image_mesa(_EGLDriver *drv, _EGLDisplay *disp, |
| 2234 | const EGLint *attr_list) |
| 2235 | { |
| 2236 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 2237 | struct dri2_egl_image *dri2_img; |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 2238 | _EGLImageAttribs attrs; |
| 2239 | unsigned int dri_use, valid_mask; |
| 2240 | int format; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2241 | EGLint err = EGL_SUCCESS; |
| 2242 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 2243 | (void) drv; |
| 2244 | |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2245 | dri2_img = malloc(sizeof *dri2_img); |
| 2246 | if (!dri2_img) { |
| 2247 | _eglError(EGL_BAD_ALLOC, "dri2_create_image_khr"); |
| 2248 | return EGL_NO_IMAGE_KHR; |
| 2249 | } |
| 2250 | |
| 2251 | if (!attr_list) { |
| 2252 | err = EGL_BAD_PARAMETER; |
| 2253 | goto cleanup_img; |
| 2254 | } |
| 2255 | |
Chia-I Wu | 713c873 | 2010-10-22 16:36:47 +0800 | [diff] [blame] | 2256 | if (!_eglInitImage(&dri2_img->base, disp)) { |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2257 | err = EGL_BAD_PARAMETER; |
| 2258 | goto cleanup_img; |
| 2259 | } |
| 2260 | |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 2261 | err = _eglParseImageAttribList(&attrs, disp, attr_list); |
| 2262 | if (err != EGL_SUCCESS) |
| 2263 | goto cleanup_img; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2264 | |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 2265 | if (attrs.Width <= 0 || attrs.Height <= 0) { |
| 2266 | _eglLog(_EGL_WARNING, "bad width or height (%dx%d)", |
| 2267 | attrs.Width, attrs.Height); |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2268 | goto cleanup_img; |
| 2269 | } |
| 2270 | |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 2271 | switch (attrs.DRMBufferFormatMESA) { |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2272 | case EGL_DRM_BUFFER_FORMAT_ARGB32_MESA: |
| 2273 | format = __DRI_IMAGE_FORMAT_ARGB8888; |
| 2274 | break; |
| 2275 | default: |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 2276 | _eglLog(_EGL_WARNING, "bad image format value 0x%04x", |
| 2277 | attrs.DRMBufferFormatMESA); |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2278 | goto cleanup_img; |
| 2279 | } |
| 2280 | |
| 2281 | valid_mask = |
| 2282 | EGL_DRM_BUFFER_USE_SCANOUT_MESA | |
| 2283 | EGL_DRM_BUFFER_USE_SHARE_MESA; |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 2284 | if (attrs.DRMBufferUseMESA & ~valid_mask) { |
| 2285 | _eglLog(_EGL_WARNING, "bad image use bit 0x%04x", |
| 2286 | attrs.DRMBufferUseMESA & ~valid_mask); |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2287 | goto cleanup_img; |
| 2288 | } |
| 2289 | |
| 2290 | dri_use = 0; |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 2291 | if (attrs.DRMBufferUseMESA & EGL_DRM_BUFFER_USE_SHARE_MESA) |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2292 | dri_use |= __DRI_IMAGE_USE_SHARE; |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 2293 | if (attrs.DRMBufferUseMESA & EGL_DRM_BUFFER_USE_SCANOUT_MESA) |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2294 | dri_use |= __DRI_IMAGE_USE_SCANOUT; |
| 2295 | |
| 2296 | dri2_img->dri_image = |
| 2297 | dri2_dpy->image->createImage(dri2_dpy->dri_screen, |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 2298 | attrs.Width, attrs.Height, |
| 2299 | format, dri_use, dri2_img); |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2300 | if (dri2_img->dri_image == NULL) { |
| 2301 | err = EGL_BAD_ALLOC; |
| 2302 | goto cleanup_img; |
| 2303 | } |
| 2304 | |
| 2305 | return &dri2_img->base; |
| 2306 | |
| 2307 | cleanup_img: |
| 2308 | free(dri2_img); |
| 2309 | _eglError(err, "dri2_create_drm_image_mesa"); |
| 2310 | |
| 2311 | return EGL_NO_IMAGE_KHR; |
| 2312 | } |
| 2313 | |
| 2314 | static EGLBoolean |
| 2315 | dri2_export_drm_image_mesa(_EGLDriver *drv, _EGLDisplay *disp, _EGLImage *img, |
| 2316 | EGLint *name, EGLint *handle, EGLint *stride) |
| 2317 | { |
| 2318 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 2319 | struct dri2_egl_image *dri2_img = dri2_egl_image(img); |
| 2320 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 2321 | (void) drv; |
| 2322 | |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2323 | if (name && !dri2_dpy->image->queryImage(dri2_img->dri_image, |
| 2324 | __DRI_IMAGE_ATTRIB_NAME, name)) { |
| 2325 | _eglError(EGL_BAD_ALLOC, "dri2_export_drm_image_mesa"); |
| 2326 | return EGL_FALSE; |
| 2327 | } |
| 2328 | |
| 2329 | if (handle) |
| 2330 | dri2_dpy->image->queryImage(dri2_img->dri_image, |
| 2331 | __DRI_IMAGE_ATTRIB_HANDLE, handle); |
| 2332 | |
| 2333 | if (stride) |
| 2334 | dri2_dpy->image->queryImage(dri2_img->dri_image, |
| 2335 | __DRI_IMAGE_ATTRIB_STRIDE, stride); |
| 2336 | |
| 2337 | return EGL_TRUE; |
| 2338 | } |
| 2339 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 2340 | /** |
| 2341 | * This is the main entrypoint into the driver, called by libEGL. |
| 2342 | * Create a new _EGLDriver object and init its dispatch table. |
| 2343 | */ |
| 2344 | _EGLDriver * |
| 2345 | _eglMain(const char *args) |
| 2346 | { |
| 2347 | struct dri2_egl_driver *dri2_drv; |
| 2348 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 2349 | (void) args; |
| 2350 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 2351 | dri2_drv = malloc(sizeof *dri2_drv); |
| 2352 | if (!dri2_drv) |
| 2353 | return NULL; |
| 2354 | |
Kristian Høgsberg | 880acbe | 2010-05-12 14:34:55 -0400 | [diff] [blame] | 2355 | memset(dri2_drv, 0, sizeof *dri2_drv); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 2356 | _eglInitDriverFallbacks(&dri2_drv->base); |
| 2357 | dri2_drv->base.API.Initialize = dri2_initialize; |
| 2358 | dri2_drv->base.API.Terminate = dri2_terminate; |
| 2359 | dri2_drv->base.API.CreateContext = dri2_create_context; |
| 2360 | dri2_drv->base.API.MakeCurrent = dri2_make_current; |
| 2361 | dri2_drv->base.API.CreateWindowSurface = dri2_create_window_surface; |
| 2362 | dri2_drv->base.API.CreatePixmapSurface = dri2_create_pixmap_surface; |
| 2363 | dri2_drv->base.API.CreatePbufferSurface = dri2_create_pbuffer_surface; |
| 2364 | dri2_drv->base.API.DestroySurface = dri2_destroy_surface; |
| 2365 | dri2_drv->base.API.SwapBuffers = dri2_swap_buffers; |
| 2366 | dri2_drv->base.API.GetProcAddress = dri2_get_proc_address; |
| 2367 | dri2_drv->base.API.WaitClient = dri2_wait_client; |
| 2368 | dri2_drv->base.API.WaitNative = dri2_wait_native; |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 2369 | dri2_drv->base.API.CopyBuffers = dri2_copy_buffers; |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 2370 | dri2_drv->base.API.BindTexImage = dri2_bind_tex_image; |
| 2371 | dri2_drv->base.API.ReleaseTexImage = dri2_release_tex_image; |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 2372 | dri2_drv->base.API.CreateImageKHR = dri2_create_image_khr; |
| 2373 | dri2_drv->base.API.DestroyImageKHR = dri2_destroy_image_khr; |
Kristian Høgsberg | 52c554a | 2010-05-06 22:01:35 -0400 | [diff] [blame] | 2374 | dri2_drv->base.API.SwapBuffersRegionNOK = dri2_swap_buffers_region; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 2375 | dri2_drv->base.API.CreateDRMImageMESA = dri2_create_drm_image_mesa; |
| 2376 | dri2_drv->base.API.ExportDRMImageMESA = dri2_export_drm_image_mesa; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 2377 | |
| 2378 | dri2_drv->base.Name = "DRI2"; |
| 2379 | dri2_drv->base.Unload = dri2_unload; |
| 2380 | |
Chia-I Wu | d18d0fd | 2010-04-06 19:52:39 +0800 | [diff] [blame] | 2381 | dri2_drv->glFlush = |
| 2382 | (void (*)(void)) dri2_get_proc_address(&dri2_drv->base, "glFlush"); |
| 2383 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 2384 | return &dri2_drv->base; |
| 2385 | } |