layer: Remove old presentation times

This commit is contained in:
Joshua Ashton 2023-09-29 22:36:37 +01:00
parent 8f5a251638
commit 50b706b862

View file

@ -25,6 +25,8 @@ using namespace std::literals;
namespace GamescopeWSILayer { namespace GamescopeWSILayer {
static const size_t MaxPastPresentationTimes = 16;
static uint64_t timespecToNanos(struct timespec& spec) { static uint64_t timespecToNanos(struct timespec& spec) {
return spec.tv_sec * 1'000'000'000ul + spec.tv_nsec; return spec.tv_sec * 1'000'000'000ul + spec.tv_nsec;
} }
@ -217,6 +219,9 @@ namespace GamescopeWSILayer {
.earliestPresentTime = (uint64_t(earliest_present_time_hi) << 32) | earliest_present_time_lo, .earliestPresentTime = (uint64_t(earliest_present_time_hi) << 32) | earliest_present_time_lo,
.presentMargin = (uint64_t(present_margin_hi) << 32) | present_margin_lo .presentMargin = (uint64_t(present_margin_hi) << 32) | present_margin_lo
}); });
// Remove the first element if we are already at the max size.
if (swapchain->pastPresentTimings.size() >= MaxPastPresentationTimes)
swapchain->pastPresentTimings.erase(swapchain->pastPresentTimings.begin());
}, },
.refresh_cycle = []( .refresh_cycle = [](