mirror of
https://github.com/hyprwm/Hyprland.git
synced 2025-08-03 21:51:55 -07:00
protocols: refactor class member vars (n-t) (#10273)
This commit is contained in:
@@ -6,52 +6,52 @@
|
||||
#include "core/Output.hpp"
|
||||
#include <aquamarine/output/Output.hpp>
|
||||
|
||||
CQueuedPresentationData::CQueuedPresentationData(SP<CWLSurfaceResource> surf) : surface(surf) {
|
||||
CQueuedPresentationData::CQueuedPresentationData(SP<CWLSurfaceResource> surf) : m_surface(surf) {
|
||||
;
|
||||
}
|
||||
|
||||
void CQueuedPresentationData::setPresentationType(bool zeroCopy_) {
|
||||
zeroCopy = zeroCopy_;
|
||||
m_zeroCopy = zeroCopy_;
|
||||
}
|
||||
|
||||
void CQueuedPresentationData::attachMonitor(PHLMONITOR pMonitor_) {
|
||||
pMonitor = pMonitor_;
|
||||
m_monitor = pMonitor_;
|
||||
}
|
||||
|
||||
void CQueuedPresentationData::presented() {
|
||||
wasPresented = true;
|
||||
m_wasPresented = true;
|
||||
}
|
||||
|
||||
void CQueuedPresentationData::discarded() {
|
||||
wasPresented = false;
|
||||
m_wasPresented = false;
|
||||
}
|
||||
|
||||
CPresentationFeedback::CPresentationFeedback(SP<CWpPresentationFeedback> resource_, SP<CWLSurfaceResource> surf) : resource(resource_), surface(surf) {
|
||||
CPresentationFeedback::CPresentationFeedback(SP<CWpPresentationFeedback> resource_, SP<CWLSurfaceResource> surf) : m_resource(resource_), m_surface(surf) {
|
||||
if UNLIKELY (!good())
|
||||
return;
|
||||
|
||||
resource->setOnDestroy([this](CWpPresentationFeedback* pMgr) {
|
||||
if (!done) // if it's done, it's probably already destroyed. If not, it will be in a sec.
|
||||
m_resource->setOnDestroy([this](CWpPresentationFeedback* pMgr) {
|
||||
if (!m_done) // if it's done, it's probably already destroyed. If not, it will be in a sec.
|
||||
PROTO::presentation->destroyResource(this);
|
||||
});
|
||||
}
|
||||
|
||||
bool CPresentationFeedback::good() {
|
||||
return 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) {
|
||||
auto client = resource->client();
|
||||
auto client = m_resource->client();
|
||||
|
||||
if LIKELY (PROTO::outputs.contains(data->pMonitor->m_name)) {
|
||||
if LIKELY (auto outputResource = PROTO::outputs.at(data->pMonitor->m_name)->outputResourceFrom(client); outputResource)
|
||||
resource->sendSyncOutput(outputResource->getResource()->resource());
|
||||
if LIKELY (PROTO::outputs.contains(data->m_monitor->m_name)) {
|
||||
if LIKELY (auto outputResource = PROTO::outputs.at(data->m_monitor->m_name)->outputResourceFrom(client); outputResource)
|
||||
m_resource->sendSyncOutput(outputResource->getResource()->resource());
|
||||
}
|
||||
|
||||
uint32_t flags = 0;
|
||||
if (!data->pMonitor->m_tearingState.activelyTearing)
|
||||
if (!data->m_monitor->m_tearingState.activelyTearing)
|
||||
flags |= WP_PRESENTATION_FEEDBACK_KIND_VSYNC;
|
||||
if (data->zeroCopy)
|
||||
if (data->m_zeroCopy)
|
||||
flags |= WP_PRESENTATION_FEEDBACK_KIND_ZERO_COPY;
|
||||
if (reportedFlags & Aquamarine::IOutput::AQ_OUTPUT_PRESENT_HW_CLOCK)
|
||||
flags |= WP_PRESENTATION_FEEDBACK_KIND_HW_CLOCK;
|
||||
@@ -64,24 +64,24 @@ void CPresentationFeedback::sendQueued(SP<CQueuedPresentationData> data, const T
|
||||
if (sizeof(time_t) > 4)
|
||||
tv_sec = TIMESPEC.tv_sec >> 32;
|
||||
|
||||
if (data->wasPresented)
|
||||
resource->sendPresented((uint32_t)tv_sec, (uint32_t)(TIMESPEC.tv_sec & 0xFFFFFFFF), (uint32_t)(TIMESPEC.tv_nsec), untilRefreshNs, (uint32_t)(seq >> 32),
|
||||
(uint32_t)(seq & 0xFFFFFFFF), (wpPresentationFeedbackKind)flags);
|
||||
if (data->m_wasPresented)
|
||||
m_resource->sendPresented((uint32_t)tv_sec, (uint32_t)(TIMESPEC.tv_sec & 0xFFFFFFFF), (uint32_t)(TIMESPEC.tv_nsec), untilRefreshNs, (uint32_t)(seq >> 32),
|
||||
(uint32_t)(seq & 0xFFFFFFFF), (wpPresentationFeedbackKind)flags);
|
||||
else
|
||||
resource->sendDiscarded();
|
||||
m_resource->sendDiscarded();
|
||||
|
||||
done = true;
|
||||
m_done = true;
|
||||
}
|
||||
|
||||
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 = PHLMONITORREF{std::any_cast<PHLMONITOR>(param)};
|
||||
std::erase_if(m_vQueue, [PMONITOR](const auto& other) { return !other->surface || other->pMonitor == PMONITOR; });
|
||||
std::erase_if(m_queue, [PMONITOR](const auto& other) { return !other->m_surface || other->m_monitor == PMONITOR; });
|
||||
});
|
||||
}
|
||||
|
||||
void CPresentationProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
|
||||
const auto RESOURCE = m_vManagers.emplace_back(makeUnique<CWpPresentation>(client, ver, id)).get();
|
||||
const auto RESOURCE = m_managers.emplace_back(makeUnique<CWpPresentation>(client, ver, id)).get();
|
||||
RESOURCE->setOnDestroy([this](CWpPresentation* p) { this->onManagerResourceDestroy(p->resource()); });
|
||||
|
||||
RESOURCE->setDestroy([this](CWpPresentation* pMgr) { this->onManagerResourceDestroy(pMgr->resource()); });
|
||||
@@ -89,50 +89,49 @@ void CPresentationProtocol::bindManager(wl_client* client, void* data, uint32_t
|
||||
}
|
||||
|
||||
void CPresentationProtocol::onManagerResourceDestroy(wl_resource* res) {
|
||||
std::erase_if(m_vManagers, [&](const auto& other) { return other->resource() == res; });
|
||||
std::erase_if(m_managers, [&](const auto& other) { return other->resource() == res; });
|
||||
}
|
||||
|
||||
void CPresentationProtocol::destroyResource(CPresentationFeedback* feedback) {
|
||||
std::erase_if(m_vFeedbacks, [&](const auto& other) { return other.get() == feedback; });
|
||||
std::erase_if(m_feedbacks, [&](const auto& other) { return other.get() == feedback; });
|
||||
}
|
||||
|
||||
void CPresentationProtocol::onGetFeedback(CWpPresentation* pMgr, wl_resource* surf, uint32_t id) {
|
||||
const auto CLIENT = pMgr->client();
|
||||
const auto RESOURCE =
|
||||
m_vFeedbacks.emplace_back(makeShared<CPresentationFeedback>(makeShared<CWpPresentationFeedback>(CLIENT, pMgr->version(), id), CWLSurfaceResource::fromResource(surf)))
|
||||
.get();
|
||||
m_feedbacks.emplace_back(makeShared<CPresentationFeedback>(makeShared<CWpPresentationFeedback>(CLIENT, pMgr->version(), id), CWLSurfaceResource::fromResource(surf))).get();
|
||||
|
||||
if UNLIKELY (!RESOURCE->good()) {
|
||||
pMgr->noMemory();
|
||||
m_vFeedbacks.pop_back();
|
||||
m_feedbacks.pop_back();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void CPresentationProtocol::onPresented(PHLMONITOR pMonitor, const Time::steady_tp& when, uint32_t untilRefreshNs, uint64_t seq, uint32_t reportedFlags) {
|
||||
for (auto const& feedback : m_vFeedbacks) {
|
||||
if (!feedback->surface)
|
||||
for (auto const& feedback : m_feedbacks) {
|
||||
if (!feedback->m_surface)
|
||||
continue;
|
||||
|
||||
for (auto const& data : m_vQueue) {
|
||||
if (!data->surface || data->surface != feedback->surface || (data->pMonitor && data->pMonitor != pMonitor))
|
||||
for (auto const& data : m_queue) {
|
||||
if (!data->m_surface || data->m_surface != feedback->m_surface || (data->m_monitor && data->m_monitor != pMonitor))
|
||||
continue;
|
||||
|
||||
feedback->sendQueued(data, when, untilRefreshNs, seq, reportedFlags);
|
||||
feedback->done = true;
|
||||
feedback->m_done = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_vFeedbacks.size() > 10000 /* arbitrary number I chose as fitting */) {
|
||||
LOGM(ERR, "FIXME: presentation has a feedback leak, and has grown to {} pending entries!!! Dropping!!!!!", m_vFeedbacks.size());
|
||||
m_vFeedbacks = {m_vFeedbacks.begin() + 9000, m_vFeedbacks.end()};
|
||||
if (m_feedbacks.size() > 10000 /* arbitrary number I chose as fitting */) {
|
||||
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()};
|
||||
}
|
||||
|
||||
std::erase_if(m_vFeedbacks, [](const auto& other) { return !other->surface || other->done; });
|
||||
std::erase_if(m_vQueue, [pMonitor](const auto& other) { return !other->surface || other->pMonitor == pMonitor || !other->pMonitor || other->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; });
|
||||
}
|
||||
|
||||
void CPresentationProtocol::queueData(SP<CQueuedPresentationData> data) {
|
||||
m_vQueue.emplace_back(data);
|
||||
m_queue.emplace_back(data);
|
||||
}
|
||||
|
Reference in New Issue
Block a user