Skip to content

Commit dc7dd0c

Browse files
committed
presentation-feedback: minor fixups
1 parent ad8979e commit dc7dd0c

File tree

6 files changed

+18
-14
lines changed

6 files changed

+18
-14
lines changed

src/helpers/Monitor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void CMonitor::onConnect(bool noRule) {
4747

4848
listeners.presented = output->events.present.registerListener([this](std::any d) {
4949
auto E = std::any_cast<Aquamarine::IOutput::SPresentEvent>(d);
50-
PROTO::presentation->onPresented(this, E.when, E.refresh, E.seq, E.flags);
50+
PROTO::presentation->onPresented(self.lock(), E.when, E.refresh, E.seq, E.flags);
5151
});
5252

5353
listeners.destroy = output->events.destroy.registerListener([this](std::any d) {
@@ -861,7 +861,7 @@ bool CMonitor::attemptDirectScanout() {
861861

862862
timespec now;
863863
clock_gettime(CLOCK_MONOTONIC, &now);
864-
PSURFACE->presentFeedback(&now, this);
864+
PSURFACE->presentFeedback(&now, self.lock());
865865

866866
output->state->addDamage(CBox{{}, vecPixelSize});
867867
output->state->resetExplicitFences();

src/protocols/PresentationTime.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ void CQueuedPresentationData::setPresentationType(bool zeroCopy_) {
1414
zeroCopy = zeroCopy_;
1515
}
1616

17-
void CQueuedPresentationData::attachMonitor(CMonitor* pMonitor_) {
17+
void CQueuedPresentationData::attachMonitor(SP<CMonitor> pMonitor_) {
1818
pMonitor = pMonitor_;
1919
}
2020

@@ -67,12 +67,14 @@ void CPresentationFeedback::sendQueued(SP<CQueuedPresentationData> data, timespe
6767
(uint32_t)(seq & 0xFFFFFFFF), (wpPresentationFeedbackKind)flags);
6868
else
6969
resource->sendDiscarded();
70+
71+
done = true;
7072
}
7173

7274
CPresentationProtocol::CPresentationProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
7375
static auto P = g_pHookSystem->hookDynamic("monitorRemoved", [this](void* self, SCallbackInfo& info, std::any param) {
7476
const auto PMONITOR = std::any_cast<CMonitor*>(param);
75-
std::erase_if(m_vQueue, [PMONITOR](const auto& other) { return !other->surface || other->pMonitor == PMONITOR; });
77+
std::erase_if(m_vQueue, [PMONITOR](const auto& other) { return !other->surface || other->pMonitor.get() == PMONITOR; });
7678
});
7779
}
7880

@@ -105,7 +107,7 @@ void CPresentationProtocol::onGetFeedback(CWpPresentation* pMgr, wl_resource* su
105107
}
106108
}
107109

108-
void CPresentationProtocol::onPresented(CMonitor* pMonitor, timespec* when, uint32_t untilRefreshNs, uint64_t seq, uint32_t reportedFlags) {
110+
void CPresentationProtocol::onPresented(SP<CMonitor> pMonitor, timespec* when, uint32_t untilRefreshNs, uint64_t seq, uint32_t reportedFlags) {
109111
timespec now;
110112
timespec* presentedAt = when;
111113
if (!presentedAt) {
@@ -119,7 +121,7 @@ void CPresentationProtocol::onPresented(CMonitor* pMonitor, timespec* when, uint
119121
continue;
120122

121123
for (auto const& data : m_vQueue) {
122-
if (!data->surface || data->surface != feedback->surface)
124+
if (!data->surface || data->surface != feedback->surface || (data->pMonitor && data->pMonitor != pMonitor))
123125
continue;
124126

125127
feedback->sendQueued(data, when, untilRefreshNs, seq, reportedFlags);
@@ -129,7 +131,7 @@ void CPresentationProtocol::onPresented(CMonitor* pMonitor, timespec* when, uint
129131
}
130132

131133
std::erase_if(m_vFeedbacks, [](const auto& other) { return !other->surface || other->done; });
132-
std::erase_if(m_vQueue, [pMonitor](const auto& other) { return !other->surface || other->pMonitor == pMonitor || !other->pMonitor; });
134+
std::erase_if(m_vQueue, [pMonitor](const auto& other) { return !other->surface || other->pMonitor == pMonitor || !other->pMonitor || other->done; });
133135
}
134136

135137
void CPresentationProtocol::queueData(SP<CQueuedPresentationData> data) {

src/protocols/PresentationTime.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@ class CQueuedPresentationData {
1414
CQueuedPresentationData(SP<CWLSurfaceResource> surf);
1515

1616
void setPresentationType(bool zeroCopy);
17-
void attachMonitor(CMonitor* pMonitor);
17+
void attachMonitor(SP<CMonitor> pMonitor);
1818

1919
void presented();
2020
void discarded();
2121

22+
bool done = false;
23+
2224
private:
2325
bool wasPresented = false;
2426
bool zeroCopy = false;
25-
CMonitor* pMonitor = nullptr;
27+
WP<CMonitor> pMonitor;
2628
WP<CWLSurfaceResource> surface;
2729

2830
DYNLISTENER(destroySurface);
@@ -53,7 +55,7 @@ class CPresentationProtocol : public IWaylandProtocol {
5355

5456
virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id);
5557

56-
void onPresented(CMonitor* pMonitor, timespec* when, uint32_t untilRefreshNs, uint64_t seq, uint32_t reportedFlags);
58+
void onPresented(SP<CMonitor> pMonitor, timespec* when, uint32_t untilRefreshNs, uint64_t seq, uint32_t reportedFlags);
5759
void queueData(SP<CQueuedPresentationData> data);
5860

5961
private:

src/protocols/core/Compositor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ void CWLSurfaceResource::updateCursorShm() {
509509
memcpy(shmData.data(), pixelData, bufLen);
510510
}
511511

512-
void CWLSurfaceResource::presentFeedback(timespec* when, CMonitor* pMonitor) {
512+
void CWLSurfaceResource::presentFeedback(timespec* when, SP<CMonitor> pMonitor) {
513513
frame(when);
514514
auto FEEDBACK = makeShared<CQueuedPresentationData>(self.lock());
515515
FEEDBACK->attachMonitor(pMonitor);

src/protocols/core/Compositor.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class CWLSurfaceResource {
124124

125125
void breadthfirst(std::function<void(SP<CWLSurfaceResource>, const Vector2D&, void*)> fn, void* data);
126126
CRegion accumulateCurrentBufferDamage();
127-
void presentFeedback(timespec* when, CMonitor* pMonitor);
127+
void presentFeedback(timespec* when, SP<CMonitor> pMonitor);
128128
void lockPendingState();
129129
void unlockPendingState();
130130

src/render/Renderer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ static void renderSurface(SP<CWLSurfaceResource> surface, int x, int y, void* da
185185
if (windowBox.width <= 1 || windowBox.height <= 1) {
186186
if (!g_pHyprRenderer->m_bBlockSurfaceFeedback) {
187187
Debug::log(TRACE, "presentFeedback for invisible surface");
188-
surface->presentFeedback(RDATA->when, RDATA->pMonitor);
188+
surface->presentFeedback(RDATA->when, RDATA->pMonitor->self.lock());
189189
}
190190

191191
return; // invisible
@@ -240,7 +240,7 @@ static void renderSurface(SP<CWLSurfaceResource> surface, int x, int y, void* da
240240
}
241241

242242
if (!g_pHyprRenderer->m_bBlockSurfaceFeedback)
243-
surface->presentFeedback(RDATA->when, RDATA->pMonitor);
243+
surface->presentFeedback(RDATA->when, RDATA->pMonitor->self.lock());
244244

245245
g_pHyprOpenGL->blend(true);
246246

0 commit comments

Comments
 (0)