MythTV  master
mythdrmcrtc.cpp
Go to the documentation of this file.
1 // MythTV
3 
10 DRMCrtc MythDRMCrtc::Create(int FD, uint32_t Id, int Index)
11 {
12  if (FD && Id)
13  if (auto crtc = std::shared_ptr<MythDRMCrtc>(new MythDRMCrtc(FD, Id, Index)); crtc.get() && crtc->m_id)
14  return crtc;
15 
16  return nullptr;
17 }
18 
19 DRMCrtc MythDRMCrtc::GetCrtc(const DRMCrtcs &Crtcs, uint32_t Id)
20 {
21  auto match = [&Id](const auto & Crtc) { return Crtc->m_id == Id; };
22  if (auto found = std::find_if(Crtcs.cbegin(), Crtcs.cend(), match); found != Crtcs.cend())
23  return *found;
24  return nullptr;
25 }
26 
28 {
29  DRMCrtcs result;
30  if (auto resources = MythDRMResources(FD); *resources)
31  {
32  for (auto i = 0; i < resources->count_crtcs; ++i)
33  if (auto crtc = Create(FD, resources->crtcs[i], i); crtc.get())
34  result.emplace_back(crtc);
35  }
36  return result;
37 }
38 
39 MythDRMCrtc::MythDRMCrtc(int FD, uint32_t Id, int Index)
40 {
41  if (auto * crtc = drmModeGetCrtc(FD, Id); crtc)
42  {
43  m_index = Index;
44  m_id = crtc->crtc_id;
45  m_fbId = crtc->buffer_id;
46  m_x = crtc->x;
47  m_y = crtc->y;
48  m_width = crtc->width;
49  m_height = crtc->height;
50  if (crtc->mode_valid)
51  m_mode = MythDRMMode::Create(&crtc->mode, 0);
52  m_properties = MythDRMProperty::GetProperties(FD, m_id, DRM_MODE_OBJECT_CRTC);
53  drmModeFreeCrtc(crtc);
54 
55  if (m_index < 0)
56  m_index = RetrieveCRTCIndex(FD, Id);
57  }
58 }
59 
60 int MythDRMCrtc::RetrieveCRTCIndex(int FD, uint32_t Id)
61 {
62  int result = -1;
63  if (auto resources = MythDRMResources(FD); *resources)
64  {
65  for (auto i = 0; i < resources->count_crtcs; ++i)
66  {
67  if (auto * crtc = drmModeGetCrtc(FD, resources->crtcs[i]); crtc)
68  {
69  bool match = crtc->crtc_id == Id;
70  drmModeFreeCrtc(crtc);
71  if (match)
72  {
73  result = i;
74  break;
75  }
76  }
77  }
78  }
79  return result;
80 }
MythDRMCrtc::GetCrtcs
static DRMCrtcs GetCrtcs(int FD)
Definition: mythdrmcrtc.cpp:27
MythDRMCrtc::RetrieveCRTCIndex
static int RetrieveCRTCIndex(int FD, uint32_t Id)
Definition: mythdrmcrtc.cpp:60
MythDRMCrtc::GetCrtc
static DRMCrtc GetCrtc(const DRMCrtcs &Crtcs, uint32_t Id)
Definition: mythdrmcrtc.cpp:19
DRMCrtc
std::shared_ptr< class MythDRMCrtc > DRMCrtc
Definition: mythdrmcrtc.h:8
MythDRMCrtc::m_properties
DRMProps m_properties
Definition: mythdrmcrtc.h:26
DRMCrtcs
std::vector< DRMCrtc > DRMCrtcs
Definition: mythdrmcrtc.h:9
MythDRMCrtc::m_id
uint32_t m_id
Definition: mythdrmcrtc.h:19
MythDRMResources
A simple wrapper around a drmModeResPtr that ensures proper cleanup.
Definition: mythdrmresources.h:24
MythDRMCrtc::MythDRMCrtc
MythDRMCrtc(int FD, uint32_t Id, int Index)
Definition: mythdrmcrtc.cpp:39
MythDRMCrtc::m_mode
DRMMode m_mode
Definition: mythdrmcrtc.h:21
MythDRMCrtc::m_height
uint32_t m_height
Definition: mythdrmcrtc.h:25
MythDRMCrtc::m_x
uint32_t m_x
Definition: mythdrmcrtc.h:22
MythDRMCrtc::m_fbId
uint32_t m_fbId
Definition: mythdrmcrtc.h:20
MythDRMMode::Create
static DRMMode Create(drmModeModeInfoPtr Mode, int Index)
Definition: mythdrmmode.cpp:7
MythDRMCrtc::m_index
int m_index
Definition: mythdrmcrtc.h:18
MythDRMCrtc::Create
static DRMCrtc Create(int FD, uint32_t Id, int Index=-1)
Definition: mythdrmcrtc.cpp:10
MythDRMCrtc::m_y
uint32_t m_y
Definition: mythdrmcrtc.h:23
mythdrmcrtc.h
MythDRMProperty::GetProperties
static DRMProps GetProperties(int FD, uint32_t ObjectId, uint32_t ObjectType)
Definition: mythdrmproperty.cpp:28
MythDRMCrtc::m_width
uint32_t m_width
Definition: mythdrmcrtc.h:24