d3d9exhook/sdvxhook2: add option to force monitor orientation
also adds adapter hook into sdvxhook2
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
#define D3D9EXHOOK_CONFIG_GFX_WINDOW_HEIGHT_KEY "gfx.window_height"
|
||||
#define D3D9EXHOOK_CONFIG_GFX_FORCED_REFRESHRATE_KEY "gfx.forced_refresh_rate"
|
||||
#define D3D9EXHOOK_CONFIG_GFX_DEVICE_ADAPTER_KEY "gfx.device_adapter"
|
||||
#define D3D9EXHOOK_CONFIG_GFX_FORCE_ORIENTATION_KEY "gfx.force_orientation"
|
||||
|
||||
#define D3D9EXHOOK_CONFIG_GFX_DEFAULT_FRAMED_VALUE false
|
||||
#define D3D9EXHOOK_CONFIG_GFX_DEFAULT_WINDOWED_VALUE false
|
||||
@@ -21,6 +22,7 @@
|
||||
#define D3D9EXHOOK_CONFIG_GFX_DEFAULT_WINDOW_HEIGHT_VALUE -1
|
||||
#define D3D9EXHOOK_CONFIG_GFX_DEFAULT_FORCED_RR_VALUE -1
|
||||
#define D3D9EXHOOK_CONFIG_GFX_DEFAULT_DEVICE_ADAPTER_VALUE -1
|
||||
#define D3D9EXHOOK_CONFIG_GFX_DEFAULT_FORCE_ORIENTATION_VALUE -1
|
||||
|
||||
void d3d9exhook_config_gfx_init(struct cconfig *config)
|
||||
{
|
||||
@@ -59,8 +61,15 @@ void d3d9exhook_config_gfx_init(struct cconfig *config)
|
||||
config,
|
||||
D3D9EXHOOK_CONFIG_GFX_DEVICE_ADAPTER_KEY,
|
||||
D3D9EXHOOK_CONFIG_GFX_DEFAULT_DEVICE_ADAPTER_VALUE,
|
||||
"D3D9ex device adapter (monitor), -1 to use default,"
|
||||
"D3D9ex device adapter (monitor), -1 to use default, "
|
||||
"0, 1, 2 etc. to use specified adapter");
|
||||
|
||||
cconfig_util_set_int(
|
||||
config,
|
||||
D3D9EXHOOK_CONFIG_GFX_FORCE_ORIENTATION_KEY,
|
||||
D3D9EXHOOK_CONFIG_GFX_DEFAULT_FORCE_ORIENTATION_VALUE,
|
||||
"Orientation to force monitor into, -1 to use default, "
|
||||
"0, 1, 2, 3 to do 0, 90, 180, 270 degrees");
|
||||
}
|
||||
|
||||
void d3d9exhook_config_gfx_get(
|
||||
@@ -137,4 +146,16 @@ void d3d9exhook_config_gfx_get(
|
||||
D3D9EXHOOK_CONFIG_GFX_DEVICE_ADAPTER_KEY,
|
||||
D3D9EXHOOK_CONFIG_GFX_DEFAULT_DEVICE_ADAPTER_VALUE);
|
||||
}
|
||||
|
||||
if (!cconfig_util_get_int(
|
||||
config,
|
||||
D3D9EXHOOK_CONFIG_GFX_FORCE_ORIENTATION_KEY,
|
||||
&config_gfx->force_orientation,
|
||||
D3D9EXHOOK_CONFIG_GFX_DEFAULT_FORCE_ORIENTATION_VALUE)) {
|
||||
log_warning(
|
||||
"Invalid value for key '%s' specified, fallback "
|
||||
"to default '%d'",
|
||||
D3D9EXHOOK_CONFIG_GFX_FORCE_ORIENTATION_KEY,
|
||||
D3D9EXHOOK_CONFIG_GFX_DEFAULT_FORCE_ORIENTATION_VALUE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ struct d3d9exhook_config_gfx {
|
||||
int32_t window_height;
|
||||
int32_t forced_refresh_rate;
|
||||
int32_t device_adapter;
|
||||
int32_t force_orientation;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -87,6 +87,7 @@ static int32_t d3d9ex_window_width = -1;
|
||||
static int32_t d3d9ex_window_height = -1;
|
||||
static bool d3d9ex_window_framed;
|
||||
static int32_t d3d9ex_device_adapter = -1;
|
||||
static int32_t d3d9ex_force_orientation = -1;
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
@@ -195,6 +196,12 @@ static HRESULT STDCALL my_CreateDeviceEx(
|
||||
IDirect3D9Ex *real = COM_PROXY_UNWRAP(self);
|
||||
HRESULT hr;
|
||||
|
||||
|
||||
if (d3d9ex_device_adapter >= 0) {
|
||||
log_info("Forcing adapter %d -> %d", adapter, d3d9ex_device_adapter);
|
||||
adapter = d3d9ex_device_adapter;
|
||||
}
|
||||
|
||||
if (d3d9ex_windowed) {
|
||||
fdm = NULL;
|
||||
pp->Windowed = TRUE;
|
||||
@@ -210,11 +217,38 @@ static HRESULT STDCALL my_CreateDeviceEx(
|
||||
fdm->RefreshRate = pp->FullScreen_RefreshRateInHz;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (d3d9ex_device_adapter >= 0) {
|
||||
log_info("Forcing adapter %d -> %d", adapter, d3d9ex_device_adapter);
|
||||
adapter = d3d9ex_device_adapter;
|
||||
if (d3d9ex_force_orientation >= DMDO_DEFAULT && d3d9ex_force_orientation <= DMDO_270) {
|
||||
D3DADAPTER_IDENTIFIER9 adapter_ident;
|
||||
if (IDirect3D9Ex_GetAdapterIdentifier(real, adapter, 0, &adapter_ident) == D3D_OK) {
|
||||
// straight outta MSDN
|
||||
DEVMODE dm;
|
||||
// initialize the DEVMODE structure
|
||||
ZeroMemory(&dm, sizeof(dm));
|
||||
dm.dmSize = sizeof(dm);
|
||||
|
||||
if (0 != EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm))
|
||||
{
|
||||
int32_t delta = d3d9ex_force_orientation - dm.dmDisplayOrientation;
|
||||
if (delta % 2 != 0) {
|
||||
// swap height and width
|
||||
DWORD dwTemp = dm.dmPelsHeight;
|
||||
dm.dmPelsHeight= dm.dmPelsWidth;
|
||||
dm.dmPelsWidth = dwTemp;
|
||||
}
|
||||
|
||||
dm.dmDisplayOrientation = d3d9ex_force_orientation;
|
||||
|
||||
long lRet = ChangeDisplaySettings(&dm, CDS_FULLSCREEN);
|
||||
|
||||
if (lRet == DISP_CHANGE_SUCCESSFUL) {
|
||||
log_info("Overriding rotation suceeded");
|
||||
} else {
|
||||
log_info("Overriding rotation failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hr = IDirect3D9Ex_CreateDeviceEx(
|
||||
@@ -279,6 +313,7 @@ void d3d9ex_configure(struct d3d9exhook_config_gfx *gfx_config)
|
||||
|
||||
d3d9ex_force_refresh_rate = gfx_config->forced_refresh_rate;
|
||||
d3d9ex_device_adapter = gfx_config->device_adapter;
|
||||
d3d9ex_force_orientation = gfx_config->force_orientation;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
Reference in New Issue
Block a user