Skip to content

Commit

Permalink
Allowing the compositor to tell you if it needs a post or not
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkae committed Oct 20, 2023
1 parent 8438d2c commit 25f4657
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class DisplayBufferCompositor
public:
virtual ~DisplayBufferCompositor() = default;

virtual void composite(SceneElementSequence&& scene_sequence) = 0;
/// Returns true if any compositing happened, otherwise false.
virtual bool composite(SceneElementSequence&& scene_sequence) = 0;

protected:
DisplayBufferCompositor() = default;
Expand Down
9 changes: 5 additions & 4 deletions src/server/compositor/default_display_buffer_compositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ mc::DefaultDisplayBufferCompositor::DefaultDisplayBufferCompositor(
{
}

void mc::DefaultDisplayBufferCompositor::composite(mc::SceneElementSequence&& scene_elements)
bool mc::DefaultDisplayBufferCompositor::composite(mc::SceneElementSequence&& scene_elements)
{
if (scene_elements.size() == 0 && !has_rendered)
return;
if (scene_elements.size() == 0 && !completed_first_render)
return false;

has_rendered = true;
completed_first_render = true;
report->began_frame(this);

auto const& view_area = display_buffer.view_area();
Expand Down Expand Up @@ -138,4 +138,5 @@ void mc::DefaultDisplayBufferCompositor::composite(mc::SceneElementSequence&& sc
}

report->finished_frame(this);
return true;
}
4 changes: 2 additions & 2 deletions src/server/compositor/default_display_buffer_compositor.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ class DefaultDisplayBufferCompositor : public DisplayBufferCompositor
std::shared_ptr<renderer::Renderer> const& renderer,
std::shared_ptr<compositor::CompositorReport> const& report);

void composite(SceneElementSequence&& scene_sequence) override;
bool composite(SceneElementSequence&& scene_sequence) override;

private:
graphics::DisplayBuffer& display_buffer;
std::shared_ptr<renderer::Renderer> const renderer;
std::unique_ptr<graphics::RenderingProvider::FramebufferProvider> const fb_adaptor;
std::shared_ptr<compositor::CompositorReport> const report;
bool has_rendered = false;
bool completed_first_render = false;
};

}
Expand Down
11 changes: 9 additions & 2 deletions src/server/compositor/multi_threaded_compositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,17 @@ class CompositingFunctor
not_posted_yet = false;
lock.unlock();

bool needs_post = false;
for (auto& tuple : compositors)
{
auto& compositor = std::get<1>(tuple);
compositor->composite(scene->scene_elements_for(compositor.get()));
if (compositor->composite(scene->scene_elements_for(compositor.get())))
needs_post = true;
}
group.post();

// We can skip the post if none of the compositors ended up compositing
if (needs_post)
group.post();

/*
* "Predictive bypass" optimization: If the last frame was
Expand Down Expand Up @@ -261,6 +266,7 @@ class CompositingFunctor
std::promise<void> stopped;
std::future<void> stopped_future;
bool not_posted_yet = true;
bool has_done_first_render = false;
};

}
Expand Down Expand Up @@ -335,6 +341,7 @@ void mc::MultiThreadedCompositor::start()
scene->add_observer(observer);

/* Optional first render */
compose_on_start = false;
if (compose_on_start)
schedule_compositing(1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ class NullDisplayBufferCompositorFactory : public compositor::DisplayBufferCompo
{
struct NullDisplayBufferCompositor : compositor::DisplayBufferCompositor
{
void composite(compositor::SceneElementSequence&&)
bool composite(compositor::SceneElementSequence&&) override
{
// yield() is needed to ensure reasonable runtime under
// valgrind for some tests
std::this_thread::yield();
return true;
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ mtf::HeadlessDisplayBufferCompositorFactory::create_compositor_for(mg::DisplayBu
return renderables;
}

void composite(mir::compositor::SceneElementSequence&& seq) override
bool composite(mir::compositor::SceneElementSequence&& seq) override
{
auto renderlist = filter(seq, db.view_area());

Expand All @@ -113,6 +113,7 @@ mtf::HeadlessDisplayBufferCompositorFactory::create_compositor_for(mg::DisplayBu
}

output->commit();
return true;
}
mg::DisplayBuffer& db;
std::unique_ptr<mg::gl::OutputSurface> const output;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,12 @@ class RecordingDisplayBufferCompositor : public mc::DisplayBufferCompositor
{
}

void composite(mc::SceneElementSequence&&)
bool composite(mc::SceneElementSequence&&)
{
mark_render_buffer();
/* Reduce run-time under valgrind */
std::this_thread::yield();
return true;
}

private:
Expand Down Expand Up @@ -275,11 +276,12 @@ class SurfaceUpdatingDisplayBufferCompositor : public mc::DisplayBufferComposito
{
}

void composite(mc::SceneElementSequence&&) override
bool composite(mc::SceneElementSequence&&) override
{
fake_surface_update();
/* Reduce run-time under valgrind */
std::this_thread::yield();
return true;
}

private:
Expand Down

0 comments on commit 25f4657

Please sign in to comment.