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>
33 #include <sys/types.h>
41 dri2_create_image_khr_pixmap(_EGLDisplay
*disp
, _EGLContext
*ctx
,
42 EGLClientBuffer buffer
, const EGLint
*attr_list
)
44 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
45 struct gbm_dri_bo
*dri_bo
= gbm_dri_bo((struct gbm_bo
*) buffer
);
46 struct dri2_egl_image
*dri2_img
;
48 dri2_img
= malloc(sizeof *dri2_img
);
50 _eglError(EGL_BAD_ALLOC
, "dri2_create_image_khr_pixmap");
54 if (!_eglInitImage(&dri2_img
->base
, disp
)) {
59 dri2_img
->dri_image
= dri2_dpy
->image
->dupImage(dri_bo
->image
, dri2_img
);
60 if (dri2_img
->dri_image
== NULL
) {
62 _eglError(EGL_BAD_ALLOC
, "dri2_create_image_khr_pixmap");
66 return &dri2_img
->base
;
70 dri2_drm_create_image_khr(_EGLDriver
*drv
, _EGLDisplay
*disp
,
71 _EGLContext
*ctx
, EGLenum target
,
72 EGLClientBuffer buffer
, const EGLint
*attr_list
)
77 case EGL_NATIVE_PIXMAP_KHR
:
78 return dri2_create_image_khr_pixmap(disp
, ctx
, buffer
, attr_list
);
80 return dri2_create_image_khr(drv
, disp
, ctx
, target
, buffer
, attr_list
);
85 dri2_drm_authenticate(_EGLDisplay
*disp
, uint32_t id
)
87 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
89 return drmAuthMagic(dri2_dpy
->fd
, id
);
93 dri2_initialize_drm(_EGLDriver
*drv
, _EGLDisplay
*disp
)
95 struct dri2_egl_display
*dri2_dpy
;
96 struct gbm_device
*gbm
;
100 dri2_dpy
= malloc(sizeof *dri2_dpy
);
102 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
104 memset(dri2_dpy
, 0, sizeof *dri2_dpy
);
106 disp
->DriverData
= (void *) dri2_dpy
;
108 gbm
= disp
->PlatformDisplay
;
110 fd
= open("/dev/dri/card0", O_RDWR
);
111 dri2_dpy
->own_gbm_device
= 1;
112 gbm
= gbm_create_device(fd
);
117 if (strcmp(gbm_device_get_backend_name(gbm
), "drm") != 0) {
122 dri2_dpy
->gbm_dri
= gbm_dri_device(gbm
);
123 if (dri2_dpy
->gbm_dri
->base
.type
!= GBM_DRM_DRIVER_TYPE_DRI
) {
129 fd
= dup(gbm_device_get_fd(gbm
));
137 dri2_dpy
->device_name
= dri2_get_device_name_for_fd(dri2_dpy
->fd
);
138 dri2_dpy
->driver_name
= dri2_dpy
->gbm_dri
->base
.driver_name
;
140 dri2_dpy
->dri_screen
= dri2_dpy
->gbm_dri
->screen
;
141 dri2_dpy
->core
= dri2_dpy
->gbm_dri
->core
;
142 dri2_dpy
->dri2
= dri2_dpy
->gbm_dri
->dri2
;
143 dri2_dpy
->image
= dri2_dpy
->gbm_dri
->image
;
144 dri2_dpy
->driver_configs
= dri2_dpy
->gbm_dri
->driver_configs
;
146 dri2_dpy
->gbm_dri
->lookup_image
= dri2_lookup_egl_image
;
147 dri2_dpy
->gbm_dri
->lookup_user_data
= disp
;
149 dri2_setup_screen(disp
);
151 for (i
= 0; dri2_dpy
->driver_configs
[i
]; i
++)
152 dri2_add_config(disp
, dri2_dpy
->driver_configs
[i
],
155 drv
->API
.CreateImageKHR
= dri2_drm_create_image_khr
;
157 #ifdef HAVE_WAYLAND_PLATFORM
158 disp
->Extensions
.WL_bind_wayland_display
= EGL_TRUE
;
160 dri2_dpy
->authenticate
= dri2_drm_authenticate
;
162 /* we're supporting EGL 1.4 */
163 disp
->VersionMajor
= 1;
164 disp
->VersionMinor
= 4;