MythTV master
mythvrr.cpp
Go to the documentation of this file.
1// libmythbase
2#include "libmythbase/mythconfig.h"
4
5// libmythui
6#include "mythvrr.h"
7#if CONFIG_DRM
10#endif
11#if CONFIG_X11
14#endif
15#include "mythdisplay.h"
16
17// Qt
18#include <QObject>
19
20#define LOC QString("VRR: ")
21
47MythVRR::MythVRR(bool Controllable, VRRType Type, bool Enabled, MythVRRRange Range)
48 : m_controllable(Controllable),
49 m_type(Type),
50 m_enabled(Enabled),
51 m_range(std::move(Range))
52{
53}
54
58{
59 if (!MDisplay)
60 return nullptr;
61
62 MythVRRPtr result = nullptr;
63
64#if CONFIG_X11 || CONFIG_DRM
65 const auto range = MDisplay->GetEDID().GetVRRRange();
66
67#if CONFIG_X11
68 // GSync is only available with X11 over Display Port
69 if (auto nvcontrol = MythNVControl::Create(); nvcontrol)
70 if (auto gsync = MythGSync::CreateGSync(nvcontrol, range); gsync)
71 result = gsync;
72#endif
73
74#if CONFIG_DRM
75 // FreeSync is only currently *controllable* via DRM with an AMD GPU/APU and Display Port
76 if (!result)
77 {
78 if (auto * display = dynamic_cast<MythDisplayDRM*>(MDisplay); display && display->GetDevice())
79 if (auto freesync = MythDRMVRR::CreateFreeSync(display->GetDevice(), range); freesync)
80 result = freesync;
81 }
82
83 // If we don't have support for controlling FreeSync then DRM may still be able to
84 // tell us if it is available/enabled - which is still useful
85 if (!result)
86 {
87 if (auto drm = MythDRMDevice::Create(MDisplay->GetCurrentScreen(), DRM_QUIET); drm)
88 if (auto freesync = MythDRMVRR::CreateFreeSync(drm, range); freesync)
89 result = freesync;
90 }
91#endif
92#endif
93
94 if (!result)
95 {
96 LOG(VB_GENERAL, LOG_INFO, LOC + "No variable refresh rate support detected");
97 }
98 else
99 {
100 LOG(VB_GENERAL, LOG_INFO, LOC + QString("VRR type '%1': Enabled: %2 Controllable: %3 %4")
101 .arg(result->TypeToString()).arg(result->Enabled()).arg(result->IsControllable())
102 .arg(result->RangeDescription()));
103 }
104 return result;
105}
106
108{
109 return m_enabled;
110}
111
113{
114 return m_range;
115}
116
118{
119 return m_controllable;
120}
121
123{
124 switch (m_type)
125 {
126 case FreeSync: return QObject::tr("FreeSync");
127 case GSync: return QObject::tr("GSync");
128 case GSyncCompat: return QObject::tr("GSync Compatible");
129 default: break;
130 }
131 return QObject::tr("None");
132}
133
135{
136 if (std::get<0>(m_range) > 0 && std::get<1>(m_range) > 0)
137 {
138 return QObject::tr("Range: %1-%2%3")
139 .arg(std::get<0>(m_range)).arg(std::get<1>(m_range))
140 .arg(std::get<2>(m_range) ? "" : " (Estimated)");
141 }
142 return {};
143}
144
static MythDRMPtr Create(QScreen *qScreen, const QString &Device=QString(), bool NeedPlanes=true)
Create a MythDRMDevice instance.
static MythVRRPtr CreateFreeSync(const MythDRMPtr &Device, MythVRRRange Range)
Definition: mythdrmvrr.cpp:56
MythDRMPtr GetDevice()
MythEDID & GetEDID()
QScreen * GetCurrentScreen()
Return a pointer to the screen to use.
MythVRRRange GetVRRRange() const
Return the range of supported refresh rates.
Definition: mythedid.cpp:113
static MythVRRPtr CreateGSync(const NVControl &Device, MythVRRRange Range)
static NVControl Create()
Create a valid instance of MythNVControl.
MythVRRRange m_range
Definition: mythvrr.h:41
bool m_enabled
Definition: mythvrr.h:40
MythVRR(bool Controllable, VRRType Type, bool Enabled, MythVRRRange Range)
Definition: mythvrr.cpp:47
VRRType
Definition: mythvrr.h:19
@ FreeSync
Definition: mythvrr.h:21
@ GSyncCompat
Definition: mythvrr.h:23
@ GSync
Definition: mythvrr.h:22
MythVRRRange GetRange() const
Definition: mythvrr.cpp:112
bool Enabled() const
Definition: mythvrr.cpp:107
static MythVRRPtr Create(class MythDisplay *MDisplay)
Create a concrete implementation of MythVRR suitable for the given Display.
Definition: mythvrr.cpp:57
bool m_controllable
Definition: mythvrr.h:38
QString RangeDescription() const
Definition: mythvrr.cpp:134
VRRType m_type
Definition: mythvrr.h:39
QString TypeToString() const
Definition: mythvrr.cpp:122
bool IsControllable() const
Definition: mythvrr.cpp:117
static constexpr const char * DRM_QUIET
Definition: mythdrmdevice.h:23
std::tuple< int, int, bool > MythVRRRange
Definition: mythedid.h:19
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
#define LOC
Definition: mythvrr.cpp:20
std::shared_ptr< class MythVRR > MythVRRPtr
Definition: mythvrr.h:12
STL namespace.