Move fullscreen display resolution control to the GUI with the rest of the fullscreen toggling code. This removes redundancy of code that was in several places through the various video plugins. Unfortunately it means the fullscreen resolution setting also had to be moved to the main configuration dialog. I am sure that will meet some resistance.

Also added a window size setting for windowed mode.

Also pulled some X11 specific code out into a separate file.


git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5395 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Glenn Rice
2010-04-22 04:28:34 +00:00
parent 8eb21d1bac
commit 140332c02e
30 changed files with 634 additions and 556 deletions

View File

@ -122,49 +122,8 @@ THREAD_RETURN XEventThread(void *pArg);
void CreateXWindow (void)
{
#if defined(HAVE_XRANDR) && HAVE_XRANDR
// Get the resolution setings for fullscreen mode
int fullWidth, fullHeight;
sscanf(g_Config.cFSResolution, "%dx%d", &fullWidth, &fullHeight);
int vidModeMajorVersion, vidModeMinorVersion;
XRRScreenSize *sizes;
int numSizes;
XRRQueryVersion(GLWin.dpy, &vidModeMajorVersion, &vidModeMinorVersion);
NOTICE_LOG(VIDEO, "XRRExtension-Version %d.%d", vidModeMajorVersion, vidModeMinorVersion);
GLWin.screenConfig = XRRGetScreenInfo(GLWin.dpy, GLWin.parent);
/* save desktop resolution */
GLWin.deskSize = XRRConfigCurrentConfiguration(GLWin.screenConfig, &GLWin.screenRotation);
/* Set the desktop resolution as the default */
GLWin.fullSize = GLWin.deskSize;
/* Find the index of the fullscreen resolution from config */
sizes = XRRConfigSizes(GLWin.screenConfig, &numSizes);
if (numSizes > 0 && sizes != NULL) {
for (int i = 0; i < numSizes; i++) {
if ((sizes[i].width == fullWidth) && (sizes[i].height == fullHeight)) {
GLWin.fullSize = i;
}
}
NOTICE_LOG(VIDEO, "Fullscreen Resolution %dx%d", sizes[GLWin.fullSize].width, sizes[GLWin.fullSize].height);
}
else {
ERROR_LOG(VIDEO, "Failed to obtain fullscreen sizes.\n"
"Using current desktop resolution for fullscreen.\n");
}
#endif
Atom wmProtocols[1];
g_VideoInitialize.pRequestWindowSize(GLWin.x, GLWin.y, (int&)GLWin.width, (int&)GLWin.height);
// Control window size and picture scaling
s_backbuffer_width = GLWin.width;
s_backbuffer_height = GLWin.height;
// Setup window attributes
GLWin.attr.colormap = XCreateColormap(GLWin.dpy,
GLWin.parent, GLWin.vi->visual, AllocNone);
@ -188,33 +147,15 @@ void CreateXWindow (void)
GLWin.xEventThread = new Common::Thread(XEventThread, NULL);
}
void ToggleDisplayMode (bool bFullscreen)
{
#if defined(HAVE_XRANDR) && HAVE_XRANDR
if (bFullscreen)
XRRSetScreenConfig(GLWin.dpy, GLWin.screenConfig, GLWin.parent,
GLWin.fullSize, GLWin.screenRotation, CurrentTime);
else
XRRSetScreenConfig(GLWin.dpy, GLWin.screenConfig, GLWin.parent,
GLWin.deskSize, GLWin.screenRotation, CurrentTime);
#endif
}
void DestroyXWindow(void)
{
/* switch back to original desktop resolution if we were in fullscreen */
#if defined(HAVE_XRANDR) && HAVE_XRANDR
ToggleDisplayMode(False);
#endif
XUnmapWindow(GLWin.dpy, GLWin.win);
GLWin.win = 0;
XFreeColormap(GLWin.dpy, GLWin.attr.colormap);
if (GLWin.xEventThread)
GLWin.xEventThread->WaitForDeath();
GLWin.xEventThread = NULL;
#if defined(HAVE_XRANDR) && HAVE_XRANDR
XRRFreeScreenConfigInfo(GLWin.screenConfig);
#endif
}
THREAD_RETURN XEventThread(void *pArg)
@ -285,8 +226,6 @@ THREAD_RETURN XEventThread(void *pArg)
case ClientMessage:
if ((ulong) event.xclient.data.l[0] == XInternAtom(GLWin.dpy, "WM_DELETE_WINDOW", False))
g_VideoInitialize.pCoreMessage(WM_USER_STOP);
if ((ulong) event.xclient.data.l[0] == XInternAtom(GLWin.dpy, "TOGGLE_DISPLAYMODE", False))
ToggleDisplayMode(event.xclient.data.l[1]);
if ((ulong) event.xclient.data.l[0] == XInternAtom(GLWin.dpy, "RESIZE", False))
XMoveResizeWindow(GLWin.dpy, GLWin.win, event.xclient.data.l[1],
event.xclient.data.l[2], event.xclient.data.l[3], event.xclient.data.l[4]);
@ -305,14 +244,12 @@ THREAD_RETURN XEventThread(void *pArg)
// Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize()
bool OpenGL_Create(SVideoInitialize &_VideoInitialize, int _iwidth, int _iheight)
{
#if (!defined(HAVE_X11) || !HAVE_X11)
int _tx, _ty, _twidth, _theight;
g_VideoInitialize.pRequestWindowSize(_tx, _ty, _twidth, _theight);
// Control window size and picture scaling
s_backbuffer_width = _twidth;
s_backbuffer_height = _theight;
#endif
g_VideoInitialize.pPeekMessages = &Callback_PeekMessages;
g_VideoInitialize.pUpdateFPSDisplay = &UpdateFPSDisplay;
@ -439,6 +376,11 @@ bool OpenGL_Create(SVideoInitialize &_VideoInitialize, int _iwidth, int _iheight
exit(0); // TODO: Don't bring down entire Emu
}
GLWin.x = _tx;
GLWin.y = _ty;
GLWin.width = _twidth;
GLWin.height = _theight;
CreateXWindow();
g_VideoInitialize.pXWindow = (Window *) &GLWin.win;
#endif
@ -455,6 +397,8 @@ bool OpenGL_MakeCurrent()
#elif defined(_WIN32)
return wglMakeCurrent(hDC,hRC);
#elif defined(HAVE_X11) && HAVE_X11
g_VideoInitialize.pRequestWindowSize(GLWin.x, GLWin.y, (int&)GLWin.width, (int&)GLWin.height);
XMoveResizeWindow(GLWin.dpy, GLWin.win, GLWin.x, GLWin.y, GLWin.width, GLWin.height);
return glXMakeCurrent(GLWin.dpy, GLWin.win, GLWin.ctx);
#endif
return true;
@ -519,7 +463,6 @@ void OpenGL_Shutdown()
cocoaGLDelete(GLWin.cocoaCtx);
#elif defined(_WIN32)
EmuWindow::ToggleDisplayMode(false);
if (hRC) // Do We Have A Rendering Context?
{
if (!wglMakeCurrent(NULL,NULL)) // Are We Able To Release The DC And RC Contexts?

View File

@ -44,9 +44,6 @@
#include <X11/Xlib.h>
#include <X11/keysym.h>
#include "Thread.h"
#if defined(HAVE_XRANDR) && HAVE_XRANDR
#include <X11/extensions/Xrandr.h>
#endif // XRANDR
#elif defined(USE_SDL) && USE_SDL
#include <GL/glew.h>
@ -90,11 +87,6 @@ typedef struct {
GLXContext ctx;
XSetWindowAttributes attr;
Common::Thread *xEventThread;
#if defined(HAVE_XRANDR) && HAVE_XRANDR
XRRScreenConfiguration *screenConfig;
Rotation screenRotation;
int deskSize, fullSize;
#endif // XRANDR
#endif // X11
#if defined(USE_WX) && USE_WX
wxGLCanvas *glCanvas;

View File

@ -37,7 +37,6 @@ BEGIN_EVENT_TABLE(GFXConfigDialogOGL,wxDialog)
EVT_BUTTON(wxID_CLOSE, GFXConfigDialogOGL::CloseClick)
EVT_BUTTON(wxID_ABOUT, GFXConfigDialogOGL::AboutClick)
EVT_CHECKBOX(ID_VSYNC, GFXConfigDialogOGL::GeneralSettingsChanged)
EVT_CHOICE(ID_FULLSCREENRESOLUTION, GFXConfigDialogOGL::GeneralSettingsChanged)
EVT_CHOICE(ID_MAXANISOTROPY, GFXConfigDialogOGL::GeneralSettingsChanged)
EVT_CHOICE(ID_MSAAMODECB, GFXConfigDialogOGL::GeneralSettingsChanged)
EVT_CHECKBOX(ID_NATIVERESOLUTION, GFXConfigDialogOGL::GeneralSettingsChanged)
@ -125,13 +124,6 @@ void GFXConfigDialogOGL::CloseClick(wxCommandEvent& WXUNUSED (event))
// Add avaliable resolutions and other settings
// ---------------
void GFXConfigDialogOGL::AddFSReso(const char *reso)
{
arrayStringFor_FullscreenCB.Add(wxString::FromAscii(reso));
}
// This one could be used to reload shaders while dolphin is running...
void GFXConfigDialogOGL::LoadShaders()
{
@ -158,10 +150,6 @@ void GFXConfigDialogOGL::LoadShaders()
void GFXConfigDialogOGL::InitializeGUILists()
{
// Resolutions
if (arrayStringFor_FullscreenCB.empty())
AddFSReso("<No resolutions found>");
// Keep Aspect Ratio
arrayStringFor_AspectRatio.Add(wxT("Auto Aspect (recommended)"));
arrayStringFor_AspectRatio.Add(wxT("Force 16:9 Widescreen"));
@ -202,9 +190,6 @@ void GFXConfigDialogOGL::InitializeGUIValues()
m_NativeResolution->SetValue(g_Config.bNativeResolution);
m_2xResolution->SetValue(g_Config.b2xResolution);
int num = 0;
num = m_WindowFSResolutionCB->FindString(wxString::FromAscii(g_Config.cFSResolution));
m_WindowFSResolutionCB->SetSelection(num);
m_KeepAR->SetSelection(g_Config.iAspectRatio);
m_Crop->SetValue(g_Config.bCrop);
@ -285,9 +270,6 @@ void GFXConfigDialogOGL::InitializeGUITooltips()
wxT("\nis of the 5:4 format if you have selected the 4:3 aspect ratio. It will assume")
wxT("\nthat your screen is of the 16:10 format if you have selected the 16:9 aspect ratio.")
wxT("\n\nApplies instanty during gameplay: <Yes>"));
m_WindowFSResolutionCB->SetToolTip(
wxT("Select resolution for fullscreen mode")
wxT("\n\nApplies instantly during gameplay: <No>"));
m_MSAAModeCB->SetToolTip(wxT(
"Applies instanty during gameplay: <No>"));
m_OSDHotKey->SetToolTip(
@ -369,8 +351,6 @@ void GFXConfigDialogOGL::CreateGUIControls()
wxStaticText *IRText = new wxStaticText(m_PageGeneral, wxID_ANY, wxT("Resolution:"), wxDefaultPosition, wxDefaultSize, 0);
m_NativeResolution = new wxCheckBox(m_PageGeneral, ID_NATIVERESOLUTION, wxT("Native"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
m_2xResolution = new wxCheckBox(m_PageGeneral, ID_2X_RESOLUTION, wxT("2x"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
wxStaticText *RText = new wxStaticText(m_PageGeneral, wxID_ANY, wxT("Fullscreen Display Resolution:"), wxDefaultPosition, wxDefaultSize, 0);
m_WindowFSResolutionCB = new wxChoice(m_PageGeneral, ID_FULLSCREENRESOLUTION, wxDefaultPosition, wxDefaultSize, arrayStringFor_FullscreenCB, 0, wxDefaultValidator, arrayStringFor_FullscreenCB[0]);
// Aspect ratio / positioning controls
wxStaticText *KeepARText = new wxStaticText(m_PageGeneral, wxID_ANY, wxT("Keep aspect ratio:"), wxDefaultPosition, wxDefaultSize, 0);
m_KeepAR = new wxChoice(m_PageGeneral, ID_ASPECT, wxDefaultPosition, wxDefaultSize, arrayStringFor_AspectRatio);
@ -410,12 +390,9 @@ void GFXConfigDialogOGL::CreateGUIControls()
sBasic->Add(m_NativeResolution, wxGBPosition(0, 1), wxGBSpan(1, 1), wxALIGN_CENTER_VERTICAL | wxALL, 5);
sBasic->Add(m_2xResolution, wxGBPosition(0, 2), wxGBSpan(1, 1), wxALIGN_CENTER_VERTICAL | wxALL, 5);
sBasic->Add(RText, wxGBPosition(1, 0), wxGBSpan(1, 1), wxALIGN_CENTER_VERTICAL | wxALL, 5);
sBasic->Add(m_WindowFSResolutionCB, wxGBPosition(1, 1), wxGBSpan(1, 1), wxALL, 5);
sBasic->Add(KeepARText, wxGBPosition(2, 0), wxGBSpan(1, 1), wxALIGN_CENTER_VERTICAL | wxALL, 5);
sBasic->Add(m_KeepAR, wxGBPosition(2, 1), wxGBSpan(1, 1), wxALL, 5);
sBasic->Add(m_Crop, wxGBPosition(2, 2), wxGBSpan(1, 1), wxALL | wxALIGN_CENTER_VERTICAL, 5);
sBasic->Add(KeepARText, wxGBPosition(1, 0), wxGBSpan(1, 1), wxALIGN_CENTER_VERTICAL | wxALL, 5);
sBasic->Add(m_KeepAR, wxGBPosition(1, 1), wxGBSpan(1, 1), wxALL, 5);
sBasic->Add(m_Crop, wxGBPosition(1, 2), wxGBSpan(1, 1), wxALL | wxALIGN_CENTER_VERTICAL, 5);
sbBasic->Add(sBasic);
sGeneral->Add(sbBasic, 0, wxEXPAND|wxALL, 5);
@ -629,9 +606,6 @@ void GFXConfigDialogOGL::GeneralSettingsChanged(wxCommandEvent& event)
case ID_FORCEFILTERING:
g_Config.bForceFiltering = m_ForceFiltering->IsChecked();
break;
case ID_FULLSCREENRESOLUTION:
strcpy(g_Config.cFSResolution, m_WindowFSResolutionCB->GetStringSelection().mb_str() );
break;
case ID_MAXANISOTROPY:
g_Config.iMaxAnisotropy = m_MaxAnisotropyCB->GetSelection() + 1;
break;
@ -786,7 +760,6 @@ void GFXConfigDialogOGL::UpdateGUI()
//besides, it would look odd if one disabled native, and it came back on again.
m_NativeResolution->Enable(!g_Config.bUseRealXFB);
m_2xResolution->Enable(!g_Config.bUseRealXFB && (!g_Config.bRunning || Renderer::Allow2x()));
m_WindowFSResolutionCB->Enable(!g_Config.bRunning);
// Disable the Copy to options when EFBCopy is disabled
m_Radio_CopyEFBToRAM->Enable(!(g_Config.bEFBCopyDisable));

View File

@ -60,7 +60,6 @@ class GFXConfigDialogOGL : public wxDialog
virtual ~GFXConfigDialogOGL();
void CloseClick(wxCommandEvent& event);
void AddFSReso(const char *reso);
void CreateGUIControls();
void GameIniLoad();
@ -98,7 +97,6 @@ class GFXConfigDialogOGL : public wxDialog
wxCheckBox *m_UseXFB;
wxCheckBox *m_UseRealXFB;
wxCheckBox *m_AutoScale;
wxChoice *m_WindowFSResolutionCB;
wxChoice *m_MaxAnisotropyCB;
wxChoice *m_MSAAModeCB, *m_PhackvalueCB, *m_PostShaderCB, *m_KeepAR;
@ -155,7 +153,6 @@ class GFXConfigDialogOGL : public wxDialog
ID_AUTOSCALE,
ID_WIDESCREENHACK,
ID_FULLSCREENRESOLUTION,
ID_FORCEFILTERING,
ID_MAXANISOTROPY,
ID_MAXANISOTROPYTEXT,

View File

@ -230,27 +230,6 @@ void OnKeyDown(WPARAM wParam)
}
// ---------------------------------------------------------------------
void ToggleDisplayMode (int bFullscreen)
{
if (bFullscreen)
{
DEVMODE dmScreenSettings;
memset(&dmScreenSettings,0,sizeof(dmScreenSettings));
dmScreenSettings.dmSize = sizeof(dmScreenSettings);
sscanf(g_Config.cFSResolution, "%dx%d", &dmScreenSettings.dmPelsWidth, &dmScreenSettings.dmPelsHeight);
dmScreenSettings.dmBitsPerPel = 32;
dmScreenSettings.dmFields = DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
// Try To Set Selected Mode And Get Results. NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar.
ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN);
}
else
{
// Change to default resolution
ChangeDisplaySettings(NULL, CDS_FULLSCREEN);
}
}
// Should really take a look at the mouse stuff in here - some of it is weird.
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
@ -289,8 +268,6 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
PostMessage(m_hParent, WM_USER, wParam, lParam);
}
else if (wParam == TOGGLE_DISPLAYMODE)
ToggleDisplayMode(lParam);
break;
// This is called when we close the window when we render to a separate window

View File

@ -99,11 +99,6 @@ if sys.platform == 'win32':
]
gfxenv['CPPPATH'] += libs
# check for Xrandr
gfxenv['HAVE_XRANDR'] = gfxenv['HAVE_X11'] and conf.CheckPKG('xrandr')
conf.Define('HAVE_XRANDR', gfxenv['HAVE_XRANDR'])
conf.Finish()
# Sanity check

View File

@ -170,88 +170,6 @@ void DllDebugger(HWND _hParent, bool Show)
#endif
}
// Search for avaliable resolutions
void AddResolutions()
{
#ifdef _WIN32
DWORD iModeNum = 0;
DEVMODE dmi;
ZeroMemory(&dmi, sizeof(dmi));
dmi.dmSize = sizeof(dmi);
std::vector<std::string> resos;
while (EnumDisplaySettings(NULL, iModeNum++, &dmi) != 0)
{
char res[100];
sprintf(res, "%dx%d", dmi.dmPelsWidth, dmi.dmPelsHeight);
std::string strRes(res);
// Only add unique resolutions
if (std::find(resos.begin(), resos.end(), strRes) == resos.end())
{
resos.push_back(strRes);
m_ConfigFrame->AddFSReso(res);
}
ZeroMemory(&dmi, sizeof(dmi));
}
#elif defined(HAVE_X11) && HAVE_X11 && defined(HAVE_XRANDR) \
&& HAVE_XRANDR && defined(HAVE_WX) && HAVE_WX
// Don't modify GLWin.dpy here.
// If the emulator is running that is bad.
Display *dpy;
int screen;
dpy = XOpenDisplay(0);
screen = DefaultScreen(dpy);
//Get all full screen resos for the config dialog
XRRScreenSize *sizes = NULL;
int modeNum = 0;
sizes = XRRSizes(dpy, screen, &modeNum);
XCloseDisplay(dpy);
if (modeNum > 0 && sizes != NULL)
{
for (int i = 0; i < modeNum; i++)
{
char temp[32];
sprintf(temp,"%dx%d", sizes[i].width, sizes[i].height);
m_ConfigFrame->AddFSReso(temp);
}
}
#elif defined(HAVE_COCOA) && HAVE_COCOA && defined(HAVE_WX) && HAVE_WX
CGDisplayModeRef mode;
CFArrayRef array;
CFIndex n, i;
int w, h;
std::vector<std::string> resos;
array = CGDisplayCopyAllDisplayModes(CGMainDisplayID(), NULL);
n = CFArrayGetCount(array);
for (i = 0; i < n; i++)
{
mode = (CGDisplayModeRef)CFArrayGetValueAtIndex(array, i);
w = CGDisplayModeGetWidth(mode);
h = CGDisplayModeGetHeight(mode);
char res[32];
sprintf(res,"%dx%d", w, h);
std::string strRes(res);
// Only add unique resolutions
if (std::find(resos.begin(), resos.end(), strRes) == resos.end())
{
resos.push_back(strRes);
m_ConfigFrame->AddFSReso(res);
}
}
CFRelease(array);
#endif
}
void DllConfig(HWND _hParent)
{
g_Config.Load((std::string(File::GetUserPath(D_CONFIG_IDX)) + "gfx_opengl.ini").c_str());
@ -262,8 +180,6 @@ void DllConfig(HWND _hParent)
wxWindow *frame = GetParentedWxWindow(_hParent);
m_ConfigFrame = new GFXConfigDialogOGL(frame);
AddResolutions();
// Prevent user to show more than 1 config window at same time
#ifdef _WIN32
frame->Disable();