Skip to content

Commit

Permalink
drm: drop buffers from KMS on .destroy
Browse files Browse the repository at this point in the history
  • Loading branch information
vaxerski committed Jul 8, 2024
1 parent d695696 commit ef43e51
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
7 changes: 7 additions & 0 deletions include/aquamarine/backend/DRM.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,19 @@ namespace Aquamarine {
Hyprutils::Memory::CWeakPointer<CDRMBackend> backend;
std::array<uint32_t, 4> boHandles = {0, 0, 0, 0};

// true if the original buffer is gone and this has been released.
bool dead = false;

private:
CDRMFB(Hyprutils::Memory::CSharedPointer<IBuffer> buffer_, Hyprutils::Memory::CWeakPointer<CDRMBackend> backend_);
uint32_t submitBuffer();
void import();

bool dropped = false, handlesClosed = false;

struct {
Hyprutils::Signal::CHyprSignalListener destroyBuffer;
} listeners;
};

struct SDRMLayer {
Expand Down
3 changes: 1 addition & 2 deletions src/allocator/GBM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ static SDRMFormat guessFormatFrom(std::vector<SDRMFormat> formats, bool cursor)
}

Aquamarine::CGBMBuffer::CGBMBuffer(const SAllocatorBufferParams& params, Hyprutils::Memory::CWeakPointer<CGBMAllocator> allocator_,
Hyprutils::Memory::CSharedPointer<CSwapchain> swapchain) :
allocator(allocator_) {
Hyprutils::Memory::CSharedPointer<CSwapchain> swapchain) : allocator(allocator_) {
if (!allocator)
return;

Expand Down
12 changes: 12 additions & 0 deletions src/backend/drm/DRM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1308,6 +1308,11 @@ bool Aquamarine::CDRMOutput::commitState(bool onlyTest) {
return false;
}

if (drmFB->dead) {
backend->backend->log(AQ_LOG_ERROR, "drm: KMS buffer is dead?!");
return false;
}

if (!isNew && backend->primary) {
// this is not a new buffer, and we are not on a primary GPU, which means
// this buffer lives on the primary. We need to re-import it to update
Expand Down Expand Up @@ -1507,6 +1512,13 @@ void Aquamarine::CDRMFB::import() {

// FIXME: why does this implode when it doesnt on wlroots or kwin?
// closeHandles();

listeners.destroyBuffer = buffer->events.destroy.registerListener([this](std::any d) {
drop();
dead = true;
id = 0;
boHandles = {0, 0, 0, 0};
});
}

void Aquamarine::CDRMFB::reimport() {
Expand Down

0 comments on commit ef43e51

Please sign in to comment.