21 return timestamp + ((alignment - (timestamp % alignment)) % alignment);
44 const std::chrono::nanoseconds vblankInterval(1'000'000'000'000ull /
refreshRate);
45 const std::chrono::nanoseconds currentTime(std::chrono::steady_clock::now().time_since_epoch());
59 if (nextRenderTimestamp < currentTime) {
60 nextRenderTimestamp = currentTime;
66 const std::chrono::nanoseconds waitInterval = nextRenderTimestamp - currentTime;
67 compositeTimer.start(std::chrono::duration_cast<std::chrono::milliseconds>(waitInterval));
115 "Got invalid presentation timestamp: %lld (current %lld)",
116 static_cast<long long>(timestamp.count()),
155 if (d->inhibitCount == 1) {
156 d->compositeTimer.stop();
162 Q_ASSERT(d->inhibitCount > 0);
165 if (d->inhibitCount == 0) {
166 d->maybeScheduleRepaint();
172 d->pendingFrameCount++;
177 d->pendingRepaint =
false;
182 return d->refreshRate;
196 d->safetyMargin = safetyMargin;
201 if (d->pendingRepaint) {
205 if (vrr &&
workspace()->activeWindow() && d->output) {
211 if (!d->pendingFrameCount && !d->inhibitCount) {
212 d->scheduleRepaint();
214 d->delayScheduleRepaint();
220 return d->lastPresentationTimestamp;
225 return d->nextPresentationTimestamp;
230 d->presentationMode = mode;
235#include "moc_renderloop.cpp"
void add(std::chrono::nanoseconds renderTime, std::chrono::nanoseconds presentationTimestamp)
std::chrono::nanoseconds result() const
void frameRequested(RenderLoop *loop)
void setPresentationMode(PresentationMode mode)
void framePresented(RenderLoop *loop, std::chrono::nanoseconds timestamp, PresentationMode mode)
void scheduleRepaint(Item *item=nullptr)
void refreshRateChanged()
std::chrono::nanoseconds lastPresentationTimestamp() const
std::chrono::nanoseconds nextPresentationTimestamp() const
void setRefreshRate(int refreshRate)
void setPresentationSafetyMargin(std::chrono::nanoseconds safetyMargin)
RenderLoop(Output *output)
static RenderLoopPrivate * get(RenderLoop *loop)
std::chrono::nanoseconds nextPresentationTimestamp
std::chrono::nanoseconds lastPresentationTimestamp
void delayScheduleRepaint()
void maybeScheduleRepaint()
void notifyFrameCompleted(std::chrono::nanoseconds timestamp, std::chrono::nanoseconds renderTime, PresentationMode mode=PresentationMode::VSync)
PresentationMode presentationMode
void notifyVblank(std::chrono::nanoseconds timestamp)
std::chrono::nanoseconds safetyMargin
RenderJournal renderJournal
RenderLoopPrivate(RenderLoop *q, Output *output)
std::chrono::nanoseconds frameTimeEstimation() const
SurfaceItem * surfaceItem() const
bool isOnOutput(Output *output) const
Window * activeWindow() const
T alignTimestamp(const T ×tamp, const T &alignment)