1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-19 00:25:07 +00:00

WindowServer+LibGUI: Notify DisplayLinks at 60 fps no matter what

The original implementation only sent out notifications when there was
something being drawn on screen. If nothing was going on, we'd get too
lazy and just not notify display links.

This obviously break requestAnimationFrame(), so now we just drive the
DisplayLinks at 60 fps no matter what. :^)
This commit is contained in:
Andreas Kling 2020-04-22 00:07:48 +02:00
parent 2d4c91df8e
commit 5326eebb1b
5 changed files with 47 additions and 2 deletions

View file

@ -342,7 +342,14 @@ void WindowServerConnection::handle(const Messages::WindowClient::WindowStateCha
void WindowServerConnection::handle(const Messages::WindowClient::DisplayLinkNotification&)
{
if (m_display_link_notification_pending)
return;
m_display_link_notification_pending = true;
deferred_invoke([this](auto&) {
DisplayLink::notify({});
m_display_link_notification_pending = false;
});
}
}

View file

@ -75,6 +75,8 @@ private:
virtual void handle(const Messages::WindowClient::UpdateSystemTheme&) override;
virtual void handle(const Messages::WindowClient::WindowStateChanged&) override;
virtual void handle(const Messages::WindowClient::DisplayLinkNotification&) override;
bool m_display_link_notification_pending { false };
};
}

View file

@ -88,6 +88,9 @@ ClientConnection::ClientConnection(Core::LocalSocket& client_socket, int client_
ClientConnection::~ClientConnection()
{
if (m_has_display_link)
Compositor::the().decrement_display_link_count({});
MenuManager::the().close_all_menus_from_client({}, *this);
auto windows = move(m_windows);
for (auto& window : windows) {
@ -772,12 +775,18 @@ OwnPtr<Messages::WindowServer::SetWindowBaseSizeAndSizeIncrementResponse> Client
void ClientConnection::handle(const Messages::WindowServer::EnableDisplayLink&)
{
if (m_has_display_link)
return;
m_has_display_link = true;
Compositor::the().increment_display_link_count({});
}
void ClientConnection::handle(const Messages::WindowServer::DisableDisplayLink&)
{
if (!m_has_display_link)
return;
m_has_display_link = false;
Compositor::the().decrement_display_link_count({});
}
void ClientConnection::notify_display_link(Badge<Compositor>)

View file

@ -60,10 +60,15 @@ WallpaperMode mode_to_enum(const String& name)
Compositor::Compositor()
{
m_display_link_notify_timer = add<Core::Timer>(
1000 / 60, [this] {
notify_display_links();
});
m_display_link_notify_timer->stop();
m_compose_timer = Core::Timer::create_single_shot(
1000 / 60,
[this] {
notify_display_links();
compose();
},
this);
@ -488,4 +493,19 @@ void Compositor::notify_display_links()
});
}
void Compositor::increment_display_link_count(Badge<ClientConnection>)
{
++m_display_link_count;
if (m_display_link_count == 1)
m_display_link_notify_timer->start();
}
void Compositor::decrement_display_link_count(Badge<ClientConnection>)
{
ASSERT(m_display_link_count);
--m_display_link_count;
if (!m_display_link_count)
m_display_link_notify_timer->stop();
}
}

View file

@ -34,6 +34,7 @@
namespace WindowServer {
class ClientConnection;
class Cursor;
enum class WallpaperMode {
@ -65,6 +66,9 @@ public:
void invalidate_cursor();
Gfx::Rect current_cursor_rect() const;
void increment_display_link_count(Badge<ClientConnection>);
void decrement_display_link_count(Badge<ClientConnection>);
private:
Compositor();
void init_bitmaps();
@ -96,6 +100,9 @@ private:
String m_wallpaper_path;
WallpaperMode m_wallpaper_mode { WallpaperMode::Unchecked };
RefPtr<Gfx::Bitmap> m_wallpaper;
RefPtr<Core::Timer> m_display_link_notify_timer;
size_t m_display_link_count { 0 };
};
}