Browse Source

Tweak framebuffer render-skipping algorithm to be slightly more aggressive to render after frame deadlines.

tags/v2.0.5
Andrew Belt 2 years ago
parent
commit
c67a4181bb
3 changed files with 16 additions and 3 deletions
  1. +1
    -0
      include/window/Window.hpp
  2. +8
    -3
      src/widget/FramebufferWidget.cpp
  3. +7
    -0
      src/window/Window.cpp

+ 1
- 0
include/window/Window.hpp View File

@@ -103,6 +103,7 @@ struct Window {
} }


PRIVATE bool& fbDirtyOnSubpixelChange(); PRIVATE bool& fbDirtyOnSubpixelChange();
PRIVATE int& fbCount();
}; };






+ 8
- 3
src/widget/FramebufferWidget.cpp View File

@@ -120,9 +120,14 @@ void FramebufferWidget::draw(const DrawArgs& args) {
setDirty(); setDirty();
} }


// It's more important to not lag the frame than to draw the framebuffer
if (dirty && APP->window->getFrameDurationRemaining() > 0.0) {
render(scale, offsetF, args.clipBox);
if (dirty) {
// Render only if there is frame time remaining (to avoid lagging frames significantly), or if it's one of the first framebuffers this frame (to avoid framebuffers from never rendering).
int count = ++APP->window->fbCount();
const int maxCount = 4;
const float minRemaining = -1 / 60.0;
if (count <= maxCount || APP->window->getFrameDurationRemaining() > minRemaining) {
render(scale, offsetF, args.clipBox);
}
} }


if (!internal->fb) if (!internal->fb)


+ 7
- 0
src/window/Window.cpp View File

@@ -100,6 +100,7 @@ struct Window::Internal {
std::map<std::string, std::shared_ptr<Image>> imageCache; std::map<std::string, std::shared_ptr<Image>> imageCache;


bool fbDirtyOnSubpixelChange = true; bool fbDirtyOnSubpixelChange = true;
int fbCount = 0;
}; };




@@ -415,6 +416,7 @@ void Window::step() {
double lastFrameTime = internal->frameTime; double lastFrameTime = internal->frameTime;
internal->frameTime = frameTime; internal->frameTime = frameTime;
internal->lastFrameDuration = frameTime - lastFrameTime; internal->lastFrameDuration = frameTime - lastFrameTime;
internal->fbCount = 0;
// DEBUG("%.2lf Hz", 1.0 / internal->lastFrameDuration); // DEBUG("%.2lf Hz", 1.0 / internal->lastFrameDuration);
// double t1 = 0.0, t2 = 0.0, t3 = 0.0, t4 = 0.0, t5 = 0.0; // double t1 = 0.0, t2 = 0.0, t3 = 0.0, t4 = 0.0, t5 = 0.0;


@@ -759,6 +761,11 @@ bool& Window::fbDirtyOnSubpixelChange() {
} }




int& Window::fbCount() {
return internal->fbCount;
}


void init() { void init() {
int err; int err;




Loading…
Cancel
Save