mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2025-07-04 00:36:36 +00:00
Select the highest full-screen refresh rate that our stream FPS evenly divides
This commit is contained in:
parent
6d6acf4308
commit
af6e99cbac
@ -91,12 +91,26 @@ int StreamingPreferences::getMaximumStreamingFrameRate()
|
|||||||
return maxFrameRate;
|
return maxFrameRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < SDL_GetNumVideoDisplays(); i++) {
|
SDL_DisplayMode mode, bestMode, desktopMode;
|
||||||
SDL_DisplayMode mode;
|
for (int displayIndex = 0; displayIndex < SDL_GetNumVideoDisplays(); displayIndex++) {
|
||||||
if (SDL_GetCurrentDisplayMode(i, &mode) == 0) {
|
// Get the native desktop resolution
|
||||||
|
if (SDL_GetDesktopDisplayMode(displayIndex, &desktopMode) == 0) {
|
||||||
|
|
||||||
|
// Start at desktop mode and work our way up
|
||||||
|
bestMode = desktopMode;
|
||||||
|
for (int i = 0; i < SDL_GetNumDisplayModes(displayIndex); i++) {
|
||||||
|
if (SDL_GetDisplayMode(displayIndex, i, &mode) == 0) {
|
||||||
|
if (mode.w == desktopMode.w && mode.h == desktopMode.h) {
|
||||||
|
if (mode.refresh_rate > bestMode.refresh_rate) {
|
||||||
|
bestMode = mode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Cap the frame rate at 120 FPS. Past this, the encoders start
|
// Cap the frame rate at 120 FPS. Past this, the encoders start
|
||||||
// to max out and drop frames.
|
// to max out and drop frames.
|
||||||
maxFrameRate = qMax(maxFrameRate, qMin(120, mode.refresh_rate));
|
maxFrameRate = qMax(maxFrameRate, qMin(120, bestMode.refresh_rate));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -544,7 +544,7 @@ void Session::getWindowDimensions(bool fullScreen,
|
|||||||
else if (fullScreen) {
|
else if (fullScreen) {
|
||||||
for (int i = 0; i < SDL_GetNumVideoDisplays(); i++) {
|
for (int i = 0; i < SDL_GetNumVideoDisplays(); i++) {
|
||||||
SDL_DisplayMode mode;
|
SDL_DisplayMode mode;
|
||||||
if (SDL_GetCurrentDisplayMode(i, &mode) == 0 &&
|
if (SDL_GetDesktopDisplayMode(i, &mode) == 0 &&
|
||||||
m_ActiveVideoWidth == mode.w &&
|
m_ActiveVideoWidth == mode.w &&
|
||||||
m_ActiveVideoHeight == mode.h) {
|
m_ActiveVideoHeight == mode.h) {
|
||||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
@ -597,6 +597,36 @@ void Session::getWindowDimensions(bool fullScreen,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Session::updateOptimalWindowDisplayMode()
|
||||||
|
{
|
||||||
|
SDL_DisplayMode desktopMode, bestMode, mode;
|
||||||
|
int displayIndex = SDL_GetWindowDisplayIndex(m_Window);
|
||||||
|
|
||||||
|
// Get the native desktop resolution
|
||||||
|
if (SDL_GetDesktopDisplayMode(displayIndex, &desktopMode) == 0) {
|
||||||
|
// Start with the native desktop resolution and try to find
|
||||||
|
// the highest refresh rate that our stream FPS evenly divides.
|
||||||
|
bestMode = desktopMode;
|
||||||
|
bestMode.refresh_rate = 0;
|
||||||
|
for (int i = 0; i < SDL_GetNumDisplayModes(displayIndex); i++) {
|
||||||
|
if (SDL_GetDisplayMode(displayIndex, i, &mode) == 0) {
|
||||||
|
if (mode.w == desktopMode.w && mode.h == desktopMode.h &&
|
||||||
|
mode.refresh_rate % m_StreamConfig.fps == 0) {
|
||||||
|
if (mode.refresh_rate > bestMode.refresh_rate) {
|
||||||
|
bestMode = mode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
|
"Chosen best display mode: %dx%dx%d",
|
||||||
|
bestMode.w, bestMode.h, bestMode.refresh_rate);
|
||||||
|
|
||||||
|
SDL_SetWindowDisplayMode(m_Window, &bestMode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Session::toggleFullscreen()
|
void Session::toggleFullscreen()
|
||||||
{
|
{
|
||||||
bool fullScreen = !(SDL_GetWindowFlags(m_Window) & m_FullScreenFlag);
|
bool fullScreen = !(SDL_GetWindowFlags(m_Window) & m_FullScreenFlag);
|
||||||
@ -752,10 +782,7 @@ void Session::exec()
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Update the window display mode based on our current monitor
|
// Update the window display mode based on our current monitor
|
||||||
SDL_DisplayMode mode;
|
updateOptimalWindowDisplayMode();
|
||||||
if (SDL_GetDesktopDisplayMode(SDL_GetWindowDisplayIndex(m_Window), &mode) == 0) {
|
|
||||||
SDL_SetWindowDisplayMode(m_Window, &mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enter full screen
|
// Enter full screen
|
||||||
SDL_SetWindowFullscreen(m_Window, m_FullScreenFlag);
|
SDL_SetWindowFullscreen(m_Window, m_FullScreenFlag);
|
||||||
@ -883,10 +910,7 @@ void Session::exec()
|
|||||||
SDL_FlushEvent(SDL_WINDOWEVENT);
|
SDL_FlushEvent(SDL_WINDOWEVENT);
|
||||||
|
|
||||||
// Update the window display mode based on our current monitor
|
// Update the window display mode based on our current monitor
|
||||||
SDL_DisplayMode mode;
|
updateOptimalWindowDisplayMode();
|
||||||
if (SDL_GetDesktopDisplayMode(SDL_GetWindowDisplayIndex(m_Window), &mode) == 0) {
|
|
||||||
SDL_SetWindowDisplayMode(m_Window, &mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now that the old decoder is dead, flush any events it may
|
// Now that the old decoder is dead, flush any events it may
|
||||||
// have queued to reset itself (if this reset was the result
|
// have queued to reset itself (if this reset was the result
|
||||||
|
@ -57,6 +57,8 @@ private:
|
|||||||
|
|
||||||
void toggleFullscreen();
|
void toggleFullscreen();
|
||||||
|
|
||||||
|
void updateOptimalWindowDisplayMode();
|
||||||
|
|
||||||
static
|
static
|
||||||
bool chooseDecoder(StreamingPreferences::VideoDecoderSelection vds,
|
bool chooseDecoder(StreamingPreferences::VideoDecoderSelection vds,
|
||||||
SDL_Window* window, int videoFormat, int width, int height,
|
SDL_Window* window, int videoFormat, int width, int height,
|
||||||
|
@ -132,10 +132,27 @@ bool Pacer::initialize(SDL_Window* window, int maxVideoFps, bool enableVsync)
|
|||||||
}
|
}
|
||||||
|
|
||||||
SDL_DisplayMode mode;
|
SDL_DisplayMode mode;
|
||||||
if (SDL_GetCurrentDisplayMode(displayIndex, &mode) == 0) {
|
if ((SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN) {
|
||||||
|
// Use the window display mode for full-screen exclusive mode
|
||||||
|
if (SDL_GetWindowDisplayMode(window, &mode) != 0) {
|
||||||
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
|
"SDL_GetWindowDisplayMode() failed: %s",
|
||||||
|
SDL_GetError());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Use the current display mode for windowed and borderless
|
||||||
|
if (SDL_GetCurrentDisplayMode(displayIndex, &mode) != 0) {
|
||||||
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
|
"SDL_GetCurrentDisplayMode() failed: %s",
|
||||||
|
SDL_GetError());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// May be zero if undefined
|
// May be zero if undefined
|
||||||
m_DisplayFps = mode.refresh_rate;
|
m_DisplayFps = mode.refresh_rate;
|
||||||
}
|
|
||||||
|
|
||||||
if (m_EnableVsync) {
|
if (m_EnableVsync) {
|
||||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user