DmabufChannel.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #pragma once
  2. #include <array>
  3. #include <cstdint>
  4. #include <optional>
  5. namespace WallpaperEngine::WebBrowser::IPC {
  6. // one painted frame of the web host as dmabuf planes, passed over a unix socket with SCM_RIGHTS; the receiver owns the
  7. // descriptors and closes them
  8. struct DmabufFrame {
  9. static constexpr int MAX_PLANES = 4;
  10. uint32_t width = 0;
  11. uint32_t height = 0;
  12. // DRM fourcc of the buffer
  13. uint32_t fourcc = 0;
  14. uint64_t modifier = 0;
  15. int planeCount = 0;
  16. uint64_t sequence = 0;
  17. std::array<uint32_t, MAX_PLANES> stride {};
  18. std::array<uint64_t, MAX_PLANES> offset {};
  19. std::array<int, MAX_PLANES> fd { -1, -1, -1, -1 };
  20. void closeAll ();
  21. };
  22. // host side: sends a frame without blocking; false when the socket is full or gone (the frame is dropped, the
  23. // descriptors stay the caller's)
  24. bool sendDmabufFrame (int socket, const DmabufFrame& frame);
  25. // main side: drains the socket and keeps the newest frame, older ones are closed. nullopt when nothing arrived;
  26. // `closed` is set when the host's end is gone. Frames that don't fit maxWidth x maxHeight or lie about their planes
  27. // are dropped
  28. std::optional<DmabufFrame> receiveLatestDmabufFrame (int socket, uint32_t maxWidth, uint32_t maxHeight, bool& closed);
  29. // two connected non blocking, close-on-exec sockets; false on failure
  30. bool makeDmabufSocketPair (int& mainEnd, int& hostEnd);
  31. }