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
= (struct gbm_dri_surface
*) _surf
;
47 struct dri2_egl_surface
*dri2_surf
= surf
->dri_private
;
48 struct gbm_dri_device
*device
= (struct 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
= (struct 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
= (struct 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
);
158 if (!dri2_drm_config_is_compatible(dri2_dpy
, config
, surface
)) {
159 _eglError(EGL_BAD_MATCH
, "EGL config not compatible with GBM format");
163 surf
= gbm_dri_surface(surface
);
164 dri2_surf
->gbm_surf
= surf
;
165 dri2_surf
->base
.Width
= surf
->base
.width
;
166 dri2_surf
->base
.Height
= surf
->base
.height
;
167 surf
->dri_private
= dri2_surf
;
169 if (dri2_dpy
->dri2
) {
170 dri2_surf
->dri_drawable
=
171 dri2_dpy
->dri2
->createNewDrawable(dri2_dpy
->dri_screen
, config
,
172 dri2_surf
->gbm_surf
);
175 assert(dri2_dpy
->swrast
!= NULL
);
177 dri2_surf
->dri_drawable
=
178 dri2_dpy
->swrast
->createNewDrawable(dri2_dpy
->dri_screen
, config
,
179 dri2_surf
->gbm_surf
);
182 if (dri2_surf
->dri_drawable
== NULL
) {
183 _eglError(EGL_BAD_ALLOC
, "createNewDrawable()");
187 return &dri2_surf
->base
;
196 dri2_drm_create_pixmap_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
197 _EGLConfig
*conf
, void *native_window
,
198 const EGLint
*attrib_list
)
200 /* From the EGL_MESA_platform_gbm spec, version 5:
202 * It is not valid to call eglCreatePlatformPixmapSurfaceEXT with a <dpy>
203 * that belongs to the GBM platform. Any such call fails and generates
206 _eglError(EGL_BAD_PARAMETER
, "cannot create EGL pixmap surfaces on GBM");
211 dri2_drm_destroy_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*surf
)
213 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
214 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
216 dri2_dpy
->core
->destroyDrawable(dri2_surf
->dri_drawable
);
218 for (unsigned i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
219 if (dri2_surf
->color_buffers
[i
].bo
)
220 gbm_bo_destroy(dri2_surf
->color_buffers
[i
].bo
);
223 dri2_egl_surface_free_local_buffers(dri2_surf
);
225 dri2_fini_surface(surf
);
232 get_back_bo(struct dri2_egl_surface
*dri2_surf
)
234 struct dri2_egl_display
*dri2_dpy
=
235 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
236 struct gbm_dri_surface
*surf
= dri2_surf
->gbm_surf
;
239 if (dri2_surf
->back
== NULL
) {
240 for (unsigned i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
241 if (!dri2_surf
->color_buffers
[i
].locked
&&
242 dri2_surf
->color_buffers
[i
].age
>= age
) {
243 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
244 age
= dri2_surf
->color_buffers
[i
].age
;
249 if (dri2_surf
->back
== NULL
)
251 if (dri2_surf
->back
->bo
== NULL
) {
252 if (surf
->base
.modifiers
)
253 dri2_surf
->back
->bo
= gbm_bo_create_with_modifiers(&dri2_dpy
->gbm_dri
->base
,
257 surf
->base
.modifiers
,
260 dri2_surf
->back
->bo
= gbm_bo_create(&dri2_dpy
->gbm_dri
->base
,
267 if (dri2_surf
->back
->bo
== NULL
)
274 get_swrast_front_bo(struct dri2_egl_surface
*dri2_surf
)
276 struct dri2_egl_display
*dri2_dpy
=
277 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
278 struct gbm_dri_surface
*surf
= dri2_surf
->gbm_surf
;
280 if (dri2_surf
->current
== NULL
) {
281 assert(!dri2_surf
->color_buffers
[0].locked
);
282 dri2_surf
->current
= &dri2_surf
->color_buffers
[0];
285 if (dri2_surf
->current
->bo
== NULL
)
286 dri2_surf
->current
->bo
= gbm_bo_create(&dri2_dpy
->gbm_dri
->base
,
287 surf
->base
.width
, surf
->base
.height
,
288 surf
->base
.format
, surf
->base
.flags
);
289 if (dri2_surf
->current
->bo
== NULL
)
296 back_bo_to_dri_buffer(struct dri2_egl_surface
*dri2_surf
, __DRIbuffer
*buffer
)
298 struct dri2_egl_display
*dri2_dpy
=
299 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
300 struct gbm_dri_bo
*bo
;
303 bo
= (struct gbm_dri_bo
*) dri2_surf
->back
->bo
;
305 dri2_dpy
->image
->queryImage(bo
->image
, __DRI_IMAGE_ATTRIB_NAME
, &name
);
306 dri2_dpy
->image
->queryImage(bo
->image
, __DRI_IMAGE_ATTRIB_STRIDE
, &pitch
);
308 buffer
->attachment
= __DRI_BUFFER_BACK_LEFT
;
310 buffer
->pitch
= pitch
;
316 dri2_drm_get_buffers_with_format(__DRIdrawable
*driDrawable
,
317 int *width
, int *height
,
318 unsigned int *attachments
, int count
,
319 int *out_count
, void *loaderPrivate
)
321 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
324 for (i
= 0, j
= 0; i
< 2 * count
; i
+= 2, j
++) {
327 assert(attachments
[i
] < __DRI_BUFFER_COUNT
);
328 assert(j
< ARRAY_SIZE(dri2_surf
->buffers
));
330 switch (attachments
[i
]) {
331 case __DRI_BUFFER_BACK_LEFT
:
332 if (get_back_bo(dri2_surf
) < 0) {
333 _eglError(EGL_BAD_ALLOC
, "failed to allocate color buffer");
336 back_bo_to_dri_buffer(dri2_surf
, &dri2_surf
->buffers
[j
]);
339 local
= dri2_egl_surface_alloc_local_buffer(dri2_surf
, attachments
[i
],
343 _eglError(EGL_BAD_ALLOC
, "failed to allocate local buffer");
346 dri2_surf
->buffers
[j
] = *local
;
355 *width
= dri2_surf
->base
.Width
;
356 *height
= dri2_surf
->base
.Height
;
358 return dri2_surf
->buffers
;
362 dri2_drm_get_buffers(__DRIdrawable
* driDrawable
,
363 int *width
, int *height
,
364 unsigned int *attachments
, int count
,
365 int *out_count
, void *loaderPrivate
)
367 unsigned int *attachments_with_format
;
369 const unsigned int format
= 32;
371 attachments_with_format
= calloc(count
, 2 * sizeof(unsigned int));
372 if (!attachments_with_format
) {
377 for (int i
= 0; i
< count
; ++i
) {
378 attachments_with_format
[2*i
] = attachments
[i
];
379 attachments_with_format
[2*i
+ 1] = format
;
383 dri2_drm_get_buffers_with_format(driDrawable
,
385 attachments_with_format
, count
,
386 out_count
, loaderPrivate
);
388 free(attachments_with_format
);
394 dri2_drm_image_get_buffers(__DRIdrawable
*driDrawable
,
398 uint32_t buffer_mask
,
399 struct __DRIimageList
*buffers
)
401 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
402 struct gbm_dri_bo
*bo
;
404 if (get_back_bo(dri2_surf
) < 0)
407 bo
= (struct gbm_dri_bo
*) dri2_surf
->back
->bo
;
408 buffers
->image_mask
= __DRI_IMAGE_BUFFER_BACK
;
409 buffers
->back
= bo
->image
;
415 dri2_drm_flush_front_buffer(__DRIdrawable
* driDrawable
, void *loaderPrivate
)
418 (void) loaderPrivate
;
422 dri2_drm_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
)
424 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
425 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
427 if (!dri2_dpy
->flush
) {
428 dri2_dpy
->core
->swapBuffers(dri2_surf
->dri_drawable
);
432 if (dri2_surf
->base
.Type
== EGL_WINDOW_BIT
) {
433 if (dri2_surf
->current
)
434 _eglError(EGL_BAD_SURFACE
, "dri2_swap_buffers");
435 for (unsigned i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++)
436 if (dri2_surf
->color_buffers
[i
].age
> 0)
437 dri2_surf
->color_buffers
[i
].age
++;
439 /* Make sure we have a back buffer in case we're swapping without
441 if (get_back_bo(dri2_surf
) < 0)
442 return _eglError(EGL_BAD_ALLOC
, "dri2_swap_buffers");
444 dri2_surf
->current
= dri2_surf
->back
;
445 dri2_surf
->current
->age
= 1;
446 dri2_surf
->back
= NULL
;
449 dri2_flush_drawable_for_swapbuffers(disp
, draw
);
450 dri2_dpy
->flush
->invalidate(dri2_surf
->dri_drawable
);
456 dri2_drm_query_buffer_age(_EGLDriver
*drv
,
457 _EGLDisplay
*disp
, _EGLSurface
*surface
)
459 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surface
);
461 if (get_back_bo(dri2_surf
) < 0) {
462 _eglError(EGL_BAD_ALLOC
, "dri2_query_buffer_age");
466 return dri2_surf
->back
->age
;
470 dri2_drm_create_image_khr_pixmap(_EGLDisplay
*disp
, _EGLContext
*ctx
,
471 EGLClientBuffer buffer
, const EGLint
*attr_list
)
473 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
474 struct gbm_dri_bo
*dri_bo
= gbm_dri_bo((struct gbm_bo
*) buffer
);
475 struct dri2_egl_image
*dri2_img
;
477 dri2_img
= malloc(sizeof *dri2_img
);
479 _eglError(EGL_BAD_ALLOC
, "dri2_create_image_khr_pixmap");
483 _eglInitImage(&dri2_img
->base
, disp
);
485 dri2_img
->dri_image
= dri2_dpy
->image
->dupImage(dri_bo
->image
, dri2_img
);
486 if (dri2_img
->dri_image
== NULL
) {
488 _eglError(EGL_BAD_ALLOC
, "dri2_create_image_khr_pixmap");
492 return &dri2_img
->base
;
496 dri2_drm_create_image_khr(_EGLDriver
*drv
, _EGLDisplay
*disp
,
497 _EGLContext
*ctx
, EGLenum target
,
498 EGLClientBuffer buffer
, const EGLint
*attr_list
)
503 case EGL_NATIVE_PIXMAP_KHR
:
504 return dri2_drm_create_image_khr_pixmap(disp
, ctx
, buffer
, attr_list
);
506 return dri2_create_image_khr(drv
, disp
, ctx
, target
, buffer
, attr_list
);
511 dri2_drm_authenticate(_EGLDisplay
*disp
, uint32_t id
)
513 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
515 return drmAuthMagic(dri2_dpy
->fd
, id
);
519 swrast_put_image2(__DRIdrawable
*driDrawable
,
529 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
531 struct gbm_dri_bo
*bo
;
533 int x_bytes
, width_bytes
;
536 if (op
!= __DRI_SWRAST_IMAGE_OP_DRAW
&&
537 op
!= __DRI_SWRAST_IMAGE_OP_SWAP
)
540 if (get_swrast_front_bo(dri2_surf
) < 0)
543 bo
= gbm_dri_bo(dri2_surf
->current
->bo
);
545 bpp
= gbm_bo_get_bpp(&bo
->base
);
549 x_bytes
= x
* (bpp
>> 3);
550 width_bytes
= width
* (bpp
>> 3);
552 if (gbm_dri_bo_map_dumb(bo
) == NULL
)
555 internal_stride
= bo
->base
.stride
;
557 dst
= bo
->map
+ x_bytes
+ (y
* internal_stride
);
560 for (int i
= 0; i
< height
; i
++) {
561 memcpy(dst
, src
, width_bytes
);
562 dst
+= internal_stride
;
566 gbm_dri_bo_unmap_dumb(bo
);
570 swrast_get_image(__DRIdrawable
*driDrawable
,
578 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
579 int internal_stride
, stride
;
580 struct gbm_dri_bo
*bo
;
582 int x_bytes
, width_bytes
;
585 if (get_swrast_front_bo(dri2_surf
) < 0)
588 bo
= gbm_dri_bo(dri2_surf
->current
->bo
);
590 bpp
= gbm_bo_get_bpp(&bo
->base
);
594 x_bytes
= x
* (bpp
>> 3);
595 width_bytes
= width
* (bpp
>> 3);
597 internal_stride
= bo
->base
.stride
;
598 stride
= width_bytes
;
600 if (gbm_dri_bo_map_dumb(bo
) == NULL
)
604 src
= bo
->map
+ x_bytes
+ (y
* internal_stride
);
606 for (int i
= 0; i
< height
; i
++) {
607 memcpy(dst
, src
, width_bytes
);
609 src
+= internal_stride
;
612 gbm_dri_bo_unmap_dumb(bo
);
616 drm_add_configs_for_visuals(_EGLDriver
*drv
, _EGLDisplay
*disp
)
618 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
619 const struct gbm_dri_visual
*visuals
= dri2_dpy
->gbm_dri
->visual_table
;
620 int num_visuals
= dri2_dpy
->gbm_dri
->num_visuals
;
621 unsigned int format_count
[num_visuals
];
622 unsigned int config_count
= 0;
624 memset(format_count
, 0, num_visuals
* sizeof(unsigned int));
626 for (unsigned i
= 0; dri2_dpy
->driver_configs
[i
]; i
++) {
627 unsigned int red
, green
, blue
, alpha
;
629 dri2_dpy
->core
->getConfigAttrib(dri2_dpy
->driver_configs
[i
],
630 __DRI_ATTRIB_RED_MASK
, &red
);
631 dri2_dpy
->core
->getConfigAttrib(dri2_dpy
->driver_configs
[i
],
632 __DRI_ATTRIB_GREEN_MASK
, &green
);
633 dri2_dpy
->core
->getConfigAttrib(dri2_dpy
->driver_configs
[i
],
634 __DRI_ATTRIB_BLUE_MASK
, &blue
);
635 dri2_dpy
->core
->getConfigAttrib(dri2_dpy
->driver_configs
[i
],
636 __DRI_ATTRIB_ALPHA_MASK
, &alpha
);
638 for (unsigned j
= 0; j
< num_visuals
; j
++) {
639 struct dri2_egl_config
*dri2_conf
;
641 if (visuals
[j
].rgba_masks
.red
!= red
||
642 visuals
[j
].rgba_masks
.green
!= green
||
643 visuals
[j
].rgba_masks
.blue
!= blue
||
644 visuals
[j
].rgba_masks
.alpha
!= alpha
)
647 const EGLint attr_list
[] = {
648 EGL_NATIVE_VISUAL_ID
, visuals
[j
].gbm_format
,
652 dri2_conf
= dri2_add_config(disp
, dri2_dpy
->driver_configs
[i
],
653 config_count
+ 1, EGL_WINDOW_BIT
, attr_list
, NULL
);
655 if (dri2_conf
->base
.ConfigID
== config_count
+ 1)
662 for (unsigned i
= 0; i
< ARRAY_SIZE(format_count
); i
++) {
663 if (!format_count
[i
]) {
664 _eglLog(_EGL_DEBUG
, "No DRI config supports native format 0x%x",
665 visuals
[i
].gbm_format
);
669 return (config_count
!= 0);
672 static const struct dri2_egl_display_vtbl dri2_drm_display_vtbl
= {
673 .authenticate
= dri2_drm_authenticate
,
674 .create_window_surface
= dri2_drm_create_window_surface
,
675 .create_pixmap_surface
= dri2_drm_create_pixmap_surface
,
676 .create_pbuffer_surface
= dri2_fallback_create_pbuffer_surface
,
677 .destroy_surface
= dri2_drm_destroy_surface
,
678 .create_image
= dri2_drm_create_image_khr
,
679 .swap_buffers
= dri2_drm_swap_buffers
,
680 .swap_buffers_with_damage
= dri2_fallback_swap_buffers_with_damage
,
681 .swap_buffers_region
= dri2_fallback_swap_buffers_region
,
682 .set_damage_region
= dri2_fallback_set_damage_region
,
683 .post_sub_buffer
= dri2_fallback_post_sub_buffer
,
684 .copy_buffers
= dri2_fallback_copy_buffers
,
685 .query_buffer_age
= dri2_drm_query_buffer_age
,
686 .create_wayland_buffer_from_image
= dri2_fallback_create_wayland_buffer_from_image
,
687 .get_sync_values
= dri2_fallback_get_sync_values
,
688 .get_dri_drawable
= dri2_surface_get_dri_drawable
,
692 dri2_initialize_drm(_EGLDriver
*drv
, _EGLDisplay
*disp
)
694 struct dri2_egl_display
*dri2_dpy
;
695 struct gbm_device
*gbm
;
698 /* Not supported yet */
699 if (disp
->Options
.ForceSoftware
)
702 loader_set_logger(_eglLog
);
704 dri2_dpy
= calloc(1, sizeof *dri2_dpy
);
706 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
709 disp
->DriverData
= (void *) dri2_dpy
;
711 gbm
= disp
->PlatformDisplay
;
714 int n
= snprintf(buf
, sizeof(buf
), DRM_DEV_NAME
, DRM_DIR_NAME
, 0);
715 if (n
!= -1 && n
< sizeof(buf
))
716 dri2_dpy
->fd
= loader_open_device(buf
);
717 gbm
= gbm_create_device(dri2_dpy
->fd
);
719 err
= "DRI2: failed to create gbm device";
722 dri2_dpy
->own_device
= true;
724 dri2_dpy
->fd
= fcntl(gbm_device_get_fd(gbm
), F_DUPFD_CLOEXEC
, 3);
725 if (dri2_dpy
->fd
< 0) {
726 err
= "DRI2: failed to fcntl() existing gbm device";
731 if (strcmp(gbm_device_get_backend_name(gbm
), "drm") != 0) {
732 err
= "DRI2: gbm device using incorrect/incompatible backend";
736 dri2_dpy
->gbm_dri
= gbm_dri_device(gbm
);
737 dri2_dpy
->driver_name
= strdup(dri2_dpy
->gbm_dri
->driver_name
);
739 dri2_dpy
->dri_screen
= dri2_dpy
->gbm_dri
->screen
;
740 dri2_dpy
->core
= dri2_dpy
->gbm_dri
->core
;
741 dri2_dpy
->dri2
= dri2_dpy
->gbm_dri
->dri2
;
742 dri2_dpy
->swrast
= dri2_dpy
->gbm_dri
->swrast
;
743 dri2_dpy
->driver_configs
= dri2_dpy
->gbm_dri
->driver_configs
;
745 dri2_dpy
->gbm_dri
->lookup_image
= dri2_lookup_egl_image
;
746 dri2_dpy
->gbm_dri
->lookup_user_data
= disp
;
748 dri2_dpy
->gbm_dri
->get_buffers
= dri2_drm_get_buffers
;
749 dri2_dpy
->gbm_dri
->flush_front_buffer
= dri2_drm_flush_front_buffer
;
750 dri2_dpy
->gbm_dri
->get_buffers_with_format
= dri2_drm_get_buffers_with_format
;
751 dri2_dpy
->gbm_dri
->image_get_buffers
= dri2_drm_image_get_buffers
;
752 dri2_dpy
->gbm_dri
->swrast_put_image2
= swrast_put_image2
;
753 dri2_dpy
->gbm_dri
->swrast_get_image
= swrast_get_image
;
755 dri2_dpy
->gbm_dri
->base
.surface_lock_front_buffer
= lock_front_buffer
;
756 dri2_dpy
->gbm_dri
->base
.surface_release_buffer
= release_buffer
;
757 dri2_dpy
->gbm_dri
->base
.surface_has_free_buffers
= has_free_buffers
;
759 if (!dri2_setup_extensions(disp
)) {
760 err
= "DRI2: failed to find required DRI extensions";
764 dri2_setup_screen(disp
);
766 if (!drm_add_configs_for_visuals(drv
, disp
)) {
767 err
= "DRI2: failed to add configs";
771 disp
->Extensions
.KHR_image_pixmap
= EGL_TRUE
;
773 disp
->Extensions
.EXT_buffer_age
= EGL_TRUE
;
775 #ifdef HAVE_WAYLAND_PLATFORM
776 dri2_dpy
->device_name
= loader_get_device_name_for_fd(dri2_dpy
->fd
);
778 dri2_set_WL_bind_wayland_display(drv
, disp
);
780 /* Fill vtbl last to prevent accidentally calling virtual function during
783 dri2_dpy
->vtbl
= &dri2_drm_display_vtbl
;
788 dri2_display_destroy(disp
);
789 return _eglError(EGL_NOT_INITIALIZED
, err
);
793 dri2_teardown_drm(struct dri2_egl_display
*dri2_dpy
)
795 if (dri2_dpy
->own_device
)
796 gbm_device_destroy(&dri2_dpy
->gbm_dri
->base
);