internal: cleanup CMonitor usage and fix a few ref hogs

ref #8221
This commit is contained in:
Vaxry
2024-10-26 02:06:13 +01:00
parent e5384774a8
commit d5689bb539
30 changed files with 116 additions and 118 deletions

View File

@@ -81,6 +81,6 @@ void CHyprlandCTMControlProtocol::destroyResource(CHyprlandCTMControlResource* r
std::erase_if(m_vManagers, [&](const auto& other) { return other.get() == res; });
}
void CHyprlandCTMControlProtocol::setCTM(SP<CMonitor> monitor, const Mat3x3& ctm) {
void CHyprlandCTMControlProtocol::setCTM(PHLMONITOR monitor, const Mat3x3& ctm) {
monitor->setCTM(ctm);
}

View File

@@ -31,7 +31,7 @@ class CHyprlandCTMControlProtocol : public IWaylandProtocol {
private:
void destroyResource(CHyprlandCTMControlResource* resource);
void setCTM(SP<CMonitor> monitor, const Mat3x3& ctm);
void setCTM(PHLMONITOR monitor, const Mat3x3& ctm);
//
std::vector<SP<CHyprlandCTMControlResource>> m_vManagers;

View File

@@ -129,7 +129,7 @@ SP<CDRMLeaseConnectorResource> CDRMLeaseConnectorResource::fromResource(wl_resou
return data ? data->self.lock() : nullptr;
}
CDRMLeaseConnectorResource::CDRMLeaseConnectorResource(SP<CWpDrmLeaseConnectorV1> resource_, SP<CMonitor> monitor_) : monitor(monitor_), resource(resource_) {
CDRMLeaseConnectorResource::CDRMLeaseConnectorResource(SP<CWpDrmLeaseConnectorV1> resource_, PHLMONITOR monitor_) : monitor(monitor_), resource(resource_) {
if (!good())
return;
@@ -203,7 +203,7 @@ bool CDRMLeaseDeviceResource::good() {
return resource->resource();
}
void CDRMLeaseDeviceResource::sendConnector(SP<CMonitor> monitor) {
void CDRMLeaseDeviceResource::sendConnector(PHLMONITOR monitor) {
if (std::find_if(connectorsSent.begin(), connectorsSent.end(), [monitor](const auto& e) { return e && !e->dead && e->monitor == monitor; }) != connectorsSent.end())
return;
@@ -289,7 +289,7 @@ void CDRMLeaseProtocol::destroyResource(CDRMLeaseResource* resource) {
std::erase_if(m_vLeases, [resource](const auto& e) { return e.get() == resource; });
}
void CDRMLeaseProtocol::offer(SP<CMonitor> monitor) {
void CDRMLeaseProtocol::offer(PHLMONITOR monitor) {
std::erase_if(primaryDevice->offeredOutputs, [](const auto& e) { return e.expired(); });
if (std::find(primaryDevice->offeredOutputs.begin(), primaryDevice->offeredOutputs.end(), monitor) != primaryDevice->offeredOutputs.end())
return;

View File

@@ -56,7 +56,7 @@ class CDRMLeaseRequestResource {
class CDRMLeaseConnectorResource {
public:
CDRMLeaseConnectorResource(SP<CWpDrmLeaseConnectorV1> resource_, SP<CMonitor> monitor_);
CDRMLeaseConnectorResource(SP<CWpDrmLeaseConnectorV1> resource_, PHLMONITOR monitor_);
static SP<CDRMLeaseConnectorResource> fromResource(wl_resource*);
bool good();
@@ -64,7 +64,7 @@ class CDRMLeaseConnectorResource {
WP<CDRMLeaseConnectorResource> self;
WP<CDRMLeaseDeviceResource> parent;
WP<CMonitor> monitor;
PHLMONITORREF monitor;
bool dead = false;
private:
@@ -82,7 +82,7 @@ class CDRMLeaseDeviceResource {
CDRMLeaseDeviceResource(SP<CWpDrmLeaseDeviceV1> resource_);
bool good();
void sendConnector(SP<CMonitor> monitor);
void sendConnector(PHLMONITOR monitor);
std::vector<WP<CDRMLeaseConnectorResource>> connectorsSent;
@@ -102,7 +102,7 @@ class CDRMLeaseDevice {
bool success = false;
SP<Aquamarine::CDRMBackend> backend;
std::vector<WP<CMonitor>> offeredOutputs;
std::vector<PHLMONITORREF> offeredOutputs;
};
class CDRMLeaseProtocol : public IWaylandProtocol {
@@ -111,7 +111,7 @@ class CDRMLeaseProtocol : public IWaylandProtocol {
virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id);
void offer(SP<CMonitor> monitor);
void offer(PHLMONITOR monitor);
private:
void destroyResource(CDRMLeaseDeviceResource* resource);

View File

@@ -21,7 +21,7 @@ static std::optional<dev_t> devIDFromFD(int fd) {
return stat.st_rdev;
}
CDMABUFFormatTable::CDMABUFFormatTable(SDMABUFTranche _rendererTranche, std::vector<std::pair<SP<CMonitor>, SDMABUFTranche>> tranches_) :
CDMABUFFormatTable::CDMABUFFormatTable(SDMABUFTranche _rendererTranche, std::vector<std::pair<PHLMONITORREF, SDMABUFTranche>> tranches_) :
rendererTranche(_rendererTranche), monitorTranches(tranches_) {
std::vector<SDMABUFFormatTableEntry> formatsVec;
@@ -436,7 +436,7 @@ CLinuxDMABufV1Protocol::CLinuxDMABufV1Protocol(const wl_interface* iface, const
.formats = g_pHyprOpenGL->getDRMFormats(),
};
std::vector<std::pair<SP<CMonitor>, SDMABUFTranche>> tches;
std::vector<std::pair<PHLMONITORREF, SDMABUFTranche>> tches;
if (g_pCompositor->m_pAqBackend->hasSession()) {
// this assumes there's only 1 device used for both scanout and rendering
@@ -453,20 +453,18 @@ CLinuxDMABufV1Protocol::CLinuxDMABufV1Protocol(const wl_interface* iface, const
static auto monitorAdded = g_pHookSystem->hookDynamic("monitorAdded", [this](void* self, SCallbackInfo& info, std::any param) {
auto pMonitor = std::any_cast<PHLMONITOR>(param);
auto mon = pMonitor->self.lock();
auto tranche = SDMABUFTranche{
.device = mainDevice,
.flags = ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FLAGS_SCANOUT,
.formats = mon->output->getRenderFormats(),
.formats = pMonitor->output->getRenderFormats(),
};
formatTable->monitorTranches.push_back(std::make_pair<>(mon, tranche));
formatTable->monitorTranches.push_back(std::make_pair<>(pMonitor, tranche));
resetFormatTable();
});
static auto monitorRemoved = g_pHookSystem->hookDynamic("monitorRemoved", [this](void* self, SCallbackInfo& info, std::any param) {
auto pMonitor = std::any_cast<PHLMONITOR>(param);
auto mon = pMonitor->self.lock();
std::erase_if(formatTable->monitorTranches, [mon](std::pair<SP<CMonitor>, SDMABUFTranche> pair) { return pair.first == mon; });
std::erase_if(formatTable->monitorTranches, [pMonitor](std::pair<PHLMONITORREF, SDMABUFTranche> pair) { return pair.first == pMonitor; });
resetFormatTable();
});
}
@@ -508,8 +506,8 @@ void CLinuxDMABufV1Protocol::resetFormatTable() {
for (auto const& feedback : m_vFeedbacks) {
feedback->resource->sendFormatTable(newFormatTable->tableFD, newFormatTable->tableSize);
if (feedback->lastFeedbackWasScanout) {
SP<CMonitor> mon;
auto HLSurface = CWLSurface::fromResource(feedback->surface);
PHLMONITOR mon;
auto HLSurface = CWLSurface::fromResource(feedback->surface);
if (auto w = HLSurface->getWindow(); w)
if (auto m = g_pCompositor->getMonitorFromID(w->m_iMonitorID); m)
mon = m->self.lock();
@@ -560,7 +558,7 @@ void CLinuxDMABufV1Protocol::destroyResource(CLinuxDMABuffer* resource) {
std::erase_if(m_vBuffers, [&](const auto& other) { return other.get() == resource; });
}
void CLinuxDMABufV1Protocol::updateScanoutTranche(SP<CWLSurfaceResource> surface, SP<CMonitor> pMonitor) {
void CLinuxDMABufV1Protocol::updateScanoutTranche(SP<CWLSurfaceResource> surface, PHLMONITOR pMonitor) {
SP<CLinuxDMABUFFeedbackResource> feedbackResource;
for (auto const& f : m_vFeedbacks) {
if (f->surface != surface)
@@ -582,7 +580,7 @@ void CLinuxDMABufV1Protocol::updateScanoutTranche(SP<CWLSurfaceResource> surface
}
const auto& monitorTranchePair = std::find_if(formatTable->monitorTranches.begin(), formatTable->monitorTranches.end(),
[pMonitor](std::pair<SP<CMonitor>, SDMABUFTranche> pair) { return pair.first == pMonitor; });
[pMonitor](std::pair<PHLMONITORREF, SDMABUFTranche> pair) { return pair.first == pMonitor; });
if (monitorTranchePair == formatTable->monitorTranches.end()) {
LOGM(LOG, "updateScanoutTranche: monitor has no tranche");

View File

@@ -48,13 +48,13 @@ struct SDMABUFTranche {
class CDMABUFFormatTable {
public:
CDMABUFFormatTable(SDMABUFTranche rendererTranche, std::vector<std::pair<SP<CMonitor>, SDMABUFTranche>> tranches);
CDMABUFFormatTable(SDMABUFTranche rendererTranche, std::vector<std::pair<PHLMONITORREF, SDMABUFTranche>> tranches);
~CDMABUFFormatTable();
int tableFD = -1;
size_t tableSize = 0;
SDMABUFTranche rendererTranche;
std::vector<std::pair<SP<CMonitor>, SDMABUFTranche>> monitorTranches;
int tableFD = -1;
size_t tableSize = 0;
SDMABUFTranche rendererTranche;
std::vector<std::pair<PHLMONITORREF, SDMABUFTranche>> monitorTranches;
};
class CLinuxDMABBUFParamsResource {
@@ -111,7 +111,7 @@ class CLinuxDMABufV1Protocol : public IWaylandProtocol {
~CLinuxDMABufV1Protocol();
virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id);
void updateScanoutTranche(SP<CWLSurfaceResource> surface, SP<CMonitor> pMonitor);
void updateScanoutTranche(SP<CWLSurfaceResource> surface, PHLMONITOR pMonitor);
private:
void destroyResource(CLinuxDMABUFResource* resource);

View File

@@ -633,7 +633,7 @@ SP<COutputMode> COutputManagementProtocol::modeFromResource(wl_resource* r) {
return nullptr;
}
SP<SWlrManagerSavedOutputState> COutputManagementProtocol::getOutputStateFor(SP<CMonitor> pMonitor) {
SP<SWlrManagerSavedOutputState> COutputManagementProtocol::getOutputStateFor(PHLMONITOR pMonitor) {
for (auto const& m : m_vManagers) {
if (!m->monitorStates.contains(pMonitor->szName))
continue;

View File

@@ -153,7 +153,7 @@ class COutputManagementProtocol : public IWaylandProtocol {
virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id);
// doesn't have to return one
SP<SWlrManagerSavedOutputState> getOutputStateFor(SP<CMonitor> pMonitor);
SP<SWlrManagerSavedOutputState> getOutputStateFor(PHLMONITOR pMonitor);
private:
void destroyResource(COutputManager* resource);

View File

@@ -14,7 +14,7 @@ void CQueuedPresentationData::setPresentationType(bool zeroCopy_) {
zeroCopy = zeroCopy_;
}
void CQueuedPresentationData::attachMonitor(SP<CMonitor> pMonitor_) {
void CQueuedPresentationData::attachMonitor(PHLMONITOR pMonitor_) {
pMonitor = pMonitor_;
}
@@ -73,7 +73,7 @@ void CPresentationFeedback::sendQueued(SP<CQueuedPresentationData> data, timespe
CPresentationProtocol::CPresentationProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
static auto P = g_pHookSystem->hookDynamic("monitorRemoved", [this](void* self, SCallbackInfo& info, std::any param) {
const auto PMONITOR = std::any_cast<PHLMONITOR>(param);
const auto PMONITOR = PHLMONITORREF{std::any_cast<PHLMONITOR>(param)};
std::erase_if(m_vQueue, [PMONITOR](const auto& other) { return !other->surface || other->pMonitor == PMONITOR; });
});
}
@@ -107,7 +107,7 @@ void CPresentationProtocol::onGetFeedback(CWpPresentation* pMgr, wl_resource* su
}
}
void CPresentationProtocol::onPresented(SP<CMonitor> pMonitor, timespec* when, uint32_t untilRefreshNs, uint64_t seq, uint32_t reportedFlags) {
void CPresentationProtocol::onPresented(PHLMONITOR pMonitor, timespec* when, uint32_t untilRefreshNs, uint64_t seq, uint32_t reportedFlags) {
timespec now;
timespec* presentedAt = when;
if (!presentedAt) {

View File

@@ -14,7 +14,7 @@ class CQueuedPresentationData {
CQueuedPresentationData(SP<CWLSurfaceResource> surf);
void setPresentationType(bool zeroCopy);
void attachMonitor(SP<CMonitor> pMonitor);
void attachMonitor(PHLMONITOR pMonitor);
void presented();
void discarded();
@@ -24,7 +24,7 @@ class CQueuedPresentationData {
private:
bool wasPresented = false;
bool zeroCopy = false;
WP<CMonitor> pMonitor;
PHLMONITORREF pMonitor;
WP<CWLSurfaceResource> surface;
friend class CPresentationFeedback;
@@ -53,7 +53,7 @@ class CPresentationProtocol : public IWaylandProtocol {
virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id);
void onPresented(SP<CMonitor> pMonitor, timespec* when, uint32_t untilRefreshNs, uint64_t seq, uint32_t reportedFlags);
void onPresented(PHLMONITOR pMonitor, timespec* when, uint32_t untilRefreshNs, uint64_t seq, uint32_t reportedFlags);
void queueData(SP<CQueuedPresentationData> data);
private:

View File

@@ -1,7 +1,7 @@
#include "VirtualPointer.hpp"
#include "core/Output.hpp"
CVirtualPointerV1Resource::CVirtualPointerV1Resource(SP<CZwlrVirtualPointerV1> resource_, WP<CMonitor> boundOutput_) : boundOutput(boundOutput_), resource(resource_) {
CVirtualPointerV1Resource::CVirtualPointerV1Resource(SP<CZwlrVirtualPointerV1> resource_, PHLMONITORREF boundOutput_) : boundOutput(boundOutput_), resource(resource_) {
if (!good())
return;
@@ -134,7 +134,7 @@ void CVirtualPointerProtocol::destroyResource(CVirtualPointerV1Resource* pointer
std::erase_if(m_vPointers, [&](const auto& other) { return other.get() == pointer; });
}
void CVirtualPointerProtocol::onCreatePointer(CZwlrVirtualPointerManagerV1* pMgr, wl_resource* seat, uint32_t id, WP<CMonitor> output) {
void CVirtualPointerProtocol::onCreatePointer(CZwlrVirtualPointerManagerV1* pMgr, wl_resource* seat, uint32_t id, PHLMONITORREF output) {
const auto RESOURCE = m_vPointers.emplace_back(makeShared<CVirtualPointerV1Resource>(makeShared<CZwlrVirtualPointerV1>(pMgr->client(), pMgr->version(), id), output));

View File

@@ -12,7 +12,7 @@
class CVirtualPointerV1Resource {
public:
CVirtualPointerV1Resource(SP<CZwlrVirtualPointerV1> resource_, WP<CMonitor> boundOutput_);
CVirtualPointerV1Resource(SP<CZwlrVirtualPointerV1> resource_, PHLMONITORREF boundOutput_);
~CVirtualPointerV1Resource();
struct {
@@ -35,12 +35,12 @@ class CVirtualPointerV1Resource {
CSignal holdEnd;
} events;
bool good();
wl_client* client();
bool good();
wl_client* client();
std::string name;
std::string name;
WP<CMonitor> boundOutput;
PHLMONITORREF boundOutput;
private:
SP<CZwlrVirtualPointerV1> resource;
@@ -63,7 +63,7 @@ class CVirtualPointerProtocol : public IWaylandProtocol {
private:
void onManagerResourceDestroy(wl_resource* res);
void destroyResource(CVirtualPointerV1Resource* pointer);
void onCreatePointer(CZwlrVirtualPointerManagerV1* pMgr, wl_resource* seat, uint32_t id, WP<CMonitor> output);
void onCreatePointer(CZwlrVirtualPointerManagerV1* pMgr, wl_resource* seat, uint32_t id, PHLMONITORREF output);
//
std::vector<UP<CZwlrVirtualPointerManagerV1>> m_vManagers;

View File

@@ -95,7 +95,7 @@ void CXDGOutputProtocol::updateAllOutputs() {
//
CXDGOutput::CXDGOutput(SP<CZxdgOutputV1> resource_, SP<CMonitor> monitor_) : monitor(monitor_), resource(resource_) {
CXDGOutput::CXDGOutput(SP<CZxdgOutputV1> resource_, PHLMONITOR monitor_) : monitor(monitor_), resource(resource_) {
if (!resource->resource())
return;

View File

@@ -10,12 +10,12 @@ class CWLOutputProtocol;
class CXDGOutput {
public:
CXDGOutput(SP<CZxdgOutputV1> resource, SP<CMonitor> monitor_);
CXDGOutput(SP<CZxdgOutputV1> resource, PHLMONITOR monitor_);
void sendDetails();
private:
WP<CMonitor> monitor;
PHLMONITORREF monitor;
SP<CZxdgOutputV1> resource;
WP<CWLOutputProtocol> outputProto;

View File

@@ -182,7 +182,7 @@ wl_client* CWLSurfaceResource::client() {
return pClient;
}
void CWLSurfaceResource::enter(SP<CMonitor> monitor) {
void CWLSurfaceResource::enter(PHLMONITOR monitor) {
if (std::find(enteredOutputs.begin(), enteredOutputs.end(), monitor) != enteredOutputs.end())
return;
@@ -209,7 +209,7 @@ void CWLSurfaceResource::enter(SP<CMonitor> monitor) {
resource->sendEnter(output->getResource().get());
}
void CWLSurfaceResource::leave(SP<CMonitor> monitor) {
void CWLSurfaceResource::leave(PHLMONITOR monitor) {
if (std::find(enteredOutputs.begin(), enteredOutputs.end(), monitor) == enteredOutputs.end())
return;
@@ -509,7 +509,7 @@ void CWLSurfaceResource::updateCursorShm() {
memcpy(shmData.data(), pixelData, bufLen);
}
void CWLSurfaceResource::presentFeedback(timespec* when, SP<CMonitor> pMonitor) {
void CWLSurfaceResource::presentFeedback(timespec* when, PHLMONITOR pMonitor) {
frame(when);
auto FEEDBACK = makeShared<CQueuedPresentationData>(self.lock());
FEEDBACK->attachMonitor(pMonitor);

View File

@@ -60,8 +60,8 @@ class CWLSurfaceResource {
bool good();
wl_client* client();
void enter(SP<CMonitor> monitor);
void leave(SP<CMonitor> monitor);
void enter(PHLMONITOR monitor);
void leave(PHLMONITOR monitor);
void sendPreferredTransform(wl_output_transform t);
void sendPreferredScale(int32_t scale);
void frame(timespec* now);
@@ -115,7 +115,7 @@ class CWLSurfaceResource {
std::vector<SP<CWLCallbackResource>> callbacks;
WP<CWLSurfaceResource> self;
WP<CWLSurface> hlSurface;
std::vector<WP<CMonitor>> enteredOutputs;
std::vector<PHLMONITORREF> enteredOutputs;
bool mapped = false;
std::vector<WP<CWLSubsurfaceResource>> subsurfaces;
SP<ISurfaceRole> role;
@@ -124,7 +124,7 @@ class CWLSurfaceResource {
void breadthfirst(std::function<void(SP<CWLSurfaceResource>, const Vector2D&, void*)> fn, void* data);
CRegion accumulateCurrentBufferDamage();
void presentFeedback(timespec* when, SP<CMonitor> pMonitor);
void presentFeedback(timespec* when, PHLMONITOR pMonitor);
void lockPendingState();
void unlockPendingState();

View File

@@ -3,7 +3,7 @@
#include "../../Compositor.hpp"
#include "../../helpers/Monitor.hpp"
CWLOutputResource::CWLOutputResource(SP<CWlOutput> resource_, SP<CMonitor> pMonitor) : monitor(pMonitor), resource(resource_) {
CWLOutputResource::CWLOutputResource(SP<CWlOutput> resource_, PHLMONITOR pMonitor) : monitor(pMonitor), resource(resource_) {
if (!good())
return;
@@ -83,7 +83,7 @@ void CWLOutputResource::updateState() {
resource->sendDone();
}
CWLOutputProtocol::CWLOutputProtocol(const wl_interface* iface, const int& ver, const std::string& name, SP<CMonitor> pMonitor) :
CWLOutputProtocol::CWLOutputProtocol(const wl_interface* iface, const int& ver, const std::string& name, PHLMONITOR pMonitor) :
IWaylandProtocol(iface, ver, name), monitor(pMonitor), szName(pMonitor->szName) {
listeners.modeChanged = monitor->events.modeChanged.registerListener([this](std::any d) {

View File

@@ -12,7 +12,7 @@ class CWLOutputProtocol;
class CWLOutputResource {
public:
CWLOutputResource(SP<CWlOutput> resource_, SP<CMonitor> pMonitor);
CWLOutputResource(SP<CWlOutput> resource_, PHLMONITOR pMonitor);
static SP<CWLOutputResource> fromResource(wl_resource*);
bool good();
@@ -20,7 +20,7 @@ class CWLOutputResource {
SP<CWlOutput> getResource();
void updateState();
WP<CMonitor> monitor;
PHLMONITORREF monitor;
WP<CWLOutputProtocol> owner;
WP<CWLOutputResource> self;
@@ -33,14 +33,14 @@ class CWLOutputResource {
class CWLOutputProtocol : public IWaylandProtocol {
public:
CWLOutputProtocol(const wl_interface* iface, const int& ver, const std::string& name, SP<CMonitor> pMonitor);
CWLOutputProtocol(const wl_interface* iface, const int& ver, const std::string& name, PHLMONITOR pMonitor);
virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id);
SP<CWLOutputResource> outputResourceFrom(wl_client* client);
void sendDone();
WP<CMonitor> monitor;
PHLMONITORREF monitor;
WP<CWLOutputProtocol> self;
// will mark the protocol for removal, will be removed when no. of bound outputs is 0 (or when overwritten by a new global)