2024-06-08 10:07:59 +02:00
|
|
|
#include "LinuxDMABUF.hpp"
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
#include <set>
|
|
|
|
|
#include <tuple>
|
|
|
|
|
#include "../helpers/MiscFunctions.hpp"
|
|
|
|
|
#include <sys/mman.h>
|
|
|
|
|
#include <xf86drm.h>
|
|
|
|
|
#include <fcntl.h>
|
2024-07-21 13:09:54 +02:00
|
|
|
#include <sys/stat.h>
|
2024-06-08 10:07:59 +02:00
|
|
|
#include "core/Compositor.hpp"
|
|
|
|
|
#include "types/DMABuffer.hpp"
|
|
|
|
|
#include "types/WLBuffer.hpp"
|
|
|
|
|
#include "../managers/HookSystemManager.hpp"
|
|
|
|
|
#include "../render/OpenGL.hpp"
|
|
|
|
|
#include "../Compositor.hpp"
|
|
|
|
|
|
2025-01-30 12:30:12 +01:00
|
|
|
using namespace Hyprutils::OS;
|
|
|
|
|
|
2024-06-08 10:07:59 +02:00
|
|
|
static std::optional<dev_t> devIDFromFD(int fd) {
|
|
|
|
|
struct stat stat;
|
|
|
|
|
if (fstat(fd, &stat) != 0)
|
|
|
|
|
return {};
|
|
|
|
|
return stat.st_rdev;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-26 02:06:13 +01:00
|
|
|
CDMABUFFormatTable::CDMABUFFormatTable(SDMABUFTranche _rendererTranche, std::vector<std::pair<PHLMONITORREF, SDMABUFTranche>> tranches_) :
|
2025-05-04 00:13:29 +02:00
|
|
|
m_rendererTranche(_rendererTranche), m_monitorTranches(tranches_) {
|
2024-07-21 13:09:54 +02:00
|
|
|
|
|
|
|
|
std::vector<SDMABUFFormatTableEntry> formatsVec;
|
2024-06-08 10:07:59 +02:00
|
|
|
std::set<std::pair<uint32_t, uint64_t>> formats;
|
2024-07-21 13:09:54 +02:00
|
|
|
|
|
|
|
|
// insert formats into vec if they got inserted into set, meaning they're unique
|
|
|
|
|
size_t i = 0;
|
|
|
|
|
|
2025-07-25 15:19:23 +00:00
|
|
|
m_rendererTranche.indices.clear();
|
2025-05-04 00:13:29 +02:00
|
|
|
for (auto const& fmt : m_rendererTranche.formats) {
|
2024-08-26 20:24:30 +02:00
|
|
|
for (auto const& mod : fmt.modifiers) {
|
2024-07-21 13:09:54 +02:00
|
|
|
auto format = std::make_pair<>(fmt.drmFormat, mod);
|
|
|
|
|
auto [_, inserted] = formats.insert(format);
|
|
|
|
|
if (inserted) {
|
|
|
|
|
// if it was inserted into set, then its unique and will have a new index in vec
|
2025-07-25 15:19:23 +00:00
|
|
|
m_rendererTranche.indices.push_back(i++);
|
2024-07-21 13:09:54 +02:00
|
|
|
formatsVec.push_back(SDMABUFFormatTableEntry{
|
|
|
|
|
.fmt = fmt.drmFormat,
|
|
|
|
|
.modifier = mod,
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
// if it wasn't inserted then find its index in vec
|
2025-05-30 18:25:59 +05:00
|
|
|
auto it = std::ranges::find_if(formatsVec, [fmt, mod](const SDMABUFFormatTableEntry& oth) { return oth.fmt == fmt.drmFormat && oth.modifier == mod; });
|
2025-07-25 15:19:23 +00:00
|
|
|
m_rendererTranche.indices.push_back(it - formatsVec.begin());
|
2024-06-08 10:07:59 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
for (auto& [monitor, tranche] : m_monitorTranches) {
|
2025-07-25 15:19:23 +00:00
|
|
|
tranche.indices.clear();
|
2024-08-26 20:24:30 +02:00
|
|
|
for (auto const& fmt : tranche.formats) {
|
|
|
|
|
for (auto const& mod : fmt.modifiers) {
|
2025-07-25 15:19:23 +00:00
|
|
|
// apparently these can implode on planes, so don't use them
|
2024-07-21 13:09:54 +02:00
|
|
|
if (mod == DRM_FORMAT_MOD_INVALID || mod == DRM_FORMAT_MOD_LINEAR)
|
|
|
|
|
continue;
|
|
|
|
|
auto format = std::make_pair<>(fmt.drmFormat, mod);
|
|
|
|
|
auto [_, inserted] = formats.insert(format);
|
|
|
|
|
if (inserted) {
|
2025-07-25 15:19:23 +00:00
|
|
|
tranche.indices.push_back(i++);
|
2024-07-21 13:09:54 +02:00
|
|
|
formatsVec.push_back(SDMABUFFormatTableEntry{
|
|
|
|
|
.fmt = fmt.drmFormat,
|
|
|
|
|
.modifier = mod,
|
|
|
|
|
});
|
|
|
|
|
} else {
|
2025-05-30 18:25:59 +05:00
|
|
|
auto it = std::ranges::find_if(formatsVec, [fmt, mod](const SDMABUFFormatTableEntry& oth) { return oth.fmt == fmt.drmFormat && oth.modifier == mod; });
|
2025-07-25 15:19:23 +00:00
|
|
|
tranche.indices.push_back(it - formatsVec.begin());
|
2024-07-21 13:09:54 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
m_tableSize = formatsVec.size() * sizeof(SDMABUFFormatTableEntry);
|
2024-07-21 13:09:54 +02:00
|
|
|
|
2025-01-30 12:30:12 +01:00
|
|
|
CFileDescriptor fds[2];
|
2025-05-04 00:13:29 +02:00
|
|
|
allocateSHMFilePair(m_tableSize, fds[0], fds[1]);
|
2024-06-08 10:07:59 +02:00
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
auto arr = (SDMABUFFormatTableEntry*)mmap(nullptr, m_tableSize, PROT_READ | PROT_WRITE, MAP_SHARED, fds[0].get(), 0);
|
2024-06-08 10:07:59 +02:00
|
|
|
|
2024-06-10 20:31:03 +00:00
|
|
|
if (arr == MAP_FAILED) {
|
2024-06-08 10:07:59 +02:00
|
|
|
LOGM(ERR, "mmap failed");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-30 18:25:59 +05:00
|
|
|
std::ranges::copy(formatsVec, arr);
|
2024-06-08 10:07:59 +02:00
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
munmap(arr, m_tableSize);
|
2024-06-08 10:07:59 +02:00
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
m_tableFD = std::move(fds[1]);
|
2024-06-08 10:07:59 +02:00
|
|
|
}
|
|
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
CLinuxDMABuffer::CLinuxDMABuffer(uint32_t id, wl_client* client, Aquamarine::SDMABUFAttrs attrs) {
|
2025-05-04 00:13:29 +02:00
|
|
|
m_buffer = makeShared<CDMABuffer>(id, client, attrs);
|
2024-06-08 10:07:59 +02:00
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
m_buffer->m_resource->m_buffer = m_buffer;
|
2024-06-08 10:07:59 +02:00
|
|
|
|
2025-07-08 09:56:40 -07:00
|
|
|
m_listeners.bufferResourceDestroy = m_buffer->events.destroy.listen([this] {
|
2025-05-04 00:13:29 +02:00
|
|
|
m_listeners.bufferResourceDestroy.reset();
|
2024-06-08 10:07:59 +02:00
|
|
|
PROTO::linuxDma->destroyResource(this);
|
|
|
|
|
});
|
|
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
if (!m_buffer->m_success)
|
2024-06-08 10:07:59 +02:00
|
|
|
LOGM(ERR, "Possibly compositor bug: buffer failed to create");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CLinuxDMABuffer::~CLinuxDMABuffer() {
|
2025-05-04 00:13:29 +02:00
|
|
|
if (m_buffer && m_buffer->m_resource)
|
|
|
|
|
m_buffer->m_resource->sendRelease();
|
syncobj: use eventfd instead of stalling fd checks (#9437)
* syncobj: cleanup and use uniqueptrs
cleanup a bit missing removals if resource not good, erasing from
containers etc. make use of unique ptrs instead. and add default
destructors.
* syncobj: rework syncobj entirerly
remove early buffer release that was breaking explicit sync, the buffer
needs to exist until the surface commit event has been emitted and draw
calls added egl sync points, move to eventfd signaling instead of
stalling sync point checks, and recommit pending commits if waiting on a
signal. add a CDRMSyncPointState helper class. move a few weak pointers
to shared pointers so they dont destruct before we need to use them.
* syncobj: queue pending states for eventfd
eventfd requires us to queue pending stats until ready and then apply to
current, and also when no ready state exist commit the client commit on
the current existing buffer, if there is one.
* syncobj: clear current buffer damage
clear current buffer damage on current buffer commits.
* syncobj: cleanup code and fix hyprlock
remove unused code, and ensure we dont commit a empty texture causing
locksession protocol and gtk4-layer-shell misbehaving.
* syncobj: ensure buffers are cleaned up
ensure the containers having the various buffers actually gets cleaned
up from their containers, incase the CSignal isnt signaled because of
expired smart pointers or just wrong order destruction because mishaps.
also move the acquire/point setting to buffer attaching. instead of on
precommit.
* syncobj: remove unused code, optimize
remove unused code and merge sync fds if fence is valid, remove manual
directscanout buffer dropping that signals release point on pageflip, it
can cause us to signal the release point while still keeping the current
buffer and rendering it yet again causing wrong things.
* syncobj: delay buffer release on non syncobj
delay buffer releases on non syncobj surfaces until next commit, and
check on async buffers if syncobj and drop and signal the release point
on backend buffer release.
* syncobj: ensure we follow protocol
ensure we follow protocol by replacing acquire/release points if they
arrive late and replace already existing ones. also remove unneded
brackets, and dont try to manual lock/release buffers when it comes to
explicit protocol. it doesnt care about buffer releases only about
acquire and release points and signaling them.
* syncobj: lets not complicate things
set points in precommit, before checking protocol errors and we catch
any pending acquire/release points arriving late.
* syncobj: move SSurfaceState to types
remove destructor resource destroying, let resources destroys them on
their events, and move SSurfaceStates to types/SurfaceState.hpp
* syncobj: actually store the merged fd
have to actually store the mergedfd to use it.
* syncobj: cleanup a bit around fences
ensure the current asynchronous buffer is actually released on pageflip
not the previous. cleanup a bit FD handling in
commitPendingAndDoExplicitSync, and reuse the in fence when syncing
surfaces.
* syncobjs: ensure fence FD doesnt leak
calling resetexplicitfence without properly ensuring the FD is closed
before will leak it, store it per monitor and let it close itself with
the CFileDescriptor class.
* syncobj: ensure buffers are actually released
buffers were never being sent released properly.
* types: Defer buffer sync releaser until unlock
* syncobj: store directscanout fence in monitor
ensure the infence fd survives the scope of attemptdirectscanout so it
doesnt close before it should have.
* syncobj: check if if acquire is expired
we might hit a race to finish on exit where the timeline just has
destructed but the buffer waiter is still pending. and such we
removeAllWaiters null dereferences.
* syncobj: code style changes
remove quack comment, change to m_foo and use a std::vector and
weakpointer in the waiter for removal instead of a std::list.
* syncobj: remove unused async buffer drop
remove unused async buffer drop, only related to directscanout and is
handled elsewhere.
---------
Co-authored-by: Lee Bousfield <ljbousfield@gmail.com>
2025-03-14 15:08:20 +01:00
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
m_buffer.reset();
|
|
|
|
|
m_listeners.bufferResourceDestroy.reset();
|
2024-06-08 10:07:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CLinuxDMABuffer::good() {
|
2025-05-04 00:13:29 +02:00
|
|
|
return m_buffer && m_buffer->good();
|
2024-06-08 10:07:59 +02:00
|
|
|
}
|
|
|
|
|
|
2025-07-10 13:07:44 +02:00
|
|
|
CLinuxDMABUFParamsResource::CLinuxDMABUFParamsResource(UP<CZwpLinuxBufferParamsV1>&& resource_) : m_resource(std::move(resource_)) {
|
2025-01-17 18:21:34 +01:00
|
|
|
if UNLIKELY (!good())
|
2024-06-08 10:07:59 +02:00
|
|
|
return;
|
|
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
m_resource->setOnDestroy([this](CZwpLinuxBufferParamsV1* r) { PROTO::linuxDma->destroyResource(this); });
|
|
|
|
|
m_resource->setDestroy([this](CZwpLinuxBufferParamsV1* r) { PROTO::linuxDma->destroyResource(this); });
|
2024-06-08 10:07:59 +02:00
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
m_attrs = makeShared<Aquamarine::SDMABUFAttrs>();
|
2024-06-08 10:07:59 +02:00
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
m_attrs->success = true;
|
2024-06-08 10:07:59 +02:00
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
m_resource->setAdd([this](CZwpLinuxBufferParamsV1* r, int32_t fd, uint32_t plane, uint32_t offset, uint32_t stride, uint32_t modHi, uint32_t modLo) {
|
|
|
|
|
if (m_used) {
|
2024-06-08 10:07:59 +02:00
|
|
|
r->error(ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_ALREADY_USED, "Already used");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (plane > 3) {
|
|
|
|
|
r->error(ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_PLANE_IDX, "plane > 3");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
if (m_attrs->fds.at(plane) != -1) {
|
2024-06-08 10:07:59 +02:00
|
|
|
r->error(ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_PLANE_IDX, "plane used");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
m_attrs->fds[plane] = fd;
|
|
|
|
|
m_attrs->strides[plane] = stride;
|
|
|
|
|
m_attrs->offsets[plane] = offset;
|
|
|
|
|
m_attrs->modifier = ((uint64_t)modHi << 32) | modLo;
|
2024-06-08 10:07:59 +02:00
|
|
|
});
|
|
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
m_resource->setCreate([this](CZwpLinuxBufferParamsV1* r, int32_t w, int32_t h, uint32_t fmt, zwpLinuxBufferParamsV1Flags flags) {
|
|
|
|
|
if (m_used) {
|
2024-06-08 10:07:59 +02:00
|
|
|
r->error(ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_ALREADY_USED, "Already used");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (flags > 0) {
|
|
|
|
|
r->sendFailed();
|
|
|
|
|
LOGM(ERR, "DMABUF flags are not supported");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
m_attrs->size = {w, h};
|
|
|
|
|
m_attrs->format = fmt;
|
2025-05-30 18:25:59 +05:00
|
|
|
m_attrs->planes = 4 - std::ranges::count(m_attrs->fds, -1);
|
2024-06-08 10:07:59 +02:00
|
|
|
|
|
|
|
|
create(0);
|
|
|
|
|
});
|
|
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
m_resource->setCreateImmed([this](CZwpLinuxBufferParamsV1* r, uint32_t id, int32_t w, int32_t h, uint32_t fmt, zwpLinuxBufferParamsV1Flags flags) {
|
|
|
|
|
if (m_used) {
|
2024-06-08 10:07:59 +02:00
|
|
|
r->error(ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_ALREADY_USED, "Already used");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (flags > 0) {
|
|
|
|
|
r->sendFailed();
|
|
|
|
|
LOGM(ERR, "DMABUF flags are not supported");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
m_attrs->size = {w, h};
|
|
|
|
|
m_attrs->format = fmt;
|
2025-05-30 18:25:59 +05:00
|
|
|
m_attrs->planes = 4 - std::ranges::count(m_attrs->fds, -1);
|
2024-06-08 10:07:59 +02:00
|
|
|
|
|
|
|
|
create(id);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-30 16:07:06 +05:00
|
|
|
bool CLinuxDMABUFParamsResource::good() {
|
2025-05-04 00:13:29 +02:00
|
|
|
return m_resource->resource();
|
2024-06-08 10:07:59 +02:00
|
|
|
}
|
|
|
|
|
|
2025-01-30 16:07:06 +05:00
|
|
|
void CLinuxDMABUFParamsResource::create(uint32_t id) {
|
2025-05-04 00:13:29 +02:00
|
|
|
m_used = true;
|
2024-06-08 10:07:59 +02:00
|
|
|
|
2025-01-17 18:21:34 +01:00
|
|
|
if UNLIKELY (!verify()) {
|
2024-06-08 10:07:59 +02:00
|
|
|
LOGM(ERR, "Failed creating a dmabuf: verify() said no");
|
|
|
|
|
return; // if verify failed, we errored the resource.
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-17 18:21:34 +01:00
|
|
|
if UNLIKELY (!commence()) {
|
2024-06-08 10:07:59 +02:00
|
|
|
LOGM(ERR, "Failed creating a dmabuf: commence() said no");
|
2025-05-04 00:13:29 +02:00
|
|
|
m_resource->sendFailed();
|
2024-06-08 10:07:59 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
LOGM(LOG, "Creating a dmabuf, with id {}: size {}, fmt {}, planes {}", id, m_attrs->size, NFormatUtils::drmFormatName(m_attrs->format), m_attrs->planes);
|
|
|
|
|
for (int i = 0; i < m_attrs->planes; ++i) {
|
|
|
|
|
LOGM(LOG, " | plane {}: mod {} fd {} stride {} offset {}", i, m_attrs->modifier, m_attrs->fds[i], m_attrs->strides[i], m_attrs->offsets[i]);
|
2024-06-08 10:07:59 +02:00
|
|
|
}
|
|
|
|
|
|
2025-07-10 13:07:44 +02:00
|
|
|
auto& buf = PROTO::linuxDma->m_buffers.emplace_back(makeUnique<CLinuxDMABuffer>(id, m_resource->client(), *m_attrs));
|
2024-06-08 10:07:59 +02:00
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
if UNLIKELY (!buf->good() || !buf->m_buffer->m_success) {
|
|
|
|
|
m_resource->sendFailed();
|
|
|
|
|
PROTO::linuxDma->m_buffers.pop_back();
|
2024-06-08 10:07:59 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!id)
|
2025-07-10 13:07:44 +02:00
|
|
|
m_resource->sendCreated(buf->m_buffer->m_resource->getResource());
|
2024-06-08 10:07:59 +02:00
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
m_createdBuffer = buf;
|
2024-06-08 10:07:59 +02:00
|
|
|
}
|
|
|
|
|
|
2025-01-30 16:07:06 +05:00
|
|
|
bool CLinuxDMABUFParamsResource::commence() {
|
2025-05-04 00:13:29 +02:00
|
|
|
if (!PROTO::linuxDma->m_mainDeviceFD.isValid())
|
2024-06-08 10:07:59 +02:00
|
|
|
return true;
|
|
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
for (int i = 0; i < m_attrs->planes; i++) {
|
2024-06-08 10:07:59 +02:00
|
|
|
uint32_t handle = 0;
|
|
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
if (drmPrimeFDToHandle(PROTO::linuxDma->m_mainDeviceFD.get(), m_attrs->fds.at(i), &handle)) {
|
2024-06-08 10:07:59 +02:00
|
|
|
LOGM(ERR, "Failed to import dmabuf fd");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
if (drmCloseBufferHandle(PROTO::linuxDma->m_mainDeviceFD.get(), handle)) {
|
2024-06-08 10:07:59 +02:00
|
|
|
LOGM(ERR, "Failed to close dmabuf handle");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-30 16:07:06 +05:00
|
|
|
bool CLinuxDMABUFParamsResource::verify() {
|
2025-05-04 00:13:29 +02:00
|
|
|
if UNLIKELY (m_attrs->planes <= 0) {
|
|
|
|
|
m_resource->error(ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INCOMPLETE, "No planes added");
|
2024-06-08 10:07:59 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
if UNLIKELY (m_attrs->fds.at(0) < 0) {
|
|
|
|
|
m_resource->error(ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INCOMPLETE, "No plane 0");
|
2024-06-08 10:07:59 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool empty = false;
|
2025-05-04 00:13:29 +02:00
|
|
|
for (auto const& plane : m_attrs->fds) {
|
2024-06-08 10:07:59 +02:00
|
|
|
if (empty && plane != -1) {
|
2025-05-04 00:13:29 +02:00
|
|
|
m_resource->error(ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_FORMAT, "Gap in planes");
|
2024-06-08 10:07:59 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (plane == -1) {
|
|
|
|
|
empty = true;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
if UNLIKELY (m_attrs->size.x < 1 || m_attrs->size.y < 1) {
|
|
|
|
|
m_resource->error(ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_DIMENSIONS, "x/y < 1");
|
2024-06-08 10:07:59 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
for (size_t i = 0; i < (size_t)m_attrs->planes; ++i) {
|
|
|
|
|
if ((uint64_t)m_attrs->offsets.at(i) + (uint64_t)m_attrs->strides.at(i) * m_attrs->size.y > UINT32_MAX) {
|
|
|
|
|
m_resource->error(ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_OUT_OF_BOUNDS,
|
|
|
|
|
std::format("size overflow on plane {}: offset {} + stride {} * height {} = {}, overflows UINT32_MAX", i, (uint64_t)m_attrs->offsets.at(i),
|
|
|
|
|
(uint64_t)m_attrs->strides.at(i), m_attrs->size.y, (uint64_t)m_attrs->offsets.at(i) + (uint64_t)m_attrs->strides.at(i)));
|
2024-06-08 10:07:59 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-10 13:07:44 +02:00
|
|
|
CLinuxDMABUFFeedbackResource::CLinuxDMABUFFeedbackResource(UP<CZwpLinuxDmabufFeedbackV1>&& resource_, SP<CWLSurfaceResource> surface_) :
|
|
|
|
|
m_surface(surface_), m_resource(std::move(resource_)) {
|
2025-01-17 18:21:34 +01:00
|
|
|
if UNLIKELY (!good())
|
2024-06-08 10:07:59 +02:00
|
|
|
return;
|
|
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
m_resource->setOnDestroy([this](CZwpLinuxDmabufFeedbackV1* r) { PROTO::linuxDma->destroyResource(this); });
|
|
|
|
|
m_resource->setDestroy([this](CZwpLinuxDmabufFeedbackV1* r) { PROTO::linuxDma->destroyResource(this); });
|
2024-06-08 10:07:59 +02:00
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
auto& formatTable = PROTO::linuxDma->m_formatTable;
|
|
|
|
|
m_resource->sendFormatTable(formatTable->m_tableFD.get(), formatTable->m_tableSize);
|
2024-07-21 13:09:54 +02:00
|
|
|
sendDefaultFeedback();
|
|
|
|
|
}
|
2024-06-08 10:07:59 +02:00
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
bool CLinuxDMABUFFeedbackResource::good() {
|
2025-05-04 00:13:29 +02:00
|
|
|
return m_resource->resource();
|
2024-07-21 13:09:54 +02:00
|
|
|
}
|
2024-06-08 10:07:59 +02:00
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
void CLinuxDMABUFFeedbackResource::sendTranche(SDMABUFTranche& tranche) {
|
2024-06-08 10:07:59 +02:00
|
|
|
struct wl_array deviceArr = {
|
2024-07-21 13:09:54 +02:00
|
|
|
.size = sizeof(tranche.device),
|
|
|
|
|
.data = (void*)&tranche.device,
|
2024-06-08 10:07:59 +02:00
|
|
|
};
|
2025-05-04 00:13:29 +02:00
|
|
|
m_resource->sendTrancheTargetDevice(&deviceArr);
|
2024-06-08 10:07:59 +02:00
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
m_resource->sendTrancheFlags((zwpLinuxDmabufFeedbackV1TrancheFlags)tranche.flags);
|
2024-07-21 13:09:54 +02:00
|
|
|
|
|
|
|
|
wl_array indices = {
|
2025-07-25 15:19:23 +00:00
|
|
|
.size = tranche.indices.size() * sizeof(tranche.indices.at(0)),
|
|
|
|
|
.data = tranche.indices.data(),
|
2024-07-21 13:09:54 +02:00
|
|
|
};
|
2025-05-04 00:13:29 +02:00
|
|
|
m_resource->sendTrancheFormats(&indices);
|
|
|
|
|
m_resource->sendTrancheDone();
|
2024-06-08 10:07:59 +02:00
|
|
|
}
|
|
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
// default tranche is based on renderer (egl)
|
|
|
|
|
void CLinuxDMABUFFeedbackResource::sendDefaultFeedback() {
|
2025-05-04 00:13:29 +02:00
|
|
|
auto mainDevice = PROTO::linuxDma->m_mainDevice;
|
|
|
|
|
auto& formatTable = PROTO::linuxDma->m_formatTable;
|
2024-06-08 10:07:59 +02:00
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
struct wl_array deviceArr = {
|
|
|
|
|
.size = sizeof(mainDevice),
|
|
|
|
|
.data = (void*)&mainDevice,
|
|
|
|
|
};
|
2025-05-04 00:13:29 +02:00
|
|
|
m_resource->sendMainDevice(&deviceArr);
|
2024-07-21 13:09:54 +02:00
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
sendTranche(formatTable->m_rendererTranche);
|
2024-07-21 13:09:54 +02:00
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
m_resource->sendDone();
|
2024-07-21 13:09:54 +02:00
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
m_lastFeedbackWasScanout = false;
|
2024-06-08 10:07:59 +02:00
|
|
|
}
|
|
|
|
|
|
2025-07-10 13:07:44 +02:00
|
|
|
CLinuxDMABUFResource::CLinuxDMABUFResource(UP<CZwpLinuxDmabufV1>&& resource_) : m_resource(std::move(resource_)) {
|
2025-01-17 18:21:34 +01:00
|
|
|
if UNLIKELY (!good())
|
2024-06-08 10:07:59 +02:00
|
|
|
return;
|
|
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
m_resource->setOnDestroy([this](CZwpLinuxDmabufV1* r) { PROTO::linuxDma->destroyResource(this); });
|
|
|
|
|
m_resource->setDestroy([this](CZwpLinuxDmabufV1* r) { PROTO::linuxDma->destroyResource(this); });
|
2024-06-08 10:07:59 +02:00
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
m_resource->setGetDefaultFeedback([](CZwpLinuxDmabufV1* r, uint32_t id) {
|
2025-07-10 13:07:44 +02:00
|
|
|
const auto& RESOURCE =
|
|
|
|
|
PROTO::linuxDma->m_feedbacks.emplace_back(makeUnique<CLinuxDMABUFFeedbackResource>(makeUnique<CZwpLinuxDmabufFeedbackV1>(r->client(), r->version(), id), nullptr));
|
2024-06-08 10:07:59 +02:00
|
|
|
|
2025-01-17 18:21:34 +01:00
|
|
|
if UNLIKELY (!RESOURCE->good()) {
|
2024-06-08 10:07:59 +02:00
|
|
|
r->noMemory();
|
2025-05-04 00:13:29 +02:00
|
|
|
PROTO::linuxDma->m_feedbacks.pop_back();
|
2024-06-08 10:07:59 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
m_resource->setGetSurfaceFeedback([](CZwpLinuxDmabufV1* r, uint32_t id, wl_resource* surf) {
|
2025-07-10 13:07:44 +02:00
|
|
|
const auto& RESOURCE = PROTO::linuxDma->m_feedbacks.emplace_back(
|
|
|
|
|
makeUnique<CLinuxDMABUFFeedbackResource>(makeUnique<CZwpLinuxDmabufFeedbackV1>(r->client(), r->version(), id), CWLSurfaceResource::fromResource(surf)));
|
2024-06-08 10:07:59 +02:00
|
|
|
|
2025-01-17 18:21:34 +01:00
|
|
|
if UNLIKELY (!RESOURCE->good()) {
|
2024-06-08 10:07:59 +02:00
|
|
|
r->noMemory();
|
2025-05-04 00:13:29 +02:00
|
|
|
PROTO::linuxDma->m_feedbacks.pop_back();
|
2024-06-08 10:07:59 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
m_resource->setCreateParams([](CZwpLinuxDmabufV1* r, uint32_t id) {
|
2025-07-10 13:07:44 +02:00
|
|
|
const auto& RESOURCE = PROTO::linuxDma->m_params.emplace_back(makeUnique<CLinuxDMABUFParamsResource>(makeUnique<CZwpLinuxBufferParamsV1>(r->client(), r->version(), id)));
|
2024-06-08 10:07:59 +02:00
|
|
|
|
2025-01-17 18:21:34 +01:00
|
|
|
if UNLIKELY (!RESOURCE->good()) {
|
2024-06-08 10:07:59 +02:00
|
|
|
r->noMemory();
|
2025-05-04 00:13:29 +02:00
|
|
|
PROTO::linuxDma->m_params.pop_back();
|
2024-06-08 10:07:59 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
if (m_resource->version() < 4)
|
2024-06-08 10:07:59 +02:00
|
|
|
sendMods();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CLinuxDMABUFResource::good() {
|
2025-05-04 00:13:29 +02:00
|
|
|
return m_resource->resource();
|
2024-06-08 10:07:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CLinuxDMABUFResource::sendMods() {
|
2025-05-04 00:13:29 +02:00
|
|
|
for (auto const& fmt : PROTO::linuxDma->m_formatTable->m_rendererTranche.formats) {
|
2024-08-26 20:24:30 +02:00
|
|
|
for (auto const& mod : fmt.modifiers) {
|
2025-05-04 00:13:29 +02:00
|
|
|
if (m_resource->version() < 3) {
|
2024-07-21 13:09:54 +02:00
|
|
|
if (mod == DRM_FORMAT_MOD_INVALID || mod == DRM_FORMAT_MOD_LINEAR)
|
2025-05-04 00:13:29 +02:00
|
|
|
m_resource->sendFormat(fmt.drmFormat);
|
2024-07-21 13:09:54 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
2024-06-08 10:07:59 +02:00
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
// TODO: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1166
|
2024-06-08 10:07:59 +02:00
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
m_resource->sendModifier(fmt.drmFormat, mod >> 32, mod & 0xFFFFFFFF);
|
2024-07-21 13:09:54 +02:00
|
|
|
}
|
2024-06-08 10:07:59 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CLinuxDMABufV1Protocol::CLinuxDMABufV1Protocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
|
|
|
|
|
static auto P = g_pHookSystem->hookDynamic("ready", [this](void* self, SCallbackInfo& info, std::any d) {
|
2025-04-22 15:23:29 +02:00
|
|
|
int rendererFD = g_pCompositor->m_drmFD;
|
2024-06-08 10:07:59 +02:00
|
|
|
auto dev = devIDFromFD(rendererFD);
|
|
|
|
|
|
|
|
|
|
if (!dev.has_value()) {
|
2024-08-15 18:16:18 +02:00
|
|
|
LOGM(ERR, "failed to get drm dev, disabling linux dmabuf");
|
2024-07-21 13:09:54 +02:00
|
|
|
removeGlobal();
|
2024-06-08 10:07:59 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
m_mainDevice = *dev;
|
2024-06-08 10:07:59 +02:00
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
SDMABUFTranche eglTranche = {
|
2025-05-04 00:13:29 +02:00
|
|
|
.device = m_mainDevice,
|
2025-07-25 15:19:23 +00:00
|
|
|
.flags = 0, // renderer isn't for ds so don't set flag.
|
2024-07-21 13:09:54 +02:00
|
|
|
.formats = g_pHyprOpenGL->getDRMFormats(),
|
2024-06-08 10:07:59 +02:00
|
|
|
};
|
|
|
|
|
|
2024-10-26 02:06:13 +01:00
|
|
|
std::vector<std::pair<PHLMONITORREF, SDMABUFTranche>> tches;
|
2024-07-21 13:09:54 +02:00
|
|
|
|
2025-04-22 15:23:29 +02:00
|
|
|
if (g_pCompositor->m_aqBackend->hasSession()) {
|
2024-07-21 13:09:54 +02:00
|
|
|
// this assumes there's only 1 device used for both scanout and rendering
|
|
|
|
|
// also that each monitor never changes its primary plane
|
|
|
|
|
|
2025-04-22 15:23:29 +02:00
|
|
|
for (auto const& mon : g_pCompositor->m_monitors) {
|
2024-07-21 13:09:54 +02:00
|
|
|
auto tranche = SDMABUFTranche{
|
2025-05-04 00:13:29 +02:00
|
|
|
.device = m_mainDevice,
|
2024-07-21 13:09:54 +02:00
|
|
|
.flags = ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FLAGS_SCANOUT,
|
2025-04-30 23:45:20 +02:00
|
|
|
.formats = mon->m_output->getRenderFormats(),
|
2024-07-21 13:09:54 +02:00
|
|
|
};
|
2024-12-07 18:51:18 +01:00
|
|
|
tches.emplace_back(std::make_pair<>(mon, tranche));
|
2024-07-21 13:09:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static auto monitorAdded = g_pHookSystem->hookDynamic("monitorAdded", [this](void* self, SCallbackInfo& info, std::any param) {
|
2024-10-19 23:03:29 +01:00
|
|
|
auto pMonitor = std::any_cast<PHLMONITOR>(param);
|
2024-07-21 13:09:54 +02:00
|
|
|
auto tranche = SDMABUFTranche{
|
2025-05-04 00:13:29 +02:00
|
|
|
.device = m_mainDevice,
|
2024-07-21 13:09:54 +02:00
|
|
|
.flags = ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FLAGS_SCANOUT,
|
2025-04-30 23:45:20 +02:00
|
|
|
.formats = pMonitor->m_output->getRenderFormats(),
|
2024-07-21 13:09:54 +02:00
|
|
|
};
|
2025-05-04 00:13:29 +02:00
|
|
|
m_formatTable->m_monitorTranches.emplace_back(std::make_pair<>(pMonitor, tranche));
|
2024-07-21 13:09:54 +02:00
|
|
|
resetFormatTable();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
static auto monitorRemoved = g_pHookSystem->hookDynamic("monitorRemoved", [this](void* self, SCallbackInfo& info, std::any param) {
|
2024-10-19 23:03:29 +01:00
|
|
|
auto pMonitor = std::any_cast<PHLMONITOR>(param);
|
2025-05-04 00:13:29 +02:00
|
|
|
std::erase_if(m_formatTable->m_monitorTranches, [pMonitor](std::pair<PHLMONITORREF, SDMABUFTranche> pair) { return pair.first == pMonitor; });
|
2024-07-21 13:09:54 +02:00
|
|
|
resetFormatTable();
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-06-08 10:07:59 +02:00
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
m_formatTable = makeUnique<CDMABUFFormatTable>(eglTranche, tches);
|
2024-06-08 10:07:59 +02:00
|
|
|
|
|
|
|
|
drmDevice* device = nullptr;
|
2025-05-04 00:13:29 +02:00
|
|
|
if (drmGetDeviceFromDevId(m_mainDevice, 0, &device) != 0) {
|
2024-08-15 18:16:18 +02:00
|
|
|
LOGM(ERR, "failed to get drm dev, disabling linux dmabuf");
|
2024-07-21 13:09:54 +02:00
|
|
|
removeGlobal();
|
2024-06-08 10:07:59 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (device->available_nodes & (1 << DRM_NODE_RENDER)) {
|
|
|
|
|
const char* name = device->nodes[DRM_NODE_RENDER];
|
2025-05-04 00:13:29 +02:00
|
|
|
m_mainDeviceFD = CFileDescriptor{open(name, O_RDWR | O_CLOEXEC)};
|
2024-06-08 10:07:59 +02:00
|
|
|
drmFreeDevice(&device);
|
2025-05-04 00:13:29 +02:00
|
|
|
if (!m_mainDeviceFD.isValid()) {
|
2024-08-15 18:16:18 +02:00
|
|
|
LOGM(ERR, "failed to open drm dev, disabling linux dmabuf");
|
2024-07-21 13:09:54 +02:00
|
|
|
removeGlobal();
|
2024-06-08 10:07:59 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2024-08-18 19:51:54 +02:00
|
|
|
LOGM(ERR, "DRM device {} has no render node, disabling linux dmabuf checks", device->nodes[DRM_NODE_PRIMARY] ? device->nodes[DRM_NODE_PRIMARY] : "null");
|
2024-06-08 10:07:59 +02:00
|
|
|
drmFreeDevice(&device);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
void CLinuxDMABufV1Protocol::resetFormatTable() {
|
2025-05-04 00:13:29 +02:00
|
|
|
if (!m_formatTable)
|
2024-07-21 13:09:54 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
LOGM(LOG, "Resetting format table");
|
|
|
|
|
|
|
|
|
|
// this might be a big copy
|
2025-05-04 00:13:29 +02:00
|
|
|
auto newFormatTable = makeUnique<CDMABUFFormatTable>(m_formatTable->m_rendererTranche, m_formatTable->m_monitorTranches);
|
2024-07-21 13:09:54 +02:00
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
for (auto const& feedback : m_feedbacks) {
|
|
|
|
|
feedback->m_resource->sendFormatTable(newFormatTable->m_tableFD.get(), newFormatTable->m_tableSize);
|
|
|
|
|
if (feedback->m_lastFeedbackWasScanout) {
|
2024-10-26 02:06:13 +01:00
|
|
|
PHLMONITOR mon;
|
2025-05-04 00:13:29 +02:00
|
|
|
auto HLSurface = CWLSurface::fromResource(feedback->m_surface);
|
2024-07-21 13:09:54 +02:00
|
|
|
if (auto w = HLSurface->getWindow(); w)
|
2025-04-28 22:25:22 +02:00
|
|
|
if (auto m = w->m_monitor.lock(); m)
|
2025-04-30 23:45:20 +02:00
|
|
|
mon = m->m_self.lock();
|
2024-07-21 13:09:54 +02:00
|
|
|
|
|
|
|
|
if (!mon) {
|
|
|
|
|
feedback->sendDefaultFeedback();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
updateScanoutTranche(feedback->m_surface, mon);
|
2024-07-21 13:09:54 +02:00
|
|
|
} else {
|
|
|
|
|
feedback->sendDefaultFeedback();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// delete old table after we sent new one
|
2025-05-04 00:13:29 +02:00
|
|
|
m_formatTable = std::move(newFormatTable);
|
2024-07-21 13:09:54 +02:00
|
|
|
}
|
|
|
|
|
|
2024-06-08 10:07:59 +02:00
|
|
|
void CLinuxDMABufV1Protocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
|
2025-07-10 13:07:44 +02:00
|
|
|
const auto& RESOURCE = m_managers.emplace_back(makeUnique<CLinuxDMABUFResource>(makeUnique<CZwpLinuxDmabufV1>(client, ver, id)));
|
2024-06-08 10:07:59 +02:00
|
|
|
|
2025-01-17 18:21:34 +01:00
|
|
|
if UNLIKELY (!RESOURCE->good()) {
|
2024-06-08 10:07:59 +02:00
|
|
|
wl_client_post_no_memory(client);
|
2025-05-04 00:13:29 +02:00
|
|
|
m_managers.pop_back();
|
2024-06-08 10:07:59 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CLinuxDMABufV1Protocol::destroyResource(CLinuxDMABUFResource* resource) {
|
2025-05-04 00:13:29 +02:00
|
|
|
std::erase_if(m_managers, [&](const auto& other) { return other.get() == resource; });
|
2024-06-08 10:07:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CLinuxDMABufV1Protocol::destroyResource(CLinuxDMABUFFeedbackResource* resource) {
|
2025-05-04 00:13:29 +02:00
|
|
|
std::erase_if(m_feedbacks, [&](const auto& other) { return other.get() == resource; });
|
2024-06-08 10:07:59 +02:00
|
|
|
}
|
|
|
|
|
|
2025-01-30 16:07:06 +05:00
|
|
|
void CLinuxDMABufV1Protocol::destroyResource(CLinuxDMABUFParamsResource* resource) {
|
2025-05-04 00:13:29 +02:00
|
|
|
std::erase_if(m_params, [&](const auto& other) { return other.get() == resource; });
|
2024-06-08 10:07:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CLinuxDMABufV1Protocol::destroyResource(CLinuxDMABuffer* resource) {
|
2025-05-04 00:13:29 +02:00
|
|
|
std::erase_if(m_buffers, [&](const auto& other) { return other.get() == resource; });
|
2024-06-08 10:07:59 +02:00
|
|
|
}
|
2024-07-21 13:09:54 +02:00
|
|
|
|
2024-10-26 02:06:13 +01:00
|
|
|
void CLinuxDMABufV1Protocol::updateScanoutTranche(SP<CWLSurfaceResource> surface, PHLMONITOR pMonitor) {
|
2025-07-10 13:07:44 +02:00
|
|
|
WP<CLinuxDMABUFFeedbackResource> feedbackResource;
|
2025-05-04 00:13:29 +02:00
|
|
|
for (auto const& f : m_feedbacks) {
|
|
|
|
|
if (f->m_surface != surface)
|
2024-07-21 13:09:54 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
feedbackResource = f;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!feedbackResource) {
|
|
|
|
|
LOGM(LOG, "updateScanoutTranche: surface has no dmabuf_feedback");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!pMonitor) {
|
|
|
|
|
LOGM(LOG, "updateScanoutTranche: resetting feedback");
|
|
|
|
|
feedbackResource->sendDefaultFeedback();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-30 18:25:59 +05:00
|
|
|
const auto& monitorTranchePair =
|
|
|
|
|
std::ranges::find_if(m_formatTable->m_monitorTranches, [pMonitor](std::pair<PHLMONITORREF, SDMABUFTranche> pair) { return pair.first == pMonitor; });
|
2024-07-21 13:09:54 +02:00
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
if (monitorTranchePair == m_formatTable->m_monitorTranches.end()) {
|
2024-07-21 13:09:54 +02:00
|
|
|
LOGM(LOG, "updateScanoutTranche: monitor has no tranche");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto& monitorTranche = (*monitorTranchePair).second;
|
|
|
|
|
|
|
|
|
|
LOGM(LOG, "updateScanoutTranche: sending a scanout tranche");
|
|
|
|
|
|
|
|
|
|
struct wl_array deviceArr = {
|
2025-05-04 00:13:29 +02:00
|
|
|
.size = sizeof(m_mainDevice),
|
|
|
|
|
.data = (void*)&m_mainDevice,
|
2024-07-21 13:09:54 +02:00
|
|
|
};
|
2025-05-04 00:13:29 +02:00
|
|
|
feedbackResource->m_resource->sendMainDevice(&deviceArr);
|
2024-07-21 13:09:54 +02:00
|
|
|
|
|
|
|
|
// prioritize scnaout tranche but have renderer fallback tranche
|
|
|
|
|
// also yes formats can be duped here because different tranche flags (ds and no ds)
|
|
|
|
|
feedbackResource->sendTranche(monitorTranche);
|
2025-05-04 00:13:29 +02:00
|
|
|
feedbackResource->sendTranche(m_formatTable->m_rendererTranche);
|
2024-07-21 13:09:54 +02:00
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
feedbackResource->m_resource->sendDone();
|
2024-07-21 13:09:54 +02:00
|
|
|
|
2025-05-04 00:13:29 +02:00
|
|
|
feedbackResource->m_lastFeedbackWasScanout = true;
|
2024-07-21 13:09:54 +02:00
|
|
|
}
|