screencopy: fix screencopy frames not being cleaned up (#8017)

---------

Co-authored-by: Vaxry <vaxry@vaxry.net>
This commit is contained in:
Ikalco 2024-10-07 19:23:48 -05:00 committed by GitHub
parent a364df4c9e
commit 0d70c44253
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 24 additions and 15 deletions

View File

@ -394,12 +394,12 @@ void CScreencopyProtocol::bindManager(wl_client* client, void* data, uint32_t ve
void CScreencopyProtocol::destroyResource(CScreencopyClient* client) {
std::erase_if(m_vClients, [&](const auto& other) { return other.get() == client; });
std::erase_if(m_vFrames, [&](const auto& other) { return other->client.get() == client; });
std::erase_if(m_vFramesAwaitingWrite, [&](const auto& other) { return other->client.get() == client; });
std::erase_if(m_vFramesAwaitingWrite, [&](const auto& other) { return !other || other->client.get() == client; });
}
void CScreencopyProtocol::destroyResource(CScreencopyFrame* frame) {
std::erase_if(m_vFrames, [&](const auto& other) { return other.get() == frame; });
std::erase_if(m_vFramesAwaitingWrite, [&](const auto& other) { return other.get() == frame; });
std::erase_if(m_vFramesAwaitingWrite, [&](const auto& other) { return !other || other.get() == frame; });
}
void CScreencopyProtocol::onOutputCommit(CMonitor* pMonitor) {
@ -412,8 +412,11 @@ void CScreencopyProtocol::onOutputCommit(CMonitor* pMonitor) {
// share frame if correct output
for (auto const& f : m_vFramesAwaitingWrite) {
if (!f)
continue;
if (!f->pMonitor || !f->buffer) {
framesToRemove.push_back(f);
framesToRemove.emplace_back(f);
continue;
}
@ -425,10 +428,10 @@ void CScreencopyProtocol::onOutputCommit(CMonitor* pMonitor) {
f->client->lastFrame.reset();
++f->client->frameCounter;
framesToRemove.push_back(f);
framesToRemove.emplace_back(f);
}
for (auto const& f : framesToRemove) {
destroyResource(f.get());
std::erase(m_vFramesAwaitingWrite, f);
}
}

View File

@ -54,7 +54,7 @@ class CScreencopyFrame {
bool good();
SP<CScreencopyFrame> self;
WP<CScreencopyFrame> self;
WP<CScreencopyClient> client;
private:
@ -92,7 +92,7 @@ class CScreencopyProtocol : public IWaylandProtocol {
private:
std::vector<SP<CScreencopyFrame>> m_vFrames;
std::vector<SP<CScreencopyFrame>> m_vFramesAwaitingWrite;
std::vector<WP<CScreencopyFrame>> m_vFramesAwaitingWrite;
std::vector<SP<CScreencopyClient>> m_vClients;
SP<CEventLoopTimer> m_pSoftwareCursorTimer;

View File

@ -354,12 +354,12 @@ void CToplevelExportProtocol::bindManager(wl_client* client, void* data, uint32_
void CToplevelExportProtocol::destroyResource(CToplevelExportClient* client) {
std::erase_if(m_vClients, [&](const auto& other) { return other.get() == client; });
std::erase_if(m_vFrames, [&](const auto& other) { return other->client.get() == client; });
std::erase_if(m_vFramesAwaitingWrite, [&](const auto& other) { return other->client.get() == client; });
std::erase_if(m_vFramesAwaitingWrite, [&](const auto& other) { return !other || other->client.get() == client; });
}
void CToplevelExportProtocol::destroyResource(CToplevelExportFrame* frame) {
std::erase_if(m_vFrames, [&](const auto& other) { return other.get() == frame; });
std::erase_if(m_vFramesAwaitingWrite, [&](const auto& other) { return other.get() == frame; });
std::erase_if(m_vFramesAwaitingWrite, [&](const auto& other) { return !other || other.get() == frame; });
}
void CToplevelExportProtocol::onOutputCommit(CMonitor* pMonitor) {
@ -370,11 +370,17 @@ void CToplevelExportProtocol::onOutputCommit(CMonitor* pMonitor) {
// share frame if correct output
for (auto const& f : m_vFramesAwaitingWrite) {
if (!f->pWindow || !validMapped(f->pWindow)) {
framesToRemove.push_back(f);
if (!f)
continue;
if (!validMapped(f->pWindow)) {
framesToRemove.emplace_back(f);
continue;
}
if (!f->pWindow)
continue;
const auto PWINDOW = f->pWindow;
if (pMonitor != g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID))
@ -394,7 +400,7 @@ void CToplevelExportProtocol::onOutputCommit(CMonitor* pMonitor) {
}
for (auto const& f : framesToRemove) {
destroyResource(f.get());
std::erase(m_vFramesAwaitingWrite, f);
}
}

View File

@ -45,7 +45,7 @@ class CToplevelExportFrame {
bool good();
SP<CToplevelExportFrame> self;
WP<CToplevelExportFrame> self;
WP<CToplevelExportClient> client;
private:
@ -85,7 +85,7 @@ class CToplevelExportProtocol : IWaylandProtocol {
private:
std::vector<SP<CToplevelExportClient>> m_vClients;
std::vector<SP<CToplevelExportFrame>> m_vFrames;
std::vector<SP<CToplevelExportFrame>> m_vFramesAwaitingWrite;
std::vector<WP<CToplevelExportFrame>> m_vFramesAwaitingWrite;
void shareFrame(CToplevelExportFrame* frame);
bool copyFrameDmabuf(CToplevelExportFrame* frame, timespec* now);

@ -1 +1 @@
Subproject commit e06482e0e611130cd1929f75e8c1cf679e57d161
Subproject commit c7c3f4cd0faed21fc90ba6bd06fe4f3e0e057ea8