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