mirror of
https://github.com/libretro/RetroArch.git
synced 2024-11-23 16:09:47 +00:00
4b2f27eff8
Fixed SR close match refresh bug. Added menu high resolution option. Fixed desktop restore bug cuusing endless resolution change requests. Fixed file conflicts Added destop restore resolution back in for manu only. Pulled Switchres fixes. Added better PI rsolution support. Ver 0.7 SR2 (Switchres API) Implimantation Removed HH experimetal check. This is better done via teh switchres.ini at present. Fixed refresh rate bug. Now new resolution and refesh is added correctly. Removed SR deinit from menu restore. Meanu now stays at last content resolution. Ver 0.6.2 SR2 (Switchres API) Implimantation Fixed super resolution bug casuing abnormal video size and aspect ratio Fixed logging issue casuing seg falts on RA exit Ver 0.6 SR2 (Switchres API) Implimantation Ver 0.2 SR2 (Switchres API) Implimantation Added forced super resolutions. Added Multi-monitor/monitor selection support. Added desktop resolution restore when switching back to menu only. Added new menu items for 31KHz standard and 120hz monitor profiles. Added new menu item INI. load monitor profile from switchrss.ini. Fixed winraw driver. Coordinates new refreshed after a resolution change. Fixed Menu aspect ratio in super resolutions. Removed static glabals. These have been added to videocrt_switch struct. Ver 0.1 SR2 (Switchres API) Implimantation Removed old CRTSwitchRes method. Added new SR2 API implimantaion. Resolution swithcing is now done by switchres libs. Both Linux and Windows working with native and super resolutions. Working multi-monitor support with monitor index selection. Working 31KHz support with standard and 120Hxz modes. The monitor index selection is still done via the RA UI. Only choose native and 15KHz form the CRT options in the RA UI as all options are now set in the switchres.ini. All other CRT optoins in the RA UI currently do nothing. Added SR wrapper to fix compile issues. Added back RPi functionality Fixed windows resize/scaling issues on resolution change Thanks @Calamity no more need for crt_switch_driver_refresh() Fix broken case after prevous commit Monitor preset options 15/31KHz now active. Added new meu option. Moitor persets can now be choosen fom the RA UI. 15KHz and 31KHz will set arcade_15 and aracde_31 respectivly. New option INI, if this is chosen your monitor preset will be selected from your switchres.ini file. Added 3KHhz, 120Hz. for old RA users. Renamed 31KHz to 31 KHz, Standard Fixed winraw input coordinates after switching resolution. Code cleanup Fixed menu aspect ratio issue Added menu resolution restore after closing content Fixed aspect ratio after menu resolution restore. code clean up Fxed menu Resulition Restore Aspect Ratio. When SR uses non integer scalled resolution. super width bug with restoring menu resolution fix added super resolution check after setting desktop resolutoion variables when menu active only sr_deinit() used to restore desktop mode. Fixed menu sr_deinit bug. now setting sr_active false Removed static globals, added them to video_switch struct Fixex compile bug due to comment // Fixed compile issues doe to c++ comments in teh switchres_wrapper.h Temporarily removed SR2 logging to fix compile isses for c90 added logging back in. Removed support for winnt and osx Added define for C89. Disabled SR if defined C89 Removed all RA compile fixes fro C89 C90 etc. Swithing now working again. Put Switchres behind HAVE_SR2. HAVE_SR2=no by default. --enable-sr2 Ver 0.5 SR2 Implimentation. Ver 0.4 SR2 Implimantation. Bake SR inside RA Removed temporary log files Disable switchres when C89/C99 builds. Removed C89 and C90 checks for SR Fixed switchres_wrapper.h location Ver 0.3 SR2 Implimenation Dissable logging for C89 __STDC__ Fix For RPi fixed missing EOL fixed RPi function definition added vidrocrt_switch stuct to RPI funcion fixed xoffset for RPi Removed old RPi function call SR disabled for videocore until VC4 switching ported Reverted back to state 5c8a56c Bake SR inside RA Use native win32 api for threads. Fix static lib linking LIBERROR would be defined twice otherwise + improper function names prefixed by __imp_ Added lidstc++ to makefile.common for switchres Fixed RPi switching. Disabled Switchres for videocore unill it is ported. removed RAA.log. Should not exist Added check for when SR fails to set mode with an aspect ratio fix. added video driver re init for RPi GB, GBA and GBC core check, adjusted reseolutions and scale. Please turn on integer scalling in the RA UI Added logas back in. Checking STDC verstion >= C11 Fixed c89 for loop declaration. Code clean up. Added new functions Fix resolution switching bug introduces with HH code clean up. Fixed menu restore bug on closw content after code clean up Moved SR logging to relevant RA logs Update makefile. Checks for X11 and xrandr fixed makefile Use native win32 api for threads. Fix static lib linking LIBERROR would be defined twice otherwise + improper function names prefixed by __imp_ Update switchres_wrapper.* header comments Update year copyright DRMKMS: build only if libdrm has the required version XRANDR: build only if xrandr is available Simplified maklefile Fixed RPI compile error with unsued functions. As before Disable Griffin. No switching support available. Never has been Removed log file 1 Added Win32 static define Added SR source Removed Videocore check on destroy SR Moved SR deinit to trigger earlier on RA exit. Fixed compile error after upstream rebase Fixed aspect ration bug cused by super resolutions. Temporarily disbabled SR logging Re inabled runtim eSR loggind. Disableed all RARCH logging on retro_deinit_drivers Removed srdeinit from menu restore. Menu stays in current reolution until a fix can be found Fixed refresh rate changes when no reolution change is detected. Forgot to add teh resolution cahge in with the refresh change oops Fixed endless no detection log. Removed HH check. This can been better adjusted using the switchres.ini fixed compile issue Added better PI crt switching and fixed typo Pulled Swicthres fixes. Updated desktop restore resolution. removed unused makefile Lockec menu refresh to 60hz fixed missing new line Fixed file conflicts Forced 640x480@60 for menu Added high resolution menu option Removed item logg checker Fixed typos Removed unused functions Fixed SR close match refesh bug. Fixed typo
482 lines
13 KiB
C++
482 lines
13 KiB
C++
/**************************************************************
|
|
|
|
display.cpp - Display manager
|
|
|
|
---------------------------------------------------------
|
|
|
|
Switchres Modeline generation engine for emulation
|
|
|
|
License GPL-2.0+
|
|
Copyright 2010-2021 Chris Kennedy, Antonio Giner,
|
|
Alexandre Wodarczyk, Gil Delescluse
|
|
|
|
**************************************************************/
|
|
|
|
#include <stdio.h>
|
|
#include "display.h"
|
|
#if defined(_WIN32)
|
|
#include "display_windows.h"
|
|
#elif defined(__linux__)
|
|
#include <string.h>
|
|
#include "display_linux.h"
|
|
#endif
|
|
#include "log.h"
|
|
|
|
//============================================================
|
|
// display_manager::make
|
|
//============================================================
|
|
|
|
display_manager *display_manager::make(display_settings *ds)
|
|
{
|
|
display_manager *display = nullptr;
|
|
|
|
#if defined(_WIN32)
|
|
display = new windows_display(ds);
|
|
#elif defined(__linux__)
|
|
display = new linux_display(ds);
|
|
#endif
|
|
|
|
return display;
|
|
}
|
|
|
|
//============================================================
|
|
// display_manager::parse_options
|
|
//============================================================
|
|
|
|
void display_manager::parse_options()
|
|
{
|
|
// Get user_mode as <w>x<h>@<r>
|
|
set_user_mode(&m_ds.user_mode);
|
|
|
|
// Get user defined modeline (overrides user_mode)
|
|
modeline user_mode = {};
|
|
if (m_ds.modeline_generation)
|
|
{
|
|
if (modeline_parse(m_ds.user_modeline, &user_mode))
|
|
{
|
|
user_mode.type |= MODE_USER_DEF;
|
|
set_user_mode(&user_mode);
|
|
}
|
|
}
|
|
|
|
// Get monitor specs
|
|
if (user_mode.hactive)
|
|
{
|
|
modeline_to_monitor_range(range, &user_mode);
|
|
monitor_show_range(range);
|
|
}
|
|
else
|
|
{
|
|
char default_monitor[] = "generic_15";
|
|
|
|
memset(&range[0], 0, sizeof(struct monitor_range) * MAX_RANGES);
|
|
|
|
if (!strcmp(m_ds.monitor, "custom"))
|
|
for (int i = 0; i < MAX_RANGES; i++) monitor_fill_range(&range[i], m_ds.crt_range[i]);
|
|
|
|
else if (!strcmp(m_ds.monitor, "lcd"))
|
|
monitor_fill_lcd_range(&range[0], m_ds.lcd_range);
|
|
|
|
else if (monitor_set_preset(m_ds.monitor, range) == 0)
|
|
monitor_set_preset(default_monitor, range);
|
|
}
|
|
}
|
|
|
|
//============================================================
|
|
// display_manager::init
|
|
//============================================================
|
|
|
|
bool display_manager::init()
|
|
{
|
|
sprintf(m_ds.screen, "ram");
|
|
|
|
return true;
|
|
}
|
|
|
|
//============================================================
|
|
// display_manager::caps
|
|
//============================================================
|
|
|
|
int display_manager::caps()
|
|
{
|
|
if (video())
|
|
return video()->caps();
|
|
else
|
|
return CUSTOM_VIDEO_CAPS_ADD;
|
|
}
|
|
|
|
//============================================================
|
|
// display_manager::add_mode
|
|
//============================================================
|
|
|
|
bool display_manager::add_mode(modeline *mode)
|
|
{
|
|
if (video() == nullptr)
|
|
return false;
|
|
|
|
// Add new mode
|
|
if (!video()->add_mode(mode))
|
|
{
|
|
log_verbose("Switchres: error adding mode ");
|
|
log_mode(mode);
|
|
return false;
|
|
}
|
|
|
|
mode->type &= ~MODE_ADD;
|
|
|
|
log_verbose("Switchres: added ");
|
|
log_mode(mode);
|
|
|
|
return true;
|
|
}
|
|
|
|
//============================================================
|
|
// display_manager::delete_mode
|
|
//============================================================
|
|
|
|
bool display_manager::delete_mode(modeline *mode)
|
|
{
|
|
if (video() == nullptr)
|
|
return false;
|
|
|
|
if (!video()->delete_mode(mode))
|
|
{
|
|
log_verbose("Switchres: error deleting mode ");
|
|
log_mode(mode);
|
|
return false;
|
|
}
|
|
|
|
log_verbose("Switchres: deleted ");
|
|
log_mode(mode);
|
|
return true;
|
|
}
|
|
|
|
//============================================================
|
|
// display_manager::update_mode
|
|
//============================================================
|
|
|
|
bool display_manager::update_mode(modeline *mode)
|
|
{
|
|
if (video() == nullptr)
|
|
return false;
|
|
|
|
// Apply new timings
|
|
if (!video()->update_mode(mode))
|
|
{
|
|
log_verbose("Switchres: error updating mode ");
|
|
log_mode(mode);
|
|
return false;
|
|
}
|
|
|
|
mode->type &= ~MODE_UPDATE;
|
|
|
|
log_verbose("Switchres: updated ");
|
|
log_mode(mode);
|
|
return true;
|
|
}
|
|
|
|
//============================================================
|
|
// display_manager::set_mode
|
|
//============================================================
|
|
|
|
bool display_manager::set_mode(modeline *)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
//============================================================
|
|
// display_manager::log_mode
|
|
//============================================================
|
|
|
|
void display_manager::log_mode(modeline *mode)
|
|
{
|
|
char modeline_txt[256];
|
|
log_verbose("%s timing %s\n", video()->api_name(), modeline_print(mode, modeline_txt, MS_FULL));
|
|
}
|
|
|
|
//============================================================
|
|
// display_manager::restore_modes
|
|
//============================================================
|
|
|
|
bool display_manager::restore_modes()
|
|
{
|
|
// Compare each mode in our table with its original state
|
|
for (unsigned i = video_modes.size(); i-- > 0; )
|
|
{
|
|
// First, delete all modes we've added
|
|
if (i + 1 > backup_modes.size())
|
|
video_modes[i].type |= MODE_DELETE;
|
|
|
|
// Now restore all modes which timings have been modified
|
|
else if (modeline_is_different(&video_modes[i], &backup_modes[i]))
|
|
{
|
|
video_modes[i] = backup_modes[i];
|
|
video_modes[i].type |= MODE_UPDATE;
|
|
}
|
|
}
|
|
// Finally, flush pending changes to driver
|
|
return flush_modes();
|
|
}
|
|
|
|
//============================================================
|
|
// display_manager::flush_modes
|
|
//============================================================
|
|
|
|
bool display_manager::flush_modes()
|
|
{
|
|
bool error = false;
|
|
std::vector<modeline *> modified_modes = {};
|
|
|
|
if (video() == nullptr)
|
|
return false;
|
|
|
|
// Loop through our mode table to collect all pending changes
|
|
for (auto &mode : video_modes)
|
|
if (mode.type & (MODE_UPDATE | MODE_ADD | MODE_DELETE))
|
|
modified_modes.push_back(&mode);
|
|
|
|
// Flush pending changes to driver
|
|
if (modified_modes.size() > 0)
|
|
{
|
|
video()->process_modelist(modified_modes);
|
|
|
|
// Log error/success result for each mode
|
|
for (auto &mode : modified_modes)
|
|
{
|
|
log_verbose("Switchres: %s %s mode ", mode->type & MODE_ERROR? "error" : "success", mode->type & MODE_DELETE? "deleting" : mode->type & MODE_ADD? "adding" : "updating");
|
|
log_mode(mode);
|
|
|
|
if (mode->type & MODE_ERROR)
|
|
error = true;
|
|
}
|
|
|
|
// Update our internal mode table to reflect the changes
|
|
for (unsigned i = video_modes.size(); i-- > 0; )
|
|
{
|
|
if (video_modes[i].type & MODE_ERROR)
|
|
continue;
|
|
|
|
if (video_modes[i].type & MODE_DELETE)
|
|
{
|
|
video_modes.erase(video_modes.begin() + i);
|
|
m_best_mode = 0;
|
|
}
|
|
else
|
|
video_modes[i].type &= ~(MODE_UPDATE | MODE_ADD);
|
|
}
|
|
}
|
|
|
|
return !error;
|
|
}
|
|
|
|
//============================================================
|
|
// display_manager::filter_modes
|
|
//============================================================
|
|
|
|
bool display_manager::filter_modes()
|
|
{
|
|
for (auto &mode : video_modes)
|
|
{
|
|
// apply options to mode type
|
|
if (m_ds.refresh_dont_care)
|
|
mode.type |= V_FREQ_EDITABLE;
|
|
|
|
if ((caps() & CUSTOM_VIDEO_CAPS_UPDATE))
|
|
mode.type |= V_FREQ_EDITABLE;
|
|
|
|
if (caps() & CUSTOM_VIDEO_CAPS_SCAN_EDITABLE)
|
|
mode.type |= SCAN_EDITABLE;
|
|
|
|
if (!m_ds.modeline_generation)
|
|
mode.type &= ~(XYV_EDITABLE | SCAN_EDITABLE);
|
|
|
|
if ((mode.type & MODE_DESKTOP) && !(caps() & CUSTOM_VIDEO_CAPS_DESKTOP_EDITABLE))
|
|
mode.type &= ~V_FREQ_EDITABLE;
|
|
|
|
if (m_ds.lock_system_modes && (mode.type & CUSTOM_VIDEO_TIMING_SYSTEM))
|
|
mode.type |= MODE_DISABLED;
|
|
|
|
// Make sure to unlock the desktop mode as fallback
|
|
if (mode.type & MODE_DESKTOP)
|
|
mode.type &= ~MODE_DISABLED;
|
|
|
|
// Lock all modes that don't match the user's -resolution rules
|
|
if (m_user_mode.width != 0 || m_user_mode.height != 0 || m_user_mode.refresh == !0)
|
|
{
|
|
if (!( (mode.width == m_user_mode.width || (mode.type & X_RES_EDITABLE) || m_user_mode.width == 0)
|
|
&& (mode.height == m_user_mode.height || (mode.type & Y_RES_EDITABLE) || m_user_mode.height == 0)
|
|
&& (mode.refresh == m_user_mode.refresh || (mode.type & V_FREQ_EDITABLE) || m_user_mode.refresh == 0) ))
|
|
mode.type |= MODE_DISABLED;
|
|
else
|
|
mode.type &= ~MODE_DISABLED;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
//============================================================
|
|
// display_manager::get_video_mode
|
|
//============================================================
|
|
|
|
modeline *display_manager::get_mode(int width, int height, float refresh, bool interlaced)
|
|
{
|
|
modeline s_mode = {};
|
|
modeline t_mode = {};
|
|
modeline best_mode = {};
|
|
char result[256]={'\x00'};
|
|
|
|
log_verbose("Switchres: Calculating best video mode for %dx%d@%.6f%s orientation: %s\n",
|
|
width, height, refresh, interlaced?"i":"", rotation()?"rotated":"normal");
|
|
|
|
best_mode.result.weight |= R_OUT_OF_RANGE;
|
|
|
|
s_mode.interlace = interlaced;
|
|
s_mode.vfreq = refresh;
|
|
|
|
s_mode.hactive = normalize(width, 8);
|
|
s_mode.vactive = height;
|
|
|
|
if (rotation()) std::swap(s_mode.hactive, s_mode.vactive);
|
|
|
|
// Create a dummy mode entry if allowed
|
|
if (caps() & CUSTOM_VIDEO_CAPS_ADD && m_ds.modeline_generation)
|
|
{
|
|
modeline new_mode = {};
|
|
new_mode.type = XYV_EDITABLE | V_FREQ_EDITABLE | SCAN_EDITABLE | MODE_ADD | (desktop_is_rotated()? MODE_ROTATED : MODE_OK);
|
|
video_modes.push_back(new_mode);
|
|
}
|
|
|
|
// Run through our mode list and find the most suitable mode
|
|
for (auto &mode : video_modes)
|
|
{
|
|
log_verbose("\nSwitchres: %s%4d%sx%s%4d%s_%s%d=%.6fHz%s%s\n",
|
|
mode.type & X_RES_EDITABLE?"(":"[", mode.width, mode.type & X_RES_EDITABLE?")":"]",
|
|
mode.type & Y_RES_EDITABLE?"(":"[", mode.height, mode.type & Y_RES_EDITABLE?")":"]",
|
|
mode.type & V_FREQ_EDITABLE?"(":"[", mode.refresh, mode.vfreq, mode.type & V_FREQ_EDITABLE?")":"]",
|
|
mode.type & MODE_DISABLED?" - locked":"");
|
|
|
|
// now get the mode if allowed
|
|
if (!(mode.type & MODE_DISABLED))
|
|
{
|
|
for (int i = 0 ; i < MAX_RANGES ; i++)
|
|
{
|
|
if (range[i].hfreq_min)
|
|
{
|
|
t_mode = mode;
|
|
|
|
// init all editable fields with source or user values
|
|
if (t_mode.type & X_RES_EDITABLE)
|
|
t_mode.hactive = m_user_mode.width? m_user_mode.width : s_mode.hactive;
|
|
|
|
if (t_mode.type & Y_RES_EDITABLE)
|
|
t_mode.vactive = m_user_mode.height? m_user_mode.height : s_mode.vactive;
|
|
|
|
if (t_mode.type & V_FREQ_EDITABLE)
|
|
{
|
|
// If user's vfreq is defined, it means we have an user modeline, so force it
|
|
if (m_user_mode.vfreq)
|
|
t_mode = m_user_mode;
|
|
else
|
|
t_mode.vfreq = s_mode.vfreq;
|
|
}
|
|
|
|
// lock resolution fields if required
|
|
if (m_user_mode.width) t_mode.type &= ~X_RES_EDITABLE;
|
|
if (m_user_mode.height) t_mode.type &= ~Y_RES_EDITABLE;
|
|
if (m_user_mode.vfreq) t_mode.type &= ~V_FREQ_EDITABLE;
|
|
|
|
modeline_create(&s_mode, &t_mode, &range[i], &m_ds.gs);
|
|
t_mode.range = i;
|
|
|
|
log_verbose("%s\n", modeline_result(&t_mode, result));
|
|
|
|
if (modeline_compare(&t_mode, &best_mode))
|
|
{
|
|
best_mode = t_mode;
|
|
m_best_mode = &mode;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// If we didn't need to create a new mode, remove our dummy entry
|
|
if (caps() & CUSTOM_VIDEO_CAPS_ADD && m_ds.modeline_generation && m_best_mode != &video_modes.back())
|
|
video_modes.pop_back();
|
|
|
|
// If we didn't find a suitable mode, exit now
|
|
if (best_mode.result.weight & R_OUT_OF_RANGE)
|
|
{
|
|
m_best_mode = 0;
|
|
log_error("Switchres: could not find a video mode that meets your specs\n");
|
|
return nullptr;
|
|
}
|
|
|
|
log_verbose("\nSwitchres: %s (%dx%d@%.6f)->(%dx%d@%.6f)\n", rotation()?"rotated":"normal",
|
|
width, height, refresh, best_mode.hactive, best_mode.vactive, best_mode.vfreq);
|
|
|
|
log_verbose("%s\n", modeline_result(&best_mode, result));
|
|
|
|
// Copy the new modeline to our mode list
|
|
if (m_ds.modeline_generation)
|
|
{
|
|
if (best_mode.type & MODE_ADD)
|
|
{
|
|
best_mode.width = best_mode.hactive;
|
|
best_mode.height = best_mode.vactive;
|
|
best_mode.refresh = int(best_mode.vfreq);
|
|
// lock new mode
|
|
best_mode.type &= ~(X_RES_EDITABLE | Y_RES_EDITABLE | (caps() & CUSTOM_VIDEO_CAPS_UPDATE? 0 : V_FREQ_EDITABLE));
|
|
}
|
|
else if (modeline_is_different(&best_mode, m_best_mode) != 0)
|
|
best_mode.type |= MODE_UPDATE;
|
|
|
|
char modeline[256]={'\x00'};
|
|
log_info("Switchres: Modeline %s\n", modeline_print(&best_mode, modeline, MS_FULL));
|
|
}
|
|
|
|
// Check if new best mode is different than previous one
|
|
m_switching_required = (m_current_mode != m_best_mode || best_mode.type & MODE_UPDATE);
|
|
|
|
*m_best_mode = best_mode;
|
|
return m_best_mode;
|
|
}
|
|
|
|
//============================================================
|
|
// display_manager::auto_specs
|
|
//============================================================
|
|
|
|
bool display_manager::auto_specs()
|
|
{
|
|
// Make sure we have a valid mode
|
|
if (desktop_mode.width == 0 || desktop_mode.height == 0 || desktop_mode.refresh == 0)
|
|
{
|
|
log_error("Switchres: Invalid desktop mode %dx%d@%d\n", desktop_mode.width, desktop_mode.height, desktop_mode.refresh);
|
|
return false;
|
|
}
|
|
|
|
log_verbose("Switchres: Creating automatic specs for LCD based on %s\n", (desktop_mode.type & CUSTOM_VIDEO_TIMING_SYSTEM)? "VESA GTF" : "current timings");
|
|
|
|
// Make sure our current refresh is within range if set to auto
|
|
if (!strcmp(m_ds.lcd_range, "auto"))
|
|
{
|
|
sprintf(m_ds.lcd_range, "%d-%d", desktop_mode.refresh - 1, desktop_mode.refresh + 1);
|
|
monitor_fill_lcd_range(range, m_ds.lcd_range);
|
|
}
|
|
|
|
// Create a working range with the best possible information
|
|
if (desktop_mode.type & CUSTOM_VIDEO_TIMING_SYSTEM) modeline_vesa_gtf(&desktop_mode);
|
|
modeline_to_monitor_range(range, &desktop_mode);
|
|
monitor_show_range(range);
|
|
|
|
// Force our resolution to LCD's native one
|
|
modeline user_mode = {};
|
|
user_mode.width = desktop_mode.width;
|
|
user_mode.height = desktop_mode.height;
|
|
user_mode.refresh = desktop_mode.refresh;
|
|
set_user_mode(&user_mode);
|
|
|
|
return true;
|
|
}
|