From fd1de8f949ff49edbaff899af7e3a6ce83b99521 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20D=C3=B6singer?= <stefan@codeweavers.com>
Date: Fri, 11 Oct 2013 10:17:42 +0200
Subject: wined3d: Delete GL contexts through the CS in uninit_3d.

---
 dlls/wined3d/device.c | 33 +++------------------------------
 1 file changed, 3 insertions(+), 30 deletions(-)

diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index 800944b..8941632 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -1091,8 +1091,6 @@ static void device_free_sampler(struct wine_rb_entry *entry, void *context)
 HRESULT CDECL wined3d_device_uninit_3d(struct wined3d_device *device)
 {
     struct wined3d_resource *resource, *cursor;
-    const struct wined3d_gl_info *gl_info;
-    struct wined3d_context *context;
     struct wined3d_surface *surface;
     UINT i;
 
@@ -1104,12 +1102,6 @@ HRESULT CDECL wined3d_device_uninit_3d(struct wined3d_device *device)
     if (wined3d_settings.cs_multithreaded)
         device->cs->ops->finish(device->cs);
 
-    /* I don't think that the interface guarantees that the device is destroyed from the same thread
-     * it was created. Thus make sure a context is active for the glDelete* calls
-     */
-    context = context_acquire(device, NULL);
-    gl_info = context->gl_info;
-
     if (device->logo_texture)
         wined3d_texture_decref(device->logo_texture);
 
@@ -1139,31 +1131,11 @@ HRESULT CDECL wined3d_device_uninit_3d(struct wined3d_device *device)
         TRACE("Unloading resource %p.\n", resource);
         wined3d_cs_emit_evict_resource(device->cs, resource);
     }
-    if (wined3d_settings.cs_multithreaded)
-        device->cs->ops->finish(device->cs);
 
     wine_rb_clear(&device->samplers, device_free_sampler, NULL);
 
-    /* Destroy the depth blt resources, they will be invalid after the reset. Also free shader
-     * private data, it might contain opengl pointers
-     */
-    if (device->depth_blt_texture)
-    {
-        gl_info->gl_ops.gl.p_glDeleteTextures(1, &device->depth_blt_texture);
-        device->depth_blt_texture = 0;
-    }
-
-    /* Destroy the shader backend. Note that this has to happen after all shaders are destroyed. */
-    device->blitter->free_private(device);
-    device->shader_backend->shader_free_private(device);
-    destroy_dummy_textures(device, gl_info);
-    destroy_default_sampler(device);
-
-    /* Release the context again as soon as possible. In particular,
-     * releasing the render target views below may release the last reference
-     * to the swapchain associated with this context, which in turn will
-     * destroy the context. */
-    context_release(context);
+    /* FIXME: Is this in the right place??? */
+    wined3d_cs_emit_delete_opengl_contexts(device->cs, device->swapchains[0]);
 
     if (device->back_buffer_view)
     {
@@ -4443,6 +4415,7 @@ void device_delete_opengl_contexts_cs(struct wined3d_device *device, struct wine
 
     HeapFree(GetProcessHeap(), 0, swapchain->context);
     swapchain->context = NULL;
+    swapchain->num_contexts = 0;
 }
 
 static void delete_opengl_contexts(struct wined3d_device *device, struct wined3d_swapchain *swapchain)
-- 
2.6.4

