Start the SDL window on the same display as the Qt UI was displayed on

This commit is contained in:
Cameron Gutman 2018-09-05 15:15:53 -07:00
parent 4df9d6b20a
commit 856318f947
3 changed files with 45 additions and 27 deletions

View file

@ -1,6 +1,7 @@
import QtQuick 2.0
import QtQuick.Controls 2.2
import QtQuick.Dialogs 1.2
import QtQuick.Window 2.2
import Session 1.0
@ -69,7 +70,7 @@ Item {
session.displayLaunchWarning.connect(displayLaunchWarning)
// Run the streaming session to completion
session.exec()
session.exec(Screen.virtualX, Screen.virtualY)
// Show the Qt window again after streaming
window.visible = true

View file

@ -274,7 +274,9 @@ Session::Session(NvComputer* computer, NvApp& app)
m_VideoDecoder(nullptr),
m_DecoderLock(0),
m_NeedsIdr(false),
m_AudioDisabled(false)
m_AudioDisabled(false),
m_DisplayOriginX(0),
m_DisplayOriginY(0)
{
qDebug() << "Server GPU:" << m_Computer->gpuModel;
@ -539,22 +541,31 @@ void Session::getWindowDimensions(bool fullScreen,
displayIndex = SDL_GetWindowDisplayIndex(m_Window);
SDL_assert(displayIndex >= 0);
}
// If there's a display matching this exact resolution, pick that
// one (for native full-screen streaming). Otherwise, assume
// display 0 for now. TODO: Default to the screen that the Qt window is on
else if (fullScreen) {
for (int i = 0; i < SDL_GetNumVideoDisplays(); i++) {
SDL_DisplayMode mode;
if (StreamUtils::getRealDesktopMode(i, &mode) &&
m_ActiveVideoWidth == mode.w &&
m_ActiveVideoHeight == mode.h) {
// Create our window on the same display that Qt's UI
// was being displayed on.
else {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
"Found exact resolution match on display: %d",
"Qt UI screen is at (%d,%d)",
m_DisplayOriginX, m_DisplayOriginY);
for (int i = 0; i < SDL_GetNumVideoDisplays(); i++) {
SDL_Rect displayBounds;
if (SDL_GetDisplayBounds(i, &displayBounds) == 0) {
if (displayBounds.x == m_DisplayOriginX &&
displayBounds.y == m_DisplayOriginY) {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
"SDL found matching display %d",
i);
displayIndex = i;
break;
}
}
else {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"SDL_GetDisplayBounds(%d) failed: %s",
i, SDL_GetError());
}
}
}
SDL_Rect usableBounds;
@ -567,17 +578,18 @@ void Session::getWindowDimensions(bool fullScreen,
if (m_Window != nullptr) {
int top, left, bottom, right;
if (SDL_GetWindowBordersSize(m_Window, &top, &left, &bottom, &right) < 0) {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"Unable to get window border size");
return;
}
if (SDL_GetWindowBordersSize(m_Window, &top, &left, &bottom, &right) == 0) {
x += left;
y += top;
width -= left + right;
height -= top + bottom;
}
else {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"Unable to get window border size: %s",
SDL_GetError());
}
// If the stream window can fit within the usable drawing area with 1:1
// scaling, do that rather than filling the screen.
@ -652,8 +664,11 @@ void Session::toggleFullscreen()
}
}
void Session::exec()
void Session::exec(int displayOriginX, int displayOriginY)
{
m_DisplayOriginX = displayOriginX;
m_DisplayOriginY = displayOriginY;
// Check for validation errors/warnings and emit
// signals for them, if appropriate
if (!validateLaunch()) {

View file

@ -19,7 +19,7 @@ class Session : public QObject
public:
explicit Session(NvComputer* computer, NvApp& app);
Q_INVOKABLE void exec();
Q_INVOKABLE void exec(int displayOriginX, int displayOriginY);
static
bool isHardwareDecodeAvailable(StreamingPreferences::VideoDecoderSelection vds,
@ -113,6 +113,8 @@ private:
bool m_NeedsIdr;
bool m_AudioDisabled;
Uint32 m_FullScreenFlag;
int m_DisplayOriginX;
int m_DisplayOriginY;
int m_ActiveVideoFormat;
int m_ActiveVideoWidth;