MythTV  master
DisplayResScreen.h
Go to the documentation of this file.
1 #ifndef __DISPLAYRESCREEN_H__
2 #define __DISPLAYRESCREEN_H__
3 
4 #include <algorithm>
5 #include <cstdint> // for uint64_t
6 #include <map>
7 #include <vector>
8 
9 #include <QString>
10 
11 #include "mythuiexp.h"
12 
14 
15 typedef std::vector<DisplayResScreen> DisplayResVector;
16 typedef DisplayResVector::iterator DisplayResVectorIt;
17 typedef DisplayResVector::const_iterator DisplayResVectorCIt;
18 
19 typedef std::map<uint64_t, DisplayResScreen> DisplayResMap;
20 typedef DisplayResMap::iterator DisplayResMapIt;
21 typedef DisplayResMap::const_iterator DisplayResMapCIt;
22 
24 {
25  public:
26  // Constructors, initializers
27  DisplayResScreen() = default;
28  DisplayResScreen(int w, int h, int mw, int mh,
29  double aspectRatio/* = -1.0*/, double refreshRate/* = 0*/);
30  DisplayResScreen(int w, int h, int mw, int mh,
31  const std::vector<double>& refreshRates);
32  DisplayResScreen(int w, int h, int mw, int mh,
33  const std::vector<double>& refreshRates,
34  const std::map<double, short>& realrates);
35  DisplayResScreen(int w, int h, int mw, int mh,
36  const double* refreshRates, uint rr_length);
37  DisplayResScreen(int w, int h, int mw, int mh,
38  const short* refreshRates, uint rr_length);
39  explicit DisplayResScreen(const QString &str);
40  inline void Init();
41 
42  // Gets
43  int Width() const { return m_width; }
44  int Height() const { return m_height; }
45  int Width_mm() const { return m_width_mm; }
46  int Height_mm() const { return m_height_mm; }
47  bool Custom() const { return m_custom; }
48 
49  inline double AspectRatio() const;
50  inline double RefreshRate() const;
51  const std::vector<double>& RefreshRates() const { return m_refreshRates; }
52 
53  // Sets, adds
54  void SetAspectRatio(double a);
55  void AddRefreshRate(double rr)
56  {
57  m_refreshRates.push_back(rr);
58  std::sort(m_refreshRates.begin(), m_refreshRates.end());
59  }
60  void ClearRefreshRates(void) { m_refreshRates.clear(); }
61  void SetRefreshRate(double rr)
62  {
63  ClearRefreshRates();
64  AddRefreshRate(rr);
65  }
66 
67  void SetCustom(bool b) { m_custom = b; }
68 
69  // Map for matching real rates and xrandr rate;
70  std::map<double, short> realRates;
71 
72  // Converters & comparitors
73  QString toString() const;
74  inline bool operator < (const DisplayResScreen& b) const;
75  inline bool operator == (const DisplayResScreen &b) const;
76 
77  // Statics
78  static QStringList Convert(const DisplayResVector& dsr);
79  static DisplayResVector Convert(const QStringList& slist);
80  static int FindBestMatch(const DisplayResVector& dsr,
81  const DisplayResScreen& d,
82  double& target_rate);
83  static inline uint64_t CalcKey(int w, int h, double rate);
84  static bool compare_rates(double f1, double f2, double precision = 0.01);
85  static uint64_t FindBestScreen(const DisplayResMap& resmap,
86  int iwidth, int iheight, double frate);
87 
88  private:
89  int m_width {0}; // size in pixels
90  int m_height {0}; // size in pixels
91  int m_width_mm {0}; // physical size in millimeters
92  int m_height_mm {0}; // physical size in millimeters
93  double m_aspect {-1.0}; // aspect ratio, calculated or set
94  std::vector<double> m_refreshRates;
95  bool m_custom {false}; // Set if resolution was defined manually
96 };
97 
99 {
101  m_aspect = -1.0;
102 }
103 
104 inline double DisplayResScreen::AspectRatio() const
105 {
106  if (m_aspect<=0.0)
107  {
108  if (0 == m_height_mm)
109  return 1.0;
110  return ((double)(m_width_mm))/((double)(m_height_mm));
111  }
112  return m_aspect;
113 }
114 
115 inline double DisplayResScreen::RefreshRate() const
116 {
117  if (m_refreshRates.size() >= 1)
118  return m_refreshRates[0];
119  else return 0.0;
120 }
121 
123 {
124  if (m_width < b.m_width)
125  return true;
126  if (m_height < b.m_height)
127  return true;
128  return false;
129 }
130 
132 {
133  return m_width == b.m_width && m_height == b.m_height;
134 }
135 
136 inline uint64_t DisplayResScreen::CalcKey(int w, int h, double rate)
137 {
138  uint64_t irate = (uint64_t) (rate * 1000.0);
139  return ((uint64_t)w << 34) | ((uint64_t)h << 18) | irate;
140 }
141 
142 #endif // __DISPLAYRESCREEN_H__
double AspectRatio() const
QString toString(MarkTypes type)
bool Custom() const
void AddRefreshRate(double rr)
bool operator==(MusicMetadata &a, MusicMetadata &b)
DisplayResMap::const_iterator DisplayResMapCIt
unsigned int uint
Definition: compat.h:140
bool operator<(const ParentalLevel &lhs, const ParentalLevel &rhs)
int Height_mm() const
std::vector< double > m_refreshRates
unsigned char b
Definition: ParseText.cpp:329
int Width_mm() const
void ClearRefreshRates(void)
static const uint16_t * d
double RefreshRate() const
bool operator<(const DisplayResScreen &b) const
std::vector< DisplayResScreen > DisplayResVector
bool operator==(const DisplayResScreen &b) const
void SetRefreshRate(double rr)
DisplayResMap::iterator DisplayResMapIt
static uint64_t CalcKey(int w, int h, double rate)
std::map< uint64_t, DisplayResScreen > DisplayResMap
DisplayResVector::iterator DisplayResVectorIt
#define MUI_PUBLIC
Definition: mythuiexp.h:9
const std::vector< double > & RefreshRates() const
std::map< double, short > realRates
int Height() const
DisplayResVector::const_iterator DisplayResVectorCIt
void SetCustom(bool b)