diff --git a/Servers/WindowServer/WSCompositor.cpp b/Servers/WindowServer/WSCompositor.cpp index 713b828d8d..8c07d25623 100644 --- a/Servers/WindowServer/WSCompositor.cpp +++ b/Servers/WindowServer/WSCompositor.cpp @@ -8,6 +8,8 @@ #include #include +// #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::WM_DeferredCompose)); - m_pending_compose_event = true; - } + m_compose_timer.start(); } bool WSCompositor::set_wallpaper(const String& path, Function&& callback) diff --git a/Servers/WindowServer/WSCompositor.h b/Servers/WindowServer/WSCompositor.h index eed376286e..9fdbf5bc50 100644 --- a/Servers/WindowServer/WSCompositor.h +++ b/Servers/WindowServer/WSCompositor.h @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -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 };