DisplayManager.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. //
  2. // DisplayManager.h
  3. // konvergo
  4. //
  5. // Created by Lionel CHAZALLON on 28/09/2014.
  6. //
  7. //
  8. #ifndef _DISPLAYMANAGER_H_
  9. #define _DISPLAYMANAGER_H_
  10. #include <QMap>
  11. #include <QPoint>
  12. #include <QString>
  13. #include <QSharedPointer>
  14. ///////////////////////////////////////////////////////////////////////////////////////////////////
  15. // Video Modes
  16. class DMVideoMode
  17. {
  18. public:
  19. int m_id;
  20. int m_width;
  21. int m_height;
  22. int m_bitsPerPixel;
  23. float m_refreshRate;
  24. bool m_interlaced;
  25. int m_privId;
  26. inline QString getPrettyName()
  27. {
  28. QString name;
  29. name = QString("%1 x%2%3").arg(m_width, 5).arg(m_height, 5).arg((m_interlaced ? "i" : " "));
  30. name += QString("x %1bpp @%2Hz").arg(m_bitsPerPixel, 2).arg(m_refreshRate);
  31. return name;
  32. }
  33. };
  34. typedef QSharedPointer<DMVideoMode> DMVideoModePtr;
  35. typedef QMap<int, DMVideoModePtr> DMVideoModeMap;
  36. ///////////////////////////////////////////////////////////////////////////////////////////////////
  37. // Displays
  38. class DMDisplay
  39. {
  40. public:
  41. int m_id;
  42. QString m_name;
  43. int m_privId;
  44. DMVideoModeMap m_videoModes;
  45. };
  46. typedef QSharedPointer<DMDisplay> DMDisplayPtr;
  47. typedef QMap<int, DMDisplayPtr> DMDisplayMap;
  48. ///////////////////////////////////////////////////////////////////////////////////////////////////
  49. // MatchMediaInfo
  50. class DMMatchMediaInfo
  51. {
  52. public:
  53. DMMatchMediaInfo() : m_refreshRate(0), m_interlaced(false) {};
  54. DMMatchMediaInfo(float refreshRate, bool interlaced)
  55. : m_refreshRate(refreshRate), m_interlaced(interlaced) {};
  56. float m_refreshRate;
  57. bool m_interlaced;
  58. };
  59. // Matching weights
  60. #define MATCH_WEIGHT_RES 1000
  61. #define MATCH_WEIGHT_REFRESH_RATE_EXACT 200
  62. #define MATCH_WEIGHT_REFRESH_RATE_MULTIPLE 75
  63. #define MATCH_WEIGHT_REFRESH_RATE_CLOSE 50
  64. #define MATCH_WEIGHT_REFRESH_RATE_MULTIPLE_CLOSE 25
  65. #define MATCH_WEIGHT_INTERLACE 10
  66. #define MATCH_WEIGHT_CURRENT 5
  67. ///////////////////////////////////////////////////////////////////////////////////////////////////
  68. // VideoMode Weight
  69. class DMVideoModeWeight
  70. {
  71. public:
  72. float m_weight;
  73. DMVideoModePtr m_mode;
  74. };
  75. typedef QSharedPointer<DMVideoModeWeight> DMVideoModeWeightPtr;
  76. typedef QMap<int, DMVideoModeWeightPtr> DMVideoModeWeightMap;
  77. ///////////////////////////////////////////////////////////////////////////////////////////////////
  78. // DisplayManager
  79. class DisplayManager : public QObject
  80. {
  81. Q_OBJECT
  82. public:
  83. explicit DisplayManager(QObject* parent);
  84. ~DisplayManager() override {}
  85. DMDisplayMap m_displays;
  86. // functions that should be implemented on each platform
  87. virtual bool initialize();
  88. virtual bool setDisplayMode(int display, int mode) = 0;
  89. virtual int getCurrentDisplayMode(int display) = 0;
  90. virtual int getMainDisplay() = 0;
  91. virtual int getDisplayFromPoint(int x, int y) = 0;
  92. // extra functions that can be implemented
  93. virtual void resetRendering() {}
  94. // other classes functions
  95. int findBestMatch(int display, DMMatchMediaInfo& matchInfo);
  96. DMVideoModePtr getCurrentVideoMode(int display);
  97. int findBestMode(int display);
  98. bool isValidDisplay(int display);
  99. bool isValidDisplayMode(int display, int mode);
  100. int getDisplayFromPoint(const QPoint& pt);
  101. private:
  102. bool isRateMultipleOf(float refresh, float multiple, bool exact = true);
  103. };
  104. typedef QSharedPointer<DisplayManager> DisplayManagerPtr;
  105. #endif /* _DISPLAYMANAGER_H_ */