video.hpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. struct Video;
  2. struct VideoDriver {
  3. VideoDriver(Video& super) : super(super) {}
  4. virtual ~VideoDriver() = default;
  5. virtual auto create() -> bool { return true; }
  6. virtual auto driver() -> string { return "None"; }
  7. virtual auto ready() -> bool { return true; }
  8. virtual auto hasFullScreen() -> bool { return false; }
  9. virtual auto hasMonitor() -> bool { return false; }
  10. virtual auto hasExclusive() -> bool { return false; }
  11. virtual auto hasContext() -> bool { return false; }
  12. virtual auto hasBlocking() -> bool { return false; }
  13. virtual auto hasFlush() -> bool { return false; }
  14. virtual auto hasFormats() -> vector<string> { return {"ARGB24"}; }
  15. virtual auto hasShader() -> bool { return false; }
  16. auto hasFormat(string format) -> bool { return (bool)hasFormats().find(format); }
  17. virtual auto setFullScreen(bool fullScreen) -> bool { return true; }
  18. virtual auto setMonitor(string monitor) -> bool { return true; }
  19. virtual auto setExclusive(bool exclusive) -> bool { return true; }
  20. virtual auto setContext(uintptr context) -> bool { return true; }
  21. virtual auto setBlocking(bool blocking) -> bool { return true; }
  22. virtual auto setFlush(bool flush) -> bool { return true; }
  23. virtual auto setFormat(string format) -> bool { return true; }
  24. virtual auto setShader(string shader) -> bool { return true; }
  25. virtual auto focused() -> bool { return true; }
  26. virtual auto clear() -> void {}
  27. virtual auto size(uint& width, uint& height) -> void {}
  28. virtual auto acquire(uint32_t*& data, uint& pitch, uint width, uint height) -> bool { return false; }
  29. virtual auto release() -> void {}
  30. virtual auto output(uint width = 0, uint height = 0) -> void {}
  31. virtual auto poll() -> void {}
  32. protected:
  33. Video& super;
  34. friend class Video;
  35. bool fullScreen = false;
  36. string monitor = "Primary";
  37. bool exclusive = false;
  38. uintptr context = 0;
  39. bool blocking = false;
  40. bool flush = false;
  41. string format = "ARGB24";
  42. string shader = "Blur";
  43. };
  44. struct Video {
  45. static auto hasDrivers() -> vector<string>;
  46. static auto hasDriver(string driver) -> bool { return (bool)hasDrivers().find(driver); }
  47. static auto optimalDriver() -> string;
  48. static auto safestDriver() -> string;
  49. struct Monitor {
  50. string name;
  51. bool primary = false;
  52. int x = 0;
  53. int y = 0;
  54. int width = 0;
  55. int height = 0;
  56. };
  57. static auto monitor(string name) -> Monitor;
  58. static auto hasMonitors() -> vector<Monitor>;
  59. static auto hasMonitor(string name) -> bool {
  60. for(auto& monitor : hasMonitors()) {
  61. if(monitor.name == name) return true;
  62. }
  63. return false;
  64. }
  65. Video() : self(*this) { reset(); }
  66. explicit operator bool() { return instance->driver() != "None"; }
  67. auto reset() -> void { instance = new VideoDriver(*this); }
  68. auto create(string driver = "") -> bool;
  69. auto driver() -> string { return instance->driver(); }
  70. auto ready() -> bool { return instance->ready(); }
  71. auto hasFullScreen() -> bool { return instance->hasFullScreen(); }
  72. auto hasMonitor() -> bool { return instance->hasMonitor(); }
  73. auto hasExclusive() -> bool { return instance->hasExclusive(); }
  74. auto hasContext() -> bool { return instance->hasContext(); }
  75. auto hasBlocking() -> bool { return instance->hasBlocking(); }
  76. auto hasFlush() -> bool { return instance->hasFlush(); }
  77. auto hasFormats() -> vector<string> { return instance->hasFormats(); }
  78. auto hasShader() -> bool { return instance->hasShader(); }
  79. auto hasFormat(string format) -> bool { return instance->hasFormat(format); }
  80. auto fullScreen() -> bool { return instance->fullScreen; }
  81. auto monitor() -> string { return instance->monitor; }
  82. auto exclusive() -> bool { return instance->exclusive; }
  83. auto context() -> uintptr { return instance->context; }
  84. auto blocking() -> bool { return instance->blocking; }
  85. auto flush() -> bool { return instance->flush; }
  86. auto format() -> string { return instance->format; }
  87. auto shader() -> string { return instance->shader; }
  88. auto setMonitor(string monitor) -> bool;
  89. auto setFullScreen(bool fullScreen) -> bool;
  90. auto setExclusive(bool exclusive) -> bool;
  91. auto setContext(uintptr context) -> bool;
  92. auto setBlocking(bool blocking) -> bool;
  93. auto setFlush(bool flush) -> bool;
  94. auto setFormat(string format) -> bool;
  95. auto setShader(string shader) -> bool;
  96. auto focused() -> bool;
  97. auto clear() -> void;
  98. struct Size {
  99. uint width = 0;
  100. uint height = 0;
  101. };
  102. auto size() -> Size;
  103. struct Acquire {
  104. explicit operator bool() const { return data; }
  105. uint32_t* data = nullptr;
  106. uint pitch = 0;
  107. };
  108. auto acquire(uint width, uint height) -> Acquire;
  109. auto release() -> void;
  110. auto output(uint width = 0, uint height = 0) -> void;
  111. auto poll() -> void;
  112. auto onUpdate(const function<void (uint, uint)>&) -> void;
  113. auto doUpdate(uint width, uint height) -> void;
  114. protected:
  115. Video& self;
  116. unique_pointer<VideoDriver> instance;
  117. function<void (uint, uint)> update;
  118. };