From: Rémi Bernon rbernon@codeweavers.com
--- dlls/winex11.drv/display.c | 35 ++++++------- dlls/winex11.drv/x11drv.h | 31 ++++++++++-- dlls/winex11.drv/xrandr.c | 97 +++++++++++++++---------------------- dlls/winex11.drv/xvidmode.c | 45 ++++++++--------- 4 files changed, 104 insertions(+), 104 deletions(-)
diff --git a/dlls/winex11.drv/display.c b/dlls/winex11.drv/display.c index f063dabcbb5..e4a0bef2f08 100644 --- a/dlls/winex11.drv/display.c +++ b/dlls/winex11.drv/display.c @@ -62,10 +62,10 @@ static BOOL nores_get_id(const WCHAR *device_name, BOOL is_primary, x11drv_setti return TRUE; }
-static BOOL nores_get_modes( x11drv_settings_id id, DWORD flags, DEVMODEW **new_modes, UINT *mode_count ) +static BOOL nores_get_modes( x11drv_settings_id id, DWORD flags, struct x11drv_mode **new_modes, UINT *mode_count ) { RECT primary = get_host_primary_monitor_rect(); - DEVMODEW *modes; + struct x11drv_mode *modes;
modes = calloc(1, sizeof(*modes)); if (!modes) @@ -74,16 +74,16 @@ static BOOL nores_get_modes( x11drv_settings_id id, DWORD flags, DEVMODEW **new_ return FALSE; }
- modes[0].dmSize = sizeof(*modes); - modes[0].dmDriverExtra = 0; - modes[0].dmFields = DM_DISPLAYORIENTATION | DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | - DM_DISPLAYFLAGS | DM_DISPLAYFREQUENCY; - modes[0].dmDisplayOrientation = DMDO_DEFAULT; - modes[0].dmBitsPerPel = screen_bpp; - modes[0].dmPelsWidth = primary.right; - modes[0].dmPelsHeight = primary.bottom; - modes[0].dmDisplayFlags = 0; - modes[0].dmDisplayFrequency = 60; + modes[0].mode.dmSize = sizeof(*modes); + modes[0].mode.dmDriverExtra = 0; + modes[0].mode.dmFields = DM_DISPLAYORIENTATION | DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | + DM_DISPLAYFLAGS | DM_DISPLAYFREQUENCY; + modes[0].mode.dmDisplayOrientation = DMDO_DEFAULT; + modes[0].mode.dmBitsPerPel = screen_bpp; + modes[0].mode.dmPelsWidth = primary.right; + modes[0].mode.dmPelsHeight = primary.bottom; + modes[0].mode.dmDisplayFlags = 0; + modes[0].mode.dmDisplayFrequency = 60;
*new_modes = modes; *mode_count = 1; @@ -175,8 +175,9 @@ static BOOL is_same_devmode( const DEVMODEW *a, const DEVMODEW *b ) * Return NULL on failure. Caller should call free_full_mode() to free the returned mode. */ static DEVMODEW *get_full_mode(x11drv_settings_id id, DEVMODEW *dev_mode) { - DEVMODEW *modes, *full_mode, *found_mode = NULL; + DEVMODEW *full_mode, *found_mode = NULL; UINT mode_count, mode_idx; + struct x11drv_mode *modes;
if (is_detached_mode(dev_mode)) return dev_mode; @@ -185,7 +186,7 @@ static DEVMODEW *get_full_mode(x11drv_settings_id id, DEVMODEW *dev_mode)
for (mode_idx = 0; mode_idx < mode_count; ++mode_idx) { - found_mode = (DEVMODEW *)((BYTE *)modes + (sizeof(*modes) + modes[0].dmDriverExtra) * mode_idx); + found_mode = &modes[mode_idx].mode; if (is_same_devmode( found_mode, dev_mode )) break; }
@@ -416,7 +417,7 @@ UINT X11DRV_UpdateDisplayDevices( const struct gdi_device_manager *device_manage struct gdi_monitor *monitors; struct x11drv_gpu *gpus; INT gpu, adapter, monitor; - DEVMODEW *modes; + struct x11drv_mode *modes; UINT mode_count;
TRACE( "via %s\n", debugstr_a(host_handler.name) ); @@ -462,8 +463,8 @@ UINT X11DRV_UpdateDisplayDevices( const struct gdi_device_manager *device_manage settings_handler.get_current_mode( settings_id, ¤t_mode ); if (settings_handler.get_modes( settings_id, EDS_ROTATEDMODE, &modes, &mode_count )) { - strip_driver_extra( modes, mode_count ); - device_manager->add_modes( ¤t_mode, mode_count, modes, param ); + strip_driver_extra( &modes->mode, mode_count ); + device_manager->add_modes( ¤t_mode, mode_count, &modes->mode, param ); free( modes ); } } diff --git a/dlls/winex11.drv/x11drv.h b/dlls/winex11.drv/x11drv.h index a92ffb6428e..f19995391e8 100644 --- a/dlls/winex11.drv/x11drv.h +++ b/dlls/winex11.drv/x11drv.h @@ -38,6 +38,9 @@ #include <X11/extensions/XInput2.h> #endif
+#undef Status /* avoid conflict with wintrnl.h */ +typedef int Status; + #define BOOL X_BOOL #define BYTE X_BYTE #define INT8 X_INT8 @@ -46,6 +49,12 @@ #define INT64 X_INT64 #include <X11/Xmd.h> #include <X11/Xproto.h> +#ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H +#include <X11/extensions/xf86vmode.h> +#endif +#ifdef HAVE_X11_EXTENSIONS_XRANDR_H +#include <X11/extensions/Xrandr.h> +#endif #undef BOOL #undef BYTE #undef INT8 @@ -54,9 +63,6 @@ #undef INT64 #undef LONG64
-#undef Status /* avoid conflict with wintrnl.h */ -typedef int Status; - /* avoid conflict with processthreadsapi.h */ #undef ControlMask
@@ -757,6 +763,21 @@ extern const unsigned int *depths; /* Use a distinct type for the settings id, to avoid mixups other types of ids */ typedef struct { ULONG_PTR id; } x11drv_settings_id;
+struct x11drv_mode +{ + DEVMODEW mode; + union + { +#ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H + XF86VidModeModeInfo xf86vm; +#endif +#ifdef HAVE_X11_EXTENSIONS_XRANDR_H + SizeID xrandr10; + RRMode xrandr14; +#endif + }; +}; + /* Required functions for changing and enumerating display settings */ struct x11drv_settings_handler { @@ -781,7 +802,7 @@ struct x11drv_settings_handler * dmDisplayFlags and dmDisplayFrequency * * Return FALSE on failure with parameters unchanged and error code set. Return TRUE on success */ - BOOL (*get_modes)(x11drv_settings_id id, DWORD flags, DEVMODEW **modes, UINT *mode_count); + BOOL (*get_modes)(x11drv_settings_id id, DWORD flags, struct x11drv_mode **modes, UINT *mode_count);
/* get_current_mode() will be called to get the current display mode of the device of id * @@ -796,7 +817,7 @@ struct x11drv_settings_handler * mode must be a valid mode from get_modes() with optional fields, such as dmPosition set. * * Return DISP_CHANGE_*, same as ChangeDisplaySettingsExW() return values */ - LONG (*set_current_mode)(x11drv_settings_id id, const DEVMODEW *mode); + LONG (*set_current_mode)(x11drv_settings_id id, const struct x11drv_mode *mode); };
#define NEXT_DEVMODEW(mode) ((DEVMODEW *)((char *)((mode) + 1) + (mode)->dmDriverExtra)) diff --git a/dlls/winex11.drv/xrandr.c b/dlls/winex11.drv/xrandr.c index 8b675ec355b..6555d07f4ca 100644 --- a/dlls/winex11.drv/xrandr.c +++ b/dlls/winex11.drv/xrandr.c @@ -238,31 +238,30 @@ static BOOL xrandr10_get_id( const WCHAR *device_name, BOOL is_primary, x11drv_s return TRUE; }
-static void add_xrandr10_mode( DEVMODEW *mode, DWORD depth, DWORD width, DWORD height, +static void add_xrandr10_mode( struct x11drv_mode *mode, DWORD depth, DWORD width, DWORD height, DWORD frequency, SizeID size_id ) { - mode->dmSize = sizeof(*mode); - mode->dmDriverExtra = sizeof(SizeID); - mode->dmFields = DM_DISPLAYORIENTATION | DM_BITSPERPEL | DM_PELSWIDTH | + mode->mode.dmSize = sizeof(*mode); + mode->mode.dmDriverExtra = sizeof(*mode) - sizeof(mode->mode); + mode->mode.dmFields = DM_DISPLAYORIENTATION | DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFLAGS; if (frequency) { - mode->dmFields |= DM_DISPLAYFREQUENCY; - mode->dmDisplayFrequency = frequency; + mode->mode.dmFields |= DM_DISPLAYFREQUENCY; + mode->mode.dmDisplayFrequency = frequency; } - mode->dmDisplayOrientation = DMDO_DEFAULT; - mode->dmBitsPerPel = depth; - mode->dmPelsWidth = width; - mode->dmPelsHeight = height; - mode->dmDisplayFlags = 0; - memcpy( mode + 1, &size_id, sizeof(size_id) ); + mode->mode.dmDisplayOrientation = DMDO_DEFAULT; + mode->mode.dmBitsPerPel = depth; + mode->mode.dmPelsWidth = width; + mode->mode.dmPelsHeight = height; + mode->mode.dmDisplayFlags = 0; + mode->xrandr10 = size_id; }
-static BOOL xrandr10_get_modes( x11drv_settings_id id, DWORD flags, DEVMODEW **new_modes, UINT *new_mode_count ) +static BOOL xrandr10_get_modes( x11drv_settings_id id, DWORD flags, struct x11drv_mode **new_modes, UINT *new_mode_count ) { - INT size_idx, depth_idx, rate_idx, mode_idx = 0; - INT size_count, rate_count, mode_count = 0; - DEVMODEW *modes, *mode; + INT size_idx, depth_idx, rate_idx, size_count, rate_count, mode_count = 0; + struct x11drv_mode *modes, *mode; XRRScreenSize *sizes; short *rates;
@@ -279,10 +278,7 @@ static BOOL xrandr10_get_modes( x11drv_settings_id id, DWORD flags, DEVMODEW **n ++mode_count; }
- /* Allocate space for reported modes in three depths, and put an SizeID at the end of DEVMODEW as - * driver private data */ - modes = calloc( mode_count * DEPTH_COUNT, sizeof(*modes) + sizeof(SizeID) ); - if (!modes) + if (!(modes = calloc( mode_count * DEPTH_COUNT, sizeof(*modes) ))) { RtlSetLastWin32Error( ERROR_NOT_ENOUGH_MEMORY ); return FALSE; @@ -295,25 +291,21 @@ static BOOL xrandr10_get_modes( x11drv_settings_id id, DWORD flags, DEVMODEW **n rates = pXRRRates( gdi_display, DefaultScreen( gdi_display ), size_idx, &rate_count ); if (!rate_count) { - add_xrandr10_mode( mode, depths[depth_idx], sizes[size_idx].width, + add_xrandr10_mode( mode++, depths[depth_idx], sizes[size_idx].width, sizes[size_idx].height, 0, size_idx ); - mode = NEXT_DEVMODEW( mode ); - mode_idx++; continue; }
for (rate_idx = 0; rate_idx < rate_count; ++rate_idx) { - add_xrandr10_mode( mode, depths[depth_idx], sizes[size_idx].width, + add_xrandr10_mode( mode++, depths[depth_idx], sizes[size_idx].width, sizes[size_idx].height, rates[rate_idx], size_idx ); - mode = NEXT_DEVMODEW( mode ); - mode_idx++; } } }
*new_modes = modes; - *new_mode_count = mode_idx; + *new_mode_count = mode - modes; return TRUE; }
@@ -1330,46 +1322,46 @@ static BOOL xrandr14_get_id( const WCHAR *device_name, BOOL is_primary, x11drv_s return TRUE; }
-static void add_xrandr14_mode( DEVMODEW *mode, XRRModeInfo *info, DWORD depth, DWORD frequency, +static void add_xrandr14_mode( struct x11drv_mode *mode, XRRModeInfo *info, DWORD depth, DWORD frequency, DWORD orientation ) { - mode->dmSize = sizeof(*mode); - mode->dmDriverExtra = sizeof(RRMode); - mode->dmFields = DM_DISPLAYORIENTATION | DM_BITSPERPEL | DM_PELSWIDTH | + mode->mode.dmSize = sizeof(*mode); + mode->mode.dmDriverExtra = sizeof(*mode) - sizeof(mode->mode); + mode->mode.dmFields = DM_DISPLAYORIENTATION | DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFLAGS; if (frequency) { - mode->dmFields |= DM_DISPLAYFREQUENCY; - mode->dmDisplayFrequency = frequency; + mode->mode.dmFields |= DM_DISPLAYFREQUENCY; + mode->mode.dmDisplayFrequency = frequency; } if (orientation == DMDO_DEFAULT || orientation == DMDO_180) { - mode->dmPelsWidth = info->width; - mode->dmPelsHeight = info->height; + mode->mode.dmPelsWidth = info->width; + mode->mode.dmPelsHeight = info->height; } else { - mode->dmPelsWidth = info->height; - mode->dmPelsHeight = info->width; + mode->mode.dmPelsWidth = info->height; + mode->mode.dmPelsHeight = info->width; } - mode->dmDisplayOrientation = orientation; - mode->dmBitsPerPel = depth; - mode->dmDisplayFlags = 0; - memcpy( mode + 1, &info->id, sizeof(info->id) ); + mode->mode.dmDisplayOrientation = orientation; + mode->mode.dmBitsPerPel = depth; + mode->mode.dmDisplayFlags = 0; + mode->xrandr14 = info->id; }
-static BOOL xrandr14_get_modes( x11drv_settings_id id, DWORD flags, DEVMODEW **new_modes, UINT *mode_count ) +static BOOL xrandr14_get_modes( x11drv_settings_id id, DWORD flags, struct x11drv_mode **new_modes, UINT *mode_count ) { DWORD frequency, orientation, orientation_count; XRRScreenResources *screen_resources; XRROutputInfo *output_info = NULL; RROutput output = (RROutput)id.id; + struct x11drv_mode *mode, *modes; XRRCrtcInfo *crtc_info = NULL; - UINT depth_idx, mode_idx = 0; XRRModeInfo *mode_info; - DEVMODEW *mode, *modes; Rotation rotations; BOOL ret = FALSE; + UINT depth_idx; RRCrtc crtc; INT i, j;
@@ -1423,12 +1415,7 @@ static BOOL xrandr14_get_modes( x11drv_settings_id id, DWORD flags, DEVMODEW **n } orientation_count = get_orientation_count( rotations );
- /* Allocate space for display modes in different color depths and orientations. - * Store a RRMode at the end of each DEVMODEW as private driver data */ - modes = calloc( output_info->nmode * DEPTH_COUNT * orientation_count, - sizeof(*modes) + sizeof(RRMode) ); - if (!modes) - goto done; + if (!(modes = calloc( output_info->nmode * DEPTH_COUNT * orientation_count, sizeof(*modes) ))) goto done;
for (i = 0, mode = modes; i < output_info->nmode; ++i) { @@ -1444,12 +1431,8 @@ static BOOL xrandr14_get_modes( x11drv_settings_id id, DWORD flags, DEVMODEW **n { for (orientation = DMDO_DEFAULT; orientation <= DMDO_270; ++orientation) { - if (!((1 << orientation) & rotations)) - continue; - - add_xrandr14_mode( mode, mode_info, depths[depth_idx], frequency, orientation ); - mode = NEXT_DEVMODEW( mode ); - ++mode_idx; + if (!((1 << orientation) & rotations)) continue; + add_xrandr14_mode( mode++, mode_info, depths[depth_idx], frequency, orientation ); } }
@@ -1459,7 +1442,7 @@ static BOOL xrandr14_get_modes( x11drv_settings_id id, DWORD flags, DEVMODEW **n
ret = TRUE; *new_modes = modes; - *mode_count = mode_idx; + *mode_count = mode - modes; done: if (crtc_info) pXRRFreeCrtcInfo( crtc_info ); diff --git a/dlls/winex11.drv/xvidmode.c b/dlls/winex11.drv/xvidmode.c index 7af34689dda..a47fed8a2e1 100644 --- a/dlls/winex11.drv/xvidmode.c +++ b/dlls/winex11.drv/xvidmode.c @@ -91,35 +91,32 @@ static BOOL xf86vm_get_id(const WCHAR *device_name, BOOL is_primary, x11drv_sett return TRUE; }
-static void add_xf86vm_mode( DEVMODEW *mode, DWORD depth, const XF86VidModeModeInfo *mode_info ) +static void add_xf86vm_mode( struct x11drv_mode *mode, DWORD depth, const XF86VidModeModeInfo *mode_info ) { - XF86VidModeModeInfo extra = *mode_info; - - mode->dmSize = sizeof(*mode); - mode->dmDriverExtra = sizeof(*mode_info); - mode->dmFields = DM_DISPLAYORIENTATION | DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFLAGS; + mode->mode.dmSize = sizeof(*mode); + mode->mode.dmDriverExtra = sizeof(*mode) - sizeof(mode->mode); + mode->mode.dmFields = DM_DISPLAYORIENTATION | DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFLAGS; if (mode_info->htotal && mode_info->vtotal) { - mode->dmFields |= DM_DISPLAYFREQUENCY; - mode->dmDisplayFrequency = mode_info->dotclock * 1000 / (mode_info->htotal * mode_info->vtotal); + mode->mode.dmFields |= DM_DISPLAYFREQUENCY; + mode->mode.dmDisplayFrequency = mode_info->dotclock * 1000 / (mode_info->htotal * mode_info->vtotal); } - mode->dmDisplayOrientation = DMDO_DEFAULT; - mode->dmBitsPerPel = depth; - mode->dmPelsWidth = mode_info->hdisplay; - mode->dmPelsHeight = mode_info->vdisplay; - mode->dmDisplayFlags = 0; - - extra.private = NULL; - extra.privsize = 0; - memcpy( mode + 1, &extra, sizeof(extra) ); + mode->mode.dmDisplayOrientation = DMDO_DEFAULT; + mode->mode.dmBitsPerPel = depth; + mode->mode.dmPelsWidth = mode_info->hdisplay; + mode->mode.dmPelsHeight = mode_info->vdisplay; + mode->mode.dmDisplayFlags = 0; + mode->xf86vm = *mode_info; + mode->xf86vm.privsize = 0; + mode->xf86vm.private = NULL; }
-static BOOL xf86vm_get_modes( x11drv_settings_id id, DWORD flags, DEVMODEW **new_modes, UINT *mode_count ) +static BOOL xf86vm_get_modes( x11drv_settings_id id, DWORD flags, struct x11drv_mode **new_modes, UINT *mode_count ) { INT xf86vm_mode_idx, xf86vm_mode_count; XF86VidModeModeInfo **xf86vm_modes; - UINT depth_idx, mode_idx = 0; - DEVMODEW *modes, *mode; + struct x11drv_mode *modes, *mode; + UINT depth_idx; Bool ret;
X11DRV_expect_error(gdi_display, XVidModeErrorHandler, NULL); @@ -129,7 +126,7 @@ static BOOL xf86vm_get_modes( x11drv_settings_id id, DWORD flags, DEVMODEW **new
/* Display modes in different color depth, with a XF86VidModeModeInfo * at the end of each * DEVMODEW as driver private data */ - if (!(modes = calloc( 1, (xf86vm_mode_count * DEPTH_COUNT) * (sizeof(DEVMODEW) + sizeof(XF86VidModeModeInfo)) ))) + if (!(modes = calloc( xf86vm_mode_count * DEPTH_COUNT, sizeof(*modes) ))) { RtlSetLastWin32Error( ERROR_NOT_ENOUGH_MEMORY ); XFree( xf86vm_modes ); @@ -140,14 +137,12 @@ static BOOL xf86vm_get_modes( x11drv_settings_id id, DWORD flags, DEVMODEW **new { for (xf86vm_mode_idx = 0; xf86vm_mode_idx < xf86vm_mode_count; ++xf86vm_mode_idx) { - add_xf86vm_mode( mode, depths[depth_idx], xf86vm_modes[xf86vm_mode_idx] ); - mode = NEXT_DEVMODEW( mode ); - mode_idx++; + add_xf86vm_mode( mode++, depths[depth_idx], xf86vm_modes[xf86vm_mode_idx] ); } }
*new_modes = modes; - *mode_count = mode_idx; + *mode_count = mode - modes;
XFree( xf86vm_modes ); return TRUE;