2 * Copyright © 2011 Intel Corporation
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:
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
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.
25 * Kristian Høgsberg <krh@bitplanet.net>
34 #include <sys/types.h>
40 #include "egl_dri2_fallbacks.h"
43 static struct gbm_bo
*
44 lock_front_buffer(struct gbm_surface
*_surf
)
46 struct gbm_dri_surface
*surf
= gbm_dri_surface(_surf
);
47 struct dri2_egl_surface
*dri2_surf
= surf
->dri_private
;
48 struct gbm_dri_device
*device
= gbm_dri_device(_surf
->gbm
);
51 if (dri2_surf
->current
== NULL
) {
52 _eglError(EGL_BAD_SURFACE
, "no front buffer");
56 bo
= dri2_surf
->current
->bo
;
59 dri2_surf
->current
->locked
= true;
60 dri2_surf
->current
= NULL
;
67 release_buffer(struct gbm_surface
*_surf
, struct gbm_bo
*bo
)
69 struct gbm_dri_surface
*surf
= gbm_dri_surface(_surf
);
70 struct dri2_egl_surface
*dri2_surf
= surf
->dri_private
;
72 for (unsigned i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
73 if (dri2_surf
->color_buffers
[i
].bo
== bo
) {
74 dri2_surf
->color_buffers
[i
].locked
= false;
81 has_free_buffers(struct gbm_surface
*_surf
)
83 struct gbm_dri_surface
*surf
= gbm_dri_surface(_surf
);
84 struct dri2_egl_surface
*dri2_surf
= surf
->dri_private
;
86 for (unsigned i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++)
87 if (!dri2_surf
->color_buffers
[i
].locked
)
94 dri2_drm_config_is_compatible(struct dri2_egl_display
*dri2_dpy
,
95 const __DRIconfig
*config
,
96 struct gbm_surface
*surface
)
98 const struct gbm_dri_visual
*visual
= NULL
;
99 unsigned int red
, green
, blue
, alpha
;
102 /* Check that the EGLConfig being used to render to the surface is
103 * compatible with the surface format. Since mixing ARGB and XRGB of
104 * otherwise-compatible formats is relatively common, explicitly allow
107 dri2_dpy
->core
->getConfigAttrib(config
, __DRI_ATTRIB_RED_MASK
, &red
);
108 dri2_dpy
->core
->getConfigAttrib(config
, __DRI_ATTRIB_GREEN_MASK
, &green
);
109 dri2_dpy
->core
->getConfigAttrib(config
, __DRI_ATTRIB_BLUE_MASK
, &blue
);
110 dri2_dpy
->core
->getConfigAttrib(config
, __DRI_ATTRIB_ALPHA_MASK
, &alpha
);
112 for (i
= 0; i
< dri2_dpy
->gbm_dri
->num_visuals
; i
++) {
113 visual
= &dri2_dpy
->gbm_dri
->visual_table
[i
];
114 if (visual
->gbm_format
== surface
->format
)
118 if (i
== dri2_dpy
->gbm_dri
->num_visuals
)
121 if (red
!= visual
->rgba_masks
.red
||
122 green
!= visual
->rgba_masks
.green
||
123 blue
!= visual
->rgba_masks
.blue
||
124 (alpha
&& visual
->rgba_masks
.alpha
&& alpha
!= visual
->rgba_masks
.alpha
)) {
132 dri2_drm_create_window_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
133 _EGLConfig
*conf
, void *native_surface
,
134 const EGLint
*attrib_list
)
136 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
137 struct dri2_egl_config
*dri2_conf
= dri2_egl_config(conf
);
138 struct dri2_egl_surface
*dri2_surf
;
139 struct gbm_surface
*surface
= native_surface
;
140 struct gbm_dri_surface
*surf
;
141 const __DRIconfig
*config
;
145 dri2_surf
= calloc(1, sizeof *dri2_surf
);
147 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
151 if (!dri2_init_surface(&dri2_surf
->base
, disp
, EGL_WINDOW_BIT
, conf
,
155 config
= dri2_get_dri_config(dri2_conf
, EGL_WINDOW_BIT
,
156 dri2_surf
->base
.GLColorspace
);
159 _eglError(EGL_BAD_MATCH
, "Unsupported surfacetype/colorspace configuration");
163 if (!dri2_drm_config_is_compatible(dri2_dpy
, config
, surface
)) {
164 _eglError(EGL_BAD_MATCH
, "EGL config not compatible with GBM format");
168 surf
= gbm_dri_surface(surface
);
169 dri2_surf
->gbm_surf
= surf
;
170 dri2_surf
->base
.Width
= surf
->base
.width
;
171 dri2_surf
->base
.Height
= surf
->base
.height
;
172 surf
->dri_private
= dri2_surf
;
174 if (dri2_dpy
->dri2
) {
175 dri2_surf
->dri_drawable
=
176 dri2_dpy
->dri2
->createNewDrawable(dri2_dpy
->dri_screen
, config
,
177 dri2_surf
->gbm_surf
);
180 assert(dri2_dpy
->swrast
!= NULL
);
182 dri2_surf
->dri_drawable
=
183 dri2_dpy
->swrast
->createNewDrawable(dri2_dpy
->dri_screen
, config
,
184 dri2_surf
->gbm_surf
);
187 if (dri2_surf
->dri_drawable
== NULL
) {
188 _eglError(EGL_BAD_ALLOC
, "createNewDrawable()");
192 return &dri2_surf
->base
;
201 dri2_drm_create_pixmap_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
202 _EGLConfig
*conf
, void *native_window
,
203 const EGLint
*attrib_list
)
205 /* From the EGL_MESA_platform_gbm spec, version 5:
207 * It is not valid to call eglCreatePlatformPixmapSurfaceEXT with a <dpy>
208 * that belongs to the GBM platform. Any such call fails and generates
211 _eglError(EGL_BAD_PARAMETER
, "cannot create EGL pixmap surfaces on GBM");
216 dri2_drm_destroy_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*surf
)
218 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
219 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
221 dri2_dpy
->core
->destroyDrawable(dri2_surf
->dri_drawable
);
223 for (unsigned i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
224 if (dri2_surf
->color_buffers
[i
].bo
)
225 gbm_bo_destroy(dri2_surf
->color_buffers
[i
].bo
);
228 dri2_egl_surface_free_local_buffers(dri2_surf
);
230 dri2_fini_surface(surf
);
237 get_back_bo(struct dri2_egl_surface
*dri2_surf
)
239 struct dri2_egl_display
*dri2_dpy
=
240 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
241 struct gbm_dri_surface
*surf
= dri2_surf
->gbm_surf
;
244 if (dri2_surf
->back
== NULL
) {
245 for (unsigned i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
246 if (!dri2_surf
->color_buffers
[i
].locked
&&
247 dri2_surf
->color_buffers
[i
].age
>= age
) {
248 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
249 age
= dri2_surf
->color_buffers
[i
].age
;
254 if (dri2_surf
->back
== NULL
)
256 if (dri2_surf
->back
->bo
== NULL
) {
257 if (surf
->base
.modifiers
)
258 dri2_surf
->back
->bo
= gbm_bo_create_with_modifiers(&dri2_dpy
->gbm_dri
->base
,
262 surf
->base
.modifiers
,
265 dri2_surf
->back
->bo
= gbm_bo_create(&dri2_dpy
->gbm_dri
->base
,
272 if (dri2_surf
->back
->bo
== NULL
)
279 get_swrast_front_bo(struct dri2_egl_surface
*dri2_surf
)
281 struct dri2_egl_display
*dri2_dpy
=
282 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
283 struct gbm_dri_surface
*surf
= dri2_surf
->gbm_surf
;
285 if (dri2_surf
->current
== NULL
) {
286 assert(!dri2_surf
->color_buffers
[0].locked
);
287 dri2_surf
->current
= &dri2_surf
->color_buffers
[0];
290 if (dri2_surf
->current
->bo
== NULL
)
291 dri2_surf
->current
->bo
= gbm_bo_create(&dri2_dpy
->gbm_dri
->base
,
292 surf
->base
.width
, surf
->base
.height
,
293 surf
->base
.format
, surf
->base
.flags
);
294 if (dri2_surf
->current
->bo
== NULL
)
301 back_bo_to_dri_buffer(struct dri2_egl_surface
*dri2_surf
, __DRIbuffer
*buffer
)
303 struct dri2_egl_display
*dri2_dpy
=
304 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
305 struct gbm_dri_bo
*bo
;
308 bo
= gbm_dri_bo(dri2_surf
->back
->bo
);
310 dri2_dpy
->image
->queryImage(bo
->image
, __DRI_IMAGE_ATTRIB_NAME
, &name
);
311 dri2_dpy
->image
->queryImage(bo
->image
, __DRI_IMAGE_ATTRIB_STRIDE
, &pitch
);
313 buffer
->attachment
= __DRI_BUFFER_BACK_LEFT
;
315 buffer
->pitch
= pitch
;
321 dri2_drm_get_buffers_with_format(__DRIdrawable
*driDrawable
,
322 int *width
, int *height
,
323 unsigned int *attachments
, int count
,
324 int *out_count
, void *loaderPrivate
)
326 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
329 for (i
= 0, j
= 0; i
< 2 * count
; i
+= 2, j
++) {
332 assert(attachments
[i
] < __DRI_BUFFER_COUNT
);
333 assert(j
< ARRAY_SIZE(dri2_surf
->buffers
));
335 switch (attachments
[i
]) {
336 case __DRI_BUFFER_BACK_LEFT
:
337 if (get_back_bo(dri2_surf
) < 0) {
338 _eglError(EGL_BAD_ALLOC
, "failed to allocate color buffer");
341 back_bo_to_dri_buffer(dri2_surf
, &dri2_surf
->buffers
[j
]);
344 local
= dri2_egl_surface_alloc_local_buffer(dri2_surf
, attachments
[i
],
348 _eglError(EGL_BAD_ALLOC
, "failed to allocate local buffer");
351 dri2_surf
->buffers
[j
] = *local
;
360 *width
= dri2_surf
->base
.Width
;
361 *height
= dri2_surf
->base
.Height
;
363 return dri2_surf
->buffers
;
367 dri2_drm_get_buffers(__DRIdrawable
* driDrawable
,
368 int *width
, int *height
,
369 unsigned int *attachments
, int count
,
370 int *out_count
, void *loaderPrivate
)
372 unsigned int *attachments_with_format
;
374 const unsigned int format
= 32;
376 attachments_with_format
= calloc(count
, 2 * sizeof(unsigned int));
377 if (!attachments_with_format
) {
382 for (int i
= 0; i
< count
; ++i
) {
383 attachments_with_format
[2*i
] = attachments
[i
];
384 attachments_with_format
[2*i
+ 1] = format
;
388 dri2_drm_get_buffers_with_format(driDrawable
,
390 attachments_with_format
, count
,
391 out_count
, loaderPrivate
);
393 free(attachments_with_format
);
399 dri2_drm_image_get_buffers(__DRIdrawable
*driDrawable
,
403 uint32_t buffer_mask
,
404 struct __DRIimageList
*buffers
)
406 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
407 struct gbm_dri_bo
*bo
;
409 if (get_back_bo(dri2_surf
) < 0)
412 bo
= gbm_dri_bo(dri2_surf
->back
->bo
);
413 buffers
->image_mask
= __DRI_IMAGE_BUFFER_BACK
;
414 buffers
->back
= bo
->image
;
420 dri2_drm_flush_front_buffer(__DRIdrawable
* driDrawable
, void *loaderPrivate
)
423 (void) loaderPrivate
;
427 dri2_drm_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
)
429 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
430 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
432 if (!dri2_dpy
->flush
) {
433 dri2_dpy
->core
->swapBuffers(dri2_surf
->dri_drawable
);
437 if (dri2_surf
->current
)
438 _eglError(EGL_BAD_SURFACE
, "dri2_swap_buffers");
439 for (unsigned i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++)
440 if (dri2_surf
->color_buffers
[i
].age
> 0)
441 dri2_surf
->color_buffers
[i
].age
++;
443 /* Make sure we have a back buffer in case we're swapping without
445 if (get_back_bo(dri2_surf
) < 0)
446 return _eglError(EGL_BAD_ALLOC
, "dri2_swap_buffers");
448 dri2_surf
->current
= dri2_surf
->back
;
449 dri2_surf
->current
->age
= 1;
450 dri2_surf
->back
= NULL
;
452 dri2_flush_drawable_for_swapbuffers(disp
, draw
);
453 dri2_dpy
->flush
->invalidate(dri2_surf
->dri_drawable
);
459 dri2_drm_query_buffer_age(_EGLDriver
*drv
,
460 _EGLDisplay
*disp
, _EGLSurface
*surface
)
462 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surface
);
464 if (get_back_bo(dri2_surf
) < 0) {
465 _eglError(EGL_BAD_ALLOC
, "dri2_query_buffer_age");
469 return dri2_surf
->back
->age
;
473 dri2_drm_create_image_khr_pixmap(_EGLDisplay
*disp
, _EGLContext
*ctx
,
474 EGLClientBuffer buffer
, const EGLint
*attr_list
)
476 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
477 struct gbm_dri_bo
*dri_bo
= gbm_dri_bo((struct gbm_bo
*) buffer
);
478 struct dri2_egl_image
*dri2_img
;
480 dri2_img
= malloc(sizeof *dri2_img
);
482 _eglError(EGL_BAD_ALLOC
, "dri2_create_image_khr_pixmap");
486 _eglInitImage(&dri2_img
->base
, disp
);
488 dri2_img
->dri_image
= dri2_dpy
->image
->dupImage(dri_bo
->image
, dri2_img
);
489 if (dri2_img
->dri_image
== NULL
) {
491 _eglError(EGL_BAD_ALLOC
, "dri2_create_image_khr_pixmap");
495 return &dri2_img
->base
;
499 dri2_drm_create_image_khr(_EGLDriver
*drv
, _EGLDisplay
*disp
,
500 _EGLContext
*ctx
, EGLenum target
,
501 EGLClientBuffer buffer
, const EGLint
*attr_list
)
506 case EGL_NATIVE_PIXMAP_KHR
:
507 return dri2_drm_create_image_khr_pixmap(disp
, ctx
, buffer
, attr_list
);
509 return dri2_create_image_khr(drv
, disp
, ctx
, target
, buffer
, attr_list
);
514 dri2_drm_authenticate(_EGLDisplay
*disp
, uint32_t id
)
516 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
518 return drmAuthMagic(dri2_dpy
->fd
, id
);
522 swrast_put_image2(__DRIdrawable
*driDrawable
,
532 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
534 struct gbm_dri_bo
*bo
;
536 int x_bytes
, width_bytes
;
539 if (op
!= __DRI_SWRAST_IMAGE_OP_DRAW
&&
540 op
!= __DRI_SWRAST_IMAGE_OP_SWAP
)
543 if (get_swrast_front_bo(dri2_surf
) < 0)
546 bo
= gbm_dri_bo(dri2_surf
->current
->bo
);
548 bpp
= gbm_bo_get_bpp(&bo
->base
);
552 x_bytes
= x
* (bpp
>> 3);
553 width_bytes
= width
* (bpp
>> 3);
555 if (gbm_dri_bo_map_dumb(bo
) == NULL
)
558 internal_stride
= bo
->base
.stride
;
560 dst
= bo
->map
+ x_bytes
+ (y
* internal_stride
);
563 for (int i
= 0; i
< height
; i
++) {
564 memcpy(dst
, src
, width_bytes
);
565 dst
+= internal_stride
;
569 gbm_dri_bo_unmap_dumb(bo
);
573 swrast_get_image(__DRIdrawable
*driDrawable
,
581 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
582 int internal_stride
, stride
;
583 struct gbm_dri_bo
*bo
;
585 int x_bytes
, width_bytes
;
588 if (get_swrast_front_bo(dri2_surf
) < 0)
591 bo
= gbm_dri_bo(dri2_surf
->current
->bo
);
593 bpp
= gbm_bo_get_bpp(&bo
->base
);
597 x_bytes
= x
* (bpp
>> 3);
598 width_bytes
= width
* (bpp
>> 3);
600 internal_stride
= bo
->base
.stride
;
601 stride
= width_bytes
;
603 if (gbm_dri_bo_map_dumb(bo
) == NULL
)
607 src
= bo
->map
+ x_bytes
+ (y
* internal_stride
);
609 for (int i
= 0; i
< height
; i
++) {
610 memcpy(dst
, src
, width_bytes
);
612 src
+= internal_stride
;
615 gbm_dri_bo_unmap_dumb(bo
);
619 drm_add_configs_for_visuals(_EGLDriver
*drv
, _EGLDisplay
*disp
)
621 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
622 const struct gbm_dri_visual
*visuals
= dri2_dpy
->gbm_dri
->visual_table
;
623 int num_visuals
= dri2_dpy
->gbm_dri
->num_visuals
;
624 unsigned int format_count
[num_visuals
];
625 unsigned int config_count
= 0;
627 memset(format_count
, 0, num_visuals
* sizeof(unsigned int));
629 for (unsigned i
= 0; dri2_dpy
->driver_configs
[i
]; i
++) {
630 unsigned int red
, green
, blue
, alpha
;
632 dri2_dpy
->core
->getConfigAttrib(dri2_dpy
->driver_configs
[i
],
633 __DRI_ATTRIB_RED_MASK
, &red
);
634 dri2_dpy
->core
->getConfigAttrib(dri2_dpy
->driver_configs
[i
],
635 __DRI_ATTRIB_GREEN_MASK
, &green
);
636 dri2_dpy
->core
->getConfigAttrib(dri2_dpy
->driver_configs
[i
],
637 __DRI_ATTRIB_BLUE_MASK
, &blue
);
638 dri2_dpy
->core
->getConfigAttrib(dri2_dpy
->driver_configs
[i
],
639 __DRI_ATTRIB_ALPHA_MASK
, &alpha
);
641 for (unsigned j
= 0; j
< num_visuals
; j
++) {
642 struct dri2_egl_config
*dri2_conf
;
644 if (visuals
[j
].rgba_masks
.red
!= red
||
645 visuals
[j
].rgba_masks
.green
!= green
||
646 visuals
[j
].rgba_masks
.blue
!= blue
||
647 visuals
[j
].rgba_masks
.alpha
!= alpha
)
650 const EGLint attr_list
[] = {
651 EGL_NATIVE_VISUAL_ID
, visuals
[j
].gbm_format
,
655 dri2_conf
= dri2_add_config(disp
, dri2_dpy
->driver_configs
[i
],
656 config_count
+ 1, EGL_WINDOW_BIT
, attr_list
, NULL
);
658 if (dri2_conf
->base
.ConfigID
== config_count
+ 1)
665 for (unsigned i
= 0; i
< ARRAY_SIZE(format_count
); i
++) {
666 if (!format_count
[i
]) {
667 _eglLog(_EGL_DEBUG
, "No DRI config supports native format 0x%x",
668 visuals
[i
].gbm_format
);
672 return (config_count
!= 0);
675 static const struct dri2_egl_display_vtbl dri2_drm_display_vtbl
= {
676 .authenticate
= dri2_drm_authenticate
,
677 .create_window_surface
= dri2_drm_create_window_surface
,
678 .create_pixmap_surface
= dri2_drm_create_pixmap_surface
,
679 .create_pbuffer_surface
= dri2_fallback_create_pbuffer_surface
,
680 .destroy_surface
= dri2_drm_destroy_surface
,
681 .create_image
= dri2_drm_create_image_khr
,
682 .swap_buffers
= dri2_drm_swap_buffers
,
683 .swap_buffers_with_damage
= dri2_fallback_swap_buffers_with_damage
,
684 .swap_buffers_region
= dri2_fallback_swap_buffers_region
,
685 .set_damage_region
= dri2_fallback_set_damage_region
,
686 .post_sub_buffer
= dri2_fallback_post_sub_buffer
,
687 .copy_buffers
= dri2_fallback_copy_buffers
,
688 .query_buffer_age
= dri2_drm_query_buffer_age
,
689 .create_wayland_buffer_from_image
= dri2_fallback_create_wayland_buffer_from_image
,
690 .get_sync_values
= dri2_fallback_get_sync_values
,
691 .get_dri_drawable
= dri2_surface_get_dri_drawable
,
695 dri2_initialize_drm(_EGLDriver
*drv
, _EGLDisplay
*disp
)
698 struct dri2_egl_display
*dri2_dpy
;
699 struct gbm_device
*gbm
;
702 /* Not supported yet */
703 if (disp
->Options
.ForceSoftware
)
706 loader_set_logger(_eglLog
);
708 dri2_dpy
= calloc(1, sizeof *dri2_dpy
);
710 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
713 disp
->DriverData
= (void *) dri2_dpy
;
715 gbm
= disp
->PlatformDisplay
;
718 int n
= snprintf(buf
, sizeof(buf
), DRM_DEV_NAME
, DRM_DIR_NAME
, 0);
719 if (n
!= -1 && n
< sizeof(buf
))
720 dri2_dpy
->fd
= loader_open_device(buf
);
721 gbm
= gbm_create_device(dri2_dpy
->fd
);
723 err
= "DRI2: failed to create gbm device";
726 dri2_dpy
->own_device
= true;
728 dri2_dpy
->fd
= fcntl(gbm_device_get_fd(gbm
), F_DUPFD_CLOEXEC
, 3);
729 if (dri2_dpy
->fd
< 0) {
730 err
= "DRI2: failed to fcntl() existing gbm device";
735 if (strcmp(gbm_device_get_backend_name(gbm
), "drm") != 0) {
736 err
= "DRI2: gbm device using incorrect/incompatible backend";
740 dev
= _eglAddDevice(dri2_dpy
->fd
, false);
742 err
= "DRI2: failed to find EGLDevice";
748 dri2_dpy
->gbm_dri
= gbm_dri_device(gbm
);
749 dri2_dpy
->driver_name
= strdup(dri2_dpy
->gbm_dri
->driver_name
);
751 dri2_dpy
->dri_screen
= dri2_dpy
->gbm_dri
->screen
;
752 dri2_dpy
->core
= dri2_dpy
->gbm_dri
->core
;
753 dri2_dpy
->dri2
= dri2_dpy
->gbm_dri
->dri2
;
754 dri2_dpy
->swrast
= dri2_dpy
->gbm_dri
->swrast
;
755 dri2_dpy
->driver_configs
= dri2_dpy
->gbm_dri
->driver_configs
;
757 dri2_dpy
->gbm_dri
->lookup_image
= dri2_lookup_egl_image
;
758 dri2_dpy
->gbm_dri
->lookup_user_data
= disp
;
760 dri2_dpy
->gbm_dri
->get_buffers
= dri2_drm_get_buffers
;
761 dri2_dpy
->gbm_dri
->flush_front_buffer
= dri2_drm_flush_front_buffer
;
762 dri2_dpy
->gbm_dri
->get_buffers_with_format
= dri2_drm_get_buffers_with_format
;
763 dri2_dpy
->gbm_dri
->image_get_buffers
= dri2_drm_image_get_buffers
;
764 dri2_dpy
->gbm_dri
->swrast_put_image2
= swrast_put_image2
;
765 dri2_dpy
->gbm_dri
->swrast_get_image
= swrast_get_image
;
767 dri2_dpy
->gbm_dri
->base
.surface_lock_front_buffer
= lock_front_buffer
;
768 dri2_dpy
->gbm_dri
->base
.surface_release_buffer
= release_buffer
;
769 dri2_dpy
->gbm_dri
->base
.surface_has_free_buffers
= has_free_buffers
;
771 if (!dri2_setup_extensions(disp
)) {
772 err
= "DRI2: failed to find required DRI extensions";
776 dri2_setup_screen(disp
);
778 if (!drm_add_configs_for_visuals(drv
, disp
)) {
779 err
= "DRI2: failed to add configs";
783 disp
->Extensions
.KHR_image_pixmap
= EGL_TRUE
;
785 disp
->Extensions
.EXT_buffer_age
= EGL_TRUE
;
787 #ifdef HAVE_WAYLAND_PLATFORM
788 dri2_dpy
->device_name
= loader_get_device_name_for_fd(dri2_dpy
->fd
);
790 dri2_set_WL_bind_wayland_display(drv
, disp
);
792 /* Fill vtbl last to prevent accidentally calling virtual function during
795 dri2_dpy
->vtbl
= &dri2_drm_display_vtbl
;
800 dri2_display_destroy(disp
);
801 return _eglError(EGL_NOT_INITIALIZED
, err
);
805 dri2_teardown_drm(struct dri2_egl_display
*dri2_dpy
)
807 if (dri2_dpy
->own_device
)
808 gbm_device_destroy(&dri2_dpy
->gbm_dri
->base
);