Merge pull request #12588 from alphanu1/master

Fixed some Monitor index bugs ad updated to the latest SR2
This commit is contained in:
Autechre 2021-07-12 16:49:44 +02:00 committed by GitHub
commit 3bc06b0d57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 97 additions and 39 deletions

View File

@ -16,6 +16,11 @@
#include "display_windows.h"
#include "log.h"
typedef struct ENUM_INFO
{
int index;
HMONITOR h_monitor;
} ENUM_INFO;
//============================================================
// windows_display::windows_display
@ -41,8 +46,54 @@ windows_display::~windows_display()
// windows_display::init
//============================================================
int CALLBACK monitor_by_index(HMONITOR h_monitor, HDC, LPRECT, LPARAM data)
{
ENUM_INFO *mon_info = (ENUM_INFO*) data;
if (--mon_info->index < 0)
{
mon_info->h_monitor = h_monitor;
return false;
}
return true;
}
bool windows_display::init()
{
char display[32] = {};
// If monitor is passed by index, find the matching device
if (strlen(m_ds.screen) == 1)
{
int monitor_index = m_ds.screen[0] - '0';
if (monitor_index < 0 || monitor_index > 9)
{
log_error("Switchres: bad monitor index %d\n", monitor_index);
return false;
}
ENUM_INFO mon_info;
mon_info.index = monitor_index;
mon_info.h_monitor = NULL;
EnumDisplayMonitors(NULL, NULL, monitor_by_index, (LPARAM)&mon_info);
if (mon_info.h_monitor != NULL)
{
MONITORINFOEXA info = {};
info.cbSize = sizeof(info);
GetMonitorInfoA(mon_info.h_monitor, &info);
snprintf(display, sizeof(display) -1, "%s", info.szDevice);
log_info("display %s\n", display);
}
else
{
log_error("Swichres: couldn't find handle for monitor index %d\n", monitor_index);
return false;
}
}
else
strncpy(display, m_ds.screen, sizeof(display)-1);
// Find the display by device name, or "auto" for primary display
DISPLAY_DEVICEA lpDisplayDevice[DISPLAY_MAX];
int idev = 0;
int found = -1;
@ -55,8 +106,8 @@ bool windows_display::init()
if (EnumDisplayDevicesA(NULL, idev, &lpDisplayDevice[idev], 0) == FALSE)
break;
if ((!strcmp(m_ds.screen, "auto") && (lpDisplayDevice[idev].StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE))
|| !strcmp(m_ds.screen, lpDisplayDevice[idev].DeviceName) || m_ds.screen[0] - '0' == idev)
if ((!strcmp(display, "auto") && (lpDisplayDevice[idev].StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE))
|| !strcmp(display, lpDisplayDevice[idev].DeviceName))
found = idev;
idev++;

View File

@ -14,8 +14,8 @@
#include "log.h"
enum log_verbosity { NONE, ERROR, INFO, DBG };
static log_verbosity log_level = INFO;
enum log_verbosity { NONE, SR_ERROR, SR_INFO, SR_DEBUG };
static log_verbosity log_level = SR_INFO;
void log_dummy(const char *, ...) {}
@ -36,21 +36,21 @@ LOG_ERROR log_error_bak = &log_dummy;
void set_log_verbose(void *func_ptr)
{
if (log_level >= DBG)
if (log_level >= SR_DEBUG)
log_verbose = (LOG_VERBOSE)func_ptr;
log_verbose_bak = (LOG_VERBOSE)func_ptr;
}
void set_log_info(void *func_ptr)
{
if (log_level >= INFO)
if (log_level >= SR_INFO)
log_info = (LOG_INFO)func_ptr;
log_info_bak = (LOG_INFO)func_ptr;
}
void set_log_error(void *func_ptr)
{
if (log_level >= ERROR)
if (log_level >= SR_ERROR)
log_error = (LOG_ERROR)func_ptr;
log_error_bak = (LOG_ERROR)func_ptr;
}
@ -60,19 +60,19 @@ void set_log_verbosity(int level)
// Keep the log in the enum bounds
if (level < NONE)
level = NONE;
if(level > DBG)
level = DBG;
if(level > SR_DEBUG)
level = SR_DEBUG;
log_error = &log_dummy;
log_info = &log_dummy;
log_verbose = &log_dummy;
if (level >= ERROR)
if (level >= SR_ERROR)
log_error = log_error_bak;
if (level >= INFO)
if (level >= SR_INFO)
log_info = log_info_bak;
if (level >= DBG)
if (level >= SR_DEBUG)
log_verbose = log_verbose_bak;
}

View File

@ -23,8 +23,10 @@ const string WHITESPACE = " \n\r\t\f\v";
#if defined(_WIN32)
#define SR_CONFIG_PATHS ";.\\;.\\ini\\;"
#else
#elif defined(__linux__)
#define SR_CONFIG_PATHS ";./;./ini/;/etc/;"
#else
#define SR_CONFIG_PATHS ";./"
#endif
//============================================================

View File

