MythTV master
mythdrmvrr.cpp
Go to the documentation of this file.
1// MythTV
2#include "mythdrmvrr.h"
4
5#define LOC QString("FreeSync: ")
6
10{
11 if (!(Device && Device->Authenticated() && Device->GetCrtc()))
12 return;
13
14 auto freesync = CreateFreeSync(Device, {0,0,false});
15 if (!freesync)
16 {
17 LOG(VB_GENERAL, LOG_INFO, LOC + "No FreeSync support detected - cannot force");
18 return;
19 }
20
21 if (freesync->Enabled() == Enable)
22 {
23 LOG(VB_GENERAL, LOG_INFO, LOC + QString("FreeSync already %1abled")
24 .arg(Enable ? "en" : "dis"));
25 return;
26 }
27
28 if (!freesync->IsControllable())
29 {
30 LOG(VB_GENERAL, LOG_INFO, LOC + QString("Cannot %1able FreeSync - do not have permission")
31 .arg(Enable ? "en" : "dis"));
32 return;
33 }
34
35 auto * freesync2 = dynamic_cast<MythDRMVRR*>(freesync.get());
36 if (!freesync2)
37 return;
38
39 // We have no Qt QPA plugin at this point, so no atomic modesetting etc etc.
40 // Just try and enable the property directly.
41 if (drmModeObjectSetProperty(Device->GetFD(), Device->GetCrtc()->m_id,
42 DRM_MODE_OBJECT_CRTC, freesync2->GetVRRProperty()->m_id, Enable ? 1 : 0) == 0)
43 {
44 // Release freesync now so that it doesn't reset the state on deletion
45 freesync = nullptr;
46 s_freeSyncDefaultValue = !Enable;
48 LOG(VB_GENERAL, LOG_INFO, LOC + (Enable ? "Enabled" : "Disabled"));
49 }
50 else
51 {
52 LOG(VB_GENERAL, LOG_ERR, LOC + "Error setting FreeSync");
53 }
54}
55
57{
58 if (!(Device && Device->GetConnector() && Device->GetCrtc()))
59 return nullptr;
60
61 auto connector = Device->GetConnector();
62 auto capable = MythDRMProperty::GetProperty("VRR_CAPABLE", connector->m_properties);
63 if (!capable)
64 return nullptr;
65 auto * capableval = dynamic_cast<MythDRMRangeProperty*>(capable.get());
66 if (!capableval || capableval->m_value < 1)
67 return nullptr;
68
69 auto crtc = Device->GetCrtc();
70 auto enabled = MythDRMProperty::GetProperty("VRR_ENABLED", crtc->m_properties);
71 if (!enabled)
72 return nullptr;
73 auto * enabledval = dynamic_cast<MythDRMRangeProperty*>(enabled.get());
74 if (!enabledval)
75 return nullptr;
76
77 // We have a valid device with VRR_CAPABLE property (connector) and VRR_ENABLED
78 // property (CRTC). Now check whether it is enabled and whether we can control it.
79 bool isenabled = enabledval->m_value > 0;
80 bool controllable = Device->Atomic() && Device->Authenticated();
81 return std::shared_ptr<MythVRR>(new MythDRMVRR(Device, enabled, controllable, isenabled, Range));
82}
83
98MythDRMVRR::MythDRMVRR(MythDRMPtr Device, DRMProp VRRProp, bool Controllable,
99 bool Enabled, MythVRRRange Range)
100 : MythVRR(Controllable, FreeSync, Enabled, Range),
101 m_device(std::move(Device)),
102 m_vrrProp(std::move(VRRProp))
103{
104}
105
107{
109 {
110 if (m_controllable)
111 {
112 LOG(VB_GENERAL, LOG_INFO, LOC + "Resetting FreeSync to desktop default");
114 }
115 s_freeSyncResetOnExit = false;
116 }
117}
118
119void MythDRMVRR::SetEnabled(bool Enable)
120{
121#if CONFIG_QTPRIVATEHEADERS
122 if (m_device && m_vrrProp && m_device->GetCrtc() &&
123 m_device->QueueAtomics({{ m_device->GetCrtc()->m_id, m_vrrProp->m_id, Enable ? 1 : 0 }}))
124#endif
125 {
126 m_enabled = Enable;
127 LOG(VB_GENERAL, LOG_INFO, LOC + (Enable ? "Enabled" : "Disabled"));
128 }
129}
130
132{
133 return m_vrrProp;
134}
A device containing images (ie. USB stick, CD, storage group etc)
static DRMProp GetProperty(const QString &Name, const DRMProps &Properties)
A wrapper around FreeSync/Adaptive-Sync support.
Definition: mythdrmvrr.h:9
static void ForceFreeSync(const MythDRMPtr &Device, bool Enable)
Force FreeSync on or off before the main app is started.
Definition: mythdrmvrr.cpp:9
void SetEnabled(bool Enable=true) override
Definition: mythdrmvrr.cpp:119
static MythVRRPtr CreateFreeSync(const MythDRMPtr &Device, MythVRRRange Range)
Definition: mythdrmvrr.cpp:56
MythDRMPtr m_device
Definition: mythdrmvrr.h:26
DRMProp m_vrrProp
Definition: mythdrmvrr.h:27
MythDRMVRR(MythDRMPtr Device, DRMProp VRRProp, bool Controllable, bool Enabled, MythVRRRange Range)
Definition: mythdrmvrr.cpp:98
static bool s_freeSyncDefaultValue
Definition: mythdrmvrr.h:12
static bool s_freeSyncResetOnExit
Definition: mythdrmvrr.h:11
~MythDRMVRR() override
Definition: mythdrmvrr.cpp:106
DRMProp GetVRRProperty()
Definition: mythdrmvrr.cpp:131
bool m_controllable
Definition: mythvrr.h:38
std::shared_ptr< class MythDRMDevice > MythDRMPtr
Definition: mythdrmdevice.h:19
std::shared_ptr< class MythDRMProperty > DRMProp
#define LOC
Definition: mythdrmvrr.cpp:5
std::tuple< int, int, bool > MythVRRRange
Definition: mythedid.h:19
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
std::shared_ptr< class MythVRR > MythVRRPtr
Definition: mythvrr.h:12
STL namespace.