mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:27:35 +00:00
WSCompositor: Use a timer to schedule compose rather than an event
Really poor man's vsync. Still not actual vsync, but at least we won't constantly spin buffers if we get many dirty rects.
This commit is contained in:
parent
411cdf067b
commit
d66fa60fcf
2 changed files with 15 additions and 14 deletions
|
@ -8,6 +8,8 @@
|
|||
#include <SharedGraphics/PNGLoader.h>
|
||||
#include <SharedGraphics/Painter.h>
|
||||
|
||||
// #define COMPOSITOR_DEBUG
|
||||
|
||||
WSCompositor& WSCompositor::the()
|
||||
{
|
||||
static WSCompositor s_the;
|
||||
|
@ -25,15 +27,15 @@ WSCompositor::WSCompositor()
|
|||
|
||||
m_wallpaper_path = "/res/wallpapers/retro.rgb";
|
||||
m_wallpaper = GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, m_wallpaper_path, { 1024, 768 });
|
||||
}
|
||||
|
||||
void WSCompositor::event(CEvent& event)
|
||||
{
|
||||
if (event.type() == WSEvent::WM_DeferredCompose) {
|
||||
m_pending_compose_event = false;
|
||||
m_compose_timer.on_timeout = [=]() {
|
||||
#if defined(COMPOSITOR_DEBUG)
|
||||
dbgprintf("WSCompositor: frame callback\n");
|
||||
#endif
|
||||
compose();
|
||||
return;
|
||||
}
|
||||
};
|
||||
m_compose_timer.set_single_shot(true);
|
||||
m_compose_timer.set_interval(1000 / 60);
|
||||
}
|
||||
|
||||
void WSCompositor::compose()
|
||||
|
@ -159,12 +161,11 @@ void WSCompositor::invalidate(const Rect& a_rect)
|
|||
if (rect.is_empty())
|
||||
return;
|
||||
|
||||
#if defined(COMPOSITOR_DEBUG)
|
||||
dbgprintf("Invalidated: %dx%d %dx%d\n", a_rect.x(), a_rect.y(), a_rect.width(), a_rect.height());
|
||||
#endif
|
||||
m_dirty_rects.add(rect);
|
||||
|
||||
if (!m_pending_compose_event) {
|
||||
WSEventLoop::the().post_event(*this, make<WSEvent>(WSEvent::WM_DeferredCompose));
|
||||
m_pending_compose_event = true;
|
||||
}
|
||||
m_compose_timer.start();
|
||||
}
|
||||
|
||||
bool WSCompositor::set_wallpaper(const String& path, Function<void(bool)>&& callback)
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <AK/OwnPtr.h>
|
||||
#include <AK/RetainPtr.h>
|
||||
#include <LibCore/CObject.h>
|
||||
#include <LibCore/CTimer.h>
|
||||
#include <SharedGraphics/DisjointRectSet.h>
|
||||
#include <SharedGraphics/GraphicsBitmap.h>
|
||||
|
||||
|
@ -26,7 +27,6 @@ public:
|
|||
Rect current_cursor_rect() const;
|
||||
|
||||
private:
|
||||
virtual void event(CEvent&) override;
|
||||
virtual const char* class_name() const override { return "WSCompositor"; }
|
||||
|
||||
WSCompositor();
|
||||
|
@ -39,7 +39,7 @@ private:
|
|||
|
||||
unsigned m_compose_count { 0 };
|
||||
unsigned m_flush_count { 0 };
|
||||
bool m_pending_compose_event { false };
|
||||
CTimer m_compose_timer;
|
||||
bool m_flash_flush { false };
|
||||
bool m_buffers_are_flipped { false };
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue