From: Paul Gofman Subject: [PATCH 1/2] wined3d: Factor out wined3d_context_gl_create_wgl() function. Message-Id: <20191114204003.162313-1-gofmanp@gmail.com> Date: Thu, 14 Nov 2019 23:40:02 +0300 Signed-off-by: Paul Gofman --- dlls/wined3d/context.c | 179 ++++++++++++++++++++++------------------- 1 file changed, 98 insertions(+), 81 deletions(-) diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c index f4c0d46f8e..5cb1b927e5 100644 --- a/dlls/wined3d/context.c +++ b/dlls/wined3d/context.c @@ -1935,11 +1935,11 @@ HRESULT wined3d_context_no3d_init(struct wined3d_context *context_no3d, struct w return WINED3D_OK; } -HRESULT wined3d_context_gl_init(struct wined3d_context_gl *context_gl, struct wined3d_swapchain_gl *swapchain_gl) +static BOOL wined3d_context_gl_create_wgl_ctx(struct wined3d_context_gl *context_gl, + struct wined3d_swapchain_gl *swapchain_gl) { const struct wined3d_format *color_format, *ds_format; struct wined3d_context *context = &context_gl->c; - const struct wined3d_d3d_info *d3d_info; const struct wined3d_gl_info *gl_info; struct wined3d_resource *target; unsigned int target_bind_flags; @@ -1947,81 +1947,8 @@ HRESULT wined3d_context_gl_init(struct wined3d_context_gl *context_gl, struct wi HGLRC ctx, share_ctx; unsigned int i; - TRACE("context_gl %p, swapchain %p.\n", context_gl, swapchain_gl); - - wined3d_context_init(&context_gl->c, &swapchain_gl->s); - device = context->device; gl_info = &device->adapter->gl_info; - context_gl->gl_info = gl_info; - d3d_info = context->d3d_info; - - context_gl->tid = GetCurrentThreadId(); - context_gl->window = context->swapchain->win_handle; - if (context_gl->window == GetDesktopWindow()) - { - TRACE("Swapchain is created on the desktop window, trying backup device context.\n"); - context_gl->dc = NULL; - } - else if (!(context_gl->dc = GetDCEx(context_gl->window, 0, DCX_USESTYLE | DCX_CACHE))) - WARN("Failed to retrieve device context, trying swapchain backup.\n"); - - if (!context_gl->dc) - { - if (!(context_gl->dc = wined3d_swapchain_gl_get_backup_dc(swapchain_gl))) - { - ERR("Failed to retrieve a device context.\n"); - return E_FAIL; - } - context_gl->dc_is_private = TRUE; - } - - list_init(&context_gl->fbo_list); - list_init(&context_gl->fbo_destroy_list); - - list_init(&context_gl->occlusion_queries); - list_init(&context_gl->fences); - list_init(&context_gl->timestamp_queries); - list_init(&context_gl->so_statistics_queries); - list_init(&context_gl->pipeline_statistics_queries); - - for (i = 0; i < ARRAY_SIZE(context_gl->tex_unit_map); ++i) - context_gl->tex_unit_map[i] = WINED3D_UNMAPPED_STAGE; - for (i = 0; i < ARRAY_SIZE(context_gl->rev_tex_unit_map); ++i) - context_gl->rev_tex_unit_map[i] = WINED3D_UNMAPPED_STAGE; - if (gl_info->limits.graphics_samplers >= WINED3D_MAX_COMBINED_SAMPLERS) - { - /* Initialize the texture unit mapping to a 1:1 mapping. */ - unsigned int base, count; - - wined3d_gl_limits_get_texture_unit_range(&gl_info->limits, WINED3D_SHADER_TYPE_PIXEL, &base, &count); - if (base + WINED3D_MAX_FRAGMENT_SAMPLERS > ARRAY_SIZE(context_gl->rev_tex_unit_map)) - { - ERR("Unexpected texture unit base index %u.\n", base); - goto fail; - } - for (i = 0; i < min(count, WINED3D_MAX_FRAGMENT_SAMPLERS); ++i) - { - context_gl->tex_unit_map[i] = base + i; - context_gl->rev_tex_unit_map[base + i] = i; - } - - wined3d_gl_limits_get_texture_unit_range(&gl_info->limits, WINED3D_SHADER_TYPE_VERTEX, &base, &count); - if (base + WINED3D_MAX_VERTEX_SAMPLERS > ARRAY_SIZE(context_gl->rev_tex_unit_map)) - { - ERR("Unexpected texture unit base index %u.\n", base); - goto fail; - } - for (i = 0; i < min(count, WINED3D_MAX_VERTEX_SAMPLERS); ++i) - { - context_gl->tex_unit_map[WINED3D_MAX_FRAGMENT_SAMPLERS + i] = base + i; - context_gl->rev_tex_unit_map[base + i] = WINED3D_MAX_FRAGMENT_SAMPLERS + i; - } - } - - if (!(context_gl->texture_type = heap_calloc(gl_info->limits.combined_samplers, - sizeof(*context_gl->texture_type)))) - goto fail; target = &context->current_rt.texture->resource; target_bind_flags = target->bind_flags; @@ -2095,7 +2022,7 @@ HRESULT wined3d_context_gl_init(struct wined3d_context_gl *context_gl, struct wi } if (!context_gl->pixel_format) - goto fail; + return FALSE; wined3d_context_gl_enter(context_gl); @@ -2103,7 +2030,7 @@ HRESULT wined3d_context_gl_init(struct wined3d_context_gl *context_gl, struct wi { ERR("Failed to set pixel format %d on device context %p.\n", context_gl->pixel_format, context_gl->dc); context_release(context); - goto fail; + return FALSE; } share_ctx = device->context_count ? wined3d_context_gl(device->contexts[0])->gl_ctx : NULL; @@ -2112,7 +2039,7 @@ HRESULT wined3d_context_gl_init(struct wined3d_context_gl *context_gl, struct wi if (!(ctx = context_create_wgl_attribs(gl_info, context_gl->dc, share_ctx))) { context_release(context); - goto fail; + return FALSE; } } else @@ -2121,7 +2048,7 @@ HRESULT wined3d_context_gl_init(struct wined3d_context_gl *context_gl, struct wi { ERR("Failed to create a WGL context.\n"); context_release(context); - goto fail; + return FALSE; } if (share_ctx && !wglShareLists(share_ctx, ctx)) @@ -2130,7 +2057,7 @@ HRESULT wined3d_context_gl_init(struct wined3d_context_gl *context_gl, struct wi context_release(context); if (!wglDeleteContext(ctx)) ERR("wglDeleteContext(%p) failed, last error %#x.\n", ctx, GetLastError()); - goto fail; + return FALSE; } } @@ -2149,9 +2076,99 @@ HRESULT wined3d_context_gl_init(struct wined3d_context_gl *context_gl, struct wi context_release(context); if (!wglDeleteContext(ctx)) ERR("wglDeleteContext(%p) failed, last error %#x.\n", ctx, GetLastError()); - goto fail; + return FALSE; + } + + return TRUE; +} + +HRESULT wined3d_context_gl_init(struct wined3d_context_gl *context_gl, struct wined3d_swapchain_gl *swapchain_gl) +{ + struct wined3d_context *context = &context_gl->c; + const struct wined3d_d3d_info *d3d_info; + const struct wined3d_gl_info *gl_info; + struct wined3d_device *device; + unsigned int i; + + TRACE("context_gl %p, swapchain %p.\n", context_gl, swapchain_gl); + + wined3d_context_init(&context_gl->c, &swapchain_gl->s); + + device = context->device; + gl_info = &device->adapter->gl_info; + context_gl->gl_info = gl_info; + d3d_info = context->d3d_info; + + context_gl->tid = GetCurrentThreadId(); + context_gl->window = context->swapchain->win_handle; + if (context_gl->window == GetDesktopWindow()) + { + TRACE("Swapchain is created on the desktop window, trying backup device context.\n"); + context_gl->dc = NULL; + } + else if (!(context_gl->dc = GetDCEx(context_gl->window, 0, DCX_USESTYLE | DCX_CACHE))) + WARN("Failed to retrieve device context, trying swapchain backup.\n"); + + if (!context_gl->dc) + { + if (!(context_gl->dc = wined3d_swapchain_gl_get_backup_dc(swapchain_gl))) + { + ERR("Failed to retrieve a device context.\n"); + return E_FAIL; + } + context_gl->dc_is_private = TRUE; + } + + list_init(&context_gl->fbo_list); + list_init(&context_gl->fbo_destroy_list); + + list_init(&context_gl->occlusion_queries); + list_init(&context_gl->fences); + list_init(&context_gl->timestamp_queries); + list_init(&context_gl->so_statistics_queries); + list_init(&context_gl->pipeline_statistics_queries); + + for (i = 0; i < ARRAY_SIZE(context_gl->tex_unit_map); ++i) + context_gl->tex_unit_map[i] = WINED3D_UNMAPPED_STAGE; + for (i = 0; i < ARRAY_SIZE(context_gl->rev_tex_unit_map); ++i) + context_gl->rev_tex_unit_map[i] = WINED3D_UNMAPPED_STAGE; + if (gl_info->limits.graphics_samplers >= WINED3D_MAX_COMBINED_SAMPLERS) + { + /* Initialize the texture unit mapping to a 1:1 mapping. */ + unsigned int base, count; + + wined3d_gl_limits_get_texture_unit_range(&gl_info->limits, WINED3D_SHADER_TYPE_PIXEL, &base, &count); + if (base + WINED3D_MAX_FRAGMENT_SAMPLERS > ARRAY_SIZE(context_gl->rev_tex_unit_map)) + { + ERR("Unexpected texture unit base index %u.\n", base); + goto fail; + } + for (i = 0; i < min(count, WINED3D_MAX_FRAGMENT_SAMPLERS); ++i) + { + context_gl->tex_unit_map[i] = base + i; + context_gl->rev_tex_unit_map[base + i] = i; + } + + wined3d_gl_limits_get_texture_unit_range(&gl_info->limits, WINED3D_SHADER_TYPE_VERTEX, &base, &count); + if (base + WINED3D_MAX_VERTEX_SAMPLERS > ARRAY_SIZE(context_gl->rev_tex_unit_map)) + { + ERR("Unexpected texture unit base index %u.\n", base); + goto fail; + } + for (i = 0; i < min(count, WINED3D_MAX_VERTEX_SAMPLERS); ++i) + { + context_gl->tex_unit_map[WINED3D_MAX_FRAGMENT_SAMPLERS + i] = base + i; + context_gl->rev_tex_unit_map[base + i] = WINED3D_MAX_FRAGMENT_SAMPLERS + i; + } } + if (!(context_gl->texture_type = heap_calloc(gl_info->limits.combined_samplers, + sizeof(*context_gl->texture_type)))) + goto fail; + + if (!wined3d_context_gl_create_wgl_ctx(context_gl, swapchain_gl)) + goto fail; + if (context_debug_output_enabled(gl_info)) { GL_EXTCALL(glDebugMessageCallback(wined3d_debug_callback, context)); -- 2.23.0