CWaylandOpenGLDriver.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #ifdef ENABLE_WAYLAND
  2. #pragma once
  3. #include <wayland-client.h>
  4. #include <wayland-cursor.h>
  5. #include <wayland-egl.h>
  6. #include <EGL/egl.h>
  7. #include <EGL/eglext.h>
  8. #include <GL/glew.h>
  9. #include "WallpaperEngine/Render/Drivers/CVideoDriver.h"
  10. #include "WallpaperEngine/Application/CApplicationContext.h"
  11. #include "WallpaperEngine/Application/CWallpaperApplication.h"
  12. #include "WallpaperEngine/Render/Drivers/Detectors/CWaylandFullScreenDetector.h"
  13. #include "WallpaperEngine/Render/Drivers/Output/CWaylandOutputViewport.h"
  14. #include "WallpaperEngine/Render/Drivers/Output/CWaylandOutput.h"
  15. namespace WallpaperEngine::Application
  16. {
  17. class CApplicationContext;
  18. class CWallpaperApplication;
  19. }
  20. namespace WallpaperEngine::Input::Drivers
  21. {
  22. class CWaylandMouseInput;
  23. }
  24. struct zwlr_layer_shell_v1;
  25. struct zwlr_layer_surface_v1;
  26. namespace WallpaperEngine::Render::Drivers
  27. {
  28. using namespace WallpaperEngine::Application;
  29. using namespace WallpaperEngine::Input::Drivers;
  30. class CWaylandOpenGLDriver;
  31. namespace Output
  32. {
  33. class CWaylandOutputViewport;
  34. class CWaylandOutput;
  35. }
  36. class CWaylandOpenGLDriver : public CVideoDriver
  37. {
  38. friend class Output::CWaylandOutput;
  39. friend class CWaylandMouseInput;
  40. public:
  41. struct SEGLContext
  42. {
  43. EGLDisplay display = nullptr;
  44. EGLConfig config = nullptr;
  45. EGLContext context = nullptr;
  46. PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC eglCreatePlatformWindowSurfaceEXT = nullptr;
  47. };
  48. struct SWaylandContext
  49. {
  50. wl_display* display = nullptr;
  51. wl_registry* registry = nullptr;
  52. wl_compositor* compositor = nullptr;
  53. wl_shm* shm = nullptr;
  54. zwlr_layer_shell_v1* layerShell = nullptr;
  55. wl_seat* seat = nullptr;
  56. };
  57. explicit CWaylandOpenGLDriver (CApplicationContext& context, CWallpaperApplication& app);
  58. ~CWaylandOpenGLDriver();
  59. [[nodiscard]] Detectors::CFullScreenDetector& getFullscreenDetector () override;
  60. [[nodiscard]] Output::COutput& getOutput () override;
  61. float getRenderTime () const override;
  62. bool closeRequested () override;
  63. void resizeWindow (glm::ivec2 size) override;
  64. void resizeWindow (glm::ivec4 sizeandpos) override;
  65. void showWindow () override;
  66. void hideWindow () override;
  67. glm::ivec2 getFramebufferSize () const override;
  68. uint32_t getFrameCounter () const override;
  69. void dispatchEventQueue() override;
  70. [[nodiscard]] void* getProcAddress (const char* name) const override;
  71. void onLayerClose(Output::CWaylandOutputViewport*);
  72. Output::CWaylandOutputViewport* surfaceToViewport(wl_surface*);
  73. Output::CWaylandOutputViewport* viewportInFocus = nullptr;
  74. [[nodiscard]] SEGLContext* getEGLContext ();
  75. [[nodiscard]] SWaylandContext* getWaylandContext ();
  76. /** List of available screens */
  77. std::vector <Output::CWaylandOutputViewport*> m_screens;
  78. private:
  79. /** Fullscreen detection used by this driver */
  80. Detectors::CWaylandFullScreenDetector m_fullscreenDetector;
  81. /** The output used by the driver */
  82. Output::CWaylandOutput m_output;
  83. /** The EGL context in use */
  84. SEGLContext m_eglContext;
  85. /** The Wayland context in use */
  86. SWaylandContext m_waylandContext;
  87. mutable bool m_requestedExit;
  88. void initEGL();
  89. void finishEGL();
  90. uint32_t m_frameCounter;
  91. CApplicationContext& m_context;
  92. std::chrono::high_resolution_clock::time_point renderStart = std::chrono::high_resolution_clock::now();
  93. };
  94. }
  95. #endif /* ENABLE_WAYLAND */