UICommon: Move Wx Graphics Settings functions

This commit is contained in:
spycrab 2017-06-16 01:37:39 +02:00
parent e14a82a87e
commit 7c97c14eba
4 changed files with 112 additions and 64 deletions

View File

@ -32,6 +32,7 @@
#include "DolphinWX/Main.h"
#include "DolphinWX/PostProcessingConfigDiag.h"
#include "DolphinWX/WxUtils.h"
#include "UICommon/VideoUtils.h"
#include "VideoCommon/PostProcessing.h"
#include "VideoCommon/VideoBackendBase.h"
#include "VideoCommon/VideoConfig.h"
@ -307,69 +308,6 @@ static wxString gpu_texture_decoding_desc =
"performance gains in some scenarios, or on systems where the CPU is the "
"bottleneck.\n\nIf unsure, leave this unchecked.");
#if !defined(__APPLE__)
// Search for available resolutions - TODO: Move to Common?
static wxArrayString GetListOfResolutions()
{
wxArrayString retlist;
retlist.Add(_("Auto"));
#ifdef _WIN32
DWORD iModeNum = 0;
DEVMODE dmi;
ZeroMemory(&dmi, sizeof(dmi));
dmi.dmSize = sizeof(dmi);
std::vector<std::string> resos;
while (EnumDisplaySettings(nullptr, 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);
retlist.Add(StrToWxStr(res));
}
ZeroMemory(&dmi, sizeof(dmi));
}
#elif defined(HAVE_XRANDR) && HAVE_XRANDR
std::vector<std::string> resos;
main_frame->m_xrr_config->AddResolutions(resos);
for (auto res : resos)
retlist.Add(StrToWxStr(res));
#elif defined(__APPLE__)
CFArrayRef modes = CGDisplayCopyAllDisplayModes(CGMainDisplayID(), nullptr);
for (CFIndex i = 0; i < CFArrayGetCount(modes); i++)
{
std::stringstream res;
CGDisplayModeRef mode;
CFStringRef encoding;
size_t w, h;
bool is32;
mode = (CGDisplayModeRef)CFArrayGetValueAtIndex(modes, i);
w = CGDisplayModeGetWidth(mode);
h = CGDisplayModeGetHeight(mode);
encoding = CGDisplayModeCopyPixelEncoding(mode);
is32 = CFEqual(encoding, CFSTR(IO32BitDirectPixels));
CFRelease(encoding);
if (!is32)
continue;
if (CGDisplayModeGetIOFlags(mode) & kDisplayModeStretchedFlag)
continue;
res << w << "x" << h;
retlist.Add(res.str());
}
CFRelease(modes);
#endif
return retlist;
}
#endif
VideoConfigDiag::VideoConfigDiag(wxWindow* parent, const std::string& title)
: wxDialog(parent, wxID_ANY, wxString::Format(_("Dolphin %s Graphics Configuration"),
wxGetTranslation(StrToWxStr(title)))),
@ -436,7 +374,17 @@ VideoConfigDiag::VideoConfigDiag(wxWindow* parent, const std::string& title)
#if !defined(__APPLE__)
// display resolution
{
wxArrayString res_list = GetListOfResolutions();
wxArrayString res_list;
res_list.Add(_("Auto"));
#if defined(HAVE_XRANDR) && HAVE_XRANDR
const auto resolutions = VideoUtils::GetAvailableResolutions(main_frame->m_xrr_config);
#else
const auto resolutions = VideoUtils::GetAvailableResolutions(nullptr);
#endif
for (const auto& res : resolutions)
res_list.Add(res);
if (res_list.empty())
res_list.Add(_("<No resolutions found>"));
label_display_resolution =

View File

@ -3,6 +3,7 @@ set(SRCS
Disassembler.cpp
UICommon.cpp
USBUtils.cpp
VideoUtils.cpp
)
if(USE_X11)

View File

@ -0,0 +1,77 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "UICommon/VideoUtils.h"
#include "Common/Assert.h"
#include "VideoCommon/VideoConfig.h"
#if defined(HAVE_XRANDR) && HAVE_XRANDR
#include "UICommon/X11Utils.h"
#endif
namespace VideoUtils
{
#if !defined(__APPLE__)
std::vector<std::string> GetAvailableResolutions(X11Utils::XRRConfiguration* xrr_config)
{
std::vector<std::string> resos;
#ifdef _WIN32
DWORD iModeNum = 0;
DEVMODE dmi;
ZeroMemory(&dmi, sizeof(dmi));
dmi.dmSize = sizeof(dmi);
while (EnumDisplaySettings(nullptr, 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);
}
ZeroMemory(&dmi, sizeof(dmi));
}
#elif defined(HAVE_XRANDR) && HAVE_XRANDR
xrr_config->AddResolutions(resos);
#endif
return resos;
}
#endif
std::vector<std::string> GetAvailableAntialiasingModes(int& msaa_modes)
{
std::vector<std::string> modes;
const auto& aa_modes = g_Config.backend_info.AAModes;
const bool supports_ssaa = g_Config.backend_info.bSupportsSSAA;
msaa_modes = 0;
for (const auto mode : aa_modes)
{
if (mode == 1)
{
modes.push_back("None");
_assert_msg_(VIDEO, !supports_ssaa || msaa_modes == 0, "SSAA setting won't work correctly");
}
else
{
modes.push_back(std::to_string(mode) + "x MSAA");
msaa_modes++;
}
}
if (supports_ssaa)
{
for (const auto mode : aa_modes)
{
if (mode != 1)
modes.push_back(std::to_string(mode) + "x SSAA");
}
}
return modes;
}
}

View File

@ -0,0 +1,22 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <string>
#include <vector>
namespace X11Utils
{
class XRRConfiguration;
}
namespace VideoUtils
{
#if !defined(__APPLE__)
std::vector<std::string> GetAvailableResolutions(X11Utils::XRRConfiguration* xrr_config);
#endif
std::vector<std::string> GetAvailableAntialiasingModes(int& m_msaa_modes);
}