From ef3df93f465e302f841150b6382f5ff4e4870c04 Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Fri, 3 May 2019 15:26:03 +0430 Subject: [PATCH] wined3d: Allocate shader backend and fragment pipe context data in device_context_add(). Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- dlls/wined3d/context.c | 39 ++++++++------------------------------- dlls/wined3d/device.c | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 31 deletions(-) diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c index 4a73cbbda13..7e7ab09b76c 100644 --- a/dlls/wined3d/context.c +++ b/dlls/wined3d/context.c @@ -1925,19 +1925,6 @@ static BOOL wined3d_context_init(struct wined3d_context *context, struct wined3d list_init(&context->fbo_list); list_init(&context->fbo_destroy_list); - if (!device->shader_backend->shader_allocate_context_data(context)) - { - ERR("Failed to allocate shader backend context data.\n"); - return FALSE; - } - - if (!device->adapter->fragment_pipe->allocate_context_data(context)) - { - ERR("Failed to allocate fragment pipeline context data.\n"); - device->shader_backend->shader_free_context_data(context); - return FALSE; - } - if (!(context->hdc = GetDCEx(swapchain->win_handle, 0, DCX_USESTYLE | DCX_CACHE))) { WARN("Failed to retrieve device context, trying swapchain backup.\n"); @@ -1945,8 +1932,6 @@ static BOOL wined3d_context_init(struct wined3d_context *context, struct wined3d if (!(context->hdc = swapchain_get_backup_dc(swapchain))) { ERR("Failed to retrieve a device context.\n"); - device->shader_backend->shader_free_context_data(context); - device->adapter->fragment_pipe->free_context_data(context); return FALSE; } context->hdc_is_private = TRUE; @@ -2001,31 +1986,23 @@ struct wined3d_context *context_create(struct wined3d_swapchain *swapchain, heap_free(context_gl); return NULL; } + if (!(device->adapter->adapter_ops->adapter_create_context(context, target, ds_format))) + { + wined3d_release_dc(context->win_handle, context->hdc); + heap_free(context_gl); + return NULL; + } if (!device_context_add(device, context)) { ERR("Failed to add the newly created context to the context list\n"); - goto fail; + wined3d_context_gl_destroy(context_gl); + return NULL; } - if (!(device->adapter->adapter_ops->adapter_create_context(context, target, ds_format))) - { - device_context_remove(device, context); - goto fail; - } - - device->shader_backend->shader_init_context_state(context); - TRACE("Created context %p.\n", context); return context; - -fail: - wined3d_release_dc(context->win_handle, context->hdc); - device->shader_backend->shader_free_context_data(context); - device->adapter->fragment_pipe->free_context_data(context); - heap_free(context_gl); - return NULL; } BOOL wined3d_adapter_gl_create_context(struct wined3d_context *context, diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index df491e1641e..a27251c86e3 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -149,14 +149,31 @@ BOOL device_context_add(struct wined3d_device *device, struct wined3d_context *c TRACE("Adding context %p.\n", context); + if (!device->shader_backend->shader_allocate_context_data(context)) + { + ERR("Failed to allocate shader backend context data.\n"); + return FALSE; + } + device->shader_backend->shader_init_context_state(context); + + if (!device->adapter->fragment_pipe->allocate_context_data(context)) + { + ERR("Failed to allocate fragment pipeline context data.\n"); + device->shader_backend->shader_free_context_data(context); + return FALSE; + } + if (!(new_array = heap_realloc(device->contexts, sizeof(*new_array) * (device->context_count + 1)))) { ERR("Failed to grow the context array.\n"); + device->adapter->fragment_pipe->free_context_data(context); + device->shader_backend->shader_free_context_data(context); return FALSE; } new_array[device->context_count++] = context; device->contexts = new_array; + return TRUE; }