i915: Destruction of surface, context and device in EGL
authorJakob Bornecrantz <jakob@tungstengraphics.com>
Mon, 7 Jul 2008 11:24:09 +0000 (13:24 +0200)
committerJakob Bornecrantz <jakob@tungstengraphics.com>
Mon, 7 Jul 2008 11:24:09 +0000 (13:24 +0200)
src/gallium/winsys/egl_drm/intel/intel_context.c
src/gallium/winsys/egl_drm/intel/intel_egl.c
src/gallium/winsys/egl_drm/intel/intel_egl.h
src/gallium/winsys/egl_drm/intel/intel_screen.c

index 7205fa4483a83448b6f59de14281b29cca7d04ca..7513f3feefe067d9b65ec27eb6f84e86c0e9c6c7 100644 (file)
@@ -178,6 +178,20 @@ intel_create_context(struct egl_drm_context *egl_context, const __GLcontextModes
        return TRUE;
 }
 
+int
+intel_destroy_context(struct egl_drm_context *egl_context)
+{
+       struct intel_context *intel = egl_context->priv;
+
+       if (intel->intel_screen->dummy == intel)
+               intel->intel_screen->dummy = NULL;
+
+       st_destroy_context(intel->st);
+       intel_be_destroy_context(&intel->base);
+       free(intel);
+       return TRUE;
+}
+
 void
 intel_make_current(struct egl_drm_context *context, struct egl_drm_drawable *draw, struct egl_drm_drawable *read)
 {
index e078b9eda101b2e1845be005cc544f2ec389dcf8..9e12a024eb0e6aeadb2bcb73d528858bbf93fe80 100644 (file)
@@ -32,7 +32,7 @@ egl_drm_create_device(int drmFD)
        memset(device, 0, sizeof(*device));
        device->drmFD = drmFD;
 
-       if (!intel_init_driver(device)) {
+       if (!intel_create_device(device)) {
                free(device);
                return NULL;
        }
@@ -180,8 +180,15 @@ drm_initialize(_EGLDriver *drv, EGLDisplay dpy, EGLint *major, EGLint *minor)
 static EGLBoolean
 drm_terminate(_EGLDriver *drv, EGLDisplay dpy)
 {
-       /* TODO: clean up */
-       free(drv);
+       struct drm_driver *drm_drv = (struct drm_driver *)drv;
+
+       intel_destroy_device(drm_drv->device);
+
+       drmClose(drm_drv->device->drmFD);
+
+       free(drm_drv->device);
+       free(drm_drv);
+
        return EGL_TRUE;
 }
 
@@ -303,6 +310,8 @@ drm_destroy_context(_EGLDriver *drv, EGLDisplay dpy, EGLContext context)
        if (fc->base.IsBound) {
                fc->base.DeletePending = EGL_TRUE;
        } else {
+               intel_destroy_context(fc->context);
+               free(fc->context);
                free(fc);
        }
        return EGL_TRUE;
@@ -322,6 +331,7 @@ drm_create_pixmap_surface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, Nat
        return EGL_NO_SURFACE;
 }
 
+
 static EGLSurface
 drm_create_pbuffer_surface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config,
                          const EGLint *attrib_list)
@@ -534,14 +544,15 @@ drm_destroy_surface(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface)
        if (fs->base.IsBound) {
                fs->base.DeletePending = EGL_TRUE;
        } else {
+               intel_bind_frontbuffer(fs->drawable, NULL);
+               intel_destroy_drawable(fs->drawable);
+               free(fs->drawable);
                free(fs);
        }
        return EGL_TRUE;
 }
 
 
-
-
 static EGLBoolean
 drm_make_current(_EGLDriver *drv, EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext context)
 {
index 18e84e8eeab3a93409b974a10eb688f2bfb70bb4..84b6c212bfdfd79fc5b65e203a7ea843731bca4a 100644 (file)
@@ -32,9 +32,15 @@ struct egl_drm_frontbuffer
 
 #include "GL/internal/glcore.h"
 
-int intel_init_driver(struct egl_drm_device *device);
+int intel_create_device(struct egl_drm_device *device);
+int intel_destroy_device(struct egl_drm_device *device);
+
 int intel_create_context(struct egl_drm_context *context, const __GLcontextModes *visual, void *sharedContextPrivate);
+int intel_destroy_context(struct egl_drm_context *context);
+
 int intel_create_drawable(struct egl_drm_drawable *drawable, const __GLcontextModes * visual);
+int intel_destroy_drawable(struct egl_drm_drawable *drawable);
+
 void intel_make_current(struct egl_drm_context *context, struct egl_drm_drawable *draw, struct egl_drm_drawable *read);
 void intel_swap_buffers(struct egl_drm_drawable *draw);
 void intel_bind_frontbuffer(struct egl_drm_drawable *draw, struct egl_drm_frontbuffer *front);
index 2818b9676c579944f0bde83d8eaa526d585f6ad7..12f605e0bea8dc095876a6de4945d763a5ed4c37 100644 (file)
@@ -41,7 +41,7 @@ extern const struct dri_extension card_extensions[];
 
 
 int
-intel_init_driver(struct egl_drm_device *device)
+intel_create_device(struct egl_drm_device *device)
 {
        struct intel_screen *intel_screen;
 
@@ -66,6 +66,19 @@ intel_init_driver(struct egl_drm_device *device)
        return TRUE;
 }
 
+int
+intel_destroy_device(struct egl_drm_device *device)
+{
+       struct intel_screen *intel_screen = (struct intel_screen *)device->priv;
+       
+       intel_be_destroy_device(&intel_screen->base);
+
+       free(intel_screen);
+       device->priv = NULL;
+
+       return TRUE;
+}
+
 int
 intel_create_drawable(struct egl_drm_drawable *drawable,
                       const __GLcontextModes * visual)
@@ -108,6 +121,18 @@ intel_create_drawable(struct egl_drm_drawable *drawable,
                return GL_FALSE;
        }
 
-   drawable->priv = (void *) intelfb;
-   return GL_TRUE;
+       drawable->priv = (void *) intelfb;
+       return GL_TRUE;
+}
+
+int
+intel_destroy_drawable(struct egl_drm_drawable *drawable)
+{
+       struct intel_framebuffer *intelfb = (struct intel_framebuffer *)drawable->priv;
+       drawable->priv = NULL;
+
+       assert(intelfb->stfb);
+       st_unreference_framebuffer(&intelfb->stfb);
+       free(intelfb);
+       return TRUE;
 }