Drop "sub-feedback" concept in PresentationFeedback

This gets rid of the container feedback to simplify presentation
feedback organization.
This commit is contained in:
Vlad Zahorodnii 2023-11-14 09:08:08 +02:00
parent 79d5a70c01
commit 9692c65390
6 changed files with 35 additions and 53 deletions

View file

@ -83,18 +83,6 @@ std::unique_ptr<SurfaceTexture> RenderBackend::createSurfaceTextureWayland(Surfa
return nullptr; return nullptr;
} }
PresentationFeedback::PresentationFeedback(std::vector<std::unique_ptr<PresentationFeedback>> &&feedbacks)
: m_subFeedbacks(std::move(feedbacks))
{
}
void PresentationFeedback::presented(std::chrono::nanoseconds refreshCycleDuration, std::chrono::nanoseconds timestamp, PresentationMode mode)
{
for (const auto &feedback : m_subFeedbacks) {
feedback->presented(refreshCycleDuration, timestamp, mode);
}
}
} // namespace KWin } // namespace KWin
#include "moc_renderbackend.cpp" #include "moc_renderbackend.cpp"

View file

@ -31,15 +31,11 @@ class PresentationFeedback
{ {
public: public:
explicit PresentationFeedback() = default; explicit PresentationFeedback() = default;
explicit PresentationFeedback(std::vector<std::unique_ptr<PresentationFeedback>> &&feedbacks);
PresentationFeedback(const PresentationFeedback &copy) = delete; PresentationFeedback(const PresentationFeedback &copy) = delete;
PresentationFeedback(PresentationFeedback &&move) = default; PresentationFeedback(PresentationFeedback &&move) = default;
virtual ~PresentationFeedback() = default; virtual ~PresentationFeedback() = default;
virtual void presented(std::chrono::nanoseconds refreshCycleDuration, std::chrono::nanoseconds timestamp, PresentationMode mode); virtual void presented(std::chrono::nanoseconds refreshCycleDuration, std::chrono::nanoseconds timestamp, PresentationMode mode) = 0;
private:
std::vector<std::unique_ptr<PresentationFeedback>> m_subFeedbacks;
}; };
class KWIN_EXPORT OutputFrame class KWIN_EXPORT OutputFrame

View file

@ -32,29 +32,37 @@ void PresentationTime::wp_presentation_feedback(Resource *resource, wl_resource
{ {
SurfaceInterface *surf = SurfaceInterface::get(surface); SurfaceInterface *surf = SurfaceInterface::get(surface);
SurfaceInterfacePrivate *surfPriv = SurfaceInterfacePrivate::get(surf); SurfaceInterfacePrivate *surfPriv = SurfaceInterfacePrivate::get(surf);
surfPriv->pending->presentationFeedbacks.push_back(std::make_unique<PresentationTimeFeedback>(surf, resource->client(), callback));
auto &feedback = surfPriv->pending->presentationFeedback;
if (!feedback) {
feedback = std::make_unique<PresentationTimeFeedback>();
} }
PresentationTimeFeedback::PresentationTimeFeedback(SurfaceInterface *surface, wl_client *client, uint32_t id) wl_resource *feedbackResource = wl_resource_create(resource->client(), &wp_presentation_feedback_interface, resource->version(), callback);
: QtWaylandServer::wp_presentation_feedback(client, id, 1) wl_resource_set_implementation(feedbackResource, nullptr, nullptr, [](wl_resource *resource) {
, m_surface(surface) wl_list_remove(wl_resource_get_link(resource));
});
wl_list_insert(feedback->resources.prev, wl_resource_get_link(feedbackResource));
}
PresentationTimeFeedback::PresentationTimeFeedback()
{ {
wl_list_init(&resources);
} }
PresentationTimeFeedback::~PresentationTimeFeedback() PresentationTimeFeedback::~PresentationTimeFeedback()
{ {
if (m_destroyed) { wl_resource *resource;
return; wl_resource *tmp;
wl_resource_for_each_safe (resource, tmp, &resources) {
wp_presentation_feedback_send_discarded(resource);
wl_resource_destroy(resource);
} }
send_discarded();
wl_resource_destroy(resource()->handle);
} }
void PresentationTimeFeedback::presented(std::chrono::nanoseconds refreshCycleDuration, std::chrono::nanoseconds timestamp, PresentationMode mode) void PresentationTimeFeedback::presented(std::chrono::nanoseconds refreshCycleDuration, std::chrono::nanoseconds timestamp, PresentationMode mode)
{ {
if (m_destroyed) {
return;
}
const auto secs = std::chrono::duration_cast<std::chrono::seconds>(timestamp); const auto secs = std::chrono::duration_cast<std::chrono::seconds>(timestamp);
const uint32_t tvSecHi = secs.count() >> 32; const uint32_t tvSecHi = secs.count() >> 32;
const uint32_t tvSecLo = secs.count() & 0xffffffff; const uint32_t tvSecLo = secs.count() & 0xffffffff;
@ -67,13 +75,11 @@ void PresentationTimeFeedback::presented(std::chrono::nanoseconds refreshCycleDu
flags |= WP_PRESENTATION_FEEDBACK_KIND_VSYNC; flags |= WP_PRESENTATION_FEEDBACK_KIND_VSYNC;
} }
send_presented(resource()->handle, tvSecHi, tvSecLo, tvNsec, refreshDuration, 0, 0, flags); wl_resource *resource;
wl_resource_destroy(resource()->handle); wl_resource *tmp;
m_destroyed = true; wl_resource_for_each_safe (resource, tmp, &resources) {
} wp_presentation_feedback_send_presented(resource, tvSecHi, tvSecLo, tvNsec, refreshDuration, 0, 0, flags);
wl_resource_destroy(resource);
void PresentationTimeFeedback::wp_presentation_feedback_destroy_resource(Resource *resource) }
{
m_destroyed = true;
} }
} }

