#pragma once #include #include #include namespace WallpaperEngine::WebBrowser::IPC { // one painted frame of the web host as dmabuf planes, passed over a unix socket with SCM_RIGHTS; the receiver owns the // descriptors and closes them struct DmabufFrame { static constexpr int MAX_PLANES = 4; uint32_t width = 0; uint32_t height = 0; // DRM fourcc of the buffer uint32_t fourcc = 0; uint64_t modifier = 0; int planeCount = 0; uint64_t sequence = 0; std::array stride {}; std::array offset {}; std::array fd { -1, -1, -1, -1 }; void closeAll (); }; // host side: sends a frame without blocking; false when the socket is full or gone (the frame is dropped, the // descriptors stay the caller's) bool sendDmabufFrame (int socket, const DmabufFrame& frame); // main side: drains the socket and keeps the newest frame, older ones are closed. nullopt when nothing arrived; // `closed` is set when the host's end is gone. Frames that don't fit maxWidth x maxHeight or lie about their planes // are dropped std::optional receiveLatestDmabufFrame (int socket, uint32_t maxWidth, uint32_t maxHeight, bool& closed); // two connected non blocking, close-on-exec sockets; false on failure bool makeDmabufSocketPair (int& mainEnd, int& hostEnd); }