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