@ -87,36 +87,45 @@ static void crt_aspect_ratio_switch(
videocrt_switch_t *p_switch,
unsigned width, unsigned height, unsigned srm_width, unsigned srm_height)
{
/* send aspect float to video_driver */
RARCH_LOG("[CRT]: Setting Video Screen Size to: %dx%d \n", width, height);
video_driver_set_size(srm_width , srm_height);
video_driver_set_viewport(srm_width , srm_height,1,1);
p_switch->fly_aspect = (float)width / (float)height;
video_driver_set_aspect_ratio_value((float)p_switch->fly_aspect);
RARCH_LOG("[CRT]: Setting Aspect Ratio: %f \n", (float)p_switch->fly_aspect);
RARCH_LOG("[CRT]: Setting Video Screen Size to: %dx%d \n", width, height);
video_driver_set_size(width , height);
video_driver_set_viewport(width , height,1,1);
video_driver_apply_state_changes();
}
static void set_aspect(videocrt_switch_t *p_switch, unsigned int width,
unsigned int height, unsigned int srm_width, unsigned srm_height,
unsigned int srm_xscale, unsigned srm_yscale)
unsigned int srm_xscale, unsigned srm_yscale, bool srm_isstretched )
{
unsigned int patched_width = 0;
unsigned int patched_height = 0;
int scaled_width = 0;
int scaled_height = 0;
/* used to fix aspect shoule SR not find a resolution */
/* used to fix aspect should SR not find a resolution */
if (srm_width == 0)
{
video_driver_get_size(&patched_width, &patched_height);
srm_xscale = 1;
srm_yscale = 1;
}else{
/* use native values as we will be multiplying by srm scale later. */
patched_width = width;
patched_height = height;
}
if (srm_isstretched && srm_width > 0)
{
srm_xscale = srm_width/width;
srm_yscale = srm_height/height;
}
scaled_width = roundf(patched_width*srm_xscale);
scaled_height = roundf(patched_height*srm_yscale);
@ -127,22 +136,19 @@ static bool crt_sr2_init(videocrt_switch_t *p_switch, int monitor_index, unsigne
{
const char* err_msg;
char* mode;
char index = 0;
char mindex[1];
char index[10];
if (monitor_index+1 >= 0 && monitor_index+1 < 10)
index = monitor_index+48;
sprintf(index, "%d", monitor_index);
else
index = '0';
mindex[0] = index;
sprintf(index, "%s", "0");
if (!p_switch->sr2_active)
{
RARCH_LOG("[CRT]: SR init \n");
sr_init();
#if (__STDC_VERSION__ >= 199409L) /* no logs for C98 or less */
sr_set_log_callback_info(RARCH_LOG);
@ -167,23 +173,22 @@ static bool crt_sr2_init(videocrt_switch_t *p_switch, int monitor_index, unsigne
RARCH_LOG("[CRT]: CRT Mode: %d - Selected from ini \n", crt_mode) ;
}
if (super_width >2 )
sr_set_user_mode(super_width, 0, 0);
RARCH_LOG("[CRT]: SR init_disp \n");
if (monitor_index+1 > 0)
{
RARCH_LOG("SRobj: RA Monitor Index: %s\n",mindex);
p_switch->rtn = sr_init_disp(mindex);
RARCH_LOG("[CRT]: SR Disp Monitor Index: %s \n", mindex);
RARCH_LOG("[CRT]: RA Monitor Index Manual: %s\n", &index[0]);
p_switch->rtn = sr_init_disp(index);
RARCH_LOG("[CRT]: SR Disp Monitor Index Manual: %s \n", &index[0]);
}
if (monitor_index == -1)
{
RARCH_LOG("SRobj: RA Monitor Index: %s\n",NULL);
p_switch->rtn = sr_init_disp(NULL);
RARCH_LOG("[CRT]: SR Disp Monitor Index: Auto \n");
RARCH_LOG("[CRT]: RA Monitor Index Auto: %s\n","auto");
p_switch->rtn = sr_init_disp("auto");
RARCH_LOG("[CRT]: SR Disp Monitor Index Auto: Auto \n");
}
RARCH_LOG("[CRT]: SR rtn %d \n", p_switch->rtn);
@ -247,12 +252,12 @@ static void switch_res_crt(
}
p_switch->sr_core_hz = srm.refresh;
set_aspect(p_switch, w , h, srm.width, srm.height, srm.x_scale, srm.y_scale);
set_aspect(p_switch, w , h, srm.width, srm.height, srm.x_scale, srm.y_scale, srm.is_stretched);
RARCH_LOG("[CRT]: SR scaled X:%d Y:%d \n",srm.x_scale, srm.y_scale);
}else {
set_aspect(p_switch, width , height, width, height ,1,1);
set_aspect(p_switch, width , height, width, height ,1,1, false);
video_driver_set_size(width , height);
video_driver_apply_state_changes();
@ -305,7 +310,7 @@ static void crt_fix_hh_res(videocrt_switch_t *p_switch, int native_width, int wi
int corrected_height = 240;
switch_res_crt(p_switch, corrected_width, corrected_height , crt_mode, corrected_width, monitor_index-1, super_width);
set_aspect(p_switch, native_width , height, native_width, height ,1,1);
set_aspect(p_switch, native_width , height, native_width, height ,1,1, false);
video_driver_set_size(native_width , height);
@ -484,7 +489,7 @@ static void crt_rpi_switch(videocrt_switch_t *p_switch, int width, int height, f
set_aspect(p_switch, width,
height, width, height,
1, 1);
1, 1, false);
int w = width;
while (w < 1920)
{