Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PCSX2: Scaling Types / 16:9 FMV aspect ratio switch #1918

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion common/include/PS2Edefs.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2010 PCSX2 Dev Team
* Copyright (C) 2002-2018 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
Expand Down Expand Up @@ -280,6 +280,7 @@ void CALLBACK GSreset();
//deprecated: GSgetTitleInfo was used in PCSX2 but no plugin supported it prior to r4070:
//void CALLBACK GSgetTitleInfo( char dest[128] );
void CALLBACK GSgetTitleInfo2(char *dest, size_t length);
void CALLBACK GSgetImageSize(int *frame_w, int *frame_h);
void CALLBACK GSwriteCSR(u32 value);
s32 CALLBACK GSfreeze(int mode, freezeData *data);
void CALLBACK GSconfigure();
Expand Down Expand Up @@ -585,6 +586,7 @@ typedef void(CALLBACK *_GSinitReadFIFO2)(u64 *pMem, int qwc);

typedef void(CALLBACK *_GSchangeSaveState)(int, const char *filename);
typedef void(CALLBACK *_GSgetTitleInfo2)(char *dest, size_t length);
typedef void(CALLBACK *_GSgetImageSize)(int *frame_w, int *frame_h);
typedef void(CALLBACK *_GSirqCallback)(void (*callback)());
typedef void(CALLBACK *_GSsetBaseMem)(void *);
typedef void(CALLBACK *_GSsetGameCRC)(int, int);
Expand Down Expand Up @@ -744,6 +746,7 @@ extern _GSinitReadFIFO2 GSinitReadFIFO2;

extern _GSchangeSaveState GSchangeSaveState;
extern _GSgetTitleInfo2 GSgetTitleInfo2;
extern _GSgetImageSize GSgetImageSize;
extern _GSmakeSnapshot GSmakeSnapshot;
extern _GSmakeSnapshot2 GSmakeSnapshot2;
extern _GSirqCallback GSirqCallback;
Expand Down
2 changes: 1 addition & 1 deletion pcsx2/IPU/IPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ static __ri void ipuBDEC(tIPU_CMD_BDEC bdec)

