Module: wine Branch: master Commit: ec6062c572509d1b916045f078c55663592ee52a URL: https://gitlab.winehq.org/wine/wine/-/commit/ec6062c572509d1b916045f078c5566...
Author: Piotr Caban piotr@codeweavers.com Date: Tue May 16 13:43:28 2023 +0200
wineps: Introduce wine_driver_open_dc wine specific export used to create printer DC.
Doing it this way avoids passing Unix library pointers throught PE.
---
dlls/gdi32/dc.c | 13 +++++++++---- dlls/win32u/dc.c | 9 ++++----- dlls/wineps.drv/init.c | 35 +++++++++++++++++++---------------- dlls/wineps.drv/unixlib.c | 25 +++++++++++++++++-------- dlls/wineps.drv/unixlib.h | 14 ++++++++------ dlls/wineps.drv/wineps.drv.spec | 2 +- 6 files changed, 58 insertions(+), 40 deletions(-)
diff --git a/dlls/gdi32/dc.c b/dlls/gdi32/dc.c index 91ab6c43bde..e7f2d8526d1 100644 --- a/dlls/gdi32/dc.c +++ b/dlls/gdi32/dc.c @@ -42,7 +42,8 @@ static CRITICAL_SECTION_DEBUG critsect_debug = }; static CRITICAL_SECTION driver_section = { &critsect_debug, -1, 0, 0, 0, 0 };
-typedef const void * (CDECL *driver_entry_point)( unsigned int version, const WCHAR *device ); +typedef HDC (CDECL *driver_entry_point)( const WCHAR *device, + const DEVMODEW *devmode, const WCHAR *output );
struct graphics_driver { @@ -138,7 +139,7 @@ static struct graphics_driver *create_driver( HMODULE module ) driver->module = module;
if (module) - driver->entry_point = (void *)GetProcAddress( module, "wine_get_gdi_driver" ); + driver->entry_point = (void *)GetProcAddress( module, "wine_driver_open_dc" ); else driver->entry_point = NULL;
@@ -312,8 +313,12 @@ HDC WINAPI CreateDCW( LPCWSTR driver, LPCWSTR device, LPCWSTR output, device_str.Buffer = (WCHAR *)device; }
- ret = NtGdiOpenDCW( device || display ? &device_str : NULL, devmode, output ? &output_str : NULL, - 0, is_display, entry_point, NULL, NULL ); + if (entry_point) + ret = entry_point( device, devmode, output ); + else + ret = NtGdiOpenDCW( device || display ? &device_str : NULL, devmode, + output ? &output_str : NULL, + 0, is_display, entry_point, NULL, NULL );
if (ret && hspool && (dc_attr = get_dc_attr( ret ))) { diff --git a/dlls/win32u/dc.c b/dlls/win32u/dc.c index bcfbed29426..9e8e2f65212 100644 --- a/dlls/win32u/dc.c +++ b/dlls/win32u/dc.c @@ -717,11 +717,10 @@ HDC WINAPI NtGdiOpenDCW( UNICODE_STRING *device, const DEVMODEW *devmode, UNICOD /* gdi_lock should not be locked */ if (is_display) funcs = get_display_driver(); - else if (hspool) - { - const struct gdi_dc_funcs * (CDECL *wine_get_gdi_driver)( unsigned int, const WCHAR * ) = hspool; - funcs = wine_get_gdi_driver( WINE_GDI_DRIVER_VERSION, device ? device->Buffer : NULL ); - } + else if (type != WINE_GDI_DRIVER_VERSION) + ERR( "version mismatch: %u\n", (unsigned int)type ); + else + funcs = hspool; if (!funcs) { ERR( "no driver found\n" ); diff --git a/dlls/wineps.drv/init.c b/dlls/wineps.drv/init.c index 136856d5dc0..ec015e1c871 100644 --- a/dlls/wineps.drv/init.c +++ b/dlls/wineps.drv/init.c @@ -897,24 +897,27 @@ fail: }
/****************************************************************************** - * PSDRV_get_gdi_driver + * PSDRV_open_printer_dc */ -const struct gdi_dc_funcs * CDECL PSDRV_get_gdi_driver( unsigned int version, const WCHAR *name ) +HDC CDECL PSDRV_open_printer_dc( const WCHAR *device, + const DEVMODEW *devmode, const WCHAR *output ) { - PRINTERINFO *pi = PSDRV_FindPrinterInfo( name ); - struct init_dc_params params; + struct open_dc_params params; + PRINTERINFO *pi; + + if (!device) + return 0;
+ pi = PSDRV_FindPrinterInfo( device ); if (!pi) - return NULL; - if (version != WINE_GDI_DRIVER_VERSION) - { - ERR( "version mismatch, gdi32 wants %u but wineps has %u\n", version, WINE_GDI_DRIVER_VERSION ); - return NULL; - } - params.name = pi->friendly_name; - params.devmode = pi->Devmode; - params.funcs = NULL; - if (!WINE_UNIX_CALL( unix_init_dc, ¶ms )) - return FALSE; - return params.funcs; + return 0; + + params.device = pi->friendly_name; + params.devmode = devmode; + params.output = output; + params.def_devmode = pi->Devmode; + params.hdc = 0; + if (!WINE_UNIX_CALL( unix_open_dc, ¶ms )) + return 0; + return params.hdc; } diff --git a/dlls/wineps.drv/unixlib.c b/dlls/wineps.drv/unixlib.c index 68509025eac..80331372572 100644 --- a/dlls/wineps.drv/unixlib.c +++ b/dlls/wineps.drv/unixlib.c @@ -1688,23 +1688,32 @@ static NTSTATUS import_ntf(void *arg) return add_ntf_fonts(params->data, params->size); }
-static NTSTATUS init_dc(void *arg) +static NTSTATUS open_dc(void *arg) { - struct init_dc_params *params = arg; + UNICODE_STRING device_str, output_str; + struct open_dc_params *params = arg; struct printer_info *pi;
- pi = find_printer_info(params->name); + pi = find_printer_info(params->device); if (!pi) { pi = malloc(sizeof(*pi)); if (!pi) return FALSE;
- pi->name = params->name; - pi->devmode = params->devmode; + pi->name = params->device; + pi->devmode = params->def_devmode; list_add_head(&printer_info_list, &pi->entry); }
- params->funcs = &psdrv_funcs; + device_str.Length = device_str.MaximumLength = lstrlenW(params->device) + 1; + device_str.Buffer = (WCHAR *)params->device; + if (params->output) + { + output_str.Length = output_str.MaximumLength = lstrlenW(params->output) + 1; + output_str.Buffer = (WCHAR *)params->output; + } + params->hdc = NtGdiOpenDCW(&device_str, params->devmode, params->output ? &output_str : NULL, + WINE_GDI_DRIVER_VERSION, 0, (HANDLE)&psdrv_funcs, NULL, NULL); return TRUE; }
@@ -1727,9 +1736,9 @@ static NTSTATUS free_printer_info(void *arg)
const unixlib_entry_t __wine_unix_call_funcs[] = { - import_ntf, - init_dc, free_printer_info, + import_ntf, + open_dc, };
C_ASSERT(ARRAYSIZE(__wine_unix_call_funcs) == unix_funcs_count); diff --git a/dlls/wineps.drv/unixlib.h b/dlls/wineps.drv/unixlib.h index 03459590dc6..e28a4416d09 100644 --- a/dlls/wineps.drv/unixlib.h +++ b/dlls/wineps.drv/unixlib.h @@ -74,9 +74,9 @@ struct installed_font /* Unix calls */ enum wineps_funcs { - unix_import_ntf, - unix_init_dc, unix_free_printer_info, + unix_import_ntf, + unix_open_dc, unix_funcs_count, };
@@ -86,9 +86,11 @@ struct import_ntf_params int size; };
-struct init_dc_params +struct open_dc_params { - const WCHAR *name; - PSDRV_DEVMODE *devmode; - const struct gdi_dc_funcs *funcs; + const WCHAR *device; + const DEVMODEW *devmode; + const WCHAR *output; + PSDRV_DEVMODE *def_devmode; + HDC hdc; }; diff --git a/dlls/wineps.drv/wineps.drv.spec b/dlls/wineps.drv/wineps.drv.spec index aca8ed2d10f..f193930a9fe 100644 --- a/dlls/wineps.drv/wineps.drv.spec +++ b/dlls/wineps.drv/wineps.drv.spec @@ -1,4 +1,4 @@ -@ cdecl wine_get_gdi_driver(long str) PSDRV_get_gdi_driver +@ cdecl wine_driver_open_dc(wstr ptr wstr) PSDRV_open_printer_dc @ stdcall -private DllRegisterServer()
# Printer driver config exports