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> |
| 43 | |
| 44 | #include <glapi/glapi.h> |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 45 | #include "eglconfig.h" |
| 46 | #include "eglcontext.h" |
| 47 | #include "egldisplay.h" |
| 48 | #include "egldriver.h" |
| 49 | #include "eglcurrent.h" |
| 50 | #include "egllog.h" |
| 51 | #include "eglsurface.h" |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 52 | #include "eglimage.h" |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 53 | |
Kristian Høgsberg | 52c554a | 2010-05-06 22:01:35 -0400 | [diff] [blame] | 54 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) |
| 55 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 56 | struct dri2_egl_driver |
| 57 | { |
| 58 | _EGLDriver base; |
Chia-I Wu | d18d0fd | 2010-04-06 19:52:39 +0800 | [diff] [blame] | 59 | |
| 60 | void (*glFlush)(void); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | struct dri2_egl_display |
| 64 | { |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 65 | xcb_connection_t *conn; |
| 66 | int dri2_major; |
| 67 | int dri2_minor; |
| 68 | __DRIscreen *dri_screen; |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 69 | const __DRIconfig **driver_configs; |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 70 | void *driver; |
| 71 | __DRIcoreExtension *core; |
| 72 | __DRIdri2Extension *dri2; |
| 73 | __DRI2flushExtension *flush; |
| 74 | __DRItexBufferExtension *tex_buffer; |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 75 | __DRIimageExtension *image; |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 76 | int fd; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 77 | |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 78 | char *device_name; |
| 79 | char *driver_name; |
| 80 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 81 | __DRIdri2LoaderExtension loader_extension; |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 82 | __DRIimageLookupExtension image_lookup_extension; |
| 83 | const __DRIextension *extensions[3]; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | struct dri2_egl_context |
| 87 | { |
| 88 | _EGLContext base; |
| 89 | __DRIcontext *dri_context; |
| 90 | }; |
| 91 | |
| 92 | struct dri2_egl_surface |
| 93 | { |
| 94 | _EGLSurface base; |
| 95 | __DRIdrawable *dri_drawable; |
| 96 | xcb_drawable_t drawable; |
| 97 | __DRIbuffer buffers[5]; |
| 98 | int buffer_count; |
| 99 | xcb_xfixes_region_t region; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 100 | int have_fake_front; |
| 101 | int swap_interval; |
| 102 | }; |
| 103 | |
| 104 | struct dri2_egl_config |
| 105 | { |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 106 | _EGLConfig base; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 107 | const __DRIconfig *dri_config; |
| 108 | }; |
| 109 | |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 110 | struct dri2_egl_image |
| 111 | { |
| 112 | _EGLImage base; |
| 113 | __DRIimage *dri_image; |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 114 | }; |
| 115 | |
Chia-I Wu | a35e633 | 2010-02-05 11:38:34 +0800 | [diff] [blame] | 116 | /* standard typecasts */ |
| 117 | _EGL_DRIVER_STANDARD_TYPECASTS(dri2_egl) |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 118 | _EGL_DRIVER_TYPECAST(dri2_egl_image, _EGLImage, obj) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 119 | |
| 120 | EGLint dri2_to_egl_attribute_map[] = { |
| 121 | 0, |
| 122 | EGL_BUFFER_SIZE, /* __DRI_ATTRIB_BUFFER_SIZE */ |
| 123 | EGL_LEVEL, /* __DRI_ATTRIB_LEVEL */ |
| 124 | EGL_RED_SIZE, /* __DRI_ATTRIB_RED_SIZE */ |
| 125 | EGL_GREEN_SIZE, /* __DRI_ATTRIB_GREEN_SIZE */ |
| 126 | EGL_BLUE_SIZE, /* __DRI_ATTRIB_BLUE_SIZE */ |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 127 | EGL_LUMINANCE_SIZE, /* __DRI_ATTRIB_LUMINANCE_SIZE */ |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 128 | EGL_ALPHA_SIZE, /* __DRI_ATTRIB_ALPHA_SIZE */ |
| 129 | 0, /* __DRI_ATTRIB_ALPHA_MASK_SIZE */ |
| 130 | EGL_DEPTH_SIZE, /* __DRI_ATTRIB_DEPTH_SIZE */ |
| 131 | EGL_STENCIL_SIZE, /* __DRI_ATTRIB_STENCIL_SIZE */ |
| 132 | 0, /* __DRI_ATTRIB_ACCUM_RED_SIZE */ |
| 133 | 0, /* __DRI_ATTRIB_ACCUM_GREEN_SIZE */ |
| 134 | 0, /* __DRI_ATTRIB_ACCUM_BLUE_SIZE */ |
| 135 | 0, /* __DRI_ATTRIB_ACCUM_ALPHA_SIZE */ |
| 136 | EGL_SAMPLE_BUFFERS, /* __DRI_ATTRIB_SAMPLE_BUFFERS */ |
| 137 | EGL_SAMPLES, /* __DRI_ATTRIB_SAMPLES */ |
| 138 | 0, /* __DRI_ATTRIB_RENDER_TYPE, */ |
| 139 | 0, /* __DRI_ATTRIB_CONFIG_CAVEAT */ |
| 140 | 0, /* __DRI_ATTRIB_CONFORMANT */ |
| 141 | 0, /* __DRI_ATTRIB_DOUBLE_BUFFER */ |
| 142 | 0, /* __DRI_ATTRIB_STEREO */ |
| 143 | 0, /* __DRI_ATTRIB_AUX_BUFFERS */ |
| 144 | 0, /* __DRI_ATTRIB_TRANSPARENT_TYPE */ |
| 145 | 0, /* __DRI_ATTRIB_TRANSPARENT_INDEX_VALUE */ |
| 146 | 0, /* __DRI_ATTRIB_TRANSPARENT_RED_VALUE */ |
| 147 | 0, /* __DRI_ATTRIB_TRANSPARENT_GREEN_VALUE */ |
| 148 | 0, /* __DRI_ATTRIB_TRANSPARENT_BLUE_VALUE */ |
| 149 | 0, /* __DRI_ATTRIB_TRANSPARENT_ALPHA_VALUE */ |
| 150 | 0, /* __DRI_ATTRIB_FLOAT_MODE */ |
| 151 | 0, /* __DRI_ATTRIB_RED_MASK */ |
| 152 | 0, /* __DRI_ATTRIB_GREEN_MASK */ |
| 153 | 0, /* __DRI_ATTRIB_BLUE_MASK */ |
| 154 | 0, /* __DRI_ATTRIB_ALPHA_MASK */ |
| 155 | EGL_MAX_PBUFFER_WIDTH, /* __DRI_ATTRIB_MAX_PBUFFER_WIDTH */ |
| 156 | EGL_MAX_PBUFFER_HEIGHT, /* __DRI_ATTRIB_MAX_PBUFFER_HEIGHT */ |
| 157 | EGL_MAX_PBUFFER_PIXELS, /* __DRI_ATTRIB_MAX_PBUFFER_PIXELS */ |
| 158 | 0, /* __DRI_ATTRIB_OPTIMAL_PBUFFER_WIDTH */ |
| 159 | 0, /* __DRI_ATTRIB_OPTIMAL_PBUFFER_HEIGHT */ |
| 160 | 0, /* __DRI_ATTRIB_VISUAL_SELECT_GROUP */ |
| 161 | 0, /* __DRI_ATTRIB_SWAP_METHOD */ |
| 162 | EGL_MAX_SWAP_INTERVAL, /* __DRI_ATTRIB_MAX_SWAP_INTERVAL */ |
| 163 | EGL_MIN_SWAP_INTERVAL, /* __DRI_ATTRIB_MIN_SWAP_INTERVAL */ |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 164 | 0, /* __DRI_ATTRIB_BIND_TO_TEXTURE_RGB */ |
| 165 | 0, /* __DRI_ATTRIB_BIND_TO_TEXTURE_RGBA */ |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 166 | 0, /* __DRI_ATTRIB_BIND_TO_MIPMAP_TEXTURE */ |
| 167 | 0, /* __DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS */ |
Kristian Høgsberg | 5dc0f49 | 2010-05-06 22:40:25 -0400 | [diff] [blame^] | 168 | EGL_Y_INVERTED_NOK, /* __DRI_ATTRIB_YINVERTED */ |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 169 | }; |
| 170 | |
| 171 | static void |
Kristian Høgsberg | c3c1a7e | 2010-02-09 20:49:40 -0500 | [diff] [blame] | 172 | dri2_add_config(_EGLDisplay *disp, const __DRIconfig *dri_config, int id, |
| 173 | int depth, xcb_visualtype_t *visual) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 174 | { |
| 175 | struct dri2_egl_config *conf; |
| 176 | struct dri2_egl_display *dri2_dpy; |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 177 | _EGLConfig base; |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 178 | unsigned int attrib, value, double_buffer; |
| 179 | EGLint key, bind_to_texture_rgb, bind_to_texture_rgba; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 180 | int i; |
| 181 | |
| 182 | dri2_dpy = disp->DriverData; |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 183 | _eglInitConfig(&base, disp, id); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 184 | |
| 185 | i = 0; |
| 186 | while (dri2_dpy->core->indexConfigAttrib(dri_config, i++, &attrib, &value)) { |
| 187 | switch (attrib) { |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 188 | case __DRI_ATTRIB_RENDER_TYPE: |
| 189 | if (value & __DRI_ATTRIB_RGBA_BIT) |
| 190 | value = EGL_RGB_BUFFER; |
| 191 | else if (value & __DRI_ATTRIB_LUMINANCE_BIT) |
| 192 | value = EGL_LUMINANCE_BUFFER; |
| 193 | else |
| 194 | /* not valid */; |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 195 | _eglSetConfigKey(&base, EGL_COLOR_BUFFER_TYPE, value); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 196 | break; |
| 197 | |
| 198 | case __DRI_ATTRIB_CONFIG_CAVEAT: |
| 199 | if (value & __DRI_ATTRIB_NON_CONFORMANT_CONFIG) |
| 200 | value = EGL_NON_CONFORMANT_CONFIG; |
| 201 | else if (value & __DRI_ATTRIB_SLOW_BIT) |
| 202 | value = EGL_SLOW_CONFIG; |
| 203 | else |
| 204 | value = EGL_NONE; |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 205 | _eglSetConfigKey(&base, EGL_CONFIG_CAVEAT, value); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 206 | break; |
| 207 | |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 208 | case __DRI_ATTRIB_BIND_TO_TEXTURE_RGB: |
| 209 | bind_to_texture_rgb = value; |
| 210 | break; |
| 211 | |
| 212 | case __DRI_ATTRIB_BIND_TO_TEXTURE_RGBA: |
| 213 | bind_to_texture_rgba = value; |
| 214 | break; |
| 215 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 216 | case __DRI_ATTRIB_DOUBLE_BUFFER: |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 217 | double_buffer = value; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 218 | break; |
| 219 | |
| 220 | default: |
| 221 | key = dri2_to_egl_attribute_map[attrib]; |
| 222 | if (key != 0) |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 223 | _eglSetConfigKey(&base, key, value); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 224 | break; |
| 225 | } |
| 226 | } |
| 227 | |
Kristian Høgsberg | c3c1a7e | 2010-02-09 20:49:40 -0500 | [diff] [blame] | 228 | /* In EGL, double buffer or not isn't a config attribute. Pixmaps |
| 229 | * surfaces are always single buffered, pbuffer surfaces are always |
| 230 | * back buffers and windows can be either, selected by passing an |
| 231 | * attribute at window surface construction time. To support this |
| 232 | * we ignore all double buffer configs and manipulate the buffer we |
| 233 | * return in the getBuffer callback to get the behaviour we want. */ |
| 234 | |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 235 | if (double_buffer) |
Kristian Høgsberg | c3c1a7e | 2010-02-09 20:49:40 -0500 | [diff] [blame] | 236 | return; |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 237 | |
Kristian Høgsberg | c3c1a7e | 2010-02-09 20:49:40 -0500 | [diff] [blame] | 238 | if (visual != NULL) { |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 239 | if (depth != _eglGetConfigKey(&base, EGL_BUFFER_SIZE)) |
Kristian Høgsberg | c3c1a7e | 2010-02-09 20:49:40 -0500 | [diff] [blame] | 240 | return; |
Kristian Høgsberg | c3c1a7e | 2010-02-09 20:49:40 -0500 | [diff] [blame] | 241 | |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 242 | _eglSetConfigKey(&base, EGL_SURFACE_TYPE, |
| 243 | EGL_WINDOW_BIT | EGL_PIXMAP_BIT | EGL_PBUFFER_BIT | |
| 244 | EGL_SWAP_BEHAVIOR_PRESERVED_BIT); |
| 245 | |
| 246 | _eglSetConfigKey(&base, EGL_NATIVE_VISUAL_ID, visual->visual_id); |
| 247 | _eglSetConfigKey(&base, EGL_NATIVE_VISUAL_TYPE, visual->_class); |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 248 | } else { |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 249 | _eglSetConfigKey(&base, EGL_SURFACE_TYPE, |
Kristian Høgsberg | 360faf8 | 2010-02-09 16:06:23 -0500 | [diff] [blame] | 250 | EGL_PIXMAP_BIT | EGL_PBUFFER_BIT); |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 251 | } |
Kristian Høgsberg | c3c1a7e | 2010-02-09 20:49:40 -0500 | [diff] [blame] | 252 | |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 253 | _eglSetConfigKey(&base, EGL_NATIVE_RENDERABLE, EGL_TRUE); |
| 254 | _eglSetConfigKey(&base, EGL_BIND_TO_TEXTURE_RGB, bind_to_texture_rgb); |
| 255 | if (_eglGetConfigKey(&base, EGL_ALPHA_SIZE) > 0) |
| 256 | _eglSetConfigKey(&base, |
Kristian Høgsberg | c3c1a7e | 2010-02-09 20:49:40 -0500 | [diff] [blame] | 257 | EGL_BIND_TO_TEXTURE_RGBA, bind_to_texture_rgba); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 258 | |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 259 | _eglSetConfigKey(&base, EGL_RENDERABLE_TYPE, disp->ClientAPIsMask); |
| 260 | _eglSetConfigKey(&base, EGL_CONFORMANT, disp->ClientAPIsMask); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 261 | |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 262 | if (!_eglValidateConfig(&base, EGL_FALSE)) { |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 263 | _eglLog(_EGL_DEBUG, "DRI2: failed to validate config %d", id); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 264 | return; |
| 265 | } |
| 266 | |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 267 | conf = malloc(sizeof *conf); |
| 268 | if (conf != NULL) { |
| 269 | memcpy(&conf->base, &base, sizeof base); |
| 270 | conf->dri_config = dri_config; |
| 271 | _eglAddConfig(disp, &conf->base); |
| 272 | } |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | /** |
| 276 | * Process list of buffer received from the server |
| 277 | * |
| 278 | * Processes the list of buffers received in a reply from the server to either |
| 279 | * \c DRI2GetBuffers or \c DRI2GetBuffersWithFormat. |
| 280 | */ |
| 281 | static void |
| 282 | dri2_process_buffers(struct dri2_egl_surface *dri2_surf, |
| 283 | xcb_dri2_dri2_buffer_t *buffers, unsigned count) |
| 284 | { |
| 285 | struct dri2_egl_display *dri2_dpy = |
| 286 | dri2_egl_display(dri2_surf->base.Resource.Display); |
| 287 | xcb_rectangle_t rectangle; |
| 288 | int i; |
| 289 | |
| 290 | dri2_surf->buffer_count = count; |
| 291 | dri2_surf->have_fake_front = 0; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 292 | |
| 293 | /* This assumes the DRI2 buffer attachment tokens matches the |
| 294 | * __DRIbuffer tokens. */ |
| 295 | for (i = 0; i < count; i++) { |
| 296 | dri2_surf->buffers[i].attachment = buffers[i].attachment; |
| 297 | dri2_surf->buffers[i].name = buffers[i].name; |
| 298 | dri2_surf->buffers[i].pitch = buffers[i].pitch; |
| 299 | dri2_surf->buffers[i].cpp = buffers[i].cpp; |
| 300 | dri2_surf->buffers[i].flags = buffers[i].flags; |
Kristian Høgsberg | c3c1a7e | 2010-02-09 20:49:40 -0500 | [diff] [blame] | 301 | |
| 302 | /* We only use the DRI drivers single buffer configs. This |
| 303 | * means that if we try to render to a window, DRI2 will give us |
| 304 | * the fake front buffer, which we'll use as a back buffer. |
| 305 | * Note that EGL doesn't require that several clients rendering |
| 306 | * to the same window must see the same aux buffers. */ |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 307 | if (dri2_surf->buffers[i].attachment == __DRI_BUFFER_FAKE_FRONT_LEFT) |
| 308 | dri2_surf->have_fake_front = 1; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | if (dri2_surf->region != XCB_NONE) |
| 312 | xcb_xfixes_destroy_region(dri2_dpy->conn, dri2_surf->region); |
| 313 | |
| 314 | rectangle.x = 0; |
| 315 | rectangle.y = 0; |
| 316 | rectangle.width = dri2_surf->base.Width; |
| 317 | rectangle.height = dri2_surf->base.Height; |
| 318 | dri2_surf->region = xcb_generate_id(dri2_dpy->conn); |
| 319 | xcb_xfixes_create_region(dri2_dpy->conn, dri2_surf->region, 1, &rectangle); |
| 320 | } |
| 321 | |
| 322 | static __DRIbuffer * |
| 323 | dri2_get_buffers(__DRIdrawable * driDrawable, |
| 324 | int *width, int *height, |
| 325 | unsigned int *attachments, int count, |
| 326 | int *out_count, void *loaderPrivate) |
| 327 | { |
| 328 | struct dri2_egl_surface *dri2_surf = loaderPrivate; |
| 329 | struct dri2_egl_display *dri2_dpy = |
| 330 | dri2_egl_display(dri2_surf->base.Resource.Display); |
| 331 | xcb_dri2_dri2_buffer_t *buffers; |
| 332 | xcb_dri2_get_buffers_reply_t *reply; |
| 333 | xcb_dri2_get_buffers_cookie_t cookie; |
| 334 | |
| 335 | cookie = xcb_dri2_get_buffers_unchecked (dri2_dpy->conn, |
| 336 | dri2_surf->drawable, |
| 337 | count, count, attachments); |
| 338 | reply = xcb_dri2_get_buffers_reply (dri2_dpy->conn, cookie, NULL); |
| 339 | buffers = xcb_dri2_get_buffers_buffers (reply); |
| 340 | if (buffers == NULL) |
| 341 | return NULL; |
| 342 | |
| 343 | *out_count = reply->count; |
| 344 | dri2_surf->base.Width = *width = reply->width; |
| 345 | dri2_surf->base.Height = *height = reply->height; |
| 346 | dri2_process_buffers(dri2_surf, buffers, *out_count); |
| 347 | |
| 348 | free(reply); |
| 349 | |
| 350 | return dri2_surf->buffers; |
| 351 | } |
| 352 | |
| 353 | static void |
| 354 | dri2_flush_front_buffer(__DRIdrawable * driDrawable, void *loaderPrivate) |
| 355 | { |
| 356 | /* FIXME: Does EGL support front buffer rendering at all? */ |
| 357 | |
| 358 | #if 0 |
| 359 | struct dri2_egl_surface *dri2_surf = loaderPrivate; |
| 360 | |
| 361 | dri2WaitGL(dri2_surf); |
| 362 | #endif |
| 363 | } |
| 364 | |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 365 | static __DRIimage * |
| 366 | dri2_lookup_egl_image(__DRIcontext *context, void *image, void *data) |
| 367 | { |
| 368 | struct dri2_egl_context *dri2_ctx = data; |
| 369 | _EGLDisplay *disp = dri2_ctx->base.Resource.Display; |
| 370 | struct dri2_egl_image *dri2_img; |
| 371 | _EGLImage *img; |
| 372 | |
| 373 | img = _eglLookupImage(image, disp); |
| 374 | if (img == NULL) { |
| 375 | _eglError(EGL_BAD_PARAMETER, "dri2_lookup_egl_image"); |
| 376 | return NULL; |
| 377 | } |
| 378 | |
| 379 | dri2_img = dri2_egl_image(image); |
| 380 | |
| 381 | return dri2_img->dri_image; |
| 382 | } |
| 383 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 384 | static __DRIbuffer * |
| 385 | dri2_get_buffers_with_format(__DRIdrawable * driDrawable, |
| 386 | int *width, int *height, |
| 387 | unsigned int *attachments, int count, |
| 388 | int *out_count, void *loaderPrivate) |
| 389 | { |
| 390 | struct dri2_egl_surface *dri2_surf = loaderPrivate; |
| 391 | struct dri2_egl_display *dri2_dpy = |
| 392 | dri2_egl_display(dri2_surf->base.Resource.Display); |
| 393 | xcb_dri2_dri2_buffer_t *buffers; |
| 394 | xcb_dri2_get_buffers_with_format_reply_t *reply; |
| 395 | xcb_dri2_get_buffers_with_format_cookie_t cookie; |
| 396 | xcb_dri2_attach_format_t *format_attachments; |
| 397 | |
| 398 | format_attachments = (xcb_dri2_attach_format_t *) attachments; |
| 399 | cookie = xcb_dri2_get_buffers_with_format_unchecked (dri2_dpy->conn, |
| 400 | dri2_surf->drawable, |
| 401 | count, count, |
| 402 | format_attachments); |
| 403 | |
| 404 | reply = xcb_dri2_get_buffers_with_format_reply (dri2_dpy->conn, |
| 405 | cookie, NULL); |
| 406 | if (reply == NULL) |
| 407 | return NULL; |
| 408 | |
| 409 | buffers = xcb_dri2_get_buffers_with_format_buffers (reply); |
| 410 | dri2_surf->base.Width = *width = reply->width; |
| 411 | dri2_surf->base.Height = *height = reply->height; |
| 412 | *out_count = reply->count; |
| 413 | dri2_process_buffers(dri2_surf, buffers, *out_count); |
| 414 | |
| 415 | free(reply); |
| 416 | |
| 417 | return dri2_surf->buffers; |
| 418 | } |
| 419 | |
| 420 | #ifdef GLX_USE_TLS |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 421 | static const char dri_driver_format[] = "%.*s/tls/%s_dri.so"; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 422 | #else |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 423 | static const char dri_driver_format[] = "%.*s/%s_dri.so"; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 424 | #endif |
| 425 | |
| 426 | static const char dri_driver_path[] = DEFAULT_DRIVER_DIR; |
| 427 | |
Kristian Høgsberg | 8c593d3 | 2010-02-09 10:57:43 -0500 | [diff] [blame] | 428 | struct dri2_extension_match { |
| 429 | const char *name; |
| 430 | int version; |
| 431 | int offset; |
| 432 | }; |
| 433 | |
| 434 | static struct dri2_extension_match dri2_driver_extensions[] = { |
| 435 | { __DRI_CORE, 1, offsetof(struct dri2_egl_display, core) }, |
| 436 | { __DRI_DRI2, 1, offsetof(struct dri2_egl_display, dri2) }, |
| 437 | { NULL } |
| 438 | }; |
| 439 | |
| 440 | static struct dri2_extension_match dri2_core_extensions[] = { |
| 441 | { __DRI2_FLUSH, 1, offsetof(struct dri2_egl_display, flush) }, |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 442 | { __DRI_TEX_BUFFER, 2, offsetof(struct dri2_egl_display, tex_buffer) }, |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 443 | { __DRI_IMAGE, 1, offsetof(struct dri2_egl_display, image) }, |
Kristian Høgsberg | 8c593d3 | 2010-02-09 10:57:43 -0500 | [diff] [blame] | 444 | { NULL } |
| 445 | }; |
| 446 | |
| 447 | static EGLBoolean |
| 448 | dri2_bind_extensions(struct dri2_egl_display *dri2_dpy, |
| 449 | struct dri2_extension_match *matches, |
| 450 | const __DRIextension **extensions) |
| 451 | { |
| 452 | int i, j, ret = EGL_TRUE; |
| 453 | void *field; |
| 454 | |
| 455 | for (i = 0; extensions[i]; i++) { |
| 456 | _eglLog(_EGL_DEBUG, "DRI2: found extension `%s'", extensions[i]->name); |
| 457 | for (j = 0; matches[j].name; j++) { |
| 458 | if (strcmp(extensions[i]->name, matches[j].name) == 0 && |
| 459 | extensions[i]->version >= matches[j].version) { |
| 460 | field = ((char *) dri2_dpy + matches[j].offset); |
| 461 | *(const __DRIextension **) field = extensions[i]; |
| 462 | _eglLog(_EGL_INFO, "DRI2: found extension %s version %d", |
| 463 | extensions[i]->name, extensions[i]->version); |
| 464 | } |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | for (j = 0; matches[j].name; j++) { |
| 469 | field = ((char *) dri2_dpy + matches[j].offset); |
| 470 | if (*(const __DRIextension **) field == NULL) { |
| 471 | _eglLog(_EGL_FATAL, "DRI2: did not find extension %s version %d", |
| 472 | matches[j].name, matches[j].version); |
| 473 | ret = EGL_FALSE; |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | return ret; |
| 478 | } |
| 479 | |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 480 | static char * |
| 481 | dri2_strndup(const char *s, int length) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 482 | { |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 483 | char *d; |
| 484 | |
| 485 | d = malloc(length + 1); |
| 486 | if (d == NULL) |
| 487 | return NULL; |
| 488 | |
| 489 | memcpy(d, s, length); |
| 490 | d[length] = '\0'; |
| 491 | |
| 492 | return d; |
| 493 | } |
| 494 | |
| 495 | static EGLBoolean |
| 496 | dri2_connect(struct dri2_egl_display *dri2_dpy) |
| 497 | { |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 498 | xcb_xfixes_query_version_reply_t *xfixes_query; |
| 499 | xcb_xfixes_query_version_cookie_t xfixes_query_cookie; |
| 500 | xcb_dri2_query_version_reply_t *dri2_query; |
| 501 | xcb_dri2_query_version_cookie_t dri2_query_cookie; |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 502 | xcb_dri2_connect_reply_t *connect; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 503 | xcb_dri2_connect_cookie_t connect_cookie; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 504 | xcb_generic_error_t *error; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 505 | xcb_screen_iterator_t s; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 506 | |
| 507 | xcb_prefetch_extension_data (dri2_dpy->conn, &xcb_xfixes_id); |
| 508 | xcb_prefetch_extension_data (dri2_dpy->conn, &xcb_dri2_id); |
| 509 | |
| 510 | xfixes_query_cookie = xcb_xfixes_query_version(dri2_dpy->conn, |
| 511 | XCB_XFIXES_MAJOR_VERSION, |
| 512 | XCB_XFIXES_MINOR_VERSION); |
| 513 | |
| 514 | dri2_query_cookie = xcb_dri2_query_version (dri2_dpy->conn, |
| 515 | XCB_DRI2_MAJOR_VERSION, |
| 516 | XCB_DRI2_MINOR_VERSION); |
| 517 | |
| 518 | s = xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy->conn)); |
| 519 | connect_cookie = xcb_dri2_connect_unchecked (dri2_dpy->conn, |
| 520 | s.data->root, |
| 521 | XCB_DRI2_DRIVER_TYPE_DRI); |
| 522 | |
| 523 | xfixes_query = |
| 524 | xcb_xfixes_query_version_reply (dri2_dpy->conn, |
| 525 | xfixes_query_cookie, &error); |
| 526 | if (xfixes_query == NULL || |
| 527 | error != NULL || xfixes_query->major_version < 2) { |
| 528 | _eglLog(_EGL_FATAL, "DRI2: failed to query xfixes version"); |
| 529 | free(error); |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 530 | return EGL_FALSE; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 531 | } |
| 532 | free(xfixes_query); |
| 533 | |
| 534 | dri2_query = |
| 535 | xcb_dri2_query_version_reply (dri2_dpy->conn, dri2_query_cookie, &error); |
| 536 | if (dri2_query == NULL || error != NULL) { |
| 537 | _eglLog(_EGL_FATAL, "DRI2: failed to query version"); |
| 538 | free(error); |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 539 | return EGL_FALSE; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 540 | } |
| 541 | dri2_dpy->dri2_major = dri2_query->major_version; |
| 542 | dri2_dpy->dri2_minor = dri2_query->minor_version; |
| 543 | free(dri2_query); |
| 544 | |
| 545 | connect = xcb_dri2_connect_reply (dri2_dpy->conn, connect_cookie, NULL); |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 546 | if (connect == NULL || |
| 547 | connect->driver_name_length + connect->device_name_length == 0) { |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 548 | _eglLog(_EGL_FATAL, "DRI2: failed to authenticate"); |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 549 | return EGL_FALSE; |
| 550 | } |
| 551 | |
| 552 | dri2_dpy->device_name = |
| 553 | dri2_strndup(xcb_dri2_connect_device_name (connect), |
| 554 | xcb_dri2_connect_device_name_length (connect)); |
| 555 | |
| 556 | dri2_dpy->driver_name = |
| 557 | dri2_strndup(xcb_dri2_connect_driver_name (connect), |
| 558 | xcb_dri2_connect_driver_name_length (connect)); |
| 559 | |
| 560 | if (dri2_dpy->device_name == NULL || dri2_dpy->driver_name == NULL) { |
| 561 | free(dri2_dpy->device_name); |
| 562 | free(dri2_dpy->driver_name); |
| 563 | free(connect); |
| 564 | return EGL_FALSE; |
| 565 | } |
| 566 | free(connect); |
| 567 | |
| 568 | return EGL_TRUE; |
| 569 | } |
| 570 | |
| 571 | static EGLBoolean |
| 572 | dri2_authenticate(struct dri2_egl_display *dri2_dpy) |
| 573 | { |
| 574 | xcb_dri2_authenticate_reply_t *authenticate; |
| 575 | xcb_dri2_authenticate_cookie_t authenticate_cookie; |
| 576 | xcb_screen_iterator_t s; |
| 577 | drm_magic_t magic; |
| 578 | |
| 579 | if (drmGetMagic(dri2_dpy->fd, &magic)) { |
| 580 | _eglLog(_EGL_FATAL, "DRI2: failed to get drm magic"); |
| 581 | return EGL_FALSE; |
| 582 | } |
| 583 | |
| 584 | s = xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy->conn)); |
| 585 | authenticate_cookie = |
| 586 | xcb_dri2_authenticate_unchecked(dri2_dpy->conn, s.data->root, magic); |
| 587 | authenticate = |
| 588 | xcb_dri2_authenticate_reply(dri2_dpy->conn, authenticate_cookie, NULL); |
| 589 | if (authenticate == NULL || !authenticate->authenticated) { |
| 590 | _eglLog(_EGL_FATAL, "DRI2: failed to authenticate"); |
| 591 | free(authenticate); |
| 592 | return EGL_FALSE; |
| 593 | } |
| 594 | |
| 595 | free(authenticate); |
| 596 | |
| 597 | return EGL_TRUE; |
| 598 | } |
| 599 | |
| 600 | static EGLBoolean |
| 601 | dri2_add_configs_for_visuals(struct dri2_egl_display *dri2_dpy, |
| 602 | _EGLDisplay *disp) |
| 603 | { |
| 604 | xcb_screen_iterator_t s; |
| 605 | xcb_depth_iterator_t d; |
| 606 | xcb_visualtype_t *visuals; |
| 607 | int i, j, id; |
| 608 | |
| 609 | s = xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy->conn)); |
| 610 | d = xcb_screen_allowed_depths_iterator(s.data); |
| 611 | id = 1; |
| 612 | while (d.rem > 0) { |
| 613 | EGLBoolean class_added[6] = { 0, }; |
| 614 | |
| 615 | visuals = xcb_depth_visuals(d.data); |
| 616 | for (i = 0; i < xcb_depth_visuals_length(d.data); i++) { |
| 617 | if (class_added[visuals[i]._class]) |
| 618 | continue; |
| 619 | |
| 620 | class_added[visuals[i]._class] = EGL_TRUE; |
| 621 | for (j = 0; dri2_dpy->driver_configs[j]; j++) |
| 622 | dri2_add_config(disp, dri2_dpy->driver_configs[j], |
| 623 | id++, d.data->depth, &visuals[i]); |
| 624 | } |
| 625 | |
| 626 | xcb_depth_next(&d); |
| 627 | } |
| 628 | |
| 629 | if (!disp->NumConfigs) { |
| 630 | _eglLog(_EGL_WARNING, "DRI2: failed to create any config"); |
| 631 | return EGL_FALSE; |
| 632 | } |
| 633 | |
| 634 | return EGL_TRUE; |
| 635 | } |
| 636 | |
| 637 | /** |
| 638 | * Called via eglInitialize(), GLX_drv->API.Initialize(). |
| 639 | */ |
| 640 | static EGLBoolean |
| 641 | dri2_initialize(_EGLDriver *drv, _EGLDisplay *disp, |
| 642 | EGLint *major, EGLint *minor) |
| 643 | { |
| 644 | const __DRIextension **extensions; |
| 645 | struct dri2_egl_display *dri2_dpy; |
| 646 | char path[PATH_MAX], *search_paths, *p, *next, *end; |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 647 | unsigned int api_mask; |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 648 | |
| 649 | dri2_dpy = malloc(sizeof *dri2_dpy); |
| 650 | if (!dri2_dpy) |
| 651 | return _eglError(EGL_BAD_ALLOC, "eglInitialize"); |
| 652 | |
| 653 | disp->DriverData = (void *) dri2_dpy; |
| 654 | if (disp->NativeDisplay == NULL) { |
| 655 | dri2_dpy->conn = xcb_connect(0, 0); |
| 656 | if (!dri2_dpy->conn) { |
| 657 | _eglLog(_EGL_WARNING, "DRI2: xcb_connect failed"); |
| 658 | goto cleanup_dpy; |
| 659 | } |
| 660 | } else { |
| 661 | dri2_dpy->conn = XGetXCBConnection(disp->NativeDisplay); |
| 662 | } |
| 663 | |
| 664 | if (dri2_dpy->conn == NULL) |
| 665 | goto cleanup_conn; |
| 666 | |
| 667 | if (dri2_dpy->conn) { |
| 668 | if (!dri2_connect(dri2_dpy)) |
| 669 | goto cleanup_conn; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | search_paths = NULL; |
| 673 | if (geteuid() == getuid()) { |
| 674 | /* don't allow setuid apps to use LIBGL_DRIVERS_PATH */ |
| 675 | search_paths = getenv("LIBGL_DRIVERS_PATH"); |
| 676 | } |
| 677 | if (search_paths == NULL) |
| 678 | search_paths = DEFAULT_DRIVER_DIR; |
| 679 | |
| 680 | dri2_dpy->driver = NULL; |
| 681 | end = search_paths + strlen(search_paths); |
| 682 | for (p = search_paths; p < end && dri2_dpy->driver == NULL; p = next + 1) { |
| 683 | next = strchr(p, ':'); |
| 684 | if (next == NULL) |
| 685 | next = end; |
| 686 | |
| 687 | snprintf(path, sizeof path, |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 688 | dri_driver_format, (int) (next - p), p, dri2_dpy->driver_name); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 689 | dri2_dpy->driver = dlopen(path, RTLD_NOW | RTLD_GLOBAL); |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 690 | if (dri2_dpy->driver == NULL) |
| 691 | _eglLog(_EGL_DEBUG, "failed to open %s: %s\n", path, dlerror()); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | if (dri2_dpy->driver == NULL) { |
Kristian Høgsberg | 7413d9a | 2010-05-13 15:42:51 -0400 | [diff] [blame] | 695 | _eglLog(_EGL_WARNING, |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 696 | "DRI2: failed to open any driver (search paths %s)", |
| 697 | search_paths); |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 698 | goto cleanup_conn; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | _eglLog(_EGL_DEBUG, "DRI2: dlopen(%s)", path); |
| 702 | extensions = dlsym(dri2_dpy->driver, __DRI_DRIVER_EXTENSIONS); |
| 703 | if (extensions == NULL) { |
Kristian Høgsberg | 7413d9a | 2010-05-13 15:42:51 -0400 | [diff] [blame] | 704 | _eglLog(_EGL_WARNING, |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 705 | "DRI2: driver exports no extensions (%s)", dlerror()); |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 706 | goto cleanup_driver; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 707 | } |
| 708 | |
Kristian Høgsberg | 8c593d3 | 2010-02-09 10:57:43 -0500 | [diff] [blame] | 709 | if (!dri2_bind_extensions(dri2_dpy, dri2_driver_extensions, extensions)) |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 710 | goto cleanup_driver; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 711 | |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 712 | dri2_dpy->fd = open(dri2_dpy->device_name, O_RDWR); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 713 | if (dri2_dpy->fd == -1) { |
Kristian Høgsberg | 7413d9a | 2010-05-13 15:42:51 -0400 | [diff] [blame] | 714 | _eglLog(_EGL_WARNING, |
Micah Fedke | 9cfaaa2 | 2010-04-28 07:25:58 -0600 | [diff] [blame] | 715 | "DRI2: could not open %s (%s)", dri2_dpy->device_name, |
| 716 | strerror(errno)); |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 717 | goto cleanup_driver; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 718 | } |
| 719 | |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 720 | if (dri2_dpy->conn) { |
| 721 | if (!dri2_authenticate(dri2_dpy)) |
| 722 | goto cleanup_fd; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 723 | } |
| 724 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 725 | if (dri2_dpy->dri2_minor >= 1) { |
| 726 | dri2_dpy->loader_extension.base.name = __DRI_DRI2_LOADER; |
| 727 | dri2_dpy->loader_extension.base.version = 3; |
| 728 | dri2_dpy->loader_extension.getBuffers = dri2_get_buffers; |
| 729 | dri2_dpy->loader_extension.flushFrontBuffer = dri2_flush_front_buffer; |
| 730 | dri2_dpy->loader_extension.getBuffersWithFormat = |
| 731 | dri2_get_buffers_with_format; |
| 732 | } else { |
| 733 | dri2_dpy->loader_extension.base.name = __DRI_DRI2_LOADER; |
| 734 | dri2_dpy->loader_extension.base.version = 2; |
| 735 | dri2_dpy->loader_extension.getBuffers = dri2_get_buffers; |
| 736 | dri2_dpy->loader_extension.flushFrontBuffer = dri2_flush_front_buffer; |
| 737 | dri2_dpy->loader_extension.getBuffersWithFormat = NULL; |
| 738 | } |
| 739 | |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 740 | dri2_dpy->image_lookup_extension.base.name = __DRI_IMAGE_LOOKUP; |
| 741 | dri2_dpy->image_lookup_extension.base.version = 1; |
| 742 | dri2_dpy->image_lookup_extension.lookupEGLImage = dri2_lookup_egl_image; |
| 743 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 744 | dri2_dpy->extensions[0] = &dri2_dpy->loader_extension.base; |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 745 | dri2_dpy->extensions[1] = &dri2_dpy->image_lookup_extension.base; |
| 746 | dri2_dpy->extensions[2] = NULL; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 747 | |
| 748 | dri2_dpy->dri_screen = |
| 749 | dri2_dpy->dri2->createNewScreen(0, dri2_dpy->fd, dri2_dpy->extensions, |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 750 | &dri2_dpy->driver_configs, dri2_dpy); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 751 | |
| 752 | if (dri2_dpy->dri_screen == NULL) { |
Kristian Høgsberg | 7413d9a | 2010-05-13 15:42:51 -0400 | [diff] [blame] | 753 | _eglLog(_EGL_WARNING, "DRI2: failed to create dri screen"); |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 754 | goto cleanup_fd; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | extensions = dri2_dpy->core->getExtensions(dri2_dpy->dri_screen); |
Kristian Høgsberg | 8c593d3 | 2010-02-09 10:57:43 -0500 | [diff] [blame] | 758 | if (!dri2_bind_extensions(dri2_dpy, dri2_core_extensions, extensions)) |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 759 | goto cleanup_dri_screen; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 760 | |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 761 | if (dri2_dpy->dri2->base.version >= 2) |
| 762 | api_mask = dri2_dpy->dri2->getAPIMask(dri2_dpy->dri_screen); |
| 763 | else |
| 764 | api_mask = __DRI_API_OPENGL; |
| 765 | |
| 766 | disp->ClientAPIsMask = 0; |
| 767 | if (api_mask & (1 <<__DRI_API_OPENGL)) |
| 768 | disp->ClientAPIsMask |= EGL_OPENGL_BIT; |
| 769 | if (api_mask & (1 <<__DRI_API_GLES)) |
| 770 | disp->ClientAPIsMask |= EGL_OPENGL_ES_BIT; |
| 771 | if (api_mask & (1 << __DRI_API_GLES2)) |
| 772 | disp->ClientAPIsMask |= EGL_OPENGL_ES2_BIT; |
| 773 | |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 774 | if (dri2_dpy->conn) { |
| 775 | if (!dri2_add_configs_for_visuals(dri2_dpy, disp)) |
| 776 | goto cleanup_configs; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 777 | } |
| 778 | |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 779 | disp->Extensions.KHR_image_base = EGL_TRUE; |
| 780 | disp->Extensions.KHR_image_pixmap = EGL_TRUE; |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 781 | disp->Extensions.KHR_gl_renderbuffer_image = EGL_TRUE; |
Kristian Høgsberg | 3a82c8c | 2010-04-14 16:22:27 -0400 | [diff] [blame] | 782 | disp->Extensions.KHR_gl_texture_2D_image = EGL_TRUE; |
Kristian Høgsberg | 52c554a | 2010-05-06 22:01:35 -0400 | [diff] [blame] | 783 | disp->Extensions.NOK_swap_region = EGL_TRUE; |
Kristian Høgsberg | 5dc0f49 | 2010-05-06 22:40:25 -0400 | [diff] [blame^] | 784 | disp->Extensions.NOK_texture_from_pixmap = EGL_TRUE; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 785 | |
| 786 | /* we're supporting EGL 1.4 */ |
| 787 | *major = 1; |
| 788 | *minor = 4; |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 789 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 790 | return EGL_TRUE; |
| 791 | |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 792 | cleanup_configs: |
| 793 | _eglCleanupDisplay(disp); |
| 794 | cleanup_dri_screen: |
| 795 | dri2_dpy->core->destroyScreen(dri2_dpy->dri_screen); |
| 796 | cleanup_fd: |
| 797 | close(dri2_dpy->fd); |
| 798 | cleanup_driver: |
| 799 | dlclose(dri2_dpy->driver); |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 800 | cleanup_conn: |
| 801 | if (disp->NativeDisplay == NULL) |
| 802 | xcb_disconnect(dri2_dpy->conn); |
| 803 | cleanup_dpy: |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 804 | free(dri2_dpy); |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 805 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 806 | return EGL_FALSE; |
| 807 | } |
| 808 | |
| 809 | /** |
| 810 | * Called via eglTerminate(), drv->API.Terminate(). |
| 811 | */ |
| 812 | static EGLBoolean |
| 813 | dri2_terminate(_EGLDriver *drv, _EGLDisplay *disp) |
| 814 | { |
| 815 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 816 | |
| 817 | _eglReleaseDisplayResources(drv, disp); |
| 818 | _eglCleanupDisplay(disp); |
| 819 | |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 820 | dri2_dpy->core->destroyScreen(dri2_dpy->dri_screen); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 821 | close(dri2_dpy->fd); |
| 822 | dlclose(dri2_dpy->driver); |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 823 | if (disp->NativeDisplay == NULL) |
| 824 | xcb_disconnect(dri2_dpy->conn); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 825 | free(dri2_dpy); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 826 | disp->DriverData = NULL; |
| 827 | |
| 828 | return EGL_TRUE; |
| 829 | } |
| 830 | |
| 831 | |
| 832 | /** |
| 833 | * Called via eglCreateContext(), drv->API.CreateContext(). |
| 834 | */ |
| 835 | static _EGLContext * |
| 836 | dri2_create_context(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf, |
| 837 | _EGLContext *share_list, const EGLint *attrib_list) |
| 838 | { |
| 839 | struct dri2_egl_context *dri2_ctx; |
| 840 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 841 | struct dri2_egl_context *dri2_ctx_shared = dri2_egl_context(share_list); |
| 842 | struct dri2_egl_config *dri2_config = dri2_egl_config(conf); |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 843 | int api; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 844 | |
| 845 | dri2_ctx = malloc(sizeof *dri2_ctx); |
| 846 | if (!dri2_ctx) { |
| 847 | _eglError(EGL_BAD_ALLOC, "eglCreateContext"); |
| 848 | return NULL; |
| 849 | } |
| 850 | |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 851 | if (!_eglInitContext(&dri2_ctx->base, disp, conf, attrib_list)) |
| 852 | goto cleanup; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 853 | |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 854 | switch (dri2_ctx->base.ClientAPI) { |
| 855 | case EGL_OPENGL_ES_API: |
| 856 | switch (dri2_ctx->base.ClientVersion) { |
| 857 | case 1: |
| 858 | api = __DRI_API_GLES; |
| 859 | break; |
| 860 | case 2: |
| 861 | api = __DRI_API_GLES2; |
| 862 | break; |
| 863 | default: |
| 864 | _eglError(EGL_BAD_PARAMETER, "eglCreateContext"); |
| 865 | return NULL; |
| 866 | } |
| 867 | break; |
| 868 | case EGL_OPENGL_API: |
| 869 | api = __DRI_API_OPENGL; |
| 870 | break; |
| 871 | default: |
| 872 | _eglError(EGL_BAD_PARAMETER, "eglCreateContext"); |
| 873 | return NULL; |
| 874 | } |
| 875 | |
| 876 | if (dri2_dpy->dri2->base.version >= 2) { |
| 877 | dri2_ctx->dri_context = |
| 878 | dri2_dpy->dri2->createNewContextForAPI(dri2_dpy->dri_screen, |
| 879 | api, |
| 880 | dri2_config->dri_config, |
| 881 | dri2_ctx_shared ? |
| 882 | dri2_ctx_shared->dri_context : NULL, |
| 883 | dri2_ctx); |
| 884 | } else if (api == __DRI_API_OPENGL) { |
| 885 | dri2_ctx->dri_context = |
| 886 | dri2_dpy->dri2->createNewContext(dri2_dpy->dri_screen, |
| 887 | dri2_config->dri_config, |
| 888 | dri2_ctx_shared ? |
| 889 | dri2_ctx_shared->dri_context : NULL, |
| 890 | dri2_ctx); |
| 891 | } else { |
| 892 | /* fail */ |
| 893 | } |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 894 | |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 895 | if (!dri2_ctx->dri_context) |
| 896 | goto cleanup; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 897 | |
| 898 | return &dri2_ctx->base; |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 899 | |
| 900 | cleanup: |
| 901 | free(dri2_ctx); |
| 902 | return NULL; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | static EGLBoolean |
| 906 | dri2_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf) |
| 907 | { |
| 908 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 909 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); |
| 910 | |
| 911 | if (_eglIsSurfaceBound(surf)) |
| 912 | return EGL_TRUE; |
| 913 | |
| 914 | (*dri2_dpy->core->destroyDrawable)(dri2_surf->dri_drawable); |
| 915 | |
| 916 | xcb_dri2_destroy_drawable (dri2_dpy->conn, dri2_surf->drawable); |
| 917 | |
| 918 | if (surf->Type == EGL_PBUFFER_BIT) |
| 919 | xcb_free_pixmap (dri2_dpy->conn, dri2_surf->drawable); |
| 920 | |
| 921 | free(surf); |
| 922 | |
| 923 | return EGL_TRUE; |
| 924 | } |
| 925 | |
| 926 | /** |
| 927 | * Called via eglMakeCurrent(), drv->API.MakeCurrent(). |
| 928 | */ |
| 929 | static EGLBoolean |
| 930 | dri2_make_current(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *dsurf, |
| 931 | _EGLSurface *rsurf, _EGLContext *ctx) |
| 932 | { |
Chia-I Wu | d18d0fd | 2010-04-06 19:52:39 +0800 | [diff] [blame] | 933 | struct dri2_egl_driver *dri2_drv = dri2_egl_driver(drv); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 934 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 935 | struct dri2_egl_surface *dri2_dsurf = dri2_egl_surface(dsurf); |
| 936 | struct dri2_egl_surface *dri2_rsurf = dri2_egl_surface(rsurf); |
| 937 | struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); |
| 938 | __DRIdrawable *ddraw, *rdraw; |
| 939 | __DRIcontext *cctx; |
| 940 | |
| 941 | /* bind the new context and return the "orphaned" one */ |
| 942 | if (!_eglBindContext(&ctx, &dsurf, &rsurf)) |
| 943 | return EGL_FALSE; |
| 944 | |
Chia-I Wu | d18d0fd | 2010-04-06 19:52:39 +0800 | [diff] [blame] | 945 | /* flush before context switch */ |
| 946 | if (ctx && dri2_drv->glFlush) |
| 947 | dri2_drv->glFlush(); |
| 948 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 949 | ddraw = (dri2_dsurf) ? dri2_dsurf->dri_drawable : NULL; |
| 950 | rdraw = (dri2_rsurf) ? dri2_rsurf->dri_drawable : NULL; |
| 951 | cctx = (dri2_ctx) ? dri2_ctx->dri_context : NULL; |
| 952 | |
| 953 | if ((cctx == NULL && ddraw == NULL && rdraw == NULL) || |
| 954 | dri2_dpy->core->bindContext(cctx, ddraw, rdraw)) { |
Chia-I Wu | fc5ca85 | 2010-02-05 11:27:55 +0800 | [diff] [blame] | 955 | if (dsurf && !_eglIsSurfaceLinked(dsurf)) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 956 | dri2_destroy_surface(drv, disp, dsurf); |
Chia-I Wu | fc5ca85 | 2010-02-05 11:27:55 +0800 | [diff] [blame] | 957 | if (rsurf && rsurf != dsurf && !_eglIsSurfaceLinked(dsurf)) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 958 | dri2_destroy_surface(drv, disp, rsurf); |
Chia-I Wu | fc5ca85 | 2010-02-05 11:27:55 +0800 | [diff] [blame] | 959 | if (ctx != NULL && !_eglIsContextLinked(ctx)) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 960 | dri2_dpy->core->unbindContext(dri2_egl_context(ctx)->dri_context); |
| 961 | |
| 962 | return EGL_TRUE; |
| 963 | } else { |
| 964 | _eglBindContext(&ctx, &dsurf, &rsurf); |
| 965 | |
| 966 | return EGL_FALSE; |
| 967 | } |
| 968 | } |
| 969 | |
| 970 | /** |
| 971 | * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface(). |
| 972 | */ |
| 973 | static _EGLSurface * |
| 974 | dri2_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type, |
| 975 | _EGLConfig *conf, EGLNativeWindowType window, |
| 976 | const EGLint *attrib_list) |
| 977 | { |
| 978 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 979 | struct dri2_egl_config *dri2_conf = dri2_egl_config(conf); |
| 980 | struct dri2_egl_surface *dri2_surf; |
| 981 | xcb_get_geometry_cookie_t cookie; |
| 982 | xcb_get_geometry_reply_t *reply; |
| 983 | xcb_screen_iterator_t s; |
| 984 | xcb_generic_error_t *error; |
| 985 | |
| 986 | dri2_surf = malloc(sizeof *dri2_surf); |
| 987 | if (!dri2_surf) { |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 988 | _eglError(EGL_BAD_ALLOC, "dri2_create_surface"); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 989 | return NULL; |
| 990 | } |
| 991 | |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 992 | if (!_eglInitSurface(&dri2_surf->base, disp, type, conf, attrib_list)) |
| 993 | goto cleanup_surf; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 994 | |
| 995 | dri2_surf->region = XCB_NONE; |
| 996 | if (type == EGL_PBUFFER_BIT) { |
| 997 | dri2_surf->drawable = xcb_generate_id(dri2_dpy->conn); |
| 998 | s = xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy->conn)); |
| 999 | xcb_create_pixmap(dri2_dpy->conn, |
| 1000 | _eglGetConfigKey(conf, EGL_BUFFER_SIZE), |
| 1001 | dri2_surf->drawable, s.data->root, |
| 1002 | dri2_surf->base.Width, dri2_surf->base.Height); |
| 1003 | } else { |
| 1004 | dri2_surf->drawable = window; |
| 1005 | } |
| 1006 | |
| 1007 | dri2_surf->dri_drawable = |
| 1008 | (*dri2_dpy->dri2->createNewDrawable) (dri2_dpy->dri_screen, |
| 1009 | dri2_conf->dri_config, dri2_surf); |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 1010 | if (dri2_surf->dri_drawable == NULL) { |
| 1011 | _eglError(EGL_BAD_ALLOC, "dri2->createNewDrawable"); |
| 1012 | goto cleanup_pixmap; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | xcb_dri2_create_drawable (dri2_dpy->conn, dri2_surf->drawable); |
| 1016 | |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 1017 | if (type != EGL_PBUFFER_BIT) { |
| 1018 | cookie = xcb_get_geometry (dri2_dpy->conn, dri2_surf->drawable); |
| 1019 | reply = xcb_get_geometry_reply (dri2_dpy->conn, cookie, &error); |
| 1020 | if (reply == NULL || error != NULL) { |
| 1021 | _eglError(EGL_BAD_ALLOC, "xcb_get_geometry"); |
| 1022 | free(error); |
| 1023 | goto cleanup_dri_drawable; |
| 1024 | } |
| 1025 | |
| 1026 | dri2_surf->base.Width = reply->width; |
| 1027 | dri2_surf->base.Height = reply->height; |
| 1028 | free(reply); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1029 | } |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1030 | |
| 1031 | return &dri2_surf->base; |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 1032 | |
| 1033 | cleanup_dri_drawable: |
| 1034 | dri2_dpy->core->destroyDrawable(dri2_surf->dri_drawable); |
| 1035 | cleanup_pixmap: |
| 1036 | if (type == EGL_PBUFFER_BIT) |
| 1037 | xcb_free_pixmap(dri2_dpy->conn, dri2_surf->drawable); |
| 1038 | cleanup_surf: |
| 1039 | free(dri2_surf); |
| 1040 | |
| 1041 | return NULL; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | /** |
| 1045 | * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface(). |
| 1046 | */ |
| 1047 | static _EGLSurface * |
| 1048 | dri2_create_window_surface(_EGLDriver *drv, _EGLDisplay *disp, |
| 1049 | _EGLConfig *conf, EGLNativeWindowType window, |
| 1050 | const EGLint *attrib_list) |
| 1051 | { |
| 1052 | return dri2_create_surface(drv, disp, EGL_WINDOW_BIT, conf, |
| 1053 | window, attrib_list); |
| 1054 | } |
| 1055 | |
| 1056 | static _EGLSurface * |
| 1057 | dri2_create_pixmap_surface(_EGLDriver *drv, _EGLDisplay *disp, |
| 1058 | _EGLConfig *conf, EGLNativePixmapType pixmap, |
| 1059 | const EGLint *attrib_list) |
| 1060 | { |
| 1061 | return dri2_create_surface(drv, disp, EGL_PIXMAP_BIT, conf, |
| 1062 | pixmap, attrib_list); |
| 1063 | } |
| 1064 | |
| 1065 | static _EGLSurface * |
| 1066 | dri2_create_pbuffer_surface(_EGLDriver *drv, _EGLDisplay *disp, |
| 1067 | _EGLConfig *conf, const EGLint *attrib_list) |
| 1068 | { |
| 1069 | return dri2_create_surface(drv, disp, EGL_PBUFFER_BIT, conf, |
| 1070 | XCB_WINDOW_NONE, attrib_list); |
| 1071 | } |
| 1072 | |
| 1073 | static EGLBoolean |
Kristian Høgsberg | 52c554a | 2010-05-06 22:01:35 -0400 | [diff] [blame] | 1074 | dri2_copy_region(_EGLDriver *drv, _EGLDisplay *disp, |
| 1075 | _EGLSurface *draw, xcb_xfixes_region_t region) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1076 | { |
Chia-I Wu | d18d0fd | 2010-04-06 19:52:39 +0800 | [diff] [blame] | 1077 | struct dri2_egl_driver *dri2_drv = dri2_egl_driver(drv); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1078 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1079 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(draw); |
Chia-I Wu | d18d0fd | 2010-04-06 19:52:39 +0800 | [diff] [blame] | 1080 | _EGLContext *ctx; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1081 | xcb_dri2_copy_region_cookie_t cookie; |
| 1082 | |
Chia-I Wu | d18d0fd | 2010-04-06 19:52:39 +0800 | [diff] [blame] | 1083 | if (dri2_drv->glFlush) { |
| 1084 | ctx = _eglGetCurrentContext(); |
| 1085 | if (ctx && ctx->DrawSurface == &dri2_surf->base) |
| 1086 | dri2_drv->glFlush(); |
| 1087 | } |
| 1088 | |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 1089 | (*dri2_dpy->flush->flush)(dri2_surf->dri_drawable); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1090 | |
| 1091 | #if 0 |
| 1092 | /* FIXME: Add support for dri swapbuffers, that'll give us swap |
| 1093 | * interval and page flipping (at least for fullscreen windows) as |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 1094 | * well as the page flip event. Unless surface->SwapBehavior is |
| 1095 | * EGL_BUFFER_PRESERVED. */ |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1096 | #if __DRI2_FLUSH_VERSION >= 2 |
| 1097 | if (pdraw->psc->f) |
| 1098 | (*pdraw->psc->f->flushInvalidate)(pdraw->driDrawable); |
| 1099 | #endif |
| 1100 | #endif |
| 1101 | |
Kristian Høgsberg | c3c1a7e | 2010-02-09 20:49:40 -0500 | [diff] [blame] | 1102 | if (!dri2_surf->have_fake_front) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1103 | return EGL_TRUE; |
| 1104 | |
| 1105 | cookie = xcb_dri2_copy_region_unchecked(dri2_dpy->conn, |
| 1106 | dri2_surf->drawable, |
Kristian Høgsberg | 52c554a | 2010-05-06 22:01:35 -0400 | [diff] [blame] | 1107 | region, |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1108 | XCB_DRI2_ATTACHMENT_BUFFER_FRONT_LEFT, |
Kristian Høgsberg | c3c1a7e | 2010-02-09 20:49:40 -0500 | [diff] [blame] | 1109 | XCB_DRI2_ATTACHMENT_BUFFER_FAKE_FRONT_LEFT); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1110 | free(xcb_dri2_copy_region_reply(dri2_dpy->conn, cookie, NULL)); |
| 1111 | |
| 1112 | return EGL_TRUE; |
| 1113 | } |
| 1114 | |
Kristian Høgsberg | 52c554a | 2010-05-06 22:01:35 -0400 | [diff] [blame] | 1115 | static EGLBoolean |
| 1116 | dri2_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw) |
| 1117 | { |
| 1118 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(draw); |
| 1119 | |
| 1120 | return dri2_copy_region(drv, disp, draw, dri2_surf->region); |
| 1121 | } |
| 1122 | |
| 1123 | static EGLBoolean |
| 1124 | dri2_swap_buffers_region(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw, |
| 1125 | EGLint numRects, const EGLint *rects) |
| 1126 | { |
| 1127 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1128 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(draw); |
| 1129 | EGLBoolean ret; |
| 1130 | xcb_xfixes_region_t region; |
| 1131 | xcb_rectangle_t rectangles[16]; |
| 1132 | int i; |
| 1133 | |
| 1134 | if (numRects > ARRAY_SIZE(rectangles)) |
| 1135 | return dri2_copy_region(drv, disp, draw, dri2_surf->region); |
| 1136 | |
| 1137 | /* FIXME: Invert y here? */ |
| 1138 | for (i = 0; i < numRects; i++) { |
| 1139 | rectangles[i].x = rects[i * 4]; |
| 1140 | rectangles[i].y = rects[i * 4 + 1]; |
| 1141 | rectangles[i].width = rects[i * 4 + 2]; |
| 1142 | rectangles[i].height = rects[i * 4 + 3]; |
| 1143 | } |
| 1144 | |
| 1145 | region = xcb_generate_id(dri2_dpy->conn); |
| 1146 | xcb_xfixes_create_region(dri2_dpy->conn, region, numRects, rectangles); |
| 1147 | ret = dri2_copy_region(drv, disp, draw, region); |
| 1148 | xcb_xfixes_destroy_region(dri2_dpy->conn, region); |
| 1149 | |
| 1150 | return ret; |
| 1151 | } |
| 1152 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1153 | /* |
| 1154 | * Called from eglGetProcAddress() via drv->API.GetProcAddress(). |
| 1155 | */ |
| 1156 | static _EGLProc |
| 1157 | dri2_get_proc_address(_EGLDriver *drv, const char *procname) |
| 1158 | { |
| 1159 | /* FIXME: Do we need to support lookup of EGL symbols too? */ |
| 1160 | |
| 1161 | return (_EGLProc) _glapi_get_proc_address(procname); |
| 1162 | } |
| 1163 | |
| 1164 | static EGLBoolean |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 1165 | dri2_wait_client(_EGLDriver *drv, _EGLDisplay *disp, _EGLContext *ctx) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1166 | { |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 1167 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1168 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(ctx->DrawSurface); |
| 1169 | |
| 1170 | /* FIXME: If EGL allows frontbuffer rendering for window surfaces, |
| 1171 | * we need to copy fake to real here.*/ |
| 1172 | |
| 1173 | (*dri2_dpy->flush->flush)(dri2_surf->dri_drawable); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1174 | |
| 1175 | return EGL_TRUE; |
| 1176 | } |
| 1177 | |
| 1178 | static EGLBoolean |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 1179 | dri2_wait_native(_EGLDriver *drv, _EGLDisplay *disp, EGLint engine) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1180 | { |
| 1181 | if (engine != EGL_CORE_NATIVE_ENGINE) |
| 1182 | return _eglError(EGL_BAD_PARAMETER, "eglWaitNative"); |
| 1183 | /* glXWaitX(); */ |
| 1184 | |
| 1185 | return EGL_TRUE; |
| 1186 | } |
| 1187 | |
| 1188 | static void |
| 1189 | dri2_unload(_EGLDriver *drv) |
| 1190 | { |
| 1191 | struct dri2_egl_driver *dri2_drv = dri2_egl_driver(drv); |
| 1192 | free(dri2_drv); |
| 1193 | } |
| 1194 | |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 1195 | static EGLBoolean |
| 1196 | dri2_copy_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf, |
| 1197 | EGLNativePixmapType target) |
| 1198 | { |
| 1199 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1200 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); |
| 1201 | xcb_gcontext_t gc; |
| 1202 | |
| 1203 | (*dri2_dpy->flush->flush)(dri2_surf->dri_drawable); |
| 1204 | |
| 1205 | gc = xcb_generate_id(dri2_dpy->conn); |
| 1206 | xcb_create_gc(dri2_dpy->conn, gc, target, 0, NULL); |
| 1207 | xcb_copy_area(dri2_dpy->conn, |
| 1208 | dri2_surf->drawable, |
| 1209 | target, |
| 1210 | gc, |
| 1211 | 0, 0, |
| 1212 | 0, 0, |
| 1213 | dri2_surf->base.Width, |
| 1214 | dri2_surf->base.Height); |
| 1215 | xcb_free_gc(dri2_dpy->conn, gc); |
| 1216 | |
| 1217 | return EGL_TRUE; |
| 1218 | } |
| 1219 | |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1220 | static EGLBoolean |
| 1221 | dri2_bind_tex_image(_EGLDriver *drv, |
| 1222 | _EGLDisplay *disp, _EGLSurface *surf, EGLint buffer) |
| 1223 | { |
| 1224 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1225 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); |
| 1226 | struct dri2_egl_context *dri2_ctx; |
| 1227 | _EGLContext *ctx; |
| 1228 | GLint format, target; |
| 1229 | |
| 1230 | ctx = _eglGetCurrentContext(); |
| 1231 | dri2_ctx = dri2_egl_context(ctx); |
| 1232 | |
Kristian Høgsberg | 5dc0f49 | 2010-05-06 22:40:25 -0400 | [diff] [blame^] | 1233 | if (!_eglBindTexImage(drv, disp, surf, buffer)) |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1234 | return EGL_FALSE; |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1235 | |
| 1236 | switch (dri2_surf->base.TextureFormat) { |
| 1237 | case EGL_TEXTURE_RGB: |
| 1238 | format = __DRI_TEXTURE_FORMAT_RGB; |
| 1239 | break; |
| 1240 | case EGL_TEXTURE_RGBA: |
| 1241 | format = __DRI_TEXTURE_FORMAT_RGBA; |
| 1242 | break; |
| 1243 | default: |
Kristian Høgsberg | 5dc0f49 | 2010-05-06 22:40:25 -0400 | [diff] [blame^] | 1244 | assert(0); |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1245 | } |
| 1246 | |
| 1247 | switch (dri2_surf->base.TextureTarget) { |
| 1248 | case EGL_TEXTURE_2D: |
| 1249 | target = GL_TEXTURE_2D; |
| 1250 | break; |
| 1251 | default: |
Kristian Høgsberg | 5dc0f49 | 2010-05-06 22:40:25 -0400 | [diff] [blame^] | 1252 | assert(0); |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1253 | } |
| 1254 | |
| 1255 | (*dri2_dpy->tex_buffer->setTexBuffer2)(dri2_ctx->dri_context, |
| 1256 | target, format, |
| 1257 | dri2_surf->dri_drawable); |
| 1258 | |
Kristian Høgsberg | 5dc0f49 | 2010-05-06 22:40:25 -0400 | [diff] [blame^] | 1259 | return EGL_TRUE; |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1260 | } |
| 1261 | |
| 1262 | static EGLBoolean |
| 1263 | dri2_release_tex_image(_EGLDriver *drv, |
| 1264 | _EGLDisplay *disp, _EGLSurface *surf, EGLint buffer) |
| 1265 | { |
| 1266 | return EGL_TRUE; |
| 1267 | } |
| 1268 | |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 1269 | static _EGLImage * |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 1270 | dri2_create_image_khr_pixmap(_EGLDisplay *disp, _EGLContext *ctx, |
| 1271 | EGLClientBuffer buffer, const EGLint *attr_list) |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 1272 | { |
| 1273 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1274 | struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); |
| 1275 | struct dri2_egl_image *dri2_img; |
| 1276 | unsigned int attachments[1]; |
| 1277 | xcb_drawable_t drawable; |
| 1278 | xcb_dri2_get_buffers_cookie_t buffers_cookie; |
| 1279 | xcb_dri2_get_buffers_reply_t *buffers_reply; |
| 1280 | xcb_dri2_dri2_buffer_t *buffers; |
| 1281 | xcb_get_geometry_cookie_t geometry_cookie; |
| 1282 | xcb_get_geometry_reply_t *geometry_reply; |
| 1283 | xcb_generic_error_t *error; |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 1284 | int stride, format; |
| 1285 | |
| 1286 | drawable = (xcb_drawable_t) buffer; |
| 1287 | xcb_dri2_create_drawable (dri2_dpy->conn, drawable); |
| 1288 | attachments[0] = XCB_DRI2_ATTACHMENT_BUFFER_FRONT_LEFT; |
| 1289 | buffers_cookie = |
| 1290 | xcb_dri2_get_buffers_unchecked (dri2_dpy->conn, |
| 1291 | drawable, 1, 1, attachments); |
| 1292 | geometry_cookie = xcb_get_geometry (dri2_dpy->conn, drawable); |
| 1293 | buffers_reply = xcb_dri2_get_buffers_reply (dri2_dpy->conn, |
| 1294 | buffers_cookie, NULL); |
| 1295 | buffers = xcb_dri2_get_buffers_buffers (buffers_reply); |
| 1296 | if (buffers == NULL) { |
| 1297 | return NULL; |
| 1298 | } |
| 1299 | |
| 1300 | geometry_reply = xcb_get_geometry_reply (dri2_dpy->conn, |
| 1301 | geometry_cookie, &error); |
| 1302 | if (geometry_reply == NULL || error != NULL) { |
| 1303 | _eglError(EGL_BAD_ALLOC, "xcb_get_geometry"); |
| 1304 | free(error); |
| 1305 | free(buffers_reply); |
| 1306 | } |
| 1307 | |
| 1308 | switch (geometry_reply->depth) { |
| 1309 | case 16: |
| 1310 | format = __DRI_IMAGE_FORMAT_RGB565; |
| 1311 | break; |
| 1312 | case 24: |
| 1313 | format = __DRI_IMAGE_FORMAT_XRGB8888; |
| 1314 | break; |
| 1315 | case 32: |
| 1316 | format = __DRI_IMAGE_FORMAT_ARGB8888; |
| 1317 | break; |
| 1318 | default: |
| 1319 | _eglError(EGL_BAD_PARAMETER, |
| 1320 | "dri2_create_image_khr: unsupported pixmap depth"); |
| 1321 | free(buffers_reply); |
| 1322 | free(geometry_reply); |
| 1323 | return NULL; |
| 1324 | } |
| 1325 | |
| 1326 | dri2_img = malloc(sizeof *dri2_img); |
| 1327 | if (!dri2_img) { |
| 1328 | free(buffers_reply); |
| 1329 | free(geometry_reply); |
| 1330 | _eglError(EGL_BAD_ALLOC, "dri2_create_image_khr"); |
| 1331 | return EGL_NO_IMAGE_KHR; |
| 1332 | } |
| 1333 | |
| 1334 | if (!_eglInitImage(&dri2_img->base, disp, attr_list)) { |
| 1335 | free(buffers_reply); |
| 1336 | free(geometry_reply); |
| 1337 | return EGL_NO_IMAGE_KHR; |
| 1338 | } |
| 1339 | |
| 1340 | stride = buffers[0].pitch / buffers[0].cpp; |
| 1341 | dri2_img->dri_image = |
| 1342 | dri2_dpy->image->createImageFromName(dri2_ctx->dri_context, |
| 1343 | buffers_reply->width, |
| 1344 | buffers_reply->height, |
| 1345 | format, |
| 1346 | buffers[0].name, |
| 1347 | stride, |
| 1348 | dri2_img); |
| 1349 | |
| 1350 | free(buffers_reply); |
| 1351 | free(geometry_reply); |
| 1352 | |
| 1353 | return &dri2_img->base; |
| 1354 | } |
| 1355 | |
| 1356 | static _EGLImage * |
| 1357 | dri2_create_image_khr_renderbuffer(_EGLDisplay *disp, _EGLContext *ctx, |
| 1358 | EGLClientBuffer buffer, |
| 1359 | const EGLint *attr_list) |
| 1360 | { |
| 1361 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1362 | struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); |
| 1363 | struct dri2_egl_image *dri2_img; |
| 1364 | GLuint renderbuffer = (GLuint) buffer; |
| 1365 | |
| 1366 | if (renderbuffer == 0) { |
| 1367 | _eglError(EGL_BAD_PARAMETER, "dri2_create_image_khr"); |
| 1368 | return EGL_NO_IMAGE_KHR; |
| 1369 | } |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 1370 | |
| 1371 | dri2_img = malloc(sizeof *dri2_img); |
| 1372 | if (!dri2_img) { |
| 1373 | _eglError(EGL_BAD_ALLOC, "dri2_create_image_khr"); |
| 1374 | return EGL_NO_IMAGE_KHR; |
| 1375 | } |
| 1376 | |
| 1377 | if (!_eglInitImage(&dri2_img->base, disp, attr_list)) |
| 1378 | return EGL_NO_IMAGE_KHR; |
| 1379 | |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 1380 | dri2_img->dri_image = |
| 1381 | dri2_dpy->image->createImageFromRenderbuffer(dri2_ctx->dri_context, |
| 1382 | renderbuffer, |
| 1383 | dri2_img); |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 1384 | |
| 1385 | return &dri2_img->base; |
| 1386 | } |
| 1387 | |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 1388 | static _EGLImage * |
| 1389 | dri2_create_image_khr(_EGLDriver *drv, _EGLDisplay *disp, |
| 1390 | _EGLContext *ctx, EGLenum target, |
| 1391 | EGLClientBuffer buffer, const EGLint *attr_list) |
| 1392 | { |
| 1393 | switch (target) { |
| 1394 | case EGL_NATIVE_PIXMAP_KHR: |
| 1395 | return dri2_create_image_khr_pixmap(disp, ctx, buffer, attr_list); |
| 1396 | case EGL_GL_RENDERBUFFER_KHR: |
| 1397 | return dri2_create_image_khr_renderbuffer(disp, ctx, buffer, attr_list); |
| 1398 | default: |
| 1399 | _eglError(EGL_BAD_PARAMETER, "dri2_create_image_khr"); |
| 1400 | return EGL_NO_IMAGE_KHR; |
| 1401 | } |
| 1402 | } |
| 1403 | |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 1404 | static EGLBoolean |
| 1405 | dri2_destroy_image_khr(_EGLDriver *drv, _EGLDisplay *disp, _EGLImage *image) |
| 1406 | { |
| 1407 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1408 | struct dri2_egl_image *dri2_img = dri2_egl_image(image); |
| 1409 | |
| 1410 | dri2_dpy->image->destroyImage(dri2_img->dri_image); |
| 1411 | free(dri2_img); |
| 1412 | |
| 1413 | return EGL_TRUE; |
| 1414 | } |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1415 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1416 | /** |
| 1417 | * This is the main entrypoint into the driver, called by libEGL. |
| 1418 | * Create a new _EGLDriver object and init its dispatch table. |
| 1419 | */ |
| 1420 | _EGLDriver * |
| 1421 | _eglMain(const char *args) |
| 1422 | { |
| 1423 | struct dri2_egl_driver *dri2_drv; |
| 1424 | |
| 1425 | dri2_drv = malloc(sizeof *dri2_drv); |
| 1426 | if (!dri2_drv) |
| 1427 | return NULL; |
| 1428 | |
Kristian Høgsberg | 880acbe | 2010-05-12 14:34:55 -0400 | [diff] [blame] | 1429 | memset(dri2_drv, 0, sizeof *dri2_drv); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1430 | _eglInitDriverFallbacks(&dri2_drv->base); |
| 1431 | dri2_drv->base.API.Initialize = dri2_initialize; |
| 1432 | dri2_drv->base.API.Terminate = dri2_terminate; |
| 1433 | dri2_drv->base.API.CreateContext = dri2_create_context; |
| 1434 | dri2_drv->base.API.MakeCurrent = dri2_make_current; |
| 1435 | dri2_drv->base.API.CreateWindowSurface = dri2_create_window_surface; |
| 1436 | dri2_drv->base.API.CreatePixmapSurface = dri2_create_pixmap_surface; |
| 1437 | dri2_drv->base.API.CreatePbufferSurface = dri2_create_pbuffer_surface; |
| 1438 | dri2_drv->base.API.DestroySurface = dri2_destroy_surface; |
| 1439 | dri2_drv->base.API.SwapBuffers = dri2_swap_buffers; |
| 1440 | dri2_drv->base.API.GetProcAddress = dri2_get_proc_address; |
| 1441 | dri2_drv->base.API.WaitClient = dri2_wait_client; |
| 1442 | dri2_drv->base.API.WaitNative = dri2_wait_native; |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 1443 | dri2_drv->base.API.CopyBuffers = dri2_copy_buffers; |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1444 | dri2_drv->base.API.BindTexImage = dri2_bind_tex_image; |
| 1445 | dri2_drv->base.API.ReleaseTexImage = dri2_release_tex_image; |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 1446 | dri2_drv->base.API.CreateImageKHR = dri2_create_image_khr; |
| 1447 | dri2_drv->base.API.DestroyImageKHR = dri2_destroy_image_khr; |
Kristian Høgsberg | 52c554a | 2010-05-06 22:01:35 -0400 | [diff] [blame] | 1448 | dri2_drv->base.API.SwapBuffersRegionNOK = dri2_swap_buffers_region; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1449 | |
| 1450 | dri2_drv->base.Name = "DRI2"; |
| 1451 | dri2_drv->base.Unload = dri2_unload; |
| 1452 | |
Chia-I Wu | d18d0fd | 2010-04-06 19:52:39 +0800 | [diff] [blame] | 1453 | dri2_drv->glFlush = |
| 1454 | (void (*)(void)) dri2_get_proc_address(&dri2_drv->base, "glFlush"); |
| 1455 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1456 | return &dri2_drv->base; |
| 1457 | } |