summaryrefslogtreecommitdiff
path: root/src/protocols
diff options
context:
space:
mode:
Diffstat (limited to 'src/protocols')
-rw-r--r--src/protocols/DRMSyncobj.cpp223
-rw-r--r--src/protocols/DRMSyncobj.hpp69
-rw-r--r--src/protocols/LinuxDMABUF.cpp3
-rw-r--r--src/protocols/LinuxDMABUF.hpp1
-rw-r--r--src/protocols/SinglePixel.cpp5
-rw-r--r--src/protocols/SinglePixel.hpp2
-rw-r--r--src/protocols/core/Compositor.cpp52
-rw-r--r--src/protocols/core/Compositor.hpp48
-rw-r--r--src/protocols/core/Shm.cpp5
-rw-r--r--src/protocols/core/Shm.hpp2
-rw-r--r--src/protocols/types/Buffer.cpp6
-rw-r--r--src/protocols/types/Buffer.hpp7
-rw-r--r--src/protocols/types/DMABuffer.cpp3
-rw-r--r--src/protocols/types/SurfaceState.hpp35
-rw-r--r--src/protocols/types/WLBuffer.cpp4
-rw-r--r--src/protocols/types/WLBuffer.hpp4
16 files changed, 301 insertions, 168 deletions
diff --git a/src/protocols/DRMSyncobj.cpp b/src/protocols/DRMSyncobj.cpp
index 38aab305..406b55e0 100644
--- a/src/protocols/DRMSyncobj.cpp
+++ b/src/protocols/DRMSyncobj.cpp
@@ -4,11 +4,82 @@
#include "core/Compositor.hpp"
#include "../helpers/sync/SyncTimeline.hpp"
#include "../Compositor.hpp"
+#include "render/OpenGL.hpp"
#include <fcntl.h>
using namespace Hyprutils::OS;
-CDRMSyncobjSurfaceResource::CDRMSyncobjSurfaceResource(SP<CWpLinuxDrmSyncobjSurfaceV1> resource_, SP<CWLSurfaceResource> surface_) : surface(surface_), resource(resource_) {
+CDRMSyncPointState::CDRMSyncPointState(WP<CDRMSyncobjTimelineResource> resource_, uint64_t point_, bool acquirePoint) :
+ m_resource(resource_), m_point(point_), m_acquirePoint(acquirePoint) {}
+
+const uint64_t& CDRMSyncPointState::point() {
+ return m_point;
+}
+
+WP<CDRMSyncobjTimelineResource> CDRMSyncPointState::resource() {
+ return m_resource;
+}
+
+WP<CSyncTimeline> CDRMSyncPointState::timeline() {
+ if (expired()) {
+ Debug::log(ERR, "CDRMSyncPointState: getting a timeline on a expired point");
+ return {};
+ }
+
+ return m_resource->timeline;
+}
+
+bool CDRMSyncPointState::expired() {
+ return !m_resource || !m_resource->timeline;
+}
+
+UP<CSyncReleaser> CDRMSyncPointState::createSyncRelease() {
+ if (expired()) {
+ Debug::log(ERR, "CDRMSyncPointState: creating a sync releaser on an expired point");
+ return nullptr;
+ }
+
+ if (m_releaseTaken)
+ Debug::log(ERR, "CDRMSyncPointState: creating a sync releaser on an already created SyncRelease");
+
+ m_releaseTaken = true;
+ return makeUnique<CSyncReleaser>(m_resource->timeline, m_point);
+}
+
+bool CDRMSyncPointState::addWaiter(const std::function<void()>& waiter) {
+ if (expired()) {
+ Debug::log(ERR, "CDRMSyncPointState: adding a waiter on an expired point");
+ return false;
+ }
+
+ m_acquireCommitted = true;
+ return m_resource->timeline->addWaiter(waiter, m_point, 0u);
+}
+
+bool CDRMSyncPointState::comitted() {
+ return m_acquireCommitted;
+}
+
+CFileDescriptor CDRMSyncPointState::exportAsFD() {
+ if (expired()) {
+ Debug::log(ERR, "CDRMSyncPointState: exporting a FD on an expired point");
+ return {};
+ }
+
+ return m_resource->timeline->exportAsSyncFileFD(m_point);
+}
+
+void CDRMSyncPointState::signal() {
+ if (expired()) {
+ Debug::log(ERR, "CDRMSyncPointState: signaling on an expired point");
+ return;
+ }
+
+ m_resource->timeline->signal(m_point);
+}
+
+CDRMSyncobjSurfaceResource::CDRMSyncobjSurfaceResource(UP<CWpLinuxDrmSyncobjSurfaceV1>&& resource_, SP<CWLSurfaceResource> surface_) :
+ surface(surface_), resource(std::move(resource_)) {
if UNLIKELY (!good())
return;
@@ -23,9 +94,8 @@ CDRMSyncobjSurfaceResource::CDRMSyncobjSurfaceResource(SP<CWpLinuxDrmSyncobjSurf
return;
}
- auto timeline = CDRMSyncobjTimelineResource::fromResource(timeline_);
- pending.acquireTimeline = timeline;
- pending.acquirePoint = ((uint64_t)hi << 32) | (uint64_t)lo;
+ auto timeline = CDRMSyncobjTimelineResource::fromResource(timeline_);
+ pendingAcquire = {timeline, ((uint64_t)hi << 32) | (uint64_t)lo, true};
});
resource->setSetReleasePoint([this](CWpLinuxDrmSyncobjSurfaceV1* r, wl_resource* timeline_, uint32_t hi, uint32_t lo) {
@@ -34,77 +104,102 @@ CDRMSyncobjSurfaceResource::CDRMSyncobjSurfaceResource(SP<CWpLinuxDrmSyncobjSurf
return;
}
- auto timeline = CDRMSyncobjTimelineResource::fromResource(timeline_);
- pending.releaseTimeline = timeline;
- pending.releasePoint = ((uint64_t)hi << 32) | (uint64_t)lo;
+ auto timeline = CDRMSyncobjTimelineResource::fromResource(timeline_);
+ pendingRelease = {timeline, ((uint64_t)hi << 32) | (uint64_t)lo, false};
});
listeners.surfacePrecommit = surface->events.precommit.registerListener([this](std::any d) {
- if ((pending.acquireTimeline || pending.releaseTimeline) && !surface->pending.texture) {
- resource->error(WP_LINUX_DRM_SYNCOBJ_SURFACE_V1_ERROR_NO_BUFFER, "Missing buffer");
- surface->pending.rejected = true;
- return;
+ if (!surface->pending.buffer && surface->pending.newBuffer && !surface->pending.texture) {
+ removeAllWaiters();
+ surface->commitPendingState(surface->pending);
+ return; // null buffer attached.
}
- if (!surface->pending.newBuffer)
- return; // this commit does not change the state here
-
- if (!!pending.acquireTimeline != !!pending.releaseTimeline) {
- resource->error(pending.acquireTimeline ? WP_LINUX_DRM_SYNCOBJ_SURFACE_V1_ERROR_NO_RELEASE_POINT : WP_LINUX_DRM_SYNCOBJ_SURFACE_V1_ERROR_NO_ACQUIRE_POINT,
- "Missing timeline");
- surface->pending.rejected = true;
- return;
+ if (!surface->pending.buffer && !surface->pending.newBuffer && surface->current.buffer) {
+ surface->current.bufferDamage.clear();
+ surface->current.damage.clear();
+ surface->commitPendingState(surface->current);
+ return; // no new buffer, but we still have current around and a commit happend, commit current again.
}
- if (!pending.acquireTimeline)
+ if (!surface->pending.buffer && !surface->pending.newBuffer && !surface->current.buffer) {
+ surface->commitPendingState(surface->pending); // no pending buffer, no current buffer. probably first commit
return;
+ }
- if (pending.acquireTimeline && pending.releaseTimeline && pending.acquireTimeline == pending.releaseTimeline) {
- if (pending.acquirePoint >= pending.releasePoint) {
- resource->error(WP_LINUX_DRM_SYNCOBJ_SURFACE_V1_ERROR_CONFLICTING_POINTS, "Acquire and release points are on the same timeline, and acquire >= release");
- surface->pending.rejected = true;
- return;
- }
+ if (!pendingAcquire.expired()) {
+ surface->pending.buffer->acquire = makeUnique<CDRMSyncPointState>(std::move(pendingAcquire));
+ pendingAcquire = {};
}
- // wait for the acquire timeline to materialize
- auto materialized = pending.acquireTimeline->timeline->check(pending.acquirePoint, DRM_SYNCOBJ_WAIT_FLAGS_WAIT_AVAILABLE);
- if (!materialized.has_value()) {
- LOGM(ERR, "Failed to check the acquire timeline");
- resource->noMemory();
- return;
+ if (!pendingRelease.expired()) {
+ surface->pending.buffer->release = makeUnique<CDRMSyncPointState>(std::move(pendingRelease));
+ pendingRelease = {};
}
- if (materialized.value())
+ if (protocolError())
return;
- surface->lockPendingState();
- pending.acquireTimeline->timeline->addWaiter([this]() { surface->unlockPendingState(); }, pending.acquirePoint, DRM_SYNCOBJ_WAIT_FLAGS_WAIT_AVAILABLE);
+ const auto& state = pendingStates.emplace_back(makeShared<SSurfaceState>(surface->pending));
+ surface->pending.damage.clear();
+ surface->pending.bufferDamage.clear();
+ surface->pending.newBuffer = false;
+ surface->pending.buffer.reset();
+
+ state->buffer->buffer->syncReleaser = state->buffer->release->createSyncRelease();
+ state->buffer->acquire->addWaiter([this, surf = surface, wp = CWeakPointer<SSurfaceState>(*std::prev(pendingStates.end()))] {
+ if (!surf)
+ return;
+
+ surf->commitPendingState(*wp.lock());
+ std::erase(pendingStates, wp);
+ });
});
+}
- listeners.surfaceCommit = surface->events.roleCommit.registerListener([this](std::any d) {
- // apply timelines if new ones have been attached, otherwise don't touch
- // the current ones
- if (pending.releaseTimeline) {
- current.releaseTimeline = pending.releaseTimeline;
- current.releasePoint = pending.releasePoint;
- }
+void CDRMSyncobjSurfaceResource::removeAllWaiters() {
+ for (auto& s : pendingStates) {
+ if (s && s->buffer && s->buffer->acquire && !s->buffer->acquire->expired())
+ s->buffer->acquire->resource()->timeline->removeAllWaiters();
+ }
- if (pending.acquireTimeline) {
- current.acquireTimeline = pending.acquireTimeline;
- current.acquirePoint = pending.acquirePoint;
+ pendingStates.clear();
+}
+
+CDRMSyncobjSurfaceResource::~CDRMSyncobjSurfaceResource() {
+ removeAllWaiters();
+}
+
+bool CDRMSyncobjSurfaceResource::protocolError() {
+ if (!surface->pending.texture) {
+ resource->error(WP_LINUX_DRM_SYNCOBJ_SURFACE_V1_ERROR_NO_BUFFER, "Missing buffer");
+ surface->pending.rejected = true;
+ return true;
+ }
+
+ if (!!surface->pending.buffer->acquire != !!surface->pending.buffer->release) {
+ resource->error(surface->pending.buffer->acquire ? WP_LINUX_DRM_SYNCOBJ_SURFACE_V1_ERROR_NO_RELEASE_POINT : WP_LINUX_DRM_SYNCOBJ_SURFACE_V1_ERROR_NO_ACQUIRE_POINT,
+ "Missing timeline");
+ surface->pending.rejected = true;
+ return true;
+ }
+
+ if (surface->pending.buffer->acquire->timeline() == surface->pending.buffer->release->timeline()) {
+ if (surface->pending.buffer->acquire->point() >= surface->pending.buffer->release->point()) {
+ resource->error(WP_LINUX_DRM_SYNCOBJ_SURFACE_V1_ERROR_CONFLICTING_POINTS, "Acquire and release points are on the same timeline, and acquire >= release");
+ surface->pending.rejected = true;
+ return true;
}
+ }
- pending.releaseTimeline.reset();
- pending.acquireTimeline.reset();
- });
+ return false;
}
bool CDRMSyncobjSurfaceResource::good() {
return resource->resource();
}
-CDRMSyncobjTimelineResource::CDRMSyncobjTimelineResource(SP<CWpLinuxDrmSyncobjTimelineV1> resource_, CFileDescriptor&& fd_) : fd(std::move(fd_)), resource(resource_) {
+CDRMSyncobjTimelineResource::CDRMSyncobjTimelineResource(UP<CWpLinuxDrmSyncobjTimelineV1>&& resource_, CFileDescriptor&& fd_) : fd(std::move(fd_)), resource(std::move(resource_)) {
if UNLIKELY (!good())
return;
@@ -121,16 +216,20 @@ CDRMSyncobjTimelineResource::CDRMSyncobjTimelineResource(SP<CWpLinuxDrmSyncobjTi
}
}
-SP<CDRMSyncobjTimelineResource> CDRMSyncobjTimelineResource::fromResource(wl_resource* res) {
- auto data = (CDRMSyncobjTimelineResource*)(((CWpLinuxDrmSyncobjTimelineV1*)wl_resource_get_user_data(res))->data());
- return data ? data->self.lock() : nullptr;
+WP<CDRMSyncobjTimelineResource> CDRMSyncobjTimelineResource::fromResource(wl_resource* res) {
+ for (const auto& r : PROTO::sync->m_vTimelines) {
+ if (r && r->resource && r->resource->resource() == res)
+ return r;
+ }
+
+ return {};
}
bool CDRMSyncobjTimelineResource::good() {
return resource->resource();
}
-CDRMSyncobjManagerResource::CDRMSyncobjManagerResource(SP<CWpLinuxDrmSyncobjManagerV1> resource_) : resource(resource_) {
+CDRMSyncobjManagerResource::CDRMSyncobjManagerResource(UP<CWpLinuxDrmSyncobjManagerV1>&& resource_) : resource(std::move(resource_)) {
if UNLIKELY (!good())
return;
@@ -154,28 +253,28 @@ CDRMSyncobjManagerResource::CDRMSyncobjManagerResource(SP<CWpLinuxDrmSyncobjMana
return;
}
- auto RESOURCE = makeShared<CDRMSyncobjSurfaceResource>(makeShared<CWpLinuxDrmSyncobjSurfaceV1>(resource->client(), resource->version(), id), SURF);
+ const auto& RESOURCE = PROTO::sync->m_vSurfaces.emplace_back(
+ makeUnique<CDRMSyncobjSurfaceResource>(makeUnique<CWpLinuxDrmSyncobjSurfaceV1>(resource->client(), resource->version(), id), SURF));
if UNLIKELY (!RESOURCE->good()) {
resource->noMemory();
+ PROTO::sync->m_vSurfaces.pop_back();
return;
}
- PROTO::sync->m_vSurfaces.emplace_back(RESOURCE);
SURF->syncobj = RESOURCE;
LOGM(LOG, "New linux_syncobj at {:x} for surface {:x}", (uintptr_t)RESOURCE.get(), (uintptr_t)SURF.get());
});
resource->setImportTimeline([this](CWpLinuxDrmSyncobjManagerV1* r, uint32_t id, int32_t fd) {
- auto RESOURCE = makeShared<CDRMSyncobjTimelineResource>(makeShared<CWpLinuxDrmSyncobjTimelineV1>(resource->client(), resource->version(), id), CFileDescriptor{fd});
+ const auto& RESOURCE = PROTO::sync->m_vTimelines.emplace_back(
+ makeUnique<CDRMSyncobjTimelineResource>(makeUnique<CWpLinuxDrmSyncobjTimelineV1>(resource->client(), resource->version(), id), CFileDescriptor{fd}));
if UNLIKELY (!RESOURCE->good()) {
resource->noMemory();
+ PROTO::sync->m_vTimelines.pop_back();
return;
}
- PROTO::sync->m_vTimelines.emplace_back(RESOURCE);
- RESOURCE->self = RESOURCE;
-
LOGM(LOG, "New linux_drm_timeline at {:x}", (uintptr_t)RESOURCE.get());
});
}
@@ -184,12 +283,10 @@ bool CDRMSyncobjManagerResource::good() {
return resource->resource();
}
-CDRMSyncobjProtocol::CDRMSyncobjProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
- drmFD = g_pCompositor->m_iDRMFD;
-}
+CDRMSyncobjProtocol::CDRMSyncobjProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name), drmFD(g_pCompositor->m_iDRMFD) {}
void CDRMSyncobjProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
- const auto RESOURCE = m_vManagers.emplace_back(makeShared<CDRMSyncobjManagerResource>(makeShared<CWpLinuxDrmSyncobjManagerV1>(client, ver, id)));
+ const auto& RESOURCE = m_vManagers.emplace_back(makeUnique<CDRMSyncobjManagerResource>(makeUnique<CWpLinuxDrmSyncobjManagerV1>(client, ver, id)));
if UNLIKELY (!RESOURCE->good()) {
wl_client_post_no_memory(client);
diff --git a/src/protocols/DRMSyncobj.hpp b/src/protocols/DRMSyncobj.hpp
index 9895dff1..78905d3d 100644
--- a/src/protocols/DRMSyncobj.hpp
+++ b/src/protocols/DRMSyncobj.hpp
@@ -2,64 +2,95 @@
#include <vector>
#include "WaylandProtocol.hpp"
+#include "helpers/sync/SyncReleaser.hpp"
#include "linux-drm-syncobj-v1.hpp"
#include "../helpers/signal/Signal.hpp"
+#include "types/SurfaceState.hpp"
#include <hyprutils/os/FileDescriptor.hpp>
+#include <list>
class CWLSurfaceResource;
class CDRMSyncobjTimelineResource;
class CSyncTimeline;
+struct SSurfaceState;
-class CDRMSyncobjSurfaceResource {
+class CDRMSyncPointState {
public:
- CDRMSyncobjSurfaceResource(SP<CWpLinuxDrmSyncobjSurfaceV1> resource_, SP<CWLSurfaceResource> surface_);
+ CDRMSyncPointState() = default;
+ CDRMSyncPointState(WP<CDRMSyncobjTimelineResource> resource_, uint64_t point_, bool acquirePoint);
+ ~CDRMSyncPointState() = default;
+
+ const uint64_t& point();
+ WP<CDRMSyncobjTimelineResource> resource();
+ WP<CSyncTimeline> timeline();
+ bool expired();
+ Hyprutils::Memory::CUniquePointer<CSyncReleaser> createSyncRelease();
+ bool addWaiter(const std::function<void()>& waiter);
+ bool comitted();
+ Hyprutils::OS::CFileDescriptor exportAsFD();
+ void signal();
- bool good();
+ private:
+ WP<CDRMSyncobjTimelineResource> m_resource = {};
+ uint64_t m_point = 0;
+ WP<CSyncTimeline> m_timeline = {};
+ bool m_acquirePoint = false;
+ bool m_acquireCommitted = false;
+ bool m_releaseTaken = false;
+};
- WP<CWLSurfaceResource> surface;
- struct {
- WP<CDRMSyncobjTimelineResource> acquireTimeline, releaseTimeline;
- uint64_t acquirePoint = 0, releasePoint = 0;
- } current, pending;
+class CDRMSyncobjSurfaceResource {
+ public:
+ CDRMSyncobjSurfaceResource(UP<CWpLinuxDrmSyncobjSurfaceV1>&& resource_, SP<CWLSurfaceResource> surface_);
+ ~CDRMSyncobjSurfaceResource();
+
+ bool protocolError();
+ bool good();
private:
- SP<CWpLinuxDrmSyncobjSurfaceV1> resource;
+ void removeAllWaiters();
+ WP<CWLSurfaceResource> surface;
+ UP<CWpLinuxDrmSyncobjSurfaceV1> resource;
+
+ CDRMSyncPointState pendingAcquire;
+ CDRMSyncPointState pendingRelease;
+ std::vector<SP<SSurfaceState>> pendingStates;
struct {
CHyprSignalListener surfacePrecommit;
- CHyprSignalListener surfaceCommit;
} listeners;
};
class CDRMSyncobjTimelineResource {
public:
- CDRMSyncobjTimelineResource(SP<CWpLinuxDrmSyncobjTimelineV1> resource_, Hyprutils::OS::CFileDescriptor&& fd_);
+ CDRMSyncobjTimelineResource(UP<CWpLinuxDrmSyncobjTimelineV1>&& resource_, Hyprutils::OS::CFileDescriptor&& fd_);
~CDRMSyncobjTimelineResource() = default;
- static SP<CDRMSyncobjTimelineResource> fromResource(wl_resource*);
+ static WP<CDRMSyncobjTimelineResource> fromResource(wl_resource*);
bool good();
- WP<CDRMSyncobjTimelineResource> self;
Hyprutils::OS::CFileDescriptor fd;
SP<CSyncTimeline> timeline;
private:
- SP<CWpLinuxDrmSyncobjTimelineV1> resource;
+ UP<CWpLinuxDrmSyncobjTimelineV1> resource;
};
class CDRMSyncobjManagerResource {
public:
- CDRMSyncobjManagerResource(SP<CWpLinuxDrmSyncobjManagerV1> resource_);
+ CDRMSyncobjManagerResource(UP<CWpLinuxDrmSyncobjManagerV1>&& resource_);
+ ~CDRMSyncobjManagerResource() = default;
bool good();
private:
- SP<CWpLinuxDrmSyncobjManagerV1> resource;
+ UP<CWpLinuxDrmSyncobjManagerV1> resource;
};
class CDRMSyncobjProtocol : public IWaylandProtocol {
public:
CDRMSyncobjProtocol(const wl_interface* iface, const int& ver, const std::string& name);
+ ~CDRMSyncobjProtocol() = default;
virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id);
@@ -69,9 +100,9 @@ class CDRMSyncobjProtocol : public IWaylandProtocol {
void destroyResource(CDRMSyncobjSurfaceResource* resource);
//
- std::vector<SP<CDRMSyncobjManagerResource>> m_vManagers;
- std::vector<SP<CDRMSyncobjTimelineResource>> m_vTimelines;
- std::vector<SP<CDRMSyncobjSurfaceResource>> m_vSurfaces;
+ std::vector<UP<CDRMSyncobjManagerResource>> m_vManagers;
+ std::vector<UP<CDRMSyncobjTimelineResource>> m_vTimelines;
+ std::vector<UP<CDRMSyncobjSurfaceResource>> m_vSurfaces;
//
int drmFD = -1;
diff --git a/src/protocols/LinuxDMABUF.cpp b/src/protocols/LinuxDMABUF.cpp
index b7b91594..72022285 100644
--- a/src/protocols/LinuxDMABUF.cpp
+++ b/src/protocols/LinuxDMABUF.cpp
@@ -111,6 +111,9 @@ CLinuxDMABuffer::CLinuxDMABuffer(uint32_t id, wl_client* client, Aquamarine::SDM
}
CLinuxDMABuffer::~CLinuxDMABuffer() {
+ if (buffer && buffer->resource)
+ buffer->resource->sendRelease();
+
buffer.reset();
listeners.bufferResourceDestroy.reset();
}
diff --git a/src/protocols/LinuxDMABUF.hpp b/src/protocols/LinuxDMABUF.hpp
index 6c967878..d55ce8a7 100644
--- a/src/protocols/LinuxDMABUF.hpp
+++ b/src/protocols/LinuxDMABUF.hpp
@@ -97,6 +97,7 @@ class CLinuxDMABUFFeedbackResource {
class CLinuxDMABUFResource {
public:
CLinuxDMABUFResource(SP<CZwpLinuxDmabufV1> resource_);
+ ~CLinuxDMABUFResource() = default;
bool good();
void sendMods();
diff --git a/src/protocols/SinglePixel.cpp b/src/protocols/SinglePixel.cpp
index 4d643a53..c383dbb3 100644
--- a/src/protocols/SinglePixel.cpp
+++ b/src/protocols/SinglePixel.cpp
@@ -24,6 +24,11 @@ CSinglePixelBuffer::CSinglePixelBuffer(uint32_t id, wl_client* client, CHyprColo
Debug::log(ERR, "Failed creating a single pixel texture: null texture id");
}
+CSinglePixelBuffer::~CSinglePixelBuffer() {
+ if (resource)
+ resource->sendRelease();
+}
+
Aquamarine::eBufferCapability CSinglePixelBuffer::caps() {
return Aquamarine::eBufferCapability::BUFFER_CAPABILITY_DATAPTR;
}
diff --git a/src/protocols/SinglePixel.hpp b/src/protocols/SinglePixel.hpp
index bd0607d6..478f3e35 100644
--- a/src/protocols/SinglePixel.hpp
+++ b/src/protocols/SinglePixel.hpp
@@ -9,7 +9,7 @@
class CSinglePixelBuffer : public IHLBuffer {
public:
CSinglePixelBuffer(uint32_t id, wl_client* client, CHyprColor col);
- virtual ~CSinglePixelBuffer() = default;
+ virtual ~CSinglePixelBuffer();
virtual Aquamarine::eBufferCapability caps();
virtual Aquamarine::eBufferType type();
diff --git a/src/protocols/core/Compositor.cpp b/src/protocols/core/Compositor.cpp
index f7af9504..a9fe33db 100644
--- a/src/protocols/core/Compositor.cpp
+++ b/src/protocols/core/Compositor.cpp
@@ -113,8 +113,8 @@ CWLSurfaceResource::CWLSurfaceResource(SP<CWlSurface> resource_) : resource(reso
return;
}
- if (stateLocks <= 0)
- commitPendingState();
+ if (!syncobj)
+ commitPendingState(pending);
});
resource->setDamage([this](CWlSurface* r, int32_t x, int32_t y, int32_t w, int32_t h) { pending.damage.add(CBox{x, y, w, h}); });
@@ -428,29 +428,14 @@ CRegion CWLSurfaceResource::accumulateCurrentBufferDamage() {
return surfaceDamage.scale(current.scale).transform(wlTransformToHyprutils(invertTransform(current.transform)), trc.x, trc.y).add(current.bufferDamage);
}
-void CWLSurfaceResource::lockPendingState() {
- stateLocks++;
-}
-
-void CWLSurfaceResource::unlockPendingState() {
- stateLocks--;
- if (stateLocks <= 0)
- commitPendingState();
-}
-
-void CWLSurfaceResource::commitPendingState() {
- static auto PDROP = CConfigValue<Hyprlang::INT>("render:allow_early_buffer_release");
- current = pending;
- pending.damage.clear();
- pending.bufferDamage.clear();
- pending.newBuffer = false;
- if (!*PDROP)
- dropPendingBuffer(); // at this point current.buffer holds the same SP and we don't use pending anymore
-
- events.roleCommit.emit();
-
- if (syncobj && syncobj->current.releaseTimeline && syncobj->current.releaseTimeline->timeline && current.buffer && current.buffer->buffer)
- current.buffer->releaser = makeShared<CSyncReleaser>(syncobj->current.releaseTimeline->timeline, syncobj->current.releasePoint);
+void CWLSurfaceResource::commitPendingState(SSurfaceState& state) {
+ if (state.newBuffer) {
+ state.newBuffer = false;
+ current = state;
+ state.damage.clear();
+ state.bufferDamage.clear();
+ state.buffer.reset();
+ }
if (current.texture)
current.texture->m_eTransform = wlTransformToHyprutils(current.transform);
@@ -463,14 +448,6 @@ void CWLSurfaceResource::commitPendingState() {
// TODO: don't update the entire texture
if (role->role() == SURFACE_ROLE_CURSOR && !DAMAGE.empty())
updateCursorShm(DAMAGE);
-
- // release the buffer if it's synchronous as update() has done everything thats needed
- // so we can let the app know we're done.
- // Some clients aren't ready to receive a release this early. Should be fine to release it on the next commitPendingState.
- if (current.buffer->buffer->isSynchronous() && *PDROP) {
- dropCurrentBuffer();
- dropPendingBuffer(); // at this point current.buffer holds the same SP and we don't use pending anymore
- }
}
// TODO: we should _accumulate_ and not replace above if sync
@@ -494,11 +471,16 @@ void CWLSurfaceResource::commitPendingState() {
nullptr);
}
- lastBuffer = current.buffer ? current.buffer->buffer : WP<IHLBuffer>{};
+ // release the buffer if it's synchronous as update() has done everything thats needed
+ // so we can let the app know we're done.
+ // if (!syncobj && current.buffer && current.buffer->buffer && current.buffer->buffer->isSynchronous()) {
+ // dropCurrentBuffer(); // lets not drop it at all, it will get dropped on next commit if a new buffer arrives.
+ // solves flickering on nonsyncobj apps on explicit sync.
+ // }
}
void CWLSurfaceResource::updateCursorShm(CRegion damage) {
- auto buf = current.buffer ? current.buffer->buffer : lastBuffer;
+ auto buf = current.buffer ? current.buffer->buffer : WP<IHLBuffer>{};
if UNLIKELY (!buf)
return;
diff --git a/src/protocols/core/Compositor.hpp b/src/protocols/core/Compositor.hpp
index 39690017..f958528c 100644
--- a/src/protocols/core/Compositor.hpp
+++ b/src/protocols/core/Compositor.hpp
@@ -16,6 +16,7 @@
#include "../../helpers/math/Math.hpp"
#include "../types/Buffer.hpp"
#include "../types/SurfaceRole.hpp"
+#include "../types/SurfaceState.hpp"
class CWLOutputResource;
class CMonitor;
@@ -77,42 +78,15 @@ class CWLSurfaceResource {
Vector2D sourceSize();
struct {
- CSignal precommit; // before commit
- CSignal roleCommit; // commit for role objects, before regular commit
- CSignal commit; // after commit
+ CSignal precommit; // before commit
+ CSignal commit; // after commit
CSignal map;
CSignal unmap;
CSignal newSubsurface;
CSignal destroy;
} events;
- struct SState {
- CRegion opaque, input = CBox{{}, {INT32_MAX, INT32_MAX}}, damage, bufferDamage = CBox{{}, {INT32_MAX, INT32_MAX}} /* initial damage */;
- wl_output_transform transform = WL_OUTPUT_TRANSFORM_NORMAL;
- int scale = 1;
- SP<CHLBufferReference> buffer; // buffer ref will be released once the buffer is no longer locked. For checking if a buffer is attached to this state, check texture.
- SP<CTexture> texture;
- Vector2D offset;
- Vector2D size, bufferSize;
- struct {
- bool hasDestination = false;
- bool hasSource = false;
- Vector2D destination;
- CBox source;
- } viewport;
- bool rejected = false;
- bool newBuffer = false;
-
- //
- void reset() {
- damage.clear();
- bufferDamage.clear();
- transform = WL_OUTPUT_TRANSFORM_NORMAL;
- scale = 1;
- offset = {};
- size = {};
- }
- } current, pending;
+ SSurfaceState current, pending;
std::vector<SP<CWLCallbackResource>> callbacks;
WP<CWLSurfaceResource> self;
@@ -130,28 +104,20 @@ class CWLSurfaceResource {
SP<CWLSurfaceResource> findFirstPreorder(std::function<bool(SP<CWLSurfaceResource>)> fn);
CRegion accumulateCurrentBufferDamage();
void presentFeedback(timespec* when, PHLMONITOR pMonitor, bool discarded = false);
- void lockPendingState();
- void unlockPendingState();
+ void commitPendingState(SSurfaceState& state);
// returns a pair: found surface (null if not found) and surface local coords.
// localCoords param is relative to 0,0 of this surface
std::pair<SP<CWLSurfaceResource>, Vector2D> at(const Vector2D& localCoords, bool allowsInput = false);
private:
- SP<CWlSurface> resource;
- wl_client* pClient = nullptr;
-
- // this is for cursor dumb copy. Due to our (and wayland's...) architecture,
- // this stupid-ass hack is used
- WP<IHLBuffer> lastBuffer;
-
- int stateLocks = 0;
+ SP<CWlSurface> resource;
+ wl_client* pClient = nullptr;
void destroy();
void releaseBuffers(bool onlyCurrent = true);
void dropPendingBuffer();
void dropCurrentBuffer();
- void commitPendingState();
void bfHelper(std::vector<SP<CWLSurfaceResource>> const& nodes, std::function<void(SP<CWLSurfaceResource>, const Vector2D&, void*)> fn, void* data);
SP<CWLSurfaceResource> findFirstPreorderHelper(SP<CWLSurfaceResource> root, std::function<bool(SP<CWLSurfaceResource>)> fn);
void updateCursorShm(CRegion damage = CBox{0, 0, INT16_MAX, INT16_MAX});
diff --git a/src/protocols/core/Shm.cpp b/src/protocols/core/Shm.cpp
index e0e62560..37a48fd3 100644
--- a/src/protocols/core/Shm.cpp
+++ b/src/protocols/core/Shm.cpp
@@ -37,6 +37,11 @@ CWLSHMBuffer::CWLSHMBuffer(SP<CWLSHMPoolResource> pool_, uint32_t id, int32_t of
Debug::log(ERR, "Failed creating a shm texture: null texture id");
}
+CWLSHMBuffer::~CWLSHMBuffer() {
+ if (resource)
+ resource->sendRelease();
+}
+
Aquamarine::eBufferCapability CWLSHMBuffer::caps() {
return Aquamarine::eBufferCapability::BUFFER_CAPABILITY_DATAPTR;
}
diff --git a/src/protocols/core/Shm.hpp b/src/protocols/core/Shm.hpp
index fef821cb..fa5f29a4 100644
--- a/src/protocols/core/Shm.hpp
+++ b/src/protocols/core/Shm.hpp
@@ -33,7 +33,7 @@ class CSHMPool {
class CWLSHMBuffer : public IHLBuffer {
public:
CWLSHMBuffer(SP<CWLSHMPoolResource> pool, uint32_t id, int32_t offset, const Vector2D& size, int32_t stride, uint32_t fmt);
- virtual ~CWLSHMBuffer() = default;
+ virtual ~CWLSHMBuffer();
virtual Aquamarine::eBufferCapability caps();
virtual Aquamarine::eBufferType type();
diff --git a/src/protocols/types/Buffer.cpp b/src/protocols/types/Buffer.cpp
index 9fb6294f..2623435b 100644
--- a/src/protocols/types/Buffer.cpp
+++ b/src/protocols/types/Buffer.cpp
@@ -18,8 +18,10 @@ void IHLBuffer::unlock() {
ASSERT(nLocks >= 0);
- if (nLocks == 0)
+ if (nLocks == 0) {
sendRelease();
+ syncReleaser.reset();
+ }
}
bool IHLBuffer::locked() {
@@ -43,7 +45,7 @@ CHLBufferReference::CHLBufferReference(SP<IHLBuffer> buffer_, SP<CWLSurfaceResou
}
CHLBufferReference::~CHLBufferReference() {
- if (buffer.expired())
+ if (!buffer)
return;
buffer->unlock();
diff --git a/src/protocols/types/Buffer.hpp b/src/protocols/types/Buffer.hpp
index bd02e2db..79cc6ce6 100644
--- a/src/protocols/types/Buffer.hpp
+++ b/src/protocols/types/Buffer.hpp
@@ -3,6 +3,7 @@
#include "../../defines.hpp"
#include "../../render/Texture.hpp"
#include "./WLBuffer.hpp"
+#include "protocols/DRMSyncobj.hpp"
#include <aquamarine/buffer/Buffer.hpp>
@@ -26,6 +27,7 @@ class IHLBuffer : public Aquamarine::IBuffer {
SP<CTexture> texture;
bool opaque = false;
SP<CWLBufferResource> resource;
+ UP<CSyncReleaser> syncReleaser;
struct {
CHyprSignalListener backendRelease;
@@ -43,8 +45,9 @@ class CHLBufferReference {
CHLBufferReference(SP<IHLBuffer> buffer, SP<CWLSurfaceResource> surface);
~CHLBufferReference();
- WP<IHLBuffer> buffer;
- SP<CSyncReleaser> releaser;
+ WP<IHLBuffer> buffer;
+ UP<CDRMSyncPointState> acquire;
+ UP<CDRMSyncPointState> release;
private:
WP<CWLSurfaceResource> surface;
diff --git a/src/protocols/types/DMABuffer.cpp b/src/protocols/types/DMABuffer.cpp
index 3f53225c..2e39bf79 100644
--- a/src/protocols/types/DMABuffer.cpp
+++ b/src/protocols/types/DMABuffer.cpp
@@ -36,6 +36,9 @@ CDMABuffer::CDMABuffer(uint32_t id, wl_client* client, Aquamarine::SDMABUFAttrs
}
CDMABuffer::~CDMABuffer() {
+ if (resource)
+ resource->sendRelease();
+
closeFDs();
}
diff --git a/src/protocols/types/SurfaceState.hpp b/src/protocols/types/SurfaceState.hpp
new file mode 100644
index 00000000..cd9be5ca
--- /dev/null
+++ b/src/protocols/types/SurfaceState.hpp
@@ -0,0 +1,35 @@
+#pragma once
+
+#include "../../helpers/math/Math.hpp"
+#include "../WaylandProtocol.hpp"
+
+class CHLBufferReference;
+class CTexture;
+
+struct SSurfaceState {
+ CRegion opaque, input = CBox{{}, {INT32_MAX, INT32_MAX}}, damage, bufferDamage = CBox{{}, {INT32_MAX, INT32_MAX}} /* initial damage */;
+ wl_output_transform transform = WL_OUTPUT_TRANSFORM_NORMAL;
+ int scale = 1;
+ SP<CHLBufferReference> buffer; // buffer ref will be released once the buffer is no longer locked. For checking if a buffer is attached to this state, check texture.
+ SP<CTexture> texture;
+ Vector2D offset;
+ Vector2D size, bufferSize;
+ struct {
+ bool hasDestination = false;
+ bool hasSource = false;
+ Vector2D destination;
+ CBox source;
+ } viewport;
+ bool rejected = false;
+ bool newBuffer = false;
+
+ //
+ void reset() {
+ damage.clear();
+ bufferDamage.clear();
+ transform = WL_OUTPUT_TRANSFORM_NORMAL;
+ scale = 1;
+ offset = {};
+ size = {};
+ }
+};
diff --git a/src/protocols/types/WLBuffer.cpp b/src/protocols/types/WLBuffer.cpp
index 4bd115a2..f2b81c00 100644
--- a/src/protocols/types/WLBuffer.cpp
+++ b/src/protocols/types/WLBuffer.cpp
@@ -5,7 +5,7 @@
#include "../../helpers/sync/SyncTimeline.hpp"
#include <xf86drm.h>
-CWLBufferResource::CWLBufferResource(SP<CWlBuffer> resource_) : resource(resource_) {
+CWLBufferResource::CWLBufferResource(WP<CWlBuffer> resource_) : resource(resource_.lock()) {
if UNLIKELY (!good())
return;
@@ -40,7 +40,7 @@ SP<CWLBufferResource> CWLBufferResource::fromResource(wl_resource* res) {
return data ? data->self.lock() : nullptr;
}
-SP<CWLBufferResource> CWLBufferResource::create(SP<CWlBuffer> resource) {
+SP<CWLBufferResource> CWLBufferResource::create(WP<CWlBuffer> resource) {
auto p = SP<CWLBufferResource>(new CWLBufferResource(resource));
p->self = p;
return p;
diff --git a/src/protocols/types/WLBuffer.hpp b/src/protocols/types/WLBuffer.hpp
index 3894affc..c7e21d4c 100644
--- a/src/protocols/types/WLBuffer.hpp
+++ b/src/protocols/types/WLBuffer.hpp
@@ -11,7 +11,7 @@ class CWLSurfaceResource;
class CWLBufferResource {
public:
- static SP<CWLBufferResource> create(SP<CWlBuffer> resource);
+ static SP<CWLBufferResource> create(WP<CWlBuffer> resource);
static SP<CWLBufferResource> fromResource(wl_resource* res);
bool good();
@@ -23,7 +23,7 @@ class CWLBufferResource {
WP<CWLBufferResource> self;
private:
- CWLBufferResource(SP<CWlBuffer> resource_);
+ CWLBufferResource(WP<CWlBuffer> resource_);
SP<CWlBuffer> resource;