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> |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 39 | #include <sys/types.h> |
| 40 | #include <sys/stat.h> |
| 41 | |
Kristian Høgsberg | 2889d96 | 2011-02-02 22:10:40 -0500 | [diff] [blame] | 42 | #include "egl_dri2.h" |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 43 | |
Kristian Høgsberg | 9dc5de5 | 2011-02-02 22:21:13 -0500 | [diff] [blame] | 44 | const __DRIuseInvalidateExtension use_invalidate = { |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 45 | { __DRI_USE_INVALIDATE, 1 } |
| 46 | }; |
| 47 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 48 | EGLint dri2_to_egl_attribute_map[] = { |
| 49 | 0, |
| 50 | EGL_BUFFER_SIZE, /* __DRI_ATTRIB_BUFFER_SIZE */ |
| 51 | EGL_LEVEL, /* __DRI_ATTRIB_LEVEL */ |
| 52 | EGL_RED_SIZE, /* __DRI_ATTRIB_RED_SIZE */ |
| 53 | EGL_GREEN_SIZE, /* __DRI_ATTRIB_GREEN_SIZE */ |
| 54 | EGL_BLUE_SIZE, /* __DRI_ATTRIB_BLUE_SIZE */ |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 55 | EGL_LUMINANCE_SIZE, /* __DRI_ATTRIB_LUMINANCE_SIZE */ |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 56 | EGL_ALPHA_SIZE, /* __DRI_ATTRIB_ALPHA_SIZE */ |
| 57 | 0, /* __DRI_ATTRIB_ALPHA_MASK_SIZE */ |
| 58 | EGL_DEPTH_SIZE, /* __DRI_ATTRIB_DEPTH_SIZE */ |
| 59 | EGL_STENCIL_SIZE, /* __DRI_ATTRIB_STENCIL_SIZE */ |
| 60 | 0, /* __DRI_ATTRIB_ACCUM_RED_SIZE */ |
| 61 | 0, /* __DRI_ATTRIB_ACCUM_GREEN_SIZE */ |
| 62 | 0, /* __DRI_ATTRIB_ACCUM_BLUE_SIZE */ |
| 63 | 0, /* __DRI_ATTRIB_ACCUM_ALPHA_SIZE */ |
| 64 | EGL_SAMPLE_BUFFERS, /* __DRI_ATTRIB_SAMPLE_BUFFERS */ |
| 65 | EGL_SAMPLES, /* __DRI_ATTRIB_SAMPLES */ |
| 66 | 0, /* __DRI_ATTRIB_RENDER_TYPE, */ |
| 67 | 0, /* __DRI_ATTRIB_CONFIG_CAVEAT */ |
| 68 | 0, /* __DRI_ATTRIB_CONFORMANT */ |
| 69 | 0, /* __DRI_ATTRIB_DOUBLE_BUFFER */ |
| 70 | 0, /* __DRI_ATTRIB_STEREO */ |
| 71 | 0, /* __DRI_ATTRIB_AUX_BUFFERS */ |
| 72 | 0, /* __DRI_ATTRIB_TRANSPARENT_TYPE */ |
| 73 | 0, /* __DRI_ATTRIB_TRANSPARENT_INDEX_VALUE */ |
| 74 | 0, /* __DRI_ATTRIB_TRANSPARENT_RED_VALUE */ |
| 75 | 0, /* __DRI_ATTRIB_TRANSPARENT_GREEN_VALUE */ |
| 76 | 0, /* __DRI_ATTRIB_TRANSPARENT_BLUE_VALUE */ |
| 77 | 0, /* __DRI_ATTRIB_TRANSPARENT_ALPHA_VALUE */ |
| 78 | 0, /* __DRI_ATTRIB_FLOAT_MODE */ |
| 79 | 0, /* __DRI_ATTRIB_RED_MASK */ |
| 80 | 0, /* __DRI_ATTRIB_GREEN_MASK */ |
| 81 | 0, /* __DRI_ATTRIB_BLUE_MASK */ |
| 82 | 0, /* __DRI_ATTRIB_ALPHA_MASK */ |
| 83 | EGL_MAX_PBUFFER_WIDTH, /* __DRI_ATTRIB_MAX_PBUFFER_WIDTH */ |
| 84 | EGL_MAX_PBUFFER_HEIGHT, /* __DRI_ATTRIB_MAX_PBUFFER_HEIGHT */ |
| 85 | EGL_MAX_PBUFFER_PIXELS, /* __DRI_ATTRIB_MAX_PBUFFER_PIXELS */ |
| 86 | 0, /* __DRI_ATTRIB_OPTIMAL_PBUFFER_WIDTH */ |
| 87 | 0, /* __DRI_ATTRIB_OPTIMAL_PBUFFER_HEIGHT */ |
| 88 | 0, /* __DRI_ATTRIB_VISUAL_SELECT_GROUP */ |
| 89 | 0, /* __DRI_ATTRIB_SWAP_METHOD */ |
| 90 | EGL_MAX_SWAP_INTERVAL, /* __DRI_ATTRIB_MAX_SWAP_INTERVAL */ |
| 91 | EGL_MIN_SWAP_INTERVAL, /* __DRI_ATTRIB_MIN_SWAP_INTERVAL */ |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 92 | 0, /* __DRI_ATTRIB_BIND_TO_TEXTURE_RGB */ |
| 93 | 0, /* __DRI_ATTRIB_BIND_TO_TEXTURE_RGBA */ |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 94 | 0, /* __DRI_ATTRIB_BIND_TO_MIPMAP_TEXTURE */ |
| 95 | 0, /* __DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS */ |
Kristian Høgsberg | 5dc0f49 | 2010-05-06 22:40:25 -0400 | [diff] [blame] | 96 | EGL_Y_INVERTED_NOK, /* __DRI_ATTRIB_YINVERTED */ |
Benjamin Franzke | 4f6fbfa | 2011-03-07 00:29:13 +0100 | [diff] [blame] | 97 | 0, /* __DRI_ATTRIB_FRAMEBUFFER_SRGB_CAPABLE */ |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 98 | }; |
| 99 | |
Benjamin Franzke | 16e3027 | 2011-06-11 23:00:40 +0200 | [diff] [blame] | 100 | static EGLBoolean |
| 101 | dri2_match_config(const _EGLConfig *conf, const _EGLConfig *criteria) |
| 102 | { |
| 103 | if (_eglCompareConfigs(conf, criteria, NULL, EGL_FALSE) != 0) |
| 104 | return EGL_FALSE; |
| 105 | |
| 106 | if (!_eglMatchConfig(conf, criteria)) |
| 107 | return EGL_FALSE; |
| 108 | |
| 109 | return EGL_TRUE; |
| 110 | } |
| 111 | |
Kristian Høgsberg | 2889d96 | 2011-02-02 22:10:40 -0500 | [diff] [blame] | 112 | struct dri2_egl_config * |
Kristian Høgsberg | c3c1a7e | 2010-02-09 20:49:40 -0500 | [diff] [blame] | 113 | dri2_add_config(_EGLDisplay *disp, const __DRIconfig *dri_config, int id, |
Chia-I Wu | 58911b8 | 2011-08-05 14:36:14 +0900 | [diff] [blame] | 114 | int depth, EGLint surface_type, const EGLint *attr_list, |
| 115 | const unsigned int *rgba_masks) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 116 | { |
| 117 | struct dri2_egl_config *conf; |
| 118 | struct dri2_egl_display *dri2_dpy; |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 119 | _EGLConfig base; |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 120 | unsigned int attrib, value, double_buffer; |
| 121 | EGLint key, bind_to_texture_rgb, bind_to_texture_rgba; |
Chia-I Wu | 58911b8 | 2011-08-05 14:36:14 +0900 | [diff] [blame] | 122 | unsigned int dri_masks[4] = { 0, 0, 0, 0 }; |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 123 | _EGLConfig *matching_config; |
| 124 | EGLint num_configs = 0; |
| 125 | EGLint config_id; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 126 | int i; |
| 127 | |
| 128 | dri2_dpy = disp->DriverData; |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 129 | _eglInitConfig(&base, disp, id); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 130 | |
| 131 | i = 0; |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 132 | double_buffer = 0; |
| 133 | bind_to_texture_rgb = 0; |
| 134 | bind_to_texture_rgba = 0; |
| 135 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 136 | while (dri2_dpy->core->indexConfigAttrib(dri_config, i++, &attrib, &value)) { |
| 137 | switch (attrib) { |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 138 | case __DRI_ATTRIB_RENDER_TYPE: |
| 139 | if (value & __DRI_ATTRIB_RGBA_BIT) |
| 140 | value = EGL_RGB_BUFFER; |
| 141 | else if (value & __DRI_ATTRIB_LUMINANCE_BIT) |
| 142 | value = EGL_LUMINANCE_BUFFER; |
| 143 | else |
| 144 | /* not valid */; |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 145 | _eglSetConfigKey(&base, EGL_COLOR_BUFFER_TYPE, value); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 146 | break; |
| 147 | |
| 148 | case __DRI_ATTRIB_CONFIG_CAVEAT: |
| 149 | if (value & __DRI_ATTRIB_NON_CONFORMANT_CONFIG) |
| 150 | value = EGL_NON_CONFORMANT_CONFIG; |
| 151 | else if (value & __DRI_ATTRIB_SLOW_BIT) |
| 152 | value = EGL_SLOW_CONFIG; |
| 153 | else |
| 154 | value = EGL_NONE; |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 155 | _eglSetConfigKey(&base, EGL_CONFIG_CAVEAT, value); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 156 | break; |
| 157 | |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 158 | case __DRI_ATTRIB_BIND_TO_TEXTURE_RGB: |
| 159 | bind_to_texture_rgb = value; |
| 160 | break; |
| 161 | |
| 162 | case __DRI_ATTRIB_BIND_TO_TEXTURE_RGBA: |
| 163 | bind_to_texture_rgba = value; |
| 164 | break; |
| 165 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 166 | case __DRI_ATTRIB_DOUBLE_BUFFER: |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 167 | double_buffer = value; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 168 | break; |
| 169 | |
Chia-I Wu | 58911b8 | 2011-08-05 14:36:14 +0900 | [diff] [blame] | 170 | case __DRI_ATTRIB_RED_MASK: |
| 171 | dri_masks[0] = value; |
| 172 | break; |
| 173 | |
| 174 | case __DRI_ATTRIB_GREEN_MASK: |
| 175 | dri_masks[1] = value; |
| 176 | break; |
| 177 | |
| 178 | case __DRI_ATTRIB_BLUE_MASK: |
| 179 | dri_masks[2] = value; |
| 180 | break; |
| 181 | |
| 182 | case __DRI_ATTRIB_ALPHA_MASK: |
| 183 | dri_masks[3] = value; |
| 184 | break; |
| 185 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 186 | default: |
| 187 | key = dri2_to_egl_attribute_map[attrib]; |
| 188 | if (key != 0) |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 189 | _eglSetConfigKey(&base, key, value); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 190 | break; |
| 191 | } |
| 192 | } |
| 193 | |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 194 | if (attr_list) |
| 195 | for (i = 0; attr_list[i] != EGL_NONE; i += 2) |
| 196 | _eglSetConfigKey(&base, attr_list[i], attr_list[i+1]); |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 197 | |
Chia-I Wu | b67f729 | 2010-10-22 15:03:11 +0800 | [diff] [blame] | 198 | if (depth > 0 && depth != base.BufferSize) |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 199 | return NULL; |
Kristian Høgsberg | c3c1a7e | 2010-02-09 20:49:40 -0500 | [diff] [blame] | 200 | |
Chia-I Wu | 58911b8 | 2011-08-05 14:36:14 +0900 | [diff] [blame] | 201 | if (rgba_masks && memcmp(rgba_masks, dri_masks, sizeof(dri_masks))) |
| 202 | return NULL; |
| 203 | |
Chia-I Wu | b67f729 | 2010-10-22 15:03:11 +0800 | [diff] [blame] | 204 | base.NativeRenderable = EGL_TRUE; |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 205 | |
Chia-I Wu | b67f729 | 2010-10-22 15:03:11 +0800 | [diff] [blame] | 206 | base.SurfaceType = surface_type; |
Benjamin Franzke | a8128d7 | 2011-02-04 12:32:30 +0100 | [diff] [blame] | 207 | if (surface_type & (EGL_PBUFFER_BIT | |
| 208 | (disp->Extensions.NOK_texture_from_pixmap ? EGL_PIXMAP_BIT : 0))) { |
Chia-I Wu | b67f729 | 2010-10-22 15:03:11 +0800 | [diff] [blame] | 209 | base.BindToTextureRGB = bind_to_texture_rgb; |
| 210 | if (base.AlphaSize > 0) |
| 211 | base.BindToTextureRGBA = bind_to_texture_rgba; |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 212 | } |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 213 | |
Chia-I Wu | a4a38dc | 2011-01-13 16:53:13 +0800 | [diff] [blame] | 214 | base.RenderableType = disp->ClientAPIs; |
| 215 | base.Conformant = disp->ClientAPIs; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 216 | |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 217 | if (!_eglValidateConfig(&base, EGL_FALSE)) { |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 218 | _eglLog(_EGL_DEBUG, "DRI2: failed to validate config %d", id); |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 219 | return NULL; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 220 | } |
| 221 | |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 222 | config_id = base.ConfigID; |
| 223 | base.ConfigID = EGL_DONT_CARE; |
| 224 | base.SurfaceType = EGL_DONT_CARE; |
| 225 | num_configs = _eglFilterArray(disp->Configs, (void **) &matching_config, 1, |
Benjamin Franzke | 16e3027 | 2011-06-11 23:00:40 +0200 | [diff] [blame] | 226 | (_EGLArrayForEach) dri2_match_config, &base); |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 227 | |
| 228 | if (num_configs == 1) { |
| 229 | conf = (struct dri2_egl_config *) matching_config; |
| 230 | |
| 231 | if (double_buffer && !conf->dri_double_config) |
| 232 | conf->dri_double_config = dri_config; |
| 233 | else if (!double_buffer && !conf->dri_single_config) |
| 234 | conf->dri_single_config = dri_config; |
| 235 | else |
Benjamin Franzke | 83c6875 | 2011-05-12 19:30:05 +0200 | [diff] [blame] | 236 | /* a similar config type is already added (unlikely) => discard */ |
| 237 | return NULL; |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 238 | } |
José Fonseca | 4a47d6d | 2011-05-12 15:23:48 +0100 | [diff] [blame] | 239 | else if (num_configs == 0) { |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 240 | conf = malloc(sizeof *conf); |
| 241 | if (conf == NULL) |
| 242 | return NULL; |
| 243 | |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 244 | memcpy(&conf->base, &base, sizeof base); |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 245 | if (double_buffer) { |
| 246 | conf->dri_double_config = dri_config; |
| 247 | conf->dri_single_config = NULL; |
| 248 | } else { |
| 249 | conf->dri_single_config = dri_config; |
| 250 | conf->dri_double_config = NULL; |
| 251 | } |
| 252 | conf->base.SurfaceType = 0; |
| 253 | conf->base.ConfigID = config_id; |
| 254 | |
Chia-I Wu | 8a6bdf3 | 2010-10-23 00:47:22 +0800 | [diff] [blame] | 255 | _eglLinkConfig(&conf->base); |
Kristian Høgsberg | c19dab7 | 2010-02-09 21:01:04 -0500 | [diff] [blame] | 256 | } |
José Fonseca | 4a47d6d | 2011-05-12 15:23:48 +0100 | [diff] [blame] | 257 | else { |
| 258 | assert(0); |
| 259 | return NULL; |
| 260 | } |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 261 | |
Fredrik Höglund | 655f2c1 | 2011-12-20 17:17:02 +0100 | [diff] [blame] | 262 | if (double_buffer) { |
Kristian Høgsberg | 447bb45 | 2011-08-31 18:20:06 -0400 | [diff] [blame] | 263 | surface_type &= ~EGL_PIXMAP_BIT; |
| 264 | |
Fredrik Höglund | 655f2c1 | 2011-12-20 17:17:02 +0100 | [diff] [blame] | 265 | if (dri2_dpy->swap_available) { |
| 266 | conf->base.MinSwapInterval = 0; |
| 267 | conf->base.MaxSwapInterval = 1000; /* XXX arbitrary value */ |
| 268 | } |
| 269 | } |
| 270 | |
Kristian Høgsberg | 447bb45 | 2011-08-31 18:20:06 -0400 | [diff] [blame] | 271 | conf->base.SurfaceType |= surface_type; |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 272 | |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 273 | return conf; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 274 | } |
| 275 | |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 276 | __DRIimage * |
Kristian Høgsberg | 17eace5 | 2010-09-22 22:01:17 -0400 | [diff] [blame] | 277 | dri2_lookup_egl_image(__DRIscreen *screen, void *image, void *data) |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 278 | { |
Kristian Høgsberg | 17eace5 | 2010-09-22 22:01:17 -0400 | [diff] [blame] | 279 | _EGLDisplay *disp = data; |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 280 | struct dri2_egl_image *dri2_img; |
| 281 | _EGLImage *img; |
| 282 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 283 | (void) screen; |
| 284 | |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 285 | img = _eglLookupImage(image, disp); |
| 286 | if (img == NULL) { |
| 287 | _eglError(EGL_BAD_PARAMETER, "dri2_lookup_egl_image"); |
| 288 | return NULL; |
| 289 | } |
| 290 | |
| 291 | dri2_img = dri2_egl_image(image); |
| 292 | |
| 293 | return dri2_img->dri_image; |
| 294 | } |
| 295 | |
Kristian Høgsberg | 2889d96 | 2011-02-02 22:10:40 -0500 | [diff] [blame] | 296 | const __DRIimageLookupExtension image_lookup_extension = { |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 297 | { __DRI_IMAGE_LOOKUP, 1 }, |
| 298 | dri2_lookup_egl_image |
| 299 | }; |
| 300 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 301 | static const char dri_driver_path[] = DEFAULT_DRIVER_DIR; |
| 302 | |
Kristian Høgsberg | 8c593d3 | 2010-02-09 10:57:43 -0500 | [diff] [blame] | 303 | struct dri2_extension_match { |
| 304 | const char *name; |
| 305 | int version; |
| 306 | int offset; |
| 307 | }; |
| 308 | |
| 309 | static struct dri2_extension_match dri2_driver_extensions[] = { |
| 310 | { __DRI_CORE, 1, offsetof(struct dri2_egl_display, core) }, |
| 311 | { __DRI_DRI2, 1, offsetof(struct dri2_egl_display, dri2) }, |
Ian Romanick | 137fce2 | 2010-09-23 09:40:58 -0700 | [diff] [blame] | 312 | { NULL, 0, 0 } |
Kristian Høgsberg | 8c593d3 | 2010-02-09 10:57:43 -0500 | [diff] [blame] | 313 | }; |
| 314 | |
| 315 | static struct dri2_extension_match dri2_core_extensions[] = { |
| 316 | { __DRI2_FLUSH, 1, offsetof(struct dri2_egl_display, flush) }, |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 317 | { __DRI_TEX_BUFFER, 2, offsetof(struct dri2_egl_display, tex_buffer) }, |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 318 | { __DRI_IMAGE, 1, offsetof(struct dri2_egl_display, image) }, |
Ian Romanick | 137fce2 | 2010-09-23 09:40:58 -0700 | [diff] [blame] | 319 | { NULL, 0, 0 } |
Kristian Høgsberg | 8c593d3 | 2010-02-09 10:57:43 -0500 | [diff] [blame] | 320 | }; |
| 321 | |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 322 | static struct dri2_extension_match swrast_driver_extensions[] = { |
| 323 | { __DRI_CORE, 1, offsetof(struct dri2_egl_display, core) }, |
| 324 | { __DRI_SWRAST, 2, offsetof(struct dri2_egl_display, swrast) }, |
| 325 | { NULL } |
| 326 | }; |
| 327 | |
| 328 | static struct dri2_extension_match swrast_core_extensions[] = { |
| 329 | { __DRI_TEX_BUFFER, 2, offsetof(struct dri2_egl_display, tex_buffer) }, |
| 330 | { NULL } |
| 331 | }; |
| 332 | |
Kristian Høgsberg | 8c593d3 | 2010-02-09 10:57:43 -0500 | [diff] [blame] | 333 | static EGLBoolean |
| 334 | dri2_bind_extensions(struct dri2_egl_display *dri2_dpy, |
| 335 | struct dri2_extension_match *matches, |
| 336 | const __DRIextension **extensions) |
| 337 | { |
| 338 | int i, j, ret = EGL_TRUE; |
| 339 | void *field; |
| 340 | |
| 341 | for (i = 0; extensions[i]; i++) { |
| 342 | _eglLog(_EGL_DEBUG, "DRI2: found extension `%s'", extensions[i]->name); |
| 343 | for (j = 0; matches[j].name; j++) { |
| 344 | if (strcmp(extensions[i]->name, matches[j].name) == 0 && |
| 345 | extensions[i]->version >= matches[j].version) { |
| 346 | field = ((char *) dri2_dpy + matches[j].offset); |
| 347 | *(const __DRIextension **) field = extensions[i]; |
| 348 | _eglLog(_EGL_INFO, "DRI2: found extension %s version %d", |
| 349 | extensions[i]->name, extensions[i]->version); |
| 350 | } |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | for (j = 0; matches[j].name; j++) { |
| 355 | field = ((char *) dri2_dpy + matches[j].offset); |
| 356 | if (*(const __DRIextension **) field == NULL) { |
| 357 | _eglLog(_EGL_FATAL, "DRI2: did not find extension %s version %d", |
| 358 | matches[j].name, matches[j].version); |
| 359 | ret = EGL_FALSE; |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | return ret; |
| 364 | } |
| 365 | |
Chia-I Wu | cf69eea | 2011-06-08 16:33:55 +0800 | [diff] [blame] | 366 | static const __DRIextension ** |
| 367 | dri2_open_driver(_EGLDisplay *disp) |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 368 | { |
Kristian Høgsberg | 0defc25 | 2010-05-28 16:16:12 -0400 | [diff] [blame] | 369 | struct dri2_egl_display *dri2_dpy = disp->DriverData; |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 370 | const __DRIextension **extensions; |
Kristian Høgsberg | 4007342 | 2010-03-02 15:34:18 -0500 | [diff] [blame] | 371 | char path[PATH_MAX], *search_paths, *p, *next, *end; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 372 | |
| 373 | search_paths = NULL; |
| 374 | if (geteuid() == getuid()) { |
| 375 | /* don't allow setuid apps to use LIBGL_DRIVERS_PATH */ |
| 376 | search_paths = getenv("LIBGL_DRIVERS_PATH"); |
| 377 | } |
| 378 | if (search_paths == NULL) |
| 379 | search_paths = DEFAULT_DRIVER_DIR; |
| 380 | |
| 381 | dri2_dpy->driver = NULL; |
| 382 | end = search_paths + strlen(search_paths); |
| 383 | 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] | 384 | int len; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 385 | next = strchr(p, ':'); |
| 386 | if (next == NULL) |
| 387 | next = end; |
| 388 | |
Eric Anholt | 6f77b75 | 2010-05-20 14:44:43 -0700 | [diff] [blame] | 389 | len = next - p; |
| 390 | #if GLX_USE_TLS |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 391 | snprintf(path, sizeof path, |
Eric Anholt | 6f77b75 | 2010-05-20 14:44:43 -0700 | [diff] [blame] | 392 | "%.*s/tls/%s_dri.so", len, p, dri2_dpy->driver_name); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 393 | dri2_dpy->driver = dlopen(path, RTLD_NOW | RTLD_GLOBAL); |
Eric Anholt | 6f77b75 | 2010-05-20 14:44:43 -0700 | [diff] [blame] | 394 | #endif |
| 395 | if (dri2_dpy->driver == NULL) { |
| 396 | snprintf(path, sizeof path, |
| 397 | "%.*s/%s_dri.so", len, p, dri2_dpy->driver_name); |
| 398 | dri2_dpy->driver = dlopen(path, RTLD_NOW | RTLD_GLOBAL); |
| 399 | if (dri2_dpy->driver == NULL) |
| 400 | _eglLog(_EGL_DEBUG, "failed to open %s: %s\n", path, dlerror()); |
| 401 | } |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | if (dri2_dpy->driver == NULL) { |
Kristian Høgsberg | 7413d9a | 2010-05-13 15:42:51 -0400 | [diff] [blame] | 405 | _eglLog(_EGL_WARNING, |
Chia-I Wu | cf69eea | 2011-06-08 16:33:55 +0800 | [diff] [blame] | 406 | "DRI2: failed to open %s (search paths %s)", |
| 407 | dri2_dpy->driver_name, search_paths); |
| 408 | return NULL; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | _eglLog(_EGL_DEBUG, "DRI2: dlopen(%s)", path); |
| 412 | extensions = dlsym(dri2_dpy->driver, __DRI_DRIVER_EXTENSIONS); |
| 413 | if (extensions == NULL) { |
Kristian Høgsberg | 7413d9a | 2010-05-13 15:42:51 -0400 | [diff] [blame] | 414 | _eglLog(_EGL_WARNING, |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 415 | "DRI2: driver exports no extensions (%s)", dlerror()); |
Kristian Høgsberg | 0defc25 | 2010-05-28 16:16:12 -0400 | [diff] [blame] | 416 | dlclose(dri2_dpy->driver); |
Chia-I Wu | cf69eea | 2011-06-08 16:33:55 +0800 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | return extensions; |
| 420 | } |
| 421 | |
| 422 | EGLBoolean |
| 423 | dri2_load_driver(_EGLDisplay *disp) |
| 424 | { |
| 425 | struct dri2_egl_display *dri2_dpy = disp->DriverData; |
| 426 | const __DRIextension **extensions; |
| 427 | |
| 428 | extensions = dri2_open_driver(disp); |
| 429 | if (!extensions) |
| 430 | return EGL_FALSE; |
| 431 | |
| 432 | if (!dri2_bind_extensions(dri2_dpy, dri2_driver_extensions, extensions)) { |
| 433 | dlclose(dri2_dpy->driver); |
Kristian Høgsberg | 0defc25 | 2010-05-28 16:16:12 -0400 | [diff] [blame] | 434 | return EGL_FALSE; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 435 | } |
| 436 | |
Chia-I Wu | cf69eea | 2011-06-08 16:33:55 +0800 | [diff] [blame] | 437 | return EGL_TRUE; |
| 438 | } |
| 439 | |
| 440 | EGLBoolean |
| 441 | dri2_load_driver_swrast(_EGLDisplay *disp) |
| 442 | { |
| 443 | struct dri2_egl_display *dri2_dpy = disp->DriverData; |
| 444 | const __DRIextension **extensions; |
| 445 | |
| 446 | dri2_dpy->driver_name = "swrast"; |
| 447 | extensions = dri2_open_driver(disp); |
Chia-I Wu | 77e031a | 2011-06-08 16:33:56 +0800 | [diff] [blame] | 448 | |
Chia-I Wu | cf69eea | 2011-06-08 16:33:55 +0800 | [diff] [blame] | 449 | if (!extensions) |
| 450 | return EGL_FALSE; |
| 451 | |
| 452 | if (!dri2_bind_extensions(dri2_dpy, swrast_driver_extensions, extensions)) { |
| 453 | dlclose(dri2_dpy->driver); |
| 454 | return EGL_FALSE; |
| 455 | } |
Kristian Høgsberg | 0defc25 | 2010-05-28 16:16:12 -0400 | [diff] [blame] | 456 | |
| 457 | return EGL_TRUE; |
| 458 | } |
| 459 | |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 460 | void |
| 461 | dri2_setup_screen(_EGLDisplay *disp) |
Kristian Høgsberg | 0defc25 | 2010-05-28 16:16:12 -0400 | [diff] [blame] | 462 | { |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 463 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Kristian Høgsberg | 0defc25 | 2010-05-28 16:16:12 -0400 | [diff] [blame] | 464 | unsigned int api_mask; |
| 465 | |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 466 | if (dri2_dpy->dri2) { |
| 467 | if (dri2_dpy->dri2->base.version >= 2) |
| 468 | api_mask = dri2_dpy->dri2->getAPIMask(dri2_dpy->dri_screen); |
| 469 | else |
| 470 | api_mask = 1 << __DRI_API_OPENGL; |
| 471 | } else { |
| 472 | assert(dri2_dpy->swrast); |
Ian Romanick | 05413dd | 2012-07-18 10:08:49 -0700 | [diff] [blame] | 473 | api_mask = 1 << __DRI_API_OPENGL | 1 << __DRI_API_GLES | 1 << __DRI_API_GLES2; |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 474 | } |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 475 | |
Chia-I Wu | a4a38dc | 2011-01-13 16:53:13 +0800 | [diff] [blame] | 476 | disp->ClientAPIs = 0; |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 477 | if (api_mask & (1 <<__DRI_API_OPENGL)) |
Chia-I Wu | a4a38dc | 2011-01-13 16:53:13 +0800 | [diff] [blame] | 478 | disp->ClientAPIs |= EGL_OPENGL_BIT; |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 479 | if (api_mask & (1 <<__DRI_API_GLES)) |
Chia-I Wu | a4a38dc | 2011-01-13 16:53:13 +0800 | [diff] [blame] | 480 | disp->ClientAPIs |= EGL_OPENGL_ES_BIT; |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 481 | if (api_mask & (1 << __DRI_API_GLES2)) |
Chia-I Wu | a4a38dc | 2011-01-13 16:53:13 +0800 | [diff] [blame] | 482 | disp->ClientAPIs |= EGL_OPENGL_ES2_BIT; |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 483 | |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 484 | if (dri2_dpy->dri2) { |
| 485 | if (dri2_dpy->dri2->base.version >= 2) { |
| 486 | disp->Extensions.KHR_surfaceless_gles1 = EGL_TRUE; |
| 487 | disp->Extensions.KHR_surfaceless_gles2 = EGL_TRUE; |
| 488 | disp->Extensions.KHR_surfaceless_opengl = EGL_TRUE; |
| 489 | } |
| 490 | } else { |
| 491 | assert(dri2_dpy->swrast); |
Ian Romanick | 05413dd | 2012-07-18 10:08:49 -0700 | [diff] [blame] | 492 | disp->Extensions.KHR_surfaceless_gles1 = EGL_TRUE; |
| 493 | disp->Extensions.KHR_surfaceless_gles2 = EGL_TRUE; |
| 494 | disp->Extensions.KHR_surfaceless_opengl = EGL_TRUE; |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 495 | } |
| 496 | |
Kristian Høgsberg | 981e338 | 2011-03-07 20:18:29 -0500 | [diff] [blame] | 497 | if (dri2_dpy->image) { |
| 498 | disp->Extensions.MESA_drm_image = EGL_TRUE; |
| 499 | disp->Extensions.KHR_image_base = EGL_TRUE; |
| 500 | disp->Extensions.KHR_gl_renderbuffer_image = EGL_TRUE; |
Kristian Høgsberg | 981e338 | 2011-03-07 20:18:29 -0500 | [diff] [blame] | 501 | } |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | EGLBoolean |
| 505 | dri2_create_screen(_EGLDisplay *disp) |
| 506 | { |
| 507 | const __DRIextension **extensions; |
| 508 | struct dri2_egl_display *dri2_dpy; |
| 509 | |
| 510 | dri2_dpy = disp->DriverData; |
| 511 | |
| 512 | if (dri2_dpy->dri2) { |
| 513 | dri2_dpy->dri_screen = |
| 514 | dri2_dpy->dri2->createNewScreen(0, dri2_dpy->fd, dri2_dpy->extensions, |
| 515 | &dri2_dpy->driver_configs, disp); |
| 516 | } else { |
| 517 | assert(dri2_dpy->swrast); |
| 518 | dri2_dpy->dri_screen = |
| 519 | dri2_dpy->swrast->createNewScreen(0, dri2_dpy->extensions, |
| 520 | &dri2_dpy->driver_configs, disp); |
| 521 | } |
| 522 | |
| 523 | if (dri2_dpy->dri_screen == NULL) { |
| 524 | _eglLog(_EGL_WARNING, "DRI2: failed to create dri screen"); |
| 525 | return EGL_FALSE; |
| 526 | } |
| 527 | |
Benjamin Franzke | 992680c | 2011-06-27 10:23:34 +0200 | [diff] [blame] | 528 | dri2_dpy->own_dri_screen = 1; |
| 529 | |
Benjamin Franzke | e5fc4c8 | 2011-05-30 10:50:52 +0200 | [diff] [blame] | 530 | extensions = dri2_dpy->core->getExtensions(dri2_dpy->dri_screen); |
| 531 | |
| 532 | if (dri2_dpy->dri2) { |
| 533 | if (!dri2_bind_extensions(dri2_dpy, dri2_core_extensions, extensions)) |
| 534 | goto cleanup_dri_screen; |
| 535 | } else { |
| 536 | assert(dri2_dpy->swrast); |
| 537 | if (!dri2_bind_extensions(dri2_dpy, swrast_core_extensions, extensions)) |
| 538 | goto cleanup_dri_screen; |
| 539 | } |
| 540 | |
| 541 | dri2_setup_screen(disp); |
Kristian Høgsberg | 981e338 | 2011-03-07 20:18:29 -0500 | [diff] [blame] | 542 | |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 543 | return EGL_TRUE; |
| 544 | |
| 545 | cleanup_dri_screen: |
| 546 | dri2_dpy->core->destroyScreen(dri2_dpy->dri_screen); |
| 547 | |
| 548 | return EGL_FALSE; |
| 549 | } |
| 550 | |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 551 | /** |
| 552 | * Called via eglInitialize(), GLX_drv->API.Initialize(). |
| 553 | */ |
| 554 | static EGLBoolean |
Chia-I Wu | a4a38dc | 2011-01-13 16:53:13 +0800 | [diff] [blame] | 555 | dri2_initialize(_EGLDriver *drv, _EGLDisplay *disp) |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 556 | { |
Chia-I Wu | a22a332 | 2011-01-13 04:40:38 +0800 | [diff] [blame] | 557 | /* not until swrast_dri is supported */ |
| 558 | if (disp->Options.UseFallback) |
| 559 | return EGL_FALSE; |
| 560 | |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 561 | switch (disp->Platform) { |
Kristian Høgsberg | 93aea63 | 2011-05-11 13:58:37 -0400 | [diff] [blame] | 562 | #ifdef HAVE_X11_PLATFORM |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 563 | case _EGL_PLATFORM_X11: |
Chia-I Wu | 655e459 | 2011-01-13 00:27:45 +0800 | [diff] [blame] | 564 | if (disp->Options.TestOnly) |
| 565 | return EGL_TRUE; |
Chia-I Wu | a4a38dc | 2011-01-13 16:53:13 +0800 | [diff] [blame] | 566 | return dri2_initialize_x11(drv, disp); |
Kristian Høgsberg | 93aea63 | 2011-05-11 13:58:37 -0400 | [diff] [blame] | 567 | #endif |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 568 | |
| 569 | #ifdef HAVE_LIBUDEV |
Benjamin Franzke | 629c15a | 2011-06-24 21:45:05 +0200 | [diff] [blame] | 570 | #ifdef HAVE_DRM_PLATFORM |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 571 | case _EGL_PLATFORM_DRM: |
Chia-I Wu | 655e459 | 2011-01-13 00:27:45 +0800 | [diff] [blame] | 572 | if (disp->Options.TestOnly) |
| 573 | return EGL_TRUE; |
Chia-I Wu | a4a38dc | 2011-01-13 16:53:13 +0800 | [diff] [blame] | 574 | return dri2_initialize_drm(drv, disp); |
Benjamin Franzke | 629c15a | 2011-06-24 21:45:05 +0200 | [diff] [blame] | 575 | #endif |
Benjamin Franzke | 93aea84 | 2011-02-04 12:39:40 +0100 | [diff] [blame] | 576 | #ifdef HAVE_WAYLAND_PLATFORM |
| 577 | case _EGL_PLATFORM_WAYLAND: |
| 578 | if (disp->Options.TestOnly) |
| 579 | return EGL_TRUE; |
| 580 | return dri2_initialize_wayland(drv, disp); |
| 581 | #endif |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 582 | #endif |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 583 | #ifdef HAVE_ANDROID_PLATFORM |
| 584 | case _EGL_PLATFORM_ANDROID: |
| 585 | if (disp->Options.TestOnly) |
| 586 | return EGL_TRUE; |
| 587 | return dri2_initialize_android(drv, disp); |
| 588 | #endif |
Kristian Høgsberg | 2168b87 | 2010-06-02 22:48:06 -0400 | [diff] [blame] | 589 | |
| 590 | default: |
| 591 | return EGL_FALSE; |
| 592 | } |
| 593 | } |
| 594 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 595 | /** |
| 596 | * Called via eglTerminate(), drv->API.Terminate(). |
| 597 | */ |
| 598 | static EGLBoolean |
| 599 | dri2_terminate(_EGLDriver *drv, _EGLDisplay *disp) |
| 600 | { |
| 601 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 602 | |
| 603 | _eglReleaseDisplayResources(drv, disp); |
| 604 | _eglCleanupDisplay(disp); |
| 605 | |
Benjamin Franzke | 992680c | 2011-06-27 10:23:34 +0200 | [diff] [blame] | 606 | if (dri2_dpy->own_dri_screen) |
| 607 | dri2_dpy->core->destroyScreen(dri2_dpy->dri_screen); |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 608 | if (dri2_dpy->fd) |
| 609 | close(dri2_dpy->fd); |
Benjamin Franzke | 992680c | 2011-06-27 10:23:34 +0200 | [diff] [blame] | 610 | if (dri2_dpy->driver) |
| 611 | dlclose(dri2_dpy->driver); |
Benjamin Franzke | 2a58453 | 2011-12-13 14:43:48 +0100 | [diff] [blame] | 612 | if (dri2_dpy->device_name) |
| 613 | free(dri2_dpy->device_name); |
Benjamin Franzke | b8325fd | 2011-06-11 22:07:02 +0200 | [diff] [blame] | 614 | |
| 615 | if (disp->PlatformDisplay == NULL) { |
| 616 | switch (disp->Platform) { |
Kristian Høgsberg | 93aea63 | 2011-05-11 13:58:37 -0400 | [diff] [blame] | 617 | #ifdef HAVE_X11_PLATFORM |
Benjamin Franzke | b8325fd | 2011-06-11 22:07:02 +0200 | [diff] [blame] | 618 | case _EGL_PLATFORM_X11: |
| 619 | xcb_disconnect(dri2_dpy->conn); |
| 620 | break; |
Kristian Høgsberg | 93aea63 | 2011-05-11 13:58:37 -0400 | [diff] [blame] | 621 | #endif |
Benjamin Franzke | 32f4cf3 | 2011-06-29 08:49:39 +0200 | [diff] [blame] | 622 | #ifdef HAVE_DRM_PLATFORM |
| 623 | case _EGL_PLATFORM_DRM: |
Benjamin Franzke | 2a58453 | 2011-12-13 14:43:48 +0100 | [diff] [blame] | 624 | if (dri2_dpy->own_device) { |
Benjamin Franzke | 32f4cf3 | 2011-06-29 08:49:39 +0200 | [diff] [blame] | 625 | gbm_device_destroy(&dri2_dpy->gbm_dri->base.base); |
| 626 | } |
| 627 | break; |
| 628 | #endif |
Benjamin Franzke | b8325fd | 2011-06-11 22:07:02 +0200 | [diff] [blame] | 629 | default: |
| 630 | break; |
| 631 | } |
| 632 | } |
| 633 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 634 | free(dri2_dpy); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 635 | disp->DriverData = NULL; |
| 636 | |
| 637 | return EGL_TRUE; |
| 638 | } |
| 639 | |
| 640 | |
| 641 | /** |
| 642 | * Called via eglCreateContext(), drv->API.CreateContext(). |
| 643 | */ |
| 644 | static _EGLContext * |
| 645 | dri2_create_context(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf, |
| 646 | _EGLContext *share_list, const EGLint *attrib_list) |
| 647 | { |
| 648 | struct dri2_egl_context *dri2_ctx; |
| 649 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 650 | struct dri2_egl_context *dri2_ctx_shared = dri2_egl_context(share_list); |
Ian Romanick | cb77f5d | 2012-07-18 14:37:28 -0700 | [diff] [blame^] | 651 | __DRIcontext *shared = |
| 652 | dri2_ctx_shared ? dri2_ctx_shared->dri_context : NULL; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 653 | struct dri2_egl_config *dri2_config = dri2_egl_config(conf); |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 654 | const __DRIconfig *dri_config; |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 655 | int api; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 656 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 657 | (void) drv; |
| 658 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 659 | dri2_ctx = malloc(sizeof *dri2_ctx); |
| 660 | if (!dri2_ctx) { |
| 661 | _eglError(EGL_BAD_ALLOC, "eglCreateContext"); |
| 662 | return NULL; |
| 663 | } |
| 664 | |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 665 | if (!_eglInitContext(&dri2_ctx->base, disp, conf, attrib_list)) |
| 666 | goto cleanup; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 667 | |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 668 | switch (dri2_ctx->base.ClientAPI) { |
| 669 | case EGL_OPENGL_ES_API: |
| 670 | switch (dri2_ctx->base.ClientVersion) { |
| 671 | case 1: |
| 672 | api = __DRI_API_GLES; |
| 673 | break; |
| 674 | case 2: |
| 675 | api = __DRI_API_GLES2; |
| 676 | break; |
| 677 | default: |
| 678 | _eglError(EGL_BAD_PARAMETER, "eglCreateContext"); |
| 679 | return NULL; |
| 680 | } |
| 681 | break; |
| 682 | case EGL_OPENGL_API: |
| 683 | api = __DRI_API_OPENGL; |
| 684 | break; |
| 685 | default: |
| 686 | _eglError(EGL_BAD_PARAMETER, "eglCreateContext"); |
| 687 | return NULL; |
| 688 | } |
| 689 | |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 690 | if (conf != NULL) { |
| 691 | /* The config chosen here isn't necessarily |
| 692 | * used for surfaces later. |
| 693 | * A pixmap surface will use the single config. |
| 694 | * This opportunity depends on disabling the |
| 695 | * doubleBufferMode check in |
| 696 | * src/mesa/main/context.c:check_compatible() |
| 697 | */ |
| 698 | if (dri2_config->dri_double_config) |
| 699 | dri_config = dri2_config->dri_double_config; |
| 700 | else |
| 701 | dri_config = dri2_config->dri_single_config; |
Chia-I Wu | 357d3f3 | 2011-08-27 01:42:16 +0800 | [diff] [blame] | 702 | |
| 703 | /* EGL_WINDOW_BIT is set only when there is a dri_double_config. This |
| 704 | * makes sure the back buffer will always be used. |
| 705 | */ |
| 706 | if (conf->SurfaceType & EGL_WINDOW_BIT) |
| 707 | dri2_ctx->base.WindowRenderBuffer = EGL_BACK_BUFFER; |
Benjamin Franzke | 87dde5b | 2011-02-09 15:30:20 +0100 | [diff] [blame] | 708 | } |
Kristian Høgsberg | efd4a8c | 2010-07-27 18:25:54 -0400 | [diff] [blame] | 709 | else |
| 710 | dri_config = NULL; |
| 711 | |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 712 | if (dri2_dpy->dri2) { |
| 713 | if (dri2_dpy->dri2->base.version >= 2) { |
| 714 | dri2_ctx->dri_context = |
| 715 | dri2_dpy->dri2->createNewContextForAPI(dri2_dpy->dri_screen, |
| 716 | api, |
| 717 | dri_config, |
Ian Romanick | cb77f5d | 2012-07-18 14:37:28 -0700 | [diff] [blame^] | 718 | shared, |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 719 | dri2_ctx); |
| 720 | } else if (api == __DRI_API_OPENGL) { |
| 721 | dri2_ctx->dri_context = |
| 722 | dri2_dpy->dri2->createNewContext(dri2_dpy->dri_screen, |
| 723 | dri_config, |
Ian Romanick | cb77f5d | 2012-07-18 14:37:28 -0700 | [diff] [blame^] | 724 | shared, |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 725 | dri2_ctx); |
| 726 | } else { |
| 727 | /* fail */ |
| 728 | } |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 729 | } else { |
Haitao Feng | f55d027 | 2011-02-16 23:05:15 -0500 | [diff] [blame] | 730 | assert(dri2_dpy->swrast); |
Ian Romanick | 05413dd | 2012-07-18 10:08:49 -0700 | [diff] [blame] | 731 | dri2_ctx->dri_context = |
| 732 | dri2_dpy->swrast->createNewContextForAPI(dri2_dpy->dri_screen, |
| 733 | api, |
| 734 | dri_config, |
Ian Romanick | cb77f5d | 2012-07-18 14:37:28 -0700 | [diff] [blame^] | 735 | shared, |
Ian Romanick | 05413dd | 2012-07-18 10:08:49 -0700 | [diff] [blame] | 736 | dri2_ctx); |
Kristian Høgsberg | e2fd98d | 2010-04-27 11:38:46 -0400 | [diff] [blame] | 737 | } |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 738 | |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 739 | if (!dri2_ctx->dri_context) |
| 740 | goto cleanup; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 741 | |
| 742 | return &dri2_ctx->base; |
Kristian Høgsberg | 9c94fae | 2010-02-05 10:49:33 -0500 | [diff] [blame] | 743 | |
| 744 | cleanup: |
| 745 | free(dri2_ctx); |
| 746 | return NULL; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 747 | } |
| 748 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 749 | /** |
Cooper Yuan | f5e757e | 2011-08-14 15:14:17 +0800 | [diff] [blame] | 750 | * Called via eglDestroyContext(), drv->API.DestroyContext(). |
| 751 | */ |
| 752 | static EGLBoolean |
| 753 | dri2_destroy_context(_EGLDriver *drv, _EGLDisplay *disp, _EGLContext *ctx) |
| 754 | { |
| 755 | struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); |
| 756 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 757 | |
| 758 | if (_eglPutContext(ctx)) { |
| 759 | dri2_dpy->core->destroyContext(dri2_ctx->dri_context); |
| 760 | free(dri2_ctx); |
| 761 | } |
| 762 | |
| 763 | return EGL_TRUE; |
| 764 | } |
| 765 | |
| 766 | /** |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 767 | * Called via eglMakeCurrent(), drv->API.MakeCurrent(). |
| 768 | */ |
| 769 | static EGLBoolean |
| 770 | dri2_make_current(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *dsurf, |
| 771 | _EGLSurface *rsurf, _EGLContext *ctx) |
| 772 | { |
Chia-I Wu | d18d0fd | 2010-04-06 19:52:39 +0800 | [diff] [blame] | 773 | struct dri2_egl_driver *dri2_drv = dri2_egl_driver(drv); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 774 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 775 | struct dri2_egl_surface *dri2_dsurf = dri2_egl_surface(dsurf); |
| 776 | struct dri2_egl_surface *dri2_rsurf = dri2_egl_surface(rsurf); |
| 777 | struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 778 | _EGLContext *old_ctx; |
| 779 | _EGLSurface *old_dsurf, *old_rsurf; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 780 | __DRIdrawable *ddraw, *rdraw; |
| 781 | __DRIcontext *cctx; |
| 782 | |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 783 | /* make new bindings */ |
| 784 | if (!_eglBindContext(ctx, dsurf, rsurf, &old_ctx, &old_dsurf, &old_rsurf)) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 785 | return EGL_FALSE; |
| 786 | |
Chia-I Wu | d18d0fd | 2010-04-06 19:52:39 +0800 | [diff] [blame] | 787 | /* flush before context switch */ |
Chia-I Wu | 547e761 | 2010-10-26 15:00:56 +0800 | [diff] [blame] | 788 | if (old_ctx && dri2_drv->glFlush) |
Chia-I Wu | d18d0fd | 2010-04-06 19:52:39 +0800 | [diff] [blame] | 789 | dri2_drv->glFlush(); |
| 790 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 791 | ddraw = (dri2_dsurf) ? dri2_dsurf->dri_drawable : NULL; |
| 792 | rdraw = (dri2_rsurf) ? dri2_rsurf->dri_drawable : NULL; |
| 793 | cctx = (dri2_ctx) ? dri2_ctx->dri_context : NULL; |
| 794 | |
Benjamin Franzke | 4e8f95f | 2011-02-09 21:19:45 +0100 | [diff] [blame] | 795 | if (old_ctx) { |
| 796 | __DRIcontext *old_cctx = dri2_egl_context(old_ctx)->dri_context; |
| 797 | dri2_dpy->core->unbindContext(old_cctx); |
| 798 | } |
| 799 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 800 | if ((cctx == NULL && ddraw == NULL && rdraw == NULL) || |
| 801 | dri2_dpy->core->bindContext(cctx, ddraw, rdraw)) { |
Benjamin Franzke | 4e8f95f | 2011-02-09 21:19:45 +0100 | [diff] [blame] | 802 | if (old_dsurf) |
| 803 | drv->API.DestroySurface(drv, disp, old_dsurf); |
| 804 | if (old_rsurf) |
| 805 | drv->API.DestroySurface(drv, disp, old_rsurf); |
Benjamin Franzke | 4e8f95f | 2011-02-09 21:19:45 +0100 | [diff] [blame] | 806 | if (old_ctx) |
Cooper Yuan | f5e757e | 2011-08-14 15:14:17 +0800 | [diff] [blame] | 807 | drv->API.DestroyContext(drv, disp, old_ctx); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 808 | |
| 809 | return EGL_TRUE; |
| 810 | } else { |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 811 | /* undo the previous _eglBindContext */ |
| 812 | _eglBindContext(old_ctx, old_dsurf, old_rsurf, &ctx, &dsurf, &rsurf); |
| 813 | assert(&dri2_ctx->base == ctx && |
| 814 | &dri2_dsurf->base == dsurf && |
| 815 | &dri2_rsurf->base == rsurf); |
| 816 | |
| 817 | _eglPutSurface(dsurf); |
| 818 | _eglPutSurface(rsurf); |
| 819 | _eglPutContext(ctx); |
| 820 | |
| 821 | _eglPutSurface(old_dsurf); |
| 822 | _eglPutSurface(old_rsurf); |
| 823 | _eglPutContext(old_ctx); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 824 | |
| 825 | return EGL_FALSE; |
| 826 | } |
| 827 | } |
| 828 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 829 | /* |
| 830 | * Called from eglGetProcAddress() via drv->API.GetProcAddress(). |
| 831 | */ |
| 832 | static _EGLProc |
| 833 | dri2_get_proc_address(_EGLDriver *drv, const char *procname) |
| 834 | { |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 835 | struct dri2_egl_driver *dri2_drv = dri2_egl_driver(drv); |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 836 | |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 837 | return dri2_drv->get_proc_address(procname); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | static EGLBoolean |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 841 | dri2_wait_client(_EGLDriver *drv, _EGLDisplay *disp, _EGLContext *ctx) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 842 | { |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 843 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 844 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(ctx->DrawSurface); |
| 845 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 846 | (void) drv; |
| 847 | |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 848 | /* FIXME: If EGL allows frontbuffer rendering for window surfaces, |
| 849 | * we need to copy fake to real here.*/ |
| 850 | |
| 851 | (*dri2_dpy->flush->flush)(dri2_surf->dri_drawable); |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 852 | |
| 853 | return EGL_TRUE; |
| 854 | } |
| 855 | |
| 856 | static EGLBoolean |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 857 | dri2_wait_native(_EGLDriver *drv, _EGLDisplay *disp, EGLint engine) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 858 | { |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 859 | (void) drv; |
| 860 | (void) disp; |
| 861 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 862 | if (engine != EGL_CORE_NATIVE_ENGINE) |
| 863 | return _eglError(EGL_BAD_PARAMETER, "eglWaitNative"); |
| 864 | /* glXWaitX(); */ |
| 865 | |
| 866 | return EGL_TRUE; |
| 867 | } |
| 868 | |
Kristian Høgsberg | c6e830c | 2010-02-04 21:49:44 -0500 | [diff] [blame] | 869 | static EGLBoolean |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 870 | dri2_bind_tex_image(_EGLDriver *drv, |
| 871 | _EGLDisplay *disp, _EGLSurface *surf, EGLint buffer) |
| 872 | { |
| 873 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 874 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); |
| 875 | struct dri2_egl_context *dri2_ctx; |
| 876 | _EGLContext *ctx; |
| 877 | GLint format, target; |
| 878 | |
| 879 | ctx = _eglGetCurrentContext(); |
| 880 | dri2_ctx = dri2_egl_context(ctx); |
| 881 | |
Kristian Høgsberg | 5dc0f49 | 2010-05-06 22:40:25 -0400 | [diff] [blame] | 882 | if (!_eglBindTexImage(drv, disp, surf, buffer)) |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 883 | return EGL_FALSE; |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 884 | |
| 885 | switch (dri2_surf->base.TextureFormat) { |
| 886 | case EGL_TEXTURE_RGB: |
| 887 | format = __DRI_TEXTURE_FORMAT_RGB; |
| 888 | break; |
| 889 | case EGL_TEXTURE_RGBA: |
| 890 | format = __DRI_TEXTURE_FORMAT_RGBA; |
| 891 | break; |
| 892 | default: |
Kristian Høgsberg | 5dc0f49 | 2010-05-06 22:40:25 -0400 | [diff] [blame] | 893 | assert(0); |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | switch (dri2_surf->base.TextureTarget) { |
| 897 | case EGL_TEXTURE_2D: |
| 898 | target = GL_TEXTURE_2D; |
| 899 | break; |
| 900 | default: |
Kristian Høgsberg | 5dc0f49 | 2010-05-06 22:40:25 -0400 | [diff] [blame] | 901 | assert(0); |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 902 | } |
| 903 | |
| 904 | (*dri2_dpy->tex_buffer->setTexBuffer2)(dri2_ctx->dri_context, |
| 905 | target, format, |
| 906 | dri2_surf->dri_drawable); |
| 907 | |
Kristian Høgsberg | 5dc0f49 | 2010-05-06 22:40:25 -0400 | [diff] [blame] | 908 | return EGL_TRUE; |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | static EGLBoolean |
| 912 | dri2_release_tex_image(_EGLDriver *drv, |
| 913 | _EGLDisplay *disp, _EGLSurface *surf, EGLint buffer) |
| 914 | { |
Juan Zhao | e59fa4c | 2011-01-09 12:03:02 -0500 | [diff] [blame] | 915 | #if __DRI_TEX_BUFFER_VERSION >= 3 |
| 916 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 917 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); |
| 918 | struct dri2_egl_context *dri2_ctx; |
| 919 | _EGLContext *ctx; |
| 920 | GLint target; |
| 921 | |
| 922 | ctx = _eglGetCurrentContext(); |
| 923 | dri2_ctx = dri2_egl_context(ctx); |
| 924 | |
| 925 | if (!_eglReleaseTexImage(drv, disp, surf, buffer)) |
| 926 | return EGL_FALSE; |
| 927 | |
| 928 | switch (dri2_surf->base.TextureTarget) { |
| 929 | case EGL_TEXTURE_2D: |
| 930 | target = GL_TEXTURE_2D; |
| 931 | break; |
| 932 | default: |
| 933 | assert(0); |
| 934 | } |
| 935 | if (dri2_dpy->tex_buffer->releaseTexBuffer!=NULL) |
| 936 | (*dri2_dpy->tex_buffer->releaseTexBuffer)(dri2_ctx->dri_context, |
| 937 | target, |
| 938 | dri2_surf->dri_drawable); |
| 939 | #endif |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 940 | |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 941 | return EGL_TRUE; |
| 942 | } |
| 943 | |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 944 | static _EGLImage * |
Kristian Høgsberg | 5f5746a | 2012-07-05 00:39:25 -0400 | [diff] [blame] | 945 | dri2_create_image(_EGLDisplay *disp, __DRIimage *dri_image) |
| 946 | { |
| 947 | struct dri2_egl_image *dri2_img; |
| 948 | |
| 949 | if (dri_image == NULL) { |
| 950 | _eglError(EGL_BAD_ALLOC, "dri2_create_image"); |
| 951 | return NULL; |
| 952 | } |
| 953 | |
| 954 | dri2_img = malloc(sizeof *dri2_img); |
| 955 | if (!dri2_img) { |
| 956 | _eglError(EGL_BAD_ALLOC, "dri2_create_image"); |
| 957 | return NULL; |
| 958 | } |
| 959 | |
| 960 | if (!_eglInitImage(&dri2_img->base, disp)) { |
| 961 | free(dri2_img); |
| 962 | return NULL; |
| 963 | } |
| 964 | |
| 965 | dri2_img->dri_image = dri_image; |
| 966 | |
| 967 | return &dri2_img->base; |
| 968 | } |
| 969 | |
| 970 | static _EGLImage * |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 971 | dri2_create_image_khr_renderbuffer(_EGLDisplay *disp, _EGLContext *ctx, |
| 972 | EGLClientBuffer buffer, |
| 973 | const EGLint *attr_list) |
| 974 | { |
| 975 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 976 | struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); |
José Fonseca | 6a66189 | 2011-05-12 15:12:16 +0100 | [diff] [blame] | 977 | GLuint renderbuffer = (GLuint) (uintptr_t) buffer; |
Kristian Høgsberg | 5f5746a | 2012-07-05 00:39:25 -0400 | [diff] [blame] | 978 | __DRIimage *dri_image; |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 979 | |
| 980 | if (renderbuffer == 0) { |
| 981 | _eglError(EGL_BAD_PARAMETER, "dri2_create_image_khr"); |
| 982 | return EGL_NO_IMAGE_KHR; |
| 983 | } |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 984 | |
Kristian Høgsberg | 5f5746a | 2012-07-05 00:39:25 -0400 | [diff] [blame] | 985 | dri_image = |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 986 | dri2_dpy->image->createImageFromRenderbuffer(dri2_ctx->dri_context, |
Kristian Høgsberg | 5f5746a | 2012-07-05 00:39:25 -0400 | [diff] [blame] | 987 | renderbuffer, NULL); |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 988 | |
Kristian Høgsberg | 5f5746a | 2012-07-05 00:39:25 -0400 | [diff] [blame] | 989 | return dri2_create_image(disp, dri_image); |
Robert Bragg | 670f182 | 2012-01-10 22:16:26 +0000 | [diff] [blame] | 990 | } |
| 991 | |
| 992 | static _EGLImage * |
| 993 | dri2_create_image_mesa_drm_buffer(_EGLDisplay *disp, _EGLContext *ctx, |
| 994 | EGLClientBuffer buffer, const EGLint *attr_list) |
| 995 | { |
Kristian Høgsberg | 5f5746a | 2012-07-05 00:39:25 -0400 | [diff] [blame] | 996 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Robert Bragg | 670f182 | 2012-01-10 22:16:26 +0000 | [diff] [blame] | 997 | EGLint format, name, pitch, err; |
| 998 | _EGLImageAttribs attrs; |
Kristian Høgsberg | 5f5746a | 2012-07-05 00:39:25 -0400 | [diff] [blame] | 999 | __DRIimage *dri_image; |
Robert Bragg | 670f182 | 2012-01-10 22:16:26 +0000 | [diff] [blame] | 1000 | |
José Fonseca | 6a66189 | 2011-05-12 15:12:16 +0100 | [diff] [blame] | 1001 | name = (EGLint) (uintptr_t) buffer; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1002 | |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1003 | err = _eglParseImageAttribList(&attrs, disp, attr_list); |
| 1004 | if (err != EGL_SUCCESS) |
| 1005 | return NULL; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1006 | |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1007 | if (attrs.Width <= 0 || attrs.Height <= 0 || |
| 1008 | attrs.DRMBufferStrideMESA <= 0) { |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1009 | _eglError(EGL_BAD_PARAMETER, |
| 1010 | "bad width, height or stride"); |
| 1011 | return NULL; |
| 1012 | } |
| 1013 | |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1014 | switch (attrs.DRMBufferFormatMESA) { |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1015 | case EGL_DRM_BUFFER_FORMAT_ARGB32_MESA: |
| 1016 | format = __DRI_IMAGE_FORMAT_ARGB8888; |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1017 | pitch = attrs.DRMBufferStrideMESA; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1018 | break; |
| 1019 | default: |
| 1020 | _eglError(EGL_BAD_PARAMETER, |
| 1021 | "dri2_create_image_khr: unsupported pixmap depth"); |
| 1022 | return NULL; |
| 1023 | } |
| 1024 | |
Kristian Høgsberg | 5f5746a | 2012-07-05 00:39:25 -0400 | [diff] [blame] | 1025 | dri_image = |
| 1026 | dri2_dpy->image->createImageFromName(dri2_dpy->dri_screen, |
| 1027 | attrs.Width, |
| 1028 | attrs.Height, |
| 1029 | format, |
| 1030 | name, |
| 1031 | pitch, |
| 1032 | NULL); |
| 1033 | |
| 1034 | return dri2_create_image(disp, dri_image); |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1035 | } |
| 1036 | |
José Fonseca | 5de2c67 | 2011-05-12 15:24:26 +0100 | [diff] [blame] | 1037 | #ifdef HAVE_WAYLAND_PLATFORM |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1038 | |
| 1039 | /* This structure describes how a wl_buffer maps to one or more |
| 1040 | * __DRIimages. A wl_drm_buffer stores the wl_drm format code and the |
| 1041 | * offsets and strides of the planes in the buffer. This table maps a |
| 1042 | * wl_drm format code to a description of the planes in the buffer |
| 1043 | * that lets us create a __DRIimage for each of the planes. */ |
| 1044 | |
| 1045 | static const struct wl_drm_format_descriptor { |
| 1046 | uint32_t wl_format; |
| 1047 | EGLint components; |
| 1048 | int nplanes; |
| 1049 | struct { |
| 1050 | int buffer_index; |
| 1051 | int width_shift; |
| 1052 | int height_shift; |
| 1053 | uint32_t dri_format; |
| 1054 | int cpp; |
| 1055 | } planes[3]; |
| 1056 | } wl_drm_formats[] = { |
Kristian Høgsberg | e23bfdb | 2012-07-19 08:54:05 -0400 | [diff] [blame] | 1057 | { WL_DRM_FORMAT_ARGB8888, EGL_TEXTURE_RGBA, 1, |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1058 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_ARGB8888, 4 }, } }, |
| 1059 | |
Kristian Høgsberg | e23bfdb | 2012-07-19 08:54:05 -0400 | [diff] [blame] | 1060 | { WL_DRM_FORMAT_XRGB8888, EGL_TEXTURE_RGB, 1, |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1061 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_XRGB8888, 4 }, } }, |
| 1062 | |
Kristian Høgsberg | e23bfdb | 2012-07-19 08:54:05 -0400 | [diff] [blame] | 1063 | { WL_DRM_FORMAT_YUV410, EGL_TEXTURE_Y_U_V_WL, 3, |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1064 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
| 1065 | { 1, 2, 2, __DRI_IMAGE_FORMAT_R8, 1 }, |
| 1066 | { 2, 2, 2, __DRI_IMAGE_FORMAT_R8, 1 } } }, |
| 1067 | |
Kristian Høgsberg | e23bfdb | 2012-07-19 08:54:05 -0400 | [diff] [blame] | 1068 | { WL_DRM_FORMAT_YUV411, EGL_TEXTURE_Y_U_V_WL, 3, |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1069 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
| 1070 | { 1, 2, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
| 1071 | { 2, 2, 0, __DRI_IMAGE_FORMAT_R8, 1 } } }, |
| 1072 | |
Kristian Høgsberg | e23bfdb | 2012-07-19 08:54:05 -0400 | [diff] [blame] | 1073 | { WL_DRM_FORMAT_YUV420, EGL_TEXTURE_Y_U_V_WL, 3, |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1074 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
| 1075 | { 1, 1, 1, __DRI_IMAGE_FORMAT_R8, 1 }, |
| 1076 | { 2, 1, 1, __DRI_IMAGE_FORMAT_R8, 1 } } }, |
| 1077 | |
Kristian Høgsberg | e23bfdb | 2012-07-19 08:54:05 -0400 | [diff] [blame] | 1078 | { WL_DRM_FORMAT_YUV422, EGL_TEXTURE_Y_U_V_WL, 3, |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1079 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
| 1080 | { 1, 1, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
| 1081 | { 2, 1, 0, __DRI_IMAGE_FORMAT_R8, 1 } } }, |
| 1082 | |
Kristian Høgsberg | e23bfdb | 2012-07-19 08:54:05 -0400 | [diff] [blame] | 1083 | { WL_DRM_FORMAT_YUV444, EGL_TEXTURE_Y_U_V_WL, 3, |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1084 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
| 1085 | { 1, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
| 1086 | { 2, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 } } }, |
| 1087 | |
Kristian Høgsberg | e23bfdb | 2012-07-19 08:54:05 -0400 | [diff] [blame] | 1088 | { WL_DRM_FORMAT_NV12, EGL_TEXTURE_Y_UV_WL, 2, |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1089 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
| 1090 | { 1, 1, 1, __DRI_IMAGE_FORMAT_GR88, 2 } } }, |
| 1091 | |
Kristian Høgsberg | e23bfdb | 2012-07-19 08:54:05 -0400 | [diff] [blame] | 1092 | { WL_DRM_FORMAT_NV16, EGL_TEXTURE_Y_UV_WL, 2, |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1093 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
| 1094 | { 1, 1, 0, __DRI_IMAGE_FORMAT_GR88, 2 } } }, |
| 1095 | |
| 1096 | /* For YUYV buffers, we set up two overlapping DRI images and treat |
| 1097 | * them as planar buffers in the compositors. Plane 0 is GR88 and |
| 1098 | * samples YU or YV pairs and places Y into the R component, while |
| 1099 | * plane 1 is ARGB and samples YUYV clusters and places pairs and |
| 1100 | * places U into the G component and V into A. This lets the |
| 1101 | * texture sampler interpolate the Y components correctly when |
| 1102 | * sampling from plane 0, and interpolate U and V correctly when |
| 1103 | * sampling from plane 1. */ |
Kristian Høgsberg | e23bfdb | 2012-07-19 08:54:05 -0400 | [diff] [blame] | 1104 | { WL_DRM_FORMAT_YUYV, EGL_TEXTURE_Y_XUXV_WL, 2, |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1105 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88, 2 }, |
| 1106 | { 0, 1, 0, __DRI_IMAGE_FORMAT_ARGB8888, 4 } } } |
| 1107 | }; |
| 1108 | |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1109 | static _EGLImage * |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1110 | dri2_create_image_wayland_wl_buffer(_EGLDisplay *disp, _EGLContext *ctx, |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 1111 | EGLClientBuffer _buffer, |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1112 | const EGLint *attr_list) |
| 1113 | { |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1114 | struct wl_drm_buffer *buffer = (struct wl_drm_buffer *) _buffer; |
Robert Bragg | 670f182 | 2012-01-10 22:16:26 +0000 | [diff] [blame] | 1115 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1116 | __DRIimage *dri_image; |
| 1117 | _EGLImageAttribs attrs; |
| 1118 | EGLint err; |
| 1119 | uint32_t format; |
| 1120 | int32_t offset, stride, plane, width, height; |
| 1121 | int cpp, index; |
| 1122 | const struct wl_drm_format_descriptor *f; |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1123 | |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1124 | if (!wayland_buffer_is_drm(&buffer->buffer)) |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 1125 | return NULL; |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1126 | |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1127 | err = _eglParseImageAttribList(&attrs, disp, attr_list); |
| 1128 | plane = attrs.PlaneWL; |
| 1129 | if (err != EGL_SUCCESS) { |
| 1130 | _eglError(EGL_BAD_PARAMETER, "dri2_create_image_wayland_wl_buffer"); |
| 1131 | return NULL; |
| 1132 | } |
| 1133 | |
| 1134 | f = buffer->driver_format; |
| 1135 | if (plane < 0 || plane >= f->nplanes) { |
| 1136 | _eglError(EGL_BAD_PARAMETER, |
| 1137 | "dri2_create_image_wayland_wl_buffer (plane out of bounds)"); |
| 1138 | return NULL; |
| 1139 | } |
| 1140 | |
| 1141 | width = buffer->buffer.width >> f->planes[plane].width_shift; |
| 1142 | height = buffer->buffer.height >> f->planes[plane].height_shift; |
| 1143 | format = f->planes[plane].dri_format; |
| 1144 | cpp = f->planes[plane].cpp; |
| 1145 | index = f->planes[plane].buffer_index; |
| 1146 | offset = buffer->offset[index]; |
| 1147 | stride = buffer->stride[index]; |
| 1148 | |
| 1149 | dri_image = dri2_dpy->image->createSubImage(buffer->driver_buffer, |
| 1150 | width, height, format, |
| 1151 | offset, stride / cpp, NULL); |
Robert Bragg | 670f182 | 2012-01-10 22:16:26 +0000 | [diff] [blame] | 1152 | |
Kristian Høgsberg | 5f5746a | 2012-07-05 00:39:25 -0400 | [diff] [blame] | 1153 | return dri2_create_image(disp, dri_image); |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1154 | } |
| 1155 | #endif |
| 1156 | |
Kristian Høgsberg | 2889d96 | 2011-02-02 22:10:40 -0500 | [diff] [blame] | 1157 | _EGLImage * |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 1158 | dri2_create_image_khr(_EGLDriver *drv, _EGLDisplay *disp, |
| 1159 | _EGLContext *ctx, EGLenum target, |
| 1160 | EGLClientBuffer buffer, const EGLint *attr_list) |
| 1161 | { |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 1162 | (void) drv; |
| 1163 | |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 1164 | switch (target) { |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 1165 | case EGL_GL_RENDERBUFFER_KHR: |
| 1166 | return dri2_create_image_khr_renderbuffer(disp, ctx, buffer, attr_list); |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1167 | case EGL_DRM_BUFFER_MESA: |
| 1168 | return dri2_create_image_mesa_drm_buffer(disp, ctx, buffer, attr_list); |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1169 | #ifdef HAVE_WAYLAND_PLATFORM |
| 1170 | case EGL_WAYLAND_BUFFER_WL: |
| 1171 | return dri2_create_image_wayland_wl_buffer(disp, ctx, buffer, attr_list); |
| 1172 | #endif |
Kristian Høgsberg | 557c20b | 2010-02-26 14:51:11 -0500 | [diff] [blame] | 1173 | default: |
| 1174 | _eglError(EGL_BAD_PARAMETER, "dri2_create_image_khr"); |
| 1175 | return EGL_NO_IMAGE_KHR; |
| 1176 | } |
| 1177 | } |
| 1178 | |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 1179 | static EGLBoolean |
| 1180 | dri2_destroy_image_khr(_EGLDriver *drv, _EGLDisplay *disp, _EGLImage *image) |
| 1181 | { |
| 1182 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1183 | struct dri2_egl_image *dri2_img = dri2_egl_image(image); |
| 1184 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 1185 | (void) drv; |
| 1186 | |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 1187 | dri2_dpy->image->destroyImage(dri2_img->dri_image); |
| 1188 | free(dri2_img); |
| 1189 | |
| 1190 | return EGL_TRUE; |
| 1191 | } |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1192 | |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1193 | static _EGLImage * |
| 1194 | dri2_create_drm_image_mesa(_EGLDriver *drv, _EGLDisplay *disp, |
| 1195 | const EGLint *attr_list) |
| 1196 | { |
| 1197 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1198 | struct dri2_egl_image *dri2_img; |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1199 | _EGLImageAttribs attrs; |
| 1200 | unsigned int dri_use, valid_mask; |
| 1201 | int format; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1202 | EGLint err = EGL_SUCCESS; |
| 1203 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 1204 | (void) drv; |
| 1205 | |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1206 | dri2_img = malloc(sizeof *dri2_img); |
| 1207 | if (!dri2_img) { |
| 1208 | _eglError(EGL_BAD_ALLOC, "dri2_create_image_khr"); |
| 1209 | return EGL_NO_IMAGE_KHR; |
| 1210 | } |
| 1211 | |
| 1212 | if (!attr_list) { |
| 1213 | err = EGL_BAD_PARAMETER; |
| 1214 | goto cleanup_img; |
| 1215 | } |
| 1216 | |
Chia-I Wu | 713c873 | 2010-10-22 16:36:47 +0800 | [diff] [blame] | 1217 | if (!_eglInitImage(&dri2_img->base, disp)) { |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1218 | err = EGL_BAD_PARAMETER; |
| 1219 | goto cleanup_img; |
| 1220 | } |
| 1221 | |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1222 | err = _eglParseImageAttribList(&attrs, disp, attr_list); |
| 1223 | if (err != EGL_SUCCESS) |
| 1224 | goto cleanup_img; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1225 | |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1226 | if (attrs.Width <= 0 || attrs.Height <= 0) { |
| 1227 | _eglLog(_EGL_WARNING, "bad width or height (%dx%d)", |
| 1228 | attrs.Width, attrs.Height); |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1229 | goto cleanup_img; |
| 1230 | } |
| 1231 | |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1232 | switch (attrs.DRMBufferFormatMESA) { |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1233 | case EGL_DRM_BUFFER_FORMAT_ARGB32_MESA: |
| 1234 | format = __DRI_IMAGE_FORMAT_ARGB8888; |
| 1235 | break; |
| 1236 | default: |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1237 | _eglLog(_EGL_WARNING, "bad image format value 0x%04x", |
| 1238 | attrs.DRMBufferFormatMESA); |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1239 | goto cleanup_img; |
| 1240 | } |
| 1241 | |
| 1242 | valid_mask = |
| 1243 | EGL_DRM_BUFFER_USE_SCANOUT_MESA | |
Kristian Høgsberg | e5169e9 | 2011-05-06 10:31:18 -0400 | [diff] [blame] | 1244 | EGL_DRM_BUFFER_USE_SHARE_MESA | |
| 1245 | EGL_DRM_BUFFER_USE_CURSOR_MESA; |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1246 | if (attrs.DRMBufferUseMESA & ~valid_mask) { |
| 1247 | _eglLog(_EGL_WARNING, "bad image use bit 0x%04x", |
| 1248 | attrs.DRMBufferUseMESA & ~valid_mask); |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1249 | goto cleanup_img; |
| 1250 | } |
| 1251 | |
| 1252 | dri_use = 0; |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1253 | if (attrs.DRMBufferUseMESA & EGL_DRM_BUFFER_USE_SHARE_MESA) |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1254 | dri_use |= __DRI_IMAGE_USE_SHARE; |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1255 | if (attrs.DRMBufferUseMESA & EGL_DRM_BUFFER_USE_SCANOUT_MESA) |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1256 | dri_use |= __DRI_IMAGE_USE_SCANOUT; |
Kristian Høgsberg | e5169e9 | 2011-05-06 10:31:18 -0400 | [diff] [blame] | 1257 | if (attrs.DRMBufferUseMESA & EGL_DRM_BUFFER_USE_CURSOR_MESA) |
| 1258 | dri_use |= __DRI_IMAGE_USE_CURSOR; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1259 | |
| 1260 | dri2_img->dri_image = |
| 1261 | dri2_dpy->image->createImage(dri2_dpy->dri_screen, |
Chia-I Wu | 5664a983 | 2010-10-22 17:09:40 +0800 | [diff] [blame] | 1262 | attrs.Width, attrs.Height, |
| 1263 | format, dri_use, dri2_img); |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1264 | if (dri2_img->dri_image == NULL) { |
| 1265 | err = EGL_BAD_ALLOC; |
| 1266 | goto cleanup_img; |
| 1267 | } |
| 1268 | |
| 1269 | return &dri2_img->base; |
| 1270 | |
| 1271 | cleanup_img: |
| 1272 | free(dri2_img); |
| 1273 | _eglError(err, "dri2_create_drm_image_mesa"); |
| 1274 | |
| 1275 | return EGL_NO_IMAGE_KHR; |
| 1276 | } |
| 1277 | |
| 1278 | static EGLBoolean |
| 1279 | dri2_export_drm_image_mesa(_EGLDriver *drv, _EGLDisplay *disp, _EGLImage *img, |
| 1280 | EGLint *name, EGLint *handle, EGLint *stride) |
| 1281 | { |
| 1282 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1283 | struct dri2_egl_image *dri2_img = dri2_egl_image(img); |
| 1284 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 1285 | (void) drv; |
| 1286 | |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1287 | if (name && !dri2_dpy->image->queryImage(dri2_img->dri_image, |
| 1288 | __DRI_IMAGE_ATTRIB_NAME, name)) { |
| 1289 | _eglError(EGL_BAD_ALLOC, "dri2_export_drm_image_mesa"); |
| 1290 | return EGL_FALSE; |
| 1291 | } |
| 1292 | |
| 1293 | if (handle) |
| 1294 | dri2_dpy->image->queryImage(dri2_img->dri_image, |
| 1295 | __DRI_IMAGE_ATTRIB_HANDLE, handle); |
| 1296 | |
| 1297 | if (stride) |
| 1298 | dri2_dpy->image->queryImage(dri2_img->dri_image, |
| 1299 | __DRI_IMAGE_ATTRIB_STRIDE, stride); |
| 1300 | |
| 1301 | return EGL_TRUE; |
| 1302 | } |
| 1303 | |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1304 | #ifdef HAVE_WAYLAND_PLATFORM |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 1305 | |
Kristian Høgsberg | 379eb47 | 2012-07-05 14:19:48 -0400 | [diff] [blame] | 1306 | static void |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 1307 | dri2_wl_reference_buffer(void *user_data, uint32_t name, |
Kristian Høgsberg | 379eb47 | 2012-07-05 14:19:48 -0400 | [diff] [blame] | 1308 | struct wl_drm_buffer *buffer) |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 1309 | { |
| 1310 | _EGLDisplay *disp = user_data; |
| 1311 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1312 | int i; |
Kristian Høgsberg | 7b1d94e | 2011-08-31 16:45:04 -0400 | [diff] [blame] | 1313 | |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1314 | for (i = 0; i < ARRAY_SIZE(wl_drm_formats); i++) |
| 1315 | if (wl_drm_formats[i].wl_format == buffer->format) { |
| 1316 | buffer->driver_format = &wl_drm_formats[i]; |
| 1317 | break; |
| 1318 | } |
| 1319 | |
| 1320 | if (buffer->driver_format == NULL) |
Kristian Høgsberg | 379eb47 | 2012-07-05 14:19:48 -0400 | [diff] [blame] | 1321 | return; |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 1322 | |
Kristian Høgsberg | 379eb47 | 2012-07-05 14:19:48 -0400 | [diff] [blame] | 1323 | buffer->driver_buffer = |
| 1324 | dri2_dpy->image->createImageFromName(dri2_dpy->dri_screen, |
| 1325 | buffer->buffer.width, |
| 1326 | buffer->buffer.height, |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1327 | __DRI_IMAGE_FORMAT_NONE, name, |
Kristian Høgsberg | 1aaec8c | 2012-07-05 16:27:05 -0400 | [diff] [blame] | 1328 | buffer->stride[0] / 4, |
Kristian Høgsberg | 379eb47 | 2012-07-05 14:19:48 -0400 | [diff] [blame] | 1329 | NULL); |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 1330 | } |
| 1331 | |
| 1332 | static void |
Kristian Høgsberg | 379eb47 | 2012-07-05 14:19:48 -0400 | [diff] [blame] | 1333 | dri2_wl_release_buffer(void *user_data, struct wl_drm_buffer *buffer) |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 1334 | { |
| 1335 | _EGLDisplay *disp = user_data; |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 1336 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1337 | |
Kristian Høgsberg | 379eb47 | 2012-07-05 14:19:48 -0400 | [diff] [blame] | 1338 | dri2_dpy->image->destroyImage(buffer->driver_buffer); |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 1339 | } |
| 1340 | |
| 1341 | static struct wayland_drm_callbacks wl_drm_callbacks = { |
| 1342 | .authenticate = NULL, |
| 1343 | .reference_buffer = dri2_wl_reference_buffer, |
| 1344 | .release_buffer = dri2_wl_release_buffer |
| 1345 | }; |
| 1346 | |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1347 | static EGLBoolean |
| 1348 | dri2_bind_wayland_display_wl(_EGLDriver *drv, _EGLDisplay *disp, |
| 1349 | struct wl_display *wl_dpy) |
| 1350 | { |
| 1351 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1352 | |
| 1353 | (void) drv; |
| 1354 | |
| 1355 | if (dri2_dpy->wl_server_drm) |
| 1356 | return EGL_FALSE; |
| 1357 | |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 1358 | wl_drm_callbacks.authenticate = |
| 1359 | (int(*)(void *, uint32_t)) dri2_dpy->authenticate; |
| 1360 | |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1361 | dri2_dpy->wl_server_drm = |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 1362 | wayland_drm_init(wl_dpy, dri2_dpy->device_name, |
| 1363 | &wl_drm_callbacks, disp); |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1364 | |
| 1365 | if (!dri2_dpy->wl_server_drm) |
| 1366 | return EGL_FALSE; |
| 1367 | |
| 1368 | return EGL_TRUE; |
| 1369 | } |
| 1370 | |
| 1371 | static EGLBoolean |
| 1372 | dri2_unbind_wayland_display_wl(_EGLDriver *drv, _EGLDisplay *disp, |
| 1373 | struct wl_display *wl_dpy) |
| 1374 | { |
| 1375 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 1376 | |
| 1377 | (void) drv; |
| 1378 | |
| 1379 | if (!dri2_dpy->wl_server_drm) |
| 1380 | return EGL_FALSE; |
| 1381 | |
Benjamin Franzke | 834b841 | 2011-04-30 11:17:01 +0200 | [diff] [blame] | 1382 | wayland_drm_uninit(dri2_dpy->wl_server_drm); |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1383 | dri2_dpy->wl_server_drm = NULL; |
| 1384 | |
| 1385 | return EGL_TRUE; |
| 1386 | } |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1387 | |
| 1388 | static EGLBoolean |
| 1389 | dri2_query_wayland_buffer_wl(_EGLDriver *drv, _EGLDisplay *disp, |
| 1390 | struct wl_buffer *_buffer, |
| 1391 | EGLint attribute, EGLint *value) |
| 1392 | { |
| 1393 | struct wl_drm_buffer *buffer = (struct wl_drm_buffer *) _buffer; |
| 1394 | const struct wl_drm_format_descriptor *format; |
| 1395 | |
| 1396 | if (!wayland_buffer_is_drm(&buffer->buffer)) |
| 1397 | return EGL_FALSE; |
| 1398 | |
| 1399 | format = buffer->driver_format; |
Kristian Høgsberg | d7522ed | 2012-07-19 09:02:25 -0400 | [diff] [blame] | 1400 | switch (attribute) { |
| 1401 | case EGL_TEXTURE_FORMAT: |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1402 | *value = format->components; |
| 1403 | return EGL_TRUE; |
Kristian Høgsberg | d7522ed | 2012-07-19 09:02:25 -0400 | [diff] [blame] | 1404 | case EGL_WIDTH: |
| 1405 | *value = buffer->buffer.width; |
| 1406 | break; |
| 1407 | case EGL_HEIGHT: |
| 1408 | *value = buffer->buffer.height; |
| 1409 | break; |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1410 | } |
| 1411 | |
| 1412 | return EGL_FALSE; |
| 1413 | } |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1414 | #endif |
| 1415 | |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 1416 | static void |
| 1417 | dri2_unload(_EGLDriver *drv) |
| 1418 | { |
| 1419 | struct dri2_egl_driver *dri2_drv = dri2_egl_driver(drv); |
Chia-I Wu | 218381d | 2011-01-30 05:09:06 +0800 | [diff] [blame] | 1420 | |
| 1421 | if (dri2_drv->handle) |
| 1422 | dlclose(dri2_drv->handle); |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 1423 | free(dri2_drv); |
| 1424 | } |
| 1425 | |
| 1426 | static EGLBoolean |
| 1427 | dri2_load(_EGLDriver *drv) |
| 1428 | { |
| 1429 | struct dri2_egl_driver *dri2_drv = dri2_egl_driver(drv); |
Matt Turner | 027ce0c | 2012-01-24 11:34:42 -0500 | [diff] [blame] | 1430 | #ifdef HAVE_SHARED_GLAPI |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 1431 | #ifdef HAVE_ANDROID_PLATFORM |
| 1432 | const char *libname = "libglapi.so"; |
| 1433 | #else |
Chia-I Wu | 218381d | 2011-01-30 05:09:06 +0800 | [diff] [blame] | 1434 | const char *libname = "libglapi.so.0"; |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 1435 | #endif |
Matt Turner | 027ce0c | 2012-01-24 11:34:42 -0500 | [diff] [blame] | 1436 | #else |
| 1437 | /* |
| 1438 | * Both libGL.so and libglapi.so are glapi providers. There is no way to |
| 1439 | * tell which one to load. |
| 1440 | */ |
| 1441 | const char *libname = NULL; |
| 1442 | #endif |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 1443 | void *handle; |
| 1444 | |
Chia-I Wu | 218381d | 2011-01-30 05:09:06 +0800 | [diff] [blame] | 1445 | /* RTLD_GLOBAL to make sure glapi symbols are visible to DRI drivers */ |
| 1446 | handle = dlopen(libname, RTLD_LAZY | RTLD_GLOBAL); |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 1447 | if (handle) { |
| 1448 | dri2_drv->get_proc_address = (_EGLProc (*)(const char *)) |
| 1449 | dlsym(handle, "_glapi_get_proc_address"); |
Chia-I Wu | 218381d | 2011-01-30 05:09:06 +0800 | [diff] [blame] | 1450 | if (!dri2_drv->get_proc_address || !libname) { |
| 1451 | /* no need to keep a reference */ |
| 1452 | dlclose(handle); |
| 1453 | handle = NULL; |
| 1454 | } |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 1455 | } |
| 1456 | |
Chia-I Wu | 218381d | 2011-01-30 05:09:06 +0800 | [diff] [blame] | 1457 | /* if glapi is not available, loading DRI drivers will fail */ |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 1458 | if (!dri2_drv->get_proc_address) { |
| 1459 | _eglLog(_EGL_WARNING, "DRI2: failed to find _glapi_get_proc_address"); |
| 1460 | return EGL_FALSE; |
| 1461 | } |
| 1462 | |
| 1463 | dri2_drv->glFlush = (void (*)(void)) |
| 1464 | dri2_drv->get_proc_address("glFlush"); |
| 1465 | |
Chia-I Wu | 218381d | 2011-01-30 05:09:06 +0800 | [diff] [blame] | 1466 | dri2_drv->handle = handle; |
| 1467 | |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 1468 | return EGL_TRUE; |
| 1469 | } |
| 1470 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1471 | /** |
| 1472 | * This is the main entrypoint into the driver, called by libEGL. |
| 1473 | * Create a new _EGLDriver object and init its dispatch table. |
| 1474 | */ |
| 1475 | _EGLDriver * |
Eric Anholt | 9f0f00c | 2012-02-05 07:01:17 +0100 | [diff] [blame] | 1476 | _eglBuiltInDriverDRI2(const char *args) |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1477 | { |
| 1478 | struct dri2_egl_driver *dri2_drv; |
| 1479 | |
Ian Romanick | eade946 | 2010-09-23 09:39:42 -0700 | [diff] [blame] | 1480 | (void) args; |
| 1481 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1482 | dri2_drv = malloc(sizeof *dri2_drv); |
| 1483 | if (!dri2_drv) |
| 1484 | return NULL; |
| 1485 | |
Chia-I Wu | 39812c4 | 2011-01-12 18:06:47 +0800 | [diff] [blame] | 1486 | memset(dri2_drv, 0, sizeof *dri2_drv); |
| 1487 | |
Völgyes Dávid | f747d03 | 2011-07-06 10:10:20 -0400 | [diff] [blame] | 1488 | if (!dri2_load(&dri2_drv->base)) { |
| 1489 | free(dri2_drv); |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 1490 | return NULL; |
Völgyes Dávid | f747d03 | 2011-07-06 10:10:20 -0400 | [diff] [blame] | 1491 | } |
Chia-I Wu | fef5d14 | 2011-01-07 15:02:41 +0800 | [diff] [blame] | 1492 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1493 | _eglInitDriverFallbacks(&dri2_drv->base); |
| 1494 | dri2_drv->base.API.Initialize = dri2_initialize; |
| 1495 | dri2_drv->base.API.Terminate = dri2_terminate; |
| 1496 | dri2_drv->base.API.CreateContext = dri2_create_context; |
Cooper Yuan | f5e757e | 2011-08-14 15:14:17 +0800 | [diff] [blame] | 1497 | dri2_drv->base.API.DestroyContext = dri2_destroy_context; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1498 | dri2_drv->base.API.MakeCurrent = dri2_make_current; |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1499 | dri2_drv->base.API.GetProcAddress = dri2_get_proc_address; |
| 1500 | dri2_drv->base.API.WaitClient = dri2_wait_client; |
| 1501 | dri2_drv->base.API.WaitNative = dri2_wait_native; |
Kristian Høgsberg | bba5a98 | 2010-02-09 15:49:28 -0500 | [diff] [blame] | 1502 | dri2_drv->base.API.BindTexImage = dri2_bind_tex_image; |
| 1503 | dri2_drv->base.API.ReleaseTexImage = dri2_release_tex_image; |
Kristian Høgsberg | f4e7d1b | 2010-02-11 19:28:26 -0500 | [diff] [blame] | 1504 | dri2_drv->base.API.CreateImageKHR = dri2_create_image_khr; |
| 1505 | dri2_drv->base.API.DestroyImageKHR = dri2_destroy_image_khr; |
Kristian Høgsberg | 5aaa53e | 2010-06-03 21:36:40 -0400 | [diff] [blame] | 1506 | dri2_drv->base.API.CreateDRMImageMESA = dri2_create_drm_image_mesa; |
| 1507 | dri2_drv->base.API.ExportDRMImageMESA = dri2_export_drm_image_mesa; |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1508 | #ifdef HAVE_WAYLAND_PLATFORM |
| 1509 | dri2_drv->base.API.BindWaylandDisplayWL = dri2_bind_wayland_display_wl; |
| 1510 | dri2_drv->base.API.UnbindWaylandDisplayWL = dri2_unbind_wayland_display_wl; |
Kristian Høgsberg | e6a3357 | 2012-07-05 16:43:04 -0400 | [diff] [blame] | 1511 | dri2_drv->base.API.QueryWaylandBufferWL = dri2_query_wayland_buffer_wl; |
Benjamin Franzke | 6b369c4 | 2011-02-21 16:22:34 +0100 | [diff] [blame] | 1512 | #endif |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1513 | |
| 1514 | dri2_drv->base.Name = "DRI2"; |
| 1515 | dri2_drv->base.Unload = dri2_unload; |
| 1516 | |
Kristian Høgsberg | 42fa009 | 2010-02-03 10:18:28 -0500 | [diff] [blame] | 1517 | return &dri2_drv->base; |
| 1518 | } |