static __fi bool ipuVDEC(u32 val)
{
if (EmuConfig.Gamefixes.FMVinSoftwareHack || g_Conf->GSWindow.IsToggleAspectRatioSwitch) {
if (EmuConfig.Gamefixes.FMVinSoftwareHack || g_Conf->GSWindow.FMVAspectRatioSwitch != FMV_AspectRatio_Switch_Off) {
static int count = 0;
if (count++ > 5) {
if (!FMVstarted) {
Expand Down
4 changes: 3 additions & 1 deletion pcsx2/PluginManager.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2010 PCSX2 Dev Team
* Copyright (C) 2002-2018 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
Expand Down Expand Up @@ -171,6 +171,7 @@ _GSinitReadFIFO GSinitReadFIFO;
_GSinitReadFIFO2 GSinitReadFIFO2;
_GSchangeSaveState GSchangeSaveState;
_GSgetTitleInfo2 GSgetTitleInfo2;
_GSgetImageSize GSgetImageSize;
_GSmakeSnapshot GSmakeSnapshot;

This comment was marked as spam.

_GSmakeSnapshot2 GSmakeSnapshot2;
_GSirqCallback GSirqCallback;
Expand Down Expand Up @@ -423,6 +424,7 @@ static const LegacyApi_OptMethod s_MethMessOpt_GS[] =
{ "GSinitReadFIFO", (vMeth**)&GSinitReadFIFO },
{ "GSinitReadFIFO2", (vMeth**)&GSinitReadFIFO2 },
{ "GSgifTransfer1", (vMeth**)&GSgifTransfer1 },
{ "GSgetImageSize", (vMeth**)&GSgetImageSize },
{ NULL }
};

Expand Down
35 changes: 31 additions & 4 deletions pcsx2/gui/AppConfig.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2010 PCSX2 Dev Team
* Copyright (C) 2002-2018 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
Expand Down Expand Up @@ -835,14 +835,17 @@ AppConfig::GSWindowOptions::GSWindowOptions()
CloseOnEsc = true;
DefaultToFullscreen = false;
AlwaysHideMouse = false;
DisableScalingCompensation = false;
DisableResizeBorders = false;
DisableScreenSaver = true;

AspectRatio = AspectRatio_4_3;
FMVAspectRatioSwitch = FMV_AspectRatio_Switch_Off;
Zoom = 100;
StretchY = 100;
OffsetX = 0;
OffsetY = 0;
ScalingType = ScalingType_Fit;

WindowSize = wxSize( 640, 480 );
WindowPos = wxDefaultPosition;
Expand All @@ -851,7 +854,6 @@ AppConfig::GSWindowOptions::GSWindowOptions()
EnableVsyncWindowFlag = false;

IsToggleFullscreenOnDoubleClick = true;
IsToggleAspectRatioSwitch = false;
}

void AppConfig::GSWindowOptions::SanityCheck()
Expand Down Expand Up @@ -880,6 +882,7 @@ void AppConfig::GSWindowOptions::LoadSave( IniInterface& ini )
IniEntry( CloseOnEsc );
IniEntry( DefaultToFullscreen );
IniEntry( AlwaysHideMouse );
IniEntry( DisableScalingCompensation );
IniEntry( DisableResizeBorders );
IniEntry( DisableScreenSaver );

Expand All @@ -890,19 +893,43 @@ void AppConfig::GSWindowOptions::LoadSave( IniInterface& ini )
IniEntry( EnableVsyncWindowFlag );

IniEntry( IsToggleFullscreenOnDoubleClick );
IniEntry( IsToggleAspectRatioSwitch );

static const wxChar* AspectRatioNames[] =
{
L"Stretch",
L"4:3",
L"16:9",
L"Frame",
// WARNING: array must be NULL terminated to compute it size
NULL
};

ini.EnumEntry( L"AspectRatio", AspectRatio, AspectRatioNames, AspectRatio );
IniEntry( Zoom );

static const wxChar* ScalingTypeNames[] =
{
L"Fill",
L"Fit",
L"Integer",
L"Centered",
// WARNING: array must be NULL terminated to compute its size
NULL
};

ini.EnumEntry(L"ScalingType", ScalingType, ScalingTypeNames, ScalingType);

static const wxChar* FMVAspectRatioSwitchNames[] =
{
L"Off",
L"4:3",
L"16:9",
// WARNING: array must be NULL terminated to compute it size
NULL
};

ini.EnumEntry(L"FMVAspectRatioSwitch", FMVAspectRatioSwitch, FMVAspectRatioSwitchNames, FMVAspectRatioSwitch);

IniEntry(Zoom);

if( ini.IsLoading() ) SanityCheck();
}
Expand Down
25 changes: 22 additions & 3 deletions pcsx2/gui/AppConfig.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2010 PCSX2 Dev Team
* Copyright (C) 2002-2018 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
Expand Down Expand Up @@ -96,9 +96,26 @@ enum AspectRatioType
AspectRatio_Stretch,
AspectRatio_4_3,
AspectRatio_16_9,
AspectRatio_Frame,
AspectRatio_MaxCount
};

enum ScalingTypes
{
ScalingType_Fit,
ScalingType_Integer,
ScalingType_Centered,
ScalingType_MaxCount
};

enum FMVAspectRatioSwitchType
{
FMV_AspectRatio_Switch_4_3,
FMV_AspectRatio_Switch_16_9,
FMV_AspectRatio_Switch_Off,
FMV_AspectRatio_Switch_MaxCount
};

enum MemoryCardType
{
MemoryCard_None,
Expand Down Expand Up @@ -201,18 +218,21 @@ class AppConfig
{
// Closes the GS/Video port on escape (good for fullscreen activity)
bool CloseOnEsc;

bool DefaultToFullscreen;
bool AlwaysHideMouse;
bool DisableScalingCompensation;
bool DisableResizeBorders;
bool DisableScreenSaver;

AspectRatioType AspectRatio;
FMVAspectRatioSwitchType FMVAspectRatioSwitch;
Fixed100 Zoom;
Fixed100 StretchY;
Fixed100 OffsetX;
Fixed100 OffsetY;

ScalingTypes ScalingType;

wxSize WindowSize;
wxPoint WindowPos;
Expand All @@ -221,7 +241,6 @@ class AppConfig
bool EnableVsyncWindowFlag;

bool IsToggleFullscreenOnDoubleClick;
bool IsToggleAspectRatioSwitch;

GSWindowOptions();

Expand Down
6 changes: 3 additions & 3 deletions pcsx2/gui/AppMain.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2010 PCSX2 Dev Team
* Copyright (C) 2002-2018 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
Expand Down Expand Up @@ -517,7 +517,7 @@ extern bool EnableFMV;

void DoFmvSwitch(bool on)
{
if (g_Conf->GSWindow.IsToggleAspectRatioSwitch) {
if (g_Conf->GSWindow.FMVAspectRatioSwitch != FMV_AspectRatio_Switch_Off) {
if (on) {
switchAR = true;
iniAR = g_Conf->GSWindow.AspectRatio;
Expand Down Expand Up @@ -546,7 +546,7 @@ void Pcsx2App::LogicalVsync()

FpsManager.DoFrame();

if (EmuConfig.Gamefixes.FMVinSoftwareHack || g_Conf->GSWindow.IsToggleAspectRatioSwitch) {
if (EmuConfig.Gamefixes.FMVinSoftwareHack || g_Conf->GSWindow.FMVAspectRatioSwitch != FMV_AspectRatio_Switch_Off) {
if (EnableFMV) {
DevCon.Warning("FMV on");
DoFmvSwitch(true);
Expand Down
77 changes: 62 additions & 15 deletions pcsx2/gui/FrameForGS.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2010 PCSX2 Dev Team
* Copyright (C) 2002-2018 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
Expand Down Expand Up @@ -29,6 +29,9 @@
#include <sstream>
#include <iomanip>

static int s_image_width;
static int s_image_height;

static const KeyAcceleratorCode FULLSCREEN_TOGGLE_ACCELERATOR_GSPANEL=KeyAcceleratorCode( WXK_RETURN ).Alt();

//#define GSWindowScaleDebug
Expand Down Expand Up @@ -56,6 +59,7 @@ void GSPanel::InitDefaultAccelerators()
m_Accels->Map( AAC( WXK_TAB ).Shift(), "Framelimiter_SlomoToggle" );

m_Accels->Map( AAC( WXK_F6 ), "GSwindow_CycleAspectRatio" );
m_Accels->Map( AAC( WXK_F6 ).Shift(), "GSwindow_CycleScalingType" );

m_Accels->Map( AAC( WXK_NUMPAD_ADD ).Cmd(), "GSwindow_ZoomIn" ); //CTRL on Windows/linux, CMD on OSX
m_Accels->Map( AAC( WXK_NUMPAD_SUBTRACT ).Cmd(), "GSwindow_ZoomOut" );
Expand Down Expand Up @@ -162,37 +166,52 @@ void GSPanel::DoResize()
extern AspectRatioType iniAR;
extern bool switchAR;
double targetAr = clientAr;
bool acceptedImageSize = s_image_width > 0 && s_image_width <= client.GetWidth() && s_image_height > 0 && s_image_height <= client.GetHeight();
AspectRatioType Aspect_Ratio = g_Conf->GSWindow.AspectRatio;

if (g_Conf->GSWindow.AspectRatio != iniAR) {
switchAR = false;
}

if (!switchAR) {
if (g_Conf->GSWindow.AspectRatio == AspectRatio_4_3)
if (!switchAR && Aspect_Ratio != AspectRatio_Stretch) {
if (Aspect_Ratio == AspectRatio_4_3)
targetAr = 4.0 / 3.0;
else if (g_Conf->GSWindow.AspectRatio == AspectRatio_16_9)
else if (Aspect_Ratio == AspectRatio_16_9)
targetAr = 16.0 / 9.0;
else if (Aspect_Ratio == AspectRatio_Frame)
targetAr = acceptedImageSize ? (double)s_image_width / s_image_height : 4.0 / 3.0;
} else if (switchAR) {
if (g_Conf->GSWindow.FMVAspectRatioSwitch == FMV_AspectRatio_Switch_16_9 && Aspect_Ratio != AspectRatio_4_3) {
targetAr = 16.0 / 9.0;
} else {
targetAr = 4.0 / 3.0;
} else {
targetAr = 4.0 / 3.0;
}
}

double arr = targetAr / clientAr;

if( arr < 1 )
if (arr < 1)
viewport.x = (int)( (double)viewport.x*arr + 0.5);
else if( arr > 1 )
else if (arr > 1)
viewport.y = (int)( (double)viewport.y/arr + 0.5);

if (Aspect_Ratio != AspectRatio_Stretch && g_Conf->GSWindow.ScalingType != ScalingType_Fit && acceptedImageSize) {
int image_width_AR = s_image_height * targetAr;
int scaling = g_Conf->GSWindow.ScalingType == ScalingType_Integer ? std::min(client.GetWidth() / image_width_AR, client.GetHeight() / s_image_height) : 1;
viewport.x = image_width_AR * scaling;
viewport.y = s_image_height * scaling;
}

float zoom = g_Conf->GSWindow.Zoom.ToFloat()/100.0;
if( zoom == 0 )//auto zoom in untill black-bars are gone (while keeping the aspect ratio).
if (zoom == 0) // auto zoom in untill black-bars are gone (while keeping the aspect ratio).
zoom = std::max( (float)arr, (float)(1.0/arr) );

viewport.Scale(zoom, zoom*g_Conf->GSWindow.StretchY.ToFloat()/100.0 );
if (viewport == client && EmuConfig.Gamefixes.FMVinSoftwareHack && g_Conf->GSWindow.IsFullscreen)
viewport.x += 1; //avoids crash on some systems switching HW><SW in fullscreen aspect ratio's with FMV Software switch.
SetSize( viewport );
SetSize(viewport);
CenterOnParent();

int cx, cy;
GetPosition(&cx, &cy);
float unit = .01*(float)std::min(viewport.x, viewport.y);
Expand Down Expand Up @@ -585,7 +604,6 @@ GSPanel* GSFrame::GetViewport()
return (GSPanel*)FindWindowById( m_id_gspanel );
}


void GSFrame::OnUpdateTitle( wxTimerEvent& evt )
{
// Update the title only after the completion of at least a single Vsync, it's pointless to display the fps
Expand Down Expand Up @@ -623,6 +641,36 @@ void GSFrame::OnUpdateTitle( wxTimerEvent& evt )
out << std::fixed << std::setprecision(2) << fps;
OSDmonitor(Color_StrongGreen, "FPS:", out.str());

const u64 &smode2 = *(u64 *)PS2GS_BASE(GS_SMODE2);
int interlacing = smode2 & 1; // INT: 0 = Progressive, 1 = Interlaced
int interlacing_mode = smode2 & 2; // FFMD: 0 = Field mode, 2 = Frame mode

AspectRatioType Aspect_Ratio = g_Conf->GSWindow.AspectRatio;

bool supported_GSWindow_Settings = (Aspect_Ratio == AspectRatio_Frame || (Aspect_Ratio != AspectRatio_Stretch &&
g_Conf->GSWindow.ScalingType != ScalingType_Fit));

if ( GSgetImageSize != nullptr && supported_GSWindow_Settings )
{
bool framemode_compensation = !g_Conf->GSWindow.DisableScalingCompensation && interlacing == 1 && interlacing_mode == 2;

int new_width = 0, new_height = 0;
GSgetImageSize(&new_width, &new_height);
if ( framemode_compensation && new_height > 1 )

This comment was marked as spam.

new_height *=2;

if ( new_width > 1 && new_height > 1 && (s_image_width != new_width || s_image_height != new_height) )
{
if ( GSPanel* gsPanel = GetViewport() )
{
s_image_width = new_width;
s_image_height = new_height;

gsPanel->DoResize();
}
}
}

#ifdef __linux__
// Important Linux note: When the title is set in fullscreen the window is redrawn. Unfortunately
// an intermediate white screen appears too which leads to a very annoying flickering.
Expand All @@ -649,9 +697,8 @@ void GSFrame::OnUpdateTitle( wxTimerEvent& evt )
}
}

const u64& smode2 = *(u64*)PS2GS_BASE(GS_SMODE2);
wxString omodef = (smode2 & 2) ? templates.OutputFrame : templates.OutputField;
wxString omodei = (smode2 & 1) ? templates.OutputInterlaced : templates.OutputProgressive;
wxString omodef = interlacing_mode == 2 ? templates.OutputFrame : templates.OutputField;
wxString omodei = interlacing == 1 ? templates.OutputInterlaced : templates.OutputProgressive;

wxString title = templates.TitleTemplate;
title.Replace(L"${slot}", pxsFmt(L"%d", States_GetCurrentSlot()));
Expand Down
3 changes: 1 addition & 2 deletions pcsx2/gui/GSFrame.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2010 PCSX2 Dev Team
* Copyright (C) 2002-2018 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
Expand Down
Loading