kodi
DRMUtils.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "DRMConnector.h"
12 #include "DRMCrtc.h"
13 #include "DRMEncoder.h"
14 #include "DRMPlane.h"
15 #include "windowing/Resolution.h"
16 #include "windowing/gbm/GBMUtils.h"
17 
18 #include <utility>
19 #include <vector>
20 
21 #include <gbm.h>
22 #include <xf86drm.h>
23 
24 namespace KODI
25 {
26 namespace WINDOWING
27 {
28 namespace GBM
29 {
30 
31 struct drm_fb
32 {
33  struct gbm_bo *bo = nullptr;
34  uint32_t fb_id;
35  uint32_t format;
36 };
37 
38 class CDRMUtils
39 {
40 public:
41  CDRMUtils() = default;
42  virtual ~CDRMUtils();
43  virtual void FlipPage(struct gbm_bo* bo, bool rendered, bool videoLayer, bool async) {}
44  virtual bool SetVideoMode(const RESOLUTION_INFO& res, struct gbm_bo* bo) { return false; }
45  virtual bool SetActive(bool active) { return false; }
46  virtual bool InitDrm();
47  virtual void DestroyDrm();
48 
49  int GetFileDescriptor() const { return m_fd; }
50  int GetRenderNodeFileDescriptor() const { return m_renderFd; }
51  const char* GetRenderDevicePath() const { return m_renderDevicePath; }
52  CDRMPlane* GetVideoPlane() const { return m_video_plane; }
53  CDRMPlane* GetGuiPlane() const { return m_gui_plane; }
54  CDRMCrtc* GetCrtc() const { return m_crtc; }
55  CDRMConnector* GetConnector() const { return m_connector; }
56 
57  std::vector<std::string> GetConnectedConnectorNames();
58 
59  virtual RESOLUTION_INFO GetCurrentMode();
60  virtual std::vector<RESOLUTION_INFO> GetModes();
61  virtual bool SetMode(const RESOLUTION_INFO& res);
62 
63  static uint32_t FourCCWithAlpha(uint32_t fourcc);
64  static uint32_t FourCCWithoutAlpha(uint32_t fourcc);
65 
66  void SetInFenceFd(int fd) { m_inFenceFd = fd; }
67  int TakeOutFenceFd()
68  {
69  int fd{-1};
70  return std::exchange(m_outFenceFd, fd);
71  }
72 
73 protected:
74  bool OpenDrm(bool needConnector);
75  drm_fb* DrmFbGetFromBo(struct gbm_bo *bo);
76 
77  int m_fd;
78  CDRMConnector* m_connector{nullptr};
79  CDRMEncoder* m_encoder{nullptr};
80  CDRMCrtc* m_crtc{nullptr};
81  CDRMCrtc* m_orig_crtc{nullptr};
82  CDRMPlane* m_video_plane{nullptr};
83  CDRMPlane* m_gui_plane{nullptr};
84  drmModeModeInfo *m_mode = nullptr;
85 
86  int m_width = 0;
87  int m_height = 0;
88 
89  int m_inFenceFd{-1};
90  int m_outFenceFd{-1};
91 
92  std::vector<std::unique_ptr<CDRMPlane>> m_planes;
93 
94 private:
95  bool FindConnector();
96  bool FindEncoder();
97  bool FindCrtc();
98  bool FindPlanes();
99  bool FindPreferredMode();
100  bool RestoreOriginalMode();
101  RESOLUTION_INFO GetResolutionInfo(drmModeModeInfoPtr mode);
102  void PrintDrmDeviceInfo(drmDevicePtr device);
103 
104  int m_renderFd;
105  const char* m_renderDevicePath{nullptr};
106 
107  std::vector<std::unique_ptr<CDRMConnector>> m_connectors;
108  std::vector<std::unique_ptr<CDRMEncoder>> m_encoders;
109  std::vector<std::unique_ptr<CDRMCrtc>> m_crtcs;
110 };
111 
112 }
113 }
114 }
Definition: DRMUtils.h:31
Definition: DRMCrtc.h:20
Definition: DRMPlane.h:24
Provide info of a resolution.
Definition: Resolution.h:66
Definition: AudioDecoder.h:18
Definition: DRMEncoder.h:20
Definition: DRMConnector.h:22
Definition: DRMUtils.h:38