View file

@ -30,19 +30,15 @@ private:
void wp_presentation_feedback(Resource *resource, wl_resource *surface, uint32_t callback) override; void wp_presentation_feedback(Resource *resource, wl_resource *surface, uint32_t callback) override;
}; };
class PresentationTimeFeedback : public PresentationFeedback, public QtWaylandServer::wp_presentation_feedback class PresentationTimeFeedback : public PresentationFeedback
{ {
public: public:
explicit PresentationTimeFeedback(SurfaceInterface *surface, wl_client *client, uint32_t id); PresentationTimeFeedback();
~PresentationTimeFeedback() override; ~PresentationTimeFeedback() override;
wl_list resources;
void presented(std::chrono::nanoseconds refreshCycleDuration, std::chrono::nanoseconds timestamp, PresentationMode mode) override; void presented(std::chrono::nanoseconds refreshCycleDuration, std::chrono::nanoseconds timestamp, PresentationMode mode) override;
private:
void wp_presentation_feedback_destroy_resource(Resource *resource) override;
SurfaceInterface *const m_surface;
bool m_destroyed = false;
}; };
} }

View file

@ -474,10 +474,7 @@ std::unique_ptr<PresentationFeedback> SurfaceInterface::takePresentationFeedback
if (output && (!d->primaryOutput || d->primaryOutput->handle() != output)) { if (output && (!d->primaryOutput || d->primaryOutput->handle() != output)) {
return nullptr; return nullptr;
} }
std::vector<std::unique_ptr<PresentationFeedback>> feedbacks; return std::move(d->current->presentationFeedback);
std::move(d->current->presentationFeedbacks.begin(), d->current->presentationFeedbacks.end(), std::back_inserter(feedbacks));
d->current->presentationFeedbacks.clear();
return std::make_unique<PresentationFeedback>(std::move(feedbacks));
} }
bool SurfaceInterface::hasFrameCallbacks() const bool SurfaceInterface::hasFrameCallbacks() const
@ -652,10 +649,9 @@ void SurfaceState::mergeInto(SurfaceState *target)
target->colorDescription = colorDescription; target->colorDescription = colorDescription;
target->colorDescriptionIsSet = true; target->colorDescriptionIsSet = true;
} }
for (auto &f : presentationFeedbacks) { if (presentationFeedback) {
target->presentationFeedbacks.push_back(std::move(f)); target->presentationFeedback = std::move(presentationFeedback);
} }
presentationFeedbacks.clear();
*this = SurfaceState{}; *this = SurfaceState{};
serial = target->serial; serial = target->serial;
@ -683,7 +679,7 @@ void SurfaceInterfacePrivate::applyState(SurfaceState *next)
const QRegion oldInputRegion = inputRegion; const QRegion oldInputRegion = inputRegion;
if (!next->damage.isEmpty() || !next->bufferDamage.isEmpty()) { if (!next->damage.isEmpty() || !next->bufferDamage.isEmpty()) {
current->presentationFeedbacks.clear(); current->presentationFeedback.reset();
} }
next->mergeInto(current.get()); next->mergeInto(current.get());
bufferRef = current->buffer; bufferRef = current->buffer;

View file

@ -69,7 +69,7 @@ struct SurfaceState
ContentType contentType = ContentType::None; ContentType contentType = ContentType::None;
PresentationHint presentationHint = PresentationHint::VSync; PresentationHint presentationHint = PresentationHint::VSync;
ColorDescription colorDescription = ColorDescription::sRGB; ColorDescription colorDescription = ColorDescription::sRGB;
std::vector<std::unique_ptr<PresentationTimeFeedback>> presentationFeedbacks; std::unique_ptr<PresentationTimeFeedback> presentationFeedback;
struct struct
{ {