Haixia Shi | 6b8accb | 2015-06-12 10:10:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Mesa 3-D graphics library |
| 3 | * |
| 4 | * Copyright (c) 2014 The Chromium OS Authors. |
| 5 | * Copyright © 2011 Intel Corporation |
| 6 | * |
| 7 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 8 | * copy of this software and associated documentation files (the "Software"), |
| 9 | * to deal in the Software without restriction, including without limitation |
| 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 11 | * and/or sell copies of the Software, and to permit persons to whom the |
| 12 | * Software is furnished to do so, subject to the following conditions: |
| 13 | * |
| 14 | * The above copyright notice and this permission notice shall be included |
| 15 | * in all copies or substantial portions of the Software. |
| 16 | * |
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 20 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 23 | * DEALINGS IN THE SOFTWARE. |
| 24 | */ |
| 25 | |
| 26 | #include <stdlib.h> |
| 27 | #include <stdio.h> |
| 28 | #include <string.h> |
| 29 | #include <xf86drm.h> |
| 30 | #include <dlfcn.h> |
| 31 | #include <sys/types.h> |
| 32 | #include <sys/stat.h> |
| 33 | #include <fcntl.h> |
| 34 | #include <unistd.h> |
| 35 | |
| 36 | #include "egl_dri2.h" |
Haixia Shi | 6b8accb | 2015-06-12 10:10:58 -0700 | [diff] [blame] | 37 | #include "loader.h" |
| 38 | |
Gurchetan Singh | 63c5d5c | 2016-05-16 16:34:07 -0700 | [diff] [blame] | 39 | static __DRIimage* |
| 40 | surfaceless_alloc_image(struct dri2_egl_display *dri2_dpy, |
| 41 | struct dri2_egl_surface *dri2_surf) |
| 42 | { |
| 43 | return dri2_dpy->image->createImage( |
| 44 | dri2_dpy->dri_screen, |
| 45 | dri2_surf->base.Width, |
| 46 | dri2_surf->base.Height, |
| 47 | dri2_surf->visual, |
| 48 | 0, |
| 49 | NULL); |
| 50 | } |
| 51 | |
| 52 | static void |
| 53 | surfaceless_free_images(struct dri2_egl_surface *dri2_surf) |
| 54 | { |
| 55 | struct dri2_egl_display *dri2_dpy = |
| 56 | dri2_egl_display(dri2_surf->base.Resource.Display); |
| 57 | |
| 58 | if (dri2_surf->front) { |
| 59 | dri2_dpy->image->destroyImage(dri2_surf->front); |
| 60 | dri2_surf->front = NULL; |
| 61 | } |
Mathias Fröhlich | c7617d8 | 2019-12-13 17:09:56 +0100 | [diff] [blame] | 62 | |
| 63 | free(dri2_surf->swrast_device_buffer); |
| 64 | dri2_surf->swrast_device_buffer = NULL; |
Gurchetan Singh | 63c5d5c | 2016-05-16 16:34:07 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | static int |
| 68 | surfaceless_image_get_buffers(__DRIdrawable *driDrawable, |
| 69 | unsigned int format, |
| 70 | uint32_t *stamp, |
| 71 | void *loaderPrivate, |
| 72 | uint32_t buffer_mask, |
| 73 | struct __DRIimageList *buffers) |
| 74 | { |
| 75 | struct dri2_egl_surface *dri2_surf = loaderPrivate; |
| 76 | struct dri2_egl_display *dri2_dpy = |
| 77 | dri2_egl_display(dri2_surf->base.Resource.Display); |
| 78 | |
| 79 | buffers->image_mask = 0; |
| 80 | buffers->front = NULL; |
| 81 | buffers->back = NULL; |
| 82 | |
| 83 | /* The EGL 1.5 spec states that pbuffers are single-buffered. Specifically, |
| 84 | * the spec states that they have a back buffer but no front buffer, in |
| 85 | * contrast to pixmaps, which have a front buffer but no back buffer. |
| 86 | * |
| 87 | * Single-buffered surfaces with no front buffer confuse Mesa; so we deviate |
| 88 | * from the spec, following the precedent of Mesa's EGL X11 platform. The |
| 89 | * X11 platform correctly assigns pbuffers to single-buffered configs, but |
| 90 | * assigns the pbuffer a front buffer instead of a back buffer. |
| 91 | * |
| 92 | * Pbuffers in the X11 platform mostly work today, so let's just copy its |
| 93 | * behavior instead of trying to fix (and hence potentially breaking) the |
| 94 | * world. |
| 95 | */ |
| 96 | |
| 97 | if (buffer_mask & __DRI_IMAGE_BUFFER_FRONT) { |
| 98 | |
| 99 | if (!dri2_surf->front) |
| 100 | dri2_surf->front = |
| 101 | surfaceless_alloc_image(dri2_dpy, dri2_surf); |
| 102 | |
| 103 | buffers->image_mask |= __DRI_IMAGE_BUFFER_FRONT; |
| 104 | buffers->front = dri2_surf->front; |
| 105 | } |
| 106 | |
| 107 | return 1; |
| 108 | } |
| 109 | |
| 110 | static _EGLSurface * |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame^] | 111 | dri2_surfaceless_create_surface(const _EGLDriver *drv, _EGLDisplay *disp, EGLint type, |
Gurchetan Singh | 63c5d5c | 2016-05-16 16:34:07 -0700 | [diff] [blame] | 112 | _EGLConfig *conf, const EGLint *attrib_list) |
| 113 | { |
| 114 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 115 | struct dri2_egl_config *dri2_conf = dri2_egl_config(conf); |
| 116 | struct dri2_egl_surface *dri2_surf; |
| 117 | const __DRIconfig *config; |
| 118 | |
| 119 | /* Make sure to calloc so all pointers |
| 120 | * are originally NULL. |
| 121 | */ |
| 122 | dri2_surf = calloc(1, sizeof *dri2_surf); |
| 123 | |
| 124 | if (!dri2_surf) { |
| 125 | _eglError(EGL_BAD_ALLOC, "eglCreatePbufferSurface"); |
| 126 | return NULL; |
| 127 | } |
| 128 | |
Paulo Zanoni | 04ecda3 | 2019-05-01 15:42:26 -0700 | [diff] [blame] | 129 | if (!dri2_init_surface(&dri2_surf->base, disp, type, conf, attrib_list, |
| 130 | false, NULL)) |
Gurchetan Singh | 63c5d5c | 2016-05-16 16:34:07 -0700 | [diff] [blame] | 131 | goto cleanup_surface; |
| 132 | |
| 133 | config = dri2_get_dri_config(dri2_conf, type, |
| 134 | dri2_surf->base.GLColorspace); |
| 135 | |
Tapani Pälli | affe63b | 2018-05-04 08:28:50 +0300 | [diff] [blame] | 136 | if (!config) { |
| 137 | _eglError(EGL_BAD_MATCH, "Unsupported surfacetype/colorspace configuration"); |
Gurchetan Singh | 63c5d5c | 2016-05-16 16:34:07 -0700 | [diff] [blame] | 138 | goto cleanup_surface; |
Tapani Pälli | affe63b | 2018-05-04 08:28:50 +0300 | [diff] [blame] | 139 | } |
Gurchetan Singh | 63c5d5c | 2016-05-16 16:34:07 -0700 | [diff] [blame] | 140 | |
Mathias Fröhlich | d32c458 | 2020-02-09 19:01:53 +0100 | [diff] [blame] | 141 | dri2_surf->visual = dri2_image_format_for_pbuffer_config(dri2_dpy, config); |
| 142 | if (dri2_surf->visual == __DRI_IMAGE_FORMAT_NONE) |
Gurchetan Singh | 63c5d5c | 2016-05-16 16:34:07 -0700 | [diff] [blame] | 143 | goto cleanup_surface; |
Gurchetan Singh | 63c5d5c | 2016-05-16 16:34:07 -0700 | [diff] [blame] | 144 | |
Mathias Fröhlich | d32c458 | 2020-02-09 19:01:53 +0100 | [diff] [blame] | 145 | if (!dri2_create_drawable(dri2_dpy, config, dri2_surf, dri2_surf)) |
| 146 | goto cleanup_surface; |
Gurchetan Singh | 63c5d5c | 2016-05-16 16:34:07 -0700 | [diff] [blame] | 147 | |
| 148 | return &dri2_surf->base; |
| 149 | |
| 150 | cleanup_surface: |
| 151 | free(dri2_surf); |
| 152 | return NULL; |
| 153 | } |
| 154 | |
| 155 | static EGLBoolean |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame^] | 156 | surfaceless_destroy_surface(const _EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf) |
Gurchetan Singh | 63c5d5c | 2016-05-16 16:34:07 -0700 | [diff] [blame] | 157 | { |
| 158 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 159 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); |
| 160 | |
Gurchetan Singh | 63c5d5c | 2016-05-16 16:34:07 -0700 | [diff] [blame] | 161 | surfaceless_free_images(dri2_surf); |
| 162 | |
Boyan Ding | 868ae3e | 2015-11-25 13:27:02 +0800 | [diff] [blame] | 163 | dri2_dpy->core->destroyDrawable(dri2_surf->dri_drawable); |
Gurchetan Singh | 63c5d5c | 2016-05-16 16:34:07 -0700 | [diff] [blame] | 164 | |
Zhongmin Wu | e013ce8 | 2017-09-15 18:32:42 +0100 | [diff] [blame] | 165 | dri2_fini_surface(surf); |
Gurchetan Singh | 63c5d5c | 2016-05-16 16:34:07 -0700 | [diff] [blame] | 166 | free(dri2_surf); |
| 167 | return EGL_TRUE; |
| 168 | } |
| 169 | |
| 170 | static _EGLSurface * |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame^] | 171 | dri2_surfaceless_create_pbuffer_surface(const _EGLDriver *drv, _EGLDisplay *disp, |
Gurchetan Singh | 63c5d5c | 2016-05-16 16:34:07 -0700 | [diff] [blame] | 172 | _EGLConfig *conf, const EGLint *attrib_list) |
| 173 | { |
| 174 | return dri2_surfaceless_create_surface(drv, disp, EGL_PBUFFER_BIT, conf, |
| 175 | attrib_list); |
| 176 | } |
| 177 | |
Emil Velikov | 79d1fb9 | 2017-05-15 16:14:17 +0100 | [diff] [blame] | 178 | static const struct dri2_egl_display_vtbl dri2_surfaceless_display_vtbl = { |
Gurchetan Singh | 63c5d5c | 2016-05-16 16:34:07 -0700 | [diff] [blame] | 179 | .create_pbuffer_surface = dri2_surfaceless_create_pbuffer_surface, |
| 180 | .destroy_surface = surfaceless_destroy_surface, |
Haixia Shi | 6b8accb | 2015-06-12 10:10:58 -0700 | [diff] [blame] | 181 | .create_image = dri2_create_image_khr, |
Gurchetan Singh | 63c5d5c | 2016-05-16 16:34:07 -0700 | [diff] [blame] | 182 | .get_dri_drawable = dri2_surface_get_dri_drawable, |
Haixia Shi | 6b8accb | 2015-06-12 10:10:58 -0700 | [diff] [blame] | 183 | }; |
| 184 | |
| 185 | static void |
| 186 | surfaceless_flush_front_buffer(__DRIdrawable *driDrawable, void *loaderPrivate) |
| 187 | { |
| 188 | } |
| 189 | |
Adam Jackson | 55a1b58 | 2019-09-10 11:44:24 -0400 | [diff] [blame] | 190 | static unsigned |
| 191 | surfaceless_get_capability(void *loaderPrivate, enum dri_loader_cap cap) |
| 192 | { |
| 193 | /* Note: loaderPrivate is _EGLDisplay* */ |
| 194 | switch (cap) { |
| 195 | case DRI_LOADER_CAP_FP16: |
| 196 | return 1; |
| 197 | default: |
| 198 | return 0; |
| 199 | } |
| 200 | } |
| 201 | |
Gurchetan Singh | 63c5d5c | 2016-05-16 16:34:07 -0700 | [diff] [blame] | 202 | static const __DRIimageLoaderExtension image_loader_extension = { |
Adam Jackson | 55a1b58 | 2019-09-10 11:44:24 -0400 | [diff] [blame] | 203 | .base = { __DRI_IMAGE_LOADER, 2 }, |
Gurchetan Singh | 63c5d5c | 2016-05-16 16:34:07 -0700 | [diff] [blame] | 204 | .getBuffers = surfaceless_image_get_buffers, |
| 205 | .flushFrontBuffer = surfaceless_flush_front_buffer, |
Adam Jackson | 55a1b58 | 2019-09-10 11:44:24 -0400 | [diff] [blame] | 206 | .getCapability = surfaceless_get_capability, |
Gurchetan Singh | 63c5d5c | 2016-05-16 16:34:07 -0700 | [diff] [blame] | 207 | }; |
| 208 | |
Emil Velikov | f871946 | 2016-08-24 23:32:27 +0100 | [diff] [blame] | 209 | static const __DRIextension *image_loader_extensions[] = { |
| 210 | &image_loader_extension.base, |
| 211 | &image_lookup_extension.base, |
| 212 | &use_invalidate.base, |
| 213 | NULL, |
| 214 | }; |
| 215 | |
David Riley | b169b84 | 2018-07-17 17:12:04 -0700 | [diff] [blame] | 216 | static const __DRIextension *swrast_loader_extensions[] = { |
Eric Anholt | 6a8d39dc | 2019-07-23 13:18:21 -0700 | [diff] [blame] | 217 | &swrast_pbuffer_loader_extension.base, |
David Riley | b169b84 | 2018-07-17 17:12:04 -0700 | [diff] [blame] | 218 | &image_loader_extension.base, |
| 219 | &image_lookup_extension.base, |
| 220 | &use_invalidate.base, |
| 221 | NULL, |
| 222 | }; |
| 223 | |
Gurchetan Singh | 540c804 | 2017-10-02 13:43:57 -0700 | [diff] [blame] | 224 | static bool |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 225 | surfaceless_probe_device(_EGLDisplay *disp, bool swrast) |
Gurchetan Singh | 540c804 | 2017-10-02 13:43:57 -0700 | [diff] [blame] | 226 | { |
Emil Velikov | 218c7b5 | 2019-02-19 14:08:07 +0000 | [diff] [blame] | 227 | #define MAX_DRM_DEVICES 64 |
Emil Velikov | 7ad1a05 | 2019-02-19 14:08:08 +0000 | [diff] [blame] | 228 | const unsigned node_type = swrast ? DRM_NODE_PRIMARY : DRM_NODE_RENDER; |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 229 | struct dri2_egl_display *dri2_dpy = disp->DriverData; |
Emil Velikov | 218c7b5 | 2019-02-19 14:08:07 +0000 | [diff] [blame] | 230 | drmDevicePtr device, devices[MAX_DRM_DEVICES] = { NULL }; |
| 231 | int i, num_devices; |
Gurchetan Singh | 540c804 | 2017-10-02 13:43:57 -0700 | [diff] [blame] | 232 | |
Emil Velikov | 218c7b5 | 2019-02-19 14:08:07 +0000 | [diff] [blame] | 233 | num_devices = drmGetDevices2(0, devices, ARRAY_SIZE(devices)); |
| 234 | if (num_devices < 0) |
| 235 | return false; |
| 236 | |
| 237 | for (i = 0; i < num_devices; ++i) { |
| 238 | device = devices[i]; |
| 239 | |
Emil Velikov | 7ad1a05 | 2019-02-19 14:08:08 +0000 | [diff] [blame] | 240 | if (!(device->available_nodes & (1 << node_type))) |
Gurchetan Singh | 540c804 | 2017-10-02 13:43:57 -0700 | [diff] [blame] | 241 | continue; |
| 242 | |
Emil Velikov | 7ad1a05 | 2019-02-19 14:08:08 +0000 | [diff] [blame] | 243 | dri2_dpy->fd = loader_open_device(device->nodes[node_type]); |
Emil Velikov | 218c7b5 | 2019-02-19 14:08:07 +0000 | [diff] [blame] | 244 | if (dri2_dpy->fd < 0) |
Gurchetan Singh | 540c804 | 2017-10-02 13:43:57 -0700 | [diff] [blame] | 245 | continue; |
| 246 | |
Emil Velikov | 218c7b5 | 2019-02-19 14:08:07 +0000 | [diff] [blame] | 247 | disp->Device = _eglAddDevice(dri2_dpy->fd, swrast); |
| 248 | if (!disp->Device) { |
| 249 | close(dri2_dpy->fd); |
| 250 | dri2_dpy->fd = -1; |
| 251 | continue; |
| 252 | } |
| 253 | |
Emil Velikov | 7ad1a05 | 2019-02-19 14:08:08 +0000 | [diff] [blame] | 254 | char *driver_name = loader_get_driver_for_fd(dri2_dpy->fd); |
| 255 | if (swrast) { |
Gurchetan Singh | 610758d | 2019-03-01 18:58:16 -0800 | [diff] [blame] | 256 | /* Use kms swrast only with vgem / virtio_gpu. |
| 257 | * virtio-gpu fallbacks to software rendering when 3D features |
| 258 | * are unavailable since 6c5ab, and kms_swrast is more |
| 259 | * feature complete than swrast. |
| 260 | */ |
Eric Anholt | 86ae3c2 | 2019-07-29 16:25:56 -0700 | [diff] [blame] | 261 | if (driver_name && |
| 262 | (strcmp(driver_name, "vgem") == 0 || |
| 263 | strcmp(driver_name, "virtio_gpu") == 0)) |
Emil Velikov | 7ad1a05 | 2019-02-19 14:08:08 +0000 | [diff] [blame] | 264 | dri2_dpy->driver_name = strdup("kms_swrast"); |
| 265 | free(driver_name); |
| 266 | } else { |
| 267 | /* Use the given hardware driver */ |
| 268 | dri2_dpy->driver_name = driver_name; |
| 269 | } |
Gurchetan Singh | 540c804 | 2017-10-02 13:43:57 -0700 | [diff] [blame] | 270 | |
Emil Velikov | 218c7b5 | 2019-02-19 14:08:07 +0000 | [diff] [blame] | 271 | if (dri2_dpy->driver_name && dri2_load_driver_dri3(disp)) |
| 272 | break; |
Gurchetan Singh | 540c804 | 2017-10-02 13:43:57 -0700 | [diff] [blame] | 273 | |
Gurchetan Singh | 540c804 | 2017-10-02 13:43:57 -0700 | [diff] [blame] | 274 | free(dri2_dpy->driver_name); |
| 275 | dri2_dpy->driver_name = NULL; |
Emil Velikov | 218c7b5 | 2019-02-19 14:08:07 +0000 | [diff] [blame] | 276 | close(dri2_dpy->fd); |
| 277 | dri2_dpy->fd = -1; |
Gurchetan Singh | 540c804 | 2017-10-02 13:43:57 -0700 | [diff] [blame] | 278 | } |
Emil Velikov | 218c7b5 | 2019-02-19 14:08:07 +0000 | [diff] [blame] | 279 | drmFreeDevices(devices, num_devices); |
Gurchetan Singh | 540c804 | 2017-10-02 13:43:57 -0700 | [diff] [blame] | 280 | |
Emil Velikov | 218c7b5 | 2019-02-19 14:08:07 +0000 | [diff] [blame] | 281 | if (i == num_devices) |
| 282 | return false; |
| 283 | |
| 284 | if (swrast) |
| 285 | dri2_dpy->loader_extensions = swrast_loader_extensions; |
| 286 | else |
| 287 | dri2_dpy->loader_extensions = image_loader_extensions; |
| 288 | |
| 289 | return true; |
Emil Velikov | 893421f | 2019-02-19 14:08:06 +0000 | [diff] [blame] | 290 | } |
David Riley | f94681b | 2018-07-17 17:12:05 -0700 | [diff] [blame] | 291 | |
Emil Velikov | 893421f | 2019-02-19 14:08:06 +0000 | [diff] [blame] | 292 | static bool |
| 293 | surfaceless_probe_device_sw(_EGLDisplay *disp) |
| 294 | { |
| 295 | struct dri2_egl_display *dri2_dpy = disp->DriverData; |
David Riley | f94681b | 2018-07-17 17:12:05 -0700 | [diff] [blame] | 296 | |
Emil Velikov | 893421f | 2019-02-19 14:08:06 +0000 | [diff] [blame] | 297 | dri2_dpy->fd = -1; |
| 298 | disp->Device = _eglAddDevice(dri2_dpy->fd, true); |
| 299 | assert(disp->Device); |
| 300 | |
| 301 | dri2_dpy->driver_name = strdup("swrast"); |
| 302 | if (!dri2_dpy->driver_name) |
| 303 | return false; |
| 304 | |
| 305 | if (!dri2_load_driver_swrast(disp)) { |
David Riley | f94681b | 2018-07-17 17:12:05 -0700 | [diff] [blame] | 306 | free(dri2_dpy->driver_name); |
| 307 | dri2_dpy->driver_name = NULL; |
Emil Velikov | 893421f | 2019-02-19 14:08:06 +0000 | [diff] [blame] | 308 | return false; |
David Riley | f94681b | 2018-07-17 17:12:05 -0700 | [diff] [blame] | 309 | } |
| 310 | |
Emil Velikov | 893421f | 2019-02-19 14:08:06 +0000 | [diff] [blame] | 311 | dri2_dpy->loader_extensions = swrast_loader_extensions; |
| 312 | return true; |
Gurchetan Singh | 540c804 | 2017-10-02 13:43:57 -0700 | [diff] [blame] | 313 | } |
| 314 | |
Haixia Shi | 6b8accb | 2015-06-12 10:10:58 -0700 | [diff] [blame] | 315 | EGLBoolean |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame^] | 316 | dri2_initialize_surfaceless(const _EGLDriver *drv, _EGLDisplay *disp) |
Haixia Shi | 6b8accb | 2015-06-12 10:10:58 -0700 | [diff] [blame] | 317 | { |
| 318 | struct dri2_egl_display *dri2_dpy; |
| 319 | const char* err; |
Gurchetan Singh | 9d9a46d | 2017-10-02 13:48:24 -0700 | [diff] [blame] | 320 | bool driver_loaded = false; |
Haixia Shi | 6b8accb | 2015-06-12 10:10:58 -0700 | [diff] [blame] | 321 | |
Haixia Shi | 6b8accb | 2015-06-12 10:10:58 -0700 | [diff] [blame] | 322 | dri2_dpy = calloc(1, sizeof *dri2_dpy); |
| 323 | if (!dri2_dpy) |
| 324 | return _eglError(EGL_BAD_ALLOC, "eglInitialize"); |
| 325 | |
Emil Velikov | c8d366b | 2017-05-11 17:22:35 +0100 | [diff] [blame] | 326 | dri2_dpy->fd = -1; |
Haixia Shi | 6b8accb | 2015-06-12 10:10:58 -0700 | [diff] [blame] | 327 | disp->DriverData = (void *) dri2_dpy; |
Gurchetan Singh | 9d9a46d | 2017-10-02 13:48:24 -0700 | [diff] [blame] | 328 | |
Eric Engestrom | 81cea66 | 2017-12-20 15:53:09 +0000 | [diff] [blame] | 329 | if (!disp->Options.ForceSoftware) { |
Gurchetan Singh | 9d9a46d | 2017-10-02 13:48:24 -0700 | [diff] [blame] | 330 | driver_loaded = surfaceless_probe_device(disp, false); |
| 331 | if (!driver_loaded) |
| 332 | _eglLog(_EGL_WARNING, |
| 333 | "No hardware driver found, falling back to software rendering"); |
| 334 | } |
| 335 | |
Emil Velikov | 893421f | 2019-02-19 14:08:06 +0000 | [diff] [blame] | 336 | if (!driver_loaded) |
| 337 | driver_loaded = surfaceless_probe_device(disp, true); |
| 338 | |
| 339 | if (!driver_loaded) { |
| 340 | _eglLog(_EGL_DEBUG, "Falling back to surfaceless swrast without DRM."); |
| 341 | if (!surfaceless_probe_device_sw(disp)) { |
| 342 | err = "DRI2: failed to load driver"; |
| 343 | goto cleanup; |
| 344 | } |
Haixia Shi | 6b8accb | 2015-06-12 10:10:58 -0700 | [diff] [blame] | 345 | } |
| 346 | |
Haixia Shi | 6b8accb | 2015-06-12 10:10:58 -0700 | [diff] [blame] | 347 | if (!dri2_create_screen(disp)) { |
| 348 | err = "DRI2: failed to create screen"; |
Emil Velikov | c8d366b | 2017-05-11 17:22:35 +0100 | [diff] [blame] | 349 | goto cleanup; |
Haixia Shi | 6b8accb | 2015-06-12 10:10:58 -0700 | [diff] [blame] | 350 | } |
| 351 | |
Emil Velikov | 2c341f2 | 2017-05-11 16:20:04 +0100 | [diff] [blame] | 352 | if (!dri2_setup_extensions(disp)) { |
| 353 | err = "DRI2: failed to find required DRI extensions"; |
| 354 | goto cleanup; |
| 355 | } |
| 356 | |
| 357 | dri2_setup_screen(disp); |
Adam Jackson | 3746ee9 | 2019-10-03 10:10:59 -0400 | [diff] [blame] | 358 | #ifdef HAVE_WAYLAND_PLATFORM |
| 359 | dri2_dpy->device_name = loader_get_device_name_for_fd(dri2_dpy->fd); |
| 360 | #endif |
| 361 | dri2_set_WL_bind_wayland_display(drv, disp); |
Emil Velikov | 2c341f2 | 2017-05-11 16:20:04 +0100 | [diff] [blame] | 362 | |
Mathias Fröhlich | f280c00 | 2020-02-16 11:13:43 +0100 | [diff] [blame] | 363 | if (!dri2_add_pbuffer_configs_for_visuals(drv, disp)) { |
Gurchetan Singh | 63c5d5c | 2016-05-16 16:34:07 -0700 | [diff] [blame] | 364 | err = "DRI2: failed to add configs"; |
Emil Velikov | c8d366b | 2017-05-11 17:22:35 +0100 | [diff] [blame] | 365 | goto cleanup; |
Haixia Shi | 6b8accb | 2015-06-12 10:10:58 -0700 | [diff] [blame] | 366 | } |
| 367 | |
Haixia Shi | 6b8accb | 2015-06-12 10:10:58 -0700 | [diff] [blame] | 368 | /* Fill vtbl last to prevent accidentally calling virtual function during |
| 369 | * initialization. |
| 370 | */ |
| 371 | dri2_dpy->vtbl = &dri2_surfaceless_display_vtbl; |
| 372 | |
| 373 | return EGL_TRUE; |
| 374 | |
Emil Velikov | c8d366b | 2017-05-11 17:22:35 +0100 | [diff] [blame] | 375 | cleanup: |
| 376 | dri2_display_destroy(disp); |
Haixia Shi | 6b8accb | 2015-06-12 10:10:58 -0700 | [diff] [blame] | 377 | return _eglError(EGL_NOT_INITIALIZED, err); |
| 378 | } |