}
static void
-drm_create_texture(_EGLDriver *drv,
+drm_create_texture(_EGLDisplay *dpy,
struct drm_screen *scrn,
unsigned w, unsigned h)
{
- struct drm_device *dev = (struct drm_device *)drv;
+ struct drm_device *dev = lookup_drm_device(dpy);
struct pipe_screen *screen = dev->screen;
struct pipe_surface *surface;
struct pipe_texture *texture;
*/
void
-drm_takedown_shown_screen(_EGLDriver *drv, struct drm_screen *screen)
+drm_takedown_shown_screen(_EGLDisplay *dpy, struct drm_screen *screen)
{
- struct drm_device *dev = (struct drm_device *)drv;
+ struct drm_device *dev = lookup_drm_device(dpy);
screen->surf = NULL;
_EGLScreen *screen,
_EGLSurface *surface, _EGLMode *mode)
{
- struct drm_device *dev = (struct drm_device *)drv;
+ struct drm_device *dev = lookup_drm_device(dpy);
struct drm_surface *surf = lookup_drm_surface(surface);
struct drm_screen *scrn = lookup_drm_screen(screen);
int ret;
unsigned int i, k;
if (scrn->shown)
- drm_takedown_shown_screen(drv, scrn);
+ drm_takedown_shown_screen(dpy, scrn);
- drm_create_texture(drv, scrn, mode->Width, mode->Height);
+ drm_create_texture(dpy, scrn, mode->Width, mode->Height);
if (!scrn->buffer)
return EGL_FALSE;
struct drm_surface *surf = lookup_drm_surface(surface);
if (!_eglIsSurfaceBound(&surf->base)) {
if (surf->screen)
- drm_takedown_shown_screen(drv, surf->screen);
+ drm_takedown_shown_screen(dpy, surf->screen);
st_unreference_framebuffer(surf->stfb);
free(surf);
}
EGLBoolean
drm_swap_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *draw)
{
- struct drm_device *dev = (struct drm_device *)drv;
+ struct drm_device *dev = lookup_drm_device(dpy);
struct drm_surface *surf = lookup_drm_surface(draw);
struct pipe_surface *back_surf;
static void
drm_unload(_EGLDriver *drv)
{
- struct drm_device *dev = (struct drm_device *)drv;
- dev->api->destroy(dev->api);
- free(dev);
+ free(drv);
}
/**
_EGLDriver *
_eglMain(const char *args)
{
- struct drm_device *drm;
+ _EGLDriver *drv;
- drm = (struct drm_device *) calloc(1, sizeof(struct drm_device));
- if (!drm) {
+ drv = (_EGLDriver *) calloc(1, sizeof(_EGLDriver));
+ if (!drv) {
return NULL;
}
- drm->api = drm_api_create();
-
/* First fill in the dispatch table with defaults */
- _eglInitDriverFallbacks(&drm->base);
+ _eglInitDriverFallbacks(drv);
/* then plug in our Drm-specific functions */
- drm->base.API.Initialize = drm_initialize;
- drm->base.API.Terminate = drm_terminate;
- drm->base.API.CreateContext = drm_create_context;
- drm->base.API.MakeCurrent = drm_make_current;
- drm->base.API.CreateWindowSurface = drm_create_window_surface;
- drm->base.API.CreatePixmapSurface = drm_create_pixmap_surface;
- drm->base.API.CreatePbufferSurface = drm_create_pbuffer_surface;
- drm->base.API.DestroySurface = drm_destroy_surface;
- drm->base.API.DestroyContext = drm_destroy_context;
- drm->base.API.CreateScreenSurfaceMESA = drm_create_screen_surface_mesa;
- drm->base.API.ShowScreenSurfaceMESA = drm_show_screen_surface_mesa;
- drm->base.API.SwapBuffers = drm_swap_buffers;
-
- drm->base.Name = "DRM/Gallium/Win";
- drm->base.Unload = drm_unload;
-
- return &drm->base;
+ drv->API.Initialize = drm_initialize;
+ drv->API.Terminate = drm_terminate;
+ drv->API.CreateContext = drm_create_context;
+ drv->API.MakeCurrent = drm_make_current;
+ drv->API.CreateWindowSurface = drm_create_window_surface;
+ drv->API.CreatePixmapSurface = drm_create_pixmap_surface;
+ drv->API.CreatePbufferSurface = drm_create_pbuffer_surface;
+ drv->API.DestroySurface = drm_destroy_surface;
+ drv->API.DestroyContext = drm_destroy_context;
+ drv->API.CreateScreenSurfaceMESA = drm_create_screen_surface_mesa;
+ drv->API.ShowScreenSurfaceMESA = drm_show_screen_surface_mesa;
+ drv->API.SwapBuffers = drm_swap_buffers;
+
+ drv->Name = "DRM/Gallium/Win";
+ drv->Unload = drm_unload;
+
+ return drv;
}
static void
EGLBoolean
drm_initialize(_EGLDriver *drv, _EGLDisplay *disp, EGLint *major, EGLint *minor)
{
- struct drm_device *dev = (struct drm_device *)drv;
+ struct drm_device *dev;
struct drm_screen *screen = NULL;
drmModeConnectorPtr connector = NULL;
drmModeResPtr res = NULL;
EGLint i;
int fd;
+ dev = (struct drm_device *) calloc(1, sizeof(struct drm_device));
+ if (!dev)
+ return EGL_FALSE;
+ dev->api = drm_api_create();
+
/* try the first node */
fd = drm_open_minor(0);
if (fd < 0)
}
dev->count_screens = num_screens;
+ disp->DriverData = dev;
+
/* for now we only have one config */
_EGLConfig *config = calloc(1, sizeof(*config));
memset(config, 1, sizeof(*config));
err_screen:
drmClose(fd);
err_fd:
+ free(dev);
return EGL_FALSE;
}
EGLBoolean
drm_terminate(_EGLDriver *drv, _EGLDisplay *dpy)
{
- struct drm_device *dev = (struct drm_device *)drv;
+ struct drm_device *dev = lookup_drm_device(dpy);
struct drm_screen *screen;
int i = 0;
_eglReleaseDisplayResources(drv, dpy);
+ _eglCleanupDisplay(dpy);
drmFreeVersion(dev->version);
screen = dev->screens[i];
if (screen->shown)
- drm_takedown_shown_screen(drv, screen);
+ drm_takedown_shown_screen(dpy, screen);
drmModeFreeProperty(screen->dpms);
drmModeFreeConnector(screen->connector);
drmClose(dev->drmFD);
- _eglCleanupDisplay(dpy);
+ dev->api->destroy(dev->api);
+ free(dev);
+ dpy->DriverData = NULL;
return EGL_TRUE;
}