mirror of
https://github.com/hyprwm/Hyprland.git
synced 2025-08-15 12:03:48 -07:00
presentation: move to unique ptrs
less refcounting, move by rvalue.
This commit is contained in:
@@ -6,10 +6,10 @@ CContentTypeManager::CContentTypeManager(SP<CWpContentTypeManagerV1> resource) :
|
|||||||
if UNLIKELY (!good())
|
if UNLIKELY (!good())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
resource->setDestroy([](CWpContentTypeManagerV1* r) {});
|
m_resource->setDestroy([](CWpContentTypeManagerV1* r) {});
|
||||||
resource->setOnDestroy([this](CWpContentTypeManagerV1* r) { PROTO::contentType->destroyResource(this); });
|
m_resource->setOnDestroy([this](CWpContentTypeManagerV1* r) { PROTO::contentType->destroyResource(this); });
|
||||||
|
|
||||||
resource->setGetSurfaceContentType([](CWpContentTypeManagerV1* r, uint32_t id, wl_resource* surface) {
|
m_resource->setGetSurfaceContentType([](CWpContentTypeManagerV1* r, uint32_t id, wl_resource* surface) {
|
||||||
LOGM(TRACE, "Get surface for id={}, surface={}", id, (uintptr_t)surface);
|
LOGM(TRACE, "Get surface for id={}, surface={}", id, (uintptr_t)surface);
|
||||||
auto SURF = CWLSurfaceResource::fromResource(surface);
|
auto SURF = CWLSurfaceResource::fromResource(surface);
|
||||||
|
|
||||||
@@ -49,12 +49,12 @@ CContentType::CContentType(SP<CWpContentTypeV1> resource) : m_resource(resource)
|
|||||||
if UNLIKELY (!good())
|
if UNLIKELY (!good())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_client = resource->client();
|
m_client = m_resource->client();
|
||||||
|
|
||||||
resource->setDestroy([this](CWpContentTypeV1* r) { PROTO::contentType->destroyResource(this); });
|
m_resource->setDestroy([this](CWpContentTypeV1* r) { PROTO::contentType->destroyResource(this); });
|
||||||
resource->setOnDestroy([this](CWpContentTypeV1* r) { PROTO::contentType->destroyResource(this); });
|
m_resource->setOnDestroy([this](CWpContentTypeV1* r) { PROTO::contentType->destroyResource(this); });
|
||||||
|
|
||||||
resource->setSetContentType([this](CWpContentTypeV1* r, wpContentTypeV1Type type) { m_value = NContentType::fromWP(type); });
|
m_resource->setSetContentType([this](CWpContentTypeV1* r, wpContentTypeV1Type type) { m_value = NContentType::fromWP(type); });
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CContentType::good() {
|
bool CContentType::good() {
|
||||||
|
@@ -26,7 +26,7 @@ void CQueuedPresentationData::discarded() {
|
|||||||
m_wasPresented = false;
|
m_wasPresented = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CPresentationFeedback::CPresentationFeedback(SP<CWpPresentationFeedback> resource_, SP<CWLSurfaceResource> surf) : m_resource(resource_), m_surface(surf) {
|
CPresentationFeedback::CPresentationFeedback(UP<CWpPresentationFeedback>&& resource_, SP<CWLSurfaceResource> surf) : m_resource(std::move(resource_)), m_surface(surf) {
|
||||||
if UNLIKELY (!good())
|
if UNLIKELY (!good())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ bool CPresentationFeedback::good() {
|
|||||||
return m_resource->resource();
|
return m_resource->resource();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPresentationFeedback::sendQueued(SP<CQueuedPresentationData> data, const Time::steady_tp& when, uint32_t untilRefreshNs, uint64_t seq, uint32_t reportedFlags) {
|
void CPresentationFeedback::sendQueued(WP<CQueuedPresentationData> data, const Time::steady_tp& when, uint32_t untilRefreshNs, uint64_t seq, uint32_t reportedFlags) {
|
||||||
auto client = m_resource->client();
|
auto client = m_resource->client();
|
||||||
|
|
||||||
if LIKELY (PROTO::outputs.contains(data->m_monitor->m_name)) {
|
if LIKELY (PROTO::outputs.contains(data->m_monitor->m_name)) {
|
||||||
@@ -98,8 +98,8 @@ void CPresentationProtocol::destroyResource(CPresentationFeedback* feedback) {
|
|||||||
|
|
||||||
void CPresentationProtocol::onGetFeedback(CWpPresentation* pMgr, wl_resource* surf, uint32_t id) {
|
void CPresentationProtocol::onGetFeedback(CWpPresentation* pMgr, wl_resource* surf, uint32_t id) {
|
||||||
const auto CLIENT = pMgr->client();
|
const auto CLIENT = pMgr->client();
|
||||||
const auto RESOURCE =
|
const auto& RESOURCE =
|
||||||
m_feedbacks.emplace_back(makeShared<CPresentationFeedback>(makeShared<CWpPresentationFeedback>(CLIENT, pMgr->version(), id), CWLSurfaceResource::fromResource(surf))).get();
|
m_feedbacks.emplace_back(makeUnique<CPresentationFeedback>(makeUnique<CWpPresentationFeedback>(CLIENT, pMgr->version(), id), CWLSurfaceResource::fromResource(surf))).get();
|
||||||
|
|
||||||
if UNLIKELY (!RESOURCE->good()) {
|
if UNLIKELY (!RESOURCE->good()) {
|
||||||
pMgr->noMemory();
|
pMgr->noMemory();
|
||||||
@@ -123,15 +123,24 @@ void CPresentationProtocol::onPresented(PHLMONITOR pMonitor, const Time::steady_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_feedbacks.size() > 10000 /* arbitrary number I chose as fitting */) {
|
if (m_feedbacks.size() > 10000) {
|
||||||
LOGM(ERR, "FIXME: presentation has a feedback leak, and has grown to {} pending entries!!! Dropping!!!!!", m_feedbacks.size());
|
LOGM(ERR, "FIXME: presentation has a feedback leak, and has grown to {} pending entries!!! Dropping!!!!!", m_feedbacks.size());
|
||||||
m_feedbacks = {m_feedbacks.begin() + 9000, m_feedbacks.end()};
|
|
||||||
|
// Move the elements from the 9000th position to the end of the vector.
|
||||||
|
std::vector<UP<CPresentationFeedback>> newFeedbacks;
|
||||||
|
newFeedbacks.reserve(m_feedbacks.size() - 9000);
|
||||||
|
|
||||||
|
for (auto it = m_feedbacks.begin() + 9000; it != m_feedbacks.end(); ++it) {
|
||||||
|
newFeedbacks.push_back(std::move(*it));
|
||||||
|
}
|
||||||
|
|
||||||
|
m_feedbacks = std::move(newFeedbacks);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::erase_if(m_feedbacks, [](const auto& other) { return !other->m_surface || other->m_done; });
|
std::erase_if(m_feedbacks, [](const auto& other) { return !other->m_surface || other->m_done; });
|
||||||
std::erase_if(m_queue, [pMonitor](const auto& other) { return !other->m_surface || other->m_monitor == pMonitor || !other->m_monitor || other->m_done; });
|
std::erase_if(m_queue, [pMonitor](const auto& other) { return !other->m_surface || other->m_monitor == pMonitor || !other->m_monitor || other->m_done; });
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPresentationProtocol::queueData(SP<CQueuedPresentationData> data) {
|
void CPresentationProtocol::queueData(UP<CQueuedPresentationData>&& data) {
|
||||||
m_queue.emplace_back(data);
|
m_queue.emplace_back(std::move(data));
|
||||||
}
|
}
|
||||||
|
@@ -33,14 +33,14 @@ class CQueuedPresentationData {
|
|||||||
|
|
||||||
class CPresentationFeedback {
|
class CPresentationFeedback {
|
||||||
public:
|
public:
|
||||||
CPresentationFeedback(SP<CWpPresentationFeedback> resource_, SP<CWLSurfaceResource> surf);
|
CPresentationFeedback(UP<CWpPresentationFeedback>&& resource_, SP<CWLSurfaceResource> surf);
|
||||||
|
|
||||||
bool good();
|
bool good();
|
||||||
|
|
||||||
void sendQueued(SP<CQueuedPresentationData> data, const Time::steady_tp& when, uint32_t untilRefreshNs, uint64_t seq, uint32_t reportedFlags);
|
void sendQueued(WP<CQueuedPresentationData> data, const Time::steady_tp& when, uint32_t untilRefreshNs, uint64_t seq, uint32_t reportedFlags);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SP<CWpPresentationFeedback> m_resource;
|
UP<CWpPresentationFeedback> m_resource;
|
||||||
WP<CWLSurfaceResource> m_surface;
|
WP<CWLSurfaceResource> m_surface;
|
||||||
bool m_done = false;
|
bool m_done = false;
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ class CPresentationProtocol : public IWaylandProtocol {
|
|||||||
virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id);
|
virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id);
|
||||||
|
|
||||||
void onPresented(PHLMONITOR pMonitor, const Time::steady_tp& when, uint32_t untilRefreshNs, uint64_t seq, uint32_t reportedFlags);
|
void onPresented(PHLMONITOR pMonitor, const Time::steady_tp& when, uint32_t untilRefreshNs, uint64_t seq, uint32_t reportedFlags);
|
||||||
void queueData(SP<CQueuedPresentationData> data);
|
void queueData(UP<CQueuedPresentationData>&& data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onManagerResourceDestroy(wl_resource* res);
|
void onManagerResourceDestroy(wl_resource* res);
|
||||||
@@ -63,8 +63,8 @@ class CPresentationProtocol : public IWaylandProtocol {
|
|||||||
|
|
||||||
//
|
//
|
||||||
std::vector<UP<CWpPresentation>> m_managers;
|
std::vector<UP<CWpPresentation>> m_managers;
|
||||||
std::vector<SP<CPresentationFeedback>> m_feedbacks;
|
std::vector<UP<CPresentationFeedback>> m_feedbacks;
|
||||||
std::vector<SP<CQueuedPresentationData>> m_queue;
|
std::vector<UP<CQueuedPresentationData>> m_queue;
|
||||||
|
|
||||||
friend class CPresentationFeedback;
|
friend class CPresentationFeedback;
|
||||||
};
|
};
|
||||||
|
@@ -575,13 +575,13 @@ void CWLSurfaceResource::updateCursorShm(CRegion damage) {
|
|||||||
|
|
||||||
void CWLSurfaceResource::presentFeedback(const Time::steady_tp& when, PHLMONITOR pMonitor, bool discarded) {
|
void CWLSurfaceResource::presentFeedback(const Time::steady_tp& when, PHLMONITOR pMonitor, bool discarded) {
|
||||||
frame(when);
|
frame(when);
|
||||||
auto FEEDBACK = makeShared<CQueuedPresentationData>(m_self.lock());
|
auto FEEDBACK = makeUnique<CQueuedPresentationData>(m_self.lock());
|
||||||
FEEDBACK->attachMonitor(pMonitor);
|
FEEDBACK->attachMonitor(pMonitor);
|
||||||
if (discarded)
|
if (discarded)
|
||||||
FEEDBACK->discarded();
|
FEEDBACK->discarded();
|
||||||
else
|
else
|
||||||
FEEDBACK->presented();
|
FEEDBACK->presented();
|
||||||
PROTO::presentation->queueData(FEEDBACK);
|
PROTO::presentation->queueData(std::move(FEEDBACK));
|
||||||
}
|
}
|
||||||
|
|
||||||
CWLCompositorResource::CWLCompositorResource(SP<CWlCompositor> resource_) : m_resource(resource_) {
|
CWLCompositorResource::CWLCompositorResource(SP<CWlCompositor> resource_) : m_resource(resource_) {
|
||||||
|
@@ -146,10 +146,10 @@ CHyprRenderer::CHyprRenderer() {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
w->m_wlSurface->resource()->frame(Time::steadyNow());
|
w->m_wlSurface->resource()->frame(Time::steadyNow());
|
||||||
auto FEEDBACK = makeShared<CQueuedPresentationData>(w->m_wlSurface->resource());
|
auto FEEDBACK = makeUnique<CQueuedPresentationData>(w->m_wlSurface->resource());
|
||||||
FEEDBACK->attachMonitor(g_pCompositor->m_lastMonitor.lock());
|
FEEDBACK->attachMonitor(g_pCompositor->m_lastMonitor.lock());
|
||||||
FEEDBACK->discarded();
|
FEEDBACK->discarded();
|
||||||
PROTO::presentation->queueData(FEEDBACK);
|
PROTO::presentation->queueData(std::move(FEEDBACK));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dirty)
|
if (dirty)
|
||||||
|
Reference in New Issue
Block a user