2011-02-03 03:21:13 +00:00
|
|
|
/*
|
|
|
|
* Copyright © 2011 Intel Corporation
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
|
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
|
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Kristian Høgsberg <krh@bitplanet.net>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2011-05-30 09:49:55 +01:00
|
|
|
#include <string.h>
|
2011-02-03 03:21:13 +00:00
|
|
|
#include <xf86drm.h>
|
2011-06-07 21:19:21 +01:00
|
|
|
#include <dlfcn.h>
|
2011-02-03 03:21:13 +00:00
|
|
|
|
|
|
|
#include "egl_dri2.h"
|
|
|
|
|
2011-02-21 15:22:34 +00:00
|
|
|
static int
|
|
|
|
dri2_drm_authenticate(_EGLDisplay *disp, uint32_t id)
|
|
|
|
{
|
|
|
|
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
|
|
|
|
|
|
|
|
return drmAuthMagic(dri2_dpy->fd, id);
|
|
|
|
}
|
|
|
|
|
2011-02-03 03:21:13 +00:00
|
|
|
EGLBoolean
|
|
|
|
dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp)
|
|
|
|
{
|
|
|
|
struct dri2_egl_display *dri2_dpy;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
dri2_dpy = malloc(sizeof *dri2_dpy);
|
|
|
|
if (!dri2_dpy)
|
|
|
|
return _eglError(EGL_BAD_ALLOC, "eglInitialize");
|
2011-02-17 04:05:15 +00:00
|
|
|
|
|
|
|
memset(dri2_dpy, 0, sizeof *dri2_dpy);
|
2011-02-03 03:21:13 +00:00
|
|
|
|
|
|
|
disp->DriverData = (void *) dri2_dpy;
|
2011-05-12 15:12:16 +01:00
|
|
|
dri2_dpy->fd = (int) (intptr_t) disp->PlatformDisplay;
|
2011-02-03 03:21:13 +00:00
|
|
|
|
|
|
|
dri2_dpy->driver_name = dri2_get_driver_for_fd(dri2_dpy->fd);
|
|
|
|
if (dri2_dpy->driver_name == NULL)
|
|
|
|
return _eglError(EGL_BAD_ALLOC, "DRI2: failed to get driver name");
|
|
|
|
|
2011-05-30 09:49:55 +01:00
|
|
|
dri2_dpy->device_name = dri2_get_device_name_for_fd(dri2_dpy->fd);
|
2011-02-21 15:22:34 +00:00
|
|
|
if (dri2_dpy->device_name == NULL) {
|
|
|
|
_eglError(EGL_BAD_ALLOC, "DRI2: failed to get device name");
|
2011-02-03 03:21:13 +00:00
|
|
|
goto cleanup_driver_name;
|
2011-02-21 15:22:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!dri2_load_driver(disp))
|
|
|
|
goto cleanup_device_name;
|
2011-02-03 03:21:13 +00:00
|
|
|
|
|
|
|
dri2_dpy->extensions[0] = &image_lookup_extension.base;
|
|
|
|
dri2_dpy->extensions[1] = &use_invalidate.base;
|
|
|
|
dri2_dpy->extensions[2] = NULL;
|
|
|
|
|
|
|
|
if (!dri2_create_screen(disp))
|
|
|
|
goto cleanup_driver;
|
|
|
|
|
|
|
|
for (i = 0; dri2_dpy->driver_configs[i]; i++)
|
2011-02-09 14:30:20 +00:00
|
|
|
dri2_add_config(disp, dri2_dpy->driver_configs[i], i + 1, 0, 0, NULL);
|
2011-02-03 03:21:13 +00:00
|
|
|
|
2011-02-21 15:22:34 +00:00
|
|
|
#ifdef HAVE_WAYLAND_PLATFORM
|
|
|
|
disp->Extensions.WL_bind_wayland_display = EGL_TRUE;
|
|
|
|
#endif
|
|
|
|
dri2_dpy->authenticate = dri2_drm_authenticate;
|
|
|
|
|
2011-02-03 03:21:13 +00:00
|
|
|
/* we're supporting EGL 1.4 */
|
|
|
|
disp->VersionMajor = 1;
|
|
|
|
disp->VersionMinor = 4;
|
|
|
|
|
|
|
|
return EGL_TRUE;
|
|
|
|
|
|
|
|
cleanup_driver:
|
|
|
|
dlclose(dri2_dpy->driver);
|
2011-02-21 15:22:34 +00:00
|
|
|
cleanup_device_name:
|
|
|
|
free(dri2_dpy->device_name);
|
2011-02-03 03:21:13 +00:00
|
|
|
cleanup_driver_name:
|
|
|
|
free(dri2_dpy->driver_name);
|
|
|
|
|
|
|
|
return EGL_FALSE;
|
|
|
|
}
|