diff --git a/app/main.cpp b/app/main.cpp index 2629b765..35006bc8 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -550,9 +550,12 @@ int main(int argc, char *argv[]) #endif } - if (WMUtils::isRunningNvidiaProprietaryDriverX11() || - !WMUtils::supportsDesktopGLWithEGL() || - qEnvironmentVariableIntValue("FORCE_QT_GLES")) { + bool forceGles; + if (!Utils::getEnvironmentVariableOverride("FORCE_QT_GLES", &forceGles)) { + forceGles = WMUtils::isRunningNvidiaProprietaryDriverX11() || + !WMUtils::supportsDesktopGLWithEGL(); + } + if (forceGles) { // The Nvidia proprietary driver causes Qt to render a black window when using // the default Desktop GL profile with EGL. AS a workaround, we default to // OpenGL ES when running on Nvidia on X11. diff --git a/app/streaming/session.cpp b/app/streaming/session.cpp index 4c042200..1f35388e 100644 --- a/app/streaming/session.cpp +++ b/app/streaming/session.cpp @@ -533,28 +533,22 @@ bool Session::populateDecoderProperties(SDL_Window* window) m_VideoCallbacks.submitDecodeUnit = drSubmitDecodeUnit; } - { - bool ok; + if (Utils::getEnvironmentVariableOverride("COLOR_SPACE_OVERRIDE", &m_StreamConfig.colorSpace)) { + SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, + "Using colorspace override: %d", + m_StreamConfig.colorSpace); + } + else { + m_StreamConfig.colorSpace = decoder->getDecoderColorspace(); + } - m_StreamConfig.colorSpace = qEnvironmentVariableIntValue("COLOR_SPACE_OVERRIDE", &ok); - if (ok) { - SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, - "Using colorspace override: %d", - m_StreamConfig.colorSpace); - } - else { - m_StreamConfig.colorSpace = decoder->getDecoderColorspace(); - } - - m_StreamConfig.colorRange = qEnvironmentVariableIntValue("COLOR_RANGE_OVERRIDE", &ok); - if (ok) { - SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, - "Using color range override: %d", - m_StreamConfig.colorRange); - } - else { - m_StreamConfig.colorRange = decoder->getDecoderColorRange(); - } + if (Utils::getEnvironmentVariableOverride("COLOR_RANGE_OVERRIDE", &m_StreamConfig.colorRange)) { + SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, + "Using color range override: %d", + m_StreamConfig.colorRange); + } + else { + m_StreamConfig.colorRange = decoder->getDecoderColorRange(); } if (decoder->isAlwaysFullScreen()) { diff --git a/app/streaming/video/ffmpeg-renderers/d3d11va.cpp b/app/streaming/video/ffmpeg-renderers/d3d11va.cpp index af594550..108b3f96 100644 --- a/app/streaming/video/ffmpeg-renderers/d3d11va.cpp +++ b/app/streaming/video/ffmpeg-renderers/d3d11va.cpp @@ -4,6 +4,7 @@ #include "d3d11va.h" #include "dxutil.h" #include "path.h" +#include "utils.h" #include "streaming/streamutils.h" #include "streaming/session.h" @@ -209,29 +210,26 @@ bool D3D11VARenderer::createDeviceByAdapterIndex(int adapterIndex, bool* adapter goto Exit; } - bool ok; - m_BindDecoderOutputTextures = !!qEnvironmentVariableIntValue("D3D11VA_FORCE_BIND", &ok); - if (!ok) { + if (Utils::getEnvironmentVariableOverride("D3D11VA_FORCE_BIND", &m_BindDecoderOutputTextures)) { + SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, + "Using D3D11VA_FORCE_BIND to override default bind/copy logic"); + } + else { // Skip copying to our own internal texture on Intel GPUs due to // significant performance impact of the extra copy. See: // https://github.com/moonlight-stream/moonlight-qt/issues/1304 m_BindDecoderOutputTextures = adapterDesc.VendorId == 0x8086; } - else { - SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, - "Using D3D11VA_FORCE_BIND to override default bind/copy logic"); - } - m_UseFenceHack = !!qEnvironmentVariableIntValue("D3D11VA_FORCE_FENCE", &ok); - if (!ok) { + if (Utils::getEnvironmentVariableOverride("D3D11VA_FORCE_FENCE", &m_UseFenceHack)) { + SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, + "Using D3D11VA_FORCE_FENCE to override default fence workaround logic"); + } + else { // Old Intel GPUs (HD 4000) require a fence to properly synchronize // the video engine with the 3D engine for texture sampling. m_UseFenceHack = adapterDesc.VendorId == 0x8086 && featureLevel < D3D_FEATURE_LEVEL_11_1; } - else { - SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, - "Using D3D11VA_FORCE_FENCE to override default fence workaround logic"); - } SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Decoder texture access: %s (fence: %s)", diff --git a/app/streaming/video/ffmpeg-renderers/drm.cpp b/app/streaming/video/ffmpeg-renderers/drm.cpp index 3683102e..3ea9204c 100644 --- a/app/streaming/video/ffmpeg-renderers/drm.cpp +++ b/app/streaming/video/ffmpeg-renderers/drm.cpp @@ -4,7 +4,7 @@ #endif #include "drm.h" -#include "string.h" +#include "utils.h" extern "C" { #include @@ -80,6 +80,7 @@ struct dma_buf_sync { #include #include +#include #include @@ -576,8 +577,12 @@ bool DrmRenderer::initialize(PDECODER_PARAMETERS params) // formats with the linear modifier on all planes, but doesn't actually // support raw YUV formats on the primary plane. Don't ever use primary // planes on Spacemit hardware to avoid triggering this bug. - bool ok, allowPrimaryPlane = !!qEnvironmentVariableIntValue("DRM_ALLOW_PRIMARY_PLANE", &ok); - if (!ok) { + bool allowPrimaryPlane; + if (Utils::getEnvironmentVariableOverride("DRM_ALLOW_PRIMARY_PLANE", &allowPrimaryPlane)) { + SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, + "Using DRM_ALLOW_PRIMARY_PLANE to override default plane selection logic"); + } + else { allowPrimaryPlane = strcmp(m_Version->name, "spacemit") != 0; } diff --git a/app/streaming/video/ffmpeg-renderers/dxva2.cpp b/app/streaming/video/ffmpeg-renderers/dxva2.cpp index b3d49806..020e8c8e 100644 --- a/app/streaming/video/ffmpeg-renderers/dxva2.cpp +++ b/app/streaming/video/ffmpeg-renderers/dxva2.cpp @@ -5,6 +5,7 @@ #include #include "dxva2.h" #include "dxutil.h" +#include "utils.h" #include "../ffmpeg.h" #include #include @@ -390,16 +391,11 @@ bool DXVA2Renderer::initializeQuirksForAdapter(IDirect3D9Ex* d3d9ex, int adapter SDL_assert(m_DeviceQuirks == 0); SDL_assert(!m_Device); - { - bool ok; - - m_DeviceQuirks = qEnvironmentVariableIntValue("DXVA2_QUIRK_FLAGS", &ok); - if (ok) { - SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, - "Using DXVA2 quirk override: 0x%x", - m_DeviceQuirks); - return true; - } + if (Utils::getEnvironmentVariableOverride("DXVA2_QUIRK_FLAGS", &m_DeviceQuirks)) { + SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, + "Using DXVA2 quirk override: 0x%x", + m_DeviceQuirks); + return true; } UINT adapterCount = d3d9ex->GetAdapterCount(); diff --git a/app/streaming/video/ffmpeg-renderers/genhwaccel.cpp b/app/streaming/video/ffmpeg-renderers/genhwaccel.cpp index 31f895c8..08c84839 100644 --- a/app/streaming/video/ffmpeg-renderers/genhwaccel.cpp +++ b/app/streaming/video/ffmpeg-renderers/genhwaccel.cpp @@ -1,4 +1,5 @@ #include "genhwaccel.h" +#include "utils.h" GenericHwAccelRenderer::GenericHwAccelRenderer(AVHWDeviceType hwDeviceType) : IFFmpegRenderer(RendererType::Unknown), @@ -56,9 +57,9 @@ bool GenericHwAccelRenderer::isDirectRenderingSupported() int GenericHwAccelRenderer::getDecoderCapabilities() { - bool ok; - int caps = qEnvironmentVariableIntValue("GENHWACCEL_CAPS", &ok); - if (ok) { + int caps; + + if (Utils::getEnvironmentVariableOverride("GENHWACCEL_CAPS", &caps)) { SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Using GENHWACCEL_CAPS for decoder capabilities: %x", caps); diff --git a/app/streaming/video/ffmpeg.cpp b/app/streaming/video/ffmpeg.cpp index ef805e4a..eab0f0f1 100644 --- a/app/streaming/video/ffmpeg.cpp +++ b/app/streaming/video/ffmpeg.cpp @@ -1,5 +1,6 @@ #include #include "ffmpeg.h" +#include "utils.h" #include "streaming/session.h" #include @@ -109,10 +110,9 @@ bool FFmpegVideoDecoder::notifyWindowChanged(PWINDOW_STATE_CHANGE_INFO info) int FFmpegVideoDecoder::getDecoderCapabilities() { - bool ok; + int capabilities; - int capabilities = qEnvironmentVariableIntValue("DECODER_CAPS", &ok); - if (ok) { + if (Utils::getEnvironmentVariableOverride("DECODER_CAPS", &capabilities)) { SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Using decoder capability override: 0x%x", capabilities); @@ -1080,8 +1080,9 @@ bool FFmpegVideoDecoder::isSeparateTestDecoderRequired(const AVCodec* decoder) // the decoder can handle a change in surface sizes while streaming. // We know v4l2m2m can't handle this (see comment below), so let's just // opt-out all non-hwaccel decoders just to be safe. - if (qEnvironmentVariableIntValue("SEPARATE_TEST_DECODER")) { - return true; + bool value; + if (Utils::getEnvironmentVariableOverride("SEPARATE_TEST_DECODER", &value)) { + return value; } else if (getAVCodecCapabilities(decoder) & AV_CODEC_CAP_HARDWARE) { return true; diff --git a/app/utils.h b/app/utils.h index c37c0dbe..d703fc0a 100644 --- a/app/utils.h +++ b/app/utils.h @@ -14,3 +14,12 @@ namespace WMUtils { bool isRunningDesktopEnvironment(); QString getDrmCardOverride(); } + +namespace Utils { + template + bool getEnvironmentVariableOverride(const char* name, T* value) { + bool ok; + *value = (T)qEnvironmentVariableIntValue(name, &ok); + return ok; + } +} diff --git a/app/wm.cpp b/app/wm.cpp index d8b6eff9..01a203da 100644 --- a/app/wm.cpp +++ b/app/wm.cpp @@ -176,8 +176,9 @@ bool WMUtils::isRunningWindowManager() bool WMUtils::isRunningDesktopEnvironment() { - if (qEnvironmentVariableIsSet("HAS_DESKTOP_ENVIRONMENT")) { - return qEnvironmentVariableIntValue("HAS_DESKTOP_ENVIRONMENT"); + bool value; + if (Utils::getEnvironmentVariableOverride("HAS_DESKTOP_ENVIRONMENT", &value)) { + return value; } #if defined(Q_OS_WIN) || defined(Q_OS_DARWIN)