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>
39 #include "util/os_file.h"
44 static struct gbm_bo
*
45 lock_front_buffer(struct gbm_surface
*_surf
)
47 struct gbm_dri_surface
*surf
= gbm_dri_surface(_surf
);
48 struct dri2_egl_surface
*dri2_surf
= surf
->dri_private
;
49 struct gbm_dri_device
*device
= gbm_dri_device(_surf
->gbm
);
52 if (dri2_surf
->current
== NULL
) {
53 _eglError(EGL_BAD_SURFACE
, "no front buffer");
57 bo
= dri2_surf
->current
->bo
;
60 dri2_surf
->current
->locked
= true;
61 dri2_surf
->current
= NULL
;
68 release_buffer(struct gbm_surface
*_surf
, struct gbm_bo
*bo
)
70 struct gbm_dri_surface
*surf
= gbm_dri_surface(_surf
);
71 struct dri2_egl_surface
*dri2_surf
= surf
->dri_private
;
73 for (unsigned i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
74 if (dri2_surf
->color_buffers
[i
].bo
== bo
) {
75 dri2_surf
->color_buffers
[i
].locked
= false;
82 has_free_buffers(struct gbm_surface
*_surf
)
84 struct gbm_dri_surface
*surf
= gbm_dri_surface(_surf
);
85 struct dri2_egl_surface
*dri2_surf
= surf
->dri_private
;
87 for (unsigned i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++)
88 if (!dri2_surf
->color_buffers
[i
].locked
)
95 dri2_drm_config_is_compatible(struct dri2_egl_display
*dri2_dpy
,
96 const __DRIconfig
*config
,
97 struct gbm_surface
*surface
)
99 const struct gbm_dri_visual
*visual
= NULL
;
101 unsigned int sizes
[4];
105 /* Check that the EGLConfig being used to render to the surface is
106 * compatible with the surface format. Since mixing ARGB and XRGB of
107 * otherwise-compatible formats is relatively common, explicitly allow
110 dri2_get_shifts_and_sizes(dri2_dpy
->core
, config
, shifts
, sizes
);
112 dri2_get_render_type_float(dri2_dpy
->core
, config
, &is_float
);
114 for (i
= 0; i
< dri2_dpy
->gbm_dri
->num_visuals
; i
++) {
115 visual
= &dri2_dpy
->gbm_dri
->visual_table
[i
];
116 if (visual
->gbm_format
== surface
->format
)
120 if (i
== dri2_dpy
->gbm_dri
->num_visuals
)
123 if (shifts
[0] != visual
->rgba_shifts
.red
||
124 shifts
[1] != visual
->rgba_shifts
.green
||
125 shifts
[2] != visual
->rgba_shifts
.blue
||
126 (shifts
[3] > -1 && visual
->rgba_shifts
.alpha
> -1 &&
127 shifts
[3] != visual
->rgba_shifts
.alpha
) ||
128 sizes
[0] != visual
->rgba_sizes
.red
||
129 sizes
[1] != visual
->rgba_sizes
.green
||
130 sizes
[2] != visual
->rgba_sizes
.blue
||
131 (sizes
[3] > 0 && visual
->rgba_sizes
.alpha
> 0 &&
132 sizes
[3] != visual
->rgba_sizes
.alpha
) ||
133 is_float
!= visual
->is_float
) {
141 dri2_drm_create_window_surface(_EGLDisplay
*disp
, _EGLConfig
*conf
,
142 void *native_surface
, const EGLint
*attrib_list
)
144 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
145 struct dri2_egl_config
*dri2_conf
= dri2_egl_config(conf
);
146 struct dri2_egl_surface
*dri2_surf
;
147 struct gbm_surface
*surface
= native_surface
;
148 struct gbm_dri_surface
*surf
;
149 const __DRIconfig
*config
;
151 dri2_surf
= calloc(1, sizeof *dri2_surf
);
153 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
157 if (!dri2_init_surface(&dri2_surf
->base
, disp
, EGL_WINDOW_BIT
, conf
,
158 attrib_list
, false, native_surface
))
161 config
= dri2_get_dri_config(dri2_conf
, EGL_WINDOW_BIT
,
162 dri2_surf
->base
.GLColorspace
);
165 _eglError(EGL_BAD_MATCH
, "Unsupported surfacetype/colorspace configuration");
169 if (!dri2_drm_config_is_compatible(dri2_dpy
, config
, surface
)) {
170 _eglError(EGL_BAD_MATCH
, "EGL config not compatible with GBM format");
174 surf
= gbm_dri_surface(surface
);
175 dri2_surf
->gbm_surf
= surf
;
176 dri2_surf
->base
.Width
= surf
->base
.width
;
177 dri2_surf
->base
.Height
= surf
->base
.height
;
178 surf
->dri_private
= dri2_surf
;
180 if (!dri2_create_drawable(dri2_dpy
, config
, dri2_surf
, dri2_surf
->gbm_surf
))
183 return &dri2_surf
->base
;
192 dri2_drm_create_pixmap_surface(_EGLDisplay
*disp
, _EGLConfig
*conf
,
193 void *native_window
, const EGLint
*attrib_list
)
195 /* From the EGL_MESA_platform_gbm spec, version 5:
197 * It is not valid to call eglCreatePlatformPixmapSurfaceEXT with a <dpy>
198 * that belongs to the GBM platform. Any such call fails and generates
201 _eglError(EGL_BAD_PARAMETER
, "cannot create EGL pixmap surfaces on GBM");
206 dri2_drm_destroy_surface(_EGLDisplay
*disp
, _EGLSurface
*surf
)
208 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
209 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
211 dri2_dpy
->core
->destroyDrawable(dri2_surf
->dri_drawable
);
213 for (unsigned i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
214 if (dri2_surf
->color_buffers
[i
].bo
)
215 gbm_bo_destroy(dri2_surf
->color_buffers
[i
].bo
);
218 dri2_egl_surface_free_local_buffers(dri2_surf
);
220 dri2_fini_surface(surf
);
227 get_back_bo(struct dri2_egl_surface
*dri2_surf
)
229 struct dri2_egl_display
*dri2_dpy
=
230 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
231 struct gbm_dri_surface
*surf
= dri2_surf
->gbm_surf
;
234 if (dri2_surf
->back
== NULL
) {
235 for (unsigned i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++) {
236 if (!dri2_surf
->color_buffers
[i
].locked
&&
237 dri2_surf
->color_buffers
[i
].age
>= age
) {
238 dri2_surf
->back
= &dri2_surf
->color_buffers
[i
];
239 age
= dri2_surf
->color_buffers
[i
].age
;
244 if (dri2_surf
->back
== NULL
)
246 if (dri2_surf
->back
->bo
== NULL
) {
247 if (surf
->base
.modifiers
)
248 dri2_surf
->back
->bo
= gbm_bo_create_with_modifiers(&dri2_dpy
->gbm_dri
->base
,
252 surf
->base
.modifiers
,
255 dri2_surf
->back
->bo
= gbm_bo_create(&dri2_dpy
->gbm_dri
->base
,
262 if (dri2_surf
->back
->bo
== NULL
)
269 get_swrast_front_bo(struct dri2_egl_surface
*dri2_surf
)
271 struct dri2_egl_display
*dri2_dpy
=
272 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
273 struct gbm_dri_surface
*surf
= dri2_surf
->gbm_surf
;
275 if (dri2_surf
->current
== NULL
) {
276 assert(!dri2_surf
->color_buffers
[0].locked
);
277 dri2_surf
->current
= &dri2_surf
->color_buffers
[0];
280 if (dri2_surf
->current
->bo
== NULL
)
281 dri2_surf
->current
->bo
= gbm_bo_create(&dri2_dpy
->gbm_dri
->base
,
282 surf
->base
.width
, surf
->base
.height
,
283 surf
->base
.format
, surf
->base
.flags
);
284 if (dri2_surf
->current
->bo
== NULL
)
291 back_bo_to_dri_buffer(struct dri2_egl_surface
*dri2_surf
, __DRIbuffer
*buffer
)
293 struct dri2_egl_display
*dri2_dpy
=
294 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
295 struct gbm_dri_bo
*bo
;
298 bo
= gbm_dri_bo(dri2_surf
->back
->bo
);
300 dri2_dpy
->image
->queryImage(bo
->image
, __DRI_IMAGE_ATTRIB_NAME
, &name
);
301 dri2_dpy
->image
->queryImage(bo
->image
, __DRI_IMAGE_ATTRIB_STRIDE
, &pitch
);
303 buffer
->attachment
= __DRI_BUFFER_BACK_LEFT
;
305 buffer
->pitch
= pitch
;
311 dri2_drm_get_buffers_with_format(__DRIdrawable
*driDrawable
,
312 int *width
, int *height
,
313 unsigned int *attachments
, int count
,
314 int *out_count
, void *loaderPrivate
)
316 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
319 for (i
= 0, j
= 0; i
< 2 * count
; i
+= 2, j
++) {
322 assert(attachments
[i
] < __DRI_BUFFER_COUNT
);
323 assert(j
< ARRAY_SIZE(dri2_surf
->buffers
));
325 switch (attachments
[i
]) {
326 case __DRI_BUFFER_BACK_LEFT
:
327 if (get_back_bo(dri2_surf
) < 0) {
328 _eglError(EGL_BAD_ALLOC
, "failed to allocate color buffer");
331 back_bo_to_dri_buffer(dri2_surf
, &dri2_surf
->buffers
[j
]);
334 local
= dri2_egl_surface_alloc_local_buffer(dri2_surf
, attachments
[i
],
338 _eglError(EGL_BAD_ALLOC
, "failed to allocate local buffer");
341 dri2_surf
->buffers
[j
] = *local
;
350 *width
= dri2_surf
->base
.Width
;
351 *height
= dri2_surf
->base
.Height
;
353 return dri2_surf
->buffers
;
357 dri2_drm_get_buffers(__DRIdrawable
* driDrawable
,
358 int *width
, int *height
,
359 unsigned int *attachments
, int count
,
360 int *out_count
, void *loaderPrivate
)
362 unsigned int *attachments_with_format
;
364 const unsigned int format
= 32;
366 attachments_with_format
= calloc(count
, 2 * sizeof(unsigned int));
367 if (!attachments_with_format
) {
372 for (int i
= 0; i
< count
; ++i
) {
373 attachments_with_format
[2*i
] = attachments
[i
];
374 attachments_with_format
[2*i
+ 1] = format
;
378 dri2_drm_get_buffers_with_format(driDrawable
,
380 attachments_with_format
, count
,
381 out_count
, loaderPrivate
);
383 free(attachments_with_format
);
389 dri2_drm_image_get_buffers(__DRIdrawable
*driDrawable
,
393 uint32_t buffer_mask
,
394 struct __DRIimageList
*buffers
)
396 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
397 struct gbm_dri_bo
*bo
;
399 if (get_back_bo(dri2_surf
) < 0)
402 bo
= gbm_dri_bo(dri2_surf
->back
->bo
);
403 buffers
->image_mask
= __DRI_IMAGE_BUFFER_BACK
;
404 buffers
->back
= bo
->image
;
410 dri2_drm_flush_front_buffer(__DRIdrawable
* driDrawable
, void *loaderPrivate
)
413 (void) loaderPrivate
;
417 dri2_drm_swap_buffers(_EGLDisplay
*disp
, _EGLSurface
*draw
)
419 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
420 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
422 if (!dri2_dpy
->flush
) {
423 dri2_dpy
->core
->swapBuffers(dri2_surf
->dri_drawable
);
427 if (dri2_surf
->current
)
428 _eglError(EGL_BAD_SURFACE
, "dri2_swap_buffers");
429 for (unsigned i
= 0; i
< ARRAY_SIZE(dri2_surf
->color_buffers
); i
++)
430 if (dri2_surf
->color_buffers
[i
].age
> 0)
431 dri2_surf
->color_buffers
[i
].age
++;
433 /* Make sure we have a back buffer in case we're swapping without
435 if (get_back_bo(dri2_surf
) < 0)
436 return _eglError(EGL_BAD_ALLOC
, "dri2_swap_buffers");
438 dri2_surf
->current
= dri2_surf
->back
;
439 dri2_surf
->current
->age
= 1;
440 dri2_surf
->back
= NULL
;
442 dri2_flush_drawable_for_swapbuffers(disp
, draw
);
443 dri2_dpy
->flush
->invalidate(dri2_surf
->dri_drawable
);
449 dri2_drm_query_buffer_age(const _EGLDriver
*drv
,
450 _EGLDisplay
*disp
, _EGLSurface
*surface
)
452 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surface
);
454 if (get_back_bo(dri2_surf
) < 0) {
455 _eglError(EGL_BAD_ALLOC
, "dri2_query_buffer_age");
459 return dri2_surf
->back
->age
;
463 dri2_drm_create_image_khr_pixmap(_EGLDisplay
*disp
, _EGLContext
*ctx
,
464 EGLClientBuffer buffer
, const EGLint
*attr_list
)
466 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
467 struct gbm_dri_bo
*dri_bo
= gbm_dri_bo((struct gbm_bo
*) buffer
);
468 struct dri2_egl_image
*dri2_img
;
470 dri2_img
= malloc(sizeof *dri2_img
);
472 _eglError(EGL_BAD_ALLOC
, "dri2_create_image_khr_pixmap");
476 _eglInitImage(&dri2_img
->base
, disp
);
478 dri2_img
->dri_image
= dri2_dpy
->image
->dupImage(dri_bo
->image
, dri2_img
);
479 if (dri2_img
->dri_image
== NULL
) {
481 _eglError(EGL_BAD_ALLOC
, "dri2_create_image_khr_pixmap");
485 return &dri2_img
->base
;
489 dri2_drm_create_image_khr(_EGLDisplay
*disp
, _EGLContext
*ctx
, EGLenum target
,
490 EGLClientBuffer buffer
, const EGLint
*attr_list
)
493 case EGL_NATIVE_PIXMAP_KHR
:
494 return dri2_drm_create_image_khr_pixmap(disp
, ctx
, buffer
, attr_list
);
496 return dri2_create_image_khr(disp
, ctx
, target
, buffer
, attr_list
);
501 dri2_drm_authenticate(_EGLDisplay
*disp
, uint32_t id
)
503 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
505 return drmAuthMagic(dri2_dpy
->fd
, id
);
509 swrast_put_image2(__DRIdrawable
*driDrawable
,
519 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
521 struct gbm_dri_bo
*bo
;
523 int x_bytes
, width_bytes
;
526 if (op
!= __DRI_SWRAST_IMAGE_OP_DRAW
&&
527 op
!= __DRI_SWRAST_IMAGE_OP_SWAP
)
530 if (get_swrast_front_bo(dri2_surf
) < 0)
533 bo
= gbm_dri_bo(dri2_surf
->current
->bo
);
535 bpp
= gbm_bo_get_bpp(&bo
->base
);
539 x_bytes
= x
* (bpp
>> 3);
540 width_bytes
= width
* (bpp
>> 3);
542 if (gbm_dri_bo_map_dumb(bo
) == NULL
)
545 internal_stride
= bo
->base
.stride
;
547 dst
= bo
->map
+ x_bytes
+ (y
* internal_stride
);
550 for (int i
= 0; i
< height
; i
++) {
551 memcpy(dst
, src
, width_bytes
);
552 dst
+= internal_stride
;
556 gbm_dri_bo_unmap_dumb(bo
);
560 swrast_get_image(__DRIdrawable
*driDrawable
,
568 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
569 int internal_stride
, stride
;
570 struct gbm_dri_bo
*bo
;
572 int x_bytes
, width_bytes
;
575 if (get_swrast_front_bo(dri2_surf
) < 0)
578 bo
= gbm_dri_bo(dri2_surf
->current
->bo
);
580 bpp
= gbm_bo_get_bpp(&bo
->base
);
584 x_bytes
= x
* (bpp
>> 3);
585 width_bytes
= width
* (bpp
>> 3);
587 internal_stride
= bo
->base
.stride
;
588 stride
= width_bytes
;
590 if (gbm_dri_bo_map_dumb(bo
) == NULL
)
594 src
= bo
->map
+ x_bytes
+ (y
* internal_stride
);
596 for (int i
= 0; i
< height
; i
++) {
597 memcpy(dst
, src
, width_bytes
);
599 src
+= internal_stride
;
602 gbm_dri_bo_unmap_dumb(bo
);
606 drm_add_configs_for_visuals(_EGLDisplay
*disp
)
608 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
609 const struct gbm_dri_visual
*visuals
= dri2_dpy
->gbm_dri
->visual_table
;
610 int num_visuals
= dri2_dpy
->gbm_dri
->num_visuals
;
611 unsigned int format_count
[num_visuals
];
612 unsigned int config_count
= 0;
614 memset(format_count
, 0, num_visuals
* sizeof(unsigned int));
616 for (unsigned i
= 0; dri2_dpy
->driver_configs
[i
]; i
++) {
617 const __DRIconfig
*config
= dri2_dpy
->driver_configs
[i
];
619 unsigned int sizes
[4];
622 dri2_get_shifts_and_sizes(dri2_dpy
->core
, config
, shifts
, sizes
);
624 dri2_get_render_type_float(dri2_dpy
->core
, config
, &is_float
);
626 for (unsigned j
= 0; j
< num_visuals
; j
++) {
627 struct dri2_egl_config
*dri2_conf
;
629 if (visuals
[j
].rgba_shifts
.red
!= shifts
[0] ||
630 visuals
[j
].rgba_shifts
.green
!= shifts
[1] ||
631 visuals
[j
].rgba_shifts
.blue
!= shifts
[2] ||
632 visuals
[j
].rgba_shifts
.alpha
!= shifts
[3] ||
633 visuals
[j
].rgba_sizes
.red
!= sizes
[0] ||
634 visuals
[j
].rgba_sizes
.green
!= sizes
[1] ||
635 visuals
[j
].rgba_sizes
.blue
!= sizes
[2] ||
636 visuals
[j
].rgba_sizes
.alpha
!= sizes
[3] ||
637 visuals
[j
].is_float
!= is_float
)
640 const EGLint attr_list
[] = {
641 EGL_NATIVE_VISUAL_ID
, visuals
[j
].gbm_format
,
645 dri2_conf
= dri2_add_config(disp
, dri2_dpy
->driver_configs
[i
],
646 config_count
+ 1, EGL_WINDOW_BIT
, attr_list
, NULL
, NULL
);
648 if (dri2_conf
->base
.ConfigID
== config_count
+ 1)
655 for (unsigned i
= 0; i
< ARRAY_SIZE(format_count
); i
++) {
656 if (!format_count
[i
]) {
657 struct gbm_format_name_desc desc
;
658 _eglLog(_EGL_DEBUG
, "No DRI config supports native format %s",
659 gbm_format_get_name(visuals
[i
].gbm_format
, &desc
));
663 return (config_count
!= 0);
666 static const struct dri2_egl_display_vtbl dri2_drm_display_vtbl
= {
667 .authenticate
= dri2_drm_authenticate
,
668 .create_window_surface
= dri2_drm_create_window_surface
,
669 .create_pixmap_surface
= dri2_drm_create_pixmap_surface
,
670 .destroy_surface
= dri2_drm_destroy_surface
,
671 .create_image
= dri2_drm_create_image_khr
,
672 .swap_buffers
= dri2_drm_swap_buffers
,
673 .query_buffer_age
= dri2_drm_query_buffer_age
,
674 .get_dri_drawable
= dri2_surface_get_dri_drawable
,
678 dri2_initialize_drm(_EGLDisplay
*disp
)
681 struct dri2_egl_display
*dri2_dpy
;
682 struct gbm_device
*gbm
;
685 dri2_dpy
= calloc(1, sizeof *dri2_dpy
);
687 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
690 disp
->DriverData
= (void *) dri2_dpy
;
692 gbm
= disp
->PlatformDisplay
;
695 int n
= snprintf(buf
, sizeof(buf
), DRM_DEV_NAME
, DRM_DIR_NAME
, 0);
696 if (n
!= -1 && n
< sizeof(buf
))
697 dri2_dpy
->fd
= loader_open_device(buf
);
698 gbm
= gbm_create_device(dri2_dpy
->fd
);
700 err
= "DRI2: failed to create gbm device";
703 dri2_dpy
->own_device
= true;
705 dri2_dpy
->fd
= os_dupfd_cloexec(gbm_device_get_fd(gbm
));
706 if (dri2_dpy
->fd
< 0) {
707 err
= "DRI2: failed to fcntl() existing gbm device";
711 dri2_dpy
->gbm_dri
= gbm_dri_device(gbm
);
713 if (strcmp(gbm_device_get_backend_name(gbm
), "drm") != 0) {
714 err
= "DRI2: gbm device using incorrect/incompatible backend";
718 dev
= _eglAddDevice(dri2_dpy
->fd
, disp
->Options
.ForceSoftware
);
720 err
= "DRI2: failed to find EGLDevice";
726 dri2_dpy
->driver_name
= strdup(dri2_dpy
->gbm_dri
->driver_name
);
727 dri2_dpy
->is_render_node
= drmGetNodeTypeFromFd(dri2_dpy
->fd
) == DRM_NODE_RENDER
;
729 /* render nodes cannot use Gem names, and thus do not support
730 * the __DRI_DRI2_LOADER extension */
731 if (!dri2_dpy
->is_render_node
) {
732 if (!dri2_load_driver(disp
)) {
733 err
= "DRI2: failed to load driver";
737 if (!dri2_load_driver_dri3(disp
)) {
738 err
= "DRI3: failed to load driver";
743 dri2_dpy
->dri_screen
= dri2_dpy
->gbm_dri
->screen
;
744 dri2_dpy
->core
= dri2_dpy
->gbm_dri
->core
;
745 dri2_dpy
->dri2
= dri2_dpy
->gbm_dri
->dri2
;
746 dri2_dpy
->swrast
= dri2_dpy
->gbm_dri
->swrast
;
747 dri2_dpy
->driver_configs
= dri2_dpy
->gbm_dri
->driver_configs
;
749 dri2_dpy
->gbm_dri
->lookup_image
= dri2_lookup_egl_image
;
750 dri2_dpy
->gbm_dri
->lookup_user_data
= disp
;
752 dri2_dpy
->gbm_dri
->get_buffers
= dri2_drm_get_buffers
;
753 dri2_dpy
->gbm_dri
->flush_front_buffer
= dri2_drm_flush_front_buffer
;
754 dri2_dpy
->gbm_dri
->get_buffers_with_format
= dri2_drm_get_buffers_with_format
;
755 dri2_dpy
->gbm_dri
->image_get_buffers
= dri2_drm_image_get_buffers
;
756 dri2_dpy
->gbm_dri
->swrast_put_image2
= swrast_put_image2
;
757 dri2_dpy
->gbm_dri
->swrast_get_image
= swrast_get_image
;
759 dri2_dpy
->gbm_dri
->base
.surface_lock_front_buffer
= lock_front_buffer
;
760 dri2_dpy
->gbm_dri
->base
.surface_release_buffer
= release_buffer
;
761 dri2_dpy
->gbm_dri
->base
.surface_has_free_buffers
= has_free_buffers
;
763 if (!dri2_setup_extensions(disp
)) {
764 err
= "DRI2: failed to find required DRI extensions";
768 dri2_setup_screen(disp
);
770 if (!drm_add_configs_for_visuals(disp
)) {
771 err
= "DRI2: failed to add configs";
775 disp
->Extensions
.KHR_image_pixmap
= EGL_TRUE
;
777 disp
->Extensions
.EXT_buffer_age
= EGL_TRUE
;
779 #ifdef HAVE_WAYLAND_PLATFORM
780 dri2_dpy
->device_name
= loader_get_device_name_for_fd(dri2_dpy
->fd
);
782 dri2_set_WL_bind_wayland_display(disp
);
784 /* Fill vtbl last to prevent accidentally calling virtual function during
787 dri2_dpy
->vtbl
= &dri2_drm_display_vtbl
;
792 dri2_display_destroy(disp
);
793 return _eglError(EGL_NOT_INITIALIZED
, err
);
797 dri2_teardown_drm(struct dri2_egl_display
*dri2_dpy
)
799 if (dri2_dpy
->own_device
)
800 gbm_device_destroy(&dri2_dpy
->gbm_dri
->base
);