diff options
author | Andreas Kling <kling@serenityos.org> | 2020-03-22 21:13:23 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-03-22 21:13:23 +0100 |
commit | 424a3f5ac3c659d57d38aba36f4062c8ecbc4044 (patch) | |
tree | c9b64b14cde9dd11d7b159beff12a89e2e470d2e /Servers/WindowServer | |
parent | bb70d0692b4aab9ec4cf24cc35abb35e2f8ef2a2 (diff) | |
download | serenity-424a3f5ac3c659d57d38aba36f4062c8ecbc4044.zip |
WindowServer+LibGUI: Add a way to get notified at display refresh rate
This patch adds GUI::DisplayLink, a mechanism for registering callbacks
that will fire at the display refresh rate.
Note that we don't actually know the screen refresh rate, but this is
instead completely driven by WindowServer's compositing timer. For all
current intents and purposes it does the job well enough. :^)
Diffstat (limited to 'Servers/WindowServer')
-rw-r--r-- | Servers/WindowServer/ClientConnection.cpp | 18 | ||||
-rw-r--r-- | Servers/WindowServer/ClientConnection.h | 8 | ||||
-rw-r--r-- | Servers/WindowServer/Compositor.cpp | 9 | ||||
-rw-r--r-- | Servers/WindowServer/Compositor.h | 1 | ||||
-rw-r--r-- | Servers/WindowServer/WindowClient.ipc | 2 | ||||
-rw-r--r-- | Servers/WindowServer/WindowServer.ipc | 3 |
6 files changed, 41 insertions, 0 deletions
diff --git a/Servers/WindowServer/ClientConnection.cpp b/Servers/WindowServer/ClientConnection.cpp index 74d1f234cd..793dfe6ad3 100644 --- a/Servers/WindowServer/ClientConnection.cpp +++ b/Servers/WindowServer/ClientConnection.cpp @@ -734,4 +734,22 @@ OwnPtr<Messages::WindowServer::SetWindowBaseSizeAndSizeIncrementResponse> Client return make<Messages::WindowServer::SetWindowBaseSizeAndSizeIncrementResponse>(); } +void ClientConnection::handle(const Messages::WindowServer::EnableDisplayLink&) +{ + m_has_display_link = true; +} + +void ClientConnection::handle(const Messages::WindowServer::DisableDisplayLink&) +{ + m_has_display_link = false; +} + +void ClientConnection::notify_display_link(Badge<Compositor>) +{ + if (!m_has_display_link) + return; + + post_message(Messages::WindowClient::DisplayLinkNotification()); +} + } diff --git a/Servers/WindowServer/ClientConnection.h b/Servers/WindowServer/ClientConnection.h index b17c384b21..a5ebdd5a65 100644 --- a/Servers/WindowServer/ClientConnection.h +++ b/Servers/WindowServer/ClientConnection.h @@ -26,6 +26,7 @@ #pragma once +#include <AK/Badge.h> #include <AK/Function.h> #include <AK/HashMap.h> #include <AK/OwnPtr.h> @@ -38,6 +39,7 @@ namespace WindowServer { +class Compositor; class Window; class Menu; class MenuBar; @@ -72,6 +74,8 @@ public: return const_cast<Menu*>(menu.value().ptr()); } + void notify_display_link(Badge<Compositor>); + private: explicit ClientConnection(Core::LocalSocket&, int client_id); @@ -117,6 +121,8 @@ private: virtual OwnPtr<Messages::WindowServer::SetSystemMenuResponse> handle(const Messages::WindowServer::SetSystemMenu&) override; virtual OwnPtr<Messages::WindowServer::SetSystemThemeResponse> handle(const Messages::WindowServer::SetSystemTheme&) override; virtual OwnPtr<Messages::WindowServer::SetWindowBaseSizeAndSizeIncrementResponse> handle(const Messages::WindowServer::SetWindowBaseSizeAndSizeIncrement&) override; + virtual void handle(const Messages::WindowServer::EnableDisplayLink&) override; + virtual void handle(const Messages::WindowServer::DisableDisplayLink&) override; HashMap<int, NonnullRefPtr<Window>> m_windows; HashMap<int, NonnullOwnPtr<MenuBar>> m_menubars; @@ -127,6 +133,8 @@ private: int m_next_menu_id { 20000 }; int m_next_window_id { 1982 }; + bool m_has_display_link { false }; + RefPtr<SharedBuffer> m_last_sent_clipboard_content; }; diff --git a/Servers/WindowServer/Compositor.cpp b/Servers/WindowServer/Compositor.cpp index a821855a16..e5cf24182b 100644 --- a/Servers/WindowServer/Compositor.cpp +++ b/Servers/WindowServer/Compositor.cpp @@ -25,6 +25,7 @@ */ #include "Compositor.h" +#include "ClientConnection.h" #include "Event.h" #include "EventLoop.h" #include "Screen.h" @@ -69,6 +70,7 @@ Compositor::Compositor() init_bitmaps(); m_compose_timer->on_timeout = [&]() { + notify_display_links(); #if defined(COMPOSITOR_DEBUG) dbgprintf("Compositor: delayed frame callback: %d rects\n", m_dirty_rects.size()); #endif @@ -466,4 +468,11 @@ void Compositor::draw_cursor() m_last_cursor_rect = cursor_rect; } +void Compositor::notify_display_links() +{ + ClientConnection::for_each_client([](auto& client) { + client.notify_display_link({}); + }); +} + } diff --git a/Servers/WindowServer/Compositor.h b/Servers/WindowServer/Compositor.h index 56c61bea3a..ce2069bdc5 100644 --- a/Servers/WindowServer/Compositor.h +++ b/Servers/WindowServer/Compositor.h @@ -70,6 +70,7 @@ private: void draw_geometry_label(); void draw_menubar(); void run_animations(); + void notify_display_links(); RefPtr<Core::Timer> m_compose_timer; RefPtr<Core::Timer> m_immediate_compose_timer; diff --git a/Servers/WindowServer/WindowClient.ipc b/Servers/WindowServer/WindowClient.ipc index 4e3c077a7d..bd0d690b52 100644 --- a/Servers/WindowServer/WindowClient.ipc +++ b/Servers/WindowServer/WindowClient.ipc @@ -35,4 +35,6 @@ endpoint WindowClient = 4 DragDropped(i32 window_id, Gfx::Point mouse_position, String text, String data_type, String data) =| UpdateSystemTheme(i32 system_theme_buffer_id) =| + + DisplayLinkNotification() =| } diff --git a/Servers/WindowServer/WindowServer.ipc b/Servers/WindowServer/WindowServer.ipc index ee805da3a7..9e29ee34b7 100644 --- a/Servers/WindowServer/WindowServer.ipc +++ b/Servers/WindowServer/WindowServer.ipc @@ -85,4 +85,7 @@ endpoint WindowServer = 2 SetSystemTheme(String theme_path, String theme_name) => (bool success) SetWindowBaseSizeAndSizeIncrement(i32 window_id, Gfx::Size base_size, Gfx::Size size_increment) => () + + EnableDisplayLink() =| + DisableDisplayLink() =| } |