13#define LOC QString("NVCtrl: ")
29using QueryTargetBinary = bool(*)(Display*,int,int,
unsigned int,
unsigned int,
unsigned char**,
int*);
32using SetAttribute = void(*)(Display*,int,
unsigned int,
unsigned int,int);
65 LOG(VB_GENERAL, LOG_INFO,
LOC +
"No GSync support detected - cannot force");
69 if (gsync->Enabled() == Enable)
71 LOG(VB_GENERAL, LOG_INFO,
LOC + QString(
"GSync already %1")
72 .arg(Enable ?
"enabled" :
"disabled"));
76 gsync->SetEnabled(Enable);
81 LOG(VB_GENERAL, LOG_INFO,
LOC + (Enable ?
"Enabled" :
"Disabled"));
90 auto displayid =
Device->GetDisplayID();
94 auto * display =
Device->m_display->GetDisplay();
114 std::get<0>(Range) = minrate;
115 std::get<2>(Range) =
true;
119 return std::shared_ptr<MythVRR>(
new MythGSync(
Device, vrrtype, allowed > 0, Range));
144 LOG(VB_GENERAL, LOG_INFO,
LOC +
"Resetting GSync to desktop default");
154 int enable = Enable ? 1 : 0;
168 static const QStringList s_paths = {
"libXNVCtrl",
"libXNVCtrl.so.0" };
169 static bool s_available =
false;
170 static bool s_checked =
false;
171 if (s_checked && !s_available)
176 for (
const auto & path : s_paths)
178 if (QLibrary lib(path); lib.load())
181 auto isnvscreen =
reinterpret_cast<bool(*)(Display*,
int)
>(lib.resolve(
"XNVCTRLIsNvScreen"));
182 auto queryversion =
reinterpret_cast<bool(*)(Display*,
int,
int)
>(lib.resolve(
"XNVCTRLQueryVersion"));
183 if (isnvscreen && queryversion)
186 if (xdisplay && xdisplay->GetDisplay())
190 if (isnvscreen(xdisplay->GetDisplay(), xdisplay->GetScreen()) &&
191 queryversion(xdisplay->GetDisplay(), major,
minor))
193 if (
auto res = std::shared_ptr<MythNVControl>(
new MythNVControl(path, xdisplay));
194 res->m_queryBinary && res->m_queryScreen && res->m_queryTarget && res->m_setAttrib)
214 m_queryBinary(reinterpret_cast<
QueryTargetBinary>(m_lib.resolve(
"XNVCTRLQueryTargetBinaryData"))),
215 m_queryScreen(reinterpret_cast<
QueryScreenAttrib>(m_lib.resolve(
"XNVCTRLQueryAttribute"))),
216 m_queryTarget(reinterpret_cast<
QueryTargetAttrib>(m_lib.resolve(
"XNVCTRLQueryTargetAttribute"))),
217 m_setAttrib(reinterpret_cast<
SetAttribute>(m_lib.resolve(
"XNVCTRLSetAttribute")))
231 uint32_t * data =
nullptr;
235 reinterpret_cast<unsigned char **
>(&data), &size))
237 LOG(VB_GENERAL, LOG_WARNING,
LOC +
"Failed to retrieve display id for screen");
247 LOG(VB_GENERAL, LOG_INFO,
LOC + QString(
"%1 display id's returned - using first")
248 .arg((size - 4) / 4));
251 int dispId =
static_cast<int>(data[1]);
A device containing images (ie. USB stick, CD, storage group etc)
MythGSync(NVControl Device, VRRType Type, bool Enabled, MythVRRRange Range)
void SetEnabled(bool Enable=true) override
static bool s_gsyncResetOnExit
static bool s_gsyncDefaultValue
static MythVRRPtr CreateGSync(MythVRRRange Range)
static void ForceGSync(bool Enable)
Enable or disable GSync before the main window is created.
A simple wrapper around libXNVCtrl - which is dynamically loaded on demand.
static NVControl Create()
Create a valid instance of MythNVControl.
MythNVControl(const QString &Path, MythXDisplay *MDisplay)
QueryTargetBinary m_queryBinary
QueryScreenAttrib m_queryScreen
QueryTargetAttrib m_queryTarget
static MythXDisplay * OpenMythXDisplay(bool Warn=true)
std::tuple< int, int, bool > MythVRRRange
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
static constexpr uint NV_CTRL_BINARY_DATA_DISPLAYS_ENABLED_ON_XSCREEN
bool(*)(Display *, int, int, unsigned int, unsigned int, unsigned char **, int *) QueryTargetBinary
static constexpr uint NV_CTRL_VRR_ALLOWED
bool(*)(Display *, int, int, unsigned int, unsigned int, int *) QueryTargetAttrib
static constexpr uint NV_CTRL_DISPLAY_VRR_ENABLED
static constexpr int NV_CTRL_TARGET_TYPE_X_SCREEN
NV_CTRL_DISPLAY_VRR_MODES
@ NV_CTRL_DISPLAY_VRR_MODE_GSYNC_COMPATIBLE
@ NV_CTRL_DISPLAY_VRR_MODE_NONE
@ NV_CTRL_DISPLAY_VRR_MODE_GSYNC
@ NV_CTRL_DISPLAY_VRR_MODE_GSYNC_COMPATIBLE_UNVALIDATED
void(*)(Display *, int, unsigned int, unsigned int, int) SetAttribute
static constexpr int NV_CTRL_TARGET_TYPE_DISPLAY
bool(*)(Display *, int, unsigned int, unsigned int, int *) QueryScreenAttrib
static constexpr uint NV_CTRL_DISPLAY_VRR_MIN_REFRESH_RATE
static constexpr uint NV_CTRL_DISPLAY_VRR_MODE
std::shared_ptr< class MythNVControl > NVControl
std::shared_ptr< class MythVRR > MythVRRPtr
VERBOSE_PREAMBLE Most true