WaylandOpenGLDriver.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #pragma once
  2. #ifdef ENABLE_WAYLAND
  3. #include <EGL/egl.h>
  4. #include <EGL/eglext.h>
  5. #include <GL/glew.h>
  6. #include <wayland-client.h>
  7. #include <wayland-cursor.h>
  8. #include <wayland-egl.h>
  9. #include "WallpaperEngine/Application/ApplicationContext.h"
  10. #include "WallpaperEngine/Application/WallpaperApplication.h"
  11. #include "WallpaperEngine/Input/Drivers/WaylandMouseInput.h"
  12. #include "WallpaperEngine/Render/Drivers/Detectors/WaylandFullScreenDetector.h"
  13. #include "WallpaperEngine/Render/Drivers/Output/WaylandOutput.h"
  14. #include "WallpaperEngine/Render/Drivers/Output/WaylandOutputViewport.h"
  15. #include "WallpaperEngine/Render/Drivers/VideoDriver.h"
  16. namespace WallpaperEngine::Application {
  17. class ApplicationContext;
  18. class WallpaperApplication;
  19. } // namespace WallpaperEngine::Application
  20. struct zwlr_layer_shell_v1;
  21. struct zwlr_layer_surface_v1;
  22. struct zxdg_output_manager_v1;
  23. struct wp_color_manager_v1;
  24. struct wp_image_description_v1;
  25. #ifdef ENABLE_KDE_FEATURES
  26. struct org_kde_plasma_shell;
  27. #endif
  28. namespace WallpaperEngine::Render::Drivers {
  29. using namespace WallpaperEngine::Application;
  30. using namespace WallpaperEngine::Input::Drivers;
  31. class WaylandOpenGLDriver;
  32. namespace Output {
  33. class WaylandOutputViewport;
  34. class WaylandOutput;
  35. } // namespace Output
  36. class WaylandOpenGLDriver final : public VideoDriver {
  37. friend class Output::WaylandOutput;
  38. friend class CWaylandMouseInput;
  39. public:
  40. struct SEGLContext {
  41. EGLDisplay display = nullptr;
  42. EGLConfig config = nullptr;
  43. EGLContext context = nullptr;
  44. PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC eglCreatePlatformWindowSurfaceEXT = nullptr;
  45. };
  46. struct WaylandContext {
  47. wl_display* display = nullptr;
  48. wl_registry* registry = nullptr;
  49. wl_compositor* compositor = nullptr;
  50. wl_shm* shm = nullptr;
  51. zwlr_layer_shell_v1* layerShell = nullptr;
  52. wl_seat* seat = nullptr;
  53. zxdg_output_manager_v1* xdgOutputManager = nullptr;
  54. /** Only bound with --hdr */
  55. wp_color_manager_v1* colorManager = nullptr;
  56. #ifdef ENABLE_KDE_FEATURES
  57. org_kde_plasma_shell* plasmaShell = nullptr;
  58. #endif
  59. };
  60. /** What wp_color_manager_v1 advertised, only these three matter for PQ output */
  61. struct ColorSupport {
  62. bool parametric = false;
  63. bool pq = false;
  64. bool bt2020 = false;
  65. };
  66. explicit WaylandOpenGLDriver (ApplicationContext& context, WallpaperApplication& app);
  67. ~WaylandOpenGLDriver ();
  68. [[nodiscard]] Output::Output& getOutput () override;
  69. float getRenderTime () const override;
  70. bool closeRequested () override;
  71. void resizeWindow (glm::ivec2 size) override;
  72. void resizeWindow (glm::ivec4 sizeandpos) override;
  73. void showWindow () override;
  74. void hideWindow () override;
  75. glm::ivec2 getFramebufferSize () const override;
  76. uint32_t getFrameCounter () const override;
  77. void dispatchEventQueue () override;
  78. [[nodiscard]] void* getProcAddress (const char* name) const override;
  79. [[nodiscard]] void* getWaylandDisplay () const override;
  80. [[nodiscard]] bool isHDRAvailable () const override;
  81. /** PQ with BT.2020 primaries (and the PQ default luminances, 203 nits reference white), shared by every HDR surface
  82. */
  83. [[nodiscard]] wp_image_description_v1* getHDRDescription () const;
  84. void onLayerClose (Output::WaylandOutputViewport*);
  85. Output::WaylandOutputViewport* surfaceToViewport (const wl_surface*) const;
  86. Output::WaylandOutputViewport* viewportInFocus = nullptr;
  87. [[nodiscard]] SEGLContext* getEGLContext ();
  88. [[nodiscard]] WaylandContext* getWaylandContext ();
  89. std::vector<Output::WaylandOutputViewport*> m_screens = {};
  90. ColorSupport colorSupport = {};
  91. bool hdrDescriptionReady = false;
  92. private:
  93. Output::WaylandOutput m_output;
  94. SEGLContext m_eglContext = {};
  95. WaylandContext m_waylandContext = {};
  96. mutable bool m_requestedExit;
  97. void initWaylandRegistry ();
  98. void setupOutputLayerSurfaces ();
  99. void initEGL ();
  100. void initGLEW ();
  101. void finishEGL () const;
  102. void initColorManagement ();
  103. wp_image_description_v1* m_hdrDescription = nullptr;
  104. uint32_t m_frameCounter = 0;
  105. ApplicationContext& m_context;
  106. WaylandMouseInput m_mouseInput;
  107. std::chrono::high_resolution_clock::time_point renderStart = std::chrono::high_resolution_clock::now ();
  108. };
  109. } // namespace WallpaperEngine::Render::Drivers
  110. #endif /* ENABLE_WAYLAND */