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